Chart.js 566 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447
  1. (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){
  2. },{}],2:[function(require,module,exports){
  3. /* MIT license */
  4. var colorNames = require(6);
  5. module.exports = {
  6. getRgba: getRgba,
  7. getHsla: getHsla,
  8. getRgb: getRgb,
  9. getHsl: getHsl,
  10. getHwb: getHwb,
  11. getAlpha: getAlpha,
  12. hexString: hexString,
  13. rgbString: rgbString,
  14. rgbaString: rgbaString,
  15. percentString: percentString,
  16. percentaString: percentaString,
  17. hslString: hslString,
  18. hslaString: hslaString,
  19. hwbString: hwbString,
  20. keyword: keyword
  21. }
  22. function getRgba(string) {
  23. if (!string) {
  24. return;
  25. }
  26. var abbr = /^#([a-fA-F0-9]{3})$/i,
  27. hex = /^#([a-fA-F0-9]{6})$/i,
  28. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  29. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  30. keyword = /(\w+)/;
  31. var rgb = [0, 0, 0],
  32. a = 1,
  33. match = string.match(abbr);
  34. if (match) {
  35. match = match[1];
  36. for (var i = 0; i < rgb.length; i++) {
  37. rgb[i] = parseInt(match[i] + match[i], 16);
  38. }
  39. }
  40. else if (match = string.match(hex)) {
  41. match = match[1];
  42. for (var i = 0; i < rgb.length; i++) {
  43. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  44. }
  45. }
  46. else if (match = string.match(rgba)) {
  47. for (var i = 0; i < rgb.length; i++) {
  48. rgb[i] = parseInt(match[i + 1]);
  49. }
  50. a = parseFloat(match[4]);
  51. }
  52. else if (match = string.match(per)) {
  53. for (var i = 0; i < rgb.length; i++) {
  54. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  55. }
  56. a = parseFloat(match[4]);
  57. }
  58. else if (match = string.match(keyword)) {
  59. if (match[1] == "transparent") {
  60. return [0, 0, 0, 0];
  61. }
  62. rgb = colorNames[match[1]];
  63. if (!rgb) {
  64. return;
  65. }
  66. }
  67. for (var i = 0; i < rgb.length; i++) {
  68. rgb[i] = scale(rgb[i], 0, 255);
  69. }
  70. if (!a && a != 0) {
  71. a = 1;
  72. }
  73. else {
  74. a = scale(a, 0, 1);
  75. }
  76. rgb[3] = a;
  77. return rgb;
  78. }
  79. function getHsla(string) {
  80. if (!string) {
  81. return;
  82. }
  83. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  84. var match = string.match(hsl);
  85. if (match) {
  86. var alpha = parseFloat(match[4]);
  87. var h = scale(parseInt(match[1]), 0, 360),
  88. s = scale(parseFloat(match[2]), 0, 100),
  89. l = scale(parseFloat(match[3]), 0, 100),
  90. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  91. return [h, s, l, a];
  92. }
  93. }
  94. function getHwb(string) {
  95. if (!string) {
  96. return;
  97. }
  98. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  99. var match = string.match(hwb);
  100. if (match) {
  101. var alpha = parseFloat(match[4]);
  102. var h = scale(parseInt(match[1]), 0, 360),
  103. w = scale(parseFloat(match[2]), 0, 100),
  104. b = scale(parseFloat(match[3]), 0, 100),
  105. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  106. return [h, w, b, a];
  107. }
  108. }
  109. function getRgb(string) {
  110. var rgba = getRgba(string);
  111. return rgba && rgba.slice(0, 3);
  112. }
  113. function getHsl(string) {
  114. var hsla = getHsla(string);
  115. return hsla && hsla.slice(0, 3);
  116. }
  117. function getAlpha(string) {
  118. var vals = getRgba(string);
  119. if (vals) {
  120. return vals[3];
  121. }
  122. else if (vals = getHsla(string)) {
  123. return vals[3];
  124. }
  125. else if (vals = getHwb(string)) {
  126. return vals[3];
  127. }
  128. }
  129. // generators
  130. function hexString(rgb) {
  131. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  132. + hexDouble(rgb[2]);
  133. }
  134. function rgbString(rgba, alpha) {
  135. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  136. return rgbaString(rgba, alpha);
  137. }
  138. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  139. }
  140. function rgbaString(rgba, alpha) {
  141. if (alpha === undefined) {
  142. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  143. }
  144. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  145. + ", " + alpha + ")";
  146. }
  147. function percentString(rgba, alpha) {
  148. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  149. return percentaString(rgba, alpha);
  150. }
  151. var r = Math.round(rgba[0]/255 * 100),
  152. g = Math.round(rgba[1]/255 * 100),
  153. b = Math.round(rgba[2]/255 * 100);
  154. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  155. }
  156. function percentaString(rgba, alpha) {
  157. var r = Math.round(rgba[0]/255 * 100),
  158. g = Math.round(rgba[1]/255 * 100),
  159. b = Math.round(rgba[2]/255 * 100);
  160. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  161. }
  162. function hslString(hsla, alpha) {
  163. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  164. return hslaString(hsla, alpha);
  165. }
  166. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  167. }
  168. function hslaString(hsla, alpha) {
  169. if (alpha === undefined) {
  170. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  171. }
  172. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  173. + alpha + ")";
  174. }
  175. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  176. // (hwb have alpha optional & 1 is default value)
  177. function hwbString(hwb, alpha) {
  178. if (alpha === undefined) {
  179. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  180. }
  181. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  182. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  183. }
  184. function keyword(rgb) {
  185. return reverseNames[rgb.slice(0, 3)];
  186. }
  187. // helpers
  188. function scale(num, min, max) {
  189. return Math.min(Math.max(min, num), max);
  190. }
  191. function hexDouble(num) {
  192. var str = num.toString(16).toUpperCase();
  193. return (str.length < 2) ? "0" + str : str;
  194. }
  195. //create a list of reverse color names
  196. var reverseNames = {};
  197. for (var name in colorNames) {
  198. reverseNames[colorNames[name]] = name;
  199. }
  200. },{"6":6}],3:[function(require,module,exports){
  201. /* MIT license */
  202. var convert = require(5);
  203. var string = require(2);
  204. var Color = function (obj) {
  205. if (obj instanceof Color) {
  206. return obj;
  207. }
  208. if (!(this instanceof Color)) {
  209. return new Color(obj);
  210. }
  211. this.valid = false;
  212. this.values = {
  213. rgb: [0, 0, 0],
  214. hsl: [0, 0, 0],
  215. hsv: [0, 0, 0],
  216. hwb: [0, 0, 0],
  217. cmyk: [0, 0, 0, 0],
  218. alpha: 1
  219. };
  220. // parse Color() argument
  221. var vals;
  222. if (typeof obj === 'string') {
  223. vals = string.getRgba(obj);
  224. if (vals) {
  225. this.setValues('rgb', vals);
  226. } else if (vals = string.getHsla(obj)) {
  227. this.setValues('hsl', vals);
  228. } else if (vals = string.getHwb(obj)) {
  229. this.setValues('hwb', vals);
  230. }
  231. } else if (typeof obj === 'object') {
  232. vals = obj;
  233. if (vals.r !== undefined || vals.red !== undefined) {
  234. this.setValues('rgb', vals);
  235. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  236. this.setValues('hsl', vals);
  237. } else if (vals.v !== undefined || vals.value !== undefined) {
  238. this.setValues('hsv', vals);
  239. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  240. this.setValues('hwb', vals);
  241. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  242. this.setValues('cmyk', vals);
  243. }
  244. }
  245. };
  246. Color.prototype = {
  247. isValid: function () {
  248. return this.valid;
  249. },
  250. rgb: function () {
  251. return this.setSpace('rgb', arguments);
  252. },
  253. hsl: function () {
  254. return this.setSpace('hsl', arguments);
  255. },
  256. hsv: function () {
  257. return this.setSpace('hsv', arguments);
  258. },
  259. hwb: function () {
  260. return this.setSpace('hwb', arguments);
  261. },
  262. cmyk: function () {
  263. return this.setSpace('cmyk', arguments);
  264. },
  265. rgbArray: function () {
  266. return this.values.rgb;
  267. },
  268. hslArray: function () {
  269. return this.values.hsl;
  270. },
  271. hsvArray: function () {
  272. return this.values.hsv;
  273. },
  274. hwbArray: function () {
  275. var values = this.values;
  276. if (values.alpha !== 1) {
  277. return values.hwb.concat([values.alpha]);
  278. }
  279. return values.hwb;
  280. },
  281. cmykArray: function () {
  282. return this.values.cmyk;
  283. },
  284. rgbaArray: function () {
  285. var values = this.values;
  286. return values.rgb.concat([values.alpha]);
  287. },
  288. hslaArray: function () {
  289. var values = this.values;
  290. return values.hsl.concat([values.alpha]);
  291. },
  292. alpha: function (val) {
  293. if (val === undefined) {
  294. return this.values.alpha;
  295. }
  296. this.setValues('alpha', val);
  297. return this;
  298. },
  299. red: function (val) {
  300. return this.setChannel('rgb', 0, val);
  301. },
  302. green: function (val) {
  303. return this.setChannel('rgb', 1, val);
  304. },
  305. blue: function (val) {
  306. return this.setChannel('rgb', 2, val);
  307. },
  308. hue: function (val) {
  309. if (val) {
  310. val %= 360;
  311. val = val < 0 ? 360 + val : val;
  312. }
  313. return this.setChannel('hsl', 0, val);
  314. },
  315. saturation: function (val) {
  316. return this.setChannel('hsl', 1, val);
  317. },
  318. lightness: function (val) {
  319. return this.setChannel('hsl', 2, val);
  320. },
  321. saturationv: function (val) {
  322. return this.setChannel('hsv', 1, val);
  323. },
  324. whiteness: function (val) {
  325. return this.setChannel('hwb', 1, val);
  326. },
  327. blackness: function (val) {
  328. return this.setChannel('hwb', 2, val);
  329. },
  330. value: function (val) {
  331. return this.setChannel('hsv', 2, val);
  332. },
  333. cyan: function (val) {
  334. return this.setChannel('cmyk', 0, val);
  335. },
  336. magenta: function (val) {
  337. return this.setChannel('cmyk', 1, val);
  338. },
  339. yellow: function (val) {
  340. return this.setChannel('cmyk', 2, val);
  341. },
  342. black: function (val) {
  343. return this.setChannel('cmyk', 3, val);
  344. },
  345. hexString: function () {
  346. return string.hexString(this.values.rgb);
  347. },
  348. rgbString: function () {
  349. return string.rgbString(this.values.rgb, this.values.alpha);
  350. },
  351. rgbaString: function () {
  352. return string.rgbaString(this.values.rgb, this.values.alpha);
  353. },
  354. percentString: function () {
  355. return string.percentString(this.values.rgb, this.values.alpha);
  356. },
  357. hslString: function () {
  358. return string.hslString(this.values.hsl, this.values.alpha);
  359. },
  360. hslaString: function () {
  361. return string.hslaString(this.values.hsl, this.values.alpha);
  362. },
  363. hwbString: function () {
  364. return string.hwbString(this.values.hwb, this.values.alpha);
  365. },
  366. keyword: function () {
  367. return string.keyword(this.values.rgb, this.values.alpha);
  368. },
  369. rgbNumber: function () {
  370. var rgb = this.values.rgb;
  371. return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
  372. },
  373. luminosity: function () {
  374. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  375. var rgb = this.values.rgb;
  376. var lum = [];
  377. for (var i = 0; i < rgb.length; i++) {
  378. var chan = rgb[i] / 255;
  379. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
  380. }
  381. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  382. },
  383. contrast: function (color2) {
  384. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  385. var lum1 = this.luminosity();
  386. var lum2 = color2.luminosity();
  387. if (lum1 > lum2) {
  388. return (lum1 + 0.05) / (lum2 + 0.05);
  389. }
  390. return (lum2 + 0.05) / (lum1 + 0.05);
  391. },
  392. level: function (color2) {
  393. var contrastRatio = this.contrast(color2);
  394. if (contrastRatio >= 7.1) {
  395. return 'AAA';
  396. }
  397. return (contrastRatio >= 4.5) ? 'AA' : '';
  398. },
  399. dark: function () {
  400. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  401. var rgb = this.values.rgb;
  402. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  403. return yiq < 128;
  404. },
  405. light: function () {
  406. return !this.dark();
  407. },
  408. negate: function () {
  409. var rgb = [];
  410. for (var i = 0; i < 3; i++) {
  411. rgb[i] = 255 - this.values.rgb[i];
  412. }
  413. this.setValues('rgb', rgb);
  414. return this;
  415. },
  416. lighten: function (ratio) {
  417. var hsl = this.values.hsl;
  418. hsl[2] += hsl[2] * ratio;
  419. this.setValues('hsl', hsl);
  420. return this;
  421. },
  422. darken: function (ratio) {
  423. var hsl = this.values.hsl;
  424. hsl[2] -= hsl[2] * ratio;
  425. this.setValues('hsl', hsl);
  426. return this;
  427. },
  428. saturate: function (ratio) {
  429. var hsl = this.values.hsl;
  430. hsl[1] += hsl[1] * ratio;
  431. this.setValues('hsl', hsl);
  432. return this;
  433. },
  434. desaturate: function (ratio) {
  435. var hsl = this.values.hsl;
  436. hsl[1] -= hsl[1] * ratio;
  437. this.setValues('hsl', hsl);
  438. return this;
  439. },
  440. whiten: function (ratio) {
  441. var hwb = this.values.hwb;
  442. hwb[1] += hwb[1] * ratio;
  443. this.setValues('hwb', hwb);
  444. return this;
  445. },
  446. blacken: function (ratio) {
  447. var hwb = this.values.hwb;
  448. hwb[2] += hwb[2] * ratio;
  449. this.setValues('hwb', hwb);
  450. return this;
  451. },
  452. greyscale: function () {
  453. var rgb = this.values.rgb;
  454. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  455. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  456. this.setValues('rgb', [val, val, val]);
  457. return this;
  458. },
  459. clearer: function (ratio) {
  460. var alpha = this.values.alpha;
  461. this.setValues('alpha', alpha - (alpha * ratio));
  462. return this;
  463. },
  464. opaquer: function (ratio) {
  465. var alpha = this.values.alpha;
  466. this.setValues('alpha', alpha + (alpha * ratio));
  467. return this;
  468. },
  469. rotate: function (degrees) {
  470. var hsl = this.values.hsl;
  471. var hue = (hsl[0] + degrees) % 360;
  472. hsl[0] = hue < 0 ? 360 + hue : hue;
  473. this.setValues('hsl', hsl);
  474. return this;
  475. },
  476. /**
  477. * Ported from sass implementation in C
  478. * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
  479. */
  480. mix: function (mixinColor, weight) {
  481. var color1 = this;
  482. var color2 = mixinColor;
  483. var p = weight === undefined ? 0.5 : weight;
  484. var w = 2 * p - 1;
  485. var a = color1.alpha() - color2.alpha();
  486. var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  487. var w2 = 1 - w1;
  488. return this
  489. .rgb(
  490. w1 * color1.red() + w2 * color2.red(),
  491. w1 * color1.green() + w2 * color2.green(),
  492. w1 * color1.blue() + w2 * color2.blue()
  493. )
  494. .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
  495. },
  496. toJSON: function () {
  497. return this.rgb();
  498. },
  499. clone: function () {
  500. // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
  501. // making the final build way to big to embed in Chart.js. So let's do it manually,
  502. // assuming that values to clone are 1 dimension arrays containing only numbers,
  503. // except 'alpha' which is a number.
  504. var result = new Color();
  505. var source = this.values;
  506. var target = result.values;
  507. var value, type;
  508. for (var prop in source) {
  509. if (source.hasOwnProperty(prop)) {
  510. value = source[prop];
  511. type = ({}).toString.call(value);
  512. if (type === '[object Array]') {
  513. target[prop] = value.slice(0);
  514. } else if (type === '[object Number]') {
  515. target[prop] = value;
  516. } else {
  517. console.error('unexpected color value:', value);
  518. }
  519. }
  520. }
  521. return result;
  522. }
  523. };
  524. Color.prototype.spaces = {
  525. rgb: ['red', 'green', 'blue'],
  526. hsl: ['hue', 'saturation', 'lightness'],
  527. hsv: ['hue', 'saturation', 'value'],
  528. hwb: ['hue', 'whiteness', 'blackness'],
  529. cmyk: ['cyan', 'magenta', 'yellow', 'black']
  530. };
  531. Color.prototype.maxes = {
  532. rgb: [255, 255, 255],
  533. hsl: [360, 100, 100],
  534. hsv: [360, 100, 100],
  535. hwb: [360, 100, 100],
  536. cmyk: [100, 100, 100, 100]
  537. };
  538. Color.prototype.getValues = function (space) {
  539. var values = this.values;
  540. var vals = {};
  541. for (var i = 0; i < space.length; i++) {
  542. vals[space.charAt(i)] = values[space][i];
  543. }
  544. if (values.alpha !== 1) {
  545. vals.a = values.alpha;
  546. }
  547. // {r: 255, g: 255, b: 255, a: 0.4}
  548. return vals;
  549. };
  550. Color.prototype.setValues = function (space, vals) {
  551. var values = this.values;
  552. var spaces = this.spaces;
  553. var maxes = this.maxes;
  554. var alpha = 1;
  555. var i;
  556. this.valid = true;
  557. if (space === 'alpha') {
  558. alpha = vals;
  559. } else if (vals.length) {
  560. // [10, 10, 10]
  561. values[space] = vals.slice(0, space.length);
  562. alpha = vals[space.length];
  563. } else if (vals[space.charAt(0)] !== undefined) {
  564. // {r: 10, g: 10, b: 10}
  565. for (i = 0; i < space.length; i++) {
  566. values[space][i] = vals[space.charAt(i)];
  567. }
  568. alpha = vals.a;
  569. } else if (vals[spaces[space][0]] !== undefined) {
  570. // {red: 10, green: 10, blue: 10}
  571. var chans = spaces[space];
  572. for (i = 0; i < space.length; i++) {
  573. values[space][i] = vals[chans[i]];
  574. }
  575. alpha = vals.alpha;
  576. }
  577. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  578. if (space === 'alpha') {
  579. return false;
  580. }
  581. var capped;
  582. // cap values of the space prior converting all values
  583. for (i = 0; i < space.length; i++) {
  584. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  585. values[space][i] = Math.round(capped);
  586. }
  587. // convert to all the other color spaces
  588. for (var sname in spaces) {
  589. if (sname !== space) {
  590. values[sname] = convert[space][sname](values[space]);
  591. }
  592. }
  593. return true;
  594. };
  595. Color.prototype.setSpace = function (space, args) {
  596. var vals = args[0];
  597. if (vals === undefined) {
  598. // color.rgb()
  599. return this.getValues(space);
  600. }
  601. // color.rgb(10, 10, 10)
  602. if (typeof vals === 'number') {
  603. vals = Array.prototype.slice.call(args);
  604. }
  605. this.setValues(space, vals);
  606. return this;
  607. };
  608. Color.prototype.setChannel = function (space, index, val) {
  609. var svalues = this.values[space];
  610. if (val === undefined) {
  611. // color.red()
  612. return svalues[index];
  613. } else if (val === svalues[index]) {
  614. // color.red(color.red())
  615. return this;
  616. }
  617. // color.red(100)
  618. svalues[index] = val;
  619. this.setValues(space, svalues);
  620. return this;
  621. };
  622. if (typeof window !== 'undefined') {
  623. window.Color = Color;
  624. }
  625. module.exports = Color;
  626. },{"2":2,"5":5}],4:[function(require,module,exports){
  627. /* MIT license */
  628. module.exports = {
  629. rgb2hsl: rgb2hsl,
  630. rgb2hsv: rgb2hsv,
  631. rgb2hwb: rgb2hwb,
  632. rgb2cmyk: rgb2cmyk,
  633. rgb2keyword: rgb2keyword,
  634. rgb2xyz: rgb2xyz,
  635. rgb2lab: rgb2lab,
  636. rgb2lch: rgb2lch,
  637. hsl2rgb: hsl2rgb,
  638. hsl2hsv: hsl2hsv,
  639. hsl2hwb: hsl2hwb,
  640. hsl2cmyk: hsl2cmyk,
  641. hsl2keyword: hsl2keyword,
  642. hsv2rgb: hsv2rgb,
  643. hsv2hsl: hsv2hsl,
  644. hsv2hwb: hsv2hwb,
  645. hsv2cmyk: hsv2cmyk,
  646. hsv2keyword: hsv2keyword,
  647. hwb2rgb: hwb2rgb,
  648. hwb2hsl: hwb2hsl,
  649. hwb2hsv: hwb2hsv,
  650. hwb2cmyk: hwb2cmyk,
  651. hwb2keyword: hwb2keyword,
  652. cmyk2rgb: cmyk2rgb,
  653. cmyk2hsl: cmyk2hsl,
  654. cmyk2hsv: cmyk2hsv,
  655. cmyk2hwb: cmyk2hwb,
  656. cmyk2keyword: cmyk2keyword,
  657. keyword2rgb: keyword2rgb,
  658. keyword2hsl: keyword2hsl,
  659. keyword2hsv: keyword2hsv,
  660. keyword2hwb: keyword2hwb,
  661. keyword2cmyk: keyword2cmyk,
  662. keyword2lab: keyword2lab,
  663. keyword2xyz: keyword2xyz,
  664. xyz2rgb: xyz2rgb,
  665. xyz2lab: xyz2lab,
  666. xyz2lch: xyz2lch,
  667. lab2xyz: lab2xyz,
  668. lab2rgb: lab2rgb,
  669. lab2lch: lab2lch,
  670. lch2lab: lch2lab,
  671. lch2xyz: lch2xyz,
  672. lch2rgb: lch2rgb
  673. }
  674. function rgb2hsl(rgb) {
  675. var r = rgb[0]/255,
  676. g = rgb[1]/255,
  677. b = rgb[2]/255,
  678. min = Math.min(r, g, b),
  679. max = Math.max(r, g, b),
  680. delta = max - min,
  681. h, s, l;
  682. if (max == min)
  683. h = 0;
  684. else if (r == max)
  685. h = (g - b) / delta;
  686. else if (g == max)
  687. h = 2 + (b - r) / delta;
  688. else if (b == max)
  689. h = 4 + (r - g)/ delta;
  690. h = Math.min(h * 60, 360);
  691. if (h < 0)
  692. h += 360;
  693. l = (min + max) / 2;
  694. if (max == min)
  695. s = 0;
  696. else if (l <= 0.5)
  697. s = delta / (max + min);
  698. else
  699. s = delta / (2 - max - min);
  700. return [h, s * 100, l * 100];
  701. }
  702. function rgb2hsv(rgb) {
  703. var r = rgb[0],
  704. g = rgb[1],
  705. b = rgb[2],
  706. min = Math.min(r, g, b),
  707. max = Math.max(r, g, b),
  708. delta = max - min,
  709. h, s, v;
  710. if (max == 0)
  711. s = 0;
  712. else
  713. s = (delta/max * 1000)/10;
  714. if (max == min)
  715. h = 0;
  716. else if (r == max)
  717. h = (g - b) / delta;
  718. else if (g == max)
  719. h = 2 + (b - r) / delta;
  720. else if (b == max)
  721. h = 4 + (r - g) / delta;
  722. h = Math.min(h * 60, 360);
  723. if (h < 0)
  724. h += 360;
  725. v = ((max / 255) * 1000) / 10;
  726. return [h, s, v];
  727. }
  728. function rgb2hwb(rgb) {
  729. var r = rgb[0],
  730. g = rgb[1],
  731. b = rgb[2],
  732. h = rgb2hsl(rgb)[0],
  733. w = 1/255 * Math.min(r, Math.min(g, b)),
  734. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  735. return [h, w * 100, b * 100];
  736. }
  737. function rgb2cmyk(rgb) {
  738. var r = rgb[0] / 255,
  739. g = rgb[1] / 255,
  740. b = rgb[2] / 255,
  741. c, m, y, k;
  742. k = Math.min(1 - r, 1 - g, 1 - b);
  743. c = (1 - r - k) / (1 - k) || 0;
  744. m = (1 - g - k) / (1 - k) || 0;
  745. y = (1 - b - k) / (1 - k) || 0;
  746. return [c * 100, m * 100, y * 100, k * 100];
  747. }
  748. function rgb2keyword(rgb) {
  749. return reverseKeywords[JSON.stringify(rgb)];
  750. }
  751. function rgb2xyz(rgb) {
  752. var r = rgb[0] / 255,
  753. g = rgb[1] / 255,
  754. b = rgb[2] / 255;
  755. // assume sRGB
  756. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  757. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  758. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  759. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  760. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  761. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  762. return [x * 100, y *100, z * 100];
  763. }
  764. function rgb2lab(rgb) {
  765. var xyz = rgb2xyz(rgb),
  766. x = xyz[0],
  767. y = xyz[1],
  768. z = xyz[2],
  769. l, a, b;
  770. x /= 95.047;
  771. y /= 100;
  772. z /= 108.883;
  773. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  774. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  775. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  776. l = (116 * y) - 16;
  777. a = 500 * (x - y);
  778. b = 200 * (y - z);
  779. return [l, a, b];
  780. }
  781. function rgb2lch(args) {
  782. return lab2lch(rgb2lab(args));
  783. }
  784. function hsl2rgb(hsl) {
  785. var h = hsl[0] / 360,
  786. s = hsl[1] / 100,
  787. l = hsl[2] / 100,
  788. t1, t2, t3, rgb, val;
  789. if (s == 0) {
  790. val = l * 255;
  791. return [val, val, val];
  792. }
  793. if (l < 0.5)
  794. t2 = l * (1 + s);
  795. else
  796. t2 = l + s - l * s;
  797. t1 = 2 * l - t2;
  798. rgb = [0, 0, 0];
  799. for (var i = 0; i < 3; i++) {
  800. t3 = h + 1 / 3 * - (i - 1);
  801. t3 < 0 && t3++;
  802. t3 > 1 && t3--;
  803. if (6 * t3 < 1)
  804. val = t1 + (t2 - t1) * 6 * t3;
  805. else if (2 * t3 < 1)
  806. val = t2;
  807. else if (3 * t3 < 2)
  808. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  809. else
  810. val = t1;
  811. rgb[i] = val * 255;
  812. }
  813. return rgb;
  814. }
  815. function hsl2hsv(hsl) {
  816. var h = hsl[0],
  817. s = hsl[1] / 100,
  818. l = hsl[2] / 100,
  819. sv, v;
  820. if(l === 0) {
  821. // no need to do calc on black
  822. // also avoids divide by 0 error
  823. return [0, 0, 0];
  824. }
  825. l *= 2;
  826. s *= (l <= 1) ? l : 2 - l;
  827. v = (l + s) / 2;
  828. sv = (2 * s) / (l + s);
  829. return [h, sv * 100, v * 100];
  830. }
  831. function hsl2hwb(args) {
  832. return rgb2hwb(hsl2rgb(args));
  833. }
  834. function hsl2cmyk(args) {
  835. return rgb2cmyk(hsl2rgb(args));
  836. }
  837. function hsl2keyword(args) {
  838. return rgb2keyword(hsl2rgb(args));
  839. }
  840. function hsv2rgb(hsv) {
  841. var h = hsv[0] / 60,
  842. s = hsv[1] / 100,
  843. v = hsv[2] / 100,
  844. hi = Math.floor(h) % 6;
  845. var f = h - Math.floor(h),
  846. p = 255 * v * (1 - s),
  847. q = 255 * v * (1 - (s * f)),
  848. t = 255 * v * (1 - (s * (1 - f))),
  849. v = 255 * v;
  850. switch(hi) {
  851. case 0:
  852. return [v, t, p];
  853. case 1:
  854. return [q, v, p];
  855. case 2:
  856. return [p, v, t];
  857. case 3:
  858. return [p, q, v];
  859. case 4:
  860. return [t, p, v];
  861. case 5:
  862. return [v, p, q];
  863. }
  864. }
  865. function hsv2hsl(hsv) {
  866. var h = hsv[0],
  867. s = hsv[1] / 100,
  868. v = hsv[2] / 100,
  869. sl, l;
  870. l = (2 - s) * v;
  871. sl = s * v;
  872. sl /= (l <= 1) ? l : 2 - l;
  873. sl = sl || 0;
  874. l /= 2;
  875. return [h, sl * 100, l * 100];
  876. }
  877. function hsv2hwb(args) {
  878. return rgb2hwb(hsv2rgb(args))
  879. }
  880. function hsv2cmyk(args) {
  881. return rgb2cmyk(hsv2rgb(args));
  882. }
  883. function hsv2keyword(args) {
  884. return rgb2keyword(hsv2rgb(args));
  885. }
  886. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  887. function hwb2rgb(hwb) {
  888. var h = hwb[0] / 360,
  889. wh = hwb[1] / 100,
  890. bl = hwb[2] / 100,
  891. ratio = wh + bl,
  892. i, v, f, n;
  893. // wh + bl cant be > 1
  894. if (ratio > 1) {
  895. wh /= ratio;
  896. bl /= ratio;
  897. }
  898. i = Math.floor(6 * h);
  899. v = 1 - bl;
  900. f = 6 * h - i;
  901. if ((i & 0x01) != 0) {
  902. f = 1 - f;
  903. }
  904. n = wh + f * (v - wh); // linear interpolation
  905. switch (i) {
  906. default:
  907. case 6:
  908. case 0: r = v; g = n; b = wh; break;
  909. case 1: r = n; g = v; b = wh; break;
  910. case 2: r = wh; g = v; b = n; break;
  911. case 3: r = wh; g = n; b = v; break;
  912. case 4: r = n; g = wh; b = v; break;
  913. case 5: r = v; g = wh; b = n; break;
  914. }
  915. return [r * 255, g * 255, b * 255];
  916. }
  917. function hwb2hsl(args) {
  918. return rgb2hsl(hwb2rgb(args));
  919. }
  920. function hwb2hsv(args) {
  921. return rgb2hsv(hwb2rgb(args));
  922. }
  923. function hwb2cmyk(args) {
  924. return rgb2cmyk(hwb2rgb(args));
  925. }
  926. function hwb2keyword(args) {
  927. return rgb2keyword(hwb2rgb(args));
  928. }
  929. function cmyk2rgb(cmyk) {
  930. var c = cmyk[0] / 100,
  931. m = cmyk[1] / 100,
  932. y = cmyk[2] / 100,
  933. k = cmyk[3] / 100,
  934. r, g, b;
  935. r = 1 - Math.min(1, c * (1 - k) + k);
  936. g = 1 - Math.min(1, m * (1 - k) + k);
  937. b = 1 - Math.min(1, y * (1 - k) + k);
  938. return [r * 255, g * 255, b * 255];
  939. }
  940. function cmyk2hsl(args) {
  941. return rgb2hsl(cmyk2rgb(args));
  942. }
  943. function cmyk2hsv(args) {
  944. return rgb2hsv(cmyk2rgb(args));
  945. }
  946. function cmyk2hwb(args) {
  947. return rgb2hwb(cmyk2rgb(args));
  948. }
  949. function cmyk2keyword(args) {
  950. return rgb2keyword(cmyk2rgb(args));
  951. }
  952. function xyz2rgb(xyz) {
  953. var x = xyz[0] / 100,
  954. y = xyz[1] / 100,
  955. z = xyz[2] / 100,
  956. r, g, b;
  957. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  958. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  959. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  960. // assume sRGB
  961. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  962. : r = (r * 12.92);
  963. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  964. : g = (g * 12.92);
  965. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  966. : b = (b * 12.92);
  967. r = Math.min(Math.max(0, r), 1);
  968. g = Math.min(Math.max(0, g), 1);
  969. b = Math.min(Math.max(0, b), 1);
  970. return [r * 255, g * 255, b * 255];
  971. }
  972. function xyz2lab(xyz) {
  973. var x = xyz[0],
  974. y = xyz[1],
  975. z = xyz[2],
  976. l, a, b;
  977. x /= 95.047;
  978. y /= 100;
  979. z /= 108.883;
  980. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  981. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  982. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  983. l = (116 * y) - 16;
  984. a = 500 * (x - y);
  985. b = 200 * (y - z);
  986. return [l, a, b];
  987. }
  988. function xyz2lch(args) {
  989. return lab2lch(xyz2lab(args));
  990. }
  991. function lab2xyz(lab) {
  992. var l = lab[0],
  993. a = lab[1],
  994. b = lab[2],
  995. x, y, z, y2;
  996. if (l <= 8) {
  997. y = (l * 100) / 903.3;
  998. y2 = (7.787 * (y / 100)) + (16 / 116);
  999. } else {
  1000. y = 100 * Math.pow((l + 16) / 116, 3);
  1001. y2 = Math.pow(y / 100, 1/3);
  1002. }
  1003. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1004. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1005. return [x, y, z];
  1006. }
  1007. function lab2lch(lab) {
  1008. var l = lab[0],
  1009. a = lab[1],
  1010. b = lab[2],
  1011. hr, h, c;
  1012. hr = Math.atan2(b, a);
  1013. h = hr * 360 / 2 / Math.PI;
  1014. if (h < 0) {
  1015. h += 360;
  1016. }
  1017. c = Math.sqrt(a * a + b * b);
  1018. return [l, c, h];
  1019. }
  1020. function lab2rgb(args) {
  1021. return xyz2rgb(lab2xyz(args));
  1022. }
  1023. function lch2lab(lch) {
  1024. var l = lch[0],
  1025. c = lch[1],
  1026. h = lch[2],
  1027. a, b, hr;
  1028. hr = h / 360 * 2 * Math.PI;
  1029. a = c * Math.cos(hr);
  1030. b = c * Math.sin(hr);
  1031. return [l, a, b];
  1032. }
  1033. function lch2xyz(args) {
  1034. return lab2xyz(lch2lab(args));
  1035. }
  1036. function lch2rgb(args) {
  1037. return lab2rgb(lch2lab(args));
  1038. }
  1039. function keyword2rgb(keyword) {
  1040. return cssKeywords[keyword];
  1041. }
  1042. function keyword2hsl(args) {
  1043. return rgb2hsl(keyword2rgb(args));
  1044. }
  1045. function keyword2hsv(args) {
  1046. return rgb2hsv(keyword2rgb(args));
  1047. }
  1048. function keyword2hwb(args) {
  1049. return rgb2hwb(keyword2rgb(args));
  1050. }
  1051. function keyword2cmyk(args) {
  1052. return rgb2cmyk(keyword2rgb(args));
  1053. }
  1054. function keyword2lab(args) {
  1055. return rgb2lab(keyword2rgb(args));
  1056. }
  1057. function keyword2xyz(args) {
  1058. return rgb2xyz(keyword2rgb(args));
  1059. }
  1060. var cssKeywords = {
  1061. aliceblue: [240,248,255],
  1062. antiquewhite: [250,235,215],
  1063. aqua: [0,255,255],
  1064. aquamarine: [127,255,212],
  1065. azure: [240,255,255],
  1066. beige: [245,245,220],
  1067. bisque: [255,228,196],
  1068. black: [0,0,0],
  1069. blanchedalmond: [255,235,205],
  1070. blue: [0,0,255],
  1071. blueviolet: [138,43,226],
  1072. brown: [165,42,42],
  1073. burlywood: [222,184,135],
  1074. cadetblue: [95,158,160],
  1075. chartreuse: [127,255,0],
  1076. chocolate: [210,105,30],
  1077. coral: [255,127,80],
  1078. cornflowerblue: [100,149,237],
  1079. cornsilk: [255,248,220],
  1080. crimson: [220,20,60],
  1081. cyan: [0,255,255],
  1082. darkblue: [0,0,139],
  1083. darkcyan: [0,139,139],
  1084. darkgoldenrod: [184,134,11],
  1085. darkgray: [169,169,169],
  1086. darkgreen: [0,100,0],
  1087. darkgrey: [169,169,169],
  1088. darkkhaki: [189,183,107],
  1089. darkmagenta: [139,0,139],
  1090. darkolivegreen: [85,107,47],
  1091. darkorange: [255,140,0],
  1092. darkorchid: [153,50,204],
  1093. darkred: [139,0,0],
  1094. darksalmon: [233,150,122],
  1095. darkseagreen: [143,188,143],
  1096. darkslateblue: [72,61,139],
  1097. darkslategray: [47,79,79],
  1098. darkslategrey: [47,79,79],
  1099. darkturquoise: [0,206,209],
  1100. darkviolet: [148,0,211],
  1101. deeppink: [255,20,147],
  1102. deepskyblue: [0,191,255],
  1103. dimgray: [105,105,105],
  1104. dimgrey: [105,105,105],
  1105. dodgerblue: [30,144,255],
  1106. firebrick: [178,34,34],
  1107. floralwhite: [255,250,240],
  1108. forestgreen: [34,139,34],
  1109. fuchsia: [255,0,255],
  1110. gainsboro: [220,220,220],
  1111. ghostwhite: [248,248,255],
  1112. gold: [255,215,0],
  1113. goldenrod: [218,165,32],
  1114. gray: [128,128,128],
  1115. green: [0,128,0],
  1116. greenyellow: [173,255,47],
  1117. grey: [128,128,128],
  1118. honeydew: [240,255,240],
  1119. hotpink: [255,105,180],
  1120. indianred: [205,92,92],
  1121. indigo: [75,0,130],
  1122. ivory: [255,255,240],
  1123. khaki: [240,230,140],
  1124. lavender: [230,230,250],
  1125. lavenderblush: [255,240,245],
  1126. lawngreen: [124,252,0],
  1127. lemonchiffon: [255,250,205],
  1128. lightblue: [173,216,230],
  1129. lightcoral: [240,128,128],
  1130. lightcyan: [224,255,255],
  1131. lightgoldenrodyellow: [250,250,210],
  1132. lightgray: [211,211,211],
  1133. lightgreen: [144,238,144],
  1134. lightgrey: [211,211,211],
  1135. lightpink: [255,182,193],
  1136. lightsalmon: [255,160,122],
  1137. lightseagreen: [32,178,170],
  1138. lightskyblue: [135,206,250],
  1139. lightslategray: [119,136,153],
  1140. lightslategrey: [119,136,153],
  1141. lightsteelblue: [176,196,222],
  1142. lightyellow: [255,255,224],
  1143. lime: [0,255,0],
  1144. limegreen: [50,205,50],
  1145. linen: [250,240,230],
  1146. magenta: [255,0,255],
  1147. maroon: [128,0,0],
  1148. mediumaquamarine: [102,205,170],
  1149. mediumblue: [0,0,205],
  1150. mediumorchid: [186,85,211],
  1151. mediumpurple: [147,112,219],
  1152. mediumseagreen: [60,179,113],
  1153. mediumslateblue: [123,104,238],
  1154. mediumspringgreen: [0,250,154],
  1155. mediumturquoise: [72,209,204],
  1156. mediumvioletred: [199,21,133],
  1157. midnightblue: [25,25,112],
  1158. mintcream: [245,255,250],
  1159. mistyrose: [255,228,225],
  1160. moccasin: [255,228,181],
  1161. navajowhite: [255,222,173],
  1162. navy: [0,0,128],
  1163. oldlace: [253,245,230],
  1164. olive: [128,128,0],
  1165. olivedrab: [107,142,35],
  1166. orange: [255,165,0],
  1167. orangered: [255,69,0],
  1168. orchid: [218,112,214],
  1169. palegoldenrod: [238,232,170],
  1170. palegreen: [152,251,152],
  1171. paleturquoise: [175,238,238],
  1172. palevioletred: [219,112,147],
  1173. papayawhip: [255,239,213],
  1174. peachpuff: [255,218,185],
  1175. peru: [205,133,63],
  1176. pink: [255,192,203],
  1177. plum: [221,160,221],
  1178. powderblue: [176,224,230],
  1179. purple: [128,0,128],
  1180. rebeccapurple: [102, 51, 153],
  1181. red: [255,0,0],
  1182. rosybrown: [188,143,143],
  1183. royalblue: [65,105,225],
  1184. saddlebrown: [139,69,19],
  1185. salmon: [250,128,114],
  1186. sandybrown: [244,164,96],
  1187. seagreen: [46,139,87],
  1188. seashell: [255,245,238],
  1189. sienna: [160,82,45],
  1190. silver: [192,192,192],
  1191. skyblue: [135,206,235],
  1192. slateblue: [106,90,205],
  1193. slategray: [112,128,144],
  1194. slategrey: [112,128,144],
  1195. snow: [255,250,250],
  1196. springgreen: [0,255,127],
  1197. steelblue: [70,130,180],
  1198. tan: [210,180,140],
  1199. teal: [0,128,128],
  1200. thistle: [216,191,216],
  1201. tomato: [255,99,71],
  1202. turquoise: [64,224,208],
  1203. violet: [238,130,238],
  1204. wheat: [245,222,179],
  1205. white: [255,255,255],
  1206. whitesmoke: [245,245,245],
  1207. yellow: [255,255,0],
  1208. yellowgreen: [154,205,50]
  1209. };
  1210. var reverseKeywords = {};
  1211. for (var key in cssKeywords) {
  1212. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1213. }
  1214. },{}],5:[function(require,module,exports){
  1215. var conversions = require(4);
  1216. var convert = function() {
  1217. return new Converter();
  1218. }
  1219. for (var func in conversions) {
  1220. // export Raw versions
  1221. convert[func + "Raw"] = (function(func) {
  1222. // accept array or plain args
  1223. return function(arg) {
  1224. if (typeof arg == "number")
  1225. arg = Array.prototype.slice.call(arguments);
  1226. return conversions[func](arg);
  1227. }
  1228. })(func);
  1229. var pair = /(\w+)2(\w+)/.exec(func),
  1230. from = pair[1],
  1231. to = pair[2];
  1232. // export rgb2hsl and ["rgb"]["hsl"]
  1233. convert[from] = convert[from] || {};
  1234. convert[from][to] = convert[func] = (function(func) {
  1235. return function(arg) {
  1236. if (typeof arg == "number")
  1237. arg = Array.prototype.slice.call(arguments);
  1238. var val = conversions[func](arg);
  1239. if (typeof val == "string" || val === undefined)
  1240. return val; // keyword
  1241. for (var i = 0; i < val.length; i++)
  1242. val[i] = Math.round(val[i]);
  1243. return val;
  1244. }
  1245. })(func);
  1246. }
  1247. /* Converter does lazy conversion and caching */
  1248. var Converter = function() {
  1249. this.convs = {};
  1250. };
  1251. /* Either get the values for a space or
  1252. set the values for a space, depending on args */
  1253. Converter.prototype.routeSpace = function(space, args) {
  1254. var values = args[0];
  1255. if (values === undefined) {
  1256. // color.rgb()
  1257. return this.getValues(space);
  1258. }
  1259. // color.rgb(10, 10, 10)
  1260. if (typeof values == "number") {
  1261. values = Array.prototype.slice.call(args);
  1262. }
  1263. return this.setValues(space, values);
  1264. };
  1265. /* Set the values for a space, invalidating cache */
  1266. Converter.prototype.setValues = function(space, values) {
  1267. this.space = space;
  1268. this.convs = {};
  1269. this.convs[space] = values;
  1270. return this;
  1271. };
  1272. /* Get the values for a space. If there's already
  1273. a conversion for the space, fetch it, otherwise
  1274. compute it */
  1275. Converter.prototype.getValues = function(space) {
  1276. var vals = this.convs[space];
  1277. if (!vals) {
  1278. var fspace = this.space,
  1279. from = this.convs[fspace];
  1280. vals = convert[fspace][space](from);
  1281. this.convs[space] = vals;
  1282. }
  1283. return vals;
  1284. };
  1285. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  1286. Converter.prototype[space] = function(vals) {
  1287. return this.routeSpace(space, arguments);
  1288. }
  1289. });
  1290. module.exports = convert;
  1291. },{"4":4}],6:[function(require,module,exports){
  1292. 'use strict'
  1293. module.exports = {
  1294. "aliceblue": [240, 248, 255],
  1295. "antiquewhite": [250, 235, 215],
  1296. "aqua": [0, 255, 255],
  1297. "aquamarine": [127, 255, 212],
  1298. "azure": [240, 255, 255],
  1299. "beige": [245, 245, 220],
  1300. "bisque": [255, 228, 196],
  1301. "black": [0, 0, 0],
  1302. "blanchedalmond": [255, 235, 205],
  1303. "blue": [0, 0, 255],
  1304. "blueviolet": [138, 43, 226],
  1305. "brown": [165, 42, 42],
  1306. "burlywood": [222, 184, 135],
  1307. "cadetblue": [95, 158, 160],
  1308. "chartreuse": [127, 255, 0],
  1309. "chocolate": [210, 105, 30],
  1310. "coral": [255, 127, 80],
  1311. "cornflowerblue": [100, 149, 237],
  1312. "cornsilk": [255, 248, 220],
  1313. "crimson": [220, 20, 60],
  1314. "cyan": [0, 255, 255],
  1315. "darkblue": [0, 0, 139],
  1316. "darkcyan": [0, 139, 139],
  1317. "darkgoldenrod": [184, 134, 11],
  1318. "darkgray": [169, 169, 169],
  1319. "darkgreen": [0, 100, 0],
  1320. "darkgrey": [169, 169, 169],
  1321. "darkkhaki": [189, 183, 107],
  1322. "darkmagenta": [139, 0, 139],
  1323. "darkolivegreen": [85, 107, 47],
  1324. "darkorange": [255, 140, 0],
  1325. "darkorchid": [153, 50, 204],
  1326. "darkred": [139, 0, 0],
  1327. "darksalmon": [233, 150, 122],
  1328. "darkseagreen": [143, 188, 143],
  1329. "darkslateblue": [72, 61, 139],
  1330. "darkslategray": [47, 79, 79],
  1331. "darkslategrey": [47, 79, 79],
  1332. "darkturquoise": [0, 206, 209],
  1333. "darkviolet": [148, 0, 211],
  1334. "deeppink": [255, 20, 147],
  1335. "deepskyblue": [0, 191, 255],
  1336. "dimgray": [105, 105, 105],
  1337. "dimgrey": [105, 105, 105],
  1338. "dodgerblue": [30, 144, 255],
  1339. "firebrick": [178, 34, 34],
  1340. "floralwhite": [255, 250, 240],
  1341. "forestgreen": [34, 139, 34],
  1342. "fuchsia": [255, 0, 255],
  1343. "gainsboro": [220, 220, 220],
  1344. "ghostwhite": [248, 248, 255],
  1345. "gold": [255, 215, 0],
  1346. "goldenrod": [218, 165, 32],
  1347. "gray": [128, 128, 128],
  1348. "green": [0, 128, 0],
  1349. "greenyellow": [173, 255, 47],
  1350. "grey": [128, 128, 128],
  1351. "honeydew": [240, 255, 240],
  1352. "hotpink": [255, 105, 180],
  1353. "indianred": [205, 92, 92],
  1354. "indigo": [75, 0, 130],
  1355. "ivory": [255, 255, 240],
  1356. "khaki": [240, 230, 140],
  1357. "lavender": [230, 230, 250],
  1358. "lavenderblush": [255, 240, 245],
  1359. "lawngreen": [124, 252, 0],
  1360. "lemonchiffon": [255, 250, 205],
  1361. "lightblue": [173, 216, 230],
  1362. "lightcoral": [240, 128, 128],
  1363. "lightcyan": [224, 255, 255],
  1364. "lightgoldenrodyellow": [250, 250, 210],
  1365. "lightgray": [211, 211, 211],
  1366. "lightgreen": [144, 238, 144],
  1367. "lightgrey": [211, 211, 211],
  1368. "lightpink": [255, 182, 193],
  1369. "lightsalmon": [255, 160, 122],
  1370. "lightseagreen": [32, 178, 170],
  1371. "lightskyblue": [135, 206, 250],
  1372. "lightslategray": [119, 136, 153],
  1373. "lightslategrey": [119, 136, 153],
  1374. "lightsteelblue": [176, 196, 222],
  1375. "lightyellow": [255, 255, 224],
  1376. "lime": [0, 255, 0],
  1377. "limegreen": [50, 205, 50],
  1378. "linen": [250, 240, 230],
  1379. "magenta": [255, 0, 255],
  1380. "maroon": [128, 0, 0],
  1381. "mediumaquamarine": [102, 205, 170],
  1382. "mediumblue": [0, 0, 205],
  1383. "mediumorchid": [186, 85, 211],
  1384. "mediumpurple": [147, 112, 219],
  1385. "mediumseagreen": [60, 179, 113],
  1386. "mediumslateblue": [123, 104, 238],
  1387. "mediumspringgreen": [0, 250, 154],
  1388. "mediumturquoise": [72, 209, 204],
  1389. "mediumvioletred": [199, 21, 133],
  1390. "midnightblue": [25, 25, 112],
  1391. "mintcream": [245, 255, 250],
  1392. "mistyrose": [255, 228, 225],
  1393. "moccasin": [255, 228, 181],
  1394. "navajowhite": [255, 222, 173],
  1395. "navy": [0, 0, 128],
  1396. "oldlace": [253, 245, 230],
  1397. "olive": [128, 128, 0],
  1398. "olivedrab": [107, 142, 35],
  1399. "orange": [255, 165, 0],
  1400. "orangered": [255, 69, 0],
  1401. "orchid": [218, 112, 214],
  1402. "palegoldenrod": [238, 232, 170],
  1403. "palegreen": [152, 251, 152],
  1404. "paleturquoise": [175, 238, 238],
  1405. "palevioletred": [219, 112, 147],
  1406. "papayawhip": [255, 239, 213],
  1407. "peachpuff": [255, 218, 185],
  1408. "peru": [205, 133, 63],
  1409. "pink": [255, 192, 203],
  1410. "plum": [221, 160, 221],
  1411. "powderblue": [176, 224, 230],
  1412. "purple": [128, 0, 128],
  1413. "rebeccapurple": [102, 51, 153],
  1414. "red": [255, 0, 0],
  1415. "rosybrown": [188, 143, 143],
  1416. "royalblue": [65, 105, 225],
  1417. "saddlebrown": [139, 69, 19],
  1418. "salmon": [250, 128, 114],
  1419. "sandybrown": [244, 164, 96],
  1420. "seagreen": [46, 139, 87],
  1421. "seashell": [255, 245, 238],
  1422. "sienna": [160, 82, 45],
  1423. "silver": [192, 192, 192],
  1424. "skyblue": [135, 206, 235],
  1425. "slateblue": [106, 90, 205],
  1426. "slategray": [112, 128, 144],
  1427. "slategrey": [112, 128, 144],
  1428. "snow": [255, 250, 250],
  1429. "springgreen": [0, 255, 127],
  1430. "steelblue": [70, 130, 180],
  1431. "tan": [210, 180, 140],
  1432. "teal": [0, 128, 128],
  1433. "thistle": [216, 191, 216],
  1434. "tomato": [255, 99, 71],
  1435. "turquoise": [64, 224, 208],
  1436. "violet": [238, 130, 238],
  1437. "wheat": [245, 222, 179],
  1438. "white": [255, 255, 255],
  1439. "whitesmoke": [245, 245, 245],
  1440. "yellow": [255, 255, 0],
  1441. "yellowgreen": [154, 205, 50]
  1442. };
  1443. },{}],7:[function(require,module,exports){
  1444. /**
  1445. * @namespace Chart
  1446. */
  1447. var Chart = require(30)();
  1448. Chart.helpers = require(46);
  1449. // @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
  1450. require(28)(Chart);
  1451. Chart.Animation = require(22);
  1452. Chart.animationService = require(23);
  1453. Chart.defaults = require(26);
  1454. Chart.Element = require(27);
  1455. Chart.elements = require(41);
  1456. Chart.Interaction = require(29);
  1457. Chart.layouts = require(31);
  1458. Chart.platform = require(49);
  1459. Chart.plugins = require(32);
  1460. Chart.Scale = require(33);
  1461. Chart.scaleService = require(34);
  1462. Chart.Ticks = require(35);
  1463. Chart.Tooltip = require(36);
  1464. require(24)(Chart);
  1465. require(25)(Chart);
  1466. require(56)(Chart);
  1467. require(54)(Chart);
  1468. require(55)(Chart);
  1469. require(57)(Chart);
  1470. require(58)(Chart);
  1471. require(59)(Chart);
  1472. // Controllers must be loaded after elements
  1473. // See Chart.core.datasetController.dataElementType
  1474. require(15)(Chart);
  1475. require(16)(Chart);
  1476. require(17)(Chart);
  1477. require(18)(Chart);
  1478. require(19)(Chart);
  1479. require(20)(Chart);
  1480. require(21)(Chart);
  1481. require(8)(Chart);
  1482. require(9)(Chart);
  1483. require(10)(Chart);
  1484. require(11)(Chart);
  1485. require(12)(Chart);
  1486. require(13)(Chart);
  1487. require(14)(Chart);
  1488. // Loading built-in plugins
  1489. var plugins = require(50);
  1490. for (var k in plugins) {
  1491. if (plugins.hasOwnProperty(k)) {
  1492. Chart.plugins.register(plugins[k]);
  1493. }
  1494. }
  1495. Chart.platform.initialize();
  1496. module.exports = Chart;
  1497. if (typeof window !== 'undefined') {
  1498. window.Chart = Chart;
  1499. }
  1500. // DEPRECATIONS
  1501. /**
  1502. * Provided for backward compatibility, not available anymore
  1503. * @namespace Chart.Legend
  1504. * @deprecated since version 2.1.5
  1505. * @todo remove at version 3
  1506. * @private
  1507. */
  1508. Chart.Legend = plugins.legend._element;
  1509. /**
  1510. * Provided for backward compatibility, not available anymore
  1511. * @namespace Chart.Title
  1512. * @deprecated since version 2.1.5
  1513. * @todo remove at version 3
  1514. * @private
  1515. */
  1516. Chart.Title = plugins.title._element;
  1517. /**
  1518. * Provided for backward compatibility, use Chart.plugins instead
  1519. * @namespace Chart.pluginService
  1520. * @deprecated since version 2.1.5
  1521. * @todo remove at version 3
  1522. * @private
  1523. */
  1524. Chart.pluginService = Chart.plugins;
  1525. /**
  1526. * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
  1527. * effect, instead simply create/register plugins via plain JavaScript objects.
  1528. * @interface Chart.PluginBase
  1529. * @deprecated since version 2.5.0
  1530. * @todo remove at version 3
  1531. * @private
  1532. */
  1533. Chart.PluginBase = Chart.Element.extend({});
  1534. /**
  1535. * Provided for backward compatibility, use Chart.helpers.canvas instead.
  1536. * @namespace Chart.canvasHelpers
  1537. * @deprecated since version 2.6.0
  1538. * @todo remove at version 3
  1539. * @private
  1540. */
  1541. Chart.canvasHelpers = Chart.helpers.canvas;
  1542. /**
  1543. * Provided for backward compatibility, use Chart.layouts instead.
  1544. * @namespace Chart.layoutService
  1545. * @deprecated since version 2.8.0
  1546. * @todo remove at version 3
  1547. * @private
  1548. */
  1549. Chart.layoutService = Chart.layouts;
  1550. },{"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){
  1551. 'use strict';
  1552. module.exports = function(Chart) {
  1553. Chart.Bar = function(context, config) {
  1554. config.type = 'bar';
  1555. return new Chart(context, config);
  1556. };
  1557. };
  1558. },{}],9:[function(require,module,exports){
  1559. 'use strict';
  1560. module.exports = function(Chart) {
  1561. Chart.Bubble = function(context, config) {
  1562. config.type = 'bubble';
  1563. return new Chart(context, config);
  1564. };
  1565. };
  1566. },{}],10:[function(require,module,exports){
  1567. 'use strict';
  1568. module.exports = function(Chart) {
  1569. Chart.Doughnut = function(context, config) {
  1570. config.type = 'doughnut';
  1571. return new Chart(context, config);
  1572. };
  1573. };
  1574. },{}],11:[function(require,module,exports){
  1575. 'use strict';
  1576. module.exports = function(Chart) {
  1577. Chart.Line = function(context, config) {
  1578. config.type = 'line';
  1579. return new Chart(context, config);
  1580. };
  1581. };
  1582. },{}],12:[function(require,module,exports){
  1583. 'use strict';
  1584. module.exports = function(Chart) {
  1585. Chart.PolarArea = function(context, config) {
  1586. config.type = 'polarArea';
  1587. return new Chart(context, config);
  1588. };
  1589. };
  1590. },{}],13:[function(require,module,exports){
  1591. 'use strict';
  1592. module.exports = function(Chart) {
  1593. Chart.Radar = function(context, config) {
  1594. config.type = 'radar';
  1595. return new Chart(context, config);
  1596. };
  1597. };
  1598. },{}],14:[function(require,module,exports){
  1599. 'use strict';
  1600. module.exports = function(Chart) {
  1601. Chart.Scatter = function(context, config) {
  1602. config.type = 'scatter';
  1603. return new Chart(context, config);
  1604. };
  1605. };
  1606. },{}],15:[function(require,module,exports){
  1607. 'use strict';
  1608. var defaults = require(26);
  1609. var elements = require(41);
  1610. var helpers = require(46);
  1611. defaults._set('bar', {
  1612. hover: {
  1613. mode: 'label'
  1614. },
  1615. scales: {
  1616. xAxes: [{
  1617. type: 'category',
  1618. // Specific to Bar Controller
  1619. categoryPercentage: 0.8,
  1620. barPercentage: 0.9,
  1621. // offset settings
  1622. offset: true,
  1623. // grid line settings
  1624. gridLines: {
  1625. offsetGridLines: true
  1626. }
  1627. }],
  1628. yAxes: [{
  1629. type: 'linear'
  1630. }]
  1631. }
  1632. });
  1633. defaults._set('horizontalBar', {
  1634. hover: {
  1635. mode: 'index',
  1636. axis: 'y'
  1637. },
  1638. scales: {
  1639. xAxes: [{
  1640. type: 'linear',
  1641. position: 'bottom'
  1642. }],
  1643. yAxes: [{
  1644. position: 'left',
  1645. type: 'category',
  1646. // Specific to Horizontal Bar Controller
  1647. categoryPercentage: 0.8,
  1648. barPercentage: 0.9,
  1649. // offset settings
  1650. offset: true,
  1651. // grid line settings
  1652. gridLines: {
  1653. offsetGridLines: true
  1654. }
  1655. }]
  1656. },
  1657. elements: {
  1658. rectangle: {
  1659. borderSkipped: 'left'
  1660. }
  1661. },
  1662. tooltips: {
  1663. callbacks: {
  1664. title: function(item, data) {
  1665. // Pick first xLabel for now
  1666. var title = '';
  1667. if (item.length > 0) {
  1668. if (item[0].yLabel) {
  1669. title = item[0].yLabel;
  1670. } else if (data.labels.length > 0 && item[0].index < data.labels.length) {
  1671. title = data.labels[item[0].index];
  1672. }
  1673. }
  1674. return title;
  1675. },
  1676. label: function(item, data) {
  1677. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  1678. return datasetLabel + ': ' + item.xLabel;
  1679. }
  1680. },
  1681. mode: 'index',
  1682. axis: 'y'
  1683. }
  1684. });
  1685. /**
  1686. * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  1687. * @private
  1688. */
  1689. function computeMinSampleSize(scale, pixels) {
  1690. var min = scale.isHorizontal() ? scale.width : scale.height;
  1691. var ticks = scale.getTicks();
  1692. var prev, curr, i, ilen;
  1693. for (i = 1, ilen = pixels.length; i < ilen; ++i) {
  1694. min = Math.min(min, pixels[i] - pixels[i - 1]);
  1695. }
  1696. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  1697. curr = scale.getPixelForTick(i);
  1698. min = i > 0 ? Math.min(min, curr - prev) : min;
  1699. prev = curr;
  1700. }
  1701. return min;
  1702. }
  1703. /**
  1704. * Computes an "ideal" category based on the absolute bar thickness or, if undefined or null,
  1705. * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This
  1706. * mode currently always generates bars equally sized (until we introduce scriptable options?).
  1707. * @private
  1708. */
  1709. function computeFitCategoryTraits(index, ruler, options) {
  1710. var thickness = options.barThickness;
  1711. var count = ruler.stackCount;
  1712. var curr = ruler.pixels[index];
  1713. var size, ratio;
  1714. if (helpers.isNullOrUndef(thickness)) {
  1715. size = ruler.min * options.categoryPercentage;
  1716. ratio = options.barPercentage;
  1717. } else {
  1718. // When bar thickness is enforced, category and bar percentages are ignored.
  1719. // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
  1720. // and deprecate barPercentage since this value is ignored when thickness is absolute.
  1721. size = thickness * count;
  1722. ratio = 1;
  1723. }
  1724. return {
  1725. chunk: size / count,
  1726. ratio: ratio,
  1727. start: curr - (size / 2)
  1728. };
  1729. }
  1730. /**
  1731. * Computes an "optimal" category that globally arranges bars side by side (no gap when
  1732. * percentage options are 1), based on the previous and following categories. This mode
  1733. * generates bars with different widths when data are not evenly spaced.
  1734. * @private
  1735. */
  1736. function computeFlexCategoryTraits(index, ruler, options) {
  1737. var pixels = ruler.pixels;
  1738. var curr = pixels[index];
  1739. var prev = index > 0 ? pixels[index - 1] : null;
  1740. var next = index < pixels.length - 1 ? pixels[index + 1] : null;
  1741. var percent = options.categoryPercentage;
  1742. var start, size;
  1743. if (prev === null) {
  1744. // first data: its size is double based on the next point or,
  1745. // if it's also the last data, we use the scale end extremity.
  1746. prev = curr - (next === null ? ruler.end - curr : next - curr);
  1747. }
  1748. if (next === null) {
  1749. // last data: its size is also double based on the previous point.
  1750. next = curr + curr - prev;
  1751. }
  1752. start = curr - ((curr - prev) / 2) * percent;
  1753. size = ((next - prev) / 2) * percent;
  1754. return {
  1755. chunk: size / ruler.stackCount,
  1756. ratio: options.barPercentage,
  1757. start: start
  1758. };
  1759. }
  1760. module.exports = function(Chart) {
  1761. Chart.controllers.bar = Chart.DatasetController.extend({
  1762. dataElementType: elements.Rectangle,
  1763. initialize: function() {
  1764. var me = this;
  1765. var meta;
  1766. Chart.DatasetController.prototype.initialize.apply(me, arguments);
  1767. meta = me.getMeta();
  1768. meta.stack = me.getDataset().stack;
  1769. meta.bar = true;
  1770. },
  1771. update: function(reset) {
  1772. var me = this;
  1773. var rects = me.getMeta().data;
  1774. var i, ilen;
  1775. me._ruler = me.getRuler();
  1776. for (i = 0, ilen = rects.length; i < ilen; ++i) {
  1777. me.updateElement(rects[i], i, reset);
  1778. }
  1779. },
  1780. updateElement: function(rectangle, index, reset) {
  1781. var me = this;
  1782. var chart = me.chart;
  1783. var meta = me.getMeta();
  1784. var dataset = me.getDataset();
  1785. var custom = rectangle.custom || {};
  1786. var rectangleOptions = chart.options.elements.rectangle;
  1787. rectangle._xScale = me.getScaleForId(meta.xAxisID);
  1788. rectangle._yScale = me.getScaleForId(meta.yAxisID);
  1789. rectangle._datasetIndex = me.index;
  1790. rectangle._index = index;
  1791. rectangle._model = {
  1792. datasetLabel: dataset.label,
  1793. label: chart.data.labels[index],
  1794. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped,
  1795. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor),
  1796. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor),
  1797. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth)
  1798. };
  1799. me.updateElementGeometry(rectangle, index, reset);
  1800. rectangle.pivot();
  1801. },
  1802. /**
  1803. * @private
  1804. */
  1805. updateElementGeometry: function(rectangle, index, reset) {
  1806. var me = this;
  1807. var model = rectangle._model;
  1808. var vscale = me.getValueScale();
  1809. var base = vscale.getBasePixel();
  1810. var horizontal = vscale.isHorizontal();
  1811. var ruler = me._ruler || me.getRuler();
  1812. var vpixels = me.calculateBarValuePixels(me.index, index);
  1813. var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
  1814. model.horizontal = horizontal;
  1815. model.base = reset ? base : vpixels.base;
  1816. model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
  1817. model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
  1818. model.height = horizontal ? ipixels.size : undefined;
  1819. model.width = horizontal ? undefined : ipixels.size;
  1820. },
  1821. /**
  1822. * @private
  1823. */
  1824. getValueScaleId: function() {
  1825. return this.getMeta().yAxisID;
  1826. },
  1827. /**
  1828. * @private
  1829. */
  1830. getIndexScaleId: function() {
  1831. return this.getMeta().xAxisID;
  1832. },
  1833. /**
  1834. * @private
  1835. */
  1836. getValueScale: function() {
  1837. return this.getScaleForId(this.getValueScaleId());
  1838. },
  1839. /**
  1840. * @private
  1841. */
  1842. getIndexScale: function() {
  1843. return this.getScaleForId(this.getIndexScaleId());
  1844. },
  1845. /**
  1846. * Returns the stacks based on groups and bar visibility.
  1847. * @param {Number} [last] - The dataset index
  1848. * @returns {Array} The stack list
  1849. * @private
  1850. */
  1851. _getStacks: function(last) {
  1852. var me = this;
  1853. var chart = me.chart;
  1854. var scale = me.getIndexScale();
  1855. var stacked = scale.options.stacked;
  1856. var ilen = last === undefined ? chart.data.datasets.length : last + 1;
  1857. var stacks = [];
  1858. var i, meta;
  1859. for (i = 0; i < ilen; ++i) {
  1860. meta = chart.getDatasetMeta(i);
  1861. if (meta.bar && chart.isDatasetVisible(i) &&
  1862. (stacked === false ||
  1863. (stacked === true && stacks.indexOf(meta.stack) === -1) ||
  1864. (stacked === undefined && (meta.stack === undefined || stacks.indexOf(meta.stack) === -1)))) {
  1865. stacks.push(meta.stack);
  1866. }
  1867. }
  1868. return stacks;
  1869. },
  1870. /**
  1871. * Returns the effective number of stacks based on groups and bar visibility.
  1872. * @private
  1873. */
  1874. getStackCount: function() {
  1875. return this._getStacks().length;
  1876. },
  1877. /**
  1878. * Returns the stack index for the given dataset based on groups and bar visibility.
  1879. * @param {Number} [datasetIndex] - The dataset index
  1880. * @param {String} [name] - The stack name to find
  1881. * @returns {Number} The stack index
  1882. * @private
  1883. */
  1884. getStackIndex: function(datasetIndex, name) {
  1885. var stacks = this._getStacks(datasetIndex);
  1886. var index = (name !== undefined)
  1887. ? stacks.indexOf(name)
  1888. : -1; // indexOf returns -1 if element is not present
  1889. return (index === -1)
  1890. ? stacks.length - 1
  1891. : index;
  1892. },
  1893. /**
  1894. * @private
  1895. */
  1896. getRuler: function() {
  1897. var me = this;
  1898. var scale = me.getIndexScale();
  1899. var stackCount = me.getStackCount();
  1900. var datasetIndex = me.index;
  1901. var isHorizontal = scale.isHorizontal();
  1902. var start = isHorizontal ? scale.left : scale.top;
  1903. var end = start + (isHorizontal ? scale.width : scale.height);
  1904. var pixels = [];
  1905. var i, ilen, min;
  1906. for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
  1907. pixels.push(scale.getPixelForValue(null, i, datasetIndex));
  1908. }
  1909. min = helpers.isNullOrUndef(scale.options.barThickness)
  1910. ? computeMinSampleSize(scale, pixels)
  1911. : -1;
  1912. return {
  1913. min: min,
  1914. pixels: pixels,
  1915. start: start,
  1916. end: end,
  1917. stackCount: stackCount,
  1918. scale: scale
  1919. };
  1920. },
  1921. /**
  1922. * Note: pixel values are not clamped to the scale area.
  1923. * @private
  1924. */
  1925. calculateBarValuePixels: function(datasetIndex, index) {
  1926. var me = this;
  1927. var chart = me.chart;
  1928. var meta = me.getMeta();
  1929. var scale = me.getValueScale();
  1930. var datasets = chart.data.datasets;
  1931. var value = scale.getRightValue(datasets[datasetIndex].data[index]);
  1932. var stacked = scale.options.stacked;
  1933. var stack = meta.stack;
  1934. var start = 0;
  1935. var i, imeta, ivalue, base, head, size;
  1936. if (stacked || (stacked === undefined && stack !== undefined)) {
  1937. for (i = 0; i < datasetIndex; ++i) {
  1938. imeta = chart.getDatasetMeta(i);
  1939. if (imeta.bar &&
  1940. imeta.stack === stack &&
  1941. imeta.controller.getValueScaleId() === scale.id &&
  1942. chart.isDatasetVisible(i)) {
  1943. ivalue = scale.getRightValue(datasets[i].data[index]);
  1944. if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
  1945. start += ivalue;
  1946. }
  1947. }
  1948. }
  1949. }
  1950. base = scale.getPixelForValue(start);
  1951. head = scale.getPixelForValue(start + value);
  1952. size = (head - base) / 2;
  1953. return {
  1954. size: size,
  1955. base: base,
  1956. head: head,
  1957. center: head + size / 2
  1958. };
  1959. },
  1960. /**
  1961. * @private
  1962. */
  1963. calculateBarIndexPixels: function(datasetIndex, index, ruler) {
  1964. var me = this;
  1965. var options = ruler.scale.options;
  1966. var range = options.barThickness === 'flex'
  1967. ? computeFlexCategoryTraits(index, ruler, options)
  1968. : computeFitCategoryTraits(index, ruler, options);
  1969. var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
  1970. var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
  1971. var size = Math.min(
  1972. helpers.valueOrDefault(options.maxBarThickness, Infinity),
  1973. range.chunk * range.ratio);
  1974. return {
  1975. base: center - size / 2,
  1976. head: center + size / 2,
  1977. center: center,
  1978. size: size
  1979. };
  1980. },
  1981. draw: function() {
  1982. var me = this;
  1983. var chart = me.chart;
  1984. var scale = me.getValueScale();
  1985. var rects = me.getMeta().data;
  1986. var dataset = me.getDataset();
  1987. var ilen = rects.length;
  1988. var i = 0;
  1989. helpers.canvas.clipArea(chart.ctx, chart.chartArea);
  1990. for (; i < ilen; ++i) {
  1991. if (!isNaN(scale.getRightValue(dataset.data[i]))) {
  1992. rects[i].draw();
  1993. }
  1994. }
  1995. helpers.canvas.unclipArea(chart.ctx);
  1996. },
  1997. });
  1998. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  1999. /**
  2000. * @private
  2001. */
  2002. getValueScaleId: function() {
  2003. return this.getMeta().xAxisID;
  2004. },
  2005. /**
  2006. * @private
  2007. */
  2008. getIndexScaleId: function() {
  2009. return this.getMeta().yAxisID;
  2010. }
  2011. });
  2012. };
  2013. },{"26":26,"41":41,"46":46}],16:[function(require,module,exports){
  2014. 'use strict';
  2015. var defaults = require(26);
  2016. var elements = require(41);
  2017. var helpers = require(46);
  2018. defaults._set('bubble', {
  2019. hover: {
  2020. mode: 'single'
  2021. },
  2022. scales: {
  2023. xAxes: [{
  2024. type: 'linear', // bubble should probably use a linear scale by default
  2025. position: 'bottom',
  2026. id: 'x-axis-0' // need an ID so datasets can reference the scale
  2027. }],
  2028. yAxes: [{
  2029. type: 'linear',
  2030. position: 'left',
  2031. id: 'y-axis-0'
  2032. }]
  2033. },
  2034. tooltips: {
  2035. callbacks: {
  2036. title: function() {
  2037. // Title doesn't make sense for scatter since we format the data as a point
  2038. return '';
  2039. },
  2040. label: function(item, data) {
  2041. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  2042. var dataPoint = data.datasets[item.datasetIndex].data[item.index];
  2043. return datasetLabel + ': (' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.r + ')';
  2044. }
  2045. }
  2046. }
  2047. });
  2048. module.exports = function(Chart) {
  2049. Chart.controllers.bubble = Chart.DatasetController.extend({
  2050. /**
  2051. * @protected
  2052. */
  2053. dataElementType: elements.Point,
  2054. /**
  2055. * @protected
  2056. */
  2057. update: function(reset) {
  2058. var me = this;
  2059. var meta = me.getMeta();
  2060. var points = meta.data;
  2061. // Update Points
  2062. helpers.each(points, function(point, index) {
  2063. me.updateElement(point, index, reset);
  2064. });
  2065. },
  2066. /**
  2067. * @protected
  2068. */
  2069. updateElement: function(point, index, reset) {
  2070. var me = this;
  2071. var meta = me.getMeta();
  2072. var custom = point.custom || {};
  2073. var xScale = me.getScaleForId(meta.xAxisID);
  2074. var yScale = me.getScaleForId(meta.yAxisID);
  2075. var options = me._resolveElementOptions(point, index);
  2076. var data = me.getDataset().data[index];
  2077. var dsIndex = me.index;
  2078. var x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex);
  2079. var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex);
  2080. point._xScale = xScale;
  2081. point._yScale = yScale;
  2082. point._options = options;
  2083. point._datasetIndex = dsIndex;
  2084. point._index = index;
  2085. point._model = {
  2086. backgroundColor: options.backgroundColor,
  2087. borderColor: options.borderColor,
  2088. borderWidth: options.borderWidth,
  2089. hitRadius: options.hitRadius,
  2090. pointStyle: options.pointStyle,
  2091. rotation: options.rotation,
  2092. radius: reset ? 0 : options.radius,
  2093. skip: custom.skip || isNaN(x) || isNaN(y),
  2094. x: x,
  2095. y: y,
  2096. };
  2097. point.pivot();
  2098. },
  2099. /**
  2100. * @protected
  2101. */
  2102. setHoverStyle: function(point) {
  2103. var model = point._model;
  2104. var options = point._options;
  2105. point.$previousStyle = {
  2106. backgroundColor: model.backgroundColor,
  2107. borderColor: model.borderColor,
  2108. borderWidth: model.borderWidth,
  2109. radius: model.radius
  2110. };
  2111. model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
  2112. model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
  2113. model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
  2114. model.radius = options.radius + options.hoverRadius;
  2115. },
  2116. /**
  2117. * @private
  2118. */
  2119. _resolveElementOptions: function(point, index) {
  2120. var me = this;
  2121. var chart = me.chart;
  2122. var datasets = chart.data.datasets;
  2123. var dataset = datasets[me.index];
  2124. var custom = point.custom || {};
  2125. var options = chart.options.elements.point;
  2126. var resolve = helpers.options.resolve;
  2127. var data = dataset.data[index];
  2128. var values = {};
  2129. var i, ilen, key;
  2130. // Scriptable options
  2131. var context = {
  2132. chart: chart,
  2133. dataIndex: index,
  2134. dataset: dataset,
  2135. datasetIndex: me.index
  2136. };
  2137. var keys = [
  2138. 'backgroundColor',
  2139. 'borderColor',
  2140. 'borderWidth',
  2141. 'hoverBackgroundColor',
  2142. 'hoverBorderColor',
  2143. 'hoverBorderWidth',
  2144. 'hoverRadius',
  2145. 'hitRadius',
  2146. 'pointStyle',
  2147. 'rotation'
  2148. ];
  2149. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  2150. key = keys[i];
  2151. values[key] = resolve([
  2152. custom[key],
  2153. dataset[key],
  2154. options[key]
  2155. ], context, index);
  2156. }
  2157. // Custom radius resolution
  2158. values.radius = resolve([
  2159. custom.radius,
  2160. data ? data.r : undefined,
  2161. dataset.radius,
  2162. options.radius
  2163. ], context, index);
  2164. return values;
  2165. }
  2166. });
  2167. };
  2168. },{"26":26,"41":41,"46":46}],17:[function(require,module,exports){
  2169. 'use strict';
  2170. var defaults = require(26);
  2171. var elements = require(41);
  2172. var helpers = require(46);
  2173. defaults._set('doughnut', {
  2174. animation: {
  2175. // Boolean - Whether we animate the rotation of the Doughnut
  2176. animateRotate: true,
  2177. // Boolean - Whether we animate scaling the Doughnut from the centre
  2178. animateScale: false
  2179. },
  2180. hover: {
  2181. mode: 'single'
  2182. },
  2183. legendCallback: function(chart) {
  2184. var text = [];
  2185. text.push('<ul class="' + chart.id + '-legend">');
  2186. var data = chart.data;
  2187. var datasets = data.datasets;
  2188. var labels = data.labels;
  2189. if (datasets.length) {
  2190. for (var i = 0; i < datasets[0].data.length; ++i) {
  2191. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2192. if (labels[i]) {
  2193. text.push(labels[i]);
  2194. }
  2195. text.push('</li>');
  2196. }
  2197. }
  2198. text.push('</ul>');
  2199. return text.join('');
  2200. },
  2201. legend: {
  2202. labels: {
  2203. generateLabels: function(chart) {
  2204. var data = chart.data;
  2205. if (data.labels.length && data.datasets.length) {
  2206. return data.labels.map(function(label, i) {
  2207. var meta = chart.getDatasetMeta(0);
  2208. var ds = data.datasets[0];
  2209. var arc = meta.data[i];
  2210. var custom = arc && arc.custom || {};
  2211. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2212. var arcOpts = chart.options.elements.arc;
  2213. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2214. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2215. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2216. return {
  2217. text: label,
  2218. fillStyle: fill,
  2219. strokeStyle: stroke,
  2220. lineWidth: bw,
  2221. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2222. // Extra data used for toggling the correct item
  2223. index: i
  2224. };
  2225. });
  2226. }
  2227. return [];
  2228. }
  2229. },
  2230. onClick: function(e, legendItem) {
  2231. var index = legendItem.index;
  2232. var chart = this.chart;
  2233. var i, ilen, meta;
  2234. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2235. meta = chart.getDatasetMeta(i);
  2236. // toggle visibility of index if exists
  2237. if (meta.data[index]) {
  2238. meta.data[index].hidden = !meta.data[index].hidden;
  2239. }
  2240. }
  2241. chart.update();
  2242. }
  2243. },
  2244. // The percentage of the chart that we cut out of the middle.
  2245. cutoutPercentage: 50,
  2246. // The rotation of the chart, where the first data arc begins.
  2247. rotation: Math.PI * -0.5,
  2248. // The total circumference of the chart.
  2249. circumference: Math.PI * 2.0,
  2250. // Need to override these to give a nice default
  2251. tooltips: {
  2252. callbacks: {
  2253. title: function() {
  2254. return '';
  2255. },
  2256. label: function(tooltipItem, data) {
  2257. var dataLabel = data.labels[tooltipItem.index];
  2258. var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2259. if (helpers.isArray(dataLabel)) {
  2260. // show value on first line of multiline label
  2261. // need to clone because we are changing the value
  2262. dataLabel = dataLabel.slice();
  2263. dataLabel[0] += value;
  2264. } else {
  2265. dataLabel += value;
  2266. }
  2267. return dataLabel;
  2268. }
  2269. }
  2270. }
  2271. });
  2272. defaults._set('pie', helpers.clone(defaults.doughnut));
  2273. defaults._set('pie', {
  2274. cutoutPercentage: 0
  2275. });
  2276. module.exports = function(Chart) {
  2277. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  2278. dataElementType: elements.Arc,
  2279. linkScales: helpers.noop,
  2280. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2281. getRingIndex: function(datasetIndex) {
  2282. var ringIndex = 0;
  2283. for (var j = 0; j < datasetIndex; ++j) {
  2284. if (this.chart.isDatasetVisible(j)) {
  2285. ++ringIndex;
  2286. }
  2287. }
  2288. return ringIndex;
  2289. },
  2290. update: function(reset) {
  2291. var me = this;
  2292. var chart = me.chart;
  2293. var chartArea = chart.chartArea;
  2294. var opts = chart.options;
  2295. var arcOpts = opts.elements.arc;
  2296. var availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth;
  2297. var availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth;
  2298. var minSize = Math.min(availableWidth, availableHeight);
  2299. var offset = {x: 0, y: 0};
  2300. var meta = me.getMeta();
  2301. var cutoutPercentage = opts.cutoutPercentage;
  2302. var circumference = opts.circumference;
  2303. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2304. if (circumference < Math.PI * 2.0) {
  2305. var startAngle = opts.rotation % (Math.PI * 2.0);
  2306. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2307. var endAngle = startAngle + circumference;
  2308. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2309. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2310. var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2311. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2312. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2313. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2314. var cutout = cutoutPercentage / 100.0;
  2315. 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))};
  2316. 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))};
  2317. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2318. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2319. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2320. }
  2321. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  2322. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  2323. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
  2324. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2325. chart.offsetX = offset.x * chart.outerRadius;
  2326. chart.offsetY = offset.y * chart.outerRadius;
  2327. meta.total = me.calculateTotal();
  2328. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  2329. me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
  2330. helpers.each(meta.data, function(arc, index) {
  2331. me.updateElement(arc, index, reset);
  2332. });
  2333. },
  2334. updateElement: function(arc, index, reset) {
  2335. var me = this;
  2336. var chart = me.chart;
  2337. var chartArea = chart.chartArea;
  2338. var opts = chart.options;
  2339. var animationOpts = opts.animation;
  2340. var centerX = (chartArea.left + chartArea.right) / 2;
  2341. var centerY = (chartArea.top + chartArea.bottom) / 2;
  2342. var startAngle = opts.rotation; // non reset case handled later
  2343. var endAngle = opts.rotation; // non reset case handled later
  2344. var dataset = me.getDataset();
  2345. var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI));
  2346. var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
  2347. var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
  2348. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2349. helpers.extend(arc, {
  2350. // Utility
  2351. _datasetIndex: me.index,
  2352. _index: index,
  2353. // Desired view properties
  2354. _model: {
  2355. x: centerX + chart.offsetX,
  2356. y: centerY + chart.offsetY,
  2357. startAngle: startAngle,
  2358. endAngle: endAngle,
  2359. circumference: circumference,
  2360. outerRadius: outerRadius,
  2361. innerRadius: innerRadius,
  2362. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  2363. }
  2364. });
  2365. var model = arc._model;
  2366. // Resets the visual styles
  2367. var custom = arc.custom || {};
  2368. var valueOrDefault = helpers.valueAtIndexOrDefault;
  2369. var elementOpts = this.chart.options.elements.arc;
  2370. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  2371. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  2372. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  2373. // Set correct angles if not resetting
  2374. if (!reset || !animationOpts.animateRotate) {
  2375. if (index === 0) {
  2376. model.startAngle = opts.rotation;
  2377. } else {
  2378. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  2379. }
  2380. model.endAngle = model.startAngle + model.circumference;
  2381. }
  2382. arc.pivot();
  2383. },
  2384. calculateTotal: function() {
  2385. var dataset = this.getDataset();
  2386. var meta = this.getMeta();
  2387. var total = 0;
  2388. var value;
  2389. helpers.each(meta.data, function(element, index) {
  2390. value = dataset.data[index];
  2391. if (!isNaN(value) && !element.hidden) {
  2392. total += Math.abs(value);
  2393. }
  2394. });
  2395. /* if (total === 0) {
  2396. total = NaN;
  2397. }*/
  2398. return total;
  2399. },
  2400. calculateCircumference: function(value) {
  2401. var total = this.getMeta().total;
  2402. if (total > 0 && !isNaN(value)) {
  2403. return (Math.PI * 2.0) * (Math.abs(value) / total);
  2404. }
  2405. return 0;
  2406. },
  2407. // gets the max border or hover width to properly scale pie charts
  2408. getMaxBorderWidth: function(arcs) {
  2409. var max = 0;
  2410. var index = this.index;
  2411. var length = arcs.length;
  2412. var borderWidth;
  2413. var hoverWidth;
  2414. for (var i = 0; i < length; i++) {
  2415. borderWidth = arcs[i]._model ? arcs[i]._model.borderWidth : 0;
  2416. hoverWidth = arcs[i]._chart ? arcs[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2417. max = borderWidth > max ? borderWidth : max;
  2418. max = hoverWidth > max ? hoverWidth : max;
  2419. }
  2420. return max;
  2421. }
  2422. });
  2423. };
  2424. },{"26":26,"41":41,"46":46}],18:[function(require,module,exports){
  2425. 'use strict';
  2426. var defaults = require(26);
  2427. var elements = require(41);
  2428. var helpers = require(46);
  2429. defaults._set('line', {
  2430. showLines: true,
  2431. spanGaps: false,
  2432. hover: {
  2433. mode: 'label'
  2434. },
  2435. scales: {
  2436. xAxes: [{
  2437. type: 'category',
  2438. id: 'x-axis-0'
  2439. }],
  2440. yAxes: [{
  2441. type: 'linear',
  2442. id: 'y-axis-0'
  2443. }]
  2444. }
  2445. });
  2446. module.exports = function(Chart) {
  2447. function lineEnabled(dataset, options) {
  2448. return helpers.valueOrDefault(dataset.showLine, options.showLines);
  2449. }
  2450. Chart.controllers.line = Chart.DatasetController.extend({
  2451. datasetElementType: elements.Line,
  2452. dataElementType: elements.Point,
  2453. update: function(reset) {
  2454. var me = this;
  2455. var meta = me.getMeta();
  2456. var line = meta.dataset;
  2457. var points = meta.data || [];
  2458. var options = me.chart.options;
  2459. var lineElementOptions = options.elements.line;
  2460. var scale = me.getScaleForId(meta.yAxisID);
  2461. var i, ilen, custom;
  2462. var dataset = me.getDataset();
  2463. var showLine = lineEnabled(dataset, options);
  2464. // Update Line
  2465. if (showLine) {
  2466. custom = line.custom || {};
  2467. // Compatibility: If the properties are defined with only the old name, use those values
  2468. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2469. dataset.lineTension = dataset.tension;
  2470. }
  2471. // Utility
  2472. line._scale = scale;
  2473. line._datasetIndex = me.index;
  2474. // Data
  2475. line._children = points;
  2476. // Model
  2477. line._model = {
  2478. // Appearance
  2479. // The default behavior of lines is to break at null values, according
  2480. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2481. // This option gives lines the ability to span gaps
  2482. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2483. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2484. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2485. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2486. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2487. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2488. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2489. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2490. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2491. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2492. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.valueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2493. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.valueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2494. };
  2495. line.pivot();
  2496. }
  2497. // Update Points
  2498. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2499. me.updateElement(points[i], i, reset);
  2500. }
  2501. if (showLine && line._model.tension !== 0) {
  2502. me.updateBezierControlPoints();
  2503. }
  2504. // Now pivot the point for animation
  2505. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2506. points[i].pivot();
  2507. }
  2508. },
  2509. getPointBackgroundColor: function(point, index) {
  2510. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2511. var dataset = this.getDataset();
  2512. var custom = point.custom || {};
  2513. if (custom.backgroundColor) {
  2514. backgroundColor = custom.backgroundColor;
  2515. } else if (dataset.pointBackgroundColor) {
  2516. backgroundColor = helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2517. } else if (dataset.backgroundColor) {
  2518. backgroundColor = dataset.backgroundColor;
  2519. }
  2520. return backgroundColor;
  2521. },
  2522. getPointBorderColor: function(point, index) {
  2523. var borderColor = this.chart.options.elements.point.borderColor;
  2524. var dataset = this.getDataset();
  2525. var custom = point.custom || {};
  2526. if (custom.borderColor) {
  2527. borderColor = custom.borderColor;
  2528. } else if (dataset.pointBorderColor) {
  2529. borderColor = helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2530. } else if (dataset.borderColor) {
  2531. borderColor = dataset.borderColor;
  2532. }
  2533. return borderColor;
  2534. },
  2535. getPointBorderWidth: function(point, index) {
  2536. var borderWidth = this.chart.options.elements.point.borderWidth;
  2537. var dataset = this.getDataset();
  2538. var custom = point.custom || {};
  2539. if (!isNaN(custom.borderWidth)) {
  2540. borderWidth = custom.borderWidth;
  2541. } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
  2542. borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2543. } else if (!isNaN(dataset.borderWidth)) {
  2544. borderWidth = dataset.borderWidth;
  2545. }
  2546. return borderWidth;
  2547. },
  2548. getPointRotation: function(point, index) {
  2549. var pointRotation = this.chart.options.elements.point.rotation;
  2550. var dataset = this.getDataset();
  2551. var custom = point.custom || {};
  2552. if (!isNaN(custom.rotation)) {
  2553. pointRotation = custom.rotation;
  2554. } else if (!isNaN(dataset.pointRotation) || helpers.isArray(dataset.pointRotation)) {
  2555. pointRotation = helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointRotation);
  2556. }
  2557. return pointRotation;
  2558. },
  2559. updateElement: function(point, index, reset) {
  2560. var me = this;
  2561. var meta = me.getMeta();
  2562. var custom = point.custom || {};
  2563. var dataset = me.getDataset();
  2564. var datasetIndex = me.index;
  2565. var value = dataset.data[index];
  2566. var yScale = me.getScaleForId(meta.yAxisID);
  2567. var xScale = me.getScaleForId(meta.xAxisID);
  2568. var pointOptions = me.chart.options.elements.point;
  2569. var x, y;
  2570. // Compatibility: If the properties are defined with only the old name, use those values
  2571. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2572. dataset.pointRadius = dataset.radius;
  2573. }
  2574. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2575. dataset.pointHitRadius = dataset.hitRadius;
  2576. }
  2577. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
  2578. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2579. // Utility
  2580. point._xScale = xScale;
  2581. point._yScale = yScale;
  2582. point._datasetIndex = datasetIndex;
  2583. point._index = index;
  2584. // Desired view properties
  2585. point._model = {
  2586. x: x,
  2587. y: y,
  2588. skip: custom.skip || isNaN(x) || isNaN(y),
  2589. // Appearance
  2590. radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2591. pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2592. rotation: me.getPointRotation(point, index),
  2593. backgroundColor: me.getPointBackgroundColor(point, index),
  2594. borderColor: me.getPointBorderColor(point, index),
  2595. borderWidth: me.getPointBorderWidth(point, index),
  2596. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2597. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2598. // Tooltip
  2599. hitRadius: custom.hitRadius || helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2600. };
  2601. },
  2602. calculatePointY: function(value, index, datasetIndex) {
  2603. var me = this;
  2604. var chart = me.chart;
  2605. var meta = me.getMeta();
  2606. var yScale = me.getScaleForId(meta.yAxisID);
  2607. var sumPos = 0;
  2608. var sumNeg = 0;
  2609. var i, ds, dsMeta;
  2610. if (yScale.options.stacked) {
  2611. for (i = 0; i < datasetIndex; i++) {
  2612. ds = chart.data.datasets[i];
  2613. dsMeta = chart.getDatasetMeta(i);
  2614. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2615. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2616. if (stackedRightValue < 0) {
  2617. sumNeg += stackedRightValue || 0;
  2618. } else {
  2619. sumPos += stackedRightValue || 0;
  2620. }
  2621. }
  2622. }
  2623. var rightValue = Number(yScale.getRightValue(value));
  2624. if (rightValue < 0) {
  2625. return yScale.getPixelForValue(sumNeg + rightValue);
  2626. }
  2627. return yScale.getPixelForValue(sumPos + rightValue);
  2628. }
  2629. return yScale.getPixelForValue(value);
  2630. },
  2631. updateBezierControlPoints: function() {
  2632. var me = this;
  2633. var meta = me.getMeta();
  2634. var area = me.chart.chartArea;
  2635. var points = (meta.data || []);
  2636. var i, ilen, point, model, controlPoints;
  2637. // Only consider points that are drawn in case the spanGaps option is used
  2638. if (meta.dataset._model.spanGaps) {
  2639. points = points.filter(function(pt) {
  2640. return !pt._model.skip;
  2641. });
  2642. }
  2643. function capControlPoint(pt, min, max) {
  2644. return Math.max(Math.min(pt, max), min);
  2645. }
  2646. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2647. helpers.splineCurveMonotone(points);
  2648. } else {
  2649. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2650. point = points[i];
  2651. model = point._model;
  2652. controlPoints = helpers.splineCurve(
  2653. helpers.previousItem(points, i)._model,
  2654. model,
  2655. helpers.nextItem(points, i)._model,
  2656. meta.dataset._model.tension
  2657. );
  2658. model.controlPointPreviousX = controlPoints.previous.x;
  2659. model.controlPointPreviousY = controlPoints.previous.y;
  2660. model.controlPointNextX = controlPoints.next.x;
  2661. model.controlPointNextY = controlPoints.next.y;
  2662. }
  2663. }
  2664. if (me.chart.options.elements.line.capBezierPoints) {
  2665. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2666. model = points[i]._model;
  2667. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2668. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2669. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2670. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2671. }
  2672. }
  2673. },
  2674. draw: function() {
  2675. var me = this;
  2676. var chart = me.chart;
  2677. var meta = me.getMeta();
  2678. var points = meta.data || [];
  2679. var area = chart.chartArea;
  2680. var ilen = points.length;
  2681. var halfBorderWidth;
  2682. var i = 0;
  2683. if (lineEnabled(me.getDataset(), chart.options)) {
  2684. halfBorderWidth = (meta.dataset._model.borderWidth || 0) / 2;
  2685. helpers.canvas.clipArea(chart.ctx, {
  2686. left: area.left,
  2687. right: area.right,
  2688. top: area.top - halfBorderWidth,
  2689. bottom: area.bottom + halfBorderWidth
  2690. });
  2691. meta.dataset.draw();
  2692. helpers.canvas.unclipArea(chart.ctx);
  2693. }
  2694. // Draw the points
  2695. for (; i < ilen; ++i) {
  2696. points[i].draw(area);
  2697. }
  2698. },
  2699. setHoverStyle: function(element) {
  2700. // Point
  2701. var dataset = this.chart.data.datasets[element._datasetIndex];
  2702. var index = element._index;
  2703. var custom = element.custom || {};
  2704. var model = element._model;
  2705. element.$previousStyle = {
  2706. backgroundColor: model.backgroundColor,
  2707. borderColor: model.borderColor,
  2708. borderWidth: model.borderWidth,
  2709. radius: model.radius
  2710. };
  2711. model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2712. model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2713. model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2714. model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2715. },
  2716. });
  2717. };
  2718. },{"26":26,"41":41,"46":46}],19:[function(require,module,exports){
  2719. 'use strict';
  2720. var defaults = require(26);
  2721. var elements = require(41);
  2722. var helpers = require(46);
  2723. defaults._set('polarArea', {
  2724. scale: {
  2725. type: 'radialLinear',
  2726. angleLines: {
  2727. display: false
  2728. },
  2729. gridLines: {
  2730. circular: true
  2731. },
  2732. pointLabels: {
  2733. display: false
  2734. },
  2735. ticks: {
  2736. beginAtZero: true
  2737. }
  2738. },
  2739. // Boolean - Whether to animate the rotation of the chart
  2740. animation: {
  2741. animateRotate: true,
  2742. animateScale: true
  2743. },
  2744. startAngle: -0.5 * Math.PI,
  2745. legendCallback: function(chart) {
  2746. var text = [];
  2747. text.push('<ul class="' + chart.id + '-legend">');
  2748. var data = chart.data;
  2749. var datasets = data.datasets;
  2750. var labels = data.labels;
  2751. if (datasets.length) {
  2752. for (var i = 0; i < datasets[0].data.length; ++i) {
  2753. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2754. if (labels[i]) {
  2755. text.push(labels[i]);
  2756. }
  2757. text.push('</li>');
  2758. }
  2759. }
  2760. text.push('</ul>');
  2761. return text.join('');
  2762. },
  2763. legend: {
  2764. labels: {
  2765. generateLabels: function(chart) {
  2766. var data = chart.data;
  2767. if (data.labels.length && data.datasets.length) {
  2768. return data.labels.map(function(label, i) {
  2769. var meta = chart.getDatasetMeta(0);
  2770. var ds = data.datasets[0];
  2771. var arc = meta.data[i];
  2772. var custom = arc.custom || {};
  2773. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2774. var arcOpts = chart.options.elements.arc;
  2775. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2776. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2777. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2778. return {
  2779. text: label,
  2780. fillStyle: fill,
  2781. strokeStyle: stroke,
  2782. lineWidth: bw,
  2783. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2784. // Extra data used for toggling the correct item
  2785. index: i
  2786. };
  2787. });
  2788. }
  2789. return [];
  2790. }
  2791. },
  2792. onClick: function(e, legendItem) {
  2793. var index = legendItem.index;
  2794. var chart = this.chart;
  2795. var i, ilen, meta;
  2796. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2797. meta = chart.getDatasetMeta(i);
  2798. meta.data[index].hidden = !meta.data[index].hidden;
  2799. }
  2800. chart.update();
  2801. }
  2802. },
  2803. // Need to override these to give a nice default
  2804. tooltips: {
  2805. callbacks: {
  2806. title: function() {
  2807. return '';
  2808. },
  2809. label: function(item, data) {
  2810. return data.labels[item.index] + ': ' + item.yLabel;
  2811. }
  2812. }
  2813. }
  2814. });
  2815. module.exports = function(Chart) {
  2816. Chart.controllers.polarArea = Chart.DatasetController.extend({
  2817. dataElementType: elements.Arc,
  2818. linkScales: helpers.noop,
  2819. update: function(reset) {
  2820. var me = this;
  2821. var dataset = me.getDataset();
  2822. var meta = me.getMeta();
  2823. var start = me.chart.options.startAngle || 0;
  2824. var starts = me._starts = [];
  2825. var angles = me._angles = [];
  2826. var i, ilen, angle;
  2827. me._updateRadius();
  2828. meta.count = me.countVisibleElements();
  2829. for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
  2830. starts[i] = start;
  2831. angle = me._computeAngle(i);
  2832. angles[i] = angle;
  2833. start += angle;
  2834. }
  2835. helpers.each(meta.data, function(arc, index) {
  2836. me.updateElement(arc, index, reset);
  2837. });
  2838. },
  2839. /**
  2840. * @private
  2841. */
  2842. _updateRadius: function() {
  2843. var me = this;
  2844. var chart = me.chart;
  2845. var chartArea = chart.chartArea;
  2846. var opts = chart.options;
  2847. var arcOpts = opts.elements.arc;
  2848. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  2849. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  2850. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  2851. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2852. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  2853. me.innerRadius = me.outerRadius - chart.radiusLength;
  2854. },
  2855. updateElement: function(arc, index, reset) {
  2856. var me = this;
  2857. var chart = me.chart;
  2858. var dataset = me.getDataset();
  2859. var opts = chart.options;
  2860. var animationOpts = opts.animation;
  2861. var scale = chart.scale;
  2862. var labels = chart.data.labels;
  2863. var centerX = scale.xCenter;
  2864. var centerY = scale.yCenter;
  2865. // var negHalfPI = -0.5 * Math.PI;
  2866. var datasetStartAngle = opts.startAngle;
  2867. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2868. var startAngle = me._starts[index];
  2869. var endAngle = startAngle + (arc.hidden ? 0 : me._angles[index]);
  2870. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2871. helpers.extend(arc, {
  2872. // Utility
  2873. _datasetIndex: me.index,
  2874. _index: index,
  2875. _scale: scale,
  2876. // Desired view properties
  2877. _model: {
  2878. x: centerX,
  2879. y: centerY,
  2880. innerRadius: 0,
  2881. outerRadius: reset ? resetRadius : distance,
  2882. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  2883. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  2884. label: helpers.valueAtIndexOrDefault(labels, index, labels[index])
  2885. }
  2886. });
  2887. // Apply border and fill style
  2888. var elementOpts = this.chart.options.elements.arc;
  2889. var custom = arc.custom || {};
  2890. var valueOrDefault = helpers.valueAtIndexOrDefault;
  2891. var model = arc._model;
  2892. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  2893. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  2894. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  2895. arc.pivot();
  2896. },
  2897. countVisibleElements: function() {
  2898. var dataset = this.getDataset();
  2899. var meta = this.getMeta();
  2900. var count = 0;
  2901. helpers.each(meta.data, function(element, index) {
  2902. if (!isNaN(dataset.data[index]) && !element.hidden) {
  2903. count++;
  2904. }
  2905. });
  2906. return count;
  2907. },
  2908. /**
  2909. * @private
  2910. */
  2911. _computeAngle: function(index) {
  2912. var me = this;
  2913. var count = this.getMeta().count;
  2914. var dataset = me.getDataset();
  2915. var meta = me.getMeta();
  2916. if (isNaN(dataset.data[index]) || meta.data[index].hidden) {
  2917. return 0;
  2918. }
  2919. // Scriptable options
  2920. var context = {
  2921. chart: me.chart,
  2922. dataIndex: index,
  2923. dataset: dataset,
  2924. datasetIndex: me.index
  2925. };
  2926. return helpers.options.resolve([
  2927. me.chart.options.elements.arc.angle,
  2928. (2 * Math.PI) / count
  2929. ], context, index);
  2930. }
  2931. });
  2932. };
  2933. },{"26":26,"41":41,"46":46}],20:[function(require,module,exports){
  2934. 'use strict';
  2935. var defaults = require(26);
  2936. var elements = require(41);
  2937. var helpers = require(46);
  2938. defaults._set('radar', {
  2939. scale: {
  2940. type: 'radialLinear'
  2941. },
  2942. elements: {
  2943. line: {
  2944. tension: 0 // no bezier in radar
  2945. }
  2946. }
  2947. });
  2948. module.exports = function(Chart) {
  2949. Chart.controllers.radar = Chart.DatasetController.extend({
  2950. datasetElementType: elements.Line,
  2951. dataElementType: elements.Point,
  2952. linkScales: helpers.noop,
  2953. update: function(reset) {
  2954. var me = this;
  2955. var meta = me.getMeta();
  2956. var line = meta.dataset;
  2957. var points = meta.data;
  2958. var custom = line.custom || {};
  2959. var dataset = me.getDataset();
  2960. var lineElementOptions = me.chart.options.elements.line;
  2961. var scale = me.chart.scale;
  2962. // Compatibility: If the properties are defined with only the old name, use those values
  2963. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2964. dataset.lineTension = dataset.tension;
  2965. }
  2966. helpers.extend(meta.dataset, {
  2967. // Utility
  2968. _datasetIndex: me.index,
  2969. _scale: scale,
  2970. // Data
  2971. _children: points,
  2972. _loop: true,
  2973. // Model
  2974. _model: {
  2975. // Appearance
  2976. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2977. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2978. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2979. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2980. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2981. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2982. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2983. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2984. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2985. }
  2986. });
  2987. meta.dataset.pivot();
  2988. // Update Points
  2989. helpers.each(points, function(point, index) {
  2990. me.updateElement(point, index, reset);
  2991. }, me);
  2992. // Update bezier control points
  2993. me.updateBezierControlPoints();
  2994. },
  2995. updateElement: function(point, index, reset) {
  2996. var me = this;
  2997. var custom = point.custom || {};
  2998. var dataset = me.getDataset();
  2999. var scale = me.chart.scale;
  3000. var pointElementOptions = me.chart.options.elements.point;
  3001. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  3002. // Compatibility: If the properties are defined with only the old name, use those values
  3003. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  3004. dataset.pointRadius = dataset.radius;
  3005. }
  3006. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  3007. dataset.pointHitRadius = dataset.hitRadius;
  3008. }
  3009. helpers.extend(point, {
  3010. // Utility
  3011. _datasetIndex: me.index,
  3012. _index: index,
  3013. _scale: scale,
  3014. // Desired view properties
  3015. _model: {
  3016. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  3017. y: reset ? scale.yCenter : pointPosition.y,
  3018. // Appearance
  3019. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
  3020. radius: custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  3021. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  3022. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  3023. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  3024. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  3025. rotation: custom.rotation ? custom.rotation : helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointElementOptions.rotation),
  3026. // Tooltip
  3027. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
  3028. }
  3029. });
  3030. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  3031. },
  3032. updateBezierControlPoints: function() {
  3033. var chartArea = this.chart.chartArea;
  3034. var meta = this.getMeta();
  3035. helpers.each(meta.data, function(point, index) {
  3036. var model = point._model;
  3037. var controlPoints = helpers.splineCurve(
  3038. helpers.previousItem(meta.data, index, true)._model,
  3039. model,
  3040. helpers.nextItem(meta.data, index, true)._model,
  3041. model.tension
  3042. );
  3043. // Prevent the bezier going outside of the bounds of the graph
  3044. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  3045. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  3046. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  3047. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  3048. // Now pivot the point for animation
  3049. point.pivot();
  3050. });
  3051. },
  3052. setHoverStyle: function(point) {
  3053. // Point
  3054. var dataset = this.chart.data.datasets[point._datasetIndex];
  3055. var custom = point.custom || {};
  3056. var index = point._index;
  3057. var model = point._model;
  3058. point.$previousStyle = {
  3059. backgroundColor: model.backgroundColor,
  3060. borderColor: model.borderColor,
  3061. borderWidth: model.borderWidth,
  3062. radius: model.radius
  3063. };
  3064. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3065. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3066. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3067. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3068. },
  3069. });
  3070. };
  3071. },{"26":26,"41":41,"46":46}],21:[function(require,module,exports){
  3072. 'use strict';
  3073. var defaults = require(26);
  3074. defaults._set('scatter', {
  3075. hover: {
  3076. mode: 'single'
  3077. },
  3078. scales: {
  3079. xAxes: [{
  3080. id: 'x-axis-1', // need an ID so datasets can reference the scale
  3081. type: 'linear', // scatter should not use a category axis
  3082. position: 'bottom'
  3083. }],
  3084. yAxes: [{
  3085. id: 'y-axis-1',
  3086. type: 'linear',
  3087. position: 'left'
  3088. }]
  3089. },
  3090. showLines: false,
  3091. tooltips: {
  3092. callbacks: {
  3093. title: function() {
  3094. return ''; // doesn't make sense for scatter since data are formatted as a point
  3095. },
  3096. label: function(item) {
  3097. return '(' + item.xLabel + ', ' + item.yLabel + ')';
  3098. }
  3099. }
  3100. }
  3101. });
  3102. module.exports = function(Chart) {
  3103. // Scatter charts use line controllers
  3104. Chart.controllers.scatter = Chart.controllers.line;
  3105. };
  3106. },{"26":26}],22:[function(require,module,exports){
  3107. 'use strict';
  3108. var Element = require(27);
  3109. var exports = module.exports = Element.extend({
  3110. chart: null, // the animation associated chart instance
  3111. currentStep: 0, // the current animation step
  3112. numSteps: 60, // default number of steps
  3113. easing: '', // the easing to use for this animation
  3114. render: null, // render function used by the animation service
  3115. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3116. onAnimationComplete: null, // user specified callback to fire when the animation finishes
  3117. });
  3118. // DEPRECATIONS
  3119. /**
  3120. * Provided for backward compatibility, use Chart.Animation instead
  3121. * @prop Chart.Animation#animationObject
  3122. * @deprecated since version 2.6.0
  3123. * @todo remove at version 3
  3124. */
  3125. Object.defineProperty(exports.prototype, 'animationObject', {
  3126. get: function() {
  3127. return this;
  3128. }
  3129. });
  3130. /**
  3131. * Provided for backward compatibility, use Chart.Animation#chart instead
  3132. * @prop Chart.Animation#chartInstance
  3133. * @deprecated since version 2.6.0
  3134. * @todo remove at version 3
  3135. */
  3136. Object.defineProperty(exports.prototype, 'chartInstance', {
  3137. get: function() {
  3138. return this.chart;
  3139. },
  3140. set: function(value) {
  3141. this.chart = value;
  3142. }
  3143. });
  3144. },{"27":27}],23:[function(require,module,exports){
  3145. /* global window: false */
  3146. 'use strict';
  3147. var defaults = require(26);
  3148. var helpers = require(46);
  3149. defaults._set('global', {
  3150. animation: {
  3151. duration: 1000,
  3152. easing: 'easeOutQuart',
  3153. onProgress: helpers.noop,
  3154. onComplete: helpers.noop
  3155. }
  3156. });
  3157. module.exports = {
  3158. frameDuration: 17,
  3159. animations: [],
  3160. dropFrames: 0,
  3161. request: null,
  3162. /**
  3163. * @param {Chart} chart - The chart to animate.
  3164. * @param {Chart.Animation} animation - The animation that we will animate.
  3165. * @param {Number} duration - The animation duration in ms.
  3166. * @param {Boolean} lazy - if true, the chart is not marked as animating to enable more responsive interactions
  3167. */
  3168. addAnimation: function(chart, animation, duration, lazy) {
  3169. var animations = this.animations;
  3170. var i, ilen;
  3171. animation.chart = chart;
  3172. if (!lazy) {
  3173. chart.animating = true;
  3174. }
  3175. for (i = 0, ilen = animations.length; i < ilen; ++i) {
  3176. if (animations[i].chart === chart) {
  3177. animations[i] = animation;
  3178. return;
  3179. }
  3180. }
  3181. animations.push(animation);
  3182. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3183. if (animations.length === 1) {
  3184. this.requestAnimationFrame();
  3185. }
  3186. },
  3187. cancelAnimation: function(chart) {
  3188. var index = helpers.findIndex(this.animations, function(animation) {
  3189. return animation.chart === chart;
  3190. });
  3191. if (index !== -1) {
  3192. this.animations.splice(index, 1);
  3193. chart.animating = false;
  3194. }
  3195. },
  3196. requestAnimationFrame: function() {
  3197. var me = this;
  3198. if (me.request === null) {
  3199. // Skip animation frame requests until the active one is executed.
  3200. // This can happen when processing mouse events, e.g. 'mousemove'
  3201. // and 'mouseout' events will trigger multiple renders.
  3202. me.request = helpers.requestAnimFrame.call(window, function() {
  3203. me.request = null;
  3204. me.startDigest();
  3205. });
  3206. }
  3207. },
  3208. /**
  3209. * @private
  3210. */
  3211. startDigest: function() {
  3212. var me = this;
  3213. var startTime = Date.now();
  3214. var framesToDrop = 0;
  3215. if (me.dropFrames > 1) {
  3216. framesToDrop = Math.floor(me.dropFrames);
  3217. me.dropFrames = me.dropFrames % 1;
  3218. }
  3219. me.advance(1 + framesToDrop);
  3220. var endTime = Date.now();
  3221. me.dropFrames += (endTime - startTime) / me.frameDuration;
  3222. // Do we have more stuff to animate?
  3223. if (me.animations.length > 0) {
  3224. me.requestAnimationFrame();
  3225. }
  3226. },
  3227. /**
  3228. * @private
  3229. */
  3230. advance: function(count) {
  3231. var animations = this.animations;
  3232. var animation, chart;
  3233. var i = 0;
  3234. while (i < animations.length) {
  3235. animation = animations[i];
  3236. chart = animation.chart;
  3237. animation.currentStep = (animation.currentStep || 0) + count;
  3238. animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
  3239. helpers.callback(animation.render, [chart, animation], chart);
  3240. helpers.callback(animation.onAnimationProgress, [animation], chart);
  3241. if (animation.currentStep >= animation.numSteps) {
  3242. helpers.callback(animation.onAnimationComplete, [animation], chart);
  3243. chart.animating = false;
  3244. animations.splice(i, 1);
  3245. } else {
  3246. ++i;
  3247. }
  3248. }
  3249. }
  3250. };
  3251. },{"26":26,"46":46}],24:[function(require,module,exports){
  3252. 'use strict';
  3253. var Animation = require(22);
  3254. var animations = require(23);
  3255. var defaults = require(26);
  3256. var helpers = require(46);
  3257. var Interaction = require(29);
  3258. var layouts = require(31);
  3259. var platform = require(49);
  3260. var plugins = require(32);
  3261. var scaleService = require(34);
  3262. var Tooltip = require(36);
  3263. module.exports = function(Chart) {
  3264. // Create a dictionary of chart types, to allow for extension of existing types
  3265. Chart.types = {};
  3266. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3267. // Destroy method on the chart will remove the instance of the chart from this reference.
  3268. Chart.instances = {};
  3269. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3270. Chart.controllers = {};
  3271. /**
  3272. * Initializes the given config with global and chart default values.
  3273. */
  3274. function initConfig(config) {
  3275. config = config || {};
  3276. // Do NOT use configMerge() for the data object because this method merges arrays
  3277. // and so would change references to labels and datasets, preventing data updates.
  3278. var data = config.data = config.data || {};
  3279. data.datasets = data.datasets || [];
  3280. data.labels = data.labels || [];
  3281. config.options = helpers.configMerge(
  3282. defaults.global,
  3283. defaults[config.type],
  3284. config.options || {});
  3285. return config;
  3286. }
  3287. /**
  3288. * Updates the config of the chart
  3289. * @param chart {Chart} chart to update the options for
  3290. */
  3291. function updateConfig(chart) {
  3292. var newOptions = chart.options;
  3293. helpers.each(chart.scales, function(scale) {
  3294. layouts.removeBox(chart, scale);
  3295. });
  3296. newOptions = helpers.configMerge(
  3297. Chart.defaults.global,
  3298. Chart.defaults[chart.config.type],
  3299. newOptions);
  3300. chart.options = chart.config.options = newOptions;
  3301. chart.ensureScalesHaveIDs();
  3302. chart.buildOrUpdateScales();
  3303. // Tooltip
  3304. chart.tooltip._options = newOptions.tooltips;
  3305. chart.tooltip.initialize();
  3306. }
  3307. function positionIsHorizontal(position) {
  3308. return position === 'top' || position === 'bottom';
  3309. }
  3310. helpers.extend(Chart.prototype, /** @lends Chart */ {
  3311. /**
  3312. * @private
  3313. */
  3314. construct: function(item, config) {
  3315. var me = this;
  3316. config = initConfig(config);
  3317. var context = platform.acquireContext(item, config);
  3318. var canvas = context && context.canvas;
  3319. var height = canvas && canvas.height;
  3320. var width = canvas && canvas.width;
  3321. me.id = helpers.uid();
  3322. me.ctx = context;
  3323. me.canvas = canvas;
  3324. me.config = config;
  3325. me.width = width;
  3326. me.height = height;
  3327. me.aspectRatio = height ? width / height : null;
  3328. me.options = config.options;
  3329. me._bufferedRender = false;
  3330. /**
  3331. * Provided for backward compatibility, Chart and Chart.Controller have been merged,
  3332. * the "instance" still need to be defined since it might be called from plugins.
  3333. * @prop Chart#chart
  3334. * @deprecated since version 2.6.0
  3335. * @todo remove at version 3
  3336. * @private
  3337. */
  3338. me.chart = me;
  3339. me.controller = me; // chart.chart.controller #inception
  3340. // Add the chart instance to the global namespace
  3341. Chart.instances[me.id] = me;
  3342. // Define alias to the config data: `chart.data === chart.config.data`
  3343. Object.defineProperty(me, 'data', {
  3344. get: function() {
  3345. return me.config.data;
  3346. },
  3347. set: function(value) {
  3348. me.config.data = value;
  3349. }
  3350. });
  3351. if (!context || !canvas) {
  3352. // The given item is not a compatible context2d element, let's return before finalizing
  3353. // the chart initialization but after setting basic chart / controller properties that
  3354. // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
  3355. // https://github.com/chartjs/Chart.js/issues/2807
  3356. console.error("Failed to create chart: can't acquire context from the given item");
  3357. return;
  3358. }
  3359. me.initialize();
  3360. me.update();
  3361. },
  3362. /**
  3363. * @private
  3364. */
  3365. initialize: function() {
  3366. var me = this;
  3367. // Before init plugin notification
  3368. plugins.notify(me, 'beforeInit');
  3369. helpers.retinaScale(me, me.options.devicePixelRatio);
  3370. me.bindEvents();
  3371. if (me.options.responsive) {
  3372. // Initial resize before chart draws (must be silent to preserve initial animations).
  3373. me.resize(true);
  3374. }
  3375. // Make sure scales have IDs and are built before we build any controllers.
  3376. me.ensureScalesHaveIDs();
  3377. me.buildOrUpdateScales();
  3378. me.initToolTip();
  3379. // After init plugin notification
  3380. plugins.notify(me, 'afterInit');
  3381. return me;
  3382. },
  3383. clear: function() {
  3384. helpers.canvas.clear(this);
  3385. return this;
  3386. },
  3387. stop: function() {
  3388. // Stops any current animation loop occurring
  3389. animations.cancelAnimation(this);
  3390. return this;
  3391. },
  3392. resize: function(silent) {
  3393. var me = this;
  3394. var options = me.options;
  3395. var canvas = me.canvas;
  3396. var aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
  3397. // the canvas render width and height will be casted to integers so make sure that
  3398. // the canvas display style uses the same integer values to avoid blurring effect.
  3399. // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
  3400. var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
  3401. var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
  3402. if (me.width === newWidth && me.height === newHeight) {
  3403. return;
  3404. }
  3405. canvas.width = me.width = newWidth;
  3406. canvas.height = me.height = newHeight;
  3407. canvas.style.width = newWidth + 'px';
  3408. canvas.style.height = newHeight + 'px';
  3409. helpers.retinaScale(me, options.devicePixelRatio);
  3410. if (!silent) {
  3411. // Notify any plugins about the resize
  3412. var newSize = {width: newWidth, height: newHeight};
  3413. plugins.notify(me, 'resize', [newSize]);
  3414. // Notify of resize
  3415. if (me.options.onResize) {
  3416. me.options.onResize(me, newSize);
  3417. }
  3418. me.stop();
  3419. me.update({
  3420. duration: me.options.responsiveAnimationDuration
  3421. });
  3422. }
  3423. },
  3424. ensureScalesHaveIDs: function() {
  3425. var options = this.options;
  3426. var scalesOptions = options.scales || {};
  3427. var scaleOptions = options.scale;
  3428. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  3429. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3430. });
  3431. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  3432. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3433. });
  3434. if (scaleOptions) {
  3435. scaleOptions.id = scaleOptions.id || 'scale';
  3436. }
  3437. },
  3438. /**
  3439. * Builds a map of scale ID to scale object for future lookup.
  3440. */
  3441. buildOrUpdateScales: function() {
  3442. var me = this;
  3443. var options = me.options;
  3444. var scales = me.scales || {};
  3445. var items = [];
  3446. var updated = Object.keys(scales).reduce(function(obj, id) {
  3447. obj[id] = false;
  3448. return obj;
  3449. }, {});
  3450. if (options.scales) {
  3451. items = items.concat(
  3452. (options.scales.xAxes || []).map(function(xAxisOptions) {
  3453. return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
  3454. }),
  3455. (options.scales.yAxes || []).map(function(yAxisOptions) {
  3456. return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
  3457. })
  3458. );
  3459. }
  3460. if (options.scale) {
  3461. items.push({
  3462. options: options.scale,
  3463. dtype: 'radialLinear',
  3464. isDefault: true,
  3465. dposition: 'chartArea'
  3466. });
  3467. }
  3468. helpers.each(items, function(item) {
  3469. var scaleOptions = item.options;
  3470. var id = scaleOptions.id;
  3471. var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
  3472. if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
  3473. scaleOptions.position = item.dposition;
  3474. }
  3475. updated[id] = true;
  3476. var scale = null;
  3477. if (id in scales && scales[id].type === scaleType) {
  3478. scale = scales[id];
  3479. scale.options = scaleOptions;
  3480. scale.ctx = me.ctx;
  3481. scale.chart = me;
  3482. } else {
  3483. var scaleClass = scaleService.getScaleConstructor(scaleType);
  3484. if (!scaleClass) {
  3485. return;
  3486. }
  3487. scale = new scaleClass({
  3488. id: id,
  3489. type: scaleType,
  3490. options: scaleOptions,
  3491. ctx: me.ctx,
  3492. chart: me
  3493. });
  3494. scales[scale.id] = scale;
  3495. }
  3496. scale.mergeTicksOptions();
  3497. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3498. // and consider it as a regular scale part of the "scales"" map only! This would
  3499. // make the logic easier and remove some useless? custom code.
  3500. if (item.isDefault) {
  3501. me.scale = scale;
  3502. }
  3503. });
  3504. // clear up discarded scales
  3505. helpers.each(updated, function(hasUpdated, id) {
  3506. if (!hasUpdated) {
  3507. delete scales[id];
  3508. }
  3509. });
  3510. me.scales = scales;
  3511. scaleService.addScalesToLayout(this);
  3512. },
  3513. buildOrUpdateControllers: function() {
  3514. var me = this;
  3515. var types = [];
  3516. var newControllers = [];
  3517. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3518. var meta = me.getDatasetMeta(datasetIndex);
  3519. var type = dataset.type || me.config.type;
  3520. if (meta.type && meta.type !== type) {
  3521. me.destroyDatasetMeta(datasetIndex);
  3522. meta = me.getDatasetMeta(datasetIndex);
  3523. }
  3524. meta.type = type;
  3525. types.push(meta.type);
  3526. if (meta.controller) {
  3527. meta.controller.updateIndex(datasetIndex);
  3528. meta.controller.linkScales();
  3529. } else {
  3530. var ControllerClass = Chart.controllers[meta.type];
  3531. if (ControllerClass === undefined) {
  3532. throw new Error('"' + meta.type + '" is not a chart type.');
  3533. }
  3534. meta.controller = new ControllerClass(me, datasetIndex);
  3535. newControllers.push(meta.controller);
  3536. }
  3537. }, me);
  3538. return newControllers;
  3539. },
  3540. /**
  3541. * Reset the elements of all datasets
  3542. * @private
  3543. */
  3544. resetElements: function() {
  3545. var me = this;
  3546. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3547. me.getDatasetMeta(datasetIndex).controller.reset();
  3548. }, me);
  3549. },
  3550. /**
  3551. * Resets the chart back to it's state before the initial animation
  3552. */
  3553. reset: function() {
  3554. this.resetElements();
  3555. this.tooltip.initialize();
  3556. },
  3557. update: function(config) {
  3558. var me = this;
  3559. if (!config || typeof config !== 'object') {
  3560. // backwards compatibility
  3561. config = {
  3562. duration: config,
  3563. lazy: arguments[1]
  3564. };
  3565. }
  3566. updateConfig(me);
  3567. // plugins options references might have change, let's invalidate the cache
  3568. // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  3569. plugins._invalidate(me);
  3570. if (plugins.notify(me, 'beforeUpdate') === false) {
  3571. return;
  3572. }
  3573. // In case the entire data object changed
  3574. me.tooltip._data = me.data;
  3575. // Make sure dataset controllers are updated and new controllers are reset
  3576. var newControllers = me.buildOrUpdateControllers();
  3577. // Make sure all dataset controllers have correct meta data counts
  3578. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3579. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3580. }, me);
  3581. me.updateLayout();
  3582. // Can only reset the new controllers after the scales have been updated
  3583. if (me.options.animation && me.options.animation.duration) {
  3584. helpers.each(newControllers, function(controller) {
  3585. controller.reset();
  3586. });
  3587. }
  3588. me.updateDatasets();
  3589. // Need to reset tooltip in case it is displayed with elements that are removed
  3590. // after update.
  3591. me.tooltip.initialize();
  3592. // Last active contains items that were previously in the tooltip.
  3593. // When we reset the tooltip, we need to clear it
  3594. me.lastActive = [];
  3595. // Do this before render so that any plugins that need final scale updates can use it
  3596. plugins.notify(me, 'afterUpdate');
  3597. if (me._bufferedRender) {
  3598. me._bufferedRequest = {
  3599. duration: config.duration,
  3600. easing: config.easing,
  3601. lazy: config.lazy
  3602. };
  3603. } else {
  3604. me.render(config);
  3605. }
  3606. },
  3607. /**
  3608. * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
  3609. * hook, in which case, plugins will not be called on `afterLayout`.
  3610. * @private
  3611. */
  3612. updateLayout: function() {
  3613. var me = this;
  3614. if (plugins.notify(me, 'beforeLayout') === false) {
  3615. return;
  3616. }
  3617. layouts.update(this, this.width, this.height);
  3618. /**
  3619. * Provided for backward compatibility, use `afterLayout` instead.
  3620. * @method IPlugin#afterScaleUpdate
  3621. * @deprecated since version 2.5.0
  3622. * @todo remove at version 3
  3623. * @private
  3624. */
  3625. plugins.notify(me, 'afterScaleUpdate');
  3626. plugins.notify(me, 'afterLayout');
  3627. },
  3628. /**
  3629. * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
  3630. * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
  3631. * @private
  3632. */
  3633. updateDatasets: function() {
  3634. var me = this;
  3635. if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
  3636. return;
  3637. }
  3638. for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3639. me.updateDataset(i);
  3640. }
  3641. plugins.notify(me, 'afterDatasetsUpdate');
  3642. },
  3643. /**
  3644. * Updates dataset at index unless a plugin returns `false` to the `beforeDatasetUpdate`
  3645. * hook, in which case, plugins will not be called on `afterDatasetUpdate`.
  3646. * @private
  3647. */
  3648. updateDataset: function(index) {
  3649. var me = this;
  3650. var meta = me.getDatasetMeta(index);
  3651. var args = {
  3652. meta: meta,
  3653. index: index
  3654. };
  3655. if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
  3656. return;
  3657. }
  3658. meta.controller.update();
  3659. plugins.notify(me, 'afterDatasetUpdate', [args]);
  3660. },
  3661. render: function(config) {
  3662. var me = this;
  3663. if (!config || typeof config !== 'object') {
  3664. // backwards compatibility
  3665. config = {
  3666. duration: config,
  3667. lazy: arguments[1]
  3668. };
  3669. }
  3670. var duration = config.duration;
  3671. var lazy = config.lazy;
  3672. if (plugins.notify(me, 'beforeRender') === false) {
  3673. return;
  3674. }
  3675. var animationOptions = me.options.animation;
  3676. var onComplete = function(animation) {
  3677. plugins.notify(me, 'afterRender');
  3678. helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
  3679. };
  3680. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3681. var animation = new Animation({
  3682. numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
  3683. easing: config.easing || animationOptions.easing,
  3684. render: function(chart, animationObject) {
  3685. var easingFunction = helpers.easing.effects[animationObject.easing];
  3686. var currentStep = animationObject.currentStep;
  3687. var stepDecimal = currentStep / animationObject.numSteps;
  3688. chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep);
  3689. },
  3690. onAnimationProgress: animationOptions.onProgress,
  3691. onAnimationComplete: onComplete
  3692. });
  3693. animations.addAnimation(me, animation, duration, lazy);
  3694. } else {
  3695. me.draw();
  3696. // See https://github.com/chartjs/Chart.js/issues/3781
  3697. onComplete(new Animation({numSteps: 0, chart: me}));
  3698. }
  3699. return me;
  3700. },
  3701. draw: function(easingValue) {
  3702. var me = this;
  3703. me.clear();
  3704. if (helpers.isNullOrUndef(easingValue)) {
  3705. easingValue = 1;
  3706. }
  3707. me.transition(easingValue);
  3708. if (me.width <= 0 || me.height <= 0) {
  3709. return;
  3710. }
  3711. if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
  3712. return;
  3713. }
  3714. // Draw all the scales
  3715. helpers.each(me.boxes, function(box) {
  3716. box.draw(me.chartArea);
  3717. }, me);
  3718. if (me.scale) {
  3719. me.scale.draw();
  3720. }
  3721. me.drawDatasets(easingValue);
  3722. me._drawTooltip(easingValue);
  3723. plugins.notify(me, 'afterDraw', [easingValue]);
  3724. },
  3725. /**
  3726. * @private
  3727. */
  3728. transition: function(easingValue) {
  3729. var me = this;
  3730. for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
  3731. if (me.isDatasetVisible(i)) {
  3732. me.getDatasetMeta(i).controller.transition(easingValue);
  3733. }
  3734. }
  3735. me.tooltip.transition(easingValue);
  3736. },
  3737. /**
  3738. * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
  3739. * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
  3740. * @private
  3741. */
  3742. drawDatasets: function(easingValue) {
  3743. var me = this;
  3744. if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
  3745. return;
  3746. }
  3747. // Draw datasets reversed to support proper line stacking
  3748. for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
  3749. if (me.isDatasetVisible(i)) {
  3750. me.drawDataset(i, easingValue);
  3751. }
  3752. }
  3753. plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
  3754. },
  3755. /**
  3756. * Draws dataset at index unless a plugin returns `false` to the `beforeDatasetDraw`
  3757. * hook, in which case, plugins will not be called on `afterDatasetDraw`.
  3758. * @private
  3759. */
  3760. drawDataset: function(index, easingValue) {
  3761. var me = this;
  3762. var meta = me.getDatasetMeta(index);
  3763. var args = {
  3764. meta: meta,
  3765. index: index,
  3766. easingValue: easingValue
  3767. };
  3768. if (plugins.notify(me, 'beforeDatasetDraw', [args]) === false) {
  3769. return;
  3770. }
  3771. meta.controller.draw(easingValue);
  3772. plugins.notify(me, 'afterDatasetDraw', [args]);
  3773. },
  3774. /**
  3775. * Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
  3776. * hook, in which case, plugins will not be called on `afterTooltipDraw`.
  3777. * @private
  3778. */
  3779. _drawTooltip: function(easingValue) {
  3780. var me = this;
  3781. var tooltip = me.tooltip;
  3782. var args = {
  3783. tooltip: tooltip,
  3784. easingValue: easingValue
  3785. };
  3786. if (plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
  3787. return;
  3788. }
  3789. tooltip.draw();
  3790. plugins.notify(me, 'afterTooltipDraw', [args]);
  3791. },
  3792. // Get the single element that was clicked on
  3793. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3794. getElementAtEvent: function(e) {
  3795. return Interaction.modes.single(this, e);
  3796. },
  3797. getElementsAtEvent: function(e) {
  3798. return Interaction.modes.label(this, e, {intersect: true});
  3799. },
  3800. getElementsAtXAxis: function(e) {
  3801. return Interaction.modes['x-axis'](this, e, {intersect: true});
  3802. },
  3803. getElementsAtEventForMode: function(e, mode, options) {
  3804. var method = Interaction.modes[mode];
  3805. if (typeof method === 'function') {
  3806. return method(this, e, options);
  3807. }
  3808. return [];
  3809. },
  3810. getDatasetAtEvent: function(e) {
  3811. return Interaction.modes.dataset(this, e, {intersect: true});
  3812. },
  3813. getDatasetMeta: function(datasetIndex) {
  3814. var me = this;
  3815. var dataset = me.data.datasets[datasetIndex];
  3816. if (!dataset._meta) {
  3817. dataset._meta = {};
  3818. }
  3819. var meta = dataset._meta[me.id];
  3820. if (!meta) {
  3821. meta = dataset._meta[me.id] = {
  3822. type: null,
  3823. data: [],
  3824. dataset: null,
  3825. controller: null,
  3826. hidden: null, // See isDatasetVisible() comment
  3827. xAxisID: null,
  3828. yAxisID: null
  3829. };
  3830. }
  3831. return meta;
  3832. },
  3833. getVisibleDatasetCount: function() {
  3834. var count = 0;
  3835. for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
  3836. if (this.isDatasetVisible(i)) {
  3837. count++;
  3838. }
  3839. }
  3840. return count;
  3841. },
  3842. isDatasetVisible: function(datasetIndex) {
  3843. var meta = this.getDatasetMeta(datasetIndex);
  3844. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  3845. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  3846. return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  3847. },
  3848. generateLegend: function() {
  3849. return this.options.legendCallback(this);
  3850. },
  3851. /**
  3852. * @private
  3853. */
  3854. destroyDatasetMeta: function(datasetIndex) {
  3855. var id = this.id;
  3856. var dataset = this.data.datasets[datasetIndex];
  3857. var meta = dataset._meta && dataset._meta[id];
  3858. if (meta) {
  3859. meta.controller.destroy();
  3860. delete dataset._meta[id];
  3861. }
  3862. },
  3863. destroy: function() {
  3864. var me = this;
  3865. var canvas = me.canvas;
  3866. var i, ilen;
  3867. me.stop();
  3868. // dataset controllers need to cleanup associated data
  3869. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3870. me.destroyDatasetMeta(i);
  3871. }
  3872. if (canvas) {
  3873. me.unbindEvents();
  3874. helpers.canvas.clear(me);
  3875. platform.releaseContext(me.ctx);
  3876. me.canvas = null;
  3877. me.ctx = null;
  3878. }
  3879. plugins.notify(me, 'destroy');
  3880. delete Chart.instances[me.id];
  3881. },
  3882. toBase64Image: function() {
  3883. return this.canvas.toDataURL.apply(this.canvas, arguments);
  3884. },
  3885. initToolTip: function() {
  3886. var me = this;
  3887. me.tooltip = new Tooltip({
  3888. _chart: me,
  3889. _chartInstance: me, // deprecated, backward compatibility
  3890. _data: me.data,
  3891. _options: me.options.tooltips
  3892. }, me);
  3893. },
  3894. /**
  3895. * @private
  3896. */
  3897. bindEvents: function() {
  3898. var me = this;
  3899. var listeners = me._listeners = {};
  3900. var listener = function() {
  3901. me.eventHandler.apply(me, arguments);
  3902. };
  3903. helpers.each(me.options.events, function(type) {
  3904. platform.addEventListener(me, type, listener);
  3905. listeners[type] = listener;
  3906. });
  3907. // Elements used to detect size change should not be injected for non responsive charts.
  3908. // See https://github.com/chartjs/Chart.js/issues/2210
  3909. if (me.options.responsive) {
  3910. listener = function() {
  3911. me.resize();
  3912. };
  3913. platform.addEventListener(me, 'resize', listener);
  3914. listeners.resize = listener;
  3915. }
  3916. },
  3917. /**
  3918. * @private
  3919. */
  3920. unbindEvents: function() {
  3921. var me = this;
  3922. var listeners = me._listeners;
  3923. if (!listeners) {
  3924. return;
  3925. }
  3926. delete me._listeners;
  3927. helpers.each(listeners, function(listener, type) {
  3928. platform.removeEventListener(me, type, listener);
  3929. });
  3930. },
  3931. updateHoverStyle: function(elements, mode, enabled) {
  3932. var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
  3933. var element, i, ilen;
  3934. for (i = 0, ilen = elements.length; i < ilen; ++i) {
  3935. element = elements[i];
  3936. if (element) {
  3937. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  3938. }
  3939. }
  3940. },
  3941. /**
  3942. * @private
  3943. */
  3944. eventHandler: function(e) {
  3945. var me = this;
  3946. var tooltip = me.tooltip;
  3947. if (plugins.notify(me, 'beforeEvent', [e]) === false) {
  3948. return;
  3949. }
  3950. // Buffer any update calls so that renders do not occur
  3951. me._bufferedRender = true;
  3952. me._bufferedRequest = null;
  3953. var changed = me.handleEvent(e);
  3954. // for smooth tooltip animations issue #4989
  3955. // the tooltip should be the source of change
  3956. // Animation check workaround:
  3957. // tooltip._start will be null when tooltip isn't animating
  3958. if (tooltip) {
  3959. changed = tooltip._start
  3960. ? tooltip.handleEvent(e)
  3961. : changed | tooltip.handleEvent(e);
  3962. }
  3963. plugins.notify(me, 'afterEvent', [e]);
  3964. var bufferedRequest = me._bufferedRequest;
  3965. if (bufferedRequest) {
  3966. // If we have an update that was triggered, we need to do a normal render
  3967. me.render(bufferedRequest);
  3968. } else if (changed && !me.animating) {
  3969. // If entering, leaving, or changing elements, animate the change via pivot
  3970. me.stop();
  3971. // We only need to render at this point. Updating will cause scales to be
  3972. // recomputed generating flicker & using more memory than necessary.
  3973. me.render({
  3974. duration: me.options.hover.animationDuration,
  3975. lazy: true
  3976. });
  3977. }
  3978. me._bufferedRender = false;
  3979. me._bufferedRequest = null;
  3980. return me;
  3981. },
  3982. /**
  3983. * Handle an event
  3984. * @private
  3985. * @param {IEvent} event the event to handle
  3986. * @return {Boolean} true if the chart needs to re-render
  3987. */
  3988. handleEvent: function(e) {
  3989. var me = this;
  3990. var options = me.options || {};
  3991. var hoverOptions = options.hover;
  3992. var changed = false;
  3993. me.lastActive = me.lastActive || [];
  3994. // Find Active Elements for hover and tooltips
  3995. if (e.type === 'mouseout') {
  3996. me.active = [];
  3997. } else {
  3998. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
  3999. }
  4000. // Invoke onHover hook
  4001. // Need to call with native event here to not break backwards compatibility
  4002. helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
  4003. if (e.type === 'mouseup' || e.type === 'click') {
  4004. if (options.onClick) {
  4005. // Use e.native here for backwards compatibility
  4006. options.onClick.call(me, e.native, me.active);
  4007. }
  4008. }
  4009. // Remove styling for last active (even if it may still be active)
  4010. if (me.lastActive.length) {
  4011. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  4012. }
  4013. // Built in hover styling
  4014. if (me.active.length && hoverOptions.mode) {
  4015. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  4016. }
  4017. changed = !helpers.arrayEquals(me.active, me.lastActive);
  4018. // Remember Last Actives
  4019. me.lastActive = me.active;
  4020. return changed;
  4021. }
  4022. });
  4023. /**
  4024. * Provided for backward compatibility, use Chart instead.
  4025. * @class Chart.Controller
  4026. * @deprecated since version 2.6.0
  4027. * @todo remove at version 3
  4028. * @private
  4029. */
  4030. Chart.Controller = Chart;
  4031. };
  4032. },{"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){
  4033. 'use strict';
  4034. var helpers = require(46);
  4035. module.exports = function(Chart) {
  4036. var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  4037. /**
  4038. * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
  4039. * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
  4040. * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
  4041. */
  4042. function listenArrayEvents(array, listener) {
  4043. if (array._chartjs) {
  4044. array._chartjs.listeners.push(listener);
  4045. return;
  4046. }
  4047. Object.defineProperty(array, '_chartjs', {
  4048. configurable: true,
  4049. enumerable: false,
  4050. value: {
  4051. listeners: [listener]
  4052. }
  4053. });
  4054. arrayEvents.forEach(function(key) {
  4055. var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
  4056. var base = array[key];
  4057. Object.defineProperty(array, key, {
  4058. configurable: true,
  4059. enumerable: false,
  4060. value: function() {
  4061. var args = Array.prototype.slice.call(arguments);
  4062. var res = base.apply(this, args);
  4063. helpers.each(array._chartjs.listeners, function(object) {
  4064. if (typeof object[method] === 'function') {
  4065. object[method].apply(object, args);
  4066. }
  4067. });
  4068. return res;
  4069. }
  4070. });
  4071. });
  4072. }
  4073. /**
  4074. * Removes the given array event listener and cleanup extra attached properties (such as
  4075. * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
  4076. */
  4077. function unlistenArrayEvents(array, listener) {
  4078. var stub = array._chartjs;
  4079. if (!stub) {
  4080. return;
  4081. }
  4082. var listeners = stub.listeners;
  4083. var index = listeners.indexOf(listener);
  4084. if (index !== -1) {
  4085. listeners.splice(index, 1);
  4086. }
  4087. if (listeners.length > 0) {
  4088. return;
  4089. }
  4090. arrayEvents.forEach(function(key) {
  4091. delete array[key];
  4092. });
  4093. delete array._chartjs;
  4094. }
  4095. // Base class for all dataset controllers (line, bar, etc)
  4096. Chart.DatasetController = function(chart, datasetIndex) {
  4097. this.initialize(chart, datasetIndex);
  4098. };
  4099. helpers.extend(Chart.DatasetController.prototype, {
  4100. /**
  4101. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  4102. * @type {Chart.core.element}
  4103. */
  4104. datasetElementType: null,
  4105. /**
  4106. * Element type used to generate a meta data (e.g. Chart.element.Point).
  4107. * @type {Chart.core.element}
  4108. */
  4109. dataElementType: null,
  4110. initialize: function(chart, datasetIndex) {
  4111. var me = this;
  4112. me.chart = chart;
  4113. me.index = datasetIndex;
  4114. me.linkScales();
  4115. me.addElements();
  4116. },
  4117. updateIndex: function(datasetIndex) {
  4118. this.index = datasetIndex;
  4119. },
  4120. linkScales: function() {
  4121. var me = this;
  4122. var meta = me.getMeta();
  4123. var dataset = me.getDataset();
  4124. if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
  4125. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  4126. }
  4127. if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
  4128. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  4129. }
  4130. },
  4131. getDataset: function() {
  4132. return this.chart.data.datasets[this.index];
  4133. },
  4134. getMeta: function() {
  4135. return this.chart.getDatasetMeta(this.index);
  4136. },
  4137. getScaleForId: function(scaleID) {
  4138. return this.chart.scales[scaleID];
  4139. },
  4140. reset: function() {
  4141. this.update(true);
  4142. },
  4143. /**
  4144. * @private
  4145. */
  4146. destroy: function() {
  4147. if (this._data) {
  4148. unlistenArrayEvents(this._data, this);
  4149. }
  4150. },
  4151. createMetaDataset: function() {
  4152. var me = this;
  4153. var type = me.datasetElementType;
  4154. return type && new type({
  4155. _chart: me.chart,
  4156. _datasetIndex: me.index
  4157. });
  4158. },
  4159. createMetaData: function(index) {
  4160. var me = this;
  4161. var type = me.dataElementType;
  4162. return type && new type({
  4163. _chart: me.chart,
  4164. _datasetIndex: me.index,
  4165. _index: index
  4166. });
  4167. },
  4168. addElements: function() {
  4169. var me = this;
  4170. var meta = me.getMeta();
  4171. var data = me.getDataset().data || [];
  4172. var metaData = meta.data;
  4173. var i, ilen;
  4174. for (i = 0, ilen = data.length; i < ilen; ++i) {
  4175. metaData[i] = metaData[i] || me.createMetaData(i);
  4176. }
  4177. meta.dataset = meta.dataset || me.createMetaDataset();
  4178. },
  4179. addElementAndReset: function(index) {
  4180. var element = this.createMetaData(index);
  4181. this.getMeta().data.splice(index, 0, element);
  4182. this.updateElement(element, index, true);
  4183. },
  4184. buildOrUpdateElements: function() {
  4185. var me = this;
  4186. var dataset = me.getDataset();
  4187. var data = dataset.data || (dataset.data = []);
  4188. // In order to correctly handle data addition/deletion animation (an thus simulate
  4189. // real-time charts), we need to monitor these data modifications and synchronize
  4190. // the internal meta data accordingly.
  4191. if (me._data !== data) {
  4192. if (me._data) {
  4193. // This case happens when the user replaced the data array instance.
  4194. unlistenArrayEvents(me._data, me);
  4195. }
  4196. listenArrayEvents(data, me);
  4197. me._data = data;
  4198. }
  4199. // Re-sync meta data in case the user replaced the data array or if we missed
  4200. // any updates and so make sure that we handle number of datapoints changing.
  4201. me.resyncElements();
  4202. },
  4203. update: helpers.noop,
  4204. transition: function(easingValue) {
  4205. var meta = this.getMeta();
  4206. var elements = meta.data || [];
  4207. var ilen = elements.length;
  4208. var i = 0;
  4209. for (; i < ilen; ++i) {
  4210. elements[i].transition(easingValue);
  4211. }
  4212. if (meta.dataset) {
  4213. meta.dataset.transition(easingValue);
  4214. }
  4215. },
  4216. draw: function() {
  4217. var meta = this.getMeta();
  4218. var elements = meta.data || [];
  4219. var ilen = elements.length;
  4220. var i = 0;
  4221. if (meta.dataset) {
  4222. meta.dataset.draw();
  4223. }
  4224. for (; i < ilen; ++i) {
  4225. elements[i].draw();
  4226. }
  4227. },
  4228. removeHoverStyle: function(element) {
  4229. helpers.merge(element._model, element.$previousStyle || {});
  4230. delete element.$previousStyle;
  4231. },
  4232. setHoverStyle: function(element) {
  4233. var dataset = this.chart.data.datasets[element._datasetIndex];
  4234. var index = element._index;
  4235. var custom = element.custom || {};
  4236. var valueOrDefault = helpers.valueAtIndexOrDefault;
  4237. var getHoverColor = helpers.getHoverColor;
  4238. var model = element._model;
  4239. element.$previousStyle = {
  4240. backgroundColor: model.backgroundColor,
  4241. borderColor: model.borderColor,
  4242. borderWidth: model.borderWidth
  4243. };
  4244. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  4245. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  4246. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  4247. },
  4248. /**
  4249. * @private
  4250. */
  4251. resyncElements: function() {
  4252. var me = this;
  4253. var meta = me.getMeta();
  4254. var data = me.getDataset().data;
  4255. var numMeta = meta.data.length;
  4256. var numData = data.length;
  4257. if (numData < numMeta) {
  4258. meta.data.splice(numData, numMeta - numData);
  4259. } else if (numData > numMeta) {
  4260. me.insertElements(numMeta, numData - numMeta);
  4261. }
  4262. },
  4263. /**
  4264. * @private
  4265. */
  4266. insertElements: function(start, count) {
  4267. for (var i = 0; i < count; ++i) {
  4268. this.addElementAndReset(start + i);
  4269. }
  4270. },
  4271. /**
  4272. * @private
  4273. */
  4274. onDataPush: function() {
  4275. this.insertElements(this.getDataset().data.length - 1, arguments.length);
  4276. },
  4277. /**
  4278. * @private
  4279. */
  4280. onDataPop: function() {
  4281. this.getMeta().data.pop();
  4282. },
  4283. /**
  4284. * @private
  4285. */
  4286. onDataShift: function() {
  4287. this.getMeta().data.shift();
  4288. },
  4289. /**
  4290. * @private
  4291. */
  4292. onDataSplice: function(start, count) {
  4293. this.getMeta().data.splice(start, count);
  4294. this.insertElements(start, arguments.length - 2);
  4295. },
  4296. /**
  4297. * @private
  4298. */
  4299. onDataUnshift: function() {
  4300. this.insertElements(0, arguments.length);
  4301. }
  4302. });
  4303. Chart.DatasetController.extend = helpers.inherits;
  4304. };
  4305. },{"46":46}],26:[function(require,module,exports){
  4306. 'use strict';
  4307. var helpers = require(46);
  4308. module.exports = {
  4309. /**
  4310. * @private
  4311. */
  4312. _set: function(scope, values) {
  4313. return helpers.merge(this[scope] || (this[scope] = {}), values);
  4314. }
  4315. };
  4316. },{"46":46}],27:[function(require,module,exports){
  4317. 'use strict';
  4318. var color = require(3);
  4319. var helpers = require(46);
  4320. function interpolate(start, view, model, ease) {
  4321. var keys = Object.keys(model);
  4322. var i, ilen, key, actual, origin, target, type, c0, c1;
  4323. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  4324. key = keys[i];
  4325. target = model[key];
  4326. // if a value is added to the model after pivot() has been called, the view
  4327. // doesn't contain it, so let's initialize the view to the target value.
  4328. if (!view.hasOwnProperty(key)) {
  4329. view[key] = target;
  4330. }
  4331. actual = view[key];
  4332. if (actual === target || key[0] === '_') {
  4333. continue;
  4334. }
  4335. if (!start.hasOwnProperty(key)) {
  4336. start[key] = actual;
  4337. }
  4338. origin = start[key];
  4339. type = typeof target;
  4340. if (type === typeof origin) {
  4341. if (type === 'string') {
  4342. c0 = color(origin);
  4343. if (c0.valid) {
  4344. c1 = color(target);
  4345. if (c1.valid) {
  4346. view[key] = c1.mix(c0, ease).rgbString();
  4347. continue;
  4348. }
  4349. }
  4350. } else if (type === 'number' && isFinite(origin) && isFinite(target)) {
  4351. view[key] = origin + (target - origin) * ease;
  4352. continue;
  4353. }
  4354. }
  4355. view[key] = target;
  4356. }
  4357. }
  4358. var Element = function(configuration) {
  4359. helpers.extend(this, configuration);
  4360. this.initialize.apply(this, arguments);
  4361. };
  4362. helpers.extend(Element.prototype, {
  4363. initialize: function() {
  4364. this.hidden = false;
  4365. },
  4366. pivot: function() {
  4367. var me = this;
  4368. if (!me._view) {
  4369. me._view = helpers.clone(me._model);
  4370. }
  4371. me._start = {};
  4372. return me;
  4373. },
  4374. transition: function(ease) {
  4375. var me = this;
  4376. var model = me._model;
  4377. var start = me._start;
  4378. var view = me._view;
  4379. // No animation -> No Transition
  4380. if (!model || ease === 1) {
  4381. me._view = model;
  4382. me._start = null;
  4383. return me;
  4384. }
  4385. if (!view) {
  4386. view = me._view = {};
  4387. }
  4388. if (!start) {
  4389. start = me._start = {};
  4390. }
  4391. interpolate(start, view, model, ease);
  4392. return me;
  4393. },
  4394. tooltipPosition: function() {
  4395. return {
  4396. x: this._model.x,
  4397. y: this._model.y
  4398. };
  4399. },
  4400. hasValue: function() {
  4401. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4402. }
  4403. });
  4404. Element.extend = helpers.inherits;
  4405. module.exports = Element;
  4406. },{"3":3,"46":46}],28:[function(require,module,exports){
  4407. /* global window: false */
  4408. /* global document: false */
  4409. 'use strict';
  4410. var color = require(3);
  4411. var defaults = require(26);
  4412. var helpers = require(46);
  4413. var scaleService = require(34);
  4414. module.exports = function() {
  4415. // -- Basic js utility methods
  4416. helpers.configMerge = function(/* objects ... */) {
  4417. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4418. merger: function(key, target, source, options) {
  4419. var tval = target[key] || {};
  4420. var sval = source[key];
  4421. if (key === 'scales') {
  4422. // scale config merging is complex. Add our own function here for that
  4423. target[key] = helpers.scaleMerge(tval, sval);
  4424. } else if (key === 'scale') {
  4425. // used in polar area & radar charts since there is only one scale
  4426. target[key] = helpers.merge(tval, [scaleService.getScaleDefaults(sval.type), sval]);
  4427. } else {
  4428. helpers._merger(key, target, source, options);
  4429. }
  4430. }
  4431. });
  4432. };
  4433. helpers.scaleMerge = function(/* objects ... */) {
  4434. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4435. merger: function(key, target, source, options) {
  4436. if (key === 'xAxes' || key === 'yAxes') {
  4437. var slen = source[key].length;
  4438. var i, type, scale;
  4439. if (!target[key]) {
  4440. target[key] = [];
  4441. }
  4442. for (i = 0; i < slen; ++i) {
  4443. scale = source[key][i];
  4444. type = helpers.valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
  4445. if (i >= target[key].length) {
  4446. target[key].push({});
  4447. }
  4448. if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
  4449. // new/untyped scale or type changed: let's apply the new defaults
  4450. // then merge source scale to correctly overwrite the defaults.
  4451. helpers.merge(target[key][i], [scaleService.getScaleDefaults(type), scale]);
  4452. } else {
  4453. // scales type are the same
  4454. helpers.merge(target[key][i], scale);
  4455. }
  4456. }
  4457. } else {
  4458. helpers._merger(key, target, source, options);
  4459. }
  4460. }
  4461. });
  4462. };
  4463. helpers.where = function(collection, filterCallback) {
  4464. if (helpers.isArray(collection) && Array.prototype.filter) {
  4465. return collection.filter(filterCallback);
  4466. }
  4467. var filtered = [];
  4468. helpers.each(collection, function(item) {
  4469. if (filterCallback(item)) {
  4470. filtered.push(item);
  4471. }
  4472. });
  4473. return filtered;
  4474. };
  4475. helpers.findIndex = Array.prototype.findIndex ?
  4476. function(array, callback, scope) {
  4477. return array.findIndex(callback, scope);
  4478. } :
  4479. function(array, callback, scope) {
  4480. scope = scope === undefined ? array : scope;
  4481. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4482. if (callback.call(scope, array[i], i, array)) {
  4483. return i;
  4484. }
  4485. }
  4486. return -1;
  4487. };
  4488. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  4489. // Default to start of the array
  4490. if (helpers.isNullOrUndef(startIndex)) {
  4491. startIndex = -1;
  4492. }
  4493. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4494. var currentItem = arrayToSearch[i];
  4495. if (filterCallback(currentItem)) {
  4496. return currentItem;
  4497. }
  4498. }
  4499. };
  4500. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  4501. // Default to end of the array
  4502. if (helpers.isNullOrUndef(startIndex)) {
  4503. startIndex = arrayToSearch.length;
  4504. }
  4505. for (var i = startIndex - 1; i >= 0; i--) {
  4506. var currentItem = arrayToSearch[i];
  4507. if (filterCallback(currentItem)) {
  4508. return currentItem;
  4509. }
  4510. }
  4511. };
  4512. // -- Math methods
  4513. helpers.isNumber = function(n) {
  4514. return !isNaN(parseFloat(n)) && isFinite(n);
  4515. };
  4516. helpers.almostEquals = function(x, y, epsilon) {
  4517. return Math.abs(x - y) < epsilon;
  4518. };
  4519. helpers.almostWhole = function(x, epsilon) {
  4520. var rounded = Math.round(x);
  4521. return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
  4522. };
  4523. helpers.max = function(array) {
  4524. return array.reduce(function(max, value) {
  4525. if (!isNaN(value)) {
  4526. return Math.max(max, value);
  4527. }
  4528. return max;
  4529. }, Number.NEGATIVE_INFINITY);
  4530. };
  4531. helpers.min = function(array) {
  4532. return array.reduce(function(min, value) {
  4533. if (!isNaN(value)) {
  4534. return Math.min(min, value);
  4535. }
  4536. return min;
  4537. }, Number.POSITIVE_INFINITY);
  4538. };
  4539. helpers.sign = Math.sign ?
  4540. function(x) {
  4541. return Math.sign(x);
  4542. } :
  4543. function(x) {
  4544. x = +x; // convert to a number
  4545. if (x === 0 || isNaN(x)) {
  4546. return x;
  4547. }
  4548. return x > 0 ? 1 : -1;
  4549. };
  4550. helpers.log10 = Math.log10 ?
  4551. function(x) {
  4552. return Math.log10(x);
  4553. } :
  4554. function(x) {
  4555. var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
  4556. // Check for whole powers of 10,
  4557. // which due to floating point rounding error should be corrected.
  4558. var powerOf10 = Math.round(exponent);
  4559. var isPowerOf10 = x === Math.pow(10, powerOf10);
  4560. return isPowerOf10 ? powerOf10 : exponent;
  4561. };
  4562. helpers.toRadians = function(degrees) {
  4563. return degrees * (Math.PI / 180);
  4564. };
  4565. helpers.toDegrees = function(radians) {
  4566. return radians * (180 / Math.PI);
  4567. };
  4568. // Gets the angle from vertical upright to the point about a centre.
  4569. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  4570. var distanceFromXCenter = anglePoint.x - centrePoint.x;
  4571. var distanceFromYCenter = anglePoint.y - centrePoint.y;
  4572. var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4573. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4574. if (angle < (-0.5 * Math.PI)) {
  4575. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4576. }
  4577. return {
  4578. angle: angle,
  4579. distance: radialDistanceFromCenter
  4580. };
  4581. };
  4582. helpers.distanceBetweenPoints = function(pt1, pt2) {
  4583. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  4584. };
  4585. helpers.aliasPixel = function(pixelWidth) {
  4586. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4587. };
  4588. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  4589. // Props to Rob Spencer at scaled innovation for his post on splining between points
  4590. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4591. // This function must also respect "skipped" points
  4592. var previous = firstPoint.skip ? middlePoint : firstPoint;
  4593. var current = middlePoint;
  4594. var next = afterPoint.skip ? middlePoint : afterPoint;
  4595. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4596. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4597. var s01 = d01 / (d01 + d12);
  4598. var s12 = d12 / (d01 + d12);
  4599. // If all points are the same, s01 & s02 will be inf
  4600. s01 = isNaN(s01) ? 0 : s01;
  4601. s12 = isNaN(s12) ? 0 : s12;
  4602. var fa = t * s01; // scaling factor for triangle Ta
  4603. var fb = t * s12;
  4604. return {
  4605. previous: {
  4606. x: current.x - fa * (next.x - previous.x),
  4607. y: current.y - fa * (next.y - previous.y)
  4608. },
  4609. next: {
  4610. x: current.x + fb * (next.x - previous.x),
  4611. y: current.y + fb * (next.y - previous.y)
  4612. }
  4613. };
  4614. };
  4615. helpers.EPSILON = Number.EPSILON || 1e-14;
  4616. helpers.splineCurveMonotone = function(points) {
  4617. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4618. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4619. // between the dataset discrete points due to the interpolation.
  4620. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4621. var pointsWithTangents = (points || []).map(function(point) {
  4622. return {
  4623. model: point._model,
  4624. deltaK: 0,
  4625. mK: 0
  4626. };
  4627. });
  4628. // Calculate slopes (deltaK) and initialize tangents (mK)
  4629. var pointsLen = pointsWithTangents.length;
  4630. var i, pointBefore, pointCurrent, pointAfter;
  4631. for (i = 0; i < pointsLen; ++i) {
  4632. pointCurrent = pointsWithTangents[i];
  4633. if (pointCurrent.model.skip) {
  4634. continue;
  4635. }
  4636. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4637. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4638. if (pointAfter && !pointAfter.model.skip) {
  4639. var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
  4640. // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
  4641. pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
  4642. }
  4643. if (!pointBefore || pointBefore.model.skip) {
  4644. pointCurrent.mK = pointCurrent.deltaK;
  4645. } else if (!pointAfter || pointAfter.model.skip) {
  4646. pointCurrent.mK = pointBefore.deltaK;
  4647. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4648. pointCurrent.mK = 0;
  4649. } else {
  4650. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4651. }
  4652. }
  4653. // Adjust tangents to ensure monotonic properties
  4654. var alphaK, betaK, tauK, squaredMagnitude;
  4655. for (i = 0; i < pointsLen - 1; ++i) {
  4656. pointCurrent = pointsWithTangents[i];
  4657. pointAfter = pointsWithTangents[i + 1];
  4658. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4659. continue;
  4660. }
  4661. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4662. pointCurrent.mK = pointAfter.mK = 0;
  4663. continue;
  4664. }
  4665. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4666. betaK = pointAfter.mK / pointCurrent.deltaK;
  4667. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4668. if (squaredMagnitude <= 9) {
  4669. continue;
  4670. }
  4671. tauK = 3 / Math.sqrt(squaredMagnitude);
  4672. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4673. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4674. }
  4675. // Compute control points
  4676. var deltaX;
  4677. for (i = 0; i < pointsLen; ++i) {
  4678. pointCurrent = pointsWithTangents[i];
  4679. if (pointCurrent.model.skip) {
  4680. continue;
  4681. }
  4682. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4683. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4684. if (pointBefore && !pointBefore.model.skip) {
  4685. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4686. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4687. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4688. }
  4689. if (pointAfter && !pointAfter.model.skip) {
  4690. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4691. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4692. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4693. }
  4694. }
  4695. };
  4696. helpers.nextItem = function(collection, index, loop) {
  4697. if (loop) {
  4698. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4699. }
  4700. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4701. };
  4702. helpers.previousItem = function(collection, index, loop) {
  4703. if (loop) {
  4704. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4705. }
  4706. return index <= 0 ? collection[0] : collection[index - 1];
  4707. };
  4708. // Implementation of the nice number algorithm used in determining where axis labels will go
  4709. helpers.niceNum = function(range, round) {
  4710. var exponent = Math.floor(helpers.log10(range));
  4711. var fraction = range / Math.pow(10, exponent);
  4712. var niceFraction;
  4713. if (round) {
  4714. if (fraction < 1.5) {
  4715. niceFraction = 1;
  4716. } else if (fraction < 3) {
  4717. niceFraction = 2;
  4718. } else if (fraction < 7) {
  4719. niceFraction = 5;
  4720. } else {
  4721. niceFraction = 10;
  4722. }
  4723. } else if (fraction <= 1.0) {
  4724. niceFraction = 1;
  4725. } else if (fraction <= 2) {
  4726. niceFraction = 2;
  4727. } else if (fraction <= 5) {
  4728. niceFraction = 5;
  4729. } else {
  4730. niceFraction = 10;
  4731. }
  4732. return niceFraction * Math.pow(10, exponent);
  4733. };
  4734. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4735. helpers.requestAnimFrame = (function() {
  4736. if (typeof window === 'undefined') {
  4737. return function(callback) {
  4738. callback();
  4739. };
  4740. }
  4741. return window.requestAnimationFrame ||
  4742. window.webkitRequestAnimationFrame ||
  4743. window.mozRequestAnimationFrame ||
  4744. window.oRequestAnimationFrame ||
  4745. window.msRequestAnimationFrame ||
  4746. function(callback) {
  4747. return window.setTimeout(callback, 1000 / 60);
  4748. };
  4749. }());
  4750. // -- DOM methods
  4751. helpers.getRelativePosition = function(evt, chart) {
  4752. var mouseX, mouseY;
  4753. var e = evt.originalEvent || evt;
  4754. var canvas = evt.target || evt.srcElement;
  4755. var boundingRect = canvas.getBoundingClientRect();
  4756. var touches = e.touches;
  4757. if (touches && touches.length > 0) {
  4758. mouseX = touches[0].clientX;
  4759. mouseY = touches[0].clientY;
  4760. } else {
  4761. mouseX = e.clientX;
  4762. mouseY = e.clientY;
  4763. }
  4764. // Scale mouse coordinates into canvas coordinates
  4765. // by following the pattern laid out by 'jerryj' in the comments of
  4766. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4767. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4768. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4769. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4770. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4771. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4772. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4773. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4774. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4775. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4776. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4777. return {
  4778. x: mouseX,
  4779. y: mouseY
  4780. };
  4781. };
  4782. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4783. function parseMaxStyle(styleValue, node, parentProperty) {
  4784. var valueInPixels;
  4785. if (typeof styleValue === 'string') {
  4786. valueInPixels = parseInt(styleValue, 10);
  4787. if (styleValue.indexOf('%') !== -1) {
  4788. // percentage * size in dimension
  4789. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4790. }
  4791. } else {
  4792. valueInPixels = styleValue;
  4793. }
  4794. return valueInPixels;
  4795. }
  4796. /**
  4797. * Returns if the given value contains an effective constraint.
  4798. * @private
  4799. */
  4800. function isConstrainedValue(value) {
  4801. return value !== undefined && value !== null && value !== 'none';
  4802. }
  4803. // Private helper to get a constraint dimension
  4804. // @param domNode : the node to check the constraint on
  4805. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  4806. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4807. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  4808. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4809. var view = document.defaultView;
  4810. var parentNode = helpers._getParentNode(domNode);
  4811. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  4812. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  4813. var hasCNode = isConstrainedValue(constrainedNode);
  4814. var hasCContainer = isConstrainedValue(constrainedContainer);
  4815. var infinity = Number.POSITIVE_INFINITY;
  4816. if (hasCNode || hasCContainer) {
  4817. return Math.min(
  4818. hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  4819. hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  4820. }
  4821. return 'none';
  4822. }
  4823. // returns Number or undefined if no constraint
  4824. helpers.getConstraintWidth = function(domNode) {
  4825. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4826. };
  4827. // returns Number or undefined if no constraint
  4828. helpers.getConstraintHeight = function(domNode) {
  4829. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4830. };
  4831. /**
  4832. * @private
  4833. */
  4834. helpers._calculatePadding = function(container, padding, parentDimension) {
  4835. padding = helpers.getStyle(container, padding);
  4836. return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10);
  4837. };
  4838. /**
  4839. * @private
  4840. */
  4841. helpers._getParentNode = function(domNode) {
  4842. var parent = domNode.parentNode;
  4843. if (parent && parent.host) {
  4844. parent = parent.host;
  4845. }
  4846. return parent;
  4847. };
  4848. helpers.getMaximumWidth = function(domNode) {
  4849. var container = helpers._getParentNode(domNode);
  4850. if (!container) {
  4851. return domNode.clientWidth;
  4852. }
  4853. var clientWidth = container.clientWidth;
  4854. var paddingLeft = helpers._calculatePadding(container, 'padding-left', clientWidth);
  4855. var paddingRight = helpers._calculatePadding(container, 'padding-right', clientWidth);
  4856. var w = clientWidth - paddingLeft - paddingRight;
  4857. var cw = helpers.getConstraintWidth(domNode);
  4858. return isNaN(cw) ? w : Math.min(w, cw);
  4859. };
  4860. helpers.getMaximumHeight = function(domNode) {
  4861. var container = helpers._getParentNode(domNode);
  4862. if (!container) {
  4863. return domNode.clientHeight;
  4864. }
  4865. var clientHeight = container.clientHeight;
  4866. var paddingTop = helpers._calculatePadding(container, 'padding-top', clientHeight);
  4867. var paddingBottom = helpers._calculatePadding(container, 'padding-bottom', clientHeight);
  4868. var h = clientHeight - paddingTop - paddingBottom;
  4869. var ch = helpers.getConstraintHeight(domNode);
  4870. return isNaN(ch) ? h : Math.min(h, ch);
  4871. };
  4872. helpers.getStyle = function(el, property) {
  4873. return el.currentStyle ?
  4874. el.currentStyle[property] :
  4875. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4876. };
  4877. helpers.retinaScale = function(chart, forceRatio) {
  4878. var pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
  4879. if (pixelRatio === 1) {
  4880. return;
  4881. }
  4882. var canvas = chart.canvas;
  4883. var height = chart.height;
  4884. var width = chart.width;
  4885. canvas.height = height * pixelRatio;
  4886. canvas.width = width * pixelRatio;
  4887. chart.ctx.scale(pixelRatio, pixelRatio);
  4888. // If no style has been set on the canvas, the render size is used as display size,
  4889. // making the chart visually bigger, so let's enforce it to the "correct" values.
  4890. // See https://github.com/chartjs/Chart.js/issues/3575
  4891. if (!canvas.style.height && !canvas.style.width) {
  4892. canvas.style.height = height + 'px';
  4893. canvas.style.width = width + 'px';
  4894. }
  4895. };
  4896. // -- Canvas methods
  4897. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  4898. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  4899. };
  4900. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  4901. cache = cache || {};
  4902. var data = cache.data = cache.data || {};
  4903. var gc = cache.garbageCollect = cache.garbageCollect || [];
  4904. if (cache.font !== font) {
  4905. data = cache.data = {};
  4906. gc = cache.garbageCollect = [];
  4907. cache.font = font;
  4908. }
  4909. ctx.font = font;
  4910. var longest = 0;
  4911. helpers.each(arrayOfThings, function(thing) {
  4912. // Undefined strings and arrays should not be measured
  4913. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  4914. longest = helpers.measureText(ctx, data, gc, longest, thing);
  4915. } else if (helpers.isArray(thing)) {
  4916. // if it is an array lets measure each element
  4917. // to do maybe simplify this function a bit so we can do this more recursively?
  4918. helpers.each(thing, function(nestedThing) {
  4919. // Undefined strings and arrays should not be measured
  4920. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  4921. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  4922. }
  4923. });
  4924. }
  4925. });
  4926. var gcLen = gc.length / 2;
  4927. if (gcLen > arrayOfThings.length) {
  4928. for (var i = 0; i < gcLen; i++) {
  4929. delete data[gc[i]];
  4930. }
  4931. gc.splice(0, gcLen);
  4932. }
  4933. return longest;
  4934. };
  4935. helpers.measureText = function(ctx, data, gc, longest, string) {
  4936. var textWidth = data[string];
  4937. if (!textWidth) {
  4938. textWidth = data[string] = ctx.measureText(string).width;
  4939. gc.push(string);
  4940. }
  4941. if (textWidth > longest) {
  4942. longest = textWidth;
  4943. }
  4944. return longest;
  4945. };
  4946. helpers.numberOfLabelLines = function(arrayOfThings) {
  4947. var numberOfLines = 1;
  4948. helpers.each(arrayOfThings, function(thing) {
  4949. if (helpers.isArray(thing)) {
  4950. if (thing.length > numberOfLines) {
  4951. numberOfLines = thing.length;
  4952. }
  4953. }
  4954. });
  4955. return numberOfLines;
  4956. };
  4957. helpers.color = !color ?
  4958. function(value) {
  4959. console.error('Color.js not found!');
  4960. return value;
  4961. } :
  4962. function(value) {
  4963. /* global CanvasGradient */
  4964. if (value instanceof CanvasGradient) {
  4965. value = defaults.global.defaultColor;
  4966. }
  4967. return color(value);
  4968. };
  4969. helpers.getHoverColor = function(colorValue) {
  4970. /* global CanvasPattern */
  4971. return (colorValue instanceof CanvasPattern) ?
  4972. colorValue :
  4973. helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
  4974. };
  4975. };
  4976. },{"26":26,"3":3,"34":34,"46":46}],29:[function(require,module,exports){
  4977. 'use strict';
  4978. var helpers = require(46);
  4979. /**
  4980. * Helper function to get relative position for an event
  4981. * @param {Event|IEvent} event - The event to get the position for
  4982. * @param {Chart} chart - The chart
  4983. * @returns {Point} the event position
  4984. */
  4985. function getRelativePosition(e, chart) {
  4986. if (e.native) {
  4987. return {
  4988. x: e.x,
  4989. y: e.y
  4990. };
  4991. }
  4992. return helpers.getRelativePosition(e, chart);
  4993. }
  4994. /**
  4995. * Helper function to traverse all of the visible elements in the chart
  4996. * @param chart {chart} the chart
  4997. * @param handler {Function} the callback to execute for each visible item
  4998. */
  4999. function parseVisibleItems(chart, handler) {
  5000. var datasets = chart.data.datasets;
  5001. var meta, i, j, ilen, jlen;
  5002. for (i = 0, ilen = datasets.length; i < ilen; ++i) {
  5003. if (!chart.isDatasetVisible(i)) {
  5004. continue;
  5005. }
  5006. meta = chart.getDatasetMeta(i);
  5007. for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
  5008. var element = meta.data[j];
  5009. if (!element._view.skip) {
  5010. handler(element);
  5011. }
  5012. }
  5013. }
  5014. }
  5015. /**
  5016. * Helper function to get the items that intersect the event position
  5017. * @param items {ChartElement[]} elements to filter
  5018. * @param position {Point} the point to be nearest to
  5019. * @return {ChartElement[]} the nearest items
  5020. */
  5021. function getIntersectItems(chart, position) {
  5022. var elements = [];
  5023. parseVisibleItems(chart, function(element) {
  5024. if (element.inRange(position.x, position.y)) {
  5025. elements.push(element);
  5026. }
  5027. });
  5028. return elements;
  5029. }
  5030. /**
  5031. * Helper function to get the items nearest to the event position considering all visible items in teh chart
  5032. * @param chart {Chart} the chart to look at elements from
  5033. * @param position {Point} the point to be nearest to
  5034. * @param intersect {Boolean} if true, only consider items that intersect the position
  5035. * @param distanceMetric {Function} function to provide the distance between points
  5036. * @return {ChartElement[]} the nearest items
  5037. */
  5038. function getNearestItems(chart, position, intersect, distanceMetric) {
  5039. var minDistance = Number.POSITIVE_INFINITY;
  5040. var nearestItems = [];
  5041. parseVisibleItems(chart, function(element) {
  5042. if (intersect && !element.inRange(position.x, position.y)) {
  5043. return;
  5044. }
  5045. var center = element.getCenterPoint();
  5046. var distance = distanceMetric(position, center);
  5047. if (distance < minDistance) {
  5048. nearestItems = [element];
  5049. minDistance = distance;
  5050. } else if (distance === minDistance) {
  5051. // Can have multiple items at the same distance in which case we sort by size
  5052. nearestItems.push(element);
  5053. }
  5054. });
  5055. return nearestItems;
  5056. }
  5057. /**
  5058. * Get a distance metric function for two points based on the
  5059. * axis mode setting
  5060. * @param {String} axis the axis mode. x|y|xy
  5061. */
  5062. function getDistanceMetricForAxis(axis) {
  5063. var useX = axis.indexOf('x') !== -1;
  5064. var useY = axis.indexOf('y') !== -1;
  5065. return function(pt1, pt2) {
  5066. var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0;
  5067. var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0;
  5068. return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
  5069. };
  5070. }
  5071. function indexMode(chart, e, options) {
  5072. var position = getRelativePosition(e, chart);
  5073. // Default axis for index mode is 'x' to match old behaviour
  5074. options.axis = options.axis || 'x';
  5075. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5076. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5077. var elements = [];
  5078. if (!items.length) {
  5079. return [];
  5080. }
  5081. chart.data.datasets.forEach(function(dataset, datasetIndex) {
  5082. if (chart.isDatasetVisible(datasetIndex)) {
  5083. var meta = chart.getDatasetMeta(datasetIndex);
  5084. var element = meta.data[items[0]._index];
  5085. // don't count items that are skipped (null data)
  5086. if (element && !element._view.skip) {
  5087. elements.push(element);
  5088. }
  5089. }
  5090. });
  5091. return elements;
  5092. }
  5093. /**
  5094. * @interface IInteractionOptions
  5095. */
  5096. /**
  5097. * If true, only consider items that intersect the point
  5098. * @name IInterfaceOptions#boolean
  5099. * @type Boolean
  5100. */
  5101. /**
  5102. * Contains interaction related functions
  5103. * @namespace Chart.Interaction
  5104. */
  5105. module.exports = {
  5106. // Helper function for different modes
  5107. modes: {
  5108. single: function(chart, e) {
  5109. var position = getRelativePosition(e, chart);
  5110. var elements = [];
  5111. parseVisibleItems(chart, function(element) {
  5112. if (element.inRange(position.x, position.y)) {
  5113. elements.push(element);
  5114. return elements;
  5115. }
  5116. });
  5117. return elements.slice(0, 1);
  5118. },
  5119. /**
  5120. * @function Chart.Interaction.modes.label
  5121. * @deprecated since version 2.4.0
  5122. * @todo remove at version 3
  5123. * @private
  5124. */
  5125. label: indexMode,
  5126. /**
  5127. * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
  5128. * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
  5129. * @function Chart.Interaction.modes.index
  5130. * @since v2.4.0
  5131. * @param chart {chart} the chart we are returning items from
  5132. * @param e {Event} the event we are find things at
  5133. * @param options {IInteractionOptions} options to use during interaction
  5134. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5135. */
  5136. index: indexMode,
  5137. /**
  5138. * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
  5139. * If the options.intersect is false, we find the nearest item and return the items in that dataset
  5140. * @function Chart.Interaction.modes.dataset
  5141. * @param chart {chart} the chart we are returning items from
  5142. * @param e {Event} the event we are find things at
  5143. * @param options {IInteractionOptions} options to use during interaction
  5144. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5145. */
  5146. dataset: function(chart, e, options) {
  5147. var position = getRelativePosition(e, chart);
  5148. options.axis = options.axis || 'xy';
  5149. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5150. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5151. if (items.length > 0) {
  5152. items = chart.getDatasetMeta(items[0]._datasetIndex).data;
  5153. }
  5154. return items;
  5155. },
  5156. /**
  5157. * @function Chart.Interaction.modes.x-axis
  5158. * @deprecated since version 2.4.0. Use index mode and intersect == true
  5159. * @todo remove at version 3
  5160. * @private
  5161. */
  5162. 'x-axis': function(chart, e) {
  5163. return indexMode(chart, e, {intersect: false});
  5164. },
  5165. /**
  5166. * Point mode returns all elements that hit test based on the event position
  5167. * of the event
  5168. * @function Chart.Interaction.modes.intersect
  5169. * @param chart {chart} the chart we are returning items from
  5170. * @param e {Event} the event we are find things at
  5171. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5172. */
  5173. point: function(chart, e) {
  5174. var position = getRelativePosition(e, chart);
  5175. return getIntersectItems(chart, position);
  5176. },
  5177. /**
  5178. * nearest mode returns the element closest to the point
  5179. * @function Chart.Interaction.modes.intersect
  5180. * @param chart {chart} the chart we are returning items from
  5181. * @param e {Event} the event we are find things at
  5182. * @param options {IInteractionOptions} options to use
  5183. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5184. */
  5185. nearest: function(chart, e, options) {
  5186. var position = getRelativePosition(e, chart);
  5187. options.axis = options.axis || 'xy';
  5188. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5189. var nearestItems = getNearestItems(chart, position, options.intersect, distanceMetric);
  5190. // We have multiple items at the same distance from the event. Now sort by smallest
  5191. if (nearestItems.length > 1) {
  5192. nearestItems.sort(function(a, b) {
  5193. var sizeA = a.getArea();
  5194. var sizeB = b.getArea();
  5195. var ret = sizeA - sizeB;
  5196. if (ret === 0) {
  5197. // if equal sort by dataset index
  5198. ret = a._datasetIndex - b._datasetIndex;
  5199. }
  5200. return ret;
  5201. });
  5202. }
  5203. // Return only 1 item
  5204. return nearestItems.slice(0, 1);
  5205. },
  5206. /**
  5207. * x mode returns the elements that hit-test at the current x coordinate
  5208. * @function Chart.Interaction.modes.x
  5209. * @param chart {chart} the chart we are returning items from
  5210. * @param e {Event} the event we are find things at
  5211. * @param options {IInteractionOptions} options to use
  5212. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5213. */
  5214. x: function(chart, e, options) {
  5215. var position = getRelativePosition(e, chart);
  5216. var items = [];
  5217. var intersectsItem = false;
  5218. parseVisibleItems(chart, function(element) {
  5219. if (element.inXRange(position.x)) {
  5220. items.push(element);
  5221. }
  5222. if (element.inRange(position.x, position.y)) {
  5223. intersectsItem = true;
  5224. }
  5225. });
  5226. // If we want to trigger on an intersect and we don't have any items
  5227. // that intersect the position, return nothing
  5228. if (options.intersect && !intersectsItem) {
  5229. items = [];
  5230. }
  5231. return items;
  5232. },
  5233. /**
  5234. * y mode returns the elements that hit-test at the current y coordinate
  5235. * @function Chart.Interaction.modes.y
  5236. * @param chart {chart} the chart we are returning items from
  5237. * @param e {Event} the event we are find things at
  5238. * @param options {IInteractionOptions} options to use
  5239. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5240. */
  5241. y: function(chart, e, options) {
  5242. var position = getRelativePosition(e, chart);
  5243. var items = [];
  5244. var intersectsItem = false;
  5245. parseVisibleItems(chart, function(element) {
  5246. if (element.inYRange(position.y)) {
  5247. items.push(element);
  5248. }
  5249. if (element.inRange(position.x, position.y)) {
  5250. intersectsItem = true;
  5251. }
  5252. });
  5253. // If we want to trigger on an intersect and we don't have any items
  5254. // that intersect the position, return nothing
  5255. if (options.intersect && !intersectsItem) {
  5256. items = [];
  5257. }
  5258. return items;
  5259. }
  5260. }
  5261. };
  5262. },{"46":46}],30:[function(require,module,exports){
  5263. 'use strict';
  5264. var defaults = require(26);
  5265. defaults._set('global', {
  5266. responsive: true,
  5267. responsiveAnimationDuration: 0,
  5268. maintainAspectRatio: true,
  5269. events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
  5270. hover: {
  5271. onHover: null,
  5272. mode: 'nearest',
  5273. intersect: true,
  5274. animationDuration: 400
  5275. },
  5276. onClick: null,
  5277. defaultColor: 'rgba(0,0,0,0.1)',
  5278. defaultFontColor: '#666',
  5279. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  5280. defaultFontSize: 12,
  5281. defaultFontStyle: 'normal',
  5282. showLines: true,
  5283. // Element defaults defined in element extensions
  5284. elements: {},
  5285. // Layout options such as padding
  5286. layout: {
  5287. padding: {
  5288. top: 0,
  5289. right: 0,
  5290. bottom: 0,
  5291. left: 0
  5292. }
  5293. }
  5294. });
  5295. module.exports = function() {
  5296. // Occupy the global variable of Chart, and create a simple base class
  5297. var Chart = function(item, config) {
  5298. this.construct(item, config);
  5299. return this;
  5300. };
  5301. Chart.Chart = Chart;
  5302. return Chart;
  5303. };
  5304. },{"26":26}],31:[function(require,module,exports){
  5305. 'use strict';
  5306. var helpers = require(46);
  5307. function filterByPosition(array, position) {
  5308. return helpers.where(array, function(v) {
  5309. return v.position === position;
  5310. });
  5311. }
  5312. function sortByWeight(array, reverse) {
  5313. array.forEach(function(v, i) {
  5314. v._tmpIndex_ = i;
  5315. return v;
  5316. });
  5317. array.sort(function(a, b) {
  5318. var v0 = reverse ? b : a;
  5319. var v1 = reverse ? a : b;
  5320. return v0.weight === v1.weight ?
  5321. v0._tmpIndex_ - v1._tmpIndex_ :
  5322. v0.weight - v1.weight;
  5323. });
  5324. array.forEach(function(v) {
  5325. delete v._tmpIndex_;
  5326. });
  5327. }
  5328. /**
  5329. * @interface ILayoutItem
  5330. * @prop {String} position - The position of the item in the chart layout. Possible values are
  5331. * 'left', 'top', 'right', 'bottom', and 'chartArea'
  5332. * @prop {Number} weight - The weight used to sort the item. Higher weights are further away from the chart area
  5333. * @prop {Boolean} fullWidth - if true, and the item is horizontal, then push vertical boxes down
  5334. * @prop {Function} isHorizontal - returns true if the layout item is horizontal (ie. top or bottom)
  5335. * @prop {Function} update - Takes two parameters: width and height. Returns size of item
  5336. * @prop {Function} getPadding - Returns an object with padding on the edges
  5337. * @prop {Number} width - Width of item. Must be valid after update()
  5338. * @prop {Number} height - Height of item. Must be valid after update()
  5339. * @prop {Number} left - Left edge of the item. Set by layout system and cannot be used in update
  5340. * @prop {Number} top - Top edge of the item. Set by layout system and cannot be used in update
  5341. * @prop {Number} right - Right edge of the item. Set by layout system and cannot be used in update
  5342. * @prop {Number} bottom - Bottom edge of the item. Set by layout system and cannot be used in update
  5343. */
  5344. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  5345. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  5346. // It is this service's responsibility of carrying out that layout.
  5347. module.exports = {
  5348. defaults: {},
  5349. /**
  5350. * Register a box to a chart.
  5351. * A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
  5352. * @param {Chart} chart - the chart to use
  5353. * @param {ILayoutItem} item - the item to add to be layed out
  5354. */
  5355. addBox: function(chart, item) {
  5356. if (!chart.boxes) {
  5357. chart.boxes = [];
  5358. }
  5359. // initialize item with default values
  5360. item.fullWidth = item.fullWidth || false;
  5361. item.position = item.position || 'top';
  5362. item.weight = item.weight || 0;
  5363. chart.boxes.push(item);
  5364. },
  5365. /**
  5366. * Remove a layoutItem from a chart
  5367. * @param {Chart} chart - the chart to remove the box from
  5368. * @param {Object} layoutItem - the item to remove from the layout
  5369. */
  5370. removeBox: function(chart, layoutItem) {
  5371. var index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
  5372. if (index !== -1) {
  5373. chart.boxes.splice(index, 1);
  5374. }
  5375. },
  5376. /**
  5377. * Sets (or updates) options on the given `item`.
  5378. * @param {Chart} chart - the chart in which the item lives (or will be added to)
  5379. * @param {Object} item - the item to configure with the given options
  5380. * @param {Object} options - the new item options.
  5381. */
  5382. configure: function(chart, item, options) {
  5383. var props = ['fullWidth', 'position', 'weight'];
  5384. var ilen = props.length;
  5385. var i = 0;
  5386. var prop;
  5387. for (; i < ilen; ++i) {
  5388. prop = props[i];
  5389. if (options.hasOwnProperty(prop)) {
  5390. item[prop] = options[prop];
  5391. }
  5392. }
  5393. },
  5394. /**
  5395. * Fits boxes of the given chart into the given size by having each box measure itself
  5396. * then running a fitting algorithm
  5397. * @param {Chart} chart - the chart
  5398. * @param {Number} width - the width to fit into
  5399. * @param {Number} height - the height to fit into
  5400. */
  5401. update: function(chart, width, height) {
  5402. if (!chart) {
  5403. return;
  5404. }
  5405. var layoutOptions = chart.options.layout || {};
  5406. var padding = helpers.options.toPadding(layoutOptions.padding);
  5407. var leftPadding = padding.left;
  5408. var rightPadding = padding.right;
  5409. var topPadding = padding.top;
  5410. var bottomPadding = padding.bottom;
  5411. var leftBoxes = filterByPosition(chart.boxes, 'left');
  5412. var rightBoxes = filterByPosition(chart.boxes, 'right');
  5413. var topBoxes = filterByPosition(chart.boxes, 'top');
  5414. var bottomBoxes = filterByPosition(chart.boxes, 'bottom');
  5415. var chartAreaBoxes = filterByPosition(chart.boxes, 'chartArea');
  5416. // Sort boxes by weight. A higher weight is further away from the chart area
  5417. sortByWeight(leftBoxes, true);
  5418. sortByWeight(rightBoxes, false);
  5419. sortByWeight(topBoxes, true);
  5420. sortByWeight(bottomBoxes, false);
  5421. // Essentially we now have any number of boxes on each of the 4 sides.
  5422. // Our canvas looks like the following.
  5423. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  5424. // B1 is the bottom axis
  5425. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  5426. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  5427. // an error will be thrown.
  5428. //
  5429. // |----------------------------------------------------|
  5430. // | T1 (Full Width) |
  5431. // |----------------------------------------------------|
  5432. // | | | T2 | |
  5433. // | |----|-------------------------------------|----|
  5434. // | | | C1 | | C2 | |
  5435. // | | |----| |----| |
  5436. // | | | | |
  5437. // | L1 | L2 | ChartArea (C0) | R1 |
  5438. // | | | | |
  5439. // | | |----| |----| |
  5440. // | | | C3 | | C4 | |
  5441. // | |----|-------------------------------------|----|
  5442. // | | | B1 | |
  5443. // |----------------------------------------------------|
  5444. // | B2 (Full Width) |
  5445. // |----------------------------------------------------|
  5446. //
  5447. // What we do to find the best sizing, we do the following
  5448. // 1. Determine the minimum size of the chart area.
  5449. // 2. Split the remaining width equally between each vertical axis
  5450. // 3. Split the remaining height equally between each horizontal axis
  5451. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  5452. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  5453. // 6. Refit each axis
  5454. // 7. Position each axis in the final location
  5455. // 8. Tell the chart the final location of the chart area
  5456. // 9. Tell any axes that overlay the chart area the positions of the chart area
  5457. // Step 1
  5458. var chartWidth = width - leftPadding - rightPadding;
  5459. var chartHeight = height - topPadding - bottomPadding;
  5460. var chartAreaWidth = chartWidth / 2; // min 50%
  5461. var chartAreaHeight = chartHeight / 2; // min 50%
  5462. // Step 2
  5463. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  5464. // Step 3
  5465. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  5466. // Step 4
  5467. var maxChartAreaWidth = chartWidth;
  5468. var maxChartAreaHeight = chartHeight;
  5469. var minBoxSizes = [];
  5470. function getMinimumBoxSize(box) {
  5471. var minSize;
  5472. var isHorizontal = box.isHorizontal();
  5473. if (isHorizontal) {
  5474. minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5475. maxChartAreaHeight -= minSize.height;
  5476. } else {
  5477. minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
  5478. maxChartAreaWidth -= minSize.width;
  5479. }
  5480. minBoxSizes.push({
  5481. horizontal: isHorizontal,
  5482. minSize: minSize,
  5483. box: box,
  5484. });
  5485. }
  5486. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  5487. // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
  5488. var maxHorizontalLeftPadding = 0;
  5489. var maxHorizontalRightPadding = 0;
  5490. var maxVerticalTopPadding = 0;
  5491. var maxVerticalBottomPadding = 0;
  5492. helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
  5493. if (horizontalBox.getPadding) {
  5494. var boxPadding = horizontalBox.getPadding();
  5495. maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
  5496. maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
  5497. }
  5498. });
  5499. helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
  5500. if (verticalBox.getPadding) {
  5501. var boxPadding = verticalBox.getPadding();
  5502. maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
  5503. maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
  5504. }
  5505. });
  5506. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  5507. // be if the axes are drawn at their minimum sizes.
  5508. // Steps 5 & 6
  5509. var totalLeftBoxesWidth = leftPadding;
  5510. var totalRightBoxesWidth = rightPadding;
  5511. var totalTopBoxesHeight = topPadding;
  5512. var totalBottomBoxesHeight = bottomPadding;
  5513. // Function to fit a box
  5514. function fitBox(box) {
  5515. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
  5516. return minBox.box === box;
  5517. });
  5518. if (minBoxSize) {
  5519. if (box.isHorizontal()) {
  5520. var scaleMargin = {
  5521. left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
  5522. right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
  5523. top: 0,
  5524. bottom: 0
  5525. };
  5526. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5527. // on the margin. Sometimes they need to increase in size slightly
  5528. box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5529. } else {
  5530. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5531. }
  5532. }
  5533. }
  5534. // Update, and calculate the left and right margins for the horizontal boxes
  5535. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5536. helpers.each(leftBoxes, function(box) {
  5537. totalLeftBoxesWidth += box.width;
  5538. });
  5539. helpers.each(rightBoxes, function(box) {
  5540. totalRightBoxesWidth += box.width;
  5541. });
  5542. // Set the Left and Right margins for the horizontal boxes
  5543. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  5544. // Figure out how much margin is on the top and bottom of the vertical boxes
  5545. helpers.each(topBoxes, function(box) {
  5546. totalTopBoxesHeight += box.height;
  5547. });
  5548. helpers.each(bottomBoxes, function(box) {
  5549. totalBottomBoxesHeight += box.height;
  5550. });
  5551. function finalFitVerticalBox(box) {
  5552. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
  5553. return minSize.box === box;
  5554. });
  5555. var scaleMargin = {
  5556. left: 0,
  5557. right: 0,
  5558. top: totalTopBoxesHeight,
  5559. bottom: totalBottomBoxesHeight
  5560. };
  5561. if (minBoxSize) {
  5562. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5563. }
  5564. }
  5565. // Let the left layout know the final margin
  5566. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  5567. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  5568. totalLeftBoxesWidth = leftPadding;
  5569. totalRightBoxesWidth = rightPadding;
  5570. totalTopBoxesHeight = topPadding;
  5571. totalBottomBoxesHeight = bottomPadding;
  5572. helpers.each(leftBoxes, function(box) {
  5573. totalLeftBoxesWidth += box.width;
  5574. });
  5575. helpers.each(rightBoxes, function(box) {
  5576. totalRightBoxesWidth += box.width;
  5577. });
  5578. helpers.each(topBoxes, function(box) {
  5579. totalTopBoxesHeight += box.height;
  5580. });
  5581. helpers.each(bottomBoxes, function(box) {
  5582. totalBottomBoxesHeight += box.height;
  5583. });
  5584. // We may be adding some padding to account for rotated x axis labels
  5585. var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
  5586. totalLeftBoxesWidth += leftPaddingAddition;
  5587. totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
  5588. var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
  5589. totalTopBoxesHeight += topPaddingAddition;
  5590. totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
  5591. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  5592. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  5593. // without calling `fit` again
  5594. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  5595. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  5596. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  5597. helpers.each(leftBoxes, function(box) {
  5598. box.height = newMaxChartAreaHeight;
  5599. });
  5600. helpers.each(rightBoxes, function(box) {
  5601. box.height = newMaxChartAreaHeight;
  5602. });
  5603. helpers.each(topBoxes, function(box) {
  5604. if (!box.fullWidth) {
  5605. box.width = newMaxChartAreaWidth;
  5606. }
  5607. });
  5608. helpers.each(bottomBoxes, function(box) {
  5609. if (!box.fullWidth) {
  5610. box.width = newMaxChartAreaWidth;
  5611. }
  5612. });
  5613. maxChartAreaHeight = newMaxChartAreaHeight;
  5614. maxChartAreaWidth = newMaxChartAreaWidth;
  5615. }
  5616. // Step 7 - Position the boxes
  5617. var left = leftPadding + leftPaddingAddition;
  5618. var top = topPadding + topPaddingAddition;
  5619. function placeBox(box) {
  5620. if (box.isHorizontal()) {
  5621. box.left = box.fullWidth ? leftPadding : totalLeftBoxesWidth;
  5622. box.right = box.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5623. box.top = top;
  5624. box.bottom = top + box.height;
  5625. // Move to next point
  5626. top = box.bottom;
  5627. } else {
  5628. box.left = left;
  5629. box.right = left + box.width;
  5630. box.top = totalTopBoxesHeight;
  5631. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5632. // Move to next point
  5633. left = box.right;
  5634. }
  5635. }
  5636. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5637. // Account for chart width and height
  5638. left += maxChartAreaWidth;
  5639. top += maxChartAreaHeight;
  5640. helpers.each(rightBoxes, placeBox);
  5641. helpers.each(bottomBoxes, placeBox);
  5642. // Step 8
  5643. chart.chartArea = {
  5644. left: totalLeftBoxesWidth,
  5645. top: totalTopBoxesHeight,
  5646. right: totalLeftBoxesWidth + maxChartAreaWidth,
  5647. bottom: totalTopBoxesHeight + maxChartAreaHeight
  5648. };
  5649. // Step 9
  5650. helpers.each(chartAreaBoxes, function(box) {
  5651. box.left = chart.chartArea.left;
  5652. box.top = chart.chartArea.top;
  5653. box.right = chart.chartArea.right;
  5654. box.bottom = chart.chartArea.bottom;
  5655. box.update(maxChartAreaWidth, maxChartAreaHeight);
  5656. });
  5657. }
  5658. };
  5659. },{"46":46}],32:[function(require,module,exports){
  5660. 'use strict';
  5661. var defaults = require(26);
  5662. var helpers = require(46);
  5663. defaults._set('global', {
  5664. plugins: {}
  5665. });
  5666. /**
  5667. * The plugin service singleton
  5668. * @namespace Chart.plugins
  5669. * @since 2.1.0
  5670. */
  5671. module.exports = {
  5672. /**
  5673. * Globally registered plugins.
  5674. * @private
  5675. */
  5676. _plugins: [],
  5677. /**
  5678. * This identifier is used to invalidate the descriptors cache attached to each chart
  5679. * when a global plugin is registered or unregistered. In this case, the cache ID is
  5680. * incremented and descriptors are regenerated during following API calls.
  5681. * @private
  5682. */
  5683. _cacheId: 0,
  5684. /**
  5685. * Registers the given plugin(s) if not already registered.
  5686. * @param {Array|Object} plugins plugin instance(s).
  5687. */
  5688. register: function(plugins) {
  5689. var p = this._plugins;
  5690. ([]).concat(plugins).forEach(function(plugin) {
  5691. if (p.indexOf(plugin) === -1) {
  5692. p.push(plugin);
  5693. }
  5694. });
  5695. this._cacheId++;
  5696. },
  5697. /**
  5698. * Unregisters the given plugin(s) only if registered.
  5699. * @param {Array|Object} plugins plugin instance(s).
  5700. */
  5701. unregister: function(plugins) {
  5702. var p = this._plugins;
  5703. ([]).concat(plugins).forEach(function(plugin) {
  5704. var idx = p.indexOf(plugin);
  5705. if (idx !== -1) {
  5706. p.splice(idx, 1);
  5707. }
  5708. });
  5709. this._cacheId++;
  5710. },
  5711. /**
  5712. * Remove all registered plugins.
  5713. * @since 2.1.5
  5714. */
  5715. clear: function() {
  5716. this._plugins = [];
  5717. this._cacheId++;
  5718. },
  5719. /**
  5720. * Returns the number of registered plugins?
  5721. * @returns {Number}
  5722. * @since 2.1.5
  5723. */
  5724. count: function() {
  5725. return this._plugins.length;
  5726. },
  5727. /**
  5728. * Returns all registered plugin instances.
  5729. * @returns {Array} array of plugin objects.
  5730. * @since 2.1.5
  5731. */
  5732. getAll: function() {
  5733. return this._plugins;
  5734. },
  5735. /**
  5736. * Calls enabled plugins for `chart` on the specified hook and with the given args.
  5737. * This method immediately returns as soon as a plugin explicitly returns false. The
  5738. * returned value can be used, for instance, to interrupt the current action.
  5739. * @param {Object} chart - The chart instance for which plugins should be called.
  5740. * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
  5741. * @param {Array} [args] - Extra arguments to apply to the hook call.
  5742. * @returns {Boolean} false if any of the plugins return false, else returns true.
  5743. */
  5744. notify: function(chart, hook, args) {
  5745. var descriptors = this.descriptors(chart);
  5746. var ilen = descriptors.length;
  5747. var i, descriptor, plugin, params, method;
  5748. for (i = 0; i < ilen; ++i) {
  5749. descriptor = descriptors[i];
  5750. plugin = descriptor.plugin;
  5751. method = plugin[hook];
  5752. if (typeof method === 'function') {
  5753. params = [chart].concat(args || []);
  5754. params.push(descriptor.options);
  5755. if (method.apply(plugin, params) === false) {
  5756. return false;
  5757. }
  5758. }
  5759. }
  5760. return true;
  5761. },
  5762. /**
  5763. * Returns descriptors of enabled plugins for the given chart.
  5764. * @returns {Array} [{ plugin, options }]
  5765. * @private
  5766. */
  5767. descriptors: function(chart) {
  5768. var cache = chart.$plugins || (chart.$plugins = {});
  5769. if (cache.id === this._cacheId) {
  5770. return cache.descriptors;
  5771. }
  5772. var plugins = [];
  5773. var descriptors = [];
  5774. var config = (chart && chart.config) || {};
  5775. var options = (config.options && config.options.plugins) || {};
  5776. this._plugins.concat(config.plugins || []).forEach(function(plugin) {
  5777. var idx = plugins.indexOf(plugin);
  5778. if (idx !== -1) {
  5779. return;
  5780. }
  5781. var id = plugin.id;
  5782. var opts = options[id];
  5783. if (opts === false) {
  5784. return;
  5785. }
  5786. if (opts === true) {
  5787. opts = helpers.clone(defaults.global.plugins[id]);
  5788. }
  5789. plugins.push(plugin);
  5790. descriptors.push({
  5791. plugin: plugin,
  5792. options: opts || {}
  5793. });
  5794. });
  5795. cache.descriptors = descriptors;
  5796. cache.id = this._cacheId;
  5797. return descriptors;
  5798. },
  5799. /**
  5800. * Invalidates cache for the given chart: descriptors hold a reference on plugin option,
  5801. * but in some cases, this reference can be changed by the user when updating options.
  5802. * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  5803. * @private
  5804. */
  5805. _invalidate: function(chart) {
  5806. delete chart.$plugins;
  5807. }
  5808. };
  5809. /**
  5810. * Plugin extension hooks.
  5811. * @interface IPlugin
  5812. * @since 2.1.0
  5813. */
  5814. /**
  5815. * @method IPlugin#beforeInit
  5816. * @desc Called before initializing `chart`.
  5817. * @param {Chart.Controller} chart - The chart instance.
  5818. * @param {Object} options - The plugin options.
  5819. */
  5820. /**
  5821. * @method IPlugin#afterInit
  5822. * @desc Called after `chart` has been initialized and before the first update.
  5823. * @param {Chart.Controller} chart - The chart instance.
  5824. * @param {Object} options - The plugin options.
  5825. */
  5826. /**
  5827. * @method IPlugin#beforeUpdate
  5828. * @desc Called before updating `chart`. If any plugin returns `false`, the update
  5829. * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
  5830. * @param {Chart.Controller} chart - The chart instance.
  5831. * @param {Object} options - The plugin options.
  5832. * @returns {Boolean} `false` to cancel the chart update.
  5833. */
  5834. /**
  5835. * @method IPlugin#afterUpdate
  5836. * @desc Called after `chart` has been updated and before rendering. Note that this
  5837. * hook will not be called if the chart update has been previously cancelled.
  5838. * @param {Chart.Controller} chart - The chart instance.
  5839. * @param {Object} options - The plugin options.
  5840. */
  5841. /**
  5842. * @method IPlugin#beforeDatasetsUpdate
  5843. * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  5844. * the datasets update is cancelled until another `update` is triggered.
  5845. * @param {Chart.Controller} chart - The chart instance.
  5846. * @param {Object} options - The plugin options.
  5847. * @returns {Boolean} false to cancel the datasets update.
  5848. * @since version 2.1.5
  5849. */
  5850. /**
  5851. * @method IPlugin#afterDatasetsUpdate
  5852. * @desc Called after the `chart` datasets have been updated. Note that this hook
  5853. * will not be called if the datasets update has been previously cancelled.
  5854. * @param {Chart.Controller} chart - The chart instance.
  5855. * @param {Object} options - The plugin options.
  5856. * @since version 2.1.5
  5857. */
  5858. /**
  5859. * @method IPlugin#beforeDatasetUpdate
  5860. * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
  5861. * returns `false`, the datasets update is cancelled until another `update` is triggered.
  5862. * @param {Chart} chart - The chart instance.
  5863. * @param {Object} args - The call arguments.
  5864. * @param {Number} args.index - The dataset index.
  5865. * @param {Object} args.meta - The dataset metadata.
  5866. * @param {Object} options - The plugin options.
  5867. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5868. */
  5869. /**
  5870. * @method IPlugin#afterDatasetUpdate
  5871. * @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
  5872. * that this hook will not be called if the datasets update has been previously cancelled.
  5873. * @param {Chart} chart - The chart instance.
  5874. * @param {Object} args - The call arguments.
  5875. * @param {Number} args.index - The dataset index.
  5876. * @param {Object} args.meta - The dataset metadata.
  5877. * @param {Object} options - The plugin options.
  5878. */
  5879. /**
  5880. * @method IPlugin#beforeLayout
  5881. * @desc Called before laying out `chart`. If any plugin returns `false`,
  5882. * the layout update is cancelled until another `update` is triggered.
  5883. * @param {Chart.Controller} chart - The chart instance.
  5884. * @param {Object} options - The plugin options.
  5885. * @returns {Boolean} `false` to cancel the chart layout.
  5886. */
  5887. /**
  5888. * @method IPlugin#afterLayout
  5889. * @desc Called after the `chart` has been layed out. Note that this hook will not
  5890. * be called if the layout update has been previously cancelled.
  5891. * @param {Chart.Controller} chart - The chart instance.
  5892. * @param {Object} options - The plugin options.
  5893. */
  5894. /**
  5895. * @method IPlugin#beforeRender
  5896. * @desc Called before rendering `chart`. If any plugin returns `false`,
  5897. * the rendering is cancelled until another `render` is triggered.
  5898. * @param {Chart.Controller} chart - The chart instance.
  5899. * @param {Object} options - The plugin options.
  5900. * @returns {Boolean} `false` to cancel the chart rendering.
  5901. */
  5902. /**
  5903. * @method IPlugin#afterRender
  5904. * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  5905. * that this hook will not be called if the rendering has been previously cancelled.
  5906. * @param {Chart.Controller} chart - The chart instance.
  5907. * @param {Object} options - The plugin options.
  5908. */
  5909. /**
  5910. * @method IPlugin#beforeDraw
  5911. * @desc Called before drawing `chart` at every animation frame specified by the given
  5912. * easing value. If any plugin returns `false`, the frame drawing is cancelled until
  5913. * another `render` is triggered.
  5914. * @param {Chart.Controller} chart - The chart instance.
  5915. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5916. * @param {Object} options - The plugin options.
  5917. * @returns {Boolean} `false` to cancel the chart drawing.
  5918. */
  5919. /**
  5920. * @method IPlugin#afterDraw
  5921. * @desc Called after the `chart` has been drawn for the specific easing value. Note
  5922. * that this hook will not be called if the drawing has been previously cancelled.
  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. */
  5927. /**
  5928. * @method IPlugin#beforeDatasetsDraw
  5929. * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  5930. * the datasets drawing is cancelled until another `render` is triggered.
  5931. * @param {Chart.Controller} chart - The chart instance.
  5932. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5933. * @param {Object} options - The plugin options.
  5934. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5935. */
  5936. /**
  5937. * @method IPlugin#afterDatasetsDraw
  5938. * @desc Called after the `chart` datasets have been drawn. Note that this hook
  5939. * will not be called if the datasets drawing has been previously cancelled.
  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. */
  5944. /**
  5945. * @method IPlugin#beforeDatasetDraw
  5946. * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
  5947. * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
  5948. * is cancelled until another `render` is triggered.
  5949. * @param {Chart} chart - The chart instance.
  5950. * @param {Object} args - The call arguments.
  5951. * @param {Number} args.index - The dataset index.
  5952. * @param {Object} args.meta - The dataset metadata.
  5953. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5954. * @param {Object} options - The plugin options.
  5955. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5956. */
  5957. /**
  5958. * @method IPlugin#afterDatasetDraw
  5959. * @desc Called after the `chart` datasets at the given `args.index` have been drawn
  5960. * (datasets are drawn in the reverse order). Note that this hook will not be called
  5961. * if the datasets drawing has been previously cancelled.
  5962. * @param {Chart} chart - The chart instance.
  5963. * @param {Object} args - The call arguments.
  5964. * @param {Number} args.index - The dataset index.
  5965. * @param {Object} args.meta - The dataset metadata.
  5966. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5967. * @param {Object} options - The plugin options.
  5968. */
  5969. /**
  5970. * @method IPlugin#beforeTooltipDraw
  5971. * @desc Called before drawing the `tooltip`. If any plugin returns `false`,
  5972. * the tooltip drawing is cancelled until another `render` is triggered.
  5973. * @param {Chart} chart - The chart instance.
  5974. * @param {Object} args - The call arguments.
  5975. * @param {Object} args.tooltip - The tooltip.
  5976. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5977. * @param {Object} options - The plugin options.
  5978. * @returns {Boolean} `false` to cancel the chart tooltip drawing.
  5979. */
  5980. /**
  5981. * @method IPlugin#afterTooltipDraw
  5982. * @desc Called after drawing the `tooltip`. Note that this hook will not
  5983. * be called if the tooltip drawing has been previously cancelled.
  5984. * @param {Chart} chart - The chart instance.
  5985. * @param {Object} args - The call arguments.
  5986. * @param {Object} args.tooltip - The tooltip.
  5987. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5988. * @param {Object} options - The plugin options.
  5989. */
  5990. /**
  5991. * @method IPlugin#beforeEvent
  5992. * @desc Called before processing the specified `event`. If any plugin returns `false`,
  5993. * the event will be discarded.
  5994. * @param {Chart.Controller} chart - The chart instance.
  5995. * @param {IEvent} event - The event object.
  5996. * @param {Object} options - The plugin options.
  5997. */
  5998. /**
  5999. * @method IPlugin#afterEvent
  6000. * @desc Called after the `event` has been consumed. Note that this hook
  6001. * will not be called if the `event` has been previously discarded.
  6002. * @param {Chart.Controller} chart - The chart instance.
  6003. * @param {IEvent} event - The event object.
  6004. * @param {Object} options - The plugin options.
  6005. */
  6006. /**
  6007. * @method IPlugin#resize
  6008. * @desc Called after the chart as been resized.
  6009. * @param {Chart.Controller} chart - The chart instance.
  6010. * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
  6011. * @param {Object} options - The plugin options.
  6012. */
  6013. /**
  6014. * @method IPlugin#destroy
  6015. * @desc Called after the chart as been destroyed.
  6016. * @param {Chart.Controller} chart - The chart instance.
  6017. * @param {Object} options - The plugin options.
  6018. */
  6019. },{"26":26,"46":46}],33:[function(require,module,exports){
  6020. 'use strict';
  6021. var defaults = require(26);
  6022. var Element = require(27);
  6023. var helpers = require(46);
  6024. var Ticks = require(35);
  6025. defaults._set('scale', {
  6026. display: true,
  6027. position: 'left',
  6028. offset: false,
  6029. // grid line settings
  6030. gridLines: {
  6031. display: true,
  6032. color: 'rgba(0, 0, 0, 0.1)',
  6033. lineWidth: 1,
  6034. drawBorder: true,
  6035. drawOnChartArea: true,
  6036. drawTicks: true,
  6037. tickMarkLength: 10,
  6038. zeroLineWidth: 1,
  6039. zeroLineColor: 'rgba(0,0,0,0.25)',
  6040. zeroLineBorderDash: [],
  6041. zeroLineBorderDashOffset: 0.0,
  6042. offsetGridLines: false,
  6043. borderDash: [],
  6044. borderDashOffset: 0.0
  6045. },
  6046. // scale label
  6047. scaleLabel: {
  6048. // display property
  6049. display: false,
  6050. // actual label
  6051. labelString: '',
  6052. // line height
  6053. lineHeight: 1.2,
  6054. // top/bottom padding
  6055. padding: {
  6056. top: 4,
  6057. bottom: 4
  6058. }
  6059. },
  6060. // label settings
  6061. ticks: {
  6062. beginAtZero: false,
  6063. minRotation: 0,
  6064. maxRotation: 50,
  6065. mirror: false,
  6066. padding: 0,
  6067. reverse: false,
  6068. display: true,
  6069. autoSkip: true,
  6070. autoSkipPadding: 0,
  6071. labelOffset: 0,
  6072. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  6073. callback: Ticks.formatters.values,
  6074. minor: {},
  6075. major: {}
  6076. }
  6077. });
  6078. function labelsFromTicks(ticks) {
  6079. var labels = [];
  6080. var i, ilen;
  6081. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  6082. labels.push(ticks[i].label);
  6083. }
  6084. return labels;
  6085. }
  6086. function getLineValue(scale, index, offsetGridLines) {
  6087. var lineValue = scale.getPixelForTick(index);
  6088. if (offsetGridLines) {
  6089. if (index === 0) {
  6090. lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
  6091. } else {
  6092. lineValue -= (lineValue - scale.getPixelForTick(index - 1)) / 2;
  6093. }
  6094. }
  6095. return lineValue;
  6096. }
  6097. function computeTextSize(context, tick, font) {
  6098. return helpers.isArray(tick) ?
  6099. helpers.longestText(context, font, tick) :
  6100. context.measureText(tick).width;
  6101. }
  6102. function parseFontOptions(options) {
  6103. var valueOrDefault = helpers.valueOrDefault;
  6104. var globalDefaults = defaults.global;
  6105. var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
  6106. var style = valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
  6107. var family = valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
  6108. return {
  6109. size: size,
  6110. style: style,
  6111. family: family,
  6112. font: helpers.fontString(size, style, family)
  6113. };
  6114. }
  6115. function parseLineHeight(options) {
  6116. return helpers.options.toLineHeight(
  6117. helpers.valueOrDefault(options.lineHeight, 1.2),
  6118. helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
  6119. }
  6120. module.exports = Element.extend({
  6121. /**
  6122. * Get the padding needed for the scale
  6123. * @method getPadding
  6124. * @private
  6125. * @returns {Padding} the necessary padding
  6126. */
  6127. getPadding: function() {
  6128. var me = this;
  6129. return {
  6130. left: me.paddingLeft || 0,
  6131. top: me.paddingTop || 0,
  6132. right: me.paddingRight || 0,
  6133. bottom: me.paddingBottom || 0
  6134. };
  6135. },
  6136. /**
  6137. * Returns the scale tick objects ({label, major})
  6138. * @since 2.7
  6139. */
  6140. getTicks: function() {
  6141. return this._ticks;
  6142. },
  6143. // These methods are ordered by lifecyle. Utilities then follow.
  6144. // Any function defined here is inherited by all scale types.
  6145. // Any function can be extended by the scale type
  6146. mergeTicksOptions: function() {
  6147. var ticks = this.options.ticks;
  6148. if (ticks.minor === false) {
  6149. ticks.minor = {
  6150. display: false
  6151. };
  6152. }
  6153. if (ticks.major === false) {
  6154. ticks.major = {
  6155. display: false
  6156. };
  6157. }
  6158. for (var key in ticks) {
  6159. if (key !== 'major' && key !== 'minor') {
  6160. if (typeof ticks.minor[key] === 'undefined') {
  6161. ticks.minor[key] = ticks[key];
  6162. }
  6163. if (typeof ticks.major[key] === 'undefined') {
  6164. ticks.major[key] = ticks[key];
  6165. }
  6166. }
  6167. }
  6168. },
  6169. beforeUpdate: function() {
  6170. helpers.callback(this.options.beforeUpdate, [this]);
  6171. },
  6172. update: function(maxWidth, maxHeight, margins) {
  6173. var me = this;
  6174. var i, ilen, labels, label, ticks, tick;
  6175. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6176. me.beforeUpdate();
  6177. // Absorb the master measurements
  6178. me.maxWidth = maxWidth;
  6179. me.maxHeight = maxHeight;
  6180. me.margins = helpers.extend({
  6181. left: 0,
  6182. right: 0,
  6183. top: 0,
  6184. bottom: 0
  6185. }, margins);
  6186. me.longestTextCache = me.longestTextCache || {};
  6187. // Dimensions
  6188. me.beforeSetDimensions();
  6189. me.setDimensions();
  6190. me.afterSetDimensions();
  6191. // Data min/max
  6192. me.beforeDataLimits();
  6193. me.determineDataLimits();
  6194. me.afterDataLimits();
  6195. // Ticks - `this.ticks` is now DEPRECATED!
  6196. // Internal ticks are now stored as objects in the PRIVATE `this._ticks` member
  6197. // and must not be accessed directly from outside this class. `this.ticks` being
  6198. // around for long time and not marked as private, we can't change its structure
  6199. // without unexpected breaking changes. If you need to access the scale ticks,
  6200. // use scale.getTicks() instead.
  6201. me.beforeBuildTicks();
  6202. // New implementations should return an array of objects but for BACKWARD COMPAT,
  6203. // we still support no return (`this.ticks` internally set by calling this method).
  6204. ticks = me.buildTicks() || [];
  6205. me.afterBuildTicks();
  6206. me.beforeTickToLabelConversion();
  6207. // New implementations should return the formatted tick labels but for BACKWARD
  6208. // COMPAT, we still support no return (`this.ticks` internally changed by calling
  6209. // this method and supposed to contain only string values).
  6210. labels = me.convertTicksToLabels(ticks) || me.ticks;
  6211. me.afterTickToLabelConversion();
  6212. me.ticks = labels; // BACKWARD COMPATIBILITY
  6213. // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
  6214. // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
  6215. for (i = 0, ilen = labels.length; i < ilen; ++i) {
  6216. label = labels[i];
  6217. tick = ticks[i];
  6218. if (!tick) {
  6219. ticks.push(tick = {
  6220. label: label,
  6221. major: false
  6222. });
  6223. } else {
  6224. tick.label = label;
  6225. }
  6226. }
  6227. me._ticks = ticks;
  6228. // Tick Rotation
  6229. me.beforeCalculateTickRotation();
  6230. me.calculateTickRotation();
  6231. me.afterCalculateTickRotation();
  6232. // Fit
  6233. me.beforeFit();
  6234. me.fit();
  6235. me.afterFit();
  6236. //
  6237. me.afterUpdate();
  6238. return me.minSize;
  6239. },
  6240. afterUpdate: function() {
  6241. helpers.callback(this.options.afterUpdate, [this]);
  6242. },
  6243. //
  6244. beforeSetDimensions: function() {
  6245. helpers.callback(this.options.beforeSetDimensions, [this]);
  6246. },
  6247. setDimensions: function() {
  6248. var me = this;
  6249. // Set the unconstrained dimension before label rotation
  6250. if (me.isHorizontal()) {
  6251. // Reset position before calculating rotation
  6252. me.width = me.maxWidth;
  6253. me.left = 0;
  6254. me.right = me.width;
  6255. } else {
  6256. me.height = me.maxHeight;
  6257. // Reset position before calculating rotation
  6258. me.top = 0;
  6259. me.bottom = me.height;
  6260. }
  6261. // Reset padding
  6262. me.paddingLeft = 0;
  6263. me.paddingTop = 0;
  6264. me.paddingRight = 0;
  6265. me.paddingBottom = 0;
  6266. },
  6267. afterSetDimensions: function() {
  6268. helpers.callback(this.options.afterSetDimensions, [this]);
  6269. },
  6270. // Data limits
  6271. beforeDataLimits: function() {
  6272. helpers.callback(this.options.beforeDataLimits, [this]);
  6273. },
  6274. determineDataLimits: helpers.noop,
  6275. afterDataLimits: function() {
  6276. helpers.callback(this.options.afterDataLimits, [this]);
  6277. },
  6278. //
  6279. beforeBuildTicks: function() {
  6280. helpers.callback(this.options.beforeBuildTicks, [this]);
  6281. },
  6282. buildTicks: helpers.noop,
  6283. afterBuildTicks: function() {
  6284. helpers.callback(this.options.afterBuildTicks, [this]);
  6285. },
  6286. beforeTickToLabelConversion: function() {
  6287. helpers.callback(this.options.beforeTickToLabelConversion, [this]);
  6288. },
  6289. convertTicksToLabels: function() {
  6290. var me = this;
  6291. // Convert ticks to strings
  6292. var tickOpts = me.options.ticks;
  6293. me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback, this);
  6294. },
  6295. afterTickToLabelConversion: function() {
  6296. helpers.callback(this.options.afterTickToLabelConversion, [this]);
  6297. },
  6298. //
  6299. beforeCalculateTickRotation: function() {
  6300. helpers.callback(this.options.beforeCalculateTickRotation, [this]);
  6301. },
  6302. calculateTickRotation: function() {
  6303. var me = this;
  6304. var context = me.ctx;
  6305. var tickOpts = me.options.ticks;
  6306. var labels = labelsFromTicks(me._ticks);
  6307. // Get the width of each grid by calculating the difference
  6308. // between x offsets between 0 and 1.
  6309. var tickFont = parseFontOptions(tickOpts);
  6310. context.font = tickFont.font;
  6311. var labelRotation = tickOpts.minRotation || 0;
  6312. if (labels.length && me.options.display && me.isHorizontal()) {
  6313. var originalLabelWidth = helpers.longestText(context, tickFont.font, labels, me.longestTextCache);
  6314. var labelWidth = originalLabelWidth;
  6315. var cosRotation, sinRotation;
  6316. // Allow 3 pixels x2 padding either side for label readability
  6317. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6318. // Max label rotation can be set or default to 90 - also act as a loop counter
  6319. while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
  6320. var angleRadians = helpers.toRadians(labelRotation);
  6321. cosRotation = Math.cos(angleRadians);
  6322. sinRotation = Math.sin(angleRadians);
  6323. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6324. // go back one step
  6325. labelRotation--;
  6326. break;
  6327. }
  6328. labelRotation++;
  6329. labelWidth = cosRotation * originalLabelWidth;
  6330. }
  6331. }
  6332. me.labelRotation = labelRotation;
  6333. },
  6334. afterCalculateTickRotation: function() {
  6335. helpers.callback(this.options.afterCalculateTickRotation, [this]);
  6336. },
  6337. //
  6338. beforeFit: function() {
  6339. helpers.callback(this.options.beforeFit, [this]);
  6340. },
  6341. fit: function() {
  6342. var me = this;
  6343. // Reset
  6344. var minSize = me.minSize = {
  6345. width: 0,
  6346. height: 0
  6347. };
  6348. var labels = labelsFromTicks(me._ticks);
  6349. var opts = me.options;
  6350. var tickOpts = opts.ticks;
  6351. var scaleLabelOpts = opts.scaleLabel;
  6352. var gridLineOpts = opts.gridLines;
  6353. var display = opts.display;
  6354. var isHorizontal = me.isHorizontal();
  6355. var tickFont = parseFontOptions(tickOpts);
  6356. var tickMarkLength = opts.gridLines.tickMarkLength;
  6357. // Width
  6358. if (isHorizontal) {
  6359. // subtract the margins to line up with the chartArea if we are a full width scale
  6360. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6361. } else {
  6362. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6363. }
  6364. // height
  6365. if (isHorizontal) {
  6366. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6367. } else {
  6368. minSize.height = me.maxHeight; // fill all the height
  6369. }
  6370. // Are we showing a title for the scale?
  6371. if (scaleLabelOpts.display && display) {
  6372. var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
  6373. var scaleLabelPadding = helpers.options.toPadding(scaleLabelOpts.padding);
  6374. var deltaHeight = scaleLabelLineHeight + scaleLabelPadding.height;
  6375. if (isHorizontal) {
  6376. minSize.height += deltaHeight;
  6377. } else {
  6378. minSize.width += deltaHeight;
  6379. }
  6380. }
  6381. // Don't bother fitting the ticks if we are not showing them
  6382. if (tickOpts.display && display) {
  6383. var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, labels, me.longestTextCache);
  6384. var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
  6385. var lineSpace = tickFont.size * 0.5;
  6386. var tickPadding = me.options.ticks.padding;
  6387. if (isHorizontal) {
  6388. // A horizontal axis is more constrained by the height.
  6389. me.longestLabelWidth = largestTextWidth;
  6390. var angleRadians = helpers.toRadians(me.labelRotation);
  6391. var cosRotation = Math.cos(angleRadians);
  6392. var sinRotation = Math.sin(angleRadians);
  6393. // TODO - improve this calculation
  6394. var labelHeight = (sinRotation * largestTextWidth)
  6395. + (tickFont.size * tallestLabelHeightInLines)
  6396. + (lineSpace * (tallestLabelHeightInLines - 1))
  6397. + lineSpace; // padding
  6398. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);
  6399. me.ctx.font = tickFont.font;
  6400. var firstLabelWidth = computeTextSize(me.ctx, labels[0], tickFont.font);
  6401. var lastLabelWidth = computeTextSize(me.ctx, labels[labels.length - 1], tickFont.font);
  6402. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
  6403. // which means that the right padding is dominated by the font height
  6404. if (me.labelRotation !== 0) {
  6405. me.paddingLeft = opts.position === 'bottom' ? (cosRotation * firstLabelWidth) + 3 : (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
  6406. me.paddingRight = opts.position === 'bottom' ? (cosRotation * lineSpace) + 3 : (cosRotation * lastLabelWidth) + 3;
  6407. } else {
  6408. me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6409. me.paddingRight = lastLabelWidth / 2 + 3;
  6410. }
  6411. } else {
  6412. // A vertical axis is more constrained by the width. Labels are the
  6413. // dominant factor here, so get that length first and account for padding
  6414. if (tickOpts.mirror) {
  6415. largestTextWidth = 0;
  6416. } else {
  6417. // use lineSpace for consistency with horizontal axis
  6418. // tickPadding is not implemented for horizontal
  6419. largestTextWidth += tickPadding + lineSpace;
  6420. }
  6421. minSize.width = Math.min(me.maxWidth, minSize.width + largestTextWidth);
  6422. me.paddingTop = tickFont.size / 2;
  6423. me.paddingBottom = tickFont.size / 2;
  6424. }
  6425. }
  6426. me.handleMargins();
  6427. me.width = minSize.width;
  6428. me.height = minSize.height;
  6429. },
  6430. /**
  6431. * Handle margins and padding interactions
  6432. * @private
  6433. */
  6434. handleMargins: function() {
  6435. var me = this;
  6436. if (me.margins) {
  6437. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6438. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6439. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6440. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6441. }
  6442. },
  6443. afterFit: function() {
  6444. helpers.callback(this.options.afterFit, [this]);
  6445. },
  6446. // Shared Methods
  6447. isHorizontal: function() {
  6448. return this.options.position === 'top' || this.options.position === 'bottom';
  6449. },
  6450. isFullWidth: function() {
  6451. return (this.options.fullWidth);
  6452. },
  6453. // 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
  6454. getRightValue: function(rawValue) {
  6455. // Null and undefined values first
  6456. if (helpers.isNullOrUndef(rawValue)) {
  6457. return NaN;
  6458. }
  6459. // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
  6460. if (typeof rawValue === 'number' && !isFinite(rawValue)) {
  6461. return NaN;
  6462. }
  6463. // If it is in fact an object, dive in one more level
  6464. if (rawValue) {
  6465. if (this.isHorizontal()) {
  6466. if (rawValue.x !== undefined) {
  6467. return this.getRightValue(rawValue.x);
  6468. }
  6469. } else if (rawValue.y !== undefined) {
  6470. return this.getRightValue(rawValue.y);
  6471. }
  6472. }
  6473. // Value is good, return it
  6474. return rawValue;
  6475. },
  6476. /**
  6477. * Used to get the value to display in the tooltip for the data at the given index
  6478. * @param index
  6479. * @param datasetIndex
  6480. */
  6481. getLabelForIndex: helpers.noop,
  6482. /**
  6483. * Returns the location of the given data point. Value can either be an index or a numerical value
  6484. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6485. * @param value
  6486. * @param index
  6487. * @param datasetIndex
  6488. */
  6489. getPixelForValue: helpers.noop,
  6490. /**
  6491. * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6492. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6493. * @param pixel
  6494. */
  6495. getValueForPixel: helpers.noop,
  6496. /**
  6497. * Returns the location of the tick at the given index
  6498. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6499. */
  6500. getPixelForTick: function(index) {
  6501. var me = this;
  6502. var offset = me.options.offset;
  6503. if (me.isHorizontal()) {
  6504. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6505. var tickWidth = innerWidth / Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  6506. var pixel = (tickWidth * index) + me.paddingLeft;
  6507. if (offset) {
  6508. pixel += tickWidth / 2;
  6509. }
  6510. var finalVal = me.left + Math.round(pixel);
  6511. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6512. return finalVal;
  6513. }
  6514. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6515. return me.top + (index * (innerHeight / (me._ticks.length - 1)));
  6516. },
  6517. /**
  6518. * Utility for getting the pixel location of a percentage of scale
  6519. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6520. */
  6521. getPixelForDecimal: function(decimal) {
  6522. var me = this;
  6523. if (me.isHorizontal()) {
  6524. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6525. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6526. var finalVal = me.left + Math.round(valueOffset);
  6527. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6528. return finalVal;
  6529. }
  6530. return me.top + (decimal * me.height);
  6531. },
  6532. /**
  6533. * Returns the pixel for the minimum chart value
  6534. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6535. */
  6536. getBasePixel: function() {
  6537. return this.getPixelForValue(this.getBaseValue());
  6538. },
  6539. getBaseValue: function() {
  6540. var me = this;
  6541. var min = me.min;
  6542. var max = me.max;
  6543. return me.beginAtZero ? 0 :
  6544. min < 0 && max < 0 ? max :
  6545. min > 0 && max > 0 ? min :
  6546. 0;
  6547. },
  6548. /**
  6549. * Returns a subset of ticks to be plotted to avoid overlapping labels.
  6550. * @private
  6551. */
  6552. _autoSkip: function(ticks) {
  6553. var skipRatio;
  6554. var me = this;
  6555. var isHorizontal = me.isHorizontal();
  6556. var optionTicks = me.options.ticks.minor;
  6557. var tickCount = ticks.length;
  6558. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6559. var cosRotation = Math.cos(labelRotationRadians);
  6560. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6561. var result = [];
  6562. var i, tick, shouldSkip;
  6563. // figure out the maximum number of gridlines to show
  6564. var maxTicks;
  6565. if (optionTicks.maxTicksLimit) {
  6566. maxTicks = optionTicks.maxTicksLimit;
  6567. }
  6568. if (isHorizontal) {
  6569. skipRatio = false;
  6570. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount > (me.width - (me.paddingLeft + me.paddingRight))) {
  6571. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount) / (me.width - (me.paddingLeft + me.paddingRight)));
  6572. }
  6573. // if they defined a max number of optionTicks,
  6574. // increase skipRatio until that number is met
  6575. if (maxTicks && tickCount > maxTicks) {
  6576. skipRatio = Math.max(skipRatio, Math.floor(tickCount / maxTicks));
  6577. }
  6578. }
  6579. for (i = 0; i < tickCount; i++) {
  6580. tick = ticks[i];
  6581. // Since we always show the last tick,we need may need to hide the last shown one before
  6582. shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
  6583. if (shouldSkip && i !== tickCount - 1) {
  6584. // leave tick in place but make sure it's not displayed (#4635)
  6585. delete tick.label;
  6586. }
  6587. result.push(tick);
  6588. }
  6589. return result;
  6590. },
  6591. // Actually draw the scale on the canvas
  6592. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6593. draw: function(chartArea) {
  6594. var me = this;
  6595. var options = me.options;
  6596. if (!options.display) {
  6597. return;
  6598. }
  6599. var context = me.ctx;
  6600. var globalDefaults = defaults.global;
  6601. var optionTicks = options.ticks.minor;
  6602. var optionMajorTicks = options.ticks.major || optionTicks;
  6603. var gridLines = options.gridLines;
  6604. var scaleLabel = options.scaleLabel;
  6605. var isRotated = me.labelRotation !== 0;
  6606. var isHorizontal = me.isHorizontal();
  6607. var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
  6608. var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6609. var tickFont = parseFontOptions(optionTicks);
  6610. var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, globalDefaults.defaultFontColor);
  6611. var majorTickFont = parseFontOptions(optionMajorTicks);
  6612. var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
  6613. var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6614. var scaleLabelFont = parseFontOptions(scaleLabel);
  6615. var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
  6616. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6617. var itemsToDraw = [];
  6618. var axisWidth = me.options.gridLines.lineWidth;
  6619. var xTickStart = options.position === 'right' ? me.left : me.right - axisWidth - tl;
  6620. var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
  6621. var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
  6622. var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
  6623. helpers.each(ticks, function(tick, index) {
  6624. // autoskipper skipped this tick (#4635)
  6625. if (helpers.isNullOrUndef(tick.label)) {
  6626. return;
  6627. }
  6628. var label = tick.label;
  6629. var lineWidth, lineColor, borderDash, borderDashOffset;
  6630. if (index === me.zeroLineIndex && options.offset === gridLines.offsetGridLines) {
  6631. // Draw the first index specially
  6632. lineWidth = gridLines.zeroLineWidth;
  6633. lineColor = gridLines.zeroLineColor;
  6634. borderDash = gridLines.zeroLineBorderDash;
  6635. borderDashOffset = gridLines.zeroLineBorderDashOffset;
  6636. } else {
  6637. lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
  6638. lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
  6639. borderDash = helpers.valueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6640. borderDashOffset = helpers.valueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6641. }
  6642. // Common properties
  6643. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6644. var textAlign = 'middle';
  6645. var textBaseline = 'middle';
  6646. var tickPadding = optionTicks.padding;
  6647. if (isHorizontal) {
  6648. var labelYOffset = tl + tickPadding;
  6649. if (options.position === 'bottom') {
  6650. // bottom
  6651. textBaseline = !isRotated ? 'top' : 'middle';
  6652. textAlign = !isRotated ? 'center' : 'right';
  6653. labelY = me.top + labelYOffset;
  6654. } else {
  6655. // top
  6656. textBaseline = !isRotated ? 'bottom' : 'middle';
  6657. textAlign = !isRotated ? 'center' : 'left';
  6658. labelY = me.bottom - labelYOffset;
  6659. }
  6660. var xLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6661. if (xLineValue < me.left) {
  6662. lineColor = 'rgba(0,0,0,0)';
  6663. }
  6664. xLineValue += helpers.aliasPixel(lineWidth);
  6665. labelX = me.getPixelForTick(index) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6666. tx1 = tx2 = x1 = x2 = xLineValue;
  6667. ty1 = yTickStart;
  6668. ty2 = yTickEnd;
  6669. y1 = chartArea.top;
  6670. y2 = chartArea.bottom + axisWidth;
  6671. } else {
  6672. var isLeft = options.position === 'left';
  6673. var labelXOffset;
  6674. if (optionTicks.mirror) {
  6675. textAlign = isLeft ? 'left' : 'right';
  6676. labelXOffset = tickPadding;
  6677. } else {
  6678. textAlign = isLeft ? 'right' : 'left';
  6679. labelXOffset = tl + tickPadding;
  6680. }
  6681. labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
  6682. var yLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6683. if (yLineValue < me.top) {
  6684. lineColor = 'rgba(0,0,0,0)';
  6685. }
  6686. yLineValue += helpers.aliasPixel(lineWidth);
  6687. labelY = me.getPixelForTick(index) + optionTicks.labelOffset;
  6688. tx1 = xTickStart;
  6689. tx2 = xTickEnd;
  6690. x1 = chartArea.left;
  6691. x2 = chartArea.right + axisWidth;
  6692. ty1 = ty2 = y1 = y2 = yLineValue;
  6693. }
  6694. itemsToDraw.push({
  6695. tx1: tx1,
  6696. ty1: ty1,
  6697. tx2: tx2,
  6698. ty2: ty2,
  6699. x1: x1,
  6700. y1: y1,
  6701. x2: x2,
  6702. y2: y2,
  6703. labelX: labelX,
  6704. labelY: labelY,
  6705. glWidth: lineWidth,
  6706. glColor: lineColor,
  6707. glBorderDash: borderDash,
  6708. glBorderDashOffset: borderDashOffset,
  6709. rotation: -1 * labelRotationRadians,
  6710. label: label,
  6711. major: tick.major,
  6712. textBaseline: textBaseline,
  6713. textAlign: textAlign
  6714. });
  6715. });
  6716. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  6717. helpers.each(itemsToDraw, function(itemToDraw) {
  6718. if (gridLines.display) {
  6719. context.save();
  6720. context.lineWidth = itemToDraw.glWidth;
  6721. context.strokeStyle = itemToDraw.glColor;
  6722. if (context.setLineDash) {
  6723. context.setLineDash(itemToDraw.glBorderDash);
  6724. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  6725. }
  6726. context.beginPath();
  6727. if (gridLines.drawTicks) {
  6728. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  6729. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  6730. }
  6731. if (gridLines.drawOnChartArea) {
  6732. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  6733. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  6734. }
  6735. context.stroke();
  6736. context.restore();
  6737. }
  6738. if (optionTicks.display) {
  6739. // Make sure we draw text in the correct color and font
  6740. context.save();
  6741. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  6742. context.rotate(itemToDraw.rotation);
  6743. context.font = itemToDraw.major ? majorTickFont.font : tickFont.font;
  6744. context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
  6745. context.textBaseline = itemToDraw.textBaseline;
  6746. context.textAlign = itemToDraw.textAlign;
  6747. var label = itemToDraw.label;
  6748. if (helpers.isArray(label)) {
  6749. var lineCount = label.length;
  6750. var lineHeight = tickFont.size * 1.5;
  6751. var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
  6752. for (var i = 0; i < lineCount; ++i) {
  6753. // We just make sure the multiline element is a string here..
  6754. context.fillText('' + label[i], 0, y);
  6755. // apply same lineSpacing as calculated @ L#320
  6756. y += lineHeight;
  6757. }
  6758. } else {
  6759. context.fillText(label, 0, 0);
  6760. }
  6761. context.restore();
  6762. }
  6763. });
  6764. if (scaleLabel.display) {
  6765. // Draw the scale label
  6766. var scaleLabelX;
  6767. var scaleLabelY;
  6768. var rotation = 0;
  6769. var halfLineHeight = parseLineHeight(scaleLabel) / 2;
  6770. if (isHorizontal) {
  6771. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  6772. scaleLabelY = options.position === 'bottom'
  6773. ? me.bottom - halfLineHeight - scaleLabelPadding.bottom
  6774. : me.top + halfLineHeight + scaleLabelPadding.top;
  6775. } else {
  6776. var isLeft = options.position === 'left';
  6777. scaleLabelX = isLeft
  6778. ? me.left + halfLineHeight + scaleLabelPadding.top
  6779. : me.right - halfLineHeight - scaleLabelPadding.top;
  6780. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  6781. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  6782. }
  6783. context.save();
  6784. context.translate(scaleLabelX, scaleLabelY);
  6785. context.rotate(rotation);
  6786. context.textAlign = 'center';
  6787. context.textBaseline = 'middle';
  6788. context.fillStyle = scaleLabelFontColor; // render in correct colour
  6789. context.font = scaleLabelFont.font;
  6790. context.fillText(scaleLabel.labelString, 0, 0);
  6791. context.restore();
  6792. }
  6793. if (gridLines.drawBorder) {
  6794. // Draw the line at the edge of the axis
  6795. context.lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0);
  6796. context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
  6797. var x1 = me.left;
  6798. var x2 = me.right + axisWidth;
  6799. var y1 = me.top;
  6800. var y2 = me.bottom + axisWidth;
  6801. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  6802. if (isHorizontal) {
  6803. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  6804. y1 += aliasPixel;
  6805. y2 += aliasPixel;
  6806. } else {
  6807. x1 = x2 = options.position === 'left' ? me.right : me.left;
  6808. x1 += aliasPixel;
  6809. x2 += aliasPixel;
  6810. }
  6811. context.beginPath();
  6812. context.moveTo(x1, y1);
  6813. context.lineTo(x2, y2);
  6814. context.stroke();
  6815. }
  6816. }
  6817. });
  6818. },{"26":26,"27":27,"35":35,"46":46}],34:[function(require,module,exports){
  6819. 'use strict';
  6820. var defaults = require(26);
  6821. var helpers = require(46);
  6822. var layouts = require(31);
  6823. module.exports = {
  6824. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  6825. // use the new chart options to grab the correct scale
  6826. constructors: {},
  6827. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  6828. // old browsers
  6829. // Scale config defaults
  6830. defaults: {},
  6831. registerScaleType: function(type, scaleConstructor, scaleDefaults) {
  6832. this.constructors[type] = scaleConstructor;
  6833. this.defaults[type] = helpers.clone(scaleDefaults);
  6834. },
  6835. getScaleConstructor: function(type) {
  6836. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  6837. },
  6838. getScaleDefaults: function(type) {
  6839. // Return the scale defaults merged with the global settings so that we always use the latest ones
  6840. return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
  6841. },
  6842. updateScaleDefaults: function(type, additions) {
  6843. var me = this;
  6844. if (me.defaults.hasOwnProperty(type)) {
  6845. me.defaults[type] = helpers.extend(me.defaults[type], additions);
  6846. }
  6847. },
  6848. addScalesToLayout: function(chart) {
  6849. // Adds each scale to the chart.boxes array to be sized accordingly
  6850. helpers.each(chart.scales, function(scale) {
  6851. // Set ILayoutItem parameters for backwards compatibility
  6852. scale.fullWidth = scale.options.fullWidth;
  6853. scale.position = scale.options.position;
  6854. scale.weight = scale.options.weight;
  6855. layouts.addBox(chart, scale);
  6856. });
  6857. }
  6858. };
  6859. },{"26":26,"31":31,"46":46}],35:[function(require,module,exports){
  6860. 'use strict';
  6861. var helpers = require(46);
  6862. /**
  6863. * Namespace to hold static tick generation functions
  6864. * @namespace Chart.Ticks
  6865. */
  6866. module.exports = {
  6867. /**
  6868. * Namespace to hold formatters for different types of ticks
  6869. * @namespace Chart.Ticks.formatters
  6870. */
  6871. formatters: {
  6872. /**
  6873. * Formatter for value labels
  6874. * @method Chart.Ticks.formatters.values
  6875. * @param value the value to display
  6876. * @return {String|Array} the label to display
  6877. */
  6878. values: function(value) {
  6879. return helpers.isArray(value) ? value : '' + value;
  6880. },
  6881. /**
  6882. * Formatter for linear numeric ticks
  6883. * @method Chart.Ticks.formatters.linear
  6884. * @param tickValue {Number} the value to be formatted
  6885. * @param index {Number} the position of the tickValue parameter in the ticks array
  6886. * @param ticks {Array<Number>} the list of ticks being converted
  6887. * @return {String} string representation of the tickValue parameter
  6888. */
  6889. linear: function(tickValue, index, ticks) {
  6890. // If we have lots of ticks, don't use the ones
  6891. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  6892. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  6893. if (Math.abs(delta) > 1) {
  6894. if (tickValue !== Math.floor(tickValue)) {
  6895. // not an integer
  6896. delta = tickValue - Math.floor(tickValue);
  6897. }
  6898. }
  6899. var logDelta = helpers.log10(Math.abs(delta));
  6900. var tickString = '';
  6901. if (tickValue !== 0) {
  6902. var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1]));
  6903. if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation
  6904. var logTick = helpers.log10(Math.abs(tickValue));
  6905. tickString = tickValue.toExponential(Math.floor(logTick) - Math.floor(logDelta));
  6906. } else {
  6907. var numDecimal = -1 * Math.floor(logDelta);
  6908. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  6909. tickString = tickValue.toFixed(numDecimal);
  6910. }
  6911. } else {
  6912. tickString = '0'; // never show decimal places for 0
  6913. }
  6914. return tickString;
  6915. },
  6916. logarithmic: function(tickValue, index, ticks) {
  6917. var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
  6918. if (tickValue === 0) {
  6919. return '0';
  6920. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
  6921. return tickValue.toExponential();
  6922. }
  6923. return '';
  6924. }
  6925. }
  6926. };
  6927. },{"46":46}],36:[function(require,module,exports){
  6928. 'use strict';
  6929. var defaults = require(26);
  6930. var Element = require(27);
  6931. var helpers = require(46);
  6932. defaults._set('global', {
  6933. tooltips: {
  6934. enabled: true,
  6935. custom: null,
  6936. mode: 'nearest',
  6937. position: 'average',
  6938. intersect: true,
  6939. backgroundColor: 'rgba(0,0,0,0.8)',
  6940. titleFontStyle: 'bold',
  6941. titleSpacing: 2,
  6942. titleMarginBottom: 6,
  6943. titleFontColor: '#fff',
  6944. titleAlign: 'left',
  6945. bodySpacing: 2,
  6946. bodyFontColor: '#fff',
  6947. bodyAlign: 'left',
  6948. footerFontStyle: 'bold',
  6949. footerSpacing: 2,
  6950. footerMarginTop: 6,
  6951. footerFontColor: '#fff',
  6952. footerAlign: 'left',
  6953. yPadding: 6,
  6954. xPadding: 6,
  6955. caretPadding: 2,
  6956. caretSize: 5,
  6957. cornerRadius: 6,
  6958. multiKeyBackground: '#fff',
  6959. displayColors: true,
  6960. borderColor: 'rgba(0,0,0,0)',
  6961. borderWidth: 0,
  6962. callbacks: {
  6963. // Args are: (tooltipItems, data)
  6964. beforeTitle: helpers.noop,
  6965. title: function(tooltipItems, data) {
  6966. // Pick first xLabel for now
  6967. var title = '';
  6968. var labels = data.labels;
  6969. var labelCount = labels ? labels.length : 0;
  6970. if (tooltipItems.length > 0) {
  6971. var item = tooltipItems[0];
  6972. if (item.xLabel) {
  6973. title = item.xLabel;
  6974. } else if (labelCount > 0 && item.index < labelCount) {
  6975. title = labels[item.index];
  6976. }
  6977. }
  6978. return title;
  6979. },
  6980. afterTitle: helpers.noop,
  6981. // Args are: (tooltipItems, data)
  6982. beforeBody: helpers.noop,
  6983. // Args are: (tooltipItem, data)
  6984. beforeLabel: helpers.noop,
  6985. label: function(tooltipItem, data) {
  6986. var label = data.datasets[tooltipItem.datasetIndex].label || '';
  6987. if (label) {
  6988. label += ': ';
  6989. }
  6990. label += tooltipItem.yLabel;
  6991. return label;
  6992. },
  6993. labelColor: function(tooltipItem, chart) {
  6994. var meta = chart.getDatasetMeta(tooltipItem.datasetIndex);
  6995. var activeElement = meta.data[tooltipItem.index];
  6996. var view = activeElement._view;
  6997. return {
  6998. borderColor: view.borderColor,
  6999. backgroundColor: view.backgroundColor
  7000. };
  7001. },
  7002. labelTextColor: function() {
  7003. return this._options.bodyFontColor;
  7004. },
  7005. afterLabel: helpers.noop,
  7006. // Args are: (tooltipItems, data)
  7007. afterBody: helpers.noop,
  7008. // Args are: (tooltipItems, data)
  7009. beforeFooter: helpers.noop,
  7010. footer: helpers.noop,
  7011. afterFooter: helpers.noop
  7012. }
  7013. }
  7014. });
  7015. var positioners = {
  7016. /**
  7017. * Average mode places the tooltip at the average position of the elements shown
  7018. * @function Chart.Tooltip.positioners.average
  7019. * @param elements {ChartElement[]} the elements being displayed in the tooltip
  7020. * @returns {Point} tooltip position
  7021. */
  7022. average: function(elements) {
  7023. if (!elements.length) {
  7024. return false;
  7025. }
  7026. var i, len;
  7027. var x = 0;
  7028. var y = 0;
  7029. var count = 0;
  7030. for (i = 0, len = elements.length; i < len; ++i) {
  7031. var el = elements[i];
  7032. if (el && el.hasValue()) {
  7033. var pos = el.tooltipPosition();
  7034. x += pos.x;
  7035. y += pos.y;
  7036. ++count;
  7037. }
  7038. }
  7039. return {
  7040. x: Math.round(x / count),
  7041. y: Math.round(y / count)
  7042. };
  7043. },
  7044. /**
  7045. * Gets the tooltip position nearest of the item nearest to the event position
  7046. * @function Chart.Tooltip.positioners.nearest
  7047. * @param elements {Chart.Element[]} the tooltip elements
  7048. * @param eventPosition {Point} the position of the event in canvas coordinates
  7049. * @returns {Point} the tooltip position
  7050. */
  7051. nearest: function(elements, eventPosition) {
  7052. var x = eventPosition.x;
  7053. var y = eventPosition.y;
  7054. var minDistance = Number.POSITIVE_INFINITY;
  7055. var i, len, nearestElement;
  7056. for (i = 0, len = elements.length; i < len; ++i) {
  7057. var el = elements[i];
  7058. if (el && el.hasValue()) {
  7059. var center = el.getCenterPoint();
  7060. var d = helpers.distanceBetweenPoints(eventPosition, center);
  7061. if (d < minDistance) {
  7062. minDistance = d;
  7063. nearestElement = el;
  7064. }
  7065. }
  7066. }
  7067. if (nearestElement) {
  7068. var tp = nearestElement.tooltipPosition();
  7069. x = tp.x;
  7070. y = tp.y;
  7071. }
  7072. return {
  7073. x: x,
  7074. y: y
  7075. };
  7076. }
  7077. };
  7078. /**
  7079. * Helper method to merge the opacity into a color
  7080. */
  7081. function mergeOpacity(colorString, opacity) {
  7082. var color = helpers.color(colorString);
  7083. return color.alpha(opacity * color.alpha()).rgbaString();
  7084. }
  7085. // Helper to push or concat based on if the 2nd parameter is an array or not
  7086. function pushOrConcat(base, toPush) {
  7087. if (toPush) {
  7088. if (helpers.isArray(toPush)) {
  7089. // base = base.concat(toPush);
  7090. Array.prototype.push.apply(base, toPush);
  7091. } else {
  7092. base.push(toPush);
  7093. }
  7094. }
  7095. return base;
  7096. }
  7097. /**
  7098. * Returns array of strings split by newline
  7099. * @param {String} value - The value to split by newline.
  7100. * @returns {Array} value if newline present - Returned from String split() method
  7101. * @function
  7102. */
  7103. function splitNewlines(str) {
  7104. if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) {
  7105. return str.split('\n');
  7106. }
  7107. return str;
  7108. }
  7109. // Private helper to create a tooltip item model
  7110. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  7111. // @return : new tooltip item
  7112. function createTooltipItem(element) {
  7113. var xScale = element._xScale;
  7114. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  7115. var index = element._index;
  7116. var datasetIndex = element._datasetIndex;
  7117. return {
  7118. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  7119. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  7120. index: index,
  7121. datasetIndex: datasetIndex,
  7122. x: element._model.x,
  7123. y: element._model.y
  7124. };
  7125. }
  7126. /**
  7127. * Helper to get the reset model for the tooltip
  7128. * @param tooltipOpts {Object} the tooltip options
  7129. */
  7130. function getBaseModel(tooltipOpts) {
  7131. var globalDefaults = defaults.global;
  7132. var valueOrDefault = helpers.valueOrDefault;
  7133. return {
  7134. // Positioning
  7135. xPadding: tooltipOpts.xPadding,
  7136. yPadding: tooltipOpts.yPadding,
  7137. xAlign: tooltipOpts.xAlign,
  7138. yAlign: tooltipOpts.yAlign,
  7139. // Body
  7140. bodyFontColor: tooltipOpts.bodyFontColor,
  7141. _bodyFontFamily: valueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  7142. _bodyFontStyle: valueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  7143. _bodyAlign: tooltipOpts.bodyAlign,
  7144. bodyFontSize: valueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  7145. bodySpacing: tooltipOpts.bodySpacing,
  7146. // Title
  7147. titleFontColor: tooltipOpts.titleFontColor,
  7148. _titleFontFamily: valueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  7149. _titleFontStyle: valueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  7150. titleFontSize: valueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  7151. _titleAlign: tooltipOpts.titleAlign,
  7152. titleSpacing: tooltipOpts.titleSpacing,
  7153. titleMarginBottom: tooltipOpts.titleMarginBottom,
  7154. // Footer
  7155. footerFontColor: tooltipOpts.footerFontColor,
  7156. _footerFontFamily: valueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  7157. _footerFontStyle: valueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  7158. footerFontSize: valueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  7159. _footerAlign: tooltipOpts.footerAlign,
  7160. footerSpacing: tooltipOpts.footerSpacing,
  7161. footerMarginTop: tooltipOpts.footerMarginTop,
  7162. // Appearance
  7163. caretSize: tooltipOpts.caretSize,
  7164. cornerRadius: tooltipOpts.cornerRadius,
  7165. backgroundColor: tooltipOpts.backgroundColor,
  7166. opacity: 0,
  7167. legendColorBackground: tooltipOpts.multiKeyBackground,
  7168. displayColors: tooltipOpts.displayColors,
  7169. borderColor: tooltipOpts.borderColor,
  7170. borderWidth: tooltipOpts.borderWidth
  7171. };
  7172. }
  7173. /**
  7174. * Get the size of the tooltip
  7175. */
  7176. function getTooltipSize(tooltip, model) {
  7177. var ctx = tooltip._chart.ctx;
  7178. var height = model.yPadding * 2; // Tooltip Padding
  7179. var width = 0;
  7180. // Count of all lines in the body
  7181. var body = model.body;
  7182. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  7183. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7184. }, 0);
  7185. combinedBodyLength += model.beforeBody.length + model.afterBody.length;
  7186. var titleLineCount = model.title.length;
  7187. var footerLineCount = model.footer.length;
  7188. var titleFontSize = model.titleFontSize;
  7189. var bodyFontSize = model.bodyFontSize;
  7190. var footerFontSize = model.footerFontSize;
  7191. height += titleLineCount * titleFontSize; // Title Lines
  7192. height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
  7193. height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
  7194. height += combinedBodyLength * bodyFontSize; // Body Lines
  7195. height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
  7196. height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
  7197. height += footerLineCount * (footerFontSize); // Footer Lines
  7198. height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
  7199. // Title width
  7200. var widthPadding = 0;
  7201. var maxLineWidth = function(line) {
  7202. width = Math.max(width, ctx.measureText(line).width + widthPadding);
  7203. };
  7204. ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
  7205. helpers.each(model.title, maxLineWidth);
  7206. // Body width
  7207. ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
  7208. helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
  7209. // Body lines may include some extra width due to the color box
  7210. widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
  7211. helpers.each(body, function(bodyItem) {
  7212. helpers.each(bodyItem.before, maxLineWidth);
  7213. helpers.each(bodyItem.lines, maxLineWidth);
  7214. helpers.each(bodyItem.after, maxLineWidth);
  7215. });
  7216. // Reset back to 0
  7217. widthPadding = 0;
  7218. // Footer width
  7219. ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
  7220. helpers.each(model.footer, maxLineWidth);
  7221. // Add padding
  7222. width += 2 * model.xPadding;
  7223. return {
  7224. width: width,
  7225. height: height
  7226. };
  7227. }
  7228. /**
  7229. * Helper to get the alignment of a tooltip given the size
  7230. */
  7231. function determineAlignment(tooltip, size) {
  7232. var model = tooltip._model;
  7233. var chart = tooltip._chart;
  7234. var chartArea = tooltip._chart.chartArea;
  7235. var xAlign = 'center';
  7236. var yAlign = 'center';
  7237. if (model.y < size.height) {
  7238. yAlign = 'top';
  7239. } else if (model.y > (chart.height - size.height)) {
  7240. yAlign = 'bottom';
  7241. }
  7242. var lf, rf; // functions to determine left, right alignment
  7243. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7244. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7245. var midX = (chartArea.left + chartArea.right) / 2;
  7246. var midY = (chartArea.top + chartArea.bottom) / 2;
  7247. if (yAlign === 'center') {
  7248. lf = function(x) {
  7249. return x <= midX;
  7250. };
  7251. rf = function(x) {
  7252. return x > midX;
  7253. };
  7254. } else {
  7255. lf = function(x) {
  7256. return x <= (size.width / 2);
  7257. };
  7258. rf = function(x) {
  7259. return x >= (chart.width - (size.width / 2));
  7260. };
  7261. }
  7262. olf = function(x) {
  7263. return x + size.width + model.caretSize + model.caretPadding > chart.width;
  7264. };
  7265. orf = function(x) {
  7266. return x - size.width - model.caretSize - model.caretPadding < 0;
  7267. };
  7268. yf = function(y) {
  7269. return y <= midY ? 'top' : 'bottom';
  7270. };
  7271. if (lf(model.x)) {
  7272. xAlign = 'left';
  7273. // Is tooltip too wide and goes over the right side of the chart.?
  7274. if (olf(model.x)) {
  7275. xAlign = 'center';
  7276. yAlign = yf(model.y);
  7277. }
  7278. } else if (rf(model.x)) {
  7279. xAlign = 'right';
  7280. // Is tooltip too wide and goes outside left edge of canvas?
  7281. if (orf(model.x)) {
  7282. xAlign = 'center';
  7283. yAlign = yf(model.y);
  7284. }
  7285. }
  7286. var opts = tooltip._options;
  7287. return {
  7288. xAlign: opts.xAlign ? opts.xAlign : xAlign,
  7289. yAlign: opts.yAlign ? opts.yAlign : yAlign
  7290. };
  7291. }
  7292. /**
  7293. * Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
  7294. */
  7295. function getBackgroundPoint(vm, size, alignment, chart) {
  7296. // Background Position
  7297. var x = vm.x;
  7298. var y = vm.y;
  7299. var caretSize = vm.caretSize;
  7300. var caretPadding = vm.caretPadding;
  7301. var cornerRadius = vm.cornerRadius;
  7302. var xAlign = alignment.xAlign;
  7303. var yAlign = alignment.yAlign;
  7304. var paddingAndSize = caretSize + caretPadding;
  7305. var radiusAndPadding = cornerRadius + caretPadding;
  7306. if (xAlign === 'right') {
  7307. x -= size.width;
  7308. } else if (xAlign === 'center') {
  7309. x -= (size.width / 2);
  7310. if (x + size.width > chart.width) {
  7311. x = chart.width - size.width;
  7312. }
  7313. if (x < 0) {
  7314. x = 0;
  7315. }
  7316. }
  7317. if (yAlign === 'top') {
  7318. y += paddingAndSize;
  7319. } else if (yAlign === 'bottom') {
  7320. y -= size.height + paddingAndSize;
  7321. } else {
  7322. y -= (size.height / 2);
  7323. }
  7324. if (yAlign === 'center') {
  7325. if (xAlign === 'left') {
  7326. x += paddingAndSize;
  7327. } else if (xAlign === 'right') {
  7328. x -= paddingAndSize;
  7329. }
  7330. } else if (xAlign === 'left') {
  7331. x -= radiusAndPadding;
  7332. } else if (xAlign === 'right') {
  7333. x += radiusAndPadding;
  7334. }
  7335. return {
  7336. x: x,
  7337. y: y
  7338. };
  7339. }
  7340. /**
  7341. * Helper to build before and after body lines
  7342. */
  7343. function getBeforeAfterBodyLines(callback) {
  7344. return pushOrConcat([], splitNewlines(callback));
  7345. }
  7346. var exports = module.exports = Element.extend({
  7347. initialize: function() {
  7348. this._model = getBaseModel(this._options);
  7349. this._lastActive = [];
  7350. },
  7351. // Get the title
  7352. // Args are: (tooltipItem, data)
  7353. getTitle: function() {
  7354. var me = this;
  7355. var opts = me._options;
  7356. var callbacks = opts.callbacks;
  7357. var beforeTitle = callbacks.beforeTitle.apply(me, arguments);
  7358. var title = callbacks.title.apply(me, arguments);
  7359. var afterTitle = callbacks.afterTitle.apply(me, arguments);
  7360. var lines = [];
  7361. lines = pushOrConcat(lines, splitNewlines(beforeTitle));
  7362. lines = pushOrConcat(lines, splitNewlines(title));
  7363. lines = pushOrConcat(lines, splitNewlines(afterTitle));
  7364. return lines;
  7365. },
  7366. // Args are: (tooltipItem, data)
  7367. getBeforeBody: function() {
  7368. return getBeforeAfterBodyLines(this._options.callbacks.beforeBody.apply(this, arguments));
  7369. },
  7370. // Args are: (tooltipItem, data)
  7371. getBody: function(tooltipItems, data) {
  7372. var me = this;
  7373. var callbacks = me._options.callbacks;
  7374. var bodyItems = [];
  7375. helpers.each(tooltipItems, function(tooltipItem) {
  7376. var bodyItem = {
  7377. before: [],
  7378. lines: [],
  7379. after: []
  7380. };
  7381. pushOrConcat(bodyItem.before, splitNewlines(callbacks.beforeLabel.call(me, tooltipItem, data)));
  7382. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  7383. pushOrConcat(bodyItem.after, splitNewlines(callbacks.afterLabel.call(me, tooltipItem, data)));
  7384. bodyItems.push(bodyItem);
  7385. });
  7386. return bodyItems;
  7387. },
  7388. // Args are: (tooltipItem, data)
  7389. getAfterBody: function() {
  7390. return getBeforeAfterBodyLines(this._options.callbacks.afterBody.apply(this, arguments));
  7391. },
  7392. // Get the footer and beforeFooter and afterFooter lines
  7393. // Args are: (tooltipItem, data)
  7394. getFooter: function() {
  7395. var me = this;
  7396. var callbacks = me._options.callbacks;
  7397. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  7398. var footer = callbacks.footer.apply(me, arguments);
  7399. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  7400. var lines = [];
  7401. lines = pushOrConcat(lines, splitNewlines(beforeFooter));
  7402. lines = pushOrConcat(lines, splitNewlines(footer));
  7403. lines = pushOrConcat(lines, splitNewlines(afterFooter));
  7404. return lines;
  7405. },
  7406. update: function(changed) {
  7407. var me = this;
  7408. var opts = me._options;
  7409. // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
  7410. // 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
  7411. // which breaks any animations.
  7412. var existingModel = me._model;
  7413. var model = me._model = getBaseModel(opts);
  7414. var active = me._active;
  7415. var data = me._data;
  7416. // In the case where active.length === 0 we need to keep these at existing values for good animations
  7417. var alignment = {
  7418. xAlign: existingModel.xAlign,
  7419. yAlign: existingModel.yAlign
  7420. };
  7421. var backgroundPoint = {
  7422. x: existingModel.x,
  7423. y: existingModel.y
  7424. };
  7425. var tooltipSize = {
  7426. width: existingModel.width,
  7427. height: existingModel.height
  7428. };
  7429. var tooltipPosition = {
  7430. x: existingModel.caretX,
  7431. y: existingModel.caretY
  7432. };
  7433. var i, len;
  7434. if (active.length) {
  7435. model.opacity = 1;
  7436. var labelColors = [];
  7437. var labelTextColors = [];
  7438. tooltipPosition = positioners[opts.position].call(me, active, me._eventPosition);
  7439. var tooltipItems = [];
  7440. for (i = 0, len = active.length; i < len; ++i) {
  7441. tooltipItems.push(createTooltipItem(active[i]));
  7442. }
  7443. // If the user provided a filter function, use it to modify the tooltip items
  7444. if (opts.filter) {
  7445. tooltipItems = tooltipItems.filter(function(a) {
  7446. return opts.filter(a, data);
  7447. });
  7448. }
  7449. // If the user provided a sorting function, use it to modify the tooltip items
  7450. if (opts.itemSort) {
  7451. tooltipItems = tooltipItems.sort(function(a, b) {
  7452. return opts.itemSort(a, b, data);
  7453. });
  7454. }
  7455. // Determine colors for boxes
  7456. helpers.each(tooltipItems, function(tooltipItem) {
  7457. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart));
  7458. labelTextColors.push(opts.callbacks.labelTextColor.call(me, tooltipItem, me._chart));
  7459. });
  7460. // Build the Text Lines
  7461. model.title = me.getTitle(tooltipItems, data);
  7462. model.beforeBody = me.getBeforeBody(tooltipItems, data);
  7463. model.body = me.getBody(tooltipItems, data);
  7464. model.afterBody = me.getAfterBody(tooltipItems, data);
  7465. model.footer = me.getFooter(tooltipItems, data);
  7466. // Initial positioning and colors
  7467. model.x = Math.round(tooltipPosition.x);
  7468. model.y = Math.round(tooltipPosition.y);
  7469. model.caretPadding = opts.caretPadding;
  7470. model.labelColors = labelColors;
  7471. model.labelTextColors = labelTextColors;
  7472. // data points
  7473. model.dataPoints = tooltipItems;
  7474. // We need to determine alignment of the tooltip
  7475. tooltipSize = getTooltipSize(this, model);
  7476. alignment = determineAlignment(this, tooltipSize);
  7477. // Final Size and Position
  7478. backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
  7479. } else {
  7480. model.opacity = 0;
  7481. }
  7482. model.xAlign = alignment.xAlign;
  7483. model.yAlign = alignment.yAlign;
  7484. model.x = backgroundPoint.x;
  7485. model.y = backgroundPoint.y;
  7486. model.width = tooltipSize.width;
  7487. model.height = tooltipSize.height;
  7488. // Point where the caret on the tooltip points to
  7489. model.caretX = tooltipPosition.x;
  7490. model.caretY = tooltipPosition.y;
  7491. me._model = model;
  7492. if (changed && opts.custom) {
  7493. opts.custom.call(me, model);
  7494. }
  7495. return me;
  7496. },
  7497. drawCaret: function(tooltipPoint, size) {
  7498. var ctx = this._chart.ctx;
  7499. var vm = this._view;
  7500. var caretPosition = this.getCaretPosition(tooltipPoint, size, vm);
  7501. ctx.lineTo(caretPosition.x1, caretPosition.y1);
  7502. ctx.lineTo(caretPosition.x2, caretPosition.y2);
  7503. ctx.lineTo(caretPosition.x3, caretPosition.y3);
  7504. },
  7505. getCaretPosition: function(tooltipPoint, size, vm) {
  7506. var x1, x2, x3, y1, y2, y3;
  7507. var caretSize = vm.caretSize;
  7508. var cornerRadius = vm.cornerRadius;
  7509. var xAlign = vm.xAlign;
  7510. var yAlign = vm.yAlign;
  7511. var ptX = tooltipPoint.x;
  7512. var ptY = tooltipPoint.y;
  7513. var width = size.width;
  7514. var height = size.height;
  7515. if (yAlign === 'center') {
  7516. y2 = ptY + (height / 2);
  7517. if (xAlign === 'left') {
  7518. x1 = ptX;
  7519. x2 = x1 - caretSize;
  7520. x3 = x1;
  7521. y1 = y2 + caretSize;
  7522. y3 = y2 - caretSize;
  7523. } else {
  7524. x1 = ptX + width;
  7525. x2 = x1 + caretSize;
  7526. x3 = x1;
  7527. y1 = y2 - caretSize;
  7528. y3 = y2 + caretSize;
  7529. }
  7530. } else {
  7531. if (xAlign === 'left') {
  7532. x2 = ptX + cornerRadius + (caretSize);
  7533. x1 = x2 - caretSize;
  7534. x3 = x2 + caretSize;
  7535. } else if (xAlign === 'right') {
  7536. x2 = ptX + width - cornerRadius - caretSize;
  7537. x1 = x2 - caretSize;
  7538. x3 = x2 + caretSize;
  7539. } else {
  7540. x2 = vm.caretX;
  7541. x1 = x2 - caretSize;
  7542. x3 = x2 + caretSize;
  7543. }
  7544. if (yAlign === 'top') {
  7545. y1 = ptY;
  7546. y2 = y1 - caretSize;
  7547. y3 = y1;
  7548. } else {
  7549. y1 = ptY + height;
  7550. y2 = y1 + caretSize;
  7551. y3 = y1;
  7552. // invert drawing order
  7553. var tmp = x3;
  7554. x3 = x1;
  7555. x1 = tmp;
  7556. }
  7557. }
  7558. return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3};
  7559. },
  7560. drawTitle: function(pt, vm, ctx, opacity) {
  7561. var title = vm.title;
  7562. if (title.length) {
  7563. ctx.textAlign = vm._titleAlign;
  7564. ctx.textBaseline = 'top';
  7565. var titleFontSize = vm.titleFontSize;
  7566. var titleSpacing = vm.titleSpacing;
  7567. ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
  7568. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7569. var i, len;
  7570. for (i = 0, len = title.length; i < len; ++i) {
  7571. ctx.fillText(title[i], pt.x, pt.y);
  7572. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  7573. if (i + 1 === title.length) {
  7574. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  7575. }
  7576. }
  7577. }
  7578. },
  7579. drawBody: function(pt, vm, ctx, opacity) {
  7580. var bodyFontSize = vm.bodyFontSize;
  7581. var bodySpacing = vm.bodySpacing;
  7582. var body = vm.body;
  7583. ctx.textAlign = vm._bodyAlign;
  7584. ctx.textBaseline = 'top';
  7585. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7586. // Before Body
  7587. var xLinePadding = 0;
  7588. var fillLineOfText = function(line) {
  7589. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  7590. pt.y += bodyFontSize + bodySpacing;
  7591. };
  7592. // Before body lines
  7593. ctx.fillStyle = mergeOpacity(vm.bodyFontColor, opacity);
  7594. helpers.each(vm.beforeBody, fillLineOfText);
  7595. var drawColorBoxes = vm.displayColors;
  7596. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  7597. // Draw body lines now
  7598. helpers.each(body, function(bodyItem, i) {
  7599. var textColor = mergeOpacity(vm.labelTextColors[i], opacity);
  7600. ctx.fillStyle = textColor;
  7601. helpers.each(bodyItem.before, fillLineOfText);
  7602. helpers.each(bodyItem.lines, function(line) {
  7603. // Draw Legend-like boxes if needed
  7604. if (drawColorBoxes) {
  7605. // Fill a white rect so that colours merge nicely if the opacity is < 1
  7606. ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
  7607. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7608. // Border
  7609. ctx.lineWidth = 1;
  7610. ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
  7611. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7612. // Inner square
  7613. ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
  7614. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  7615. ctx.fillStyle = textColor;
  7616. }
  7617. fillLineOfText(line);
  7618. });
  7619. helpers.each(bodyItem.after, fillLineOfText);
  7620. });
  7621. // Reset back to 0 for after body
  7622. xLinePadding = 0;
  7623. // After body lines
  7624. helpers.each(vm.afterBody, fillLineOfText);
  7625. pt.y -= bodySpacing; // Remove last body spacing
  7626. },
  7627. drawFooter: function(pt, vm, ctx, opacity) {
  7628. var footer = vm.footer;
  7629. if (footer.length) {
  7630. pt.y += vm.footerMarginTop;
  7631. ctx.textAlign = vm._footerAlign;
  7632. ctx.textBaseline = 'top';
  7633. ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
  7634. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7635. helpers.each(footer, function(line) {
  7636. ctx.fillText(line, pt.x, pt.y);
  7637. pt.y += vm.footerFontSize + vm.footerSpacing;
  7638. });
  7639. }
  7640. },
  7641. drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
  7642. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  7643. ctx.strokeStyle = mergeOpacity(vm.borderColor, opacity);
  7644. ctx.lineWidth = vm.borderWidth;
  7645. var xAlign = vm.xAlign;
  7646. var yAlign = vm.yAlign;
  7647. var x = pt.x;
  7648. var y = pt.y;
  7649. var width = tooltipSize.width;
  7650. var height = tooltipSize.height;
  7651. var radius = vm.cornerRadius;
  7652. ctx.beginPath();
  7653. ctx.moveTo(x + radius, y);
  7654. if (yAlign === 'top') {
  7655. this.drawCaret(pt, tooltipSize);
  7656. }
  7657. ctx.lineTo(x + width - radius, y);
  7658. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  7659. if (yAlign === 'center' && xAlign === 'right') {
  7660. this.drawCaret(pt, tooltipSize);
  7661. }
  7662. ctx.lineTo(x + width, y + height - radius);
  7663. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  7664. if (yAlign === 'bottom') {
  7665. this.drawCaret(pt, tooltipSize);
  7666. }
  7667. ctx.lineTo(x + radius, y + height);
  7668. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  7669. if (yAlign === 'center' && xAlign === 'left') {
  7670. this.drawCaret(pt, tooltipSize);
  7671. }
  7672. ctx.lineTo(x, y + radius);
  7673. ctx.quadraticCurveTo(x, y, x + radius, y);
  7674. ctx.closePath();
  7675. ctx.fill();
  7676. if (vm.borderWidth > 0) {
  7677. ctx.stroke();
  7678. }
  7679. },
  7680. draw: function() {
  7681. var ctx = this._chart.ctx;
  7682. var vm = this._view;
  7683. if (vm.opacity === 0) {
  7684. return;
  7685. }
  7686. var tooltipSize = {
  7687. width: vm.width,
  7688. height: vm.height
  7689. };
  7690. var pt = {
  7691. x: vm.x,
  7692. y: vm.y
  7693. };
  7694. // IE11/Edge does not like very small opacities, so snap to 0
  7695. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  7696. // Truthy/falsey value for empty tooltip
  7697. var hasTooltipContent = vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length;
  7698. if (this._options.enabled && hasTooltipContent) {
  7699. // Draw Background
  7700. this.drawBackground(pt, vm, ctx, tooltipSize, opacity);
  7701. // Draw Title, Body, and Footer
  7702. pt.x += vm.xPadding;
  7703. pt.y += vm.yPadding;
  7704. // Titles
  7705. this.drawTitle(pt, vm, ctx, opacity);
  7706. // Body
  7707. this.drawBody(pt, vm, ctx, opacity);
  7708. // Footer
  7709. this.drawFooter(pt, vm, ctx, opacity);
  7710. }
  7711. },
  7712. /**
  7713. * Handle an event
  7714. * @private
  7715. * @param {IEvent} event - The event to handle
  7716. * @returns {Boolean} true if the tooltip changed
  7717. */
  7718. handleEvent: function(e) {
  7719. var me = this;
  7720. var options = me._options;
  7721. var changed = false;
  7722. me._lastActive = me._lastActive || [];
  7723. // Find Active Elements for tooltips
  7724. if (e.type === 'mouseout') {
  7725. me._active = [];
  7726. } else {
  7727. me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
  7728. }
  7729. // Remember Last Actives
  7730. changed = !helpers.arrayEquals(me._active, me._lastActive);
  7731. // Only handle target event on tooltip change
  7732. if (changed) {
  7733. me._lastActive = me._active;
  7734. if (options.enabled || options.custom) {
  7735. me._eventPosition = {
  7736. x: e.x,
  7737. y: e.y
  7738. };
  7739. me.update(true);
  7740. me.pivot();
  7741. }
  7742. }
  7743. return changed;
  7744. }
  7745. });
  7746. /**
  7747. * @namespace Chart.Tooltip.positioners
  7748. */
  7749. exports.positioners = positioners;
  7750. },{"26":26,"27":27,"46":46}],37:[function(require,module,exports){
  7751. 'use strict';
  7752. var defaults = require(26);
  7753. var Element = require(27);
  7754. var helpers = require(46);
  7755. defaults._set('global', {
  7756. elements: {
  7757. arc: {
  7758. backgroundColor: defaults.global.defaultColor,
  7759. borderColor: '#fff',
  7760. borderWidth: 2
  7761. }
  7762. }
  7763. });
  7764. module.exports = Element.extend({
  7765. inLabelRange: function(mouseX) {
  7766. var vm = this._view;
  7767. if (vm) {
  7768. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  7769. }
  7770. return false;
  7771. },
  7772. inRange: function(chartX, chartY) {
  7773. var vm = this._view;
  7774. if (vm) {
  7775. var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
  7776. var angle = pointRelativePosition.angle;
  7777. var distance = pointRelativePosition.distance;
  7778. // Sanitise angle range
  7779. var startAngle = vm.startAngle;
  7780. var endAngle = vm.endAngle;
  7781. while (endAngle < startAngle) {
  7782. endAngle += 2.0 * Math.PI;
  7783. }
  7784. while (angle > endAngle) {
  7785. angle -= 2.0 * Math.PI;
  7786. }
  7787. while (angle < startAngle) {
  7788. angle += 2.0 * Math.PI;
  7789. }
  7790. // Check if within the range of the open/close angle
  7791. var betweenAngles = (angle >= startAngle && angle <= endAngle);
  7792. var withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  7793. return (betweenAngles && withinRadius);
  7794. }
  7795. return false;
  7796. },
  7797. getCenterPoint: function() {
  7798. var vm = this._view;
  7799. var halfAngle = (vm.startAngle + vm.endAngle) / 2;
  7800. var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
  7801. return {
  7802. x: vm.x + Math.cos(halfAngle) * halfRadius,
  7803. y: vm.y + Math.sin(halfAngle) * halfRadius
  7804. };
  7805. },
  7806. getArea: function() {
  7807. var vm = this._view;
  7808. return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
  7809. },
  7810. tooltipPosition: function() {
  7811. var vm = this._view;
  7812. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
  7813. var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  7814. return {
  7815. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  7816. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  7817. };
  7818. },
  7819. draw: function() {
  7820. var ctx = this._chart.ctx;
  7821. var vm = this._view;
  7822. var sA = vm.startAngle;
  7823. var eA = vm.endAngle;
  7824. ctx.beginPath();
  7825. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  7826. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  7827. ctx.closePath();
  7828. ctx.strokeStyle = vm.borderColor;
  7829. ctx.lineWidth = vm.borderWidth;
  7830. ctx.fillStyle = vm.backgroundColor;
  7831. ctx.fill();
  7832. ctx.lineJoin = 'bevel';
  7833. if (vm.borderWidth) {
  7834. ctx.stroke();
  7835. }
  7836. }
  7837. });
  7838. },{"26":26,"27":27,"46":46}],38:[function(require,module,exports){
  7839. 'use strict';
  7840. var defaults = require(26);
  7841. var Element = require(27);
  7842. var helpers = require(46);
  7843. var globalDefaults = defaults.global;
  7844. defaults._set('global', {
  7845. elements: {
  7846. line: {
  7847. tension: 0.4,
  7848. backgroundColor: globalDefaults.defaultColor,
  7849. borderWidth: 3,
  7850. borderColor: globalDefaults.defaultColor,
  7851. borderCapStyle: 'butt',
  7852. borderDash: [],
  7853. borderDashOffset: 0.0,
  7854. borderJoinStyle: 'miter',
  7855. capBezierPoints: true,
  7856. fill: true, // do we fill in the area between the line and its base axis
  7857. }
  7858. }
  7859. });
  7860. module.exports = Element.extend({
  7861. draw: function() {
  7862. var me = this;
  7863. var vm = me._view;
  7864. var ctx = me._chart.ctx;
  7865. var spanGaps = vm.spanGaps;
  7866. var points = me._children.slice(); // clone array
  7867. var globalOptionLineElements = globalDefaults.elements.line;
  7868. var lastDrawnIndex = -1;
  7869. var index, current, previous, currentVM;
  7870. // If we are looping, adding the first point again
  7871. if (me._loop && points.length) {
  7872. points.push(points[0]);
  7873. }
  7874. ctx.save();
  7875. // Stroke Line Options
  7876. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  7877. // IE 9 and 10 do not support line dash
  7878. if (ctx.setLineDash) {
  7879. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  7880. }
  7881. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  7882. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  7883. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  7884. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  7885. // Stroke Line
  7886. ctx.beginPath();
  7887. lastDrawnIndex = -1;
  7888. for (index = 0; index < points.length; ++index) {
  7889. current = points[index];
  7890. previous = helpers.previousItem(points, index);
  7891. currentVM = current._view;
  7892. // First point moves to it's starting position no matter what
  7893. if (index === 0) {
  7894. if (!currentVM.skip) {
  7895. ctx.moveTo(currentVM.x, currentVM.y);
  7896. lastDrawnIndex = index;
  7897. }
  7898. } else {
  7899. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7900. if (!currentVM.skip) {
  7901. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  7902. // There was a gap and this is the first point after the gap
  7903. ctx.moveTo(currentVM.x, currentVM.y);
  7904. } else {
  7905. // Line to next point
  7906. helpers.canvas.lineTo(ctx, previous._view, current._view);
  7907. }
  7908. lastDrawnIndex = index;
  7909. }
  7910. }
  7911. }
  7912. ctx.stroke();
  7913. ctx.restore();
  7914. }
  7915. });
  7916. },{"26":26,"27":27,"46":46}],39:[function(require,module,exports){
  7917. 'use strict';
  7918. var defaults = require(26);
  7919. var Element = require(27);
  7920. var helpers = require(46);
  7921. var defaultColor = defaults.global.defaultColor;
  7922. defaults._set('global', {
  7923. elements: {
  7924. point: {
  7925. radius: 3,
  7926. pointStyle: 'circle',
  7927. backgroundColor: defaultColor,
  7928. borderColor: defaultColor,
  7929. borderWidth: 1,
  7930. // Hover
  7931. hitRadius: 1,
  7932. hoverRadius: 4,
  7933. hoverBorderWidth: 1
  7934. }
  7935. }
  7936. });
  7937. function xRange(mouseX) {
  7938. var vm = this._view;
  7939. return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
  7940. }
  7941. function yRange(mouseY) {
  7942. var vm = this._view;
  7943. return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false;
  7944. }
  7945. module.exports = Element.extend({
  7946. inRange: function(mouseX, mouseY) {
  7947. var vm = this._view;
  7948. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  7949. },
  7950. inLabelRange: xRange,
  7951. inXRange: xRange,
  7952. inYRange: yRange,
  7953. getCenterPoint: function() {
  7954. var vm = this._view;
  7955. return {
  7956. x: vm.x,
  7957. y: vm.y
  7958. };
  7959. },
  7960. getArea: function() {
  7961. return Math.PI * Math.pow(this._view.radius, 2);
  7962. },
  7963. tooltipPosition: function() {
  7964. var vm = this._view;
  7965. return {
  7966. x: vm.x,
  7967. y: vm.y,
  7968. padding: vm.radius + vm.borderWidth
  7969. };
  7970. },
  7971. draw: function(chartArea) {
  7972. var vm = this._view;
  7973. var model = this._model;
  7974. var ctx = this._chart.ctx;
  7975. var pointStyle = vm.pointStyle;
  7976. var rotation = vm.rotation;
  7977. var radius = vm.radius;
  7978. var x = vm.x;
  7979. var y = vm.y;
  7980. var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)
  7981. if (vm.skip) {
  7982. return;
  7983. }
  7984. // Clipping for Points.
  7985. if (chartArea === undefined || (model.x >= chartArea.left && chartArea.right * errMargin >= model.x && model.y >= chartArea.top && chartArea.bottom * errMargin >= model.y)) {
  7986. ctx.strokeStyle = vm.borderColor || defaultColor;
  7987. ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
  7988. ctx.fillStyle = vm.backgroundColor || defaultColor;
  7989. helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y, rotation);
  7990. }
  7991. }
  7992. });
  7993. },{"26":26,"27":27,"46":46}],40:[function(require,module,exports){
  7994. 'use strict';
  7995. var defaults = require(26);
  7996. var Element = require(27);
  7997. defaults._set('global', {
  7998. elements: {
  7999. rectangle: {
  8000. backgroundColor: defaults.global.defaultColor,
  8001. borderColor: defaults.global.defaultColor,
  8002. borderSkipped: 'bottom',
  8003. borderWidth: 0
  8004. }
  8005. }
  8006. });
  8007. function isVertical(bar) {
  8008. return bar._view.width !== undefined;
  8009. }
  8010. /**
  8011. * Helper function to get the bounds of the bar regardless of the orientation
  8012. * @param bar {Chart.Element.Rectangle} the bar
  8013. * @return {Bounds} bounds of the bar
  8014. * @private
  8015. */
  8016. function getBarBounds(bar) {
  8017. var vm = bar._view;
  8018. var x1, x2, y1, y2;
  8019. if (isVertical(bar)) {
  8020. // vertical
  8021. var halfWidth = vm.width / 2;
  8022. x1 = vm.x - halfWidth;
  8023. x2 = vm.x + halfWidth;
  8024. y1 = Math.min(vm.y, vm.base);
  8025. y2 = Math.max(vm.y, vm.base);
  8026. } else {
  8027. // horizontal bar
  8028. var halfHeight = vm.height / 2;
  8029. x1 = Math.min(vm.x, vm.base);
  8030. x2 = Math.max(vm.x, vm.base);
  8031. y1 = vm.y - halfHeight;
  8032. y2 = vm.y + halfHeight;
  8033. }
  8034. return {
  8035. left: x1,
  8036. top: y1,
  8037. right: x2,
  8038. bottom: y2
  8039. };
  8040. }
  8041. module.exports = Element.extend({
  8042. draw: function() {
  8043. var ctx = this._chart.ctx;
  8044. var vm = this._view;
  8045. var left, right, top, bottom, signX, signY, borderSkipped;
  8046. var borderWidth = vm.borderWidth;
  8047. if (!vm.horizontal) {
  8048. // bar
  8049. left = vm.x - vm.width / 2;
  8050. right = vm.x + vm.width / 2;
  8051. top = vm.y;
  8052. bottom = vm.base;
  8053. signX = 1;
  8054. signY = bottom > top ? 1 : -1;
  8055. borderSkipped = vm.borderSkipped || 'bottom';
  8056. } else {
  8057. // horizontal bar
  8058. left = vm.base;
  8059. right = vm.x;
  8060. top = vm.y - vm.height / 2;
  8061. bottom = vm.y + vm.height / 2;
  8062. signX = right > left ? 1 : -1;
  8063. signY = 1;
  8064. borderSkipped = vm.borderSkipped || 'left';
  8065. }
  8066. // Canvas doesn't allow us to stroke inside the width so we can
  8067. // adjust the sizes to fit if we're setting a stroke on the line
  8068. if (borderWidth) {
  8069. // borderWidth shold be less than bar width and bar height.
  8070. var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
  8071. borderWidth = borderWidth > barSize ? barSize : borderWidth;
  8072. var halfStroke = borderWidth / 2;
  8073. // Adjust borderWidth when bar top position is near vm.base(zero).
  8074. var borderLeft = left + (borderSkipped !== 'left' ? halfStroke * signX : 0);
  8075. var borderRight = right + (borderSkipped !== 'right' ? -halfStroke * signX : 0);
  8076. var borderTop = top + (borderSkipped !== 'top' ? halfStroke * signY : 0);
  8077. var borderBottom = bottom + (borderSkipped !== 'bottom' ? -halfStroke * signY : 0);
  8078. // not become a vertical line?
  8079. if (borderLeft !== borderRight) {
  8080. top = borderTop;
  8081. bottom = borderBottom;
  8082. }
  8083. // not become a horizontal line?
  8084. if (borderTop !== borderBottom) {
  8085. left = borderLeft;
  8086. right = borderRight;
  8087. }
  8088. }
  8089. ctx.beginPath();
  8090. ctx.fillStyle = vm.backgroundColor;
  8091. ctx.strokeStyle = vm.borderColor;
  8092. ctx.lineWidth = borderWidth;
  8093. // Corner points, from bottom-left to bottom-right clockwise
  8094. // | 1 2 |
  8095. // | 0 3 |
  8096. var corners = [
  8097. [left, bottom],
  8098. [left, top],
  8099. [right, top],
  8100. [right, bottom]
  8101. ];
  8102. // Find first (starting) corner with fallback to 'bottom'
  8103. var borders = ['bottom', 'left', 'top', 'right'];
  8104. var startCorner = borders.indexOf(borderSkipped, 0);
  8105. if (startCorner === -1) {
  8106. startCorner = 0;
  8107. }
  8108. function cornerAt(index) {
  8109. return corners[(startCorner + index) % 4];
  8110. }
  8111. // Draw rectangle from 'startCorner'
  8112. var corner = cornerAt(0);
  8113. ctx.moveTo(corner[0], corner[1]);
  8114. for (var i = 1; i < 4; i++) {
  8115. corner = cornerAt(i);
  8116. ctx.lineTo(corner[0], corner[1]);
  8117. }
  8118. ctx.fill();
  8119. if (borderWidth) {
  8120. ctx.stroke();
  8121. }
  8122. },
  8123. height: function() {
  8124. var vm = this._view;
  8125. return vm.base - vm.y;
  8126. },
  8127. inRange: function(mouseX, mouseY) {
  8128. var inRange = false;
  8129. if (this._view) {
  8130. var bounds = getBarBounds(this);
  8131. inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
  8132. }
  8133. return inRange;
  8134. },
  8135. inLabelRange: function(mouseX, mouseY) {
  8136. var me = this;
  8137. if (!me._view) {
  8138. return false;
  8139. }
  8140. var inRange = false;
  8141. var bounds = getBarBounds(me);
  8142. if (isVertical(me)) {
  8143. inRange = mouseX >= bounds.left && mouseX <= bounds.right;
  8144. } else {
  8145. inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
  8146. }
  8147. return inRange;
  8148. },
  8149. inXRange: function(mouseX) {
  8150. var bounds = getBarBounds(this);
  8151. return mouseX >= bounds.left && mouseX <= bounds.right;
  8152. },
  8153. inYRange: function(mouseY) {
  8154. var bounds = getBarBounds(this);
  8155. return mouseY >= bounds.top && mouseY <= bounds.bottom;
  8156. },
  8157. getCenterPoint: function() {
  8158. var vm = this._view;
  8159. var x, y;
  8160. if (isVertical(this)) {
  8161. x = vm.x;
  8162. y = (vm.y + vm.base) / 2;
  8163. } else {
  8164. x = (vm.x + vm.base) / 2;
  8165. y = vm.y;
  8166. }
  8167. return {x: x, y: y};
  8168. },
  8169. getArea: function() {
  8170. var vm = this._view;
  8171. return vm.width * Math.abs(vm.y - vm.base);
  8172. },
  8173. tooltipPosition: function() {
  8174. var vm = this._view;
  8175. return {
  8176. x: vm.x,
  8177. y: vm.y
  8178. };
  8179. }
  8180. });
  8181. },{"26":26,"27":27}],41:[function(require,module,exports){
  8182. 'use strict';
  8183. module.exports = {};
  8184. module.exports.Arc = require(37);
  8185. module.exports.Line = require(38);
  8186. module.exports.Point = require(39);
  8187. module.exports.Rectangle = require(40);
  8188. },{"37":37,"38":38,"39":39,"40":40}],42:[function(require,module,exports){
  8189. 'use strict';
  8190. var helpers = require(43);
  8191. /**
  8192. * @namespace Chart.helpers.canvas
  8193. */
  8194. var exports = module.exports = {
  8195. /**
  8196. * Clears the entire canvas associated to the given `chart`.
  8197. * @param {Chart} chart - The chart for which to clear the canvas.
  8198. */
  8199. clear: function(chart) {
  8200. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  8201. },
  8202. /**
  8203. * Creates a "path" for a rectangle with rounded corners at position (x, y) with a
  8204. * given size (width, height) and the same `radius` for all corners.
  8205. * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context.
  8206. * @param {Number} x - The x axis of the coordinate for the rectangle starting point.
  8207. * @param {Number} y - The y axis of the coordinate for the rectangle starting point.
  8208. * @param {Number} width - The rectangle's width.
  8209. * @param {Number} height - The rectangle's height.
  8210. * @param {Number} radius - The rounded amount (in pixels) for the four corners.
  8211. * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
  8212. */
  8213. roundedRect: function(ctx, x, y, width, height, radius) {
  8214. if (radius) {
  8215. // NOTE(SB) `epsilon` helps to prevent minor artifacts appearing
  8216. // on Chrome when `r` is exactly half the height or the width.
  8217. var epsilon = 0.0000001;
  8218. var r = Math.min(radius, (height / 2) - epsilon, (width / 2) - epsilon);
  8219. ctx.moveTo(x + r, y);
  8220. ctx.lineTo(x + width - r, y);
  8221. ctx.arcTo(x + width, y, x + width, y + r, r);
  8222. ctx.lineTo(x + width, y + height - r);
  8223. ctx.arcTo(x + width, y + height, x + width - r, y + height, r);
  8224. ctx.lineTo(x + r, y + height);
  8225. ctx.arcTo(x, y + height, x, y + height - r, r);
  8226. ctx.lineTo(x, y + r);
  8227. ctx.arcTo(x, y, x + r, y, r);
  8228. ctx.closePath();
  8229. ctx.moveTo(x, y);
  8230. } else {
  8231. ctx.rect(x, y, width, height);
  8232. }
  8233. },
  8234. drawPoint: function(ctx, style, radius, x, y, rotation) {
  8235. var type, edgeLength, xOffset, yOffset, height, size;
  8236. rotation = rotation || 0;
  8237. if (style && typeof style === 'object') {
  8238. type = style.toString();
  8239. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  8240. ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
  8241. return;
  8242. }
  8243. }
  8244. if (isNaN(radius) || radius <= 0) {
  8245. return;
  8246. }
  8247. ctx.save();
  8248. ctx.translate(x, y);
  8249. ctx.rotate(rotation * Math.PI / 180);
  8250. ctx.beginPath();
  8251. switch (style) {
  8252. // Default includes circle
  8253. default:
  8254. ctx.arc(0, 0, radius, 0, Math.PI * 2);
  8255. ctx.closePath();
  8256. break;
  8257. case 'triangle':
  8258. edgeLength = 3 * radius / Math.sqrt(3);
  8259. height = edgeLength * Math.sqrt(3) / 2;
  8260. ctx.moveTo(-edgeLength / 2, height / 3);
  8261. ctx.lineTo(edgeLength / 2, height / 3);
  8262. ctx.lineTo(0, -2 * height / 3);
  8263. ctx.closePath();
  8264. break;
  8265. case 'rect':
  8266. size = 1 / Math.SQRT2 * radius;
  8267. ctx.rect(-size, -size, 2 * size, 2 * size);
  8268. break;
  8269. case 'rectRounded':
  8270. var offset = radius / Math.SQRT2;
  8271. var leftX = -offset;
  8272. var topY = -offset;
  8273. var sideSize = Math.SQRT2 * radius;
  8274. // NOTE(SB) the rounded rect implementation changed to use `arcTo`
  8275. // instead of `quadraticCurveTo` since it generates better results
  8276. // when rect is almost a circle. 0.425 (instead of 0.5) produces
  8277. // results visually closer to the previous impl.
  8278. this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius * 0.425);
  8279. break;
  8280. case 'rectRot':
  8281. size = 1 / Math.SQRT2 * radius;
  8282. ctx.moveTo(-size, 0);
  8283. ctx.lineTo(0, size);
  8284. ctx.lineTo(size, 0);
  8285. ctx.lineTo(0, -size);
  8286. ctx.closePath();
  8287. break;
  8288. case 'cross':
  8289. ctx.moveTo(0, radius);
  8290. ctx.lineTo(0, -radius);
  8291. ctx.moveTo(-radius, 0);
  8292. ctx.lineTo(radius, 0);
  8293. break;
  8294. case 'crossRot':
  8295. xOffset = Math.cos(Math.PI / 4) * radius;
  8296. yOffset = Math.sin(Math.PI / 4) * radius;
  8297. ctx.moveTo(-xOffset, -yOffset);
  8298. ctx.lineTo(xOffset, yOffset);
  8299. ctx.moveTo(-xOffset, yOffset);
  8300. ctx.lineTo(xOffset, -yOffset);
  8301. break;
  8302. case 'star':
  8303. ctx.moveTo(0, radius);
  8304. ctx.lineTo(0, -radius);
  8305. ctx.moveTo(-radius, 0);
  8306. ctx.lineTo(radius, 0);
  8307. xOffset = Math.cos(Math.PI / 4) * radius;
  8308. yOffset = Math.sin(Math.PI / 4) * radius;
  8309. ctx.moveTo(-xOffset, -yOffset);
  8310. ctx.lineTo(xOffset, yOffset);
  8311. ctx.moveTo(-xOffset, yOffset);
  8312. ctx.lineTo(xOffset, -yOffset);
  8313. break;
  8314. case 'line':
  8315. ctx.moveTo(-radius, 0);
  8316. ctx.lineTo(radius, 0);
  8317. break;
  8318. case 'dash':
  8319. ctx.moveTo(0, 0);
  8320. ctx.lineTo(radius, 0);
  8321. break;
  8322. }
  8323. ctx.fill();
  8324. ctx.stroke();
  8325. ctx.restore();
  8326. },
  8327. clipArea: function(ctx, area) {
  8328. ctx.save();
  8329. ctx.beginPath();
  8330. ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
  8331. ctx.clip();
  8332. },
  8333. unclipArea: function(ctx) {
  8334. ctx.restore();
  8335. },
  8336. lineTo: function(ctx, previous, target, flip) {
  8337. if (target.steppedLine) {
  8338. if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
  8339. ctx.lineTo(previous.x, target.y);
  8340. } else {
  8341. ctx.lineTo(target.x, previous.y);
  8342. }
  8343. ctx.lineTo(target.x, target.y);
  8344. return;
  8345. }
  8346. if (!target.tension) {
  8347. ctx.lineTo(target.x, target.y);
  8348. return;
  8349. }
  8350. ctx.bezierCurveTo(
  8351. flip ? previous.controlPointPreviousX : previous.controlPointNextX,
  8352. flip ? previous.controlPointPreviousY : previous.controlPointNextY,
  8353. flip ? target.controlPointNextX : target.controlPointPreviousX,
  8354. flip ? target.controlPointNextY : target.controlPointPreviousY,
  8355. target.x,
  8356. target.y);
  8357. }
  8358. };
  8359. // DEPRECATIONS
  8360. /**
  8361. * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
  8362. * @namespace Chart.helpers.clear
  8363. * @deprecated since version 2.7.0
  8364. * @todo remove at version 3
  8365. * @private
  8366. */
  8367. helpers.clear = exports.clear;
  8368. /**
  8369. * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
  8370. * @namespace Chart.helpers.drawRoundedRectangle
  8371. * @deprecated since version 2.7.0
  8372. * @todo remove at version 3
  8373. * @private
  8374. */
  8375. helpers.drawRoundedRectangle = function(ctx) {
  8376. ctx.beginPath();
  8377. exports.roundedRect.apply(exports, arguments);
  8378. };
  8379. },{"43":43}],43:[function(require,module,exports){
  8380. 'use strict';
  8381. /**
  8382. * @namespace Chart.helpers
  8383. */
  8384. var helpers = {
  8385. /**
  8386. * An empty function that can be used, for example, for optional callback.
  8387. */
  8388. noop: function() {},
  8389. /**
  8390. * Returns a unique id, sequentially generated from a global variable.
  8391. * @returns {Number}
  8392. * @function
  8393. */
  8394. uid: (function() {
  8395. var id = 0;
  8396. return function() {
  8397. return id++;
  8398. };
  8399. }()),
  8400. /**
  8401. * Returns true if `value` is neither null nor undefined, else returns false.
  8402. * @param {*} value - The value to test.
  8403. * @returns {Boolean}
  8404. * @since 2.7.0
  8405. */
  8406. isNullOrUndef: function(value) {
  8407. return value === null || typeof value === 'undefined';
  8408. },
  8409. /**
  8410. * Returns true if `value` is an array, else returns false.
  8411. * @param {*} value - The value to test.
  8412. * @returns {Boolean}
  8413. * @function
  8414. */
  8415. isArray: Array.isArray ? Array.isArray : function(value) {
  8416. return Object.prototype.toString.call(value) === '[object Array]';
  8417. },
  8418. /**
  8419. * Returns true if `value` is an object (excluding null), else returns false.
  8420. * @param {*} value - The value to test.
  8421. * @returns {Boolean}
  8422. * @since 2.7.0
  8423. */
  8424. isObject: function(value) {
  8425. return value !== null && Object.prototype.toString.call(value) === '[object Object]';
  8426. },
  8427. /**
  8428. * Returns `value` if defined, else returns `defaultValue`.
  8429. * @param {*} value - The value to return if defined.
  8430. * @param {*} defaultValue - The value to return if `value` is undefined.
  8431. * @returns {*}
  8432. */
  8433. valueOrDefault: function(value, defaultValue) {
  8434. return typeof value === 'undefined' ? defaultValue : value;
  8435. },
  8436. /**
  8437. * Returns value at the given `index` in array if defined, else returns `defaultValue`.
  8438. * @param {Array} value - The array to lookup for value at `index`.
  8439. * @param {Number} index - The index in `value` to lookup for value.
  8440. * @param {*} defaultValue - The value to return if `value[index]` is undefined.
  8441. * @returns {*}
  8442. */
  8443. valueAtIndexOrDefault: function(value, index, defaultValue) {
  8444. return helpers.valueOrDefault(helpers.isArray(value) ? value[index] : value, defaultValue);
  8445. },
  8446. /**
  8447. * Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
  8448. * value returned by `fn`. If `fn` is not a function, this method returns undefined.
  8449. * @param {Function} fn - The function to call.
  8450. * @param {Array|undefined|null} args - The arguments with which `fn` should be called.
  8451. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8452. * @returns {*}
  8453. */
  8454. callback: function(fn, args, thisArg) {
  8455. if (fn && typeof fn.call === 'function') {
  8456. return fn.apply(thisArg, args);
  8457. }
  8458. },
  8459. /**
  8460. * Note(SB) for performance sake, this method should only be used when loopable type
  8461. * is unknown or in none intensive code (not called often and small loopable). Else
  8462. * it's preferable to use a regular for() loop and save extra function calls.
  8463. * @param {Object|Array} loopable - The object or array to be iterated.
  8464. * @param {Function} fn - The function to call for each item.
  8465. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8466. * @param {Boolean} [reverse] - If true, iterates backward on the loopable.
  8467. */
  8468. each: function(loopable, fn, thisArg, reverse) {
  8469. var i, len, keys;
  8470. if (helpers.isArray(loopable)) {
  8471. len = loopable.length;
  8472. if (reverse) {
  8473. for (i = len - 1; i >= 0; i--) {
  8474. fn.call(thisArg, loopable[i], i);
  8475. }
  8476. } else {
  8477. for (i = 0; i < len; i++) {
  8478. fn.call(thisArg, loopable[i], i);
  8479. }
  8480. }
  8481. } else if (helpers.isObject(loopable)) {
  8482. keys = Object.keys(loopable);
  8483. len = keys.length;
  8484. for (i = 0; i < len; i++) {
  8485. fn.call(thisArg, loopable[keys[i]], keys[i]);
  8486. }
  8487. }
  8488. },
  8489. /**
  8490. * Returns true if the `a0` and `a1` arrays have the same content, else returns false.
  8491. * @see http://stackoverflow.com/a/14853974
  8492. * @param {Array} a0 - The array to compare
  8493. * @param {Array} a1 - The array to compare
  8494. * @returns {Boolean}
  8495. */
  8496. arrayEquals: function(a0, a1) {
  8497. var i, ilen, v0, v1;
  8498. if (!a0 || !a1 || a0.length !== a1.length) {
  8499. return false;
  8500. }
  8501. for (i = 0, ilen = a0.length; i < ilen; ++i) {
  8502. v0 = a0[i];
  8503. v1 = a1[i];
  8504. if (v0 instanceof Array && v1 instanceof Array) {
  8505. if (!helpers.arrayEquals(v0, v1)) {
  8506. return false;
  8507. }
  8508. } else if (v0 !== v1) {
  8509. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  8510. return false;
  8511. }
  8512. }
  8513. return true;
  8514. },
  8515. /**
  8516. * Returns a deep copy of `source` without keeping references on objects and arrays.
  8517. * @param {*} source - The value to clone.
  8518. * @returns {*}
  8519. */
  8520. clone: function(source) {
  8521. if (helpers.isArray(source)) {
  8522. return source.map(helpers.clone);
  8523. }
  8524. if (helpers.isObject(source)) {
  8525. var target = {};
  8526. var keys = Object.keys(source);
  8527. var klen = keys.length;
  8528. var k = 0;
  8529. for (; k < klen; ++k) {
  8530. target[keys[k]] = helpers.clone(source[keys[k]]);
  8531. }
  8532. return target;
  8533. }
  8534. return source;
  8535. },
  8536. /**
  8537. * The default merger when Chart.helpers.merge is called without merger option.
  8538. * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
  8539. * @private
  8540. */
  8541. _merger: function(key, target, source, options) {
  8542. var tval = target[key];
  8543. var sval = source[key];
  8544. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8545. helpers.merge(tval, sval, options);
  8546. } else {
  8547. target[key] = helpers.clone(sval);
  8548. }
  8549. },
  8550. /**
  8551. * Merges source[key] in target[key] only if target[key] is undefined.
  8552. * @private
  8553. */
  8554. _mergerIf: function(key, target, source) {
  8555. var tval = target[key];
  8556. var sval = source[key];
  8557. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8558. helpers.mergeIf(tval, sval);
  8559. } else if (!target.hasOwnProperty(key)) {
  8560. target[key] = helpers.clone(sval);
  8561. }
  8562. },
  8563. /**
  8564. * Recursively deep copies `source` properties into `target` with the given `options`.
  8565. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8566. * @param {Object} target - The target object in which all sources are merged into.
  8567. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8568. * @param {Object} [options] - Merging options:
  8569. * @param {Function} [options.merger] - The merge method (key, target, source, options)
  8570. * @returns {Object} The `target` object.
  8571. */
  8572. merge: function(target, source, options) {
  8573. var sources = helpers.isArray(source) ? source : [source];
  8574. var ilen = sources.length;
  8575. var merge, i, keys, klen, k;
  8576. if (!helpers.isObject(target)) {
  8577. return target;
  8578. }
  8579. options = options || {};
  8580. merge = options.merger || helpers._merger;
  8581. for (i = 0; i < ilen; ++i) {
  8582. source = sources[i];
  8583. if (!helpers.isObject(source)) {
  8584. continue;
  8585. }
  8586. keys = Object.keys(source);
  8587. for (k = 0, klen = keys.length; k < klen; ++k) {
  8588. merge(keys[k], target, source, options);
  8589. }
  8590. }
  8591. return target;
  8592. },
  8593. /**
  8594. * Recursively deep copies `source` properties into `target` *only* if not defined in target.
  8595. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8596. * @param {Object} target - The target object in which all sources are merged into.
  8597. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8598. * @returns {Object} The `target` object.
  8599. */
  8600. mergeIf: function(target, source) {
  8601. return helpers.merge(target, source, {merger: helpers._mergerIf});
  8602. },
  8603. /**
  8604. * Applies the contents of two or more objects together into the first object.
  8605. * @param {Object} target - The target object in which all objects are merged into.
  8606. * @param {Object} arg1 - Object containing additional properties to merge in target.
  8607. * @param {Object} argN - Additional objects containing properties to merge in target.
  8608. * @returns {Object} The `target` object.
  8609. */
  8610. extend: function(target) {
  8611. var setFn = function(value, key) {
  8612. target[key] = value;
  8613. };
  8614. for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
  8615. helpers.each(arguments[i], setFn);
  8616. }
  8617. return target;
  8618. },
  8619. /**
  8620. * Basic javascript inheritance based on the model created in Backbone.js
  8621. */
  8622. inherits: function(extensions) {
  8623. var me = this;
  8624. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
  8625. return me.apply(this, arguments);
  8626. };
  8627. var Surrogate = function() {
  8628. this.constructor = ChartElement;
  8629. };
  8630. Surrogate.prototype = me.prototype;
  8631. ChartElement.prototype = new Surrogate();
  8632. ChartElement.extend = helpers.inherits;
  8633. if (extensions) {
  8634. helpers.extend(ChartElement.prototype, extensions);
  8635. }
  8636. ChartElement.__super__ = me.prototype;
  8637. return ChartElement;
  8638. }
  8639. };
  8640. module.exports = helpers;
  8641. // DEPRECATIONS
  8642. /**
  8643. * Provided for backward compatibility, use Chart.helpers.callback instead.
  8644. * @function Chart.helpers.callCallback
  8645. * @deprecated since version 2.6.0
  8646. * @todo remove at version 3
  8647. * @private
  8648. */
  8649. helpers.callCallback = helpers.callback;
  8650. /**
  8651. * Provided for backward compatibility, use Array.prototype.indexOf instead.
  8652. * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
  8653. * @function Chart.helpers.indexOf
  8654. * @deprecated since version 2.7.0
  8655. * @todo remove at version 3
  8656. * @private
  8657. */
  8658. helpers.indexOf = function(array, item, fromIndex) {
  8659. return Array.prototype.indexOf.call(array, item, fromIndex);
  8660. };
  8661. /**
  8662. * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
  8663. * @function Chart.helpers.getValueOrDefault
  8664. * @deprecated since version 2.7.0
  8665. * @todo remove at version 3
  8666. * @private
  8667. */
  8668. helpers.getValueOrDefault = helpers.valueOrDefault;
  8669. /**
  8670. * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
  8671. * @function Chart.helpers.getValueAtIndexOrDefault
  8672. * @deprecated since version 2.7.0
  8673. * @todo remove at version 3
  8674. * @private
  8675. */
  8676. helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  8677. },{}],44:[function(require,module,exports){
  8678. 'use strict';
  8679. var helpers = require(43);
  8680. /**
  8681. * Easing functions adapted from Robert Penner's easing equations.
  8682. * @namespace Chart.helpers.easingEffects
  8683. * @see http://www.robertpenner.com/easing/
  8684. */
  8685. var effects = {
  8686. linear: function(t) {
  8687. return t;
  8688. },
  8689. easeInQuad: function(t) {
  8690. return t * t;
  8691. },
  8692. easeOutQuad: function(t) {
  8693. return -t * (t - 2);
  8694. },
  8695. easeInOutQuad: function(t) {
  8696. if ((t /= 0.5) < 1) {
  8697. return 0.5 * t * t;
  8698. }
  8699. return -0.5 * ((--t) * (t - 2) - 1);
  8700. },
  8701. easeInCubic: function(t) {
  8702. return t * t * t;
  8703. },
  8704. easeOutCubic: function(t) {
  8705. return (t = t - 1) * t * t + 1;
  8706. },
  8707. easeInOutCubic: function(t) {
  8708. if ((t /= 0.5) < 1) {
  8709. return 0.5 * t * t * t;
  8710. }
  8711. return 0.5 * ((t -= 2) * t * t + 2);
  8712. },
  8713. easeInQuart: function(t) {
  8714. return t * t * t * t;
  8715. },
  8716. easeOutQuart: function(t) {
  8717. return -((t = t - 1) * t * t * t - 1);
  8718. },
  8719. easeInOutQuart: function(t) {
  8720. if ((t /= 0.5) < 1) {
  8721. return 0.5 * t * t * t * t;
  8722. }
  8723. return -0.5 * ((t -= 2) * t * t * t - 2);
  8724. },
  8725. easeInQuint: function(t) {
  8726. return t * t * t * t * t;
  8727. },
  8728. easeOutQuint: function(t) {
  8729. return (t = t - 1) * t * t * t * t + 1;
  8730. },
  8731. easeInOutQuint: function(t) {
  8732. if ((t /= 0.5) < 1) {
  8733. return 0.5 * t * t * t * t * t;
  8734. }
  8735. return 0.5 * ((t -= 2) * t * t * t * t + 2);
  8736. },
  8737. easeInSine: function(t) {
  8738. return -Math.cos(t * (Math.PI / 2)) + 1;
  8739. },
  8740. easeOutSine: function(t) {
  8741. return Math.sin(t * (Math.PI / 2));
  8742. },
  8743. easeInOutSine: function(t) {
  8744. return -0.5 * (Math.cos(Math.PI * t) - 1);
  8745. },
  8746. easeInExpo: function(t) {
  8747. return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
  8748. },
  8749. easeOutExpo: function(t) {
  8750. return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
  8751. },
  8752. easeInOutExpo: function(t) {
  8753. if (t === 0) {
  8754. return 0;
  8755. }
  8756. if (t === 1) {
  8757. return 1;
  8758. }
  8759. if ((t /= 0.5) < 1) {
  8760. return 0.5 * Math.pow(2, 10 * (t - 1));
  8761. }
  8762. return 0.5 * (-Math.pow(2, -10 * --t) + 2);
  8763. },
  8764. easeInCirc: function(t) {
  8765. if (t >= 1) {
  8766. return t;
  8767. }
  8768. return -(Math.sqrt(1 - t * t) - 1);
  8769. },
  8770. easeOutCirc: function(t) {
  8771. return Math.sqrt(1 - (t = t - 1) * t);
  8772. },
  8773. easeInOutCirc: function(t) {
  8774. if ((t /= 0.5) < 1) {
  8775. return -0.5 * (Math.sqrt(1 - t * t) - 1);
  8776. }
  8777. return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  8778. },
  8779. easeInElastic: function(t) {
  8780. var s = 1.70158;
  8781. var p = 0;
  8782. var a = 1;
  8783. if (t === 0) {
  8784. return 0;
  8785. }
  8786. if (t === 1) {
  8787. return 1;
  8788. }
  8789. if (!p) {
  8790. p = 0.3;
  8791. }
  8792. if (a < 1) {
  8793. a = 1;
  8794. s = p / 4;
  8795. } else {
  8796. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8797. }
  8798. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  8799. },
  8800. easeOutElastic: function(t) {
  8801. var s = 1.70158;
  8802. var p = 0;
  8803. var a = 1;
  8804. if (t === 0) {
  8805. return 0;
  8806. }
  8807. if (t === 1) {
  8808. return 1;
  8809. }
  8810. if (!p) {
  8811. p = 0.3;
  8812. }
  8813. if (a < 1) {
  8814. a = 1;
  8815. s = p / 4;
  8816. } else {
  8817. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8818. }
  8819. return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
  8820. },
  8821. easeInOutElastic: function(t) {
  8822. var s = 1.70158;
  8823. var p = 0;
  8824. var a = 1;
  8825. if (t === 0) {
  8826. return 0;
  8827. }
  8828. if ((t /= 0.5) === 2) {
  8829. return 1;
  8830. }
  8831. if (!p) {
  8832. p = 0.45;
  8833. }
  8834. if (a < 1) {
  8835. a = 1;
  8836. s = p / 4;
  8837. } else {
  8838. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8839. }
  8840. if (t < 1) {
  8841. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  8842. }
  8843. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
  8844. },
  8845. easeInBack: function(t) {
  8846. var s = 1.70158;
  8847. return t * t * ((s + 1) * t - s);
  8848. },
  8849. easeOutBack: function(t) {
  8850. var s = 1.70158;
  8851. return (t = t - 1) * t * ((s + 1) * t + s) + 1;
  8852. },
  8853. easeInOutBack: function(t) {
  8854. var s = 1.70158;
  8855. if ((t /= 0.5) < 1) {
  8856. return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
  8857. }
  8858. return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  8859. },
  8860. easeInBounce: function(t) {
  8861. return 1 - effects.easeOutBounce(1 - t);
  8862. },
  8863. easeOutBounce: function(t) {
  8864. if (t < (1 / 2.75)) {
  8865. return 7.5625 * t * t;
  8866. }
  8867. if (t < (2 / 2.75)) {
  8868. return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
  8869. }
  8870. if (t < (2.5 / 2.75)) {
  8871. return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
  8872. }
  8873. return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
  8874. },
  8875. easeInOutBounce: function(t) {
  8876. if (t < 0.5) {
  8877. return effects.easeInBounce(t * 2) * 0.5;
  8878. }
  8879. return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
  8880. }
  8881. };
  8882. module.exports = {
  8883. effects: effects
  8884. };
  8885. // DEPRECATIONS
  8886. /**
  8887. * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
  8888. * @function Chart.helpers.easingEffects
  8889. * @deprecated since version 2.7.0
  8890. * @todo remove at version 3
  8891. * @private
  8892. */
  8893. helpers.easingEffects = effects;
  8894. },{"43":43}],45:[function(require,module,exports){
  8895. 'use strict';
  8896. var helpers = require(43);
  8897. /**
  8898. * @alias Chart.helpers.options
  8899. * @namespace
  8900. */
  8901. module.exports = {
  8902. /**
  8903. * Converts the given line height `value` in pixels for a specific font `size`.
  8904. * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
  8905. * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
  8906. * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
  8907. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
  8908. * @since 2.7.0
  8909. */
  8910. toLineHeight: function(value, size) {
  8911. var matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
  8912. if (!matches || matches[1] === 'normal') {
  8913. return size * 1.2;
  8914. }
  8915. value = +matches[2];
  8916. switch (matches[3]) {
  8917. case 'px':
  8918. return value;
  8919. case '%':
  8920. value /= 100;
  8921. break;
  8922. default:
  8923. break;
  8924. }
  8925. return size * value;
  8926. },
  8927. /**
  8928. * Converts the given value into a padding object with pre-computed width/height.
  8929. * @param {Number|Object} value - If a number, set the value to all TRBL component,
  8930. * else, if and object, use defined properties and sets undefined ones to 0.
  8931. * @returns {Object} The padding values (top, right, bottom, left, width, height)
  8932. * @since 2.7.0
  8933. */
  8934. toPadding: function(value) {
  8935. var t, r, b, l;
  8936. if (helpers.isObject(value)) {
  8937. t = +value.top || 0;
  8938. r = +value.right || 0;
  8939. b = +value.bottom || 0;
  8940. l = +value.left || 0;
  8941. } else {
  8942. t = r = b = l = +value || 0;
  8943. }
  8944. return {
  8945. top: t,
  8946. right: r,
  8947. bottom: b,
  8948. left: l,
  8949. height: t + b,
  8950. width: l + r
  8951. };
  8952. },
  8953. /**
  8954. * Evaluates the given `inputs` sequentially and returns the first defined value.
  8955. * @param {Array[]} inputs - An array of values, falling back to the last value.
  8956. * @param {Object} [context] - If defined and the current value is a function, the value
  8957. * is called with `context` as first argument and the result becomes the new input.
  8958. * @param {Number} [index] - If defined and the current value is an array, the value
  8959. * at `index` become the new input.
  8960. * @since 2.7.0
  8961. */
  8962. resolve: function(inputs, context, index) {
  8963. var i, ilen, value;
  8964. for (i = 0, ilen = inputs.length; i < ilen; ++i) {
  8965. value = inputs[i];
  8966. if (value === undefined) {
  8967. continue;
  8968. }
  8969. if (context !== undefined && typeof value === 'function') {
  8970. value = value(context);
  8971. }
  8972. if (index !== undefined && helpers.isArray(value)) {
  8973. value = value[index];
  8974. }
  8975. if (value !== undefined) {
  8976. return value;
  8977. }
  8978. }
  8979. }
  8980. };
  8981. },{"43":43}],46:[function(require,module,exports){
  8982. 'use strict';
  8983. module.exports = require(43);
  8984. module.exports.easing = require(44);
  8985. module.exports.canvas = require(42);
  8986. module.exports.options = require(45);
  8987. },{"42":42,"43":43,"44":44,"45":45}],47:[function(require,module,exports){
  8988. /**
  8989. * Platform fallback implementation (minimal).
  8990. * @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
  8991. */
  8992. module.exports = {
  8993. acquireContext: function(item) {
  8994. if (item && item.canvas) {
  8995. // Support for any object associated to a canvas (including a context2d)
  8996. item = item.canvas;
  8997. }
  8998. return item && item.getContext('2d') || null;
  8999. }
  9000. };
  9001. },{}],48:[function(require,module,exports){
  9002. /**
  9003. * Chart.Platform implementation for targeting a web browser
  9004. */
  9005. 'use strict';
  9006. var helpers = require(46);
  9007. var EXPANDO_KEY = '$chartjs';
  9008. var CSS_PREFIX = 'chartjs-';
  9009. var CSS_RENDER_MONITOR = CSS_PREFIX + 'render-monitor';
  9010. var CSS_RENDER_ANIMATION = CSS_PREFIX + 'render-animation';
  9011. var ANIMATION_START_EVENTS = ['animationstart', 'webkitAnimationStart'];
  9012. /**
  9013. * DOM event types -> Chart.js event types.
  9014. * Note: only events with different types are mapped.
  9015. * @see https://developer.mozilla.org/en-US/docs/Web/Events
  9016. */
  9017. var EVENT_TYPES = {
  9018. touchstart: 'mousedown',
  9019. touchmove: 'mousemove',
  9020. touchend: 'mouseup',
  9021. pointerenter: 'mouseenter',
  9022. pointerdown: 'mousedown',
  9023. pointermove: 'mousemove',
  9024. pointerup: 'mouseup',
  9025. pointerleave: 'mouseout',
  9026. pointerout: 'mouseout'
  9027. };
  9028. /**
  9029. * The "used" size is the final value of a dimension property after all calculations have
  9030. * been performed. This method uses the computed style of `element` but returns undefined
  9031. * if the computed style is not expressed in pixels. That can happen in some cases where
  9032. * `element` has a size relative to its parent and this last one is not yet displayed,
  9033. * for example because of `display: none` on a parent node.
  9034. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
  9035. * @returns {Number} Size in pixels or undefined if unknown.
  9036. */
  9037. function readUsedSize(element, property) {
  9038. var value = helpers.getStyle(element, property);
  9039. var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
  9040. return matches ? Number(matches[1]) : undefined;
  9041. }
  9042. /**
  9043. * Initializes the canvas style and render size without modifying the canvas display size,
  9044. * since responsiveness is handled by the controller.resize() method. The config is used
  9045. * to determine the aspect ratio to apply in case no explicit height has been specified.
  9046. */
  9047. function initCanvas(canvas, config) {
  9048. var style = canvas.style;
  9049. // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
  9050. // returns null or '' if no explicit value has been set to the canvas attribute.
  9051. var renderHeight = canvas.getAttribute('height');
  9052. var renderWidth = canvas.getAttribute('width');
  9053. // Chart.js modifies some canvas values that we want to restore on destroy
  9054. canvas[EXPANDO_KEY] = {
  9055. initial: {
  9056. height: renderHeight,
  9057. width: renderWidth,
  9058. style: {
  9059. display: style.display,
  9060. height: style.height,
  9061. width: style.width
  9062. }
  9063. }
  9064. };
  9065. // Force canvas to display as block to avoid extra space caused by inline
  9066. // elements, which would interfere with the responsive resize process.
  9067. // https://github.com/chartjs/Chart.js/issues/2538
  9068. style.display = style.display || 'block';
  9069. if (renderWidth === null || renderWidth === '') {
  9070. var displayWidth = readUsedSize(canvas, 'width');
  9071. if (displayWidth !== undefined) {
  9072. canvas.width = displayWidth;
  9073. }
  9074. }
  9075. if (renderHeight === null || renderHeight === '') {
  9076. if (canvas.style.height === '') {
  9077. // If no explicit render height and style height, let's apply the aspect ratio,
  9078. // which one can be specified by the user but also by charts as default option
  9079. // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
  9080. canvas.height = canvas.width / (config.options.aspectRatio || 2);
  9081. } else {
  9082. var displayHeight = readUsedSize(canvas, 'height');
  9083. if (displayWidth !== undefined) {
  9084. canvas.height = displayHeight;
  9085. }
  9086. }
  9087. }
  9088. return canvas;
  9089. }
  9090. /**
  9091. * Detects support for options object argument in addEventListener.
  9092. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  9093. * @private
  9094. */
  9095. var supportsEventListenerOptions = (function() {
  9096. var supports = false;
  9097. try {
  9098. var options = Object.defineProperty({}, 'passive', {
  9099. get: function() {
  9100. supports = true;
  9101. }
  9102. });
  9103. window.addEventListener('e', null, options);
  9104. } catch (e) {
  9105. // continue regardless of error
  9106. }
  9107. return supports;
  9108. }());
  9109. // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  9110. // https://github.com/chartjs/Chart.js/issues/4287
  9111. var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
  9112. function addEventListener(node, type, listener) {
  9113. node.addEventListener(type, listener, eventListenerOptions);
  9114. }
  9115. function removeEventListener(node, type, listener) {
  9116. node.removeEventListener(type, listener, eventListenerOptions);
  9117. }
  9118. function createEvent(type, chart, x, y, nativeEvent) {
  9119. return {
  9120. type: type,
  9121. chart: chart,
  9122. native: nativeEvent || null,
  9123. x: x !== undefined ? x : null,
  9124. y: y !== undefined ? y : null,
  9125. };
  9126. }
  9127. function fromNativeEvent(event, chart) {
  9128. var type = EVENT_TYPES[event.type] || event.type;
  9129. var pos = helpers.getRelativePosition(event, chart);
  9130. return createEvent(type, chart, pos.x, pos.y, event);
  9131. }
  9132. function throttled(fn, thisArg) {
  9133. var ticking = false;
  9134. var args = [];
  9135. return function() {
  9136. args = Array.prototype.slice.call(arguments);
  9137. thisArg = thisArg || this;
  9138. if (!ticking) {
  9139. ticking = true;
  9140. helpers.requestAnimFrame.call(window, function() {
  9141. ticking = false;
  9142. fn.apply(thisArg, args);
  9143. });
  9144. }
  9145. };
  9146. }
  9147. // Implementation based on https://github.com/marcj/css-element-queries
  9148. function createResizer(handler) {
  9149. var resizer = document.createElement('div');
  9150. var cls = CSS_PREFIX + 'size-monitor';
  9151. var maxSize = 1000000;
  9152. var style =
  9153. 'position:absolute;' +
  9154. 'left:0;' +
  9155. 'top:0;' +
  9156. 'right:0;' +
  9157. 'bottom:0;' +
  9158. 'overflow:hidden;' +
  9159. 'pointer-events:none;' +
  9160. 'visibility:hidden;' +
  9161. 'z-index:-1;';
  9162. resizer.style.cssText = style;
  9163. resizer.className = cls;
  9164. resizer.innerHTML =
  9165. '<div class="' + cls + '-expand" style="' + style + '">' +
  9166. '<div style="' +
  9167. 'position:absolute;' +
  9168. 'width:' + maxSize + 'px;' +
  9169. 'height:' + maxSize + 'px;' +
  9170. 'left:0;' +
  9171. 'top:0">' +
  9172. '</div>' +
  9173. '</div>' +
  9174. '<div class="' + cls + '-shrink" style="' + style + '">' +
  9175. '<div style="' +
  9176. 'position:absolute;' +
  9177. 'width:200%;' +
  9178. 'height:200%;' +
  9179. 'left:0; ' +
  9180. 'top:0">' +
  9181. '</div>' +
  9182. '</div>';
  9183. var expand = resizer.childNodes[0];
  9184. var shrink = resizer.childNodes[1];
  9185. resizer._reset = function() {
  9186. expand.scrollLeft = maxSize;
  9187. expand.scrollTop = maxSize;
  9188. shrink.scrollLeft = maxSize;
  9189. shrink.scrollTop = maxSize;
  9190. };
  9191. var onScroll = function() {
  9192. resizer._reset();
  9193. handler();
  9194. };
  9195. addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
  9196. addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
  9197. return resizer;
  9198. }
  9199. // https://davidwalsh.name/detect-node-insertion
  9200. function watchForRender(node, handler) {
  9201. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9202. var proxy = expando.renderProxy = function(e) {
  9203. if (e.animationName === CSS_RENDER_ANIMATION) {
  9204. handler();
  9205. }
  9206. };
  9207. helpers.each(ANIMATION_START_EVENTS, function(type) {
  9208. addEventListener(node, type, proxy);
  9209. });
  9210. // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
  9211. // is removed then added back immediately (same animation frame?). Accessing the
  9212. // `offsetParent` property will force a reflow and re-evaluate the CSS animation.
  9213. // https://gist.github.com/paulirish/5d52fb081b3570c81e3a#box-metrics
  9214. // https://github.com/chartjs/Chart.js/issues/4737
  9215. expando.reflow = !!node.offsetParent;
  9216. node.classList.add(CSS_RENDER_MONITOR);
  9217. }
  9218. function unwatchForRender(node) {
  9219. var expando = node[EXPANDO_KEY] || {};
  9220. var proxy = expando.renderProxy;
  9221. if (proxy) {
  9222. helpers.each(ANIMATION_START_EVENTS, function(type) {
  9223. removeEventListener(node, type, proxy);
  9224. });
  9225. delete expando.renderProxy;
  9226. }
  9227. node.classList.remove(CSS_RENDER_MONITOR);
  9228. }
  9229. function addResizeListener(node, listener, chart) {
  9230. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9231. // Let's keep track of this added resizer and thus avoid DOM query when removing it.
  9232. var resizer = expando.resizer = createResizer(throttled(function() {
  9233. if (expando.resizer) {
  9234. return listener(createEvent('resize', chart));
  9235. }
  9236. }));
  9237. // The resizer needs to be attached to the node parent, so we first need to be
  9238. // sure that `node` is attached to the DOM before injecting the resizer element.
  9239. watchForRender(node, function() {
  9240. if (expando.resizer) {
  9241. var container = node.parentNode;
  9242. if (container && container !== resizer.parentNode) {
  9243. container.insertBefore(resizer, container.firstChild);
  9244. }
  9245. // The container size might have changed, let's reset the resizer state.
  9246. resizer._reset();
  9247. }
  9248. });
  9249. }
  9250. function removeResizeListener(node) {
  9251. var expando = node[EXPANDO_KEY] || {};
  9252. var resizer = expando.resizer;
  9253. delete expando.resizer;
  9254. unwatchForRender(node);
  9255. if (resizer && resizer.parentNode) {
  9256. resizer.parentNode.removeChild(resizer);
  9257. }
  9258. }
  9259. function injectCSS(platform, css) {
  9260. // http://stackoverflow.com/q/3922139
  9261. var style = platform._style || document.createElement('style');
  9262. if (!platform._style) {
  9263. platform._style = style;
  9264. css = '/* Chart.js */\n' + css;
  9265. style.setAttribute('type', 'text/css');
  9266. document.getElementsByTagName('head')[0].appendChild(style);
  9267. }
  9268. style.appendChild(document.createTextNode(css));
  9269. }
  9270. module.exports = {
  9271. /**
  9272. * This property holds whether this platform is enabled for the current environment.
  9273. * Currently used by platform.js to select the proper implementation.
  9274. * @private
  9275. */
  9276. _enabled: typeof window !== 'undefined' && typeof document !== 'undefined',
  9277. initialize: function() {
  9278. var keyframes = 'from{opacity:0.99}to{opacity:1}';
  9279. injectCSS(this,
  9280. // DOM rendering detection
  9281. // https://davidwalsh.name/detect-node-insertion
  9282. '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9283. '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9284. '.' + CSS_RENDER_MONITOR + '{' +
  9285. '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9286. 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9287. '}'
  9288. );
  9289. },
  9290. acquireContext: function(item, config) {
  9291. if (typeof item === 'string') {
  9292. item = document.getElementById(item);
  9293. } else if (item.length) {
  9294. // Support for array based queries (such as jQuery)
  9295. item = item[0];
  9296. }
  9297. if (item && item.canvas) {
  9298. // Support for any object associated to a canvas (including a context2d)
  9299. item = item.canvas;
  9300. }
  9301. // To prevent canvas fingerprinting, some add-ons undefine the getContext
  9302. // method, for example: https://github.com/kkapsner/CanvasBlocker
  9303. // https://github.com/chartjs/Chart.js/issues/2807
  9304. var context = item && item.getContext && item.getContext('2d');
  9305. // `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
  9306. // inside an iframe or when running in a protected environment. We could guess the
  9307. // types from their toString() value but let's keep things flexible and assume it's
  9308. // a sufficient condition if the item has a context2D which has item as `canvas`.
  9309. // https://github.com/chartjs/Chart.js/issues/3887
  9310. // https://github.com/chartjs/Chart.js/issues/4102
  9311. // https://github.com/chartjs/Chart.js/issues/4152
  9312. if (context && context.canvas === item) {
  9313. initCanvas(item, config);
  9314. return context;
  9315. }
  9316. return null;
  9317. },
  9318. releaseContext: function(context) {
  9319. var canvas = context.canvas;
  9320. if (!canvas[EXPANDO_KEY]) {
  9321. return;
  9322. }
  9323. var initial = canvas[EXPANDO_KEY].initial;
  9324. ['height', 'width'].forEach(function(prop) {
  9325. var value = initial[prop];
  9326. if (helpers.isNullOrUndef(value)) {
  9327. canvas.removeAttribute(prop);
  9328. } else {
  9329. canvas.setAttribute(prop, value);
  9330. }
  9331. });
  9332. helpers.each(initial.style || {}, function(value, key) {
  9333. canvas.style[key] = value;
  9334. });
  9335. // The canvas render size might have been changed (and thus the state stack discarded),
  9336. // we can't use save() and restore() to restore the initial state. So make sure that at
  9337. // least the canvas context is reset to the default state by setting the canvas width.
  9338. // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
  9339. canvas.width = canvas.width;
  9340. delete canvas[EXPANDO_KEY];
  9341. },
  9342. addEventListener: function(chart, type, listener) {
  9343. var canvas = chart.canvas;
  9344. if (type === 'resize') {
  9345. // Note: the resize event is not supported on all browsers.
  9346. addResizeListener(canvas, listener, chart);
  9347. return;
  9348. }
  9349. var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
  9350. var proxies = expando.proxies || (expando.proxies = {});
  9351. var proxy = proxies[chart.id + '_' + type] = function(event) {
  9352. listener(fromNativeEvent(event, chart));
  9353. };
  9354. addEventListener(canvas, type, proxy);
  9355. },
  9356. removeEventListener: function(chart, type, listener) {
  9357. var canvas = chart.canvas;
  9358. if (type === 'resize') {
  9359. // Note: the resize event is not supported on all browsers.
  9360. removeResizeListener(canvas, listener);
  9361. return;
  9362. }
  9363. var expando = listener[EXPANDO_KEY] || {};
  9364. var proxies = expando.proxies || {};
  9365. var proxy = proxies[chart.id + '_' + type];
  9366. if (!proxy) {
  9367. return;
  9368. }
  9369. removeEventListener(canvas, type, proxy);
  9370. }
  9371. };
  9372. // DEPRECATIONS
  9373. /**
  9374. * Provided for backward compatibility, use EventTarget.addEventListener instead.
  9375. * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9376. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  9377. * @function Chart.helpers.addEvent
  9378. * @deprecated since version 2.7.0
  9379. * @todo remove at version 3
  9380. * @private
  9381. */
  9382. helpers.addEvent = addEventListener;
  9383. /**
  9384. * Provided for backward compatibility, use EventTarget.removeEventListener instead.
  9385. * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9386. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
  9387. * @function Chart.helpers.removeEvent
  9388. * @deprecated since version 2.7.0
  9389. * @todo remove at version 3
  9390. * @private
  9391. */
  9392. helpers.removeEvent = removeEventListener;
  9393. },{"46":46}],49:[function(require,module,exports){
  9394. 'use strict';
  9395. var helpers = require(46);
  9396. var basic = require(47);
  9397. var dom = require(48);
  9398. // @TODO Make possible to select another platform at build time.
  9399. var implementation = dom._enabled ? dom : basic;
  9400. /**
  9401. * @namespace Chart.platform
  9402. * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
  9403. * @since 2.4.0
  9404. */
  9405. module.exports = helpers.extend({
  9406. /**
  9407. * @since 2.7.0
  9408. */
  9409. initialize: function() {},
  9410. /**
  9411. * Called at chart construction time, returns a context2d instance implementing
  9412. * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
  9413. * @param {*} item - The native item from which to acquire context (platform specific)
  9414. * @param {Object} options - The chart options
  9415. * @returns {CanvasRenderingContext2D} context2d instance
  9416. */
  9417. acquireContext: function() {},
  9418. /**
  9419. * Called at chart destruction time, releases any resources associated to the context
  9420. * previously returned by the acquireContext() method.
  9421. * @param {CanvasRenderingContext2D} context - The context2d instance
  9422. * @returns {Boolean} true if the method succeeded, else false
  9423. */
  9424. releaseContext: function() {},
  9425. /**
  9426. * Registers the specified listener on the given chart.
  9427. * @param {Chart} chart - Chart from which to listen for event
  9428. * @param {String} type - The ({@link IEvent}) type to listen for
  9429. * @param {Function} listener - Receives a notification (an object that implements
  9430. * the {@link IEvent} interface) when an event of the specified type occurs.
  9431. */
  9432. addEventListener: function() {},
  9433. /**
  9434. * Removes the specified listener previously registered with addEventListener.
  9435. * @param {Chart} chart -Chart from which to remove the listener
  9436. * @param {String} type - The ({@link IEvent}) type to remove
  9437. * @param {Function} listener - The listener function to remove from the event target.
  9438. */
  9439. removeEventListener: function() {}
  9440. }, implementation);
  9441. /**
  9442. * @interface IPlatform
  9443. * Allows abstracting platform dependencies away from the chart
  9444. * @borrows Chart.platform.acquireContext as acquireContext
  9445. * @borrows Chart.platform.releaseContext as releaseContext
  9446. * @borrows Chart.platform.addEventListener as addEventListener
  9447. * @borrows Chart.platform.removeEventListener as removeEventListener
  9448. */
  9449. /**
  9450. * @interface IEvent
  9451. * @prop {String} type - The event type name, possible values are:
  9452. * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
  9453. * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
  9454. * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
  9455. * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
  9456. * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
  9457. */
  9458. },{"46":46,"47":47,"48":48}],50:[function(require,module,exports){
  9459. 'use strict';
  9460. module.exports = {};
  9461. module.exports.filler = require(51);
  9462. module.exports.legend = require(52);
  9463. module.exports.title = require(53);
  9464. },{"51":51,"52":52,"53":53}],51:[function(require,module,exports){
  9465. /**
  9466. * Plugin based on discussion from the following Chart.js issues:
  9467. * @see https://github.com/chartjs/Chart.js/issues/2380#issuecomment-279961569
  9468. * @see https://github.com/chartjs/Chart.js/issues/2440#issuecomment-256461897
  9469. */
  9470. 'use strict';
  9471. var defaults = require(26);
  9472. var elements = require(41);
  9473. var helpers = require(46);
  9474. defaults._set('global', {
  9475. plugins: {
  9476. filler: {
  9477. propagate: true
  9478. }
  9479. }
  9480. });
  9481. var mappers = {
  9482. dataset: function(source) {
  9483. var index = source.fill;
  9484. var chart = source.chart;
  9485. var meta = chart.getDatasetMeta(index);
  9486. var visible = meta && chart.isDatasetVisible(index);
  9487. var points = (visible && meta.dataset._children) || [];
  9488. var length = points.length || 0;
  9489. return !length ? null : function(point, i) {
  9490. return (i < length && points[i]._view) || null;
  9491. };
  9492. },
  9493. boundary: function(source) {
  9494. var boundary = source.boundary;
  9495. var x = boundary ? boundary.x : null;
  9496. var y = boundary ? boundary.y : null;
  9497. return function(point) {
  9498. return {
  9499. x: x === null ? point.x : x,
  9500. y: y === null ? point.y : y,
  9501. };
  9502. };
  9503. }
  9504. };
  9505. // @todo if (fill[0] === '#')
  9506. function decodeFill(el, index, count) {
  9507. var model = el._model || {};
  9508. var fill = model.fill;
  9509. var target;
  9510. if (fill === undefined) {
  9511. fill = !!model.backgroundColor;
  9512. }
  9513. if (fill === false || fill === null) {
  9514. return false;
  9515. }
  9516. if (fill === true) {
  9517. return 'origin';
  9518. }
  9519. target = parseFloat(fill, 10);
  9520. if (isFinite(target) && Math.floor(target) === target) {
  9521. if (fill[0] === '-' || fill[0] === '+') {
  9522. target = index + target;
  9523. }
  9524. if (target === index || target < 0 || target >= count) {
  9525. return false;
  9526. }
  9527. return target;
  9528. }
  9529. switch (fill) {
  9530. // compatibility
  9531. case 'bottom':
  9532. return 'start';
  9533. case 'top':
  9534. return 'end';
  9535. case 'zero':
  9536. return 'origin';
  9537. // supported boundaries
  9538. case 'origin':
  9539. case 'start':
  9540. case 'end':
  9541. return fill;
  9542. // invalid fill values
  9543. default:
  9544. return false;
  9545. }
  9546. }
  9547. function computeBoundary(source) {
  9548. var model = source.el._model || {};
  9549. var scale = source.el._scale || {};
  9550. var fill = source.fill;
  9551. var target = null;
  9552. var horizontal;
  9553. if (isFinite(fill)) {
  9554. return null;
  9555. }
  9556. // Backward compatibility: until v3, we still need to support boundary values set on
  9557. // the model (scaleTop, scaleBottom and scaleZero) because some external plugins and
  9558. // controllers might still use it (e.g. the Smith chart).
  9559. if (fill === 'start') {
  9560. target = model.scaleBottom === undefined ? scale.bottom : model.scaleBottom;
  9561. } else if (fill === 'end') {
  9562. target = model.scaleTop === undefined ? scale.top : model.scaleTop;
  9563. } else if (model.scaleZero !== undefined) {
  9564. target = model.scaleZero;
  9565. } else if (scale.getBasePosition) {
  9566. target = scale.getBasePosition();
  9567. } else if (scale.getBasePixel) {
  9568. target = scale.getBasePixel();
  9569. }
  9570. if (target !== undefined && target !== null) {
  9571. if (target.x !== undefined && target.y !== undefined) {
  9572. return target;
  9573. }
  9574. if (typeof target === 'number' && isFinite(target)) {
  9575. horizontal = scale.isHorizontal();
  9576. return {
  9577. x: horizontal ? target : null,
  9578. y: horizontal ? null : target
  9579. };
  9580. }
  9581. }
  9582. return null;
  9583. }
  9584. function resolveTarget(sources, index, propagate) {
  9585. var source = sources[index];
  9586. var fill = source.fill;
  9587. var visited = [index];
  9588. var target;
  9589. if (!propagate) {
  9590. return fill;
  9591. }
  9592. while (fill !== false && visited.indexOf(fill) === -1) {
  9593. if (!isFinite(fill)) {
  9594. return fill;
  9595. }
  9596. target = sources[fill];
  9597. if (!target) {
  9598. return false;
  9599. }
  9600. if (target.visible) {
  9601. return fill;
  9602. }
  9603. visited.push(fill);
  9604. fill = target.fill;
  9605. }
  9606. return false;
  9607. }
  9608. function createMapper(source) {
  9609. var fill = source.fill;
  9610. var type = 'dataset';
  9611. if (fill === false) {
  9612. return null;
  9613. }
  9614. if (!isFinite(fill)) {
  9615. type = 'boundary';
  9616. }
  9617. return mappers[type](source);
  9618. }
  9619. function isDrawable(point) {
  9620. return point && !point.skip;
  9621. }
  9622. function drawArea(ctx, curve0, curve1, len0, len1) {
  9623. var i;
  9624. if (!len0 || !len1) {
  9625. return;
  9626. }
  9627. // building first area curve (normal)
  9628. ctx.moveTo(curve0[0].x, curve0[0].y);
  9629. for (i = 1; i < len0; ++i) {
  9630. helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
  9631. }
  9632. // joining the two area curves
  9633. ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
  9634. // building opposite area curve (reverse)
  9635. for (i = len1 - 1; i > 0; --i) {
  9636. helpers.canvas.lineTo(ctx, curve1[i], curve1[i - 1], true);
  9637. }
  9638. }
  9639. function doFill(ctx, points, mapper, view, color, loop) {
  9640. var count = points.length;
  9641. var span = view.spanGaps;
  9642. var curve0 = [];
  9643. var curve1 = [];
  9644. var len0 = 0;
  9645. var len1 = 0;
  9646. var i, ilen, index, p0, p1, d0, d1;
  9647. ctx.beginPath();
  9648. for (i = 0, ilen = (count + !!loop); i < ilen; ++i) {
  9649. index = i % count;
  9650. p0 = points[index]._view;
  9651. p1 = mapper(p0, index, view);
  9652. d0 = isDrawable(p0);
  9653. d1 = isDrawable(p1);
  9654. if (d0 && d1) {
  9655. len0 = curve0.push(p0);
  9656. len1 = curve1.push(p1);
  9657. } else if (len0 && len1) {
  9658. if (!span) {
  9659. drawArea(ctx, curve0, curve1, len0, len1);
  9660. len0 = len1 = 0;
  9661. curve0 = [];
  9662. curve1 = [];
  9663. } else {
  9664. if (d0) {
  9665. curve0.push(p0);
  9666. }
  9667. if (d1) {
  9668. curve1.push(p1);
  9669. }
  9670. }
  9671. }
  9672. }
  9673. drawArea(ctx, curve0, curve1, len0, len1);
  9674. ctx.closePath();
  9675. ctx.fillStyle = color;
  9676. ctx.fill();
  9677. }
  9678. module.exports = {
  9679. id: 'filler',
  9680. afterDatasetsUpdate: function(chart, options) {
  9681. var count = (chart.data.datasets || []).length;
  9682. var propagate = options.propagate;
  9683. var sources = [];
  9684. var meta, i, el, source;
  9685. for (i = 0; i < count; ++i) {
  9686. meta = chart.getDatasetMeta(i);
  9687. el = meta.dataset;
  9688. source = null;
  9689. if (el && el._model && el instanceof elements.Line) {
  9690. source = {
  9691. visible: chart.isDatasetVisible(i),
  9692. fill: decodeFill(el, i, count),
  9693. chart: chart,
  9694. el: el
  9695. };
  9696. }
  9697. meta.$filler = source;
  9698. sources.push(source);
  9699. }
  9700. for (i = 0; i < count; ++i) {
  9701. source = sources[i];
  9702. if (!source) {
  9703. continue;
  9704. }
  9705. source.fill = resolveTarget(sources, i, propagate);
  9706. source.boundary = computeBoundary(source);
  9707. source.mapper = createMapper(source);
  9708. }
  9709. },
  9710. beforeDatasetDraw: function(chart, args) {
  9711. var meta = args.meta.$filler;
  9712. if (!meta) {
  9713. return;
  9714. }
  9715. var ctx = chart.ctx;
  9716. var el = meta.el;
  9717. var view = el._view;
  9718. var points = el._children || [];
  9719. var mapper = meta.mapper;
  9720. var color = view.backgroundColor || defaults.global.defaultColor;
  9721. if (mapper && color && points.length) {
  9722. helpers.canvas.clipArea(ctx, chart.chartArea);
  9723. doFill(ctx, points, mapper, view, color, el._loop);
  9724. helpers.canvas.unclipArea(ctx);
  9725. }
  9726. }
  9727. };
  9728. },{"26":26,"41":41,"46":46}],52:[function(require,module,exports){
  9729. 'use strict';
  9730. var defaults = require(26);
  9731. var Element = require(27);
  9732. var helpers = require(46);
  9733. var layouts = require(31);
  9734. var noop = helpers.noop;
  9735. defaults._set('global', {
  9736. legend: {
  9737. display: true,
  9738. position: 'top',
  9739. fullWidth: true,
  9740. reverse: false,
  9741. weight: 1000,
  9742. // a callback that will handle
  9743. onClick: function(e, legendItem) {
  9744. var index = legendItem.datasetIndex;
  9745. var ci = this.chart;
  9746. var meta = ci.getDatasetMeta(index);
  9747. // See controller.isDatasetVisible comment
  9748. meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
  9749. // We hid a dataset ... rerender the chart
  9750. ci.update();
  9751. },
  9752. onHover: null,
  9753. labels: {
  9754. boxWidth: 40,
  9755. padding: 10,
  9756. // Generates labels shown in the legend
  9757. // Valid properties to return:
  9758. // text : text to display
  9759. // fillStyle : fill of coloured box
  9760. // strokeStyle: stroke of coloured box
  9761. // hidden : if this legend item refers to a hidden item
  9762. // lineCap : cap style for line
  9763. // lineDash
  9764. // lineDashOffset :
  9765. // lineJoin :
  9766. // lineWidth :
  9767. generateLabels: function(chart) {
  9768. var data = chart.data;
  9769. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  9770. return {
  9771. text: dataset.label,
  9772. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  9773. hidden: !chart.isDatasetVisible(i),
  9774. lineCap: dataset.borderCapStyle,
  9775. lineDash: dataset.borderDash,
  9776. lineDashOffset: dataset.borderDashOffset,
  9777. lineJoin: dataset.borderJoinStyle,
  9778. lineWidth: dataset.borderWidth,
  9779. strokeStyle: dataset.borderColor,
  9780. pointStyle: dataset.pointStyle,
  9781. // Below is extra data used for toggling the datasets
  9782. datasetIndex: i
  9783. };
  9784. }, this) : [];
  9785. }
  9786. }
  9787. },
  9788. legendCallback: function(chart) {
  9789. var text = [];
  9790. text.push('<ul class="' + chart.id + '-legend">');
  9791. for (var i = 0; i < chart.data.datasets.length; i++) {
  9792. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  9793. if (chart.data.datasets[i].label) {
  9794. text.push(chart.data.datasets[i].label);
  9795. }
  9796. text.push('</li>');
  9797. }
  9798. text.push('</ul>');
  9799. return text.join('');
  9800. }
  9801. });
  9802. /**
  9803. * Helper function to get the box width based on the usePointStyle option
  9804. * @param labelopts {Object} the label options on the legend
  9805. * @param fontSize {Number} the label font size
  9806. * @return {Number} width of the color box area
  9807. */
  9808. function getBoxWidth(labelOpts, fontSize) {
  9809. return labelOpts.usePointStyle ?
  9810. fontSize * Math.SQRT2 :
  9811. labelOpts.boxWidth;
  9812. }
  9813. /**
  9814. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  9815. */
  9816. var Legend = Element.extend({
  9817. initialize: function(config) {
  9818. helpers.extend(this, config);
  9819. // Contains hit boxes for each dataset (in dataset order)
  9820. this.legendHitBoxes = [];
  9821. // Are we in doughnut mode which has a different data type
  9822. this.doughnutMode = false;
  9823. },
  9824. // These methods are ordered by lifecycle. Utilities then follow.
  9825. // Any function defined here is inherited by all legend types.
  9826. // Any function can be extended by the legend type
  9827. beforeUpdate: noop,
  9828. update: function(maxWidth, maxHeight, margins) {
  9829. var me = this;
  9830. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  9831. me.beforeUpdate();
  9832. // Absorb the master measurements
  9833. me.maxWidth = maxWidth;
  9834. me.maxHeight = maxHeight;
  9835. me.margins = margins;
  9836. // Dimensions
  9837. me.beforeSetDimensions();
  9838. me.setDimensions();
  9839. me.afterSetDimensions();
  9840. // Labels
  9841. me.beforeBuildLabels();
  9842. me.buildLabels();
  9843. me.afterBuildLabels();
  9844. // Fit
  9845. me.beforeFit();
  9846. me.fit();
  9847. me.afterFit();
  9848. //
  9849. me.afterUpdate();
  9850. return me.minSize;
  9851. },
  9852. afterUpdate: noop,
  9853. //
  9854. beforeSetDimensions: noop,
  9855. setDimensions: function() {
  9856. var me = this;
  9857. // Set the unconstrained dimension before label rotation
  9858. if (me.isHorizontal()) {
  9859. // Reset position before calculating rotation
  9860. me.width = me.maxWidth;
  9861. me.left = 0;
  9862. me.right = me.width;
  9863. } else {
  9864. me.height = me.maxHeight;
  9865. // Reset position before calculating rotation
  9866. me.top = 0;
  9867. me.bottom = me.height;
  9868. }
  9869. // Reset padding
  9870. me.paddingLeft = 0;
  9871. me.paddingTop = 0;
  9872. me.paddingRight = 0;
  9873. me.paddingBottom = 0;
  9874. // Reset minSize
  9875. me.minSize = {
  9876. width: 0,
  9877. height: 0
  9878. };
  9879. },
  9880. afterSetDimensions: noop,
  9881. //
  9882. beforeBuildLabels: noop,
  9883. buildLabels: function() {
  9884. var me = this;
  9885. var labelOpts = me.options.labels || {};
  9886. var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];
  9887. if (labelOpts.filter) {
  9888. legendItems = legendItems.filter(function(item) {
  9889. return labelOpts.filter(item, me.chart.data);
  9890. });
  9891. }
  9892. if (me.options.reverse) {
  9893. legendItems.reverse();
  9894. }
  9895. me.legendItems = legendItems;
  9896. },
  9897. afterBuildLabels: noop,
  9898. //
  9899. beforeFit: noop,
  9900. fit: function() {
  9901. var me = this;
  9902. var opts = me.options;
  9903. var labelOpts = opts.labels;
  9904. var display = opts.display;
  9905. var ctx = me.ctx;
  9906. var globalDefault = defaults.global;
  9907. var valueOrDefault = helpers.valueOrDefault;
  9908. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  9909. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  9910. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  9911. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  9912. // Reset hit boxes
  9913. var hitboxes = me.legendHitBoxes = [];
  9914. var minSize = me.minSize;
  9915. var isHorizontal = me.isHorizontal();
  9916. if (isHorizontal) {
  9917. minSize.width = me.maxWidth; // fill all the width
  9918. minSize.height = display ? 10 : 0;
  9919. } else {
  9920. minSize.width = display ? 10 : 0;
  9921. minSize.height = me.maxHeight; // fill all the height
  9922. }
  9923. // Increase sizes here
  9924. if (display) {
  9925. ctx.font = labelFont;
  9926. if (isHorizontal) {
  9927. // Labels
  9928. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  9929. var lineWidths = me.lineWidths = [0];
  9930. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  9931. ctx.textAlign = 'left';
  9932. ctx.textBaseline = 'top';
  9933. helpers.each(me.legendItems, function(legendItem, i) {
  9934. var boxWidth = getBoxWidth(labelOpts, fontSize);
  9935. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  9936. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  9937. totalHeight += fontSize + (labelOpts.padding);
  9938. lineWidths[lineWidths.length] = me.left;
  9939. }
  9940. // Store the hitbox width and height here. Final position will be updated in `draw`
  9941. hitboxes[i] = {
  9942. left: 0,
  9943. top: 0,
  9944. width: width,
  9945. height: fontSize
  9946. };
  9947. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  9948. });
  9949. minSize.height += totalHeight;
  9950. } else {
  9951. var vPadding = labelOpts.padding;
  9952. var columnWidths = me.columnWidths = [];
  9953. var totalWidth = labelOpts.padding;
  9954. var currentColWidth = 0;
  9955. var currentColHeight = 0;
  9956. var itemHeight = fontSize + vPadding;
  9957. helpers.each(me.legendItems, function(legendItem, i) {
  9958. var boxWidth = getBoxWidth(labelOpts, fontSize);
  9959. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  9960. // If too tall, go to new column
  9961. if (currentColHeight + itemHeight > minSize.height) {
  9962. totalWidth += currentColWidth + labelOpts.padding;
  9963. columnWidths.push(currentColWidth); // previous column width
  9964. currentColWidth = 0;
  9965. currentColHeight = 0;
  9966. }
  9967. // Get max width
  9968. currentColWidth = Math.max(currentColWidth, itemWidth);
  9969. currentColHeight += itemHeight;
  9970. // Store the hitbox width and height here. Final position will be updated in `draw`
  9971. hitboxes[i] = {
  9972. left: 0,
  9973. top: 0,
  9974. width: itemWidth,
  9975. height: fontSize
  9976. };
  9977. });
  9978. totalWidth += currentColWidth;
  9979. columnWidths.push(currentColWidth);
  9980. minSize.width += totalWidth;
  9981. }
  9982. }
  9983. me.width = minSize.width;
  9984. me.height = minSize.height;
  9985. },
  9986. afterFit: noop,
  9987. // Shared Methods
  9988. isHorizontal: function() {
  9989. return this.options.position === 'top' || this.options.position === 'bottom';
  9990. },
  9991. // Actually draw the legend on the canvas
  9992. draw: function() {
  9993. var me = this;
  9994. var opts = me.options;
  9995. var labelOpts = opts.labels;
  9996. var globalDefault = defaults.global;
  9997. var lineDefault = globalDefault.elements.line;
  9998. var legendWidth = me.width;
  9999. var lineWidths = me.lineWidths;
  10000. if (opts.display) {
  10001. var ctx = me.ctx;
  10002. var valueOrDefault = helpers.valueOrDefault;
  10003. var fontColor = valueOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor);
  10004. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  10005. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  10006. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  10007. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10008. var cursor;
  10009. // Canvas setup
  10010. ctx.textAlign = 'left';
  10011. ctx.textBaseline = 'middle';
  10012. ctx.lineWidth = 0.5;
  10013. ctx.strokeStyle = fontColor; // for strikethrough effect
  10014. ctx.fillStyle = fontColor; // render in correct colour
  10015. ctx.font = labelFont;
  10016. var boxWidth = getBoxWidth(labelOpts, fontSize);
  10017. var hitboxes = me.legendHitBoxes;
  10018. // current position
  10019. var drawLegendBox = function(x, y, legendItem) {
  10020. if (isNaN(boxWidth) || boxWidth <= 0) {
  10021. return;
  10022. }
  10023. // Set the ctx for the box
  10024. ctx.save();
  10025. ctx.fillStyle = valueOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  10026. ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  10027. ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  10028. ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  10029. ctx.lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  10030. ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  10031. var isLineWidthZero = (valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  10032. if (ctx.setLineDash) {
  10033. // IE 9 and 10 do not support line dash
  10034. ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
  10035. }
  10036. if (opts.labels && opts.labels.usePointStyle) {
  10037. // Recalculate x and y for drawPoint() because its expecting
  10038. // x and y to be center of figure (instead of top left)
  10039. var radius = fontSize * Math.SQRT2 / 2;
  10040. var offSet = radius / Math.SQRT2;
  10041. var centerX = x + offSet;
  10042. var centerY = y + offSet;
  10043. // Draw pointStyle as legend symbol
  10044. helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  10045. } else {
  10046. // Draw box as legend symbol
  10047. if (!isLineWidthZero) {
  10048. ctx.strokeRect(x, y, boxWidth, fontSize);
  10049. }
  10050. ctx.fillRect(x, y, boxWidth, fontSize);
  10051. }
  10052. ctx.restore();
  10053. };
  10054. var fillText = function(x, y, legendItem, textWidth) {
  10055. var halfFontSize = fontSize / 2;
  10056. var xLeft = boxWidth + halfFontSize + x;
  10057. var yMiddle = y + halfFontSize;
  10058. ctx.fillText(legendItem.text, xLeft, yMiddle);
  10059. if (legendItem.hidden) {
  10060. // Strikethrough the text if hidden
  10061. ctx.beginPath();
  10062. ctx.lineWidth = 2;
  10063. ctx.moveTo(xLeft, yMiddle);
  10064. ctx.lineTo(xLeft + textWidth, yMiddle);
  10065. ctx.stroke();
  10066. }
  10067. };
  10068. // Horizontal
  10069. var isHorizontal = me.isHorizontal();
  10070. if (isHorizontal) {
  10071. cursor = {
  10072. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  10073. y: me.top + labelOpts.padding,
  10074. line: 0
  10075. };
  10076. } else {
  10077. cursor = {
  10078. x: me.left + labelOpts.padding,
  10079. y: me.top + labelOpts.padding,
  10080. line: 0
  10081. };
  10082. }
  10083. var itemHeight = fontSize + labelOpts.padding;
  10084. helpers.each(me.legendItems, function(legendItem, i) {
  10085. var textWidth = ctx.measureText(legendItem.text).width;
  10086. var width = boxWidth + (fontSize / 2) + textWidth;
  10087. var x = cursor.x;
  10088. var y = cursor.y;
  10089. if (isHorizontal) {
  10090. if (x + width >= legendWidth) {
  10091. y = cursor.y += itemHeight;
  10092. cursor.line++;
  10093. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  10094. }
  10095. } else if (y + itemHeight > me.bottom) {
  10096. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  10097. y = cursor.y = me.top + labelOpts.padding;
  10098. cursor.line++;
  10099. }
  10100. drawLegendBox(x, y, legendItem);
  10101. hitboxes[i].left = x;
  10102. hitboxes[i].top = y;
  10103. // Fill the actual label
  10104. fillText(x, y, legendItem, textWidth);
  10105. if (isHorizontal) {
  10106. cursor.x += width + (labelOpts.padding);
  10107. } else {
  10108. cursor.y += itemHeight;
  10109. }
  10110. });
  10111. }
  10112. },
  10113. /**
  10114. * Handle an event
  10115. * @private
  10116. * @param {IEvent} event - The event to handle
  10117. * @return {Boolean} true if a change occured
  10118. */
  10119. handleEvent: function(e) {
  10120. var me = this;
  10121. var opts = me.options;
  10122. var type = e.type === 'mouseup' ? 'click' : e.type;
  10123. var changed = false;
  10124. if (type === 'mousemove') {
  10125. if (!opts.onHover) {
  10126. return;
  10127. }
  10128. } else if (type === 'click') {
  10129. if (!opts.onClick) {
  10130. return;
  10131. }
  10132. } else {
  10133. return;
  10134. }
  10135. // Chart event already has relative position in it
  10136. var x = e.x;
  10137. var y = e.y;
  10138. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  10139. // See if we are touching one of the dataset boxes
  10140. var lh = me.legendHitBoxes;
  10141. for (var i = 0; i < lh.length; ++i) {
  10142. var hitBox = lh[i];
  10143. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  10144. // Touching an element
  10145. if (type === 'click') {
  10146. // use e.native for backwards compatibility
  10147. opts.onClick.call(me, e.native, me.legendItems[i]);
  10148. changed = true;
  10149. break;
  10150. } else if (type === 'mousemove') {
  10151. // use e.native for backwards compatibility
  10152. opts.onHover.call(me, e.native, me.legendItems[i]);
  10153. changed = true;
  10154. break;
  10155. }
  10156. }
  10157. }
  10158. }
  10159. return changed;
  10160. }
  10161. });
  10162. function createNewLegendAndAttach(chart, legendOpts) {
  10163. var legend = new Legend({
  10164. ctx: chart.ctx,
  10165. options: legendOpts,
  10166. chart: chart
  10167. });
  10168. layouts.configure(chart, legend, legendOpts);
  10169. layouts.addBox(chart, legend);
  10170. chart.legend = legend;
  10171. }
  10172. module.exports = {
  10173. id: 'legend',
  10174. /**
  10175. * Backward compatibility: since 2.1.5, the legend is registered as a plugin, making
  10176. * Chart.Legend obsolete. To avoid a breaking change, we export the Legend as part of
  10177. * the plugin, which one will be re-exposed in the chart.js file.
  10178. * https://github.com/chartjs/Chart.js/pull/2640
  10179. * @private
  10180. */
  10181. _element: Legend,
  10182. beforeInit: function(chart) {
  10183. var legendOpts = chart.options.legend;
  10184. if (legendOpts) {
  10185. createNewLegendAndAttach(chart, legendOpts);
  10186. }
  10187. },
  10188. beforeUpdate: function(chart) {
  10189. var legendOpts = chart.options.legend;
  10190. var legend = chart.legend;
  10191. if (legendOpts) {
  10192. helpers.mergeIf(legendOpts, defaults.global.legend);
  10193. if (legend) {
  10194. layouts.configure(chart, legend, legendOpts);
  10195. legend.options = legendOpts;
  10196. } else {
  10197. createNewLegendAndAttach(chart, legendOpts);
  10198. }
  10199. } else if (legend) {
  10200. layouts.removeBox(chart, legend);
  10201. delete chart.legend;
  10202. }
  10203. },
  10204. afterEvent: function(chart, e) {
  10205. var legend = chart.legend;
  10206. if (legend) {
  10207. legend.handleEvent(e);
  10208. }
  10209. }
  10210. };
  10211. },{"26":26,"27":27,"31":31,"46":46}],53:[function(require,module,exports){
  10212. 'use strict';
  10213. var defaults = require(26);
  10214. var Element = require(27);
  10215. var helpers = require(46);
  10216. var layouts = require(31);
  10217. var noop = helpers.noop;
  10218. defaults._set('global', {
  10219. title: {
  10220. display: false,
  10221. fontStyle: 'bold',
  10222. fullWidth: true,
  10223. lineHeight: 1.2,
  10224. padding: 10,
  10225. position: 'top',
  10226. text: '',
  10227. weight: 2000 // by default greater than legend (1000) to be above
  10228. }
  10229. });
  10230. /**
  10231. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  10232. */
  10233. var Title = Element.extend({
  10234. initialize: function(config) {
  10235. var me = this;
  10236. helpers.extend(me, config);
  10237. // Contains hit boxes for each dataset (in dataset order)
  10238. me.legendHitBoxes = [];
  10239. },
  10240. // These methods are ordered by lifecycle. Utilities then follow.
  10241. beforeUpdate: noop,
  10242. update: function(maxWidth, maxHeight, margins) {
  10243. var me = this;
  10244. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  10245. me.beforeUpdate();
  10246. // Absorb the master measurements
  10247. me.maxWidth = maxWidth;
  10248. me.maxHeight = maxHeight;
  10249. me.margins = margins;
  10250. // Dimensions
  10251. me.beforeSetDimensions();
  10252. me.setDimensions();
  10253. me.afterSetDimensions();
  10254. // Labels
  10255. me.beforeBuildLabels();
  10256. me.buildLabels();
  10257. me.afterBuildLabels();
  10258. // Fit
  10259. me.beforeFit();
  10260. me.fit();
  10261. me.afterFit();
  10262. //
  10263. me.afterUpdate();
  10264. return me.minSize;
  10265. },
  10266. afterUpdate: noop,
  10267. //
  10268. beforeSetDimensions: noop,
  10269. setDimensions: function() {
  10270. var me = this;
  10271. // Set the unconstrained dimension before label rotation
  10272. if (me.isHorizontal()) {
  10273. // Reset position before calculating rotation
  10274. me.width = me.maxWidth;
  10275. me.left = 0;
  10276. me.right = me.width;
  10277. } else {
  10278. me.height = me.maxHeight;
  10279. // Reset position before calculating rotation
  10280. me.top = 0;
  10281. me.bottom = me.height;
  10282. }
  10283. // Reset padding
  10284. me.paddingLeft = 0;
  10285. me.paddingTop = 0;
  10286. me.paddingRight = 0;
  10287. me.paddingBottom = 0;
  10288. // Reset minSize
  10289. me.minSize = {
  10290. width: 0,
  10291. height: 0
  10292. };
  10293. },
  10294. afterSetDimensions: noop,
  10295. //
  10296. beforeBuildLabels: noop,
  10297. buildLabels: noop,
  10298. afterBuildLabels: noop,
  10299. //
  10300. beforeFit: noop,
  10301. fit: function() {
  10302. var me = this;
  10303. var valueOrDefault = helpers.valueOrDefault;
  10304. var opts = me.options;
  10305. var display = opts.display;
  10306. var fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize);
  10307. var minSize = me.minSize;
  10308. var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
  10309. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10310. var textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
  10311. if (me.isHorizontal()) {
  10312. minSize.width = me.maxWidth; // fill all the width
  10313. minSize.height = textSize;
  10314. } else {
  10315. minSize.width = textSize;
  10316. minSize.height = me.maxHeight; // fill all the height
  10317. }
  10318. me.width = minSize.width;
  10319. me.height = minSize.height;
  10320. },
  10321. afterFit: noop,
  10322. // Shared Methods
  10323. isHorizontal: function() {
  10324. var pos = this.options.position;
  10325. return pos === 'top' || pos === 'bottom';
  10326. },
  10327. // Actually draw the title block on the canvas
  10328. draw: function() {
  10329. var me = this;
  10330. var ctx = me.ctx;
  10331. var valueOrDefault = helpers.valueOrDefault;
  10332. var opts = me.options;
  10333. var globalDefaults = defaults.global;
  10334. if (opts.display) {
  10335. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize);
  10336. var fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle);
  10337. var fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily);
  10338. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10339. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10340. var offset = lineHeight / 2 + opts.padding;
  10341. var rotation = 0;
  10342. var top = me.top;
  10343. var left = me.left;
  10344. var bottom = me.bottom;
  10345. var right = me.right;
  10346. var maxWidth, titleX, titleY;
  10347. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  10348. ctx.font = titleFont;
  10349. // Horizontal
  10350. if (me.isHorizontal()) {
  10351. titleX = left + ((right - left) / 2); // midpoint of the width
  10352. titleY = top + offset;
  10353. maxWidth = right - left;
  10354. } else {
  10355. titleX = opts.position === 'left' ? left + offset : right - offset;
  10356. titleY = top + ((bottom - top) / 2);
  10357. maxWidth = bottom - top;
  10358. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  10359. }
  10360. ctx.save();
  10361. ctx.translate(titleX, titleY);
  10362. ctx.rotate(rotation);
  10363. ctx.textAlign = 'center';
  10364. ctx.textBaseline = 'middle';
  10365. var text = opts.text;
  10366. if (helpers.isArray(text)) {
  10367. var y = 0;
  10368. for (var i = 0; i < text.length; ++i) {
  10369. ctx.fillText(text[i], 0, y, maxWidth);
  10370. y += lineHeight;
  10371. }
  10372. } else {
  10373. ctx.fillText(text, 0, 0, maxWidth);
  10374. }
  10375. ctx.restore();
  10376. }
  10377. }
  10378. });
  10379. function createNewTitleBlockAndAttach(chart, titleOpts) {
  10380. var title = new Title({
  10381. ctx: chart.ctx,
  10382. options: titleOpts,
  10383. chart: chart
  10384. });
  10385. layouts.configure(chart, title, titleOpts);
  10386. layouts.addBox(chart, title);
  10387. chart.titleBlock = title;
  10388. }
  10389. module.exports = {
  10390. id: 'title',
  10391. /**
  10392. * Backward compatibility: since 2.1.5, the title is registered as a plugin, making
  10393. * Chart.Title obsolete. To avoid a breaking change, we export the Title as part of
  10394. * the plugin, which one will be re-exposed in the chart.js file.
  10395. * https://github.com/chartjs/Chart.js/pull/2640
  10396. * @private
  10397. */
  10398. _element: Title,
  10399. beforeInit: function(chart) {
  10400. var titleOpts = chart.options.title;
  10401. if (titleOpts) {
  10402. createNewTitleBlockAndAttach(chart, titleOpts);
  10403. }
  10404. },
  10405. beforeUpdate: function(chart) {
  10406. var titleOpts = chart.options.title;
  10407. var titleBlock = chart.titleBlock;
  10408. if (titleOpts) {
  10409. helpers.mergeIf(titleOpts, defaults.global.title);
  10410. if (titleBlock) {
  10411. layouts.configure(chart, titleBlock, titleOpts);
  10412. titleBlock.options = titleOpts;
  10413. } else {
  10414. createNewTitleBlockAndAttach(chart, titleOpts);
  10415. }
  10416. } else if (titleBlock) {
  10417. layouts.removeBox(chart, titleBlock);
  10418. delete chart.titleBlock;
  10419. }
  10420. }
  10421. };
  10422. },{"26":26,"27":27,"31":31,"46":46}],54:[function(require,module,exports){
  10423. 'use strict';
  10424. var Scale = require(33);
  10425. var scaleService = require(34);
  10426. module.exports = function() {
  10427. // Default config for a category scale
  10428. var defaultConfig = {
  10429. position: 'bottom'
  10430. };
  10431. var DatasetScale = Scale.extend({
  10432. /**
  10433. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
  10434. * else fall back to data.labels
  10435. * @private
  10436. */
  10437. getLabels: function() {
  10438. var data = this.chart.data;
  10439. return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  10440. },
  10441. determineDataLimits: function() {
  10442. var me = this;
  10443. var labels = me.getLabels();
  10444. me.minIndex = 0;
  10445. me.maxIndex = labels.length - 1;
  10446. var findIndex;
  10447. if (me.options.ticks.min !== undefined) {
  10448. // user specified min value
  10449. findIndex = labels.indexOf(me.options.ticks.min);
  10450. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  10451. }
  10452. if (me.options.ticks.max !== undefined) {
  10453. // user specified max value
  10454. findIndex = labels.indexOf(me.options.ticks.max);
  10455. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  10456. }
  10457. me.min = labels[me.minIndex];
  10458. me.max = labels[me.maxIndex];
  10459. },
  10460. buildTicks: function() {
  10461. var me = this;
  10462. var labels = me.getLabels();
  10463. // If we are viewing some subset of labels, slice the original array
  10464. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  10465. },
  10466. getLabelForIndex: function(index, datasetIndex) {
  10467. var me = this;
  10468. var data = me.chart.data;
  10469. var isHorizontal = me.isHorizontal();
  10470. if (data.yLabels && !isHorizontal) {
  10471. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  10472. }
  10473. return me.ticks[index - me.minIndex];
  10474. },
  10475. // Used to get data value locations. Value can either be an index or a numerical value
  10476. getPixelForValue: function(value, index) {
  10477. var me = this;
  10478. var offset = me.options.offset;
  10479. // 1 is added because we need the length but we have the indexes
  10480. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1)), 1);
  10481. // If value is a data object, then index is the index in the data array,
  10482. // not the index of the scale. We need to change that.
  10483. var valueCategory;
  10484. if (value !== undefined && value !== null) {
  10485. valueCategory = me.isHorizontal() ? value.x : value.y;
  10486. }
  10487. if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
  10488. var labels = me.getLabels();
  10489. value = valueCategory || value;
  10490. var idx = labels.indexOf(value);
  10491. index = idx !== -1 ? idx : index;
  10492. }
  10493. if (me.isHorizontal()) {
  10494. var valueWidth = me.width / offsetAmt;
  10495. var widthOffset = (valueWidth * (index - me.minIndex));
  10496. if (offset) {
  10497. widthOffset += (valueWidth / 2);
  10498. }
  10499. return me.left + Math.round(widthOffset);
  10500. }
  10501. var valueHeight = me.height / offsetAmt;
  10502. var heightOffset = (valueHeight * (index - me.minIndex));
  10503. if (offset) {
  10504. heightOffset += (valueHeight / 2);
  10505. }
  10506. return me.top + Math.round(heightOffset);
  10507. },
  10508. getPixelForTick: function(index) {
  10509. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null);
  10510. },
  10511. getValueForPixel: function(pixel) {
  10512. var me = this;
  10513. var offset = me.options.offset;
  10514. var value;
  10515. var offsetAmt = Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  10516. var horz = me.isHorizontal();
  10517. var valueDimension = (horz ? me.width : me.height) / offsetAmt;
  10518. pixel -= horz ? me.left : me.top;
  10519. if (offset) {
  10520. pixel -= (valueDimension / 2);
  10521. }
  10522. if (pixel <= 0) {
  10523. value = 0;
  10524. } else {
  10525. value = Math.round(pixel / valueDimension);
  10526. }
  10527. return value + me.minIndex;
  10528. },
  10529. getBasePixel: function() {
  10530. return this.bottom;
  10531. }
  10532. });
  10533. scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  10534. };
  10535. },{"33":33,"34":34}],55:[function(require,module,exports){
  10536. 'use strict';
  10537. var defaults = require(26);
  10538. var helpers = require(46);
  10539. var scaleService = require(34);
  10540. var Ticks = require(35);
  10541. module.exports = function(Chart) {
  10542. var defaultConfig = {
  10543. position: 'left',
  10544. ticks: {
  10545. callback: Ticks.formatters.linear
  10546. }
  10547. };
  10548. var LinearScale = Chart.LinearScaleBase.extend({
  10549. determineDataLimits: function() {
  10550. var me = this;
  10551. var opts = me.options;
  10552. var chart = me.chart;
  10553. var data = chart.data;
  10554. var datasets = data.datasets;
  10555. var isHorizontal = me.isHorizontal();
  10556. var DEFAULT_MIN = 0;
  10557. var DEFAULT_MAX = 1;
  10558. function IDMatches(meta) {
  10559. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10560. }
  10561. // First Calculate the range
  10562. me.min = null;
  10563. me.max = null;
  10564. var hasStacks = opts.stacked;
  10565. if (hasStacks === undefined) {
  10566. helpers.each(datasets, function(dataset, datasetIndex) {
  10567. if (hasStacks) {
  10568. return;
  10569. }
  10570. var meta = chart.getDatasetMeta(datasetIndex);
  10571. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10572. meta.stack !== undefined) {
  10573. hasStacks = true;
  10574. }
  10575. });
  10576. }
  10577. if (opts.stacked || hasStacks) {
  10578. var valuesPerStack = {};
  10579. helpers.each(datasets, function(dataset, datasetIndex) {
  10580. var meta = chart.getDatasetMeta(datasetIndex);
  10581. var key = [
  10582. meta.type,
  10583. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10584. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10585. meta.stack
  10586. ].join('.');
  10587. if (valuesPerStack[key] === undefined) {
  10588. valuesPerStack[key] = {
  10589. positiveValues: [],
  10590. negativeValues: []
  10591. };
  10592. }
  10593. // Store these per type
  10594. var positiveValues = valuesPerStack[key].positiveValues;
  10595. var negativeValues = valuesPerStack[key].negativeValues;
  10596. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10597. helpers.each(dataset.data, function(rawValue, index) {
  10598. var value = +me.getRightValue(rawValue);
  10599. if (isNaN(value) || meta.data[index].hidden) {
  10600. return;
  10601. }
  10602. positiveValues[index] = positiveValues[index] || 0;
  10603. negativeValues[index] = negativeValues[index] || 0;
  10604. if (opts.relativePoints) {
  10605. positiveValues[index] = 100;
  10606. } else if (value < 0) {
  10607. negativeValues[index] += value;
  10608. } else {
  10609. positiveValues[index] += value;
  10610. }
  10611. });
  10612. }
  10613. });
  10614. helpers.each(valuesPerStack, function(valuesForType) {
  10615. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  10616. var minVal = helpers.min(values);
  10617. var maxVal = helpers.max(values);
  10618. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  10619. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  10620. });
  10621. } else {
  10622. helpers.each(datasets, function(dataset, datasetIndex) {
  10623. var meta = chart.getDatasetMeta(datasetIndex);
  10624. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10625. helpers.each(dataset.data, function(rawValue, index) {
  10626. var value = +me.getRightValue(rawValue);
  10627. if (isNaN(value) || meta.data[index].hidden) {
  10628. return;
  10629. }
  10630. if (me.min === null) {
  10631. me.min = value;
  10632. } else if (value < me.min) {
  10633. me.min = value;
  10634. }
  10635. if (me.max === null) {
  10636. me.max = value;
  10637. } else if (value > me.max) {
  10638. me.max = value;
  10639. }
  10640. });
  10641. }
  10642. });
  10643. }
  10644. me.min = isFinite(me.min) && !isNaN(me.min) ? me.min : DEFAULT_MIN;
  10645. me.max = isFinite(me.max) && !isNaN(me.max) ? me.max : DEFAULT_MAX;
  10646. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  10647. this.handleTickRangeOptions();
  10648. },
  10649. getTickLimit: function() {
  10650. var maxTicks;
  10651. var me = this;
  10652. var tickOpts = me.options.ticks;
  10653. if (me.isHorizontal()) {
  10654. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  10655. } else {
  10656. // The factor of 2 used to scale the font size has been experimentally determined.
  10657. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
  10658. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  10659. }
  10660. return maxTicks;
  10661. },
  10662. // Called after the ticks are built. We need
  10663. handleDirectionalChanges: function() {
  10664. if (!this.isHorizontal()) {
  10665. // We are in a vertical orientation. The top value is the highest. So reverse the array
  10666. this.ticks.reverse();
  10667. }
  10668. },
  10669. getLabelForIndex: function(index, datasetIndex) {
  10670. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  10671. },
  10672. // Utils
  10673. getPixelForValue: function(value) {
  10674. // This must be called after fit has been run so that
  10675. // this.left, this.top, this.right, and this.bottom have been defined
  10676. var me = this;
  10677. var start = me.start;
  10678. var rightValue = +me.getRightValue(value);
  10679. var pixel;
  10680. var range = me.end - start;
  10681. if (me.isHorizontal()) {
  10682. pixel = me.left + (me.width / range * (rightValue - start));
  10683. } else {
  10684. pixel = me.bottom - (me.height / range * (rightValue - start));
  10685. }
  10686. return pixel;
  10687. },
  10688. getValueForPixel: function(pixel) {
  10689. var me = this;
  10690. var isHorizontal = me.isHorizontal();
  10691. var innerDimension = isHorizontal ? me.width : me.height;
  10692. var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
  10693. return me.start + ((me.end - me.start) * offset);
  10694. },
  10695. getPixelForTick: function(index) {
  10696. return this.getPixelForValue(this.ticksAsNumbers[index]);
  10697. }
  10698. });
  10699. scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  10700. };
  10701. },{"26":26,"34":34,"35":35,"46":46}],56:[function(require,module,exports){
  10702. 'use strict';
  10703. var helpers = require(46);
  10704. var Scale = require(33);
  10705. /**
  10706. * Generate a set of linear ticks
  10707. * @param generationOptions the options used to generate the ticks
  10708. * @param dataRange the range of the data
  10709. * @returns {Array<Number>} array of tick values
  10710. */
  10711. function generateTicks(generationOptions, dataRange) {
  10712. var ticks = [];
  10713. // To get a "nice" value for the tick spacing, we will use the appropriately named
  10714. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  10715. // for details.
  10716. var factor;
  10717. var precision;
  10718. var spacing;
  10719. if (generationOptions.stepSize && generationOptions.stepSize > 0) {
  10720. spacing = generationOptions.stepSize;
  10721. } else {
  10722. var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
  10723. spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
  10724. precision = generationOptions.precision;
  10725. if (precision !== undefined) {
  10726. // If the user specified a precision, round to that number of decimal places
  10727. factor = Math.pow(10, precision);
  10728. spacing = Math.ceil(spacing * factor) / factor;
  10729. }
  10730. }
  10731. var niceMin = Math.floor(dataRange.min / spacing) * spacing;
  10732. var niceMax = Math.ceil(dataRange.max / spacing) * spacing;
  10733. // If min, max and stepSize is set and they make an evenly spaced scale use it.
  10734. if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && generationOptions.stepSize) {
  10735. // If very close to our whole number, use it.
  10736. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
  10737. niceMin = generationOptions.min;
  10738. niceMax = generationOptions.max;
  10739. }
  10740. }
  10741. var numSpaces = (niceMax - niceMin) / spacing;
  10742. // If very close to our rounded value, use it.
  10743. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  10744. numSpaces = Math.round(numSpaces);
  10745. } else {
  10746. numSpaces = Math.ceil(numSpaces);
  10747. }
  10748. precision = 1;
  10749. if (spacing < 1) {
  10750. precision = Math.pow(10, 1 - Math.floor(helpers.log10(spacing)));
  10751. niceMin = Math.round(niceMin * precision) / precision;
  10752. niceMax = Math.round(niceMax * precision) / precision;
  10753. }
  10754. ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
  10755. for (var j = 1; j < numSpaces; ++j) {
  10756. ticks.push(Math.round((niceMin + j * spacing) * precision) / precision);
  10757. }
  10758. ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);
  10759. return ticks;
  10760. }
  10761. module.exports = function(Chart) {
  10762. var noop = helpers.noop;
  10763. Chart.LinearScaleBase = Scale.extend({
  10764. getRightValue: function(value) {
  10765. if (typeof value === 'string') {
  10766. return +value;
  10767. }
  10768. return Scale.prototype.getRightValue.call(this, value);
  10769. },
  10770. handleTickRangeOptions: function() {
  10771. var me = this;
  10772. var opts = me.options;
  10773. var tickOpts = opts.ticks;
  10774. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  10775. // do nothing since that would make the chart weird. If the user really wants a weird chart
  10776. // axis, they can manually override it
  10777. if (tickOpts.beginAtZero) {
  10778. var minSign = helpers.sign(me.min);
  10779. var maxSign = helpers.sign(me.max);
  10780. if (minSign < 0 && maxSign < 0) {
  10781. // move the top up to 0
  10782. me.max = 0;
  10783. } else if (minSign > 0 && maxSign > 0) {
  10784. // move the bottom down to 0
  10785. me.min = 0;
  10786. }
  10787. }
  10788. var setMin = tickOpts.min !== undefined || tickOpts.suggestedMin !== undefined;
  10789. var setMax = tickOpts.max !== undefined || tickOpts.suggestedMax !== undefined;
  10790. if (tickOpts.min !== undefined) {
  10791. me.min = tickOpts.min;
  10792. } else if (tickOpts.suggestedMin !== undefined) {
  10793. if (me.min === null) {
  10794. me.min = tickOpts.suggestedMin;
  10795. } else {
  10796. me.min = Math.min(me.min, tickOpts.suggestedMin);
  10797. }
  10798. }
  10799. if (tickOpts.max !== undefined) {
  10800. me.max = tickOpts.max;
  10801. } else if (tickOpts.suggestedMax !== undefined) {
  10802. if (me.max === null) {
  10803. me.max = tickOpts.suggestedMax;
  10804. } else {
  10805. me.max = Math.max(me.max, tickOpts.suggestedMax);
  10806. }
  10807. }
  10808. if (setMin !== setMax) {
  10809. // We set the min or the max but not both.
  10810. // So ensure that our range is good
  10811. // Inverted or 0 length range can happen when
  10812. // ticks.min is set, and no datasets are visible
  10813. if (me.min >= me.max) {
  10814. if (setMin) {
  10815. me.max = me.min + 1;
  10816. } else {
  10817. me.min = me.max - 1;
  10818. }
  10819. }
  10820. }
  10821. if (me.min === me.max) {
  10822. me.max++;
  10823. if (!tickOpts.beginAtZero) {
  10824. me.min--;
  10825. }
  10826. }
  10827. },
  10828. getTickLimit: noop,
  10829. handleDirectionalChanges: noop,
  10830. buildTicks: function() {
  10831. var me = this;
  10832. var opts = me.options;
  10833. var tickOpts = opts.ticks;
  10834. // Figure out what the max number of ticks we can support it is based on the size of
  10835. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  10836. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  10837. // the graph. Make sure we always have at least 2 ticks
  10838. var maxTicks = me.getTickLimit();
  10839. maxTicks = Math.max(2, maxTicks);
  10840. var numericGeneratorOptions = {
  10841. maxTicks: maxTicks,
  10842. min: tickOpts.min,
  10843. max: tickOpts.max,
  10844. precision: tickOpts.precision,
  10845. stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
  10846. };
  10847. var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
  10848. me.handleDirectionalChanges();
  10849. // At this point, we need to update our max and min given the tick values since we have expanded the
  10850. // range of the scale
  10851. me.max = helpers.max(ticks);
  10852. me.min = helpers.min(ticks);
  10853. if (tickOpts.reverse) {
  10854. ticks.reverse();
  10855. me.start = me.max;
  10856. me.end = me.min;
  10857. } else {
  10858. me.start = me.min;
  10859. me.end = me.max;
  10860. }
  10861. },
  10862. convertTicksToLabels: function() {
  10863. var me = this;
  10864. me.ticksAsNumbers = me.ticks.slice();
  10865. me.zeroLineIndex = me.ticks.indexOf(0);
  10866. Scale.prototype.convertTicksToLabels.call(me);
  10867. }
  10868. });
  10869. };
  10870. },{"33":33,"46":46}],57:[function(require,module,exports){
  10871. 'use strict';
  10872. var helpers = require(46);
  10873. var Scale = require(33);
  10874. var scaleService = require(34);
  10875. var Ticks = require(35);
  10876. /**
  10877. * Generate a set of logarithmic ticks
  10878. * @param generationOptions the options used to generate the ticks
  10879. * @param dataRange the range of the data
  10880. * @returns {Array<Number>} array of tick values
  10881. */
  10882. function generateTicks(generationOptions, dataRange) {
  10883. var ticks = [];
  10884. var valueOrDefault = helpers.valueOrDefault;
  10885. // Figure out what the max number of ticks we can support it is based on the size of
  10886. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  10887. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  10888. // the graph
  10889. var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
  10890. var endExp = Math.floor(helpers.log10(dataRange.max));
  10891. var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
  10892. var exp, significand;
  10893. if (tickVal === 0) {
  10894. exp = Math.floor(helpers.log10(dataRange.minNotZero));
  10895. significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
  10896. ticks.push(tickVal);
  10897. tickVal = significand * Math.pow(10, exp);
  10898. } else {
  10899. exp = Math.floor(helpers.log10(tickVal));
  10900. significand = Math.floor(tickVal / Math.pow(10, exp));
  10901. }
  10902. var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
  10903. do {
  10904. ticks.push(tickVal);
  10905. ++significand;
  10906. if (significand === 10) {
  10907. significand = 1;
  10908. ++exp;
  10909. precision = exp >= 0 ? 1 : precision;
  10910. }
  10911. tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
  10912. } while (exp < endExp || (exp === endExp && significand < endSignificand));
  10913. var lastTick = valueOrDefault(generationOptions.max, tickVal);
  10914. ticks.push(lastTick);
  10915. return ticks;
  10916. }
  10917. module.exports = function(Chart) {
  10918. var defaultConfig = {
  10919. position: 'left',
  10920. // label settings
  10921. ticks: {
  10922. callback: Ticks.formatters.logarithmic
  10923. }
  10924. };
  10925. var LogarithmicScale = Scale.extend({
  10926. determineDataLimits: function() {
  10927. var me = this;
  10928. var opts = me.options;
  10929. var chart = me.chart;
  10930. var data = chart.data;
  10931. var datasets = data.datasets;
  10932. var isHorizontal = me.isHorizontal();
  10933. function IDMatches(meta) {
  10934. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10935. }
  10936. // Calculate Range
  10937. me.min = null;
  10938. me.max = null;
  10939. me.minNotZero = null;
  10940. var hasStacks = opts.stacked;
  10941. if (hasStacks === undefined) {
  10942. helpers.each(datasets, function(dataset, datasetIndex) {
  10943. if (hasStacks) {
  10944. return;
  10945. }
  10946. var meta = chart.getDatasetMeta(datasetIndex);
  10947. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10948. meta.stack !== undefined) {
  10949. hasStacks = true;
  10950. }
  10951. });
  10952. }
  10953. if (opts.stacked || hasStacks) {
  10954. var valuesPerStack = {};
  10955. helpers.each(datasets, function(dataset, datasetIndex) {
  10956. var meta = chart.getDatasetMeta(datasetIndex);
  10957. var key = [
  10958. meta.type,
  10959. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10960. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10961. meta.stack
  10962. ].join('.');
  10963. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10964. if (valuesPerStack[key] === undefined) {
  10965. valuesPerStack[key] = [];
  10966. }
  10967. helpers.each(dataset.data, function(rawValue, index) {
  10968. var values = valuesPerStack[key];
  10969. var value = +me.getRightValue(rawValue);
  10970. // invalid, hidden and negative values are ignored
  10971. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  10972. return;
  10973. }
  10974. values[index] = values[index] || 0;
  10975. values[index] += value;
  10976. });
  10977. }
  10978. });
  10979. helpers.each(valuesPerStack, function(valuesForType) {
  10980. if (valuesForType.length > 0) {
  10981. var minVal = helpers.min(valuesForType);
  10982. var maxVal = helpers.max(valuesForType);
  10983. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  10984. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  10985. }
  10986. });
  10987. } else {
  10988. helpers.each(datasets, function(dataset, datasetIndex) {
  10989. var meta = chart.getDatasetMeta(datasetIndex);
  10990. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10991. helpers.each(dataset.data, function(rawValue, index) {
  10992. var value = +me.getRightValue(rawValue);
  10993. // invalid, hidden and negative values are ignored
  10994. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  10995. return;
  10996. }
  10997. if (me.min === null) {
  10998. me.min = value;
  10999. } else if (value < me.min) {
  11000. me.min = value;
  11001. }
  11002. if (me.max === null) {
  11003. me.max = value;
  11004. } else if (value > me.max) {
  11005. me.max = value;
  11006. }
  11007. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  11008. me.minNotZero = value;
  11009. }
  11010. });
  11011. }
  11012. });
  11013. }
  11014. // Common base implementation to handle ticks.min, ticks.max
  11015. this.handleTickRangeOptions();
  11016. },
  11017. handleTickRangeOptions: function() {
  11018. var me = this;
  11019. var opts = me.options;
  11020. var tickOpts = opts.ticks;
  11021. var valueOrDefault = helpers.valueOrDefault;
  11022. var DEFAULT_MIN = 1;
  11023. var DEFAULT_MAX = 10;
  11024. me.min = valueOrDefault(tickOpts.min, me.min);
  11025. me.max = valueOrDefault(tickOpts.max, me.max);
  11026. if (me.min === me.max) {
  11027. if (me.min !== 0 && me.min !== null) {
  11028. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  11029. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  11030. } else {
  11031. me.min = DEFAULT_MIN;
  11032. me.max = DEFAULT_MAX;
  11033. }
  11034. }
  11035. if (me.min === null) {
  11036. me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
  11037. }
  11038. if (me.max === null) {
  11039. me.max = me.min !== 0
  11040. ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
  11041. : DEFAULT_MAX;
  11042. }
  11043. if (me.minNotZero === null) {
  11044. if (me.min > 0) {
  11045. me.minNotZero = me.min;
  11046. } else if (me.max < 1) {
  11047. me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
  11048. } else {
  11049. me.minNotZero = DEFAULT_MIN;
  11050. }
  11051. }
  11052. },
  11053. buildTicks: function() {
  11054. var me = this;
  11055. var opts = me.options;
  11056. var tickOpts = opts.ticks;
  11057. var reverse = !me.isHorizontal();
  11058. var generationOptions = {
  11059. min: tickOpts.min,
  11060. max: tickOpts.max
  11061. };
  11062. var ticks = me.ticks = generateTicks(generationOptions, me);
  11063. // At this point, we need to update our max and min given the tick values since we have expanded the
  11064. // range of the scale
  11065. me.max = helpers.max(ticks);
  11066. me.min = helpers.min(ticks);
  11067. if (tickOpts.reverse) {
  11068. reverse = !reverse;
  11069. me.start = me.max;
  11070. me.end = me.min;
  11071. } else {
  11072. me.start = me.min;
  11073. me.end = me.max;
  11074. }
  11075. if (reverse) {
  11076. ticks.reverse();
  11077. }
  11078. },
  11079. convertTicksToLabels: function() {
  11080. this.tickValues = this.ticks.slice();
  11081. Scale.prototype.convertTicksToLabels.call(this);
  11082. },
  11083. // Get the correct tooltip label
  11084. getLabelForIndex: function(index, datasetIndex) {
  11085. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11086. },
  11087. getPixelForTick: function(index) {
  11088. return this.getPixelForValue(this.tickValues[index]);
  11089. },
  11090. /**
  11091. * Returns the value of the first tick.
  11092. * @param {Number} value - The minimum not zero value.
  11093. * @return {Number} The first tick value.
  11094. * @private
  11095. */
  11096. _getFirstTickValue: function(value) {
  11097. var exp = Math.floor(helpers.log10(value));
  11098. var significand = Math.floor(value / Math.pow(10, exp));
  11099. return significand * Math.pow(10, exp);
  11100. },
  11101. getPixelForValue: function(value) {
  11102. var me = this;
  11103. var reverse = me.options.ticks.reverse;
  11104. var log10 = helpers.log10;
  11105. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11106. var offset = 0;
  11107. var innerDimension, pixel, start, end, sign;
  11108. value = +me.getRightValue(value);
  11109. if (reverse) {
  11110. start = me.end;
  11111. end = me.start;
  11112. sign = -1;
  11113. } else {
  11114. start = me.start;
  11115. end = me.end;
  11116. sign = 1;
  11117. }
  11118. if (me.isHorizontal()) {
  11119. innerDimension = me.width;
  11120. pixel = reverse ? me.right : me.left;
  11121. } else {
  11122. innerDimension = me.height;
  11123. sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
  11124. pixel = reverse ? me.top : me.bottom;
  11125. }
  11126. if (value !== start) {
  11127. if (start === 0) { // include zero tick
  11128. offset = helpers.getValueOrDefault(
  11129. me.options.ticks.fontSize,
  11130. Chart.defaults.global.defaultFontSize
  11131. );
  11132. innerDimension -= offset;
  11133. start = firstTickValue;
  11134. }
  11135. if (value !== 0) {
  11136. offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
  11137. }
  11138. pixel += sign * offset;
  11139. }
  11140. return pixel;
  11141. },
  11142. getValueForPixel: function(pixel) {
  11143. var me = this;
  11144. var reverse = me.options.ticks.reverse;
  11145. var log10 = helpers.log10;
  11146. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11147. var innerDimension, start, end, value;
  11148. if (reverse) {
  11149. start = me.end;
  11150. end = me.start;
  11151. } else {
  11152. start = me.start;
  11153. end = me.end;
  11154. }
  11155. if (me.isHorizontal()) {
  11156. innerDimension = me.width;
  11157. value = reverse ? me.right - pixel : pixel - me.left;
  11158. } else {
  11159. innerDimension = me.height;
  11160. value = reverse ? pixel - me.top : me.bottom - pixel;
  11161. }
  11162. if (value !== start) {
  11163. if (start === 0) { // include zero tick
  11164. var offset = helpers.getValueOrDefault(
  11165. me.options.ticks.fontSize,
  11166. Chart.defaults.global.defaultFontSize
  11167. );
  11168. value -= offset;
  11169. innerDimension -= offset;
  11170. start = firstTickValue;
  11171. }
  11172. value *= log10(end) - log10(start);
  11173. value /= innerDimension;
  11174. value = Math.pow(10, log10(start) + value);
  11175. }
  11176. return value;
  11177. }
  11178. });
  11179. scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  11180. };
  11181. },{"33":33,"34":34,"35":35,"46":46}],58:[function(require,module,exports){
  11182. 'use strict';
  11183. var defaults = require(26);
  11184. var helpers = require(46);
  11185. var scaleService = require(34);
  11186. var Ticks = require(35);
  11187. module.exports = function(Chart) {
  11188. var globalDefaults = defaults.global;
  11189. var defaultConfig = {
  11190. display: true,
  11191. // Boolean - Whether to animate scaling the chart from the centre
  11192. animate: true,
  11193. position: 'chartArea',
  11194. angleLines: {
  11195. display: true,
  11196. color: 'rgba(0, 0, 0, 0.1)',
  11197. lineWidth: 1
  11198. },
  11199. gridLines: {
  11200. circular: false
  11201. },
  11202. // label settings
  11203. ticks: {
  11204. // Boolean - Show a backdrop to the scale label
  11205. showLabelBackdrop: true,
  11206. // String - The colour of the label backdrop
  11207. backdropColor: 'rgba(255,255,255,0.75)',
  11208. // Number - The backdrop padding above & below the label in pixels
  11209. backdropPaddingY: 2,
  11210. // Number - The backdrop padding to the side of the label in pixels
  11211. backdropPaddingX: 2,
  11212. callback: Ticks.formatters.linear
  11213. },
  11214. pointLabels: {
  11215. // Boolean - if true, show point labels
  11216. display: true,
  11217. // Number - Point label font size in pixels
  11218. fontSize: 10,
  11219. // Function - Used to convert point labels
  11220. callback: function(label) {
  11221. return label;
  11222. }
  11223. }
  11224. };
  11225. function getValueCount(scale) {
  11226. var opts = scale.options;
  11227. return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
  11228. }
  11229. function getPointLabelFontOptions(scale) {
  11230. var pointLabelOptions = scale.options.pointLabels;
  11231. var fontSize = helpers.valueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
  11232. var fontStyle = helpers.valueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
  11233. var fontFamily = helpers.valueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
  11234. var font = helpers.fontString(fontSize, fontStyle, fontFamily);
  11235. return {
  11236. size: fontSize,
  11237. style: fontStyle,
  11238. family: fontFamily,
  11239. font: font
  11240. };
  11241. }
  11242. function measureLabelSize(ctx, fontSize, label) {
  11243. if (helpers.isArray(label)) {
  11244. return {
  11245. w: helpers.longestText(ctx, ctx.font, label),
  11246. h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
  11247. };
  11248. }
  11249. return {
  11250. w: ctx.measureText(label).width,
  11251. h: fontSize
  11252. };
  11253. }
  11254. function determineLimits(angle, pos, size, min, max) {
  11255. if (angle === min || angle === max) {
  11256. return {
  11257. start: pos - (size / 2),
  11258. end: pos + (size / 2)
  11259. };
  11260. } else if (angle < min || angle > max) {
  11261. return {
  11262. start: pos - size - 5,
  11263. end: pos
  11264. };
  11265. }
  11266. return {
  11267. start: pos,
  11268. end: pos + size + 5
  11269. };
  11270. }
  11271. /**
  11272. * Helper function to fit a radial linear scale with point labels
  11273. */
  11274. function fitWithPointLabels(scale) {
  11275. /*
  11276. * Right, this is really confusing and there is a lot of maths going on here
  11277. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  11278. *
  11279. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  11280. *
  11281. * Solution:
  11282. *
  11283. * We assume the radius of the polygon is half the size of the canvas at first
  11284. * at each index we check if the text overlaps.
  11285. *
  11286. * Where it does, we store that angle and that index.
  11287. *
  11288. * After finding the largest index and angle we calculate how much we need to remove
  11289. * from the shape radius to move the point inwards by that x.
  11290. *
  11291. * We average the left and right distances to get the maximum shape radius that can fit in the box
  11292. * along with labels.
  11293. *
  11294. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  11295. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  11296. *
  11297. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  11298. * and position it in the most space efficient manner
  11299. *
  11300. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  11301. */
  11302. var plFont = getPointLabelFontOptions(scale);
  11303. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  11304. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  11305. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11306. var furthestLimits = {
  11307. r: scale.width,
  11308. l: 0,
  11309. t: scale.height,
  11310. b: 0
  11311. };
  11312. var furthestAngles = {};
  11313. var i, textSize, pointPosition;
  11314. scale.ctx.font = plFont.font;
  11315. scale._pointLabelSizes = [];
  11316. var valueCount = getValueCount(scale);
  11317. for (i = 0; i < valueCount; i++) {
  11318. pointPosition = scale.getPointPosition(i, largestPossibleRadius);
  11319. textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
  11320. scale._pointLabelSizes[i] = textSize;
  11321. // Add quarter circle to make degree 0 mean top of circle
  11322. var angleRadians = scale.getIndexAngle(i);
  11323. var angle = helpers.toDegrees(angleRadians) % 360;
  11324. var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
  11325. var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
  11326. if (hLimits.start < furthestLimits.l) {
  11327. furthestLimits.l = hLimits.start;
  11328. furthestAngles.l = angleRadians;
  11329. }
  11330. if (hLimits.end > furthestLimits.r) {
  11331. furthestLimits.r = hLimits.end;
  11332. furthestAngles.r = angleRadians;
  11333. }
  11334. if (vLimits.start < furthestLimits.t) {
  11335. furthestLimits.t = vLimits.start;
  11336. furthestAngles.t = angleRadians;
  11337. }
  11338. if (vLimits.end > furthestLimits.b) {
  11339. furthestLimits.b = vLimits.end;
  11340. furthestAngles.b = angleRadians;
  11341. }
  11342. }
  11343. scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
  11344. }
  11345. /**
  11346. * Helper function to fit a radial linear scale with no point labels
  11347. */
  11348. function fit(scale) {
  11349. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11350. scale.drawingArea = Math.round(largestPossibleRadius);
  11351. scale.setCenterPoint(0, 0, 0, 0);
  11352. }
  11353. function getTextAlignForAngle(angle) {
  11354. if (angle === 0 || angle === 180) {
  11355. return 'center';
  11356. } else if (angle < 180) {
  11357. return 'left';
  11358. }
  11359. return 'right';
  11360. }
  11361. function fillText(ctx, text, position, fontSize) {
  11362. if (helpers.isArray(text)) {
  11363. var y = position.y;
  11364. var spacing = 1.5 * fontSize;
  11365. for (var i = 0; i < text.length; ++i) {
  11366. ctx.fillText(text[i], position.x, y);
  11367. y += spacing;
  11368. }
  11369. } else {
  11370. ctx.fillText(text, position.x, position.y);
  11371. }
  11372. }
  11373. function adjustPointPositionForLabelHeight(angle, textSize, position) {
  11374. if (angle === 90 || angle === 270) {
  11375. position.y -= (textSize.h / 2);
  11376. } else if (angle > 270 || angle < 90) {
  11377. position.y -= textSize.h;
  11378. }
  11379. }
  11380. function drawPointLabels(scale) {
  11381. var ctx = scale.ctx;
  11382. var opts = scale.options;
  11383. var angleLineOpts = opts.angleLines;
  11384. var pointLabelOpts = opts.pointLabels;
  11385. ctx.lineWidth = angleLineOpts.lineWidth;
  11386. ctx.strokeStyle = angleLineOpts.color;
  11387. var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
  11388. // Point Label Font
  11389. var plFont = getPointLabelFontOptions(scale);
  11390. ctx.textBaseline = 'top';
  11391. for (var i = getValueCount(scale) - 1; i >= 0; i--) {
  11392. if (angleLineOpts.display) {
  11393. var outerPosition = scale.getPointPosition(i, outerDistance);
  11394. ctx.beginPath();
  11395. ctx.moveTo(scale.xCenter, scale.yCenter);
  11396. ctx.lineTo(outerPosition.x, outerPosition.y);
  11397. ctx.stroke();
  11398. ctx.closePath();
  11399. }
  11400. if (pointLabelOpts.display) {
  11401. // Extra 3px out for some label spacing
  11402. var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
  11403. // Keep this in loop since we may support array properties here
  11404. var pointLabelFontColor = helpers.valueAtIndexOrDefault(pointLabelOpts.fontColor, i, globalDefaults.defaultFontColor);
  11405. ctx.font = plFont.font;
  11406. ctx.fillStyle = pointLabelFontColor;
  11407. var angleRadians = scale.getIndexAngle(i);
  11408. var angle = helpers.toDegrees(angleRadians);
  11409. ctx.textAlign = getTextAlignForAngle(angle);
  11410. adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
  11411. fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
  11412. }
  11413. }
  11414. }
  11415. function drawRadiusLine(scale, gridLineOpts, radius, index) {
  11416. var ctx = scale.ctx;
  11417. ctx.strokeStyle = helpers.valueAtIndexOrDefault(gridLineOpts.color, index - 1);
  11418. ctx.lineWidth = helpers.valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  11419. if (scale.options.gridLines.circular) {
  11420. // Draw circular arcs between the points
  11421. ctx.beginPath();
  11422. ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
  11423. ctx.closePath();
  11424. ctx.stroke();
  11425. } else {
  11426. // Draw straight lines connecting each index
  11427. var valueCount = getValueCount(scale);
  11428. if (valueCount === 0) {
  11429. return;
  11430. }
  11431. ctx.beginPath();
  11432. var pointPosition = scale.getPointPosition(0, radius);
  11433. ctx.moveTo(pointPosition.x, pointPosition.y);
  11434. for (var i = 1; i < valueCount; i++) {
  11435. pointPosition = scale.getPointPosition(i, radius);
  11436. ctx.lineTo(pointPosition.x, pointPosition.y);
  11437. }
  11438. ctx.closePath();
  11439. ctx.stroke();
  11440. }
  11441. }
  11442. function numberOrZero(param) {
  11443. return helpers.isNumber(param) ? param : 0;
  11444. }
  11445. var LinearRadialScale = Chart.LinearScaleBase.extend({
  11446. setDimensions: function() {
  11447. var me = this;
  11448. var opts = me.options;
  11449. var tickOpts = opts.ticks;
  11450. // Set the unconstrained dimension before label rotation
  11451. me.width = me.maxWidth;
  11452. me.height = me.maxHeight;
  11453. me.xCenter = Math.round(me.width / 2);
  11454. me.yCenter = Math.round(me.height / 2);
  11455. var minSize = helpers.min([me.height, me.width]);
  11456. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11457. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  11458. },
  11459. determineDataLimits: function() {
  11460. var me = this;
  11461. var chart = me.chart;
  11462. var min = Number.POSITIVE_INFINITY;
  11463. var max = Number.NEGATIVE_INFINITY;
  11464. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  11465. if (chart.isDatasetVisible(datasetIndex)) {
  11466. var meta = chart.getDatasetMeta(datasetIndex);
  11467. helpers.each(dataset.data, function(rawValue, index) {
  11468. var value = +me.getRightValue(rawValue);
  11469. if (isNaN(value) || meta.data[index].hidden) {
  11470. return;
  11471. }
  11472. min = Math.min(value, min);
  11473. max = Math.max(value, max);
  11474. });
  11475. }
  11476. });
  11477. me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
  11478. me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
  11479. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  11480. me.handleTickRangeOptions();
  11481. },
  11482. getTickLimit: function() {
  11483. var tickOpts = this.options.ticks;
  11484. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11485. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  11486. },
  11487. convertTicksToLabels: function() {
  11488. var me = this;
  11489. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  11490. // Point labels
  11491. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  11492. },
  11493. getLabelForIndex: function(index, datasetIndex) {
  11494. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11495. },
  11496. fit: function() {
  11497. if (this.options.pointLabels.display) {
  11498. fitWithPointLabels(this);
  11499. } else {
  11500. fit(this);
  11501. }
  11502. },
  11503. /**
  11504. * Set radius reductions and determine new radius and center point
  11505. * @private
  11506. */
  11507. setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
  11508. var me = this;
  11509. var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
  11510. var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
  11511. var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
  11512. var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
  11513. radiusReductionLeft = numberOrZero(radiusReductionLeft);
  11514. radiusReductionRight = numberOrZero(radiusReductionRight);
  11515. radiusReductionTop = numberOrZero(radiusReductionTop);
  11516. radiusReductionBottom = numberOrZero(radiusReductionBottom);
  11517. me.drawingArea = Math.min(
  11518. Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
  11519. Math.round(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
  11520. me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
  11521. },
  11522. setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
  11523. var me = this;
  11524. var maxRight = me.width - rightMovement - me.drawingArea;
  11525. var maxLeft = leftMovement + me.drawingArea;
  11526. var maxTop = topMovement + me.drawingArea;
  11527. var maxBottom = me.height - bottomMovement - me.drawingArea;
  11528. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  11529. me.yCenter = Math.round(((maxTop + maxBottom) / 2) + me.top);
  11530. },
  11531. getIndexAngle: function(index) {
  11532. var angleMultiplier = (Math.PI * 2) / getValueCount(this);
  11533. var startAngle = this.chart.options && this.chart.options.startAngle ?
  11534. this.chart.options.startAngle :
  11535. 0;
  11536. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  11537. // Start from the top instead of right, so remove a quarter of the circle
  11538. return index * angleMultiplier + startAngleRadians;
  11539. },
  11540. getDistanceFromCenterForValue: function(value) {
  11541. var me = this;
  11542. if (value === null) {
  11543. return 0; // null always in center
  11544. }
  11545. // Take into account half font size + the yPadding of the top value
  11546. var scalingFactor = me.drawingArea / (me.max - me.min);
  11547. if (me.options.ticks.reverse) {
  11548. return (me.max - value) * scalingFactor;
  11549. }
  11550. return (value - me.min) * scalingFactor;
  11551. },
  11552. getPointPosition: function(index, distanceFromCenter) {
  11553. var me = this;
  11554. var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
  11555. return {
  11556. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  11557. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  11558. };
  11559. },
  11560. getPointPositionForValue: function(index, value) {
  11561. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  11562. },
  11563. getBasePosition: function() {
  11564. var me = this;
  11565. var min = me.min;
  11566. var max = me.max;
  11567. return me.getPointPositionForValue(0,
  11568. me.beginAtZero ? 0 :
  11569. min < 0 && max < 0 ? max :
  11570. min > 0 && max > 0 ? min :
  11571. 0);
  11572. },
  11573. draw: function() {
  11574. var me = this;
  11575. var opts = me.options;
  11576. var gridLineOpts = opts.gridLines;
  11577. var tickOpts = opts.ticks;
  11578. var valueOrDefault = helpers.valueOrDefault;
  11579. if (opts.display) {
  11580. var ctx = me.ctx;
  11581. var startAngle = this.getIndexAngle(0);
  11582. // Tick Font
  11583. var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11584. var tickFontStyle = valueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  11585. var tickFontFamily = valueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  11586. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  11587. helpers.each(me.ticks, function(label, index) {
  11588. // Don't draw a centre value (if it is minimum)
  11589. if (index > 0 || tickOpts.reverse) {
  11590. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  11591. // Draw circular lines around the scale
  11592. if (gridLineOpts.display && index !== 0) {
  11593. drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
  11594. }
  11595. if (tickOpts.display) {
  11596. var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  11597. ctx.font = tickLabelFont;
  11598. ctx.save();
  11599. ctx.translate(me.xCenter, me.yCenter);
  11600. ctx.rotate(startAngle);
  11601. if (tickOpts.showLabelBackdrop) {
  11602. var labelWidth = ctx.measureText(label).width;
  11603. ctx.fillStyle = tickOpts.backdropColor;
  11604. ctx.fillRect(
  11605. -labelWidth / 2 - tickOpts.backdropPaddingX,
  11606. -yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
  11607. labelWidth + tickOpts.backdropPaddingX * 2,
  11608. tickFontSize + tickOpts.backdropPaddingY * 2
  11609. );
  11610. }
  11611. ctx.textAlign = 'center';
  11612. ctx.textBaseline = 'middle';
  11613. ctx.fillStyle = tickFontColor;
  11614. ctx.fillText(label, 0, -yCenterOffset);
  11615. ctx.restore();
  11616. }
  11617. }
  11618. });
  11619. if (opts.angleLines.display || opts.pointLabels.display) {
  11620. drawPointLabels(me);
  11621. }
  11622. }
  11623. }
  11624. });
  11625. scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  11626. };
  11627. },{"26":26,"34":34,"35":35,"46":46}],59:[function(require,module,exports){
  11628. /* global window: false */
  11629. 'use strict';
  11630. var moment = require(1);
  11631. moment = typeof moment === 'function' ? moment : window.moment;
  11632. var defaults = require(26);
  11633. var helpers = require(46);
  11634. var Scale = require(33);
  11635. var scaleService = require(34);
  11636. // Integer constants are from the ES6 spec.
  11637. var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
  11638. var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  11639. var INTERVALS = {
  11640. millisecond: {
  11641. common: true,
  11642. size: 1,
  11643. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  11644. },
  11645. second: {
  11646. common: true,
  11647. size: 1000,
  11648. steps: [1, 2, 5, 10, 15, 30]
  11649. },
  11650. minute: {
  11651. common: true,
  11652. size: 60000,
  11653. steps: [1, 2, 5, 10, 15, 30]
  11654. },
  11655. hour: {
  11656. common: true,
  11657. size: 3600000,
  11658. steps: [1, 2, 3, 6, 12]
  11659. },
  11660. day: {
  11661. common: true,
  11662. size: 86400000,
  11663. steps: [1, 2, 5]
  11664. },
  11665. week: {
  11666. common: false,
  11667. size: 604800000,
  11668. steps: [1, 2, 3, 4]
  11669. },
  11670. month: {
  11671. common: true,
  11672. size: 2.628e9,
  11673. steps: [1, 2, 3]
  11674. },
  11675. quarter: {
  11676. common: false,
  11677. size: 7.884e9,
  11678. steps: [1, 2, 3, 4]
  11679. },
  11680. year: {
  11681. common: true,
  11682. size: 3.154e10
  11683. }
  11684. };
  11685. var UNITS = Object.keys(INTERVALS);
  11686. function sorter(a, b) {
  11687. return a - b;
  11688. }
  11689. function arrayUnique(items) {
  11690. var hash = {};
  11691. var out = [];
  11692. var i, ilen, item;
  11693. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11694. item = items[i];
  11695. if (!hash[item]) {
  11696. hash[item] = true;
  11697. out.push(item);
  11698. }
  11699. }
  11700. return out;
  11701. }
  11702. /**
  11703. * Returns an array of {time, pos} objects used to interpolate a specific `time` or position
  11704. * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
  11705. * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other
  11706. * extremity (left + width or top + height). Note that it would be more optimized to directly
  11707. * store pre-computed pixels, but the scale dimensions are not guaranteed at the time we need
  11708. * to create the lookup table. The table ALWAYS contains at least two items: min and max.
  11709. *
  11710. * @param {Number[]} timestamps - timestamps sorted from lowest to highest.
  11711. * @param {String} distribution - If 'linear', timestamps will be spread linearly along the min
  11712. * and max range, so basically, the table will contains only two items: {min, 0} and {max, 1}.
  11713. * If 'series', timestamps will be positioned at the same distance from each other. In this
  11714. * case, only timestamps that break the time linearity are registered, meaning that in the
  11715. * best case, all timestamps are linear, the table contains only min and max.
  11716. */
  11717. function buildLookupTable(timestamps, min, max, distribution) {
  11718. if (distribution === 'linear' || !timestamps.length) {
  11719. return [
  11720. {time: min, pos: 0},
  11721. {time: max, pos: 1}
  11722. ];
  11723. }
  11724. var table = [];
  11725. var items = [min];
  11726. var i, ilen, prev, curr, next;
  11727. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  11728. curr = timestamps[i];
  11729. if (curr > min && curr < max) {
  11730. items.push(curr);
  11731. }
  11732. }
  11733. items.push(max);
  11734. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11735. next = items[i + 1];
  11736. prev = items[i - 1];
  11737. curr = items[i];
  11738. // only add points that breaks the scale linearity
  11739. if (prev === undefined || next === undefined || Math.round((next + prev) / 2) !== curr) {
  11740. table.push({time: curr, pos: i / (ilen - 1)});
  11741. }
  11742. }
  11743. return table;
  11744. }
  11745. // @see adapted from http://www.anujgakhar.com/2014/03/01/binary-search-in-javascript/
  11746. function lookup(table, key, value) {
  11747. var lo = 0;
  11748. var hi = table.length - 1;
  11749. var mid, i0, i1;
  11750. while (lo >= 0 && lo <= hi) {
  11751. mid = (lo + hi) >> 1;
  11752. i0 = table[mid - 1] || null;
  11753. i1 = table[mid];
  11754. if (!i0) {
  11755. // given value is outside table (before first item)
  11756. return {lo: null, hi: i1};
  11757. } else if (i1[key] < value) {
  11758. lo = mid + 1;
  11759. } else if (i0[key] > value) {
  11760. hi = mid - 1;
  11761. } else {
  11762. return {lo: i0, hi: i1};
  11763. }
  11764. }
  11765. // given value is outside table (after last item)
  11766. return {lo: i1, hi: null};
  11767. }
  11768. /**
  11769. * Linearly interpolates the given source `value` using the table items `skey` values and
  11770. * returns the associated `tkey` value. For example, interpolate(table, 'time', 42, 'pos')
  11771. * returns the position for a timestamp equal to 42. If value is out of bounds, values at
  11772. * index [0, 1] or [n - 1, n] are used for the interpolation.
  11773. */
  11774. function interpolate(table, skey, sval, tkey) {
  11775. var range = lookup(table, skey, sval);
  11776. // Note: the lookup table ALWAYS contains at least 2 items (min and max)
  11777. var prev = !range.lo ? table[0] : !range.hi ? table[table.length - 2] : range.lo;
  11778. var next = !range.lo ? table[1] : !range.hi ? table[table.length - 1] : range.hi;
  11779. var span = next[skey] - prev[skey];
  11780. var ratio = span ? (sval - prev[skey]) / span : 0;
  11781. var offset = (next[tkey] - prev[tkey]) * ratio;
  11782. return prev[tkey] + offset;
  11783. }
  11784. /**
  11785. * Convert the given value to a moment object using the given time options.
  11786. * @see http://momentjs.com/docs/#/parsing/
  11787. */
  11788. function momentify(value, options) {
  11789. var parser = options.parser;
  11790. var format = options.parser || options.format;
  11791. if (typeof parser === 'function') {
  11792. return parser(value);
  11793. }
  11794. if (typeof value === 'string' && typeof format === 'string') {
  11795. return moment(value, format);
  11796. }
  11797. if (!(value instanceof moment)) {
  11798. value = moment(value);
  11799. }
  11800. if (value.isValid()) {
  11801. return value;
  11802. }
  11803. // Labels are in an incompatible moment format and no `parser` has been provided.
  11804. // The user might still use the deprecated `format` option to convert his inputs.
  11805. if (typeof format === 'function') {
  11806. return format(value);
  11807. }
  11808. return value;
  11809. }
  11810. function parse(input, scale) {
  11811. if (helpers.isNullOrUndef(input)) {
  11812. return null;
  11813. }
  11814. var options = scale.options.time;
  11815. var value = momentify(scale.getRightValue(input), options);
  11816. if (!value.isValid()) {
  11817. return null;
  11818. }
  11819. if (options.round) {
  11820. value.startOf(options.round);
  11821. }
  11822. return value.valueOf();
  11823. }
  11824. /**
  11825. * Returns the number of unit to skip to be able to display up to `capacity` number of ticks
  11826. * in `unit` for the given `min` / `max` range and respecting the interval steps constraints.
  11827. */
  11828. function determineStepSize(min, max, unit, capacity) {
  11829. var range = max - min;
  11830. var interval = INTERVALS[unit];
  11831. var milliseconds = interval.size;
  11832. var steps = interval.steps;
  11833. var i, ilen, factor;
  11834. if (!steps) {
  11835. return Math.ceil(range / (capacity * milliseconds));
  11836. }
  11837. for (i = 0, ilen = steps.length; i < ilen; ++i) {
  11838. factor = steps[i];
  11839. if (Math.ceil(range / (milliseconds * factor)) <= capacity) {
  11840. break;
  11841. }
  11842. }
  11843. return factor;
  11844. }
  11845. /**
  11846. * Figures out what unit results in an appropriate number of auto-generated ticks
  11847. */
  11848. function determineUnitForAutoTicks(minUnit, min, max, capacity) {
  11849. var ilen = UNITS.length;
  11850. var i, interval, factor;
  11851. for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
  11852. interval = INTERVALS[UNITS[i]];
  11853. factor = interval.steps ? interval.steps[interval.steps.length - 1] : MAX_INTEGER;
  11854. if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
  11855. return UNITS[i];
  11856. }
  11857. }
  11858. return UNITS[ilen - 1];
  11859. }
  11860. /**
  11861. * Figures out what unit to format a set of ticks with
  11862. */
  11863. function determineUnitForFormatting(ticks, minUnit, min, max) {
  11864. var duration = moment.duration(moment(max).diff(moment(min)));
  11865. var ilen = UNITS.length;
  11866. var i, unit;
  11867. for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
  11868. unit = UNITS[i];
  11869. if (INTERVALS[unit].common && duration.as(unit) >= ticks.length) {
  11870. return unit;
  11871. }
  11872. }
  11873. return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
  11874. }
  11875. function determineMajorUnit(unit) {
  11876. for (var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i) {
  11877. if (INTERVALS[UNITS[i]].common) {
  11878. return UNITS[i];
  11879. }
  11880. }
  11881. }
  11882. /**
  11883. * Generates a maximum of `capacity` timestamps between min and max, rounded to the
  11884. * `minor` unit, aligned on the `major` unit and using the given scale time `options`.
  11885. * Important: this method can return ticks outside the min and max range, it's the
  11886. * responsibility of the calling code to clamp values if needed.
  11887. */
  11888. function generate(min, max, capacity, options) {
  11889. var timeOpts = options.time;
  11890. var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, capacity);
  11891. var major = determineMajorUnit(minor);
  11892. var stepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
  11893. var weekday = minor === 'week' ? timeOpts.isoWeekday : false;
  11894. var majorTicksEnabled = options.ticks.major.enabled;
  11895. var interval = INTERVALS[minor];
  11896. var first = moment(min);
  11897. var last = moment(max);
  11898. var ticks = [];
  11899. var time;
  11900. if (!stepSize) {
  11901. stepSize = determineStepSize(min, max, minor, capacity);
  11902. }
  11903. // For 'week' unit, handle the first day of week option
  11904. if (weekday) {
  11905. first = first.isoWeekday(weekday);
  11906. last = last.isoWeekday(weekday);
  11907. }
  11908. // Align first/last ticks on unit
  11909. first = first.startOf(weekday ? 'day' : minor);
  11910. last = last.startOf(weekday ? 'day' : minor);
  11911. // Make sure that the last tick include max
  11912. if (last < max) {
  11913. last.add(1, minor);
  11914. }
  11915. time = moment(first);
  11916. if (majorTicksEnabled && major && !weekday && !timeOpts.round) {
  11917. // Align the first tick on the previous `minor` unit aligned on the `major` unit:
  11918. // we first aligned time on the previous `major` unit then add the number of full
  11919. // stepSize there is between first and the previous major time.
  11920. time.startOf(major);
  11921. time.add(~~((first - time) / (interval.size * stepSize)) * stepSize, minor);
  11922. }
  11923. for (; time < last; time.add(stepSize, minor)) {
  11924. ticks.push(+time);
  11925. }
  11926. ticks.push(+time);
  11927. return ticks;
  11928. }
  11929. /**
  11930. * Returns the right and left offsets from edges in the form of {left, right}.
  11931. * Offsets are added when the `offset` option is true.
  11932. */
  11933. function computeOffsets(table, ticks, min, max, options) {
  11934. var left = 0;
  11935. var right = 0;
  11936. var upper, lower;
  11937. if (options.offset && ticks.length) {
  11938. if (!options.time.min) {
  11939. upper = ticks.length > 1 ? ticks[1] : max;
  11940. lower = ticks[0];
  11941. left = (
  11942. interpolate(table, 'time', upper, 'pos') -
  11943. interpolate(table, 'time', lower, 'pos')
  11944. ) / 2;
  11945. }
  11946. if (!options.time.max) {
  11947. upper = ticks[ticks.length - 1];
  11948. lower = ticks.length > 1 ? ticks[ticks.length - 2] : min;
  11949. right = (
  11950. interpolate(table, 'time', upper, 'pos') -
  11951. interpolate(table, 'time', lower, 'pos')
  11952. ) / 2;
  11953. }
  11954. }
  11955. return {left: left, right: right};
  11956. }
  11957. function ticksFromTimestamps(values, majorUnit) {
  11958. var ticks = [];
  11959. var i, ilen, value, major;
  11960. for (i = 0, ilen = values.length; i < ilen; ++i) {
  11961. value = values[i];
  11962. major = majorUnit ? value === +moment(value).startOf(majorUnit) : false;
  11963. ticks.push({
  11964. value: value,
  11965. major: major
  11966. });
  11967. }
  11968. return ticks;
  11969. }
  11970. function determineLabelFormat(data, timeOpts) {
  11971. var i, momentDate, hasTime;
  11972. var ilen = data.length;
  11973. // find the label with the most parts (milliseconds, minutes, etc.)
  11974. // format all labels with the same level of detail as the most specific label
  11975. for (i = 0; i < ilen; i++) {
  11976. momentDate = momentify(data[i], timeOpts);
  11977. if (momentDate.millisecond() !== 0) {
  11978. return 'MMM D, YYYY h:mm:ss.SSS a';
  11979. }
  11980. if (momentDate.second() !== 0 || momentDate.minute() !== 0 || momentDate.hour() !== 0) {
  11981. hasTime = true;
  11982. }
  11983. }
  11984. if (hasTime) {
  11985. return 'MMM D, YYYY h:mm:ss a';
  11986. }
  11987. return 'MMM D, YYYY';
  11988. }
  11989. module.exports = function() {
  11990. var defaultConfig = {
  11991. position: 'bottom',
  11992. /**
  11993. * Data distribution along the scale:
  11994. * - 'linear': data are spread according to their time (distances can vary),
  11995. * - 'series': data are spread at the same distance from each other.
  11996. * @see https://github.com/chartjs/Chart.js/pull/4507
  11997. * @since 2.7.0
  11998. */
  11999. distribution: 'linear',
  12000. /**
  12001. * Scale boundary strategy (bypassed by min/max time options)
  12002. * - `data`: make sure data are fully visible, ticks outside are removed
  12003. * - `ticks`: make sure ticks are fully visible, data outside are truncated
  12004. * @see https://github.com/chartjs/Chart.js/pull/4556
  12005. * @since 2.7.0
  12006. */
  12007. bounds: 'data',
  12008. time: {
  12009. 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
  12010. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  12011. unit: false, // false == automatic or override with week, month, year, etc.
  12012. round: false, // none, or override with week, month, year, etc.
  12013. displayFormat: false, // DEPRECATED
  12014. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  12015. minUnit: 'millisecond',
  12016. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  12017. displayFormats: {
  12018. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  12019. second: 'h:mm:ss a', // 11:20:01 AM
  12020. minute: 'h:mm a', // 11:20 AM
  12021. hour: 'hA', // 5PM
  12022. day: 'MMM D', // Sep 4
  12023. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  12024. month: 'MMM YYYY', // Sept 2015
  12025. quarter: '[Q]Q - YYYY', // Q3
  12026. year: 'YYYY' // 2015
  12027. },
  12028. },
  12029. ticks: {
  12030. autoSkip: false,
  12031. /**
  12032. * Ticks generation input values:
  12033. * - 'auto': generates "optimal" ticks based on scale size and time options.
  12034. * - 'data': generates ticks from data (including labels from data {t|x|y} objects).
  12035. * - 'labels': generates ticks from user given `data.labels` values ONLY.
  12036. * @see https://github.com/chartjs/Chart.js/pull/4507
  12037. * @since 2.7.0
  12038. */
  12039. source: 'auto',
  12040. major: {
  12041. enabled: false
  12042. }
  12043. }
  12044. };
  12045. var TimeScale = Scale.extend({
  12046. initialize: function() {
  12047. if (!moment) {
  12048. 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');
  12049. }
  12050. this.mergeTicksOptions();
  12051. Scale.prototype.initialize.call(this);
  12052. },
  12053. update: function() {
  12054. var me = this;
  12055. var options = me.options;
  12056. // DEPRECATIONS: output a message only one time per update
  12057. if (options.time && options.time.format) {
  12058. console.warn('options.time.format is deprecated and replaced by options.time.parser.');
  12059. }
  12060. return Scale.prototype.update.apply(me, arguments);
  12061. },
  12062. /**
  12063. * Allows data to be referenced via 't' attribute
  12064. */
  12065. getRightValue: function(rawValue) {
  12066. if (rawValue && rawValue.t !== undefined) {
  12067. rawValue = rawValue.t;
  12068. }
  12069. return Scale.prototype.getRightValue.call(this, rawValue);
  12070. },
  12071. determineDataLimits: function() {
  12072. var me = this;
  12073. var chart = me.chart;
  12074. var timeOpts = me.options.time;
  12075. var unit = timeOpts.unit || 'day';
  12076. var min = MAX_INTEGER;
  12077. var max = MIN_INTEGER;
  12078. var timestamps = [];
  12079. var datasets = [];
  12080. var labels = [];
  12081. var i, j, ilen, jlen, data, timestamp;
  12082. // Convert labels to timestamps
  12083. for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) {
  12084. labels.push(parse(chart.data.labels[i], me));
  12085. }
  12086. // Convert data to timestamps
  12087. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  12088. if (chart.isDatasetVisible(i)) {
  12089. data = chart.data.datasets[i].data;
  12090. // Let's consider that all data have the same format.
  12091. if (helpers.isObject(data[0])) {
  12092. datasets[i] = [];
  12093. for (j = 0, jlen = data.length; j < jlen; ++j) {
  12094. timestamp = parse(data[j], me);
  12095. timestamps.push(timestamp);
  12096. datasets[i][j] = timestamp;
  12097. }
  12098. } else {
  12099. timestamps.push.apply(timestamps, labels);
  12100. datasets[i] = labels.slice(0);
  12101. }
  12102. } else {
  12103. datasets[i] = [];
  12104. }
  12105. }
  12106. if (labels.length) {
  12107. // Sort labels **after** data have been converted
  12108. labels = arrayUnique(labels).sort(sorter);
  12109. min = Math.min(min, labels[0]);
  12110. max = Math.max(max, labels[labels.length - 1]);
  12111. }
  12112. if (timestamps.length) {
  12113. timestamps = arrayUnique(timestamps).sort(sorter);
  12114. min = Math.min(min, timestamps[0]);
  12115. max = Math.max(max, timestamps[timestamps.length - 1]);
  12116. }
  12117. min = parse(timeOpts.min, me) || min;
  12118. max = parse(timeOpts.max, me) || max;
  12119. // In case there is no valid min/max, set limits based on unit time option
  12120. min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
  12121. max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;
  12122. // Make sure that max is strictly higher than min (required by the lookup table)
  12123. me.min = Math.min(min, max);
  12124. me.max = Math.max(min + 1, max);
  12125. // PRIVATE
  12126. me._horizontal = me.isHorizontal();
  12127. me._table = [];
  12128. me._timestamps = {
  12129. data: timestamps,
  12130. datasets: datasets,
  12131. labels: labels
  12132. };
  12133. },
  12134. buildTicks: function() {
  12135. var me = this;
  12136. var min = me.min;
  12137. var max = me.max;
  12138. var options = me.options;
  12139. var timeOpts = options.time;
  12140. var timestamps = [];
  12141. var ticks = [];
  12142. var i, ilen, timestamp;
  12143. switch (options.ticks.source) {
  12144. case 'data':
  12145. timestamps = me._timestamps.data;
  12146. break;
  12147. case 'labels':
  12148. timestamps = me._timestamps.labels;
  12149. break;
  12150. case 'auto':
  12151. default:
  12152. timestamps = generate(min, max, me.getLabelCapacity(min), options);
  12153. }
  12154. if (options.bounds === 'ticks' && timestamps.length) {
  12155. min = timestamps[0];
  12156. max = timestamps[timestamps.length - 1];
  12157. }
  12158. // Enforce limits with user min/max options
  12159. min = parse(timeOpts.min, me) || min;
  12160. max = parse(timeOpts.max, me) || max;
  12161. // Remove ticks outside the min/max range
  12162. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  12163. timestamp = timestamps[i];
  12164. if (timestamp >= min && timestamp <= max) {
  12165. ticks.push(timestamp);
  12166. }
  12167. }
  12168. me.min = min;
  12169. me.max = max;
  12170. // PRIVATE
  12171. me._unit = timeOpts.unit || determineUnitForFormatting(ticks, timeOpts.minUnit, me.min, me.max);
  12172. me._majorUnit = determineMajorUnit(me._unit);
  12173. me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
  12174. me._offsets = computeOffsets(me._table, ticks, min, max, options);
  12175. me._labelFormat = determineLabelFormat(me._timestamps.data, timeOpts);
  12176. return ticksFromTimestamps(ticks, me._majorUnit);
  12177. },
  12178. getLabelForIndex: function(index, datasetIndex) {
  12179. var me = this;
  12180. var data = me.chart.data;
  12181. var timeOpts = me.options.time;
  12182. var label = data.labels && index < data.labels.length ? data.labels[index] : '';
  12183. var value = data.datasets[datasetIndex].data[index];
  12184. if (helpers.isObject(value)) {
  12185. label = me.getRightValue(value);
  12186. }
  12187. if (timeOpts.tooltipFormat) {
  12188. return momentify(label, timeOpts).format(timeOpts.tooltipFormat);
  12189. }
  12190. if (typeof label === 'string') {
  12191. return label;
  12192. }
  12193. return momentify(label, timeOpts).format(me._labelFormat);
  12194. },
  12195. /**
  12196. * Function to format an individual tick mark
  12197. * @private
  12198. */
  12199. tickFormatFunction: function(tick, index, ticks, formatOverride) {
  12200. var me = this;
  12201. var options = me.options;
  12202. var time = tick.valueOf();
  12203. var formats = options.time.displayFormats;
  12204. var minorFormat = formats[me._unit];
  12205. var majorUnit = me._majorUnit;
  12206. var majorFormat = formats[majorUnit];
  12207. var majorTime = tick.clone().startOf(majorUnit).valueOf();
  12208. var majorTickOpts = options.ticks.major;
  12209. var major = majorTickOpts.enabled && majorUnit && majorFormat && time === majorTime;
  12210. var label = tick.format(formatOverride ? formatOverride : major ? majorFormat : minorFormat);
  12211. var tickOpts = major ? majorTickOpts : options.ticks.minor;
  12212. var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
  12213. return formatter ? formatter(label, index, ticks) : label;
  12214. },
  12215. convertTicksToLabels: function(ticks) {
  12216. var labels = [];
  12217. var i, ilen;
  12218. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  12219. labels.push(this.tickFormatFunction(moment(ticks[i].value), i, ticks));
  12220. }
  12221. return labels;
  12222. },
  12223. /**
  12224. * @private
  12225. */
  12226. getPixelForOffset: function(time) {
  12227. var me = this;
  12228. var size = me._horizontal ? me.width : me.height;
  12229. var start = me._horizontal ? me.left : me.top;
  12230. var pos = interpolate(me._table, 'time', time, 'pos');
  12231. return start + size * (me._offsets.left + pos) / (me._offsets.left + 1 + me._offsets.right);
  12232. },
  12233. getPixelForValue: function(value, index, datasetIndex) {
  12234. var me = this;
  12235. var time = null;
  12236. if (index !== undefined && datasetIndex !== undefined) {
  12237. time = me._timestamps.datasets[datasetIndex][index];
  12238. }
  12239. if (time === null) {
  12240. time = parse(value, me);
  12241. }
  12242. if (time !== null) {
  12243. return me.getPixelForOffset(time);
  12244. }
  12245. },
  12246. getPixelForTick: function(index) {
  12247. var ticks = this.getTicks();
  12248. return index >= 0 && index < ticks.length ?
  12249. this.getPixelForOffset(ticks[index].value) :
  12250. null;
  12251. },
  12252. getValueForPixel: function(pixel) {
  12253. var me = this;
  12254. var size = me._horizontal ? me.width : me.height;
  12255. var start = me._horizontal ? me.left : me.top;
  12256. var pos = (size ? (pixel - start) / size : 0) * (me._offsets.left + 1 + me._offsets.left) - me._offsets.right;
  12257. var time = interpolate(me._table, 'pos', pos, 'time');
  12258. return moment(time);
  12259. },
  12260. /**
  12261. * Crude approximation of what the label width might be
  12262. * @private
  12263. */
  12264. getLabelWidth: function(label) {
  12265. var me = this;
  12266. var ticksOpts = me.options.ticks;
  12267. var tickLabelWidth = me.ctx.measureText(label).width;
  12268. var angle = helpers.toRadians(ticksOpts.maxRotation);
  12269. var cosRotation = Math.cos(angle);
  12270. var sinRotation = Math.sin(angle);
  12271. var tickFontSize = helpers.valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize);
  12272. return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  12273. },
  12274. /**
  12275. * @private
  12276. */
  12277. getLabelCapacity: function(exampleTime) {
  12278. var me = this;
  12279. var formatOverride = me.options.time.displayFormats.millisecond; // Pick the longest format for guestimation
  12280. var exampleLabel = me.tickFormatFunction(moment(exampleTime), 0, [], formatOverride);
  12281. var tickLabelWidth = me.getLabelWidth(exampleLabel);
  12282. var innerWidth = me.isHorizontal() ? me.width : me.height;
  12283. var capacity = Math.floor(innerWidth / tickLabelWidth);
  12284. return capacity > 0 ? capacity : 1;
  12285. }
  12286. });
  12287. scaleService.registerScaleType('time', TimeScale, defaultConfig);
  12288. };
  12289. },{"1":1,"26":26,"33":33,"34":34,"46":46}]},{},[7])(7)
  12290. });