Chart.js 306 KB

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