Chart.js 352 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.5.0
  5. *
  6. * Copyright 2017 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(28)();
  1455. require(26)(Chart);
  1456. require(42)(Chart);
  1457. require(22)(Chart);
  1458. require(31)(Chart);
  1459. require(25)(Chart);
  1460. require(21)(Chart);
  1461. require(23)(Chart);
  1462. require(24)(Chart);
  1463. require(29)(Chart);
  1464. require(33)(Chart);
  1465. require(34)(Chart);
  1466. require(32)(Chart);
  1467. require(35)(Chart);
  1468. require(30)(Chart);
  1469. require(27)(Chart);
  1470. require(36)(Chart);
  1471. require(37)(Chart);
  1472. require(38)(Chart);
  1473. require(39)(Chart);
  1474. require(40)(Chart);
  1475. require(45)(Chart);
  1476. require(43)(Chart);
  1477. require(44)(Chart);
  1478. require(46)(Chart);
  1479. require(47)(Chart);
  1480. require(48)(Chart);
  1481. // Controllers must be loaded after elements
  1482. // See Chart.core.datasetController.dataElementType
  1483. require(15)(Chart);
  1484. require(16)(Chart);
  1485. require(17)(Chart);
  1486. require(18)(Chart);
  1487. require(19)(Chart);
  1488. require(20)(Chart);
  1489. require(8)(Chart);
  1490. require(9)(Chart);
  1491. require(10)(Chart);
  1492. require(11)(Chart);
  1493. require(12)(Chart);
  1494. require(13)(Chart);
  1495. require(14)(Chart);
  1496. window.Chart = module.exports = Chart;
  1497. },{"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,"42":42,"43":43,"44":44,"45":45,"46":46,"47":47,"48":48,"8":8,"9":9}],8:[function(require,module,exports){
  1498. 'use strict';
  1499. module.exports = function(Chart) {
  1500. Chart.Bar = function(context, config) {
  1501. config.type = 'bar';
  1502. return new Chart(context, config);
  1503. };
  1504. };
  1505. },{}],9:[function(require,module,exports){
  1506. 'use strict';
  1507. module.exports = function(Chart) {
  1508. Chart.Bubble = function(context, config) {
  1509. config.type = 'bubble';
  1510. return new Chart(context, config);
  1511. };
  1512. };
  1513. },{}],10:[function(require,module,exports){
  1514. 'use strict';
  1515. module.exports = function(Chart) {
  1516. Chart.Doughnut = function(context, config) {
  1517. config.type = 'doughnut';
  1518. return new Chart(context, config);
  1519. };
  1520. };
  1521. },{}],11:[function(require,module,exports){
  1522. 'use strict';
  1523. module.exports = function(Chart) {
  1524. Chart.Line = function(context, config) {
  1525. config.type = 'line';
  1526. return new Chart(context, config);
  1527. };
  1528. };
  1529. },{}],12:[function(require,module,exports){
  1530. 'use strict';
  1531. module.exports = function(Chart) {
  1532. Chart.PolarArea = function(context, config) {
  1533. config.type = 'polarArea';
  1534. return new Chart(context, config);
  1535. };
  1536. };
  1537. },{}],13:[function(require,module,exports){
  1538. 'use strict';
  1539. module.exports = function(Chart) {
  1540. Chart.Radar = function(context, config) {
  1541. config.type = 'radar';
  1542. return new Chart(context, config);
  1543. };
  1544. };
  1545. },{}],14:[function(require,module,exports){
  1546. 'use strict';
  1547. module.exports = function(Chart) {
  1548. var defaultConfig = {
  1549. hover: {
  1550. mode: 'single'
  1551. },
  1552. scales: {
  1553. xAxes: [{
  1554. type: 'linear', // scatter should not use a category axis
  1555. position: 'bottom',
  1556. id: 'x-axis-1' // need an ID so datasets can reference the scale
  1557. }],
  1558. yAxes: [{
  1559. type: 'linear',
  1560. position: 'left',
  1561. id: 'y-axis-1'
  1562. }]
  1563. },
  1564. tooltips: {
  1565. callbacks: {
  1566. title: function() {
  1567. // Title doesn't make sense for scatter since we format the data as a point
  1568. return '';
  1569. },
  1570. label: function(tooltipItem) {
  1571. return '(' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ')';
  1572. }
  1573. }
  1574. }
  1575. };
  1576. // Register the default config for this type
  1577. Chart.defaults.scatter = defaultConfig;
  1578. // Scatter charts use line controllers
  1579. Chart.controllers.scatter = Chart.controllers.line;
  1580. Chart.Scatter = function(context, config) {
  1581. config.type = 'scatter';
  1582. return new Chart(context, config);
  1583. };
  1584. };
  1585. },{}],15:[function(require,module,exports){
  1586. 'use strict';
  1587. module.exports = function(Chart) {
  1588. var helpers = Chart.helpers;
  1589. Chart.defaults.bar = {
  1590. hover: {
  1591. mode: 'label'
  1592. },
  1593. scales: {
  1594. xAxes: [{
  1595. type: 'category',
  1596. // Specific to Bar Controller
  1597. categoryPercentage: 0.8,
  1598. barPercentage: 0.9,
  1599. // grid line settings
  1600. gridLines: {
  1601. offsetGridLines: true
  1602. }
  1603. }],
  1604. yAxes: [{
  1605. type: 'linear'
  1606. }]
  1607. }
  1608. };
  1609. Chart.controllers.bar = Chart.DatasetController.extend({
  1610. dataElementType: Chart.elements.Rectangle,
  1611. initialize: function(chart, datasetIndex) {
  1612. Chart.DatasetController.prototype.initialize.call(this, chart, datasetIndex);
  1613. var me = this;
  1614. var meta = me.getMeta();
  1615. var dataset = me.getDataset();
  1616. meta.stack = dataset.stack;
  1617. // Use this to indicate that this is a bar dataset.
  1618. meta.bar = true;
  1619. },
  1620. // Correctly calculate the bar width accounting for stacks and the fact that not all bars are visible
  1621. getStackCount: function() {
  1622. var me = this;
  1623. var meta = me.getMeta();
  1624. var yScale = me.getScaleForId(meta.yAxisID);
  1625. var stacks = [];
  1626. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  1627. var dsMeta = me.chart.getDatasetMeta(datasetIndex);
  1628. if (dsMeta.bar && me.chart.isDatasetVisible(datasetIndex) &&
  1629. (yScale.options.stacked === false ||
  1630. (yScale.options.stacked === true && stacks.indexOf(dsMeta.stack) === -1) ||
  1631. (yScale.options.stacked === undefined && (dsMeta.stack === undefined || stacks.indexOf(dsMeta.stack) === -1)))) {
  1632. stacks.push(dsMeta.stack);
  1633. }
  1634. }, me);
  1635. return stacks.length;
  1636. },
  1637. update: function(reset) {
  1638. var me = this;
  1639. helpers.each(me.getMeta().data, function(rectangle, index) {
  1640. me.updateElement(rectangle, index, reset);
  1641. }, me);
  1642. },
  1643. updateElement: function(rectangle, index, reset) {
  1644. var me = this;
  1645. var meta = me.getMeta();
  1646. var xScale = me.getScaleForId(meta.xAxisID);
  1647. var yScale = me.getScaleForId(meta.yAxisID);
  1648. var scaleBase = yScale.getBasePixel();
  1649. var rectangleElementOptions = me.chart.options.elements.rectangle;
  1650. var custom = rectangle.custom || {};
  1651. var dataset = me.getDataset();
  1652. rectangle._xScale = xScale;
  1653. rectangle._yScale = yScale;
  1654. rectangle._datasetIndex = me.index;
  1655. rectangle._index = index;
  1656. var ruler = me.getRuler(index); // The index argument for compatible
  1657. rectangle._model = {
  1658. x: me.calculateBarX(index, me.index, ruler),
  1659. y: reset ? scaleBase : me.calculateBarY(index, me.index),
  1660. // Tooltip
  1661. label: me.chart.data.labels[index],
  1662. datasetLabel: dataset.label,
  1663. // Appearance
  1664. horizontal: false,
  1665. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  1666. width: me.calculateBarWidth(ruler),
  1667. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  1668. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  1669. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  1670. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  1671. };
  1672. rectangle.pivot();
  1673. },
  1674. calculateBarBase: function(datasetIndex, index) {
  1675. var me = this;
  1676. var meta = me.getMeta();
  1677. var yScale = me.getScaleForId(meta.yAxisID);
  1678. var base = yScale.getBaseValue();
  1679. var original = base;
  1680. if ((yScale.options.stacked === true) ||
  1681. (yScale.options.stacked === undefined && meta.stack !== undefined)) {
  1682. var chart = me.chart;
  1683. var datasets = chart.data.datasets;
  1684. var value = Number(datasets[datasetIndex].data[index]);
  1685. for (var i = 0; i < datasetIndex; i++) {
  1686. var currentDs = datasets[i];
  1687. var currentDsMeta = chart.getDatasetMeta(i);
  1688. if (currentDsMeta.bar && currentDsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i) &&
  1689. meta.stack === currentDsMeta.stack) {
  1690. var currentVal = Number(currentDs.data[index]);
  1691. base += value < 0 ? Math.min(currentVal, original) : Math.max(currentVal, original);
  1692. }
  1693. }
  1694. return yScale.getPixelForValue(base);
  1695. }
  1696. return yScale.getBasePixel();
  1697. },
  1698. getRuler: function() {
  1699. var me = this;
  1700. var meta = me.getMeta();
  1701. var xScale = me.getScaleForId(meta.xAxisID);
  1702. var stackCount = me.getStackCount();
  1703. var tickWidth = xScale.width / xScale.ticks.length;
  1704. var categoryWidth = tickWidth * xScale.options.categoryPercentage;
  1705. var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2;
  1706. var fullBarWidth = categoryWidth / stackCount;
  1707. var barWidth = fullBarWidth * xScale.options.barPercentage;
  1708. var barSpacing = fullBarWidth - (fullBarWidth * xScale.options.barPercentage);
  1709. return {
  1710. stackCount: stackCount,
  1711. tickWidth: tickWidth,
  1712. categoryWidth: categoryWidth,
  1713. categorySpacing: categorySpacing,
  1714. fullBarWidth: fullBarWidth,
  1715. barWidth: barWidth,
  1716. barSpacing: barSpacing
  1717. };
  1718. },
  1719. calculateBarWidth: function(ruler) {
  1720. var me = this;
  1721. var meta = me.getMeta();
  1722. var xScale = me.getScaleForId(meta.xAxisID);
  1723. if (xScale.options.barThickness) {
  1724. return xScale.options.barThickness;
  1725. }
  1726. return ruler.barWidth;
  1727. },
  1728. // Get stack index from the given dataset index accounting for stacks and the fact that not all bars are visible
  1729. getStackIndex: function(datasetIndex) {
  1730. var me = this;
  1731. var meta = me.chart.getDatasetMeta(datasetIndex);
  1732. var yScale = me.getScaleForId(meta.yAxisID);
  1733. var dsMeta, j;
  1734. var stacks = [meta.stack];
  1735. for (j = 0; j < datasetIndex; ++j) {
  1736. dsMeta = this.chart.getDatasetMeta(j);
  1737. if (dsMeta.bar && this.chart.isDatasetVisible(j) &&
  1738. (yScale.options.stacked === false ||
  1739. (yScale.options.stacked === true && stacks.indexOf(dsMeta.stack) === -1) ||
  1740. (yScale.options.stacked === undefined && (dsMeta.stack === undefined || stacks.indexOf(dsMeta.stack) === -1)))) {
  1741. stacks.push(dsMeta.stack);
  1742. }
  1743. }
  1744. return stacks.length - 1;
  1745. },
  1746. calculateBarX: function(index, datasetIndex, ruler) {
  1747. var me = this;
  1748. var meta = me.getMeta();
  1749. var xScale = me.getScaleForId(meta.xAxisID);
  1750. var stackIndex = me.getStackIndex(datasetIndex);
  1751. var leftTick = xScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  1752. leftTick -= me.chart.isCombo ? (ruler.tickWidth / 2) : 0;
  1753. return leftTick +
  1754. (ruler.barWidth / 2) +
  1755. ruler.categorySpacing +
  1756. (ruler.barWidth * stackIndex) +
  1757. (ruler.barSpacing / 2) +
  1758. (ruler.barSpacing * stackIndex);
  1759. },
  1760. calculateBarY: function(index, datasetIndex) {
  1761. var me = this;
  1762. var meta = me.getMeta();
  1763. var yScale = me.getScaleForId(meta.yAxisID);
  1764. var value = Number(me.getDataset().data[index]);
  1765. if (yScale.options.stacked ||
  1766. (yScale.options.stacked === undefined && meta.stack !== undefined)) {
  1767. var base = yScale.getBaseValue();
  1768. var sumPos = base,
  1769. sumNeg = base;
  1770. for (var i = 0; i < datasetIndex; i++) {
  1771. var ds = me.chart.data.datasets[i];
  1772. var dsMeta = me.chart.getDatasetMeta(i);
  1773. if (dsMeta.bar && dsMeta.yAxisID === yScale.id && me.chart.isDatasetVisible(i) &&
  1774. meta.stack === dsMeta.stack) {
  1775. var stackedVal = Number(ds.data[index]);
  1776. if (stackedVal < 0) {
  1777. sumNeg += stackedVal || 0;
  1778. } else {
  1779. sumPos += stackedVal || 0;
  1780. }
  1781. }
  1782. }
  1783. if (value < 0) {
  1784. return yScale.getPixelForValue(sumNeg + value);
  1785. }
  1786. return yScale.getPixelForValue(sumPos + value);
  1787. }
  1788. return yScale.getPixelForValue(value);
  1789. },
  1790. draw: function(ease) {
  1791. var me = this;
  1792. var easingDecimal = ease || 1;
  1793. var metaData = me.getMeta().data;
  1794. var dataset = me.getDataset();
  1795. var i, len;
  1796. Chart.canvasHelpers.clipArea(me.chart.chart.ctx, me.chart.chartArea);
  1797. for (i = 0, len = metaData.length; i < len; ++i) {
  1798. var d = dataset.data[i];
  1799. if (d !== null && d !== undefined && !isNaN(d)) {
  1800. metaData[i].transition(easingDecimal).draw();
  1801. }
  1802. }
  1803. Chart.canvasHelpers.unclipArea(me.chart.chart.ctx);
  1804. },
  1805. setHoverStyle: function(rectangle) {
  1806. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1807. var index = rectangle._index;
  1808. var custom = rectangle.custom || {};
  1809. var model = rectangle._model;
  1810. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  1811. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  1812. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  1813. },
  1814. removeHoverStyle: function(rectangle) {
  1815. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1816. var index = rectangle._index;
  1817. var custom = rectangle.custom || {};
  1818. var model = rectangle._model;
  1819. var rectangleElementOptions = this.chart.options.elements.rectangle;
  1820. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor);
  1821. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor);
  1822. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth);
  1823. }
  1824. });
  1825. // including horizontalBar in the bar file, instead of a file of its own
  1826. // it extends bar (like pie extends doughnut)
  1827. Chart.defaults.horizontalBar = {
  1828. hover: {
  1829. mode: 'label'
  1830. },
  1831. scales: {
  1832. xAxes: [{
  1833. type: 'linear',
  1834. position: 'bottom'
  1835. }],
  1836. yAxes: [{
  1837. position: 'left',
  1838. type: 'category',
  1839. // Specific to Horizontal Bar Controller
  1840. categoryPercentage: 0.8,
  1841. barPercentage: 0.9,
  1842. // grid line settings
  1843. gridLines: {
  1844. offsetGridLines: true
  1845. }
  1846. }]
  1847. },
  1848. elements: {
  1849. rectangle: {
  1850. borderSkipped: 'left'
  1851. }
  1852. },
  1853. tooltips: {
  1854. callbacks: {
  1855. title: function(tooltipItems, data) {
  1856. // Pick first xLabel for now
  1857. var title = '';
  1858. if (tooltipItems.length > 0) {
  1859. if (tooltipItems[0].yLabel) {
  1860. title = tooltipItems[0].yLabel;
  1861. } else if (data.labels.length > 0 && tooltipItems[0].index < data.labels.length) {
  1862. title = data.labels[tooltipItems[0].index];
  1863. }
  1864. }
  1865. return title;
  1866. },
  1867. label: function(tooltipItem, data) {
  1868. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  1869. return datasetLabel + ': ' + tooltipItem.xLabel;
  1870. }
  1871. }
  1872. }
  1873. };
  1874. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  1875. // Correctly calculate the bar width accounting for stacks and the fact that not all bars are visible
  1876. getStackCount: function() {
  1877. var me = this;
  1878. var meta = me.getMeta();
  1879. var xScale = me.getScaleForId(meta.xAxisID);
  1880. var stacks = [];
  1881. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  1882. var dsMeta = me.chart.getDatasetMeta(datasetIndex);
  1883. if (dsMeta.bar && me.chart.isDatasetVisible(datasetIndex) &&
  1884. (xScale.options.stacked === false ||
  1885. (xScale.options.stacked === true && stacks.indexOf(dsMeta.stack) === -1) ||
  1886. (xScale.options.stacked === undefined && (dsMeta.stack === undefined || stacks.indexOf(dsMeta.stack) === -1)))) {
  1887. stacks.push(dsMeta.stack);
  1888. }
  1889. }, me);
  1890. return stacks.length;
  1891. },
  1892. updateElement: function(rectangle, index, reset) {
  1893. var me = this;
  1894. var meta = me.getMeta();
  1895. var xScale = me.getScaleForId(meta.xAxisID);
  1896. var yScale = me.getScaleForId(meta.yAxisID);
  1897. var scaleBase = xScale.getBasePixel();
  1898. var custom = rectangle.custom || {};
  1899. var dataset = me.getDataset();
  1900. var rectangleElementOptions = me.chart.options.elements.rectangle;
  1901. rectangle._xScale = xScale;
  1902. rectangle._yScale = yScale;
  1903. rectangle._datasetIndex = me.index;
  1904. rectangle._index = index;
  1905. var ruler = me.getRuler(index); // The index argument for compatible
  1906. rectangle._model = {
  1907. x: reset ? scaleBase : me.calculateBarX(index, me.index),
  1908. y: me.calculateBarY(index, me.index, ruler),
  1909. // Tooltip
  1910. label: me.chart.data.labels[index],
  1911. datasetLabel: dataset.label,
  1912. // Appearance
  1913. horizontal: true,
  1914. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  1915. height: me.calculateBarHeight(ruler),
  1916. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  1917. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  1918. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  1919. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  1920. };
  1921. rectangle.pivot();
  1922. },
  1923. calculateBarBase: function(datasetIndex, index) {
  1924. var me = this;
  1925. var meta = me.getMeta();
  1926. var xScale = me.getScaleForId(meta.xAxisID);
  1927. var base = xScale.getBaseValue();
  1928. var originalBase = base;
  1929. if (xScale.options.stacked ||
  1930. (xScale.options.stacked === undefined && meta.stack !== undefined)) {
  1931. var chart = me.chart;
  1932. var datasets = chart.data.datasets;
  1933. var value = Number(datasets[datasetIndex].data[index]);
  1934. for (var i = 0; i < datasetIndex; i++) {
  1935. var currentDs = datasets[i];
  1936. var currentDsMeta = chart.getDatasetMeta(i);
  1937. if (currentDsMeta.bar && currentDsMeta.xAxisID === xScale.id && chart.isDatasetVisible(i) &&
  1938. meta.stack === currentDsMeta.stack) {
  1939. var currentVal = Number(currentDs.data[index]);
  1940. base += value < 0 ? Math.min(currentVal, originalBase) : Math.max(currentVal, originalBase);
  1941. }
  1942. }
  1943. return xScale.getPixelForValue(base);
  1944. }
  1945. return xScale.getBasePixel();
  1946. },
  1947. getRuler: function() {
  1948. var me = this;
  1949. var meta = me.getMeta();
  1950. var yScale = me.getScaleForId(meta.yAxisID);
  1951. var stackCount = me.getStackCount();
  1952. var tickHeight = yScale.height / yScale.ticks.length;
  1953. var categoryHeight = tickHeight * yScale.options.categoryPercentage;
  1954. var categorySpacing = (tickHeight - (tickHeight * yScale.options.categoryPercentage)) / 2;
  1955. var fullBarHeight = categoryHeight / stackCount;
  1956. var barHeight = fullBarHeight * yScale.options.barPercentage;
  1957. var barSpacing = fullBarHeight - (fullBarHeight * yScale.options.barPercentage);
  1958. return {
  1959. stackCount: stackCount,
  1960. tickHeight: tickHeight,
  1961. categoryHeight: categoryHeight,
  1962. categorySpacing: categorySpacing,
  1963. fullBarHeight: fullBarHeight,
  1964. barHeight: barHeight,
  1965. barSpacing: barSpacing
  1966. };
  1967. },
  1968. calculateBarHeight: function(ruler) {
  1969. var me = this;
  1970. var meta = me.getMeta();
  1971. var yScale = me.getScaleForId(meta.yAxisID);
  1972. if (yScale.options.barThickness) {
  1973. return yScale.options.barThickness;
  1974. }
  1975. return ruler.barHeight;
  1976. },
  1977. // Get stack index from the given dataset index accounting for stacks and the fact that not all bars are visible
  1978. getStackIndex: function(datasetIndex) {
  1979. var me = this;
  1980. var meta = me.chart.getDatasetMeta(datasetIndex);
  1981. var xScale = me.getScaleForId(meta.xAxisID);
  1982. var dsMeta, j;
  1983. var stacks = [meta.stack];
  1984. for (j = 0; j < datasetIndex; ++j) {
  1985. dsMeta = this.chart.getDatasetMeta(j);
  1986. if (dsMeta.bar && this.chart.isDatasetVisible(j) &&
  1987. (xScale.options.stacked === false ||
  1988. (xScale.options.stacked === true && stacks.indexOf(dsMeta.stack) === -1) ||
  1989. (xScale.options.stacked === undefined && (dsMeta.stack === undefined || stacks.indexOf(dsMeta.stack) === -1)))) {
  1990. stacks.push(dsMeta.stack);
  1991. }
  1992. }
  1993. return stacks.length - 1;
  1994. },
  1995. calculateBarX: function(index, datasetIndex) {
  1996. var me = this;
  1997. var meta = me.getMeta();
  1998. var xScale = me.getScaleForId(meta.xAxisID);
  1999. var value = Number(me.getDataset().data[index]);
  2000. if (xScale.options.stacked ||
  2001. (xScale.options.stacked === undefined && meta.stack !== undefined)) {
  2002. var base = xScale.getBaseValue();
  2003. var sumPos = base,
  2004. sumNeg = base;
  2005. for (var i = 0; i < datasetIndex; i++) {
  2006. var ds = me.chart.data.datasets[i];
  2007. var dsMeta = me.chart.getDatasetMeta(i);
  2008. if (dsMeta.bar && dsMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(i) &&
  2009. meta.stack === dsMeta.stack) {
  2010. var stackedVal = Number(ds.data[index]);
  2011. if (stackedVal < 0) {
  2012. sumNeg += stackedVal || 0;
  2013. } else {
  2014. sumPos += stackedVal || 0;
  2015. }
  2016. }
  2017. }
  2018. if (value < 0) {
  2019. return xScale.getPixelForValue(sumNeg + value);
  2020. }
  2021. return xScale.getPixelForValue(sumPos + value);
  2022. }
  2023. return xScale.getPixelForValue(value);
  2024. },
  2025. calculateBarY: function(index, datasetIndex, ruler) {
  2026. var me = this;
  2027. var meta = me.getMeta();
  2028. var yScale = me.getScaleForId(meta.yAxisID);
  2029. var stackIndex = me.getStackIndex(datasetIndex);
  2030. var topTick = yScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  2031. topTick -= me.chart.isCombo ? (ruler.tickHeight / 2) : 0;
  2032. return topTick +
  2033. (ruler.barHeight / 2) +
  2034. ruler.categorySpacing +
  2035. (ruler.barHeight * stackIndex) +
  2036. (ruler.barSpacing / 2) +
  2037. (ruler.barSpacing * stackIndex);
  2038. }
  2039. });
  2040. };
  2041. },{}],16:[function(require,module,exports){
  2042. 'use strict';
  2043. module.exports = function(Chart) {
  2044. var helpers = Chart.helpers;
  2045. Chart.defaults.bubble = {
  2046. hover: {
  2047. mode: 'single'
  2048. },
  2049. scales: {
  2050. xAxes: [{
  2051. type: 'linear', // bubble should probably use a linear scale by default
  2052. position: 'bottom',
  2053. id: 'x-axis-0' // need an ID so datasets can reference the scale
  2054. }],
  2055. yAxes: [{
  2056. type: 'linear',
  2057. position: 'left',
  2058. id: 'y-axis-0'
  2059. }]
  2060. },
  2061. tooltips: {
  2062. callbacks: {
  2063. title: function() {
  2064. // Title doesn't make sense for scatter since we format the data as a point
  2065. return '';
  2066. },
  2067. label: function(tooltipItem, data) {
  2068. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  2069. var dataPoint = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2070. return datasetLabel + ': (' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ', ' + dataPoint.r + ')';
  2071. }
  2072. }
  2073. }
  2074. };
  2075. Chart.controllers.bubble = Chart.DatasetController.extend({
  2076. dataElementType: Chart.elements.Point,
  2077. update: function(reset) {
  2078. var me = this;
  2079. var meta = me.getMeta();
  2080. var points = meta.data;
  2081. // Update Points
  2082. helpers.each(points, function(point, index) {
  2083. me.updateElement(point, index, reset);
  2084. });
  2085. },
  2086. updateElement: function(point, index, reset) {
  2087. var me = this;
  2088. var meta = me.getMeta();
  2089. var xScale = me.getScaleForId(meta.xAxisID);
  2090. var yScale = me.getScaleForId(meta.yAxisID);
  2091. var custom = point.custom || {};
  2092. var dataset = me.getDataset();
  2093. var data = dataset.data[index];
  2094. var pointElementOptions = me.chart.options.elements.point;
  2095. var dsIndex = me.index;
  2096. helpers.extend(point, {
  2097. // Utility
  2098. _xScale: xScale,
  2099. _yScale: yScale,
  2100. _datasetIndex: dsIndex,
  2101. _index: index,
  2102. // Desired view properties
  2103. _model: {
  2104. x: reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex, me.chart.isCombo),
  2105. y: reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex),
  2106. // Appearance
  2107. radius: reset ? 0 : custom.radius ? custom.radius : me.getRadius(data),
  2108. // Tooltip
  2109. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  2110. }
  2111. });
  2112. // Trick to reset the styles of the point
  2113. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, pointElementOptions);
  2114. var model = point._model;
  2115. model.skip = custom.skip ? custom.skip : (isNaN(model.x) || isNaN(model.y));
  2116. point.pivot();
  2117. },
  2118. getRadius: function(value) {
  2119. return value.r || this.chart.options.elements.point.radius;
  2120. },
  2121. setHoverStyle: function(point) {
  2122. var me = this;
  2123. Chart.DatasetController.prototype.setHoverStyle.call(me, point);
  2124. // Radius
  2125. var dataset = me.chart.data.datasets[point._datasetIndex];
  2126. var index = point._index;
  2127. var custom = point.custom || {};
  2128. var model = point._model;
  2129. model.radius = custom.hoverRadius ? custom.hoverRadius : (helpers.getValueAtIndexOrDefault(dataset.hoverRadius, index, me.chart.options.elements.point.hoverRadius)) + me.getRadius(dataset.data[index]);
  2130. },
  2131. removeHoverStyle: function(point) {
  2132. var me = this;
  2133. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, me.chart.options.elements.point);
  2134. var dataVal = me.chart.data.datasets[point._datasetIndex].data[point._index];
  2135. var custom = point.custom || {};
  2136. var model = point._model;
  2137. model.radius = custom.radius ? custom.radius : me.getRadius(dataVal);
  2138. }
  2139. });
  2140. };
  2141. },{}],17:[function(require,module,exports){
  2142. 'use strict';
  2143. module.exports = function(Chart) {
  2144. var helpers = Chart.helpers,
  2145. defaults = Chart.defaults;
  2146. defaults.doughnut = {
  2147. animation: {
  2148. // Boolean - Whether we animate the rotation of the Doughnut
  2149. animateRotate: true,
  2150. // Boolean - Whether we animate scaling the Doughnut from the centre
  2151. animateScale: false
  2152. },
  2153. aspectRatio: 1,
  2154. hover: {
  2155. mode: 'single'
  2156. },
  2157. legendCallback: function(chart) {
  2158. var text = [];
  2159. text.push('<ul class="' + chart.id + '-legend">');
  2160. var data = chart.data;
  2161. var datasets = data.datasets;
  2162. var labels = data.labels;
  2163. if (datasets.length) {
  2164. for (var i = 0; i < datasets[0].data.length; ++i) {
  2165. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2166. if (labels[i]) {
  2167. text.push(labels[i]);
  2168. }
  2169. text.push('</li>');
  2170. }
  2171. }
  2172. text.push('</ul>');
  2173. return text.join('');
  2174. },
  2175. legend: {
  2176. labels: {
  2177. generateLabels: function(chart) {
  2178. var data = chart.data;
  2179. if (data.labels.length && data.datasets.length) {
  2180. return data.labels.map(function(label, i) {
  2181. var meta = chart.getDatasetMeta(0);
  2182. var ds = data.datasets[0];
  2183. var arc = meta.data[i];
  2184. var custom = arc && arc.custom || {};
  2185. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2186. var arcOpts = chart.options.elements.arc;
  2187. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2188. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2189. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2190. return {
  2191. text: label,
  2192. fillStyle: fill,
  2193. strokeStyle: stroke,
  2194. lineWidth: bw,
  2195. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2196. // Extra data used for toggling the correct item
  2197. index: i
  2198. };
  2199. });
  2200. }
  2201. return [];
  2202. }
  2203. },
  2204. onClick: function(e, legendItem) {
  2205. var index = legendItem.index;
  2206. var chart = this.chart;
  2207. var i, ilen, meta;
  2208. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2209. meta = chart.getDatasetMeta(i);
  2210. // toggle visibility of index if exists
  2211. if (meta.data[index]) {
  2212. meta.data[index].hidden = !meta.data[index].hidden;
  2213. }
  2214. }
  2215. chart.update();
  2216. }
  2217. },
  2218. // The percentage of the chart that we cut out of the middle.
  2219. cutoutPercentage: 50,
  2220. // The rotation of the chart, where the first data arc begins.
  2221. rotation: Math.PI * -0.5,
  2222. // The total circumference of the chart.
  2223. circumference: Math.PI * 2.0,
  2224. // Need to override these to give a nice default
  2225. tooltips: {
  2226. callbacks: {
  2227. title: function() {
  2228. return '';
  2229. },
  2230. label: function(tooltipItem, data) {
  2231. var dataLabel = data.labels[tooltipItem.index];
  2232. var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2233. if (helpers.isArray(dataLabel)) {
  2234. // show value on first line of multiline label
  2235. // need to clone because we are changing the value
  2236. dataLabel = dataLabel.slice();
  2237. dataLabel[0] += value;
  2238. } else {
  2239. dataLabel += value;
  2240. }
  2241. return dataLabel;
  2242. }
  2243. }
  2244. }
  2245. };
  2246. defaults.pie = helpers.clone(defaults.doughnut);
  2247. helpers.extend(defaults.pie, {
  2248. cutoutPercentage: 0
  2249. });
  2250. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  2251. dataElementType: Chart.elements.Arc,
  2252. linkScales: helpers.noop,
  2253. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2254. getRingIndex: function(datasetIndex) {
  2255. var ringIndex = 0;
  2256. for (var j = 0; j < datasetIndex; ++j) {
  2257. if (this.chart.isDatasetVisible(j)) {
  2258. ++ringIndex;
  2259. }
  2260. }
  2261. return ringIndex;
  2262. },
  2263. update: function(reset) {
  2264. var me = this;
  2265. var chart = me.chart,
  2266. chartArea = chart.chartArea,
  2267. opts = chart.options,
  2268. arcOpts = opts.elements.arc,
  2269. availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth,
  2270. availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth,
  2271. minSize = Math.min(availableWidth, availableHeight),
  2272. offset = {
  2273. x: 0,
  2274. y: 0
  2275. },
  2276. meta = me.getMeta(),
  2277. cutoutPercentage = opts.cutoutPercentage,
  2278. circumference = opts.circumference;
  2279. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2280. if (circumference < Math.PI * 2.0) {
  2281. var startAngle = opts.rotation % (Math.PI * 2.0);
  2282. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2283. var endAngle = startAngle + circumference;
  2284. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2285. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2286. var contains0 = (startAngle <= 0 && 0 <= endAngle) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2287. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2288. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2289. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2290. var cutout = cutoutPercentage / 100.0;
  2291. 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))};
  2292. 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))};
  2293. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2294. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2295. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2296. }
  2297. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  2298. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  2299. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
  2300. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2301. chart.offsetX = offset.x * chart.outerRadius;
  2302. chart.offsetY = offset.y * chart.outerRadius;
  2303. meta.total = me.calculateTotal();
  2304. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  2305. me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
  2306. helpers.each(meta.data, function(arc, index) {
  2307. me.updateElement(arc, index, reset);
  2308. });
  2309. },
  2310. updateElement: function(arc, index, reset) {
  2311. var me = this;
  2312. var chart = me.chart,
  2313. chartArea = chart.chartArea,
  2314. opts = chart.options,
  2315. animationOpts = opts.animation,
  2316. centerX = (chartArea.left + chartArea.right) / 2,
  2317. centerY = (chartArea.top + chartArea.bottom) / 2,
  2318. startAngle = opts.rotation, // non reset case handled later
  2319. endAngle = opts.rotation, // non reset case handled later
  2320. dataset = me.getDataset(),
  2321. circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI)),
  2322. innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius,
  2323. outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius,
  2324. valueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2325. helpers.extend(arc, {
  2326. // Utility
  2327. _datasetIndex: me.index,
  2328. _index: index,
  2329. // Desired view properties
  2330. _model: {
  2331. x: centerX + chart.offsetX,
  2332. y: centerY + chart.offsetY,
  2333. startAngle: startAngle,
  2334. endAngle: endAngle,
  2335. circumference: circumference,
  2336. outerRadius: outerRadius,
  2337. innerRadius: innerRadius,
  2338. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  2339. }
  2340. });
  2341. var model = arc._model;
  2342. // Resets the visual styles
  2343. this.removeHoverStyle(arc);
  2344. // Set correct angles if not resetting
  2345. if (!reset || !animationOpts.animateRotate) {
  2346. if (index === 0) {
  2347. model.startAngle = opts.rotation;
  2348. } else {
  2349. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  2350. }
  2351. model.endAngle = model.startAngle + model.circumference;
  2352. }
  2353. arc.pivot();
  2354. },
  2355. removeHoverStyle: function(arc) {
  2356. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  2357. },
  2358. calculateTotal: function() {
  2359. var dataset = this.getDataset();
  2360. var meta = this.getMeta();
  2361. var total = 0;
  2362. var value;
  2363. helpers.each(meta.data, function(element, index) {
  2364. value = dataset.data[index];
  2365. if (!isNaN(value) && !element.hidden) {
  2366. total += Math.abs(value);
  2367. }
  2368. });
  2369. /* if (total === 0) {
  2370. total = NaN;
  2371. }*/
  2372. return total;
  2373. },
  2374. calculateCircumference: function(value) {
  2375. var total = this.getMeta().total;
  2376. if (total > 0 && !isNaN(value)) {
  2377. return (Math.PI * 2.0) * (value / total);
  2378. }
  2379. return 0;
  2380. },
  2381. // gets the max border or hover width to properly scale pie charts
  2382. getMaxBorderWidth: function(elements) {
  2383. var max = 0,
  2384. index = this.index,
  2385. length = elements.length,
  2386. borderWidth,
  2387. hoverWidth;
  2388. for (var i = 0; i < length; i++) {
  2389. borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0;
  2390. hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2391. max = borderWidth > max ? borderWidth : max;
  2392. max = hoverWidth > max ? hoverWidth : max;
  2393. }
  2394. return max;
  2395. }
  2396. });
  2397. };
  2398. },{}],18:[function(require,module,exports){
  2399. 'use strict';
  2400. module.exports = function(Chart) {
  2401. var helpers = Chart.helpers;
  2402. Chart.defaults.line = {
  2403. showLines: true,
  2404. spanGaps: false,
  2405. hover: {
  2406. mode: 'label'
  2407. },
  2408. scales: {
  2409. xAxes: [{
  2410. type: 'category',
  2411. id: 'x-axis-0'
  2412. }],
  2413. yAxes: [{
  2414. type: 'linear',
  2415. id: 'y-axis-0'
  2416. }]
  2417. }
  2418. };
  2419. function lineEnabled(dataset, options) {
  2420. return helpers.getValueOrDefault(dataset.showLine, options.showLines);
  2421. }
  2422. Chart.controllers.line = Chart.DatasetController.extend({
  2423. datasetElementType: Chart.elements.Line,
  2424. dataElementType: Chart.elements.Point,
  2425. update: function(reset) {
  2426. var me = this;
  2427. var meta = me.getMeta();
  2428. var line = meta.dataset;
  2429. var points = meta.data || [];
  2430. var options = me.chart.options;
  2431. var lineElementOptions = options.elements.line;
  2432. var scale = me.getScaleForId(meta.yAxisID);
  2433. var i, ilen, custom;
  2434. var dataset = me.getDataset();
  2435. var showLine = lineEnabled(dataset, options);
  2436. // Update Line
  2437. if (showLine) {
  2438. custom = line.custom || {};
  2439. // Compatibility: If the properties are defined with only the old name, use those values
  2440. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2441. dataset.lineTension = dataset.tension;
  2442. }
  2443. // Utility
  2444. line._scale = scale;
  2445. line._datasetIndex = me.index;
  2446. // Data
  2447. line._children = points;
  2448. // Model
  2449. line._model = {
  2450. // Appearance
  2451. // The default behavior of lines is to break at null values, according
  2452. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2453. // This option gives lines the ability to span gaps
  2454. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2455. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2456. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2457. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2458. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2459. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2460. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2461. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2462. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2463. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2464. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.getValueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2465. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.getValueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2466. // Scale
  2467. scaleTop: scale.top,
  2468. scaleBottom: scale.bottom,
  2469. scaleZero: scale.getBasePixel()
  2470. };
  2471. line.pivot();
  2472. }
  2473. // Update Points
  2474. for (i=0, ilen=points.length; i<ilen; ++i) {
  2475. me.updateElement(points[i], i, reset);
  2476. }
  2477. if (showLine && line._model.tension !== 0) {
  2478. me.updateBezierControlPoints();
  2479. }
  2480. // Now pivot the point for animation
  2481. for (i=0, ilen=points.length; i<ilen; ++i) {
  2482. points[i].pivot();
  2483. }
  2484. },
  2485. getPointBackgroundColor: function(point, index) {
  2486. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2487. var dataset = this.getDataset();
  2488. var custom = point.custom || {};
  2489. if (custom.backgroundColor) {
  2490. backgroundColor = custom.backgroundColor;
  2491. } else if (dataset.pointBackgroundColor) {
  2492. backgroundColor = helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2493. } else if (dataset.backgroundColor) {
  2494. backgroundColor = dataset.backgroundColor;
  2495. }
  2496. return backgroundColor;
  2497. },
  2498. getPointBorderColor: function(point, index) {
  2499. var borderColor = this.chart.options.elements.point.borderColor;
  2500. var dataset = this.getDataset();
  2501. var custom = point.custom || {};
  2502. if (custom.borderColor) {
  2503. borderColor = custom.borderColor;
  2504. } else if (dataset.pointBorderColor) {
  2505. borderColor = helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2506. } else if (dataset.borderColor) {
  2507. borderColor = dataset.borderColor;
  2508. }
  2509. return borderColor;
  2510. },
  2511. getPointBorderWidth: function(point, index) {
  2512. var borderWidth = this.chart.options.elements.point.borderWidth;
  2513. var dataset = this.getDataset();
  2514. var custom = point.custom || {};
  2515. if (!isNaN(custom.borderWidth)) {
  2516. borderWidth = custom.borderWidth;
  2517. } else if (!isNaN(dataset.pointBorderWidth)) {
  2518. borderWidth = helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2519. } else if (!isNaN(dataset.borderWidth)) {
  2520. borderWidth = dataset.borderWidth;
  2521. }
  2522. return borderWidth;
  2523. },
  2524. updateElement: function(point, index, reset) {
  2525. var me = this;
  2526. var meta = me.getMeta();
  2527. var custom = point.custom || {};
  2528. var dataset = me.getDataset();
  2529. var datasetIndex = me.index;
  2530. var value = dataset.data[index];
  2531. var yScale = me.getScaleForId(meta.yAxisID);
  2532. var xScale = me.getScaleForId(meta.xAxisID);
  2533. var pointOptions = me.chart.options.elements.point;
  2534. var x, y;
  2535. var labels = me.chart.data.labels || [];
  2536. var includeOffset = (labels.length === 1 || dataset.data.length === 1) || me.chart.isCombo;
  2537. // Compatibility: If the properties are defined with only the old name, use those values
  2538. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2539. dataset.pointRadius = dataset.radius;
  2540. }
  2541. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2542. dataset.pointHitRadius = dataset.hitRadius;
  2543. }
  2544. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex, includeOffset);
  2545. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2546. // Utility
  2547. point._xScale = xScale;
  2548. point._yScale = yScale;
  2549. point._datasetIndex = datasetIndex;
  2550. point._index = index;
  2551. // Desired view properties
  2552. point._model = {
  2553. x: x,
  2554. y: y,
  2555. skip: custom.skip || isNaN(x) || isNaN(y),
  2556. // Appearance
  2557. radius: custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2558. pointStyle: custom.pointStyle || helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2559. backgroundColor: me.getPointBackgroundColor(point, index),
  2560. borderColor: me.getPointBorderColor(point, index),
  2561. borderWidth: me.getPointBorderWidth(point, index),
  2562. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2563. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2564. // Tooltip
  2565. hitRadius: custom.hitRadius || helpers.getValueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2566. };
  2567. },
  2568. calculatePointY: function(value, index, datasetIndex) {
  2569. var me = this;
  2570. var chart = me.chart;
  2571. var meta = me.getMeta();
  2572. var yScale = me.getScaleForId(meta.yAxisID);
  2573. var sumPos = 0;
  2574. var sumNeg = 0;
  2575. var i, ds, dsMeta;
  2576. if (yScale.options.stacked) {
  2577. for (i = 0; i < datasetIndex; i++) {
  2578. ds = chart.data.datasets[i];
  2579. dsMeta = chart.getDatasetMeta(i);
  2580. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2581. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2582. if (stackedRightValue < 0) {
  2583. sumNeg += stackedRightValue || 0;
  2584. } else {
  2585. sumPos += stackedRightValue || 0;
  2586. }
  2587. }
  2588. }
  2589. var rightValue = Number(yScale.getRightValue(value));
  2590. if (rightValue < 0) {
  2591. return yScale.getPixelForValue(sumNeg + rightValue);
  2592. }
  2593. return yScale.getPixelForValue(sumPos + rightValue);
  2594. }
  2595. return yScale.getPixelForValue(value);
  2596. },
  2597. updateBezierControlPoints: function() {
  2598. var me = this;
  2599. var meta = me.getMeta();
  2600. var area = me.chart.chartArea;
  2601. var points = (meta.data || []);
  2602. var i, ilen, point, model, controlPoints;
  2603. // Only consider points that are drawn in case the spanGaps option is used
  2604. if (meta.dataset._model.spanGaps) {
  2605. points = points.filter(function(pt) {
  2606. return !pt._model.skip;
  2607. });
  2608. }
  2609. function capControlPoint(pt, min, max) {
  2610. return Math.max(Math.min(pt, max), min);
  2611. }
  2612. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2613. helpers.splineCurveMonotone(points);
  2614. } else {
  2615. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2616. point = points[i];
  2617. model = point._model;
  2618. controlPoints = helpers.splineCurve(
  2619. helpers.previousItem(points, i)._model,
  2620. model,
  2621. helpers.nextItem(points, i)._model,
  2622. meta.dataset._model.tension
  2623. );
  2624. model.controlPointPreviousX = controlPoints.previous.x;
  2625. model.controlPointPreviousY = controlPoints.previous.y;
  2626. model.controlPointNextX = controlPoints.next.x;
  2627. model.controlPointNextY = controlPoints.next.y;
  2628. }
  2629. }
  2630. if (me.chart.options.elements.line.capBezierPoints) {
  2631. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2632. model = points[i]._model;
  2633. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2634. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2635. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2636. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2637. }
  2638. }
  2639. },
  2640. draw: function(ease) {
  2641. var me = this;
  2642. var meta = me.getMeta();
  2643. var points = meta.data || [];
  2644. var easingDecimal = ease || 1;
  2645. var i, ilen;
  2646. // Transition Point Locations
  2647. for (i=0, ilen=points.length; i<ilen; ++i) {
  2648. points[i].transition(easingDecimal);
  2649. }
  2650. Chart.canvasHelpers.clipArea(me.chart.chart.ctx, me.chart.chartArea);
  2651. // Transition and Draw the line
  2652. if (lineEnabled(me.getDataset(), me.chart.options)) {
  2653. meta.dataset.transition(easingDecimal).draw();
  2654. }
  2655. Chart.canvasHelpers.unclipArea(me.chart.chart.ctx);
  2656. // Draw the points
  2657. for (i=0, ilen=points.length; i<ilen; ++i) {
  2658. points[i].draw(me.chart.chartArea);
  2659. }
  2660. },
  2661. setHoverStyle: function(point) {
  2662. // Point
  2663. var dataset = this.chart.data.datasets[point._datasetIndex];
  2664. var index = point._index;
  2665. var custom = point.custom || {};
  2666. var model = point._model;
  2667. model.radius = custom.hoverRadius || helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2668. model.backgroundColor = custom.hoverBackgroundColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2669. model.borderColor = custom.hoverBorderColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2670. model.borderWidth = custom.hoverBorderWidth || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2671. },
  2672. removeHoverStyle: function(point) {
  2673. var me = this;
  2674. var dataset = me.chart.data.datasets[point._datasetIndex];
  2675. var index = point._index;
  2676. var custom = point.custom || {};
  2677. var model = point._model;
  2678. // Compatibility: If the properties are defined with only the old name, use those values
  2679. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2680. dataset.pointRadius = dataset.radius;
  2681. }
  2682. model.radius = custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius);
  2683. model.backgroundColor = me.getPointBackgroundColor(point, index);
  2684. model.borderColor = me.getPointBorderColor(point, index);
  2685. model.borderWidth = me.getPointBorderWidth(point, index);
  2686. }
  2687. });
  2688. };
  2689. },{}],19:[function(require,module,exports){
  2690. 'use strict';
  2691. module.exports = function(Chart) {
  2692. var helpers = Chart.helpers;
  2693. Chart.defaults.polarArea = {
  2694. scale: {
  2695. type: 'radialLinear',
  2696. lineArc: true, // so that lines are circular
  2697. ticks: {
  2698. beginAtZero: true
  2699. }
  2700. },
  2701. // Boolean - Whether to animate the rotation of the chart
  2702. animation: {
  2703. animateRotate: true,
  2704. animateScale: true
  2705. },
  2706. startAngle: -0.5 * Math.PI,
  2707. aspectRatio: 1,
  2708. legendCallback: function(chart) {
  2709. var text = [];
  2710. text.push('<ul class="' + chart.id + '-legend">');
  2711. var data = chart.data;
  2712. var datasets = data.datasets;
  2713. var labels = data.labels;
  2714. if (datasets.length) {
  2715. for (var i = 0; i < datasets[0].data.length; ++i) {
  2716. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2717. if (labels[i]) {
  2718. text.push(labels[i]);
  2719. }
  2720. text.push('</li>');
  2721. }
  2722. }
  2723. text.push('</ul>');
  2724. return text.join('');
  2725. },
  2726. legend: {
  2727. labels: {
  2728. generateLabels: function(chart) {
  2729. var data = chart.data;
  2730. if (data.labels.length && data.datasets.length) {
  2731. return data.labels.map(function(label, i) {
  2732. var meta = chart.getDatasetMeta(0);
  2733. var ds = data.datasets[0];
  2734. var arc = meta.data[i];
  2735. var custom = arc.custom || {};
  2736. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2737. var arcOpts = chart.options.elements.arc;
  2738. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2739. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2740. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2741. return {
  2742. text: label,
  2743. fillStyle: fill,
  2744. strokeStyle: stroke,
  2745. lineWidth: bw,
  2746. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2747. // Extra data used for toggling the correct item
  2748. index: i
  2749. };
  2750. });
  2751. }
  2752. return [];
  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. }
  2865. return 0;
  2866. }
  2867. });
  2868. };
  2869. },{}],20:[function(require,module,exports){
  2870. 'use strict';
  2871. module.exports = function(Chart) {
  2872. var helpers = Chart.helpers;
  2873. Chart.defaults.radar = {
  2874. aspectRatio: 1,
  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. update: function(reset) {
  2889. var me = this;
  2890. var meta = me.getMeta();
  2891. var line = meta.dataset;
  2892. var points = meta.data;
  2893. var custom = line.custom || {};
  2894. var dataset = me.getDataset();
  2895. var lineElementOptions = me.chart.options.elements.line;
  2896. var scale = me.chart.scale;
  2897. // Compatibility: If the properties are defined with only the old name, use those values
  2898. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2899. dataset.lineTension = dataset.tension;
  2900. }
  2901. helpers.extend(meta.dataset, {
  2902. // Utility
  2903. _datasetIndex: me.index,
  2904. // Data
  2905. _children: points,
  2906. _loop: true,
  2907. // Model
  2908. _model: {
  2909. // Appearance
  2910. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2911. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2912. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2913. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2914. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2915. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2916. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2917. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2918. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2919. // Scale
  2920. scaleTop: scale.top,
  2921. scaleBottom: scale.bottom,
  2922. scaleZero: scale.getBasePosition()
  2923. }
  2924. });
  2925. meta.dataset.pivot();
  2926. // Update Points
  2927. helpers.each(points, function(point, index) {
  2928. me.updateElement(point, index, reset);
  2929. }, me);
  2930. // Update bezier control points
  2931. me.updateBezierControlPoints();
  2932. },
  2933. updateElement: function(point, index, reset) {
  2934. var me = this;
  2935. var custom = point.custom || {};
  2936. var dataset = me.getDataset();
  2937. var scale = me.chart.scale;
  2938. var pointElementOptions = me.chart.options.elements.point;
  2939. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  2940. helpers.extend(point, {
  2941. // Utility
  2942. _datasetIndex: me.index,
  2943. _index: index,
  2944. _scale: scale,
  2945. // Desired view properties
  2946. _model: {
  2947. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  2948. y: reset ? scale.yCenter : pointPosition.y,
  2949. // Appearance
  2950. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
  2951. radius: custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  2952. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  2953. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  2954. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  2955. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  2956. // Tooltip
  2957. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  2958. }
  2959. });
  2960. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  2961. },
  2962. updateBezierControlPoints: function() {
  2963. var chartArea = this.chart.chartArea;
  2964. var meta = this.getMeta();
  2965. helpers.each(meta.data, function(point, index) {
  2966. var model = point._model;
  2967. var controlPoints = helpers.splineCurve(
  2968. helpers.previousItem(meta.data, index, true)._model,
  2969. model,
  2970. helpers.nextItem(meta.data, index, true)._model,
  2971. model.tension
  2972. );
  2973. // Prevent the bezier going outside of the bounds of the graph
  2974. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  2975. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  2976. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  2977. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  2978. // Now pivot the point for animation
  2979. point.pivot();
  2980. });
  2981. },
  2982. draw: function(ease) {
  2983. var meta = this.getMeta();
  2984. var easingDecimal = ease || 1;
  2985. // Transition Point Locations
  2986. helpers.each(meta.data, function(point) {
  2987. point.transition(easingDecimal);
  2988. });
  2989. // Transition and Draw the line
  2990. meta.dataset.transition(easingDecimal).draw();
  2991. // Draw the points
  2992. helpers.each(meta.data, function(point) {
  2993. point.draw();
  2994. });
  2995. },
  2996. setHoverStyle: function(point) {
  2997. // Point
  2998. var dataset = this.chart.data.datasets[point._datasetIndex];
  2999. var custom = point.custom || {};
  3000. var index = point._index;
  3001. var model = point._model;
  3002. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3003. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3004. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3005. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3006. },
  3007. removeHoverStyle: function(point) {
  3008. var dataset = this.chart.data.datasets[point._datasetIndex];
  3009. var custom = point.custom || {};
  3010. var index = point._index;
  3011. var model = point._model;
  3012. var pointElementOptions = this.chart.options.elements.point;
  3013. model.radius = custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, pointElementOptions.radius);
  3014. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
  3015. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
  3016. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);
  3017. }
  3018. });
  3019. };
  3020. },{}],21:[function(require,module,exports){
  3021. /* global window: false */
  3022. 'use strict';
  3023. module.exports = function(Chart) {
  3024. var helpers = Chart.helpers;
  3025. Chart.defaults.global.animation = {
  3026. duration: 1000,
  3027. easing: 'easeOutQuart',
  3028. onProgress: helpers.noop,
  3029. onComplete: helpers.noop
  3030. };
  3031. Chart.Animation = Chart.Element.extend({
  3032. currentStep: null, // the current animation step
  3033. numSteps: 60, // default number of steps
  3034. easing: '', // the easing to use for this animation
  3035. render: null, // render function used by the animation service
  3036. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3037. onAnimationComplete: null // user specified callback to fire when the animation finishes
  3038. });
  3039. Chart.animationService = {
  3040. frameDuration: 17,
  3041. animations: [],
  3042. dropFrames: 0,
  3043. request: null,
  3044. /**
  3045. * @function Chart.animationService.addAnimation
  3046. * @param chartInstance {ChartController} the chart to animate
  3047. * @param animationObject {IAnimation} the animation that we will animate
  3048. * @param duration {Number} length of animation in ms
  3049. * @param lazy {Boolean} if true, the chart is not marked as animating to enable more responsive interactions
  3050. */
  3051. addAnimation: function(chartInstance, animationObject, duration, lazy) {
  3052. var me = this;
  3053. if (!lazy) {
  3054. chartInstance.animating = true;
  3055. }
  3056. for (var index = 0; index < me.animations.length; ++index) {
  3057. if (me.animations[index].chartInstance === chartInstance) {
  3058. // replacing an in progress animation
  3059. me.animations[index].animationObject = animationObject;
  3060. return;
  3061. }
  3062. }
  3063. me.animations.push({
  3064. chartInstance: chartInstance,
  3065. animationObject: animationObject
  3066. });
  3067. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3068. if (me.animations.length === 1) {
  3069. me.requestAnimationFrame();
  3070. }
  3071. },
  3072. // Cancel the animation for a given chart instance
  3073. cancelAnimation: function(chartInstance) {
  3074. var index = helpers.findIndex(this.animations, function(animationWrapper) {
  3075. return animationWrapper.chartInstance === chartInstance;
  3076. });
  3077. if (index !== -1) {
  3078. this.animations.splice(index, 1);
  3079. chartInstance.animating = false;
  3080. }
  3081. },
  3082. requestAnimationFrame: function() {
  3083. var me = this;
  3084. if (me.request === null) {
  3085. // Skip animation frame requests until the active one is executed.
  3086. // This can happen when processing mouse events, e.g. 'mousemove'
  3087. // and 'mouseout' events will trigger multiple renders.
  3088. me.request = helpers.requestAnimFrame.call(window, function() {
  3089. me.request = null;
  3090. me.startDigest();
  3091. });
  3092. }
  3093. },
  3094. startDigest: function() {
  3095. var me = this;
  3096. var startTime = Date.now();
  3097. var framesToDrop = 0;
  3098. if (me.dropFrames > 1) {
  3099. framesToDrop = Math.floor(me.dropFrames);
  3100. me.dropFrames = me.dropFrames % 1;
  3101. }
  3102. var i = 0;
  3103. while (i < me.animations.length) {
  3104. if (me.animations[i].animationObject.currentStep === null) {
  3105. me.animations[i].animationObject.currentStep = 0;
  3106. }
  3107. me.animations[i].animationObject.currentStep += 1 + framesToDrop;
  3108. if (me.animations[i].animationObject.currentStep > me.animations[i].animationObject.numSteps) {
  3109. me.animations[i].animationObject.currentStep = me.animations[i].animationObject.numSteps;
  3110. }
  3111. me.animations[i].animationObject.render(me.animations[i].chartInstance, me.animations[i].animationObject);
  3112. if (me.animations[i].animationObject.onAnimationProgress && me.animations[i].animationObject.onAnimationProgress.call) {
  3113. me.animations[i].animationObject.onAnimationProgress.call(me.animations[i].chartInstance, me.animations[i]);
  3114. }
  3115. if (me.animations[i].animationObject.currentStep === me.animations[i].animationObject.numSteps) {
  3116. if (me.animations[i].animationObject.onAnimationComplete && me.animations[i].animationObject.onAnimationComplete.call) {
  3117. me.animations[i].animationObject.onAnimationComplete.call(me.animations[i].chartInstance, me.animations[i]);
  3118. }
  3119. // executed the last frame. Remove the animation.
  3120. me.animations[i].chartInstance.animating = false;
  3121. me.animations.splice(i, 1);
  3122. } else {
  3123. ++i;
  3124. }
  3125. }
  3126. var endTime = Date.now();
  3127. var dropFrames = (endTime - startTime) / me.frameDuration;
  3128. me.dropFrames += dropFrames;
  3129. // Do we have more stuff to animate?
  3130. if (me.animations.length > 0) {
  3131. me.requestAnimationFrame();
  3132. }
  3133. }
  3134. };
  3135. };
  3136. },{}],22:[function(require,module,exports){
  3137. 'use strict';
  3138. module.exports = function(Chart) {
  3139. // Global Chart canvas helpers object for drawing items to canvas
  3140. var helpers = Chart.canvasHelpers = {};
  3141. helpers.drawPoint = function(ctx, pointStyle, radius, x, y) {
  3142. var type, edgeLength, xOffset, yOffset, height, size;
  3143. if (typeof pointStyle === 'object') {
  3144. type = pointStyle.toString();
  3145. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  3146. ctx.drawImage(pointStyle, x - pointStyle.width / 2, y - pointStyle.height / 2);
  3147. return;
  3148. }
  3149. }
  3150. if (isNaN(radius) || radius <= 0) {
  3151. return;
  3152. }
  3153. switch (pointStyle) {
  3154. // Default includes circle
  3155. default:
  3156. ctx.beginPath();
  3157. ctx.arc(x, y, radius, 0, Math.PI * 2);
  3158. ctx.closePath();
  3159. ctx.fill();
  3160. break;
  3161. case 'triangle':
  3162. ctx.beginPath();
  3163. edgeLength = 3 * radius / Math.sqrt(3);
  3164. height = edgeLength * Math.sqrt(3) / 2;
  3165. ctx.moveTo(x - edgeLength / 2, y + height / 3);
  3166. ctx.lineTo(x + edgeLength / 2, y + height / 3);
  3167. ctx.lineTo(x, y - 2 * height / 3);
  3168. ctx.closePath();
  3169. ctx.fill();
  3170. break;
  3171. case 'rect':
  3172. size = 1 / Math.SQRT2 * radius;
  3173. ctx.beginPath();
  3174. ctx.fillRect(x - size, y - size, 2 * size, 2 * size);
  3175. ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
  3176. break;
  3177. case 'rectRounded':
  3178. var offset = radius / Math.SQRT2;
  3179. var leftX = x - offset;
  3180. var topY = y - offset;
  3181. var sideSize = Math.SQRT2 * radius;
  3182. Chart.helpers.drawRoundedRectangle(ctx, leftX, topY, sideSize, sideSize, radius / 2);
  3183. ctx.fill();
  3184. break;
  3185. case 'rectRot':
  3186. size = 1 / Math.SQRT2 * radius;
  3187. ctx.beginPath();
  3188. ctx.moveTo(x - size, y);
  3189. ctx.lineTo(x, y + size);
  3190. ctx.lineTo(x + size, y);
  3191. ctx.lineTo(x, y - size);
  3192. ctx.closePath();
  3193. ctx.fill();
  3194. break;
  3195. case 'cross':
  3196. ctx.beginPath();
  3197. ctx.moveTo(x, y + radius);
  3198. ctx.lineTo(x, y - radius);
  3199. ctx.moveTo(x - radius, y);
  3200. ctx.lineTo(x + radius, y);
  3201. ctx.closePath();
  3202. break;
  3203. case 'crossRot':
  3204. ctx.beginPath();
  3205. xOffset = Math.cos(Math.PI / 4) * radius;
  3206. yOffset = Math.sin(Math.PI / 4) * radius;
  3207. ctx.moveTo(x - xOffset, y - yOffset);
  3208. ctx.lineTo(x + xOffset, y + yOffset);
  3209. ctx.moveTo(x - xOffset, y + yOffset);
  3210. ctx.lineTo(x + xOffset, y - yOffset);
  3211. ctx.closePath();
  3212. break;
  3213. case 'star':
  3214. ctx.beginPath();
  3215. ctx.moveTo(x, y + radius);
  3216. ctx.lineTo(x, y - radius);
  3217. ctx.moveTo(x - radius, y);
  3218. ctx.lineTo(x + radius, y);
  3219. xOffset = Math.cos(Math.PI / 4) * radius;
  3220. yOffset = Math.sin(Math.PI / 4) * radius;
  3221. ctx.moveTo(x - xOffset, y - yOffset);
  3222. ctx.lineTo(x + xOffset, y + yOffset);
  3223. ctx.moveTo(x - xOffset, y + yOffset);
  3224. ctx.lineTo(x + xOffset, y - yOffset);
  3225. ctx.closePath();
  3226. break;
  3227. case 'line':
  3228. ctx.beginPath();
  3229. ctx.moveTo(x - radius, y);
  3230. ctx.lineTo(x + radius, y);
  3231. ctx.closePath();
  3232. break;
  3233. case 'dash':
  3234. ctx.beginPath();
  3235. ctx.moveTo(x, y);
  3236. ctx.lineTo(x + radius, y);
  3237. ctx.closePath();
  3238. break;
  3239. }
  3240. ctx.stroke();
  3241. };
  3242. helpers.clipArea = function(ctx, clipArea) {
  3243. ctx.save();
  3244. ctx.beginPath();
  3245. ctx.rect(clipArea.left, clipArea.top, clipArea.right - clipArea.left, clipArea.bottom - clipArea.top);
  3246. ctx.clip();
  3247. };
  3248. helpers.unclipArea = function(ctx) {
  3249. ctx.restore();
  3250. };
  3251. };
  3252. },{}],23:[function(require,module,exports){
  3253. 'use strict';
  3254. module.exports = function(Chart) {
  3255. var helpers = Chart.helpers;
  3256. var plugins = Chart.plugins;
  3257. var platform = Chart.platform;
  3258. // Create a dictionary of chart types, to allow for extension of existing types
  3259. Chart.types = {};
  3260. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3261. // Destroy method on the chart will remove the instance of the chart from this reference.
  3262. Chart.instances = {};
  3263. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3264. Chart.controllers = {};
  3265. /**
  3266. * Initializes the given config with global and chart default values.
  3267. */
  3268. function initConfig(config) {
  3269. config = config || {};
  3270. // Do NOT use configMerge() for the data object because this method merges arrays
  3271. // and so would change references to labels and datasets, preventing data updates.
  3272. var data = config.data = config.data || {};
  3273. data.datasets = data.datasets || [];
  3274. data.labels = data.labels || [];
  3275. config.options = helpers.configMerge(
  3276. Chart.defaults.global,
  3277. Chart.defaults[config.type],
  3278. config.options || {});
  3279. return config;
  3280. }
  3281. /**
  3282. * Updates the config of the chart
  3283. * @param chart {Chart.Controller} chart to update the options for
  3284. */
  3285. function updateConfig(chart) {
  3286. var newOptions = chart.options;
  3287. // Update Scale(s) with options
  3288. if (newOptions.scale) {
  3289. chart.scale.options = newOptions.scale;
  3290. } else if (newOptions.scales) {
  3291. newOptions.scales.xAxes.concat(newOptions.scales.yAxes).forEach(function(scaleOptions) {
  3292. chart.scales[scaleOptions.id].options = scaleOptions;
  3293. });
  3294. }
  3295. // Tooltip
  3296. chart.tooltip._options = newOptions.tooltips;
  3297. }
  3298. /**
  3299. * @class Chart.Controller
  3300. * The main controller of a chart.
  3301. */
  3302. Chart.Controller = function(item, config, instance) {
  3303. var me = this;
  3304. config = initConfig(config);
  3305. var context = platform.acquireContext(item, config);
  3306. var canvas = context && context.canvas;
  3307. var height = canvas && canvas.height;
  3308. var width = canvas && canvas.width;
  3309. instance.ctx = context;
  3310. instance.canvas = canvas;
  3311. instance.config = config;
  3312. instance.width = width;
  3313. instance.height = height;
  3314. instance.aspectRatio = height? width / height : null;
  3315. me.id = helpers.uid();
  3316. me.chart = instance;
  3317. me.config = config;
  3318. me.options = config.options;
  3319. me._bufferedRender = false;
  3320. // Add the chart instance to the global namespace
  3321. Chart.instances[me.id] = me;
  3322. Object.defineProperty(me, 'data', {
  3323. get: function() {
  3324. return me.config.data;
  3325. }
  3326. });
  3327. if (!context || !canvas) {
  3328. // The given item is not a compatible context2d element, let's return before finalizing
  3329. // the chart initialization but after setting basic chart / controller properties that
  3330. // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
  3331. // https://github.com/chartjs/Chart.js/issues/2807
  3332. console.error("Failed to create chart: can't acquire context from the given item");
  3333. return me;
  3334. }
  3335. me.initialize();
  3336. me.update();
  3337. return me;
  3338. };
  3339. helpers.extend(Chart.Controller.prototype, /** @lends Chart.Controller.prototype */ {
  3340. initialize: function() {
  3341. var me = this;
  3342. // Before init plugin notification
  3343. plugins.notify(me, 'beforeInit');
  3344. helpers.retinaScale(me.chart);
  3345. me.bindEvents();
  3346. if (me.options.responsive) {
  3347. // Initial resize before chart draws (must be silent to preserve initial animations).
  3348. me.resize(true);
  3349. }
  3350. // Make sure scales have IDs and are built before we build any controllers.
  3351. me.ensureScalesHaveIDs();
  3352. me.buildScales();
  3353. me.initToolTip();
  3354. // After init plugin notification
  3355. plugins.notify(me, 'afterInit');
  3356. return me;
  3357. },
  3358. clear: function() {
  3359. helpers.clear(this.chart);
  3360. return this;
  3361. },
  3362. stop: function() {
  3363. // Stops any current animation loop occurring
  3364. Chart.animationService.cancelAnimation(this);
  3365. return this;
  3366. },
  3367. resize: function(silent) {
  3368. var me = this;
  3369. var chart = me.chart;
  3370. var options = me.options;
  3371. var canvas = chart.canvas;
  3372. var aspectRatio = (options.maintainAspectRatio && chart.aspectRatio) || null;
  3373. // the canvas render width and height will be casted to integers so make sure that
  3374. // the canvas display style uses the same integer values to avoid blurring effect.
  3375. var newWidth = Math.floor(helpers.getMaximumWidth(canvas));
  3376. var newHeight = Math.floor(aspectRatio? newWidth / aspectRatio : helpers.getMaximumHeight(canvas));
  3377. if (chart.width === newWidth && chart.height === newHeight) {
  3378. return;
  3379. }
  3380. canvas.width = chart.width = newWidth;
  3381. canvas.height = chart.height = newHeight;
  3382. canvas.style.width = newWidth + 'px';
  3383. canvas.style.height = newHeight + 'px';
  3384. helpers.retinaScale(chart);
  3385. if (!silent) {
  3386. // Notify any plugins about the resize
  3387. var newSize = {width: newWidth, height: newHeight};
  3388. plugins.notify(me, 'resize', [newSize]);
  3389. // Notify of resize
  3390. if (me.options.onResize) {
  3391. me.options.onResize(me, newSize);
  3392. }
  3393. me.stop();
  3394. me.update(me.options.responsiveAnimationDuration);
  3395. }
  3396. },
  3397. ensureScalesHaveIDs: function() {
  3398. var options = this.options;
  3399. var scalesOptions = options.scales || {};
  3400. var scaleOptions = options.scale;
  3401. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  3402. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3403. });
  3404. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  3405. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3406. });
  3407. if (scaleOptions) {
  3408. scaleOptions.id = scaleOptions.id || 'scale';
  3409. }
  3410. },
  3411. /**
  3412. * Builds a map of scale ID to scale object for future lookup.
  3413. */
  3414. buildScales: function() {
  3415. var me = this;
  3416. var options = me.options;
  3417. var scales = me.scales = {};
  3418. var items = [];
  3419. if (options.scales) {
  3420. items = items.concat(
  3421. (options.scales.xAxes || []).map(function(xAxisOptions) {
  3422. return {options: xAxisOptions, dtype: 'category'};
  3423. }),
  3424. (options.scales.yAxes || []).map(function(yAxisOptions) {
  3425. return {options: yAxisOptions, dtype: 'linear'};
  3426. })
  3427. );
  3428. }
  3429. if (options.scale) {
  3430. items.push({options: options.scale, dtype: 'radialLinear', isDefault: true});
  3431. }
  3432. helpers.each(items, function(item) {
  3433. var scaleOptions = item.options;
  3434. var scaleType = helpers.getValueOrDefault(scaleOptions.type, item.dtype);
  3435. var scaleClass = Chart.scaleService.getScaleConstructor(scaleType);
  3436. if (!scaleClass) {
  3437. return;
  3438. }
  3439. var scale = new scaleClass({
  3440. id: scaleOptions.id,
  3441. options: scaleOptions,
  3442. ctx: me.chart.ctx,
  3443. chart: me
  3444. });
  3445. scales[scale.id] = scale;
  3446. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3447. // and consider it as a regular scale part of the "scales"" map only! This would
  3448. // make the logic easier and remove some useless? custom code.
  3449. if (item.isDefault) {
  3450. me.scale = scale;
  3451. }
  3452. });
  3453. Chart.scaleService.addScalesToLayout(this);
  3454. },
  3455. buildOrUpdateControllers: function() {
  3456. var me = this;
  3457. var types = [];
  3458. var newControllers = [];
  3459. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3460. var meta = me.getDatasetMeta(datasetIndex);
  3461. if (!meta.type) {
  3462. meta.type = dataset.type || me.config.type;
  3463. }
  3464. types.push(meta.type);
  3465. if (meta.controller) {
  3466. meta.controller.updateIndex(datasetIndex);
  3467. } else {
  3468. meta.controller = new Chart.controllers[meta.type](me, datasetIndex);
  3469. newControllers.push(meta.controller);
  3470. }
  3471. }, me);
  3472. if (types.length > 1) {
  3473. for (var i = 1; i < types.length; i++) {
  3474. if (types[i] !== types[i - 1]) {
  3475. me.isCombo = true;
  3476. break;
  3477. }
  3478. }
  3479. }
  3480. return newControllers;
  3481. },
  3482. /**
  3483. * Reset the elements of all datasets
  3484. * @private
  3485. */
  3486. resetElements: function() {
  3487. var me = this;
  3488. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3489. me.getDatasetMeta(datasetIndex).controller.reset();
  3490. }, me);
  3491. },
  3492. /**
  3493. * Resets the chart back to it's state before the initial animation
  3494. */
  3495. reset: function() {
  3496. this.resetElements();
  3497. this.tooltip.initialize();
  3498. },
  3499. update: function(animationDuration, lazy) {
  3500. var me = this;
  3501. updateConfig(me);
  3502. if (plugins.notify(me, 'beforeUpdate') === false) {
  3503. return;
  3504. }
  3505. // In case the entire data object changed
  3506. me.tooltip._data = me.data;
  3507. // Make sure dataset controllers are updated and new controllers are reset
  3508. var newControllers = me.buildOrUpdateControllers();
  3509. // Make sure all dataset controllers have correct meta data counts
  3510. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3511. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3512. }, me);
  3513. me.updateLayout();
  3514. // Can only reset the new controllers after the scales have been updated
  3515. helpers.each(newControllers, function(controller) {
  3516. controller.reset();
  3517. });
  3518. me.updateDatasets();
  3519. // Do this before render so that any plugins that need final scale updates can use it
  3520. plugins.notify(me, 'afterUpdate');
  3521. if (me._bufferedRender) {
  3522. me._bufferedRequest = {
  3523. lazy: lazy,
  3524. duration: animationDuration
  3525. };
  3526. } else {
  3527. me.render(animationDuration, lazy);
  3528. }
  3529. },
  3530. /**
  3531. * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
  3532. * hook, in which case, plugins will not be called on `afterLayout`.
  3533. * @private
  3534. */
  3535. updateLayout: function() {
  3536. var me = this;
  3537. if (plugins.notify(me, 'beforeLayout') === false) {
  3538. return;
  3539. }
  3540. Chart.layoutService.update(this, this.chart.width, this.chart.height);
  3541. /**
  3542. * Provided for backward compatibility, use `afterLayout` instead.
  3543. * @method IPlugin#afterScaleUpdate
  3544. * @deprecated since version 2.5.0
  3545. * @todo remove at version 3
  3546. */
  3547. plugins.notify(me, 'afterScaleUpdate');
  3548. plugins.notify(me, 'afterLayout');
  3549. },
  3550. /**
  3551. * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
  3552. * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
  3553. * @private
  3554. */
  3555. updateDatasets: function() {
  3556. var me = this;
  3557. if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
  3558. return;
  3559. }
  3560. for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3561. me.getDatasetMeta(i).controller.update();
  3562. }
  3563. plugins.notify(me, 'afterDatasetsUpdate');
  3564. },
  3565. render: function(duration, lazy) {
  3566. var me = this;
  3567. if (plugins.notify(me, 'beforeRender') === false) {
  3568. return;
  3569. }
  3570. var animationOptions = me.options.animation;
  3571. var onComplete = function() {
  3572. plugins.notify(me, 'afterRender');
  3573. var callback = animationOptions && animationOptions.onComplete;
  3574. if (callback && callback.call) {
  3575. callback.call(me);
  3576. }
  3577. };
  3578. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3579. var animation = new Chart.Animation();
  3580. animation.numSteps = (duration || animationOptions.duration) / 16.66; // 60 fps
  3581. animation.easing = animationOptions.easing;
  3582. // render function
  3583. animation.render = function(chartInstance, animationObject) {
  3584. var easingFunction = helpers.easingEffects[animationObject.easing];
  3585. var stepDecimal = animationObject.currentStep / animationObject.numSteps;
  3586. var easeDecimal = easingFunction(stepDecimal);
  3587. chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
  3588. };
  3589. // user events
  3590. animation.onAnimationProgress = animationOptions.onProgress;
  3591. animation.onAnimationComplete = onComplete;
  3592. Chart.animationService.addAnimation(me, animation, duration, lazy);
  3593. } else {
  3594. me.draw();
  3595. onComplete();
  3596. }
  3597. return me;
  3598. },
  3599. draw: function(easingValue) {
  3600. var me = this;
  3601. me.clear();
  3602. if (easingValue === undefined || easingValue === null) {
  3603. easingValue = 1;
  3604. }
  3605. if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
  3606. return;
  3607. }
  3608. // Draw all the scales
  3609. helpers.each(me.boxes, function(box) {
  3610. box.draw(me.chartArea);
  3611. }, me);
  3612. if (me.scale) {
  3613. me.scale.draw();
  3614. }
  3615. me.drawDatasets(easingValue);
  3616. // Finally draw the tooltip
  3617. me.tooltip.transition(easingValue).draw();
  3618. plugins.notify(me, 'afterDraw', [easingValue]);
  3619. },
  3620. /**
  3621. * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
  3622. * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
  3623. * @private
  3624. */
  3625. drawDatasets: function(easingValue) {
  3626. var me = this;
  3627. if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
  3628. return;
  3629. }
  3630. // Draw each dataset via its respective controller (reversed to support proper line stacking)
  3631. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3632. if (me.isDatasetVisible(datasetIndex)) {
  3633. me.getDatasetMeta(datasetIndex).controller.draw(easingValue);
  3634. }
  3635. }, me, true);
  3636. plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
  3637. },
  3638. // Get the single element that was clicked on
  3639. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3640. getElementAtEvent: function(e) {
  3641. return Chart.Interaction.modes.single(this, e);
  3642. },
  3643. getElementsAtEvent: function(e) {
  3644. return Chart.Interaction.modes.label(this, e, {intersect: true});
  3645. },
  3646. getElementsAtXAxis: function(e) {
  3647. return Chart.Interaction.modes['x-axis'](this, e, {intersect: true});
  3648. },
  3649. getElementsAtEventForMode: function(e, mode, options) {
  3650. var method = Chart.Interaction.modes[mode];
  3651. if (typeof method === 'function') {
  3652. return method(this, e, options);
  3653. }
  3654. return [];
  3655. },
  3656. getDatasetAtEvent: function(e) {
  3657. return Chart.Interaction.modes.dataset(this, e, {intersect: true});
  3658. },
  3659. getDatasetMeta: function(datasetIndex) {
  3660. var me = this;
  3661. var dataset = me.data.datasets[datasetIndex];
  3662. if (!dataset._meta) {
  3663. dataset._meta = {};
  3664. }
  3665. var meta = dataset._meta[me.id];
  3666. if (!meta) {
  3667. meta = dataset._meta[me.id] = {
  3668. type: null,
  3669. data: [],
  3670. dataset: null,
  3671. controller: null,
  3672. hidden: null, // See isDatasetVisible() comment
  3673. xAxisID: null,
  3674. yAxisID: null
  3675. };
  3676. }
  3677. return meta;
  3678. },
  3679. getVisibleDatasetCount: function() {
  3680. var count = 0;
  3681. for (var i = 0, ilen = this.data.datasets.length; i<ilen; ++i) {
  3682. if (this.isDatasetVisible(i)) {
  3683. count++;
  3684. }
  3685. }
  3686. return count;
  3687. },
  3688. isDatasetVisible: function(datasetIndex) {
  3689. var meta = this.getDatasetMeta(datasetIndex);
  3690. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  3691. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  3692. return typeof meta.hidden === 'boolean'? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  3693. },
  3694. generateLegend: function() {
  3695. return this.options.legendCallback(this);
  3696. },
  3697. destroy: function() {
  3698. var me = this;
  3699. var canvas = me.chart.canvas;
  3700. var meta, i, ilen;
  3701. me.stop();
  3702. // dataset controllers need to cleanup associated data
  3703. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3704. meta = me.getDatasetMeta(i);
  3705. if (meta.controller) {
  3706. meta.controller.destroy();
  3707. meta.controller = null;
  3708. }
  3709. }
  3710. if (canvas) {
  3711. me.unbindEvents();
  3712. helpers.clear(me.chart);
  3713. platform.releaseContext(me.chart.ctx);
  3714. me.chart.canvas = null;
  3715. me.chart.ctx = null;
  3716. }
  3717. plugins.notify(me, 'destroy');
  3718. delete Chart.instances[me.id];
  3719. },
  3720. toBase64Image: function() {
  3721. return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
  3722. },
  3723. initToolTip: function() {
  3724. var me = this;
  3725. me.tooltip = new Chart.Tooltip({
  3726. _chart: me.chart,
  3727. _chartInstance: me,
  3728. _data: me.data,
  3729. _options: me.options.tooltips
  3730. }, me);
  3731. me.tooltip.initialize();
  3732. },
  3733. /**
  3734. * @private
  3735. */
  3736. bindEvents: function() {
  3737. var me = this;
  3738. var listeners = me._listeners = {};
  3739. var listener = function() {
  3740. me.eventHandler.apply(me, arguments);
  3741. };
  3742. helpers.each(me.options.events, function(type) {
  3743. platform.addEventListener(me, type, listener);
  3744. listeners[type] = listener;
  3745. });
  3746. // Responsiveness is currently based on the use of an iframe, however this method causes
  3747. // performance issues and could be troublesome when used with ad blockers. So make sure
  3748. // that the user is still able to create a chart without iframe when responsive is false.
  3749. // See https://github.com/chartjs/Chart.js/issues/2210
  3750. if (me.options.responsive) {
  3751. listener = function() {
  3752. me.resize();
  3753. };
  3754. platform.addEventListener(me, 'resize', listener);
  3755. listeners.resize = listener;
  3756. }
  3757. },
  3758. /**
  3759. * @private
  3760. */
  3761. unbindEvents: function() {
  3762. var me = this;
  3763. var listeners = me._listeners;
  3764. if (!listeners) {
  3765. return;
  3766. }
  3767. delete me._listeners;
  3768. helpers.each(listeners, function(listener, type) {
  3769. platform.removeEventListener(me, type, listener);
  3770. });
  3771. },
  3772. updateHoverStyle: function(elements, mode, enabled) {
  3773. var method = enabled? 'setHoverStyle' : 'removeHoverStyle';
  3774. var element, i, ilen;
  3775. for (i=0, ilen=elements.length; i<ilen; ++i) {
  3776. element = elements[i];
  3777. if (element) {
  3778. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  3779. }
  3780. }
  3781. },
  3782. /**
  3783. * @private
  3784. */
  3785. eventHandler: function(e) {
  3786. var me = this;
  3787. var tooltip = me.tooltip;
  3788. if (plugins.notify(me, 'beforeEvent', [e]) === false) {
  3789. return;
  3790. }
  3791. // Buffer any update calls so that renders do not occur
  3792. me._bufferedRender = true;
  3793. me._bufferedRequest = null;
  3794. var changed = me.handleEvent(e);
  3795. changed |= tooltip && tooltip.handleEvent(e);
  3796. plugins.notify(me, 'afterEvent', [e]);
  3797. var bufferedRequest = me._bufferedRequest;
  3798. if (bufferedRequest) {
  3799. // If we have an update that was triggered, we need to do a normal render
  3800. me.render(bufferedRequest.duration, bufferedRequest.lazy);
  3801. } else if (changed && !me.animating) {
  3802. // If entering, leaving, or changing elements, animate the change via pivot
  3803. me.stop();
  3804. // We only need to render at this point. Updating will cause scales to be
  3805. // recomputed generating flicker & using more memory than necessary.
  3806. me.render(me.options.hover.animationDuration, true);
  3807. }
  3808. me._bufferedRender = false;
  3809. me._bufferedRequest = null;
  3810. return me;
  3811. },
  3812. /**
  3813. * Handle an event
  3814. * @private
  3815. * @param {IEvent} event the event to handle
  3816. * @return {Boolean} true if the chart needs to re-render
  3817. */
  3818. handleEvent: function(e) {
  3819. var me = this;
  3820. var options = me.options || {};
  3821. var hoverOptions = options.hover;
  3822. var changed = false;
  3823. me.lastActive = me.lastActive || [];
  3824. // Find Active Elements for hover and tooltips
  3825. if (e.type === 'mouseout') {
  3826. me.active = [];
  3827. } else {
  3828. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
  3829. }
  3830. // On Hover hook
  3831. if (hoverOptions.onHover) {
  3832. // Need to call with native event here to not break backwards compatibility
  3833. hoverOptions.onHover.call(me, e.native, me.active);
  3834. }
  3835. if (e.type === 'mouseup' || e.type === 'click') {
  3836. if (options.onClick) {
  3837. // Use e.native here for backwards compatibility
  3838. options.onClick.call(me, e.native, me.active);
  3839. }
  3840. }
  3841. // Remove styling for last active (even if it may still be active)
  3842. if (me.lastActive.length) {
  3843. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  3844. }
  3845. // Built in hover styling
  3846. if (me.active.length && hoverOptions.mode) {
  3847. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  3848. }
  3849. changed = !helpers.arrayEquals(me.active, me.lastActive);
  3850. // Remember Last Actives
  3851. me.lastActive = me.active;
  3852. return changed;
  3853. }
  3854. });
  3855. };
  3856. },{}],24:[function(require,module,exports){
  3857. 'use strict';
  3858. module.exports = function(Chart) {
  3859. var helpers = Chart.helpers;
  3860. var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  3861. /**
  3862. * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
  3863. * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
  3864. * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
  3865. */
  3866. function listenArrayEvents(array, listener) {
  3867. if (array._chartjs) {
  3868. array._chartjs.listeners.push(listener);
  3869. return;
  3870. }
  3871. Object.defineProperty(array, '_chartjs', {
  3872. configurable: true,
  3873. enumerable: false,
  3874. value: {
  3875. listeners: [listener]
  3876. }
  3877. });
  3878. arrayEvents.forEach(function(key) {
  3879. var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
  3880. var base = array[key];
  3881. Object.defineProperty(array, key, {
  3882. configurable: true,
  3883. enumerable: false,
  3884. value: function() {
  3885. var args = Array.prototype.slice.call(arguments);
  3886. var res = base.apply(this, args);
  3887. helpers.each(array._chartjs.listeners, function(object) {
  3888. if (typeof object[method] === 'function') {
  3889. object[method].apply(object, args);
  3890. }
  3891. });
  3892. return res;
  3893. }
  3894. });
  3895. });
  3896. }
  3897. /**
  3898. * Removes the given array event listener and cleanup extra attached properties (such as
  3899. * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
  3900. */
  3901. function unlistenArrayEvents(array, listener) {
  3902. var stub = array._chartjs;
  3903. if (!stub) {
  3904. return;
  3905. }
  3906. var listeners = stub.listeners;
  3907. var index = listeners.indexOf(listener);
  3908. if (index !== -1) {
  3909. listeners.splice(index, 1);
  3910. }
  3911. if (listeners.length > 0) {
  3912. return;
  3913. }
  3914. arrayEvents.forEach(function(key) {
  3915. delete array[key];
  3916. });
  3917. delete array._chartjs;
  3918. }
  3919. // Base class for all dataset controllers (line, bar, etc)
  3920. Chart.DatasetController = function(chart, datasetIndex) {
  3921. this.initialize(chart, datasetIndex);
  3922. };
  3923. helpers.extend(Chart.DatasetController.prototype, {
  3924. /**
  3925. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  3926. * @type {Chart.core.element}
  3927. */
  3928. datasetElementType: null,
  3929. /**
  3930. * Element type used to generate a meta data (e.g. Chart.element.Point).
  3931. * @type {Chart.core.element}
  3932. */
  3933. dataElementType: null,
  3934. initialize: function(chart, datasetIndex) {
  3935. var me = this;
  3936. me.chart = chart;
  3937. me.index = datasetIndex;
  3938. me.linkScales();
  3939. me.addElements();
  3940. },
  3941. updateIndex: function(datasetIndex) {
  3942. this.index = datasetIndex;
  3943. },
  3944. linkScales: function() {
  3945. var me = this;
  3946. var meta = me.getMeta();
  3947. var dataset = me.getDataset();
  3948. if (meta.xAxisID === null) {
  3949. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  3950. }
  3951. if (meta.yAxisID === null) {
  3952. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  3953. }
  3954. },
  3955. getDataset: function() {
  3956. return this.chart.data.datasets[this.index];
  3957. },
  3958. getMeta: function() {
  3959. return this.chart.getDatasetMeta(this.index);
  3960. },
  3961. getScaleForId: function(scaleID) {
  3962. return this.chart.scales[scaleID];
  3963. },
  3964. reset: function() {
  3965. this.update(true);
  3966. },
  3967. /**
  3968. * @private
  3969. */
  3970. destroy: function() {
  3971. if (this._data) {
  3972. unlistenArrayEvents(this._data, this);
  3973. }
  3974. },
  3975. createMetaDataset: function() {
  3976. var me = this;
  3977. var type = me.datasetElementType;
  3978. return type && new type({
  3979. _chart: me.chart.chart,
  3980. _datasetIndex: me.index
  3981. });
  3982. },
  3983. createMetaData: function(index) {
  3984. var me = this;
  3985. var type = me.dataElementType;
  3986. return type && new type({
  3987. _chart: me.chart.chart,
  3988. _datasetIndex: me.index,
  3989. _index: index
  3990. });
  3991. },
  3992. addElements: function() {
  3993. var me = this;
  3994. var meta = me.getMeta();
  3995. var data = me.getDataset().data || [];
  3996. var metaData = meta.data;
  3997. var i, ilen;
  3998. for (i=0, ilen=data.length; i<ilen; ++i) {
  3999. metaData[i] = metaData[i] || me.createMetaData(i);
  4000. }
  4001. meta.dataset = meta.dataset || me.createMetaDataset();
  4002. },
  4003. addElementAndReset: function(index) {
  4004. var element = this.createMetaData(index);
  4005. this.getMeta().data.splice(index, 0, element);
  4006. this.updateElement(element, index, true);
  4007. },
  4008. buildOrUpdateElements: function() {
  4009. var me = this;
  4010. var dataset = me.getDataset();
  4011. var data = dataset.data || (dataset.data = []);
  4012. // In order to correctly handle data addition/deletion animation (an thus simulate
  4013. // real-time charts), we need to monitor these data modifications and synchronize
  4014. // the internal meta data accordingly.
  4015. if (me._data !== data) {
  4016. if (me._data) {
  4017. // This case happens when the user replaced the data array instance.
  4018. unlistenArrayEvents(me._data, me);
  4019. }
  4020. listenArrayEvents(data, me);
  4021. me._data = data;
  4022. }
  4023. // Re-sync meta data in case the user replaced the data array or if we missed
  4024. // any updates and so make sure that we handle number of datapoints changing.
  4025. me.resyncElements();
  4026. },
  4027. update: helpers.noop,
  4028. draw: function(ease) {
  4029. var easingDecimal = ease || 1;
  4030. var i, len;
  4031. var metaData = this.getMeta().data;
  4032. for (i = 0, len = metaData.length; i < len; ++i) {
  4033. metaData[i].transition(easingDecimal).draw();
  4034. }
  4035. },
  4036. removeHoverStyle: function(element, elementOpts) {
  4037. var dataset = this.chart.data.datasets[element._datasetIndex],
  4038. index = element._index,
  4039. custom = element.custom || {},
  4040. valueOrDefault = helpers.getValueAtIndexOrDefault,
  4041. model = element._model;
  4042. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  4043. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  4044. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  4045. },
  4046. setHoverStyle: function(element) {
  4047. var dataset = this.chart.data.datasets[element._datasetIndex],
  4048. index = element._index,
  4049. custom = element.custom || {},
  4050. valueOrDefault = helpers.getValueAtIndexOrDefault,
  4051. getHoverColor = helpers.getHoverColor,
  4052. model = element._model;
  4053. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  4054. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  4055. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  4056. },
  4057. /**
  4058. * @private
  4059. */
  4060. resyncElements: function() {
  4061. var me = this;
  4062. var meta = me.getMeta();
  4063. var data = me.getDataset().data;
  4064. var numMeta = meta.data.length;
  4065. var numData = data.length;
  4066. if (numData < numMeta) {
  4067. meta.data.splice(numData, numMeta - numData);
  4068. } else if (numData > numMeta) {
  4069. me.insertElements(numMeta, numData - numMeta);
  4070. }
  4071. },
  4072. /**
  4073. * @private
  4074. */
  4075. insertElements: function(start, count) {
  4076. for (var i=0; i<count; ++i) {
  4077. this.addElementAndReset(start + i);
  4078. }
  4079. },
  4080. /**
  4081. * @private
  4082. */
  4083. onDataPush: function() {
  4084. this.insertElements(this.getDataset().data.length-1, arguments.length);
  4085. },
  4086. /**
  4087. * @private
  4088. */
  4089. onDataPop: function() {
  4090. this.getMeta().data.pop();
  4091. },
  4092. /**
  4093. * @private
  4094. */
  4095. onDataShift: function() {
  4096. this.getMeta().data.shift();
  4097. },
  4098. /**
  4099. * @private
  4100. */
  4101. onDataSplice: function(start, count) {
  4102. this.getMeta().data.splice(start, count);
  4103. this.insertElements(start, arguments.length - 2);
  4104. },
  4105. /**
  4106. * @private
  4107. */
  4108. onDataUnshift: function() {
  4109. this.insertElements(0, arguments.length);
  4110. }
  4111. });
  4112. Chart.DatasetController.extend = helpers.inherits;
  4113. };
  4114. },{}],25:[function(require,module,exports){
  4115. 'use strict';
  4116. module.exports = function(Chart) {
  4117. var helpers = Chart.helpers;
  4118. Chart.elements = {};
  4119. Chart.Element = function(configuration) {
  4120. helpers.extend(this, configuration);
  4121. this.initialize.apply(this, arguments);
  4122. };
  4123. helpers.extend(Chart.Element.prototype, {
  4124. initialize: function() {
  4125. this.hidden = false;
  4126. },
  4127. pivot: function() {
  4128. var me = this;
  4129. if (!me._view) {
  4130. me._view = helpers.clone(me._model);
  4131. }
  4132. me._start = helpers.clone(me._view);
  4133. return me;
  4134. },
  4135. transition: function(ease) {
  4136. var me = this;
  4137. if (!me._view) {
  4138. me._view = helpers.clone(me._model);
  4139. }
  4140. // No animation -> No Transition
  4141. if (ease === 1) {
  4142. me._view = me._model;
  4143. me._start = null;
  4144. return me;
  4145. }
  4146. if (!me._start) {
  4147. me.pivot();
  4148. }
  4149. helpers.each(me._model, function(value, key) {
  4150. if (key[0] === '_') {
  4151. // Only non-underscored properties
  4152. // Init if doesn't exist
  4153. } else if (!me._view.hasOwnProperty(key)) {
  4154. if (typeof value === 'number' && !isNaN(me._view[key])) {
  4155. me._view[key] = value * ease;
  4156. } else {
  4157. me._view[key] = value;
  4158. }
  4159. // No unnecessary computations
  4160. } else if (value === me._view[key]) {
  4161. // It's the same! Woohoo!
  4162. // Color transitions if possible
  4163. } else if (typeof value === 'string') {
  4164. try {
  4165. var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
  4166. me._view[key] = color.rgbString();
  4167. } catch (err) {
  4168. me._view[key] = value;
  4169. }
  4170. // Number transitions
  4171. } else if (typeof value === 'number') {
  4172. var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
  4173. me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
  4174. // Everything else
  4175. } else {
  4176. me._view[key] = value;
  4177. }
  4178. }, me);
  4179. return me;
  4180. },
  4181. tooltipPosition: function() {
  4182. return {
  4183. x: this._model.x,
  4184. y: this._model.y
  4185. };
  4186. },
  4187. hasValue: function() {
  4188. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4189. }
  4190. });
  4191. Chart.Element.extend = helpers.inherits;
  4192. };
  4193. },{}],26:[function(require,module,exports){
  4194. /* global window: false */
  4195. /* global document: false */
  4196. 'use strict';
  4197. var color = require(3);
  4198. module.exports = function(Chart) {
  4199. // Global Chart helpers object for utility methods and classes
  4200. var helpers = Chart.helpers = {};
  4201. // -- Basic js utility methods
  4202. helpers.each = function(loopable, callback, self, reverse) {
  4203. // Check to see if null or undefined firstly.
  4204. var i, len;
  4205. if (helpers.isArray(loopable)) {
  4206. len = loopable.length;
  4207. if (reverse) {
  4208. for (i = len - 1; i >= 0; i--) {
  4209. callback.call(self, loopable[i], i);
  4210. }
  4211. } else {
  4212. for (i = 0; i < len; i++) {
  4213. callback.call(self, loopable[i], i);
  4214. }
  4215. }
  4216. } else if (typeof loopable === 'object') {
  4217. var keys = Object.keys(loopable);
  4218. len = keys.length;
  4219. for (i = 0; i < len; i++) {
  4220. callback.call(self, loopable[keys[i]], keys[i]);
  4221. }
  4222. }
  4223. };
  4224. helpers.clone = function(obj) {
  4225. var objClone = {};
  4226. helpers.each(obj, function(value, key) {
  4227. if (helpers.isArray(value)) {
  4228. objClone[key] = value.slice(0);
  4229. } else if (typeof value === 'object' && value !== null) {
  4230. objClone[key] = helpers.clone(value);
  4231. } else {
  4232. objClone[key] = value;
  4233. }
  4234. });
  4235. return objClone;
  4236. };
  4237. helpers.extend = function(base) {
  4238. var setFn = function(value, key) {
  4239. base[key] = value;
  4240. };
  4241. for (var i = 1, ilen = arguments.length; i < ilen; i++) {
  4242. helpers.each(arguments[i], setFn);
  4243. }
  4244. return base;
  4245. };
  4246. // Need a special merge function to chart configs since they are now grouped
  4247. helpers.configMerge = function(_base) {
  4248. var base = helpers.clone(_base);
  4249. helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
  4250. helpers.each(extension, function(value, key) {
  4251. var baseHasProperty = base.hasOwnProperty(key);
  4252. var baseVal = baseHasProperty ? base[key] : {};
  4253. if (key === 'scales') {
  4254. // Scale config merging is complex. Add our own function here for that
  4255. base[key] = helpers.scaleMerge(baseVal, value);
  4256. } else if (key === 'scale') {
  4257. // Used in polar area & radar charts since there is only one scale
  4258. base[key] = helpers.configMerge(baseVal, Chart.scaleService.getScaleDefaults(value.type), value);
  4259. } else if (baseHasProperty
  4260. && typeof baseVal === 'object'
  4261. && !helpers.isArray(baseVal)
  4262. && baseVal !== null
  4263. && typeof value === 'object'
  4264. && !helpers.isArray(value)) {
  4265. // If we are overwriting an object with an object, do a merge of the properties.
  4266. base[key] = helpers.configMerge(baseVal, value);
  4267. } else {
  4268. // can just overwrite the value in this case
  4269. base[key] = value;
  4270. }
  4271. });
  4272. });
  4273. return base;
  4274. };
  4275. helpers.scaleMerge = function(_base, extension) {
  4276. var base = helpers.clone(_base);
  4277. helpers.each(extension, function(value, key) {
  4278. if (key === 'xAxes' || key === 'yAxes') {
  4279. // These properties are arrays of items
  4280. if (base.hasOwnProperty(key)) {
  4281. helpers.each(value, function(valueObj, index) {
  4282. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  4283. var axisDefaults = Chart.scaleService.getScaleDefaults(axisType);
  4284. if (index >= base[key].length || !base[key][index].type) {
  4285. base[key].push(helpers.configMerge(axisDefaults, valueObj));
  4286. } else if (valueObj.type && valueObj.type !== base[key][index].type) {
  4287. // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
  4288. base[key][index] = helpers.configMerge(base[key][index], axisDefaults, valueObj);
  4289. } else {
  4290. // Type is the same
  4291. base[key][index] = helpers.configMerge(base[key][index], valueObj);
  4292. }
  4293. });
  4294. } else {
  4295. base[key] = [];
  4296. helpers.each(value, function(valueObj) {
  4297. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  4298. base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
  4299. });
  4300. }
  4301. } else if (base.hasOwnProperty(key) && typeof base[key] === 'object' && base[key] !== null && typeof value === 'object') {
  4302. // If we are overwriting an object with an object, do a merge of the properties.
  4303. base[key] = helpers.configMerge(base[key], value);
  4304. } else {
  4305. // can just overwrite the value in this case
  4306. base[key] = value;
  4307. }
  4308. });
  4309. return base;
  4310. };
  4311. helpers.getValueAtIndexOrDefault = function(value, index, defaultValue) {
  4312. if (value === undefined || value === null) {
  4313. return defaultValue;
  4314. }
  4315. if (helpers.isArray(value)) {
  4316. return index < value.length ? value[index] : defaultValue;
  4317. }
  4318. return value;
  4319. };
  4320. helpers.getValueOrDefault = function(value, defaultValue) {
  4321. return value === undefined ? defaultValue : value;
  4322. };
  4323. helpers.indexOf = Array.prototype.indexOf?
  4324. function(array, item) {
  4325. return array.indexOf(item);
  4326. }:
  4327. function(array, item) {
  4328. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4329. if (array[i] === item) {
  4330. return i;
  4331. }
  4332. }
  4333. return -1;
  4334. };
  4335. helpers.where = function(collection, filterCallback) {
  4336. if (helpers.isArray(collection) && Array.prototype.filter) {
  4337. return collection.filter(filterCallback);
  4338. }
  4339. var filtered = [];
  4340. helpers.each(collection, function(item) {
  4341. if (filterCallback(item)) {
  4342. filtered.push(item);
  4343. }
  4344. });
  4345. return filtered;
  4346. };
  4347. helpers.findIndex = Array.prototype.findIndex?
  4348. function(array, callback, scope) {
  4349. return array.findIndex(callback, scope);
  4350. } :
  4351. function(array, callback, scope) {
  4352. scope = scope === undefined? array : scope;
  4353. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4354. if (callback.call(scope, array[i], i, array)) {
  4355. return i;
  4356. }
  4357. }
  4358. return -1;
  4359. };
  4360. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  4361. // Default to start of the array
  4362. if (startIndex === undefined || startIndex === null) {
  4363. startIndex = -1;
  4364. }
  4365. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4366. var currentItem = arrayToSearch[i];
  4367. if (filterCallback(currentItem)) {
  4368. return currentItem;
  4369. }
  4370. }
  4371. };
  4372. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  4373. // Default to end of the array
  4374. if (startIndex === undefined || startIndex === null) {
  4375. startIndex = arrayToSearch.length;
  4376. }
  4377. for (var i = startIndex - 1; i >= 0; i--) {
  4378. var currentItem = arrayToSearch[i];
  4379. if (filterCallback(currentItem)) {
  4380. return currentItem;
  4381. }
  4382. }
  4383. };
  4384. helpers.inherits = function(extensions) {
  4385. // Basic javascript inheritance based on the model created in Backbone.js
  4386. var me = this;
  4387. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
  4388. return me.apply(this, arguments);
  4389. };
  4390. var Surrogate = function() {
  4391. this.constructor = ChartElement;
  4392. };
  4393. Surrogate.prototype = me.prototype;
  4394. ChartElement.prototype = new Surrogate();
  4395. ChartElement.extend = helpers.inherits;
  4396. if (extensions) {
  4397. helpers.extend(ChartElement.prototype, extensions);
  4398. }
  4399. ChartElement.__super__ = me.prototype;
  4400. return ChartElement;
  4401. };
  4402. helpers.noop = function() {};
  4403. helpers.uid = (function() {
  4404. var id = 0;
  4405. return function() {
  4406. return id++;
  4407. };
  4408. }());
  4409. // -- Math methods
  4410. helpers.isNumber = function(n) {
  4411. return !isNaN(parseFloat(n)) && isFinite(n);
  4412. };
  4413. helpers.almostEquals = function(x, y, epsilon) {
  4414. return Math.abs(x - y) < epsilon;
  4415. };
  4416. helpers.almostWhole = function(x, epsilon) {
  4417. var rounded = Math.round(x);
  4418. return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
  4419. };
  4420. helpers.max = function(array) {
  4421. return array.reduce(function(max, value) {
  4422. if (!isNaN(value)) {
  4423. return Math.max(max, value);
  4424. }
  4425. return max;
  4426. }, Number.NEGATIVE_INFINITY);
  4427. };
  4428. helpers.min = function(array) {
  4429. return array.reduce(function(min, value) {
  4430. if (!isNaN(value)) {
  4431. return Math.min(min, value);
  4432. }
  4433. return min;
  4434. }, Number.POSITIVE_INFINITY);
  4435. };
  4436. helpers.sign = Math.sign?
  4437. function(x) {
  4438. return Math.sign(x);
  4439. } :
  4440. function(x) {
  4441. x = +x; // convert to a number
  4442. if (x === 0 || isNaN(x)) {
  4443. return x;
  4444. }
  4445. return x > 0 ? 1 : -1;
  4446. };
  4447. helpers.log10 = Math.log10?
  4448. function(x) {
  4449. return Math.log10(x);
  4450. } :
  4451. function(x) {
  4452. return Math.log(x) / Math.LN10;
  4453. };
  4454. helpers.toRadians = function(degrees) {
  4455. return degrees * (Math.PI / 180);
  4456. };
  4457. helpers.toDegrees = function(radians) {
  4458. return radians * (180 / Math.PI);
  4459. };
  4460. // Gets the angle from vertical upright to the point about a centre.
  4461. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  4462. var distanceFromXCenter = anglePoint.x - centrePoint.x,
  4463. distanceFromYCenter = anglePoint.y - centrePoint.y,
  4464. radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4465. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4466. if (angle < (-0.5 * Math.PI)) {
  4467. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4468. }
  4469. return {
  4470. angle: angle,
  4471. distance: radialDistanceFromCenter
  4472. };
  4473. };
  4474. helpers.distanceBetweenPoints = function(pt1, pt2) {
  4475. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  4476. };
  4477. helpers.aliasPixel = function(pixelWidth) {
  4478. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4479. };
  4480. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  4481. // Props to Rob Spencer at scaled innovation for his post on splining between points
  4482. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4483. // This function must also respect "skipped" points
  4484. var previous = firstPoint.skip ? middlePoint : firstPoint,
  4485. current = middlePoint,
  4486. next = afterPoint.skip ? middlePoint : afterPoint;
  4487. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4488. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4489. var s01 = d01 / (d01 + d12);
  4490. var s12 = d12 / (d01 + d12);
  4491. // If all points are the same, s01 & s02 will be inf
  4492. s01 = isNaN(s01) ? 0 : s01;
  4493. s12 = isNaN(s12) ? 0 : s12;
  4494. var fa = t * s01; // scaling factor for triangle Ta
  4495. var fb = t * s12;
  4496. return {
  4497. previous: {
  4498. x: current.x - fa * (next.x - previous.x),
  4499. y: current.y - fa * (next.y - previous.y)
  4500. },
  4501. next: {
  4502. x: current.x + fb * (next.x - previous.x),
  4503. y: current.y + fb * (next.y - previous.y)
  4504. }
  4505. };
  4506. };
  4507. helpers.EPSILON = Number.EPSILON || 1e-14;
  4508. helpers.splineCurveMonotone = function(points) {
  4509. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4510. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4511. // between the dataset discrete points due to the interpolation.
  4512. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4513. var pointsWithTangents = (points || []).map(function(point) {
  4514. return {
  4515. model: point._model,
  4516. deltaK: 0,
  4517. mK: 0
  4518. };
  4519. });
  4520. // Calculate slopes (deltaK) and initialize tangents (mK)
  4521. var pointsLen = pointsWithTangents.length;
  4522. var i, pointBefore, pointCurrent, pointAfter;
  4523. for (i = 0; i < pointsLen; ++i) {
  4524. pointCurrent = pointsWithTangents[i];
  4525. if (pointCurrent.model.skip) {
  4526. continue;
  4527. }
  4528. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4529. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4530. if (pointAfter && !pointAfter.model.skip) {
  4531. var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
  4532. // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
  4533. pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
  4534. }
  4535. if (!pointBefore || pointBefore.model.skip) {
  4536. pointCurrent.mK = pointCurrent.deltaK;
  4537. } else if (!pointAfter || pointAfter.model.skip) {
  4538. pointCurrent.mK = pointBefore.deltaK;
  4539. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4540. pointCurrent.mK = 0;
  4541. } else {
  4542. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4543. }
  4544. }
  4545. // Adjust tangents to ensure monotonic properties
  4546. var alphaK, betaK, tauK, squaredMagnitude;
  4547. for (i = 0; i < pointsLen - 1; ++i) {
  4548. pointCurrent = pointsWithTangents[i];
  4549. pointAfter = pointsWithTangents[i + 1];
  4550. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4551. continue;
  4552. }
  4553. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4554. pointCurrent.mK = pointAfter.mK = 0;
  4555. continue;
  4556. }
  4557. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4558. betaK = pointAfter.mK / pointCurrent.deltaK;
  4559. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4560. if (squaredMagnitude <= 9) {
  4561. continue;
  4562. }
  4563. tauK = 3 / Math.sqrt(squaredMagnitude);
  4564. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4565. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4566. }
  4567. // Compute control points
  4568. var deltaX;
  4569. for (i = 0; i < pointsLen; ++i) {
  4570. pointCurrent = pointsWithTangents[i];
  4571. if (pointCurrent.model.skip) {
  4572. continue;
  4573. }
  4574. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4575. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4576. if (pointBefore && !pointBefore.model.skip) {
  4577. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4578. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4579. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4580. }
  4581. if (pointAfter && !pointAfter.model.skip) {
  4582. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4583. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4584. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4585. }
  4586. }
  4587. };
  4588. helpers.nextItem = function(collection, index, loop) {
  4589. if (loop) {
  4590. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4591. }
  4592. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4593. };
  4594. helpers.previousItem = function(collection, index, loop) {
  4595. if (loop) {
  4596. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4597. }
  4598. return index <= 0 ? collection[0] : collection[index - 1];
  4599. };
  4600. // Implementation of the nice number algorithm used in determining where axis labels will go
  4601. helpers.niceNum = function(range, round) {
  4602. var exponent = Math.floor(helpers.log10(range));
  4603. var fraction = range / Math.pow(10, exponent);
  4604. var niceFraction;
  4605. if (round) {
  4606. if (fraction < 1.5) {
  4607. niceFraction = 1;
  4608. } else if (fraction < 3) {
  4609. niceFraction = 2;
  4610. } else if (fraction < 7) {
  4611. niceFraction = 5;
  4612. } else {
  4613. niceFraction = 10;
  4614. }
  4615. } else if (fraction <= 1.0) {
  4616. niceFraction = 1;
  4617. } else if (fraction <= 2) {
  4618. niceFraction = 2;
  4619. } else if (fraction <= 5) {
  4620. niceFraction = 5;
  4621. } else {
  4622. niceFraction = 10;
  4623. }
  4624. return niceFraction * Math.pow(10, exponent);
  4625. };
  4626. // Easing functions adapted from Robert Penner's easing equations
  4627. // http://www.robertpenner.com/easing/
  4628. var easingEffects = helpers.easingEffects = {
  4629. linear: function(t) {
  4630. return t;
  4631. },
  4632. easeInQuad: function(t) {
  4633. return t * t;
  4634. },
  4635. easeOutQuad: function(t) {
  4636. return -1 * t * (t - 2);
  4637. },
  4638. easeInOutQuad: function(t) {
  4639. if ((t /= 1 / 2) < 1) {
  4640. return 1 / 2 * t * t;
  4641. }
  4642. return -1 / 2 * ((--t) * (t - 2) - 1);
  4643. },
  4644. easeInCubic: function(t) {
  4645. return t * t * t;
  4646. },
  4647. easeOutCubic: function(t) {
  4648. return 1 * ((t = t / 1 - 1) * t * t + 1);
  4649. },
  4650. easeInOutCubic: function(t) {
  4651. if ((t /= 1 / 2) < 1) {
  4652. return 1 / 2 * t * t * t;
  4653. }
  4654. return 1 / 2 * ((t -= 2) * t * t + 2);
  4655. },
  4656. easeInQuart: function(t) {
  4657. return t * t * t * t;
  4658. },
  4659. easeOutQuart: function(t) {
  4660. return -1 * ((t = t / 1 - 1) * t * t * t - 1);
  4661. },
  4662. easeInOutQuart: function(t) {
  4663. if ((t /= 1 / 2) < 1) {
  4664. return 1 / 2 * t * t * t * t;
  4665. }
  4666. return -1 / 2 * ((t -= 2) * t * t * t - 2);
  4667. },
  4668. easeInQuint: function(t) {
  4669. return 1 * (t /= 1) * t * t * t * t;
  4670. },
  4671. easeOutQuint: function(t) {
  4672. return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
  4673. },
  4674. easeInOutQuint: function(t) {
  4675. if ((t /= 1 / 2) < 1) {
  4676. return 1 / 2 * t * t * t * t * t;
  4677. }
  4678. return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
  4679. },
  4680. easeInSine: function(t) {
  4681. return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
  4682. },
  4683. easeOutSine: function(t) {
  4684. return 1 * Math.sin(t / 1 * (Math.PI / 2));
  4685. },
  4686. easeInOutSine: function(t) {
  4687. return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
  4688. },
  4689. easeInExpo: function(t) {
  4690. return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
  4691. },
  4692. easeOutExpo: function(t) {
  4693. return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
  4694. },
  4695. easeInOutExpo: function(t) {
  4696. if (t === 0) {
  4697. return 0;
  4698. }
  4699. if (t === 1) {
  4700. return 1;
  4701. }
  4702. if ((t /= 1 / 2) < 1) {
  4703. return 1 / 2 * Math.pow(2, 10 * (t - 1));
  4704. }
  4705. return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
  4706. },
  4707. easeInCirc: function(t) {
  4708. if (t >= 1) {
  4709. return t;
  4710. }
  4711. return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
  4712. },
  4713. easeOutCirc: function(t) {
  4714. return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
  4715. },
  4716. easeInOutCirc: function(t) {
  4717. if ((t /= 1 / 2) < 1) {
  4718. return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
  4719. }
  4720. return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  4721. },
  4722. easeInElastic: function(t) {
  4723. var s = 1.70158;
  4724. var p = 0;
  4725. var a = 1;
  4726. if (t === 0) {
  4727. return 0;
  4728. }
  4729. if ((t /= 1) === 1) {
  4730. return 1;
  4731. }
  4732. if (!p) {
  4733. p = 1 * 0.3;
  4734. }
  4735. if (a < Math.abs(1)) {
  4736. a = 1;
  4737. s = p / 4;
  4738. } else {
  4739. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4740. }
  4741. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4742. },
  4743. easeOutElastic: function(t) {
  4744. var s = 1.70158;
  4745. var p = 0;
  4746. var a = 1;
  4747. if (t === 0) {
  4748. return 0;
  4749. }
  4750. if ((t /= 1) === 1) {
  4751. return 1;
  4752. }
  4753. if (!p) {
  4754. p = 1 * 0.3;
  4755. }
  4756. if (a < Math.abs(1)) {
  4757. a = 1;
  4758. s = p / 4;
  4759. } else {
  4760. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4761. }
  4762. return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
  4763. },
  4764. easeInOutElastic: function(t) {
  4765. var s = 1.70158;
  4766. var p = 0;
  4767. var a = 1;
  4768. if (t === 0) {
  4769. return 0;
  4770. }
  4771. if ((t /= 1 / 2) === 2) {
  4772. return 1;
  4773. }
  4774. if (!p) {
  4775. p = 1 * (0.3 * 1.5);
  4776. }
  4777. if (a < Math.abs(1)) {
  4778. a = 1;
  4779. s = p / 4;
  4780. } else {
  4781. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4782. }
  4783. if (t < 1) {
  4784. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4785. }
  4786. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
  4787. },
  4788. easeInBack: function(t) {
  4789. var s = 1.70158;
  4790. return 1 * (t /= 1) * t * ((s + 1) * t - s);
  4791. },
  4792. easeOutBack: function(t) {
  4793. var s = 1.70158;
  4794. return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
  4795. },
  4796. easeInOutBack: function(t) {
  4797. var s = 1.70158;
  4798. if ((t /= 1 / 2) < 1) {
  4799. return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
  4800. }
  4801. return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  4802. },
  4803. easeInBounce: function(t) {
  4804. return 1 - easingEffects.easeOutBounce(1 - t);
  4805. },
  4806. easeOutBounce: function(t) {
  4807. if ((t /= 1) < (1 / 2.75)) {
  4808. return 1 * (7.5625 * t * t);
  4809. } else if (t < (2 / 2.75)) {
  4810. return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
  4811. } else if (t < (2.5 / 2.75)) {
  4812. return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
  4813. }
  4814. return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
  4815. },
  4816. easeInOutBounce: function(t) {
  4817. if (t < 1 / 2) {
  4818. return easingEffects.easeInBounce(t * 2) * 0.5;
  4819. }
  4820. return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
  4821. }
  4822. };
  4823. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4824. helpers.requestAnimFrame = (function() {
  4825. return window.requestAnimationFrame ||
  4826. window.webkitRequestAnimationFrame ||
  4827. window.mozRequestAnimationFrame ||
  4828. window.oRequestAnimationFrame ||
  4829. window.msRequestAnimationFrame ||
  4830. function(callback) {
  4831. return window.setTimeout(callback, 1000 / 60);
  4832. };
  4833. }());
  4834. // -- DOM methods
  4835. helpers.getRelativePosition = function(evt, chart) {
  4836. var mouseX, mouseY;
  4837. var e = evt.originalEvent || evt,
  4838. canvas = evt.currentTarget || evt.srcElement,
  4839. boundingRect = canvas.getBoundingClientRect();
  4840. var touches = e.touches;
  4841. if (touches && touches.length > 0) {
  4842. mouseX = touches[0].clientX;
  4843. mouseY = touches[0].clientY;
  4844. } else {
  4845. mouseX = e.clientX;
  4846. mouseY = e.clientY;
  4847. }
  4848. // Scale mouse coordinates into canvas coordinates
  4849. // by following the pattern laid out by 'jerryj' in the comments of
  4850. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4851. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4852. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4853. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4854. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4855. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4856. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4857. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4858. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4859. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4860. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4861. return {
  4862. x: mouseX,
  4863. y: mouseY
  4864. };
  4865. };
  4866. helpers.addEvent = function(node, eventType, method) {
  4867. if (node.addEventListener) {
  4868. node.addEventListener(eventType, method);
  4869. } else if (node.attachEvent) {
  4870. node.attachEvent('on' + eventType, method);
  4871. } else {
  4872. node['on' + eventType] = method;
  4873. }
  4874. };
  4875. helpers.removeEvent = function(node, eventType, handler) {
  4876. if (node.removeEventListener) {
  4877. node.removeEventListener(eventType, handler, false);
  4878. } else if (node.detachEvent) {
  4879. node.detachEvent('on' + eventType, handler);
  4880. } else {
  4881. node['on' + eventType] = helpers.noop;
  4882. }
  4883. };
  4884. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4885. function parseMaxStyle(styleValue, node, parentProperty) {
  4886. var valueInPixels;
  4887. if (typeof(styleValue) === 'string') {
  4888. valueInPixels = parseInt(styleValue, 10);
  4889. if (styleValue.indexOf('%') !== -1) {
  4890. // percentage * size in dimension
  4891. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4892. }
  4893. } else {
  4894. valueInPixels = styleValue;
  4895. }
  4896. return valueInPixels;
  4897. }
  4898. /**
  4899. * Returns if the given value contains an effective constraint.
  4900. * @private
  4901. */
  4902. function isConstrainedValue(value) {
  4903. return value !== undefined && value !== null && value !== 'none';
  4904. }
  4905. // Private helper to get a constraint dimension
  4906. // @param domNode : the node to check the constraint on
  4907. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  4908. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4909. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  4910. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4911. var view = document.defaultView;
  4912. var parentNode = domNode.parentNode;
  4913. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  4914. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  4915. var hasCNode = isConstrainedValue(constrainedNode);
  4916. var hasCContainer = isConstrainedValue(constrainedContainer);
  4917. var infinity = Number.POSITIVE_INFINITY;
  4918. if (hasCNode || hasCContainer) {
  4919. return Math.min(
  4920. hasCNode? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  4921. hasCContainer? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  4922. }
  4923. return 'none';
  4924. }
  4925. // returns Number or undefined if no constraint
  4926. helpers.getConstraintWidth = function(domNode) {
  4927. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4928. };
  4929. // returns Number or undefined if no constraint
  4930. helpers.getConstraintHeight = function(domNode) {
  4931. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4932. };
  4933. helpers.getMaximumWidth = function(domNode) {
  4934. var container = domNode.parentNode;
  4935. var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
  4936. var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
  4937. var w = container.clientWidth - paddingLeft - paddingRight;
  4938. var cw = helpers.getConstraintWidth(domNode);
  4939. return isNaN(cw)? w : Math.min(w, cw);
  4940. };
  4941. helpers.getMaximumHeight = function(domNode) {
  4942. var container = domNode.parentNode;
  4943. var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
  4944. var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
  4945. var h = container.clientHeight - paddingTop - paddingBottom;
  4946. var ch = helpers.getConstraintHeight(domNode);
  4947. return isNaN(ch)? h : Math.min(h, ch);
  4948. };
  4949. helpers.getStyle = function(el, property) {
  4950. return el.currentStyle ?
  4951. el.currentStyle[property] :
  4952. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4953. };
  4954. helpers.retinaScale = function(chart) {
  4955. var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1;
  4956. if (pixelRatio === 1) {
  4957. return;
  4958. }
  4959. var canvas = chart.canvas;
  4960. var height = chart.height;
  4961. var width = chart.width;
  4962. canvas.height = height * pixelRatio;
  4963. canvas.width = width * pixelRatio;
  4964. chart.ctx.scale(pixelRatio, pixelRatio);
  4965. // If no style has been set on the canvas, the render size is used as display size,
  4966. // making the chart visually bigger, so let's enforce it to the "correct" values.
  4967. // See https://github.com/chartjs/Chart.js/issues/3575
  4968. canvas.style.height = height + 'px';
  4969. canvas.style.width = width + 'px';
  4970. };
  4971. // -- Canvas methods
  4972. helpers.clear = function(chart) {
  4973. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  4974. };
  4975. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  4976. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  4977. };
  4978. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  4979. cache = cache || {};
  4980. var data = cache.data = cache.data || {};
  4981. var gc = cache.garbageCollect = cache.garbageCollect || [];
  4982. if (cache.font !== font) {
  4983. data = cache.data = {};
  4984. gc = cache.garbageCollect = [];
  4985. cache.font = font;
  4986. }
  4987. ctx.font = font;
  4988. var longest = 0;
  4989. helpers.each(arrayOfThings, function(thing) {
  4990. // Undefined strings and arrays should not be measured
  4991. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  4992. longest = helpers.measureText(ctx, data, gc, longest, thing);
  4993. } else if (helpers.isArray(thing)) {
  4994. // if it is an array lets measure each element
  4995. // to do maybe simplify this function a bit so we can do this more recursively?
  4996. helpers.each(thing, function(nestedThing) {
  4997. // Undefined strings and arrays should not be measured
  4998. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  4999. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  5000. }
  5001. });
  5002. }
  5003. });
  5004. var gcLen = gc.length / 2;
  5005. if (gcLen > arrayOfThings.length) {
  5006. for (var i = 0; i < gcLen; i++) {
  5007. delete data[gc[i]];
  5008. }
  5009. gc.splice(0, gcLen);
  5010. }
  5011. return longest;
  5012. };
  5013. helpers.measureText = function(ctx, data, gc, longest, string) {
  5014. var textWidth = data[string];
  5015. if (!textWidth) {
  5016. textWidth = data[string] = ctx.measureText(string).width;
  5017. gc.push(string);
  5018. }
  5019. if (textWidth > longest) {
  5020. longest = textWidth;
  5021. }
  5022. return longest;
  5023. };
  5024. helpers.numberOfLabelLines = function(arrayOfThings) {
  5025. var numberOfLines = 1;
  5026. helpers.each(arrayOfThings, function(thing) {
  5027. if (helpers.isArray(thing)) {
  5028. if (thing.length > numberOfLines) {
  5029. numberOfLines = thing.length;
  5030. }
  5031. }
  5032. });
  5033. return numberOfLines;
  5034. };
  5035. helpers.drawRoundedRectangle = function(ctx, x, y, width, height, radius) {
  5036. ctx.beginPath();
  5037. ctx.moveTo(x + radius, y);
  5038. ctx.lineTo(x + width - radius, y);
  5039. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  5040. ctx.lineTo(x + width, y + height - radius);
  5041. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  5042. ctx.lineTo(x + radius, y + height);
  5043. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  5044. ctx.lineTo(x, y + radius);
  5045. ctx.quadraticCurveTo(x, y, x + radius, y);
  5046. ctx.closePath();
  5047. };
  5048. helpers.color = function(c) {
  5049. if (!color) {
  5050. console.error('Color.js not found!');
  5051. return c;
  5052. }
  5053. /* global CanvasGradient */
  5054. if (c instanceof CanvasGradient) {
  5055. return color(Chart.defaults.global.defaultColor);
  5056. }
  5057. return color(c);
  5058. };
  5059. helpers.isArray = Array.isArray?
  5060. function(obj) {
  5061. return Array.isArray(obj);
  5062. } :
  5063. function(obj) {
  5064. return Object.prototype.toString.call(obj) === '[object Array]';
  5065. };
  5066. // ! @see http://stackoverflow.com/a/14853974
  5067. helpers.arrayEquals = function(a0, a1) {
  5068. var i, ilen, v0, v1;
  5069. if (!a0 || !a1 || a0.length !== a1.length) {
  5070. return false;
  5071. }
  5072. for (i = 0, ilen=a0.length; i < ilen; ++i) {
  5073. v0 = a0[i];
  5074. v1 = a1[i];
  5075. if (v0 instanceof Array && v1 instanceof Array) {
  5076. if (!helpers.arrayEquals(v0, v1)) {
  5077. return false;
  5078. }
  5079. } else if (v0 !== v1) {
  5080. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  5081. return false;
  5082. }
  5083. }
  5084. return true;
  5085. };
  5086. helpers.callCallback = function(fn, args, _tArg) {
  5087. if (fn && typeof fn.call === 'function') {
  5088. fn.apply(_tArg, args);
  5089. }
  5090. };
  5091. helpers.getHoverColor = function(colorValue) {
  5092. /* global CanvasPattern */
  5093. return (colorValue instanceof CanvasPattern) ?
  5094. colorValue :
  5095. helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
  5096. };
  5097. };
  5098. },{"3":3}],27:[function(require,module,exports){
  5099. 'use strict';
  5100. module.exports = function(Chart) {
  5101. var helpers = Chart.helpers;
  5102. /**
  5103. * Helper function to get relative position for an event
  5104. * @param {Event|IEvent} event - The event to get the position for
  5105. * @param {Chart} chart - The chart
  5106. * @returns {Point} the event position
  5107. */
  5108. function getRelativePosition(e, chart) {
  5109. if (e.native) {
  5110. return {
  5111. x: e.x,
  5112. y: e.y
  5113. };
  5114. }
  5115. return helpers.getRelativePosition(e, chart);
  5116. }
  5117. /**
  5118. * Helper function to traverse all of the visible elements in the chart
  5119. * @param chart {chart} the chart
  5120. * @param handler {Function} the callback to execute for each visible item
  5121. */
  5122. function parseVisibleItems(chart, handler) {
  5123. var datasets = chart.data.datasets;
  5124. var meta, i, j, ilen, jlen;
  5125. for (i = 0, ilen = datasets.length; i < ilen; ++i) {
  5126. if (!chart.isDatasetVisible(i)) {
  5127. continue;
  5128. }
  5129. meta = chart.getDatasetMeta(i);
  5130. for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
  5131. var element = meta.data[j];
  5132. if (!element._view.skip) {
  5133. handler(element);
  5134. }
  5135. }
  5136. }
  5137. }
  5138. /**
  5139. * Helper function to get the items that intersect the event position
  5140. * @param items {ChartElement[]} elements to filter
  5141. * @param position {Point} the point to be nearest to
  5142. * @return {ChartElement[]} the nearest items
  5143. */
  5144. function getIntersectItems(chart, position) {
  5145. var elements = [];
  5146. parseVisibleItems(chart, function(element) {
  5147. if (element.inRange(position.x, position.y)) {
  5148. elements.push(element);
  5149. }
  5150. });
  5151. return elements;
  5152. }
  5153. /**
  5154. * Helper function to get the items nearest to the event position considering all visible items in teh chart
  5155. * @param chart {Chart} the chart to look at elements from
  5156. * @param position {Point} the point to be nearest to
  5157. * @param intersect {Boolean} if true, only consider items that intersect the position
  5158. * @param distanceMetric {Function} Optional function to provide the distance between
  5159. * @return {ChartElement[]} the nearest items
  5160. */
  5161. function getNearestItems(chart, position, intersect, distanceMetric) {
  5162. var minDistance = Number.POSITIVE_INFINITY;
  5163. var nearestItems = [];
  5164. if (!distanceMetric) {
  5165. distanceMetric = helpers.distanceBetweenPoints;
  5166. }
  5167. parseVisibleItems(chart, function(element) {
  5168. if (intersect && !element.inRange(position.x, position.y)) {
  5169. return;
  5170. }
  5171. var center = element.getCenterPoint();
  5172. var distance = distanceMetric(position, center);
  5173. if (distance < minDistance) {
  5174. nearestItems = [element];
  5175. minDistance = distance;
  5176. } else if (distance === minDistance) {
  5177. // Can have multiple items at the same distance in which case we sort by size
  5178. nearestItems.push(element);
  5179. }
  5180. });
  5181. return nearestItems;
  5182. }
  5183. function indexMode(chart, e, options) {
  5184. var position = getRelativePosition(e, chart.chart);
  5185. var distanceMetric = function(pt1, pt2) {
  5186. return Math.abs(pt1.x - pt2.x);
  5187. };
  5188. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5189. var elements = [];
  5190. if (!items.length) {
  5191. return [];
  5192. }
  5193. chart.data.datasets.forEach(function(dataset, datasetIndex) {
  5194. if (chart.isDatasetVisible(datasetIndex)) {
  5195. var meta = chart.getDatasetMeta(datasetIndex),
  5196. element = meta.data[items[0]._index];
  5197. // don't count items that are skipped (null data)
  5198. if (element && !element._view.skip) {
  5199. elements.push(element);
  5200. }
  5201. }
  5202. });
  5203. return elements;
  5204. }
  5205. /**
  5206. * @interface IInteractionOptions
  5207. */
  5208. /**
  5209. * If true, only consider items that intersect the point
  5210. * @name IInterfaceOptions#boolean
  5211. * @type Boolean
  5212. */
  5213. /**
  5214. * Contains interaction related functions
  5215. * @namespace Chart.Interaction
  5216. */
  5217. Chart.Interaction = {
  5218. // Helper function for different modes
  5219. modes: {
  5220. single: function(chart, e) {
  5221. var position = getRelativePosition(e, chart.chart);
  5222. var elements = [];
  5223. parseVisibleItems(chart, function(element) {
  5224. if (element.inRange(position.x, position.y)) {
  5225. elements.push(element);
  5226. return elements;
  5227. }
  5228. });
  5229. return elements.slice(0, 1);
  5230. },
  5231. /**
  5232. * @function Chart.Interaction.modes.label
  5233. * @deprecated since version 2.4.0
  5234. */
  5235. label: indexMode,
  5236. /**
  5237. * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
  5238. * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
  5239. * @function Chart.Interaction.modes.index
  5240. * @since v2.4.0
  5241. * @param chart {chart} the chart we are returning items from
  5242. * @param e {Event} the event we are find things at
  5243. * @param options {IInteractionOptions} options to use during interaction
  5244. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5245. */
  5246. index: indexMode,
  5247. /**
  5248. * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
  5249. * If the options.intersect is false, we find the nearest item and return the items in that dataset
  5250. * @function Chart.Interaction.modes.dataset
  5251. * @param chart {chart} the chart we are returning items from
  5252. * @param e {Event} the event we are find things at
  5253. * @param options {IInteractionOptions} options to use during interaction
  5254. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5255. */
  5256. dataset: function(chart, e, options) {
  5257. var position = getRelativePosition(e, chart.chart);
  5258. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false);
  5259. if (items.length > 0) {
  5260. items = chart.getDatasetMeta(items[0]._datasetIndex).data;
  5261. }
  5262. return items;
  5263. },
  5264. /**
  5265. * @function Chart.Interaction.modes.x-axis
  5266. * @deprecated since version 2.4.0. Use index mode and intersect == true
  5267. */
  5268. 'x-axis': function(chart, e) {
  5269. return indexMode(chart, e, true);
  5270. },
  5271. /**
  5272. * Point mode returns all elements that hit test based on the event position
  5273. * of the event
  5274. * @function Chart.Interaction.modes.intersect
  5275. * @param chart {chart} the chart we are returning items from
  5276. * @param e {Event} the event we are find things at
  5277. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5278. */
  5279. point: function(chart, e) {
  5280. var position = getRelativePosition(e, chart.chart);
  5281. return getIntersectItems(chart, position);
  5282. },
  5283. /**
  5284. * nearest mode returns the element closest to the point
  5285. * @function Chart.Interaction.modes.intersect
  5286. * @param chart {chart} the chart we are returning items from
  5287. * @param e {Event} the event we are find things at
  5288. * @param options {IInteractionOptions} options to use
  5289. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5290. */
  5291. nearest: function(chart, e, options) {
  5292. var position = getRelativePosition(e, chart.chart);
  5293. var nearestItems = getNearestItems(chart, position, options.intersect);
  5294. // We have multiple items at the same distance from the event. Now sort by smallest
  5295. if (nearestItems.length > 1) {
  5296. nearestItems.sort(function(a, b) {
  5297. var sizeA = a.getArea();
  5298. var sizeB = b.getArea();
  5299. var ret = sizeA - sizeB;
  5300. if (ret === 0) {
  5301. // if equal sort by dataset index
  5302. ret = a._datasetIndex - b._datasetIndex;
  5303. }
  5304. return ret;
  5305. });
  5306. }
  5307. // Return only 1 item
  5308. return nearestItems.slice(0, 1);
  5309. },
  5310. /**
  5311. * x mode returns the elements that hit-test at the current x coordinate
  5312. * @function Chart.Interaction.modes.x
  5313. * @param chart {chart} the chart we are returning items from
  5314. * @param e {Event} the event we are find things at
  5315. * @param options {IInteractionOptions} options to use
  5316. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5317. */
  5318. x: function(chart, e, options) {
  5319. var position = getRelativePosition(e, chart.chart);
  5320. var items = [];
  5321. var intersectsItem = false;
  5322. parseVisibleItems(chart, function(element) {
  5323. if (element.inXRange(position.x)) {
  5324. items.push(element);
  5325. }
  5326. if (element.inRange(position.x, position.y)) {
  5327. intersectsItem = true;
  5328. }
  5329. });
  5330. // If we want to trigger on an intersect and we don't have any items
  5331. // that intersect the position, return nothing
  5332. if (options.intersect && !intersectsItem) {
  5333. items = [];
  5334. }
  5335. return items;
  5336. },
  5337. /**
  5338. * y mode returns the elements that hit-test at the current y coordinate
  5339. * @function Chart.Interaction.modes.y
  5340. * @param chart {chart} the chart we are returning items from
  5341. * @param e {Event} the event we are find things at
  5342. * @param options {IInteractionOptions} options to use
  5343. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5344. */
  5345. y: function(chart, e, options) {
  5346. var position = getRelativePosition(e, chart.chart);
  5347. var items = [];
  5348. var intersectsItem = false;
  5349. parseVisibleItems(chart, function(element) {
  5350. if (element.inYRange(position.y)) {
  5351. items.push(element);
  5352. }
  5353. if (element.inRange(position.x, position.y)) {
  5354. intersectsItem = true;
  5355. }
  5356. });
  5357. // If we want to trigger on an intersect and we don't have any items
  5358. // that intersect the position, return nothing
  5359. if (options.intersect && !intersectsItem) {
  5360. items = [];
  5361. }
  5362. return items;
  5363. }
  5364. }
  5365. };
  5366. };
  5367. },{}],28:[function(require,module,exports){
  5368. 'use strict';
  5369. module.exports = function() {
  5370. // Occupy the global variable of Chart, and create a simple base class
  5371. var Chart = function(item, config) {
  5372. this.controller = new Chart.Controller(item, config, this);
  5373. return this.controller;
  5374. };
  5375. // Globally expose the defaults to allow for user updating/changing
  5376. Chart.defaults = {
  5377. global: {
  5378. responsive: true,
  5379. responsiveAnimationDuration: 0,
  5380. maintainAspectRatio: true,
  5381. events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
  5382. hover: {
  5383. onHover: null,
  5384. mode: 'nearest',
  5385. intersect: true,
  5386. animationDuration: 400
  5387. },
  5388. onClick: null,
  5389. defaultColor: 'rgba(0,0,0,0.1)',
  5390. defaultFontColor: '#666',
  5391. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  5392. defaultFontSize: 12,
  5393. defaultFontStyle: 'normal',
  5394. showLines: true,
  5395. // Element defaults defined in element extensions
  5396. elements: {},
  5397. // Legend callback string
  5398. legendCallback: function(chart) {
  5399. var text = [];
  5400. text.push('<ul class="' + chart.id + '-legend">');
  5401. for (var i = 0; i < chart.data.datasets.length; i++) {
  5402. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  5403. if (chart.data.datasets[i].label) {
  5404. text.push(chart.data.datasets[i].label);
  5405. }
  5406. text.push('</li>');
  5407. }
  5408. text.push('</ul>');
  5409. return text.join('');
  5410. }
  5411. }
  5412. };
  5413. Chart.Chart = Chart;
  5414. return Chart;
  5415. };
  5416. },{}],29:[function(require,module,exports){
  5417. 'use strict';
  5418. module.exports = function(Chart) {
  5419. var helpers = Chart.helpers;
  5420. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  5421. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  5422. // It is this service's responsibility of carrying out that layout.
  5423. Chart.layoutService = {
  5424. defaults: {},
  5425. // Register a box to a chartInstance. A box is simply a reference to an object that requires layout. eg. Scales, Legend, Plugins.
  5426. addBox: function(chartInstance, box) {
  5427. if (!chartInstance.boxes) {
  5428. chartInstance.boxes = [];
  5429. }
  5430. chartInstance.boxes.push(box);
  5431. },
  5432. removeBox: function(chartInstance, box) {
  5433. if (!chartInstance.boxes) {
  5434. return;
  5435. }
  5436. chartInstance.boxes.splice(chartInstance.boxes.indexOf(box), 1);
  5437. },
  5438. // The most important function
  5439. update: function(chartInstance, width, height) {
  5440. if (!chartInstance) {
  5441. return;
  5442. }
  5443. var layoutOptions = chartInstance.options.layout;
  5444. var padding = layoutOptions ? layoutOptions.padding : null;
  5445. var leftPadding = 0;
  5446. var rightPadding = 0;
  5447. var topPadding = 0;
  5448. var bottomPadding = 0;
  5449. if (!isNaN(padding)) {
  5450. // options.layout.padding is a number. assign to all
  5451. leftPadding = padding;
  5452. rightPadding = padding;
  5453. topPadding = padding;
  5454. bottomPadding = padding;
  5455. } else {
  5456. leftPadding = padding.left || 0;
  5457. rightPadding = padding.right || 0;
  5458. topPadding = padding.top || 0;
  5459. bottomPadding = padding.bottom || 0;
  5460. }
  5461. var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
  5462. return box.options.position === 'left';
  5463. });
  5464. var rightBoxes = helpers.where(chartInstance.boxes, function(box) {
  5465. return box.options.position === 'right';
  5466. });
  5467. var topBoxes = helpers.where(chartInstance.boxes, function(box) {
  5468. return box.options.position === 'top';
  5469. });
  5470. var bottomBoxes = helpers.where(chartInstance.boxes, function(box) {
  5471. return box.options.position === 'bottom';
  5472. });
  5473. // Boxes that overlay the chartarea such as the radialLinear scale
  5474. var chartAreaBoxes = helpers.where(chartInstance.boxes, function(box) {
  5475. return box.options.position === 'chartArea';
  5476. });
  5477. // Ensure that full width boxes are at the very top / bottom
  5478. topBoxes.sort(function(a, b) {
  5479. return (b.options.fullWidth ? 1 : 0) - (a.options.fullWidth ? 1 : 0);
  5480. });
  5481. bottomBoxes.sort(function(a, b) {
  5482. return (a.options.fullWidth ? 1 : 0) - (b.options.fullWidth ? 1 : 0);
  5483. });
  5484. // Essentially we now have any number of boxes on each of the 4 sides.
  5485. // Our canvas looks like the following.
  5486. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  5487. // B1 is the bottom axis
  5488. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  5489. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  5490. // an error will be thrown.
  5491. //
  5492. // |----------------------------------------------------|
  5493. // | T1 (Full Width) |
  5494. // |----------------------------------------------------|
  5495. // | | | T2 | |
  5496. // | |----|-------------------------------------|----|
  5497. // | | | C1 | | C2 | |
  5498. // | | |----| |----| |
  5499. // | | | | |
  5500. // | L1 | L2 | ChartArea (C0) | R1 |
  5501. // | | | | |
  5502. // | | |----| |----| |
  5503. // | | | C3 | | C4 | |
  5504. // | |----|-------------------------------------|----|
  5505. // | | | B1 | |
  5506. // |----------------------------------------------------|
  5507. // | B2 (Full Width) |
  5508. // |----------------------------------------------------|
  5509. //
  5510. // What we do to find the best sizing, we do the following
  5511. // 1. Determine the minimum size of the chart area.
  5512. // 2. Split the remaining width equally between each vertical axis
  5513. // 3. Split the remaining height equally between each horizontal axis
  5514. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  5515. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  5516. // 6. Refit each axis
  5517. // 7. Position each axis in the final location
  5518. // 8. Tell the chart the final location of the chart area
  5519. // 9. Tell any axes that overlay the chart area the positions of the chart area
  5520. // Step 1
  5521. var chartWidth = width - leftPadding - rightPadding;
  5522. var chartHeight = height - topPadding - bottomPadding;
  5523. var chartAreaWidth = chartWidth / 2; // min 50%
  5524. var chartAreaHeight = chartHeight / 2; // min 50%
  5525. // Step 2
  5526. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  5527. // Step 3
  5528. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  5529. // Step 4
  5530. var maxChartAreaWidth = chartWidth;
  5531. var maxChartAreaHeight = chartHeight;
  5532. var minBoxSizes = [];
  5533. function getMinimumBoxSize(box) {
  5534. var minSize;
  5535. var isHorizontal = box.isHorizontal();
  5536. if (isHorizontal) {
  5537. minSize = box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5538. maxChartAreaHeight -= minSize.height;
  5539. } else {
  5540. minSize = box.update(verticalBoxWidth, chartAreaHeight);
  5541. maxChartAreaWidth -= minSize.width;
  5542. }
  5543. minBoxSizes.push({
  5544. horizontal: isHorizontal,
  5545. minSize: minSize,
  5546. box: box,
  5547. });
  5548. }
  5549. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  5550. // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
  5551. var maxHorizontalLeftPadding = 0;
  5552. var maxHorizontalRightPadding = 0;
  5553. var maxVerticalTopPadding = 0;
  5554. var maxVerticalBottomPadding = 0;
  5555. helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
  5556. if (horizontalBox.getPadding) {
  5557. var boxPadding = horizontalBox.getPadding();
  5558. maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
  5559. maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
  5560. }
  5561. });
  5562. helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
  5563. if (verticalBox.getPadding) {
  5564. var boxPadding = verticalBox.getPadding();
  5565. maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
  5566. maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
  5567. }
  5568. });
  5569. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  5570. // be if the axes are drawn at their minimum sizes.
  5571. // Steps 5 & 6
  5572. var totalLeftBoxesWidth = leftPadding;
  5573. var totalRightBoxesWidth = rightPadding;
  5574. var totalTopBoxesHeight = topPadding;
  5575. var totalBottomBoxesHeight = bottomPadding;
  5576. // Function to fit a box
  5577. function fitBox(box) {
  5578. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
  5579. return minBox.box === box;
  5580. });
  5581. if (minBoxSize) {
  5582. if (box.isHorizontal()) {
  5583. var scaleMargin = {
  5584. left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
  5585. right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
  5586. top: 0,
  5587. bottom: 0
  5588. };
  5589. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5590. // on the margin. Sometimes they need to increase in size slightly
  5591. box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5592. } else {
  5593. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5594. }
  5595. }
  5596. }
  5597. // Update, and calculate the left and right margins for the horizontal boxes
  5598. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5599. helpers.each(leftBoxes, function(box) {
  5600. totalLeftBoxesWidth += box.width;
  5601. });
  5602. helpers.each(rightBoxes, function(box) {
  5603. totalRightBoxesWidth += box.width;
  5604. });
  5605. // Set the Left and Right margins for the horizontal boxes
  5606. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  5607. // Figure out how much margin is on the top and bottom of the vertical boxes
  5608. helpers.each(topBoxes, function(box) {
  5609. totalTopBoxesHeight += box.height;
  5610. });
  5611. helpers.each(bottomBoxes, function(box) {
  5612. totalBottomBoxesHeight += box.height;
  5613. });
  5614. function finalFitVerticalBox(box) {
  5615. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
  5616. return minSize.box === box;
  5617. });
  5618. var scaleMargin = {
  5619. left: 0,
  5620. right: 0,
  5621. top: totalTopBoxesHeight,
  5622. bottom: totalBottomBoxesHeight
  5623. };
  5624. if (minBoxSize) {
  5625. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5626. }
  5627. }
  5628. // Let the left layout know the final margin
  5629. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  5630. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  5631. totalLeftBoxesWidth = leftPadding;
  5632. totalRightBoxesWidth = rightPadding;
  5633. totalTopBoxesHeight = topPadding;
  5634. totalBottomBoxesHeight = bottomPadding;
  5635. helpers.each(leftBoxes, function(box) {
  5636. totalLeftBoxesWidth += box.width;
  5637. });
  5638. helpers.each(rightBoxes, function(box) {
  5639. totalRightBoxesWidth += box.width;
  5640. });
  5641. helpers.each(topBoxes, function(box) {
  5642. totalTopBoxesHeight += box.height;
  5643. });
  5644. helpers.each(bottomBoxes, function(box) {
  5645. totalBottomBoxesHeight += box.height;
  5646. });
  5647. // We may be adding some padding to account for rotated x axis labels
  5648. var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
  5649. totalLeftBoxesWidth += leftPaddingAddition;
  5650. totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
  5651. var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
  5652. totalTopBoxesHeight += topPaddingAddition;
  5653. totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
  5654. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  5655. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  5656. // without calling `fit` again
  5657. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  5658. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  5659. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  5660. helpers.each(leftBoxes, function(box) {
  5661. box.height = newMaxChartAreaHeight;
  5662. });
  5663. helpers.each(rightBoxes, function(box) {
  5664. box.height = newMaxChartAreaHeight;
  5665. });
  5666. helpers.each(topBoxes, function(box) {
  5667. if (!box.options.fullWidth) {
  5668. box.width = newMaxChartAreaWidth;
  5669. }
  5670. });
  5671. helpers.each(bottomBoxes, function(box) {
  5672. if (!box.options.fullWidth) {
  5673. box.width = newMaxChartAreaWidth;
  5674. }
  5675. });
  5676. maxChartAreaHeight = newMaxChartAreaHeight;
  5677. maxChartAreaWidth = newMaxChartAreaWidth;
  5678. }
  5679. // Step 7 - Position the boxes
  5680. var left = leftPadding + leftPaddingAddition;
  5681. var top = topPadding + topPaddingAddition;
  5682. function placeBox(box) {
  5683. if (box.isHorizontal()) {
  5684. box.left = box.options.fullWidth ? leftPadding : totalLeftBoxesWidth;
  5685. box.right = box.options.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5686. box.top = top;
  5687. box.bottom = top + box.height;
  5688. // Move to next point
  5689. top = box.bottom;
  5690. } else {
  5691. box.left = left;
  5692. box.right = left + box.width;
  5693. box.top = totalTopBoxesHeight;
  5694. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5695. // Move to next point
  5696. left = box.right;
  5697. }
  5698. }
  5699. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5700. // Account for chart width and height
  5701. left += maxChartAreaWidth;
  5702. top += maxChartAreaHeight;
  5703. helpers.each(rightBoxes, placeBox);
  5704. helpers.each(bottomBoxes, placeBox);
  5705. // Step 8
  5706. chartInstance.chartArea = {
  5707. left: totalLeftBoxesWidth,
  5708. top: totalTopBoxesHeight,
  5709. right: totalLeftBoxesWidth + maxChartAreaWidth,
  5710. bottom: totalTopBoxesHeight + maxChartAreaHeight
  5711. };
  5712. // Step 9
  5713. helpers.each(chartAreaBoxes, function(box) {
  5714. box.left = chartInstance.chartArea.left;
  5715. box.top = chartInstance.chartArea.top;
  5716. box.right = chartInstance.chartArea.right;
  5717. box.bottom = chartInstance.chartArea.bottom;
  5718. box.update(maxChartAreaWidth, maxChartAreaHeight);
  5719. });
  5720. }
  5721. };
  5722. };
  5723. },{}],30:[function(require,module,exports){
  5724. 'use strict';
  5725. module.exports = function(Chart) {
  5726. var helpers = Chart.helpers;
  5727. var noop = helpers.noop;
  5728. Chart.defaults.global.legend = {
  5729. display: true,
  5730. position: 'top',
  5731. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  5732. reverse: false,
  5733. // a callback that will handle
  5734. onClick: function(e, legendItem) {
  5735. var index = legendItem.datasetIndex;
  5736. var ci = this.chart;
  5737. var meta = ci.getDatasetMeta(index);
  5738. // See controller.isDatasetVisible comment
  5739. meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null;
  5740. // We hid a dataset ... rerender the chart
  5741. ci.update();
  5742. },
  5743. onHover: null,
  5744. labels: {
  5745. boxWidth: 40,
  5746. padding: 10,
  5747. // Generates labels shown in the legend
  5748. // Valid properties to return:
  5749. // text : text to display
  5750. // fillStyle : fill of coloured box
  5751. // strokeStyle: stroke of coloured box
  5752. // hidden : if this legend item refers to a hidden item
  5753. // lineCap : cap style for line
  5754. // lineDash
  5755. // lineDashOffset :
  5756. // lineJoin :
  5757. // lineWidth :
  5758. generateLabels: function(chart) {
  5759. var data = chart.data;
  5760. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  5761. return {
  5762. text: dataset.label,
  5763. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  5764. hidden: !chart.isDatasetVisible(i),
  5765. lineCap: dataset.borderCapStyle,
  5766. lineDash: dataset.borderDash,
  5767. lineDashOffset: dataset.borderDashOffset,
  5768. lineJoin: dataset.borderJoinStyle,
  5769. lineWidth: dataset.borderWidth,
  5770. strokeStyle: dataset.borderColor,
  5771. pointStyle: dataset.pointStyle,
  5772. // Below is extra data used for toggling the datasets
  5773. datasetIndex: i
  5774. };
  5775. }, this) : [];
  5776. }
  5777. }
  5778. };
  5779. /**
  5780. * Helper function to get the box width based on the usePointStyle option
  5781. * @param labelopts {Object} the label options on the legend
  5782. * @param fontSize {Number} the label font size
  5783. * @return {Number} width of the color box area
  5784. */
  5785. function getBoxWidth(labelOpts, fontSize) {
  5786. return labelOpts.usePointStyle ?
  5787. fontSize * Math.SQRT2 :
  5788. labelOpts.boxWidth;
  5789. }
  5790. Chart.Legend = Chart.Element.extend({
  5791. initialize: function(config) {
  5792. helpers.extend(this, config);
  5793. // Contains hit boxes for each dataset (in dataset order)
  5794. this.legendHitBoxes = [];
  5795. // Are we in doughnut mode which has a different data type
  5796. this.doughnutMode = false;
  5797. },
  5798. // These methods are ordered by lifecycle. Utilities then follow.
  5799. // Any function defined here is inherited by all legend types.
  5800. // Any function can be extended by the legend type
  5801. beforeUpdate: noop,
  5802. update: function(maxWidth, maxHeight, margins) {
  5803. var me = this;
  5804. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  5805. me.beforeUpdate();
  5806. // Absorb the master measurements
  5807. me.maxWidth = maxWidth;
  5808. me.maxHeight = maxHeight;
  5809. me.margins = margins;
  5810. // Dimensions
  5811. me.beforeSetDimensions();
  5812. me.setDimensions();
  5813. me.afterSetDimensions();
  5814. // Labels
  5815. me.beforeBuildLabels();
  5816. me.buildLabels();
  5817. me.afterBuildLabels();
  5818. // Fit
  5819. me.beforeFit();
  5820. me.fit();
  5821. me.afterFit();
  5822. //
  5823. me.afterUpdate();
  5824. return me.minSize;
  5825. },
  5826. afterUpdate: noop,
  5827. //
  5828. beforeSetDimensions: noop,
  5829. setDimensions: function() {
  5830. var me = this;
  5831. // Set the unconstrained dimension before label rotation
  5832. if (me.isHorizontal()) {
  5833. // Reset position before calculating rotation
  5834. me.width = me.maxWidth;
  5835. me.left = 0;
  5836. me.right = me.width;
  5837. } else {
  5838. me.height = me.maxHeight;
  5839. // Reset position before calculating rotation
  5840. me.top = 0;
  5841. me.bottom = me.height;
  5842. }
  5843. // Reset padding
  5844. me.paddingLeft = 0;
  5845. me.paddingTop = 0;
  5846. me.paddingRight = 0;
  5847. me.paddingBottom = 0;
  5848. // Reset minSize
  5849. me.minSize = {
  5850. width: 0,
  5851. height: 0
  5852. };
  5853. },
  5854. afterSetDimensions: noop,
  5855. //
  5856. beforeBuildLabels: noop,
  5857. buildLabels: function() {
  5858. var me = this;
  5859. var labelOpts = me.options.labels;
  5860. var legendItems = labelOpts.generateLabels.call(me, me.chart);
  5861. if (labelOpts.filter) {
  5862. legendItems = legendItems.filter(function(item) {
  5863. return labelOpts.filter(item, me.chart.data);
  5864. });
  5865. }
  5866. if (me.options.reverse) {
  5867. legendItems.reverse();
  5868. }
  5869. me.legendItems = legendItems;
  5870. },
  5871. afterBuildLabels: noop,
  5872. //
  5873. beforeFit: noop,
  5874. fit: function() {
  5875. var me = this;
  5876. var opts = me.options;
  5877. var labelOpts = opts.labels;
  5878. var display = opts.display;
  5879. var ctx = me.ctx;
  5880. var globalDefault = Chart.defaults.global,
  5881. itemOrDefault = helpers.getValueOrDefault,
  5882. fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
  5883. fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
  5884. fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
  5885. labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  5886. // Reset hit boxes
  5887. var hitboxes = me.legendHitBoxes = [];
  5888. var minSize = me.minSize;
  5889. var isHorizontal = me.isHorizontal();
  5890. if (isHorizontal) {
  5891. minSize.width = me.maxWidth; // fill all the width
  5892. minSize.height = display ? 10 : 0;
  5893. } else {
  5894. minSize.width = display ? 10 : 0;
  5895. minSize.height = me.maxHeight; // fill all the height
  5896. }
  5897. // Increase sizes here
  5898. if (display) {
  5899. ctx.font = labelFont;
  5900. if (isHorizontal) {
  5901. // Labels
  5902. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  5903. var lineWidths = me.lineWidths = [0];
  5904. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  5905. ctx.textAlign = 'left';
  5906. ctx.textBaseline = 'top';
  5907. helpers.each(me.legendItems, function(legendItem, i) {
  5908. var boxWidth = getBoxWidth(labelOpts, fontSize);
  5909. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  5910. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  5911. totalHeight += fontSize + (labelOpts.padding);
  5912. lineWidths[lineWidths.length] = me.left;
  5913. }
  5914. // Store the hitbox width and height here. Final position will be updated in `draw`
  5915. hitboxes[i] = {
  5916. left: 0,
  5917. top: 0,
  5918. width: width,
  5919. height: fontSize
  5920. };
  5921. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  5922. });
  5923. minSize.height += totalHeight;
  5924. } else {
  5925. var vPadding = labelOpts.padding;
  5926. var columnWidths = me.columnWidths = [];
  5927. var totalWidth = labelOpts.padding;
  5928. var currentColWidth = 0;
  5929. var currentColHeight = 0;
  5930. var itemHeight = fontSize + vPadding;
  5931. helpers.each(me.legendItems, function(legendItem, i) {
  5932. var boxWidth = getBoxWidth(labelOpts, fontSize);
  5933. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  5934. // If too tall, go to new column
  5935. if (currentColHeight + itemHeight > minSize.height) {
  5936. totalWidth += currentColWidth + labelOpts.padding;
  5937. columnWidths.push(currentColWidth); // previous column width
  5938. currentColWidth = 0;
  5939. currentColHeight = 0;
  5940. }
  5941. // Get max width
  5942. currentColWidth = Math.max(currentColWidth, itemWidth);
  5943. currentColHeight += itemHeight;
  5944. // Store the hitbox width and height here. Final position will be updated in `draw`
  5945. hitboxes[i] = {
  5946. left: 0,
  5947. top: 0,
  5948. width: itemWidth,
  5949. height: fontSize
  5950. };
  5951. });
  5952. totalWidth += currentColWidth;
  5953. columnWidths.push(currentColWidth);
  5954. minSize.width += totalWidth;
  5955. }
  5956. }
  5957. me.width = minSize.width;
  5958. me.height = minSize.height;
  5959. },
  5960. afterFit: noop,
  5961. // Shared Methods
  5962. isHorizontal: function() {
  5963. return this.options.position === 'top' || this.options.position === 'bottom';
  5964. },
  5965. // Actually draw the legend on the canvas
  5966. draw: function() {
  5967. var me = this;
  5968. var opts = me.options;
  5969. var labelOpts = opts.labels;
  5970. var globalDefault = Chart.defaults.global,
  5971. lineDefault = globalDefault.elements.line,
  5972. legendWidth = me.width,
  5973. lineWidths = me.lineWidths;
  5974. if (opts.display) {
  5975. var ctx = me.ctx,
  5976. cursor,
  5977. itemOrDefault = helpers.getValueOrDefault,
  5978. fontColor = itemOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor),
  5979. fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
  5980. fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
  5981. fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
  5982. labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  5983. // Canvas setup
  5984. ctx.textAlign = 'left';
  5985. ctx.textBaseline = 'top';
  5986. ctx.lineWidth = 0.5;
  5987. ctx.strokeStyle = fontColor; // for strikethrough effect
  5988. ctx.fillStyle = fontColor; // render in correct colour
  5989. ctx.font = labelFont;
  5990. var boxWidth = getBoxWidth(labelOpts, fontSize),
  5991. hitboxes = me.legendHitBoxes;
  5992. // current position
  5993. var drawLegendBox = function(x, y, legendItem) {
  5994. if (isNaN(boxWidth) || boxWidth <= 0) {
  5995. return;
  5996. }
  5997. // Set the ctx for the box
  5998. ctx.save();
  5999. ctx.fillStyle = itemOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  6000. ctx.lineCap = itemOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  6001. ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  6002. ctx.lineJoin = itemOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  6003. ctx.lineWidth = itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  6004. ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  6005. var isLineWidthZero = (itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  6006. if (ctx.setLineDash) {
  6007. // IE 9 and 10 do not support line dash
  6008. ctx.setLineDash(itemOrDefault(legendItem.lineDash, lineDefault.borderDash));
  6009. }
  6010. if (opts.labels && opts.labels.usePointStyle) {
  6011. // Recalculate x and y for drawPoint() because its expecting
  6012. // x and y to be center of figure (instead of top left)
  6013. var radius = fontSize * Math.SQRT2 / 2;
  6014. var offSet = radius / Math.SQRT2;
  6015. var centerX = x + offSet;
  6016. var centerY = y + offSet;
  6017. // Draw pointStyle as legend symbol
  6018. Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  6019. } else {
  6020. // Draw box as legend symbol
  6021. if (!isLineWidthZero) {
  6022. ctx.strokeRect(x, y, boxWidth, fontSize);
  6023. }
  6024. ctx.fillRect(x, y, boxWidth, fontSize);
  6025. }
  6026. ctx.restore();
  6027. };
  6028. var fillText = function(x, y, legendItem, textWidth) {
  6029. ctx.fillText(legendItem.text, boxWidth + (fontSize / 2) + x, y);
  6030. if (legendItem.hidden) {
  6031. // Strikethrough the text if hidden
  6032. ctx.beginPath();
  6033. ctx.lineWidth = 2;
  6034. ctx.moveTo(boxWidth + (fontSize / 2) + x, y + (fontSize / 2));
  6035. ctx.lineTo(boxWidth + (fontSize / 2) + x + textWidth, y + (fontSize / 2));
  6036. ctx.stroke();
  6037. }
  6038. };
  6039. // Horizontal
  6040. var isHorizontal = me.isHorizontal();
  6041. if (isHorizontal) {
  6042. cursor = {
  6043. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  6044. y: me.top + labelOpts.padding,
  6045. line: 0
  6046. };
  6047. } else {
  6048. cursor = {
  6049. x: me.left + labelOpts.padding,
  6050. y: me.top + labelOpts.padding,
  6051. line: 0
  6052. };
  6053. }
  6054. var itemHeight = fontSize + labelOpts.padding;
  6055. helpers.each(me.legendItems, function(legendItem, i) {
  6056. var textWidth = ctx.measureText(legendItem.text).width,
  6057. width = boxWidth + (fontSize / 2) + textWidth,
  6058. x = cursor.x,
  6059. y = cursor.y;
  6060. if (isHorizontal) {
  6061. if (x + width >= legendWidth) {
  6062. y = cursor.y += itemHeight;
  6063. cursor.line++;
  6064. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  6065. }
  6066. } else if (y + itemHeight > me.bottom) {
  6067. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  6068. y = cursor.y = me.top + labelOpts.padding;
  6069. cursor.line++;
  6070. }
  6071. drawLegendBox(x, y, legendItem);
  6072. hitboxes[i].left = x;
  6073. hitboxes[i].top = y;
  6074. // Fill the actual label
  6075. fillText(x, y, legendItem, textWidth);
  6076. if (isHorizontal) {
  6077. cursor.x += width + (labelOpts.padding);
  6078. } else {
  6079. cursor.y += itemHeight;
  6080. }
  6081. });
  6082. }
  6083. },
  6084. /**
  6085. * Handle an event
  6086. * @private
  6087. * @param {IEvent} event - The event to handle
  6088. * @return {Boolean} true if a change occured
  6089. */
  6090. handleEvent: function(e) {
  6091. var me = this;
  6092. var opts = me.options;
  6093. var type = e.type === 'mouseup' ? 'click' : e.type;
  6094. var changed = false;
  6095. if (type === 'mousemove') {
  6096. if (!opts.onHover) {
  6097. return;
  6098. }
  6099. } else if (type === 'click') {
  6100. if (!opts.onClick) {
  6101. return;
  6102. }
  6103. } else {
  6104. return;
  6105. }
  6106. // Chart event already has relative position in it
  6107. var x = e.x,
  6108. y = e.y;
  6109. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  6110. // See if we are touching one of the dataset boxes
  6111. var lh = me.legendHitBoxes;
  6112. for (var i = 0; i < lh.length; ++i) {
  6113. var hitBox = lh[i];
  6114. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  6115. // Touching an element
  6116. if (type === 'click') {
  6117. // use e.native for backwards compatibility
  6118. opts.onClick.call(me, e.native, me.legendItems[i]);
  6119. changed = true;
  6120. break;
  6121. } else if (type === 'mousemove') {
  6122. // use e.native for backwards compatibility
  6123. opts.onHover.call(me, e.native, me.legendItems[i]);
  6124. changed = true;
  6125. break;
  6126. }
  6127. }
  6128. }
  6129. }
  6130. return changed;
  6131. }
  6132. });
  6133. function createNewLegendAndAttach(chartInstance, legendOpts) {
  6134. var legend = new Chart.Legend({
  6135. ctx: chartInstance.chart.ctx,
  6136. options: legendOpts,
  6137. chart: chartInstance
  6138. });
  6139. chartInstance.legend = legend;
  6140. Chart.layoutService.addBox(chartInstance, legend);
  6141. }
  6142. // Register the legend plugin
  6143. Chart.plugins.register({
  6144. beforeInit: function(chartInstance) {
  6145. var legendOpts = chartInstance.options.legend;
  6146. if (legendOpts) {
  6147. createNewLegendAndAttach(chartInstance, legendOpts);
  6148. }
  6149. },
  6150. beforeUpdate: function(chartInstance) {
  6151. var legendOpts = chartInstance.options.legend;
  6152. if (legendOpts) {
  6153. legendOpts = helpers.configMerge(Chart.defaults.global.legend, legendOpts);
  6154. if (chartInstance.legend) {
  6155. chartInstance.legend.options = legendOpts;
  6156. } else {
  6157. createNewLegendAndAttach(chartInstance, legendOpts);
  6158. }
  6159. } else {
  6160. Chart.layoutService.removeBox(chartInstance, chartInstance.legend);
  6161. delete chartInstance.legend;
  6162. }
  6163. },
  6164. afterEvent: function(chartInstance, e) {
  6165. var legend = chartInstance.legend;
  6166. if (legend) {
  6167. legend.handleEvent(e);
  6168. }
  6169. }
  6170. });
  6171. };
  6172. },{}],31:[function(require,module,exports){
  6173. 'use strict';
  6174. module.exports = function(Chart) {
  6175. var helpers = Chart.helpers;
  6176. Chart.defaults.global.plugins = {};
  6177. /**
  6178. * The plugin service singleton
  6179. * @namespace Chart.plugins
  6180. * @since 2.1.0
  6181. */
  6182. Chart.plugins = {
  6183. /**
  6184. * Globally registered plugins.
  6185. * @private
  6186. */
  6187. _plugins: [],
  6188. /**
  6189. * This identifier is used to invalidate the descriptors cache attached to each chart
  6190. * when a global plugin is registered or unregistered. In this case, the cache ID is
  6191. * incremented and descriptors are regenerated during following API calls.
  6192. * @private
  6193. */
  6194. _cacheId: 0,
  6195. /**
  6196. * Registers the given plugin(s) if not already registered.
  6197. * @param {Array|Object} plugins plugin instance(s).
  6198. */
  6199. register: function(plugins) {
  6200. var p = this._plugins;
  6201. ([]).concat(plugins).forEach(function(plugin) {
  6202. if (p.indexOf(plugin) === -1) {
  6203. p.push(plugin);
  6204. }
  6205. });
  6206. this._cacheId++;
  6207. },
  6208. /**
  6209. * Unregisters the given plugin(s) only if registered.
  6210. * @param {Array|Object} plugins plugin instance(s).
  6211. */
  6212. unregister: function(plugins) {
  6213. var p = this._plugins;
  6214. ([]).concat(plugins).forEach(function(plugin) {
  6215. var idx = p.indexOf(plugin);
  6216. if (idx !== -1) {
  6217. p.splice(idx, 1);
  6218. }
  6219. });
  6220. this._cacheId++;
  6221. },
  6222. /**
  6223. * Remove all registered plugins.
  6224. * @since 2.1.5
  6225. */
  6226. clear: function() {
  6227. this._plugins = [];
  6228. this._cacheId++;
  6229. },
  6230. /**
  6231. * Returns the number of registered plugins?
  6232. * @returns {Number}
  6233. * @since 2.1.5
  6234. */
  6235. count: function() {
  6236. return this._plugins.length;
  6237. },
  6238. /**
  6239. * Returns all registered plugin instances.
  6240. * @returns {Array} array of plugin objects.
  6241. * @since 2.1.5
  6242. */
  6243. getAll: function() {
  6244. return this._plugins;
  6245. },
  6246. /**
  6247. * Calls enabled plugins for `chart` on the specified hook and with the given args.
  6248. * This method immediately returns as soon as a plugin explicitly returns false. The
  6249. * returned value can be used, for instance, to interrupt the current action.
  6250. * @param {Object} chart - The chart instance for which plugins should be called.
  6251. * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
  6252. * @param {Array} [args] - Extra arguments to apply to the hook call.
  6253. * @returns {Boolean} false if any of the plugins return false, else returns true.
  6254. */
  6255. notify: function(chart, hook, args) {
  6256. var descriptors = this.descriptors(chart);
  6257. var ilen = descriptors.length;
  6258. var i, descriptor, plugin, params, method;
  6259. for (i=0; i<ilen; ++i) {
  6260. descriptor = descriptors[i];
  6261. plugin = descriptor.plugin;
  6262. method = plugin[hook];
  6263. if (typeof method === 'function') {
  6264. params = [chart].concat(args || []);
  6265. params.push(descriptor.options);
  6266. if (method.apply(plugin, params) === false) {
  6267. return false;
  6268. }
  6269. }
  6270. }
  6271. return true;
  6272. },
  6273. /**
  6274. * Returns descriptors of enabled plugins for the given chart.
  6275. * @returns {Array} [{ plugin, options }]
  6276. * @private
  6277. */
  6278. descriptors: function(chart) {
  6279. var cache = chart._plugins || (chart._plugins = {});
  6280. if (cache.id === this._cacheId) {
  6281. return cache.descriptors;
  6282. }
  6283. var plugins = [];
  6284. var descriptors = [];
  6285. var config = (chart && chart.config) || {};
  6286. var defaults = Chart.defaults.global.plugins;
  6287. var options = (config.options && config.options.plugins) || {};
  6288. this._plugins.concat(config.plugins || []).forEach(function(plugin) {
  6289. var idx = plugins.indexOf(plugin);
  6290. if (idx !== -1) {
  6291. return;
  6292. }
  6293. var id = plugin.id;
  6294. var opts = options[id];
  6295. if (opts === false) {
  6296. return;
  6297. }
  6298. if (opts === true) {
  6299. opts = helpers.clone(defaults[id]);
  6300. }
  6301. plugins.push(plugin);
  6302. descriptors.push({
  6303. plugin: plugin,
  6304. options: opts || {}
  6305. });
  6306. });
  6307. cache.descriptors = descriptors;
  6308. cache.id = this._cacheId;
  6309. return descriptors;
  6310. }
  6311. };
  6312. /**
  6313. * Plugin extension hooks.
  6314. * @interface IPlugin
  6315. * @since 2.1.0
  6316. */
  6317. /**
  6318. * @method IPlugin#beforeInit
  6319. * @desc Called before initializing `chart`.
  6320. * @param {Chart.Controller} chart - The chart instance.
  6321. * @param {Object} options - The plugin options.
  6322. */
  6323. /**
  6324. * @method IPlugin#afterInit
  6325. * @desc Called after `chart` has been initialized and before the first update.
  6326. * @param {Chart.Controller} chart - The chart instance.
  6327. * @param {Object} options - The plugin options.
  6328. */
  6329. /**
  6330. * @method IPlugin#beforeUpdate
  6331. * @desc Called before updating `chart`. If any plugin returns `false`, the update
  6332. * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
  6333. * @param {Chart.Controller} chart - The chart instance.
  6334. * @param {Object} options - The plugin options.
  6335. * @returns {Boolean} `false` to cancel the chart update.
  6336. */
  6337. /**
  6338. * @method IPlugin#afterUpdate
  6339. * @desc Called after `chart` has been updated and before rendering. Note that this
  6340. * hook will not be called if the chart update has been previously cancelled.
  6341. * @param {Chart.Controller} chart - The chart instance.
  6342. * @param {Object} options - The plugin options.
  6343. */
  6344. /**
  6345. * @method IPlugin#beforeDatasetsUpdate
  6346. * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  6347. * the datasets update is cancelled until another `update` is triggered.
  6348. * @param {Chart.Controller} chart - The chart instance.
  6349. * @param {Object} options - The plugin options.
  6350. * @returns {Boolean} false to cancel the datasets update.
  6351. * @since version 2.1.5
  6352. */
  6353. /**
  6354. * @method IPlugin#afterDatasetsUpdate
  6355. * @desc Called after the `chart` datasets have been updated. Note that this hook
  6356. * will not be called if the datasets update has been previously cancelled.
  6357. * @param {Chart.Controller} chart - The chart instance.
  6358. * @param {Object} options - The plugin options.
  6359. * @since version 2.1.5
  6360. */
  6361. /**
  6362. * @method IPlugin#beforeLayout
  6363. * @desc Called before laying out `chart`. If any plugin returns `false`,
  6364. * the layout update is cancelled until another `update` is triggered.
  6365. * @param {Chart.Controller} chart - The chart instance.
  6366. * @param {Object} options - The plugin options.
  6367. * @returns {Boolean} `false` to cancel the chart layout.
  6368. */
  6369. /**
  6370. * @method IPlugin#afterLayout
  6371. * @desc Called after the `chart` has been layed out. Note that this hook will not
  6372. * be called if the layout update has been previously cancelled.
  6373. * @param {Chart.Controller} chart - The chart instance.
  6374. * @param {Object} options - The plugin options.
  6375. */
  6376. /**
  6377. * @method IPlugin#beforeRender
  6378. * @desc Called before rendering `chart`. If any plugin returns `false`,
  6379. * the rendering is cancelled until another `render` is triggered.
  6380. * @param {Chart.Controller} chart - The chart instance.
  6381. * @param {Object} options - The plugin options.
  6382. * @returns {Boolean} `false` to cancel the chart rendering.
  6383. */
  6384. /**
  6385. * @method IPlugin#afterRender
  6386. * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  6387. * that this hook will not be called if the rendering has been previously cancelled.
  6388. * @param {Chart.Controller} chart - The chart instance.
  6389. * @param {Object} options - The plugin options.
  6390. */
  6391. /**
  6392. * @method IPlugin#beforeDraw
  6393. * @desc Called before drawing `chart` at every animation frame specified by the given
  6394. * easing value. If any plugin returns `false`, the frame drawing is cancelled until
  6395. * another `render` is triggered.
  6396. * @param {Chart.Controller} chart - The chart instance.
  6397. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6398. * @param {Object} options - The plugin options.
  6399. * @returns {Boolean} `false` to cancel the chart drawing.
  6400. */
  6401. /**
  6402. * @method IPlugin#afterDraw
  6403. * @desc Called after the `chart` has been drawn for the specific easing value. Note
  6404. * that this hook will not be called if the drawing has been previously cancelled.
  6405. * @param {Chart.Controller} chart - The chart instance.
  6406. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6407. * @param {Object} options - The plugin options.
  6408. */
  6409. /**
  6410. * @method IPlugin#beforeDatasetsDraw
  6411. * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  6412. * the datasets drawing is cancelled until another `render` is triggered.
  6413. * @param {Chart.Controller} chart - The chart instance.
  6414. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6415. * @param {Object} options - The plugin options.
  6416. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  6417. */
  6418. /**
  6419. * @method IPlugin#afterDatasetsDraw
  6420. * @desc Called after the `chart` datasets have been drawn. Note that this hook
  6421. * will not be called if the datasets drawing has been previously cancelled.
  6422. * @param {Chart.Controller} chart - The chart instance.
  6423. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6424. * @param {Object} options - The plugin options.
  6425. */
  6426. /**
  6427. * @method IPlugin#beforeEvent
  6428. * @desc Called before processing the specified `event`. If any plugin returns `false`,
  6429. * the event will be discarded.
  6430. * @param {Chart.Controller} chart - The chart instance.
  6431. * @param {IEvent} event - The event object.
  6432. * @param {Object} options - The plugin options.
  6433. */
  6434. /**
  6435. * @method IPlugin#afterEvent
  6436. * @desc Called after the `event` has been consumed. Note that this hook
  6437. * will not be called if the `event` has been previously discarded.
  6438. * @param {Chart.Controller} chart - The chart instance.
  6439. * @param {IEvent} event - The event object.
  6440. * @param {Object} options - The plugin options.
  6441. */
  6442. /**
  6443. * @method IPlugin#resize
  6444. * @desc Called after the chart as been resized.
  6445. * @param {Chart.Controller} chart - The chart instance.
  6446. * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
  6447. * @param {Object} options - The plugin options.
  6448. */
  6449. /**
  6450. * @method IPlugin#destroy
  6451. * @desc Called after the chart as been destroyed.
  6452. * @param {Chart.Controller} chart - The chart instance.
  6453. * @param {Object} options - The plugin options.
  6454. */
  6455. /**
  6456. * Provided for backward compatibility, use Chart.plugins instead
  6457. * @namespace Chart.pluginService
  6458. * @deprecated since version 2.1.5
  6459. * @todo remove at version 3
  6460. * @private
  6461. */
  6462. Chart.pluginService = Chart.plugins;
  6463. /**
  6464. * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
  6465. * effect, instead simply create/register plugins via plain JavaScript objects.
  6466. * @interface Chart.PluginBase
  6467. * @deprecated since version 2.5.0
  6468. * @todo remove at version 3
  6469. * @private
  6470. */
  6471. Chart.PluginBase = helpers.inherits({});
  6472. };
  6473. },{}],32:[function(require,module,exports){
  6474. 'use strict';
  6475. module.exports = function(Chart) {
  6476. var helpers = Chart.helpers;
  6477. Chart.defaults.scale = {
  6478. display: true,
  6479. position: 'left',
  6480. // grid line settings
  6481. gridLines: {
  6482. display: true,
  6483. color: 'rgba(0, 0, 0, 0.1)',
  6484. lineWidth: 1,
  6485. drawBorder: true,
  6486. drawOnChartArea: true,
  6487. drawTicks: true,
  6488. tickMarkLength: 10,
  6489. zeroLineWidth: 1,
  6490. zeroLineColor: 'rgba(0,0,0,0.25)',
  6491. offsetGridLines: false,
  6492. borderDash: [],
  6493. borderDashOffset: 0.0
  6494. },
  6495. // scale label
  6496. scaleLabel: {
  6497. // actual label
  6498. labelString: '',
  6499. // display property
  6500. display: false
  6501. },
  6502. // label settings
  6503. ticks: {
  6504. beginAtZero: false,
  6505. minRotation: 0,
  6506. maxRotation: 50,
  6507. mirror: false,
  6508. padding: 0,
  6509. reverse: false,
  6510. display: true,
  6511. autoSkip: true,
  6512. autoSkipPadding: 0,
  6513. labelOffset: 0,
  6514. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  6515. callback: Chart.Ticks.formatters.values
  6516. }
  6517. };
  6518. function computeTextSize(context, tick, font) {
  6519. return helpers.isArray(tick) ?
  6520. helpers.longestText(context, font, tick) :
  6521. context.measureText(tick).width;
  6522. }
  6523. function parseFontOptions(options) {
  6524. var getValueOrDefault = helpers.getValueOrDefault;
  6525. var globalDefaults = Chart.defaults.global;
  6526. var size = getValueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
  6527. var style = getValueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
  6528. var family = getValueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
  6529. return {
  6530. size: size,
  6531. style: style,
  6532. family: family,
  6533. font: helpers.fontString(size, style, family)
  6534. };
  6535. }
  6536. Chart.Scale = Chart.Element.extend({
  6537. /**
  6538. * Get the padding needed for the scale
  6539. * @method getPadding
  6540. * @private
  6541. * @returns {Padding} the necessary padding
  6542. */
  6543. getPadding: function() {
  6544. var me = this;
  6545. return {
  6546. left: me.paddingLeft || 0,
  6547. top: me.paddingTop || 0,
  6548. right: me.paddingRight || 0,
  6549. bottom: me.paddingBottom || 0
  6550. };
  6551. },
  6552. // These methods are ordered by lifecyle. Utilities then follow.
  6553. // Any function defined here is inherited by all scale types.
  6554. // Any function can be extended by the scale type
  6555. beforeUpdate: function() {
  6556. helpers.callCallback(this.options.beforeUpdate, [this]);
  6557. },
  6558. update: function(maxWidth, maxHeight, margins) {
  6559. var me = this;
  6560. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6561. me.beforeUpdate();
  6562. // Absorb the master measurements
  6563. me.maxWidth = maxWidth;
  6564. me.maxHeight = maxHeight;
  6565. me.margins = helpers.extend({
  6566. left: 0,
  6567. right: 0,
  6568. top: 0,
  6569. bottom: 0
  6570. }, margins);
  6571. me.longestTextCache = me.longestTextCache || {};
  6572. // Dimensions
  6573. me.beforeSetDimensions();
  6574. me.setDimensions();
  6575. me.afterSetDimensions();
  6576. // Data min/max
  6577. me.beforeDataLimits();
  6578. me.determineDataLimits();
  6579. me.afterDataLimits();
  6580. // Ticks
  6581. me.beforeBuildTicks();
  6582. me.buildTicks();
  6583. me.afterBuildTicks();
  6584. me.beforeTickToLabelConversion();
  6585. me.convertTicksToLabels();
  6586. me.afterTickToLabelConversion();
  6587. // Tick Rotation
  6588. me.beforeCalculateTickRotation();
  6589. me.calculateTickRotation();
  6590. me.afterCalculateTickRotation();
  6591. // Fit
  6592. me.beforeFit();
  6593. me.fit();
  6594. me.afterFit();
  6595. //
  6596. me.afterUpdate();
  6597. return me.minSize;
  6598. },
  6599. afterUpdate: function() {
  6600. helpers.callCallback(this.options.afterUpdate, [this]);
  6601. },
  6602. //
  6603. beforeSetDimensions: function() {
  6604. helpers.callCallback(this.options.beforeSetDimensions, [this]);
  6605. },
  6606. setDimensions: function() {
  6607. var me = this;
  6608. // Set the unconstrained dimension before label rotation
  6609. if (me.isHorizontal()) {
  6610. // Reset position before calculating rotation
  6611. me.width = me.maxWidth;
  6612. me.left = 0;
  6613. me.right = me.width;
  6614. } else {
  6615. me.height = me.maxHeight;
  6616. // Reset position before calculating rotation
  6617. me.top = 0;
  6618. me.bottom = me.height;
  6619. }
  6620. // Reset padding
  6621. me.paddingLeft = 0;
  6622. me.paddingTop = 0;
  6623. me.paddingRight = 0;
  6624. me.paddingBottom = 0;
  6625. },
  6626. afterSetDimensions: function() {
  6627. helpers.callCallback(this.options.afterSetDimensions, [this]);
  6628. },
  6629. // Data limits
  6630. beforeDataLimits: function() {
  6631. helpers.callCallback(this.options.beforeDataLimits, [this]);
  6632. },
  6633. determineDataLimits: helpers.noop,
  6634. afterDataLimits: function() {
  6635. helpers.callCallback(this.options.afterDataLimits, [this]);
  6636. },
  6637. //
  6638. beforeBuildTicks: function() {
  6639. helpers.callCallback(this.options.beforeBuildTicks, [this]);
  6640. },
  6641. buildTicks: helpers.noop,
  6642. afterBuildTicks: function() {
  6643. helpers.callCallback(this.options.afterBuildTicks, [this]);
  6644. },
  6645. beforeTickToLabelConversion: function() {
  6646. helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
  6647. },
  6648. convertTicksToLabels: function() {
  6649. var me = this;
  6650. // Convert ticks to strings
  6651. var tickOpts = me.options.ticks;
  6652. me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback);
  6653. },
  6654. afterTickToLabelConversion: function() {
  6655. helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
  6656. },
  6657. //
  6658. beforeCalculateTickRotation: function() {
  6659. helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
  6660. },
  6661. calculateTickRotation: function() {
  6662. var me = this;
  6663. var context = me.ctx;
  6664. var tickOpts = me.options.ticks;
  6665. // Get the width of each grid by calculating the difference
  6666. // between x offsets between 0 and 1.
  6667. var tickFont = parseFontOptions(tickOpts);
  6668. context.font = tickFont.font;
  6669. var labelRotation = tickOpts.minRotation || 0;
  6670. if (me.options.display && me.isHorizontal()) {
  6671. var originalLabelWidth = helpers.longestText(context, tickFont.font, me.ticks, me.longestTextCache);
  6672. var labelWidth = originalLabelWidth;
  6673. var cosRotation;
  6674. var sinRotation;
  6675. // Allow 3 pixels x2 padding either side for label readability
  6676. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6677. // Max label rotation can be set or default to 90 - also act as a loop counter
  6678. while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
  6679. var angleRadians = helpers.toRadians(labelRotation);
  6680. cosRotation = Math.cos(angleRadians);
  6681. sinRotation = Math.sin(angleRadians);
  6682. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6683. // go back one step
  6684. labelRotation--;
  6685. break;
  6686. }
  6687. labelRotation++;
  6688. labelWidth = cosRotation * originalLabelWidth;
  6689. }
  6690. }
  6691. me.labelRotation = labelRotation;
  6692. },
  6693. afterCalculateTickRotation: function() {
  6694. helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
  6695. },
  6696. //
  6697. beforeFit: function() {
  6698. helpers.callCallback(this.options.beforeFit, [this]);
  6699. },
  6700. fit: function() {
  6701. var me = this;
  6702. // Reset
  6703. var minSize = me.minSize = {
  6704. width: 0,
  6705. height: 0
  6706. };
  6707. var opts = me.options;
  6708. var tickOpts = opts.ticks;
  6709. var scaleLabelOpts = opts.scaleLabel;
  6710. var gridLineOpts = opts.gridLines;
  6711. var display = opts.display;
  6712. var isHorizontal = me.isHorizontal();
  6713. var tickFont = parseFontOptions(tickOpts);
  6714. var scaleLabelFontSize = parseFontOptions(scaleLabelOpts).size * 1.5;
  6715. var tickMarkLength = opts.gridLines.tickMarkLength;
  6716. // Width
  6717. if (isHorizontal) {
  6718. // subtract the margins to line up with the chartArea if we are a full width scale
  6719. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6720. } else {
  6721. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6722. }
  6723. // height
  6724. if (isHorizontal) {
  6725. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6726. } else {
  6727. minSize.height = me.maxHeight; // fill all the height
  6728. }
  6729. // Are we showing a title for the scale?
  6730. if (scaleLabelOpts.display && display) {
  6731. if (isHorizontal) {
  6732. minSize.height += scaleLabelFontSize;
  6733. } else {
  6734. minSize.width += scaleLabelFontSize;
  6735. }
  6736. }
  6737. // Don't bother fitting the ticks if we are not showing them
  6738. if (tickOpts.display && display) {
  6739. var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, me.ticks, me.longestTextCache);
  6740. var tallestLabelHeightInLines = helpers.numberOfLabelLines(me.ticks);
  6741. var lineSpace = tickFont.size * 0.5;
  6742. if (isHorizontal) {
  6743. // A horizontal axis is more constrained by the height.
  6744. me.longestLabelWidth = largestTextWidth;
  6745. var angleRadians = helpers.toRadians(me.labelRotation);
  6746. var cosRotation = Math.cos(angleRadians);
  6747. var sinRotation = Math.sin(angleRadians);
  6748. // TODO - improve this calculation
  6749. var labelHeight = (sinRotation * largestTextWidth)
  6750. + (tickFont.size * tallestLabelHeightInLines)
  6751. + (lineSpace * tallestLabelHeightInLines);
  6752. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
  6753. me.ctx.font = tickFont.font;
  6754. var firstTick = me.ticks[0];
  6755. var firstLabelWidth = computeTextSize(me.ctx, firstTick, tickFont.font);
  6756. var lastTick = me.ticks[me.ticks.length - 1];
  6757. var lastLabelWidth = computeTextSize(me.ctx, lastTick, tickFont.font);
  6758. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
  6759. // by the font height
  6760. if (me.labelRotation !== 0) {
  6761. me.paddingLeft = opts.position === 'bottom'? (cosRotation * firstLabelWidth) + 3: (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
  6762. me.paddingRight = opts.position === 'bottom'? (cosRotation * lineSpace) + 3: (cosRotation * lastLabelWidth) + 3;
  6763. } else {
  6764. me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6765. me.paddingRight = lastLabelWidth / 2 + 3;
  6766. }
  6767. } else {
  6768. // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
  6769. // Account for padding
  6770. if (tickOpts.mirror) {
  6771. largestTextWidth = 0;
  6772. } else {
  6773. largestTextWidth += me.options.ticks.padding;
  6774. }
  6775. minSize.width += largestTextWidth;
  6776. me.paddingTop = tickFont.size / 2;
  6777. me.paddingBottom = tickFont.size / 2;
  6778. }
  6779. }
  6780. me.handleMargins();
  6781. me.width = minSize.width;
  6782. me.height = minSize.height;
  6783. },
  6784. /**
  6785. * Handle margins and padding interactions
  6786. * @private
  6787. */
  6788. handleMargins: function() {
  6789. var me = this;
  6790. if (me.margins) {
  6791. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6792. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6793. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6794. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6795. }
  6796. },
  6797. afterFit: function() {
  6798. helpers.callCallback(this.options.afterFit, [this]);
  6799. },
  6800. // Shared Methods
  6801. isHorizontal: function() {
  6802. return this.options.position === 'top' || this.options.position === 'bottom';
  6803. },
  6804. isFullWidth: function() {
  6805. return (this.options.fullWidth);
  6806. },
  6807. // 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
  6808. getRightValue: function(rawValue) {
  6809. // Null and undefined values first
  6810. if (rawValue === null || typeof(rawValue) === 'undefined') {
  6811. return NaN;
  6812. }
  6813. // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
  6814. if (typeof(rawValue) === 'number' && !isFinite(rawValue)) {
  6815. return NaN;
  6816. }
  6817. // If it is in fact an object, dive in one more level
  6818. if (typeof(rawValue) === 'object') {
  6819. if ((rawValue instanceof Date) || (rawValue.isValid)) {
  6820. return rawValue;
  6821. }
  6822. return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
  6823. }
  6824. // Value is good, return it
  6825. return rawValue;
  6826. },
  6827. // Used to get the value to display in the tooltip for the data at the given index
  6828. // function getLabelForIndex(index, datasetIndex)
  6829. getLabelForIndex: helpers.noop,
  6830. // Used to get data value locations. Value can either be an index or a numerical value
  6831. getPixelForValue: helpers.noop,
  6832. // Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6833. getValueForPixel: helpers.noop,
  6834. // Used for tick location, should
  6835. getPixelForTick: function(index, includeOffset) {
  6836. var me = this;
  6837. if (me.isHorizontal()) {
  6838. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6839. var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  6840. var pixel = (tickWidth * index) + me.paddingLeft;
  6841. if (includeOffset) {
  6842. pixel += tickWidth / 2;
  6843. }
  6844. var finalVal = me.left + Math.round(pixel);
  6845. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6846. return finalVal;
  6847. }
  6848. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6849. return me.top + (index * (innerHeight / (me.ticks.length - 1)));
  6850. },
  6851. // Utility for getting the pixel location of a percentage of scale
  6852. getPixelForDecimal: function(decimal /* , includeOffset*/) {
  6853. var me = this;
  6854. if (me.isHorizontal()) {
  6855. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6856. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6857. var finalVal = me.left + Math.round(valueOffset);
  6858. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6859. return finalVal;
  6860. }
  6861. return me.top + (decimal * me.height);
  6862. },
  6863. getBasePixel: function() {
  6864. return this.getPixelForValue(this.getBaseValue());
  6865. },
  6866. getBaseValue: function() {
  6867. var me = this;
  6868. var min = me.min;
  6869. var max = me.max;
  6870. return me.beginAtZero ? 0:
  6871. min < 0 && max < 0? max :
  6872. min > 0 && max > 0? min :
  6873. 0;
  6874. },
  6875. // Actually draw the scale on the canvas
  6876. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6877. draw: function(chartArea) {
  6878. var me = this;
  6879. var options = me.options;
  6880. if (!options.display) {
  6881. return;
  6882. }
  6883. var context = me.ctx;
  6884. var globalDefaults = Chart.defaults.global;
  6885. var optionTicks = options.ticks;
  6886. var gridLines = options.gridLines;
  6887. var scaleLabel = options.scaleLabel;
  6888. var isRotated = me.labelRotation !== 0;
  6889. var skipRatio;
  6890. var useAutoskipper = optionTicks.autoSkip;
  6891. var isHorizontal = me.isHorizontal();
  6892. // figure out the maximum number of gridlines to show
  6893. var maxTicks;
  6894. if (optionTicks.maxTicksLimit) {
  6895. maxTicks = optionTicks.maxTicksLimit;
  6896. }
  6897. var tickFontColor = helpers.getValueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6898. var tickFont = parseFontOptions(optionTicks);
  6899. var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
  6900. var borderDash = helpers.getValueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6901. var borderDashOffset = helpers.getValueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6902. var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6903. var scaleLabelFont = parseFontOptions(scaleLabel);
  6904. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6905. var cosRotation = Math.cos(labelRotationRadians);
  6906. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6907. // Make sure we draw text in the correct color and font
  6908. context.fillStyle = tickFontColor;
  6909. var itemsToDraw = [];
  6910. if (isHorizontal) {
  6911. skipRatio = false;
  6912. // Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
  6913. // See #2584
  6914. if (isRotated) {
  6915. longestRotatedLabel /= 2;
  6916. }
  6917. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) {
  6918. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight)));
  6919. }
  6920. // if they defined a max number of optionTicks,
  6921. // increase skipRatio until that number is met
  6922. if (maxTicks && me.ticks.length > maxTicks) {
  6923. while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) {
  6924. if (!skipRatio) {
  6925. skipRatio = 1;
  6926. }
  6927. skipRatio += 1;
  6928. }
  6929. }
  6930. if (!useAutoskipper) {
  6931. skipRatio = false;
  6932. }
  6933. }
  6934. var xTickStart = options.position === 'right' ? me.left : me.right - tl;
  6935. var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
  6936. var yTickStart = options.position === 'bottom' ? me.top : me.bottom - tl;
  6937. var yTickEnd = options.position === 'bottom' ? me.top + tl : me.bottom;
  6938. helpers.each(me.ticks, function(label, index) {
  6939. // If the callback returned a null or undefined value, do not draw this line
  6940. if (label === undefined || label === null) {
  6941. return;
  6942. }
  6943. var isLastTick = me.ticks.length === index + 1;
  6944. // Since we always show the last tick,we need may need to hide the last shown one before
  6945. var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
  6946. if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
  6947. return;
  6948. }
  6949. var lineWidth, lineColor;
  6950. if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
  6951. // Draw the first index specially
  6952. lineWidth = gridLines.zeroLineWidth;
  6953. lineColor = gridLines.zeroLineColor;
  6954. } else {
  6955. lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
  6956. lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
  6957. }
  6958. // Common properties
  6959. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6960. var textAlign = 'middle';
  6961. var textBaseline = 'middle';
  6962. if (isHorizontal) {
  6963. if (options.position === 'bottom') {
  6964. // bottom
  6965. textBaseline = !isRotated? 'top':'middle';
  6966. textAlign = !isRotated? 'center': 'right';
  6967. labelY = me.top + tl;
  6968. } else {
  6969. // top
  6970. textBaseline = !isRotated? 'bottom':'middle';
  6971. textAlign = !isRotated? 'center': 'left';
  6972. labelY = me.bottom - tl;
  6973. }
  6974. var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines
  6975. labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6976. tx1 = tx2 = x1 = x2 = xLineValue;
  6977. ty1 = yTickStart;
  6978. ty2 = yTickEnd;
  6979. y1 = chartArea.top;
  6980. y2 = chartArea.bottom;
  6981. } else {
  6982. var isLeft = options.position === 'left';
  6983. var tickPadding = optionTicks.padding;
  6984. var labelXOffset;
  6985. if (optionTicks.mirror) {
  6986. textAlign = isLeft ? 'left' : 'right';
  6987. labelXOffset = tickPadding;
  6988. } else {
  6989. textAlign = isLeft ? 'right' : 'left';
  6990. labelXOffset = tl + tickPadding;
  6991. }
  6992. labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
  6993. var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
  6994. yLineValue += helpers.aliasPixel(lineWidth);
  6995. labelY = me.getPixelForTick(index, gridLines.offsetGridLines);
  6996. tx1 = xTickStart;
  6997. tx2 = xTickEnd;
  6998. x1 = chartArea.left;
  6999. x2 = chartArea.right;
  7000. ty1 = ty2 = y1 = y2 = yLineValue;
  7001. }
  7002. itemsToDraw.push({
  7003. tx1: tx1,
  7004. ty1: ty1,
  7005. tx2: tx2,
  7006. ty2: ty2,
  7007. x1: x1,
  7008. y1: y1,
  7009. x2: x2,
  7010. y2: y2,
  7011. labelX: labelX,
  7012. labelY: labelY,
  7013. glWidth: lineWidth,
  7014. glColor: lineColor,
  7015. glBorderDash: borderDash,
  7016. glBorderDashOffset: borderDashOffset,
  7017. rotation: -1 * labelRotationRadians,
  7018. label: label,
  7019. textBaseline: textBaseline,
  7020. textAlign: textAlign
  7021. });
  7022. });
  7023. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  7024. helpers.each(itemsToDraw, function(itemToDraw) {
  7025. if (gridLines.display) {
  7026. context.save();
  7027. context.lineWidth = itemToDraw.glWidth;
  7028. context.strokeStyle = itemToDraw.glColor;
  7029. if (context.setLineDash) {
  7030. context.setLineDash(itemToDraw.glBorderDash);
  7031. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  7032. }
  7033. context.beginPath();
  7034. if (gridLines.drawTicks) {
  7035. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  7036. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  7037. }
  7038. if (gridLines.drawOnChartArea) {
  7039. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  7040. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  7041. }
  7042. context.stroke();
  7043. context.restore();
  7044. }
  7045. if (optionTicks.display) {
  7046. context.save();
  7047. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  7048. context.rotate(itemToDraw.rotation);
  7049. context.font = tickFont.font;
  7050. context.textBaseline = itemToDraw.textBaseline;
  7051. context.textAlign = itemToDraw.textAlign;
  7052. var label = itemToDraw.label;
  7053. if (helpers.isArray(label)) {
  7054. for (var i = 0, y = 0; i < label.length; ++i) {
  7055. // We just make sure the multiline element is a string here..
  7056. context.fillText('' + label[i], 0, y);
  7057. // apply same lineSpacing as calculated @ L#320
  7058. y += (tickFont.size * 1.5);
  7059. }
  7060. } else {
  7061. context.fillText(label, 0, 0);
  7062. }
  7063. context.restore();
  7064. }
  7065. });
  7066. if (scaleLabel.display) {
  7067. // Draw the scale label
  7068. var scaleLabelX;
  7069. var scaleLabelY;
  7070. var rotation = 0;
  7071. if (isHorizontal) {
  7072. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  7073. scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFont.size / 2) : me.top + (scaleLabelFont.size / 2);
  7074. } else {
  7075. var isLeft = options.position === 'left';
  7076. scaleLabelX = isLeft ? me.left + (scaleLabelFont.size / 2) : me.right - (scaleLabelFont.size / 2);
  7077. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  7078. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  7079. }
  7080. context.save();
  7081. context.translate(scaleLabelX, scaleLabelY);
  7082. context.rotate(rotation);
  7083. context.textAlign = 'center';
  7084. context.textBaseline = 'middle';
  7085. context.fillStyle = scaleLabelFontColor; // render in correct colour
  7086. context.font = scaleLabelFont.font;
  7087. context.fillText(scaleLabel.labelString, 0, 0);
  7088. context.restore();
  7089. }
  7090. if (gridLines.drawBorder) {
  7091. // Draw the line at the edge of the axis
  7092. context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0);
  7093. context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0);
  7094. var x1 = me.left,
  7095. x2 = me.right,
  7096. y1 = me.top,
  7097. y2 = me.bottom;
  7098. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  7099. if (isHorizontal) {
  7100. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  7101. y1 += aliasPixel;
  7102. y2 += aliasPixel;
  7103. } else {
  7104. x1 = x2 = options.position === 'left' ? me.right : me.left;
  7105. x1 += aliasPixel;
  7106. x2 += aliasPixel;
  7107. }
  7108. context.beginPath();
  7109. context.moveTo(x1, y1);
  7110. context.lineTo(x2, y2);
  7111. context.stroke();
  7112. }
  7113. }
  7114. });
  7115. };
  7116. },{}],33:[function(require,module,exports){
  7117. 'use strict';
  7118. module.exports = function(Chart) {
  7119. var helpers = Chart.helpers;
  7120. Chart.scaleService = {
  7121. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  7122. // use the new chart options to grab the correct scale
  7123. constructors: {},
  7124. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  7125. // old browsers
  7126. // Scale config defaults
  7127. defaults: {},
  7128. registerScaleType: function(type, scaleConstructor, defaults) {
  7129. this.constructors[type] = scaleConstructor;
  7130. this.defaults[type] = helpers.clone(defaults);
  7131. },
  7132. getScaleConstructor: function(type) {
  7133. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  7134. },
  7135. getScaleDefaults: function(type) {
  7136. // Return the scale defaults merged with the global settings so that we always use the latest ones
  7137. return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
  7138. },
  7139. updateScaleDefaults: function(type, additions) {
  7140. var defaults = this.defaults;
  7141. if (defaults.hasOwnProperty(type)) {
  7142. defaults[type] = helpers.extend(defaults[type], additions);
  7143. }
  7144. },
  7145. addScalesToLayout: function(chartInstance) {
  7146. // Adds each scale to the chart.boxes array to be sized accordingly
  7147. helpers.each(chartInstance.scales, function(scale) {
  7148. Chart.layoutService.addBox(chartInstance, scale);
  7149. });
  7150. }
  7151. };
  7152. };
  7153. },{}],34:[function(require,module,exports){
  7154. 'use strict';
  7155. module.exports = function(Chart) {
  7156. var helpers = Chart.helpers;
  7157. /**
  7158. * Namespace to hold static tick generation functions
  7159. * @namespace Chart.Ticks
  7160. */
  7161. Chart.Ticks = {
  7162. /**
  7163. * Namespace to hold generators for different types of ticks
  7164. * @namespace Chart.Ticks.generators
  7165. */
  7166. generators: {
  7167. /**
  7168. * Interface for the options provided to the numeric tick generator
  7169. * @interface INumericTickGenerationOptions
  7170. */
  7171. /**
  7172. * The maximum number of ticks to display
  7173. * @name INumericTickGenerationOptions#maxTicks
  7174. * @type Number
  7175. */
  7176. /**
  7177. * The distance between each tick.
  7178. * @name INumericTickGenerationOptions#stepSize
  7179. * @type Number
  7180. * @optional
  7181. */
  7182. /**
  7183. * Forced minimum for the ticks. If not specified, the minimum of the data range is used to calculate the tick minimum
  7184. * @name INumericTickGenerationOptions#min
  7185. * @type Number
  7186. * @optional
  7187. */
  7188. /**
  7189. * The maximum value of the ticks. If not specified, the maximum of the data range is used to calculate the tick maximum
  7190. * @name INumericTickGenerationOptions#max
  7191. * @type Number
  7192. * @optional
  7193. */
  7194. /**
  7195. * Generate a set of linear ticks
  7196. * @method Chart.Ticks.generators.linear
  7197. * @param generationOptions {INumericTickGenerationOptions} the options used to generate the ticks
  7198. * @param dataRange {IRange} the range of the data
  7199. * @returns {Array<Number>} array of tick values
  7200. */
  7201. linear: function(generationOptions, dataRange) {
  7202. var ticks = [];
  7203. // To get a "nice" value for the tick spacing, we will use the appropriately named
  7204. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  7205. // for details.
  7206. var spacing;
  7207. if (generationOptions.stepSize && generationOptions.stepSize > 0) {
  7208. spacing = generationOptions.stepSize;
  7209. } else {
  7210. var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
  7211. spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
  7212. }
  7213. var niceMin = Math.floor(dataRange.min / spacing) * spacing;
  7214. var niceMax = Math.ceil(dataRange.max / spacing) * spacing;
  7215. // If min, max and stepSize is set and they make an evenly spaced scale use it.
  7216. if (generationOptions.min && generationOptions.max && generationOptions.stepSize) {
  7217. // If very close to our whole number, use it.
  7218. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
  7219. niceMin = generationOptions.min;
  7220. niceMax = generationOptions.max;
  7221. }
  7222. }
  7223. var numSpaces = (niceMax - niceMin) / spacing;
  7224. // If very close to our rounded value, use it.
  7225. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  7226. numSpaces = Math.round(numSpaces);
  7227. } else {
  7228. numSpaces = Math.ceil(numSpaces);
  7229. }
  7230. // Put the values into the ticks array
  7231. ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
  7232. for (var j = 1; j < numSpaces; ++j) {
  7233. ticks.push(niceMin + (j * spacing));
  7234. }
  7235. ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);
  7236. return ticks;
  7237. },
  7238. /**
  7239. * Generate a set of logarithmic ticks
  7240. * @method Chart.Ticks.generators.logarithmic
  7241. * @param generationOptions {INumericTickGenerationOptions} the options used to generate the ticks
  7242. * @param dataRange {IRange} the range of the data
  7243. * @returns {Array<Number>} array of tick values
  7244. */
  7245. logarithmic: function(generationOptions, dataRange) {
  7246. var ticks = [];
  7247. var getValueOrDefault = helpers.getValueOrDefault;
  7248. // Figure out what the max number of ticks we can support it is based on the size of
  7249. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  7250. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  7251. // the graph
  7252. var tickVal = getValueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
  7253. var endExp = Math.floor(helpers.log10(dataRange.max));
  7254. var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
  7255. var exp;
  7256. var significand;
  7257. if (tickVal === 0) {
  7258. exp = Math.floor(helpers.log10(dataRange.minNotZero));
  7259. significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
  7260. ticks.push(tickVal);
  7261. tickVal = significand * Math.pow(10, exp);
  7262. } else {
  7263. exp = Math.floor(helpers.log10(tickVal));
  7264. significand = Math.floor(tickVal / Math.pow(10, exp));
  7265. }
  7266. do {
  7267. ticks.push(tickVal);
  7268. ++significand;
  7269. if (significand === 10) {
  7270. significand = 1;
  7271. ++exp;
  7272. }
  7273. tickVal = significand * Math.pow(10, exp);
  7274. } while (exp < endExp || (exp === endExp && significand < endSignificand));
  7275. var lastTick = getValueOrDefault(generationOptions.max, tickVal);
  7276. ticks.push(lastTick);
  7277. return ticks;
  7278. }
  7279. },
  7280. /**
  7281. * Namespace to hold formatters for different types of ticks
  7282. * @namespace Chart.Ticks.formatters
  7283. */
  7284. formatters: {
  7285. /**
  7286. * Formatter for value labels
  7287. * @method Chart.Ticks.formatters.values
  7288. * @param value the value to display
  7289. * @return {String|Array} the label to display
  7290. */
  7291. values: function(value) {
  7292. return helpers.isArray(value) ? value : '' + value;
  7293. },
  7294. /**
  7295. * Formatter for linear numeric ticks
  7296. * @method Chart.Ticks.formatters.linear
  7297. * @param tickValue {Number} the value to be formatted
  7298. * @param index {Number} the position of the tickValue parameter in the ticks array
  7299. * @param ticks {Array<Number>} the list of ticks being converted
  7300. * @return {String} string representation of the tickValue parameter
  7301. */
  7302. linear: function(tickValue, index, ticks) {
  7303. // If we have lots of ticks, don't use the ones
  7304. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  7305. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  7306. if (Math.abs(delta) > 1) {
  7307. if (tickValue !== Math.floor(tickValue)) {
  7308. // not an integer
  7309. delta = tickValue - Math.floor(tickValue);
  7310. }
  7311. }
  7312. var logDelta = helpers.log10(Math.abs(delta));
  7313. var tickString = '';
  7314. if (tickValue !== 0) {
  7315. var numDecimal = -1 * Math.floor(logDelta);
  7316. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  7317. tickString = tickValue.toFixed(numDecimal);
  7318. } else {
  7319. tickString = '0'; // never show decimal places for 0
  7320. }
  7321. return tickString;
  7322. },
  7323. logarithmic: function(tickValue, index, ticks) {
  7324. var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
  7325. if (tickValue === 0) {
  7326. return '0';
  7327. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
  7328. return tickValue.toExponential();
  7329. }
  7330. return '';
  7331. }
  7332. }
  7333. };
  7334. };
  7335. },{}],35:[function(require,module,exports){
  7336. 'use strict';
  7337. module.exports = function(Chart) {
  7338. var helpers = Chart.helpers;
  7339. Chart.defaults.global.title = {
  7340. display: false,
  7341. position: 'top',
  7342. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  7343. fontStyle: 'bold',
  7344. padding: 10,
  7345. // actual title
  7346. text: ''
  7347. };
  7348. var noop = helpers.noop;
  7349. Chart.Title = Chart.Element.extend({
  7350. initialize: function(config) {
  7351. var me = this;
  7352. helpers.extend(me, config);
  7353. // Contains hit boxes for each dataset (in dataset order)
  7354. me.legendHitBoxes = [];
  7355. },
  7356. // These methods are ordered by lifecycle. Utilities then follow.
  7357. beforeUpdate: noop,
  7358. update: function(maxWidth, maxHeight, margins) {
  7359. var me = this;
  7360. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  7361. me.beforeUpdate();
  7362. // Absorb the master measurements
  7363. me.maxWidth = maxWidth;
  7364. me.maxHeight = maxHeight;
  7365. me.margins = margins;
  7366. // Dimensions
  7367. me.beforeSetDimensions();
  7368. me.setDimensions();
  7369. me.afterSetDimensions();
  7370. // Labels
  7371. me.beforeBuildLabels();
  7372. me.buildLabels();
  7373. me.afterBuildLabels();
  7374. // Fit
  7375. me.beforeFit();
  7376. me.fit();
  7377. me.afterFit();
  7378. //
  7379. me.afterUpdate();
  7380. return me.minSize;
  7381. },
  7382. afterUpdate: noop,
  7383. //
  7384. beforeSetDimensions: noop,
  7385. setDimensions: function() {
  7386. var me = this;
  7387. // Set the unconstrained dimension before label rotation
  7388. if (me.isHorizontal()) {
  7389. // Reset position before calculating rotation
  7390. me.width = me.maxWidth;
  7391. me.left = 0;
  7392. me.right = me.width;
  7393. } else {
  7394. me.height = me.maxHeight;
  7395. // Reset position before calculating rotation
  7396. me.top = 0;
  7397. me.bottom = me.height;
  7398. }
  7399. // Reset padding
  7400. me.paddingLeft = 0;
  7401. me.paddingTop = 0;
  7402. me.paddingRight = 0;
  7403. me.paddingBottom = 0;
  7404. // Reset minSize
  7405. me.minSize = {
  7406. width: 0,
  7407. height: 0
  7408. };
  7409. },
  7410. afterSetDimensions: noop,
  7411. //
  7412. beforeBuildLabels: noop,
  7413. buildLabels: noop,
  7414. afterBuildLabels: noop,
  7415. //
  7416. beforeFit: noop,
  7417. fit: function() {
  7418. var me = this,
  7419. valueOrDefault = helpers.getValueOrDefault,
  7420. opts = me.options,
  7421. globalDefaults = Chart.defaults.global,
  7422. display = opts.display,
  7423. fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  7424. minSize = me.minSize;
  7425. if (me.isHorizontal()) {
  7426. minSize.width = me.maxWidth; // fill all the width
  7427. minSize.height = display ? fontSize + (opts.padding * 2) : 0;
  7428. } else {
  7429. minSize.width = display ? fontSize + (opts.padding * 2) : 0;
  7430. minSize.height = me.maxHeight; // fill all the height
  7431. }
  7432. me.width = minSize.width;
  7433. me.height = minSize.height;
  7434. },
  7435. afterFit: noop,
  7436. // Shared Methods
  7437. isHorizontal: function() {
  7438. var pos = this.options.position;
  7439. return pos === 'top' || pos === 'bottom';
  7440. },
  7441. // Actually draw the title block on the canvas
  7442. draw: function() {
  7443. var me = this,
  7444. ctx = me.ctx,
  7445. valueOrDefault = helpers.getValueOrDefault,
  7446. opts = me.options,
  7447. globalDefaults = Chart.defaults.global;
  7448. if (opts.display) {
  7449. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  7450. fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle),
  7451. fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily),
  7452. titleFont = helpers.fontString(fontSize, fontStyle, fontFamily),
  7453. rotation = 0,
  7454. titleX,
  7455. titleY,
  7456. top = me.top,
  7457. left = me.left,
  7458. bottom = me.bottom,
  7459. right = me.right,
  7460. maxWidth;
  7461. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  7462. ctx.font = titleFont;
  7463. // Horizontal
  7464. if (me.isHorizontal()) {
  7465. titleX = left + ((right - left) / 2); // midpoint of the width
  7466. titleY = top + ((bottom - top) / 2); // midpoint of the height
  7467. maxWidth = right - left;
  7468. } else {
  7469. titleX = opts.position === 'left' ? left + (fontSize / 2) : right - (fontSize / 2);
  7470. titleY = top + ((bottom - top) / 2);
  7471. maxWidth = bottom - top;
  7472. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  7473. }
  7474. ctx.save();
  7475. ctx.translate(titleX, titleY);
  7476. ctx.rotate(rotation);
  7477. ctx.textAlign = 'center';
  7478. ctx.textBaseline = 'middle';
  7479. ctx.fillText(opts.text, 0, 0, maxWidth);
  7480. ctx.restore();
  7481. }
  7482. }
  7483. });
  7484. function createNewTitleBlockAndAttach(chartInstance, titleOpts) {
  7485. var title = new Chart.Title({
  7486. ctx: chartInstance.chart.ctx,
  7487. options: titleOpts,
  7488. chart: chartInstance
  7489. });
  7490. chartInstance.titleBlock = title;
  7491. Chart.layoutService.addBox(chartInstance, title);
  7492. }
  7493. // Register the title plugin
  7494. Chart.plugins.register({
  7495. beforeInit: function(chartInstance) {
  7496. var titleOpts = chartInstance.options.title;
  7497. if (titleOpts) {
  7498. createNewTitleBlockAndAttach(chartInstance, titleOpts);
  7499. }
  7500. },
  7501. beforeUpdate: function(chartInstance) {
  7502. var titleOpts = chartInstance.options.title;
  7503. if (titleOpts) {
  7504. titleOpts = helpers.configMerge(Chart.defaults.global.title, titleOpts);
  7505. if (chartInstance.titleBlock) {
  7506. chartInstance.titleBlock.options = titleOpts;
  7507. } else {
  7508. createNewTitleBlockAndAttach(chartInstance, titleOpts);
  7509. }
  7510. } else {
  7511. Chart.layoutService.removeBox(chartInstance, chartInstance.titleBlock);
  7512. delete chartInstance.titleBlock;
  7513. }
  7514. }
  7515. });
  7516. };
  7517. },{}],36:[function(require,module,exports){
  7518. 'use strict';
  7519. module.exports = function(Chart) {
  7520. var helpers = Chart.helpers;
  7521. /**
  7522. * Helper method to merge the opacity into a color
  7523. */
  7524. function mergeOpacity(colorString, opacity) {
  7525. var color = helpers.color(colorString);
  7526. return color.alpha(opacity * color.alpha()).rgbaString();
  7527. }
  7528. Chart.defaults.global.tooltips = {
  7529. enabled: true,
  7530. custom: null,
  7531. mode: 'nearest',
  7532. position: 'average',
  7533. intersect: true,
  7534. backgroundColor: 'rgba(0,0,0,0.8)',
  7535. titleFontStyle: 'bold',
  7536. titleSpacing: 2,
  7537. titleMarginBottom: 6,
  7538. titleFontColor: '#fff',
  7539. titleAlign: 'left',
  7540. bodySpacing: 2,
  7541. bodyFontColor: '#fff',
  7542. bodyAlign: 'left',
  7543. footerFontStyle: 'bold',
  7544. footerSpacing: 2,
  7545. footerMarginTop: 6,
  7546. footerFontColor: '#fff',
  7547. footerAlign: 'left',
  7548. yPadding: 6,
  7549. xPadding: 6,
  7550. caretSize: 5,
  7551. cornerRadius: 6,
  7552. multiKeyBackground: '#fff',
  7553. displayColors: true,
  7554. callbacks: {
  7555. // Args are: (tooltipItems, data)
  7556. beforeTitle: helpers.noop,
  7557. title: function(tooltipItems, data) {
  7558. // Pick first xLabel for now
  7559. var title = '';
  7560. var labels = data.labels;
  7561. var labelCount = labels ? labels.length : 0;
  7562. if (tooltipItems.length > 0) {
  7563. var item = tooltipItems[0];
  7564. if (item.xLabel) {
  7565. title = item.xLabel;
  7566. } else if (labelCount > 0 && item.index < labelCount) {
  7567. title = labels[item.index];
  7568. }
  7569. }
  7570. return title;
  7571. },
  7572. afterTitle: helpers.noop,
  7573. // Args are: (tooltipItems, data)
  7574. beforeBody: helpers.noop,
  7575. // Args are: (tooltipItem, data)
  7576. beforeLabel: helpers.noop,
  7577. label: function(tooltipItem, data) {
  7578. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  7579. return datasetLabel + ': ' + tooltipItem.yLabel;
  7580. },
  7581. labelColor: function(tooltipItem, chartInstance) {
  7582. var meta = chartInstance.getDatasetMeta(tooltipItem.datasetIndex);
  7583. var activeElement = meta.data[tooltipItem.index];
  7584. var view = activeElement._view;
  7585. return {
  7586. borderColor: view.borderColor,
  7587. backgroundColor: view.backgroundColor
  7588. };
  7589. },
  7590. afterLabel: helpers.noop,
  7591. // Args are: (tooltipItems, data)
  7592. afterBody: helpers.noop,
  7593. // Args are: (tooltipItems, data)
  7594. beforeFooter: helpers.noop,
  7595. footer: helpers.noop,
  7596. afterFooter: helpers.noop
  7597. }
  7598. };
  7599. // Helper to push or concat based on if the 2nd parameter is an array or not
  7600. function pushOrConcat(base, toPush) {
  7601. if (toPush) {
  7602. if (helpers.isArray(toPush)) {
  7603. // base = base.concat(toPush);
  7604. Array.prototype.push.apply(base, toPush);
  7605. } else {
  7606. base.push(toPush);
  7607. }
  7608. }
  7609. return base;
  7610. }
  7611. // Private helper to create a tooltip item model
  7612. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  7613. // @return : new tooltip item
  7614. function createTooltipItem(element) {
  7615. var xScale = element._xScale;
  7616. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  7617. var index = element._index,
  7618. datasetIndex = element._datasetIndex;
  7619. return {
  7620. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  7621. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  7622. index: index,
  7623. datasetIndex: datasetIndex,
  7624. x: element._model.x,
  7625. y: element._model.y
  7626. };
  7627. }
  7628. /**
  7629. * Helper to get the reset model for the tooltip
  7630. * @param tooltipOpts {Object} the tooltip options
  7631. */
  7632. function getBaseModel(tooltipOpts) {
  7633. var globalDefaults = Chart.defaults.global;
  7634. var getValueOrDefault = helpers.getValueOrDefault;
  7635. return {
  7636. // Positioning
  7637. xPadding: tooltipOpts.xPadding,
  7638. yPadding: tooltipOpts.yPadding,
  7639. xAlign: tooltipOpts.xAlign,
  7640. yAlign: tooltipOpts.yAlign,
  7641. // Body
  7642. bodyFontColor: tooltipOpts.bodyFontColor,
  7643. _bodyFontFamily: getValueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  7644. _bodyFontStyle: getValueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  7645. _bodyAlign: tooltipOpts.bodyAlign,
  7646. bodyFontSize: getValueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  7647. bodySpacing: tooltipOpts.bodySpacing,
  7648. // Title
  7649. titleFontColor: tooltipOpts.titleFontColor,
  7650. _titleFontFamily: getValueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  7651. _titleFontStyle: getValueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  7652. titleFontSize: getValueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  7653. _titleAlign: tooltipOpts.titleAlign,
  7654. titleSpacing: tooltipOpts.titleSpacing,
  7655. titleMarginBottom: tooltipOpts.titleMarginBottom,
  7656. // Footer
  7657. footerFontColor: tooltipOpts.footerFontColor,
  7658. _footerFontFamily: getValueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  7659. _footerFontStyle: getValueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  7660. footerFontSize: getValueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  7661. _footerAlign: tooltipOpts.footerAlign,
  7662. footerSpacing: tooltipOpts.footerSpacing,
  7663. footerMarginTop: tooltipOpts.footerMarginTop,
  7664. // Appearance
  7665. caretSize: tooltipOpts.caretSize,
  7666. cornerRadius: tooltipOpts.cornerRadius,
  7667. backgroundColor: tooltipOpts.backgroundColor,
  7668. opacity: 0,
  7669. legendColorBackground: tooltipOpts.multiKeyBackground,
  7670. displayColors: tooltipOpts.displayColors
  7671. };
  7672. }
  7673. /**
  7674. * Get the size of the tooltip
  7675. */
  7676. function getTooltipSize(tooltip, model) {
  7677. var ctx = tooltip._chart.ctx;
  7678. var height = model.yPadding * 2; // Tooltip Padding
  7679. var width = 0;
  7680. // Count of all lines in the body
  7681. var body = model.body;
  7682. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  7683. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7684. }, 0);
  7685. combinedBodyLength += model.beforeBody.length + model.afterBody.length;
  7686. var titleLineCount = model.title.length;
  7687. var footerLineCount = model.footer.length;
  7688. var titleFontSize = model.titleFontSize,
  7689. bodyFontSize = model.bodyFontSize,
  7690. footerFontSize = model.footerFontSize;
  7691. height += titleLineCount * titleFontSize; // Title Lines
  7692. height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
  7693. height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
  7694. height += combinedBodyLength * bodyFontSize; // Body Lines
  7695. height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
  7696. height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
  7697. height += footerLineCount * (footerFontSize); // Footer Lines
  7698. height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
  7699. // Title width
  7700. var widthPadding = 0;
  7701. var maxLineWidth = function(line) {
  7702. width = Math.max(width, ctx.measureText(line).width + widthPadding);
  7703. };
  7704. ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
  7705. helpers.each(model.title, maxLineWidth);
  7706. // Body width
  7707. ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
  7708. helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
  7709. // Body lines may include some extra width due to the color box
  7710. widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
  7711. helpers.each(body, function(bodyItem) {
  7712. helpers.each(bodyItem.before, maxLineWidth);
  7713. helpers.each(bodyItem.lines, maxLineWidth);
  7714. helpers.each(bodyItem.after, maxLineWidth);
  7715. });
  7716. // Reset back to 0
  7717. widthPadding = 0;
  7718. // Footer width
  7719. ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
  7720. helpers.each(model.footer, maxLineWidth);
  7721. // Add padding
  7722. width += 2 * model.xPadding;
  7723. return {
  7724. width: width,
  7725. height: height
  7726. };
  7727. }
  7728. /**
  7729. * Helper to get the alignment of a tooltip given the size
  7730. */
  7731. function determineAlignment(tooltip, size) {
  7732. var model = tooltip._model;
  7733. var chart = tooltip._chart;
  7734. var chartArea = tooltip._chartInstance.chartArea;
  7735. var xAlign = 'center';
  7736. var yAlign = 'center';
  7737. if (model.y < size.height) {
  7738. yAlign = 'top';
  7739. } else if (model.y > (chart.height - size.height)) {
  7740. yAlign = 'bottom';
  7741. }
  7742. var lf, rf; // functions to determine left, right alignment
  7743. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7744. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7745. var midX = (chartArea.left + chartArea.right) / 2;
  7746. var midY = (chartArea.top + chartArea.bottom) / 2;
  7747. if (yAlign === 'center') {
  7748. lf = function(x) {
  7749. return x <= midX;
  7750. };
  7751. rf = function(x) {
  7752. return x > midX;
  7753. };
  7754. } else {
  7755. lf = function(x) {
  7756. return x <= (size.width / 2);
  7757. };
  7758. rf = function(x) {
  7759. return x >= (chart.width - (size.width / 2));
  7760. };
  7761. }
  7762. olf = function(x) {
  7763. return x + size.width > chart.width;
  7764. };
  7765. orf = function(x) {
  7766. return x - size.width < 0;
  7767. };
  7768. yf = function(y) {
  7769. return y <= midY ? 'top' : 'bottom';
  7770. };
  7771. if (lf(model.x)) {
  7772. xAlign = 'left';
  7773. // Is tooltip too wide and goes over the right side of the chart.?
  7774. if (olf(model.x)) {
  7775. xAlign = 'center';
  7776. yAlign = yf(model.y);
  7777. }
  7778. } else if (rf(model.x)) {
  7779. xAlign = 'right';
  7780. // Is tooltip too wide and goes outside left edge of canvas?
  7781. if (orf(model.x)) {
  7782. xAlign = 'center';
  7783. yAlign = yf(model.y);
  7784. }
  7785. }
  7786. var opts = tooltip._options;
  7787. return {
  7788. xAlign: opts.xAlign ? opts.xAlign : xAlign,
  7789. yAlign: opts.yAlign ? opts.yAlign : yAlign
  7790. };
  7791. }
  7792. /**
  7793. * @Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
  7794. */
  7795. function getBackgroundPoint(vm, size, alignment) {
  7796. // Background Position
  7797. var x = vm.x;
  7798. var y = vm.y;
  7799. var caretSize = vm.caretSize,
  7800. caretPadding = vm.caretPadding,
  7801. cornerRadius = vm.cornerRadius,
  7802. xAlign = alignment.xAlign,
  7803. yAlign = alignment.yAlign,
  7804. paddingAndSize = caretSize + caretPadding,
  7805. radiusAndPadding = cornerRadius + caretPadding;
  7806. if (xAlign === 'right') {
  7807. x -= size.width;
  7808. } else if (xAlign === 'center') {
  7809. x -= (size.width / 2);
  7810. }
  7811. if (yAlign === 'top') {
  7812. y += paddingAndSize;
  7813. } else if (yAlign === 'bottom') {
  7814. y -= size.height + paddingAndSize;
  7815. } else {
  7816. y -= (size.height / 2);
  7817. }
  7818. if (yAlign === 'center') {
  7819. if (xAlign === 'left') {
  7820. x += paddingAndSize;
  7821. } else if (xAlign === 'right') {
  7822. x -= paddingAndSize;
  7823. }
  7824. } else if (xAlign === 'left') {
  7825. x -= radiusAndPadding;
  7826. } else if (xAlign === 'right') {
  7827. x += radiusAndPadding;
  7828. }
  7829. return {
  7830. x: x,
  7831. y: y
  7832. };
  7833. }
  7834. Chart.Tooltip = Chart.Element.extend({
  7835. initialize: function() {
  7836. this._model = getBaseModel(this._options);
  7837. },
  7838. // Get the title
  7839. // Args are: (tooltipItem, data)
  7840. getTitle: function() {
  7841. var me = this;
  7842. var opts = me._options;
  7843. var callbacks = opts.callbacks;
  7844. var beforeTitle = callbacks.beforeTitle.apply(me, arguments),
  7845. title = callbacks.title.apply(me, arguments),
  7846. afterTitle = callbacks.afterTitle.apply(me, arguments);
  7847. var lines = [];
  7848. lines = pushOrConcat(lines, beforeTitle);
  7849. lines = pushOrConcat(lines, title);
  7850. lines = pushOrConcat(lines, afterTitle);
  7851. return lines;
  7852. },
  7853. // Args are: (tooltipItem, data)
  7854. getBeforeBody: function() {
  7855. var lines = this._options.callbacks.beforeBody.apply(this, arguments);
  7856. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  7857. },
  7858. // Args are: (tooltipItem, data)
  7859. getBody: function(tooltipItems, data) {
  7860. var me = this;
  7861. var callbacks = me._options.callbacks;
  7862. var bodyItems = [];
  7863. helpers.each(tooltipItems, function(tooltipItem) {
  7864. var bodyItem = {
  7865. before: [],
  7866. lines: [],
  7867. after: []
  7868. };
  7869. pushOrConcat(bodyItem.before, callbacks.beforeLabel.call(me, tooltipItem, data));
  7870. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  7871. pushOrConcat(bodyItem.after, callbacks.afterLabel.call(me, tooltipItem, data));
  7872. bodyItems.push(bodyItem);
  7873. });
  7874. return bodyItems;
  7875. },
  7876. // Args are: (tooltipItem, data)
  7877. getAfterBody: function() {
  7878. var lines = this._options.callbacks.afterBody.apply(this, arguments);
  7879. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  7880. },
  7881. // Get the footer and beforeFooter and afterFooter lines
  7882. // Args are: (tooltipItem, data)
  7883. getFooter: function() {
  7884. var me = this;
  7885. var callbacks = me._options.callbacks;
  7886. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  7887. var footer = callbacks.footer.apply(me, arguments);
  7888. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  7889. var lines = [];
  7890. lines = pushOrConcat(lines, beforeFooter);
  7891. lines = pushOrConcat(lines, footer);
  7892. lines = pushOrConcat(lines, afterFooter);
  7893. return lines;
  7894. },
  7895. update: function(changed) {
  7896. var me = this;
  7897. var opts = me._options;
  7898. // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
  7899. // that does _view = _model if ease === 1. This causes the 2nd tooltip update to set properties in both the view and model at the same time
  7900. // which breaks any animations.
  7901. var existingModel = me._model;
  7902. var model = me._model = getBaseModel(opts);
  7903. var active = me._active;
  7904. var data = me._data;
  7905. var chartInstance = me._chartInstance;
  7906. // In the case where active.length === 0 we need to keep these at existing values for good animations
  7907. var alignment = {
  7908. xAlign: existingModel.xAlign,
  7909. yAlign: existingModel.yAlign
  7910. };
  7911. var backgroundPoint = {
  7912. x: existingModel.x,
  7913. y: existingModel.y
  7914. };
  7915. var tooltipSize = {
  7916. width: existingModel.width,
  7917. height: existingModel.height
  7918. };
  7919. var tooltipPosition = {
  7920. x: existingModel.caretX,
  7921. y: existingModel.caretY
  7922. };
  7923. var i, len;
  7924. if (active.length) {
  7925. model.opacity = 1;
  7926. var labelColors = [];
  7927. tooltipPosition = Chart.Tooltip.positioners[opts.position](active, me._eventPosition);
  7928. var tooltipItems = [];
  7929. for (i = 0, len = active.length; i < len; ++i) {
  7930. tooltipItems.push(createTooltipItem(active[i]));
  7931. }
  7932. // If the user provided a filter function, use it to modify the tooltip items
  7933. if (opts.filter) {
  7934. tooltipItems = tooltipItems.filter(function(a) {
  7935. return opts.filter(a, data);
  7936. });
  7937. }
  7938. // If the user provided a sorting function, use it to modify the tooltip items
  7939. if (opts.itemSort) {
  7940. tooltipItems = tooltipItems.sort(function(a, b) {
  7941. return opts.itemSort(a, b, data);
  7942. });
  7943. }
  7944. // Determine colors for boxes
  7945. helpers.each(tooltipItems, function(tooltipItem) {
  7946. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, chartInstance));
  7947. });
  7948. // Build the Text Lines
  7949. model.title = me.getTitle(tooltipItems, data);
  7950. model.beforeBody = me.getBeforeBody(tooltipItems, data);
  7951. model.body = me.getBody(tooltipItems, data);
  7952. model.afterBody = me.getAfterBody(tooltipItems, data);
  7953. model.footer = me.getFooter(tooltipItems, data);
  7954. // Initial positioning and colors
  7955. model.x = Math.round(tooltipPosition.x);
  7956. model.y = Math.round(tooltipPosition.y);
  7957. model.caretPadding = helpers.getValueOrDefault(tooltipPosition.padding, 2);
  7958. model.labelColors = labelColors;
  7959. // data points
  7960. model.dataPoints = tooltipItems;
  7961. // We need to determine alignment of the tooltip
  7962. tooltipSize = getTooltipSize(this, model);
  7963. alignment = determineAlignment(this, tooltipSize);
  7964. // Final Size and Position
  7965. backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment);
  7966. } else {
  7967. model.opacity = 0;
  7968. }
  7969. model.xAlign = alignment.xAlign;
  7970. model.yAlign = alignment.yAlign;
  7971. model.x = backgroundPoint.x;
  7972. model.y = backgroundPoint.y;
  7973. model.width = tooltipSize.width;
  7974. model.height = tooltipSize.height;
  7975. // Point where the caret on the tooltip points to
  7976. model.caretX = tooltipPosition.x;
  7977. model.caretY = tooltipPosition.y;
  7978. me._model = model;
  7979. if (changed && opts.custom) {
  7980. opts.custom.call(me, model);
  7981. }
  7982. return me;
  7983. },
  7984. drawCaret: function(tooltipPoint, size, opacity) {
  7985. var vm = this._view;
  7986. var ctx = this._chart.ctx;
  7987. var x1, x2, x3;
  7988. var y1, y2, y3;
  7989. var caretSize = vm.caretSize;
  7990. var cornerRadius = vm.cornerRadius;
  7991. var xAlign = vm.xAlign,
  7992. yAlign = vm.yAlign;
  7993. var ptX = tooltipPoint.x,
  7994. ptY = tooltipPoint.y;
  7995. var width = size.width,
  7996. height = size.height;
  7997. if (yAlign === 'center') {
  7998. // Left or right side
  7999. if (xAlign === 'left') {
  8000. x1 = ptX;
  8001. x2 = x1 - caretSize;
  8002. x3 = x1;
  8003. } else {
  8004. x1 = ptX + width;
  8005. x2 = x1 + caretSize;
  8006. x3 = x1;
  8007. }
  8008. y2 = ptY + (height / 2);
  8009. y1 = y2 - caretSize;
  8010. y3 = y2 + caretSize;
  8011. } else {
  8012. if (xAlign === 'left') {
  8013. x1 = ptX + cornerRadius;
  8014. x2 = x1 + caretSize;
  8015. x3 = x2 + caretSize;
  8016. } else if (xAlign === 'right') {
  8017. x1 = ptX + width - cornerRadius;
  8018. x2 = x1 - caretSize;
  8019. x3 = x2 - caretSize;
  8020. } else {
  8021. x2 = ptX + (width / 2);
  8022. x1 = x2 - caretSize;
  8023. x3 = x2 + caretSize;
  8024. }
  8025. if (yAlign === 'top') {
  8026. y1 = ptY;
  8027. y2 = y1 - caretSize;
  8028. y3 = y1;
  8029. } else {
  8030. y1 = ptY + height;
  8031. y2 = y1 + caretSize;
  8032. y3 = y1;
  8033. }
  8034. }
  8035. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  8036. ctx.beginPath();
  8037. ctx.moveTo(x1, y1);
  8038. ctx.lineTo(x2, y2);
  8039. ctx.lineTo(x3, y3);
  8040. ctx.closePath();
  8041. ctx.fill();
  8042. },
  8043. drawTitle: function(pt, vm, ctx, opacity) {
  8044. var title = vm.title;
  8045. if (title.length) {
  8046. ctx.textAlign = vm._titleAlign;
  8047. ctx.textBaseline = 'top';
  8048. var titleFontSize = vm.titleFontSize,
  8049. titleSpacing = vm.titleSpacing;
  8050. ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
  8051. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  8052. var i, len;
  8053. for (i = 0, len = title.length; i < len; ++i) {
  8054. ctx.fillText(title[i], pt.x, pt.y);
  8055. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  8056. if (i + 1 === title.length) {
  8057. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  8058. }
  8059. }
  8060. }
  8061. },
  8062. drawBody: function(pt, vm, ctx, opacity) {
  8063. var bodyFontSize = vm.bodyFontSize;
  8064. var bodySpacing = vm.bodySpacing;
  8065. var body = vm.body;
  8066. ctx.textAlign = vm._bodyAlign;
  8067. ctx.textBaseline = 'top';
  8068. var textColor = mergeOpacity(vm.bodyFontColor, opacity);
  8069. ctx.fillStyle = textColor;
  8070. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  8071. // Before Body
  8072. var xLinePadding = 0;
  8073. var fillLineOfText = function(line) {
  8074. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  8075. pt.y += bodyFontSize + bodySpacing;
  8076. };
  8077. // Before body lines
  8078. helpers.each(vm.beforeBody, fillLineOfText);
  8079. var drawColorBoxes = vm.displayColors;
  8080. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  8081. // Draw body lines now
  8082. helpers.each(body, function(bodyItem, i) {
  8083. helpers.each(bodyItem.before, fillLineOfText);
  8084. helpers.each(bodyItem.lines, function(line) {
  8085. // Draw Legend-like boxes if needed
  8086. if (drawColorBoxes) {
  8087. // Fill a white rect so that colours merge nicely if the opacity is < 1
  8088. ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
  8089. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  8090. // Border
  8091. ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
  8092. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  8093. // Inner square
  8094. ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
  8095. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  8096. ctx.fillStyle = textColor;
  8097. }
  8098. fillLineOfText(line);
  8099. });
  8100. helpers.each(bodyItem.after, fillLineOfText);
  8101. });
  8102. // Reset back to 0 for after body
  8103. xLinePadding = 0;
  8104. // After body lines
  8105. helpers.each(vm.afterBody, fillLineOfText);
  8106. pt.y -= bodySpacing; // Remove last body spacing
  8107. },
  8108. drawFooter: function(pt, vm, ctx, opacity) {
  8109. var footer = vm.footer;
  8110. if (footer.length) {
  8111. pt.y += vm.footerMarginTop;
  8112. ctx.textAlign = vm._footerAlign;
  8113. ctx.textBaseline = 'top';
  8114. ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
  8115. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  8116. helpers.each(footer, function(line) {
  8117. ctx.fillText(line, pt.x, pt.y);
  8118. pt.y += vm.footerFontSize + vm.footerSpacing;
  8119. });
  8120. }
  8121. },
  8122. drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
  8123. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  8124. helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
  8125. ctx.fill();
  8126. },
  8127. draw: function() {
  8128. var ctx = this._chart.ctx;
  8129. var vm = this._view;
  8130. if (vm.opacity === 0) {
  8131. return;
  8132. }
  8133. var tooltipSize = {
  8134. width: vm.width,
  8135. height: vm.height
  8136. };
  8137. var pt = {
  8138. x: vm.x,
  8139. y: vm.y
  8140. };
  8141. // IE11/Edge does not like very small opacities, so snap to 0
  8142. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  8143. if (this._options.enabled) {
  8144. // Draw Background
  8145. this.drawBackground(pt, vm, ctx, tooltipSize, opacity);
  8146. // Draw Caret
  8147. this.drawCaret(pt, tooltipSize, opacity);
  8148. // Draw Title, Body, and Footer
  8149. pt.x += vm.xPadding;
  8150. pt.y += vm.yPadding;
  8151. // Titles
  8152. this.drawTitle(pt, vm, ctx, opacity);
  8153. // Body
  8154. this.drawBody(pt, vm, ctx, opacity);
  8155. // Footer
  8156. this.drawFooter(pt, vm, ctx, opacity);
  8157. }
  8158. },
  8159. /**
  8160. * Handle an event
  8161. * @private
  8162. * @param {IEvent} event - The event to handle
  8163. * @returns {Boolean} true if the tooltip changed
  8164. */
  8165. handleEvent: function(e) {
  8166. var me = this;
  8167. var options = me._options;
  8168. var changed = false;
  8169. me._lastActive = me._lastActive || [];
  8170. // Find Active Elements for tooltips
  8171. if (e.type === 'mouseout') {
  8172. me._active = [];
  8173. } else {
  8174. me._active = me._chartInstance.getElementsAtEventForMode(e, options.mode, options);
  8175. }
  8176. // Remember Last Actives
  8177. changed = !helpers.arrayEquals(me._active, me._lastActive);
  8178. me._lastActive = me._active;
  8179. if (options.enabled || options.custom) {
  8180. me._eventPosition = {
  8181. x: e.x,
  8182. y: e.y
  8183. };
  8184. var model = me._model;
  8185. me.update(true);
  8186. me.pivot();
  8187. // See if our tooltip position changed
  8188. changed |= (model.x !== me._model.x) || (model.y !== me._model.y);
  8189. }
  8190. return changed;
  8191. }
  8192. });
  8193. /**
  8194. * @namespace Chart.Tooltip.positioners
  8195. */
  8196. Chart.Tooltip.positioners = {
  8197. /**
  8198. * Average mode places the tooltip at the average position of the elements shown
  8199. * @function Chart.Tooltip.positioners.average
  8200. * @param elements {ChartElement[]} the elements being displayed in the tooltip
  8201. * @returns {Point} tooltip position
  8202. */
  8203. average: function(elements) {
  8204. if (!elements.length) {
  8205. return false;
  8206. }
  8207. var i, len;
  8208. var x = 0;
  8209. var y = 0;
  8210. var count = 0;
  8211. for (i = 0, len = elements.length; i < len; ++i) {
  8212. var el = elements[i];
  8213. if (el && el.hasValue()) {
  8214. var pos = el.tooltipPosition();
  8215. x += pos.x;
  8216. y += pos.y;
  8217. ++count;
  8218. }
  8219. }
  8220. return {
  8221. x: Math.round(x / count),
  8222. y: Math.round(y / count)
  8223. };
  8224. },
  8225. /**
  8226. * Gets the tooltip position nearest of the item nearest to the event position
  8227. * @function Chart.Tooltip.positioners.nearest
  8228. * @param elements {Chart.Element[]} the tooltip elements
  8229. * @param eventPosition {Point} the position of the event in canvas coordinates
  8230. * @returns {Point} the tooltip position
  8231. */
  8232. nearest: function(elements, eventPosition) {
  8233. var x = eventPosition.x;
  8234. var y = eventPosition.y;
  8235. var nearestElement;
  8236. var minDistance = Number.POSITIVE_INFINITY;
  8237. var i, len;
  8238. for (i = 0, len = elements.length; i < len; ++i) {
  8239. var el = elements[i];
  8240. if (el && el.hasValue()) {
  8241. var center = el.getCenterPoint();
  8242. var d = helpers.distanceBetweenPoints(eventPosition, center);
  8243. if (d < minDistance) {
  8244. minDistance = d;
  8245. nearestElement = el;
  8246. }
  8247. }
  8248. }
  8249. if (nearestElement) {
  8250. var tp = nearestElement.tooltipPosition();
  8251. x = tp.x;
  8252. y = tp.y;
  8253. }
  8254. return {
  8255. x: x,
  8256. y: y
  8257. };
  8258. }
  8259. };
  8260. };
  8261. },{}],37:[function(require,module,exports){
  8262. 'use strict';
  8263. module.exports = function(Chart) {
  8264. var helpers = Chart.helpers,
  8265. globalOpts = Chart.defaults.global;
  8266. globalOpts.elements.arc = {
  8267. backgroundColor: globalOpts.defaultColor,
  8268. borderColor: '#fff',
  8269. borderWidth: 2
  8270. };
  8271. Chart.elements.Arc = Chart.Element.extend({
  8272. inLabelRange: function(mouseX) {
  8273. var vm = this._view;
  8274. if (vm) {
  8275. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  8276. }
  8277. return false;
  8278. },
  8279. inRange: function(chartX, chartY) {
  8280. var vm = this._view;
  8281. if (vm) {
  8282. var pointRelativePosition = helpers.getAngleFromPoint(vm, {
  8283. x: chartX,
  8284. y: chartY
  8285. }),
  8286. angle = pointRelativePosition.angle,
  8287. distance = pointRelativePosition.distance;
  8288. // Sanitise angle range
  8289. var startAngle = vm.startAngle;
  8290. var endAngle = vm.endAngle;
  8291. while (endAngle < startAngle) {
  8292. endAngle += 2.0 * Math.PI;
  8293. }
  8294. while (angle > endAngle) {
  8295. angle -= 2.0 * Math.PI;
  8296. }
  8297. while (angle < startAngle) {
  8298. angle += 2.0 * Math.PI;
  8299. }
  8300. // Check if within the range of the open/close angle
  8301. var betweenAngles = (angle >= startAngle && angle <= endAngle),
  8302. withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  8303. return (betweenAngles && withinRadius);
  8304. }
  8305. return false;
  8306. },
  8307. getCenterPoint: function() {
  8308. var vm = this._view;
  8309. var halfAngle = (vm.startAngle + vm.endAngle) / 2;
  8310. var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
  8311. return {
  8312. x: vm.x + Math.cos(halfAngle) * halfRadius,
  8313. y: vm.y + Math.sin(halfAngle) * halfRadius
  8314. };
  8315. },
  8316. getArea: function() {
  8317. var vm = this._view;
  8318. return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
  8319. },
  8320. tooltipPosition: function() {
  8321. var vm = this._view;
  8322. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
  8323. rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  8324. return {
  8325. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  8326. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  8327. };
  8328. },
  8329. draw: function() {
  8330. var ctx = this._chart.ctx,
  8331. vm = this._view,
  8332. sA = vm.startAngle,
  8333. eA = vm.endAngle;
  8334. ctx.beginPath();
  8335. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  8336. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  8337. ctx.closePath();
  8338. ctx.strokeStyle = vm.borderColor;
  8339. ctx.lineWidth = vm.borderWidth;
  8340. ctx.fillStyle = vm.backgroundColor;
  8341. ctx.fill();
  8342. ctx.lineJoin = 'bevel';
  8343. if (vm.borderWidth) {
  8344. ctx.stroke();
  8345. }
  8346. }
  8347. });
  8348. };
  8349. },{}],38:[function(require,module,exports){
  8350. 'use strict';
  8351. module.exports = function(Chart) {
  8352. var helpers = Chart.helpers;
  8353. var globalDefaults = Chart.defaults.global;
  8354. Chart.defaults.global.elements.line = {
  8355. tension: 0.4,
  8356. backgroundColor: globalDefaults.defaultColor,
  8357. borderWidth: 3,
  8358. borderColor: globalDefaults.defaultColor,
  8359. borderCapStyle: 'butt',
  8360. borderDash: [],
  8361. borderDashOffset: 0.0,
  8362. borderJoinStyle: 'miter',
  8363. capBezierPoints: true,
  8364. fill: true, // do we fill in the area between the line and its base axis
  8365. };
  8366. Chart.elements.Line = Chart.Element.extend({
  8367. draw: function() {
  8368. var me = this;
  8369. var vm = me._view;
  8370. var spanGaps = vm.spanGaps;
  8371. var fillPoint = vm.scaleZero;
  8372. var loop = me._loop;
  8373. // Handle different fill modes for cartesian lines
  8374. if (!loop) {
  8375. if (vm.fill === 'top') {
  8376. fillPoint = vm.scaleTop;
  8377. } else if (vm.fill === 'bottom') {
  8378. fillPoint = vm.scaleBottom;
  8379. }
  8380. }
  8381. var ctx = me._chart.ctx;
  8382. ctx.save();
  8383. // Helper function to draw a line to a point
  8384. function lineToPoint(previousPoint, point) {
  8385. var pointVM = point._view;
  8386. if (point._view.steppedLine === true) {
  8387. ctx.lineTo(pointVM.x, previousPoint._view.y);
  8388. ctx.lineTo(pointVM.x, pointVM.y);
  8389. } else if (point._view.tension === 0) {
  8390. ctx.lineTo(pointVM.x, pointVM.y);
  8391. } else {
  8392. ctx.bezierCurveTo(
  8393. previousPoint._view.controlPointNextX,
  8394. previousPoint._view.controlPointNextY,
  8395. pointVM.controlPointPreviousX,
  8396. pointVM.controlPointPreviousY,
  8397. pointVM.x,
  8398. pointVM.y
  8399. );
  8400. }
  8401. }
  8402. var points = me._children.slice(); // clone array
  8403. var lastDrawnIndex = -1;
  8404. // If we are looping, adding the first point again
  8405. if (loop && points.length) {
  8406. points.push(points[0]);
  8407. }
  8408. var index, current, previous, currentVM;
  8409. // Fill Line
  8410. if (points.length && vm.fill) {
  8411. ctx.beginPath();
  8412. for (index = 0; index < points.length; ++index) {
  8413. current = points[index];
  8414. previous = helpers.previousItem(points, index);
  8415. currentVM = current._view;
  8416. // First point moves to it's starting position no matter what
  8417. if (index === 0) {
  8418. if (loop) {
  8419. ctx.moveTo(fillPoint.x, fillPoint.y);
  8420. } else {
  8421. ctx.moveTo(currentVM.x, fillPoint);
  8422. }
  8423. if (!currentVM.skip) {
  8424. lastDrawnIndex = index;
  8425. ctx.lineTo(currentVM.x, currentVM.y);
  8426. }
  8427. } else {
  8428. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  8429. if (currentVM.skip) {
  8430. // Only do this if this is the first point that is skipped
  8431. if (!spanGaps && lastDrawnIndex === (index - 1)) {
  8432. if (loop) {
  8433. ctx.lineTo(fillPoint.x, fillPoint.y);
  8434. } else {
  8435. ctx.lineTo(previous._view.x, fillPoint);
  8436. }
  8437. }
  8438. } else {
  8439. if (lastDrawnIndex !== (index - 1)) {
  8440. // 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.
  8441. // If the first data point is NaN, then there is no real gap to skip
  8442. if (spanGaps && lastDrawnIndex !== -1) {
  8443. // We are spanning the gap, so simple draw a line to this point
  8444. lineToPoint(previous, current);
  8445. } else if (loop) {
  8446. ctx.lineTo(currentVM.x, currentVM.y);
  8447. } else {
  8448. ctx.lineTo(currentVM.x, fillPoint);
  8449. ctx.lineTo(currentVM.x, currentVM.y);
  8450. }
  8451. } else {
  8452. // Line to next point
  8453. lineToPoint(previous, current);
  8454. }
  8455. lastDrawnIndex = index;
  8456. }
  8457. }
  8458. }
  8459. if (!loop && lastDrawnIndex !== -1) {
  8460. ctx.lineTo(points[lastDrawnIndex]._view.x, fillPoint);
  8461. }
  8462. ctx.fillStyle = vm.backgroundColor || globalDefaults.defaultColor;
  8463. ctx.closePath();
  8464. ctx.fill();
  8465. }
  8466. // Stroke Line Options
  8467. var globalOptionLineElements = globalDefaults.elements.line;
  8468. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  8469. // IE 9 and 10 do not support line dash
  8470. if (ctx.setLineDash) {
  8471. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  8472. }
  8473. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  8474. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  8475. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  8476. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  8477. // Stroke Line
  8478. ctx.beginPath();
  8479. lastDrawnIndex = -1;
  8480. for (index = 0; index < points.length; ++index) {
  8481. current = points[index];
  8482. previous = helpers.previousItem(points, index);
  8483. currentVM = current._view;
  8484. // First point moves to it's starting position no matter what
  8485. if (index === 0) {
  8486. if (!currentVM.skip) {
  8487. ctx.moveTo(currentVM.x, currentVM.y);
  8488. lastDrawnIndex = index;
  8489. }
  8490. } else {
  8491. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  8492. if (!currentVM.skip) {
  8493. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  8494. // There was a gap and this is the first point after the gap
  8495. ctx.moveTo(currentVM.x, currentVM.y);
  8496. } else {
  8497. // Line to next point
  8498. lineToPoint(previous, current);
  8499. }
  8500. lastDrawnIndex = index;
  8501. }
  8502. }
  8503. }
  8504. ctx.stroke();
  8505. ctx.restore();
  8506. }
  8507. });
  8508. };
  8509. },{}],39:[function(require,module,exports){
  8510. 'use strict';
  8511. module.exports = function(Chart) {
  8512. var helpers = Chart.helpers,
  8513. globalOpts = Chart.defaults.global,
  8514. defaultColor = globalOpts.defaultColor;
  8515. globalOpts.elements.point = {
  8516. radius: 3,
  8517. pointStyle: 'circle',
  8518. backgroundColor: defaultColor,
  8519. borderWidth: 1,
  8520. borderColor: defaultColor,
  8521. // Hover
  8522. hitRadius: 1,
  8523. hoverRadius: 4,
  8524. hoverBorderWidth: 1
  8525. };
  8526. function xRange(mouseX) {
  8527. var vm = this._view;
  8528. return vm ? (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
  8529. }
  8530. function yRange(mouseY) {
  8531. var vm = this._view;
  8532. return vm ? (Math.pow(mouseY - vm.y, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
  8533. }
  8534. Chart.elements.Point = Chart.Element.extend({
  8535. inRange: function(mouseX, mouseY) {
  8536. var vm = this._view;
  8537. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  8538. },
  8539. inLabelRange: xRange,
  8540. inXRange: xRange,
  8541. inYRange: yRange,
  8542. getCenterPoint: function() {
  8543. var vm = this._view;
  8544. return {
  8545. x: vm.x,
  8546. y: vm.y
  8547. };
  8548. },
  8549. getArea: function() {
  8550. return Math.PI * Math.pow(this._view.radius, 2);
  8551. },
  8552. tooltipPosition: function() {
  8553. var vm = this._view;
  8554. return {
  8555. x: vm.x,
  8556. y: vm.y,
  8557. padding: vm.radius + vm.borderWidth
  8558. };
  8559. },
  8560. draw: function(chartArea) {
  8561. var vm = this._view;
  8562. var model = this._model;
  8563. var ctx = this._chart.ctx;
  8564. var pointStyle = vm.pointStyle;
  8565. var radius = vm.radius;
  8566. var x = vm.x;
  8567. var y = vm.y;
  8568. var color = Chart.helpers.color;
  8569. var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)
  8570. var ratio = 0;
  8571. if (vm.skip) {
  8572. return;
  8573. }
  8574. ctx.strokeStyle = vm.borderColor || defaultColor;
  8575. ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, globalOpts.elements.point.borderWidth);
  8576. ctx.fillStyle = vm.backgroundColor || defaultColor;
  8577. // Cliping for Points.
  8578. // going out from inner charArea?
  8579. if ((chartArea !== undefined) && ((model.x < chartArea.left) || (chartArea.right*errMargin < model.x) || (model.y < chartArea.top) || (chartArea.bottom*errMargin < model.y))) {
  8580. // Point fade out
  8581. if (model.x < chartArea.left) {
  8582. ratio = (x - model.x) / (chartArea.left - model.x);
  8583. } else if (chartArea.right*errMargin < model.x) {
  8584. ratio = (model.x - x) / (model.x - chartArea.right);
  8585. } else if (model.y < chartArea.top) {
  8586. ratio = (y - model.y) / (chartArea.top - model.y);
  8587. } else if (chartArea.bottom*errMargin < model.y) {
  8588. ratio = (model.y - y) / (model.y - chartArea.bottom);
  8589. }
  8590. ratio = Math.round(ratio*100) / 100;
  8591. ctx.strokeStyle = color(ctx.strokeStyle).alpha(ratio).rgbString();
  8592. ctx.fillStyle = color(ctx.fillStyle).alpha(ratio).rgbString();
  8593. }
  8594. Chart.canvasHelpers.drawPoint(ctx, pointStyle, radius, x, y);
  8595. }
  8596. });
  8597. };
  8598. },{}],40:[function(require,module,exports){
  8599. 'use strict';
  8600. module.exports = function(Chart) {
  8601. var globalOpts = Chart.defaults.global;
  8602. globalOpts.elements.rectangle = {
  8603. backgroundColor: globalOpts.defaultColor,
  8604. borderWidth: 0,
  8605. borderColor: globalOpts.defaultColor,
  8606. borderSkipped: 'bottom'
  8607. };
  8608. function isVertical(bar) {
  8609. return bar._view.width !== undefined;
  8610. }
  8611. /**
  8612. * Helper function to get the bounds of the bar regardless of the orientation
  8613. * @private
  8614. * @param bar {Chart.Element.Rectangle} the bar
  8615. * @return {Bounds} bounds of the bar
  8616. */
  8617. function getBarBounds(bar) {
  8618. var vm = bar._view;
  8619. var x1, x2, y1, y2;
  8620. if (isVertical(bar)) {
  8621. // vertical
  8622. var halfWidth = vm.width / 2;
  8623. x1 = vm.x - halfWidth;
  8624. x2 = vm.x + halfWidth;
  8625. y1 = Math.min(vm.y, vm.base);
  8626. y2 = Math.max(vm.y, vm.base);
  8627. } else {
  8628. // horizontal bar
  8629. var halfHeight = vm.height / 2;
  8630. x1 = Math.min(vm.x, vm.base);
  8631. x2 = Math.max(vm.x, vm.base);
  8632. y1 = vm.y - halfHeight;
  8633. y2 = vm.y + halfHeight;
  8634. }
  8635. return {
  8636. left: x1,
  8637. top: y1,
  8638. right: x2,
  8639. bottom: y2
  8640. };
  8641. }
  8642. Chart.elements.Rectangle = Chart.Element.extend({
  8643. draw: function() {
  8644. var ctx = this._chart.ctx;
  8645. var vm = this._view;
  8646. var left, right, top, bottom, signX, signY, borderSkipped;
  8647. var borderWidth = vm.borderWidth;
  8648. if (!vm.horizontal) {
  8649. // bar
  8650. left = vm.x - vm.width / 2;
  8651. right = vm.x + vm.width / 2;
  8652. top = vm.y;
  8653. bottom = vm.base;
  8654. signX = 1;
  8655. signY = bottom > top? 1: -1;
  8656. borderSkipped = vm.borderSkipped || 'bottom';
  8657. } else {
  8658. // horizontal bar
  8659. left = vm.base;
  8660. right = vm.x;
  8661. top = vm.y - vm.height / 2;
  8662. bottom = vm.y + vm.height / 2;
  8663. signX = right > left? 1: -1;
  8664. signY = 1;
  8665. borderSkipped = vm.borderSkipped || 'left';
  8666. }
  8667. // Canvas doesn't allow us to stroke inside the width so we can
  8668. // adjust the sizes to fit if we're setting a stroke on the line
  8669. if (borderWidth) {
  8670. // borderWidth shold be less than bar width and bar height.
  8671. var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
  8672. borderWidth = borderWidth > barSize? barSize: borderWidth;
  8673. var halfStroke = borderWidth / 2;
  8674. // Adjust borderWidth when bar top position is near vm.base(zero).
  8675. var borderLeft = left + (borderSkipped !== 'left'? halfStroke * signX: 0);
  8676. var borderRight = right + (borderSkipped !== 'right'? -halfStroke * signX: 0);
  8677. var borderTop = top + (borderSkipped !== 'top'? halfStroke * signY: 0);
  8678. var borderBottom = bottom + (borderSkipped !== 'bottom'? -halfStroke * signY: 0);
  8679. // not become a vertical line?
  8680. if (borderLeft !== borderRight) {
  8681. top = borderTop;
  8682. bottom = borderBottom;
  8683. }
  8684. // not become a horizontal line?
  8685. if (borderTop !== borderBottom) {
  8686. left = borderLeft;
  8687. right = borderRight;
  8688. }
  8689. }
  8690. ctx.beginPath();
  8691. ctx.fillStyle = vm.backgroundColor;
  8692. ctx.strokeStyle = vm.borderColor;
  8693. ctx.lineWidth = borderWidth;
  8694. // Corner points, from bottom-left to bottom-right clockwise
  8695. // | 1 2 |
  8696. // | 0 3 |
  8697. var corners = [
  8698. [left, bottom],
  8699. [left, top],
  8700. [right, top],
  8701. [right, bottom]
  8702. ];
  8703. // Find first (starting) corner with fallback to 'bottom'
  8704. var borders = ['bottom', 'left', 'top', 'right'];
  8705. var startCorner = borders.indexOf(borderSkipped, 0);
  8706. if (startCorner === -1) {
  8707. startCorner = 0;
  8708. }
  8709. function cornerAt(index) {
  8710. return corners[(startCorner + index) % 4];
  8711. }
  8712. // Draw rectangle from 'startCorner'
  8713. var corner = cornerAt(0);
  8714. ctx.moveTo(corner[0], corner[1]);
  8715. for (var i = 1; i < 4; i++) {
  8716. corner = cornerAt(i);
  8717. ctx.lineTo(corner[0], corner[1]);
  8718. }
  8719. ctx.fill();
  8720. if (borderWidth) {
  8721. ctx.stroke();
  8722. }
  8723. },
  8724. height: function() {
  8725. var vm = this._view;
  8726. return vm.base - vm.y;
  8727. },
  8728. inRange: function(mouseX, mouseY) {
  8729. var inRange = false;
  8730. if (this._view) {
  8731. var bounds = getBarBounds(this);
  8732. inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
  8733. }
  8734. return inRange;
  8735. },
  8736. inLabelRange: function(mouseX, mouseY) {
  8737. var me = this;
  8738. if (!me._view) {
  8739. return false;
  8740. }
  8741. var inRange = false;
  8742. var bounds = getBarBounds(me);
  8743. if (isVertical(me)) {
  8744. inRange = mouseX >= bounds.left && mouseX <= bounds.right;
  8745. } else {
  8746. inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
  8747. }
  8748. return inRange;
  8749. },
  8750. inXRange: function(mouseX) {
  8751. var bounds = getBarBounds(this);
  8752. return mouseX >= bounds.left && mouseX <= bounds.right;
  8753. },
  8754. inYRange: function(mouseY) {
  8755. var bounds = getBarBounds(this);
  8756. return mouseY >= bounds.top && mouseY <= bounds.bottom;
  8757. },
  8758. getCenterPoint: function() {
  8759. var vm = this._view;
  8760. var x, y;
  8761. if (isVertical(this)) {
  8762. x = vm.x;
  8763. y = (vm.y + vm.base) / 2;
  8764. } else {
  8765. x = (vm.x + vm.base) / 2;
  8766. y = vm.y;
  8767. }
  8768. return {x: x, y: y};
  8769. },
  8770. getArea: function() {
  8771. var vm = this._view;
  8772. return vm.width * Math.abs(vm.y - vm.base);
  8773. },
  8774. tooltipPosition: function() {
  8775. var vm = this._view;
  8776. return {
  8777. x: vm.x,
  8778. y: vm.y
  8779. };
  8780. }
  8781. });
  8782. };
  8783. },{}],41:[function(require,module,exports){
  8784. 'use strict';
  8785. // Chart.Platform implementation for targeting a web browser
  8786. module.exports = function(Chart) {
  8787. var helpers = Chart.helpers;
  8788. // DOM event types -> Chart.js event types.
  8789. // Note: only events with different types are mapped.
  8790. // https://developer.mozilla.org/en-US/docs/Web/Events
  8791. var eventTypeMap = {
  8792. // Touch events
  8793. touchstart: 'mousedown',
  8794. touchmove: 'mousemove',
  8795. touchend: 'mouseup',
  8796. // Pointer events
  8797. pointerenter: 'mouseenter',
  8798. pointerdown: 'mousedown',
  8799. pointermove: 'mousemove',
  8800. pointerup: 'mouseup',
  8801. pointerleave: 'mouseout',
  8802. pointerout: 'mouseout'
  8803. };
  8804. /**
  8805. * The "used" size is the final value of a dimension property after all calculations have
  8806. * been performed. This method uses the computed style of `element` but returns undefined
  8807. * if the computed style is not expressed in pixels. That can happen in some cases where
  8808. * `element` has a size relative to its parent and this last one is not yet displayed,
  8809. * for example because of `display: none` on a parent node.
  8810. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
  8811. * @returns {Number} Size in pixels or undefined if unknown.
  8812. */
  8813. function readUsedSize(element, property) {
  8814. var value = helpers.getStyle(element, property);
  8815. var matches = value && value.match(/(\d+)px/);
  8816. return matches? Number(matches[1]) : undefined;
  8817. }
  8818. /**
  8819. * Initializes the canvas style and render size without modifying the canvas display size,
  8820. * since responsiveness is handled by the controller.resize() method. The config is used
  8821. * to determine the aspect ratio to apply in case no explicit height has been specified.
  8822. */
  8823. function initCanvas(canvas, config) {
  8824. var style = canvas.style;
  8825. // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
  8826. // returns null or '' if no explicit value has been set to the canvas attribute.
  8827. var renderHeight = canvas.getAttribute('height');
  8828. var renderWidth = canvas.getAttribute('width');
  8829. // Chart.js modifies some canvas values that we want to restore on destroy
  8830. canvas._chartjs = {
  8831. initial: {
  8832. height: renderHeight,
  8833. width: renderWidth,
  8834. style: {
  8835. display: style.display,
  8836. height: style.height,
  8837. width: style.width
  8838. }
  8839. }
  8840. };
  8841. // Force canvas to display as block to avoid extra space caused by inline
  8842. // elements, which would interfere with the responsive resize process.
  8843. // https://github.com/chartjs/Chart.js/issues/2538
  8844. style.display = style.display || 'block';
  8845. if (renderWidth === null || renderWidth === '') {
  8846. var displayWidth = readUsedSize(canvas, 'width');
  8847. if (displayWidth !== undefined) {
  8848. canvas.width = displayWidth;
  8849. }
  8850. }
  8851. if (renderHeight === null || renderHeight === '') {
  8852. if (canvas.style.height === '') {
  8853. // If no explicit render height and style height, let's apply the aspect ratio,
  8854. // which one can be specified by the user but also by charts as default option
  8855. // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
  8856. canvas.height = canvas.width / (config.options.aspectRatio || 2);
  8857. } else {
  8858. var displayHeight = readUsedSize(canvas, 'height');
  8859. if (displayWidth !== undefined) {
  8860. canvas.height = displayHeight;
  8861. }
  8862. }
  8863. }
  8864. return canvas;
  8865. }
  8866. function createEvent(type, chart, x, y, native) {
  8867. return {
  8868. type: type,
  8869. chart: chart,
  8870. native: native || null,
  8871. x: x !== undefined? x : null,
  8872. y: y !== undefined? y : null,
  8873. };
  8874. }
  8875. function fromNativeEvent(event, chart) {
  8876. var type = eventTypeMap[event.type] || event.type;
  8877. var pos = helpers.getRelativePosition(event, chart);
  8878. return createEvent(type, chart, pos.x, pos.y, event);
  8879. }
  8880. function createResizer(handler) {
  8881. var iframe = document.createElement('iframe');
  8882. iframe.className = 'chartjs-hidden-iframe';
  8883. iframe.style.cssText =
  8884. 'display:block;'+
  8885. 'overflow:hidden;'+
  8886. 'border:0;'+
  8887. 'margin:0;'+
  8888. 'top:0;'+
  8889. 'left:0;'+
  8890. 'bottom:0;'+
  8891. 'right:0;'+
  8892. 'height:100%;'+
  8893. 'width:100%;'+
  8894. 'position:absolute;'+
  8895. 'pointer-events:none;'+
  8896. 'z-index:-1;';
  8897. // Prevent the iframe to gain focus on tab.
  8898. // https://github.com/chartjs/Chart.js/issues/3090
  8899. iframe.tabIndex = -1;
  8900. // If the iframe is re-attached to the DOM, the resize listener is removed because the
  8901. // content is reloaded, so make sure to install the handler after the iframe is loaded.
  8902. // https://github.com/chartjs/Chart.js/issues/3521
  8903. helpers.addEvent(iframe, 'load', function() {
  8904. helpers.addEvent(iframe.contentWindow || iframe, 'resize', handler);
  8905. // The iframe size might have changed while loading, which can also
  8906. // happen if the size has been changed while detached from the DOM.
  8907. handler();
  8908. });
  8909. return iframe;
  8910. }
  8911. function addResizeListener(node, listener, chart) {
  8912. var stub = node._chartjs = {
  8913. ticking: false
  8914. };
  8915. // Throttle the callback notification until the next animation frame.
  8916. var notify = function() {
  8917. if (!stub.ticking) {
  8918. stub.ticking = true;
  8919. helpers.requestAnimFrame.call(window, function() {
  8920. if (stub.resizer) {
  8921. stub.ticking = false;
  8922. return listener(createEvent('resize', chart));
  8923. }
  8924. });
  8925. }
  8926. };
  8927. // Let's keep track of this added iframe and thus avoid DOM query when removing it.
  8928. stub.resizer = createResizer(notify);
  8929. node.insertBefore(stub.resizer, node.firstChild);
  8930. }
  8931. function removeResizeListener(node) {
  8932. if (!node || !node._chartjs) {
  8933. return;
  8934. }
  8935. var resizer = node._chartjs.resizer;
  8936. if (resizer) {
  8937. resizer.parentNode.removeChild(resizer);
  8938. node._chartjs.resizer = null;
  8939. }
  8940. delete node._chartjs;
  8941. }
  8942. return {
  8943. acquireContext: function(item, config) {
  8944. if (typeof item === 'string') {
  8945. item = document.getElementById(item);
  8946. } else if (item.length) {
  8947. // Support for array based queries (such as jQuery)
  8948. item = item[0];
  8949. }
  8950. if (item && item.canvas) {
  8951. // Support for any object associated to a canvas (including a context2d)
  8952. item = item.canvas;
  8953. }
  8954. if (item instanceof HTMLCanvasElement) {
  8955. // To prevent canvas fingerprinting, some add-ons undefine the getContext
  8956. // method, for example: https://github.com/kkapsner/CanvasBlocker
  8957. // https://github.com/chartjs/Chart.js/issues/2807
  8958. var context = item.getContext && item.getContext('2d');
  8959. if (context instanceof CanvasRenderingContext2D) {
  8960. initCanvas(item, config);
  8961. return context;
  8962. }
  8963. }
  8964. return null;
  8965. },
  8966. releaseContext: function(context) {
  8967. var canvas = context.canvas;
  8968. if (!canvas._chartjs) {
  8969. return;
  8970. }
  8971. var initial = canvas._chartjs.initial;
  8972. ['height', 'width'].forEach(function(prop) {
  8973. var value = initial[prop];
  8974. if (value === undefined || value === null) {
  8975. canvas.removeAttribute(prop);
  8976. } else {
  8977. canvas.setAttribute(prop, value);
  8978. }
  8979. });
  8980. helpers.each(initial.style || {}, function(value, key) {
  8981. canvas.style[key] = value;
  8982. });
  8983. // The canvas render size might have been changed (and thus the state stack discarded),
  8984. // we can't use save() and restore() to restore the initial state. So make sure that at
  8985. // least the canvas context is reset to the default state by setting the canvas width.
  8986. // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
  8987. canvas.width = canvas.width;
  8988. delete canvas._chartjs;
  8989. },
  8990. addEventListener: function(chart, type, listener) {
  8991. var canvas = chart.chart.canvas;
  8992. if (type === 'resize') {
  8993. // Note: the resize event is not supported on all browsers.
  8994. addResizeListener(canvas.parentNode, listener, chart.chart);
  8995. return;
  8996. }
  8997. var stub = listener._chartjs || (listener._chartjs = {});
  8998. var proxies = stub.proxies || (stub.proxies = {});
  8999. var proxy = proxies[chart.id + '_' + type] = function(event) {
  9000. listener(fromNativeEvent(event, chart.chart));
  9001. };
  9002. helpers.addEvent(canvas, type, proxy);
  9003. },
  9004. removeEventListener: function(chart, type, listener) {
  9005. var canvas = chart.chart.canvas;
  9006. if (type === 'resize') {
  9007. // Note: the resize event is not supported on all browsers.
  9008. removeResizeListener(canvas.parentNode, listener);
  9009. return;
  9010. }
  9011. var stub = listener._chartjs || {};
  9012. var proxies = stub.proxies || {};
  9013. var proxy = proxies[chart.id + '_' + type];
  9014. if (!proxy) {
  9015. return;
  9016. }
  9017. helpers.removeEvent(canvas, type, proxy);
  9018. }
  9019. };
  9020. };
  9021. },{}],42:[function(require,module,exports){
  9022. 'use strict';
  9023. // By default, select the browser (DOM) platform.
  9024. // @TODO Make possible to select another platform at build time.
  9025. var implementation = require(41);
  9026. module.exports = function(Chart) {
  9027. /**
  9028. * @namespace Chart.platform
  9029. * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
  9030. * @since 2.4.0
  9031. */
  9032. Chart.platform = {
  9033. /**
  9034. * Called at chart construction time, returns a context2d instance implementing
  9035. * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
  9036. * @param {*} item - The native item from which to acquire context (platform specific)
  9037. * @param {Object} options - The chart options
  9038. * @returns {CanvasRenderingContext2D} context2d instance
  9039. */
  9040. acquireContext: function() {},
  9041. /**
  9042. * Called at chart destruction time, releases any resources associated to the context
  9043. * previously returned by the acquireContext() method.
  9044. * @param {CanvasRenderingContext2D} context - The context2d instance
  9045. * @returns {Boolean} true if the method succeeded, else false
  9046. */
  9047. releaseContext: function() {},
  9048. /**
  9049. * Registers the specified listener on the given chart.
  9050. * @param {Chart} chart - Chart from which to listen for event
  9051. * @param {String} type - The ({@link IEvent}) type to listen for
  9052. * @param {Function} listener - Receives a notification (an object that implements
  9053. * the {@link IEvent} interface) when an event of the specified type occurs.
  9054. */
  9055. addEventListener: function() {},
  9056. /**
  9057. * Removes the specified listener previously registered with addEventListener.
  9058. * @param {Chart} chart -Chart from which to remove the listener
  9059. * @param {String} type - The ({@link IEvent}) type to remove
  9060. * @param {Function} listener - The listener function to remove from the event target.
  9061. */
  9062. removeEventListener: function() {}
  9063. };
  9064. /**
  9065. * @interface IPlatform
  9066. * Allows abstracting platform dependencies away from the chart
  9067. * @borrows Chart.platform.acquireContext as acquireContext
  9068. * @borrows Chart.platform.releaseContext as releaseContext
  9069. * @borrows Chart.platform.addEventListener as addEventListener
  9070. * @borrows Chart.platform.removeEventListener as removeEventListener
  9071. */
  9072. /**
  9073. * @interface IEvent
  9074. * @prop {String} type - The event type name, possible values are:
  9075. * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
  9076. * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
  9077. * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
  9078. * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
  9079. * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
  9080. */
  9081. Chart.helpers.extend(Chart.platform, implementation(Chart));
  9082. };
  9083. },{"41":41}],43:[function(require,module,exports){
  9084. 'use strict';
  9085. module.exports = function(Chart) {
  9086. var helpers = Chart.helpers;
  9087. // Default config for a category scale
  9088. var defaultConfig = {
  9089. position: 'bottom'
  9090. };
  9091. var DatasetScale = Chart.Scale.extend({
  9092. /**
  9093. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
  9094. * else fall back to data.labels
  9095. * @private
  9096. */
  9097. getLabels: function() {
  9098. var data = this.chart.data;
  9099. return (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  9100. },
  9101. // Implement this so that
  9102. determineDataLimits: function() {
  9103. var me = this;
  9104. var labels = me.getLabels();
  9105. me.minIndex = 0;
  9106. me.maxIndex = labels.length - 1;
  9107. var findIndex;
  9108. if (me.options.ticks.min !== undefined) {
  9109. // user specified min value
  9110. findIndex = helpers.indexOf(labels, me.options.ticks.min);
  9111. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  9112. }
  9113. if (me.options.ticks.max !== undefined) {
  9114. // user specified max value
  9115. findIndex = helpers.indexOf(labels, me.options.ticks.max);
  9116. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  9117. }
  9118. me.min = labels[me.minIndex];
  9119. me.max = labels[me.maxIndex];
  9120. },
  9121. buildTicks: function() {
  9122. var me = this;
  9123. var labels = me.getLabels();
  9124. // If we are viewing some subset of labels, slice the original array
  9125. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  9126. },
  9127. getLabelForIndex: function(index, datasetIndex) {
  9128. var me = this;
  9129. var data = me.chart.data;
  9130. var isHorizontal = me.isHorizontal();
  9131. if (data.yLabels && !isHorizontal) {
  9132. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  9133. }
  9134. return me.ticks[index - me.minIndex];
  9135. },
  9136. // Used to get data value locations. Value can either be an index or a numerical value
  9137. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  9138. var me = this;
  9139. // 1 is added because we need the length but we have the indexes
  9140. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  9141. if (value !== undefined && isNaN(index)) {
  9142. var labels = me.getLabels();
  9143. var idx = labels.indexOf(value);
  9144. index = idx !== -1 ? idx : index;
  9145. }
  9146. if (me.isHorizontal()) {
  9147. var valueWidth = me.width / offsetAmt;
  9148. var widthOffset = (valueWidth * (index - me.minIndex));
  9149. if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) {
  9150. widthOffset += (valueWidth / 2);
  9151. }
  9152. return me.left + Math.round(widthOffset);
  9153. }
  9154. var valueHeight = me.height / offsetAmt;
  9155. var heightOffset = (valueHeight * (index - me.minIndex));
  9156. if (me.options.gridLines.offsetGridLines && includeOffset) {
  9157. heightOffset += (valueHeight / 2);
  9158. }
  9159. return me.top + Math.round(heightOffset);
  9160. },
  9161. getPixelForTick: function(index, includeOffset) {
  9162. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
  9163. },
  9164. getValueForPixel: function(pixel) {
  9165. var me = this;
  9166. var value;
  9167. var offsetAmt = Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  9168. var horz = me.isHorizontal();
  9169. var valueDimension = (horz ? me.width : me.height) / offsetAmt;
  9170. pixel -= horz ? me.left : me.top;
  9171. if (me.options.gridLines.offsetGridLines) {
  9172. pixel -= (valueDimension / 2);
  9173. }
  9174. if (pixel <= 0) {
  9175. value = 0;
  9176. } else {
  9177. value = Math.round(pixel / valueDimension);
  9178. }
  9179. return value;
  9180. },
  9181. getBasePixel: function() {
  9182. return this.bottom;
  9183. }
  9184. });
  9185. Chart.scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  9186. };
  9187. },{}],44:[function(require,module,exports){
  9188. 'use strict';
  9189. module.exports = function(Chart) {
  9190. var helpers = Chart.helpers;
  9191. var defaultConfig = {
  9192. position: 'left',
  9193. ticks: {
  9194. callback: Chart.Ticks.formatters.linear
  9195. }
  9196. };
  9197. var LinearScale = Chart.LinearScaleBase.extend({
  9198. determineDataLimits: function() {
  9199. var me = this;
  9200. var opts = me.options;
  9201. var chart = me.chart;
  9202. var data = chart.data;
  9203. var datasets = data.datasets;
  9204. var isHorizontal = me.isHorizontal();
  9205. function IDMatches(meta) {
  9206. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  9207. }
  9208. // First Calculate the range
  9209. me.min = null;
  9210. me.max = null;
  9211. var hasStacks = opts.stacked;
  9212. if (hasStacks === undefined) {
  9213. helpers.each(datasets, function(dataset, datasetIndex) {
  9214. if (hasStacks) {
  9215. return;
  9216. }
  9217. var meta = chart.getDatasetMeta(datasetIndex);
  9218. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  9219. meta.stack !== undefined) {
  9220. hasStacks = true;
  9221. }
  9222. });
  9223. }
  9224. if (opts.stacked || hasStacks) {
  9225. var valuesPerStack = {};
  9226. helpers.each(datasets, function(dataset, datasetIndex) {
  9227. var meta = chart.getDatasetMeta(datasetIndex);
  9228. var key = [
  9229. meta.type,
  9230. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  9231. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  9232. meta.stack
  9233. ].join('.');
  9234. if (valuesPerStack[key] === undefined) {
  9235. valuesPerStack[key] = {
  9236. positiveValues: [],
  9237. negativeValues: []
  9238. };
  9239. }
  9240. // Store these per type
  9241. var positiveValues = valuesPerStack[key].positiveValues;
  9242. var negativeValues = valuesPerStack[key].negativeValues;
  9243. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  9244. helpers.each(dataset.data, function(rawValue, index) {
  9245. var value = +me.getRightValue(rawValue);
  9246. if (isNaN(value) || meta.data[index].hidden) {
  9247. return;
  9248. }
  9249. positiveValues[index] = positiveValues[index] || 0;
  9250. negativeValues[index] = negativeValues[index] || 0;
  9251. if (opts.relativePoints) {
  9252. positiveValues[index] = 100;
  9253. } else if (value < 0) {
  9254. negativeValues[index] += value;
  9255. } else {
  9256. positiveValues[index] += value;
  9257. }
  9258. });
  9259. }
  9260. });
  9261. helpers.each(valuesPerStack, function(valuesForType) {
  9262. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  9263. var minVal = helpers.min(values);
  9264. var maxVal = helpers.max(values);
  9265. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  9266. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  9267. });
  9268. } else {
  9269. helpers.each(datasets, function(dataset, datasetIndex) {
  9270. var meta = chart.getDatasetMeta(datasetIndex);
  9271. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  9272. helpers.each(dataset.data, function(rawValue, index) {
  9273. var value = +me.getRightValue(rawValue);
  9274. if (isNaN(value) || meta.data[index].hidden) {
  9275. return;
  9276. }
  9277. if (me.min === null) {
  9278. me.min = value;
  9279. } else if (value < me.min) {
  9280. me.min = value;
  9281. }
  9282. if (me.max === null) {
  9283. me.max = value;
  9284. } else if (value > me.max) {
  9285. me.max = value;
  9286. }
  9287. });
  9288. }
  9289. });
  9290. }
  9291. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  9292. this.handleTickRangeOptions();
  9293. },
  9294. getTickLimit: function() {
  9295. var maxTicks;
  9296. var me = this;
  9297. var tickOpts = me.options.ticks;
  9298. if (me.isHorizontal()) {
  9299. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  9300. } else {
  9301. // The factor of 2 used to scale the font size has been experimentally determined.
  9302. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, Chart.defaults.global.defaultFontSize);
  9303. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  9304. }
  9305. return maxTicks;
  9306. },
  9307. // Called after the ticks are built. We need
  9308. handleDirectionalChanges: function() {
  9309. if (!this.isHorizontal()) {
  9310. // We are in a vertical orientation. The top value is the highest. So reverse the array
  9311. this.ticks.reverse();
  9312. }
  9313. },
  9314. getLabelForIndex: function(index, datasetIndex) {
  9315. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  9316. },
  9317. // Utils
  9318. getPixelForValue: function(value) {
  9319. // This must be called after fit has been run so that
  9320. // this.left, this.top, this.right, and this.bottom have been defined
  9321. var me = this;
  9322. var start = me.start;
  9323. var rightValue = +me.getRightValue(value);
  9324. var pixel;
  9325. var range = me.end - start;
  9326. if (me.isHorizontal()) {
  9327. pixel = me.left + (me.width / range * (rightValue - start));
  9328. return Math.round(pixel);
  9329. }
  9330. pixel = me.bottom - (me.height / range * (rightValue - start));
  9331. return Math.round(pixel);
  9332. },
  9333. getValueForPixel: function(pixel) {
  9334. var me = this;
  9335. var isHorizontal = me.isHorizontal();
  9336. var innerDimension = isHorizontal ? me.width : me.height;
  9337. var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
  9338. return me.start + ((me.end - me.start) * offset);
  9339. },
  9340. getPixelForTick: function(index) {
  9341. return this.getPixelForValue(this.ticksAsNumbers[index]);
  9342. }
  9343. });
  9344. Chart.scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  9345. };
  9346. },{}],45:[function(require,module,exports){
  9347. 'use strict';
  9348. module.exports = function(Chart) {
  9349. var helpers = Chart.helpers,
  9350. noop = helpers.noop;
  9351. Chart.LinearScaleBase = Chart.Scale.extend({
  9352. handleTickRangeOptions: function() {
  9353. var me = this;
  9354. var opts = me.options;
  9355. var tickOpts = opts.ticks;
  9356. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  9357. // do nothing since that would make the chart weird. If the user really wants a weird chart
  9358. // axis, they can manually override it
  9359. if (tickOpts.beginAtZero) {
  9360. var minSign = helpers.sign(me.min);
  9361. var maxSign = helpers.sign(me.max);
  9362. if (minSign < 0 && maxSign < 0) {
  9363. // move the top up to 0
  9364. me.max = 0;
  9365. } else if (minSign > 0 && maxSign > 0) {
  9366. // move the bottom down to 0
  9367. me.min = 0;
  9368. }
  9369. }
  9370. if (tickOpts.min !== undefined) {
  9371. me.min = tickOpts.min;
  9372. } else if (tickOpts.suggestedMin !== undefined) {
  9373. me.min = Math.min(me.min, tickOpts.suggestedMin);
  9374. }
  9375. if (tickOpts.max !== undefined) {
  9376. me.max = tickOpts.max;
  9377. } else if (tickOpts.suggestedMax !== undefined) {
  9378. me.max = Math.max(me.max, tickOpts.suggestedMax);
  9379. }
  9380. if (me.min === me.max) {
  9381. me.max++;
  9382. if (!tickOpts.beginAtZero) {
  9383. me.min--;
  9384. }
  9385. }
  9386. },
  9387. getTickLimit: noop,
  9388. handleDirectionalChanges: noop,
  9389. buildTicks: function() {
  9390. var me = this;
  9391. var opts = me.options;
  9392. var tickOpts = opts.ticks;
  9393. // Figure out what the max number of ticks we can support it is based on the size of
  9394. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  9395. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  9396. // the graph. Make sure we always have at least 2 ticks
  9397. var maxTicks = me.getTickLimit();
  9398. maxTicks = Math.max(2, maxTicks);
  9399. var numericGeneratorOptions = {
  9400. maxTicks: maxTicks,
  9401. min: tickOpts.min,
  9402. max: tickOpts.max,
  9403. stepSize: helpers.getValueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
  9404. };
  9405. var ticks = me.ticks = Chart.Ticks.generators.linear(numericGeneratorOptions, me);
  9406. me.handleDirectionalChanges();
  9407. // At this point, we need to update our max and min given the tick values since we have expanded the
  9408. // range of the scale
  9409. me.max = helpers.max(ticks);
  9410. me.min = helpers.min(ticks);
  9411. if (tickOpts.reverse) {
  9412. ticks.reverse();
  9413. me.start = me.max;
  9414. me.end = me.min;
  9415. } else {
  9416. me.start = me.min;
  9417. me.end = me.max;
  9418. }
  9419. },
  9420. convertTicksToLabels: function() {
  9421. var me = this;
  9422. me.ticksAsNumbers = me.ticks.slice();
  9423. me.zeroLineIndex = me.ticks.indexOf(0);
  9424. Chart.Scale.prototype.convertTicksToLabels.call(me);
  9425. }
  9426. });
  9427. };
  9428. },{}],46:[function(require,module,exports){
  9429. 'use strict';
  9430. module.exports = function(Chart) {
  9431. var helpers = Chart.helpers;
  9432. var defaultConfig = {
  9433. position: 'left',
  9434. // label settings
  9435. ticks: {
  9436. callback: Chart.Ticks.formatters.logarithmic
  9437. }
  9438. };
  9439. var LogarithmicScale = Chart.Scale.extend({
  9440. determineDataLimits: function() {
  9441. var me = this;
  9442. var opts = me.options;
  9443. var tickOpts = opts.ticks;
  9444. var chart = me.chart;
  9445. var data = chart.data;
  9446. var datasets = data.datasets;
  9447. var getValueOrDefault = helpers.getValueOrDefault;
  9448. var isHorizontal = me.isHorizontal();
  9449. function IDMatches(meta) {
  9450. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  9451. }
  9452. // Calculate Range
  9453. me.min = null;
  9454. me.max = null;
  9455. me.minNotZero = null;
  9456. var hasStacks = opts.stacked;
  9457. if (hasStacks === undefined) {
  9458. helpers.each(datasets, function(dataset, datasetIndex) {
  9459. if (hasStacks) {
  9460. return;
  9461. }
  9462. var meta = chart.getDatasetMeta(datasetIndex);
  9463. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  9464. meta.stack !== undefined) {
  9465. hasStacks = true;
  9466. }
  9467. });
  9468. }
  9469. if (opts.stacked || hasStacks) {
  9470. var valuesPerStack = {};
  9471. helpers.each(datasets, function(dataset, datasetIndex) {
  9472. var meta = chart.getDatasetMeta(datasetIndex);
  9473. var key = [
  9474. meta.type,
  9475. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  9476. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  9477. meta.stack
  9478. ].join('.');
  9479. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  9480. if (valuesPerStack[key] === undefined) {
  9481. valuesPerStack[key] = [];
  9482. }
  9483. helpers.each(dataset.data, function(rawValue, index) {
  9484. var values = valuesPerStack[key];
  9485. var value = +me.getRightValue(rawValue);
  9486. if (isNaN(value) || meta.data[index].hidden) {
  9487. return;
  9488. }
  9489. values[index] = values[index] || 0;
  9490. if (opts.relativePoints) {
  9491. values[index] = 100;
  9492. } else {
  9493. // Don't need to split positive and negative since the log scale can't handle a 0 crossing
  9494. values[index] += value;
  9495. }
  9496. });
  9497. }
  9498. });
  9499. helpers.each(valuesPerStack, function(valuesForType) {
  9500. var minVal = helpers.min(valuesForType);
  9501. var maxVal = helpers.max(valuesForType);
  9502. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  9503. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  9504. });
  9505. } else {
  9506. helpers.each(datasets, function(dataset, datasetIndex) {
  9507. var meta = chart.getDatasetMeta(datasetIndex);
  9508. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  9509. helpers.each(dataset.data, function(rawValue, index) {
  9510. var value = +me.getRightValue(rawValue);
  9511. if (isNaN(value) || meta.data[index].hidden) {
  9512. return;
  9513. }
  9514. if (me.min === null) {
  9515. me.min = value;
  9516. } else if (value < me.min) {
  9517. me.min = value;
  9518. }
  9519. if (me.max === null) {
  9520. me.max = value;
  9521. } else if (value > me.max) {
  9522. me.max = value;
  9523. }
  9524. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  9525. me.minNotZero = value;
  9526. }
  9527. });
  9528. }
  9529. });
  9530. }
  9531. me.min = getValueOrDefault(tickOpts.min, me.min);
  9532. me.max = getValueOrDefault(tickOpts.max, me.max);
  9533. if (me.min === me.max) {
  9534. if (me.min !== 0 && me.min !== null) {
  9535. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  9536. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  9537. } else {
  9538. me.min = 1;
  9539. me.max = 10;
  9540. }
  9541. }
  9542. },
  9543. buildTicks: function() {
  9544. var me = this;
  9545. var opts = me.options;
  9546. var tickOpts = opts.ticks;
  9547. var generationOptions = {
  9548. min: tickOpts.min,
  9549. max: tickOpts.max
  9550. };
  9551. var ticks = me.ticks = Chart.Ticks.generators.logarithmic(generationOptions, me);
  9552. if (!me.isHorizontal()) {
  9553. // We are in a vertical orientation. The top value is the highest. So reverse the array
  9554. ticks.reverse();
  9555. }
  9556. // At this point, we need to update our max and min given the tick values since we have expanded the
  9557. // range of the scale
  9558. me.max = helpers.max(ticks);
  9559. me.min = helpers.min(ticks);
  9560. if (tickOpts.reverse) {
  9561. ticks.reverse();
  9562. me.start = me.max;
  9563. me.end = me.min;
  9564. } else {
  9565. me.start = me.min;
  9566. me.end = me.max;
  9567. }
  9568. },
  9569. convertTicksToLabels: function() {
  9570. this.tickValues = this.ticks.slice();
  9571. Chart.Scale.prototype.convertTicksToLabels.call(this);
  9572. },
  9573. // Get the correct tooltip label
  9574. getLabelForIndex: function(index, datasetIndex) {
  9575. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  9576. },
  9577. getPixelForTick: function(index) {
  9578. return this.getPixelForValue(this.tickValues[index]);
  9579. },
  9580. getPixelForValue: function(value) {
  9581. var me = this;
  9582. var innerDimension;
  9583. var pixel;
  9584. var start = me.start;
  9585. var newVal = +me.getRightValue(value);
  9586. var range;
  9587. var opts = me.options;
  9588. var tickOpts = opts.ticks;
  9589. if (me.isHorizontal()) {
  9590. range = helpers.log10(me.end) - helpers.log10(start); // todo: if start === 0
  9591. if (newVal === 0) {
  9592. pixel = me.left;
  9593. } else {
  9594. innerDimension = me.width;
  9595. pixel = me.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  9596. }
  9597. } else {
  9598. // Bottom - top since pixels increase downward on a screen
  9599. innerDimension = me.height;
  9600. if (start === 0 && !tickOpts.reverse) {
  9601. range = helpers.log10(me.end) - helpers.log10(me.minNotZero);
  9602. if (newVal === start) {
  9603. pixel = me.bottom;
  9604. } else if (newVal === me.minNotZero) {
  9605. pixel = me.bottom - innerDimension * 0.02;
  9606. } else {
  9607. pixel = me.bottom - innerDimension * 0.02 - (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
  9608. }
  9609. } else if (me.end === 0 && tickOpts.reverse) {
  9610. range = helpers.log10(me.start) - helpers.log10(me.minNotZero);
  9611. if (newVal === me.end) {
  9612. pixel = me.top;
  9613. } else if (newVal === me.minNotZero) {
  9614. pixel = me.top + innerDimension * 0.02;
  9615. } else {
  9616. pixel = me.top + innerDimension * 0.02 + (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
  9617. }
  9618. } else {
  9619. range = helpers.log10(me.end) - helpers.log10(start);
  9620. innerDimension = me.height;
  9621. pixel = me.bottom - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  9622. }
  9623. }
  9624. return pixel;
  9625. },
  9626. getValueForPixel: function(pixel) {
  9627. var me = this;
  9628. var range = helpers.log10(me.end) - helpers.log10(me.start);
  9629. var value, innerDimension;
  9630. if (me.isHorizontal()) {
  9631. innerDimension = me.width;
  9632. value = me.start * Math.pow(10, (pixel - me.left) * range / innerDimension);
  9633. } else { // todo: if start === 0
  9634. innerDimension = me.height;
  9635. value = Math.pow(10, (me.bottom - pixel) * range / innerDimension) / me.start;
  9636. }
  9637. return value;
  9638. }
  9639. });
  9640. Chart.scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  9641. };
  9642. },{}],47:[function(require,module,exports){
  9643. 'use strict';
  9644. module.exports = function(Chart) {
  9645. var helpers = Chart.helpers;
  9646. var globalDefaults = Chart.defaults.global;
  9647. var defaultConfig = {
  9648. display: true,
  9649. // Boolean - Whether to animate scaling the chart from the centre
  9650. animate: true,
  9651. lineArc: false,
  9652. position: 'chartArea',
  9653. angleLines: {
  9654. display: true,
  9655. color: 'rgba(0, 0, 0, 0.1)',
  9656. lineWidth: 1
  9657. },
  9658. // label settings
  9659. ticks: {
  9660. // Boolean - Show a backdrop to the scale label
  9661. showLabelBackdrop: true,
  9662. // String - The colour of the label backdrop
  9663. backdropColor: 'rgba(255,255,255,0.75)',
  9664. // Number - The backdrop padding above & below the label in pixels
  9665. backdropPaddingY: 2,
  9666. // Number - The backdrop padding to the side of the label in pixels
  9667. backdropPaddingX: 2,
  9668. callback: Chart.Ticks.formatters.linear
  9669. },
  9670. pointLabels: {
  9671. // Number - Point label font size in pixels
  9672. fontSize: 10,
  9673. // Function - Used to convert point labels
  9674. callback: function(label) {
  9675. return label;
  9676. }
  9677. }
  9678. };
  9679. function getValueCount(scale) {
  9680. return !scale.options.lineArc ? scale.chart.data.labels.length : 0;
  9681. }
  9682. function getPointLabelFontOptions(scale) {
  9683. var pointLabelOptions = scale.options.pointLabels;
  9684. var fontSize = helpers.getValueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
  9685. var fontStyle = helpers.getValueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
  9686. var fontFamily = helpers.getValueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
  9687. var font = helpers.fontString(fontSize, fontStyle, fontFamily);
  9688. return {
  9689. size: fontSize,
  9690. style: fontStyle,
  9691. family: fontFamily,
  9692. font: font
  9693. };
  9694. }
  9695. function measureLabelSize(ctx, fontSize, label) {
  9696. if (helpers.isArray(label)) {
  9697. return {
  9698. w: helpers.longestText(ctx, ctx.font, label),
  9699. h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
  9700. };
  9701. }
  9702. return {
  9703. w: ctx.measureText(label).width,
  9704. h: fontSize
  9705. };
  9706. }
  9707. function determineLimits(angle, pos, size, min, max) {
  9708. if (angle === min || angle === max) {
  9709. return {
  9710. start: pos - (size / 2),
  9711. end: pos + (size / 2)
  9712. };
  9713. } else if (angle < min || angle > max) {
  9714. return {
  9715. start: pos - size - 5,
  9716. end: pos
  9717. };
  9718. }
  9719. return {
  9720. start: pos,
  9721. end: pos + size + 5
  9722. };
  9723. }
  9724. /**
  9725. * Helper function to fit a radial linear scale with point labels
  9726. */
  9727. function fitWithPointLabels(scale) {
  9728. /*
  9729. * Right, this is really confusing and there is a lot of maths going on here
  9730. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  9731. *
  9732. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  9733. *
  9734. * Solution:
  9735. *
  9736. * We assume the radius of the polygon is half the size of the canvas at first
  9737. * at each index we check if the text overlaps.
  9738. *
  9739. * Where it does, we store that angle and that index.
  9740. *
  9741. * After finding the largest index and angle we calculate how much we need to remove
  9742. * from the shape radius to move the point inwards by that x.
  9743. *
  9744. * We average the left and right distances to get the maximum shape radius that can fit in the box
  9745. * along with labels.
  9746. *
  9747. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  9748. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  9749. *
  9750. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  9751. * and position it in the most space efficient manner
  9752. *
  9753. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  9754. */
  9755. var plFont = getPointLabelFontOptions(scale);
  9756. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  9757. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  9758. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  9759. var furthestLimits = {
  9760. l: scale.width,
  9761. r: 0,
  9762. t: scale.height,
  9763. b: 0
  9764. };
  9765. var furthestAngles = {};
  9766. var i;
  9767. var textSize;
  9768. var pointPosition;
  9769. scale.ctx.font = plFont.font;
  9770. scale._pointLabelSizes = [];
  9771. var valueCount = getValueCount(scale);
  9772. for (i = 0; i < valueCount; i++) {
  9773. pointPosition = scale.getPointPosition(i, largestPossibleRadius);
  9774. textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
  9775. scale._pointLabelSizes[i] = textSize;
  9776. // Add quarter circle to make degree 0 mean top of circle
  9777. var angleRadians = scale.getIndexAngle(i);
  9778. var angle = helpers.toDegrees(angleRadians) % 360;
  9779. var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
  9780. var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
  9781. if (hLimits.start < furthestLimits.l) {
  9782. furthestLimits.l = hLimits.start;
  9783. furthestAngles.l = angleRadians;
  9784. }
  9785. if (hLimits.end > furthestLimits.r) {
  9786. furthestLimits.r = hLimits.end;
  9787. furthestAngles.r = angleRadians;
  9788. }
  9789. if (vLimits.start < furthestLimits.t) {
  9790. furthestLimits.t = vLimits.start;
  9791. furthestAngles.t = angleRadians;
  9792. }
  9793. if (vLimits.end > furthestLimits.b) {
  9794. furthestLimits.b = vLimits.end;
  9795. furthestAngles.b = angleRadians;
  9796. }
  9797. }
  9798. scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
  9799. }
  9800. /**
  9801. * Helper function to fit a radial linear scale with no point labels
  9802. */
  9803. function fit(scale) {
  9804. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  9805. scale.drawingArea = Math.round(largestPossibleRadius);
  9806. scale.setCenterPoint(0, 0, 0, 0);
  9807. }
  9808. function getTextAlignForAngle(angle) {
  9809. if (angle === 0 || angle === 180) {
  9810. return 'center';
  9811. } else if (angle < 180) {
  9812. return 'left';
  9813. }
  9814. return 'right';
  9815. }
  9816. function fillText(ctx, text, position, fontSize) {
  9817. if (helpers.isArray(text)) {
  9818. var y = position.y;
  9819. var spacing = 1.5 * fontSize;
  9820. for (var i = 0; i < text.length; ++i) {
  9821. ctx.fillText(text[i], position.x, y);
  9822. y+= spacing;
  9823. }
  9824. } else {
  9825. ctx.fillText(text, position.x, position.y);
  9826. }
  9827. }
  9828. function adjustPointPositionForLabelHeight(angle, textSize, position) {
  9829. if (angle === 90 || angle === 270) {
  9830. position.y -= (textSize.h / 2);
  9831. } else if (angle > 270 || angle < 90) {
  9832. position.y -= textSize.h;
  9833. }
  9834. }
  9835. function drawPointLabels(scale) {
  9836. var ctx = scale.ctx;
  9837. var getValueOrDefault = helpers.getValueOrDefault;
  9838. var opts = scale.options;
  9839. var angleLineOpts = opts.angleLines;
  9840. var pointLabelOpts = opts.pointLabels;
  9841. ctx.lineWidth = angleLineOpts.lineWidth;
  9842. ctx.strokeStyle = angleLineOpts.color;
  9843. var outerDistance = scale.getDistanceFromCenterForValue(opts.reverse ? scale.min : scale.max);
  9844. // Point Label Font
  9845. var plFont = getPointLabelFontOptions(scale);
  9846. ctx.textBaseline = 'top';
  9847. for (var i = getValueCount(scale) - 1; i >= 0; i--) {
  9848. if (angleLineOpts.display) {
  9849. var outerPosition = scale.getPointPosition(i, outerDistance);
  9850. ctx.beginPath();
  9851. ctx.moveTo(scale.xCenter, scale.yCenter);
  9852. ctx.lineTo(outerPosition.x, outerPosition.y);
  9853. ctx.stroke();
  9854. ctx.closePath();
  9855. }
  9856. // Extra 3px out for some label spacing
  9857. var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
  9858. // Keep this in loop since we may support array properties here
  9859. var pointLabelFontColor = getValueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
  9860. ctx.font = plFont.font;
  9861. ctx.fillStyle = pointLabelFontColor;
  9862. var angleRadians = scale.getIndexAngle(i);
  9863. var angle = helpers.toDegrees(angleRadians);
  9864. ctx.textAlign = getTextAlignForAngle(angle);
  9865. adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
  9866. fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
  9867. }
  9868. }
  9869. function drawRadiusLine(scale, gridLineOpts, radius, index) {
  9870. var ctx = scale.ctx;
  9871. ctx.strokeStyle = helpers.getValueAtIndexOrDefault(gridLineOpts.color, index - 1);
  9872. ctx.lineWidth = helpers.getValueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  9873. if (scale.options.lineArc) {
  9874. // Draw circular arcs between the points
  9875. ctx.beginPath();
  9876. ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
  9877. ctx.closePath();
  9878. ctx.stroke();
  9879. } else {
  9880. // Draw straight lines connecting each index
  9881. var valueCount = getValueCount(scale);
  9882. if (valueCount === 0) {
  9883. return;
  9884. }
  9885. ctx.beginPath();
  9886. var pointPosition = scale.getPointPosition(0, radius);
  9887. ctx.moveTo(pointPosition.x, pointPosition.y);
  9888. for (var i = 1; i < valueCount; i++) {
  9889. pointPosition = scale.getPointPosition(i, radius);
  9890. ctx.lineTo(pointPosition.x, pointPosition.y);
  9891. }
  9892. ctx.closePath();
  9893. ctx.stroke();
  9894. }
  9895. }
  9896. function numberOrZero(param) {
  9897. return helpers.isNumber(param) ? param : 0;
  9898. }
  9899. var LinearRadialScale = Chart.LinearScaleBase.extend({
  9900. setDimensions: function() {
  9901. var me = this;
  9902. var opts = me.options;
  9903. var tickOpts = opts.ticks;
  9904. // Set the unconstrained dimension before label rotation
  9905. me.width = me.maxWidth;
  9906. me.height = me.maxHeight;
  9907. me.xCenter = Math.round(me.width / 2);
  9908. me.yCenter = Math.round(me.height / 2);
  9909. var minSize = helpers.min([me.height, me.width]);
  9910. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  9911. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  9912. },
  9913. determineDataLimits: function() {
  9914. var me = this;
  9915. var chart = me.chart;
  9916. var min = Number.POSITIVE_INFINITY;
  9917. var max = Number.NEGATIVE_INFINITY;
  9918. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  9919. if (chart.isDatasetVisible(datasetIndex)) {
  9920. var meta = chart.getDatasetMeta(datasetIndex);
  9921. helpers.each(dataset.data, function(rawValue, index) {
  9922. var value = +me.getRightValue(rawValue);
  9923. if (isNaN(value) || meta.data[index].hidden) {
  9924. return;
  9925. }
  9926. min = Math.min(value, min);
  9927. max = Math.max(value, max);
  9928. });
  9929. }
  9930. });
  9931. me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
  9932. me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
  9933. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  9934. me.handleTickRangeOptions();
  9935. },
  9936. getTickLimit: function() {
  9937. var tickOpts = this.options.ticks;
  9938. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  9939. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  9940. },
  9941. convertTicksToLabels: function() {
  9942. var me = this;
  9943. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  9944. // Point labels
  9945. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  9946. },
  9947. getLabelForIndex: function(index, datasetIndex) {
  9948. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  9949. },
  9950. fit: function() {
  9951. if (this.options.lineArc) {
  9952. fit(this);
  9953. } else {
  9954. fitWithPointLabels(this);
  9955. }
  9956. },
  9957. /**
  9958. * Set radius reductions and determine new radius and center point
  9959. * @private
  9960. */
  9961. setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
  9962. var me = this;
  9963. var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
  9964. var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
  9965. var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
  9966. var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
  9967. radiusReductionLeft = numberOrZero(radiusReductionLeft);
  9968. radiusReductionRight = numberOrZero(radiusReductionRight);
  9969. radiusReductionTop = numberOrZero(radiusReductionTop);
  9970. radiusReductionBottom = numberOrZero(radiusReductionBottom);
  9971. me.drawingArea = Math.min(
  9972. Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
  9973. Math.round(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
  9974. me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
  9975. },
  9976. setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
  9977. var me = this;
  9978. var maxRight = me.width - rightMovement - me.drawingArea,
  9979. maxLeft = leftMovement + me.drawingArea,
  9980. maxTop = topMovement + me.drawingArea,
  9981. maxBottom = me.height - bottomMovement - me.drawingArea;
  9982. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  9983. me.yCenter = Math.round(((maxTop + maxBottom) / 2) + me.top);
  9984. },
  9985. getIndexAngle: function(index) {
  9986. var angleMultiplier = (Math.PI * 2) / getValueCount(this);
  9987. var startAngle = this.chart.options && this.chart.options.startAngle ?
  9988. this.chart.options.startAngle :
  9989. 0;
  9990. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  9991. // Start from the top instead of right, so remove a quarter of the circle
  9992. return index * angleMultiplier + startAngleRadians;
  9993. },
  9994. getDistanceFromCenterForValue: function(value) {
  9995. var me = this;
  9996. if (value === null) {
  9997. return 0; // null always in center
  9998. }
  9999. // Take into account half font size + the yPadding of the top value
  10000. var scalingFactor = me.drawingArea / (me.max - me.min);
  10001. if (me.options.reverse) {
  10002. return (me.max - value) * scalingFactor;
  10003. }
  10004. return (value - me.min) * scalingFactor;
  10005. },
  10006. getPointPosition: function(index, distanceFromCenter) {
  10007. var me = this;
  10008. var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
  10009. return {
  10010. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  10011. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  10012. };
  10013. },
  10014. getPointPositionForValue: function(index, value) {
  10015. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  10016. },
  10017. getBasePosition: function() {
  10018. var me = this;
  10019. var min = me.min;
  10020. var max = me.max;
  10021. return me.getPointPositionForValue(0,
  10022. me.beginAtZero? 0:
  10023. min < 0 && max < 0? max :
  10024. min > 0 && max > 0? min :
  10025. 0);
  10026. },
  10027. draw: function() {
  10028. var me = this;
  10029. var opts = me.options;
  10030. var gridLineOpts = opts.gridLines;
  10031. var tickOpts = opts.ticks;
  10032. var getValueOrDefault = helpers.getValueOrDefault;
  10033. if (opts.display) {
  10034. var ctx = me.ctx;
  10035. // Tick Font
  10036. var tickFontSize = getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  10037. var tickFontStyle = getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  10038. var tickFontFamily = getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  10039. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  10040. helpers.each(me.ticks, function(label, index) {
  10041. // Don't draw a centre value (if it is minimum)
  10042. if (index > 0 || opts.reverse) {
  10043. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  10044. var yHeight = me.yCenter - yCenterOffset;
  10045. // Draw circular lines around the scale
  10046. if (gridLineOpts.display && index !== 0) {
  10047. drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
  10048. }
  10049. if (tickOpts.display) {
  10050. var tickFontColor = getValueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  10051. ctx.font = tickLabelFont;
  10052. if (tickOpts.showLabelBackdrop) {
  10053. var labelWidth = ctx.measureText(label).width;
  10054. ctx.fillStyle = tickOpts.backdropColor;
  10055. ctx.fillRect(
  10056. me.xCenter - labelWidth / 2 - tickOpts.backdropPaddingX,
  10057. yHeight - tickFontSize / 2 - tickOpts.backdropPaddingY,
  10058. labelWidth + tickOpts.backdropPaddingX * 2,
  10059. tickFontSize + tickOpts.backdropPaddingY * 2
  10060. );
  10061. }
  10062. ctx.textAlign = 'center';
  10063. ctx.textBaseline = 'middle';
  10064. ctx.fillStyle = tickFontColor;
  10065. ctx.fillText(label, me.xCenter, yHeight);
  10066. }
  10067. }
  10068. });
  10069. if (!opts.lineArc) {
  10070. drawPointLabels(me);
  10071. }
  10072. }
  10073. }
  10074. });
  10075. Chart.scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  10076. };
  10077. },{}],48:[function(require,module,exports){
  10078. /* global window: false */
  10079. 'use strict';
  10080. var moment = require(1);
  10081. moment = typeof(moment) === 'function' ? moment : window.moment;
  10082. module.exports = function(Chart) {
  10083. var helpers = Chart.helpers;
  10084. var time = {
  10085. units: [{
  10086. name: 'millisecond',
  10087. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  10088. }, {
  10089. name: 'second',
  10090. steps: [1, 2, 5, 10, 30]
  10091. }, {
  10092. name: 'minute',
  10093. steps: [1, 2, 5, 10, 30]
  10094. }, {
  10095. name: 'hour',
  10096. steps: [1, 2, 3, 6, 12]
  10097. }, {
  10098. name: 'day',
  10099. steps: [1, 2, 5]
  10100. }, {
  10101. name: 'week',
  10102. maxStep: 4
  10103. }, {
  10104. name: 'month',
  10105. maxStep: 3
  10106. }, {
  10107. name: 'quarter',
  10108. maxStep: 4
  10109. }, {
  10110. name: 'year',
  10111. maxStep: false
  10112. }]
  10113. };
  10114. var defaultConfig = {
  10115. position: 'bottom',
  10116. time: {
  10117. 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
  10118. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  10119. unit: false, // false == automatic or override with week, month, year, etc.
  10120. round: false, // none, or override with week, month, year, etc.
  10121. displayFormat: false, // DEPRECATED
  10122. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  10123. minUnit: 'millisecond',
  10124. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  10125. displayFormats: {
  10126. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  10127. second: 'h:mm:ss a', // 11:20:01 AM
  10128. minute: 'h:mm:ss a', // 11:20:01 AM
  10129. hour: 'MMM D, hA', // Sept 4, 5PM
  10130. day: 'll', // Sep 4 2015
  10131. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  10132. month: 'MMM YYYY', // Sept 2015
  10133. quarter: '[Q]Q - YYYY', // Q3
  10134. year: 'YYYY' // 2015
  10135. }
  10136. },
  10137. ticks: {
  10138. autoSkip: false
  10139. }
  10140. };
  10141. var TimeScale = Chart.Scale.extend({
  10142. initialize: function() {
  10143. if (!moment) {
  10144. 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');
  10145. }
  10146. Chart.Scale.prototype.initialize.call(this);
  10147. },
  10148. getLabelMoment: function(datasetIndex, index) {
  10149. if (datasetIndex === null || index === null) {
  10150. return null;
  10151. }
  10152. if (typeof this.labelMoments[datasetIndex] !== 'undefined') {
  10153. return this.labelMoments[datasetIndex][index];
  10154. }
  10155. return null;
  10156. },
  10157. getLabelDiff: function(datasetIndex, index) {
  10158. var me = this;
  10159. if (datasetIndex === null || index === null) {
  10160. return null;
  10161. }
  10162. if (me.labelDiffs === undefined) {
  10163. me.buildLabelDiffs();
  10164. }
  10165. if (typeof me.labelDiffs[datasetIndex] !== 'undefined') {
  10166. return me.labelDiffs[datasetIndex][index];
  10167. }
  10168. return null;
  10169. },
  10170. getMomentStartOf: function(tick) {
  10171. var me = this;
  10172. if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) {
  10173. return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday);
  10174. }
  10175. return tick.clone().startOf(me.tickUnit);
  10176. },
  10177. determineDataLimits: function() {
  10178. var me = this;
  10179. me.labelMoments = [];
  10180. // Only parse these once. If the dataset does not have data as x,y pairs, we will use
  10181. // these
  10182. var scaleLabelMoments = [];
  10183. if (me.chart.data.labels && me.chart.data.labels.length > 0) {
  10184. helpers.each(me.chart.data.labels, function(label) {
  10185. var labelMoment = me.parseTime(label);
  10186. if (labelMoment.isValid()) {
  10187. if (me.options.time.round) {
  10188. labelMoment.startOf(me.options.time.round);
  10189. }
  10190. scaleLabelMoments.push(labelMoment);
  10191. }
  10192. }, me);
  10193. me.firstTick = moment.min.call(me, scaleLabelMoments);
  10194. me.lastTick = moment.max.call(me, scaleLabelMoments);
  10195. } else {
  10196. me.firstTick = null;
  10197. me.lastTick = null;
  10198. }
  10199. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  10200. var momentsForDataset = [];
  10201. var datasetVisible = me.chart.isDatasetVisible(datasetIndex);
  10202. if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
  10203. helpers.each(dataset.data, function(value) {
  10204. var labelMoment = me.parseTime(me.getRightValue(value));
  10205. if (labelMoment.isValid()) {
  10206. if (me.options.time.round) {
  10207. labelMoment.startOf(me.options.time.round);
  10208. }
  10209. momentsForDataset.push(labelMoment);
  10210. if (datasetVisible) {
  10211. // May have gone outside the scale ranges, make sure we keep the first and last ticks updated
  10212. me.firstTick = me.firstTick !== null ? moment.min(me.firstTick, labelMoment) : labelMoment;
  10213. me.lastTick = me.lastTick !== null ? moment.max(me.lastTick, labelMoment) : labelMoment;
  10214. }
  10215. }
  10216. }, me);
  10217. } else {
  10218. // We have no labels. Use the ones from the scale
  10219. momentsForDataset = scaleLabelMoments;
  10220. }
  10221. me.labelMoments.push(momentsForDataset);
  10222. }, me);
  10223. // Set these after we've done all the data
  10224. if (me.options.time.min) {
  10225. me.firstTick = me.parseTime(me.options.time.min);
  10226. }
  10227. if (me.options.time.max) {
  10228. me.lastTick = me.parseTime(me.options.time.max);
  10229. }
  10230. // We will modify these, so clone for later
  10231. me.firstTick = (me.firstTick || moment()).clone();
  10232. me.lastTick = (me.lastTick || moment()).clone();
  10233. },
  10234. buildLabelDiffs: function() {
  10235. var me = this;
  10236. me.labelDiffs = [];
  10237. var scaleLabelDiffs = [];
  10238. // Parse common labels once
  10239. if (me.chart.data.labels && me.chart.data.labels.length > 0) {
  10240. helpers.each(me.chart.data.labels, function(label) {
  10241. var labelMoment = me.parseTime(label);
  10242. if (labelMoment.isValid()) {
  10243. if (me.options.time.round) {
  10244. labelMoment.startOf(me.options.time.round);
  10245. }
  10246. scaleLabelDiffs.push(labelMoment.diff(me.firstTick, me.tickUnit, true));
  10247. }
  10248. }, me);
  10249. }
  10250. helpers.each(me.chart.data.datasets, function(dataset) {
  10251. var diffsForDataset = [];
  10252. if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
  10253. helpers.each(dataset.data, function(value) {
  10254. var labelMoment = me.parseTime(me.getRightValue(value));
  10255. if (labelMoment.isValid()) {
  10256. if (me.options.time.round) {
  10257. labelMoment.startOf(me.options.time.round);
  10258. }
  10259. diffsForDataset.push(labelMoment.diff(me.firstTick, me.tickUnit, true));
  10260. }
  10261. }, me);
  10262. } else {
  10263. // We have no labels. Use common ones
  10264. diffsForDataset = scaleLabelDiffs;
  10265. }
  10266. me.labelDiffs.push(diffsForDataset);
  10267. }, me);
  10268. },
  10269. buildTicks: function() {
  10270. var me = this;
  10271. me.ctx.save();
  10272. var tickFontSize = helpers.getValueOrDefault(me.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  10273. var tickFontStyle = helpers.getValueOrDefault(me.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  10274. var tickFontFamily = helpers.getValueOrDefault(me.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  10275. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  10276. me.ctx.font = tickLabelFont;
  10277. me.ticks = [];
  10278. me.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
  10279. me.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
  10280. // Set unit override if applicable
  10281. if (me.options.time.unit) {
  10282. me.tickUnit = me.options.time.unit || 'day';
  10283. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  10284. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  10285. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, 1);
  10286. } else {
  10287. // Determine the smallest needed unit of the time
  10288. var innerWidth = me.isHorizontal() ? me.width : me.height;
  10289. // Crude approximation of what the label length might be
  10290. var tempFirstLabel = me.tickFormatFunction(me.firstTick, 0, []);
  10291. var tickLabelWidth = me.ctx.measureText(tempFirstLabel).width;
  10292. var cosRotation = Math.cos(helpers.toRadians(me.options.ticks.maxRotation));
  10293. var sinRotation = Math.sin(helpers.toRadians(me.options.ticks.maxRotation));
  10294. tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  10295. var labelCapacity = innerWidth / (tickLabelWidth);
  10296. // Start as small as possible
  10297. me.tickUnit = me.options.time.minUnit;
  10298. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  10299. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  10300. var unitDefinitionIndex = 0;
  10301. var unitDefinition = time.units[unitDefinitionIndex];
  10302. // While we aren't ideal and we don't have units left
  10303. while (unitDefinitionIndex < time.units.length) {
  10304. // Can we scale this unit. If `false` we can scale infinitely
  10305. me.unitScale = 1;
  10306. if (helpers.isArray(unitDefinition.steps) && Math.ceil(me.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
  10307. // Use one of the predefined steps
  10308. for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
  10309. if (unitDefinition.steps[idx] >= Math.ceil(me.scaleSizeInUnits / labelCapacity)) {
  10310. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, unitDefinition.steps[idx]);
  10311. break;
  10312. }
  10313. }
  10314. break;
  10315. } else if ((unitDefinition.maxStep === false) || (Math.ceil(me.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
  10316. // We have a max step. Scale this unit
  10317. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, Math.ceil(me.scaleSizeInUnits / labelCapacity));
  10318. break;
  10319. } else {
  10320. // Move to the next unit up
  10321. ++unitDefinitionIndex;
  10322. unitDefinition = time.units[unitDefinitionIndex];
  10323. me.tickUnit = unitDefinition.name;
  10324. var leadingUnitBuffer = me.firstTick.diff(me.getMomentStartOf(me.firstTick), me.tickUnit, true);
  10325. var trailingUnitBuffer = me.getMomentStartOf(me.lastTick.clone().add(1, me.tickUnit)).diff(me.lastTick, me.tickUnit, true);
  10326. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
  10327. me.displayFormat = me.options.time.displayFormats[unitDefinition.name];
  10328. }
  10329. }
  10330. }
  10331. var roundedStart;
  10332. // Only round the first tick if we have no hard minimum
  10333. if (!me.options.time.min) {
  10334. me.firstTick = me.getMomentStartOf(me.firstTick);
  10335. roundedStart = me.firstTick;
  10336. } else {
  10337. roundedStart = me.getMomentStartOf(me.firstTick);
  10338. }
  10339. // Only round the last tick if we have no hard maximum
  10340. if (!me.options.time.max) {
  10341. var roundedEnd = me.getMomentStartOf(me.lastTick);
  10342. var delta = roundedEnd.diff(me.lastTick, me.tickUnit, true);
  10343. if (delta < 0) {
  10344. // Do not use end of because we need me to be in the next time unit
  10345. me.lastTick = me.getMomentStartOf(me.lastTick.add(1, me.tickUnit));
  10346. } else if (delta >= 0) {
  10347. me.lastTick = roundedEnd;
  10348. }
  10349. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  10350. }
  10351. // Tick displayFormat override
  10352. if (me.options.time.displayFormat) {
  10353. me.displayFormat = me.options.time.displayFormat;
  10354. }
  10355. // first tick. will have been rounded correctly if options.time.min is not specified
  10356. me.ticks.push(me.firstTick.clone());
  10357. // For every unit in between the first and last moment, create a moment and add it to the ticks tick
  10358. for (var i = me.unitScale; i <= me.scaleSizeInUnits; i += me.unitScale) {
  10359. var newTick = roundedStart.clone().add(i, me.tickUnit);
  10360. // Are we greater than the max time
  10361. if (me.options.time.max && newTick.diff(me.lastTick, me.tickUnit, true) >= 0) {
  10362. break;
  10363. }
  10364. me.ticks.push(newTick);
  10365. }
  10366. // Always show the right tick
  10367. var diff = me.ticks[me.ticks.length - 1].diff(me.lastTick, me.tickUnit);
  10368. if (diff !== 0 || me.scaleSizeInUnits === 0) {
  10369. // 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
  10370. // but the last tick was not rounded.
  10371. if (me.options.time.max) {
  10372. me.ticks.push(me.lastTick.clone());
  10373. me.scaleSizeInUnits = me.lastTick.diff(me.ticks[0], me.tickUnit, true);
  10374. } else {
  10375. // me.ticks.push(me.lastTick.clone());
  10376. // me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  10377. }
  10378. }
  10379. me.ctx.restore();
  10380. // Invalidate label diffs cache
  10381. me.labelDiffs = undefined;
  10382. },
  10383. // Get tooltip label
  10384. getLabelForIndex: function(index, datasetIndex) {
  10385. var me = this;
  10386. var label = me.chart.data.labels && index < me.chart.data.labels.length ? me.chart.data.labels[index] : '';
  10387. var value = me.chart.data.datasets[datasetIndex].data[index];
  10388. if (value !== null && typeof value === 'object') {
  10389. label = me.getRightValue(value);
  10390. }
  10391. // Format nicely
  10392. if (me.options.time.tooltipFormat) {
  10393. label = me.parseTime(label).format(me.options.time.tooltipFormat);
  10394. }
  10395. return label;
  10396. },
  10397. // Function to format an individual tick mark
  10398. tickFormatFunction: function(tick, index, ticks) {
  10399. var formattedTick = tick.format(this.displayFormat);
  10400. var tickOpts = this.options.ticks;
  10401. var callback = helpers.getValueOrDefault(tickOpts.callback, tickOpts.userCallback);
  10402. if (callback) {
  10403. return callback(formattedTick, index, ticks);
  10404. }
  10405. return formattedTick;
  10406. },
  10407. convertTicksToLabels: function() {
  10408. var me = this;
  10409. me.tickMoments = me.ticks;
  10410. me.ticks = me.ticks.map(me.tickFormatFunction, me);
  10411. },
  10412. getPixelForValue: function(value, index, datasetIndex) {
  10413. var me = this;
  10414. var offset = null;
  10415. if (index !== undefined && datasetIndex !== undefined) {
  10416. offset = me.getLabelDiff(datasetIndex, index);
  10417. }
  10418. if (offset === null) {
  10419. if (!value || !value.isValid) {
  10420. // not already a moment object
  10421. value = me.parseTime(me.getRightValue(value));
  10422. }
  10423. if (value && value.isValid && value.isValid()) {
  10424. offset = value.diff(me.firstTick, me.tickUnit, true);
  10425. }
  10426. }
  10427. if (offset !== null) {
  10428. var decimal = offset !== 0 ? offset / me.scaleSizeInUnits : offset;
  10429. if (me.isHorizontal()) {
  10430. var valueOffset = (me.width * decimal);
  10431. return me.left + Math.round(valueOffset);
  10432. }
  10433. var heightOffset = (me.height * decimal);
  10434. return me.top + Math.round(heightOffset);
  10435. }
  10436. },
  10437. getPixelForTick: function(index) {
  10438. return this.getPixelForValue(this.tickMoments[index], null, null);
  10439. },
  10440. getValueForPixel: function(pixel) {
  10441. var me = this;
  10442. var innerDimension = me.isHorizontal() ? me.width : me.height;
  10443. var offset = (pixel - (me.isHorizontal() ? me.left : me.top)) / innerDimension;
  10444. offset *= me.scaleSizeInUnits;
  10445. return me.firstTick.clone().add(moment.duration(offset, me.tickUnit).asSeconds(), 'seconds');
  10446. },
  10447. parseTime: function(label) {
  10448. var me = this;
  10449. if (typeof me.options.time.parser === 'string') {
  10450. return moment(label, me.options.time.parser);
  10451. }
  10452. if (typeof me.options.time.parser === 'function') {
  10453. return me.options.time.parser(label);
  10454. }
  10455. // Date objects
  10456. if (typeof label.getMonth === 'function' || typeof label === 'number') {
  10457. return moment(label);
  10458. }
  10459. // Moment support
  10460. if (label.isValid && label.isValid()) {
  10461. return label;
  10462. }
  10463. // Custom parsing (return an instance of moment)
  10464. if (typeof me.options.time.format !== 'string' && me.options.time.format.call) {
  10465. 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');
  10466. return me.options.time.format(label);
  10467. }
  10468. // Moment format parsing
  10469. return moment(label, me.options.time.format);
  10470. }
  10471. });
  10472. Chart.scaleService.registerScaleType('time', TimeScale, defaultConfig);
  10473. };
  10474. },{"1":1}]},{},[7])(7)
  10475. });