Chart.js 393 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.7.3
  5. *
  6. * Copyright 2018 Chart.js Contributors
  7. * Released under the MIT license
  8. * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md
  9. */
  10. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Chart = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  11. },{}],2:[function(require,module,exports){
  12. /* MIT license */
  13. var colorNames = require(6);
  14. module.exports = {
  15. getRgba: getRgba,
  16. getHsla: getHsla,
  17. getRgb: getRgb,
  18. getHsl: getHsl,
  19. getHwb: getHwb,
  20. getAlpha: getAlpha,
  21. hexString: hexString,
  22. rgbString: rgbString,
  23. rgbaString: rgbaString,
  24. percentString: percentString,
  25. percentaString: percentaString,
  26. hslString: hslString,
  27. hslaString: hslaString,
  28. hwbString: hwbString,
  29. keyword: keyword
  30. }
  31. function getRgba(string) {
  32. if (!string) {
  33. return;
  34. }
  35. var abbr = /^#([a-fA-F0-9]{3})$/i,
  36. hex = /^#([a-fA-F0-9]{6})$/i,
  37. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  38. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  39. keyword = /(\w+)/;
  40. var rgb = [0, 0, 0],
  41. a = 1,
  42. match = string.match(abbr);
  43. if (match) {
  44. match = match[1];
  45. for (var i = 0; i < rgb.length; i++) {
  46. rgb[i] = parseInt(match[i] + match[i], 16);
  47. }
  48. }
  49. else if (match = string.match(hex)) {
  50. match = match[1];
  51. for (var i = 0; i < rgb.length; i++) {
  52. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  53. }
  54. }
  55. else if (match = string.match(rgba)) {
  56. for (var i = 0; i < rgb.length; i++) {
  57. rgb[i] = parseInt(match[i + 1]);
  58. }
  59. a = parseFloat(match[4]);
  60. }
  61. else if (match = string.match(per)) {
  62. for (var i = 0; i < rgb.length; i++) {
  63. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  64. }
  65. a = parseFloat(match[4]);
  66. }
  67. else if (match = string.match(keyword)) {
  68. if (match[1] == "transparent") {
  69. return [0, 0, 0, 0];
  70. }
  71. rgb = colorNames[match[1]];
  72. if (!rgb) {
  73. return;
  74. }
  75. }
  76. for (var i = 0; i < rgb.length; i++) {
  77. rgb[i] = scale(rgb[i], 0, 255);
  78. }
  79. if (!a && a != 0) {
  80. a = 1;
  81. }
  82. else {
  83. a = scale(a, 0, 1);
  84. }
  85. rgb[3] = a;
  86. return rgb;
  87. }
  88. function getHsla(string) {
  89. if (!string) {
  90. return;
  91. }
  92. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  93. var match = string.match(hsl);
  94. if (match) {
  95. var alpha = parseFloat(match[4]);
  96. var h = scale(parseInt(match[1]), 0, 360),
  97. s = scale(parseFloat(match[2]), 0, 100),
  98. l = scale(parseFloat(match[3]), 0, 100),
  99. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  100. return [h, s, l, a];
  101. }
  102. }
  103. function getHwb(string) {
  104. if (!string) {
  105. return;
  106. }
  107. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  108. var match = string.match(hwb);
  109. if (match) {
  110. var alpha = parseFloat(match[4]);
  111. var h = scale(parseInt(match[1]), 0, 360),
  112. w = scale(parseFloat(match[2]), 0, 100),
  113. b = scale(parseFloat(match[3]), 0, 100),
  114. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  115. return [h, w, b, a];
  116. }
  117. }
  118. function getRgb(string) {
  119. var rgba = getRgba(string);
  120. return rgba && rgba.slice(0, 3);
  121. }
  122. function getHsl(string) {
  123. var hsla = getHsla(string);
  124. return hsla && hsla.slice(0, 3);
  125. }
  126. function getAlpha(string) {
  127. var vals = getRgba(string);
  128. if (vals) {
  129. return vals[3];
  130. }
  131. else if (vals = getHsla(string)) {
  132. return vals[3];
  133. }
  134. else if (vals = getHwb(string)) {
  135. return vals[3];
  136. }
  137. }
  138. // generators
  139. function hexString(rgb) {
  140. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  141. + hexDouble(rgb[2]);
  142. }
  143. function rgbString(rgba, alpha) {
  144. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  145. return rgbaString(rgba, alpha);
  146. }
  147. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  148. }
  149. function rgbaString(rgba, alpha) {
  150. if (alpha === undefined) {
  151. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  152. }
  153. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  154. + ", " + alpha + ")";
  155. }
  156. function percentString(rgba, alpha) {
  157. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  158. return percentaString(rgba, alpha);
  159. }
  160. var r = Math.round(rgba[0]/255 * 100),
  161. g = Math.round(rgba[1]/255 * 100),
  162. b = Math.round(rgba[2]/255 * 100);
  163. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  164. }
  165. function percentaString(rgba, alpha) {
  166. var r = Math.round(rgba[0]/255 * 100),
  167. g = Math.round(rgba[1]/255 * 100),
  168. b = Math.round(rgba[2]/255 * 100);
  169. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  170. }
  171. function hslString(hsla, alpha) {
  172. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  173. return hslaString(hsla, alpha);
  174. }
  175. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  176. }
  177. function hslaString(hsla, alpha) {
  178. if (alpha === undefined) {
  179. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  180. }
  181. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  182. + alpha + ")";
  183. }
  184. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  185. // (hwb have alpha optional & 1 is default value)
  186. function hwbString(hwb, alpha) {
  187. if (alpha === undefined) {
  188. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  189. }
  190. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  191. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  192. }
  193. function keyword(rgb) {
  194. return reverseNames[rgb.slice(0, 3)];
  195. }
  196. // helpers
  197. function scale(num, min, max) {
  198. return Math.min(Math.max(min, num), max);
  199. }
  200. function hexDouble(num) {
  201. var str = num.toString(16).toUpperCase();
  202. return (str.length < 2) ? "0" + str : str;
  203. }
  204. //create a list of reverse color names
  205. var reverseNames = {};
  206. for (var name in colorNames) {
  207. reverseNames[colorNames[name]] = name;
  208. }
  209. },{"6":6}],3:[function(require,module,exports){
  210. /* MIT license */
  211. var convert = require(5);
  212. var string = require(2);
  213. var Color = function (obj) {
  214. if (obj instanceof Color) {
  215. return obj;
  216. }
  217. if (!(this instanceof Color)) {
  218. return new Color(obj);
  219. }
  220. this.valid = false;
  221. this.values = {
  222. rgb: [0, 0, 0],
  223. hsl: [0, 0, 0],
  224. hsv: [0, 0, 0],
  225. hwb: [0, 0, 0],
  226. cmyk: [0, 0, 0, 0],
  227. alpha: 1
  228. };
  229. // parse Color() argument
  230. var vals;
  231. if (typeof obj === 'string') {
  232. vals = string.getRgba(obj);
  233. if (vals) {
  234. this.setValues('rgb', vals);
  235. } else if (vals = string.getHsla(obj)) {
  236. this.setValues('hsl', vals);
  237. } else if (vals = string.getHwb(obj)) {
  238. this.setValues('hwb', vals);
  239. }
  240. } else if (typeof obj === 'object') {
  241. vals = obj;
  242. if (vals.r !== undefined || vals.red !== undefined) {
  243. this.setValues('rgb', vals);
  244. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  245. this.setValues('hsl', vals);
  246. } else if (vals.v !== undefined || vals.value !== undefined) {
  247. this.setValues('hsv', vals);
  248. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  249. this.setValues('hwb', vals);
  250. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  251. this.setValues('cmyk', vals);
  252. }
  253. }
  254. };
  255. Color.prototype = {
  256. isValid: function () {
  257. return this.valid;
  258. },
  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. this.valid = true;
  566. if (space === 'alpha') {
  567. alpha = vals;
  568. } else if (vals.length) {
  569. // [10, 10, 10]
  570. values[space] = vals.slice(0, space.length);
  571. alpha = vals[space.length];
  572. } else if (vals[space.charAt(0)] !== undefined) {
  573. // {r: 10, g: 10, b: 10}
  574. for (i = 0; i < space.length; i++) {
  575. values[space][i] = vals[space.charAt(i)];
  576. }
  577. alpha = vals.a;
  578. } else if (vals[spaces[space][0]] !== undefined) {
  579. // {red: 10, green: 10, blue: 10}
  580. var chans = spaces[space];
  581. for (i = 0; i < space.length; i++) {
  582. values[space][i] = vals[chans[i]];
  583. }
  584. alpha = vals.alpha;
  585. }
  586. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  587. if (space === 'alpha') {
  588. return false;
  589. }
  590. var capped;
  591. // cap values of the space prior converting all values
  592. for (i = 0; i < space.length; i++) {
  593. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  594. values[space][i] = Math.round(capped);
  595. }
  596. // convert to all the other color spaces
  597. for (var sname in spaces) {
  598. if (sname !== space) {
  599. values[sname] = convert[space][sname](values[space]);
  600. }
  601. }
  602. return true;
  603. };
  604. Color.prototype.setSpace = function (space, args) {
  605. var vals = args[0];
  606. if (vals === undefined) {
  607. // color.rgb()
  608. return this.getValues(space);
  609. }
  610. // color.rgb(10, 10, 10)
  611. if (typeof vals === 'number') {
  612. vals = Array.prototype.slice.call(args);
  613. }
  614. this.setValues(space, vals);
  615. return this;
  616. };
  617. Color.prototype.setChannel = function (space, index, val) {
  618. var svalues = this.values[space];
  619. if (val === undefined) {
  620. // color.red()
  621. return svalues[index];
  622. } else if (val === svalues[index]) {
  623. // color.red(color.red())
  624. return this;
  625. }
  626. // color.red(100)
  627. svalues[index] = val;
  628. this.setValues(space, svalues);
  629. return this;
  630. };
  631. if (typeof window !== 'undefined') {
  632. window.Color = Color;
  633. }
  634. module.exports = Color;
  635. },{"2":2,"5":5}],4:[function(require,module,exports){
  636. /* MIT license */
  637. module.exports = {
  638. rgb2hsl: rgb2hsl,
  639. rgb2hsv: rgb2hsv,
  640. rgb2hwb: rgb2hwb,
  641. rgb2cmyk: rgb2cmyk,
  642. rgb2keyword: rgb2keyword,
  643. rgb2xyz: rgb2xyz,
  644. rgb2lab: rgb2lab,
  645. rgb2lch: rgb2lch,
  646. hsl2rgb: hsl2rgb,
  647. hsl2hsv: hsl2hsv,
  648. hsl2hwb: hsl2hwb,
  649. hsl2cmyk: hsl2cmyk,
  650. hsl2keyword: hsl2keyword,
  651. hsv2rgb: hsv2rgb,
  652. hsv2hsl: hsv2hsl,
  653. hsv2hwb: hsv2hwb,
  654. hsv2cmyk: hsv2cmyk,
  655. hsv2keyword: hsv2keyword,
  656. hwb2rgb: hwb2rgb,
  657. hwb2hsl: hwb2hsl,
  658. hwb2hsv: hwb2hsv,
  659. hwb2cmyk: hwb2cmyk,
  660. hwb2keyword: hwb2keyword,
  661. cmyk2rgb: cmyk2rgb,
  662. cmyk2hsl: cmyk2hsl,
  663. cmyk2hsv: cmyk2hsv,
  664. cmyk2hwb: cmyk2hwb,
  665. cmyk2keyword: cmyk2keyword,
  666. keyword2rgb: keyword2rgb,
  667. keyword2hsl: keyword2hsl,
  668. keyword2hsv: keyword2hsv,
  669. keyword2hwb: keyword2hwb,
  670. keyword2cmyk: keyword2cmyk,
  671. keyword2lab: keyword2lab,
  672. keyword2xyz: keyword2xyz,
  673. xyz2rgb: xyz2rgb,
  674. xyz2lab: xyz2lab,
  675. xyz2lch: xyz2lch,
  676. lab2xyz: lab2xyz,
  677. lab2rgb: lab2rgb,
  678. lab2lch: lab2lch,
  679. lch2lab: lch2lab,
  680. lch2xyz: lch2xyz,
  681. lch2rgb: lch2rgb
  682. }
  683. function rgb2hsl(rgb) {
  684. var r = rgb[0]/255,
  685. g = rgb[1]/255,
  686. b = rgb[2]/255,
  687. min = Math.min(r, g, b),
  688. max = Math.max(r, g, b),
  689. delta = max - min,
  690. h, s, l;
  691. if (max == min)
  692. h = 0;
  693. else if (r == max)
  694. h = (g - b) / delta;
  695. else if (g == max)
  696. h = 2 + (b - r) / delta;
  697. else if (b == max)
  698. h = 4 + (r - g)/ delta;
  699. h = Math.min(h * 60, 360);
  700. if (h < 0)
  701. h += 360;
  702. l = (min + max) / 2;
  703. if (max == min)
  704. s = 0;
  705. else if (l <= 0.5)
  706. s = delta / (max + min);
  707. else
  708. s = delta / (2 - max - min);
  709. return [h, s * 100, l * 100];
  710. }
  711. function rgb2hsv(rgb) {
  712. var r = rgb[0],
  713. g = rgb[1],
  714. b = rgb[2],
  715. min = Math.min(r, g, b),
  716. max = Math.max(r, g, b),
  717. delta = max - min,
  718. h, s, v;
  719. if (max == 0)
  720. s = 0;
  721. else
  722. s = (delta/max * 1000)/10;
  723. if (max == min)
  724. h = 0;
  725. else if (r == max)
  726. h = (g - b) / delta;
  727. else if (g == max)
  728. h = 2 + (b - r) / delta;
  729. else if (b == max)
  730. h = 4 + (r - g) / delta;
  731. h = Math.min(h * 60, 360);
  732. if (h < 0)
  733. h += 360;
  734. v = ((max / 255) * 1000) / 10;
  735. return [h, s, v];
  736. }
  737. function rgb2hwb(rgb) {
  738. var r = rgb[0],
  739. g = rgb[1],
  740. b = rgb[2],
  741. h = rgb2hsl(rgb)[0],
  742. w = 1/255 * Math.min(r, Math.min(g, b)),
  743. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  744. return [h, w * 100, b * 100];
  745. }
  746. function rgb2cmyk(rgb) {
  747. var r = rgb[0] / 255,
  748. g = rgb[1] / 255,
  749. b = rgb[2] / 255,
  750. c, m, y, k;
  751. k = Math.min(1 - r, 1 - g, 1 - b);
  752. c = (1 - r - k) / (1 - k) || 0;
  753. m = (1 - g - k) / (1 - k) || 0;
  754. y = (1 - b - k) / (1 - k) || 0;
  755. return [c * 100, m * 100, y * 100, k * 100];
  756. }
  757. function rgb2keyword(rgb) {
  758. return reverseKeywords[JSON.stringify(rgb)];
  759. }
  760. function rgb2xyz(rgb) {
  761. var r = rgb[0] / 255,
  762. g = rgb[1] / 255,
  763. b = rgb[2] / 255;
  764. // assume sRGB
  765. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  766. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  767. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  768. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  769. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  770. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  771. return [x * 100, y *100, z * 100];
  772. }
  773. function rgb2lab(rgb) {
  774. var xyz = rgb2xyz(rgb),
  775. x = xyz[0],
  776. y = xyz[1],
  777. z = xyz[2],
  778. l, a, b;
  779. x /= 95.047;
  780. y /= 100;
  781. z /= 108.883;
  782. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  783. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  784. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  785. l = (116 * y) - 16;
  786. a = 500 * (x - y);
  787. b = 200 * (y - z);
  788. return [l, a, b];
  789. }
  790. function rgb2lch(args) {
  791. return lab2lch(rgb2lab(args));
  792. }
  793. function hsl2rgb(hsl) {
  794. var h = hsl[0] / 360,
  795. s = hsl[1] / 100,
  796. l = hsl[2] / 100,
  797. t1, t2, t3, rgb, val;
  798. if (s == 0) {
  799. val = l * 255;
  800. return [val, val, val];
  801. }
  802. if (l < 0.5)
  803. t2 = l * (1 + s);
  804. else
  805. t2 = l + s - l * s;
  806. t1 = 2 * l - t2;
  807. rgb = [0, 0, 0];
  808. for (var i = 0; i < 3; i++) {
  809. t3 = h + 1 / 3 * - (i - 1);
  810. t3 < 0 && t3++;
  811. t3 > 1 && t3--;
  812. if (6 * t3 < 1)
  813. val = t1 + (t2 - t1) * 6 * t3;
  814. else if (2 * t3 < 1)
  815. val = t2;
  816. else if (3 * t3 < 2)
  817. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  818. else
  819. val = t1;
  820. rgb[i] = val * 255;
  821. }
  822. return rgb;
  823. }
  824. function hsl2hsv(hsl) {
  825. var h = hsl[0],
  826. s = hsl[1] / 100,
  827. l = hsl[2] / 100,
  828. sv, v;
  829. if(l === 0) {
  830. // no need to do calc on black
  831. // also avoids divide by 0 error
  832. return [0, 0, 0];
  833. }
  834. l *= 2;
  835. s *= (l <= 1) ? l : 2 - l;
  836. v = (l + s) / 2;
  837. sv = (2 * s) / (l + s);
  838. return [h, sv * 100, v * 100];
  839. }
  840. function hsl2hwb(args) {
  841. return rgb2hwb(hsl2rgb(args));
  842. }
  843. function hsl2cmyk(args) {
  844. return rgb2cmyk(hsl2rgb(args));
  845. }
  846. function hsl2keyword(args) {
  847. return rgb2keyword(hsl2rgb(args));
  848. }
  849. function hsv2rgb(hsv) {
  850. var h = hsv[0] / 60,
  851. s = hsv[1] / 100,
  852. v = hsv[2] / 100,
  853. hi = Math.floor(h) % 6;
  854. var f = h - Math.floor(h),
  855. p = 255 * v * (1 - s),
  856. q = 255 * v * (1 - (s * f)),
  857. t = 255 * v * (1 - (s * (1 - f))),
  858. v = 255 * v;
  859. switch(hi) {
  860. case 0:
  861. return [v, t, p];
  862. case 1:
  863. return [q, v, p];
  864. case 2:
  865. return [p, v, t];
  866. case 3:
  867. return [p, q, v];
  868. case 4:
  869. return [t, p, v];
  870. case 5:
  871. return [v, p, q];
  872. }
  873. }
  874. function hsv2hsl(hsv) {
  875. var h = hsv[0],
  876. s = hsv[1] / 100,
  877. v = hsv[2] / 100,
  878. sl, l;
  879. l = (2 - s) * v;
  880. sl = s * v;
  881. sl /= (l <= 1) ? l : 2 - l;
  882. sl = sl || 0;
  883. l /= 2;
  884. return [h, sl * 100, l * 100];
  885. }
  886. function hsv2hwb(args) {
  887. return rgb2hwb(hsv2rgb(args))
  888. }
  889. function hsv2cmyk(args) {
  890. return rgb2cmyk(hsv2rgb(args));
  891. }
  892. function hsv2keyword(args) {
  893. return rgb2keyword(hsv2rgb(args));
  894. }
  895. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  896. function hwb2rgb(hwb) {
  897. var h = hwb[0] / 360,
  898. wh = hwb[1] / 100,
  899. bl = hwb[2] / 100,
  900. ratio = wh + bl,
  901. i, v, f, n;
  902. // wh + bl cant be > 1
  903. if (ratio > 1) {
  904. wh /= ratio;
  905. bl /= ratio;
  906. }
  907. i = Math.floor(6 * h);
  908. v = 1 - bl;
  909. f = 6 * h - i;
  910. if ((i & 0x01) != 0) {
  911. f = 1 - f;
  912. }
  913. n = wh + f * (v - wh); // linear interpolation
  914. switch (i) {
  915. default:
  916. case 6:
  917. case 0: r = v; g = n; b = wh; break;
  918. case 1: r = n; g = v; b = wh; break;
  919. case 2: r = wh; g = v; b = n; break;
  920. case 3: r = wh; g = n; b = v; break;
  921. case 4: r = n; g = wh; b = v; break;
  922. case 5: r = v; g = wh; b = n; break;
  923. }
  924. return [r * 255, g * 255, b * 255];
  925. }
  926. function hwb2hsl(args) {
  927. return rgb2hsl(hwb2rgb(args));
  928. }
  929. function hwb2hsv(args) {
  930. return rgb2hsv(hwb2rgb(args));
  931. }
  932. function hwb2cmyk(args) {
  933. return rgb2cmyk(hwb2rgb(args));
  934. }
  935. function hwb2keyword(args) {
  936. return rgb2keyword(hwb2rgb(args));
  937. }
  938. function cmyk2rgb(cmyk) {
  939. var c = cmyk[0] / 100,
  940. m = cmyk[1] / 100,
  941. y = cmyk[2] / 100,
  942. k = cmyk[3] / 100,
  943. r, g, b;
  944. r = 1 - Math.min(1, c * (1 - k) + k);
  945. g = 1 - Math.min(1, m * (1 - k) + k);
  946. b = 1 - Math.min(1, y * (1 - k) + k);
  947. return [r * 255, g * 255, b * 255];
  948. }
  949. function cmyk2hsl(args) {
  950. return rgb2hsl(cmyk2rgb(args));
  951. }
  952. function cmyk2hsv(args) {
  953. return rgb2hsv(cmyk2rgb(args));
  954. }
  955. function cmyk2hwb(args) {
  956. return rgb2hwb(cmyk2rgb(args));
  957. }
  958. function cmyk2keyword(args) {
  959. return rgb2keyword(cmyk2rgb(args));
  960. }
  961. function xyz2rgb(xyz) {
  962. var x = xyz[0] / 100,
  963. y = xyz[1] / 100,
  964. z = xyz[2] / 100,
  965. r, g, b;
  966. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  967. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  968. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  969. // assume sRGB
  970. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  971. : r = (r * 12.92);
  972. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  973. : g = (g * 12.92);
  974. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  975. : b = (b * 12.92);
  976. r = Math.min(Math.max(0, r), 1);
  977. g = Math.min(Math.max(0, g), 1);
  978. b = Math.min(Math.max(0, b), 1);
  979. return [r * 255, g * 255, b * 255];
  980. }
  981. function xyz2lab(xyz) {
  982. var x = xyz[0],
  983. y = xyz[1],
  984. z = xyz[2],
  985. l, a, b;
  986. x /= 95.047;
  987. y /= 100;
  988. z /= 108.883;
  989. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  990. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  991. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  992. l = (116 * y) - 16;
  993. a = 500 * (x - y);
  994. b = 200 * (y - z);
  995. return [l, a, b];
  996. }
  997. function xyz2lch(args) {
  998. return lab2lch(xyz2lab(args));
  999. }
  1000. function lab2xyz(lab) {
  1001. var l = lab[0],
  1002. a = lab[1],
  1003. b = lab[2],
  1004. x, y, z, y2;
  1005. if (l <= 8) {
  1006. y = (l * 100) / 903.3;
  1007. y2 = (7.787 * (y / 100)) + (16 / 116);
  1008. } else {
  1009. y = 100 * Math.pow((l + 16) / 116, 3);
  1010. y2 = Math.pow(y / 100, 1/3);
  1011. }
  1012. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1013. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1014. return [x, y, z];
  1015. }
  1016. function lab2lch(lab) {
  1017. var l = lab[0],
  1018. a = lab[1],
  1019. b = lab[2],
  1020. hr, h, c;
  1021. hr = Math.atan2(b, a);
  1022. h = hr * 360 / 2 / Math.PI;
  1023. if (h < 0) {
  1024. h += 360;
  1025. }
  1026. c = Math.sqrt(a * a + b * b);
  1027. return [l, c, h];
  1028. }
  1029. function lab2rgb(args) {
  1030. return xyz2rgb(lab2xyz(args));
  1031. }
  1032. function lch2lab(lch) {
  1033. var l = lch[0],
  1034. c = lch[1],
  1035. h = lch[2],
  1036. a, b, hr;
  1037. hr = h / 360 * 2 * Math.PI;
  1038. a = c * Math.cos(hr);
  1039. b = c * Math.sin(hr);
  1040. return [l, a, b];
  1041. }
  1042. function lch2xyz(args) {
  1043. return lab2xyz(lch2lab(args));
  1044. }
  1045. function lch2rgb(args) {
  1046. return lab2rgb(lch2lab(args));
  1047. }
  1048. function keyword2rgb(keyword) {
  1049. return cssKeywords[keyword];
  1050. }
  1051. function keyword2hsl(args) {
  1052. return rgb2hsl(keyword2rgb(args));
  1053. }
  1054. function keyword2hsv(args) {
  1055. return rgb2hsv(keyword2rgb(args));
  1056. }
  1057. function keyword2hwb(args) {
  1058. return rgb2hwb(keyword2rgb(args));
  1059. }
  1060. function keyword2cmyk(args) {
  1061. return rgb2cmyk(keyword2rgb(args));
  1062. }
  1063. function keyword2lab(args) {
  1064. return rgb2lab(keyword2rgb(args));
  1065. }
  1066. function keyword2xyz(args) {
  1067. return rgb2xyz(keyword2rgb(args));
  1068. }
  1069. var cssKeywords = {
  1070. aliceblue: [240,248,255],
  1071. antiquewhite: [250,235,215],
  1072. aqua: [0,255,255],
  1073. aquamarine: [127,255,212],
  1074. azure: [240,255,255],
  1075. beige: [245,245,220],
  1076. bisque: [255,228,196],
  1077. black: [0,0,0],
  1078. blanchedalmond: [255,235,205],
  1079. blue: [0,0,255],
  1080. blueviolet: [138,43,226],
  1081. brown: [165,42,42],
  1082. burlywood: [222,184,135],
  1083. cadetblue: [95,158,160],
  1084. chartreuse: [127,255,0],
  1085. chocolate: [210,105,30],
  1086. coral: [255,127,80],
  1087. cornflowerblue: [100,149,237],
  1088. cornsilk: [255,248,220],
  1089. crimson: [220,20,60],
  1090. cyan: [0,255,255],
  1091. darkblue: [0,0,139],
  1092. darkcyan: [0,139,139],
  1093. darkgoldenrod: [184,134,11],
  1094. darkgray: [169,169,169],
  1095. darkgreen: [0,100,0],
  1096. darkgrey: [169,169,169],
  1097. darkkhaki: [189,183,107],
  1098. darkmagenta: [139,0,139],
  1099. darkolivegreen: [85,107,47],
  1100. darkorange: [255,140,0],
  1101. darkorchid: [153,50,204],
  1102. darkred: [139,0,0],
  1103. darksalmon: [233,150,122],
  1104. darkseagreen: [143,188,143],
  1105. darkslateblue: [72,61,139],
  1106. darkslategray: [47,79,79],
  1107. darkslategrey: [47,79,79],
  1108. darkturquoise: [0,206,209],
  1109. darkviolet: [148,0,211],
  1110. deeppink: [255,20,147],
  1111. deepskyblue: [0,191,255],
  1112. dimgray: [105,105,105],
  1113. dimgrey: [105,105,105],
  1114. dodgerblue: [30,144,255],
  1115. firebrick: [178,34,34],
  1116. floralwhite: [255,250,240],
  1117. forestgreen: [34,139,34],
  1118. fuchsia: [255,0,255],
  1119. gainsboro: [220,220,220],
  1120. ghostwhite: [248,248,255],
  1121. gold: [255,215,0],
  1122. goldenrod: [218,165,32],
  1123. gray: [128,128,128],
  1124. green: [0,128,0],
  1125. greenyellow: [173,255,47],
  1126. grey: [128,128,128],
  1127. honeydew: [240,255,240],
  1128. hotpink: [255,105,180],
  1129. indianred: [205,92,92],
  1130. indigo: [75,0,130],
  1131. ivory: [255,255,240],
  1132. khaki: [240,230,140],
  1133. lavender: [230,230,250],
  1134. lavenderblush: [255,240,245],
  1135. lawngreen: [124,252,0],
  1136. lemonchiffon: [255,250,205],
  1137. lightblue: [173,216,230],
  1138. lightcoral: [240,128,128],
  1139. lightcyan: [224,255,255],
  1140. lightgoldenrodyellow: [250,250,210],
  1141. lightgray: [211,211,211],
  1142. lightgreen: [144,238,144],
  1143. lightgrey: [211,211,211],
  1144. lightpink: [255,182,193],
  1145. lightsalmon: [255,160,122],
  1146. lightseagreen: [32,178,170],
  1147. lightskyblue: [135,206,250],
  1148. lightslategray: [119,136,153],
  1149. lightslategrey: [119,136,153],
  1150. lightsteelblue: [176,196,222],
  1151. lightyellow: [255,255,224],
  1152. lime: [0,255,0],
  1153. limegreen: [50,205,50],
  1154. linen: [250,240,230],
  1155. magenta: [255,0,255],
  1156. maroon: [128,0,0],
  1157. mediumaquamarine: [102,205,170],
  1158. mediumblue: [0,0,205],
  1159. mediumorchid: [186,85,211],
  1160. mediumpurple: [147,112,219],
  1161. mediumseagreen: [60,179,113],
  1162. mediumslateblue: [123,104,238],
  1163. mediumspringgreen: [0,250,154],
  1164. mediumturquoise: [72,209,204],
  1165. mediumvioletred: [199,21,133],
  1166. midnightblue: [25,25,112],
  1167. mintcream: [245,255,250],
  1168. mistyrose: [255,228,225],
  1169. moccasin: [255,228,181],
  1170. navajowhite: [255,222,173],
  1171. navy: [0,0,128],
  1172. oldlace: [253,245,230],
  1173. olive: [128,128,0],
  1174. olivedrab: [107,142,35],
  1175. orange: [255,165,0],
  1176. orangered: [255,69,0],
  1177. orchid: [218,112,214],
  1178. palegoldenrod: [238,232,170],
  1179. palegreen: [152,251,152],
  1180. paleturquoise: [175,238,238],
  1181. palevioletred: [219,112,147],
  1182. papayawhip: [255,239,213],
  1183. peachpuff: [255,218,185],
  1184. peru: [205,133,63],
  1185. pink: [255,192,203],
  1186. plum: [221,160,221],
  1187. powderblue: [176,224,230],
  1188. purple: [128,0,128],
  1189. rebeccapurple: [102, 51, 153],
  1190. red: [255,0,0],
  1191. rosybrown: [188,143,143],
  1192. royalblue: [65,105,225],
  1193. saddlebrown: [139,69,19],
  1194. salmon: [250,128,114],
  1195. sandybrown: [244,164,96],
  1196. seagreen: [46,139,87],
  1197. seashell: [255,245,238],
  1198. sienna: [160,82,45],
  1199. silver: [192,192,192],
  1200. skyblue: [135,206,235],
  1201. slateblue: [106,90,205],
  1202. slategray: [112,128,144],
  1203. slategrey: [112,128,144],
  1204. snow: [255,250,250],
  1205. springgreen: [0,255,127],
  1206. steelblue: [70,130,180],
  1207. tan: [210,180,140],
  1208. teal: [0,128,128],
  1209. thistle: [216,191,216],
  1210. tomato: [255,99,71],
  1211. turquoise: [64,224,208],
  1212. violet: [238,130,238],
  1213. wheat: [245,222,179],
  1214. white: [255,255,255],
  1215. whitesmoke: [245,245,245],
  1216. yellow: [255,255,0],
  1217. yellowgreen: [154,205,50]
  1218. };
  1219. var reverseKeywords = {};
  1220. for (var key in cssKeywords) {
  1221. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1222. }
  1223. },{}],5:[function(require,module,exports){
  1224. var conversions = require(4);
  1225. var convert = function() {
  1226. return new Converter();
  1227. }
  1228. for (var func in conversions) {
  1229. // export Raw versions
  1230. convert[func + "Raw"] = (function(func) {
  1231. // accept array or plain args
  1232. return function(arg) {
  1233. if (typeof arg == "number")
  1234. arg = Array.prototype.slice.call(arguments);
  1235. return conversions[func](arg);
  1236. }
  1237. })(func);
  1238. var pair = /(\w+)2(\w+)/.exec(func),
  1239. from = pair[1],
  1240. to = pair[2];
  1241. // export rgb2hsl and ["rgb"]["hsl"]
  1242. convert[from] = convert[from] || {};
  1243. convert[from][to] = convert[func] = (function(func) {
  1244. return function(arg) {
  1245. if (typeof arg == "number")
  1246. arg = Array.prototype.slice.call(arguments);
  1247. var val = conversions[func](arg);
  1248. if (typeof val == "string" || val === undefined)
  1249. return val; // keyword
  1250. for (var i = 0; i < val.length; i++)
  1251. val[i] = Math.round(val[i]);
  1252. return val;
  1253. }
  1254. })(func);
  1255. }
  1256. /* Converter does lazy conversion and caching */
  1257. var Converter = function() {
  1258. this.convs = {};
  1259. };
  1260. /* Either get the values for a space or
  1261. set the values for a space, depending on args */
  1262. Converter.prototype.routeSpace = function(space, args) {
  1263. var values = args[0];
  1264. if (values === undefined) {
  1265. // color.rgb()
  1266. return this.getValues(space);
  1267. }
  1268. // color.rgb(10, 10, 10)
  1269. if (typeof values == "number") {
  1270. values = Array.prototype.slice.call(args);
  1271. }
  1272. return this.setValues(space, values);
  1273. };
  1274. /* Set the values for a space, invalidating cache */
  1275. Converter.prototype.setValues = function(space, values) {
  1276. this.space = space;
  1277. this.convs = {};
  1278. this.convs[space] = values;
  1279. return this;
  1280. };
  1281. /* Get the values for a space. If there's already
  1282. a conversion for the space, fetch it, otherwise
  1283. compute it */
  1284. Converter.prototype.getValues = function(space) {
  1285. var vals = this.convs[space];
  1286. if (!vals) {
  1287. var fspace = this.space,
  1288. from = this.convs[fspace];
  1289. vals = convert[fspace][space](from);
  1290. this.convs[space] = vals;
  1291. }
  1292. return vals;
  1293. };
  1294. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  1295. Converter.prototype[space] = function(vals) {
  1296. return this.routeSpace(space, arguments);
  1297. }
  1298. });
  1299. module.exports = convert;
  1300. },{"4":4}],6:[function(require,module,exports){
  1301. 'use strict'
  1302. module.exports = {
  1303. "aliceblue": [240, 248, 255],
  1304. "antiquewhite": [250, 235, 215],
  1305. "aqua": [0, 255, 255],
  1306. "aquamarine": [127, 255, 212],
  1307. "azure": [240, 255, 255],
  1308. "beige": [245, 245, 220],
  1309. "bisque": [255, 228, 196],
  1310. "black": [0, 0, 0],
  1311. "blanchedalmond": [255, 235, 205],
  1312. "blue": [0, 0, 255],
  1313. "blueviolet": [138, 43, 226],
  1314. "brown": [165, 42, 42],
  1315. "burlywood": [222, 184, 135],
  1316. "cadetblue": [95, 158, 160],
  1317. "chartreuse": [127, 255, 0],
  1318. "chocolate": [210, 105, 30],
  1319. "coral": [255, 127, 80],
  1320. "cornflowerblue": [100, 149, 237],
  1321. "cornsilk": [255, 248, 220],
  1322. "crimson": [220, 20, 60],
  1323. "cyan": [0, 255, 255],
  1324. "darkblue": [0, 0, 139],
  1325. "darkcyan": [0, 139, 139],
  1326. "darkgoldenrod": [184, 134, 11],
  1327. "darkgray": [169, 169, 169],
  1328. "darkgreen": [0, 100, 0],
  1329. "darkgrey": [169, 169, 169],
  1330. "darkkhaki": [189, 183, 107],
  1331. "darkmagenta": [139, 0, 139],
  1332. "darkolivegreen": [85, 107, 47],
  1333. "darkorange": [255, 140, 0],
  1334. "darkorchid": [153, 50, 204],
  1335. "darkred": [139, 0, 0],
  1336. "darksalmon": [233, 150, 122],
  1337. "darkseagreen": [143, 188, 143],
  1338. "darkslateblue": [72, 61, 139],
  1339. "darkslategray": [47, 79, 79],
  1340. "darkslategrey": [47, 79, 79],
  1341. "darkturquoise": [0, 206, 209],
  1342. "darkviolet": [148, 0, 211],
  1343. "deeppink": [255, 20, 147],
  1344. "deepskyblue": [0, 191, 255],
  1345. "dimgray": [105, 105, 105],
  1346. "dimgrey": [105, 105, 105],
  1347. "dodgerblue": [30, 144, 255],
  1348. "firebrick": [178, 34, 34],
  1349. "floralwhite": [255, 250, 240],
  1350. "forestgreen": [34, 139, 34],
  1351. "fuchsia": [255, 0, 255],
  1352. "gainsboro": [220, 220, 220],
  1353. "ghostwhite": [248, 248, 255],
  1354. "gold": [255, 215, 0],
  1355. "goldenrod": [218, 165, 32],
  1356. "gray": [128, 128, 128],
  1357. "green": [0, 128, 0],
  1358. "greenyellow": [173, 255, 47],
  1359. "grey": [128, 128, 128],
  1360. "honeydew": [240, 255, 240],
  1361. "hotpink": [255, 105, 180],
  1362. "indianred": [205, 92, 92],
  1363. "indigo": [75, 0, 130],
  1364. "ivory": [255, 255, 240],
  1365. "khaki": [240, 230, 140],
  1366. "lavender": [230, 230, 250],
  1367. "lavenderblush": [255, 240, 245],
  1368. "lawngreen": [124, 252, 0],
  1369. "lemonchiffon": [255, 250, 205],
  1370. "lightblue": [173, 216, 230],
  1371. "lightcoral": [240, 128, 128],
  1372. "lightcyan": [224, 255, 255],
  1373. "lightgoldenrodyellow": [250, 250, 210],
  1374. "lightgray": [211, 211, 211],
  1375. "lightgreen": [144, 238, 144],
  1376. "lightgrey": [211, 211, 211],
  1377. "lightpink": [255, 182, 193],
  1378. "lightsalmon": [255, 160, 122],
  1379. "lightseagreen": [32, 178, 170],
  1380. "lightskyblue": [135, 206, 250],
  1381. "lightslategray": [119, 136, 153],
  1382. "lightslategrey": [119, 136, 153],
  1383. "lightsteelblue": [176, 196, 222],
  1384. "lightyellow": [255, 255, 224],
  1385. "lime": [0, 255, 0],
  1386. "limegreen": [50, 205, 50],
  1387. "linen": [250, 240, 230],
  1388. "magenta": [255, 0, 255],
  1389. "maroon": [128, 0, 0],
  1390. "mediumaquamarine": [102, 205, 170],
  1391. "mediumblue": [0, 0, 205],
  1392. "mediumorchid": [186, 85, 211],
  1393. "mediumpurple": [147, 112, 219],
  1394. "mediumseagreen": [60, 179, 113],
  1395. "mediumslateblue": [123, 104, 238],
  1396. "mediumspringgreen": [0, 250, 154],
  1397. "mediumturquoise": [72, 209, 204],
  1398. "mediumvioletred": [199, 21, 133],
  1399. "midnightblue": [25, 25, 112],
  1400. "mintcream": [245, 255, 250],
  1401. "mistyrose": [255, 228, 225],
  1402. "moccasin": [255, 228, 181],
  1403. "navajowhite": [255, 222, 173],
  1404. "navy": [0, 0, 128],
  1405. "oldlace": [253, 245, 230],
  1406. "olive": [128, 128, 0],
  1407. "olivedrab": [107, 142, 35],
  1408. "orange": [255, 165, 0],
  1409. "orangered": [255, 69, 0],
  1410. "orchid": [218, 112, 214],
  1411. "palegoldenrod": [238, 232, 170],
  1412. "palegreen": [152, 251, 152],
  1413. "paleturquoise": [175, 238, 238],
  1414. "palevioletred": [219, 112, 147],
  1415. "papayawhip": [255, 239, 213],
  1416. "peachpuff": [255, 218, 185],
  1417. "peru": [205, 133, 63],
  1418. "pink": [255, 192, 203],
  1419. "plum": [221, 160, 221],
  1420. "powderblue": [176, 224, 230],
  1421. "purple": [128, 0, 128],
  1422. "rebeccapurple": [102, 51, 153],
  1423. "red": [255, 0, 0],
  1424. "rosybrown": [188, 143, 143],
  1425. "royalblue": [65, 105, 225],
  1426. "saddlebrown": [139, 69, 19],
  1427. "salmon": [250, 128, 114],
  1428. "sandybrown": [244, 164, 96],
  1429. "seagreen": [46, 139, 87],
  1430. "seashell": [255, 245, 238],
  1431. "sienna": [160, 82, 45],
  1432. "silver": [192, 192, 192],
  1433. "skyblue": [135, 206, 235],
  1434. "slateblue": [106, 90, 205],
  1435. "slategray": [112, 128, 144],
  1436. "slategrey": [112, 128, 144],
  1437. "snow": [255, 250, 250],
  1438. "springgreen": [0, 255, 127],
  1439. "steelblue": [70, 130, 180],
  1440. "tan": [210, 180, 140],
  1441. "teal": [0, 128, 128],
  1442. "thistle": [216, 191, 216],
  1443. "tomato": [255, 99, 71],
  1444. "turquoise": [64, 224, 208],
  1445. "violet": [238, 130, 238],
  1446. "wheat": [245, 222, 179],
  1447. "white": [255, 255, 255],
  1448. "whitesmoke": [245, 245, 245],
  1449. "yellow": [255, 255, 0],
  1450. "yellowgreen": [154, 205, 50]
  1451. };
  1452. },{}],7:[function(require,module,exports){
  1453. /**
  1454. * @namespace Chart
  1455. */
  1456. var Chart = require(30)();
  1457. Chart.helpers = require(46);
  1458. // @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
  1459. require(28)(Chart);
  1460. Chart.Animation = require(22);
  1461. Chart.animationService = require(23);
  1462. Chart.defaults = require(26);
  1463. Chart.Element = require(27);
  1464. Chart.elements = require(41);
  1465. Chart.Interaction = require(29);
  1466. Chart.layouts = require(31);
  1467. Chart.platform = require(49);
  1468. Chart.plugins = require(32);
  1469. Chart.Scale = require(33);
  1470. Chart.scaleService = require(34);
  1471. Chart.Ticks = require(35);
  1472. Chart.Tooltip = require(36);
  1473. require(24)(Chart);
  1474. require(25)(Chart);
  1475. require(56)(Chart);
  1476. require(54)(Chart);
  1477. require(55)(Chart);
  1478. require(57)(Chart);
  1479. require(58)(Chart);
  1480. require(59)(Chart);
  1481. // Controllers must be loaded after elements
  1482. // See Chart.core.datasetController.dataElementType
  1483. require(15)(Chart);
  1484. require(16)(Chart);
  1485. require(17)(Chart);
  1486. require(18)(Chart);
  1487. require(19)(Chart);
  1488. require(20)(Chart);
  1489. require(21)(Chart);
  1490. require(8)(Chart);
  1491. require(9)(Chart);
  1492. require(10)(Chart);
  1493. require(11)(Chart);
  1494. require(12)(Chart);
  1495. require(13)(Chart);
  1496. require(14)(Chart);
  1497. // Loading built-in plugins
  1498. var plugins = require(50);
  1499. for (var k in plugins) {
  1500. if (plugins.hasOwnProperty(k)) {
  1501. Chart.plugins.register(plugins[k]);
  1502. }
  1503. }
  1504. Chart.platform.initialize();
  1505. module.exports = Chart;
  1506. if (typeof window !== 'undefined') {
  1507. window.Chart = Chart;
  1508. }
  1509. // DEPRECATIONS
  1510. /**
  1511. * Provided for backward compatibility, not available anymore
  1512. * @namespace Chart.Legend
  1513. * @deprecated since version 2.1.5
  1514. * @todo remove at version 3
  1515. * @private
  1516. */
  1517. Chart.Legend = plugins.legend._element;
  1518. /**
  1519. * Provided for backward compatibility, not available anymore
  1520. * @namespace Chart.Title
  1521. * @deprecated since version 2.1.5
  1522. * @todo remove at version 3
  1523. * @private
  1524. */
  1525. Chart.Title = plugins.title._element;
  1526. /**
  1527. * Provided for backward compatibility, use Chart.plugins instead
  1528. * @namespace Chart.pluginService
  1529. * @deprecated since version 2.1.5
  1530. * @todo remove at version 3
  1531. * @private
  1532. */
  1533. Chart.pluginService = Chart.plugins;
  1534. /**
  1535. * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
  1536. * effect, instead simply create/register plugins via plain JavaScript objects.
  1537. * @interface Chart.PluginBase
  1538. * @deprecated since version 2.5.0
  1539. * @todo remove at version 3
  1540. * @private
  1541. */
  1542. Chart.PluginBase = Chart.Element.extend({});
  1543. /**
  1544. * Provided for backward compatibility, use Chart.helpers.canvas instead.
  1545. * @namespace Chart.canvasHelpers
  1546. * @deprecated since version 2.6.0
  1547. * @todo remove at version 3
  1548. * @private
  1549. */
  1550. Chart.canvasHelpers = Chart.helpers.canvas;
  1551. /**
  1552. * Provided for backward compatibility, use Chart.layouts instead.
  1553. * @namespace Chart.layoutService
  1554. * @deprecated since version 2.8.0
  1555. * @todo remove at version 3
  1556. * @private
  1557. */
  1558. Chart.layoutService = Chart.layouts;
  1559. },{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"33":33,"34":34,"35":35,"36":36,"41":41,"46":46,"49":49,"50":50,"54":54,"55":55,"56":56,"57":57,"58":58,"59":59,"8":8,"9":9}],8:[function(require,module,exports){
  1560. 'use strict';
  1561. module.exports = function(Chart) {
  1562. Chart.Bar = function(context, config) {
  1563. config.type = 'bar';
  1564. return new Chart(context, config);
  1565. };
  1566. };
  1567. },{}],9:[function(require,module,exports){
  1568. 'use strict';
  1569. module.exports = function(Chart) {
  1570. Chart.Bubble = function(context, config) {
  1571. config.type = 'bubble';
  1572. return new Chart(context, config);
  1573. };
  1574. };
  1575. },{}],10:[function(require,module,exports){
  1576. 'use strict';
  1577. module.exports = function(Chart) {
  1578. Chart.Doughnut = function(context, config) {
  1579. config.type = 'doughnut';
  1580. return new Chart(context, config);
  1581. };
  1582. };
  1583. },{}],11:[function(require,module,exports){
  1584. 'use strict';
  1585. module.exports = function(Chart) {
  1586. Chart.Line = function(context, config) {
  1587. config.type = 'line';
  1588. return new Chart(context, config);
  1589. };
  1590. };
  1591. },{}],12:[function(require,module,exports){
  1592. 'use strict';
  1593. module.exports = function(Chart) {
  1594. Chart.PolarArea = function(context, config) {
  1595. config.type = 'polarArea';
  1596. return new Chart(context, config);
  1597. };
  1598. };
  1599. },{}],13:[function(require,module,exports){
  1600. 'use strict';
  1601. module.exports = function(Chart) {
  1602. Chart.Radar = function(context, config) {
  1603. config.type = 'radar';
  1604. return new Chart(context, config);
  1605. };
  1606. };
  1607. },{}],14:[function(require,module,exports){
  1608. 'use strict';
  1609. module.exports = function(Chart) {
  1610. Chart.Scatter = function(context, config) {
  1611. config.type = 'scatter';
  1612. return new Chart(context, config);
  1613. };
  1614. };
  1615. },{}],15:[function(require,module,exports){
  1616. 'use strict';
  1617. var defaults = require(26);
  1618. var elements = require(41);
  1619. var helpers = require(46);
  1620. defaults._set('bar', {
  1621. hover: {
  1622. mode: 'label'
  1623. },
  1624. scales: {
  1625. xAxes: [{
  1626. type: 'category',
  1627. // Specific to Bar Controller
  1628. categoryPercentage: 0.8,
  1629. barPercentage: 0.9,
  1630. // offset settings
  1631. offset: true,
  1632. // grid line settings
  1633. gridLines: {
  1634. offsetGridLines: true
  1635. }
  1636. }],
  1637. yAxes: [{
  1638. type: 'linear'
  1639. }]
  1640. }
  1641. });
  1642. defaults._set('horizontalBar', {
  1643. hover: {
  1644. mode: 'index',
  1645. axis: 'y'
  1646. },
  1647. scales: {
  1648. xAxes: [{
  1649. type: 'linear',
  1650. position: 'bottom'
  1651. }],
  1652. yAxes: [{
  1653. position: 'left',
  1654. type: 'category',
  1655. // Specific to Horizontal Bar Controller
  1656. categoryPercentage: 0.8,
  1657. barPercentage: 0.9,
  1658. // offset settings
  1659. offset: true,
  1660. // grid line settings
  1661. gridLines: {
  1662. offsetGridLines: true
  1663. }
  1664. }]
  1665. },
  1666. elements: {
  1667. rectangle: {
  1668. borderSkipped: 'left'
  1669. }
  1670. },
  1671. tooltips: {
  1672. callbacks: {
  1673. title: function(item, data) {
  1674. // Pick first xLabel for now
  1675. var title = '';
  1676. if (item.length > 0) {
  1677. if (item[0].yLabel) {
  1678. title = item[0].yLabel;
  1679. } else if (data.labels.length > 0 && item[0].index < data.labels.length) {
  1680. title = data.labels[item[0].index];
  1681. }
  1682. }
  1683. return title;
  1684. },
  1685. label: function(item, data) {
  1686. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  1687. return datasetLabel + ': ' + item.xLabel;
  1688. }
  1689. },
  1690. mode: 'index',
  1691. axis: 'y'
  1692. }
  1693. });
  1694. /**
  1695. * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  1696. * @private
  1697. */
  1698. function computeMinSampleSize(scale, pixels) {
  1699. var min = scale.isHorizontal() ? scale.width : scale.height;
  1700. var ticks = scale.getTicks();
  1701. var prev, curr, i, ilen;
  1702. for (i = 1, ilen = pixels.length; i < ilen; ++i) {
  1703. min = Math.min(min, pixels[i] - pixels[i - 1]);
  1704. }
  1705. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  1706. curr = scale.getPixelForTick(i);
  1707. min = i > 0 ? Math.min(min, curr - prev) : min;
  1708. prev = curr;
  1709. }
  1710. return min;
  1711. }
  1712. /**
  1713. * Computes an "ideal" category based on the absolute bar thickness or, if undefined or null,
  1714. * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This
  1715. * mode currently always generates bars equally sized (until we introduce scriptable options?).
  1716. * @private
  1717. */
  1718. function computeFitCategoryTraits(index, ruler, options) {
  1719. var thickness = options.barThickness;
  1720. var count = ruler.stackCount;
  1721. var curr = ruler.pixels[index];
  1722. var size, ratio;
  1723. if (helpers.isNullOrUndef(thickness)) {
  1724. size = ruler.min * options.categoryPercentage;
  1725. ratio = options.barPercentage;
  1726. } else {
  1727. // When bar thickness is enforced, category and bar percentages are ignored.
  1728. // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
  1729. // and deprecate barPercentage since this value is ignored when thickness is absolute.
  1730. size = thickness * count;
  1731. ratio = 1;
  1732. }
  1733. return {
  1734. chunk: size / count,
  1735. ratio: ratio,
  1736. start: curr - (size / 2)
  1737. };
  1738. }
  1739. /**
  1740. * Computes an "optimal" category that globally arranges bars side by side (no gap when
  1741. * percentage options are 1), based on the previous and following categories. This mode
  1742. * generates bars with different widths when data are not evenly spaced.
  1743. * @private
  1744. */
  1745. function computeFlexCategoryTraits(index, ruler, options) {
  1746. var pixels = ruler.pixels;
  1747. var curr = pixels[index];
  1748. var prev = index > 0 ? pixels[index - 1] : null;
  1749. var next = index < pixels.length - 1 ? pixels[index + 1] : null;
  1750. var percent = options.categoryPercentage;
  1751. var start, size;
  1752. if (prev === null) {
  1753. // first data: its size is double based on the next point or,
  1754. // if it's also the last data, we use the scale end extremity.
  1755. prev = curr - (next === null ? ruler.end - curr : next - curr);
  1756. }
  1757. if (next === null) {
  1758. // last data: its size is also double based on the previous point.
  1759. next = curr + curr - prev;
  1760. }
  1761. start = curr - ((curr - prev) / 2) * percent;
  1762. size = ((next - prev) / 2) * percent;
  1763. return {
  1764. chunk: size / ruler.stackCount,
  1765. ratio: options.barPercentage,
  1766. start: start
  1767. };
  1768. }
  1769. module.exports = function(Chart) {
  1770. Chart.controllers.bar = Chart.DatasetController.extend({
  1771. dataElementType: elements.Rectangle,
  1772. initialize: function() {
  1773. var me = this;
  1774. var meta;
  1775. Chart.DatasetController.prototype.initialize.apply(me, arguments);
  1776. meta = me.getMeta();
  1777. meta.stack = me.getDataset().stack;
  1778. meta.bar = true;
  1779. },
  1780. update: function(reset) {
  1781. var me = this;
  1782. var rects = me.getMeta().data;
  1783. var i, ilen;
  1784. me._ruler = me.getRuler();
  1785. for (i = 0, ilen = rects.length; i < ilen; ++i) {
  1786. me.updateElement(rects[i], i, reset);
  1787. }
  1788. },
  1789. updateElement: function(rectangle, index, reset) {
  1790. var me = this;
  1791. var chart = me.chart;
  1792. var meta = me.getMeta();
  1793. var dataset = me.getDataset();
  1794. var custom = rectangle.custom || {};
  1795. var rectangleOptions = chart.options.elements.rectangle;
  1796. rectangle._xScale = me.getScaleForId(meta.xAxisID);
  1797. rectangle._yScale = me.getScaleForId(meta.yAxisID);
  1798. rectangle._datasetIndex = me.index;
  1799. rectangle._index = index;
  1800. rectangle._model = {
  1801. datasetLabel: dataset.label,
  1802. label: chart.data.labels[index],
  1803. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped,
  1804. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor),
  1805. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor),
  1806. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth)
  1807. };
  1808. me.updateElementGeometry(rectangle, index, reset);
  1809. rectangle.pivot();
  1810. },
  1811. /**
  1812. * @private
  1813. */
  1814. updateElementGeometry: function(rectangle, index, reset) {
  1815. var me = this;
  1816. var model = rectangle._model;
  1817. var vscale = me.getValueScale();
  1818. var base = vscale.getBasePixel();
  1819. var horizontal = vscale.isHorizontal();
  1820. var ruler = me._ruler || me.getRuler();
  1821. var vpixels = me.calculateBarValuePixels(me.index, index);
  1822. var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
  1823. model.horizontal = horizontal;
  1824. model.base = reset ? base : vpixels.base;
  1825. model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
  1826. model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
  1827. model.height = horizontal ? ipixels.size : undefined;
  1828. model.width = horizontal ? undefined : ipixels.size;
  1829. },
  1830. /**
  1831. * @private
  1832. */
  1833. getValueScaleId: function() {
  1834. return this.getMeta().yAxisID;
  1835. },
  1836. /**
  1837. * @private
  1838. */
  1839. getIndexScaleId: function() {
  1840. return this.getMeta().xAxisID;
  1841. },
  1842. /**
  1843. * @private
  1844. */
  1845. getValueScale: function() {
  1846. return this.getScaleForId(this.getValueScaleId());
  1847. },
  1848. /**
  1849. * @private
  1850. */
  1851. getIndexScale: function() {
  1852. return this.getScaleForId(this.getIndexScaleId());
  1853. },
  1854. /**
  1855. * Returns the stacks based on groups and bar visibility.
  1856. * @param {Number} [last] - The dataset index
  1857. * @returns {Array} The stack list
  1858. * @private
  1859. */
  1860. _getStacks: function(last) {
  1861. var me = this;
  1862. var chart = me.chart;
  1863. var scale = me.getIndexScale();
  1864. var stacked = scale.options.stacked;
  1865. var ilen = last === undefined ? chart.data.datasets.length : last + 1;
  1866. var stacks = [];
  1867. var i, meta;
  1868. for (i = 0; i < ilen; ++i) {
  1869. meta = chart.getDatasetMeta(i);
  1870. if (meta.bar && chart.isDatasetVisible(i) &&
  1871. (stacked === false ||
  1872. (stacked === true && stacks.indexOf(meta.stack) === -1) ||
  1873. (stacked === undefined && (meta.stack === undefined || stacks.indexOf(meta.stack) === -1)))) {
  1874. stacks.push(meta.stack);
  1875. }
  1876. }
  1877. return stacks;
  1878. },
  1879. /**
  1880. * Returns the effective number of stacks based on groups and bar visibility.
  1881. * @private
  1882. */
  1883. getStackCount: function() {
  1884. return this._getStacks().length;
  1885. },
  1886. /**
  1887. * Returns the stack index for the given dataset based on groups and bar visibility.
  1888. * @param {Number} [datasetIndex] - The dataset index
  1889. * @param {String} [name] - The stack name to find
  1890. * @returns {Number} The stack index
  1891. * @private
  1892. */
  1893. getStackIndex: function(datasetIndex, name) {
  1894. var stacks = this._getStacks(datasetIndex);
  1895. var index = (name !== undefined)
  1896. ? stacks.indexOf(name)
  1897. : -1; // indexOf returns -1 if element is not present
  1898. return (index === -1)
  1899. ? stacks.length - 1
  1900. : index;
  1901. },
  1902. /**
  1903. * @private
  1904. */
  1905. getRuler: function() {
  1906. var me = this;
  1907. var scale = me.getIndexScale();
  1908. var stackCount = me.getStackCount();
  1909. var datasetIndex = me.index;
  1910. var isHorizontal = scale.isHorizontal();
  1911. var start = isHorizontal ? scale.left : scale.top;
  1912. var end = start + (isHorizontal ? scale.width : scale.height);
  1913. var pixels = [];
  1914. var i, ilen, min;
  1915. for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
  1916. pixels.push(scale.getPixelForValue(null, i, datasetIndex));
  1917. }
  1918. min = helpers.isNullOrUndef(scale.options.barThickness)
  1919. ? computeMinSampleSize(scale, pixels)
  1920. : -1;
  1921. return {
  1922. min: min,
  1923. pixels: pixels,
  1924. start: start,
  1925. end: end,
  1926. stackCount: stackCount,
  1927. scale: scale
  1928. };
  1929. },
  1930. /**
  1931. * Note: pixel values are not clamped to the scale area.
  1932. * @private
  1933. */
  1934. calculateBarValuePixels: function(datasetIndex, index) {
  1935. var me = this;
  1936. var chart = me.chart;
  1937. var meta = me.getMeta();
  1938. var scale = me.getValueScale();
  1939. var datasets = chart.data.datasets;
  1940. var value = scale.getRightValue(datasets[datasetIndex].data[index]);
  1941. var stacked = scale.options.stacked;
  1942. var stack = meta.stack;
  1943. var start = 0;
  1944. var i, imeta, ivalue, base, head, size;
  1945. if (stacked || (stacked === undefined && stack !== undefined)) {
  1946. for (i = 0; i < datasetIndex; ++i) {
  1947. imeta = chart.getDatasetMeta(i);
  1948. if (imeta.bar &&
  1949. imeta.stack === stack &&
  1950. imeta.controller.getValueScaleId() === scale.id &&
  1951. chart.isDatasetVisible(i)) {
  1952. ivalue = scale.getRightValue(datasets[i].data[index]);
  1953. if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
  1954. start += ivalue;
  1955. }
  1956. }
  1957. }
  1958. }
  1959. base = scale.getPixelForValue(start);
  1960. head = scale.getPixelForValue(start + value);
  1961. size = (head - base) / 2;
  1962. return {
  1963. size: size,
  1964. base: base,
  1965. head: head,
  1966. center: head + size / 2
  1967. };
  1968. },
  1969. /**
  1970. * @private
  1971. */
  1972. calculateBarIndexPixels: function(datasetIndex, index, ruler) {
  1973. var me = this;
  1974. var options = ruler.scale.options;
  1975. var range = options.barThickness === 'flex'
  1976. ? computeFlexCategoryTraits(index, ruler, options)
  1977. : computeFitCategoryTraits(index, ruler, options);
  1978. var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
  1979. var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
  1980. var size = Math.min(
  1981. helpers.valueOrDefault(options.maxBarThickness, Infinity),
  1982. range.chunk * range.ratio);
  1983. return {
  1984. base: center - size / 2,
  1985. head: center + size / 2,
  1986. center: center,
  1987. size: size
  1988. };
  1989. },
  1990. draw: function() {
  1991. var me = this;
  1992. var chart = me.chart;
  1993. var scale = me.getValueScale();
  1994. var rects = me.getMeta().data;
  1995. var dataset = me.getDataset();
  1996. var ilen = rects.length;
  1997. var i = 0;
  1998. helpers.canvas.clipArea(chart.ctx, chart.chartArea);
  1999. for (; i < ilen; ++i) {
  2000. if (!isNaN(scale.getRightValue(dataset.data[i]))) {
  2001. rects[i].draw();
  2002. }
  2003. }
  2004. helpers.canvas.unclipArea(chart.ctx);
  2005. },
  2006. });
  2007. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  2008. /**
  2009. * @private
  2010. */
  2011. getValueScaleId: function() {
  2012. return this.getMeta().xAxisID;
  2013. },
  2014. /**
  2015. * @private
  2016. */
  2017. getIndexScaleId: function() {
  2018. return this.getMeta().yAxisID;
  2019. }
  2020. });
  2021. };
  2022. },{"26":26,"41":41,"46":46}],16:[function(require,module,exports){
  2023. 'use strict';
  2024. var defaults = require(26);
  2025. var elements = require(41);
  2026. var helpers = require(46);
  2027. defaults._set('bubble', {
  2028. hover: {
  2029. mode: 'single'
  2030. },
  2031. scales: {
  2032. xAxes: [{
  2033. type: 'linear', // bubble should probably use a linear scale by default
  2034. position: 'bottom',
  2035. id: 'x-axis-0' // need an ID so datasets can reference the scale
  2036. }],
  2037. yAxes: [{
  2038. type: 'linear',
  2039. position: 'left',
  2040. id: 'y-axis-0'
  2041. }]
  2042. },
  2043. tooltips: {
  2044. callbacks: {
  2045. title: function() {
  2046. // Title doesn't make sense for scatter since we format the data as a point
  2047. return '';
  2048. },
  2049. label: function(item, data) {
  2050. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  2051. var dataPoint = data.datasets[item.datasetIndex].data[item.index];
  2052. return datasetLabel + ': (' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.r + ')';
  2053. }
  2054. }
  2055. }
  2056. });
  2057. module.exports = function(Chart) {
  2058. Chart.controllers.bubble = Chart.DatasetController.extend({
  2059. /**
  2060. * @protected
  2061. */
  2062. dataElementType: elements.Point,
  2063. /**
  2064. * @protected
  2065. */
  2066. update: function(reset) {
  2067. var me = this;
  2068. var meta = me.getMeta();
  2069. var points = meta.data;
  2070. // Update Points
  2071. helpers.each(points, function(point, index) {
  2072. me.updateElement(point, index, reset);
  2073. });
  2074. },
  2075. /**
  2076. * @protected
  2077. */
  2078. updateElement: function(point, index, reset) {
  2079. var me = this;
  2080. var meta = me.getMeta();
  2081. var custom = point.custom || {};
  2082. var xScale = me.getScaleForId(meta.xAxisID);
  2083. var yScale = me.getScaleForId(meta.yAxisID);
  2084. var options = me._resolveElementOptions(point, index);
  2085. var data = me.getDataset().data[index];
  2086. var dsIndex = me.index;
  2087. var x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex);
  2088. var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex);
  2089. point._xScale = xScale;
  2090. point._yScale = yScale;
  2091. point._options = options;
  2092. point._datasetIndex = dsIndex;
  2093. point._index = index;
  2094. point._model = {
  2095. backgroundColor: options.backgroundColor,
  2096. borderColor: options.borderColor,
  2097. borderWidth: options.borderWidth,
  2098. hitRadius: options.hitRadius,
  2099. pointStyle: options.pointStyle,
  2100. rotation: options.rotation,
  2101. radius: reset ? 0 : options.radius,
  2102. skip: custom.skip || isNaN(x) || isNaN(y),
  2103. x: x,
  2104. y: y,
  2105. };
  2106. point.pivot();
  2107. },
  2108. /**
  2109. * @protected
  2110. */
  2111. setHoverStyle: function(point) {
  2112. var model = point._model;
  2113. var options = point._options;
  2114. point.$previousStyle = {
  2115. backgroundColor: model.backgroundColor,
  2116. borderColor: model.borderColor,
  2117. borderWidth: model.borderWidth,
  2118. radius: model.radius
  2119. };
  2120. model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
  2121. model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
  2122. model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
  2123. model.radius = options.radius + options.hoverRadius;
  2124. },
  2125. /**
  2126. * @private
  2127. */
  2128. _resolveElementOptions: function(point, index) {
  2129. var me = this;
  2130. var chart = me.chart;
  2131. var datasets = chart.data.datasets;
  2132. var dataset = datasets[me.index];
  2133. var custom = point.custom || {};
  2134. var options = chart.options.elements.point;
  2135. var resolve = helpers.options.resolve;
  2136. var data = dataset.data[index];
  2137. var values = {};
  2138. var i, ilen, key;
  2139. // Scriptable options
  2140. var context = {
  2141. chart: chart,
  2142. dataIndex: index,
  2143. dataset: dataset,
  2144. datasetIndex: me.index
  2145. };
  2146. var keys = [
  2147. 'backgroundColor',
  2148. 'borderColor',
  2149. 'borderWidth',
  2150. 'hoverBackgroundColor',
  2151. 'hoverBorderColor',
  2152. 'hoverBorderWidth',
  2153. 'hoverRadius',
  2154. 'hitRadius',
  2155. 'pointStyle',
  2156. 'rotation'
  2157. ];
  2158. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  2159. key = keys[i];
  2160. values[key] = resolve([
  2161. custom[key],
  2162. dataset[key],
  2163. options[key]
  2164. ], context, index);
  2165. }
  2166. // Custom radius resolution
  2167. values.radius = resolve([
  2168. custom.radius,
  2169. data ? data.r : undefined,
  2170. dataset.radius,
  2171. options.radius
  2172. ], context, index);
  2173. return values;
  2174. }
  2175. });
  2176. };
  2177. },{"26":26,"41":41,"46":46}],17:[function(require,module,exports){
  2178. 'use strict';
  2179. var defaults = require(26);
  2180. var elements = require(41);
  2181. var helpers = require(46);
  2182. defaults._set('doughnut', {
  2183. animation: {
  2184. // Boolean - Whether we animate the rotation of the Doughnut
  2185. animateRotate: true,
  2186. // Boolean - Whether we animate scaling the Doughnut from the centre
  2187. animateScale: false
  2188. },
  2189. hover: {
  2190. mode: 'single'
  2191. },
  2192. legendCallback: function(chart) {
  2193. var text = [];
  2194. text.push('<ul class="' + chart.id + '-legend">');
  2195. var data = chart.data;
  2196. var datasets = data.datasets;
  2197. var labels = data.labels;
  2198. if (datasets.length) {
  2199. for (var i = 0; i < datasets[0].data.length; ++i) {
  2200. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2201. if (labels[i]) {
  2202. text.push(labels[i]);
  2203. }
  2204. text.push('</li>');
  2205. }
  2206. }
  2207. text.push('</ul>');
  2208. return text.join('');
  2209. },
  2210. legend: {
  2211. labels: {
  2212. generateLabels: function(chart) {
  2213. var data = chart.data;
  2214. if (data.labels.length && data.datasets.length) {
  2215. return data.labels.map(function(label, i) {
  2216. var meta = chart.getDatasetMeta(0);
  2217. var ds = data.datasets[0];
  2218. var arc = meta.data[i];
  2219. var custom = arc && arc.custom || {};
  2220. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2221. var arcOpts = chart.options.elements.arc;
  2222. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2223. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2224. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2225. return {
  2226. text: label,
  2227. fillStyle: fill,
  2228. strokeStyle: stroke,
  2229. lineWidth: bw,
  2230. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2231. // Extra data used for toggling the correct item
  2232. index: i
  2233. };
  2234. });
  2235. }
  2236. return [];
  2237. }
  2238. },
  2239. onClick: function(e, legendItem) {
  2240. var index = legendItem.index;
  2241. var chart = this.chart;
  2242. var i, ilen, meta;
  2243. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2244. meta = chart.getDatasetMeta(i);
  2245. // toggle visibility of index if exists
  2246. if (meta.data[index]) {
  2247. meta.data[index].hidden = !meta.data[index].hidden;
  2248. }
  2249. }
  2250. chart.update();
  2251. }
  2252. },
  2253. // The percentage of the chart that we cut out of the middle.
  2254. cutoutPercentage: 50,
  2255. // The rotation of the chart, where the first data arc begins.
  2256. rotation: Math.PI * -0.5,
  2257. // The total circumference of the chart.
  2258. circumference: Math.PI * 2.0,
  2259. // Need to override these to give a nice default
  2260. tooltips: {
  2261. callbacks: {
  2262. title: function() {
  2263. return '';
  2264. },
  2265. label: function(tooltipItem, data) {
  2266. var dataLabel = data.labels[tooltipItem.index];
  2267. var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2268. if (helpers.isArray(dataLabel)) {
  2269. // show value on first line of multiline label
  2270. // need to clone because we are changing the value
  2271. dataLabel = dataLabel.slice();
  2272. dataLabel[0] += value;
  2273. } else {
  2274. dataLabel += value;
  2275. }
  2276. return dataLabel;
  2277. }
  2278. }
  2279. }
  2280. });
  2281. defaults._set('pie', helpers.clone(defaults.doughnut));
  2282. defaults._set('pie', {
  2283. cutoutPercentage: 0
  2284. });
  2285. module.exports = function(Chart) {
  2286. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  2287. dataElementType: elements.Arc,
  2288. linkScales: helpers.noop,
  2289. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2290. getRingIndex: function(datasetIndex) {
  2291. var ringIndex = 0;
  2292. for (var j = 0; j < datasetIndex; ++j) {
  2293. if (this.chart.isDatasetVisible(j)) {
  2294. ++ringIndex;
  2295. }
  2296. }
  2297. return ringIndex;
  2298. },
  2299. update: function(reset) {
  2300. var me = this;
  2301. var chart = me.chart;
  2302. var chartArea = chart.chartArea;
  2303. var opts = chart.options;
  2304. var arcOpts = opts.elements.arc;
  2305. var availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth;
  2306. var availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth;
  2307. var minSize = Math.min(availableWidth, availableHeight);
  2308. var offset = {x: 0, y: 0};
  2309. var meta = me.getMeta();
  2310. var cutoutPercentage = opts.cutoutPercentage;
  2311. var circumference = opts.circumference;
  2312. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2313. if (circumference < Math.PI * 2.0) {
  2314. var startAngle = opts.rotation % (Math.PI * 2.0);
  2315. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2316. var endAngle = startAngle + circumference;
  2317. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2318. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2319. var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2320. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2321. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2322. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2323. var cutout = cutoutPercentage / 100.0;
  2324. 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))};
  2325. 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))};
  2326. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2327. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2328. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2329. }
  2330. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  2331. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  2332. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
  2333. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2334. chart.offsetX = offset.x * chart.outerRadius;
  2335. chart.offsetY = offset.y * chart.outerRadius;
  2336. meta.total = me.calculateTotal();
  2337. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  2338. me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
  2339. helpers.each(meta.data, function(arc, index) {
  2340. me.updateElement(arc, index, reset);
  2341. });
  2342. },
  2343. updateElement: function(arc, index, reset) {
  2344. var me = this;
  2345. var chart = me.chart;
  2346. var chartArea = chart.chartArea;
  2347. var opts = chart.options;
  2348. var animationOpts = opts.animation;
  2349. var centerX = (chartArea.left + chartArea.right) / 2;
  2350. var centerY = (chartArea.top + chartArea.bottom) / 2;
  2351. var startAngle = opts.rotation; // non reset case handled later
  2352. var endAngle = opts.rotation; // non reset case handled later
  2353. var dataset = me.getDataset();
  2354. var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI));
  2355. var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
  2356. var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
  2357. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2358. helpers.extend(arc, {
  2359. // Utility
  2360. _datasetIndex: me.index,
  2361. _index: index,
  2362. // Desired view properties
  2363. _model: {
  2364. x: centerX + chart.offsetX,
  2365. y: centerY + chart.offsetY,
  2366. startAngle: startAngle,
  2367. endAngle: endAngle,
  2368. circumference: circumference,
  2369. outerRadius: outerRadius,
  2370. innerRadius: innerRadius,
  2371. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  2372. }
  2373. });
  2374. var model = arc._model;
  2375. // Resets the visual styles
  2376. var custom = arc.custom || {};
  2377. var valueOrDefault = helpers.valueAtIndexOrDefault;
  2378. var elementOpts = this.chart.options.elements.arc;
  2379. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  2380. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  2381. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  2382. // Set correct angles if not resetting
  2383. if (!reset || !animationOpts.animateRotate) {
  2384. if (index === 0) {
  2385. model.startAngle = opts.rotation;
  2386. } else {
  2387. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  2388. }
  2389. model.endAngle = model.startAngle + model.circumference;
  2390. }
  2391. arc.pivot();
  2392. },
  2393. calculateTotal: function() {
  2394. var dataset = this.getDataset();
  2395. var meta = this.getMeta();
  2396. var total = 0;
  2397. var value;
  2398. helpers.each(meta.data, function(element, index) {
  2399. value = dataset.data[index];
  2400. if (!isNaN(value) && !element.hidden) {
  2401. total += Math.abs(value);
  2402. }
  2403. });
  2404. /* if (total === 0) {
  2405. total = NaN;
  2406. }*/
  2407. return total;
  2408. },
  2409. calculateCircumference: function(value) {
  2410. var total = this.getMeta().total;
  2411. if (total > 0 && !isNaN(value)) {
  2412. return (Math.PI * 2.0) * (Math.abs(value) / total);
  2413. }
  2414. return 0;
  2415. },
  2416. // gets the max border or hover width to properly scale pie charts
  2417. getMaxBorderWidth: function(arcs) {
  2418. var max = 0;
  2419. var index = this.index;
  2420. var length = arcs.length;
  2421. var borderWidth;
  2422. var hoverWidth;
  2423. for (var i = 0; i < length; i++) {
  2424. borderWidth = arcs[i]._model ? arcs[i]._model.borderWidth : 0;
  2425. hoverWidth = arcs[i]._chart ? arcs[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2426. max = borderWidth > max ? borderWidth : max;
  2427. max = hoverWidth > max ? hoverWidth : max;
  2428. }
  2429. return max;
  2430. }
  2431. });
  2432. };
  2433. },{"26":26,"41":41,"46":46}],18:[function(require,module,exports){
  2434. 'use strict';
  2435. var defaults = require(26);
  2436. var elements = require(41);
  2437. var helpers = require(46);
  2438. defaults._set('line', {
  2439. showLines: true,
  2440. spanGaps: false,
  2441. hover: {
  2442. mode: 'label'
  2443. },
  2444. scales: {
  2445. xAxes: [{
  2446. type: 'category',
  2447. id: 'x-axis-0'
  2448. }],
  2449. yAxes: [{
  2450. type: 'linear',
  2451. id: 'y-axis-0'
  2452. }]
  2453. }
  2454. });
  2455. module.exports = function(Chart) {
  2456. function lineEnabled(dataset, options) {
  2457. return helpers.valueOrDefault(dataset.showLine, options.showLines);
  2458. }
  2459. Chart.controllers.line = Chart.DatasetController.extend({
  2460. datasetElementType: elements.Line,
  2461. dataElementType: elements.Point,
  2462. update: function(reset) {
  2463. var me = this;
  2464. var meta = me.getMeta();
  2465. var line = meta.dataset;
  2466. var points = meta.data || [];
  2467. var options = me.chart.options;
  2468. var lineElementOptions = options.elements.line;
  2469. var scale = me.getScaleForId(meta.yAxisID);
  2470. var i, ilen, custom;
  2471. var dataset = me.getDataset();
  2472. var showLine = lineEnabled(dataset, options);
  2473. // Update Line
  2474. if (showLine) {
  2475. custom = line.custom || {};
  2476. // Compatibility: If the properties are defined with only the old name, use those values
  2477. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2478. dataset.lineTension = dataset.tension;
  2479. }
  2480. // Utility
  2481. line._scale = scale;
  2482. line._datasetIndex = me.index;
  2483. // Data
  2484. line._children = points;
  2485. // Model
  2486. line._model = {
  2487. // Appearance
  2488. // The default behavior of lines is to break at null values, according
  2489. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2490. // This option gives lines the ability to span gaps
  2491. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2492. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2493. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2494. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2495. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2496. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2497. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2498. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2499. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2500. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2501. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.valueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2502. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.valueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2503. };
  2504. line.pivot();
  2505. }
  2506. // Update Points
  2507. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2508. me.updateElement(points[i], i, reset);
  2509. }
  2510. if (showLine && line._model.tension !== 0) {
  2511. me.updateBezierControlPoints();
  2512. }
  2513. // Now pivot the point for animation
  2514. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2515. points[i].pivot();
  2516. }
  2517. },
  2518. getPointBackgroundColor: function(point, index) {
  2519. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2520. var dataset = this.getDataset();
  2521. var custom = point.custom || {};
  2522. if (custom.backgroundColor) {
  2523. backgroundColor = custom.backgroundColor;
  2524. } else if (dataset.pointBackgroundColor) {
  2525. backgroundColor = helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2526. } else if (dataset.backgroundColor) {
  2527. backgroundColor = dataset.backgroundColor;
  2528. }
  2529. return backgroundColor;
  2530. },
  2531. getPointBorderColor: function(point, index) {
  2532. var borderColor = this.chart.options.elements.point.borderColor;
  2533. var dataset = this.getDataset();
  2534. var custom = point.custom || {};
  2535. if (custom.borderColor) {
  2536. borderColor = custom.borderColor;
  2537. } else if (dataset.pointBorderColor) {
  2538. borderColor = helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2539. } else if (dataset.borderColor) {
  2540. borderColor = dataset.borderColor;
  2541. }
  2542. return borderColor;
  2543. },
  2544. getPointBorderWidth: function(point, index) {
  2545. var borderWidth = this.chart.options.elements.point.borderWidth;
  2546. var dataset = this.getDataset();
  2547. var custom = point.custom || {};
  2548. if (!isNaN(custom.borderWidth)) {
  2549. borderWidth = custom.borderWidth;
  2550. } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
  2551. borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2552. } else if (!isNaN(dataset.borderWidth)) {
  2553. borderWidth = dataset.borderWidth;
  2554. }
  2555. return borderWidth;
  2556. },
  2557. getPointRotation: function(point, index) {
  2558. var pointRotation = this.chart.options.elements.point.rotation;
  2559. var dataset = this.getDataset();
  2560. var custom = point.custom || {};
  2561. if (!isNaN(custom.rotation)) {
  2562. pointRotation = custom.rotation;
  2563. } else if (!isNaN(dataset.pointRotation) || helpers.isArray(dataset.pointRotation)) {
  2564. pointRotation = helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointRotation);
  2565. }
  2566. return pointRotation;
  2567. },
  2568. updateElement: function(point, index, reset) {
  2569. var me = this;
  2570. var meta = me.getMeta();
  2571. var custom = point.custom || {};
  2572. var dataset = me.getDataset();
  2573. var datasetIndex = me.index;
  2574. var value = dataset.data[index];
  2575. var yScale = me.getScaleForId(meta.yAxisID);
  2576. var xScale = me.getScaleForId(meta.xAxisID);
  2577. var pointOptions = me.chart.options.elements.point;
  2578. var x, y;
  2579. // Compatibility: If the properties are defined with only the old name, use those values
  2580. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2581. dataset.pointRadius = dataset.radius;
  2582. }
  2583. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2584. dataset.pointHitRadius = dataset.hitRadius;
  2585. }
  2586. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
  2587. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2588. // Utility
  2589. point._xScale = xScale;
  2590. point._yScale = yScale;
  2591. point._datasetIndex = datasetIndex;
  2592. point._index = index;
  2593. // Desired view properties
  2594. point._model = {
  2595. x: x,
  2596. y: y,
  2597. skip: custom.skip || isNaN(x) || isNaN(y),
  2598. // Appearance
  2599. radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2600. pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2601. rotation: me.getPointRotation(point, index),
  2602. backgroundColor: me.getPointBackgroundColor(point, index),
  2603. borderColor: me.getPointBorderColor(point, index),
  2604. borderWidth: me.getPointBorderWidth(point, index),
  2605. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2606. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2607. // Tooltip
  2608. hitRadius: custom.hitRadius || helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2609. };
  2610. },
  2611. calculatePointY: function(value, index, datasetIndex) {
  2612. var me = this;
  2613. var chart = me.chart;
  2614. var meta = me.getMeta();
  2615. var yScale = me.getScaleForId(meta.yAxisID);
  2616. var sumPos = 0;
  2617. var sumNeg = 0;
  2618. var i, ds, dsMeta;
  2619. if (yScale.options.stacked) {
  2620. for (i = 0; i < datasetIndex; i++) {
  2621. ds = chart.data.datasets[i];
  2622. dsMeta = chart.getDatasetMeta(i);
  2623. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2624. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2625. if (stackedRightValue < 0) {
  2626. sumNeg += stackedRightValue || 0;
  2627. } else {
  2628. sumPos += stackedRightValue || 0;
  2629. }
  2630. }
  2631. }
  2632. var rightValue = Number(yScale.getRightValue(value));
  2633. if (rightValue < 0) {
  2634. return yScale.getPixelForValue(sumNeg + rightValue);
  2635. }
  2636. return yScale.getPixelForValue(sumPos + rightValue);
  2637. }
  2638. return yScale.getPixelForValue(value);
  2639. },
  2640. updateBezierControlPoints: function() {
  2641. var me = this;
  2642. var meta = me.getMeta();
  2643. var area = me.chart.chartArea;
  2644. var points = (meta.data || []);
  2645. var i, ilen, point, model, controlPoints;
  2646. // Only consider points that are drawn in case the spanGaps option is used
  2647. if (meta.dataset._model.spanGaps) {
  2648. points = points.filter(function(pt) {
  2649. return !pt._model.skip;
  2650. });
  2651. }
  2652. function capControlPoint(pt, min, max) {
  2653. return Math.max(Math.min(pt, max), min);
  2654. }
  2655. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2656. helpers.splineCurveMonotone(points);
  2657. } else {
  2658. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2659. point = points[i];
  2660. model = point._model;
  2661. controlPoints = helpers.splineCurve(
  2662. helpers.previousItem(points, i)._model,
  2663. model,
  2664. helpers.nextItem(points, i)._model,
  2665. meta.dataset._model.tension
  2666. );
  2667. model.controlPointPreviousX = controlPoints.previous.x;
  2668. model.controlPointPreviousY = controlPoints.previous.y;
  2669. model.controlPointNextX = controlPoints.next.x;
  2670. model.controlPointNextY = controlPoints.next.y;
  2671. }
  2672. }
  2673. if (me.chart.options.elements.line.capBezierPoints) {
  2674. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2675. model = points[i]._model;
  2676. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2677. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2678. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2679. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2680. }
  2681. }
  2682. },
  2683. draw: function() {
  2684. var me = this;
  2685. var chart = me.chart;
  2686. var meta = me.getMeta();
  2687. var points = meta.data || [];
  2688. var area = chart.chartArea;
  2689. var ilen = points.length;
  2690. var halfBorderWidth;
  2691. var i = 0;
  2692. if (lineEnabled(me.getDataset(), chart.options)) {
  2693. halfBorderWidth = (meta.dataset._model.borderWidth || 0) / 2;
  2694. helpers.canvas.clipArea(chart.ctx, {
  2695. left: area.left,
  2696. right: area.right,
  2697. top: area.top - halfBorderWidth,
  2698. bottom: area.bottom + halfBorderWidth
  2699. });
  2700. meta.dataset.draw();
  2701. helpers.canvas.unclipArea(chart.ctx);
  2702. }
  2703. // Draw the points
  2704. for (; i < ilen; ++i) {
  2705. points[i].draw(area);
  2706. }
  2707. },
  2708. setHoverStyle: function(element) {
  2709. // Point
  2710. var dataset = this.chart.data.datasets[element._datasetIndex];
  2711. var index = element._index;
  2712. var custom = element.custom || {};
  2713. var model = element._model;
  2714. element.$previousStyle = {
  2715. backgroundColor: model.backgroundColor,
  2716. borderColor: model.borderColor,
  2717. borderWidth: model.borderWidth,
  2718. radius: model.radius
  2719. };
  2720. model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2721. model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2722. model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2723. model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2724. },
  2725. });
  2726. };
  2727. },{"26":26,"41":41,"46":46}],19:[function(require,module,exports){
  2728. 'use strict';
  2729. var defaults = require(26);
  2730. var elements = require(41);
  2731. var helpers = require(46);
  2732. defaults._set('polarArea', {
  2733. scale: {
  2734. type: 'radialLinear',
  2735. angleLines: {
  2736. display: false
  2737. },
  2738. gridLines: {
  2739. circular: true
  2740. },
  2741. pointLabels: {
  2742. display: false
  2743. },
  2744. ticks: {
  2745. beginAtZero: true
  2746. }
  2747. },
  2748. // Boolean - Whether to animate the rotation of the chart
  2749. animation: {
  2750. animateRotate: true,
  2751. animateScale: true
  2752. },
  2753. startAngle: -0.5 * Math.PI,
  2754. legendCallback: function(chart) {
  2755. var text = [];
  2756. text.push('<ul class="' + chart.id + '-legend">');
  2757. var data = chart.data;
  2758. var datasets = data.datasets;
  2759. var labels = data.labels;
  2760. if (datasets.length) {
  2761. for (var i = 0; i < datasets[0].data.length; ++i) {
  2762. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2763. if (labels[i]) {
  2764. text.push(labels[i]);
  2765. }
  2766. text.push('</li>');
  2767. }
  2768. }
  2769. text.push('</ul>');
  2770. return text.join('');
  2771. },
  2772. legend: {
  2773. labels: {
  2774. generateLabels: function(chart) {
  2775. var data = chart.data;
  2776. if (data.labels.length && data.datasets.length) {
  2777. return data.labels.map(function(label, i) {
  2778. var meta = chart.getDatasetMeta(0);
  2779. var ds = data.datasets[0];
  2780. var arc = meta.data[i];
  2781. var custom = arc.custom || {};
  2782. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2783. var arcOpts = chart.options.elements.arc;
  2784. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2785. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2786. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2787. return {
  2788. text: label,
  2789. fillStyle: fill,
  2790. strokeStyle: stroke,
  2791. lineWidth: bw,
  2792. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2793. // Extra data used for toggling the correct item
  2794. index: i
  2795. };
  2796. });
  2797. }
  2798. return [];
  2799. }
  2800. },
  2801. onClick: function(e, legendItem) {
  2802. var index = legendItem.index;
  2803. var chart = this.chart;
  2804. var i, ilen, meta;
  2805. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2806. meta = chart.getDatasetMeta(i);
  2807. meta.data[index].hidden = !meta.data[index].hidden;
  2808. }
  2809. chart.update();
  2810. }
  2811. },
  2812. // Need to override these to give a nice default
  2813. tooltips: {
  2814. callbacks: {
  2815. title: function() {
  2816. return '';
  2817. },
  2818. label: function(item, data) {
  2819. return data.labels[item.index] + ': ' + item.yLabel;
  2820. }
  2821. }
  2822. }
  2823. });
  2824. module.exports = function(Chart) {
  2825. Chart.controllers.polarArea = Chart.DatasetController.extend({
  2826. dataElementType: elements.Arc,
  2827. linkScales: helpers.noop,
  2828. update: function(reset) {
  2829. var me = this;
  2830. var dataset = me.getDataset();
  2831. var meta = me.getMeta();
  2832. var start = me.chart.options.startAngle || 0;
  2833. var starts = me._starts = [];
  2834. var angles = me._angles = [];
  2835. var i, ilen, angle;
  2836. me._updateRadius();
  2837. meta.count = me.countVisibleElements();
  2838. for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
  2839. starts[i] = start;
  2840. angle = me._computeAngle(i);
  2841. angles[i] = angle;
  2842. start += angle;
  2843. }
  2844. helpers.each(meta.data, function(arc, index) {
  2845. me.updateElement(arc, index, reset);
  2846. });
  2847. },
  2848. /**
  2849. * @private
  2850. */
  2851. _updateRadius: function() {
  2852. var me = this;
  2853. var chart = me.chart;
  2854. var chartArea = chart.chartArea;
  2855. var opts = chart.options;
  2856. var arcOpts = opts.elements.arc;
  2857. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  2858. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  2859. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  2860. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2861. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  2862. me.innerRadius = me.outerRadius - chart.radiusLength;
  2863. },
  2864. updateElement: function(arc, index, reset) {
  2865. var me = this;
  2866. var chart = me.chart;
  2867. var dataset = me.getDataset();
  2868. var opts = chart.options;
  2869. var animationOpts = opts.animation;
  2870. var scale = chart.scale;
  2871. var labels = chart.data.labels;
  2872. var centerX = scale.xCenter;
  2873. var centerY = scale.yCenter;
  2874. // var negHalfPI = -0.5 * Math.PI;
  2875. var datasetStartAngle = opts.startAngle;
  2876. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2877. var startAngle = me._starts[index];
  2878. var endAngle = startAngle + (arc.hidden ? 0 : me._angles[index]);
  2879. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2880. helpers.extend(arc, {
  2881. // Utility
  2882. _datasetIndex: me.index,
  2883. _index: index,
  2884. _scale: scale,
  2885. // Desired view properties
  2886. _model: {
  2887. x: centerX,
  2888. y: centerY,
  2889. innerRadius: 0,
  2890. outerRadius: reset ? resetRadius : distance,
  2891. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  2892. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  2893. label: helpers.valueAtIndexOrDefault(labels, index, labels[index])
  2894. }
  2895. });
  2896. // Apply border and fill style
  2897. var elementOpts = this.chart.options.elements.arc;
  2898. var custom = arc.custom || {};
  2899. var valueOrDefault = helpers.valueAtIndexOrDefault;
  2900. var model = arc._model;
  2901. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  2902. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  2903. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  2904. arc.pivot();
  2905. },
  2906. countVisibleElements: function() {
  2907. var dataset = this.getDataset();
  2908. var meta = this.getMeta();
  2909. var count = 0;
  2910. helpers.each(meta.data, function(element, index) {
  2911. if (!isNaN(dataset.data[index]) && !element.hidden) {
  2912. count++;
  2913. }
  2914. });
  2915. return count;
  2916. },
  2917. /**
  2918. * @private
  2919. */
  2920. _computeAngle: function(index) {
  2921. var me = this;
  2922. var count = this.getMeta().count;
  2923. var dataset = me.getDataset();
  2924. var meta = me.getMeta();
  2925. if (isNaN(dataset.data[index]) || meta.data[index].hidden) {
  2926. return 0;
  2927. }
  2928. // Scriptable options
  2929. var context = {
  2930. chart: me.chart,
  2931. dataIndex: index,
  2932. dataset: dataset,
  2933. datasetIndex: me.index
  2934. };
  2935. return helpers.options.resolve([
  2936. me.chart.options.elements.arc.angle,
  2937. (2 * Math.PI) / count
  2938. ], context, index);
  2939. }
  2940. });
  2941. };
  2942. },{"26":26,"41":41,"46":46}],20:[function(require,module,exports){
  2943. 'use strict';
  2944. var defaults = require(26);
  2945. var elements = require(41);
  2946. var helpers = require(46);
  2947. defaults._set('radar', {
  2948. scale: {
  2949. type: 'radialLinear'
  2950. },
  2951. elements: {
  2952. line: {
  2953. tension: 0 // no bezier in radar
  2954. }
  2955. }
  2956. });
  2957. module.exports = function(Chart) {
  2958. Chart.controllers.radar = Chart.DatasetController.extend({
  2959. datasetElementType: elements.Line,
  2960. dataElementType: elements.Point,
  2961. linkScales: helpers.noop,
  2962. update: function(reset) {
  2963. var me = this;
  2964. var meta = me.getMeta();
  2965. var line = meta.dataset;
  2966. var points = meta.data;
  2967. var custom = line.custom || {};
  2968. var dataset = me.getDataset();
  2969. var lineElementOptions = me.chart.options.elements.line;
  2970. var scale = me.chart.scale;
  2971. // Compatibility: If the properties are defined with only the old name, use those values
  2972. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2973. dataset.lineTension = dataset.tension;
  2974. }
  2975. helpers.extend(meta.dataset, {
  2976. // Utility
  2977. _datasetIndex: me.index,
  2978. _scale: scale,
  2979. // Data
  2980. _children: points,
  2981. _loop: true,
  2982. // Model
  2983. _model: {
  2984. // Appearance
  2985. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2986. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2987. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2988. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2989. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2990. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2991. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2992. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2993. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2994. }
  2995. });
  2996. meta.dataset.pivot();
  2997. // Update Points
  2998. helpers.each(points, function(point, index) {
  2999. me.updateElement(point, index, reset);
  3000. }, me);
  3001. // Update bezier control points
  3002. me.updateBezierControlPoints();
  3003. },
  3004. updateElement: function(point, index, reset) {
  3005. var me = this;
  3006. var custom = point.custom || {};
  3007. var dataset = me.getDataset();
  3008. var scale = me.chart.scale;
  3009. var pointElementOptions = me.chart.options.elements.point;
  3010. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  3011. // Compatibility: If the properties are defined with only the old name, use those values
  3012. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  3013. dataset.pointRadius = dataset.radius;
  3014. }
  3015. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  3016. dataset.pointHitRadius = dataset.hitRadius;
  3017. }
  3018. helpers.extend(point, {
  3019. // Utility
  3020. _datasetIndex: me.index,
  3021. _index: index,
  3022. _scale: scale,
  3023. // Desired view properties
  3024. _model: {
  3025. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  3026. y: reset ? scale.yCenter : pointPosition.y,
  3027. // Appearance
  3028. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
  3029. radius: custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  3030. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  3031. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  3032. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  3033. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  3034. rotation: custom.rotation ? custom.rotation : helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointElementOptions.rotation),
  3035. // Tooltip
  3036. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
  3037. }
  3038. });
  3039. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  3040. },
  3041. updateBezierControlPoints: function() {
  3042. var chartArea = this.chart.chartArea;
  3043. var meta = this.getMeta();
  3044. helpers.each(meta.data, function(point, index) {
  3045. var model = point._model;
  3046. var controlPoints = helpers.splineCurve(
  3047. helpers.previousItem(meta.data, index, true)._model,
  3048. model,
  3049. helpers.nextItem(meta.data, index, true)._model,
  3050. model.tension
  3051. );
  3052. // Prevent the bezier going outside of the bounds of the graph
  3053. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  3054. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  3055. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  3056. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  3057. // Now pivot the point for animation
  3058. point.pivot();
  3059. });
  3060. },
  3061. setHoverStyle: function(point) {
  3062. // Point
  3063. var dataset = this.chart.data.datasets[point._datasetIndex];
  3064. var custom = point.custom || {};
  3065. var index = point._index;
  3066. var model = point._model;
  3067. point.$previousStyle = {
  3068. backgroundColor: model.backgroundColor,
  3069. borderColor: model.borderColor,
  3070. borderWidth: model.borderWidth,
  3071. radius: model.radius
  3072. };
  3073. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3074. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3075. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3076. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3077. },
  3078. });
  3079. };
  3080. },{"26":26,"41":41,"46":46}],21:[function(require,module,exports){
  3081. 'use strict';
  3082. var defaults = require(26);
  3083. defaults._set('scatter', {
  3084. hover: {
  3085. mode: 'single'
  3086. },
  3087. scales: {
  3088. xAxes: [{
  3089. id: 'x-axis-1', // need an ID so datasets can reference the scale
  3090. type: 'linear', // scatter should not use a category axis
  3091. position: 'bottom'
  3092. }],
  3093. yAxes: [{
  3094. id: 'y-axis-1',
  3095. type: 'linear',
  3096. position: 'left'
  3097. }]
  3098. },
  3099. showLines: false,
  3100. tooltips: {
  3101. callbacks: {
  3102. title: function() {
  3103. return ''; // doesn't make sense for scatter since data are formatted as a point
  3104. },
  3105. label: function(item) {
  3106. return '(' + item.xLabel + ', ' + item.yLabel + ')';
  3107. }
  3108. }
  3109. }
  3110. });
  3111. module.exports = function(Chart) {
  3112. // Scatter charts use line controllers
  3113. Chart.controllers.scatter = Chart.controllers.line;
  3114. };
  3115. },{"26":26}],22:[function(require,module,exports){
  3116. 'use strict';
  3117. var Element = require(27);
  3118. var exports = module.exports = Element.extend({
  3119. chart: null, // the animation associated chart instance
  3120. currentStep: 0, // the current animation step
  3121. numSteps: 60, // default number of steps
  3122. easing: '', // the easing to use for this animation
  3123. render: null, // render function used by the animation service
  3124. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3125. onAnimationComplete: null, // user specified callback to fire when the animation finishes
  3126. });
  3127. // DEPRECATIONS
  3128. /**
  3129. * Provided for backward compatibility, use Chart.Animation instead
  3130. * @prop Chart.Animation#animationObject
  3131. * @deprecated since version 2.6.0
  3132. * @todo remove at version 3
  3133. */
  3134. Object.defineProperty(exports.prototype, 'animationObject', {
  3135. get: function() {
  3136. return this;
  3137. }
  3138. });
  3139. /**
  3140. * Provided for backward compatibility, use Chart.Animation#chart instead
  3141. * @prop Chart.Animation#chartInstance
  3142. * @deprecated since version 2.6.0
  3143. * @todo remove at version 3
  3144. */
  3145. Object.defineProperty(exports.prototype, 'chartInstance', {
  3146. get: function() {
  3147. return this.chart;
  3148. },
  3149. set: function(value) {
  3150. this.chart = value;
  3151. }
  3152. });
  3153. },{"27":27}],23:[function(require,module,exports){
  3154. /* global window: false */
  3155. 'use strict';
  3156. var defaults = require(26);
  3157. var helpers = require(46);
  3158. defaults._set('global', {
  3159. animation: {
  3160. duration: 1000,
  3161. easing: 'easeOutQuart',
  3162. onProgress: helpers.noop,
  3163. onComplete: helpers.noop
  3164. }
  3165. });
  3166. module.exports = {
  3167. frameDuration: 17,
  3168. animations: [],
  3169. dropFrames: 0,
  3170. request: null,
  3171. /**
  3172. * @param {Chart} chart - The chart to animate.
  3173. * @param {Chart.Animation} animation - The animation that we will animate.
  3174. * @param {Number} duration - The animation duration in ms.
  3175. * @param {Boolean} lazy - if true, the chart is not marked as animating to enable more responsive interactions
  3176. */
  3177. addAnimation: function(chart, animation, duration, lazy) {
  3178. var animations = this.animations;
  3179. var i, ilen;
  3180. animation.chart = chart;
  3181. if (!lazy) {
  3182. chart.animating = true;
  3183. }
  3184. for (i = 0, ilen = animations.length; i < ilen; ++i) {
  3185. if (animations[i].chart === chart) {
  3186. animations[i] = animation;
  3187. return;
  3188. }
  3189. }
  3190. animations.push(animation);
  3191. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3192. if (animations.length === 1) {
  3193. this.requestAnimationFrame();
  3194. }
  3195. },
  3196. cancelAnimation: function(chart) {
  3197. var index = helpers.findIndex(this.animations, function(animation) {
  3198. return animation.chart === chart;
  3199. });
  3200. if (index !== -1) {
  3201. this.animations.splice(index, 1);
  3202. chart.animating = false;
  3203. }
  3204. },
  3205. requestAnimationFrame: function() {
  3206. var me = this;
  3207. if (me.request === null) {
  3208. // Skip animation frame requests until the active one is executed.
  3209. // This can happen when processing mouse events, e.g. 'mousemove'
  3210. // and 'mouseout' events will trigger multiple renders.
  3211. me.request = helpers.requestAnimFrame.call(window, function() {
  3212. me.request = null;
  3213. me.startDigest();
  3214. });
  3215. }
  3216. },
  3217. /**
  3218. * @private
  3219. */
  3220. startDigest: function() {
  3221. var me = this;
  3222. var startTime = Date.now();
  3223. var framesToDrop = 0;
  3224. if (me.dropFrames > 1) {
  3225. framesToDrop = Math.floor(me.dropFrames);
  3226. me.dropFrames = me.dropFrames % 1;
  3227. }
  3228. me.advance(1 + framesToDrop);
  3229. var endTime = Date.now();
  3230. me.dropFrames += (endTime - startTime) / me.frameDuration;
  3231. // Do we have more stuff to animate?
  3232. if (me.animations.length > 0) {
  3233. me.requestAnimationFrame();
  3234. }
  3235. },
  3236. /**
  3237. * @private
  3238. */
  3239. advance: function(count) {
  3240. var animations = this.animations;
  3241. var animation, chart;
  3242. var i = 0;
  3243. while (i < animations.length) {
  3244. animation = animations[i];
  3245. chart = animation.chart;
  3246. animation.currentStep = (animation.currentStep || 0) + count;
  3247. animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
  3248. helpers.callback(animation.render, [chart, animation], chart);
  3249. helpers.callback(animation.onAnimationProgress, [animation], chart);
  3250. if (animation.currentStep >= animation.numSteps) {
  3251. helpers.callback(animation.onAnimationComplete, [animation], chart);
  3252. chart.animating = false;
  3253. animations.splice(i, 1);
  3254. } else {
  3255. ++i;
  3256. }
  3257. }
  3258. }
  3259. };
  3260. },{"26":26,"46":46}],24:[function(require,module,exports){
  3261. 'use strict';
  3262. var Animation = require(22);
  3263. var animations = require(23);
  3264. var defaults = require(26);
  3265. var helpers = require(46);
  3266. var Interaction = require(29);
  3267. var layouts = require(31);
  3268. var platform = require(49);
  3269. var plugins = require(32);
  3270. var scaleService = require(34);
  3271. var Tooltip = require(36);
  3272. module.exports = function(Chart) {
  3273. // Create a dictionary of chart types, to allow for extension of existing types
  3274. Chart.types = {};
  3275. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3276. // Destroy method on the chart will remove the instance of the chart from this reference.
  3277. Chart.instances = {};
  3278. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3279. Chart.controllers = {};
  3280. /**
  3281. * Initializes the given config with global and chart default values.
  3282. */
  3283. function initConfig(config) {
  3284. config = config || {};
  3285. // Do NOT use configMerge() for the data object because this method merges arrays
  3286. // and so would change references to labels and datasets, preventing data updates.
  3287. var data = config.data = config.data || {};
  3288. data.datasets = data.datasets || [];
  3289. data.labels = data.labels || [];
  3290. config.options = helpers.configMerge(
  3291. defaults.global,
  3292. defaults[config.type],
  3293. config.options || {});
  3294. return config;
  3295. }
  3296. /**
  3297. * Updates the config of the chart
  3298. * @param chart {Chart} chart to update the options for
  3299. */
  3300. function updateConfig(chart) {
  3301. var newOptions = chart.options;
  3302. helpers.each(chart.scales, function(scale) {
  3303. layouts.removeBox(chart, scale);
  3304. });
  3305. newOptions = helpers.configMerge(
  3306. Chart.defaults.global,
  3307. Chart.defaults[chart.config.type],
  3308. newOptions);
  3309. chart.options = chart.config.options = newOptions;
  3310. chart.ensureScalesHaveIDs();
  3311. chart.buildOrUpdateScales();
  3312. // Tooltip
  3313. chart.tooltip._options = newOptions.tooltips;
  3314. chart.tooltip.initialize();
  3315. }
  3316. function positionIsHorizontal(position) {
  3317. return position === 'top' || position === 'bottom';
  3318. }
  3319. helpers.extend(Chart.prototype, /** @lends Chart */ {
  3320. /**
  3321. * @private
  3322. */
  3323. construct: function(item, config) {
  3324. var me = this;
  3325. config = initConfig(config);
  3326. var context = platform.acquireContext(item, config);
  3327. var canvas = context && context.canvas;
  3328. var height = canvas && canvas.height;
  3329. var width = canvas && canvas.width;
  3330. me.id = helpers.uid();
  3331. me.ctx = context;
  3332. me.canvas = canvas;
  3333. me.config = config;
  3334. me.width = width;
  3335. me.height = height;
  3336. me.aspectRatio = height ? width / height : null;
  3337. me.options = config.options;
  3338. me._bufferedRender = false;
  3339. /**
  3340. * Provided for backward compatibility, Chart and Chart.Controller have been merged,
  3341. * the "instance" still need to be defined since it might be called from plugins.
  3342. * @prop Chart#chart
  3343. * @deprecated since version 2.6.0
  3344. * @todo remove at version 3
  3345. * @private
  3346. */
  3347. me.chart = me;
  3348. me.controller = me; // chart.chart.controller #inception
  3349. // Add the chart instance to the global namespace
  3350. Chart.instances[me.id] = me;
  3351. // Define alias to the config data: `chart.data === chart.config.data`
  3352. Object.defineProperty(me, 'data', {
  3353. get: function() {
  3354. return me.config.data;
  3355. },
  3356. set: function(value) {
  3357. me.config.data = value;
  3358. }
  3359. });
  3360. if (!context || !canvas) {
  3361. // The given item is not a compatible context2d element, let's return before finalizing
  3362. // the chart initialization but after setting basic chart / controller properties that
  3363. // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
  3364. // https://github.com/chartjs/Chart.js/issues/2807
  3365. console.error("Failed to create chart: can't acquire context from the given item");
  3366. return;
  3367. }
  3368. me.initialize();
  3369. me.update();
  3370. },
  3371. /**
  3372. * @private
  3373. */
  3374. initialize: function() {
  3375. var me = this;
  3376. // Before init plugin notification
  3377. plugins.notify(me, 'beforeInit');
  3378. helpers.retinaScale(me, me.options.devicePixelRatio);
  3379. me.bindEvents();
  3380. if (me.options.responsive) {
  3381. // Initial resize before chart draws (must be silent to preserve initial animations).
  3382. me.resize(true);
  3383. }
  3384. // Make sure scales have IDs and are built before we build any controllers.
  3385. me.ensureScalesHaveIDs();
  3386. me.buildOrUpdateScales();
  3387. me.initToolTip();
  3388. // After init plugin notification
  3389. plugins.notify(me, 'afterInit');
  3390. return me;
  3391. },
  3392. clear: function() {
  3393. helpers.canvas.clear(this);
  3394. return this;
  3395. },
  3396. stop: function() {
  3397. // Stops any current animation loop occurring
  3398. animations.cancelAnimation(this);
  3399. return this;
  3400. },
  3401. resize: function(silent) {
  3402. var me = this;
  3403. var options = me.options;
  3404. var canvas = me.canvas;
  3405. var aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
  3406. // the canvas render width and height will be casted to integers so make sure that
  3407. // the canvas display style uses the same integer values to avoid blurring effect.
  3408. // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
  3409. var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
  3410. var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
  3411. if (me.width === newWidth && me.height === newHeight) {
  3412. return;
  3413. }
  3414. canvas.width = me.width = newWidth;
  3415. canvas.height = me.height = newHeight;
  3416. canvas.style.width = newWidth + 'px';
  3417. canvas.style.height = newHeight + 'px';
  3418. helpers.retinaScale(me, options.devicePixelRatio);
  3419. if (!silent) {
  3420. // Notify any plugins about the resize
  3421. var newSize = {width: newWidth, height: newHeight};
  3422. plugins.notify(me, 'resize', [newSize]);
  3423. // Notify of resize
  3424. if (me.options.onResize) {
  3425. me.options.onResize(me, newSize);
  3426. }
  3427. me.stop();
  3428. me.update({
  3429. duration: me.options.responsiveAnimationDuration
  3430. });
  3431. }
  3432. },
  3433. ensureScalesHaveIDs: function() {
  3434. var options = this.options;
  3435. var scalesOptions = options.scales || {};
  3436. var scaleOptions = options.scale;
  3437. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  3438. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3439. });
  3440. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  3441. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3442. });
  3443. if (scaleOptions) {
  3444. scaleOptions.id = scaleOptions.id || 'scale';
  3445. }
  3446. },
  3447. /**
  3448. * Builds a map of scale ID to scale object for future lookup.
  3449. */
  3450. buildOrUpdateScales: function() {
  3451. var me = this;
  3452. var options = me.options;
  3453. var scales = me.scales || {};
  3454. var items = [];
  3455. var updated = Object.keys(scales).reduce(function(obj, id) {
  3456. obj[id] = false;
  3457. return obj;
  3458. }, {});
  3459. if (options.scales) {
  3460. items = items.concat(
  3461. (options.scales.xAxes || []).map(function(xAxisOptions) {
  3462. return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
  3463. }),
  3464. (options.scales.yAxes || []).map(function(yAxisOptions) {
  3465. return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
  3466. })
  3467. );
  3468. }
  3469. if (options.scale) {
  3470. items.push({
  3471. options: options.scale,
  3472. dtype: 'radialLinear',
  3473. isDefault: true,
  3474. dposition: 'chartArea'
  3475. });
  3476. }
  3477. helpers.each(items, function(item) {
  3478. var scaleOptions = item.options;
  3479. var id = scaleOptions.id;
  3480. var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
  3481. if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
  3482. scaleOptions.position = item.dposition;
  3483. }
  3484. updated[id] = true;
  3485. var scale = null;
  3486. if (id in scales && scales[id].type === scaleType) {
  3487. scale = scales[id];
  3488. scale.options = scaleOptions;
  3489. scale.ctx = me.ctx;
  3490. scale.chart = me;
  3491. } else {
  3492. var scaleClass = scaleService.getScaleConstructor(scaleType);
  3493. if (!scaleClass) {
  3494. return;
  3495. }
  3496. scale = new scaleClass({
  3497. id: id,
  3498. type: scaleType,
  3499. options: scaleOptions,
  3500. ctx: me.ctx,
  3501. chart: me
  3502. });
  3503. scales[scale.id] = scale;
  3504. }
  3505. scale.mergeTicksOptions();
  3506. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3507. // and consider it as a regular scale part of the "scales"" map only! This would
  3508. // make the logic easier and remove some useless? custom code.
  3509. if (item.isDefault) {
  3510. me.scale = scale;
  3511. }
  3512. });
  3513. // clear up discarded scales
  3514. helpers.each(updated, function(hasUpdated, id) {
  3515. if (!hasUpdated) {
  3516. delete scales[id];
  3517. }
  3518. });
  3519. me.scales = scales;
  3520. scaleService.addScalesToLayout(this);
  3521. },
  3522. buildOrUpdateControllers: function() {
  3523. var me = this;
  3524. var types = [];
  3525. var newControllers = [];
  3526. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3527. var meta = me.getDatasetMeta(datasetIndex);
  3528. var type = dataset.type || me.config.type;
  3529. if (meta.type && meta.type !== type) {
  3530. me.destroyDatasetMeta(datasetIndex);
  3531. meta = me.getDatasetMeta(datasetIndex);
  3532. }
  3533. meta.type = type;
  3534. types.push(meta.type);
  3535. if (meta.controller) {
  3536. meta.controller.updateIndex(datasetIndex);
  3537. meta.controller.linkScales();
  3538. } else {
  3539. var ControllerClass = Chart.controllers[meta.type];
  3540. if (ControllerClass === undefined) {
  3541. throw new Error('"' + meta.type + '" is not a chart type.');
  3542. }
  3543. meta.controller = new ControllerClass(me, datasetIndex);
  3544. newControllers.push(meta.controller);
  3545. }
  3546. }, me);
  3547. return newControllers;
  3548. },
  3549. /**
  3550. * Reset the elements of all datasets
  3551. * @private
  3552. */
  3553. resetElements: function() {
  3554. var me = this;
  3555. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3556. me.getDatasetMeta(datasetIndex).controller.reset();
  3557. }, me);
  3558. },
  3559. /**
  3560. * Resets the chart back to it's state before the initial animation
  3561. */
  3562. reset: function() {
  3563. this.resetElements();
  3564. this.tooltip.initialize();
  3565. },
  3566. update: function(config) {
  3567. var me = this;
  3568. if (!config || typeof config !== 'object') {
  3569. // backwards compatibility
  3570. config = {
  3571. duration: config,
  3572. lazy: arguments[1]
  3573. };
  3574. }
  3575. updateConfig(me);
  3576. // plugins options references might have change, let's invalidate the cache
  3577. // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  3578. plugins._invalidate(me);
  3579. if (plugins.notify(me, 'beforeUpdate') === false) {
  3580. return;
  3581. }
  3582. // In case the entire data object changed
  3583. me.tooltip._data = me.data;
  3584. // Make sure dataset controllers are updated and new controllers are reset
  3585. var newControllers = me.buildOrUpdateControllers();
  3586. // Make sure all dataset controllers have correct meta data counts
  3587. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3588. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3589. }, me);
  3590. me.updateLayout();
  3591. // Can only reset the new controllers after the scales have been updated
  3592. if (me.options.animation && me.options.animation.duration) {
  3593. helpers.each(newControllers, function(controller) {
  3594. controller.reset();
  3595. });
  3596. }
  3597. me.updateDatasets();
  3598. // Need to reset tooltip in case it is displayed with elements that are removed
  3599. // after update.
  3600. me.tooltip.initialize();
  3601. // Last active contains items that were previously in the tooltip.
  3602. // When we reset the tooltip, we need to clear it
  3603. me.lastActive = [];
  3604. // Do this before render so that any plugins that need final scale updates can use it
  3605. plugins.notify(me, 'afterUpdate');
  3606. if (me._bufferedRender) {
  3607. me._bufferedRequest = {
  3608. duration: config.duration,
  3609. easing: config.easing,
  3610. lazy: config.lazy
  3611. };
  3612. } else {
  3613. me.render(config);
  3614. }
  3615. },
  3616. /**
  3617. * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
  3618. * hook, in which case, plugins will not be called on `afterLayout`.
  3619. * @private
  3620. */
  3621. updateLayout: function() {
  3622. var me = this;
  3623. if (plugins.notify(me, 'beforeLayout') === false) {
  3624. return;
  3625. }
  3626. layouts.update(this, this.width, this.height);
  3627. /**
  3628. * Provided for backward compatibility, use `afterLayout` instead.
  3629. * @method IPlugin#afterScaleUpdate
  3630. * @deprecated since version 2.5.0
  3631. * @todo remove at version 3
  3632. * @private
  3633. */
  3634. plugins.notify(me, 'afterScaleUpdate');
  3635. plugins.notify(me, 'afterLayout');
  3636. },
  3637. /**
  3638. * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
  3639. * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
  3640. * @private
  3641. */
  3642. updateDatasets: function() {
  3643. var me = this;
  3644. if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
  3645. return;
  3646. }
  3647. for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3648. me.updateDataset(i);
  3649. }
  3650. plugins.notify(me, 'afterDatasetsUpdate');
  3651. },
  3652. /**
  3653. * Updates dataset at index unless a plugin returns `false` to the `beforeDatasetUpdate`
  3654. * hook, in which case, plugins will not be called on `afterDatasetUpdate`.
  3655. * @private
  3656. */
  3657. updateDataset: function(index) {
  3658. var me = this;
  3659. var meta = me.getDatasetMeta(index);
  3660. var args = {
  3661. meta: meta,
  3662. index: index
  3663. };
  3664. if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
  3665. return;
  3666. }
  3667. meta.controller.update();
  3668. plugins.notify(me, 'afterDatasetUpdate', [args]);
  3669. },
  3670. render: function(config) {
  3671. var me = this;
  3672. if (!config || typeof config !== 'object') {
  3673. // backwards compatibility
  3674. config = {
  3675. duration: config,
  3676. lazy: arguments[1]
  3677. };
  3678. }
  3679. var duration = config.duration;
  3680. var lazy = config.lazy;
  3681. if (plugins.notify(me, 'beforeRender') === false) {
  3682. return;
  3683. }
  3684. var animationOptions = me.options.animation;
  3685. var onComplete = function(animation) {
  3686. plugins.notify(me, 'afterRender');
  3687. helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
  3688. };
  3689. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3690. var animation = new Animation({
  3691. numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
  3692. easing: config.easing || animationOptions.easing,
  3693. render: function(chart, animationObject) {
  3694. var easingFunction = helpers.easing.effects[animationObject.easing];
  3695. var currentStep = animationObject.currentStep;
  3696. var stepDecimal = currentStep / animationObject.numSteps;
  3697. chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep);
  3698. },
  3699. onAnimationProgress: animationOptions.onProgress,
  3700. onAnimationComplete: onComplete
  3701. });
  3702. animations.addAnimation(me, animation, duration, lazy);
  3703. } else {
  3704. me.draw();
  3705. // See https://github.com/chartjs/Chart.js/issues/3781
  3706. onComplete(new Animation({numSteps: 0, chart: me}));
  3707. }
  3708. return me;
  3709. },
  3710. draw: function(easingValue) {
  3711. var me = this;
  3712. me.clear();
  3713. if (helpers.isNullOrUndef(easingValue)) {
  3714. easingValue = 1;
  3715. }
  3716. me.transition(easingValue);
  3717. if (me.width <= 0 || me.height <= 0) {
  3718. return;
  3719. }
  3720. if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
  3721. return;
  3722. }
  3723. // Draw all the scales
  3724. helpers.each(me.boxes, function(box) {
  3725. box.draw(me.chartArea);
  3726. }, me);
  3727. if (me.scale) {
  3728. me.scale.draw();
  3729. }
  3730. me.drawDatasets(easingValue);
  3731. me._drawTooltip(easingValue);
  3732. plugins.notify(me, 'afterDraw', [easingValue]);
  3733. },
  3734. /**
  3735. * @private
  3736. */
  3737. transition: function(easingValue) {
  3738. var me = this;
  3739. for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
  3740. if (me.isDatasetVisible(i)) {
  3741. me.getDatasetMeta(i).controller.transition(easingValue);
  3742. }
  3743. }
  3744. me.tooltip.transition(easingValue);
  3745. },
  3746. /**
  3747. * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
  3748. * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
  3749. * @private
  3750. */
  3751. drawDatasets: function(easingValue) {
  3752. var me = this;
  3753. if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
  3754. return;
  3755. }
  3756. // Draw datasets reversed to support proper line stacking
  3757. for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
  3758. if (me.isDatasetVisible(i)) {
  3759. me.drawDataset(i, easingValue);
  3760. }
  3761. }
  3762. plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
  3763. },
  3764. /**
  3765. * Draws dataset at index unless a plugin returns `false` to the `beforeDatasetDraw`
  3766. * hook, in which case, plugins will not be called on `afterDatasetDraw`.
  3767. * @private
  3768. */
  3769. drawDataset: function(index, easingValue) {
  3770. var me = this;
  3771. var meta = me.getDatasetMeta(index);
  3772. var args = {
  3773. meta: meta,
  3774. index: index,
  3775. easingValue: easingValue
  3776. };
  3777. if (plugins.notify(me, 'beforeDatasetDraw', [args]) === false) {
  3778. return;
  3779. }
  3780. meta.controller.draw(easingValue);
  3781. plugins.notify(me, 'afterDatasetDraw', [args]);
  3782. },
  3783. /**
  3784. * Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
  3785. * hook, in which case, plugins will not be called on `afterTooltipDraw`.
  3786. * @private
  3787. */
  3788. _drawTooltip: function(easingValue) {
  3789. var me = this;
  3790. var tooltip = me.tooltip;
  3791. var args = {
  3792. tooltip: tooltip,
  3793. easingValue: easingValue
  3794. };
  3795. if (plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
  3796. return;
  3797. }
  3798. tooltip.draw();
  3799. plugins.notify(me, 'afterTooltipDraw', [args]);
  3800. },
  3801. // Get the single element that was clicked on
  3802. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3803. getElementAtEvent: function(e) {
  3804. return Interaction.modes.single(this, e);
  3805. },
  3806. getElementsAtEvent: function(e) {
  3807. return Interaction.modes.label(this, e, {intersect: true});
  3808. },
  3809. getElementsAtXAxis: function(e) {
  3810. return Interaction.modes['x-axis'](this, e, {intersect: true});
  3811. },
  3812. getElementsAtEventForMode: function(e, mode, options) {
  3813. var method = Interaction.modes[mode];
  3814. if (typeof method === 'function') {
  3815. return method(this, e, options);
  3816. }
  3817. return [];
  3818. },
  3819. getDatasetAtEvent: function(e) {
  3820. return Interaction.modes.dataset(this, e, {intersect: true});
  3821. },
  3822. getDatasetMeta: function(datasetIndex) {
  3823. var me = this;
  3824. var dataset = me.data.datasets[datasetIndex];
  3825. if (!dataset._meta) {
  3826. dataset._meta = {};
  3827. }
  3828. var meta = dataset._meta[me.id];
  3829. if (!meta) {
  3830. meta = dataset._meta[me.id] = {
  3831. type: null,
  3832. data: [],
  3833. dataset: null,
  3834. controller: null,
  3835. hidden: null, // See isDatasetVisible() comment
  3836. xAxisID: null,
  3837. yAxisID: null
  3838. };
  3839. }
  3840. return meta;
  3841. },
  3842. getVisibleDatasetCount: function() {
  3843. var count = 0;
  3844. for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
  3845. if (this.isDatasetVisible(i)) {
  3846. count++;
  3847. }
  3848. }
  3849. return count;
  3850. },
  3851. isDatasetVisible: function(datasetIndex) {
  3852. var meta = this.getDatasetMeta(datasetIndex);
  3853. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  3854. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  3855. return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  3856. },
  3857. generateLegend: function() {
  3858. return this.options.legendCallback(this);
  3859. },
  3860. /**
  3861. * @private
  3862. */
  3863. destroyDatasetMeta: function(datasetIndex) {
  3864. var id = this.id;
  3865. var dataset = this.data.datasets[datasetIndex];
  3866. var meta = dataset._meta && dataset._meta[id];
  3867. if (meta) {
  3868. meta.controller.destroy();
  3869. delete dataset._meta[id];
  3870. }
  3871. },
  3872. destroy: function() {
  3873. var me = this;
  3874. var canvas = me.canvas;
  3875. var i, ilen;
  3876. me.stop();
  3877. // dataset controllers need to cleanup associated data
  3878. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3879. me.destroyDatasetMeta(i);
  3880. }
  3881. if (canvas) {
  3882. me.unbindEvents();
  3883. helpers.canvas.clear(me);
  3884. platform.releaseContext(me.ctx);
  3885. me.canvas = null;
  3886. me.ctx = null;
  3887. }
  3888. plugins.notify(me, 'destroy');
  3889. delete Chart.instances[me.id];
  3890. },
  3891. toBase64Image: function() {
  3892. return this.canvas.toDataURL.apply(this.canvas, arguments);
  3893. },
  3894. initToolTip: function() {
  3895. var me = this;
  3896. me.tooltip = new Tooltip({
  3897. _chart: me,
  3898. _chartInstance: me, // deprecated, backward compatibility
  3899. _data: me.data,
  3900. _options: me.options.tooltips
  3901. }, me);
  3902. },
  3903. /**
  3904. * @private
  3905. */
  3906. bindEvents: function() {
  3907. var me = this;
  3908. var listeners = me._listeners = {};
  3909. var listener = function() {
  3910. me.eventHandler.apply(me, arguments);
  3911. };
  3912. helpers.each(me.options.events, function(type) {
  3913. platform.addEventListener(me, type, listener);
  3914. listeners[type] = listener;
  3915. });
  3916. // Elements used to detect size change should not be injected for non responsive charts.
  3917. // See https://github.com/chartjs/Chart.js/issues/2210
  3918. if (me.options.responsive) {
  3919. listener = function() {
  3920. me.resize();
  3921. };
  3922. platform.addEventListener(me, 'resize', listener);
  3923. listeners.resize = listener;
  3924. }
  3925. },
  3926. /**
  3927. * @private
  3928. */
  3929. unbindEvents: function() {
  3930. var me = this;
  3931. var listeners = me._listeners;
  3932. if (!listeners) {
  3933. return;
  3934. }
  3935. delete me._listeners;
  3936. helpers.each(listeners, function(listener, type) {
  3937. platform.removeEventListener(me, type, listener);
  3938. });
  3939. },
  3940. updateHoverStyle: function(elements, mode, enabled) {
  3941. var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
  3942. var element, i, ilen;
  3943. for (i = 0, ilen = elements.length; i < ilen; ++i) {
  3944. element = elements[i];
  3945. if (element) {
  3946. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  3947. }
  3948. }
  3949. },
  3950. /**
  3951. * @private
  3952. */
  3953. eventHandler: function(e) {
  3954. var me = this;
  3955. var tooltip = me.tooltip;
  3956. if (plugins.notify(me, 'beforeEvent', [e]) === false) {
  3957. return;
  3958. }
  3959. // Buffer any update calls so that renders do not occur
  3960. me._bufferedRender = true;
  3961. me._bufferedRequest = null;
  3962. var changed = me.handleEvent(e);
  3963. // for smooth tooltip animations issue #4989
  3964. // the tooltip should be the source of change
  3965. // Animation check workaround:
  3966. // tooltip._start will be null when tooltip isn't animating
  3967. if (tooltip) {
  3968. changed = tooltip._start
  3969. ? tooltip.handleEvent(e)
  3970. : changed | tooltip.handleEvent(e);
  3971. }
  3972. plugins.notify(me, 'afterEvent', [e]);
  3973. var bufferedRequest = me._bufferedRequest;
  3974. if (bufferedRequest) {
  3975. // If we have an update that was triggered, we need to do a normal render
  3976. me.render(bufferedRequest);
  3977. } else if (changed && !me.animating) {
  3978. // If entering, leaving, or changing elements, animate the change via pivot
  3979. me.stop();
  3980. // We only need to render at this point. Updating will cause scales to be
  3981. // recomputed generating flicker & using more memory than necessary.
  3982. me.render({
  3983. duration: me.options.hover.animationDuration,
  3984. lazy: true
  3985. });
  3986. }
  3987. me._bufferedRender = false;
  3988. me._bufferedRequest = null;
  3989. return me;
  3990. },
  3991. /**
  3992. * Handle an event
  3993. * @private
  3994. * @param {IEvent} event the event to handle
  3995. * @return {Boolean} true if the chart needs to re-render
  3996. */
  3997. handleEvent: function(e) {
  3998. var me = this;
  3999. var options = me.options || {};
  4000. var hoverOptions = options.hover;
  4001. var changed = false;
  4002. me.lastActive = me.lastActive || [];
  4003. // Find Active Elements for hover and tooltips
  4004. if (e.type === 'mouseout') {
  4005. me.active = [];
  4006. } else {
  4007. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
  4008. }
  4009. // Invoke onHover hook
  4010. // Need to call with native event here to not break backwards compatibility
  4011. helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
  4012. if (e.type === 'mouseup' || e.type === 'click') {
  4013. if (options.onClick) {
  4014. // Use e.native here for backwards compatibility
  4015. options.onClick.call(me, e.native, me.active);
  4016. }
  4017. }
  4018. // Remove styling for last active (even if it may still be active)
  4019. if (me.lastActive.length) {
  4020. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  4021. }
  4022. // Built in hover styling
  4023. if (me.active.length && hoverOptions.mode) {
  4024. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  4025. }
  4026. changed = !helpers.arrayEquals(me.active, me.lastActive);
  4027. // Remember Last Actives
  4028. me.lastActive = me.active;
  4029. return changed;
  4030. }
  4031. });
  4032. /**
  4033. * Provided for backward compatibility, use Chart instead.
  4034. * @class Chart.Controller
  4035. * @deprecated since version 2.6.0
  4036. * @todo remove at version 3
  4037. * @private
  4038. */
  4039. Chart.Controller = Chart;
  4040. };
  4041. },{"22":22,"23":23,"26":26,"29":29,"31":31,"32":32,"34":34,"36":36,"46":46,"49":49}],25:[function(require,module,exports){
  4042. 'use strict';
  4043. var helpers = require(46);
  4044. module.exports = function(Chart) {
  4045. var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  4046. /**
  4047. * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
  4048. * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
  4049. * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
  4050. */
  4051. function listenArrayEvents(array, listener) {
  4052. if (array._chartjs) {
  4053. array._chartjs.listeners.push(listener);
  4054. return;
  4055. }
  4056. Object.defineProperty(array, '_chartjs', {
  4057. configurable: true,
  4058. enumerable: false,
  4059. value: {
  4060. listeners: [listener]
  4061. }
  4062. });
  4063. arrayEvents.forEach(function(key) {
  4064. var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
  4065. var base = array[key];
  4066. Object.defineProperty(array, key, {
  4067. configurable: true,
  4068. enumerable: false,
  4069. value: function() {
  4070. var args = Array.prototype.slice.call(arguments);
  4071. var res = base.apply(this, args);
  4072. helpers.each(array._chartjs.listeners, function(object) {
  4073. if (typeof object[method] === 'function') {
  4074. object[method].apply(object, args);
  4075. }
  4076. });
  4077. return res;
  4078. }
  4079. });
  4080. });
  4081. }
  4082. /**
  4083. * Removes the given array event listener and cleanup extra attached properties (such as
  4084. * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
  4085. */
  4086. function unlistenArrayEvents(array, listener) {
  4087. var stub = array._chartjs;
  4088. if (!stub) {
  4089. return;
  4090. }
  4091. var listeners = stub.listeners;
  4092. var index = listeners.indexOf(listener);
  4093. if (index !== -1) {
  4094. listeners.splice(index, 1);
  4095. }
  4096. if (listeners.length > 0) {
  4097. return;
  4098. }
  4099. arrayEvents.forEach(function(key) {
  4100. delete array[key];
  4101. });
  4102. delete array._chartjs;
  4103. }
  4104. // Base class for all dataset controllers (line, bar, etc)
  4105. Chart.DatasetController = function(chart, datasetIndex) {
  4106. this.initialize(chart, datasetIndex);
  4107. };
  4108. helpers.extend(Chart.DatasetController.prototype, {
  4109. /**
  4110. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  4111. * @type {Chart.core.element}
  4112. */
  4113. datasetElementType: null,
  4114. /**
  4115. * Element type used to generate a meta data (e.g. Chart.element.Point).
  4116. * @type {Chart.core.element}
  4117. */
  4118. dataElementType: null,
  4119. initialize: function(chart, datasetIndex) {
  4120. var me = this;
  4121. me.chart = chart;
  4122. me.index = datasetIndex;
  4123. me.linkScales();
  4124. me.addElements();
  4125. },
  4126. updateIndex: function(datasetIndex) {
  4127. this.index = datasetIndex;
  4128. },
  4129. linkScales: function() {
  4130. var me = this;
  4131. var meta = me.getMeta();
  4132. var dataset = me.getDataset();
  4133. if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
  4134. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  4135. }
  4136. if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
  4137. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  4138. }
  4139. },
  4140. getDataset: function() {
  4141. return this.chart.data.datasets[this.index];
  4142. },
  4143. getMeta: function() {
  4144. return this.chart.getDatasetMeta(this.index);
  4145. },
  4146. getScaleForId: function(scaleID) {
  4147. return this.chart.scales[scaleID];
  4148. },
  4149. reset: function() {
  4150. this.update(true);
  4151. },
  4152. /**
  4153. * @private
  4154. */
  4155. destroy: function() {
  4156. if (this._data) {
  4157. unlistenArrayEvents(this._data, this);
  4158. }
  4159. },
  4160. createMetaDataset: function() {
  4161. var me = this;
  4162. var type = me.datasetElementType;
  4163. return type && new type({
  4164. _chart: me.chart,
  4165. _datasetIndex: me.index
  4166. });
  4167. },
  4168. createMetaData: function(index) {
  4169. var me = this;
  4170. var type = me.dataElementType;
  4171. return type && new type({
  4172. _chart: me.chart,
  4173. _datasetIndex: me.index,
  4174. _index: index
  4175. });
  4176. },
  4177. addElements: function() {
  4178. var me = this;
  4179. var meta = me.getMeta();
  4180. var data = me.getDataset().data || [];
  4181. var metaData = meta.data;
  4182. var i, ilen;
  4183. for (i = 0, ilen = data.length; i < ilen; ++i) {
  4184. metaData[i] = metaData[i] || me.createMetaData(i);
  4185. }
  4186. meta.dataset = meta.dataset || me.createMetaDataset();
  4187. },
  4188. addElementAndReset: function(index) {
  4189. var element = this.createMetaData(index);
  4190. this.getMeta().data.splice(index, 0, element);
  4191. this.updateElement(element, index, true);
  4192. },
  4193. buildOrUpdateElements: function() {
  4194. var me = this;
  4195. var dataset = me.getDataset();
  4196. var data = dataset.data || (dataset.data = []);
  4197. // In order to correctly handle data addition/deletion animation (an thus simulate
  4198. // real-time charts), we need to monitor these data modifications and synchronize
  4199. // the internal meta data accordingly.
  4200. if (me._data !== data) {
  4201. if (me._data) {
  4202. // This case happens when the user replaced the data array instance.
  4203. unlistenArrayEvents(me._data, me);
  4204. }
  4205. listenArrayEvents(data, me);
  4206. me._data = data;
  4207. }
  4208. // Re-sync meta data in case the user replaced the data array or if we missed
  4209. // any updates and so make sure that we handle number of datapoints changing.
  4210. me.resyncElements();
  4211. },
  4212. update: helpers.noop,
  4213. transition: function(easingValue) {
  4214. var meta = this.getMeta();
  4215. var elements = meta.data || [];
  4216. var ilen = elements.length;
  4217. var i = 0;
  4218. for (; i < ilen; ++i) {
  4219. elements[i].transition(easingValue);
  4220. }
  4221. if (meta.dataset) {
  4222. meta.dataset.transition(easingValue);
  4223. }
  4224. },
  4225. draw: function() {
  4226. var meta = this.getMeta();
  4227. var elements = meta.data || [];
  4228. var ilen = elements.length;
  4229. var i = 0;
  4230. if (meta.dataset) {
  4231. meta.dataset.draw();
  4232. }
  4233. for (; i < ilen; ++i) {
  4234. elements[i].draw();
  4235. }
  4236. },
  4237. removeHoverStyle: function(element) {
  4238. helpers.merge(element._model, element.$previousStyle || {});
  4239. delete element.$previousStyle;
  4240. },
  4241. setHoverStyle: function(element) {
  4242. var dataset = this.chart.data.datasets[element._datasetIndex];
  4243. var index = element._index;
  4244. var custom = element.custom || {};
  4245. var valueOrDefault = helpers.valueAtIndexOrDefault;
  4246. var getHoverColor = helpers.getHoverColor;
  4247. var model = element._model;
  4248. element.$previousStyle = {
  4249. backgroundColor: model.backgroundColor,
  4250. borderColor: model.borderColor,
  4251. borderWidth: model.borderWidth
  4252. };
  4253. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  4254. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  4255. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  4256. },
  4257. /**
  4258. * @private
  4259. */
  4260. resyncElements: function() {
  4261. var me = this;
  4262. var meta = me.getMeta();
  4263. var data = me.getDataset().data;
  4264. var numMeta = meta.data.length;
  4265. var numData = data.length;
  4266. if (numData < numMeta) {
  4267. meta.data.splice(numData, numMeta - numData);
  4268. } else if (numData > numMeta) {
  4269. me.insertElements(numMeta, numData - numMeta);
  4270. }
  4271. },
  4272. /**
  4273. * @private
  4274. */
  4275. insertElements: function(start, count) {
  4276. for (var i = 0; i < count; ++i) {
  4277. this.addElementAndReset(start + i);
  4278. }
  4279. },
  4280. /**
  4281. * @private
  4282. */
  4283. onDataPush: function() {
  4284. this.insertElements(this.getDataset().data.length - 1, arguments.length);
  4285. },
  4286. /**
  4287. * @private
  4288. */
  4289. onDataPop: function() {
  4290. this.getMeta().data.pop();
  4291. },
  4292. /**
  4293. * @private
  4294. */
  4295. onDataShift: function() {
  4296. this.getMeta().data.shift();
  4297. },
  4298. /**
  4299. * @private
  4300. */
  4301. onDataSplice: function(start, count) {
  4302. this.getMeta().data.splice(start, count);
  4303. this.insertElements(start, arguments.length - 2);
  4304. },
  4305. /**
  4306. * @private
  4307. */
  4308. onDataUnshift: function() {
  4309. this.insertElements(0, arguments.length);
  4310. }
  4311. });
  4312. Chart.DatasetController.extend = helpers.inherits;
  4313. };
  4314. },{"46":46}],26:[function(require,module,exports){
  4315. 'use strict';
  4316. var helpers = require(46);
  4317. module.exports = {
  4318. /**
  4319. * @private
  4320. */
  4321. _set: function(scope, values) {
  4322. return helpers.merge(this[scope] || (this[scope] = {}), values);
  4323. }
  4324. };
  4325. },{"46":46}],27:[function(require,module,exports){
  4326. 'use strict';
  4327. var color = require(3);
  4328. var helpers = require(46);
  4329. function interpolate(start, view, model, ease) {
  4330. var keys = Object.keys(model);
  4331. var i, ilen, key, actual, origin, target, type, c0, c1;
  4332. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  4333. key = keys[i];
  4334. target = model[key];
  4335. // if a value is added to the model after pivot() has been called, the view
  4336. // doesn't contain it, so let's initialize the view to the target value.
  4337. if (!view.hasOwnProperty(key)) {
  4338. view[key] = target;
  4339. }
  4340. actual = view[key];
  4341. if (actual === target || key[0] === '_') {
  4342. continue;
  4343. }
  4344. if (!start.hasOwnProperty(key)) {
  4345. start[key] = actual;
  4346. }
  4347. origin = start[key];
  4348. type = typeof target;
  4349. if (type === typeof origin) {
  4350. if (type === 'string') {
  4351. c0 = color(origin);
  4352. if (c0.valid) {
  4353. c1 = color(target);
  4354. if (c1.valid) {
  4355. view[key] = c1.mix(c0, ease).rgbString();
  4356. continue;
  4357. }
  4358. }
  4359. } else if (type === 'number' && isFinite(origin) && isFinite(target)) {
  4360. view[key] = origin + (target - origin) * ease;
  4361. continue;
  4362. }
  4363. }
  4364. view[key] = target;
  4365. }
  4366. }
  4367. var Element = function(configuration) {
  4368. helpers.extend(this, configuration);
  4369. this.initialize.apply(this, arguments);
  4370. };
  4371. helpers.extend(Element.prototype, {
  4372. initialize: function() {
  4373. this.hidden = false;
  4374. },
  4375. pivot: function() {
  4376. var me = this;
  4377. if (!me._view) {
  4378. me._view = helpers.clone(me._model);
  4379. }
  4380. me._start = {};
  4381. return me;
  4382. },
  4383. transition: function(ease) {
  4384. var me = this;
  4385. var model = me._model;
  4386. var start = me._start;
  4387. var view = me._view;
  4388. // No animation -> No Transition
  4389. if (!model || ease === 1) {
  4390. me._view = model;
  4391. me._start = null;
  4392. return me;
  4393. }
  4394. if (!view) {
  4395. view = me._view = {};
  4396. }
  4397. if (!start) {
  4398. start = me._start = {};
  4399. }
  4400. interpolate(start, view, model, ease);
  4401. return me;
  4402. },
  4403. tooltipPosition: function() {
  4404. return {
  4405. x: this._model.x,
  4406. y: this._model.y
  4407. };
  4408. },
  4409. hasValue: function() {
  4410. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4411. }
  4412. });
  4413. Element.extend = helpers.inherits;
  4414. module.exports = Element;
  4415. },{"3":3,"46":46}],28:[function(require,module,exports){
  4416. /* global window: false */
  4417. /* global document: false */
  4418. 'use strict';
  4419. var color = require(3);
  4420. var defaults = require(26);
  4421. var helpers = require(46);
  4422. var scaleService = require(34);
  4423. module.exports = function() {
  4424. // -- Basic js utility methods
  4425. helpers.configMerge = function(/* objects ... */) {
  4426. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4427. merger: function(key, target, source, options) {
  4428. var tval = target[key] || {};
  4429. var sval = source[key];
  4430. if (key === 'scales') {
  4431. // scale config merging is complex. Add our own function here for that
  4432. target[key] = helpers.scaleMerge(tval, sval);
  4433. } else if (key === 'scale') {
  4434. // used in polar area & radar charts since there is only one scale
  4435. target[key] = helpers.merge(tval, [scaleService.getScaleDefaults(sval.type), sval]);
  4436. } else {
  4437. helpers._merger(key, target, source, options);
  4438. }
  4439. }
  4440. });
  4441. };
  4442. helpers.scaleMerge = function(/* objects ... */) {
  4443. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4444. merger: function(key, target, source, options) {
  4445. if (key === 'xAxes' || key === 'yAxes') {
  4446. var slen = source[key].length;
  4447. var i, type, scale;
  4448. if (!target[key]) {
  4449. target[key] = [];
  4450. }
  4451. for (i = 0; i < slen; ++i) {
  4452. scale = source[key][i];
  4453. type = helpers.valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
  4454. if (i >= target[key].length) {
  4455. target[key].push({});
  4456. }
  4457. if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
  4458. // new/untyped scale or type changed: let's apply the new defaults
  4459. // then merge source scale to correctly overwrite the defaults.
  4460. helpers.merge(target[key][i], [scaleService.getScaleDefaults(type), scale]);
  4461. } else {
  4462. // scales type are the same
  4463. helpers.merge(target[key][i], scale);
  4464. }
  4465. }
  4466. } else {
  4467. helpers._merger(key, target, source, options);
  4468. }
  4469. }
  4470. });
  4471. };
  4472. helpers.where = function(collection, filterCallback) {
  4473. if (helpers.isArray(collection) && Array.prototype.filter) {
  4474. return collection.filter(filterCallback);
  4475. }
  4476. var filtered = [];
  4477. helpers.each(collection, function(item) {
  4478. if (filterCallback(item)) {
  4479. filtered.push(item);
  4480. }
  4481. });
  4482. return filtered;
  4483. };
  4484. helpers.findIndex = Array.prototype.findIndex ?
  4485. function(array, callback, scope) {
  4486. return array.findIndex(callback, scope);
  4487. } :
  4488. function(array, callback, scope) {
  4489. scope = scope === undefined ? array : scope;
  4490. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4491. if (callback.call(scope, array[i], i, array)) {
  4492. return i;
  4493. }
  4494. }
  4495. return -1;
  4496. };
  4497. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  4498. // Default to start of the array
  4499. if (helpers.isNullOrUndef(startIndex)) {
  4500. startIndex = -1;
  4501. }
  4502. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4503. var currentItem = arrayToSearch[i];
  4504. if (filterCallback(currentItem)) {
  4505. return currentItem;
  4506. }
  4507. }
  4508. };
  4509. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  4510. // Default to end of the array
  4511. if (helpers.isNullOrUndef(startIndex)) {
  4512. startIndex = arrayToSearch.length;
  4513. }
  4514. for (var i = startIndex - 1; i >= 0; i--) {
  4515. var currentItem = arrayToSearch[i];
  4516. if (filterCallback(currentItem)) {
  4517. return currentItem;
  4518. }
  4519. }
  4520. };
  4521. // -- Math methods
  4522. helpers.isNumber = function(n) {
  4523. return !isNaN(parseFloat(n)) && isFinite(n);
  4524. };
  4525. helpers.almostEquals = function(x, y, epsilon) {
  4526. return Math.abs(x - y) < epsilon;
  4527. };
  4528. helpers.almostWhole = function(x, epsilon) {
  4529. var rounded = Math.round(x);
  4530. return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
  4531. };
  4532. helpers.max = function(array) {
  4533. return array.reduce(function(max, value) {
  4534. if (!isNaN(value)) {
  4535. return Math.max(max, value);
  4536. }
  4537. return max;
  4538. }, Number.NEGATIVE_INFINITY);
  4539. };
  4540. helpers.min = function(array) {
  4541. return array.reduce(function(min, value) {
  4542. if (!isNaN(value)) {
  4543. return Math.min(min, value);
  4544. }
  4545. return min;
  4546. }, Number.POSITIVE_INFINITY);
  4547. };
  4548. helpers.sign = Math.sign ?
  4549. function(x) {
  4550. return Math.sign(x);
  4551. } :
  4552. function(x) {
  4553. x = +x; // convert to a number
  4554. if (x === 0 || isNaN(x)) {
  4555. return x;
  4556. }
  4557. return x > 0 ? 1 : -1;
  4558. };
  4559. helpers.log10 = Math.log10 ?
  4560. function(x) {
  4561. return Math.log10(x);
  4562. } :
  4563. function(x) {
  4564. var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
  4565. // Check for whole powers of 10,
  4566. // which due to floating point rounding error should be corrected.
  4567. var powerOf10 = Math.round(exponent);
  4568. var isPowerOf10 = x === Math.pow(10, powerOf10);
  4569. return isPowerOf10 ? powerOf10 : exponent;
  4570. };
  4571. helpers.toRadians = function(degrees) {
  4572. return degrees * (Math.PI / 180);
  4573. };
  4574. helpers.toDegrees = function(radians) {
  4575. return radians * (180 / Math.PI);
  4576. };
  4577. // Gets the angle from vertical upright to the point about a centre.
  4578. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  4579. var distanceFromXCenter = anglePoint.x - centrePoint.x;
  4580. var distanceFromYCenter = anglePoint.y - centrePoint.y;
  4581. var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4582. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4583. if (angle < (-0.5 * Math.PI)) {
  4584. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4585. }
  4586. return {
  4587. angle: angle,
  4588. distance: radialDistanceFromCenter
  4589. };
  4590. };
  4591. helpers.distanceBetweenPoints = function(pt1, pt2) {
  4592. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  4593. };
  4594. helpers.aliasPixel = function(pixelWidth) {
  4595. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4596. };
  4597. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  4598. // Props to Rob Spencer at scaled innovation for his post on splining between points
  4599. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4600. // This function must also respect "skipped" points
  4601. var previous = firstPoint.skip ? middlePoint : firstPoint;
  4602. var current = middlePoint;
  4603. var next = afterPoint.skip ? middlePoint : afterPoint;
  4604. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4605. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4606. var s01 = d01 / (d01 + d12);
  4607. var s12 = d12 / (d01 + d12);
  4608. // If all points are the same, s01 & s02 will be inf
  4609. s01 = isNaN(s01) ? 0 : s01;
  4610. s12 = isNaN(s12) ? 0 : s12;
  4611. var fa = t * s01; // scaling factor for triangle Ta
  4612. var fb = t * s12;
  4613. return {
  4614. previous: {
  4615. x: current.x - fa * (next.x - previous.x),
  4616. y: current.y - fa * (next.y - previous.y)
  4617. },
  4618. next: {
  4619. x: current.x + fb * (next.x - previous.x),
  4620. y: current.y + fb * (next.y - previous.y)
  4621. }
  4622. };
  4623. };
  4624. helpers.EPSILON = Number.EPSILON || 1e-14;
  4625. helpers.splineCurveMonotone = function(points) {
  4626. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4627. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4628. // between the dataset discrete points due to the interpolation.
  4629. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4630. var pointsWithTangents = (points || []).map(function(point) {
  4631. return {
  4632. model: point._model,
  4633. deltaK: 0,
  4634. mK: 0
  4635. };
  4636. });
  4637. // Calculate slopes (deltaK) and initialize tangents (mK)
  4638. var pointsLen = pointsWithTangents.length;
  4639. var i, pointBefore, pointCurrent, pointAfter;
  4640. for (i = 0; i < pointsLen; ++i) {
  4641. pointCurrent = pointsWithTangents[i];
  4642. if (pointCurrent.model.skip) {
  4643. continue;
  4644. }
  4645. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4646. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4647. if (pointAfter && !pointAfter.model.skip) {
  4648. var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
  4649. // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
  4650. pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
  4651. }
  4652. if (!pointBefore || pointBefore.model.skip) {
  4653. pointCurrent.mK = pointCurrent.deltaK;
  4654. } else if (!pointAfter || pointAfter.model.skip) {
  4655. pointCurrent.mK = pointBefore.deltaK;
  4656. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4657. pointCurrent.mK = 0;
  4658. } else {
  4659. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4660. }
  4661. }
  4662. // Adjust tangents to ensure monotonic properties
  4663. var alphaK, betaK, tauK, squaredMagnitude;
  4664. for (i = 0; i < pointsLen - 1; ++i) {
  4665. pointCurrent = pointsWithTangents[i];
  4666. pointAfter = pointsWithTangents[i + 1];
  4667. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4668. continue;
  4669. }
  4670. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4671. pointCurrent.mK = pointAfter.mK = 0;
  4672. continue;
  4673. }
  4674. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4675. betaK = pointAfter.mK / pointCurrent.deltaK;
  4676. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4677. if (squaredMagnitude <= 9) {
  4678. continue;
  4679. }
  4680. tauK = 3 / Math.sqrt(squaredMagnitude);
  4681. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4682. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4683. }
  4684. // Compute control points
  4685. var deltaX;
  4686. for (i = 0; i < pointsLen; ++i) {
  4687. pointCurrent = pointsWithTangents[i];
  4688. if (pointCurrent.model.skip) {
  4689. continue;
  4690. }
  4691. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4692. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4693. if (pointBefore && !pointBefore.model.skip) {
  4694. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4695. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4696. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4697. }
  4698. if (pointAfter && !pointAfter.model.skip) {
  4699. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4700. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4701. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4702. }
  4703. }
  4704. };
  4705. helpers.nextItem = function(collection, index, loop) {
  4706. if (loop) {
  4707. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4708. }
  4709. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4710. };
  4711. helpers.previousItem = function(collection, index, loop) {
  4712. if (loop) {
  4713. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4714. }
  4715. return index <= 0 ? collection[0] : collection[index - 1];
  4716. };
  4717. // Implementation of the nice number algorithm used in determining where axis labels will go
  4718. helpers.niceNum = function(range, round) {
  4719. var exponent = Math.floor(helpers.log10(range));
  4720. var fraction = range / Math.pow(10, exponent);
  4721. var niceFraction;
  4722. if (round) {
  4723. if (fraction < 1.5) {
  4724. niceFraction = 1;
  4725. } else if (fraction < 3) {
  4726. niceFraction = 2;
  4727. } else if (fraction < 7) {
  4728. niceFraction = 5;
  4729. } else {
  4730. niceFraction = 10;
  4731. }
  4732. } else if (fraction <= 1.0) {
  4733. niceFraction = 1;
  4734. } else if (fraction <= 2) {
  4735. niceFraction = 2;
  4736. } else if (fraction <= 5) {
  4737. niceFraction = 5;
  4738. } else {
  4739. niceFraction = 10;
  4740. }
  4741. return niceFraction * Math.pow(10, exponent);
  4742. };
  4743. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4744. helpers.requestAnimFrame = (function() {
  4745. if (typeof window === 'undefined') {
  4746. return function(callback) {
  4747. callback();
  4748. };
  4749. }
  4750. return window.requestAnimationFrame ||
  4751. window.webkitRequestAnimationFrame ||
  4752. window.mozRequestAnimationFrame ||
  4753. window.oRequestAnimationFrame ||
  4754. window.msRequestAnimationFrame ||
  4755. function(callback) {
  4756. return window.setTimeout(callback, 1000 / 60);
  4757. };
  4758. }());
  4759. // -- DOM methods
  4760. helpers.getRelativePosition = function(evt, chart) {
  4761. var mouseX, mouseY;
  4762. var e = evt.originalEvent || evt;
  4763. var canvas = evt.target || evt.srcElement;
  4764. var boundingRect = canvas.getBoundingClientRect();
  4765. var touches = e.touches;
  4766. if (touches && touches.length > 0) {
  4767. mouseX = touches[0].clientX;
  4768. mouseY = touches[0].clientY;
  4769. } else {
  4770. mouseX = e.clientX;
  4771. mouseY = e.clientY;
  4772. }
  4773. // Scale mouse coordinates into canvas coordinates
  4774. // by following the pattern laid out by 'jerryj' in the comments of
  4775. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4776. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4777. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4778. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4779. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4780. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4781. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4782. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4783. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4784. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4785. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4786. return {
  4787. x: mouseX,
  4788. y: mouseY
  4789. };
  4790. };
  4791. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4792. function parseMaxStyle(styleValue, node, parentProperty) {
  4793. var valueInPixels;
  4794. if (typeof styleValue === 'string') {
  4795. valueInPixels = parseInt(styleValue, 10);
  4796. if (styleValue.indexOf('%') !== -1) {
  4797. // percentage * size in dimension
  4798. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4799. }
  4800. } else {
  4801. valueInPixels = styleValue;
  4802. }
  4803. return valueInPixels;
  4804. }
  4805. /**
  4806. * Returns if the given value contains an effective constraint.
  4807. * @private
  4808. */
  4809. function isConstrainedValue(value) {
  4810. return value !== undefined && value !== null && value !== 'none';
  4811. }
  4812. // Private helper to get a constraint dimension
  4813. // @param domNode : the node to check the constraint on
  4814. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  4815. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4816. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  4817. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4818. var view = document.defaultView;
  4819. var parentNode = helpers._getParentNode(domNode);
  4820. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  4821. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  4822. var hasCNode = isConstrainedValue(constrainedNode);
  4823. var hasCContainer = isConstrainedValue(constrainedContainer);
  4824. var infinity = Number.POSITIVE_INFINITY;
  4825. if (hasCNode || hasCContainer) {
  4826. return Math.min(
  4827. hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  4828. hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  4829. }
  4830. return 'none';
  4831. }
  4832. // returns Number or undefined if no constraint
  4833. helpers.getConstraintWidth = function(domNode) {
  4834. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4835. };
  4836. // returns Number or undefined if no constraint
  4837. helpers.getConstraintHeight = function(domNode) {
  4838. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4839. };
  4840. /**
  4841. * @private
  4842. */
  4843. helpers._calculatePadding = function(container, padding, parentDimension) {
  4844. padding = helpers.getStyle(container, padding);
  4845. return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10);
  4846. };
  4847. /**
  4848. * @private
  4849. */
  4850. helpers._getParentNode = function(domNode) {
  4851. var parent = domNode.parentNode;
  4852. if (parent && parent.host) {
  4853. parent = parent.host;
  4854. }
  4855. return parent;
  4856. };
  4857. helpers.getMaximumWidth = function(domNode) {
  4858. var container = helpers._getParentNode(domNode);
  4859. if (!container) {
  4860. return domNode.clientWidth;
  4861. }
  4862. var clientWidth = container.clientWidth;
  4863. var paddingLeft = helpers._calculatePadding(container, 'padding-left', clientWidth);
  4864. var paddingRight = helpers._calculatePadding(container, 'padding-right', clientWidth);
  4865. var w = clientWidth - paddingLeft - paddingRight;
  4866. var cw = helpers.getConstraintWidth(domNode);
  4867. return isNaN(cw) ? w : Math.min(w, cw);
  4868. };
  4869. helpers.getMaximumHeight = function(domNode) {
  4870. var container = helpers._getParentNode(domNode);
  4871. if (!container) {
  4872. return domNode.clientHeight;
  4873. }
  4874. var clientHeight = container.clientHeight;
  4875. var paddingTop = helpers._calculatePadding(container, 'padding-top', clientHeight);
  4876. var paddingBottom = helpers._calculatePadding(container, 'padding-bottom', clientHeight);
  4877. var h = clientHeight - paddingTop - paddingBottom;
  4878. var ch = helpers.getConstraintHeight(domNode);
  4879. return isNaN(ch) ? h : Math.min(h, ch);
  4880. };
  4881. helpers.getStyle = function(el, property) {
  4882. return el.currentStyle ?
  4883. el.currentStyle[property] :
  4884. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4885. };
  4886. helpers.retinaScale = function(chart, forceRatio) {
  4887. var pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
  4888. if (pixelRatio === 1) {
  4889. return;
  4890. }
  4891. var canvas = chart.canvas;
  4892. var height = chart.height;
  4893. var width = chart.width;
  4894. canvas.height = height * pixelRatio;
  4895. canvas.width = width * pixelRatio;
  4896. chart.ctx.scale(pixelRatio, pixelRatio);
  4897. // If no style has been set on the canvas, the render size is used as display size,
  4898. // making the chart visually bigger, so let's enforce it to the "correct" values.
  4899. // See https://github.com/chartjs/Chart.js/issues/3575
  4900. if (!canvas.style.height && !canvas.style.width) {
  4901. canvas.style.height = height + 'px';
  4902. canvas.style.width = width + 'px';
  4903. }
  4904. };
  4905. // -- Canvas methods
  4906. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  4907. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  4908. };
  4909. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  4910. cache = cache || {};
  4911. var data = cache.data = cache.data || {};
  4912. var gc = cache.garbageCollect = cache.garbageCollect || [];
  4913. if (cache.font !== font) {
  4914. data = cache.data = {};
  4915. gc = cache.garbageCollect = [];
  4916. cache.font = font;
  4917. }
  4918. ctx.font = font;
  4919. var longest = 0;
  4920. helpers.each(arrayOfThings, function(thing) {
  4921. // Undefined strings and arrays should not be measured
  4922. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  4923. longest = helpers.measureText(ctx, data, gc, longest, thing);
  4924. } else if (helpers.isArray(thing)) {
  4925. // if it is an array lets measure each element
  4926. // to do maybe simplify this function a bit so we can do this more recursively?
  4927. helpers.each(thing, function(nestedThing) {
  4928. // Undefined strings and arrays should not be measured
  4929. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  4930. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  4931. }
  4932. });
  4933. }
  4934. });
  4935. var gcLen = gc.length / 2;
  4936. if (gcLen > arrayOfThings.length) {
  4937. for (var i = 0; i < gcLen; i++) {
  4938. delete data[gc[i]];
  4939. }
  4940. gc.splice(0, gcLen);
  4941. }
  4942. return longest;
  4943. };
  4944. helpers.measureText = function(ctx, data, gc, longest, string) {
  4945. var textWidth = data[string];
  4946. if (!textWidth) {
  4947. textWidth = data[string] = ctx.measureText(string).width;
  4948. gc.push(string);
  4949. }
  4950. if (textWidth > longest) {
  4951. longest = textWidth;
  4952. }
  4953. return longest;
  4954. };
  4955. helpers.numberOfLabelLines = function(arrayOfThings) {
  4956. var numberOfLines = 1;
  4957. helpers.each(arrayOfThings, function(thing) {
  4958. if (helpers.isArray(thing)) {
  4959. if (thing.length > numberOfLines) {
  4960. numberOfLines = thing.length;
  4961. }
  4962. }
  4963. });
  4964. return numberOfLines;
  4965. };
  4966. helpers.color = !color ?
  4967. function(value) {
  4968. console.error('Color.js not found!');
  4969. return value;
  4970. } :
  4971. function(value) {
  4972. /* global CanvasGradient */
  4973. if (value instanceof CanvasGradient) {
  4974. value = defaults.global.defaultColor;
  4975. }
  4976. return color(value);
  4977. };
  4978. helpers.getHoverColor = function(colorValue) {
  4979. /* global CanvasPattern */
  4980. return (colorValue instanceof CanvasPattern) ?
  4981. colorValue :
  4982. helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
  4983. };
  4984. };
  4985. },{"26":26,"3":3,"34":34,"46":46}],29:[function(require,module,exports){
  4986. 'use strict';
  4987. var helpers = require(46);
  4988. /**
  4989. * Helper function to get relative position for an event
  4990. * @param {Event|IEvent} event - The event to get the position for
  4991. * @param {Chart} chart - The chart
  4992. * @returns {Point} the event position
  4993. */
  4994. function getRelativePosition(e, chart) {
  4995. if (e.native) {
  4996. return {
  4997. x: e.x,
  4998. y: e.y
  4999. };
  5000. }
  5001. return helpers.getRelativePosition(e, chart);
  5002. }
  5003. /**
  5004. * Helper function to traverse all of the visible elements in the chart
  5005. * @param chart {chart} the chart
  5006. * @param handler {Function} the callback to execute for each visible item
  5007. */
  5008. function parseVisibleItems(chart, handler) {
  5009. var datasets = chart.data.datasets;
  5010. var meta, i, j, ilen, jlen;
  5011. for (i = 0, ilen = datasets.length; i < ilen; ++i) {
  5012. if (!chart.isDatasetVisible(i)) {
  5013. continue;
  5014. }
  5015. meta = chart.getDatasetMeta(i);
  5016. for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
  5017. var element = meta.data[j];
  5018. if (!element._view.skip) {
  5019. handler(element);
  5020. }
  5021. }
  5022. }
  5023. }
  5024. /**
  5025. * Helper function to get the items that intersect the event position
  5026. * @param items {ChartElement[]} elements to filter
  5027. * @param position {Point} the point to be nearest to
  5028. * @return {ChartElement[]} the nearest items
  5029. */
  5030. function getIntersectItems(chart, position) {
  5031. var elements = [];
  5032. parseVisibleItems(chart, function(element) {
  5033. if (element.inRange(position.x, position.y)) {
  5034. elements.push(element);
  5035. }
  5036. });
  5037. return elements;
  5038. }
  5039. /**
  5040. * Helper function to get the items nearest to the event position considering all visible items in teh chart
  5041. * @param chart {Chart} the chart to look at elements from
  5042. * @param position {Point} the point to be nearest to
  5043. * @param intersect {Boolean} if true, only consider items that intersect the position
  5044. * @param distanceMetric {Function} function to provide the distance between points
  5045. * @return {ChartElement[]} the nearest items
  5046. */
  5047. function getNearestItems(chart, position, intersect, distanceMetric) {
  5048. var minDistance = Number.POSITIVE_INFINITY;
  5049. var nearestItems = [];
  5050. parseVisibleItems(chart, function(element) {
  5051. if (intersect && !element.inRange(position.x, position.y)) {
  5052. return;
  5053. }
  5054. var center = element.getCenterPoint();
  5055. var distance = distanceMetric(position, center);
  5056. if (distance < minDistance) {
  5057. nearestItems = [element];
  5058. minDistance = distance;
  5059. } else if (distance === minDistance) {
  5060. // Can have multiple items at the same distance in which case we sort by size
  5061. nearestItems.push(element);
  5062. }
  5063. });
  5064. return nearestItems;
  5065. }
  5066. /**
  5067. * Get a distance metric function for two points based on the
  5068. * axis mode setting
  5069. * @param {String} axis the axis mode. x|y|xy
  5070. */
  5071. function getDistanceMetricForAxis(axis) {
  5072. var useX = axis.indexOf('x') !== -1;
  5073. var useY = axis.indexOf('y') !== -1;
  5074. return function(pt1, pt2) {
  5075. var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0;
  5076. var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0;
  5077. return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
  5078. };
  5079. }
  5080. function indexMode(chart, e, options) {
  5081. var position = getRelativePosition(e, chart);
  5082. // Default axis for index mode is 'x' to match old behaviour
  5083. options.axis = options.axis || 'x';
  5084. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5085. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5086. var elements = [];
  5087. if (!items.length) {
  5088. return [];
  5089. }
  5090. chart.data.datasets.forEach(function(dataset, datasetIndex) {
  5091. if (chart.isDatasetVisible(datasetIndex)) {
  5092. var meta = chart.getDatasetMeta(datasetIndex);
  5093. var element = meta.data[items[0]._index];
  5094. // don't count items that are skipped (null data)
  5095. if (element && !element._view.skip) {
  5096. elements.push(element);
  5097. }
  5098. }
  5099. });
  5100. return elements;
  5101. }
  5102. /**
  5103. * @interface IInteractionOptions
  5104. */
  5105. /**
  5106. * If true, only consider items that intersect the point
  5107. * @name IInterfaceOptions#boolean
  5108. * @type Boolean
  5109. */
  5110. /**
  5111. * Contains interaction related functions
  5112. * @namespace Chart.Interaction
  5113. */
  5114. module.exports = {
  5115. // Helper function for different modes
  5116. modes: {
  5117. single: function(chart, e) {
  5118. var position = getRelativePosition(e, chart);
  5119. var elements = [];
  5120. parseVisibleItems(chart, function(element) {
  5121. if (element.inRange(position.x, position.y)) {
  5122. elements.push(element);
  5123. return elements;
  5124. }
  5125. });
  5126. return elements.slice(0, 1);
  5127. },
  5128. /**
  5129. * @function Chart.Interaction.modes.label
  5130. * @deprecated since version 2.4.0
  5131. * @todo remove at version 3
  5132. * @private
  5133. */
  5134. label: indexMode,
  5135. /**
  5136. * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
  5137. * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
  5138. * @function Chart.Interaction.modes.index
  5139. * @since v2.4.0
  5140. * @param chart {chart} the chart we are returning items from
  5141. * @param e {Event} the event we are find things at
  5142. * @param options {IInteractionOptions} options to use during interaction
  5143. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5144. */
  5145. index: indexMode,
  5146. /**
  5147. * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
  5148. * If the options.intersect is false, we find the nearest item and return the items in that dataset
  5149. * @function Chart.Interaction.modes.dataset
  5150. * @param chart {chart} the chart we are returning items from
  5151. * @param e {Event} the event we are find things at
  5152. * @param options {IInteractionOptions} options to use during interaction
  5153. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5154. */
  5155. dataset: function(chart, e, options) {
  5156. var position = getRelativePosition(e, chart);
  5157. options.axis = options.axis || 'xy';
  5158. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5159. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5160. if (items.length > 0) {
  5161. items = chart.getDatasetMeta(items[0]._datasetIndex).data;
  5162. }
  5163. return items;
  5164. },
  5165. /**
  5166. * @function Chart.Interaction.modes.x-axis
  5167. * @deprecated since version 2.4.0. Use index mode and intersect == true
  5168. * @todo remove at version 3
  5169. * @private
  5170. */
  5171. 'x-axis': function(chart, e) {
  5172. return indexMode(chart, e, {intersect: false});
  5173. },
  5174. /**
  5175. * Point mode returns all elements that hit test based on the event position
  5176. * of the event
  5177. * @function Chart.Interaction.modes.intersect
  5178. * @param chart {chart} the chart we are returning items from
  5179. * @param e {Event} the event we are find things at
  5180. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5181. */
  5182. point: function(chart, e) {
  5183. var position = getRelativePosition(e, chart);
  5184. return getIntersectItems(chart, position);
  5185. },
  5186. /**
  5187. * nearest mode returns the element closest to the point
  5188. * @function Chart.Interaction.modes.intersect
  5189. * @param chart {chart} the chart we are returning items from
  5190. * @param e {Event} the event we are find things at
  5191. * @param options {IInteractionOptions} options to use
  5192. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5193. */
  5194. nearest: function(chart, e, options) {
  5195. var position = getRelativePosition(e, chart);
  5196. options.axis = options.axis || 'xy';
  5197. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5198. var nearestItems = getNearestItems(chart, position, options.intersect, distanceMetric);
  5199. // We have multiple items at the same distance from the event. Now sort by smallest
  5200. if (nearestItems.length > 1) {
  5201. nearestItems.sort(function(a, b) {
  5202. var sizeA = a.getArea();
  5203. var sizeB = b.getArea();
  5204. var ret = sizeA - sizeB;
  5205. if (ret === 0) {
  5206. // if equal sort by dataset index
  5207. ret = a._datasetIndex - b._datasetIndex;
  5208. }
  5209. return ret;
  5210. });
  5211. }
  5212. // Return only 1 item
  5213. return nearestItems.slice(0, 1);
  5214. },
  5215. /**
  5216. * x mode returns the elements that hit-test at the current x coordinate
  5217. * @function Chart.Interaction.modes.x
  5218. * @param chart {chart} the chart we are returning items from
  5219. * @param e {Event} the event we are find things at
  5220. * @param options {IInteractionOptions} options to use
  5221. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5222. */
  5223. x: function(chart, e, options) {
  5224. var position = getRelativePosition(e, chart);
  5225. var items = [];
  5226. var intersectsItem = false;
  5227. parseVisibleItems(chart, function(element) {
  5228. if (element.inXRange(position.x)) {
  5229. items.push(element);
  5230. }
  5231. if (element.inRange(position.x, position.y)) {
  5232. intersectsItem = true;
  5233. }
  5234. });
  5235. // If we want to trigger on an intersect and we don't have any items
  5236. // that intersect the position, return nothing
  5237. if (options.intersect && !intersectsItem) {
  5238. items = [];
  5239. }
  5240. return items;
  5241. },
  5242. /**
  5243. * y mode returns the elements that hit-test at the current y coordinate
  5244. * @function Chart.Interaction.modes.y
  5245. * @param chart {chart} the chart we are returning items from
  5246. * @param e {Event} the event we are find things at
  5247. * @param options {IInteractionOptions} options to use
  5248. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5249. */
  5250. y: function(chart, e, options) {
  5251. var position = getRelativePosition(e, chart);
  5252. var items = [];
  5253. var intersectsItem = false;
  5254. parseVisibleItems(chart, function(element) {
  5255. if (element.inYRange(position.y)) {
  5256. items.push(element);
  5257. }
  5258. if (element.inRange(position.x, position.y)) {
  5259. intersectsItem = true;
  5260. }
  5261. });
  5262. // If we want to trigger on an intersect and we don't have any items
  5263. // that intersect the position, return nothing
  5264. if (options.intersect && !intersectsItem) {
  5265. items = [];
  5266. }
  5267. return items;
  5268. }
  5269. }
  5270. };
  5271. },{"46":46}],30:[function(require,module,exports){
  5272. 'use strict';
  5273. var defaults = require(26);
  5274. defaults._set('global', {
  5275. responsive: true,
  5276. responsiveAnimationDuration: 0,
  5277. maintainAspectRatio: true,
  5278. events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
  5279. hover: {
  5280. onHover: null,
  5281. mode: 'nearest',
  5282. intersect: true,
  5283. animationDuration: 400
  5284. },
  5285. onClick: null,
  5286. defaultColor: 'rgba(0,0,0,0.1)',
  5287. defaultFontColor: '#666',
  5288. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  5289. defaultFontSize: 12,
  5290. defaultFontStyle: 'normal',
  5291. showLines: true,
  5292. // Element defaults defined in element extensions
  5293. elements: {},
  5294. // Layout options such as padding
  5295. layout: {
  5296. padding: {
  5297. top: 0,
  5298. right: 0,
  5299. bottom: 0,
  5300. left: 0
  5301. }
  5302. }
  5303. });
  5304. module.exports = function() {
  5305. // Occupy the global variable of Chart, and create a simple base class
  5306. var Chart = function(item, config) {
  5307. this.construct(item, config);
  5308. return this;
  5309. };
  5310. Chart.Chart = Chart;
  5311. return Chart;
  5312. };
  5313. },{"26":26}],31:[function(require,module,exports){
  5314. 'use strict';
  5315. var helpers = require(46);
  5316. function filterByPosition(array, position) {
  5317. return helpers.where(array, function(v) {
  5318. return v.position === position;
  5319. });
  5320. }
  5321. function sortByWeight(array, reverse) {
  5322. array.forEach(function(v, i) {
  5323. v._tmpIndex_ = i;
  5324. return v;
  5325. });
  5326. array.sort(function(a, b) {
  5327. var v0 = reverse ? b : a;
  5328. var v1 = reverse ? a : b;
  5329. return v0.weight === v1.weight ?
  5330. v0._tmpIndex_ - v1._tmpIndex_ :
  5331. v0.weight - v1.weight;
  5332. });
  5333. array.forEach(function(v) {
  5334. delete v._tmpIndex_;
  5335. });
  5336. }
  5337. /**
  5338. * @interface ILayoutItem
  5339. * @prop {String} position - The position of the item in the chart layout. Possible values are
  5340. * 'left', 'top', 'right', 'bottom', and 'chartArea'
  5341. * @prop {Number} weight - The weight used to sort the item. Higher weights are further away from the chart area
  5342. * @prop {Boolean} fullWidth - if true, and the item is horizontal, then push vertical boxes down
  5343. * @prop {Function} isHorizontal - returns true if the layout item is horizontal (ie. top or bottom)
  5344. * @prop {Function} update - Takes two parameters: width and height. Returns size of item
  5345. * @prop {Function} getPadding - Returns an object with padding on the edges
  5346. * @prop {Number} width - Width of item. Must be valid after update()
  5347. * @prop {Number} height - Height of item. Must be valid after update()
  5348. * @prop {Number} left - Left edge of the item. Set by layout system and cannot be used in update
  5349. * @prop {Number} top - Top edge of the item. Set by layout system and cannot be used in update
  5350. * @prop {Number} right - Right edge of the item. Set by layout system and cannot be used in update
  5351. * @prop {Number} bottom - Bottom edge of the item. Set by layout system and cannot be used in update
  5352. */
  5353. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  5354. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  5355. // It is this service's responsibility of carrying out that layout.
  5356. module.exports = {
  5357. defaults: {},
  5358. /**
  5359. * Register a box to a chart.
  5360. * A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
  5361. * @param {Chart} chart - the chart to use
  5362. * @param {ILayoutItem} item - the item to add to be layed out
  5363. */
  5364. addBox: function(chart, item) {
  5365. if (!chart.boxes) {
  5366. chart.boxes = [];
  5367. }
  5368. // initialize item with default values
  5369. item.fullWidth = item.fullWidth || false;
  5370. item.position = item.position || 'top';
  5371. item.weight = item.weight || 0;
  5372. chart.boxes.push(item);
  5373. },
  5374. /**
  5375. * Remove a layoutItem from a chart
  5376. * @param {Chart} chart - the chart to remove the box from
  5377. * @param {Object} layoutItem - the item to remove from the layout
  5378. */
  5379. removeBox: function(chart, layoutItem) {
  5380. var index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
  5381. if (index !== -1) {
  5382. chart.boxes.splice(index, 1);
  5383. }
  5384. },
  5385. /**
  5386. * Sets (or updates) options on the given `item`.
  5387. * @param {Chart} chart - the chart in which the item lives (or will be added to)
  5388. * @param {Object} item - the item to configure with the given options
  5389. * @param {Object} options - the new item options.
  5390. */
  5391. configure: function(chart, item, options) {
  5392. var props = ['fullWidth', 'position', 'weight'];
  5393. var ilen = props.length;
  5394. var i = 0;
  5395. var prop;
  5396. for (; i < ilen; ++i) {
  5397. prop = props[i];
  5398. if (options.hasOwnProperty(prop)) {
  5399. item[prop] = options[prop];
  5400. }
  5401. }
  5402. },
  5403. /**
  5404. * Fits boxes of the given chart into the given size by having each box measure itself
  5405. * then running a fitting algorithm
  5406. * @param {Chart} chart - the chart
  5407. * @param {Number} width - the width to fit into
  5408. * @param {Number} height - the height to fit into
  5409. */
  5410. update: function(chart, width, height) {
  5411. if (!chart) {
  5412. return;
  5413. }
  5414. var layoutOptions = chart.options.layout || {};
  5415. var padding = helpers.options.toPadding(layoutOptions.padding);
  5416. var leftPadding = padding.left;
  5417. var rightPadding = padding.right;
  5418. var topPadding = padding.top;
  5419. var bottomPadding = padding.bottom;
  5420. var leftBoxes = filterByPosition(chart.boxes, 'left');
  5421. var rightBoxes = filterByPosition(chart.boxes, 'right');
  5422. var topBoxes = filterByPosition(chart.boxes, 'top');
  5423. var bottomBoxes = filterByPosition(chart.boxes, 'bottom');
  5424. var chartAreaBoxes = filterByPosition(chart.boxes, 'chartArea');
  5425. // Sort boxes by weight. A higher weight is further away from the chart area
  5426. sortByWeight(leftBoxes, true);
  5427. sortByWeight(rightBoxes, false);
  5428. sortByWeight(topBoxes, true);
  5429. sortByWeight(bottomBoxes, false);
  5430. // Essentially we now have any number of boxes on each of the 4 sides.
  5431. // Our canvas looks like the following.
  5432. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  5433. // B1 is the bottom axis
  5434. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  5435. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  5436. // an error will be thrown.
  5437. //
  5438. // |----------------------------------------------------|
  5439. // | T1 (Full Width) |
  5440. // |----------------------------------------------------|
  5441. // | | | T2 | |
  5442. // | |----|-------------------------------------|----|
  5443. // | | | C1 | | C2 | |
  5444. // | | |----| |----| |
  5445. // | | | | |
  5446. // | L1 | L2 | ChartArea (C0) | R1 |
  5447. // | | | | |
  5448. // | | |----| |----| |
  5449. // | | | C3 | | C4 | |
  5450. // | |----|-------------------------------------|----|
  5451. // | | | B1 | |
  5452. // |----------------------------------------------------|
  5453. // | B2 (Full Width) |
  5454. // |----------------------------------------------------|
  5455. //
  5456. // What we do to find the best sizing, we do the following
  5457. // 1. Determine the minimum size of the chart area.
  5458. // 2. Split the remaining width equally between each vertical axis
  5459. // 3. Split the remaining height equally between each horizontal axis
  5460. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  5461. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  5462. // 6. Refit each axis
  5463. // 7. Position each axis in the final location
  5464. // 8. Tell the chart the final location of the chart area
  5465. // 9. Tell any axes that overlay the chart area the positions of the chart area
  5466. // Step 1
  5467. var chartWidth = width - leftPadding - rightPadding;
  5468. var chartHeight = height - topPadding - bottomPadding;
  5469. var chartAreaWidth = chartWidth / 2; // min 50%
  5470. var chartAreaHeight = chartHeight / 2; // min 50%
  5471. // Step 2
  5472. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  5473. // Step 3
  5474. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  5475. // Step 4
  5476. var maxChartAreaWidth = chartWidth;
  5477. var maxChartAreaHeight = chartHeight;
  5478. var minBoxSizes = [];
  5479. function getMinimumBoxSize(box) {
  5480. var minSize;
  5481. var isHorizontal = box.isHorizontal();
  5482. if (isHorizontal) {
  5483. minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5484. maxChartAreaHeight -= minSize.height;
  5485. } else {
  5486. minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
  5487. maxChartAreaWidth -= minSize.width;
  5488. }
  5489. minBoxSizes.push({
  5490. horizontal: isHorizontal,
  5491. minSize: minSize,
  5492. box: box,
  5493. });
  5494. }
  5495. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  5496. // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
  5497. var maxHorizontalLeftPadding = 0;
  5498. var maxHorizontalRightPadding = 0;
  5499. var maxVerticalTopPadding = 0;
  5500. var maxVerticalBottomPadding = 0;
  5501. helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
  5502. if (horizontalBox.getPadding) {
  5503. var boxPadding = horizontalBox.getPadding();
  5504. maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
  5505. maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
  5506. }
  5507. });
  5508. helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
  5509. if (verticalBox.getPadding) {
  5510. var boxPadding = verticalBox.getPadding();
  5511. maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
  5512. maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
  5513. }
  5514. });
  5515. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  5516. // be if the axes are drawn at their minimum sizes.
  5517. // Steps 5 & 6
  5518. var totalLeftBoxesWidth = leftPadding;
  5519. var totalRightBoxesWidth = rightPadding;
  5520. var totalTopBoxesHeight = topPadding;
  5521. var totalBottomBoxesHeight = bottomPadding;
  5522. // Function to fit a box
  5523. function fitBox(box) {
  5524. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
  5525. return minBox.box === box;
  5526. });
  5527. if (minBoxSize) {
  5528. if (box.isHorizontal()) {
  5529. var scaleMargin = {
  5530. left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
  5531. right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
  5532. top: 0,
  5533. bottom: 0
  5534. };
  5535. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5536. // on the margin. Sometimes they need to increase in size slightly
  5537. box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5538. } else {
  5539. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5540. }
  5541. }
  5542. }
  5543. // Update, and calculate the left and right margins for the horizontal boxes
  5544. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5545. helpers.each(leftBoxes, function(box) {
  5546. totalLeftBoxesWidth += box.width;
  5547. });
  5548. helpers.each(rightBoxes, function(box) {
  5549. totalRightBoxesWidth += box.width;
  5550. });
  5551. // Set the Left and Right margins for the horizontal boxes
  5552. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  5553. // Figure out how much margin is on the top and bottom of the vertical boxes
  5554. helpers.each(topBoxes, function(box) {
  5555. totalTopBoxesHeight += box.height;
  5556. });
  5557. helpers.each(bottomBoxes, function(box) {
  5558. totalBottomBoxesHeight += box.height;
  5559. });
  5560. function finalFitVerticalBox(box) {
  5561. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
  5562. return minSize.box === box;
  5563. });
  5564. var scaleMargin = {
  5565. left: 0,
  5566. right: 0,
  5567. top: totalTopBoxesHeight,
  5568. bottom: totalBottomBoxesHeight
  5569. };
  5570. if (minBoxSize) {
  5571. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5572. }
  5573. }
  5574. // Let the left layout know the final margin
  5575. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  5576. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  5577. totalLeftBoxesWidth = leftPadding;
  5578. totalRightBoxesWidth = rightPadding;
  5579. totalTopBoxesHeight = topPadding;
  5580. totalBottomBoxesHeight = bottomPadding;
  5581. helpers.each(leftBoxes, function(box) {
  5582. totalLeftBoxesWidth += box.width;
  5583. });
  5584. helpers.each(rightBoxes, function(box) {
  5585. totalRightBoxesWidth += box.width;
  5586. });
  5587. helpers.each(topBoxes, function(box) {
  5588. totalTopBoxesHeight += box.height;
  5589. });
  5590. helpers.each(bottomBoxes, function(box) {
  5591. totalBottomBoxesHeight += box.height;
  5592. });
  5593. // We may be adding some padding to account for rotated x axis labels
  5594. var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
  5595. totalLeftBoxesWidth += leftPaddingAddition;
  5596. totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
  5597. var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
  5598. totalTopBoxesHeight += topPaddingAddition;
  5599. totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
  5600. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  5601. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  5602. // without calling `fit` again
  5603. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  5604. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  5605. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  5606. helpers.each(leftBoxes, function(box) {
  5607. box.height = newMaxChartAreaHeight;
  5608. });
  5609. helpers.each(rightBoxes, function(box) {
  5610. box.height = newMaxChartAreaHeight;
  5611. });
  5612. helpers.each(topBoxes, function(box) {
  5613. if (!box.fullWidth) {
  5614. box.width = newMaxChartAreaWidth;
  5615. }
  5616. });
  5617. helpers.each(bottomBoxes, function(box) {
  5618. if (!box.fullWidth) {
  5619. box.width = newMaxChartAreaWidth;
  5620. }
  5621. });
  5622. maxChartAreaHeight = newMaxChartAreaHeight;
  5623. maxChartAreaWidth = newMaxChartAreaWidth;
  5624. }
  5625. // Step 7 - Position the boxes
  5626. var left = leftPadding + leftPaddingAddition;
  5627. var top = topPadding + topPaddingAddition;
  5628. function placeBox(box) {
  5629. if (box.isHorizontal()) {
  5630. box.left = box.fullWidth ? leftPadding : totalLeftBoxesWidth;
  5631. box.right = box.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5632. box.top = top;
  5633. box.bottom = top + box.height;
  5634. // Move to next point
  5635. top = box.bottom;
  5636. } else {
  5637. box.left = left;
  5638. box.right = left + box.width;
  5639. box.top = totalTopBoxesHeight;
  5640. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5641. // Move to next point
  5642. left = box.right;
  5643. }
  5644. }
  5645. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5646. // Account for chart width and height
  5647. left += maxChartAreaWidth;
  5648. top += maxChartAreaHeight;
  5649. helpers.each(rightBoxes, placeBox);
  5650. helpers.each(bottomBoxes, placeBox);
  5651. // Step 8
  5652. chart.chartArea = {
  5653. left: totalLeftBoxesWidth,
  5654. top: totalTopBoxesHeight,
  5655. right: totalLeftBoxesWidth + maxChartAreaWidth,
  5656. bottom: totalTopBoxesHeight + maxChartAreaHeight
  5657. };
  5658. // Step 9
  5659. helpers.each(chartAreaBoxes, function(box) {
  5660. box.left = chart.chartArea.left;
  5661. box.top = chart.chartArea.top;
  5662. box.right = chart.chartArea.right;
  5663. box.bottom = chart.chartArea.bottom;
  5664. box.update(maxChartAreaWidth, maxChartAreaHeight);
  5665. });
  5666. }
  5667. };
  5668. },{"46":46}],32:[function(require,module,exports){
  5669. 'use strict';
  5670. var defaults = require(26);
  5671. var helpers = require(46);
  5672. defaults._set('global', {
  5673. plugins: {}
  5674. });
  5675. /**
  5676. * The plugin service singleton
  5677. * @namespace Chart.plugins
  5678. * @since 2.1.0
  5679. */
  5680. module.exports = {
  5681. /**
  5682. * Globally registered plugins.
  5683. * @private
  5684. */
  5685. _plugins: [],
  5686. /**
  5687. * This identifier is used to invalidate the descriptors cache attached to each chart
  5688. * when a global plugin is registered or unregistered. In this case, the cache ID is
  5689. * incremented and descriptors are regenerated during following API calls.
  5690. * @private
  5691. */
  5692. _cacheId: 0,
  5693. /**
  5694. * Registers the given plugin(s) if not already registered.
  5695. * @param {Array|Object} plugins plugin instance(s).
  5696. */
  5697. register: function(plugins) {
  5698. var p = this._plugins;
  5699. ([]).concat(plugins).forEach(function(plugin) {
  5700. if (p.indexOf(plugin) === -1) {
  5701. p.push(plugin);
  5702. }
  5703. });
  5704. this._cacheId++;
  5705. },
  5706. /**
  5707. * Unregisters the given plugin(s) only if registered.
  5708. * @param {Array|Object} plugins plugin instance(s).
  5709. */
  5710. unregister: function(plugins) {
  5711. var p = this._plugins;
  5712. ([]).concat(plugins).forEach(function(plugin) {
  5713. var idx = p.indexOf(plugin);
  5714. if (idx !== -1) {
  5715. p.splice(idx, 1);
  5716. }
  5717. });
  5718. this._cacheId++;
  5719. },
  5720. /**
  5721. * Remove all registered plugins.
  5722. * @since 2.1.5
  5723. */
  5724. clear: function() {
  5725. this._plugins = [];
  5726. this._cacheId++;
  5727. },
  5728. /**
  5729. * Returns the number of registered plugins?
  5730. * @returns {Number}
  5731. * @since 2.1.5
  5732. */
  5733. count: function() {
  5734. return this._plugins.length;
  5735. },
  5736. /**
  5737. * Returns all registered plugin instances.
  5738. * @returns {Array} array of plugin objects.
  5739. * @since 2.1.5
  5740. */
  5741. getAll: function() {
  5742. return this._plugins;
  5743. },
  5744. /**
  5745. * Calls enabled plugins for `chart` on the specified hook and with the given args.
  5746. * This method immediately returns as soon as a plugin explicitly returns false. The
  5747. * returned value can be used, for instance, to interrupt the current action.
  5748. * @param {Object} chart - The chart instance for which plugins should be called.
  5749. * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
  5750. * @param {Array} [args] - Extra arguments to apply to the hook call.
  5751. * @returns {Boolean} false if any of the plugins return false, else returns true.
  5752. */
  5753. notify: function(chart, hook, args) {
  5754. var descriptors = this.descriptors(chart);
  5755. var ilen = descriptors.length;
  5756. var i, descriptor, plugin, params, method;
  5757. for (i = 0; i < ilen; ++i) {
  5758. descriptor = descriptors[i];
  5759. plugin = descriptor.plugin;
  5760. method = plugin[hook];
  5761. if (typeof method === 'function') {
  5762. params = [chart].concat(args || []);
  5763. params.push(descriptor.options);
  5764. if (method.apply(plugin, params) === false) {
  5765. return false;
  5766. }
  5767. }
  5768. }
  5769. return true;
  5770. },
  5771. /**
  5772. * Returns descriptors of enabled plugins for the given chart.
  5773. * @returns {Array} [{ plugin, options }]
  5774. * @private
  5775. */
  5776. descriptors: function(chart) {
  5777. var cache = chart.$plugins || (chart.$plugins = {});
  5778. if (cache.id === this._cacheId) {
  5779. return cache.descriptors;
  5780. }
  5781. var plugins = [];
  5782. var descriptors = [];
  5783. var config = (chart && chart.config) || {};
  5784. var options = (config.options && config.options.plugins) || {};
  5785. this._plugins.concat(config.plugins || []).forEach(function(plugin) {
  5786. var idx = plugins.indexOf(plugin);
  5787. if (idx !== -1) {
  5788. return;
  5789. }
  5790. var id = plugin.id;
  5791. var opts = options[id];
  5792. if (opts === false) {
  5793. return;
  5794. }
  5795. if (opts === true) {
  5796. opts = helpers.clone(defaults.global.plugins[id]);
  5797. }
  5798. plugins.push(plugin);
  5799. descriptors.push({
  5800. plugin: plugin,
  5801. options: opts || {}
  5802. });
  5803. });
  5804. cache.descriptors = descriptors;
  5805. cache.id = this._cacheId;
  5806. return descriptors;
  5807. },
  5808. /**
  5809. * Invalidates cache for the given chart: descriptors hold a reference on plugin option,
  5810. * but in some cases, this reference can be changed by the user when updating options.
  5811. * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  5812. * @private
  5813. */
  5814. _invalidate: function(chart) {
  5815. delete chart.$plugins;
  5816. }
  5817. };
  5818. /**
  5819. * Plugin extension hooks.
  5820. * @interface IPlugin
  5821. * @since 2.1.0
  5822. */
  5823. /**
  5824. * @method IPlugin#beforeInit
  5825. * @desc Called before initializing `chart`.
  5826. * @param {Chart.Controller} chart - The chart instance.
  5827. * @param {Object} options - The plugin options.
  5828. */
  5829. /**
  5830. * @method IPlugin#afterInit
  5831. * @desc Called after `chart` has been initialized and before the first update.
  5832. * @param {Chart.Controller} chart - The chart instance.
  5833. * @param {Object} options - The plugin options.
  5834. */
  5835. /**
  5836. * @method IPlugin#beforeUpdate
  5837. * @desc Called before updating `chart`. If any plugin returns `false`, the update
  5838. * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
  5839. * @param {Chart.Controller} chart - The chart instance.
  5840. * @param {Object} options - The plugin options.
  5841. * @returns {Boolean} `false` to cancel the chart update.
  5842. */
  5843. /**
  5844. * @method IPlugin#afterUpdate
  5845. * @desc Called after `chart` has been updated and before rendering. Note that this
  5846. * hook will not be called if the chart update has been previously cancelled.
  5847. * @param {Chart.Controller} chart - The chart instance.
  5848. * @param {Object} options - The plugin options.
  5849. */
  5850. /**
  5851. * @method IPlugin#beforeDatasetsUpdate
  5852. * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  5853. * the datasets update is cancelled until another `update` is triggered.
  5854. * @param {Chart.Controller} chart - The chart instance.
  5855. * @param {Object} options - The plugin options.
  5856. * @returns {Boolean} false to cancel the datasets update.
  5857. * @since version 2.1.5
  5858. */
  5859. /**
  5860. * @method IPlugin#afterDatasetsUpdate
  5861. * @desc Called after the `chart` datasets have been updated. Note that this hook
  5862. * will not be called if the datasets update has been previously cancelled.
  5863. * @param {Chart.Controller} chart - The chart instance.
  5864. * @param {Object} options - The plugin options.
  5865. * @since version 2.1.5
  5866. */
  5867. /**
  5868. * @method IPlugin#beforeDatasetUpdate
  5869. * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
  5870. * returns `false`, the datasets update is cancelled until another `update` is triggered.
  5871. * @param {Chart} chart - The chart instance.
  5872. * @param {Object} args - The call arguments.
  5873. * @param {Number} args.index - The dataset index.
  5874. * @param {Object} args.meta - The dataset metadata.
  5875. * @param {Object} options - The plugin options.
  5876. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5877. */
  5878. /**
  5879. * @method IPlugin#afterDatasetUpdate
  5880. * @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
  5881. * that this hook will not be called if the datasets update has been previously cancelled.
  5882. * @param {Chart} chart - The chart instance.
  5883. * @param {Object} args - The call arguments.
  5884. * @param {Number} args.index - The dataset index.
  5885. * @param {Object} args.meta - The dataset metadata.
  5886. * @param {Object} options - The plugin options.
  5887. */
  5888. /**
  5889. * @method IPlugin#beforeLayout
  5890. * @desc Called before laying out `chart`. If any plugin returns `false`,
  5891. * the layout update is cancelled until another `update` is triggered.
  5892. * @param {Chart.Controller} chart - The chart instance.
  5893. * @param {Object} options - The plugin options.
  5894. * @returns {Boolean} `false` to cancel the chart layout.
  5895. */
  5896. /**
  5897. * @method IPlugin#afterLayout
  5898. * @desc Called after the `chart` has been layed out. Note that this hook will not
  5899. * be called if the layout update has been previously cancelled.
  5900. * @param {Chart.Controller} chart - The chart instance.
  5901. * @param {Object} options - The plugin options.
  5902. */
  5903. /**
  5904. * @method IPlugin#beforeRender
  5905. * @desc Called before rendering `chart`. If any plugin returns `false`,
  5906. * the rendering is cancelled until another `render` is triggered.
  5907. * @param {Chart.Controller} chart - The chart instance.
  5908. * @param {Object} options - The plugin options.
  5909. * @returns {Boolean} `false` to cancel the chart rendering.
  5910. */
  5911. /**
  5912. * @method IPlugin#afterRender
  5913. * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  5914. * that this hook will not be called if the rendering has been previously cancelled.
  5915. * @param {Chart.Controller} chart - The chart instance.
  5916. * @param {Object} options - The plugin options.
  5917. */
  5918. /**
  5919. * @method IPlugin#beforeDraw
  5920. * @desc Called before drawing `chart` at every animation frame specified by the given
  5921. * easing value. If any plugin returns `false`, the frame drawing is cancelled until
  5922. * another `render` is triggered.
  5923. * @param {Chart.Controller} chart - The chart instance.
  5924. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5925. * @param {Object} options - The plugin options.
  5926. * @returns {Boolean} `false` to cancel the chart drawing.
  5927. */
  5928. /**
  5929. * @method IPlugin#afterDraw
  5930. * @desc Called after the `chart` has been drawn for the specific easing value. Note
  5931. * that this hook will not be called if the drawing has been previously cancelled.
  5932. * @param {Chart.Controller} chart - The chart instance.
  5933. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5934. * @param {Object} options - The plugin options.
  5935. */
  5936. /**
  5937. * @method IPlugin#beforeDatasetsDraw
  5938. * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  5939. * the datasets drawing is cancelled until another `render` is triggered.
  5940. * @param {Chart.Controller} chart - The chart instance.
  5941. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5942. * @param {Object} options - The plugin options.
  5943. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5944. */
  5945. /**
  5946. * @method IPlugin#afterDatasetsDraw
  5947. * @desc Called after the `chart` datasets have been drawn. Note that this hook
  5948. * will not be called if the datasets drawing has been previously cancelled.
  5949. * @param {Chart.Controller} chart - The chart instance.
  5950. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5951. * @param {Object} options - The plugin options.
  5952. */
  5953. /**
  5954. * @method IPlugin#beforeDatasetDraw
  5955. * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
  5956. * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
  5957. * is cancelled until another `render` is triggered.
  5958. * @param {Chart} chart - The chart instance.
  5959. * @param {Object} args - The call arguments.
  5960. * @param {Number} args.index - The dataset index.
  5961. * @param {Object} args.meta - The dataset metadata.
  5962. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5963. * @param {Object} options - The plugin options.
  5964. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5965. */
  5966. /**
  5967. * @method IPlugin#afterDatasetDraw
  5968. * @desc Called after the `chart` datasets at the given `args.index` have been drawn
  5969. * (datasets are drawn in the reverse order). Note that this hook will not be called
  5970. * if the datasets drawing has been previously cancelled.
  5971. * @param {Chart} chart - The chart instance.
  5972. * @param {Object} args - The call arguments.
  5973. * @param {Number} args.index - The dataset index.
  5974. * @param {Object} args.meta - The dataset metadata.
  5975. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5976. * @param {Object} options - The plugin options.
  5977. */
  5978. /**
  5979. * @method IPlugin#beforeTooltipDraw
  5980. * @desc Called before drawing the `tooltip`. If any plugin returns `false`,
  5981. * the tooltip drawing is cancelled until another `render` is triggered.
  5982. * @param {Chart} chart - The chart instance.
  5983. * @param {Object} args - The call arguments.
  5984. * @param {Object} args.tooltip - The tooltip.
  5985. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5986. * @param {Object} options - The plugin options.
  5987. * @returns {Boolean} `false` to cancel the chart tooltip drawing.
  5988. */
  5989. /**
  5990. * @method IPlugin#afterTooltipDraw
  5991. * @desc Called after drawing the `tooltip`. Note that this hook will not
  5992. * be called if the tooltip drawing has been previously cancelled.
  5993. * @param {Chart} chart - The chart instance.
  5994. * @param {Object} args - The call arguments.
  5995. * @param {Object} args.tooltip - The tooltip.
  5996. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5997. * @param {Object} options - The plugin options.
  5998. */
  5999. /**
  6000. * @method IPlugin#beforeEvent
  6001. * @desc Called before processing the specified `event`. If any plugin returns `false`,
  6002. * the event will be discarded.
  6003. * @param {Chart.Controller} chart - The chart instance.
  6004. * @param {IEvent} event - The event object.
  6005. * @param {Object} options - The plugin options.
  6006. */
  6007. /**
  6008. * @method IPlugin#afterEvent
  6009. * @desc Called after the `event` has been consumed. Note that this hook
  6010. * will not be called if the `event` has been previously discarded.
  6011. * @param {Chart.Controller} chart - The chart instance.
  6012. * @param {IEvent} event - The event object.
  6013. * @param {Object} options - The plugin options.
  6014. */
  6015. /**
  6016. * @method IPlugin#resize
  6017. * @desc Called after the chart as been resized.
  6018. * @param {Chart.Controller} chart - The chart instance.
  6019. * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
  6020. * @param {Object} options - The plugin options.
  6021. */
  6022. /**
  6023. * @method IPlugin#destroy
  6024. * @desc Called after the chart as been destroyed.
  6025. * @param {Chart.Controller} chart - The chart instance.
  6026. * @param {Object} options - The plugin options.
  6027. */
  6028. },{"26":26,"46":46}],33:[function(require,module,exports){
  6029. 'use strict';
  6030. var defaults = require(26);
  6031. var Element = require(27);
  6032. var helpers = require(46);
  6033. var Ticks = require(35);
  6034. defaults._set('scale', {
  6035. display: true,
  6036. position: 'left',
  6037. offset: false,
  6038. // grid line settings
  6039. gridLines: {
  6040. display: true,
  6041. color: 'rgba(0, 0, 0, 0.1)',
  6042. lineWidth: 1,
  6043. drawBorder: true,
  6044. drawOnChartArea: true,
  6045. drawTicks: true,
  6046. tickMarkLength: 10,
  6047. zeroLineWidth: 1,
  6048. zeroLineColor: 'rgba(0,0,0,0.25)',
  6049. zeroLineBorderDash: [],
  6050. zeroLineBorderDashOffset: 0.0,
  6051. offsetGridLines: false,
  6052. borderDash: [],
  6053. borderDashOffset: 0.0
  6054. },
  6055. // scale label
  6056. scaleLabel: {
  6057. // display property
  6058. display: false,
  6059. // actual label
  6060. labelString: '',
  6061. // line height
  6062. lineHeight: 1.2,
  6063. // top/bottom padding
  6064. padding: {
  6065. top: 4,
  6066. bottom: 4
  6067. }
  6068. },
  6069. // label settings
  6070. ticks: {
  6071. beginAtZero: false,
  6072. minRotation: 0,
  6073. maxRotation: 50,
  6074. mirror: false,
  6075. padding: 0,
  6076. reverse: false,
  6077. display: true,
  6078. autoSkip: true,
  6079. autoSkipPadding: 0,
  6080. labelOffset: 0,
  6081. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  6082. callback: Ticks.formatters.values,
  6083. minor: {},
  6084. major: {}
  6085. }
  6086. });
  6087. function labelsFromTicks(ticks) {
  6088. var labels = [];
  6089. var i, ilen;
  6090. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  6091. labels.push(ticks[i].label);
  6092. }
  6093. return labels;
  6094. }
  6095. function getLineValue(scale, index, offsetGridLines) {
  6096. var lineValue = scale.getPixelForTick(index);
  6097. if (offsetGridLines) {
  6098. if (index === 0) {
  6099. lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
  6100. } else {
  6101. lineValue -= (lineValue - scale.getPixelForTick(index - 1)) / 2;
  6102. }
  6103. }
  6104. return lineValue;
  6105. }
  6106. function computeTextSize(context, tick, font) {
  6107. return helpers.isArray(tick) ?
  6108. helpers.longestText(context, font, tick) :
  6109. context.measureText(tick).width;
  6110. }
  6111. function parseFontOptions(options) {
  6112. var valueOrDefault = helpers.valueOrDefault;
  6113. var globalDefaults = defaults.global;
  6114. var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
  6115. var style = valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
  6116. var family = valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
  6117. return {
  6118. size: size,
  6119. style: style,
  6120. family: family,
  6121. font: helpers.fontString(size, style, family)
  6122. };
  6123. }
  6124. function parseLineHeight(options) {
  6125. return helpers.options.toLineHeight(
  6126. helpers.valueOrDefault(options.lineHeight, 1.2),
  6127. helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
  6128. }
  6129. module.exports = Element.extend({
  6130. /**
  6131. * Get the padding needed for the scale
  6132. * @method getPadding
  6133. * @private
  6134. * @returns {Padding} the necessary padding
  6135. */
  6136. getPadding: function() {
  6137. var me = this;
  6138. return {
  6139. left: me.paddingLeft || 0,
  6140. top: me.paddingTop || 0,
  6141. right: me.paddingRight || 0,
  6142. bottom: me.paddingBottom || 0
  6143. };
  6144. },
  6145. /**
  6146. * Returns the scale tick objects ({label, major})
  6147. * @since 2.7
  6148. */
  6149. getTicks: function() {
  6150. return this._ticks;
  6151. },
  6152. // These methods are ordered by lifecyle. Utilities then follow.
  6153. // Any function defined here is inherited by all scale types.
  6154. // Any function can be extended by the scale type
  6155. mergeTicksOptions: function() {
  6156. var ticks = this.options.ticks;
  6157. if (ticks.minor === false) {
  6158. ticks.minor = {
  6159. display: false
  6160. };
  6161. }
  6162. if (ticks.major === false) {
  6163. ticks.major = {
  6164. display: false
  6165. };
  6166. }
  6167. for (var key in ticks) {
  6168. if (key !== 'major' && key !== 'minor') {
  6169. if (typeof ticks.minor[key] === 'undefined') {
  6170. ticks.minor[key] = ticks[key];
  6171. }
  6172. if (typeof ticks.major[key] === 'undefined') {
  6173. ticks.major[key] = ticks[key];
  6174. }
  6175. }
  6176. }
  6177. },
  6178. beforeUpdate: function() {
  6179. helpers.callback(this.options.beforeUpdate, [this]);
  6180. },
  6181. update: function(maxWidth, maxHeight, margins) {
  6182. var me = this;
  6183. var i, ilen, labels, label, ticks, tick;
  6184. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6185. me.beforeUpdate();
  6186. // Absorb the master measurements
  6187. me.maxWidth = maxWidth;
  6188. me.maxHeight = maxHeight;
  6189. me.margins = helpers.extend({
  6190. left: 0,
  6191. right: 0,
  6192. top: 0,
  6193. bottom: 0
  6194. }, margins);
  6195. me.longestTextCache = me.longestTextCache || {};
  6196. // Dimensions
  6197. me.beforeSetDimensions();
  6198. me.setDimensions();
  6199. me.afterSetDimensions();
  6200. // Data min/max
  6201. me.beforeDataLimits();
  6202. me.determineDataLimits();
  6203. me.afterDataLimits();
  6204. // Ticks - `this.ticks` is now DEPRECATED!
  6205. // Internal ticks are now stored as objects in the PRIVATE `this._ticks` member
  6206. // and must not be accessed directly from outside this class. `this.ticks` being
  6207. // around for long time and not marked as private, we can't change its structure
  6208. // without unexpected breaking changes. If you need to access the scale ticks,
  6209. // use scale.getTicks() instead.
  6210. me.beforeBuildTicks();
  6211. // New implementations should return an array of objects but for BACKWARD COMPAT,
  6212. // we still support no return (`this.ticks` internally set by calling this method).
  6213. ticks = me.buildTicks() || [];
  6214. me.afterBuildTicks();
  6215. me.beforeTickToLabelConversion();
  6216. // New implementations should return the formatted tick labels but for BACKWARD
  6217. // COMPAT, we still support no return (`this.ticks` internally changed by calling
  6218. // this method and supposed to contain only string values).
  6219. labels = me.convertTicksToLabels(ticks) || me.ticks;
  6220. me.afterTickToLabelConversion();
  6221. me.ticks = labels; // BACKWARD COMPATIBILITY
  6222. // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
  6223. // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
  6224. for (i = 0, ilen = labels.length; i < ilen; ++i) {
  6225. label = labels[i];
  6226. tick = ticks[i];
  6227. if (!tick) {
  6228. ticks.push(tick = {
  6229. label: label,
  6230. major: false
  6231. });
  6232. } else {
  6233. tick.label = label;
  6234. }
  6235. }
  6236. me._ticks = ticks;
  6237. // Tick Rotation
  6238. me.beforeCalculateTickRotation();
  6239. me.calculateTickRotation();
  6240. me.afterCalculateTickRotation();
  6241. // Fit
  6242. me.beforeFit();
  6243. me.fit();
  6244. me.afterFit();
  6245. //
  6246. me.afterUpdate();
  6247. return me.minSize;
  6248. },
  6249. afterUpdate: function() {
  6250. helpers.callback(this.options.afterUpdate, [this]);
  6251. },
  6252. //
  6253. beforeSetDimensions: function() {
  6254. helpers.callback(this.options.beforeSetDimensions, [this]);
  6255. },
  6256. setDimensions: function() {
  6257. var me = this;
  6258. // Set the unconstrained dimension before label rotation
  6259. if (me.isHorizontal()) {
  6260. // Reset position before calculating rotation
  6261. me.width = me.maxWidth;
  6262. me.left = 0;
  6263. me.right = me.width;
  6264. } else {
  6265. me.height = me.maxHeight;
  6266. // Reset position before calculating rotation
  6267. me.top = 0;
  6268. me.bottom = me.height;
  6269. }
  6270. // Reset padding
  6271. me.paddingLeft = 0;
  6272. me.paddingTop = 0;
  6273. me.paddingRight = 0;
  6274. me.paddingBottom = 0;
  6275. },
  6276. afterSetDimensions: function() {
  6277. helpers.callback(this.options.afterSetDimensions, [this]);
  6278. },
  6279. // Data limits
  6280. beforeDataLimits: function() {
  6281. helpers.callback(this.options.beforeDataLimits, [this]);
  6282. },
  6283. determineDataLimits: helpers.noop,
  6284. afterDataLimits: function() {
  6285. helpers.callback(this.options.afterDataLimits, [this]);
  6286. },
  6287. //
  6288. beforeBuildTicks: function() {
  6289. helpers.callback(this.options.beforeBuildTicks, [this]);
  6290. },
  6291. buildTicks: helpers.noop,
  6292. afterBuildTicks: function() {
  6293. helpers.callback(this.options.afterBuildTicks, [this]);
  6294. },
  6295. beforeTickToLabelConversion: function() {
  6296. helpers.callback(this.options.beforeTickToLabelConversion, [this]);
  6297. },
  6298. convertTicksToLabels: function() {
  6299. var me = this;
  6300. // Convert ticks to strings
  6301. var tickOpts = me.options.ticks;
  6302. me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback, this);
  6303. },
  6304. afterTickToLabelConversion: function() {
  6305. helpers.callback(this.options.afterTickToLabelConversion, [this]);
  6306. },
  6307. //
  6308. beforeCalculateTickRotation: function() {
  6309. helpers.callback(this.options.beforeCalculateTickRotation, [this]);
  6310. },
  6311. calculateTickRotation: function() {
  6312. var me = this;
  6313. var context = me.ctx;
  6314. var tickOpts = me.options.ticks;
  6315. var labels = labelsFromTicks(me._ticks);
  6316. // Get the width of each grid by calculating the difference
  6317. // between x offsets between 0 and 1.
  6318. var tickFont = parseFontOptions(tickOpts);
  6319. context.font = tickFont.font;
  6320. var labelRotation = tickOpts.minRotation || 0;
  6321. if (labels.length && me.options.display && me.isHorizontal()) {
  6322. var originalLabelWidth = helpers.longestText(context, tickFont.font, labels, me.longestTextCache);
  6323. var labelWidth = originalLabelWidth;
  6324. var cosRotation, sinRotation;
  6325. // Allow 3 pixels x2 padding either side for label readability
  6326. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6327. // Max label rotation can be set or default to 90 - also act as a loop counter
  6328. while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
  6329. var angleRadians = helpers.toRadians(labelRotation);
  6330. cosRotation = Math.cos(angleRadians);
  6331. sinRotation = Math.sin(angleRadians);
  6332. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6333. // go back one step
  6334. labelRotation--;
  6335. break;
  6336. }
  6337. labelRotation++;
  6338. labelWidth = cosRotation * originalLabelWidth;
  6339. }
  6340. }
  6341. me.labelRotation = labelRotation;
  6342. },
  6343. afterCalculateTickRotation: function() {
  6344. helpers.callback(this.options.afterCalculateTickRotation, [this]);
  6345. },
  6346. //
  6347. beforeFit: function() {
  6348. helpers.callback(this.options.beforeFit, [this]);
  6349. },
  6350. fit: function() {
  6351. var me = this;
  6352. // Reset
  6353. var minSize = me.minSize = {
  6354. width: 0,
  6355. height: 0
  6356. };
  6357. var labels = labelsFromTicks(me._ticks);
  6358. var opts = me.options;
  6359. var tickOpts = opts.ticks;
  6360. var scaleLabelOpts = opts.scaleLabel;
  6361. var gridLineOpts = opts.gridLines;
  6362. var display = opts.display;
  6363. var isHorizontal = me.isHorizontal();
  6364. var tickFont = parseFontOptions(tickOpts);
  6365. var tickMarkLength = opts.gridLines.tickMarkLength;
  6366. // Width
  6367. if (isHorizontal) {
  6368. // subtract the margins to line up with the chartArea if we are a full width scale
  6369. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6370. } else {
  6371. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6372. }
  6373. // height
  6374. if (isHorizontal) {
  6375. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6376. } else {
  6377. minSize.height = me.maxHeight; // fill all the height
  6378. }
  6379. // Are we showing a title for the scale?
  6380. if (scaleLabelOpts.display && display) {
  6381. var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
  6382. var scaleLabelPadding = helpers.options.toPadding(scaleLabelOpts.padding);
  6383. var deltaHeight = scaleLabelLineHeight + scaleLabelPadding.height;
  6384. if (isHorizontal) {
  6385. minSize.height += deltaHeight;
  6386. } else {
  6387. minSize.width += deltaHeight;
  6388. }
  6389. }
  6390. // Don't bother fitting the ticks if we are not showing them
  6391. if (tickOpts.display && display) {
  6392. var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, labels, me.longestTextCache);
  6393. var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
  6394. var lineSpace = tickFont.size * 0.5;
  6395. var tickPadding = me.options.ticks.padding;
  6396. if (isHorizontal) {
  6397. // A horizontal axis is more constrained by the height.
  6398. me.longestLabelWidth = largestTextWidth;
  6399. var angleRadians = helpers.toRadians(me.labelRotation);
  6400. var cosRotation = Math.cos(angleRadians);
  6401. var sinRotation = Math.sin(angleRadians);
  6402. // TODO - improve this calculation
  6403. var labelHeight = (sinRotation * largestTextWidth)
  6404. + (tickFont.size * tallestLabelHeightInLines)
  6405. + (lineSpace * (tallestLabelHeightInLines - 1))
  6406. + lineSpace; // padding
  6407. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);
  6408. me.ctx.font = tickFont.font;
  6409. var firstLabelWidth = computeTextSize(me.ctx, labels[0], tickFont.font);
  6410. var lastLabelWidth = computeTextSize(me.ctx, labels[labels.length - 1], tickFont.font);
  6411. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
  6412. // which means that the right padding is dominated by the font height
  6413. if (me.labelRotation !== 0) {
  6414. me.paddingLeft = opts.position === 'bottom' ? (cosRotation * firstLabelWidth) + 3 : (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
  6415. me.paddingRight = opts.position === 'bottom' ? (cosRotation * lineSpace) + 3 : (cosRotation * lastLabelWidth) + 3;
  6416. } else {
  6417. me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6418. me.paddingRight = lastLabelWidth / 2 + 3;
  6419. }
  6420. } else {
  6421. // A vertical axis is more constrained by the width. Labels are the
  6422. // dominant factor here, so get that length first and account for padding
  6423. if (tickOpts.mirror) {
  6424. largestTextWidth = 0;
  6425. } else {
  6426. // use lineSpace for consistency with horizontal axis
  6427. // tickPadding is not implemented for horizontal
  6428. largestTextWidth += tickPadding + lineSpace;
  6429. }
  6430. minSize.width = Math.min(me.maxWidth, minSize.width + largestTextWidth);
  6431. me.paddingTop = tickFont.size / 2;
  6432. me.paddingBottom = tickFont.size / 2;
  6433. }
  6434. }
  6435. me.handleMargins();
  6436. me.width = minSize.width;
  6437. me.height = minSize.height;
  6438. },
  6439. /**
  6440. * Handle margins and padding interactions
  6441. * @private
  6442. */
  6443. handleMargins: function() {
  6444. var me = this;
  6445. if (me.margins) {
  6446. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6447. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6448. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6449. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6450. }
  6451. },
  6452. afterFit: function() {
  6453. helpers.callback(this.options.afterFit, [this]);
  6454. },
  6455. // Shared Methods
  6456. isHorizontal: function() {
  6457. return this.options.position === 'top' || this.options.position === 'bottom';
  6458. },
  6459. isFullWidth: function() {
  6460. return (this.options.fullWidth);
  6461. },
  6462. // 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
  6463. getRightValue: function(rawValue) {
  6464. // Null and undefined values first
  6465. if (helpers.isNullOrUndef(rawValue)) {
  6466. return NaN;
  6467. }
  6468. // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
  6469. if (typeof rawValue === 'number' && !isFinite(rawValue)) {
  6470. return NaN;
  6471. }
  6472. // If it is in fact an object, dive in one more level
  6473. if (rawValue) {
  6474. if (this.isHorizontal()) {
  6475. if (rawValue.x !== undefined) {
  6476. return this.getRightValue(rawValue.x);
  6477. }
  6478. } else if (rawValue.y !== undefined) {
  6479. return this.getRightValue(rawValue.y);
  6480. }
  6481. }
  6482. // Value is good, return it
  6483. return rawValue;
  6484. },
  6485. /**
  6486. * Used to get the value to display in the tooltip for the data at the given index
  6487. * @param index
  6488. * @param datasetIndex
  6489. */
  6490. getLabelForIndex: helpers.noop,
  6491. /**
  6492. * Returns the location of the given data point. Value can either be an index or a numerical value
  6493. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6494. * @param value
  6495. * @param index
  6496. * @param datasetIndex
  6497. */
  6498. getPixelForValue: helpers.noop,
  6499. /**
  6500. * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6501. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6502. * @param pixel
  6503. */
  6504. getValueForPixel: helpers.noop,
  6505. /**
  6506. * Returns the location of the tick at the given index
  6507. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6508. */
  6509. getPixelForTick: function(index) {
  6510. var me = this;
  6511. var offset = me.options.offset;
  6512. if (me.isHorizontal()) {
  6513. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6514. var tickWidth = innerWidth / Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  6515. var pixel = (tickWidth * index) + me.paddingLeft;
  6516. if (offset) {
  6517. pixel += tickWidth / 2;
  6518. }
  6519. var finalVal = me.left + Math.round(pixel);
  6520. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6521. return finalVal;
  6522. }
  6523. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6524. return me.top + (index * (innerHeight / (me._ticks.length - 1)));
  6525. },
  6526. /**
  6527. * Utility for getting the pixel location of a percentage of scale
  6528. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6529. */
  6530. getPixelForDecimal: function(decimal) {
  6531. var me = this;
  6532. if (me.isHorizontal()) {
  6533. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6534. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6535. var finalVal = me.left + Math.round(valueOffset);
  6536. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6537. return finalVal;
  6538. }
  6539. return me.top + (decimal * me.height);
  6540. },
  6541. /**
  6542. * Returns the pixel for the minimum chart value
  6543. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6544. */
  6545. getBasePixel: function() {
  6546. return this.getPixelForValue(this.getBaseValue());
  6547. },
  6548. getBaseValue: function() {
  6549. var me = this;
  6550. var min = me.min;
  6551. var max = me.max;
  6552. return me.beginAtZero ? 0 :
  6553. min < 0 && max < 0 ? max :
  6554. min > 0 && max > 0 ? min :
  6555. 0;
  6556. },
  6557. /**
  6558. * Returns a subset of ticks to be plotted to avoid overlapping labels.
  6559. * @private
  6560. */
  6561. _autoSkip: function(ticks) {
  6562. var skipRatio;
  6563. var me = this;
  6564. var isHorizontal = me.isHorizontal();
  6565. var optionTicks = me.options.ticks.minor;
  6566. var tickCount = ticks.length;
  6567. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6568. var cosRotation = Math.cos(labelRotationRadians);
  6569. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6570. var result = [];
  6571. var i, tick, shouldSkip;
  6572. // figure out the maximum number of gridlines to show
  6573. var maxTicks;
  6574. if (optionTicks.maxTicksLimit) {
  6575. maxTicks = optionTicks.maxTicksLimit;
  6576. }
  6577. if (isHorizontal) {
  6578. skipRatio = false;
  6579. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount > (me.width - (me.paddingLeft + me.paddingRight))) {
  6580. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount) / (me.width - (me.paddingLeft + me.paddingRight)));
  6581. }
  6582. // if they defined a max number of optionTicks,
  6583. // increase skipRatio until that number is met
  6584. if (maxTicks && tickCount > maxTicks) {
  6585. skipRatio = Math.max(skipRatio, Math.floor(tickCount / maxTicks));
  6586. }
  6587. }
  6588. for (i = 0; i < tickCount; i++) {
  6589. tick = ticks[i];
  6590. // Since we always show the last tick,we need may need to hide the last shown one before
  6591. shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
  6592. if (shouldSkip && i !== tickCount - 1) {
  6593. // leave tick in place but make sure it's not displayed (#4635)
  6594. delete tick.label;
  6595. }
  6596. result.push(tick);
  6597. }
  6598. return result;
  6599. },
  6600. // Actually draw the scale on the canvas
  6601. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6602. draw: function(chartArea) {
  6603. var me = this;
  6604. var options = me.options;
  6605. if (!options.display) {
  6606. return;
  6607. }
  6608. var context = me.ctx;
  6609. var globalDefaults = defaults.global;
  6610. var optionTicks = options.ticks.minor;
  6611. var optionMajorTicks = options.ticks.major || optionTicks;
  6612. var gridLines = options.gridLines;
  6613. var scaleLabel = options.scaleLabel;
  6614. var isRotated = me.labelRotation !== 0;
  6615. var isHorizontal = me.isHorizontal();
  6616. var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
  6617. var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6618. var tickFont = parseFontOptions(optionTicks);
  6619. var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, globalDefaults.defaultFontColor);
  6620. var majorTickFont = parseFontOptions(optionMajorTicks);
  6621. var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
  6622. var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6623. var scaleLabelFont = parseFontOptions(scaleLabel);
  6624. var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
  6625. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6626. var itemsToDraw = [];
  6627. var axisWidth = me.options.gridLines.lineWidth;
  6628. var xTickStart = options.position === 'right' ? me.left : me.right - axisWidth - tl;
  6629. var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
  6630. var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
  6631. var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
  6632. helpers.each(ticks, function(tick, index) {
  6633. // autoskipper skipped this tick (#4635)
  6634. if (helpers.isNullOrUndef(tick.label)) {
  6635. return;
  6636. }
  6637. var label = tick.label;
  6638. var lineWidth, lineColor, borderDash, borderDashOffset;
  6639. if (index === me.zeroLineIndex && options.offset === gridLines.offsetGridLines) {
  6640. // Draw the first index specially
  6641. lineWidth = gridLines.zeroLineWidth;
  6642. lineColor = gridLines.zeroLineColor;
  6643. borderDash = gridLines.zeroLineBorderDash;
  6644. borderDashOffset = gridLines.zeroLineBorderDashOffset;
  6645. } else {
  6646. lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
  6647. lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
  6648. borderDash = helpers.valueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6649. borderDashOffset = helpers.valueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6650. }
  6651. // Common properties
  6652. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6653. var textAlign = 'middle';
  6654. var textBaseline = 'middle';
  6655. var tickPadding = optionTicks.padding;
  6656. if (isHorizontal) {
  6657. var labelYOffset = tl + tickPadding;
  6658. if (options.position === 'bottom') {
  6659. // bottom
  6660. textBaseline = !isRotated ? 'top' : 'middle';
  6661. textAlign = !isRotated ? 'center' : 'right';
  6662. labelY = me.top + labelYOffset;
  6663. } else {
  6664. // top
  6665. textBaseline = !isRotated ? 'bottom' : 'middle';
  6666. textAlign = !isRotated ? 'center' : 'left';
  6667. labelY = me.bottom - labelYOffset;
  6668. }
  6669. var xLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6670. if (xLineValue < me.left) {
  6671. lineColor = 'rgba(0,0,0,0)';
  6672. }
  6673. xLineValue += helpers.aliasPixel(lineWidth);
  6674. labelX = me.getPixelForTick(index) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6675. tx1 = tx2 = x1 = x2 = xLineValue;
  6676. ty1 = yTickStart;
  6677. ty2 = yTickEnd;
  6678. y1 = chartArea.top;
  6679. y2 = chartArea.bottom + axisWidth;
  6680. } else {
  6681. var isLeft = options.position === 'left';
  6682. var labelXOffset;
  6683. if (optionTicks.mirror) {
  6684. textAlign = isLeft ? 'left' : 'right';
  6685. labelXOffset = tickPadding;
  6686. } else {
  6687. textAlign = isLeft ? 'right' : 'left';
  6688. labelXOffset = tl + tickPadding;
  6689. }
  6690. labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
  6691. var yLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6692. if (yLineValue < me.top) {
  6693. lineColor = 'rgba(0,0,0,0)';
  6694. }
  6695. yLineValue += helpers.aliasPixel(lineWidth);
  6696. labelY = me.getPixelForTick(index) + optionTicks.labelOffset;
  6697. tx1 = xTickStart;
  6698. tx2 = xTickEnd;
  6699. x1 = chartArea.left;
  6700. x2 = chartArea.right + axisWidth;
  6701. ty1 = ty2 = y1 = y2 = yLineValue;
  6702. }
  6703. itemsToDraw.push({
  6704. tx1: tx1,
  6705. ty1: ty1,
  6706. tx2: tx2,
  6707. ty2: ty2,
  6708. x1: x1,
  6709. y1: y1,
  6710. x2: x2,
  6711. y2: y2,
  6712. labelX: labelX,
  6713. labelY: labelY,
  6714. glWidth: lineWidth,
  6715. glColor: lineColor,
  6716. glBorderDash: borderDash,
  6717. glBorderDashOffset: borderDashOffset,
  6718. rotation: -1 * labelRotationRadians,
  6719. label: label,
  6720. major: tick.major,
  6721. textBaseline: textBaseline,
  6722. textAlign: textAlign
  6723. });
  6724. });
  6725. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  6726. helpers.each(itemsToDraw, function(itemToDraw) {
  6727. if (gridLines.display) {
  6728. context.save();
  6729. context.lineWidth = itemToDraw.glWidth;
  6730. context.strokeStyle = itemToDraw.glColor;
  6731. if (context.setLineDash) {
  6732. context.setLineDash(itemToDraw.glBorderDash);
  6733. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  6734. }
  6735. context.beginPath();
  6736. if (gridLines.drawTicks) {
  6737. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  6738. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  6739. }
  6740. if (gridLines.drawOnChartArea) {
  6741. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  6742. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  6743. }
  6744. context.stroke();
  6745. context.restore();
  6746. }
  6747. if (optionTicks.display) {
  6748. // Make sure we draw text in the correct color and font
  6749. context.save();
  6750. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  6751. context.rotate(itemToDraw.rotation);
  6752. context.font = itemToDraw.major ? majorTickFont.font : tickFont.font;
  6753. context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
  6754. context.textBaseline = itemToDraw.textBaseline;
  6755. context.textAlign = itemToDraw.textAlign;
  6756. var label = itemToDraw.label;
  6757. if (helpers.isArray(label)) {
  6758. var lineCount = label.length;
  6759. var lineHeight = tickFont.size * 1.5;
  6760. var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
  6761. for (var i = 0; i < lineCount; ++i) {
  6762. // We just make sure the multiline element is a string here..
  6763. context.fillText('' + label[i], 0, y);
  6764. // apply same lineSpacing as calculated @ L#320
  6765. y += lineHeight;
  6766. }
  6767. } else {
  6768. context.fillText(label, 0, 0);
  6769. }
  6770. context.restore();
  6771. }
  6772. });
  6773. if (scaleLabel.display) {
  6774. // Draw the scale label
  6775. var scaleLabelX;
  6776. var scaleLabelY;
  6777. var rotation = 0;
  6778. var halfLineHeight = parseLineHeight(scaleLabel) / 2;
  6779. if (isHorizontal) {
  6780. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  6781. scaleLabelY = options.position === 'bottom'
  6782. ? me.bottom - halfLineHeight - scaleLabelPadding.bottom
  6783. : me.top + halfLineHeight + scaleLabelPadding.top;
  6784. } else {
  6785. var isLeft = options.position === 'left';
  6786. scaleLabelX = isLeft
  6787. ? me.left + halfLineHeight + scaleLabelPadding.top
  6788. : me.right - halfLineHeight - scaleLabelPadding.top;
  6789. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  6790. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  6791. }
  6792. context.save();
  6793. context.translate(scaleLabelX, scaleLabelY);
  6794. context.rotate(rotation);
  6795. context.textAlign = 'center';
  6796. context.textBaseline = 'middle';
  6797. context.fillStyle = scaleLabelFontColor; // render in correct colour
  6798. context.font = scaleLabelFont.font;
  6799. context.fillText(scaleLabel.labelString, 0, 0);
  6800. context.restore();
  6801. }
  6802. if (gridLines.drawBorder) {
  6803. // Draw the line at the edge of the axis
  6804. context.lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0);
  6805. context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
  6806. var x1 = me.left;
  6807. var x2 = me.right + axisWidth;
  6808. var y1 = me.top;
  6809. var y2 = me.bottom + axisWidth;
  6810. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  6811. if (isHorizontal) {
  6812. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  6813. y1 += aliasPixel;
  6814. y2 += aliasPixel;
  6815. } else {
  6816. x1 = x2 = options.position === 'left' ? me.right : me.left;
  6817. x1 += aliasPixel;
  6818. x2 += aliasPixel;
  6819. }
  6820. context.beginPath();
  6821. context.moveTo(x1, y1);
  6822. context.lineTo(x2, y2);
  6823. context.stroke();
  6824. }
  6825. }
  6826. });
  6827. },{"26":26,"27":27,"35":35,"46":46}],34:[function(require,module,exports){
  6828. 'use strict';
  6829. var defaults = require(26);
  6830. var helpers = require(46);
  6831. var layouts = require(31);
  6832. module.exports = {
  6833. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  6834. // use the new chart options to grab the correct scale
  6835. constructors: {},
  6836. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  6837. // old browsers
  6838. // Scale config defaults
  6839. defaults: {},
  6840. registerScaleType: function(type, scaleConstructor, scaleDefaults) {
  6841. this.constructors[type] = scaleConstructor;
  6842. this.defaults[type] = helpers.clone(scaleDefaults);
  6843. },
  6844. getScaleConstructor: function(type) {
  6845. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  6846. },
  6847. getScaleDefaults: function(type) {
  6848. // Return the scale defaults merged with the global settings so that we always use the latest ones
  6849. return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
  6850. },
  6851. updateScaleDefaults: function(type, additions) {
  6852. var me = this;
  6853. if (me.defaults.hasOwnProperty(type)) {
  6854. me.defaults[type] = helpers.extend(me.defaults[type], additions);
  6855. }
  6856. },
  6857. addScalesToLayout: function(chart) {
  6858. // Adds each scale to the chart.boxes array to be sized accordingly
  6859. helpers.each(chart.scales, function(scale) {
  6860. // Set ILayoutItem parameters for backwards compatibility
  6861. scale.fullWidth = scale.options.fullWidth;
  6862. scale.position = scale.options.position;
  6863. scale.weight = scale.options.weight;
  6864. layouts.addBox(chart, scale);
  6865. });
  6866. }
  6867. };
  6868. },{"26":26,"31":31,"46":46}],35:[function(require,module,exports){
  6869. 'use strict';
  6870. var helpers = require(46);
  6871. /**
  6872. * Namespace to hold static tick generation functions
  6873. * @namespace Chart.Ticks
  6874. */
  6875. module.exports = {
  6876. /**
  6877. * Namespace to hold formatters for different types of ticks
  6878. * @namespace Chart.Ticks.formatters
  6879. */
  6880. formatters: {
  6881. /**
  6882. * Formatter for value labels
  6883. * @method Chart.Ticks.formatters.values
  6884. * @param value the value to display
  6885. * @return {String|Array} the label to display
  6886. */
  6887. values: function(value) {
  6888. return helpers.isArray(value) ? value : '' + value;
  6889. },
  6890. /**
  6891. * Formatter for linear numeric ticks
  6892. * @method Chart.Ticks.formatters.linear
  6893. * @param tickValue {Number} the value to be formatted
  6894. * @param index {Number} the position of the tickValue parameter in the ticks array
  6895. * @param ticks {Array<Number>} the list of ticks being converted
  6896. * @return {String} string representation of the tickValue parameter
  6897. */
  6898. linear: function(tickValue, index, ticks) {
  6899. // If we have lots of ticks, don't use the ones
  6900. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  6901. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  6902. if (Math.abs(delta) > 1) {
  6903. if (tickValue !== Math.floor(tickValue)) {
  6904. // not an integer
  6905. delta = tickValue - Math.floor(tickValue);
  6906. }
  6907. }
  6908. var logDelta = helpers.log10(Math.abs(delta));
  6909. var tickString = '';
  6910. if (tickValue !== 0) {
  6911. var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1]));
  6912. if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation
  6913. var logTick = helpers.log10(Math.abs(tickValue));
  6914. tickString = tickValue.toExponential(Math.floor(logTick) - Math.floor(logDelta));
  6915. } else {
  6916. var numDecimal = -1 * Math.floor(logDelta);
  6917. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  6918. tickString = tickValue.toFixed(numDecimal);
  6919. }
  6920. } else {
  6921. tickString = '0'; // never show decimal places for 0
  6922. }
  6923. return tickString;
  6924. },
  6925. logarithmic: function(tickValue, index, ticks) {
  6926. var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
  6927. if (tickValue === 0) {
  6928. return '0';
  6929. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
  6930. return tickValue.toExponential();
  6931. }
  6932. return '';
  6933. }
  6934. }
  6935. };
  6936. },{"46":46}],36:[function(require,module,exports){
  6937. 'use strict';
  6938. var defaults = require(26);
  6939. var Element = require(27);
  6940. var helpers = require(46);
  6941. defaults._set('global', {
  6942. tooltips: {
  6943. enabled: true,
  6944. custom: null,
  6945. mode: 'nearest',
  6946. position: 'average',
  6947. intersect: true,
  6948. backgroundColor: 'rgba(0,0,0,0.8)',
  6949. titleFontStyle: 'bold',
  6950. titleSpacing: 2,
  6951. titleMarginBottom: 6,
  6952. titleFontColor: '#fff',
  6953. titleAlign: 'left',
  6954. bodySpacing: 2,
  6955. bodyFontColor: '#fff',
  6956. bodyAlign: 'left',
  6957. footerFontStyle: 'bold',
  6958. footerSpacing: 2,
  6959. footerMarginTop: 6,
  6960. footerFontColor: '#fff',
  6961. footerAlign: 'left',
  6962. yPadding: 6,
  6963. xPadding: 6,
  6964. caretPadding: 2,
  6965. caretSize: 5,
  6966. cornerRadius: 6,
  6967. multiKeyBackground: '#fff',
  6968. displayColors: true,
  6969. borderColor: 'rgba(0,0,0,0)',
  6970. borderWidth: 0,
  6971. callbacks: {
  6972. // Args are: (tooltipItems, data)
  6973. beforeTitle: helpers.noop,
  6974. title: function(tooltipItems, data) {
  6975. // Pick first xLabel for now
  6976. var title = '';
  6977. var labels = data.labels;
  6978. var labelCount = labels ? labels.length : 0;
  6979. if (tooltipItems.length > 0) {
  6980. var item = tooltipItems[0];
  6981. if (item.xLabel) {
  6982. title = item.xLabel;
  6983. } else if (labelCount > 0 && item.index < labelCount) {
  6984. title = labels[item.index];
  6985. }
  6986. }
  6987. return title;
  6988. },
  6989. afterTitle: helpers.noop,
  6990. // Args are: (tooltipItems, data)
  6991. beforeBody: helpers.noop,
  6992. // Args are: (tooltipItem, data)
  6993. beforeLabel: helpers.noop,
  6994. label: function(tooltipItem, data) {
  6995. var label = data.datasets[tooltipItem.datasetIndex].label || '';
  6996. if (label) {
  6997. label += ': ';
  6998. }
  6999. label += tooltipItem.yLabel;
  7000. return label;
  7001. },
  7002. labelColor: function(tooltipItem, chart) {
  7003. var meta = chart.getDatasetMeta(tooltipItem.datasetIndex);
  7004. var activeElement = meta.data[tooltipItem.index];
  7005. var view = activeElement._view;
  7006. return {
  7007. borderColor: view.borderColor,
  7008. backgroundColor: view.backgroundColor
  7009. };
  7010. },
  7011. labelTextColor: function() {
  7012. return this._options.bodyFontColor;
  7013. },
  7014. afterLabel: helpers.noop,
  7015. // Args are: (tooltipItems, data)
  7016. afterBody: helpers.noop,
  7017. // Args are: (tooltipItems, data)
  7018. beforeFooter: helpers.noop,
  7019. footer: helpers.noop,
  7020. afterFooter: helpers.noop
  7021. }
  7022. }
  7023. });
  7024. var positioners = {
  7025. /**
  7026. * Average mode places the tooltip at the average position of the elements shown
  7027. * @function Chart.Tooltip.positioners.average
  7028. * @param elements {ChartElement[]} the elements being displayed in the tooltip
  7029. * @returns {Point} tooltip position
  7030. */
  7031. average: function(elements) {
  7032. if (!elements.length) {
  7033. return false;
  7034. }
  7035. var i, len;
  7036. var x = 0;
  7037. var y = 0;
  7038. var count = 0;
  7039. for (i = 0, len = elements.length; i < len; ++i) {
  7040. var el = elements[i];
  7041. if (el && el.hasValue()) {
  7042. var pos = el.tooltipPosition();
  7043. x += pos.x;
  7044. y += pos.y;
  7045. ++count;
  7046. }
  7047. }
  7048. return {
  7049. x: Math.round(x / count),
  7050. y: Math.round(y / count)
  7051. };
  7052. },
  7053. /**
  7054. * Gets the tooltip position nearest of the item nearest to the event position
  7055. * @function Chart.Tooltip.positioners.nearest
  7056. * @param elements {Chart.Element[]} the tooltip elements
  7057. * @param eventPosition {Point} the position of the event in canvas coordinates
  7058. * @returns {Point} the tooltip position
  7059. */
  7060. nearest: function(elements, eventPosition) {
  7061. var x = eventPosition.x;
  7062. var y = eventPosition.y;
  7063. var minDistance = Number.POSITIVE_INFINITY;
  7064. var i, len, nearestElement;
  7065. for (i = 0, len = elements.length; i < len; ++i) {
  7066. var el = elements[i];
  7067. if (el && el.hasValue()) {
  7068. var center = el.getCenterPoint();
  7069. var d = helpers.distanceBetweenPoints(eventPosition, center);
  7070. if (d < minDistance) {
  7071. minDistance = d;
  7072. nearestElement = el;
  7073. }
  7074. }
  7075. }
  7076. if (nearestElement) {
  7077. var tp = nearestElement.tooltipPosition();
  7078. x = tp.x;
  7079. y = tp.y;
  7080. }
  7081. return {
  7082. x: x,
  7083. y: y
  7084. };
  7085. }
  7086. };
  7087. /**
  7088. * Helper method to merge the opacity into a color
  7089. */
  7090. function mergeOpacity(colorString, opacity) {
  7091. var color = helpers.color(colorString);
  7092. return color.alpha(opacity * color.alpha()).rgbaString();
  7093. }
  7094. // Helper to push or concat based on if the 2nd parameter is an array or not
  7095. function pushOrConcat(base, toPush) {
  7096. if (toPush) {
  7097. if (helpers.isArray(toPush)) {
  7098. // base = base.concat(toPush);
  7099. Array.prototype.push.apply(base, toPush);
  7100. } else {
  7101. base.push(toPush);
  7102. }
  7103. }
  7104. return base;
  7105. }
  7106. /**
  7107. * Returns array of strings split by newline
  7108. * @param {String} value - The value to split by newline.
  7109. * @returns {Array} value if newline present - Returned from String split() method
  7110. * @function
  7111. */
  7112. function splitNewlines(str) {
  7113. if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) {
  7114. return str.split('\n');
  7115. }
  7116. return str;
  7117. }
  7118. // Private helper to create a tooltip item model
  7119. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  7120. // @return : new tooltip item
  7121. function createTooltipItem(element) {
  7122. var xScale = element._xScale;
  7123. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  7124. var index = element._index;
  7125. var datasetIndex = element._datasetIndex;
  7126. return {
  7127. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  7128. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  7129. index: index,
  7130. datasetIndex: datasetIndex,
  7131. x: element._model.x,
  7132. y: element._model.y
  7133. };
  7134. }
  7135. /**
  7136. * Helper to get the reset model for the tooltip
  7137. * @param tooltipOpts {Object} the tooltip options
  7138. */
  7139. function getBaseModel(tooltipOpts) {
  7140. var globalDefaults = defaults.global;
  7141. var valueOrDefault = helpers.valueOrDefault;
  7142. return {
  7143. // Positioning
  7144. xPadding: tooltipOpts.xPadding,
  7145. yPadding: tooltipOpts.yPadding,
  7146. xAlign: tooltipOpts.xAlign,
  7147. yAlign: tooltipOpts.yAlign,
  7148. // Body
  7149. bodyFontColor: tooltipOpts.bodyFontColor,
  7150. _bodyFontFamily: valueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  7151. _bodyFontStyle: valueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  7152. _bodyAlign: tooltipOpts.bodyAlign,
  7153. bodyFontSize: valueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  7154. bodySpacing: tooltipOpts.bodySpacing,
  7155. // Title
  7156. titleFontColor: tooltipOpts.titleFontColor,
  7157. _titleFontFamily: valueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  7158. _titleFontStyle: valueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  7159. titleFontSize: valueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  7160. _titleAlign: tooltipOpts.titleAlign,
  7161. titleSpacing: tooltipOpts.titleSpacing,
  7162. titleMarginBottom: tooltipOpts.titleMarginBottom,
  7163. // Footer
  7164. footerFontColor: tooltipOpts.footerFontColor,
  7165. _footerFontFamily: valueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  7166. _footerFontStyle: valueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  7167. footerFontSize: valueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  7168. _footerAlign: tooltipOpts.footerAlign,
  7169. footerSpacing: tooltipOpts.footerSpacing,
  7170. footerMarginTop: tooltipOpts.footerMarginTop,
  7171. // Appearance
  7172. caretSize: tooltipOpts.caretSize,
  7173. cornerRadius: tooltipOpts.cornerRadius,
  7174. backgroundColor: tooltipOpts.backgroundColor,
  7175. opacity: 0,
  7176. legendColorBackground: tooltipOpts.multiKeyBackground,
  7177. displayColors: tooltipOpts.displayColors,
  7178. borderColor: tooltipOpts.borderColor,
  7179. borderWidth: tooltipOpts.borderWidth
  7180. };
  7181. }
  7182. /**
  7183. * Get the size of the tooltip
  7184. */
  7185. function getTooltipSize(tooltip, model) {
  7186. var ctx = tooltip._chart.ctx;
  7187. var height = model.yPadding * 2; // Tooltip Padding
  7188. var width = 0;
  7189. // Count of all lines in the body
  7190. var body = model.body;
  7191. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  7192. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7193. }, 0);
  7194. combinedBodyLength += model.beforeBody.length + model.afterBody.length;
  7195. var titleLineCount = model.title.length;
  7196. var footerLineCount = model.footer.length;
  7197. var titleFontSize = model.titleFontSize;
  7198. var bodyFontSize = model.bodyFontSize;
  7199. var footerFontSize = model.footerFontSize;
  7200. height += titleLineCount * titleFontSize; // Title Lines
  7201. height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
  7202. height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
  7203. height += combinedBodyLength * bodyFontSize; // Body Lines
  7204. height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
  7205. height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
  7206. height += footerLineCount * (footerFontSize); // Footer Lines
  7207. height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
  7208. // Title width
  7209. var widthPadding = 0;
  7210. var maxLineWidth = function(line) {
  7211. width = Math.max(width, ctx.measureText(line).width + widthPadding);
  7212. };
  7213. ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
  7214. helpers.each(model.title, maxLineWidth);
  7215. // Body width
  7216. ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
  7217. helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
  7218. // Body lines may include some extra width due to the color box
  7219. widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
  7220. helpers.each(body, function(bodyItem) {
  7221. helpers.each(bodyItem.before, maxLineWidth);
  7222. helpers.each(bodyItem.lines, maxLineWidth);
  7223. helpers.each(bodyItem.after, maxLineWidth);
  7224. });
  7225. // Reset back to 0
  7226. widthPadding = 0;
  7227. // Footer width
  7228. ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
  7229. helpers.each(model.footer, maxLineWidth);
  7230. // Add padding
  7231. width += 2 * model.xPadding;
  7232. return {
  7233. width: width,
  7234. height: height
  7235. };
  7236. }
  7237. /**
  7238. * Helper to get the alignment of a tooltip given the size
  7239. */
  7240. function determineAlignment(tooltip, size) {
  7241. var model = tooltip._model;
  7242. var chart = tooltip._chart;
  7243. var chartArea = tooltip._chart.chartArea;
  7244. var xAlign = 'center';
  7245. var yAlign = 'center';
  7246. if (model.y < size.height) {
  7247. yAlign = 'top';
  7248. } else if (model.y > (chart.height - size.height)) {
  7249. yAlign = 'bottom';
  7250. }
  7251. var lf, rf; // functions to determine left, right alignment
  7252. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7253. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7254. var midX = (chartArea.left + chartArea.right) / 2;
  7255. var midY = (chartArea.top + chartArea.bottom) / 2;
  7256. if (yAlign === 'center') {
  7257. lf = function(x) {
  7258. return x <= midX;
  7259. };
  7260. rf = function(x) {
  7261. return x > midX;
  7262. };
  7263. } else {
  7264. lf = function(x) {
  7265. return x <= (size.width / 2);
  7266. };
  7267. rf = function(x) {
  7268. return x >= (chart.width - (size.width / 2));
  7269. };
  7270. }
  7271. olf = function(x) {
  7272. return x + size.width + model.caretSize + model.caretPadding > chart.width;
  7273. };
  7274. orf = function(x) {
  7275. return x - size.width - model.caretSize - model.caretPadding < 0;
  7276. };
  7277. yf = function(y) {
  7278. return y <= midY ? 'top' : 'bottom';
  7279. };
  7280. if (lf(model.x)) {
  7281. xAlign = 'left';
  7282. // Is tooltip too wide and goes over the right side of the chart.?
  7283. if (olf(model.x)) {
  7284. xAlign = 'center';
  7285. yAlign = yf(model.y);
  7286. }
  7287. } else if (rf(model.x)) {
  7288. xAlign = 'right';
  7289. // Is tooltip too wide and goes outside left edge of canvas?
  7290. if (orf(model.x)) {
  7291. xAlign = 'center';
  7292. yAlign = yf(model.y);
  7293. }
  7294. }
  7295. var opts = tooltip._options;
  7296. return {
  7297. xAlign: opts.xAlign ? opts.xAlign : xAlign,
  7298. yAlign: opts.yAlign ? opts.yAlign : yAlign
  7299. };
  7300. }
  7301. /**
  7302. * Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
  7303. */
  7304. function getBackgroundPoint(vm, size, alignment, chart) {
  7305. // Background Position
  7306. var x = vm.x;
  7307. var y = vm.y;
  7308. var caretSize = vm.caretSize;
  7309. var caretPadding = vm.caretPadding;
  7310. var cornerRadius = vm.cornerRadius;
  7311. var xAlign = alignment.xAlign;
  7312. var yAlign = alignment.yAlign;
  7313. var paddingAndSize = caretSize + caretPadding;
  7314. var radiusAndPadding = cornerRadius + caretPadding;
  7315. if (xAlign === 'right') {
  7316. x -= size.width;
  7317. } else if (xAlign === 'center') {
  7318. x -= (size.width / 2);
  7319. if (x + size.width > chart.width) {
  7320. x = chart.width - size.width;
  7321. }
  7322. if (x < 0) {
  7323. x = 0;
  7324. }
  7325. }
  7326. if (yAlign === 'top') {
  7327. y += paddingAndSize;
  7328. } else if (yAlign === 'bottom') {
  7329. y -= size.height + paddingAndSize;
  7330. } else {
  7331. y -= (size.height / 2);
  7332. }
  7333. if (yAlign === 'center') {
  7334. if (xAlign === 'left') {
  7335. x += paddingAndSize;
  7336. } else if (xAlign === 'right') {
  7337. x -= paddingAndSize;
  7338. }
  7339. } else if (xAlign === 'left') {
  7340. x -= radiusAndPadding;
  7341. } else if (xAlign === 'right') {
  7342. x += radiusAndPadding;
  7343. }
  7344. return {
  7345. x: x,
  7346. y: y
  7347. };
  7348. }
  7349. /**
  7350. * Helper to build before and after body lines
  7351. */
  7352. function getBeforeAfterBodyLines(callback) {
  7353. return pushOrConcat([], splitNewlines(callback));
  7354. }
  7355. var exports = module.exports = Element.extend({
  7356. initialize: function() {
  7357. this._model = getBaseModel(this._options);
  7358. this._lastActive = [];
  7359. },
  7360. // Get the title
  7361. // Args are: (tooltipItem, data)
  7362. getTitle: function() {
  7363. var me = this;
  7364. var opts = me._options;
  7365. var callbacks = opts.callbacks;
  7366. var beforeTitle = callbacks.beforeTitle.apply(me, arguments);
  7367. var title = callbacks.title.apply(me, arguments);
  7368. var afterTitle = callbacks.afterTitle.apply(me, arguments);
  7369. var lines = [];
  7370. lines = pushOrConcat(lines, splitNewlines(beforeTitle));
  7371. lines = pushOrConcat(lines, splitNewlines(title));
  7372. lines = pushOrConcat(lines, splitNewlines(afterTitle));
  7373. return lines;
  7374. },
  7375. // Args are: (tooltipItem, data)
  7376. getBeforeBody: function() {
  7377. return getBeforeAfterBodyLines(this._options.callbacks.beforeBody.apply(this, arguments));
  7378. },
  7379. // Args are: (tooltipItem, data)
  7380. getBody: function(tooltipItems, data) {
  7381. var me = this;
  7382. var callbacks = me._options.callbacks;
  7383. var bodyItems = [];
  7384. helpers.each(tooltipItems, function(tooltipItem) {
  7385. var bodyItem = {
  7386. before: [],
  7387. lines: [],
  7388. after: []
  7389. };
  7390. pushOrConcat(bodyItem.before, splitNewlines(callbacks.beforeLabel.call(me, tooltipItem, data)));
  7391. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  7392. pushOrConcat(bodyItem.after, splitNewlines(callbacks.afterLabel.call(me, tooltipItem, data)));
  7393. bodyItems.push(bodyItem);
  7394. });
  7395. return bodyItems;
  7396. },
  7397. // Args are: (tooltipItem, data)
  7398. getAfterBody: function() {
  7399. return getBeforeAfterBodyLines(this._options.callbacks.afterBody.apply(this, arguments));
  7400. },
  7401. // Get the footer and beforeFooter and afterFooter lines
  7402. // Args are: (tooltipItem, data)
  7403. getFooter: function() {
  7404. var me = this;
  7405. var callbacks = me._options.callbacks;
  7406. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  7407. var footer = callbacks.footer.apply(me, arguments);
  7408. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  7409. var lines = [];
  7410. lines = pushOrConcat(lines, splitNewlines(beforeFooter));
  7411. lines = pushOrConcat(lines, splitNewlines(footer));
  7412. lines = pushOrConcat(lines, splitNewlines(afterFooter));
  7413. return lines;
  7414. },
  7415. update: function(changed) {
  7416. var me = this;
  7417. var opts = me._options;
  7418. // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
  7419. // that does _view = _model if ease === 1. This causes the 2nd tooltip update to set properties in both the view and model at the same time
  7420. // which breaks any animations.
  7421. var existingModel = me._model;
  7422. var model = me._model = getBaseModel(opts);
  7423. var active = me._active;
  7424. var data = me._data;
  7425. // In the case where active.length === 0 we need to keep these at existing values for good animations
  7426. var alignment = {
  7427. xAlign: existingModel.xAlign,
  7428. yAlign: existingModel.yAlign
  7429. };
  7430. var backgroundPoint = {
  7431. x: existingModel.x,
  7432. y: existingModel.y
  7433. };
  7434. var tooltipSize = {
  7435. width: existingModel.width,
  7436. height: existingModel.height
  7437. };
  7438. var tooltipPosition = {
  7439. x: existingModel.caretX,
  7440. y: existingModel.caretY
  7441. };
  7442. var i, len;
  7443. if (active.length) {
  7444. model.opacity = 1;
  7445. var labelColors = [];
  7446. var labelTextColors = [];
  7447. tooltipPosition = positioners[opts.position].call(me, active, me._eventPosition);
  7448. var tooltipItems = [];
  7449. for (i = 0, len = active.length; i < len; ++i) {
  7450. tooltipItems.push(createTooltipItem(active[i]));
  7451. }
  7452. // If the user provided a filter function, use it to modify the tooltip items
  7453. if (opts.filter) {
  7454. tooltipItems = tooltipItems.filter(function(a) {
  7455. return opts.filter(a, data);
  7456. });
  7457. }
  7458. // If the user provided a sorting function, use it to modify the tooltip items
  7459. if (opts.itemSort) {
  7460. tooltipItems = tooltipItems.sort(function(a, b) {
  7461. return opts.itemSort(a, b, data);
  7462. });
  7463. }
  7464. // Determine colors for boxes
  7465. helpers.each(tooltipItems, function(tooltipItem) {
  7466. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart));
  7467. labelTextColors.push(opts.callbacks.labelTextColor.call(me, tooltipItem, me._chart));
  7468. });
  7469. // Build the Text Lines
  7470. model.title = me.getTitle(tooltipItems, data);
  7471. model.beforeBody = me.getBeforeBody(tooltipItems, data);
  7472. model.body = me.getBody(tooltipItems, data);
  7473. model.afterBody = me.getAfterBody(tooltipItems, data);
  7474. model.footer = me.getFooter(tooltipItems, data);
  7475. // Initial positioning and colors
  7476. model.x = Math.round(tooltipPosition.x);
  7477. model.y = Math.round(tooltipPosition.y);
  7478. model.caretPadding = opts.caretPadding;
  7479. model.labelColors = labelColors;
  7480. model.labelTextColors = labelTextColors;
  7481. // data points
  7482. model.dataPoints = tooltipItems;
  7483. // We need to determine alignment of the tooltip
  7484. tooltipSize = getTooltipSize(this, model);
  7485. alignment = determineAlignment(this, tooltipSize);
  7486. // Final Size and Position
  7487. backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
  7488. } else {
  7489. model.opacity = 0;
  7490. }
  7491. model.xAlign = alignment.xAlign;
  7492. model.yAlign = alignment.yAlign;
  7493. model.x = backgroundPoint.x;
  7494. model.y = backgroundPoint.y;
  7495. model.width = tooltipSize.width;
  7496. model.height = tooltipSize.height;
  7497. // Point where the caret on the tooltip points to
  7498. model.caretX = tooltipPosition.x;
  7499. model.caretY = tooltipPosition.y;
  7500. me._model = model;
  7501. if (changed && opts.custom) {
  7502. opts.custom.call(me, model);
  7503. }
  7504. return me;
  7505. },
  7506. drawCaret: function(tooltipPoint, size) {
  7507. var ctx = this._chart.ctx;
  7508. var vm = this._view;
  7509. var caretPosition = this.getCaretPosition(tooltipPoint, size, vm);
  7510. ctx.lineTo(caretPosition.x1, caretPosition.y1);
  7511. ctx.lineTo(caretPosition.x2, caretPosition.y2);
  7512. ctx.lineTo(caretPosition.x3, caretPosition.y3);
  7513. },
  7514. getCaretPosition: function(tooltipPoint, size, vm) {
  7515. var x1, x2, x3, y1, y2, y3;
  7516. var caretSize = vm.caretSize;
  7517. var cornerRadius = vm.cornerRadius;
  7518. var xAlign = vm.xAlign;
  7519. var yAlign = vm.yAlign;
  7520. var ptX = tooltipPoint.x;
  7521. var ptY = tooltipPoint.y;
  7522. var width = size.width;
  7523. var height = size.height;
  7524. if (yAlign === 'center') {
  7525. y2 = ptY + (height / 2);
  7526. if (xAlign === 'left') {
  7527. x1 = ptX;
  7528. x2 = x1 - caretSize;
  7529. x3 = x1;
  7530. y1 = y2 + caretSize;
  7531. y3 = y2 - caretSize;
  7532. } else {
  7533. x1 = ptX + width;
  7534. x2 = x1 + caretSize;
  7535. x3 = x1;
  7536. y1 = y2 - caretSize;
  7537. y3 = y2 + caretSize;
  7538. }
  7539. } else {
  7540. if (xAlign === 'left') {
  7541. x2 = ptX + cornerRadius + (caretSize);
  7542. x1 = x2 - caretSize;
  7543. x3 = x2 + caretSize;
  7544. } else if (xAlign === 'right') {
  7545. x2 = ptX + width - cornerRadius - caretSize;
  7546. x1 = x2 - caretSize;
  7547. x3 = x2 + caretSize;
  7548. } else {
  7549. x2 = vm.caretX;
  7550. x1 = x2 - caretSize;
  7551. x3 = x2 + caretSize;
  7552. }
  7553. if (yAlign === 'top') {
  7554. y1 = ptY;
  7555. y2 = y1 - caretSize;
  7556. y3 = y1;
  7557. } else {
  7558. y1 = ptY + height;
  7559. y2 = y1 + caretSize;
  7560. y3 = y1;
  7561. // invert drawing order
  7562. var tmp = x3;
  7563. x3 = x1;
  7564. x1 = tmp;
  7565. }
  7566. }
  7567. return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3};
  7568. },
  7569. drawTitle: function(pt, vm, ctx, opacity) {
  7570. var title = vm.title;
  7571. if (title.length) {
  7572. ctx.textAlign = vm._titleAlign;
  7573. ctx.textBaseline = 'top';
  7574. var titleFontSize = vm.titleFontSize;
  7575. var titleSpacing = vm.titleSpacing;
  7576. ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
  7577. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7578. var i, len;
  7579. for (i = 0, len = title.length; i < len; ++i) {
  7580. ctx.fillText(title[i], pt.x, pt.y);
  7581. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  7582. if (i + 1 === title.length) {
  7583. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  7584. }
  7585. }
  7586. }
  7587. },
  7588. drawBody: function(pt, vm, ctx, opacity) {
  7589. var bodyFontSize = vm.bodyFontSize;
  7590. var bodySpacing = vm.bodySpacing;
  7591. var body = vm.body;
  7592. ctx.textAlign = vm._bodyAlign;
  7593. ctx.textBaseline = 'top';
  7594. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7595. // Before Body
  7596. var xLinePadding = 0;
  7597. var fillLineOfText = function(line) {
  7598. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  7599. pt.y += bodyFontSize + bodySpacing;
  7600. };
  7601. // Before body lines
  7602. ctx.fillStyle = mergeOpacity(vm.bodyFontColor, opacity);
  7603. helpers.each(vm.beforeBody, fillLineOfText);
  7604. var drawColorBoxes = vm.displayColors;
  7605. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  7606. // Draw body lines now
  7607. helpers.each(body, function(bodyItem, i) {
  7608. var textColor = mergeOpacity(vm.labelTextColors[i], opacity);
  7609. ctx.fillStyle = textColor;
  7610. helpers.each(bodyItem.before, fillLineOfText);
  7611. helpers.each(bodyItem.lines, function(line) {
  7612. // Draw Legend-like boxes if needed
  7613. if (drawColorBoxes) {
  7614. // Fill a white rect so that colours merge nicely if the opacity is < 1
  7615. ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
  7616. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7617. // Border
  7618. ctx.lineWidth = 1;
  7619. ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
  7620. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7621. // Inner square
  7622. ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
  7623. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  7624. ctx.fillStyle = textColor;
  7625. }
  7626. fillLineOfText(line);
  7627. });
  7628. helpers.each(bodyItem.after, fillLineOfText);
  7629. });
  7630. // Reset back to 0 for after body
  7631. xLinePadding = 0;
  7632. // After body lines
  7633. helpers.each(vm.afterBody, fillLineOfText);
  7634. pt.y -= bodySpacing; // Remove last body spacing
  7635. },
  7636. drawFooter: function(pt, vm, ctx, opacity) {
  7637. var footer = vm.footer;
  7638. if (footer.length) {
  7639. pt.y += vm.footerMarginTop;
  7640. ctx.textAlign = vm._footerAlign;
  7641. ctx.textBaseline = 'top';
  7642. ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
  7643. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7644. helpers.each(footer, function(line) {
  7645. ctx.fillText(line, pt.x, pt.y);
  7646. pt.y += vm.footerFontSize + vm.footerSpacing;
  7647. });
  7648. }
  7649. },
  7650. drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
  7651. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  7652. ctx.strokeStyle = mergeOpacity(vm.borderColor, opacity);
  7653. ctx.lineWidth = vm.borderWidth;
  7654. var xAlign = vm.xAlign;
  7655. var yAlign = vm.yAlign;
  7656. var x = pt.x;
  7657. var y = pt.y;
  7658. var width = tooltipSize.width;
  7659. var height = tooltipSize.height;
  7660. var radius = vm.cornerRadius;
  7661. ctx.beginPath();
  7662. ctx.moveTo(x + radius, y);
  7663. if (yAlign === 'top') {
  7664. this.drawCaret(pt, tooltipSize);
  7665. }
  7666. ctx.lineTo(x + width - radius, y);
  7667. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  7668. if (yAlign === 'center' && xAlign === 'right') {
  7669. this.drawCaret(pt, tooltipSize);
  7670. }
  7671. ctx.lineTo(x + width, y + height - radius);
  7672. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  7673. if (yAlign === 'bottom') {
  7674. this.drawCaret(pt, tooltipSize);
  7675. }
  7676. ctx.lineTo(x + radius, y + height);
  7677. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  7678. if (yAlign === 'center' && xAlign === 'left') {
  7679. this.drawCaret(pt, tooltipSize);
  7680. }
  7681. ctx.lineTo(x, y + radius);
  7682. ctx.quadraticCurveTo(x, y, x + radius, y);
  7683. ctx.closePath();
  7684. ctx.fill();
  7685. if (vm.borderWidth > 0) {
  7686. ctx.stroke();
  7687. }
  7688. },
  7689. draw: function() {
  7690. var ctx = this._chart.ctx;
  7691. var vm = this._view;
  7692. if (vm.opacity === 0) {
  7693. return;
  7694. }
  7695. var tooltipSize = {
  7696. width: vm.width,
  7697. height: vm.height
  7698. };
  7699. var pt = {
  7700. x: vm.x,
  7701. y: vm.y
  7702. };
  7703. // IE11/Edge does not like very small opacities, so snap to 0
  7704. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  7705. // Truthy/falsey value for empty tooltip
  7706. var hasTooltipContent = vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length;
  7707. if (this._options.enabled && hasTooltipContent) {
  7708. // Draw Background
  7709. this.drawBackground(pt, vm, ctx, tooltipSize, opacity);
  7710. // Draw Title, Body, and Footer
  7711. pt.x += vm.xPadding;
  7712. pt.y += vm.yPadding;
  7713. // Titles
  7714. this.drawTitle(pt, vm, ctx, opacity);
  7715. // Body
  7716. this.drawBody(pt, vm, ctx, opacity);
  7717. // Footer
  7718. this.drawFooter(pt, vm, ctx, opacity);
  7719. }
  7720. },
  7721. /**
  7722. * Handle an event
  7723. * @private
  7724. * @param {IEvent} event - The event to handle
  7725. * @returns {Boolean} true if the tooltip changed
  7726. */
  7727. handleEvent: function(e) {
  7728. var me = this;
  7729. var options = me._options;
  7730. var changed = false;
  7731. me._lastActive = me._lastActive || [];
  7732. // Find Active Elements for tooltips
  7733. if (e.type === 'mouseout') {
  7734. me._active = [];
  7735. } else {
  7736. me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
  7737. }
  7738. // Remember Last Actives
  7739. changed = !helpers.arrayEquals(me._active, me._lastActive);
  7740. // Only handle target event on tooltip change
  7741. if (changed) {
  7742. me._lastActive = me._active;
  7743. if (options.enabled || options.custom) {
  7744. me._eventPosition = {
  7745. x: e.x,
  7746. y: e.y
  7747. };
  7748. me.update(true);
  7749. me.pivot();
  7750. }
  7751. }
  7752. return changed;
  7753. }
  7754. });
  7755. /**
  7756. * @namespace Chart.Tooltip.positioners
  7757. */
  7758. exports.positioners = positioners;
  7759. },{"26":26,"27":27,"46":46}],37:[function(require,module,exports){
  7760. 'use strict';
  7761. var defaults = require(26);
  7762. var Element = require(27);
  7763. var helpers = require(46);
  7764. defaults._set('global', {
  7765. elements: {
  7766. arc: {
  7767. backgroundColor: defaults.global.defaultColor,
  7768. borderColor: '#fff',
  7769. borderWidth: 2
  7770. }
  7771. }
  7772. });
  7773. module.exports = Element.extend({
  7774. inLabelRange: function(mouseX) {
  7775. var vm = this._view;
  7776. if (vm) {
  7777. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  7778. }
  7779. return false;
  7780. },
  7781. inRange: function(chartX, chartY) {
  7782. var vm = this._view;
  7783. if (vm) {
  7784. var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
  7785. var angle = pointRelativePosition.angle;
  7786. var distance = pointRelativePosition.distance;
  7787. // Sanitise angle range
  7788. var startAngle = vm.startAngle;
  7789. var endAngle = vm.endAngle;
  7790. while (endAngle < startAngle) {
  7791. endAngle += 2.0 * Math.PI;
  7792. }
  7793. while (angle > endAngle) {
  7794. angle -= 2.0 * Math.PI;
  7795. }
  7796. while (angle < startAngle) {
  7797. angle += 2.0 * Math.PI;
  7798. }
  7799. // Check if within the range of the open/close angle
  7800. var betweenAngles = (angle >= startAngle && angle <= endAngle);
  7801. var withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  7802. return (betweenAngles && withinRadius);
  7803. }
  7804. return false;
  7805. },
  7806. getCenterPoint: function() {
  7807. var vm = this._view;
  7808. var halfAngle = (vm.startAngle + vm.endAngle) / 2;
  7809. var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
  7810. return {
  7811. x: vm.x + Math.cos(halfAngle) * halfRadius,
  7812. y: vm.y + Math.sin(halfAngle) * halfRadius
  7813. };
  7814. },
  7815. getArea: function() {
  7816. var vm = this._view;
  7817. return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
  7818. },
  7819. tooltipPosition: function() {
  7820. var vm = this._view;
  7821. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
  7822. var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  7823. return {
  7824. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  7825. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  7826. };
  7827. },
  7828. draw: function() {
  7829. var ctx = this._chart.ctx;
  7830. var vm = this._view;
  7831. var sA = vm.startAngle;
  7832. var eA = vm.endAngle;
  7833. ctx.beginPath();
  7834. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  7835. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  7836. ctx.closePath();
  7837. ctx.strokeStyle = vm.borderColor;
  7838. ctx.lineWidth = vm.borderWidth;
  7839. ctx.fillStyle = vm.backgroundColor;
  7840. ctx.fill();
  7841. ctx.lineJoin = 'bevel';
  7842. if (vm.borderWidth) {
  7843. ctx.stroke();
  7844. }
  7845. }
  7846. });
  7847. },{"26":26,"27":27,"46":46}],38:[function(require,module,exports){
  7848. 'use strict';
  7849. var defaults = require(26);
  7850. var Element = require(27);
  7851. var helpers = require(46);
  7852. var globalDefaults = defaults.global;
  7853. defaults._set('global', {
  7854. elements: {
  7855. line: {
  7856. tension: 0.4,
  7857. backgroundColor: globalDefaults.defaultColor,
  7858. borderWidth: 3,
  7859. borderColor: globalDefaults.defaultColor,
  7860. borderCapStyle: 'butt',
  7861. borderDash: [],
  7862. borderDashOffset: 0.0,
  7863. borderJoinStyle: 'miter',
  7864. capBezierPoints: true,
  7865. fill: true, // do we fill in the area between the line and its base axis
  7866. }
  7867. }
  7868. });
  7869. module.exports = Element.extend({
  7870. draw: function() {
  7871. var me = this;
  7872. var vm = me._view;
  7873. var ctx = me._chart.ctx;
  7874. var spanGaps = vm.spanGaps;
  7875. var points = me._children.slice(); // clone array
  7876. var globalOptionLineElements = globalDefaults.elements.line;
  7877. var lastDrawnIndex = -1;
  7878. var index, current, previous, currentVM;
  7879. // If we are looping, adding the first point again
  7880. if (me._loop && points.length) {
  7881. points.push(points[0]);
  7882. }
  7883. ctx.save();
  7884. // Stroke Line Options
  7885. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  7886. // IE 9 and 10 do not support line dash
  7887. if (ctx.setLineDash) {
  7888. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  7889. }
  7890. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  7891. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  7892. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  7893. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  7894. // Stroke Line
  7895. ctx.beginPath();
  7896. lastDrawnIndex = -1;
  7897. for (index = 0; index < points.length; ++index) {
  7898. current = points[index];
  7899. previous = helpers.previousItem(points, index);
  7900. currentVM = current._view;
  7901. // First point moves to it's starting position no matter what
  7902. if (index === 0) {
  7903. if (!currentVM.skip) {
  7904. ctx.moveTo(currentVM.x, currentVM.y);
  7905. lastDrawnIndex = index;
  7906. }
  7907. } else {
  7908. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7909. if (!currentVM.skip) {
  7910. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  7911. // There was a gap and this is the first point after the gap
  7912. ctx.moveTo(currentVM.x, currentVM.y);
  7913. } else {
  7914. // Line to next point
  7915. helpers.canvas.lineTo(ctx, previous._view, current._view);
  7916. }
  7917. lastDrawnIndex = index;
  7918. }
  7919. }
  7920. }
  7921. ctx.stroke();
  7922. ctx.restore();
  7923. }
  7924. });
  7925. },{"26":26,"27":27,"46":46}],39:[function(require,module,exports){
  7926. 'use strict';
  7927. var defaults = require(26);
  7928. var Element = require(27);
  7929. var helpers = require(46);
  7930. var defaultColor = defaults.global.defaultColor;
  7931. defaults._set('global', {
  7932. elements: {
  7933. point: {
  7934. radius: 3,
  7935. pointStyle: 'circle',
  7936. backgroundColor: defaultColor,
  7937. borderColor: defaultColor,
  7938. borderWidth: 1,
  7939. // Hover
  7940. hitRadius: 1,
  7941. hoverRadius: 4,
  7942. hoverBorderWidth: 1
  7943. }
  7944. }
  7945. });
  7946. function xRange(mouseX) {
  7947. var vm = this._view;
  7948. return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
  7949. }
  7950. function yRange(mouseY) {
  7951. var vm = this._view;
  7952. return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false;
  7953. }
  7954. module.exports = Element.extend({
  7955. inRange: function(mouseX, mouseY) {
  7956. var vm = this._view;
  7957. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  7958. },
  7959. inLabelRange: xRange,
  7960. inXRange: xRange,
  7961. inYRange: yRange,
  7962. getCenterPoint: function() {
  7963. var vm = this._view;
  7964. return {
  7965. x: vm.x,
  7966. y: vm.y
  7967. };
  7968. },
  7969. getArea: function() {
  7970. return Math.PI * Math.pow(this._view.radius, 2);
  7971. },
  7972. tooltipPosition: function() {
  7973. var vm = this._view;
  7974. return {
  7975. x: vm.x,
  7976. y: vm.y,
  7977. padding: vm.radius + vm.borderWidth
  7978. };
  7979. },
  7980. draw: function(chartArea) {
  7981. var vm = this._view;
  7982. var model = this._model;
  7983. var ctx = this._chart.ctx;
  7984. var pointStyle = vm.pointStyle;
  7985. var rotation = vm.rotation;
  7986. var radius = vm.radius;
  7987. var x = vm.x;
  7988. var y = vm.y;
  7989. var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)
  7990. if (vm.skip) {
  7991. return;
  7992. }
  7993. // Clipping for Points.
  7994. if (chartArea === undefined || (model.x >= chartArea.left && chartArea.right * errMargin >= model.x && model.y >= chartArea.top && chartArea.bottom * errMargin >= model.y)) {
  7995. ctx.strokeStyle = vm.borderColor || defaultColor;
  7996. ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
  7997. ctx.fillStyle = vm.backgroundColor || defaultColor;
  7998. helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y, rotation);
  7999. }
  8000. }
  8001. });
  8002. },{"26":26,"27":27,"46":46}],40:[function(require,module,exports){
  8003. 'use strict';
  8004. var defaults = require(26);
  8005. var Element = require(27);
  8006. defaults._set('global', {
  8007. elements: {
  8008. rectangle: {
  8009. backgroundColor: defaults.global.defaultColor,
  8010. borderColor: defaults.global.defaultColor,
  8011. borderSkipped: 'bottom',
  8012. borderWidth: 0
  8013. }
  8014. }
  8015. });
  8016. function isVertical(bar) {
  8017. return bar._view.width !== undefined;
  8018. }
  8019. /**
  8020. * Helper function to get the bounds of the bar regardless of the orientation
  8021. * @param bar {Chart.Element.Rectangle} the bar
  8022. * @return {Bounds} bounds of the bar
  8023. * @private
  8024. */
  8025. function getBarBounds(bar) {
  8026. var vm = bar._view;
  8027. var x1, x2, y1, y2;
  8028. if (isVertical(bar)) {
  8029. // vertical
  8030. var halfWidth = vm.width / 2;
  8031. x1 = vm.x - halfWidth;
  8032. x2 = vm.x + halfWidth;
  8033. y1 = Math.min(vm.y, vm.base);
  8034. y2 = Math.max(vm.y, vm.base);
  8035. } else {
  8036. // horizontal bar
  8037. var halfHeight = vm.height / 2;
  8038. x1 = Math.min(vm.x, vm.base);
  8039. x2 = Math.max(vm.x, vm.base);
  8040. y1 = vm.y - halfHeight;
  8041. y2 = vm.y + halfHeight;
  8042. }
  8043. return {
  8044. left: x1,
  8045. top: y1,
  8046. right: x2,
  8047. bottom: y2
  8048. };
  8049. }
  8050. module.exports = Element.extend({
  8051. draw: function() {
  8052. var ctx = this._chart.ctx;
  8053. var vm = this._view;
  8054. var left, right, top, bottom, signX, signY, borderSkipped;
  8055. var borderWidth = vm.borderWidth;
  8056. if (!vm.horizontal) {
  8057. // bar
  8058. left = vm.x - vm.width / 2;
  8059. right = vm.x + vm.width / 2;
  8060. top = vm.y;
  8061. bottom = vm.base;
  8062. signX = 1;
  8063. signY = bottom > top ? 1 : -1;
  8064. borderSkipped = vm.borderSkipped || 'bottom';
  8065. } else {
  8066. // horizontal bar
  8067. left = vm.base;
  8068. right = vm.x;
  8069. top = vm.y - vm.height / 2;
  8070. bottom = vm.y + vm.height / 2;
  8071. signX = right > left ? 1 : -1;
  8072. signY = 1;
  8073. borderSkipped = vm.borderSkipped || 'left';
  8074. }
  8075. // Canvas doesn't allow us to stroke inside the width so we can
  8076. // adjust the sizes to fit if we're setting a stroke on the line
  8077. if (borderWidth) {
  8078. // borderWidth shold be less than bar width and bar height.
  8079. var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
  8080. borderWidth = borderWidth > barSize ? barSize : borderWidth;
  8081. var halfStroke = borderWidth / 2;
  8082. // Adjust borderWidth when bar top position is near vm.base(zero).
  8083. var borderLeft = left + (borderSkipped !== 'left' ? halfStroke * signX : 0);
  8084. var borderRight = right + (borderSkipped !== 'right' ? -halfStroke * signX : 0);
  8085. var borderTop = top + (borderSkipped !== 'top' ? halfStroke * signY : 0);
  8086. var borderBottom = bottom + (borderSkipped !== 'bottom' ? -halfStroke * signY : 0);
  8087. // not become a vertical line?
  8088. if (borderLeft !== borderRight) {
  8089. top = borderTop;
  8090. bottom = borderBottom;
  8091. }
  8092. // not become a horizontal line?
  8093. if (borderTop !== borderBottom) {
  8094. left = borderLeft;
  8095. right = borderRight;
  8096. }
  8097. }
  8098. ctx.beginPath();
  8099. ctx.fillStyle = vm.backgroundColor;
  8100. ctx.strokeStyle = vm.borderColor;
  8101. ctx.lineWidth = borderWidth;
  8102. // Corner points, from bottom-left to bottom-right clockwise
  8103. // | 1 2 |
  8104. // | 0 3 |
  8105. var corners = [
  8106. [left, bottom],
  8107. [left, top],
  8108. [right, top],
  8109. [right, bottom]
  8110. ];
  8111. // Find first (starting) corner with fallback to 'bottom'
  8112. var borders = ['bottom', 'left', 'top', 'right'];
  8113. var startCorner = borders.indexOf(borderSkipped, 0);
  8114. if (startCorner === -1) {
  8115. startCorner = 0;
  8116. }
  8117. function cornerAt(index) {
  8118. return corners[(startCorner + index) % 4];
  8119. }
  8120. // Draw rectangle from 'startCorner'
  8121. var corner = cornerAt(0);
  8122. ctx.moveTo(corner[0], corner[1]);
  8123. for (var i = 1; i < 4; i++) {
  8124. corner = cornerAt(i);
  8125. ctx.lineTo(corner[0], corner[1]);
  8126. }
  8127. ctx.fill();
  8128. if (borderWidth) {
  8129. ctx.stroke();
  8130. }
  8131. },
  8132. height: function() {
  8133. var vm = this._view;
  8134. return vm.base - vm.y;
  8135. },
  8136. inRange: function(mouseX, mouseY) {
  8137. var inRange = false;
  8138. if (this._view) {
  8139. var bounds = getBarBounds(this);
  8140. inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
  8141. }
  8142. return inRange;
  8143. },
  8144. inLabelRange: function(mouseX, mouseY) {
  8145. var me = this;
  8146. if (!me._view) {
  8147. return false;
  8148. }
  8149. var inRange = false;
  8150. var bounds = getBarBounds(me);
  8151. if (isVertical(me)) {
  8152. inRange = mouseX >= bounds.left && mouseX <= bounds.right;
  8153. } else {
  8154. inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
  8155. }
  8156. return inRange;
  8157. },
  8158. inXRange: function(mouseX) {
  8159. var bounds = getBarBounds(this);
  8160. return mouseX >= bounds.left && mouseX <= bounds.right;
  8161. },
  8162. inYRange: function(mouseY) {
  8163. var bounds = getBarBounds(this);
  8164. return mouseY >= bounds.top && mouseY <= bounds.bottom;
  8165. },
  8166. getCenterPoint: function() {
  8167. var vm = this._view;
  8168. var x, y;
  8169. if (isVertical(this)) {
  8170. x = vm.x;
  8171. y = (vm.y + vm.base) / 2;
  8172. } else {
  8173. x = (vm.x + vm.base) / 2;
  8174. y = vm.y;
  8175. }
  8176. return {x: x, y: y};
  8177. },
  8178. getArea: function() {
  8179. var vm = this._view;
  8180. return vm.width * Math.abs(vm.y - vm.base);
  8181. },
  8182. tooltipPosition: function() {
  8183. var vm = this._view;
  8184. return {
  8185. x: vm.x,
  8186. y: vm.y
  8187. };
  8188. }
  8189. });
  8190. },{"26":26,"27":27}],41:[function(require,module,exports){
  8191. 'use strict';
  8192. module.exports = {};
  8193. module.exports.Arc = require(37);
  8194. module.exports.Line = require(38);
  8195. module.exports.Point = require(39);
  8196. module.exports.Rectangle = require(40);
  8197. },{"37":37,"38":38,"39":39,"40":40}],42:[function(require,module,exports){
  8198. 'use strict';
  8199. var helpers = require(43);
  8200. /**
  8201. * @namespace Chart.helpers.canvas
  8202. */
  8203. var exports = module.exports = {
  8204. /**
  8205. * Clears the entire canvas associated to the given `chart`.
  8206. * @param {Chart} chart - The chart for which to clear the canvas.
  8207. */
  8208. clear: function(chart) {
  8209. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  8210. },
  8211. /**
  8212. * Creates a "path" for a rectangle with rounded corners at position (x, y) with a
  8213. * given size (width, height) and the same `radius` for all corners.
  8214. * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context.
  8215. * @param {Number} x - The x axis of the coordinate for the rectangle starting point.
  8216. * @param {Number} y - The y axis of the coordinate for the rectangle starting point.
  8217. * @param {Number} width - The rectangle's width.
  8218. * @param {Number} height - The rectangle's height.
  8219. * @param {Number} radius - The rounded amount (in pixels) for the four corners.
  8220. * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
  8221. */
  8222. roundedRect: function(ctx, x, y, width, height, radius) {
  8223. if (radius) {
  8224. // NOTE(SB) `epsilon` helps to prevent minor artifacts appearing
  8225. // on Chrome when `r` is exactly half the height or the width.
  8226. var epsilon = 0.0000001;
  8227. var r = Math.min(radius, (height / 2) - epsilon, (width / 2) - epsilon);
  8228. ctx.moveTo(x + r, y);
  8229. ctx.lineTo(x + width - r, y);
  8230. ctx.arcTo(x + width, y, x + width, y + r, r);
  8231. ctx.lineTo(x + width, y + height - r);
  8232. ctx.arcTo(x + width, y + height, x + width - r, y + height, r);
  8233. ctx.lineTo(x + r, y + height);
  8234. ctx.arcTo(x, y + height, x, y + height - r, r);
  8235. ctx.lineTo(x, y + r);
  8236. ctx.arcTo(x, y, x + r, y, r);
  8237. ctx.closePath();
  8238. ctx.moveTo(x, y);
  8239. } else {
  8240. ctx.rect(x, y, width, height);
  8241. }
  8242. },
  8243. drawPoint: function(ctx, style, radius, x, y, rotation) {
  8244. var type, edgeLength, xOffset, yOffset, height, size;
  8245. rotation = rotation || 0;
  8246. if (style && typeof style === 'object') {
  8247. type = style.toString();
  8248. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  8249. ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
  8250. return;
  8251. }
  8252. }
  8253. if (isNaN(radius) || radius <= 0) {
  8254. return;
  8255. }
  8256. ctx.save();
  8257. ctx.translate(x, y);
  8258. ctx.rotate(rotation * Math.PI / 180);
  8259. ctx.beginPath();
  8260. switch (style) {
  8261. // Default includes circle
  8262. default:
  8263. ctx.arc(0, 0, radius, 0, Math.PI * 2);
  8264. ctx.closePath();
  8265. break;
  8266. case 'triangle':
  8267. edgeLength = 3 * radius / Math.sqrt(3);
  8268. height = edgeLength * Math.sqrt(3) / 2;
  8269. ctx.moveTo(-edgeLength / 2, height / 3);
  8270. ctx.lineTo(edgeLength / 2, height / 3);
  8271. ctx.lineTo(0, -2 * height / 3);
  8272. ctx.closePath();
  8273. break;
  8274. case 'rect':
  8275. size = 1 / Math.SQRT2 * radius;
  8276. ctx.rect(-size, -size, 2 * size, 2 * size);
  8277. break;
  8278. case 'rectRounded':
  8279. var offset = radius / Math.SQRT2;
  8280. var leftX = -offset;
  8281. var topY = -offset;
  8282. var sideSize = Math.SQRT2 * radius;
  8283. // NOTE(SB) the rounded rect implementation changed to use `arcTo`
  8284. // instead of `quadraticCurveTo` since it generates better results
  8285. // when rect is almost a circle. 0.425 (instead of 0.5) produces
  8286. // results visually closer to the previous impl.
  8287. this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius * 0.425);
  8288. break;
  8289. case 'rectRot':
  8290. size = 1 / Math.SQRT2 * radius;
  8291. ctx.moveTo(-size, 0);
  8292. ctx.lineTo(0, size);
  8293. ctx.lineTo(size, 0);
  8294. ctx.lineTo(0, -size);
  8295. ctx.closePath();
  8296. break;
  8297. case 'cross':
  8298. ctx.moveTo(0, radius);
  8299. ctx.lineTo(0, -radius);
  8300. ctx.moveTo(-radius, 0);
  8301. ctx.lineTo(radius, 0);
  8302. break;
  8303. case 'crossRot':
  8304. xOffset = Math.cos(Math.PI / 4) * radius;
  8305. yOffset = Math.sin(Math.PI / 4) * radius;
  8306. ctx.moveTo(-xOffset, -yOffset);
  8307. ctx.lineTo(xOffset, yOffset);
  8308. ctx.moveTo(-xOffset, yOffset);
  8309. ctx.lineTo(xOffset, -yOffset);
  8310. break;
  8311. case 'star':
  8312. ctx.moveTo(0, radius);
  8313. ctx.lineTo(0, -radius);
  8314. ctx.moveTo(-radius, 0);
  8315. ctx.lineTo(radius, 0);
  8316. xOffset = Math.cos(Math.PI / 4) * radius;
  8317. yOffset = Math.sin(Math.PI / 4) * radius;
  8318. ctx.moveTo(-xOffset, -yOffset);
  8319. ctx.lineTo(xOffset, yOffset);
  8320. ctx.moveTo(-xOffset, yOffset);
  8321. ctx.lineTo(xOffset, -yOffset);
  8322. break;
  8323. case 'line':
  8324. ctx.moveTo(-radius, 0);
  8325. ctx.lineTo(radius, 0);
  8326. break;
  8327. case 'dash':
  8328. ctx.moveTo(0, 0);
  8329. ctx.lineTo(radius, 0);
  8330. break;
  8331. }
  8332. ctx.fill();
  8333. ctx.stroke();
  8334. ctx.restore();
  8335. },
  8336. clipArea: function(ctx, area) {
  8337. ctx.save();
  8338. ctx.beginPath();
  8339. ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
  8340. ctx.clip();
  8341. },
  8342. unclipArea: function(ctx) {
  8343. ctx.restore();
  8344. },
  8345. lineTo: function(ctx, previous, target, flip) {
  8346. if (target.steppedLine) {
  8347. if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
  8348. ctx.lineTo(previous.x, target.y);
  8349. } else {
  8350. ctx.lineTo(target.x, previous.y);
  8351. }
  8352. ctx.lineTo(target.x, target.y);
  8353. return;
  8354. }
  8355. if (!target.tension) {
  8356. ctx.lineTo(target.x, target.y);
  8357. return;
  8358. }
  8359. ctx.bezierCurveTo(
  8360. flip ? previous.controlPointPreviousX : previous.controlPointNextX,
  8361. flip ? previous.controlPointPreviousY : previous.controlPointNextY,
  8362. flip ? target.controlPointNextX : target.controlPointPreviousX,
  8363. flip ? target.controlPointNextY : target.controlPointPreviousY,
  8364. target.x,
  8365. target.y);
  8366. }
  8367. };
  8368. // DEPRECATIONS
  8369. /**
  8370. * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
  8371. * @namespace Chart.helpers.clear
  8372. * @deprecated since version 2.7.0
  8373. * @todo remove at version 3
  8374. * @private
  8375. */
  8376. helpers.clear = exports.clear;
  8377. /**
  8378. * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
  8379. * @namespace Chart.helpers.drawRoundedRectangle
  8380. * @deprecated since version 2.7.0
  8381. * @todo remove at version 3
  8382. * @private
  8383. */
  8384. helpers.drawRoundedRectangle = function(ctx) {
  8385. ctx.beginPath();
  8386. exports.roundedRect.apply(exports, arguments);
  8387. };
  8388. },{"43":43}],43:[function(require,module,exports){
  8389. 'use strict';
  8390. /**
  8391. * @namespace Chart.helpers
  8392. */
  8393. var helpers = {
  8394. /**
  8395. * An empty function that can be used, for example, for optional callback.
  8396. */
  8397. noop: function() {},
  8398. /**
  8399. * Returns a unique id, sequentially generated from a global variable.
  8400. * @returns {Number}
  8401. * @function
  8402. */
  8403. uid: (function() {
  8404. var id = 0;
  8405. return function() {
  8406. return id++;
  8407. };
  8408. }()),
  8409. /**
  8410. * Returns true if `value` is neither null nor undefined, else returns false.
  8411. * @param {*} value - The value to test.
  8412. * @returns {Boolean}
  8413. * @since 2.7.0
  8414. */
  8415. isNullOrUndef: function(value) {
  8416. return value === null || typeof value === 'undefined';
  8417. },
  8418. /**
  8419. * Returns true if `value` is an array, else returns false.
  8420. * @param {*} value - The value to test.
  8421. * @returns {Boolean}
  8422. * @function
  8423. */
  8424. isArray: Array.isArray ? Array.isArray : function(value) {
  8425. return Object.prototype.toString.call(value) === '[object Array]';
  8426. },
  8427. /**
  8428. * Returns true if `value` is an object (excluding null), else returns false.
  8429. * @param {*} value - The value to test.
  8430. * @returns {Boolean}
  8431. * @since 2.7.0
  8432. */
  8433. isObject: function(value) {
  8434. return value !== null && Object.prototype.toString.call(value) === '[object Object]';
  8435. },
  8436. /**
  8437. * Returns `value` if defined, else returns `defaultValue`.
  8438. * @param {*} value - The value to return if defined.
  8439. * @param {*} defaultValue - The value to return if `value` is undefined.
  8440. * @returns {*}
  8441. */
  8442. valueOrDefault: function(value, defaultValue) {
  8443. return typeof value === 'undefined' ? defaultValue : value;
  8444. },
  8445. /**
  8446. * Returns value at the given `index` in array if defined, else returns `defaultValue`.
  8447. * @param {Array} value - The array to lookup for value at `index`.
  8448. * @param {Number} index - The index in `value` to lookup for value.
  8449. * @param {*} defaultValue - The value to return if `value[index]` is undefined.
  8450. * @returns {*}
  8451. */
  8452. valueAtIndexOrDefault: function(value, index, defaultValue) {
  8453. return helpers.valueOrDefault(helpers.isArray(value) ? value[index] : value, defaultValue);
  8454. },
  8455. /**
  8456. * Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
  8457. * value returned by `fn`. If `fn` is not a function, this method returns undefined.
  8458. * @param {Function} fn - The function to call.
  8459. * @param {Array|undefined|null} args - The arguments with which `fn` should be called.
  8460. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8461. * @returns {*}
  8462. */
  8463. callback: function(fn, args, thisArg) {
  8464. if (fn && typeof fn.call === 'function') {
  8465. return fn.apply(thisArg, args);
  8466. }
  8467. },
  8468. /**
  8469. * Note(SB) for performance sake, this method should only be used when loopable type
  8470. * is unknown or in none intensive code (not called often and small loopable). Else
  8471. * it's preferable to use a regular for() loop and save extra function calls.
  8472. * @param {Object|Array} loopable - The object or array to be iterated.
  8473. * @param {Function} fn - The function to call for each item.
  8474. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8475. * @param {Boolean} [reverse] - If true, iterates backward on the loopable.
  8476. */
  8477. each: function(loopable, fn, thisArg, reverse) {
  8478. var i, len, keys;
  8479. if (helpers.isArray(loopable)) {
  8480. len = loopable.length;
  8481. if (reverse) {
  8482. for (i = len - 1; i >= 0; i--) {
  8483. fn.call(thisArg, loopable[i], i);
  8484. }
  8485. } else {
  8486. for (i = 0; i < len; i++) {
  8487. fn.call(thisArg, loopable[i], i);
  8488. }
  8489. }
  8490. } else if (helpers.isObject(loopable)) {
  8491. keys = Object.keys(loopable);
  8492. len = keys.length;
  8493. for (i = 0; i < len; i++) {
  8494. fn.call(thisArg, loopable[keys[i]], keys[i]);
  8495. }
  8496. }
  8497. },
  8498. /**
  8499. * Returns true if the `a0` and `a1` arrays have the same content, else returns false.
  8500. * @see http://stackoverflow.com/a/14853974
  8501. * @param {Array} a0 - The array to compare
  8502. * @param {Array} a1 - The array to compare
  8503. * @returns {Boolean}
  8504. */
  8505. arrayEquals: function(a0, a1) {
  8506. var i, ilen, v0, v1;
  8507. if (!a0 || !a1 || a0.length !== a1.length) {
  8508. return false;
  8509. }
  8510. for (i = 0, ilen = a0.length; i < ilen; ++i) {
  8511. v0 = a0[i];
  8512. v1 = a1[i];
  8513. if (v0 instanceof Array && v1 instanceof Array) {
  8514. if (!helpers.arrayEquals(v0, v1)) {
  8515. return false;
  8516. }
  8517. } else if (v0 !== v1) {
  8518. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  8519. return false;
  8520. }
  8521. }
  8522. return true;
  8523. },
  8524. /**
  8525. * Returns a deep copy of `source` without keeping references on objects and arrays.
  8526. * @param {*} source - The value to clone.
  8527. * @returns {*}
  8528. */
  8529. clone: function(source) {
  8530. if (helpers.isArray(source)) {
  8531. return source.map(helpers.clone);
  8532. }
  8533. if (helpers.isObject(source)) {
  8534. var target = {};
  8535. var keys = Object.keys(source);
  8536. var klen = keys.length;
  8537. var k = 0;
  8538. for (; k < klen; ++k) {
  8539. target[keys[k]] = helpers.clone(source[keys[k]]);
  8540. }
  8541. return target;
  8542. }
  8543. return source;
  8544. },
  8545. /**
  8546. * The default merger when Chart.helpers.merge is called without merger option.
  8547. * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
  8548. * @private
  8549. */
  8550. _merger: function(key, target, source, options) {
  8551. var tval = target[key];
  8552. var sval = source[key];
  8553. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8554. helpers.merge(tval, sval, options);
  8555. } else {
  8556. target[key] = helpers.clone(sval);
  8557. }
  8558. },
  8559. /**
  8560. * Merges source[key] in target[key] only if target[key] is undefined.
  8561. * @private
  8562. */
  8563. _mergerIf: function(key, target, source) {
  8564. var tval = target[key];
  8565. var sval = source[key];
  8566. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8567. helpers.mergeIf(tval, sval);
  8568. } else if (!target.hasOwnProperty(key)) {
  8569. target[key] = helpers.clone(sval);
  8570. }
  8571. },
  8572. /**
  8573. * Recursively deep copies `source` properties into `target` with the given `options`.
  8574. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8575. * @param {Object} target - The target object in which all sources are merged into.
  8576. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8577. * @param {Object} [options] - Merging options:
  8578. * @param {Function} [options.merger] - The merge method (key, target, source, options)
  8579. * @returns {Object} The `target` object.
  8580. */
  8581. merge: function(target, source, options) {
  8582. var sources = helpers.isArray(source) ? source : [source];
  8583. var ilen = sources.length;
  8584. var merge, i, keys, klen, k;
  8585. if (!helpers.isObject(target)) {
  8586. return target;
  8587. }
  8588. options = options || {};
  8589. merge = options.merger || helpers._merger;
  8590. for (i = 0; i < ilen; ++i) {
  8591. source = sources[i];
  8592. if (!helpers.isObject(source)) {
  8593. continue;
  8594. }
  8595. keys = Object.keys(source);
  8596. for (k = 0, klen = keys.length; k < klen; ++k) {
  8597. merge(keys[k], target, source, options);
  8598. }
  8599. }
  8600. return target;
  8601. },
  8602. /**
  8603. * Recursively deep copies `source` properties into `target` *only* if not defined in target.
  8604. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8605. * @param {Object} target - The target object in which all sources are merged into.
  8606. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8607. * @returns {Object} The `target` object.
  8608. */
  8609. mergeIf: function(target, source) {
  8610. return helpers.merge(target, source, {merger: helpers._mergerIf});
  8611. },
  8612. /**
  8613. * Applies the contents of two or more objects together into the first object.
  8614. * @param {Object} target - The target object in which all objects are merged into.
  8615. * @param {Object} arg1 - Object containing additional properties to merge in target.
  8616. * @param {Object} argN - Additional objects containing properties to merge in target.
  8617. * @returns {Object} The `target` object.
  8618. */
  8619. extend: function(target) {
  8620. var setFn = function(value, key) {
  8621. target[key] = value;
  8622. };
  8623. for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
  8624. helpers.each(arguments[i], setFn);
  8625. }
  8626. return target;
  8627. },
  8628. /**
  8629. * Basic javascript inheritance based on the model created in Backbone.js
  8630. */
  8631. inherits: function(extensions) {
  8632. var me = this;
  8633. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
  8634. return me.apply(this, arguments);
  8635. };
  8636. var Surrogate = function() {
  8637. this.constructor = ChartElement;
  8638. };
  8639. Surrogate.prototype = me.prototype;
  8640. ChartElement.prototype = new Surrogate();
  8641. ChartElement.extend = helpers.inherits;
  8642. if (extensions) {
  8643. helpers.extend(ChartElement.prototype, extensions);
  8644. }
  8645. ChartElement.__super__ = me.prototype;
  8646. return ChartElement;
  8647. }
  8648. };
  8649. module.exports = helpers;
  8650. // DEPRECATIONS
  8651. /**
  8652. * Provided for backward compatibility, use Chart.helpers.callback instead.
  8653. * @function Chart.helpers.callCallback
  8654. * @deprecated since version 2.6.0
  8655. * @todo remove at version 3
  8656. * @private
  8657. */
  8658. helpers.callCallback = helpers.callback;
  8659. /**
  8660. * Provided for backward compatibility, use Array.prototype.indexOf instead.
  8661. * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
  8662. * @function Chart.helpers.indexOf
  8663. * @deprecated since version 2.7.0
  8664. * @todo remove at version 3
  8665. * @private
  8666. */
  8667. helpers.indexOf = function(array, item, fromIndex) {
  8668. return Array.prototype.indexOf.call(array, item, fromIndex);
  8669. };
  8670. /**
  8671. * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
  8672. * @function Chart.helpers.getValueOrDefault
  8673. * @deprecated since version 2.7.0
  8674. * @todo remove at version 3
  8675. * @private
  8676. */
  8677. helpers.getValueOrDefault = helpers.valueOrDefault;
  8678. /**
  8679. * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
  8680. * @function Chart.helpers.getValueAtIndexOrDefault
  8681. * @deprecated since version 2.7.0
  8682. * @todo remove at version 3
  8683. * @private
  8684. */
  8685. helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  8686. },{}],44:[function(require,module,exports){
  8687. 'use strict';
  8688. var helpers = require(43);
  8689. /**
  8690. * Easing functions adapted from Robert Penner's easing equations.
  8691. * @namespace Chart.helpers.easingEffects
  8692. * @see http://www.robertpenner.com/easing/
  8693. */
  8694. var effects = {
  8695. linear: function(t) {
  8696. return t;
  8697. },
  8698. easeInQuad: function(t) {
  8699. return t * t;
  8700. },
  8701. easeOutQuad: function(t) {
  8702. return -t * (t - 2);
  8703. },
  8704. easeInOutQuad: function(t) {
  8705. if ((t /= 0.5) < 1) {
  8706. return 0.5 * t * t;
  8707. }
  8708. return -0.5 * ((--t) * (t - 2) - 1);
  8709. },
  8710. easeInCubic: function(t) {
  8711. return t * t * t;
  8712. },
  8713. easeOutCubic: function(t) {
  8714. return (t = t - 1) * t * t + 1;
  8715. },
  8716. easeInOutCubic: function(t) {
  8717. if ((t /= 0.5) < 1) {
  8718. return 0.5 * t * t * t;
  8719. }
  8720. return 0.5 * ((t -= 2) * t * t + 2);
  8721. },
  8722. easeInQuart: function(t) {
  8723. return t * t * t * t;
  8724. },
  8725. easeOutQuart: function(t) {
  8726. return -((t = t - 1) * t * t * t - 1);
  8727. },
  8728. easeInOutQuart: function(t) {
  8729. if ((t /= 0.5) < 1) {
  8730. return 0.5 * t * t * t * t;
  8731. }
  8732. return -0.5 * ((t -= 2) * t * t * t - 2);
  8733. },
  8734. easeInQuint: function(t) {
  8735. return t * t * t * t * t;
  8736. },
  8737. easeOutQuint: function(t) {
  8738. return (t = t - 1) * t * t * t * t + 1;
  8739. },
  8740. easeInOutQuint: function(t) {
  8741. if ((t /= 0.5) < 1) {
  8742. return 0.5 * t * t * t * t * t;
  8743. }
  8744. return 0.5 * ((t -= 2) * t * t * t * t + 2);
  8745. },
  8746. easeInSine: function(t) {
  8747. return -Math.cos(t * (Math.PI / 2)) + 1;
  8748. },
  8749. easeOutSine: function(t) {
  8750. return Math.sin(t * (Math.PI / 2));
  8751. },
  8752. easeInOutSine: function(t) {
  8753. return -0.5 * (Math.cos(Math.PI * t) - 1);
  8754. },
  8755. easeInExpo: function(t) {
  8756. return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
  8757. },
  8758. easeOutExpo: function(t) {
  8759. return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
  8760. },
  8761. easeInOutExpo: function(t) {
  8762. if (t === 0) {
  8763. return 0;
  8764. }
  8765. if (t === 1) {
  8766. return 1;
  8767. }
  8768. if ((t /= 0.5) < 1) {
  8769. return 0.5 * Math.pow(2, 10 * (t - 1));
  8770. }
  8771. return 0.5 * (-Math.pow(2, -10 * --t) + 2);
  8772. },
  8773. easeInCirc: function(t) {
  8774. if (t >= 1) {
  8775. return t;
  8776. }
  8777. return -(Math.sqrt(1 - t * t) - 1);
  8778. },
  8779. easeOutCirc: function(t) {
  8780. return Math.sqrt(1 - (t = t - 1) * t);
  8781. },
  8782. easeInOutCirc: function(t) {
  8783. if ((t /= 0.5) < 1) {
  8784. return -0.5 * (Math.sqrt(1 - t * t) - 1);
  8785. }
  8786. return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  8787. },
  8788. easeInElastic: function(t) {
  8789. var s = 1.70158;
  8790. var p = 0;
  8791. var a = 1;
  8792. if (t === 0) {
  8793. return 0;
  8794. }
  8795. if (t === 1) {
  8796. return 1;
  8797. }
  8798. if (!p) {
  8799. p = 0.3;
  8800. }
  8801. if (a < 1) {
  8802. a = 1;
  8803. s = p / 4;
  8804. } else {
  8805. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8806. }
  8807. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  8808. },
  8809. easeOutElastic: function(t) {
  8810. var s = 1.70158;
  8811. var p = 0;
  8812. var a = 1;
  8813. if (t === 0) {
  8814. return 0;
  8815. }
  8816. if (t === 1) {
  8817. return 1;
  8818. }
  8819. if (!p) {
  8820. p = 0.3;
  8821. }
  8822. if (a < 1) {
  8823. a = 1;
  8824. s = p / 4;
  8825. } else {
  8826. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8827. }
  8828. return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
  8829. },
  8830. easeInOutElastic: function(t) {
  8831. var s = 1.70158;
  8832. var p = 0;
  8833. var a = 1;
  8834. if (t === 0) {
  8835. return 0;
  8836. }
  8837. if ((t /= 0.5) === 2) {
  8838. return 1;
  8839. }
  8840. if (!p) {
  8841. p = 0.45;
  8842. }
  8843. if (a < 1) {
  8844. a = 1;
  8845. s = p / 4;
  8846. } else {
  8847. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8848. }
  8849. if (t < 1) {
  8850. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  8851. }
  8852. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
  8853. },
  8854. easeInBack: function(t) {
  8855. var s = 1.70158;
  8856. return t * t * ((s + 1) * t - s);
  8857. },
  8858. easeOutBack: function(t) {
  8859. var s = 1.70158;
  8860. return (t = t - 1) * t * ((s + 1) * t + s) + 1;
  8861. },
  8862. easeInOutBack: function(t) {
  8863. var s = 1.70158;
  8864. if ((t /= 0.5) < 1) {
  8865. return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
  8866. }
  8867. return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  8868. },
  8869. easeInBounce: function(t) {
  8870. return 1 - effects.easeOutBounce(1 - t);
  8871. },
  8872. easeOutBounce: function(t) {
  8873. if (t < (1 / 2.75)) {
  8874. return 7.5625 * t * t;
  8875. }
  8876. if (t < (2 / 2.75)) {
  8877. return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
  8878. }
  8879. if (t < (2.5 / 2.75)) {
  8880. return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
  8881. }
  8882. return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
  8883. },
  8884. easeInOutBounce: function(t) {
  8885. if (t < 0.5) {
  8886. return effects.easeInBounce(t * 2) * 0.5;
  8887. }
  8888. return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
  8889. }
  8890. };
  8891. module.exports = {
  8892. effects: effects
  8893. };
  8894. // DEPRECATIONS
  8895. /**
  8896. * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
  8897. * @function Chart.helpers.easingEffects
  8898. * @deprecated since version 2.7.0
  8899. * @todo remove at version 3
  8900. * @private
  8901. */
  8902. helpers.easingEffects = effects;
  8903. },{"43":43}],45:[function(require,module,exports){
  8904. 'use strict';
  8905. var helpers = require(43);
  8906. /**
  8907. * @alias Chart.helpers.options
  8908. * @namespace
  8909. */
  8910. module.exports = {
  8911. /**
  8912. * Converts the given line height `value` in pixels for a specific font `size`.
  8913. * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
  8914. * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
  8915. * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
  8916. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
  8917. * @since 2.7.0
  8918. */
  8919. toLineHeight: function(value, size) {
  8920. var matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
  8921. if (!matches || matches[1] === 'normal') {
  8922. return size * 1.2;
  8923. }
  8924. value = +matches[2];
  8925. switch (matches[3]) {
  8926. case 'px':
  8927. return value;
  8928. case '%':
  8929. value /= 100;
  8930. break;
  8931. default:
  8932. break;
  8933. }
  8934. return size * value;
  8935. },
  8936. /**
  8937. * Converts the given value into a padding object with pre-computed width/height.
  8938. * @param {Number|Object} value - If a number, set the value to all TRBL component,
  8939. * else, if and object, use defined properties and sets undefined ones to 0.
  8940. * @returns {Object} The padding values (top, right, bottom, left, width, height)
  8941. * @since 2.7.0
  8942. */
  8943. toPadding: function(value) {
  8944. var t, r, b, l;
  8945. if (helpers.isObject(value)) {
  8946. t = +value.top || 0;
  8947. r = +value.right || 0;
  8948. b = +value.bottom || 0;
  8949. l = +value.left || 0;
  8950. } else {
  8951. t = r = b = l = +value || 0;
  8952. }
  8953. return {
  8954. top: t,
  8955. right: r,
  8956. bottom: b,
  8957. left: l,
  8958. height: t + b,
  8959. width: l + r
  8960. };
  8961. },
  8962. /**
  8963. * Evaluates the given `inputs` sequentially and returns the first defined value.
  8964. * @param {Array[]} inputs - An array of values, falling back to the last value.
  8965. * @param {Object} [context] - If defined and the current value is a function, the value
  8966. * is called with `context` as first argument and the result becomes the new input.
  8967. * @param {Number} [index] - If defined and the current value is an array, the value
  8968. * at `index` become the new input.
  8969. * @since 2.7.0
  8970. */
  8971. resolve: function(inputs, context, index) {
  8972. var i, ilen, value;
  8973. for (i = 0, ilen = inputs.length; i < ilen; ++i) {
  8974. value = inputs[i];
  8975. if (value === undefined) {
  8976. continue;
  8977. }
  8978. if (context !== undefined && typeof value === 'function') {
  8979. value = value(context);
  8980. }
  8981. if (index !== undefined && helpers.isArray(value)) {
  8982. value = value[index];
  8983. }
  8984. if (value !== undefined) {
  8985. return value;
  8986. }
  8987. }
  8988. }
  8989. };
  8990. },{"43":43}],46:[function(require,module,exports){
  8991. 'use strict';
  8992. module.exports = require(43);
  8993. module.exports.easing = require(44);
  8994. module.exports.canvas = require(42);
  8995. module.exports.options = require(45);
  8996. },{"42":42,"43":43,"44":44,"45":45}],47:[function(require,module,exports){
  8997. /**
  8998. * Platform fallback implementation (minimal).
  8999. * @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
  9000. */
  9001. module.exports = {
  9002. acquireContext: function(item) {
  9003. if (item && item.canvas) {
  9004. // Support for any object associated to a canvas (including a context2d)
  9005. item = item.canvas;
  9006. }
  9007. return item && item.getContext('2d') || null;
  9008. }
  9009. };
  9010. },{}],48:[function(require,module,exports){
  9011. /**
  9012. * Chart.Platform implementation for targeting a web browser
  9013. */
  9014. 'use strict';
  9015. var helpers = require(46);
  9016. var EXPANDO_KEY = '$chartjs';
  9017. var CSS_PREFIX = 'chartjs-';
  9018. var CSS_RENDER_MONITOR = CSS_PREFIX + 'render-monitor';
  9019. var CSS_RENDER_ANIMATION = CSS_PREFIX + 'render-animation';
  9020. var ANIMATION_START_EVENTS = ['animationstart', 'webkitAnimationStart'];
  9021. /**
  9022. * DOM event types -> Chart.js event types.
  9023. * Note: only events with different types are mapped.
  9024. * @see https://developer.mozilla.org/en-US/docs/Web/Events
  9025. */
  9026. var EVENT_TYPES = {
  9027. touchstart: 'mousedown',
  9028. touchmove: 'mousemove',
  9029. touchend: 'mouseup',
  9030. pointerenter: 'mouseenter',
  9031. pointerdown: 'mousedown',
  9032. pointermove: 'mousemove',
  9033. pointerup: 'mouseup',
  9034. pointerleave: 'mouseout',
  9035. pointerout: 'mouseout'
  9036. };
  9037. /**
  9038. * The "used" size is the final value of a dimension property after all calculations have
  9039. * been performed. This method uses the computed style of `element` but returns undefined
  9040. * if the computed style is not expressed in pixels. That can happen in some cases where
  9041. * `element` has a size relative to its parent and this last one is not yet displayed,
  9042. * for example because of `display: none` on a parent node.
  9043. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
  9044. * @returns {Number} Size in pixels or undefined if unknown.
  9045. */
  9046. function readUsedSize(element, property) {
  9047. var value = helpers.getStyle(element, property);
  9048. var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
  9049. return matches ? Number(matches[1]) : undefined;
  9050. }
  9051. /**
  9052. * Initializes the canvas style and render size without modifying the canvas display size,
  9053. * since responsiveness is handled by the controller.resize() method. The config is used
  9054. * to determine the aspect ratio to apply in case no explicit height has been specified.
  9055. */
  9056. function initCanvas(canvas, config) {
  9057. var style = canvas.style;
  9058. // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
  9059. // returns null or '' if no explicit value has been set to the canvas attribute.
  9060. var renderHeight = canvas.getAttribute('height');
  9061. var renderWidth = canvas.getAttribute('width');
  9062. // Chart.js modifies some canvas values that we want to restore on destroy
  9063. canvas[EXPANDO_KEY] = {
  9064. initial: {
  9065. height: renderHeight,
  9066. width: renderWidth,
  9067. style: {
  9068. display: style.display,
  9069. height: style.height,
  9070. width: style.width
  9071. }
  9072. }
  9073. };
  9074. // Force canvas to display as block to avoid extra space caused by inline
  9075. // elements, which would interfere with the responsive resize process.
  9076. // https://github.com/chartjs/Chart.js/issues/2538
  9077. style.display = style.display || 'block';
  9078. if (renderWidth === null || renderWidth === '') {
  9079. var displayWidth = readUsedSize(canvas, 'width');
  9080. if (displayWidth !== undefined) {
  9081. canvas.width = displayWidth;
  9082. }
  9083. }
  9084. if (renderHeight === null || renderHeight === '') {
  9085. if (canvas.style.height === '') {
  9086. // If no explicit render height and style height, let's apply the aspect ratio,
  9087. // which one can be specified by the user but also by charts as default option
  9088. // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
  9089. canvas.height = canvas.width / (config.options.aspectRatio || 2);
  9090. } else {
  9091. var displayHeight = readUsedSize(canvas, 'height');
  9092. if (displayWidth !== undefined) {
  9093. canvas.height = displayHeight;
  9094. }
  9095. }
  9096. }
  9097. return canvas;
  9098. }
  9099. /**
  9100. * Detects support for options object argument in addEventListener.
  9101. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  9102. * @private
  9103. */
  9104. var supportsEventListenerOptions = (function() {
  9105. var supports = false;
  9106. try {
  9107. var options = Object.defineProperty({}, 'passive', {
  9108. get: function() {
  9109. supports = true;
  9110. }
  9111. });
  9112. window.addEventListener('e', null, options);
  9113. } catch (e) {
  9114. // continue regardless of error
  9115. }
  9116. return supports;
  9117. }());
  9118. // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  9119. // https://github.com/chartjs/Chart.js/issues/4287
  9120. var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
  9121. function addEventListener(node, type, listener) {
  9122. node.addEventListener(type, listener, eventListenerOptions);
  9123. }
  9124. function removeEventListener(node, type, listener) {
  9125. node.removeEventListener(type, listener, eventListenerOptions);
  9126. }
  9127. function createEvent(type, chart, x, y, nativeEvent) {
  9128. return {
  9129. type: type,
  9130. chart: chart,
  9131. native: nativeEvent || null,
  9132. x: x !== undefined ? x : null,
  9133. y: y !== undefined ? y : null,
  9134. };
  9135. }
  9136. function fromNativeEvent(event, chart) {
  9137. var type = EVENT_TYPES[event.type] || event.type;
  9138. var pos = helpers.getRelativePosition(event, chart);
  9139. return createEvent(type, chart, pos.x, pos.y, event);
  9140. }
  9141. function throttled(fn, thisArg) {
  9142. var ticking = false;
  9143. var args = [];
  9144. return function() {
  9145. args = Array.prototype.slice.call(arguments);
  9146. thisArg = thisArg || this;
  9147. if (!ticking) {
  9148. ticking = true;
  9149. helpers.requestAnimFrame.call(window, function() {
  9150. ticking = false;
  9151. fn.apply(thisArg, args);
  9152. });
  9153. }
  9154. };
  9155. }
  9156. // Implementation based on https://github.com/marcj/css-element-queries
  9157. function createResizer(handler) {
  9158. var resizer = document.createElement('div');
  9159. var cls = CSS_PREFIX + 'size-monitor';
  9160. var maxSize = 1000000;
  9161. var style =
  9162. 'position:absolute;' +
  9163. 'left:0;' +
  9164. 'top:0;' +
  9165. 'right:0;' +
  9166. 'bottom:0;' +
  9167. 'overflow:hidden;' +
  9168. 'pointer-events:none;' +
  9169. 'visibility:hidden;' +
  9170. 'z-index:-1;';
  9171. resizer.style.cssText = style;
  9172. resizer.className = cls;
  9173. resizer.innerHTML =
  9174. '<div class="' + cls + '-expand" style="' + style + '">' +
  9175. '<div style="' +
  9176. 'position:absolute;' +
  9177. 'width:' + maxSize + 'px;' +
  9178. 'height:' + maxSize + 'px;' +
  9179. 'left:0;' +
  9180. 'top:0">' +
  9181. '</div>' +
  9182. '</div>' +
  9183. '<div class="' + cls + '-shrink" style="' + style + '">' +
  9184. '<div style="' +
  9185. 'position:absolute;' +
  9186. 'width:200%;' +
  9187. 'height:200%;' +
  9188. 'left:0; ' +
  9189. 'top:0">' +
  9190. '</div>' +
  9191. '</div>';
  9192. var expand = resizer.childNodes[0];
  9193. var shrink = resizer.childNodes[1];
  9194. resizer._reset = function() {
  9195. expand.scrollLeft = maxSize;
  9196. expand.scrollTop = maxSize;
  9197. shrink.scrollLeft = maxSize;
  9198. shrink.scrollTop = maxSize;
  9199. };
  9200. var onScroll = function() {
  9201. resizer._reset();
  9202. handler();
  9203. };
  9204. addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
  9205. addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
  9206. return resizer;
  9207. }
  9208. // https://davidwalsh.name/detect-node-insertion
  9209. function watchForRender(node, handler) {
  9210. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9211. var proxy = expando.renderProxy = function(e) {
  9212. if (e.animationName === CSS_RENDER_ANIMATION) {
  9213. handler();
  9214. }
  9215. };
  9216. helpers.each(ANIMATION_START_EVENTS, function(type) {
  9217. addEventListener(node, type, proxy);
  9218. });
  9219. // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
  9220. // is removed then added back immediately (same animation frame?). Accessing the
  9221. // `offsetParent` property will force a reflow and re-evaluate the CSS animation.
  9222. // https://gist.github.com/paulirish/5d52fb081b3570c81e3a#box-metrics
  9223. // https://github.com/chartjs/Chart.js/issues/4737
  9224. expando.reflow = !!node.offsetParent;
  9225. node.classList.add(CSS_RENDER_MONITOR);
  9226. }
  9227. function unwatchForRender(node) {
  9228. var expando = node[EXPANDO_KEY] || {};
  9229. var proxy = expando.renderProxy;
  9230. if (proxy) {
  9231. helpers.each(ANIMATION_START_EVENTS, function(type) {
  9232. removeEventListener(node, type, proxy);
  9233. });
  9234. delete expando.renderProxy;
  9235. }
  9236. node.classList.remove(CSS_RENDER_MONITOR);
  9237. }
  9238. function addResizeListener(node, listener, chart) {
  9239. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9240. // Let's keep track of this added resizer and thus avoid DOM query when removing it.
  9241. var resizer = expando.resizer = createResizer(throttled(function() {
  9242. if (expando.resizer) {
  9243. return listener(createEvent('resize', chart));
  9244. }
  9245. }));
  9246. // The resizer needs to be attached to the node parent, so we first need to be
  9247. // sure that `node` is attached to the DOM before injecting the resizer element.
  9248. watchForRender(node, function() {
  9249. if (expando.resizer) {
  9250. var container = node.parentNode;
  9251. if (container && container !== resizer.parentNode) {
  9252. container.insertBefore(resizer, container.firstChild);
  9253. }
  9254. // The container size might have changed, let's reset the resizer state.
  9255. resizer._reset();
  9256. }
  9257. });
  9258. }
  9259. function removeResizeListener(node) {
  9260. var expando = node[EXPANDO_KEY] || {};
  9261. var resizer = expando.resizer;
  9262. delete expando.resizer;
  9263. unwatchForRender(node);
  9264. if (resizer && resizer.parentNode) {
  9265. resizer.parentNode.removeChild(resizer);
  9266. }
  9267. }
  9268. function injectCSS(platform, css) {
  9269. // http://stackoverflow.com/q/3922139
  9270. var style = platform._style || document.createElement('style');
  9271. if (!platform._style) {
  9272. platform._style = style;
  9273. css = '/* Chart.js */\n' + css;
  9274. style.setAttribute('type', 'text/css');
  9275. document.getElementsByTagName('head')[0].appendChild(style);
  9276. }
  9277. style.appendChild(document.createTextNode(css));
  9278. }
  9279. module.exports = {
  9280. /**
  9281. * This property holds whether this platform is enabled for the current environment.
  9282. * Currently used by platform.js to select the proper implementation.
  9283. * @private
  9284. */
  9285. _enabled: typeof window !== 'undefined' && typeof document !== 'undefined',
  9286. initialize: function() {
  9287. var keyframes = 'from{opacity:0.99}to{opacity:1}';
  9288. injectCSS(this,
  9289. // DOM rendering detection
  9290. // https://davidwalsh.name/detect-node-insertion
  9291. '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9292. '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9293. '.' + CSS_RENDER_MONITOR + '{' +
  9294. '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9295. 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9296. '}'
  9297. );
  9298. },
  9299. acquireContext: function(item, config) {
  9300. if (typeof item === 'string') {
  9301. item = document.getElementById(item);
  9302. } else if (item.length) {
  9303. // Support for array based queries (such as jQuery)
  9304. item = item[0];
  9305. }
  9306. if (item && item.canvas) {
  9307. // Support for any object associated to a canvas (including a context2d)
  9308. item = item.canvas;
  9309. }
  9310. // To prevent canvas fingerprinting, some add-ons undefine the getContext
  9311. // method, for example: https://github.com/kkapsner/CanvasBlocker
  9312. // https://github.com/chartjs/Chart.js/issues/2807
  9313. var context = item && item.getContext && item.getContext('2d');
  9314. // `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
  9315. // inside an iframe or when running in a protected environment. We could guess the
  9316. // types from their toString() value but let's keep things flexible and assume it's
  9317. // a sufficient condition if the item has a context2D which has item as `canvas`.
  9318. // https://github.com/chartjs/Chart.js/issues/3887
  9319. // https://github.com/chartjs/Chart.js/issues/4102
  9320. // https://github.com/chartjs/Chart.js/issues/4152
  9321. if (context && context.canvas === item) {
  9322. initCanvas(item, config);
  9323. return context;
  9324. }
  9325. return null;
  9326. },
  9327. releaseContext: function(context) {
  9328. var canvas = context.canvas;
  9329. if (!canvas[EXPANDO_KEY]) {
  9330. return;
  9331. }
  9332. var initial = canvas[EXPANDO_KEY].initial;
  9333. ['height', 'width'].forEach(function(prop) {
  9334. var value = initial[prop];
  9335. if (helpers.isNullOrUndef(value)) {
  9336. canvas.removeAttribute(prop);
  9337. } else {
  9338. canvas.setAttribute(prop, value);
  9339. }
  9340. });
  9341. helpers.each(initial.style || {}, function(value, key) {
  9342. canvas.style[key] = value;
  9343. });
  9344. // The canvas render size might have been changed (and thus the state stack discarded),
  9345. // we can't use save() and restore() to restore the initial state. So make sure that at
  9346. // least the canvas context is reset to the default state by setting the canvas width.
  9347. // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
  9348. canvas.width = canvas.width;
  9349. delete canvas[EXPANDO_KEY];
  9350. },
  9351. addEventListener: function(chart, type, listener) {
  9352. var canvas = chart.canvas;
  9353. if (type === 'resize') {
  9354. // Note: the resize event is not supported on all browsers.
  9355. addResizeListener(canvas, listener, chart);
  9356. return;
  9357. }
  9358. var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
  9359. var proxies = expando.proxies || (expando.proxies = {});
  9360. var proxy = proxies[chart.id + '_' + type] = function(event) {
  9361. listener(fromNativeEvent(event, chart));
  9362. };
  9363. addEventListener(canvas, type, proxy);
  9364. },
  9365. removeEventListener: function(chart, type, listener) {
  9366. var canvas = chart.canvas;
  9367. if (type === 'resize') {
  9368. // Note: the resize event is not supported on all browsers.
  9369. removeResizeListener(canvas, listener);
  9370. return;
  9371. }
  9372. var expando = listener[EXPANDO_KEY] || {};
  9373. var proxies = expando.proxies || {};
  9374. var proxy = proxies[chart.id + '_' + type];
  9375. if (!proxy) {
  9376. return;
  9377. }
  9378. removeEventListener(canvas, type, proxy);
  9379. }
  9380. };
  9381. // DEPRECATIONS
  9382. /**
  9383. * Provided for backward compatibility, use EventTarget.addEventListener instead.
  9384. * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9385. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  9386. * @function Chart.helpers.addEvent
  9387. * @deprecated since version 2.7.0
  9388. * @todo remove at version 3
  9389. * @private
  9390. */
  9391. helpers.addEvent = addEventListener;
  9392. /**
  9393. * Provided for backward compatibility, use EventTarget.removeEventListener instead.
  9394. * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9395. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
  9396. * @function Chart.helpers.removeEvent
  9397. * @deprecated since version 2.7.0
  9398. * @todo remove at version 3
  9399. * @private
  9400. */
  9401. helpers.removeEvent = removeEventListener;
  9402. },{"46":46}],49:[function(require,module,exports){
  9403. 'use strict';
  9404. var helpers = require(46);
  9405. var basic = require(47);
  9406. var dom = require(48);
  9407. // @TODO Make possible to select another platform at build time.
  9408. var implementation = dom._enabled ? dom : basic;
  9409. /**
  9410. * @namespace Chart.platform
  9411. * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
  9412. * @since 2.4.0
  9413. */
  9414. module.exports = helpers.extend({
  9415. /**
  9416. * @since 2.7.0
  9417. */
  9418. initialize: function() {},
  9419. /**
  9420. * Called at chart construction time, returns a context2d instance implementing
  9421. * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
  9422. * @param {*} item - The native item from which to acquire context (platform specific)
  9423. * @param {Object} options - The chart options
  9424. * @returns {CanvasRenderingContext2D} context2d instance
  9425. */
  9426. acquireContext: function() {},
  9427. /**
  9428. * Called at chart destruction time, releases any resources associated to the context
  9429. * previously returned by the acquireContext() method.
  9430. * @param {CanvasRenderingContext2D} context - The context2d instance
  9431. * @returns {Boolean} true if the method succeeded, else false
  9432. */
  9433. releaseContext: function() {},
  9434. /**
  9435. * Registers the specified listener on the given chart.
  9436. * @param {Chart} chart - Chart from which to listen for event
  9437. * @param {String} type - The ({@link IEvent}) type to listen for
  9438. * @param {Function} listener - Receives a notification (an object that implements
  9439. * the {@link IEvent} interface) when an event of the specified type occurs.
  9440. */
  9441. addEventListener: function() {},
  9442. /**
  9443. * Removes the specified listener previously registered with addEventListener.
  9444. * @param {Chart} chart -Chart from which to remove the listener
  9445. * @param {String} type - The ({@link IEvent}) type to remove
  9446. * @param {Function} listener - The listener function to remove from the event target.
  9447. */
  9448. removeEventListener: function() {}
  9449. }, implementation);
  9450. /**
  9451. * @interface IPlatform
  9452. * Allows abstracting platform dependencies away from the chart
  9453. * @borrows Chart.platform.acquireContext as acquireContext
  9454. * @borrows Chart.platform.releaseContext as releaseContext
  9455. * @borrows Chart.platform.addEventListener as addEventListener
  9456. * @borrows Chart.platform.removeEventListener as removeEventListener
  9457. */
  9458. /**
  9459. * @interface IEvent
  9460. * @prop {String} type - The event type name, possible values are:
  9461. * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
  9462. * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
  9463. * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
  9464. * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
  9465. * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
  9466. */
  9467. },{"46":46,"47":47,"48":48}],50:[function(require,module,exports){
  9468. 'use strict';
  9469. module.exports = {};
  9470. module.exports.filler = require(51);
  9471. module.exports.legend = require(52);
  9472. module.exports.title = require(53);
  9473. },{"51":51,"52":52,"53":53}],51:[function(require,module,exports){
  9474. /**
  9475. * Plugin based on discussion from the following Chart.js issues:
  9476. * @see https://github.com/chartjs/Chart.js/issues/2380#issuecomment-279961569
  9477. * @see https://github.com/chartjs/Chart.js/issues/2440#issuecomment-256461897
  9478. */
  9479. 'use strict';
  9480. var defaults = require(26);
  9481. var elements = require(41);
  9482. var helpers = require(46);
  9483. defaults._set('global', {
  9484. plugins: {
  9485. filler: {
  9486. propagate: true
  9487. }
  9488. }
  9489. });
  9490. var mappers = {
  9491. dataset: function(source) {
  9492. var index = source.fill;
  9493. var chart = source.chart;
  9494. var meta = chart.getDatasetMeta(index);
  9495. var visible = meta && chart.isDatasetVisible(index);
  9496. var points = (visible && meta.dataset._children) || [];
  9497. var length = points.length || 0;
  9498. return !length ? null : function(point, i) {
  9499. return (i < length && points[i]._view) || null;
  9500. };
  9501. },
  9502. boundary: function(source) {
  9503. var boundary = source.boundary;
  9504. var x = boundary ? boundary.x : null;
  9505. var y = boundary ? boundary.y : null;
  9506. return function(point) {
  9507. return {
  9508. x: x === null ? point.x : x,
  9509. y: y === null ? point.y : y,
  9510. };
  9511. };
  9512. }
  9513. };
  9514. // @todo if (fill[0] === '#')
  9515. function decodeFill(el, index, count) {
  9516. var model = el._model || {};
  9517. var fill = model.fill;
  9518. var target;
  9519. if (fill === undefined) {
  9520. fill = !!model.backgroundColor;
  9521. }
  9522. if (fill === false || fill === null) {
  9523. return false;
  9524. }
  9525. if (fill === true) {
  9526. return 'origin';
  9527. }
  9528. target = parseFloat(fill, 10);
  9529. if (isFinite(target) && Math.floor(target) === target) {
  9530. if (fill[0] === '-' || fill[0] === '+') {
  9531. target = index + target;
  9532. }
  9533. if (target === index || target < 0 || target >= count) {
  9534. return false;
  9535. }
  9536. return target;
  9537. }
  9538. switch (fill) {
  9539. // compatibility
  9540. case 'bottom':
  9541. return 'start';
  9542. case 'top':
  9543. return 'end';
  9544. case 'zero':
  9545. return 'origin';
  9546. // supported boundaries
  9547. case 'origin':
  9548. case 'start':
  9549. case 'end':
  9550. return fill;
  9551. // invalid fill values
  9552. default:
  9553. return false;
  9554. }
  9555. }
  9556. function computeBoundary(source) {
  9557. var model = source.el._model || {};
  9558. var scale = source.el._scale || {};
  9559. var fill = source.fill;
  9560. var target = null;
  9561. var horizontal;
  9562. if (isFinite(fill)) {
  9563. return null;
  9564. }
  9565. // Backward compatibility: until v3, we still need to support boundary values set on
  9566. // the model (scaleTop, scaleBottom and scaleZero) because some external plugins and
  9567. // controllers might still use it (e.g. the Smith chart).
  9568. if (fill === 'start') {
  9569. target = model.scaleBottom === undefined ? scale.bottom : model.scaleBottom;
  9570. } else if (fill === 'end') {
  9571. target = model.scaleTop === undefined ? scale.top : model.scaleTop;
  9572. } else if (model.scaleZero !== undefined) {
  9573. target = model.scaleZero;
  9574. } else if (scale.getBasePosition) {
  9575. target = scale.getBasePosition();
  9576. } else if (scale.getBasePixel) {
  9577. target = scale.getBasePixel();
  9578. }
  9579. if (target !== undefined && target !== null) {
  9580. if (target.x !== undefined && target.y !== undefined) {
  9581. return target;
  9582. }
  9583. if (typeof target === 'number' && isFinite(target)) {
  9584. horizontal = scale.isHorizontal();
  9585. return {
  9586. x: horizontal ? target : null,
  9587. y: horizontal ? null : target
  9588. };
  9589. }
  9590. }
  9591. return null;
  9592. }
  9593. function resolveTarget(sources, index, propagate) {
  9594. var source = sources[index];
  9595. var fill = source.fill;
  9596. var visited = [index];
  9597. var target;
  9598. if (!propagate) {
  9599. return fill;
  9600. }
  9601. while (fill !== false && visited.indexOf(fill) === -1) {
  9602. if (!isFinite(fill)) {
  9603. return fill;
  9604. }
  9605. target = sources[fill];
  9606. if (!target) {
  9607. return false;
  9608. }
  9609. if (target.visible) {
  9610. return fill;
  9611. }
  9612. visited.push(fill);
  9613. fill = target.fill;
  9614. }
  9615. return false;
  9616. }
  9617. function createMapper(source) {
  9618. var fill = source.fill;
  9619. var type = 'dataset';
  9620. if (fill === false) {
  9621. return null;
  9622. }
  9623. if (!isFinite(fill)) {
  9624. type = 'boundary';
  9625. }
  9626. return mappers[type](source);
  9627. }
  9628. function isDrawable(point) {
  9629. return point && !point.skip;
  9630. }
  9631. function drawArea(ctx, curve0, curve1, len0, len1) {
  9632. var i;
  9633. if (!len0 || !len1) {
  9634. return;
  9635. }
  9636. // building first area curve (normal)
  9637. ctx.moveTo(curve0[0].x, curve0[0].y);
  9638. for (i = 1; i < len0; ++i) {
  9639. helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
  9640. }
  9641. // joining the two area curves
  9642. ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
  9643. // building opposite area curve (reverse)
  9644. for (i = len1 - 1; i > 0; --i) {
  9645. helpers.canvas.lineTo(ctx, curve1[i], curve1[i - 1], true);
  9646. }
  9647. }
  9648. function doFill(ctx, points, mapper, view, color, loop) {
  9649. var count = points.length;
  9650. var span = view.spanGaps;
  9651. var curve0 = [];
  9652. var curve1 = [];
  9653. var len0 = 0;
  9654. var len1 = 0;
  9655. var i, ilen, index, p0, p1, d0, d1;
  9656. ctx.beginPath();
  9657. for (i = 0, ilen = (count + !!loop); i < ilen; ++i) {
  9658. index = i % count;
  9659. p0 = points[index]._view;
  9660. p1 = mapper(p0, index, view);
  9661. d0 = isDrawable(p0);
  9662. d1 = isDrawable(p1);
  9663. if (d0 && d1) {
  9664. len0 = curve0.push(p0);
  9665. len1 = curve1.push(p1);
  9666. } else if (len0 && len1) {
  9667. if (!span) {
  9668. drawArea(ctx, curve0, curve1, len0, len1);
  9669. len0 = len1 = 0;
  9670. curve0 = [];
  9671. curve1 = [];
  9672. } else {
  9673. if (d0) {
  9674. curve0.push(p0);
  9675. }
  9676. if (d1) {
  9677. curve1.push(p1);
  9678. }
  9679. }
  9680. }
  9681. }
  9682. drawArea(ctx, curve0, curve1, len0, len1);
  9683. ctx.closePath();
  9684. ctx.fillStyle = color;
  9685. ctx.fill();
  9686. }
  9687. module.exports = {
  9688. id: 'filler',
  9689. afterDatasetsUpdate: function(chart, options) {
  9690. var count = (chart.data.datasets || []).length;
  9691. var propagate = options.propagate;
  9692. var sources = [];
  9693. var meta, i, el, source;
  9694. for (i = 0; i < count; ++i) {
  9695. meta = chart.getDatasetMeta(i);
  9696. el = meta.dataset;
  9697. source = null;
  9698. if (el && el._model && el instanceof elements.Line) {
  9699. source = {
  9700. visible: chart.isDatasetVisible(i),
  9701. fill: decodeFill(el, i, count),
  9702. chart: chart,
  9703. el: el
  9704. };
  9705. }
  9706. meta.$filler = source;
  9707. sources.push(source);
  9708. }
  9709. for (i = 0; i < count; ++i) {
  9710. source = sources[i];
  9711. if (!source) {
  9712. continue;
  9713. }
  9714. source.fill = resolveTarget(sources, i, propagate);
  9715. source.boundary = computeBoundary(source);
  9716. source.mapper = createMapper(source);
  9717. }
  9718. },
  9719. beforeDatasetDraw: function(chart, args) {
  9720. var meta = args.meta.$filler;
  9721. if (!meta) {
  9722. return;
  9723. }
  9724. var ctx = chart.ctx;
  9725. var el = meta.el;
  9726. var view = el._view;
  9727. var points = el._children || [];
  9728. var mapper = meta.mapper;
  9729. var color = view.backgroundColor || defaults.global.defaultColor;
  9730. if (mapper && color && points.length) {
  9731. helpers.canvas.clipArea(ctx, chart.chartArea);
  9732. doFill(ctx, points, mapper, view, color, el._loop);
  9733. helpers.canvas.unclipArea(ctx);
  9734. }
  9735. }
  9736. };
  9737. },{"26":26,"41":41,"46":46}],52:[function(require,module,exports){
  9738. 'use strict';
  9739. var defaults = require(26);
  9740. var Element = require(27);
  9741. var helpers = require(46);
  9742. var layouts = require(31);
  9743. var noop = helpers.noop;
  9744. defaults._set('global', {
  9745. legend: {
  9746. display: true,
  9747. position: 'top',
  9748. fullWidth: true,
  9749. reverse: false,
  9750. weight: 1000,
  9751. // a callback that will handle
  9752. onClick: function(e, legendItem) {
  9753. var index = legendItem.datasetIndex;
  9754. var ci = this.chart;
  9755. var meta = ci.getDatasetMeta(index);
  9756. // See controller.isDatasetVisible comment
  9757. meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
  9758. // We hid a dataset ... rerender the chart
  9759. ci.update();
  9760. },
  9761. onHover: null,
  9762. labels: {
  9763. boxWidth: 40,
  9764. padding: 10,
  9765. // Generates labels shown in the legend
  9766. // Valid properties to return:
  9767. // text : text to display
  9768. // fillStyle : fill of coloured box
  9769. // strokeStyle: stroke of coloured box
  9770. // hidden : if this legend item refers to a hidden item
  9771. // lineCap : cap style for line
  9772. // lineDash
  9773. // lineDashOffset :
  9774. // lineJoin :
  9775. // lineWidth :
  9776. generateLabels: function(chart) {
  9777. var data = chart.data;
  9778. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  9779. return {
  9780. text: dataset.label,
  9781. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  9782. hidden: !chart.isDatasetVisible(i),
  9783. lineCap: dataset.borderCapStyle,
  9784. lineDash: dataset.borderDash,
  9785. lineDashOffset: dataset.borderDashOffset,
  9786. lineJoin: dataset.borderJoinStyle,
  9787. lineWidth: dataset.borderWidth,
  9788. strokeStyle: dataset.borderColor,
  9789. pointStyle: dataset.pointStyle,
  9790. // Below is extra data used for toggling the datasets
  9791. datasetIndex: i
  9792. };
  9793. }, this) : [];
  9794. }
  9795. }
  9796. },
  9797. legendCallback: function(chart) {
  9798. var text = [];
  9799. text.push('<ul class="' + chart.id + '-legend">');
  9800. for (var i = 0; i < chart.data.datasets.length; i++) {
  9801. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  9802. if (chart.data.datasets[i].label) {
  9803. text.push(chart.data.datasets[i].label);
  9804. }
  9805. text.push('</li>');
  9806. }
  9807. text.push('</ul>');
  9808. return text.join('');
  9809. }
  9810. });
  9811. /**
  9812. * Helper function to get the box width based on the usePointStyle option
  9813. * @param labelopts {Object} the label options on the legend
  9814. * @param fontSize {Number} the label font size
  9815. * @return {Number} width of the color box area
  9816. */
  9817. function getBoxWidth(labelOpts, fontSize) {
  9818. return labelOpts.usePointStyle ?
  9819. fontSize * Math.SQRT2 :
  9820. labelOpts.boxWidth;
  9821. }
  9822. /**
  9823. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  9824. */
  9825. var Legend = Element.extend({
  9826. initialize: function(config) {
  9827. helpers.extend(this, config);
  9828. // Contains hit boxes for each dataset (in dataset order)
  9829. this.legendHitBoxes = [];
  9830. // Are we in doughnut mode which has a different data type
  9831. this.doughnutMode = false;
  9832. },
  9833. // These methods are ordered by lifecycle. Utilities then follow.
  9834. // Any function defined here is inherited by all legend types.
  9835. // Any function can be extended by the legend type
  9836. beforeUpdate: noop,
  9837. update: function(maxWidth, maxHeight, margins) {
  9838. var me = this;
  9839. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  9840. me.beforeUpdate();
  9841. // Absorb the master measurements
  9842. me.maxWidth = maxWidth;
  9843. me.maxHeight = maxHeight;
  9844. me.margins = margins;
  9845. // Dimensions
  9846. me.beforeSetDimensions();
  9847. me.setDimensions();
  9848. me.afterSetDimensions();
  9849. // Labels
  9850. me.beforeBuildLabels();
  9851. me.buildLabels();
  9852. me.afterBuildLabels();
  9853. // Fit
  9854. me.beforeFit();
  9855. me.fit();
  9856. me.afterFit();
  9857. //
  9858. me.afterUpdate();
  9859. return me.minSize;
  9860. },
  9861. afterUpdate: noop,
  9862. //
  9863. beforeSetDimensions: noop,
  9864. setDimensions: function() {
  9865. var me = this;
  9866. // Set the unconstrained dimension before label rotation
  9867. if (me.isHorizontal()) {
  9868. // Reset position before calculating rotation
  9869. me.width = me.maxWidth;
  9870. me.left = 0;
  9871. me.right = me.width;
  9872. } else {
  9873. me.height = me.maxHeight;
  9874. // Reset position before calculating rotation
  9875. me.top = 0;
  9876. me.bottom = me.height;
  9877. }
  9878. // Reset padding
  9879. me.paddingLeft = 0;
  9880. me.paddingTop = 0;
  9881. me.paddingRight = 0;
  9882. me.paddingBottom = 0;
  9883. // Reset minSize
  9884. me.minSize = {
  9885. width: 0,
  9886. height: 0
  9887. };
  9888. },
  9889. afterSetDimensions: noop,
  9890. //
  9891. beforeBuildLabels: noop,
  9892. buildLabels: function() {
  9893. var me = this;
  9894. var labelOpts = me.options.labels || {};
  9895. var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];
  9896. if (labelOpts.filter) {
  9897. legendItems = legendItems.filter(function(item) {
  9898. return labelOpts.filter(item, me.chart.data);
  9899. });
  9900. }
  9901. if (me.options.reverse) {
  9902. legendItems.reverse();
  9903. }
  9904. me.legendItems = legendItems;
  9905. },
  9906. afterBuildLabels: noop,
  9907. //
  9908. beforeFit: noop,
  9909. fit: function() {
  9910. var me = this;
  9911. var opts = me.options;
  9912. var labelOpts = opts.labels;
  9913. var display = opts.display;
  9914. var ctx = me.ctx;
  9915. var globalDefault = defaults.global;
  9916. var valueOrDefault = helpers.valueOrDefault;
  9917. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  9918. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  9919. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  9920. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  9921. // Reset hit boxes
  9922. var hitboxes = me.legendHitBoxes = [];
  9923. var minSize = me.minSize;
  9924. var isHorizontal = me.isHorizontal();
  9925. if (isHorizontal) {
  9926. minSize.width = me.maxWidth; // fill all the width
  9927. minSize.height = display ? 10 : 0;
  9928. } else {
  9929. minSize.width = display ? 10 : 0;
  9930. minSize.height = me.maxHeight; // fill all the height
  9931. }
  9932. // Increase sizes here
  9933. if (display) {
  9934. ctx.font = labelFont;
  9935. if (isHorizontal) {
  9936. // Labels
  9937. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  9938. var lineWidths = me.lineWidths = [0];
  9939. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  9940. ctx.textAlign = 'left';
  9941. ctx.textBaseline = 'top';
  9942. helpers.each(me.legendItems, function(legendItem, i) {
  9943. var boxWidth = getBoxWidth(labelOpts, fontSize);
  9944. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  9945. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  9946. totalHeight += fontSize + (labelOpts.padding);
  9947. lineWidths[lineWidths.length] = me.left;
  9948. }
  9949. // Store the hitbox width and height here. Final position will be updated in `draw`
  9950. hitboxes[i] = {
  9951. left: 0,
  9952. top: 0,
  9953. width: width,
  9954. height: fontSize
  9955. };
  9956. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  9957. });
  9958. minSize.height += totalHeight;
  9959. } else {
  9960. var vPadding = labelOpts.padding;
  9961. var columnWidths = me.columnWidths = [];
  9962. var totalWidth = labelOpts.padding;
  9963. var currentColWidth = 0;
  9964. var currentColHeight = 0;
  9965. var itemHeight = fontSize + vPadding;
  9966. helpers.each(me.legendItems, function(legendItem, i) {
  9967. var boxWidth = getBoxWidth(labelOpts, fontSize);
  9968. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  9969. // If too tall, go to new column
  9970. if (currentColHeight + itemHeight > minSize.height) {
  9971. totalWidth += currentColWidth + labelOpts.padding;
  9972. columnWidths.push(currentColWidth); // previous column width
  9973. currentColWidth = 0;
  9974. currentColHeight = 0;
  9975. }
  9976. // Get max width
  9977. currentColWidth = Math.max(currentColWidth, itemWidth);
  9978. currentColHeight += itemHeight;
  9979. // Store the hitbox width and height here. Final position will be updated in `draw`
  9980. hitboxes[i] = {
  9981. left: 0,
  9982. top: 0,
  9983. width: itemWidth,
  9984. height: fontSize
  9985. };
  9986. });
  9987. totalWidth += currentColWidth;
  9988. columnWidths.push(currentColWidth);
  9989. minSize.width += totalWidth;
  9990. }
  9991. }
  9992. me.width = minSize.width;
  9993. me.height = minSize.height;
  9994. },
  9995. afterFit: noop,
  9996. // Shared Methods
  9997. isHorizontal: function() {
  9998. return this.options.position === 'top' || this.options.position === 'bottom';
  9999. },
  10000. // Actually draw the legend on the canvas
  10001. draw: function() {
  10002. var me = this;
  10003. var opts = me.options;
  10004. var labelOpts = opts.labels;
  10005. var globalDefault = defaults.global;
  10006. var lineDefault = globalDefault.elements.line;
  10007. var legendWidth = me.width;
  10008. var lineWidths = me.lineWidths;
  10009. if (opts.display) {
  10010. var ctx = me.ctx;
  10011. var valueOrDefault = helpers.valueOrDefault;
  10012. var fontColor = valueOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor);
  10013. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  10014. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  10015. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  10016. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10017. var cursor;
  10018. // Canvas setup
  10019. ctx.textAlign = 'left';
  10020. ctx.textBaseline = 'middle';
  10021. ctx.lineWidth = 0.5;
  10022. ctx.strokeStyle = fontColor; // for strikethrough effect
  10023. ctx.fillStyle = fontColor; // render in correct colour
  10024. ctx.font = labelFont;
  10025. var boxWidth = getBoxWidth(labelOpts, fontSize);
  10026. var hitboxes = me.legendHitBoxes;
  10027. // current position
  10028. var drawLegendBox = function(x, y, legendItem) {
  10029. if (isNaN(boxWidth) || boxWidth <= 0) {
  10030. return;
  10031. }
  10032. // Set the ctx for the box
  10033. ctx.save();
  10034. ctx.fillStyle = valueOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  10035. ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  10036. ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  10037. ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  10038. ctx.lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  10039. ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  10040. var isLineWidthZero = (valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  10041. if (ctx.setLineDash) {
  10042. // IE 9 and 10 do not support line dash
  10043. ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
  10044. }
  10045. if (opts.labels && opts.labels.usePointStyle) {
  10046. // Recalculate x and y for drawPoint() because its expecting
  10047. // x and y to be center of figure (instead of top left)
  10048. var radius = fontSize * Math.SQRT2 / 2;
  10049. var offSet = radius / Math.SQRT2;
  10050. var centerX = x + offSet;
  10051. var centerY = y + offSet;
  10052. // Draw pointStyle as legend symbol
  10053. helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  10054. } else {
  10055. // Draw box as legend symbol
  10056. if (!isLineWidthZero) {
  10057. ctx.strokeRect(x, y, boxWidth, fontSize);
  10058. }
  10059. ctx.fillRect(x, y, boxWidth, fontSize);
  10060. }
  10061. ctx.restore();
  10062. };
  10063. var fillText = function(x, y, legendItem, textWidth) {
  10064. var halfFontSize = fontSize / 2;
  10065. var xLeft = boxWidth + halfFontSize + x;
  10066. var yMiddle = y + halfFontSize;
  10067. ctx.fillText(legendItem.text, xLeft, yMiddle);
  10068. if (legendItem.hidden) {
  10069. // Strikethrough the text if hidden
  10070. ctx.beginPath();
  10071. ctx.lineWidth = 2;
  10072. ctx.moveTo(xLeft, yMiddle);
  10073. ctx.lineTo(xLeft + textWidth, yMiddle);
  10074. ctx.stroke();
  10075. }
  10076. };
  10077. // Horizontal
  10078. var isHorizontal = me.isHorizontal();
  10079. if (isHorizontal) {
  10080. cursor = {
  10081. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  10082. y: me.top + labelOpts.padding,
  10083. line: 0
  10084. };
  10085. } else {
  10086. cursor = {
  10087. x: me.left + labelOpts.padding,
  10088. y: me.top + labelOpts.padding,
  10089. line: 0
  10090. };
  10091. }
  10092. var itemHeight = fontSize + labelOpts.padding;
  10093. helpers.each(me.legendItems, function(legendItem, i) {
  10094. var textWidth = ctx.measureText(legendItem.text).width;
  10095. var width = boxWidth + (fontSize / 2) + textWidth;
  10096. var x = cursor.x;
  10097. var y = cursor.y;
  10098. if (isHorizontal) {
  10099. if (x + width >= legendWidth) {
  10100. y = cursor.y += itemHeight;
  10101. cursor.line++;
  10102. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  10103. }
  10104. } else if (y + itemHeight > me.bottom) {
  10105. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  10106. y = cursor.y = me.top + labelOpts.padding;
  10107. cursor.line++;
  10108. }
  10109. drawLegendBox(x, y, legendItem);
  10110. hitboxes[i].left = x;
  10111. hitboxes[i].top = y;
  10112. // Fill the actual label
  10113. fillText(x, y, legendItem, textWidth);
  10114. if (isHorizontal) {
  10115. cursor.x += width + (labelOpts.padding);
  10116. } else {
  10117. cursor.y += itemHeight;
  10118. }
  10119. });
  10120. }
  10121. },
  10122. /**
  10123. * Handle an event
  10124. * @private
  10125. * @param {IEvent} event - The event to handle
  10126. * @return {Boolean} true if a change occured
  10127. */
  10128. handleEvent: function(e) {
  10129. var me = this;
  10130. var opts = me.options;
  10131. var type = e.type === 'mouseup' ? 'click' : e.type;
  10132. var changed = false;
  10133. if (type === 'mousemove') {
  10134. if (!opts.onHover) {
  10135. return;
  10136. }
  10137. } else if (type === 'click') {
  10138. if (!opts.onClick) {
  10139. return;
  10140. }
  10141. } else {
  10142. return;
  10143. }
  10144. // Chart event already has relative position in it
  10145. var x = e.x;
  10146. var y = e.y;
  10147. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  10148. // See if we are touching one of the dataset boxes
  10149. var lh = me.legendHitBoxes;
  10150. for (var i = 0; i < lh.length; ++i) {
  10151. var hitBox = lh[i];
  10152. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  10153. // Touching an element
  10154. if (type === 'click') {
  10155. // use e.native for backwards compatibility
  10156. opts.onClick.call(me, e.native, me.legendItems[i]);
  10157. changed = true;
  10158. break;
  10159. } else if (type === 'mousemove') {
  10160. // use e.native for backwards compatibility
  10161. opts.onHover.call(me, e.native, me.legendItems[i]);
  10162. changed = true;
  10163. break;
  10164. }
  10165. }
  10166. }
  10167. }
  10168. return changed;
  10169. }
  10170. });
  10171. function createNewLegendAndAttach(chart, legendOpts) {
  10172. var legend = new Legend({
  10173. ctx: chart.ctx,
  10174. options: legendOpts,
  10175. chart: chart
  10176. });
  10177. layouts.configure(chart, legend, legendOpts);
  10178. layouts.addBox(chart, legend);
  10179. chart.legend = legend;
  10180. }
  10181. module.exports = {
  10182. id: 'legend',
  10183. /**
  10184. * Backward compatibility: since 2.1.5, the legend is registered as a plugin, making
  10185. * Chart.Legend obsolete. To avoid a breaking change, we export the Legend as part of
  10186. * the plugin, which one will be re-exposed in the chart.js file.
  10187. * https://github.com/chartjs/Chart.js/pull/2640
  10188. * @private
  10189. */
  10190. _element: Legend,
  10191. beforeInit: function(chart) {
  10192. var legendOpts = chart.options.legend;
  10193. if (legendOpts) {
  10194. createNewLegendAndAttach(chart, legendOpts);
  10195. }
  10196. },
  10197. beforeUpdate: function(chart) {
  10198. var legendOpts = chart.options.legend;
  10199. var legend = chart.legend;
  10200. if (legendOpts) {
  10201. helpers.mergeIf(legendOpts, defaults.global.legend);
  10202. if (legend) {
  10203. layouts.configure(chart, legend, legendOpts);
  10204. legend.options = legendOpts;
  10205. } else {
  10206. createNewLegendAndAttach(chart, legendOpts);
  10207. }
  10208. } else if (legend) {
  10209. layouts.removeBox(chart, legend);
  10210. delete chart.legend;
  10211. }
  10212. },
  10213. afterEvent: function(chart, e) {
  10214. var legend = chart.legend;
  10215. if (legend) {
  10216. legend.handleEvent(e);
  10217. }
  10218. }
  10219. };
  10220. },{"26":26,"27":27,"31":31,"46":46}],53:[function(require,module,exports){
  10221. 'use strict';
  10222. var defaults = require(26);
  10223. var Element = require(27);
  10224. var helpers = require(46);
  10225. var layouts = require(31);
  10226. var noop = helpers.noop;
  10227. defaults._set('global', {
  10228. title: {
  10229. display: false,
  10230. fontStyle: 'bold',
  10231. fullWidth: true,
  10232. lineHeight: 1.2,
  10233. padding: 10,
  10234. position: 'top',
  10235. text: '',
  10236. weight: 2000 // by default greater than legend (1000) to be above
  10237. }
  10238. });
  10239. /**
  10240. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  10241. */
  10242. var Title = Element.extend({
  10243. initialize: function(config) {
  10244. var me = this;
  10245. helpers.extend(me, config);
  10246. // Contains hit boxes for each dataset (in dataset order)
  10247. me.legendHitBoxes = [];
  10248. },
  10249. // These methods are ordered by lifecycle. Utilities then follow.
  10250. beforeUpdate: noop,
  10251. update: function(maxWidth, maxHeight, margins) {
  10252. var me = this;
  10253. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  10254. me.beforeUpdate();
  10255. // Absorb the master measurements
  10256. me.maxWidth = maxWidth;
  10257. me.maxHeight = maxHeight;
  10258. me.margins = margins;
  10259. // Dimensions
  10260. me.beforeSetDimensions();
  10261. me.setDimensions();
  10262. me.afterSetDimensions();
  10263. // Labels
  10264. me.beforeBuildLabels();
  10265. me.buildLabels();
  10266. me.afterBuildLabels();
  10267. // Fit
  10268. me.beforeFit();
  10269. me.fit();
  10270. me.afterFit();
  10271. //
  10272. me.afterUpdate();
  10273. return me.minSize;
  10274. },
  10275. afterUpdate: noop,
  10276. //
  10277. beforeSetDimensions: noop,
  10278. setDimensions: function() {
  10279. var me = this;
  10280. // Set the unconstrained dimension before label rotation
  10281. if (me.isHorizontal()) {
  10282. // Reset position before calculating rotation
  10283. me.width = me.maxWidth;
  10284. me.left = 0;
  10285. me.right = me.width;
  10286. } else {
  10287. me.height = me.maxHeight;
  10288. // Reset position before calculating rotation
  10289. me.top = 0;
  10290. me.bottom = me.height;
  10291. }
  10292. // Reset padding
  10293. me.paddingLeft = 0;
  10294. me.paddingTop = 0;
  10295. me.paddingRight = 0;
  10296. me.paddingBottom = 0;
  10297. // Reset minSize
  10298. me.minSize = {
  10299. width: 0,
  10300. height: 0
  10301. };
  10302. },
  10303. afterSetDimensions: noop,
  10304. //
  10305. beforeBuildLabels: noop,
  10306. buildLabels: noop,
  10307. afterBuildLabels: noop,
  10308. //
  10309. beforeFit: noop,
  10310. fit: function() {
  10311. var me = this;
  10312. var valueOrDefault = helpers.valueOrDefault;
  10313. var opts = me.options;
  10314. var display = opts.display;
  10315. var fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize);
  10316. var minSize = me.minSize;
  10317. var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
  10318. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10319. var textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
  10320. if (me.isHorizontal()) {
  10321. minSize.width = me.maxWidth; // fill all the width
  10322. minSize.height = textSize;
  10323. } else {
  10324. minSize.width = textSize;
  10325. minSize.height = me.maxHeight; // fill all the height
  10326. }
  10327. me.width = minSize.width;
  10328. me.height = minSize.height;
  10329. },
  10330. afterFit: noop,
  10331. // Shared Methods
  10332. isHorizontal: function() {
  10333. var pos = this.options.position;
  10334. return pos === 'top' || pos === 'bottom';
  10335. },
  10336. // Actually draw the title block on the canvas
  10337. draw: function() {
  10338. var me = this;
  10339. var ctx = me.ctx;
  10340. var valueOrDefault = helpers.valueOrDefault;
  10341. var opts = me.options;
  10342. var globalDefaults = defaults.global;
  10343. if (opts.display) {
  10344. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize);
  10345. var fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle);
  10346. var fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily);
  10347. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10348. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10349. var offset = lineHeight / 2 + opts.padding;
  10350. var rotation = 0;
  10351. var top = me.top;
  10352. var left = me.left;
  10353. var bottom = me.bottom;
  10354. var right = me.right;
  10355. var maxWidth, titleX, titleY;
  10356. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  10357. ctx.font = titleFont;
  10358. // Horizontal
  10359. if (me.isHorizontal()) {
  10360. titleX = left + ((right - left) / 2); // midpoint of the width
  10361. titleY = top + offset;
  10362. maxWidth = right - left;
  10363. } else {
  10364. titleX = opts.position === 'left' ? left + offset : right - offset;
  10365. titleY = top + ((bottom - top) / 2);
  10366. maxWidth = bottom - top;
  10367. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  10368. }
  10369. ctx.save();
  10370. ctx.translate(titleX, titleY);
  10371. ctx.rotate(rotation);
  10372. ctx.textAlign = 'center';
  10373. ctx.textBaseline = 'middle';
  10374. var text = opts.text;
  10375. if (helpers.isArray(text)) {
  10376. var y = 0;
  10377. for (var i = 0; i < text.length; ++i) {
  10378. ctx.fillText(text[i], 0, y, maxWidth);
  10379. y += lineHeight;
  10380. }
  10381. } else {
  10382. ctx.fillText(text, 0, 0, maxWidth);
  10383. }
  10384. ctx.restore();
  10385. }
  10386. }
  10387. });
  10388. function createNewTitleBlockAndAttach(chart, titleOpts) {
  10389. var title = new Title({
  10390. ctx: chart.ctx,
  10391. options: titleOpts,
  10392. chart: chart
  10393. });
  10394. layouts.configure(chart, title, titleOpts);
  10395. layouts.addBox(chart, title);
  10396. chart.titleBlock = title;
  10397. }
  10398. module.exports = {
  10399. id: 'title',
  10400. /**
  10401. * Backward compatibility: since 2.1.5, the title is registered as a plugin, making
  10402. * Chart.Title obsolete. To avoid a breaking change, we export the Title as part of
  10403. * the plugin, which one will be re-exposed in the chart.js file.
  10404. * https://github.com/chartjs/Chart.js/pull/2640
  10405. * @private
  10406. */
  10407. _element: Title,
  10408. beforeInit: function(chart) {
  10409. var titleOpts = chart.options.title;
  10410. if (titleOpts) {
  10411. createNewTitleBlockAndAttach(chart, titleOpts);
  10412. }
  10413. },
  10414. beforeUpdate: function(chart) {
  10415. var titleOpts = chart.options.title;
  10416. var titleBlock = chart.titleBlock;
  10417. if (titleOpts) {
  10418. helpers.mergeIf(titleOpts, defaults.global.title);
  10419. if (titleBlock) {
  10420. layouts.configure(chart, titleBlock, titleOpts);
  10421. titleBlock.options = titleOpts;
  10422. } else {
  10423. createNewTitleBlockAndAttach(chart, titleOpts);
  10424. }
  10425. } else if (titleBlock) {
  10426. layouts.removeBox(chart, titleBlock);
  10427. delete chart.titleBlock;
  10428. }
  10429. }
  10430. };
  10431. },{"26":26,"27":27,"31":31,"46":46}],54:[function(require,module,exports){
  10432. 'use strict';
  10433. var Scale = require(33);
  10434. var scaleService = require(34);
  10435. module.exports = function() {
  10436. // Default config for a category scale
  10437. var defaultConfig = {
  10438. position: 'bottom'
  10439. };
  10440. var DatasetScale = Scale.extend({
  10441. /**
  10442. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
  10443. * else fall back to data.labels
  10444. * @private
  10445. */
  10446. getLabels: function() {
  10447. var data = this.chart.data;
  10448. return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  10449. },
  10450. determineDataLimits: function() {
  10451. var me = this;
  10452. var labels = me.getLabels();
  10453. me.minIndex = 0;
  10454. me.maxIndex = labels.length - 1;
  10455. var findIndex;
  10456. if (me.options.ticks.min !== undefined) {
  10457. // user specified min value
  10458. findIndex = labels.indexOf(me.options.ticks.min);
  10459. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  10460. }
  10461. if (me.options.ticks.max !== undefined) {
  10462. // user specified max value
  10463. findIndex = labels.indexOf(me.options.ticks.max);
  10464. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  10465. }
  10466. me.min = labels[me.minIndex];
  10467. me.max = labels[me.maxIndex];
  10468. },
  10469. buildTicks: function() {
  10470. var me = this;
  10471. var labels = me.getLabels();
  10472. // If we are viewing some subset of labels, slice the original array
  10473. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  10474. },
  10475. getLabelForIndex: function(index, datasetIndex) {
  10476. var me = this;
  10477. var data = me.chart.data;
  10478. var isHorizontal = me.isHorizontal();
  10479. if (data.yLabels && !isHorizontal) {
  10480. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  10481. }
  10482. return me.ticks[index - me.minIndex];
  10483. },
  10484. // Used to get data value locations. Value can either be an index or a numerical value
  10485. getPixelForValue: function(value, index) {
  10486. var me = this;
  10487. var offset = me.options.offset;
  10488. // 1 is added because we need the length but we have the indexes
  10489. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1)), 1);
  10490. // If value is a data object, then index is the index in the data array,
  10491. // not the index of the scale. We need to change that.
  10492. var valueCategory;
  10493. if (value !== undefined && value !== null) {
  10494. valueCategory = me.isHorizontal() ? value.x : value.y;
  10495. }
  10496. if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
  10497. var labels = me.getLabels();
  10498. value = valueCategory || value;
  10499. var idx = labels.indexOf(value);
  10500. index = idx !== -1 ? idx : index;
  10501. }
  10502. if (me.isHorizontal()) {
  10503. var valueWidth = me.width / offsetAmt;
  10504. var widthOffset = (valueWidth * (index - me.minIndex));
  10505. if (offset) {
  10506. widthOffset += (valueWidth / 2);
  10507. }
  10508. return me.left + Math.round(widthOffset);
  10509. }
  10510. var valueHeight = me.height / offsetAmt;
  10511. var heightOffset = (valueHeight * (index - me.minIndex));
  10512. if (offset) {
  10513. heightOffset += (valueHeight / 2);
  10514. }
  10515. return me.top + Math.round(heightOffset);
  10516. },
  10517. getPixelForTick: function(index) {
  10518. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null);
  10519. },
  10520. getValueForPixel: function(pixel) {
  10521. var me = this;
  10522. var offset = me.options.offset;
  10523. var value;
  10524. var offsetAmt = Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  10525. var horz = me.isHorizontal();
  10526. var valueDimension = (horz ? me.width : me.height) / offsetAmt;
  10527. pixel -= horz ? me.left : me.top;
  10528. if (offset) {
  10529. pixel -= (valueDimension / 2);
  10530. }
  10531. if (pixel <= 0) {
  10532. value = 0;
  10533. } else {
  10534. value = Math.round(pixel / valueDimension);
  10535. }
  10536. return value + me.minIndex;
  10537. },
  10538. getBasePixel: function() {
  10539. return this.bottom;
  10540. }
  10541. });
  10542. scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  10543. };
  10544. },{"33":33,"34":34}],55:[function(require,module,exports){
  10545. 'use strict';
  10546. var defaults = require(26);
  10547. var helpers = require(46);
  10548. var scaleService = require(34);
  10549. var Ticks = require(35);
  10550. module.exports = function(Chart) {
  10551. var defaultConfig = {
  10552. position: 'left',
  10553. ticks: {
  10554. callback: Ticks.formatters.linear
  10555. }
  10556. };
  10557. var LinearScale = Chart.LinearScaleBase.extend({
  10558. determineDataLimits: function() {
  10559. var me = this;
  10560. var opts = me.options;
  10561. var chart = me.chart;
  10562. var data = chart.data;
  10563. var datasets = data.datasets;
  10564. var isHorizontal = me.isHorizontal();
  10565. var DEFAULT_MIN = 0;
  10566. var DEFAULT_MAX = 1;
  10567. function IDMatches(meta) {
  10568. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10569. }
  10570. // First Calculate the range
  10571. me.min = null;
  10572. me.max = null;
  10573. var hasStacks = opts.stacked;
  10574. if (hasStacks === undefined) {
  10575. helpers.each(datasets, function(dataset, datasetIndex) {
  10576. if (hasStacks) {
  10577. return;
  10578. }
  10579. var meta = chart.getDatasetMeta(datasetIndex);
  10580. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10581. meta.stack !== undefined) {
  10582. hasStacks = true;
  10583. }
  10584. });
  10585. }
  10586. if (opts.stacked || hasStacks) {
  10587. var valuesPerStack = {};
  10588. helpers.each(datasets, function(dataset, datasetIndex) {
  10589. var meta = chart.getDatasetMeta(datasetIndex);
  10590. var key = [
  10591. meta.type,
  10592. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10593. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10594. meta.stack
  10595. ].join('.');
  10596. if (valuesPerStack[key] === undefined) {
  10597. valuesPerStack[key] = {
  10598. positiveValues: [],
  10599. negativeValues: []
  10600. };
  10601. }
  10602. // Store these per type
  10603. var positiveValues = valuesPerStack[key].positiveValues;
  10604. var negativeValues = valuesPerStack[key].negativeValues;
  10605. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10606. helpers.each(dataset.data, function(rawValue, index) {
  10607. var value = +me.getRightValue(rawValue);
  10608. if (isNaN(value) || meta.data[index].hidden) {
  10609. return;
  10610. }
  10611. positiveValues[index] = positiveValues[index] || 0;
  10612. negativeValues[index] = negativeValues[index] || 0;
  10613. if (opts.relativePoints) {
  10614. positiveValues[index] = 100;
  10615. } else if (value < 0) {
  10616. negativeValues[index] += value;
  10617. } else {
  10618. positiveValues[index] += value;
  10619. }
  10620. });
  10621. }
  10622. });
  10623. helpers.each(valuesPerStack, function(valuesForType) {
  10624. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  10625. var minVal = helpers.min(values);
  10626. var maxVal = helpers.max(values);
  10627. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  10628. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  10629. });
  10630. } else {
  10631. helpers.each(datasets, function(dataset, datasetIndex) {
  10632. var meta = chart.getDatasetMeta(datasetIndex);
  10633. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10634. helpers.each(dataset.data, function(rawValue, index) {
  10635. var value = +me.getRightValue(rawValue);
  10636. if (isNaN(value) || meta.data[index].hidden) {
  10637. return;
  10638. }
  10639. if (me.min === null) {
  10640. me.min = value;
  10641. } else if (value < me.min) {
  10642. me.min = value;
  10643. }
  10644. if (me.max === null) {
  10645. me.max = value;
  10646. } else if (value > me.max) {
  10647. me.max = value;
  10648. }
  10649. });
  10650. }
  10651. });
  10652. }
  10653. me.min = isFinite(me.min) && !isNaN(me.min) ? me.min : DEFAULT_MIN;
  10654. me.max = isFinite(me.max) && !isNaN(me.max) ? me.max : DEFAULT_MAX;
  10655. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  10656. this.handleTickRangeOptions();
  10657. },
  10658. getTickLimit: function() {
  10659. var maxTicks;
  10660. var me = this;
  10661. var tickOpts = me.options.ticks;
  10662. if (me.isHorizontal()) {
  10663. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  10664. } else {
  10665. // The factor of 2 used to scale the font size has been experimentally determined.
  10666. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
  10667. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  10668. }
  10669. return maxTicks;
  10670. },
  10671. // Called after the ticks are built. We need
  10672. handleDirectionalChanges: function() {
  10673. if (!this.isHorizontal()) {
  10674. // We are in a vertical orientation. The top value is the highest. So reverse the array
  10675. this.ticks.reverse();
  10676. }
  10677. },
  10678. getLabelForIndex: function(index, datasetIndex) {
  10679. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  10680. },
  10681. // Utils
  10682. getPixelForValue: function(value) {
  10683. // This must be called after fit has been run so that
  10684. // this.left, this.top, this.right, and this.bottom have been defined
  10685. var me = this;
  10686. var start = me.start;
  10687. var rightValue = +me.getRightValue(value);
  10688. var pixel;
  10689. var range = me.end - start;
  10690. if (me.isHorizontal()) {
  10691. pixel = me.left + (me.width / range * (rightValue - start));
  10692. } else {
  10693. pixel = me.bottom - (me.height / range * (rightValue - start));
  10694. }
  10695. return pixel;
  10696. },
  10697. getValueForPixel: function(pixel) {
  10698. var me = this;
  10699. var isHorizontal = me.isHorizontal();
  10700. var innerDimension = isHorizontal ? me.width : me.height;
  10701. var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
  10702. return me.start + ((me.end - me.start) * offset);
  10703. },
  10704. getPixelForTick: function(index) {
  10705. return this.getPixelForValue(this.ticksAsNumbers[index]);
  10706. }
  10707. });
  10708. scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  10709. };
  10710. },{"26":26,"34":34,"35":35,"46":46}],56:[function(require,module,exports){
  10711. 'use strict';
  10712. var helpers = require(46);
  10713. var Scale = require(33);
  10714. /**
  10715. * Generate a set of linear ticks
  10716. * @param generationOptions the options used to generate the ticks
  10717. * @param dataRange the range of the data
  10718. * @returns {Array<Number>} array of tick values
  10719. */
  10720. function generateTicks(generationOptions, dataRange) {
  10721. var ticks = [];
  10722. // To get a "nice" value for the tick spacing, we will use the appropriately named
  10723. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  10724. // for details.
  10725. var factor;
  10726. var precision;
  10727. var spacing;
  10728. if (generationOptions.stepSize && generationOptions.stepSize > 0) {
  10729. spacing = generationOptions.stepSize;
  10730. } else {
  10731. var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
  10732. spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
  10733. precision = generationOptions.precision;
  10734. if (precision !== undefined) {
  10735. // If the user specified a precision, round to that number of decimal places
  10736. factor = Math.pow(10, precision);
  10737. spacing = Math.ceil(spacing * factor) / factor;
  10738. }
  10739. }
  10740. var niceMin = Math.floor(dataRange.min / spacing) * spacing;
  10741. var niceMax = Math.ceil(dataRange.max / spacing) * spacing;
  10742. // If min, max and stepSize is set and they make an evenly spaced scale use it.
  10743. if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && generationOptions.stepSize) {
  10744. // If very close to our whole number, use it.
  10745. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
  10746. niceMin = generationOptions.min;
  10747. niceMax = generationOptions.max;
  10748. }
  10749. }
  10750. var numSpaces = (niceMax - niceMin) / spacing;
  10751. // If very close to our rounded value, use it.
  10752. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  10753. numSpaces = Math.round(numSpaces);
  10754. } else {
  10755. numSpaces = Math.ceil(numSpaces);
  10756. }
  10757. precision = 1;
  10758. if (spacing < 1) {
  10759. precision = Math.pow(10, 1 - Math.floor(helpers.log10(spacing)));
  10760. niceMin = Math.round(niceMin * precision) / precision;
  10761. niceMax = Math.round(niceMax * precision) / precision;
  10762. }
  10763. ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
  10764. for (var j = 1; j < numSpaces; ++j) {
  10765. ticks.push(Math.round((niceMin + j * spacing) * precision) / precision);
  10766. }
  10767. ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);
  10768. return ticks;
  10769. }
  10770. module.exports = function(Chart) {
  10771. var noop = helpers.noop;
  10772. Chart.LinearScaleBase = Scale.extend({
  10773. getRightValue: function(value) {
  10774. if (typeof value === 'string') {
  10775. return +value;
  10776. }
  10777. return Scale.prototype.getRightValue.call(this, value);
  10778. },
  10779. handleTickRangeOptions: function() {
  10780. var me = this;
  10781. var opts = me.options;
  10782. var tickOpts = opts.ticks;
  10783. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  10784. // do nothing since that would make the chart weird. If the user really wants a weird chart
  10785. // axis, they can manually override it
  10786. if (tickOpts.beginAtZero) {
  10787. var minSign = helpers.sign(me.min);
  10788. var maxSign = helpers.sign(me.max);
  10789. if (minSign < 0 && maxSign < 0) {
  10790. // move the top up to 0
  10791. me.max = 0;
  10792. } else if (minSign > 0 && maxSign > 0) {
  10793. // move the bottom down to 0
  10794. me.min = 0;
  10795. }
  10796. }
  10797. var setMin = tickOpts.min !== undefined || tickOpts.suggestedMin !== undefined;
  10798. var setMax = tickOpts.max !== undefined || tickOpts.suggestedMax !== undefined;
  10799. if (tickOpts.min !== undefined) {
  10800. me.min = tickOpts.min;
  10801. } else if (tickOpts.suggestedMin !== undefined) {
  10802. if (me.min === null) {
  10803. me.min = tickOpts.suggestedMin;
  10804. } else {
  10805. me.min = Math.min(me.min, tickOpts.suggestedMin);
  10806. }
  10807. }
  10808. if (tickOpts.max !== undefined) {
  10809. me.max = tickOpts.max;
  10810. } else if (tickOpts.suggestedMax !== undefined) {
  10811. if (me.max === null) {
  10812. me.max = tickOpts.suggestedMax;
  10813. } else {
  10814. me.max = Math.max(me.max, tickOpts.suggestedMax);
  10815. }
  10816. }
  10817. if (setMin !== setMax) {
  10818. // We set the min or the max but not both.
  10819. // So ensure that our range is good
  10820. // Inverted or 0 length range can happen when
  10821. // ticks.min is set, and no datasets are visible
  10822. if (me.min >= me.max) {
  10823. if (setMin) {
  10824. me.max = me.min + 1;
  10825. } else {
  10826. me.min = me.max - 1;
  10827. }
  10828. }
  10829. }
  10830. if (me.min === me.max) {
  10831. me.max++;
  10832. if (!tickOpts.beginAtZero) {
  10833. me.min--;
  10834. }
  10835. }
  10836. },
  10837. getTickLimit: noop,
  10838. handleDirectionalChanges: noop,
  10839. buildTicks: function() {
  10840. var me = this;
  10841. var opts = me.options;
  10842. var tickOpts = opts.ticks;
  10843. // Figure out what the max number of ticks we can support it is based on the size of
  10844. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  10845. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  10846. // the graph. Make sure we always have at least 2 ticks
  10847. var maxTicks = me.getTickLimit();
  10848. maxTicks = Math.max(2, maxTicks);
  10849. var numericGeneratorOptions = {
  10850. maxTicks: maxTicks,
  10851. min: tickOpts.min,
  10852. max: tickOpts.max,
  10853. precision: tickOpts.precision,
  10854. stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
  10855. };
  10856. var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
  10857. me.handleDirectionalChanges();
  10858. // At this point, we need to update our max and min given the tick values since we have expanded the
  10859. // range of the scale
  10860. me.max = helpers.max(ticks);
  10861. me.min = helpers.min(ticks);
  10862. if (tickOpts.reverse) {
  10863. ticks.reverse();
  10864. me.start = me.max;
  10865. me.end = me.min;
  10866. } else {
  10867. me.start = me.min;
  10868. me.end = me.max;
  10869. }
  10870. },
  10871. convertTicksToLabels: function() {
  10872. var me = this;
  10873. me.ticksAsNumbers = me.ticks.slice();
  10874. me.zeroLineIndex = me.ticks.indexOf(0);
  10875. Scale.prototype.convertTicksToLabels.call(me);
  10876. }
  10877. });
  10878. };
  10879. },{"33":33,"46":46}],57:[function(require,module,exports){
  10880. 'use strict';
  10881. var helpers = require(46);
  10882. var Scale = require(33);
  10883. var scaleService = require(34);
  10884. var Ticks = require(35);
  10885. /**
  10886. * Generate a set of logarithmic ticks
  10887. * @param generationOptions the options used to generate the ticks
  10888. * @param dataRange the range of the data
  10889. * @returns {Array<Number>} array of tick values
  10890. */
  10891. function generateTicks(generationOptions, dataRange) {
  10892. var ticks = [];
  10893. var valueOrDefault = helpers.valueOrDefault;
  10894. // Figure out what the max number of ticks we can support it is based on the size of
  10895. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  10896. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  10897. // the graph
  10898. var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
  10899. var endExp = Math.floor(helpers.log10(dataRange.max));
  10900. var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
  10901. var exp, significand;
  10902. if (tickVal === 0) {
  10903. exp = Math.floor(helpers.log10(dataRange.minNotZero));
  10904. significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
  10905. ticks.push(tickVal);
  10906. tickVal = significand * Math.pow(10, exp);
  10907. } else {
  10908. exp = Math.floor(helpers.log10(tickVal));
  10909. significand = Math.floor(tickVal / Math.pow(10, exp));
  10910. }
  10911. var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
  10912. do {
  10913. ticks.push(tickVal);
  10914. ++significand;
  10915. if (significand === 10) {
  10916. significand = 1;
  10917. ++exp;
  10918. precision = exp >= 0 ? 1 : precision;
  10919. }
  10920. tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
  10921. } while (exp < endExp || (exp === endExp && significand < endSignificand));
  10922. var lastTick = valueOrDefault(generationOptions.max, tickVal);
  10923. ticks.push(lastTick);
  10924. return ticks;
  10925. }
  10926. module.exports = function(Chart) {
  10927. var defaultConfig = {
  10928. position: 'left',
  10929. // label settings
  10930. ticks: {
  10931. callback: Ticks.formatters.logarithmic
  10932. }
  10933. };
  10934. var LogarithmicScale = Scale.extend({
  10935. determineDataLimits: function() {
  10936. var me = this;
  10937. var opts = me.options;
  10938. var chart = me.chart;
  10939. var data = chart.data;
  10940. var datasets = data.datasets;
  10941. var isHorizontal = me.isHorizontal();
  10942. function IDMatches(meta) {
  10943. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10944. }
  10945. // Calculate Range
  10946. me.min = null;
  10947. me.max = null;
  10948. me.minNotZero = null;
  10949. var hasStacks = opts.stacked;
  10950. if (hasStacks === undefined) {
  10951. helpers.each(datasets, function(dataset, datasetIndex) {
  10952. if (hasStacks) {
  10953. return;
  10954. }
  10955. var meta = chart.getDatasetMeta(datasetIndex);
  10956. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10957. meta.stack !== undefined) {
  10958. hasStacks = true;
  10959. }
  10960. });
  10961. }
  10962. if (opts.stacked || hasStacks) {
  10963. var valuesPerStack = {};
  10964. helpers.each(datasets, function(dataset, datasetIndex) {
  10965. var meta = chart.getDatasetMeta(datasetIndex);
  10966. var key = [
  10967. meta.type,
  10968. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10969. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10970. meta.stack
  10971. ].join('.');
  10972. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10973. if (valuesPerStack[key] === undefined) {
  10974. valuesPerStack[key] = [];
  10975. }
  10976. helpers.each(dataset.data, function(rawValue, index) {
  10977. var values = valuesPerStack[key];
  10978. var value = +me.getRightValue(rawValue);
  10979. // invalid, hidden and negative values are ignored
  10980. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  10981. return;
  10982. }
  10983. values[index] = values[index] || 0;
  10984. values[index] += value;
  10985. });
  10986. }
  10987. });
  10988. helpers.each(valuesPerStack, function(valuesForType) {
  10989. if (valuesForType.length > 0) {
  10990. var minVal = helpers.min(valuesForType);
  10991. var maxVal = helpers.max(valuesForType);
  10992. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  10993. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  10994. }
  10995. });
  10996. } else {
  10997. helpers.each(datasets, function(dataset, datasetIndex) {
  10998. var meta = chart.getDatasetMeta(datasetIndex);
  10999. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11000. helpers.each(dataset.data, function(rawValue, index) {
  11001. var value = +me.getRightValue(rawValue);
  11002. // invalid, hidden and negative values are ignored
  11003. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  11004. return;
  11005. }
  11006. if (me.min === null) {
  11007. me.min = value;
  11008. } else if (value < me.min) {
  11009. me.min = value;
  11010. }
  11011. if (me.max === null) {
  11012. me.max = value;
  11013. } else if (value > me.max) {
  11014. me.max = value;
  11015. }
  11016. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  11017. me.minNotZero = value;
  11018. }
  11019. });
  11020. }
  11021. });
  11022. }
  11023. // Common base implementation to handle ticks.min, ticks.max
  11024. this.handleTickRangeOptions();
  11025. },
  11026. handleTickRangeOptions: function() {
  11027. var me = this;
  11028. var opts = me.options;
  11029. var tickOpts = opts.ticks;
  11030. var valueOrDefault = helpers.valueOrDefault;
  11031. var DEFAULT_MIN = 1;
  11032. var DEFAULT_MAX = 10;
  11033. me.min = valueOrDefault(tickOpts.min, me.min);
  11034. me.max = valueOrDefault(tickOpts.max, me.max);
  11035. if (me.min === me.max) {
  11036. if (me.min !== 0 && me.min !== null) {
  11037. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  11038. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  11039. } else {
  11040. me.min = DEFAULT_MIN;
  11041. me.max = DEFAULT_MAX;
  11042. }
  11043. }
  11044. if (me.min === null) {
  11045. me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
  11046. }
  11047. if (me.max === null) {
  11048. me.max = me.min !== 0
  11049. ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
  11050. : DEFAULT_MAX;
  11051. }
  11052. if (me.minNotZero === null) {
  11053. if (me.min > 0) {
  11054. me.minNotZero = me.min;
  11055. } else if (me.max < 1) {
  11056. me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
  11057. } else {
  11058. me.minNotZero = DEFAULT_MIN;
  11059. }
  11060. }
  11061. },
  11062. buildTicks: function() {
  11063. var me = this;
  11064. var opts = me.options;
  11065. var tickOpts = opts.ticks;
  11066. var reverse = !me.isHorizontal();
  11067. var generationOptions = {
  11068. min: tickOpts.min,
  11069. max: tickOpts.max
  11070. };
  11071. var ticks = me.ticks = generateTicks(generationOptions, me);
  11072. // At this point, we need to update our max and min given the tick values since we have expanded the
  11073. // range of the scale
  11074. me.max = helpers.max(ticks);
  11075. me.min = helpers.min(ticks);
  11076. if (tickOpts.reverse) {
  11077. reverse = !reverse;
  11078. me.start = me.max;
  11079. me.end = me.min;
  11080. } else {
  11081. me.start = me.min;
  11082. me.end = me.max;
  11083. }
  11084. if (reverse) {
  11085. ticks.reverse();
  11086. }
  11087. },
  11088. convertTicksToLabels: function() {
  11089. this.tickValues = this.ticks.slice();
  11090. Scale.prototype.convertTicksToLabels.call(this);
  11091. },
  11092. // Get the correct tooltip label
  11093. getLabelForIndex: function(index, datasetIndex) {
  11094. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11095. },
  11096. getPixelForTick: function(index) {
  11097. return this.getPixelForValue(this.tickValues[index]);
  11098. },
  11099. /**
  11100. * Returns the value of the first tick.
  11101. * @param {Number} value - The minimum not zero value.
  11102. * @return {Number} The first tick value.
  11103. * @private
  11104. */
  11105. _getFirstTickValue: function(value) {
  11106. var exp = Math.floor(helpers.log10(value));
  11107. var significand = Math.floor(value / Math.pow(10, exp));
  11108. return significand * Math.pow(10, exp);
  11109. },
  11110. getPixelForValue: function(value) {
  11111. var me = this;
  11112. var reverse = me.options.ticks.reverse;
  11113. var log10 = helpers.log10;
  11114. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11115. var offset = 0;
  11116. var innerDimension, pixel, start, end, sign;
  11117. value = +me.getRightValue(value);
  11118. if (reverse) {
  11119. start = me.end;
  11120. end = me.start;
  11121. sign = -1;
  11122. } else {
  11123. start = me.start;
  11124. end = me.end;
  11125. sign = 1;
  11126. }
  11127. if (me.isHorizontal()) {
  11128. innerDimension = me.width;
  11129. pixel = reverse ? me.right : me.left;
  11130. } else {
  11131. innerDimension = me.height;
  11132. sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
  11133. pixel = reverse ? me.top : me.bottom;
  11134. }
  11135. if (value !== start) {
  11136. if (start === 0) { // include zero tick
  11137. offset = helpers.getValueOrDefault(
  11138. me.options.ticks.fontSize,
  11139. Chart.defaults.global.defaultFontSize
  11140. );
  11141. innerDimension -= offset;
  11142. start = firstTickValue;
  11143. }
  11144. if (value !== 0) {
  11145. offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
  11146. }
  11147. pixel += sign * offset;
  11148. }
  11149. return pixel;
  11150. },
  11151. getValueForPixel: function(pixel) {
  11152. var me = this;
  11153. var reverse = me.options.ticks.reverse;
  11154. var log10 = helpers.log10;
  11155. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11156. var innerDimension, start, end, value;
  11157. if (reverse) {
  11158. start = me.end;
  11159. end = me.start;
  11160. } else {
  11161. start = me.start;
  11162. end = me.end;
  11163. }
  11164. if (me.isHorizontal()) {
  11165. innerDimension = me.width;
  11166. value = reverse ? me.right - pixel : pixel - me.left;
  11167. } else {
  11168. innerDimension = me.height;
  11169. value = reverse ? pixel - me.top : me.bottom - pixel;
  11170. }
  11171. if (value !== start) {
  11172. if (start === 0) { // include zero tick
  11173. var offset = helpers.getValueOrDefault(
  11174. me.options.ticks.fontSize,
  11175. Chart.defaults.global.defaultFontSize
  11176. );
  11177. value -= offset;
  11178. innerDimension -= offset;
  11179. start = firstTickValue;
  11180. }
  11181. value *= log10(end) - log10(start);
  11182. value /= innerDimension;
  11183. value = Math.pow(10, log10(start) + value);
  11184. }
  11185. return value;
  11186. }
  11187. });
  11188. scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  11189. };
  11190. },{"33":33,"34":34,"35":35,"46":46}],58:[function(require,module,exports){
  11191. 'use strict';
  11192. var defaults = require(26);
  11193. var helpers = require(46);
  11194. var scaleService = require(34);
  11195. var Ticks = require(35);
  11196. module.exports = function(Chart) {
  11197. var globalDefaults = defaults.global;
  11198. var defaultConfig = {
  11199. display: true,
  11200. // Boolean - Whether to animate scaling the chart from the centre
  11201. animate: true,
  11202. position: 'chartArea',
  11203. angleLines: {
  11204. display: true,
  11205. color: 'rgba(0, 0, 0, 0.1)',
  11206. lineWidth: 1
  11207. },
  11208. gridLines: {
  11209. circular: false
  11210. },
  11211. // label settings
  11212. ticks: {
  11213. // Boolean - Show a backdrop to the scale label
  11214. showLabelBackdrop: true,
  11215. // String - The colour of the label backdrop
  11216. backdropColor: 'rgba(255,255,255,0.75)',
  11217. // Number - The backdrop padding above & below the label in pixels
  11218. backdropPaddingY: 2,
  11219. // Number - The backdrop padding to the side of the label in pixels
  11220. backdropPaddingX: 2,
  11221. callback: Ticks.formatters.linear
  11222. },
  11223. pointLabels: {
  11224. // Boolean - if true, show point labels
  11225. display: true,
  11226. // Number - Point label font size in pixels
  11227. fontSize: 10,
  11228. // Function - Used to convert point labels
  11229. callback: function(label) {
  11230. return label;
  11231. }
  11232. }
  11233. };
  11234. function getValueCount(scale) {
  11235. var opts = scale.options;
  11236. return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
  11237. }
  11238. function getPointLabelFontOptions(scale) {
  11239. var pointLabelOptions = scale.options.pointLabels;
  11240. var fontSize = helpers.valueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
  11241. var fontStyle = helpers.valueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
  11242. var fontFamily = helpers.valueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
  11243. var font = helpers.fontString(fontSize, fontStyle, fontFamily);
  11244. return {
  11245. size: fontSize,
  11246. style: fontStyle,
  11247. family: fontFamily,
  11248. font: font
  11249. };
  11250. }
  11251. function measureLabelSize(ctx, fontSize, label) {
  11252. if (helpers.isArray(label)) {
  11253. return {
  11254. w: helpers.longestText(ctx, ctx.font, label),
  11255. h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
  11256. };
  11257. }
  11258. return {
  11259. w: ctx.measureText(label).width,
  11260. h: fontSize
  11261. };
  11262. }
  11263. function determineLimits(angle, pos, size, min, max) {
  11264. if (angle === min || angle === max) {
  11265. return {
  11266. start: pos - (size / 2),
  11267. end: pos + (size / 2)
  11268. };
  11269. } else if (angle < min || angle > max) {
  11270. return {
  11271. start: pos - size - 5,
  11272. end: pos
  11273. };
  11274. }
  11275. return {
  11276. start: pos,
  11277. end: pos + size + 5
  11278. };
  11279. }
  11280. /**
  11281. * Helper function to fit a radial linear scale with point labels
  11282. */
  11283. function fitWithPointLabels(scale) {
  11284. /*
  11285. * Right, this is really confusing and there is a lot of maths going on here
  11286. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  11287. *
  11288. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  11289. *
  11290. * Solution:
  11291. *
  11292. * We assume the radius of the polygon is half the size of the canvas at first
  11293. * at each index we check if the text overlaps.
  11294. *
  11295. * Where it does, we store that angle and that index.
  11296. *
  11297. * After finding the largest index and angle we calculate how much we need to remove
  11298. * from the shape radius to move the point inwards by that x.
  11299. *
  11300. * We average the left and right distances to get the maximum shape radius that can fit in the box
  11301. * along with labels.
  11302. *
  11303. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  11304. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  11305. *
  11306. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  11307. * and position it in the most space efficient manner
  11308. *
  11309. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  11310. */
  11311. var plFont = getPointLabelFontOptions(scale);
  11312. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  11313. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  11314. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11315. var furthestLimits = {
  11316. r: scale.width,
  11317. l: 0,
  11318. t: scale.height,
  11319. b: 0
  11320. };
  11321. var furthestAngles = {};
  11322. var i, textSize, pointPosition;
  11323. scale.ctx.font = plFont.font;
  11324. scale._pointLabelSizes = [];
  11325. var valueCount = getValueCount(scale);
  11326. for (i = 0; i < valueCount; i++) {
  11327. pointPosition = scale.getPointPosition(i, largestPossibleRadius);
  11328. textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
  11329. scale._pointLabelSizes[i] = textSize;
  11330. // Add quarter circle to make degree 0 mean top of circle
  11331. var angleRadians = scale.getIndexAngle(i);
  11332. var angle = helpers.toDegrees(angleRadians) % 360;
  11333. var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
  11334. var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
  11335. if (hLimits.start < furthestLimits.l) {
  11336. furthestLimits.l = hLimits.start;
  11337. furthestAngles.l = angleRadians;
  11338. }
  11339. if (hLimits.end > furthestLimits.r) {
  11340. furthestLimits.r = hLimits.end;
  11341. furthestAngles.r = angleRadians;
  11342. }
  11343. if (vLimits.start < furthestLimits.t) {
  11344. furthestLimits.t = vLimits.start;
  11345. furthestAngles.t = angleRadians;
  11346. }
  11347. if (vLimits.end > furthestLimits.b) {
  11348. furthestLimits.b = vLimits.end;
  11349. furthestAngles.b = angleRadians;
  11350. }
  11351. }
  11352. scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
  11353. }
  11354. /**
  11355. * Helper function to fit a radial linear scale with no point labels
  11356. */
  11357. function fit(scale) {
  11358. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11359. scale.drawingArea = Math.round(largestPossibleRadius);
  11360. scale.setCenterPoint(0, 0, 0, 0);
  11361. }
  11362. function getTextAlignForAngle(angle) {
  11363. if (angle === 0 || angle === 180) {
  11364. return 'center';
  11365. } else if (angle < 180) {
  11366. return 'left';
  11367. }
  11368. return 'right';
  11369. }
  11370. function fillText(ctx, text, position, fontSize) {
  11371. if (helpers.isArray(text)) {
  11372. var y = position.y;
  11373. var spacing = 1.5 * fontSize;
  11374. for (var i = 0; i < text.length; ++i) {
  11375. ctx.fillText(text[i], position.x, y);
  11376. y += spacing;
  11377. }
  11378. } else {
  11379. ctx.fillText(text, position.x, position.y);
  11380. }
  11381. }
  11382. function adjustPointPositionForLabelHeight(angle, textSize, position) {
  11383. if (angle === 90 || angle === 270) {
  11384. position.y -= (textSize.h / 2);
  11385. } else if (angle > 270 || angle < 90) {
  11386. position.y -= textSize.h;
  11387. }
  11388. }
  11389. function drawPointLabels(scale) {
  11390. var ctx = scale.ctx;
  11391. var opts = scale.options;
  11392. var angleLineOpts = opts.angleLines;
  11393. var pointLabelOpts = opts.pointLabels;
  11394. ctx.lineWidth = angleLineOpts.lineWidth;
  11395. ctx.strokeStyle = angleLineOpts.color;
  11396. var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
  11397. // Point Label Font
  11398. var plFont = getPointLabelFontOptions(scale);
  11399. ctx.textBaseline = 'top';
  11400. for (var i = getValueCount(scale) - 1; i >= 0; i--) {
  11401. if (angleLineOpts.display) {
  11402. var outerPosition = scale.getPointPosition(i, outerDistance);
  11403. ctx.beginPath();
  11404. ctx.moveTo(scale.xCenter, scale.yCenter);
  11405. ctx.lineTo(outerPosition.x, outerPosition.y);
  11406. ctx.stroke();
  11407. ctx.closePath();
  11408. }
  11409. if (pointLabelOpts.display) {
  11410. // Extra 3px out for some label spacing
  11411. var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
  11412. // Keep this in loop since we may support array properties here
  11413. var pointLabelFontColor = helpers.valueAtIndexOrDefault(pointLabelOpts.fontColor, i, globalDefaults.defaultFontColor);
  11414. ctx.font = plFont.font;
  11415. ctx.fillStyle = pointLabelFontColor;
  11416. var angleRadians = scale.getIndexAngle(i);
  11417. var angle = helpers.toDegrees(angleRadians);
  11418. ctx.textAlign = getTextAlignForAngle(angle);
  11419. adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
  11420. fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
  11421. }
  11422. }
  11423. }
  11424. function drawRadiusLine(scale, gridLineOpts, radius, index) {
  11425. var ctx = scale.ctx;
  11426. ctx.strokeStyle = helpers.valueAtIndexOrDefault(gridLineOpts.color, index - 1);
  11427. ctx.lineWidth = helpers.valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  11428. if (scale.options.gridLines.circular) {
  11429. // Draw circular arcs between the points
  11430. ctx.beginPath();
  11431. ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
  11432. ctx.closePath();
  11433. ctx.stroke();
  11434. } else {
  11435. // Draw straight lines connecting each index
  11436. var valueCount = getValueCount(scale);
  11437. if (valueCount === 0) {
  11438. return;
  11439. }
  11440. ctx.beginPath();
  11441. var pointPosition = scale.getPointPosition(0, radius);
  11442. ctx.moveTo(pointPosition.x, pointPosition.y);
  11443. for (var i = 1; i < valueCount; i++) {
  11444. pointPosition = scale.getPointPosition(i, radius);
  11445. ctx.lineTo(pointPosition.x, pointPosition.y);
  11446. }
  11447. ctx.closePath();
  11448. ctx.stroke();
  11449. }
  11450. }
  11451. function numberOrZero(param) {
  11452. return helpers.isNumber(param) ? param : 0;
  11453. }
  11454. var LinearRadialScale = Chart.LinearScaleBase.extend({
  11455. setDimensions: function() {
  11456. var me = this;
  11457. var opts = me.options;
  11458. var tickOpts = opts.ticks;
  11459. // Set the unconstrained dimension before label rotation
  11460. me.width = me.maxWidth;
  11461. me.height = me.maxHeight;
  11462. me.xCenter = Math.round(me.width / 2);
  11463. me.yCenter = Math.round(me.height / 2);
  11464. var minSize = helpers.min([me.height, me.width]);
  11465. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11466. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  11467. },
  11468. determineDataLimits: function() {
  11469. var me = this;
  11470. var chart = me.chart;
  11471. var min = Number.POSITIVE_INFINITY;
  11472. var max = Number.NEGATIVE_INFINITY;
  11473. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  11474. if (chart.isDatasetVisible(datasetIndex)) {
  11475. var meta = chart.getDatasetMeta(datasetIndex);
  11476. helpers.each(dataset.data, function(rawValue, index) {
  11477. var value = +me.getRightValue(rawValue);
  11478. if (isNaN(value) || meta.data[index].hidden) {
  11479. return;
  11480. }
  11481. min = Math.min(value, min);
  11482. max = Math.max(value, max);
  11483. });
  11484. }
  11485. });
  11486. me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
  11487. me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
  11488. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  11489. me.handleTickRangeOptions();
  11490. },
  11491. getTickLimit: function() {
  11492. var tickOpts = this.options.ticks;
  11493. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11494. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  11495. },
  11496. convertTicksToLabels: function() {
  11497. var me = this;
  11498. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  11499. // Point labels
  11500. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  11501. },
  11502. getLabelForIndex: function(index, datasetIndex) {
  11503. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11504. },
  11505. fit: function() {
  11506. if (this.options.pointLabels.display) {
  11507. fitWithPointLabels(this);
  11508. } else {
  11509. fit(this);
  11510. }
  11511. },
  11512. /**
  11513. * Set radius reductions and determine new radius and center point
  11514. * @private
  11515. */
  11516. setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
  11517. var me = this;
  11518. var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
  11519. var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
  11520. var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
  11521. var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
  11522. radiusReductionLeft = numberOrZero(radiusReductionLeft);
  11523. radiusReductionRight = numberOrZero(radiusReductionRight);
  11524. radiusReductionTop = numberOrZero(radiusReductionTop);
  11525. radiusReductionBottom = numberOrZero(radiusReductionBottom);
  11526. me.drawingArea = Math.min(
  11527. Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
  11528. Math.round(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
  11529. me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
  11530. },
  11531. setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
  11532. var me = this;
  11533. var maxRight = me.width - rightMovement - me.drawingArea;
  11534. var maxLeft = leftMovement + me.drawingArea;
  11535. var maxTop = topMovement + me.drawingArea;
  11536. var maxBottom = me.height - bottomMovement - me.drawingArea;
  11537. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  11538. me.yCenter = Math.round(((maxTop + maxBottom) / 2) + me.top);
  11539. },
  11540. getIndexAngle: function(index) {
  11541. var angleMultiplier = (Math.PI * 2) / getValueCount(this);
  11542. var startAngle = this.chart.options && this.chart.options.startAngle ?
  11543. this.chart.options.startAngle :
  11544. 0;
  11545. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  11546. // Start from the top instead of right, so remove a quarter of the circle
  11547. return index * angleMultiplier + startAngleRadians;
  11548. },
  11549. getDistanceFromCenterForValue: function(value) {
  11550. var me = this;
  11551. if (value === null) {
  11552. return 0; // null always in center
  11553. }
  11554. // Take into account half font size + the yPadding of the top value
  11555. var scalingFactor = me.drawingArea / (me.max - me.min);
  11556. if (me.options.ticks.reverse) {
  11557. return (me.max - value) * scalingFactor;
  11558. }
  11559. return (value - me.min) * scalingFactor;
  11560. },
  11561. getPointPosition: function(index, distanceFromCenter) {
  11562. var me = this;
  11563. var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
  11564. return {
  11565. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  11566. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  11567. };
  11568. },
  11569. getPointPositionForValue: function(index, value) {
  11570. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  11571. },
  11572. getBasePosition: function() {
  11573. var me = this;
  11574. var min = me.min;
  11575. var max = me.max;
  11576. return me.getPointPositionForValue(0,
  11577. me.beginAtZero ? 0 :
  11578. min < 0 && max < 0 ? max :
  11579. min > 0 && max > 0 ? min :
  11580. 0);
  11581. },
  11582. draw: function() {
  11583. var me = this;
  11584. var opts = me.options;
  11585. var gridLineOpts = opts.gridLines;
  11586. var tickOpts = opts.ticks;
  11587. var valueOrDefault = helpers.valueOrDefault;
  11588. if (opts.display) {
  11589. var ctx = me.ctx;
  11590. var startAngle = this.getIndexAngle(0);
  11591. // Tick Font
  11592. var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11593. var tickFontStyle = valueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  11594. var tickFontFamily = valueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  11595. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  11596. helpers.each(me.ticks, function(label, index) {
  11597. // Don't draw a centre value (if it is minimum)
  11598. if (index > 0 || tickOpts.reverse) {
  11599. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  11600. // Draw circular lines around the scale
  11601. if (gridLineOpts.display && index !== 0) {
  11602. drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
  11603. }
  11604. if (tickOpts.display) {
  11605. var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  11606. ctx.font = tickLabelFont;
  11607. ctx.save();
  11608. ctx.translate(me.xCenter, me.yCenter);
  11609. ctx.rotate(startAngle);
  11610. if (tickOpts.showLabelBackdrop) {
  11611. var labelWidth = ctx.measureText(label).width;
  11612. ctx.fillStyle = tickOpts.backdropColor;
  11613. ctx.fillRect(
  11614. -labelWidth / 2 - tickOpts.backdropPaddingX,
  11615. -yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
  11616. labelWidth + tickOpts.backdropPaddingX * 2,
  11617. tickFontSize + tickOpts.backdropPaddingY * 2
  11618. );
  11619. }
  11620. ctx.textAlign = 'center';
  11621. ctx.textBaseline = 'middle';
  11622. ctx.fillStyle = tickFontColor;
  11623. ctx.fillText(label, 0, -yCenterOffset);
  11624. ctx.restore();
  11625. }
  11626. }
  11627. });
  11628. if (opts.angleLines.display || opts.pointLabels.display) {
  11629. drawPointLabels(me);
  11630. }
  11631. }
  11632. }
  11633. });
  11634. scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  11635. };
  11636. },{"26":26,"34":34,"35":35,"46":46}],59:[function(require,module,exports){
  11637. /* global window: false */
  11638. 'use strict';
  11639. var moment = require(1);
  11640. moment = typeof moment === 'function' ? moment : window.moment;
  11641. var defaults = require(26);
  11642. var helpers = require(46);
  11643. var Scale = require(33);
  11644. var scaleService = require(34);
  11645. // Integer constants are from the ES6 spec.
  11646. var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
  11647. var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  11648. var INTERVALS = {
  11649. millisecond: {
  11650. common: true,
  11651. size: 1,
  11652. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  11653. },
  11654. second: {
  11655. common: true,
  11656. size: 1000,
  11657. steps: [1, 2, 5, 10, 15, 30]
  11658. },
  11659. minute: {
  11660. common: true,
  11661. size: 60000,
  11662. steps: [1, 2, 5, 10, 15, 30]
  11663. },
  11664. hour: {
  11665. common: true,
  11666. size: 3600000,
  11667. steps: [1, 2, 3, 6, 12]
  11668. },
  11669. day: {
  11670. common: true,
  11671. size: 86400000,
  11672. steps: [1, 2, 5]
  11673. },
  11674. week: {
  11675. common: false,
  11676. size: 604800000,
  11677. steps: [1, 2, 3, 4]
  11678. },
  11679. month: {
  11680. common: true,
  11681. size: 2.628e9,
  11682. steps: [1, 2, 3]
  11683. },
  11684. quarter: {
  11685. common: false,
  11686. size: 7.884e9,
  11687. steps: [1, 2, 3, 4]
  11688. },
  11689. year: {
  11690. common: true,
  11691. size: 3.154e10
  11692. }
  11693. };
  11694. var UNITS = Object.keys(INTERVALS);
  11695. function sorter(a, b) {
  11696. return a - b;
  11697. }
  11698. function arrayUnique(items) {
  11699. var hash = {};
  11700. var out = [];
  11701. var i, ilen, item;
  11702. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11703. item = items[i];
  11704. if (!hash[item]) {
  11705. hash[item] = true;
  11706. out.push(item);
  11707. }
  11708. }
  11709. return out;
  11710. }
  11711. /**
  11712. * Returns an array of {time, pos} objects used to interpolate a specific `time` or position
  11713. * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
  11714. * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other
  11715. * extremity (left + width or top + height). Note that it would be more optimized to directly
  11716. * store pre-computed pixels, but the scale dimensions are not guaranteed at the time we need
  11717. * to create the lookup table. The table ALWAYS contains at least two items: min and max.
  11718. *
  11719. * @param {Number[]} timestamps - timestamps sorted from lowest to highest.
  11720. * @param {String} distribution - If 'linear', timestamps will be spread linearly along the min
  11721. * and max range, so basically, the table will contains only two items: {min, 0} and {max, 1}.
  11722. * If 'series', timestamps will be positioned at the same distance from each other. In this
  11723. * case, only timestamps that break the time linearity are registered, meaning that in the
  11724. * best case, all timestamps are linear, the table contains only min and max.
  11725. */
  11726. function buildLookupTable(timestamps, min, max, distribution) {
  11727. if (distribution === 'linear' || !timestamps.length) {
  11728. return [
  11729. {time: min, pos: 0},
  11730. {time: max, pos: 1}
  11731. ];
  11732. }
  11733. var table = [];
  11734. var items = [min];
  11735. var i, ilen, prev, curr, next;
  11736. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  11737. curr = timestamps[i];
  11738. if (curr > min && curr < max) {
  11739. items.push(curr);
  11740. }
  11741. }
  11742. items.push(max);
  11743. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11744. next = items[i + 1];
  11745. prev = items[i - 1];
  11746. curr = items[i];
  11747. // only add points that breaks the scale linearity
  11748. if (prev === undefined || next === undefined || Math.round((next + prev) / 2) !== curr) {
  11749. table.push({time: curr, pos: i / (ilen - 1)});
  11750. }
  11751. }
  11752. return table;
  11753. }
  11754. // @see adapted from http://www.anujgakhar.com/2014/03/01/binary-search-in-javascript/
  11755. function lookup(table, key, value) {
  11756. var lo = 0;
  11757. var hi = table.length - 1;
  11758. var mid, i0, i1;
  11759. while (lo >= 0 && lo <= hi) {
  11760. mid = (lo + hi) >> 1;
  11761. i0 = table[mid - 1] || null;
  11762. i1 = table[mid];
  11763. if (!i0) {
  11764. // given value is outside table (before first item)
  11765. return {lo: null, hi: i1};
  11766. } else if (i1[key] < value) {
  11767. lo = mid + 1;
  11768. } else if (i0[key] > value) {
  11769. hi = mid - 1;
  11770. } else {
  11771. return {lo: i0, hi: i1};
  11772. }
  11773. }
  11774. // given value is outside table (after last item)
  11775. return {lo: i1, hi: null};
  11776. }
  11777. /**
  11778. * Linearly interpolates the given source `value` using the table items `skey` values and
  11779. * returns the associated `tkey` value. For example, interpolate(table, 'time', 42, 'pos')
  11780. * returns the position for a timestamp equal to 42. If value is out of bounds, values at
  11781. * index [0, 1] or [n - 1, n] are used for the interpolation.
  11782. */
  11783. function interpolate(table, skey, sval, tkey) {
  11784. var range = lookup(table, skey, sval);
  11785. // Note: the lookup table ALWAYS contains at least 2 items (min and max)
  11786. var prev = !range.lo ? table[0] : !range.hi ? table[table.length - 2] : range.lo;
  11787. var next = !range.lo ? table[1] : !range.hi ? table[table.length - 1] : range.hi;
  11788. var span = next[skey] - prev[skey];
  11789. var ratio = span ? (sval - prev[skey]) / span : 0;
  11790. var offset = (next[tkey] - prev[tkey]) * ratio;
  11791. return prev[tkey] + offset;
  11792. }
  11793. /**
  11794. * Convert the given value to a moment object using the given time options.
  11795. * @see http://momentjs.com/docs/#/parsing/
  11796. */
  11797. function momentify(value, options) {
  11798. var parser = options.parser;
  11799. var format = options.parser || options.format;
  11800. if (typeof parser === 'function') {
  11801. return parser(value);
  11802. }
  11803. if (typeof value === 'string' && typeof format === 'string') {
  11804. return moment(value, format);
  11805. }
  11806. if (!(value instanceof moment)) {
  11807. value = moment(value);
  11808. }
  11809. if (value.isValid()) {
  11810. return value;
  11811. }
  11812. // Labels are in an incompatible moment format and no `parser` has been provided.
  11813. // The user might still use the deprecated `format` option to convert his inputs.
  11814. if (typeof format === 'function') {
  11815. return format(value);
  11816. }
  11817. return value;
  11818. }
  11819. function parse(input, scale) {
  11820. if (helpers.isNullOrUndef(input)) {
  11821. return null;
  11822. }
  11823. var options = scale.options.time;
  11824. var value = momentify(scale.getRightValue(input), options);
  11825. if (!value.isValid()) {
  11826. return null;
  11827. }
  11828. if (options.round) {
  11829. value.startOf(options.round);
  11830. }
  11831. return value.valueOf();
  11832. }
  11833. /**
  11834. * Returns the number of unit to skip to be able to display up to `capacity` number of ticks
  11835. * in `unit` for the given `min` / `max` range and respecting the interval steps constraints.
  11836. */
  11837. function determineStepSize(min, max, unit, capacity) {
  11838. var range = max - min;
  11839. var interval = INTERVALS[unit];
  11840. var milliseconds = interval.size;
  11841. var steps = interval.steps;
  11842. var i, ilen, factor;
  11843. if (!steps) {
  11844. return Math.ceil(range / (capacity * milliseconds));
  11845. }
  11846. for (i = 0, ilen = steps.length; i < ilen; ++i) {
  11847. factor = steps[i];
  11848. if (Math.ceil(range / (milliseconds * factor)) <= capacity) {
  11849. break;
  11850. }
  11851. }
  11852. return factor;
  11853. }
  11854. /**
  11855. * Figures out what unit results in an appropriate number of auto-generated ticks
  11856. */
  11857. function determineUnitForAutoTicks(minUnit, min, max, capacity) {
  11858. var ilen = UNITS.length;
  11859. var i, interval, factor;
  11860. for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
  11861. interval = INTERVALS[UNITS[i]];
  11862. factor = interval.steps ? interval.steps[interval.steps.length - 1] : MAX_INTEGER;
  11863. if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
  11864. return UNITS[i];
  11865. }
  11866. }
  11867. return UNITS[ilen - 1];
  11868. }
  11869. /**
  11870. * Figures out what unit to format a set of ticks with
  11871. */
  11872. function determineUnitForFormatting(ticks, minUnit, min, max) {
  11873. var duration = moment.duration(moment(max).diff(moment(min)));
  11874. var ilen = UNITS.length;
  11875. var i, unit;
  11876. for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
  11877. unit = UNITS[i];
  11878. if (INTERVALS[unit].common && duration.as(unit) >= ticks.length) {
  11879. return unit;
  11880. }
  11881. }
  11882. return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
  11883. }
  11884. function determineMajorUnit(unit) {
  11885. for (var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i) {
  11886. if (INTERVALS[UNITS[i]].common) {
  11887. return UNITS[i];
  11888. }
  11889. }
  11890. }
  11891. /**
  11892. * Generates a maximum of `capacity` timestamps between min and max, rounded to the
  11893. * `minor` unit, aligned on the `major` unit and using the given scale time `options`.
  11894. * Important: this method can return ticks outside the min and max range, it's the
  11895. * responsibility of the calling code to clamp values if needed.
  11896. */
  11897. function generate(min, max, capacity, options) {
  11898. var timeOpts = options.time;
  11899. var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, capacity);
  11900. var major = determineMajorUnit(minor);
  11901. var stepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
  11902. var weekday = minor === 'week' ? timeOpts.isoWeekday : false;
  11903. var majorTicksEnabled = options.ticks.major.enabled;
  11904. var interval = INTERVALS[minor];
  11905. var first = moment(min);
  11906. var last = moment(max);
  11907. var ticks = [];
  11908. var time;
  11909. if (!stepSize) {
  11910. stepSize = determineStepSize(min, max, minor, capacity);
  11911. }
  11912. // For 'week' unit, handle the first day of week option
  11913. if (weekday) {
  11914. first = first.isoWeekday(weekday);
  11915. last = last.isoWeekday(weekday);
  11916. }
  11917. // Align first/last ticks on unit
  11918. first = first.startOf(weekday ? 'day' : minor);
  11919. last = last.startOf(weekday ? 'day' : minor);
  11920. // Make sure that the last tick include max
  11921. if (last < max) {
  11922. last.add(1, minor);
  11923. }
  11924. time = moment(first);
  11925. if (majorTicksEnabled && major && !weekday && !timeOpts.round) {
  11926. // Align the first tick on the previous `minor` unit aligned on the `major` unit:
  11927. // we first aligned time on the previous `major` unit then add the number of full
  11928. // stepSize there is between first and the previous major time.
  11929. time.startOf(major);
  11930. time.add(~~((first - time) / (interval.size * stepSize)) * stepSize, minor);
  11931. }
  11932. for (; time < last; time.add(stepSize, minor)) {
  11933. ticks.push(+time);
  11934. }
  11935. ticks.push(+time);
  11936. return ticks;
  11937. }
  11938. /**
  11939. * Returns the right and left offsets from edges in the form of {left, right}.
  11940. * Offsets are added when the `offset` option is true.
  11941. */
  11942. function computeOffsets(table, ticks, min, max, options) {
  11943. var left = 0;
  11944. var right = 0;
  11945. var upper, lower;
  11946. if (options.offset && ticks.length) {
  11947. if (!options.time.min) {
  11948. upper = ticks.length > 1 ? ticks[1] : max;
  11949. lower = ticks[0];
  11950. left = (
  11951. interpolate(table, 'time', upper, 'pos') -
  11952. interpolate(table, 'time', lower, 'pos')
  11953. ) / 2;
  11954. }
  11955. if (!options.time.max) {
  11956. upper = ticks[ticks.length - 1];
  11957. lower = ticks.length > 1 ? ticks[ticks.length - 2] : min;
  11958. right = (
  11959. interpolate(table, 'time', upper, 'pos') -
  11960. interpolate(table, 'time', lower, 'pos')
  11961. ) / 2;
  11962. }
  11963. }
  11964. return {left: left, right: right};
  11965. }
  11966. function ticksFromTimestamps(values, majorUnit) {
  11967. var ticks = [];
  11968. var i, ilen, value, major;
  11969. for (i = 0, ilen = values.length; i < ilen; ++i) {
  11970. value = values[i];
  11971. major = majorUnit ? value === +moment(value).startOf(majorUnit) : false;
  11972. ticks.push({
  11973. value: value,
  11974. major: major
  11975. });
  11976. }
  11977. return ticks;
  11978. }
  11979. function determineLabelFormat(data, timeOpts) {
  11980. var i, momentDate, hasTime;
  11981. var ilen = data.length;
  11982. // find the label with the most parts (milliseconds, minutes, etc.)
  11983. // format all labels with the same level of detail as the most specific label
  11984. for (i = 0; i < ilen; i++) {
  11985. momentDate = momentify(data[i], timeOpts);
  11986. if (momentDate.millisecond() !== 0) {
  11987. return 'MMM D, YYYY h:mm:ss.SSS a';
  11988. }
  11989. if (momentDate.second() !== 0 || momentDate.minute() !== 0 || momentDate.hour() !== 0) {
  11990. hasTime = true;
  11991. }
  11992. }
  11993. if (hasTime) {
  11994. return 'MMM D, YYYY h:mm:ss a';
  11995. }
  11996. return 'MMM D, YYYY';
  11997. }
  11998. module.exports = function() {
  11999. var defaultConfig = {
  12000. position: 'bottom',
  12001. /**
  12002. * Data distribution along the scale:
  12003. * - 'linear': data are spread according to their time (distances can vary),
  12004. * - 'series': data are spread at the same distance from each other.
  12005. * @see https://github.com/chartjs/Chart.js/pull/4507
  12006. * @since 2.7.0
  12007. */
  12008. distribution: 'linear',
  12009. /**
  12010. * Scale boundary strategy (bypassed by min/max time options)
  12011. * - `data`: make sure data are fully visible, ticks outside are removed
  12012. * - `ticks`: make sure ticks are fully visible, data outside are truncated
  12013. * @see https://github.com/chartjs/Chart.js/pull/4556
  12014. * @since 2.7.0
  12015. */
  12016. bounds: 'data',
  12017. time: {
  12018. 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
  12019. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  12020. unit: false, // false == automatic or override with week, month, year, etc.
  12021. round: false, // none, or override with week, month, year, etc.
  12022. displayFormat: false, // DEPRECATED
  12023. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  12024. minUnit: 'millisecond',
  12025. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  12026. displayFormats: {
  12027. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  12028. second: 'h:mm:ss a', // 11:20:01 AM
  12029. minute: 'h:mm a', // 11:20 AM
  12030. hour: 'hA', // 5PM
  12031. day: 'MMM D', // Sep 4
  12032. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  12033. month: 'MMM YYYY', // Sept 2015
  12034. quarter: '[Q]Q - YYYY', // Q3
  12035. year: 'YYYY' // 2015
  12036. },
  12037. },
  12038. ticks: {
  12039. autoSkip: false,
  12040. /**
  12041. * Ticks generation input values:
  12042. * - 'auto': generates "optimal" ticks based on scale size and time options.
  12043. * - 'data': generates ticks from data (including labels from data {t|x|y} objects).
  12044. * - 'labels': generates ticks from user given `data.labels` values ONLY.
  12045. * @see https://github.com/chartjs/Chart.js/pull/4507
  12046. * @since 2.7.0
  12047. */
  12048. source: 'auto',
  12049. major: {
  12050. enabled: false
  12051. }
  12052. }
  12053. };
  12054. var TimeScale = Scale.extend({
  12055. initialize: function() {
  12056. if (!moment) {
  12057. 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');
  12058. }
  12059. this.mergeTicksOptions();
  12060. Scale.prototype.initialize.call(this);
  12061. },
  12062. update: function() {
  12063. var me = this;
  12064. var options = me.options;
  12065. // DEPRECATIONS: output a message only one time per update
  12066. if (options.time && options.time.format) {
  12067. console.warn('options.time.format is deprecated and replaced by options.time.parser.');
  12068. }
  12069. return Scale.prototype.update.apply(me, arguments);
  12070. },
  12071. /**
  12072. * Allows data to be referenced via 't' attribute
  12073. */
  12074. getRightValue: function(rawValue) {
  12075. if (rawValue && rawValue.t !== undefined) {
  12076. rawValue = rawValue.t;
  12077. }
  12078. return Scale.prototype.getRightValue.call(this, rawValue);
  12079. },
  12080. determineDataLimits: function() {
  12081. var me = this;
  12082. var chart = me.chart;
  12083. var timeOpts = me.options.time;
  12084. var unit = timeOpts.unit || 'day';
  12085. var min = MAX_INTEGER;
  12086. var max = MIN_INTEGER;
  12087. var timestamps = [];
  12088. var datasets = [];
  12089. var labels = [];
  12090. var i, j, ilen, jlen, data, timestamp;
  12091. // Convert labels to timestamps
  12092. for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) {
  12093. labels.push(parse(chart.data.labels[i], me));
  12094. }
  12095. // Convert data to timestamps
  12096. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  12097. if (chart.isDatasetVisible(i)) {
  12098. data = chart.data.datasets[i].data;
  12099. // Let's consider that all data have the same format.
  12100. if (helpers.isObject(data[0])) {
  12101. datasets[i] = [];
  12102. for (j = 0, jlen = data.length; j < jlen; ++j) {
  12103. timestamp = parse(data[j], me);
  12104. timestamps.push(timestamp);
  12105. datasets[i][j] = timestamp;
  12106. }
  12107. } else {
  12108. timestamps.push.apply(timestamps, labels);
  12109. datasets[i] = labels.slice(0);
  12110. }
  12111. } else {
  12112. datasets[i] = [];
  12113. }
  12114. }
  12115. if (labels.length) {
  12116. // Sort labels **after** data have been converted
  12117. labels = arrayUnique(labels).sort(sorter);
  12118. min = Math.min(min, labels[0]);
  12119. max = Math.max(max, labels[labels.length - 1]);
  12120. }
  12121. if (timestamps.length) {
  12122. timestamps = arrayUnique(timestamps).sort(sorter);
  12123. min = Math.min(min, timestamps[0]);
  12124. max = Math.max(max, timestamps[timestamps.length - 1]);
  12125. }
  12126. min = parse(timeOpts.min, me) || min;
  12127. max = parse(timeOpts.max, me) || max;
  12128. // In case there is no valid min/max, set limits based on unit time option
  12129. min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
  12130. max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;
  12131. // Make sure that max is strictly higher than min (required by the lookup table)
  12132. me.min = Math.min(min, max);
  12133. me.max = Math.max(min + 1, max);
  12134. // PRIVATE
  12135. me._horizontal = me.isHorizontal();
  12136. me._table = [];
  12137. me._timestamps = {
  12138. data: timestamps,
  12139. datasets: datasets,
  12140. labels: labels
  12141. };
  12142. },
  12143. buildTicks: function() {
  12144. var me = this;
  12145. var min = me.min;
  12146. var max = me.max;
  12147. var options = me.options;
  12148. var timeOpts = options.time;
  12149. var timestamps = [];
  12150. var ticks = [];
  12151. var i, ilen, timestamp;
  12152. switch (options.ticks.source) {
  12153. case 'data':
  12154. timestamps = me._timestamps.data;
  12155. break;
  12156. case 'labels':
  12157. timestamps = me._timestamps.labels;
  12158. break;
  12159. case 'auto':
  12160. default:
  12161. timestamps = generate(min, max, me.getLabelCapacity(min), options);
  12162. }
  12163. if (options.bounds === 'ticks' && timestamps.length) {
  12164. min = timestamps[0];
  12165. max = timestamps[timestamps.length - 1];
  12166. }
  12167. // Enforce limits with user min/max options
  12168. min = parse(timeOpts.min, me) || min;
  12169. max = parse(timeOpts.max, me) || max;
  12170. // Remove ticks outside the min/max range
  12171. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  12172. timestamp = timestamps[i];
  12173. if (timestamp >= min && timestamp <= max) {
  12174. ticks.push(timestamp);
  12175. }
  12176. }
  12177. me.min = min;
  12178. me.max = max;
  12179. // PRIVATE
  12180. me._unit = timeOpts.unit || determineUnitForFormatting(ticks, timeOpts.minUnit, me.min, me.max);
  12181. me._majorUnit = determineMajorUnit(me._unit);
  12182. me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
  12183. me._offsets = computeOffsets(me._table, ticks, min, max, options);
  12184. me._labelFormat = determineLabelFormat(me._timestamps.data, timeOpts);
  12185. return ticksFromTimestamps(ticks, me._majorUnit);
  12186. },
  12187. getLabelForIndex: function(index, datasetIndex) {
  12188. var me = this;
  12189. var data = me.chart.data;
  12190. var timeOpts = me.options.time;
  12191. var label = data.labels && index < data.labels.length ? data.labels[index] : '';
  12192. var value = data.datasets[datasetIndex].data[index];
  12193. if (helpers.isObject(value)) {
  12194. label = me.getRightValue(value);
  12195. }
  12196. if (timeOpts.tooltipFormat) {
  12197. return momentify(label, timeOpts).format(timeOpts.tooltipFormat);
  12198. }
  12199. if (typeof label === 'string') {
  12200. return label;
  12201. }
  12202. return momentify(label, timeOpts).format(me._labelFormat);
  12203. },
  12204. /**
  12205. * Function to format an individual tick mark
  12206. * @private
  12207. */
  12208. tickFormatFunction: function(tick, index, ticks, formatOverride) {
  12209. var me = this;
  12210. var options = me.options;
  12211. var time = tick.valueOf();
  12212. var formats = options.time.displayFormats;
  12213. var minorFormat = formats[me._unit];
  12214. var majorUnit = me._majorUnit;
  12215. var majorFormat = formats[majorUnit];
  12216. var majorTime = tick.clone().startOf(majorUnit).valueOf();
  12217. var majorTickOpts = options.ticks.major;
  12218. var major = majorTickOpts.enabled && majorUnit && majorFormat && time === majorTime;
  12219. var label = tick.format(formatOverride ? formatOverride : major ? majorFormat : minorFormat);
  12220. var tickOpts = major ? majorTickOpts : options.ticks.minor;
  12221. var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
  12222. return formatter ? formatter(label, index, ticks) : label;
  12223. },
  12224. convertTicksToLabels: function(ticks) {
  12225. var labels = [];
  12226. var i, ilen;
  12227. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  12228. labels.push(this.tickFormatFunction(moment(ticks[i].value), i, ticks));
  12229. }
  12230. return labels;
  12231. },
  12232. /**
  12233. * @private
  12234. */
  12235. getPixelForOffset: function(time) {
  12236. var me = this;
  12237. var size = me._horizontal ? me.width : me.height;
  12238. var start = me._horizontal ? me.left : me.top;
  12239. var pos = interpolate(me._table, 'time', time, 'pos');
  12240. return start + size * (me._offsets.left + pos) / (me._offsets.left + 1 + me._offsets.right);
  12241. },
  12242. getPixelForValue: function(value, index, datasetIndex) {
  12243. var me = this;
  12244. var time = null;
  12245. if (index !== undefined && datasetIndex !== undefined) {
  12246. time = me._timestamps.datasets[datasetIndex][index];
  12247. }
  12248. if (time === null) {
  12249. time = parse(value, me);
  12250. }
  12251. if (time !== null) {
  12252. return me.getPixelForOffset(time);
  12253. }
  12254. },
  12255. getPixelForTick: function(index) {
  12256. var ticks = this.getTicks();
  12257. return index >= 0 && index < ticks.length ?
  12258. this.getPixelForOffset(ticks[index].value) :
  12259. null;
  12260. },
  12261. getValueForPixel: function(pixel) {
  12262. var me = this;
  12263. var size = me._horizontal ? me.width : me.height;
  12264. var start = me._horizontal ? me.left : me.top;
  12265. var pos = (size ? (pixel - start) / size : 0) * (me._offsets.left + 1 + me._offsets.left) - me._offsets.right;
  12266. var time = interpolate(me._table, 'pos', pos, 'time');
  12267. return moment(time);
  12268. },
  12269. /**
  12270. * Crude approximation of what the label width might be
  12271. * @private
  12272. */
  12273. getLabelWidth: function(label) {
  12274. var me = this;
  12275. var ticksOpts = me.options.ticks;
  12276. var tickLabelWidth = me.ctx.measureText(label).width;
  12277. var angle = helpers.toRadians(ticksOpts.maxRotation);
  12278. var cosRotation = Math.cos(angle);
  12279. var sinRotation = Math.sin(angle);
  12280. var tickFontSize = helpers.valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize);
  12281. return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  12282. },
  12283. /**
  12284. * @private
  12285. */
  12286. getLabelCapacity: function(exampleTime) {
  12287. var me = this;
  12288. var formatOverride = me.options.time.displayFormats.millisecond; // Pick the longest format for guestimation
  12289. var exampleLabel = me.tickFormatFunction(moment(exampleTime), 0, [], formatOverride);
  12290. var tickLabelWidth = me.getLabelWidth(exampleLabel);
  12291. var innerWidth = me.isHorizontal() ? me.width : me.height;
  12292. var capacity = Math.floor(innerWidth / tickLabelWidth);
  12293. return capacity > 0 ? capacity : 1;
  12294. }
  12295. });
  12296. scaleService.registerScaleType('time', TimeScale, defaultConfig);
  12297. };
  12298. },{"1":1,"26":26,"33":33,"34":34,"46":46}]},{},[7])(7)
  12299. });