Chart.bundle.js 523 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.7.2
  5. *
  6. * Copyright 2018 Chart.js Contributors
  7. * Released under the MIT license
  8. * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md
  9. */
  10. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Chart = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
  11. /* MIT license */
  12. var colorNames = require(5);
  13. module.exports = {
  14. getRgba: getRgba,
  15. getHsla: getHsla,
  16. getRgb: getRgb,
  17. getHsl: getHsl,
  18. getHwb: getHwb,
  19. getAlpha: getAlpha,
  20. hexString: hexString,
  21. rgbString: rgbString,
  22. rgbaString: rgbaString,
  23. percentString: percentString,
  24. percentaString: percentaString,
  25. hslString: hslString,
  26. hslaString: hslaString,
  27. hwbString: hwbString,
  28. keyword: keyword
  29. }
  30. function getRgba(string) {
  31. if (!string) {
  32. return;
  33. }
  34. var abbr = /^#([a-fA-F0-9]{3})$/i,
  35. hex = /^#([a-fA-F0-9]{6})$/i,
  36. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  37. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  38. keyword = /(\w+)/;
  39. var rgb = [0, 0, 0],
  40. a = 1,
  41. match = string.match(abbr);
  42. if (match) {
  43. match = match[1];
  44. for (var i = 0; i < rgb.length; i++) {
  45. rgb[i] = parseInt(match[i] + match[i], 16);
  46. }
  47. }
  48. else if (match = string.match(hex)) {
  49. match = match[1];
  50. for (var i = 0; i < rgb.length; i++) {
  51. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  52. }
  53. }
  54. else if (match = string.match(rgba)) {
  55. for (var i = 0; i < rgb.length; i++) {
  56. rgb[i] = parseInt(match[i + 1]);
  57. }
  58. a = parseFloat(match[4]);
  59. }
  60. else if (match = string.match(per)) {
  61. for (var i = 0; i < rgb.length; i++) {
  62. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  63. }
  64. a = parseFloat(match[4]);
  65. }
  66. else if (match = string.match(keyword)) {
  67. if (match[1] == "transparent") {
  68. return [0, 0, 0, 0];
  69. }
  70. rgb = colorNames[match[1]];
  71. if (!rgb) {
  72. return;
  73. }
  74. }
  75. for (var i = 0; i < rgb.length; i++) {
  76. rgb[i] = scale(rgb[i], 0, 255);
  77. }
  78. if (!a && a != 0) {
  79. a = 1;
  80. }
  81. else {
  82. a = scale(a, 0, 1);
  83. }
  84. rgb[3] = a;
  85. return rgb;
  86. }
  87. function getHsla(string) {
  88. if (!string) {
  89. return;
  90. }
  91. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  92. var match = string.match(hsl);
  93. if (match) {
  94. var alpha = parseFloat(match[4]);
  95. var h = scale(parseInt(match[1]), 0, 360),
  96. s = scale(parseFloat(match[2]), 0, 100),
  97. l = scale(parseFloat(match[3]), 0, 100),
  98. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  99. return [h, s, l, a];
  100. }
  101. }
  102. function getHwb(string) {
  103. if (!string) {
  104. return;
  105. }
  106. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  107. var match = string.match(hwb);
  108. if (match) {
  109. var alpha = parseFloat(match[4]);
  110. var h = scale(parseInt(match[1]), 0, 360),
  111. w = scale(parseFloat(match[2]), 0, 100),
  112. b = scale(parseFloat(match[3]), 0, 100),
  113. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  114. return [h, w, b, a];
  115. }
  116. }
  117. function getRgb(string) {
  118. var rgba = getRgba(string);
  119. return rgba && rgba.slice(0, 3);
  120. }
  121. function getHsl(string) {
  122. var hsla = getHsla(string);
  123. return hsla && hsla.slice(0, 3);
  124. }
  125. function getAlpha(string) {
  126. var vals = getRgba(string);
  127. if (vals) {
  128. return vals[3];
  129. }
  130. else if (vals = getHsla(string)) {
  131. return vals[3];
  132. }
  133. else if (vals = getHwb(string)) {
  134. return vals[3];
  135. }
  136. }
  137. // generators
  138. function hexString(rgb) {
  139. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  140. + hexDouble(rgb[2]);
  141. }
  142. function rgbString(rgba, alpha) {
  143. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  144. return rgbaString(rgba, alpha);
  145. }
  146. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  147. }
  148. function rgbaString(rgba, alpha) {
  149. if (alpha === undefined) {
  150. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  151. }
  152. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  153. + ", " + alpha + ")";
  154. }
  155. function percentString(rgba, alpha) {
  156. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  157. return percentaString(rgba, alpha);
  158. }
  159. var r = Math.round(rgba[0]/255 * 100),
  160. g = Math.round(rgba[1]/255 * 100),
  161. b = Math.round(rgba[2]/255 * 100);
  162. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  163. }
  164. function percentaString(rgba, alpha) {
  165. var r = Math.round(rgba[0]/255 * 100),
  166. g = Math.round(rgba[1]/255 * 100),
  167. b = Math.round(rgba[2]/255 * 100);
  168. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  169. }
  170. function hslString(hsla, alpha) {
  171. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  172. return hslaString(hsla, alpha);
  173. }
  174. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  175. }
  176. function hslaString(hsla, alpha) {
  177. if (alpha === undefined) {
  178. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  179. }
  180. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  181. + alpha + ")";
  182. }
  183. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  184. // (hwb have alpha optional & 1 is default value)
  185. function hwbString(hwb, alpha) {
  186. if (alpha === undefined) {
  187. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  188. }
  189. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  190. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  191. }
  192. function keyword(rgb) {
  193. return reverseNames[rgb.slice(0, 3)];
  194. }
  195. // helpers
  196. function scale(num, min, max) {
  197. return Math.min(Math.max(min, num), max);
  198. }
  199. function hexDouble(num) {
  200. var str = num.toString(16).toUpperCase();
  201. return (str.length < 2) ? "0" + str : str;
  202. }
  203. //create a list of reverse color names
  204. var reverseNames = {};
  205. for (var name in colorNames) {
  206. reverseNames[colorNames[name]] = name;
  207. }
  208. },{"5":5}],2:[function(require,module,exports){
  209. /* MIT license */
  210. var convert = require(4);
  211. var string = require(1);
  212. var Color = function (obj) {
  213. if (obj instanceof Color) {
  214. return obj;
  215. }
  216. if (!(this instanceof Color)) {
  217. return new Color(obj);
  218. }
  219. this.valid = false;
  220. this.values = {
  221. rgb: [0, 0, 0],
  222. hsl: [0, 0, 0],
  223. hsv: [0, 0, 0],
  224. hwb: [0, 0, 0],
  225. cmyk: [0, 0, 0, 0],
  226. alpha: 1
  227. };
  228. // parse Color() argument
  229. var vals;
  230. if (typeof obj === 'string') {
  231. vals = string.getRgba(obj);
  232. if (vals) {
  233. this.setValues('rgb', vals);
  234. } else if (vals = string.getHsla(obj)) {
  235. this.setValues('hsl', vals);
  236. } else if (vals = string.getHwb(obj)) {
  237. this.setValues('hwb', vals);
  238. }
  239. } else if (typeof obj === 'object') {
  240. vals = obj;
  241. if (vals.r !== undefined || vals.red !== undefined) {
  242. this.setValues('rgb', vals);
  243. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  244. this.setValues('hsl', vals);
  245. } else if (vals.v !== undefined || vals.value !== undefined) {
  246. this.setValues('hsv', vals);
  247. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  248. this.setValues('hwb', vals);
  249. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  250. this.setValues('cmyk', vals);
  251. }
  252. }
  253. };
  254. Color.prototype = {
  255. isValid: function () {
  256. return this.valid;
  257. },
  258. rgb: function () {
  259. return this.setSpace('rgb', arguments);
  260. },
  261. hsl: function () {
  262. return this.setSpace('hsl', arguments);
  263. },
  264. hsv: function () {
  265. return this.setSpace('hsv', arguments);
  266. },
  267. hwb: function () {
  268. return this.setSpace('hwb', arguments);
  269. },
  270. cmyk: function () {
  271. return this.setSpace('cmyk', arguments);
  272. },
  273. rgbArray: function () {
  274. return this.values.rgb;
  275. },
  276. hslArray: function () {
  277. return this.values.hsl;
  278. },
  279. hsvArray: function () {
  280. return this.values.hsv;
  281. },
  282. hwbArray: function () {
  283. var values = this.values;
  284. if (values.alpha !== 1) {
  285. return values.hwb.concat([values.alpha]);
  286. }
  287. return values.hwb;
  288. },
  289. cmykArray: function () {
  290. return this.values.cmyk;
  291. },
  292. rgbaArray: function () {
  293. var values = this.values;
  294. return values.rgb.concat([values.alpha]);
  295. },
  296. hslaArray: function () {
  297. var values = this.values;
  298. return values.hsl.concat([values.alpha]);
  299. },
  300. alpha: function (val) {
  301. if (val === undefined) {
  302. return this.values.alpha;
  303. }
  304. this.setValues('alpha', val);
  305. return this;
  306. },
  307. red: function (val) {
  308. return this.setChannel('rgb', 0, val);
  309. },
  310. green: function (val) {
  311. return this.setChannel('rgb', 1, val);
  312. },
  313. blue: function (val) {
  314. return this.setChannel('rgb', 2, val);
  315. },
  316. hue: function (val) {
  317. if (val) {
  318. val %= 360;
  319. val = val < 0 ? 360 + val : val;
  320. }
  321. return this.setChannel('hsl', 0, val);
  322. },
  323. saturation: function (val) {
  324. return this.setChannel('hsl', 1, val);
  325. },
  326. lightness: function (val) {
  327. return this.setChannel('hsl', 2, val);
  328. },
  329. saturationv: function (val) {
  330. return this.setChannel('hsv', 1, val);
  331. },
  332. whiteness: function (val) {
  333. return this.setChannel('hwb', 1, val);
  334. },
  335. blackness: function (val) {
  336. return this.setChannel('hwb', 2, val);
  337. },
  338. value: function (val) {
  339. return this.setChannel('hsv', 2, val);
  340. },
  341. cyan: function (val) {
  342. return this.setChannel('cmyk', 0, val);
  343. },
  344. magenta: function (val) {
  345. return this.setChannel('cmyk', 1, val);
  346. },
  347. yellow: function (val) {
  348. return this.setChannel('cmyk', 2, val);
  349. },
  350. black: function (val) {
  351. return this.setChannel('cmyk', 3, val);
  352. },
  353. hexString: function () {
  354. return string.hexString(this.values.rgb);
  355. },
  356. rgbString: function () {
  357. return string.rgbString(this.values.rgb, this.values.alpha);
  358. },
  359. rgbaString: function () {
  360. return string.rgbaString(this.values.rgb, this.values.alpha);
  361. },
  362. percentString: function () {
  363. return string.percentString(this.values.rgb, this.values.alpha);
  364. },
  365. hslString: function () {
  366. return string.hslString(this.values.hsl, this.values.alpha);
  367. },
  368. hslaString: function () {
  369. return string.hslaString(this.values.hsl, this.values.alpha);
  370. },
  371. hwbString: function () {
  372. return string.hwbString(this.values.hwb, this.values.alpha);
  373. },
  374. keyword: function () {
  375. return string.keyword(this.values.rgb, this.values.alpha);
  376. },
  377. rgbNumber: function () {
  378. var rgb = this.values.rgb;
  379. return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
  380. },
  381. luminosity: function () {
  382. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  383. var rgb = this.values.rgb;
  384. var lum = [];
  385. for (var i = 0; i < rgb.length; i++) {
  386. var chan = rgb[i] / 255;
  387. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
  388. }
  389. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  390. },
  391. contrast: function (color2) {
  392. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  393. var lum1 = this.luminosity();
  394. var lum2 = color2.luminosity();
  395. if (lum1 > lum2) {
  396. return (lum1 + 0.05) / (lum2 + 0.05);
  397. }
  398. return (lum2 + 0.05) / (lum1 + 0.05);
  399. },
  400. level: function (color2) {
  401. var contrastRatio = this.contrast(color2);
  402. if (contrastRatio >= 7.1) {
  403. return 'AAA';
  404. }
  405. return (contrastRatio >= 4.5) ? 'AA' : '';
  406. },
  407. dark: function () {
  408. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  409. var rgb = this.values.rgb;
  410. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  411. return yiq < 128;
  412. },
  413. light: function () {
  414. return !this.dark();
  415. },
  416. negate: function () {
  417. var rgb = [];
  418. for (var i = 0; i < 3; i++) {
  419. rgb[i] = 255 - this.values.rgb[i];
  420. }
  421. this.setValues('rgb', rgb);
  422. return this;
  423. },
  424. lighten: function (ratio) {
  425. var hsl = this.values.hsl;
  426. hsl[2] += hsl[2] * ratio;
  427. this.setValues('hsl', hsl);
  428. return this;
  429. },
  430. darken: function (ratio) {
  431. var hsl = this.values.hsl;
  432. hsl[2] -= hsl[2] * ratio;
  433. this.setValues('hsl', hsl);
  434. return this;
  435. },
  436. saturate: function (ratio) {
  437. var hsl = this.values.hsl;
  438. hsl[1] += hsl[1] * ratio;
  439. this.setValues('hsl', hsl);
  440. return this;
  441. },
  442. desaturate: function (ratio) {
  443. var hsl = this.values.hsl;
  444. hsl[1] -= hsl[1] * ratio;
  445. this.setValues('hsl', hsl);
  446. return this;
  447. },
  448. whiten: function (ratio) {
  449. var hwb = this.values.hwb;
  450. hwb[1] += hwb[1] * ratio;
  451. this.setValues('hwb', hwb);
  452. return this;
  453. },
  454. blacken: function (ratio) {
  455. var hwb = this.values.hwb;
  456. hwb[2] += hwb[2] * ratio;
  457. this.setValues('hwb', hwb);
  458. return this;
  459. },
  460. greyscale: function () {
  461. var rgb = this.values.rgb;
  462. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  463. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  464. this.setValues('rgb', [val, val, val]);
  465. return this;
  466. },
  467. clearer: function (ratio) {
  468. var alpha = this.values.alpha;
  469. this.setValues('alpha', alpha - (alpha * ratio));
  470. return this;
  471. },
  472. opaquer: function (ratio) {
  473. var alpha = this.values.alpha;
  474. this.setValues('alpha', alpha + (alpha * ratio));
  475. return this;
  476. },
  477. rotate: function (degrees) {
  478. var hsl = this.values.hsl;
  479. var hue = (hsl[0] + degrees) % 360;
  480. hsl[0] = hue < 0 ? 360 + hue : hue;
  481. this.setValues('hsl', hsl);
  482. return this;
  483. },
  484. /**
  485. * Ported from sass implementation in C
  486. * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
  487. */
  488. mix: function (mixinColor, weight) {
  489. var color1 = this;
  490. var color2 = mixinColor;
  491. var p = weight === undefined ? 0.5 : weight;
  492. var w = 2 * p - 1;
  493. var a = color1.alpha() - color2.alpha();
  494. var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  495. var w2 = 1 - w1;
  496. return this
  497. .rgb(
  498. w1 * color1.red() + w2 * color2.red(),
  499. w1 * color1.green() + w2 * color2.green(),
  500. w1 * color1.blue() + w2 * color2.blue()
  501. )
  502. .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
  503. },
  504. toJSON: function () {
  505. return this.rgb();
  506. },
  507. clone: function () {
  508. // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
  509. // making the final build way to big to embed in Chart.js. So let's do it manually,
  510. // assuming that values to clone are 1 dimension arrays containing only numbers,
  511. // except 'alpha' which is a number.
  512. var result = new Color();
  513. var source = this.values;
  514. var target = result.values;
  515. var value, type;
  516. for (var prop in source) {
  517. if (source.hasOwnProperty(prop)) {
  518. value = source[prop];
  519. type = ({}).toString.call(value);
  520. if (type === '[object Array]') {
  521. target[prop] = value.slice(0);
  522. } else if (type === '[object Number]') {
  523. target[prop] = value;
  524. } else {
  525. console.error('unexpected color value:', value);
  526. }
  527. }
  528. }
  529. return result;
  530. }
  531. };
  532. Color.prototype.spaces = {
  533. rgb: ['red', 'green', 'blue'],
  534. hsl: ['hue', 'saturation', 'lightness'],
  535. hsv: ['hue', 'saturation', 'value'],
  536. hwb: ['hue', 'whiteness', 'blackness'],
  537. cmyk: ['cyan', 'magenta', 'yellow', 'black']
  538. };
  539. Color.prototype.maxes = {
  540. rgb: [255, 255, 255],
  541. hsl: [360, 100, 100],
  542. hsv: [360, 100, 100],
  543. hwb: [360, 100, 100],
  544. cmyk: [100, 100, 100, 100]
  545. };
  546. Color.prototype.getValues = function (space) {
  547. var values = this.values;
  548. var vals = {};
  549. for (var i = 0; i < space.length; i++) {
  550. vals[space.charAt(i)] = values[space][i];
  551. }
  552. if (values.alpha !== 1) {
  553. vals.a = values.alpha;
  554. }
  555. // {r: 255, g: 255, b: 255, a: 0.4}
  556. return vals;
  557. };
  558. Color.prototype.setValues = function (space, vals) {
  559. var values = this.values;
  560. var spaces = this.spaces;
  561. var maxes = this.maxes;
  562. var alpha = 1;
  563. var i;
  564. this.valid = true;
  565. if (space === 'alpha') {
  566. alpha = vals;
  567. } else if (vals.length) {
  568. // [10, 10, 10]
  569. values[space] = vals.slice(0, space.length);
  570. alpha = vals[space.length];
  571. } else if (vals[space.charAt(0)] !== undefined) {
  572. // {r: 10, g: 10, b: 10}
  573. for (i = 0; i < space.length; i++) {
  574. values[space][i] = vals[space.charAt(i)];
  575. }
  576. alpha = vals.a;
  577. } else if (vals[spaces[space][0]] !== undefined) {
  578. // {red: 10, green: 10, blue: 10}
  579. var chans = spaces[space];
  580. for (i = 0; i < space.length; i++) {
  581. values[space][i] = vals[chans[i]];
  582. }
  583. alpha = vals.alpha;
  584. }
  585. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  586. if (space === 'alpha') {
  587. return false;
  588. }
  589. var capped;
  590. // cap values of the space prior converting all values
  591. for (i = 0; i < space.length; i++) {
  592. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  593. values[space][i] = Math.round(capped);
  594. }
  595. // convert to all the other color spaces
  596. for (var sname in spaces) {
  597. if (sname !== space) {
  598. values[sname] = convert[space][sname](values[space]);
  599. }
  600. }
  601. return true;
  602. };
  603. Color.prototype.setSpace = function (space, args) {
  604. var vals = args[0];
  605. if (vals === undefined) {
  606. // color.rgb()
  607. return this.getValues(space);
  608. }
  609. // color.rgb(10, 10, 10)
  610. if (typeof vals === 'number') {
  611. vals = Array.prototype.slice.call(args);
  612. }
  613. this.setValues(space, vals);
  614. return this;
  615. };
  616. Color.prototype.setChannel = function (space, index, val) {
  617. var svalues = this.values[space];
  618. if (val === undefined) {
  619. // color.red()
  620. return svalues[index];
  621. } else if (val === svalues[index]) {
  622. // color.red(color.red())
  623. return this;
  624. }
  625. // color.red(100)
  626. svalues[index] = val;
  627. this.setValues(space, svalues);
  628. return this;
  629. };
  630. if (typeof window !== 'undefined') {
  631. window.Color = Color;
  632. }
  633. module.exports = Color;
  634. },{"1":1,"4":4}],3:[function(require,module,exports){
  635. /* MIT license */
  636. module.exports = {
  637. rgb2hsl: rgb2hsl,
  638. rgb2hsv: rgb2hsv,
  639. rgb2hwb: rgb2hwb,
  640. rgb2cmyk: rgb2cmyk,
  641. rgb2keyword: rgb2keyword,
  642. rgb2xyz: rgb2xyz,
  643. rgb2lab: rgb2lab,
  644. rgb2lch: rgb2lch,
  645. hsl2rgb: hsl2rgb,
  646. hsl2hsv: hsl2hsv,
  647. hsl2hwb: hsl2hwb,
  648. hsl2cmyk: hsl2cmyk,
  649. hsl2keyword: hsl2keyword,
  650. hsv2rgb: hsv2rgb,
  651. hsv2hsl: hsv2hsl,
  652. hsv2hwb: hsv2hwb,
  653. hsv2cmyk: hsv2cmyk,
  654. hsv2keyword: hsv2keyword,
  655. hwb2rgb: hwb2rgb,
  656. hwb2hsl: hwb2hsl,
  657. hwb2hsv: hwb2hsv,
  658. hwb2cmyk: hwb2cmyk,
  659. hwb2keyword: hwb2keyword,
  660. cmyk2rgb: cmyk2rgb,
  661. cmyk2hsl: cmyk2hsl,
  662. cmyk2hsv: cmyk2hsv,
  663. cmyk2hwb: cmyk2hwb,
  664. cmyk2keyword: cmyk2keyword,
  665. keyword2rgb: keyword2rgb,
  666. keyword2hsl: keyword2hsl,
  667. keyword2hsv: keyword2hsv,
  668. keyword2hwb: keyword2hwb,
  669. keyword2cmyk: keyword2cmyk,
  670. keyword2lab: keyword2lab,
  671. keyword2xyz: keyword2xyz,
  672. xyz2rgb: xyz2rgb,
  673. xyz2lab: xyz2lab,
  674. xyz2lch: xyz2lch,
  675. lab2xyz: lab2xyz,
  676. lab2rgb: lab2rgb,
  677. lab2lch: lab2lch,
  678. lch2lab: lch2lab,
  679. lch2xyz: lch2xyz,
  680. lch2rgb: lch2rgb
  681. }
  682. function rgb2hsl(rgb) {
  683. var r = rgb[0]/255,
  684. g = rgb[1]/255,
  685. b = rgb[2]/255,
  686. min = Math.min(r, g, b),
  687. max = Math.max(r, g, b),
  688. delta = max - min,
  689. h, s, l;
  690. if (max == min)
  691. h = 0;
  692. else if (r == max)
  693. h = (g - b) / delta;
  694. else if (g == max)
  695. h = 2 + (b - r) / delta;
  696. else if (b == max)
  697. h = 4 + (r - g)/ delta;
  698. h = Math.min(h * 60, 360);
  699. if (h < 0)
  700. h += 360;
  701. l = (min + max) / 2;
  702. if (max == min)
  703. s = 0;
  704. else if (l <= 0.5)
  705. s = delta / (max + min);
  706. else
  707. s = delta / (2 - max - min);
  708. return [h, s * 100, l * 100];
  709. }
  710. function rgb2hsv(rgb) {
  711. var r = rgb[0],
  712. g = rgb[1],
  713. b = rgb[2],
  714. min = Math.min(r, g, b),
  715. max = Math.max(r, g, b),
  716. delta = max - min,
  717. h, s, v;
  718. if (max == 0)
  719. s = 0;
  720. else
  721. s = (delta/max * 1000)/10;
  722. if (max == min)
  723. h = 0;
  724. else if (r == max)
  725. h = (g - b) / delta;
  726. else if (g == max)
  727. h = 2 + (b - r) / delta;
  728. else if (b == max)
  729. h = 4 + (r - g) / delta;
  730. h = Math.min(h * 60, 360);
  731. if (h < 0)
  732. h += 360;
  733. v = ((max / 255) * 1000) / 10;
  734. return [h, s, v];
  735. }
  736. function rgb2hwb(rgb) {
  737. var r = rgb[0],
  738. g = rgb[1],
  739. b = rgb[2],
  740. h = rgb2hsl(rgb)[0],
  741. w = 1/255 * Math.min(r, Math.min(g, b)),
  742. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  743. return [h, w * 100, b * 100];
  744. }
  745. function rgb2cmyk(rgb) {
  746. var r = rgb[0] / 255,
  747. g = rgb[1] / 255,
  748. b = rgb[2] / 255,
  749. c, m, y, k;
  750. k = Math.min(1 - r, 1 - g, 1 - b);
  751. c = (1 - r - k) / (1 - k) || 0;
  752. m = (1 - g - k) / (1 - k) || 0;
  753. y = (1 - b - k) / (1 - k) || 0;
  754. return [c * 100, m * 100, y * 100, k * 100];
  755. }
  756. function rgb2keyword(rgb) {
  757. return reverseKeywords[JSON.stringify(rgb)];
  758. }
  759. function rgb2xyz(rgb) {
  760. var r = rgb[0] / 255,
  761. g = rgb[1] / 255,
  762. b = rgb[2] / 255;
  763. // assume sRGB
  764. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  765. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  766. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  767. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  768. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  769. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  770. return [x * 100, y *100, z * 100];
  771. }
  772. function rgb2lab(rgb) {
  773. var xyz = rgb2xyz(rgb),
  774. x = xyz[0],
  775. y = xyz[1],
  776. z = xyz[2],
  777. l, a, b;
  778. x /= 95.047;
  779. y /= 100;
  780. z /= 108.883;
  781. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  782. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  783. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  784. l = (116 * y) - 16;
  785. a = 500 * (x - y);
  786. b = 200 * (y - z);
  787. return [l, a, b];
  788. }
  789. function rgb2lch(args) {
  790. return lab2lch(rgb2lab(args));
  791. }
  792. function hsl2rgb(hsl) {
  793. var h = hsl[0] / 360,
  794. s = hsl[1] / 100,
  795. l = hsl[2] / 100,
  796. t1, t2, t3, rgb, val;
  797. if (s == 0) {
  798. val = l * 255;
  799. return [val, val, val];
  800. }
  801. if (l < 0.5)
  802. t2 = l * (1 + s);
  803. else
  804. t2 = l + s - l * s;
  805. t1 = 2 * l - t2;
  806. rgb = [0, 0, 0];
  807. for (var i = 0; i < 3; i++) {
  808. t3 = h + 1 / 3 * - (i - 1);
  809. t3 < 0 && t3++;
  810. t3 > 1 && t3--;
  811. if (6 * t3 < 1)
  812. val = t1 + (t2 - t1) * 6 * t3;
  813. else if (2 * t3 < 1)
  814. val = t2;
  815. else if (3 * t3 < 2)
  816. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  817. else
  818. val = t1;
  819. rgb[i] = val * 255;
  820. }
  821. return rgb;
  822. }
  823. function hsl2hsv(hsl) {
  824. var h = hsl[0],
  825. s = hsl[1] / 100,
  826. l = hsl[2] / 100,
  827. sv, v;
  828. if(l === 0) {
  829. // no need to do calc on black
  830. // also avoids divide by 0 error
  831. return [0, 0, 0];
  832. }
  833. l *= 2;
  834. s *= (l <= 1) ? l : 2 - l;
  835. v = (l + s) / 2;
  836. sv = (2 * s) / (l + s);
  837. return [h, sv * 100, v * 100];
  838. }
  839. function hsl2hwb(args) {
  840. return rgb2hwb(hsl2rgb(args));
  841. }
  842. function hsl2cmyk(args) {
  843. return rgb2cmyk(hsl2rgb(args));
  844. }
  845. function hsl2keyword(args) {
  846. return rgb2keyword(hsl2rgb(args));
  847. }
  848. function hsv2rgb(hsv) {
  849. var h = hsv[0] / 60,
  850. s = hsv[1] / 100,
  851. v = hsv[2] / 100,
  852. hi = Math.floor(h) % 6;
  853. var f = h - Math.floor(h),
  854. p = 255 * v * (1 - s),
  855. q = 255 * v * (1 - (s * f)),
  856. t = 255 * v * (1 - (s * (1 - f))),
  857. v = 255 * v;
  858. switch(hi) {
  859. case 0:
  860. return [v, t, p];
  861. case 1:
  862. return [q, v, p];
  863. case 2:
  864. return [p, v, t];
  865. case 3:
  866. return [p, q, v];
  867. case 4:
  868. return [t, p, v];
  869. case 5:
  870. return [v, p, q];
  871. }
  872. }
  873. function hsv2hsl(hsv) {
  874. var h = hsv[0],
  875. s = hsv[1] / 100,
  876. v = hsv[2] / 100,
  877. sl, l;
  878. l = (2 - s) * v;
  879. sl = s * v;
  880. sl /= (l <= 1) ? l : 2 - l;
  881. sl = sl || 0;
  882. l /= 2;
  883. return [h, sl * 100, l * 100];
  884. }
  885. function hsv2hwb(args) {
  886. return rgb2hwb(hsv2rgb(args))
  887. }
  888. function hsv2cmyk(args) {
  889. return rgb2cmyk(hsv2rgb(args));
  890. }
  891. function hsv2keyword(args) {
  892. return rgb2keyword(hsv2rgb(args));
  893. }
  894. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  895. function hwb2rgb(hwb) {
  896. var h = hwb[0] / 360,
  897. wh = hwb[1] / 100,
  898. bl = hwb[2] / 100,
  899. ratio = wh + bl,
  900. i, v, f, n;
  901. // wh + bl cant be > 1
  902. if (ratio > 1) {
  903. wh /= ratio;
  904. bl /= ratio;
  905. }
  906. i = Math.floor(6 * h);
  907. v = 1 - bl;
  908. f = 6 * h - i;
  909. if ((i & 0x01) != 0) {
  910. f = 1 - f;
  911. }
  912. n = wh + f * (v - wh); // linear interpolation
  913. switch (i) {
  914. default:
  915. case 6:
  916. case 0: r = v; g = n; b = wh; break;
  917. case 1: r = n; g = v; b = wh; break;
  918. case 2: r = wh; g = v; b = n; break;
  919. case 3: r = wh; g = n; b = v; break;
  920. case 4: r = n; g = wh; b = v; break;
  921. case 5: r = v; g = wh; b = n; break;
  922. }
  923. return [r * 255, g * 255, b * 255];
  924. }
  925. function hwb2hsl(args) {
  926. return rgb2hsl(hwb2rgb(args));
  927. }
  928. function hwb2hsv(args) {
  929. return rgb2hsv(hwb2rgb(args));
  930. }
  931. function hwb2cmyk(args) {
  932. return rgb2cmyk(hwb2rgb(args));
  933. }
  934. function hwb2keyword(args) {
  935. return rgb2keyword(hwb2rgb(args));
  936. }
  937. function cmyk2rgb(cmyk) {
  938. var c = cmyk[0] / 100,
  939. m = cmyk[1] / 100,
  940. y = cmyk[2] / 100,
  941. k = cmyk[3] / 100,
  942. r, g, b;
  943. r = 1 - Math.min(1, c * (1 - k) + k);
  944. g = 1 - Math.min(1, m * (1 - k) + k);
  945. b = 1 - Math.min(1, y * (1 - k) + k);
  946. return [r * 255, g * 255, b * 255];
  947. }
  948. function cmyk2hsl(args) {
  949. return rgb2hsl(cmyk2rgb(args));
  950. }
  951. function cmyk2hsv(args) {
  952. return rgb2hsv(cmyk2rgb(args));
  953. }
  954. function cmyk2hwb(args) {
  955. return rgb2hwb(cmyk2rgb(args));
  956. }
  957. function cmyk2keyword(args) {
  958. return rgb2keyword(cmyk2rgb(args));
  959. }
  960. function xyz2rgb(xyz) {
  961. var x = xyz[0] / 100,
  962. y = xyz[1] / 100,
  963. z = xyz[2] / 100,
  964. r, g, b;
  965. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  966. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  967. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  968. // assume sRGB
  969. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  970. : r = (r * 12.92);
  971. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  972. : g = (g * 12.92);
  973. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  974. : b = (b * 12.92);
  975. r = Math.min(Math.max(0, r), 1);
  976. g = Math.min(Math.max(0, g), 1);
  977. b = Math.min(Math.max(0, b), 1);
  978. return [r * 255, g * 255, b * 255];
  979. }
  980. function xyz2lab(xyz) {
  981. var x = xyz[0],
  982. y = xyz[1],
  983. z = xyz[2],
  984. l, a, b;
  985. x /= 95.047;
  986. y /= 100;
  987. z /= 108.883;
  988. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  989. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  990. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  991. l = (116 * y) - 16;
  992. a = 500 * (x - y);
  993. b = 200 * (y - z);
  994. return [l, a, b];
  995. }
  996. function xyz2lch(args) {
  997. return lab2lch(xyz2lab(args));
  998. }
  999. function lab2xyz(lab) {
  1000. var l = lab[0],
  1001. a = lab[1],
  1002. b = lab[2],
  1003. x, y, z, y2;
  1004. if (l <= 8) {
  1005. y = (l * 100) / 903.3;
  1006. y2 = (7.787 * (y / 100)) + (16 / 116);
  1007. } else {
  1008. y = 100 * Math.pow((l + 16) / 116, 3);
  1009. y2 = Math.pow(y / 100, 1/3);
  1010. }
  1011. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1012. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1013. return [x, y, z];
  1014. }
  1015. function lab2lch(lab) {
  1016. var l = lab[0],
  1017. a = lab[1],
  1018. b = lab[2],
  1019. hr, h, c;
  1020. hr = Math.atan2(b, a);
  1021. h = hr * 360 / 2 / Math.PI;
  1022. if (h < 0) {
  1023. h += 360;
  1024. }
  1025. c = Math.sqrt(a * a + b * b);
  1026. return [l, c, h];
  1027. }
  1028. function lab2rgb(args) {
  1029. return xyz2rgb(lab2xyz(args));
  1030. }
  1031. function lch2lab(lch) {
  1032. var l = lch[0],
  1033. c = lch[1],
  1034. h = lch[2],
  1035. a, b, hr;
  1036. hr = h / 360 * 2 * Math.PI;
  1037. a = c * Math.cos(hr);
  1038. b = c * Math.sin(hr);
  1039. return [l, a, b];
  1040. }
  1041. function lch2xyz(args) {
  1042. return lab2xyz(lch2lab(args));
  1043. }
  1044. function lch2rgb(args) {
  1045. return lab2rgb(lch2lab(args));
  1046. }
  1047. function keyword2rgb(keyword) {
  1048. return cssKeywords[keyword];
  1049. }
  1050. function keyword2hsl(args) {
  1051. return rgb2hsl(keyword2rgb(args));
  1052. }
  1053. function keyword2hsv(args) {
  1054. return rgb2hsv(keyword2rgb(args));
  1055. }
  1056. function keyword2hwb(args) {
  1057. return rgb2hwb(keyword2rgb(args));
  1058. }
  1059. function keyword2cmyk(args) {
  1060. return rgb2cmyk(keyword2rgb(args));
  1061. }
  1062. function keyword2lab(args) {
  1063. return rgb2lab(keyword2rgb(args));
  1064. }
  1065. function keyword2xyz(args) {
  1066. return rgb2xyz(keyword2rgb(args));
  1067. }
  1068. var cssKeywords = {
  1069. aliceblue: [240,248,255],
  1070. antiquewhite: [250,235,215],
  1071. aqua: [0,255,255],
  1072. aquamarine: [127,255,212],
  1073. azure: [240,255,255],
  1074. beige: [245,245,220],
  1075. bisque: [255,228,196],
  1076. black: [0,0,0],
  1077. blanchedalmond: [255,235,205],
  1078. blue: [0,0,255],
  1079. blueviolet: [138,43,226],
  1080. brown: [165,42,42],
  1081. burlywood: [222,184,135],
  1082. cadetblue: [95,158,160],
  1083. chartreuse: [127,255,0],
  1084. chocolate: [210,105,30],
  1085. coral: [255,127,80],
  1086. cornflowerblue: [100,149,237],
  1087. cornsilk: [255,248,220],
  1088. crimson: [220,20,60],
  1089. cyan: [0,255,255],
  1090. darkblue: [0,0,139],
  1091. darkcyan: [0,139,139],
  1092. darkgoldenrod: [184,134,11],
  1093. darkgray: [169,169,169],
  1094. darkgreen: [0,100,0],
  1095. darkgrey: [169,169,169],
  1096. darkkhaki: [189,183,107],
  1097. darkmagenta: [139,0,139],
  1098. darkolivegreen: [85,107,47],
  1099. darkorange: [255,140,0],
  1100. darkorchid: [153,50,204],
  1101. darkred: [139,0,0],
  1102. darksalmon: [233,150,122],
  1103. darkseagreen: [143,188,143],
  1104. darkslateblue: [72,61,139],
  1105. darkslategray: [47,79,79],
  1106. darkslategrey: [47,79,79],
  1107. darkturquoise: [0,206,209],
  1108. darkviolet: [148,0,211],
  1109. deeppink: [255,20,147],
  1110. deepskyblue: [0,191,255],
  1111. dimgray: [105,105,105],
  1112. dimgrey: [105,105,105],
  1113. dodgerblue: [30,144,255],
  1114. firebrick: [178,34,34],
  1115. floralwhite: [255,250,240],
  1116. forestgreen: [34,139,34],
  1117. fuchsia: [255,0,255],
  1118. gainsboro: [220,220,220],
  1119. ghostwhite: [248,248,255],
  1120. gold: [255,215,0],
  1121. goldenrod: [218,165,32],
  1122. gray: [128,128,128],
  1123. green: [0,128,0],
  1124. greenyellow: [173,255,47],
  1125. grey: [128,128,128],
  1126. honeydew: [240,255,240],
  1127. hotpink: [255,105,180],
  1128. indianred: [205,92,92],
  1129. indigo: [75,0,130],
  1130. ivory: [255,255,240],
  1131. khaki: [240,230,140],
  1132. lavender: [230,230,250],
  1133. lavenderblush: [255,240,245],
  1134. lawngreen: [124,252,0],
  1135. lemonchiffon: [255,250,205],
  1136. lightblue: [173,216,230],
  1137. lightcoral: [240,128,128],
  1138. lightcyan: [224,255,255],
  1139. lightgoldenrodyellow: [250,250,210],
  1140. lightgray: [211,211,211],
  1141. lightgreen: [144,238,144],
  1142. lightgrey: [211,211,211],
  1143. lightpink: [255,182,193],
  1144. lightsalmon: [255,160,122],
  1145. lightseagreen: [32,178,170],
  1146. lightskyblue: [135,206,250],
  1147. lightslategray: [119,136,153],
  1148. lightslategrey: [119,136,153],
  1149. lightsteelblue: [176,196,222],
  1150. lightyellow: [255,255,224],
  1151. lime: [0,255,0],
  1152. limegreen: [50,205,50],
  1153. linen: [250,240,230],
  1154. magenta: [255,0,255],
  1155. maroon: [128,0,0],
  1156. mediumaquamarine: [102,205,170],
  1157. mediumblue: [0,0,205],
  1158. mediumorchid: [186,85,211],
  1159. mediumpurple: [147,112,219],
  1160. mediumseagreen: [60,179,113],
  1161. mediumslateblue: [123,104,238],
  1162. mediumspringgreen: [0,250,154],
  1163. mediumturquoise: [72,209,204],
  1164. mediumvioletred: [199,21,133],
  1165. midnightblue: [25,25,112],
  1166. mintcream: [245,255,250],
  1167. mistyrose: [255,228,225],
  1168. moccasin: [255,228,181],
  1169. navajowhite: [255,222,173],
  1170. navy: [0,0,128],
  1171. oldlace: [253,245,230],
  1172. olive: [128,128,0],
  1173. olivedrab: [107,142,35],
  1174. orange: [255,165,0],
  1175. orangered: [255,69,0],
  1176. orchid: [218,112,214],
  1177. palegoldenrod: [238,232,170],
  1178. palegreen: [152,251,152],
  1179. paleturquoise: [175,238,238],
  1180. palevioletred: [219,112,147],
  1181. papayawhip: [255,239,213],
  1182. peachpuff: [255,218,185],
  1183. peru: [205,133,63],
  1184. pink: [255,192,203],
  1185. plum: [221,160,221],
  1186. powderblue: [176,224,230],
  1187. purple: [128,0,128],
  1188. rebeccapurple: [102, 51, 153],
  1189. red: [255,0,0],
  1190. rosybrown: [188,143,143],
  1191. royalblue: [65,105,225],
  1192. saddlebrown: [139,69,19],
  1193. salmon: [250,128,114],
  1194. sandybrown: [244,164,96],
  1195. seagreen: [46,139,87],
  1196. seashell: [255,245,238],
  1197. sienna: [160,82,45],
  1198. silver: [192,192,192],
  1199. skyblue: [135,206,235],
  1200. slateblue: [106,90,205],
  1201. slategray: [112,128,144],
  1202. slategrey: [112,128,144],
  1203. snow: [255,250,250],
  1204. springgreen: [0,255,127],
  1205. steelblue: [70,130,180],
  1206. tan: [210,180,140],
  1207. teal: [0,128,128],
  1208. thistle: [216,191,216],
  1209. tomato: [255,99,71],
  1210. turquoise: [64,224,208],
  1211. violet: [238,130,238],
  1212. wheat: [245,222,179],
  1213. white: [255,255,255],
  1214. whitesmoke: [245,245,245],
  1215. yellow: [255,255,0],
  1216. yellowgreen: [154,205,50]
  1217. };
  1218. var reverseKeywords = {};
  1219. for (var key in cssKeywords) {
  1220. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1221. }
  1222. },{}],4:[function(require,module,exports){
  1223. var conversions = require(3);
  1224. var convert = function() {
  1225. return new Converter();
  1226. }
  1227. for (var func in conversions) {
  1228. // export Raw versions
  1229. convert[func + "Raw"] = (function(func) {
  1230. // accept array or plain args
  1231. return function(arg) {
  1232. if (typeof arg == "number")
  1233. arg = Array.prototype.slice.call(arguments);
  1234. return conversions[func](arg);
  1235. }
  1236. })(func);
  1237. var pair = /(\w+)2(\w+)/.exec(func),
  1238. from = pair[1],
  1239. to = pair[2];
  1240. // export rgb2hsl and ["rgb"]["hsl"]
  1241. convert[from] = convert[from] || {};
  1242. convert[from][to] = convert[func] = (function(func) {
  1243. return function(arg) {
  1244. if (typeof arg == "number")
  1245. arg = Array.prototype.slice.call(arguments);
  1246. var val = conversions[func](arg);
  1247. if (typeof val == "string" || val === undefined)
  1248. return val; // keyword
  1249. for (var i = 0; i < val.length; i++)
  1250. val[i] = Math.round(val[i]);
  1251. return val;
  1252. }
  1253. })(func);
  1254. }
  1255. /* Converter does lazy conversion and caching */
  1256. var Converter = function() {
  1257. this.convs = {};
  1258. };
  1259. /* Either get the values for a space or
  1260. set the values for a space, depending on args */
  1261. Converter.prototype.routeSpace = function(space, args) {
  1262. var values = args[0];
  1263. if (values === undefined) {
  1264. // color.rgb()
  1265. return this.getValues(space);
  1266. }
  1267. // color.rgb(10, 10, 10)
  1268. if (typeof values == "number") {
  1269. values = Array.prototype.slice.call(args);
  1270. }
  1271. return this.setValues(space, values);
  1272. };
  1273. /* Set the values for a space, invalidating cache */
  1274. Converter.prototype.setValues = function(space, values) {
  1275. this.space = space;
  1276. this.convs = {};
  1277. this.convs[space] = values;
  1278. return this;
  1279. };
  1280. /* Get the values for a space. If there's already
  1281. a conversion for the space, fetch it, otherwise
  1282. compute it */
  1283. Converter.prototype.getValues = function(space) {
  1284. var vals = this.convs[space];
  1285. if (!vals) {
  1286. var fspace = this.space,
  1287. from = this.convs[fspace];
  1288. vals = convert[fspace][space](from);
  1289. this.convs[space] = vals;
  1290. }
  1291. return vals;
  1292. };
  1293. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  1294. Converter.prototype[space] = function(vals) {
  1295. return this.routeSpace(space, arguments);
  1296. }
  1297. });
  1298. module.exports = convert;
  1299. },{"3":3}],5:[function(require,module,exports){
  1300. 'use strict'
  1301. module.exports = {
  1302. "aliceblue": [240, 248, 255],
  1303. "antiquewhite": [250, 235, 215],
  1304. "aqua": [0, 255, 255],
  1305. "aquamarine": [127, 255, 212],
  1306. "azure": [240, 255, 255],
  1307. "beige": [245, 245, 220],
  1308. "bisque": [255, 228, 196],
  1309. "black": [0, 0, 0],
  1310. "blanchedalmond": [255, 235, 205],
  1311. "blue": [0, 0, 255],
  1312. "blueviolet": [138, 43, 226],
  1313. "brown": [165, 42, 42],
  1314. "burlywood": [222, 184, 135],
  1315. "cadetblue": [95, 158, 160],
  1316. "chartreuse": [127, 255, 0],
  1317. "chocolate": [210, 105, 30],
  1318. "coral": [255, 127, 80],
  1319. "cornflowerblue": [100, 149, 237],
  1320. "cornsilk": [255, 248, 220],
  1321. "crimson": [220, 20, 60],
  1322. "cyan": [0, 255, 255],
  1323. "darkblue": [0, 0, 139],
  1324. "darkcyan": [0, 139, 139],
  1325. "darkgoldenrod": [184, 134, 11],
  1326. "darkgray": [169, 169, 169],
  1327. "darkgreen": [0, 100, 0],
  1328. "darkgrey": [169, 169, 169],
  1329. "darkkhaki": [189, 183, 107],
  1330. "darkmagenta": [139, 0, 139],
  1331. "darkolivegreen": [85, 107, 47],
  1332. "darkorange": [255, 140, 0],
  1333. "darkorchid": [153, 50, 204],
  1334. "darkred": [139, 0, 0],
  1335. "darksalmon": [233, 150, 122],
  1336. "darkseagreen": [143, 188, 143],
  1337. "darkslateblue": [72, 61, 139],
  1338. "darkslategray": [47, 79, 79],
  1339. "darkslategrey": [47, 79, 79],
  1340. "darkturquoise": [0, 206, 209],
  1341. "darkviolet": [148, 0, 211],
  1342. "deeppink": [255, 20, 147],
  1343. "deepskyblue": [0, 191, 255],
  1344. "dimgray": [105, 105, 105],
  1345. "dimgrey": [105, 105, 105],
  1346. "dodgerblue": [30, 144, 255],
  1347. "firebrick": [178, 34, 34],
  1348. "floralwhite": [255, 250, 240],
  1349. "forestgreen": [34, 139, 34],
  1350. "fuchsia": [255, 0, 255],
  1351. "gainsboro": [220, 220, 220],
  1352. "ghostwhite": [248, 248, 255],
  1353. "gold": [255, 215, 0],
  1354. "goldenrod": [218, 165, 32],
  1355. "gray": [128, 128, 128],
  1356. "green": [0, 128, 0],
  1357. "greenyellow": [173, 255, 47],
  1358. "grey": [128, 128, 128],
  1359. "honeydew": [240, 255, 240],
  1360. "hotpink": [255, 105, 180],
  1361. "indianred": [205, 92, 92],
  1362. "indigo": [75, 0, 130],
  1363. "ivory": [255, 255, 240],
  1364. "khaki": [240, 230, 140],
  1365. "lavender": [230, 230, 250],
  1366. "lavenderblush": [255, 240, 245],
  1367. "lawngreen": [124, 252, 0],
  1368. "lemonchiffon": [255, 250, 205],
  1369. "lightblue": [173, 216, 230],
  1370. "lightcoral": [240, 128, 128],
  1371. "lightcyan": [224, 255, 255],
  1372. "lightgoldenrodyellow": [250, 250, 210],
  1373. "lightgray": [211, 211, 211],
  1374. "lightgreen": [144, 238, 144],
  1375. "lightgrey": [211, 211, 211],
  1376. "lightpink": [255, 182, 193],
  1377. "lightsalmon": [255, 160, 122],
  1378. "lightseagreen": [32, 178, 170],
  1379. "lightskyblue": [135, 206, 250],
  1380. "lightslategray": [119, 136, 153],
  1381. "lightslategrey": [119, 136, 153],
  1382. "lightsteelblue": [176, 196, 222],
  1383. "lightyellow": [255, 255, 224],
  1384. "lime": [0, 255, 0],
  1385. "limegreen": [50, 205, 50],
  1386. "linen": [250, 240, 230],
  1387. "magenta": [255, 0, 255],
  1388. "maroon": [128, 0, 0],
  1389. "mediumaquamarine": [102, 205, 170],
  1390. "mediumblue": [0, 0, 205],
  1391. "mediumorchid": [186, 85, 211],
  1392. "mediumpurple": [147, 112, 219],
  1393. "mediumseagreen": [60, 179, 113],
  1394. "mediumslateblue": [123, 104, 238],
  1395. "mediumspringgreen": [0, 250, 154],
  1396. "mediumturquoise": [72, 209, 204],
  1397. "mediumvioletred": [199, 21, 133],
  1398. "midnightblue": [25, 25, 112],
  1399. "mintcream": [245, 255, 250],
  1400. "mistyrose": [255, 228, 225],
  1401. "moccasin": [255, 228, 181],
  1402. "navajowhite": [255, 222, 173],
  1403. "navy": [0, 0, 128],
  1404. "oldlace": [253, 245, 230],
  1405. "olive": [128, 128, 0],
  1406. "olivedrab": [107, 142, 35],
  1407. "orange": [255, 165, 0],
  1408. "orangered": [255, 69, 0],
  1409. "orchid": [218, 112, 214],
  1410. "palegoldenrod": [238, 232, 170],
  1411. "palegreen": [152, 251, 152],
  1412. "paleturquoise": [175, 238, 238],
  1413. "palevioletred": [219, 112, 147],
  1414. "papayawhip": [255, 239, 213],
  1415. "peachpuff": [255, 218, 185],
  1416. "peru": [205, 133, 63],
  1417. "pink": [255, 192, 203],
  1418. "plum": [221, 160, 221],
  1419. "powderblue": [176, 224, 230],
  1420. "purple": [128, 0, 128],
  1421. "rebeccapurple": [102, 51, 153],
  1422. "red": [255, 0, 0],
  1423. "rosybrown": [188, 143, 143],
  1424. "royalblue": [65, 105, 225],
  1425. "saddlebrown": [139, 69, 19],
  1426. "salmon": [250, 128, 114],
  1427. "sandybrown": [244, 164, 96],
  1428. "seagreen": [46, 139, 87],
  1429. "seashell": [255, 245, 238],
  1430. "sienna": [160, 82, 45],
  1431. "silver": [192, 192, 192],
  1432. "skyblue": [135, 206, 235],
  1433. "slateblue": [106, 90, 205],
  1434. "slategray": [112, 128, 144],
  1435. "slategrey": [112, 128, 144],
  1436. "snow": [255, 250, 250],
  1437. "springgreen": [0, 255, 127],
  1438. "steelblue": [70, 130, 180],
  1439. "tan": [210, 180, 140],
  1440. "teal": [0, 128, 128],
  1441. "thistle": [216, 191, 216],
  1442. "tomato": [255, 99, 71],
  1443. "turquoise": [64, 224, 208],
  1444. "violet": [238, 130, 238],
  1445. "wheat": [245, 222, 179],
  1446. "white": [255, 255, 255],
  1447. "whitesmoke": [245, 245, 245],
  1448. "yellow": [255, 255, 0],
  1449. "yellowgreen": [154, 205, 50]
  1450. };
  1451. },{}],6:[function(require,module,exports){
  1452. //! moment.js
  1453. //! version : 2.20.1
  1454. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  1455. //! license : MIT
  1456. //! momentjs.com
  1457. ;(function (global, factory) {
  1458. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  1459. typeof define === 'function' && define.amd ? define(factory) :
  1460. global.moment = factory()
  1461. }(this, (function () { 'use strict';
  1462. var hookCallback;
  1463. function hooks () {
  1464. return hookCallback.apply(null, arguments);
  1465. }
  1466. // This is done to register the method called with moment()
  1467. // without creating circular dependencies.
  1468. function setHookCallback (callback) {
  1469. hookCallback = callback;
  1470. }
  1471. function isArray(input) {
  1472. return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
  1473. }
  1474. function isObject(input) {
  1475. // IE8 will treat undefined and null as object if it wasn't for
  1476. // input != null
  1477. return input != null && Object.prototype.toString.call(input) === '[object Object]';
  1478. }
  1479. function isObjectEmpty(obj) {
  1480. if (Object.getOwnPropertyNames) {
  1481. return (Object.getOwnPropertyNames(obj).length === 0);
  1482. } else {
  1483. var k;
  1484. for (k in obj) {
  1485. if (obj.hasOwnProperty(k)) {
  1486. return false;
  1487. }
  1488. }
  1489. return true;
  1490. }
  1491. }
  1492. function isUndefined(input) {
  1493. return input === void 0;
  1494. }
  1495. function isNumber(input) {
  1496. return typeof input === 'number' || Object.prototype.toString.call(input) === '[object Number]';
  1497. }
  1498. function isDate(input) {
  1499. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  1500. }
  1501. function map(arr, fn) {
  1502. var res = [], i;
  1503. for (i = 0; i < arr.length; ++i) {
  1504. res.push(fn(arr[i], i));
  1505. }
  1506. return res;
  1507. }
  1508. function hasOwnProp(a, b) {
  1509. return Object.prototype.hasOwnProperty.call(a, b);
  1510. }
  1511. function extend(a, b) {
  1512. for (var i in b) {
  1513. if (hasOwnProp(b, i)) {
  1514. a[i] = b[i];
  1515. }
  1516. }
  1517. if (hasOwnProp(b, 'toString')) {
  1518. a.toString = b.toString;
  1519. }
  1520. if (hasOwnProp(b, 'valueOf')) {
  1521. a.valueOf = b.valueOf;
  1522. }
  1523. return a;
  1524. }
  1525. function createUTC (input, format, locale, strict) {
  1526. return createLocalOrUTC(input, format, locale, strict, true).utc();
  1527. }
  1528. function defaultParsingFlags() {
  1529. // We need to deep clone this object.
  1530. return {
  1531. empty : false,
  1532. unusedTokens : [],
  1533. unusedInput : [],
  1534. overflow : -2,
  1535. charsLeftOver : 0,
  1536. nullInput : false,
  1537. invalidMonth : null,
  1538. invalidFormat : false,
  1539. userInvalidated : false,
  1540. iso : false,
  1541. parsedDateParts : [],
  1542. meridiem : null,
  1543. rfc2822 : false,
  1544. weekdayMismatch : false
  1545. };
  1546. }
  1547. function getParsingFlags(m) {
  1548. if (m._pf == null) {
  1549. m._pf = defaultParsingFlags();
  1550. }
  1551. return m._pf;
  1552. }
  1553. var some;
  1554. if (Array.prototype.some) {
  1555. some = Array.prototype.some;
  1556. } else {
  1557. some = function (fun) {
  1558. var t = Object(this);
  1559. var len = t.length >>> 0;
  1560. for (var i = 0; i < len; i++) {
  1561. if (i in t && fun.call(this, t[i], i, t)) {
  1562. return true;
  1563. }
  1564. }
  1565. return false;
  1566. };
  1567. }
  1568. function isValid(m) {
  1569. if (m._isValid == null) {
  1570. var flags = getParsingFlags(m);
  1571. var parsedParts = some.call(flags.parsedDateParts, function (i) {
  1572. return i != null;
  1573. });
  1574. var isNowValid = !isNaN(m._d.getTime()) &&
  1575. flags.overflow < 0 &&
  1576. !flags.empty &&
  1577. !flags.invalidMonth &&
  1578. !flags.invalidWeekday &&
  1579. !flags.weekdayMismatch &&
  1580. !flags.nullInput &&
  1581. !flags.invalidFormat &&
  1582. !flags.userInvalidated &&
  1583. (!flags.meridiem || (flags.meridiem && parsedParts));
  1584. if (m._strict) {
  1585. isNowValid = isNowValid &&
  1586. flags.charsLeftOver === 0 &&
  1587. flags.unusedTokens.length === 0 &&
  1588. flags.bigHour === undefined;
  1589. }
  1590. if (Object.isFrozen == null || !Object.isFrozen(m)) {
  1591. m._isValid = isNowValid;
  1592. }
  1593. else {
  1594. return isNowValid;
  1595. }
  1596. }
  1597. return m._isValid;
  1598. }
  1599. function createInvalid (flags) {
  1600. var m = createUTC(NaN);
  1601. if (flags != null) {
  1602. extend(getParsingFlags(m), flags);
  1603. }
  1604. else {
  1605. getParsingFlags(m).userInvalidated = true;
  1606. }
  1607. return m;
  1608. }
  1609. // Plugins that add properties should also add the key here (null value),
  1610. // so we can properly clone ourselves.
  1611. var momentProperties = hooks.momentProperties = [];
  1612. function copyConfig(to, from) {
  1613. var i, prop, val;
  1614. if (!isUndefined(from._isAMomentObject)) {
  1615. to._isAMomentObject = from._isAMomentObject;
  1616. }
  1617. if (!isUndefined(from._i)) {
  1618. to._i = from._i;
  1619. }
  1620. if (!isUndefined(from._f)) {
  1621. to._f = from._f;
  1622. }
  1623. if (!isUndefined(from._l)) {
  1624. to._l = from._l;
  1625. }
  1626. if (!isUndefined(from._strict)) {
  1627. to._strict = from._strict;
  1628. }
  1629. if (!isUndefined(from._tzm)) {
  1630. to._tzm = from._tzm;
  1631. }
  1632. if (!isUndefined(from._isUTC)) {
  1633. to._isUTC = from._isUTC;
  1634. }
  1635. if (!isUndefined(from._offset)) {
  1636. to._offset = from._offset;
  1637. }
  1638. if (!isUndefined(from._pf)) {
  1639. to._pf = getParsingFlags(from);
  1640. }
  1641. if (!isUndefined(from._locale)) {
  1642. to._locale = from._locale;
  1643. }
  1644. if (momentProperties.length > 0) {
  1645. for (i = 0; i < momentProperties.length; i++) {
  1646. prop = momentProperties[i];
  1647. val = from[prop];
  1648. if (!isUndefined(val)) {
  1649. to[prop] = val;
  1650. }
  1651. }
  1652. }
  1653. return to;
  1654. }
  1655. var updateInProgress = false;
  1656. // Moment prototype object
  1657. function Moment(config) {
  1658. copyConfig(this, config);
  1659. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  1660. if (!this.isValid()) {
  1661. this._d = new Date(NaN);
  1662. }
  1663. // Prevent infinite loop in case updateOffset creates new moment
  1664. // objects.
  1665. if (updateInProgress === false) {
  1666. updateInProgress = true;
  1667. hooks.updateOffset(this);
  1668. updateInProgress = false;
  1669. }
  1670. }
  1671. function isMoment (obj) {
  1672. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  1673. }
  1674. function absFloor (number) {
  1675. if (number < 0) {
  1676. // -0 -> 0
  1677. return Math.ceil(number) || 0;
  1678. } else {
  1679. return Math.floor(number);
  1680. }
  1681. }
  1682. function toInt(argumentForCoercion) {
  1683. var coercedNumber = +argumentForCoercion,
  1684. value = 0;
  1685. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  1686. value = absFloor(coercedNumber);
  1687. }
  1688. return value;
  1689. }
  1690. // compare two arrays, return the number of differences
  1691. function compareArrays(array1, array2, dontConvert) {
  1692. var len = Math.min(array1.length, array2.length),
  1693. lengthDiff = Math.abs(array1.length - array2.length),
  1694. diffs = 0,
  1695. i;
  1696. for (i = 0; i < len; i++) {
  1697. if ((dontConvert && array1[i] !== array2[i]) ||
  1698. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  1699. diffs++;
  1700. }
  1701. }
  1702. return diffs + lengthDiff;
  1703. }
  1704. function warn(msg) {
  1705. if (hooks.suppressDeprecationWarnings === false &&
  1706. (typeof console !== 'undefined') && console.warn) {
  1707. console.warn('Deprecation warning: ' + msg);
  1708. }
  1709. }
  1710. function deprecate(msg, fn) {
  1711. var firstTime = true;
  1712. return extend(function () {
  1713. if (hooks.deprecationHandler != null) {
  1714. hooks.deprecationHandler(null, msg);
  1715. }
  1716. if (firstTime) {
  1717. var args = [];
  1718. var arg;
  1719. for (var i = 0; i < arguments.length; i++) {
  1720. arg = '';
  1721. if (typeof arguments[i] === 'object') {
  1722. arg += '\n[' + i + '] ';
  1723. for (var key in arguments[0]) {
  1724. arg += key + ': ' + arguments[0][key] + ', ';
  1725. }
  1726. arg = arg.slice(0, -2); // Remove trailing comma and space
  1727. } else {
  1728. arg = arguments[i];
  1729. }
  1730. args.push(arg);
  1731. }
  1732. warn(msg + '\nArguments: ' + Array.prototype.slice.call(args).join('') + '\n' + (new Error()).stack);
  1733. firstTime = false;
  1734. }
  1735. return fn.apply(this, arguments);
  1736. }, fn);
  1737. }
  1738. var deprecations = {};
  1739. function deprecateSimple(name, msg) {
  1740. if (hooks.deprecationHandler != null) {
  1741. hooks.deprecationHandler(name, msg);
  1742. }
  1743. if (!deprecations[name]) {
  1744. warn(msg);
  1745. deprecations[name] = true;
  1746. }
  1747. }
  1748. hooks.suppressDeprecationWarnings = false;
  1749. hooks.deprecationHandler = null;
  1750. function isFunction(input) {
  1751. return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
  1752. }
  1753. function set (config) {
  1754. var prop, i;
  1755. for (i in config) {
  1756. prop = config[i];
  1757. if (isFunction(prop)) {
  1758. this[i] = prop;
  1759. } else {
  1760. this['_' + i] = prop;
  1761. }
  1762. }
  1763. this._config = config;
  1764. // Lenient ordinal parsing accepts just a number in addition to
  1765. // number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
  1766. // TODO: Remove "ordinalParse" fallback in next major release.
  1767. this._dayOfMonthOrdinalParseLenient = new RegExp(
  1768. (this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
  1769. '|' + (/\d{1,2}/).source);
  1770. }
  1771. function mergeConfigs(parentConfig, childConfig) {
  1772. var res = extend({}, parentConfig), prop;
  1773. for (prop in childConfig) {
  1774. if (hasOwnProp(childConfig, prop)) {
  1775. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  1776. res[prop] = {};
  1777. extend(res[prop], parentConfig[prop]);
  1778. extend(res[prop], childConfig[prop]);
  1779. } else if (childConfig[prop] != null) {
  1780. res[prop] = childConfig[prop];
  1781. } else {
  1782. delete res[prop];
  1783. }
  1784. }
  1785. }
  1786. for (prop in parentConfig) {
  1787. if (hasOwnProp(parentConfig, prop) &&
  1788. !hasOwnProp(childConfig, prop) &&
  1789. isObject(parentConfig[prop])) {
  1790. // make sure changes to properties don't modify parent config
  1791. res[prop] = extend({}, res[prop]);
  1792. }
  1793. }
  1794. return res;
  1795. }
  1796. function Locale(config) {
  1797. if (config != null) {
  1798. this.set(config);
  1799. }
  1800. }
  1801. var keys;
  1802. if (Object.keys) {
  1803. keys = Object.keys;
  1804. } else {
  1805. keys = function (obj) {
  1806. var i, res = [];
  1807. for (i in obj) {
  1808. if (hasOwnProp(obj, i)) {
  1809. res.push(i);
  1810. }
  1811. }
  1812. return res;
  1813. };
  1814. }
  1815. var defaultCalendar = {
  1816. sameDay : '[Today at] LT',
  1817. nextDay : '[Tomorrow at] LT',
  1818. nextWeek : 'dddd [at] LT',
  1819. lastDay : '[Yesterday at] LT',
  1820. lastWeek : '[Last] dddd [at] LT',
  1821. sameElse : 'L'
  1822. };
  1823. function calendar (key, mom, now) {
  1824. var output = this._calendar[key] || this._calendar['sameElse'];
  1825. return isFunction(output) ? output.call(mom, now) : output;
  1826. }
  1827. var defaultLongDateFormat = {
  1828. LTS : 'h:mm:ss A',
  1829. LT : 'h:mm A',
  1830. L : 'MM/DD/YYYY',
  1831. LL : 'MMMM D, YYYY',
  1832. LLL : 'MMMM D, YYYY h:mm A',
  1833. LLLL : 'dddd, MMMM D, YYYY h:mm A'
  1834. };
  1835. function longDateFormat (key) {
  1836. var format = this._longDateFormat[key],
  1837. formatUpper = this._longDateFormat[key.toUpperCase()];
  1838. if (format || !formatUpper) {
  1839. return format;
  1840. }
  1841. this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
  1842. return val.slice(1);
  1843. });
  1844. return this._longDateFormat[key];
  1845. }
  1846. var defaultInvalidDate = 'Invalid date';
  1847. function invalidDate () {
  1848. return this._invalidDate;
  1849. }
  1850. var defaultOrdinal = '%d';
  1851. var defaultDayOfMonthOrdinalParse = /\d{1,2}/;
  1852. function ordinal (number) {
  1853. return this._ordinal.replace('%d', number);
  1854. }
  1855. var defaultRelativeTime = {
  1856. future : 'in %s',
  1857. past : '%s ago',
  1858. s : 'a few seconds',
  1859. ss : '%d seconds',
  1860. m : 'a minute',
  1861. mm : '%d minutes',
  1862. h : 'an hour',
  1863. hh : '%d hours',
  1864. d : 'a day',
  1865. dd : '%d days',
  1866. M : 'a month',
  1867. MM : '%d months',
  1868. y : 'a year',
  1869. yy : '%d years'
  1870. };
  1871. function relativeTime (number, withoutSuffix, string, isFuture) {
  1872. var output = this._relativeTime[string];
  1873. return (isFunction(output)) ?
  1874. output(number, withoutSuffix, string, isFuture) :
  1875. output.replace(/%d/i, number);
  1876. }
  1877. function pastFuture (diff, output) {
  1878. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  1879. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  1880. }
  1881. var aliases = {};
  1882. function addUnitAlias (unit, shorthand) {
  1883. var lowerCase = unit.toLowerCase();
  1884. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  1885. }
  1886. function normalizeUnits(units) {
  1887. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  1888. }
  1889. function normalizeObjectUnits(inputObject) {
  1890. var normalizedInput = {},
  1891. normalizedProp,
  1892. prop;
  1893. for (prop in inputObject) {
  1894. if (hasOwnProp(inputObject, prop)) {
  1895. normalizedProp = normalizeUnits(prop);
  1896. if (normalizedProp) {
  1897. normalizedInput[normalizedProp] = inputObject[prop];
  1898. }
  1899. }
  1900. }
  1901. return normalizedInput;
  1902. }
  1903. var priorities = {};
  1904. function addUnitPriority(unit, priority) {
  1905. priorities[unit] = priority;
  1906. }
  1907. function getPrioritizedUnits(unitsObj) {
  1908. var units = [];
  1909. for (var u in unitsObj) {
  1910. units.push({unit: u, priority: priorities[u]});
  1911. }
  1912. units.sort(function (a, b) {
  1913. return a.priority - b.priority;
  1914. });
  1915. return units;
  1916. }
  1917. function zeroFill(number, targetLength, forceSign) {
  1918. var absNumber = '' + Math.abs(number),
  1919. zerosToFill = targetLength - absNumber.length,
  1920. sign = number >= 0;
  1921. return (sign ? (forceSign ? '+' : '') : '-') +
  1922. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
  1923. }
  1924. var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
  1925. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  1926. var formatFunctions = {};
  1927. var formatTokenFunctions = {};
  1928. // token: 'M'
  1929. // padded: ['MM', 2]
  1930. // ordinal: 'Mo'
  1931. // callback: function () { this.month() + 1 }
  1932. function addFormatToken (token, padded, ordinal, callback) {
  1933. var func = callback;
  1934. if (typeof callback === 'string') {
  1935. func = function () {
  1936. return this[callback]();
  1937. };
  1938. }
  1939. if (token) {
  1940. formatTokenFunctions[token] = func;
  1941. }
  1942. if (padded) {
  1943. formatTokenFunctions[padded[0]] = function () {
  1944. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  1945. };
  1946. }
  1947. if (ordinal) {
  1948. formatTokenFunctions[ordinal] = function () {
  1949. return this.localeData().ordinal(func.apply(this, arguments), token);
  1950. };
  1951. }
  1952. }
  1953. function removeFormattingTokens(input) {
  1954. if (input.match(/\[[\s\S]/)) {
  1955. return input.replace(/^\[|\]$/g, '');
  1956. }
  1957. return input.replace(/\\/g, '');
  1958. }
  1959. function makeFormatFunction(format) {
  1960. var array = format.match(formattingTokens), i, length;
  1961. for (i = 0, length = array.length; i < length; i++) {
  1962. if (formatTokenFunctions[array[i]]) {
  1963. array[i] = formatTokenFunctions[array[i]];
  1964. } else {
  1965. array[i] = removeFormattingTokens(array[i]);
  1966. }
  1967. }
  1968. return function (mom) {
  1969. var output = '', i;
  1970. for (i = 0; i < length; i++) {
  1971. output += isFunction(array[i]) ? array[i].call(mom, format) : array[i];
  1972. }
  1973. return output;
  1974. };
  1975. }
  1976. // format date using native date object
  1977. function formatMoment(m, format) {
  1978. if (!m.isValid()) {
  1979. return m.localeData().invalidDate();
  1980. }
  1981. format = expandFormat(format, m.localeData());
  1982. formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
  1983. return formatFunctions[format](m);
  1984. }
  1985. function expandFormat(format, locale) {
  1986. var i = 5;
  1987. function replaceLongDateFormatTokens(input) {
  1988. return locale.longDateFormat(input) || input;
  1989. }
  1990. localFormattingTokens.lastIndex = 0;
  1991. while (i >= 0 && localFormattingTokens.test(format)) {
  1992. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  1993. localFormattingTokens.lastIndex = 0;
  1994. i -= 1;
  1995. }
  1996. return format;
  1997. }
  1998. var match1 = /\d/; // 0 - 9
  1999. var match2 = /\d\d/; // 00 - 99
  2000. var match3 = /\d{3}/; // 000 - 999
  2001. var match4 = /\d{4}/; // 0000 - 9999
  2002. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  2003. var match1to2 = /\d\d?/; // 0 - 99
  2004. var match3to4 = /\d\d\d\d?/; // 999 - 9999
  2005. var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  2006. var match1to3 = /\d{1,3}/; // 0 - 999
  2007. var match1to4 = /\d{1,4}/; // 0 - 9999
  2008. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  2009. var matchUnsigned = /\d+/; // 0 - inf
  2010. var matchSigned = /[+-]?\d+/; // -inf - inf
  2011. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  2012. var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  2013. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  2014. // any word (or two) characters or numbers including two/three word month in arabic.
  2015. // includes scottish gaelic two word and hyphenated months
  2016. var matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i;
  2017. var regexes = {};
  2018. function addRegexToken (token, regex, strictRegex) {
  2019. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  2020. return (isStrict && strictRegex) ? strictRegex : regex;
  2021. };
  2022. }
  2023. function getParseRegexForToken (token, config) {
  2024. if (!hasOwnProp(regexes, token)) {
  2025. return new RegExp(unescapeFormat(token));
  2026. }
  2027. return regexes[token](config._strict, config._locale);
  2028. }
  2029. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  2030. function unescapeFormat(s) {
  2031. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  2032. return p1 || p2 || p3 || p4;
  2033. }));
  2034. }
  2035. function regexEscape(s) {
  2036. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  2037. }
  2038. var tokens = {};
  2039. function addParseToken (token, callback) {
  2040. var i, func = callback;
  2041. if (typeof token === 'string') {
  2042. token = [token];
  2043. }
  2044. if (isNumber(callback)) {
  2045. func = function (input, array) {
  2046. array[callback] = toInt(input);
  2047. };
  2048. }
  2049. for (i = 0; i < token.length; i++) {
  2050. tokens[token[i]] = func;
  2051. }
  2052. }
  2053. function addWeekParseToken (token, callback) {
  2054. addParseToken(token, function (input, array, config, token) {
  2055. config._w = config._w || {};
  2056. callback(input, config._w, config, token);
  2057. });
  2058. }
  2059. function addTimeToArrayFromToken(token, input, config) {
  2060. if (input != null && hasOwnProp(tokens, token)) {
  2061. tokens[token](input, config._a, config, token);
  2062. }
  2063. }
  2064. var YEAR = 0;
  2065. var MONTH = 1;
  2066. var DATE = 2;
  2067. var HOUR = 3;
  2068. var MINUTE = 4;
  2069. var SECOND = 5;
  2070. var MILLISECOND = 6;
  2071. var WEEK = 7;
  2072. var WEEKDAY = 8;
  2073. // FORMATTING
  2074. addFormatToken('Y', 0, 0, function () {
  2075. var y = this.year();
  2076. return y <= 9999 ? '' + y : '+' + y;
  2077. });
  2078. addFormatToken(0, ['YY', 2], 0, function () {
  2079. return this.year() % 100;
  2080. });
  2081. addFormatToken(0, ['YYYY', 4], 0, 'year');
  2082. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  2083. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  2084. // ALIASES
  2085. addUnitAlias('year', 'y');
  2086. // PRIORITIES
  2087. addUnitPriority('year', 1);
  2088. // PARSING
  2089. addRegexToken('Y', matchSigned);
  2090. addRegexToken('YY', match1to2, match2);
  2091. addRegexToken('YYYY', match1to4, match4);
  2092. addRegexToken('YYYYY', match1to6, match6);
  2093. addRegexToken('YYYYYY', match1to6, match6);
  2094. addParseToken(['YYYYY', 'YYYYYY'], YEAR);
  2095. addParseToken('YYYY', function (input, array) {
  2096. array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
  2097. });
  2098. addParseToken('YY', function (input, array) {
  2099. array[YEAR] = hooks.parseTwoDigitYear(input);
  2100. });
  2101. addParseToken('Y', function (input, array) {
  2102. array[YEAR] = parseInt(input, 10);
  2103. });
  2104. // HELPERS
  2105. function daysInYear(year) {
  2106. return isLeapYear(year) ? 366 : 365;
  2107. }
  2108. function isLeapYear(year) {
  2109. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  2110. }
  2111. // HOOKS
  2112. hooks.parseTwoDigitYear = function (input) {
  2113. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  2114. };
  2115. // MOMENTS
  2116. var getSetYear = makeGetSet('FullYear', true);
  2117. function getIsLeapYear () {
  2118. return isLeapYear(this.year());
  2119. }
  2120. function makeGetSet (unit, keepTime) {
  2121. return function (value) {
  2122. if (value != null) {
  2123. set$1(this, unit, value);
  2124. hooks.updateOffset(this, keepTime);
  2125. return this;
  2126. } else {
  2127. return get(this, unit);
  2128. }
  2129. };
  2130. }
  2131. function get (mom, unit) {
  2132. return mom.isValid() ?
  2133. mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
  2134. }
  2135. function set$1 (mom, unit, value) {
  2136. if (mom.isValid() && !isNaN(value)) {
  2137. if (unit === 'FullYear' && isLeapYear(mom.year()) && mom.month() === 1 && mom.date() === 29) {
  2138. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value, mom.month(), daysInMonth(value, mom.month()));
  2139. }
  2140. else {
  2141. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  2142. }
  2143. }
  2144. }
  2145. // MOMENTS
  2146. function stringGet (units) {
  2147. units = normalizeUnits(units);
  2148. if (isFunction(this[units])) {
  2149. return this[units]();
  2150. }
  2151. return this;
  2152. }
  2153. function stringSet (units, value) {
  2154. if (typeof units === 'object') {
  2155. units = normalizeObjectUnits(units);
  2156. var prioritized = getPrioritizedUnits(units);
  2157. for (var i = 0; i < prioritized.length; i++) {
  2158. this[prioritized[i].unit](units[prioritized[i].unit]);
  2159. }
  2160. } else {
  2161. units = normalizeUnits(units);
  2162. if (isFunction(this[units])) {
  2163. return this[units](value);
  2164. }
  2165. }
  2166. return this;
  2167. }
  2168. function mod(n, x) {
  2169. return ((n % x) + x) % x;
  2170. }
  2171. var indexOf;
  2172. if (Array.prototype.indexOf) {
  2173. indexOf = Array.prototype.indexOf;
  2174. } else {
  2175. indexOf = function (o) {
  2176. // I know
  2177. var i;
  2178. for (i = 0; i < this.length; ++i) {
  2179. if (this[i] === o) {
  2180. return i;
  2181. }
  2182. }
  2183. return -1;
  2184. };
  2185. }
  2186. function daysInMonth(year, month) {
  2187. if (isNaN(year) || isNaN(month)) {
  2188. return NaN;
  2189. }
  2190. var modMonth = mod(month, 12);
  2191. year += (month - modMonth) / 12;
  2192. return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2);
  2193. }
  2194. // FORMATTING
  2195. addFormatToken('M', ['MM', 2], 'Mo', function () {
  2196. return this.month() + 1;
  2197. });
  2198. addFormatToken('MMM', 0, 0, function (format) {
  2199. return this.localeData().monthsShort(this, format);
  2200. });
  2201. addFormatToken('MMMM', 0, 0, function (format) {
  2202. return this.localeData().months(this, format);
  2203. });
  2204. // ALIASES
  2205. addUnitAlias('month', 'M');
  2206. // PRIORITY
  2207. addUnitPriority('month', 8);
  2208. // PARSING
  2209. addRegexToken('M', match1to2);
  2210. addRegexToken('MM', match1to2, match2);
  2211. addRegexToken('MMM', function (isStrict, locale) {
  2212. return locale.monthsShortRegex(isStrict);
  2213. });
  2214. addRegexToken('MMMM', function (isStrict, locale) {
  2215. return locale.monthsRegex(isStrict);
  2216. });
  2217. addParseToken(['M', 'MM'], function (input, array) {
  2218. array[MONTH] = toInt(input) - 1;
  2219. });
  2220. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  2221. var month = config._locale.monthsParse(input, token, config._strict);
  2222. // if we didn't find a month name, mark the date as invalid.
  2223. if (month != null) {
  2224. array[MONTH] = month;
  2225. } else {
  2226. getParsingFlags(config).invalidMonth = input;
  2227. }
  2228. });
  2229. // LOCALES
  2230. var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/;
  2231. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  2232. function localeMonths (m, format) {
  2233. if (!m) {
  2234. return isArray(this._months) ? this._months :
  2235. this._months['standalone'];
  2236. }
  2237. return isArray(this._months) ? this._months[m.month()] :
  2238. this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()];
  2239. }
  2240. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  2241. function localeMonthsShort (m, format) {
  2242. if (!m) {
  2243. return isArray(this._monthsShort) ? this._monthsShort :
  2244. this._monthsShort['standalone'];
  2245. }
  2246. return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
  2247. this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  2248. }
  2249. function handleStrictParse(monthName, format, strict) {
  2250. var i, ii, mom, llc = monthName.toLocaleLowerCase();
  2251. if (!this._monthsParse) {
  2252. // this is not used
  2253. this._monthsParse = [];
  2254. this._longMonthsParse = [];
  2255. this._shortMonthsParse = [];
  2256. for (i = 0; i < 12; ++i) {
  2257. mom = createUTC([2000, i]);
  2258. this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
  2259. this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
  2260. }
  2261. }
  2262. if (strict) {
  2263. if (format === 'MMM') {
  2264. ii = indexOf.call(this._shortMonthsParse, llc);
  2265. return ii !== -1 ? ii : null;
  2266. } else {
  2267. ii = indexOf.call(this._longMonthsParse, llc);
  2268. return ii !== -1 ? ii : null;
  2269. }
  2270. } else {
  2271. if (format === 'MMM') {
  2272. ii = indexOf.call(this._shortMonthsParse, llc);
  2273. if (ii !== -1) {
  2274. return ii;
  2275. }
  2276. ii = indexOf.call(this._longMonthsParse, llc);
  2277. return ii !== -1 ? ii : null;
  2278. } else {
  2279. ii = indexOf.call(this._longMonthsParse, llc);
  2280. if (ii !== -1) {
  2281. return ii;
  2282. }
  2283. ii = indexOf.call(this._shortMonthsParse, llc);
  2284. return ii !== -1 ? ii : null;
  2285. }
  2286. }
  2287. }
  2288. function localeMonthsParse (monthName, format, strict) {
  2289. var i, mom, regex;
  2290. if (this._monthsParseExact) {
  2291. return handleStrictParse.call(this, monthName, format, strict);
  2292. }
  2293. if (!this._monthsParse) {
  2294. this._monthsParse = [];
  2295. this._longMonthsParse = [];
  2296. this._shortMonthsParse = [];
  2297. }
  2298. // TODO: add sorting
  2299. // Sorting makes sure if one month (or abbr) is a prefix of another
  2300. // see sorting in computeMonthsParse
  2301. for (i = 0; i < 12; i++) {
  2302. // make the regex if we don't have it already
  2303. mom = createUTC([2000, i]);
  2304. if (strict && !this._longMonthsParse[i]) {
  2305. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  2306. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  2307. }
  2308. if (!strict && !this._monthsParse[i]) {
  2309. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  2310. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  2311. }
  2312. // test the regex
  2313. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  2314. return i;
  2315. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  2316. return i;
  2317. } else if (!strict && this._monthsParse[i].test(monthName)) {
  2318. return i;
  2319. }
  2320. }
  2321. }
  2322. // MOMENTS
  2323. function setMonth (mom, value) {
  2324. var dayOfMonth;
  2325. if (!mom.isValid()) {
  2326. // No op
  2327. return mom;
  2328. }
  2329. if (typeof value === 'string') {
  2330. if (/^\d+$/.test(value)) {
  2331. value = toInt(value);
  2332. } else {
  2333. value = mom.localeData().monthsParse(value);
  2334. // TODO: Another silent failure?
  2335. if (!isNumber(value)) {
  2336. return mom;
  2337. }
  2338. }
  2339. }
  2340. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  2341. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  2342. return mom;
  2343. }
  2344. function getSetMonth (value) {
  2345. if (value != null) {
  2346. setMonth(this, value);
  2347. hooks.updateOffset(this, true);
  2348. return this;
  2349. } else {
  2350. return get(this, 'Month');
  2351. }
  2352. }
  2353. function getDaysInMonth () {
  2354. return daysInMonth(this.year(), this.month());
  2355. }
  2356. var defaultMonthsShortRegex = matchWord;
  2357. function monthsShortRegex (isStrict) {
  2358. if (this._monthsParseExact) {
  2359. if (!hasOwnProp(this, '_monthsRegex')) {
  2360. computeMonthsParse.call(this);
  2361. }
  2362. if (isStrict) {
  2363. return this._monthsShortStrictRegex;
  2364. } else {
  2365. return this._monthsShortRegex;
  2366. }
  2367. } else {
  2368. if (!hasOwnProp(this, '_monthsShortRegex')) {
  2369. this._monthsShortRegex = defaultMonthsShortRegex;
  2370. }
  2371. return this._monthsShortStrictRegex && isStrict ?
  2372. this._monthsShortStrictRegex : this._monthsShortRegex;
  2373. }
  2374. }
  2375. var defaultMonthsRegex = matchWord;
  2376. function monthsRegex (isStrict) {
  2377. if (this._monthsParseExact) {
  2378. if (!hasOwnProp(this, '_monthsRegex')) {
  2379. computeMonthsParse.call(this);
  2380. }
  2381. if (isStrict) {
  2382. return this._monthsStrictRegex;
  2383. } else {
  2384. return this._monthsRegex;
  2385. }
  2386. } else {
  2387. if (!hasOwnProp(this, '_monthsRegex')) {
  2388. this._monthsRegex = defaultMonthsRegex;
  2389. }
  2390. return this._monthsStrictRegex && isStrict ?
  2391. this._monthsStrictRegex : this._monthsRegex;
  2392. }
  2393. }
  2394. function computeMonthsParse () {
  2395. function cmpLenRev(a, b) {
  2396. return b.length - a.length;
  2397. }
  2398. var shortPieces = [], longPieces = [], mixedPieces = [],
  2399. i, mom;
  2400. for (i = 0; i < 12; i++) {
  2401. // make the regex if we don't have it already
  2402. mom = createUTC([2000, i]);
  2403. shortPieces.push(this.monthsShort(mom, ''));
  2404. longPieces.push(this.months(mom, ''));
  2405. mixedPieces.push(this.months(mom, ''));
  2406. mixedPieces.push(this.monthsShort(mom, ''));
  2407. }
  2408. // Sorting makes sure if one month (or abbr) is a prefix of another it
  2409. // will match the longer piece.
  2410. shortPieces.sort(cmpLenRev);
  2411. longPieces.sort(cmpLenRev);
  2412. mixedPieces.sort(cmpLenRev);
  2413. for (i = 0; i < 12; i++) {
  2414. shortPieces[i] = regexEscape(shortPieces[i]);
  2415. longPieces[i] = regexEscape(longPieces[i]);
  2416. }
  2417. for (i = 0; i < 24; i++) {
  2418. mixedPieces[i] = regexEscape(mixedPieces[i]);
  2419. }
  2420. this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  2421. this._monthsShortRegex = this._monthsRegex;
  2422. this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  2423. this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  2424. }
  2425. function createDate (y, m, d, h, M, s, ms) {
  2426. // can't just apply() to create a date:
  2427. // https://stackoverflow.com/q/181348
  2428. var date = new Date(y, m, d, h, M, s, ms);
  2429. // the date constructor remaps years 0-99 to 1900-1999
  2430. if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  2431. date.setFullYear(y);
  2432. }
  2433. return date;
  2434. }
  2435. function createUTCDate (y) {
  2436. var date = new Date(Date.UTC.apply(null, arguments));
  2437. // the Date.UTC function remaps years 0-99 to 1900-1999
  2438. if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  2439. date.setUTCFullYear(y);
  2440. }
  2441. return date;
  2442. }
  2443. // start-of-first-week - start-of-year
  2444. function firstWeekOffset(year, dow, doy) {
  2445. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  2446. fwd = 7 + dow - doy,
  2447. // first-week day local weekday -- which local weekday is fwd
  2448. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  2449. return -fwdlw + fwd - 1;
  2450. }
  2451. // https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  2452. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  2453. var localWeekday = (7 + weekday - dow) % 7,
  2454. weekOffset = firstWeekOffset(year, dow, doy),
  2455. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  2456. resYear, resDayOfYear;
  2457. if (dayOfYear <= 0) {
  2458. resYear = year - 1;
  2459. resDayOfYear = daysInYear(resYear) + dayOfYear;
  2460. } else if (dayOfYear > daysInYear(year)) {
  2461. resYear = year + 1;
  2462. resDayOfYear = dayOfYear - daysInYear(year);
  2463. } else {
  2464. resYear = year;
  2465. resDayOfYear = dayOfYear;
  2466. }
  2467. return {
  2468. year: resYear,
  2469. dayOfYear: resDayOfYear
  2470. };
  2471. }
  2472. function weekOfYear(mom, dow, doy) {
  2473. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  2474. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  2475. resWeek, resYear;
  2476. if (week < 1) {
  2477. resYear = mom.year() - 1;
  2478. resWeek = week + weeksInYear(resYear, dow, doy);
  2479. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  2480. resWeek = week - weeksInYear(mom.year(), dow, doy);
  2481. resYear = mom.year() + 1;
  2482. } else {
  2483. resYear = mom.year();
  2484. resWeek = week;
  2485. }
  2486. return {
  2487. week: resWeek,
  2488. year: resYear
  2489. };
  2490. }
  2491. function weeksInYear(year, dow, doy) {
  2492. var weekOffset = firstWeekOffset(year, dow, doy),
  2493. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  2494. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  2495. }
  2496. // FORMATTING
  2497. addFormatToken('w', ['ww', 2], 'wo', 'week');
  2498. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  2499. // ALIASES
  2500. addUnitAlias('week', 'w');
  2501. addUnitAlias('isoWeek', 'W');
  2502. // PRIORITIES
  2503. addUnitPriority('week', 5);
  2504. addUnitPriority('isoWeek', 5);
  2505. // PARSING
  2506. addRegexToken('w', match1to2);
  2507. addRegexToken('ww', match1to2, match2);
  2508. addRegexToken('W', match1to2);
  2509. addRegexToken('WW', match1to2, match2);
  2510. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  2511. week[token.substr(0, 1)] = toInt(input);
  2512. });
  2513. // HELPERS
  2514. // LOCALES
  2515. function localeWeek (mom) {
  2516. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  2517. }
  2518. var defaultLocaleWeek = {
  2519. dow : 0, // Sunday is the first day of the week.
  2520. doy : 6 // The week that contains Jan 1st is the first week of the year.
  2521. };
  2522. function localeFirstDayOfWeek () {
  2523. return this._week.dow;
  2524. }
  2525. function localeFirstDayOfYear () {
  2526. return this._week.doy;
  2527. }
  2528. // MOMENTS
  2529. function getSetWeek (input) {
  2530. var week = this.localeData().week(this);
  2531. return input == null ? week : this.add((input - week) * 7, 'd');
  2532. }
  2533. function getSetISOWeek (input) {
  2534. var week = weekOfYear(this, 1, 4).week;
  2535. return input == null ? week : this.add((input - week) * 7, 'd');
  2536. }
  2537. // FORMATTING
  2538. addFormatToken('d', 0, 'do', 'day');
  2539. addFormatToken('dd', 0, 0, function (format) {
  2540. return this.localeData().weekdaysMin(this, format);
  2541. });
  2542. addFormatToken('ddd', 0, 0, function (format) {
  2543. return this.localeData().weekdaysShort(this, format);
  2544. });
  2545. addFormatToken('dddd', 0, 0, function (format) {
  2546. return this.localeData().weekdays(this, format);
  2547. });
  2548. addFormatToken('e', 0, 0, 'weekday');
  2549. addFormatToken('E', 0, 0, 'isoWeekday');
  2550. // ALIASES
  2551. addUnitAlias('day', 'd');
  2552. addUnitAlias('weekday', 'e');
  2553. addUnitAlias('isoWeekday', 'E');
  2554. // PRIORITY
  2555. addUnitPriority('day', 11);
  2556. addUnitPriority('weekday', 11);
  2557. addUnitPriority('isoWeekday', 11);
  2558. // PARSING
  2559. addRegexToken('d', match1to2);
  2560. addRegexToken('e', match1to2);
  2561. addRegexToken('E', match1to2);
  2562. addRegexToken('dd', function (isStrict, locale) {
  2563. return locale.weekdaysMinRegex(isStrict);
  2564. });
  2565. addRegexToken('ddd', function (isStrict, locale) {
  2566. return locale.weekdaysShortRegex(isStrict);
  2567. });
  2568. addRegexToken('dddd', function (isStrict, locale) {
  2569. return locale.weekdaysRegex(isStrict);
  2570. });
  2571. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  2572. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  2573. // if we didn't get a weekday name, mark the date as invalid
  2574. if (weekday != null) {
  2575. week.d = weekday;
  2576. } else {
  2577. getParsingFlags(config).invalidWeekday = input;
  2578. }
  2579. });
  2580. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  2581. week[token] = toInt(input);
  2582. });
  2583. // HELPERS
  2584. function parseWeekday(input, locale) {
  2585. if (typeof input !== 'string') {
  2586. return input;
  2587. }
  2588. if (!isNaN(input)) {
  2589. return parseInt(input, 10);
  2590. }
  2591. input = locale.weekdaysParse(input);
  2592. if (typeof input === 'number') {
  2593. return input;
  2594. }
  2595. return null;
  2596. }
  2597. function parseIsoWeekday(input, locale) {
  2598. if (typeof input === 'string') {
  2599. return locale.weekdaysParse(input) % 7 || 7;
  2600. }
  2601. return isNaN(input) ? null : input;
  2602. }
  2603. // LOCALES
  2604. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  2605. function localeWeekdays (m, format) {
  2606. if (!m) {
  2607. return isArray(this._weekdays) ? this._weekdays :
  2608. this._weekdays['standalone'];
  2609. }
  2610. return isArray(this._weekdays) ? this._weekdays[m.day()] :
  2611. this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  2612. }
  2613. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  2614. function localeWeekdaysShort (m) {
  2615. return (m) ? this._weekdaysShort[m.day()] : this._weekdaysShort;
  2616. }
  2617. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  2618. function localeWeekdaysMin (m) {
  2619. return (m) ? this._weekdaysMin[m.day()] : this._weekdaysMin;
  2620. }
  2621. function handleStrictParse$1(weekdayName, format, strict) {
  2622. var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
  2623. if (!this._weekdaysParse) {
  2624. this._weekdaysParse = [];
  2625. this._shortWeekdaysParse = [];
  2626. this._minWeekdaysParse = [];
  2627. for (i = 0; i < 7; ++i) {
  2628. mom = createUTC([2000, 1]).day(i);
  2629. this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
  2630. this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
  2631. this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  2632. }
  2633. }
  2634. if (strict) {
  2635. if (format === 'dddd') {
  2636. ii = indexOf.call(this._weekdaysParse, llc);
  2637. return ii !== -1 ? ii : null;
  2638. } else if (format === 'ddd') {
  2639. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2640. return ii !== -1 ? ii : null;
  2641. } else {
  2642. ii = indexOf.call(this._minWeekdaysParse, llc);
  2643. return ii !== -1 ? ii : null;
  2644. }
  2645. } else {
  2646. if (format === 'dddd') {
  2647. ii = indexOf.call(this._weekdaysParse, llc);
  2648. if (ii !== -1) {
  2649. return ii;
  2650. }
  2651. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2652. if (ii !== -1) {
  2653. return ii;
  2654. }
  2655. ii = indexOf.call(this._minWeekdaysParse, llc);
  2656. return ii !== -1 ? ii : null;
  2657. } else if (format === 'ddd') {
  2658. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2659. if (ii !== -1) {
  2660. return ii;
  2661. }
  2662. ii = indexOf.call(this._weekdaysParse, llc);
  2663. if (ii !== -1) {
  2664. return ii;
  2665. }
  2666. ii = indexOf.call(this._minWeekdaysParse, llc);
  2667. return ii !== -1 ? ii : null;
  2668. } else {
  2669. ii = indexOf.call(this._minWeekdaysParse, llc);
  2670. if (ii !== -1) {
  2671. return ii;
  2672. }
  2673. ii = indexOf.call(this._weekdaysParse, llc);
  2674. if (ii !== -1) {
  2675. return ii;
  2676. }
  2677. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2678. return ii !== -1 ? ii : null;
  2679. }
  2680. }
  2681. }
  2682. function localeWeekdaysParse (weekdayName, format, strict) {
  2683. var i, mom, regex;
  2684. if (this._weekdaysParseExact) {
  2685. return handleStrictParse$1.call(this, weekdayName, format, strict);
  2686. }
  2687. if (!this._weekdaysParse) {
  2688. this._weekdaysParse = [];
  2689. this._minWeekdaysParse = [];
  2690. this._shortWeekdaysParse = [];
  2691. this._fullWeekdaysParse = [];
  2692. }
  2693. for (i = 0; i < 7; i++) {
  2694. // make the regex if we don't have it already
  2695. mom = createUTC([2000, 1]).day(i);
  2696. if (strict && !this._fullWeekdaysParse[i]) {
  2697. this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
  2698. this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
  2699. this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
  2700. }
  2701. if (!this._weekdaysParse[i]) {
  2702. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  2703. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  2704. }
  2705. // test the regex
  2706. if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  2707. return i;
  2708. } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  2709. return i;
  2710. } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  2711. return i;
  2712. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  2713. return i;
  2714. }
  2715. }
  2716. }
  2717. // MOMENTS
  2718. function getSetDayOfWeek (input) {
  2719. if (!this.isValid()) {
  2720. return input != null ? this : NaN;
  2721. }
  2722. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  2723. if (input != null) {
  2724. input = parseWeekday(input, this.localeData());
  2725. return this.add(input - day, 'd');
  2726. } else {
  2727. return day;
  2728. }
  2729. }
  2730. function getSetLocaleDayOfWeek (input) {
  2731. if (!this.isValid()) {
  2732. return input != null ? this : NaN;
  2733. }
  2734. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  2735. return input == null ? weekday : this.add(input - weekday, 'd');
  2736. }
  2737. function getSetISODayOfWeek (input) {
  2738. if (!this.isValid()) {
  2739. return input != null ? this : NaN;
  2740. }
  2741. // behaves the same as moment#day except
  2742. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  2743. // as a setter, sunday should belong to the previous week.
  2744. if (input != null) {
  2745. var weekday = parseIsoWeekday(input, this.localeData());
  2746. return this.day(this.day() % 7 ? weekday : weekday - 7);
  2747. } else {
  2748. return this.day() || 7;
  2749. }
  2750. }
  2751. var defaultWeekdaysRegex = matchWord;
  2752. function weekdaysRegex (isStrict) {
  2753. if (this._weekdaysParseExact) {
  2754. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2755. computeWeekdaysParse.call(this);
  2756. }
  2757. if (isStrict) {
  2758. return this._weekdaysStrictRegex;
  2759. } else {
  2760. return this._weekdaysRegex;
  2761. }
  2762. } else {
  2763. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2764. this._weekdaysRegex = defaultWeekdaysRegex;
  2765. }
  2766. return this._weekdaysStrictRegex && isStrict ?
  2767. this._weekdaysStrictRegex : this._weekdaysRegex;
  2768. }
  2769. }
  2770. var defaultWeekdaysShortRegex = matchWord;
  2771. function weekdaysShortRegex (isStrict) {
  2772. if (this._weekdaysParseExact) {
  2773. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2774. computeWeekdaysParse.call(this);
  2775. }
  2776. if (isStrict) {
  2777. return this._weekdaysShortStrictRegex;
  2778. } else {
  2779. return this._weekdaysShortRegex;
  2780. }
  2781. } else {
  2782. if (!hasOwnProp(this, '_weekdaysShortRegex')) {
  2783. this._weekdaysShortRegex = defaultWeekdaysShortRegex;
  2784. }
  2785. return this._weekdaysShortStrictRegex && isStrict ?
  2786. this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
  2787. }
  2788. }
  2789. var defaultWeekdaysMinRegex = matchWord;
  2790. function weekdaysMinRegex (isStrict) {
  2791. if (this._weekdaysParseExact) {
  2792. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2793. computeWeekdaysParse.call(this);
  2794. }
  2795. if (isStrict) {
  2796. return this._weekdaysMinStrictRegex;
  2797. } else {
  2798. return this._weekdaysMinRegex;
  2799. }
  2800. } else {
  2801. if (!hasOwnProp(this, '_weekdaysMinRegex')) {
  2802. this._weekdaysMinRegex = defaultWeekdaysMinRegex;
  2803. }
  2804. return this._weekdaysMinStrictRegex && isStrict ?
  2805. this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
  2806. }
  2807. }
  2808. function computeWeekdaysParse () {
  2809. function cmpLenRev(a, b) {
  2810. return b.length - a.length;
  2811. }
  2812. var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
  2813. i, mom, minp, shortp, longp;
  2814. for (i = 0; i < 7; i++) {
  2815. // make the regex if we don't have it already
  2816. mom = createUTC([2000, 1]).day(i);
  2817. minp = this.weekdaysMin(mom, '');
  2818. shortp = this.weekdaysShort(mom, '');
  2819. longp = this.weekdays(mom, '');
  2820. minPieces.push(minp);
  2821. shortPieces.push(shortp);
  2822. longPieces.push(longp);
  2823. mixedPieces.push(minp);
  2824. mixedPieces.push(shortp);
  2825. mixedPieces.push(longp);
  2826. }
  2827. // Sorting makes sure if one weekday (or abbr) is a prefix of another it
  2828. // will match the longer piece.
  2829. minPieces.sort(cmpLenRev);
  2830. shortPieces.sort(cmpLenRev);
  2831. longPieces.sort(cmpLenRev);
  2832. mixedPieces.sort(cmpLenRev);
  2833. for (i = 0; i < 7; i++) {
  2834. shortPieces[i] = regexEscape(shortPieces[i]);
  2835. longPieces[i] = regexEscape(longPieces[i]);
  2836. mixedPieces[i] = regexEscape(mixedPieces[i]);
  2837. }
  2838. this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  2839. this._weekdaysShortRegex = this._weekdaysRegex;
  2840. this._weekdaysMinRegex = this._weekdaysRegex;
  2841. this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  2842. this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  2843. this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
  2844. }
  2845. // FORMATTING
  2846. function hFormat() {
  2847. return this.hours() % 12 || 12;
  2848. }
  2849. function kFormat() {
  2850. return this.hours() || 24;
  2851. }
  2852. addFormatToken('H', ['HH', 2], 0, 'hour');
  2853. addFormatToken('h', ['hh', 2], 0, hFormat);
  2854. addFormatToken('k', ['kk', 2], 0, kFormat);
  2855. addFormatToken('hmm', 0, 0, function () {
  2856. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  2857. });
  2858. addFormatToken('hmmss', 0, 0, function () {
  2859. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  2860. zeroFill(this.seconds(), 2);
  2861. });
  2862. addFormatToken('Hmm', 0, 0, function () {
  2863. return '' + this.hours() + zeroFill(this.minutes(), 2);
  2864. });
  2865. addFormatToken('Hmmss', 0, 0, function () {
  2866. return '' + this.hours() + zeroFill(this.minutes(), 2) +
  2867. zeroFill(this.seconds(), 2);
  2868. });
  2869. function meridiem (token, lowercase) {
  2870. addFormatToken(token, 0, 0, function () {
  2871. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  2872. });
  2873. }
  2874. meridiem('a', true);
  2875. meridiem('A', false);
  2876. // ALIASES
  2877. addUnitAlias('hour', 'h');
  2878. // PRIORITY
  2879. addUnitPriority('hour', 13);
  2880. // PARSING
  2881. function matchMeridiem (isStrict, locale) {
  2882. return locale._meridiemParse;
  2883. }
  2884. addRegexToken('a', matchMeridiem);
  2885. addRegexToken('A', matchMeridiem);
  2886. addRegexToken('H', match1to2);
  2887. addRegexToken('h', match1to2);
  2888. addRegexToken('k', match1to2);
  2889. addRegexToken('HH', match1to2, match2);
  2890. addRegexToken('hh', match1to2, match2);
  2891. addRegexToken('kk', match1to2, match2);
  2892. addRegexToken('hmm', match3to4);
  2893. addRegexToken('hmmss', match5to6);
  2894. addRegexToken('Hmm', match3to4);
  2895. addRegexToken('Hmmss', match5to6);
  2896. addParseToken(['H', 'HH'], HOUR);
  2897. addParseToken(['k', 'kk'], function (input, array, config) {
  2898. var kInput = toInt(input);
  2899. array[HOUR] = kInput === 24 ? 0 : kInput;
  2900. });
  2901. addParseToken(['a', 'A'], function (input, array, config) {
  2902. config._isPm = config._locale.isPM(input);
  2903. config._meridiem = input;
  2904. });
  2905. addParseToken(['h', 'hh'], function (input, array, config) {
  2906. array[HOUR] = toInt(input);
  2907. getParsingFlags(config).bigHour = true;
  2908. });
  2909. addParseToken('hmm', function (input, array, config) {
  2910. var pos = input.length - 2;
  2911. array[HOUR] = toInt(input.substr(0, pos));
  2912. array[MINUTE] = toInt(input.substr(pos));
  2913. getParsingFlags(config).bigHour = true;
  2914. });
  2915. addParseToken('hmmss', function (input, array, config) {
  2916. var pos1 = input.length - 4;
  2917. var pos2 = input.length - 2;
  2918. array[HOUR] = toInt(input.substr(0, pos1));
  2919. array[MINUTE] = toInt(input.substr(pos1, 2));
  2920. array[SECOND] = toInt(input.substr(pos2));
  2921. getParsingFlags(config).bigHour = true;
  2922. });
  2923. addParseToken('Hmm', function (input, array, config) {
  2924. var pos = input.length - 2;
  2925. array[HOUR] = toInt(input.substr(0, pos));
  2926. array[MINUTE] = toInt(input.substr(pos));
  2927. });
  2928. addParseToken('Hmmss', function (input, array, config) {
  2929. var pos1 = input.length - 4;
  2930. var pos2 = input.length - 2;
  2931. array[HOUR] = toInt(input.substr(0, pos1));
  2932. array[MINUTE] = toInt(input.substr(pos1, 2));
  2933. array[SECOND] = toInt(input.substr(pos2));
  2934. });
  2935. // LOCALES
  2936. function localeIsPM (input) {
  2937. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  2938. // Using charAt should be more compatible.
  2939. return ((input + '').toLowerCase().charAt(0) === 'p');
  2940. }
  2941. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  2942. function localeMeridiem (hours, minutes, isLower) {
  2943. if (hours > 11) {
  2944. return isLower ? 'pm' : 'PM';
  2945. } else {
  2946. return isLower ? 'am' : 'AM';
  2947. }
  2948. }
  2949. // MOMENTS
  2950. // Setting the hour should keep the time, because the user explicitly
  2951. // specified which hour he wants. So trying to maintain the same hour (in
  2952. // a new timezone) makes sense. Adding/subtracting hours does not follow
  2953. // this rule.
  2954. var getSetHour = makeGetSet('Hours', true);
  2955. // months
  2956. // week
  2957. // weekdays
  2958. // meridiem
  2959. var baseConfig = {
  2960. calendar: defaultCalendar,
  2961. longDateFormat: defaultLongDateFormat,
  2962. invalidDate: defaultInvalidDate,
  2963. ordinal: defaultOrdinal,
  2964. dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse,
  2965. relativeTime: defaultRelativeTime,
  2966. months: defaultLocaleMonths,
  2967. monthsShort: defaultLocaleMonthsShort,
  2968. week: defaultLocaleWeek,
  2969. weekdays: defaultLocaleWeekdays,
  2970. weekdaysMin: defaultLocaleWeekdaysMin,
  2971. weekdaysShort: defaultLocaleWeekdaysShort,
  2972. meridiemParse: defaultLocaleMeridiemParse
  2973. };
  2974. // internal storage for locale config files
  2975. var locales = {};
  2976. var localeFamilies = {};
  2977. var globalLocale;
  2978. function normalizeLocale(key) {
  2979. return key ? key.toLowerCase().replace('_', '-') : key;
  2980. }
  2981. // pick the locale from the array
  2982. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  2983. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  2984. function chooseLocale(names) {
  2985. var i = 0, j, next, locale, split;
  2986. while (i < names.length) {
  2987. split = normalizeLocale(names[i]).split('-');
  2988. j = split.length;
  2989. next = normalizeLocale(names[i + 1]);
  2990. next = next ? next.split('-') : null;
  2991. while (j > 0) {
  2992. locale = loadLocale(split.slice(0, j).join('-'));
  2993. if (locale) {
  2994. return locale;
  2995. }
  2996. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  2997. //the next array item is better than a shallower substring of this one
  2998. break;
  2999. }
  3000. j--;
  3001. }
  3002. i++;
  3003. }
  3004. return null;
  3005. }
  3006. function loadLocale(name) {
  3007. var oldLocale = null;
  3008. // TODO: Find a better way to register and load all the locales in Node
  3009. if (!locales[name] && (typeof module !== 'undefined') &&
  3010. module && module.exports) {
  3011. try {
  3012. oldLocale = globalLocale._abbr;
  3013. var aliasedRequire = require;
  3014. aliasedRequire('./locale/' + name);
  3015. getSetGlobalLocale(oldLocale);
  3016. } catch (e) {}
  3017. }
  3018. return locales[name];
  3019. }
  3020. // This function will load locale and then set the global locale. If
  3021. // no arguments are passed in, it will simply return the current global
  3022. // locale key.
  3023. function getSetGlobalLocale (key, values) {
  3024. var data;
  3025. if (key) {
  3026. if (isUndefined(values)) {
  3027. data = getLocale(key);
  3028. }
  3029. else {
  3030. data = defineLocale(key, values);
  3031. }
  3032. if (data) {
  3033. // moment.duration._locale = moment._locale = data;
  3034. globalLocale = data;
  3035. }
  3036. }
  3037. return globalLocale._abbr;
  3038. }
  3039. function defineLocale (name, config) {
  3040. if (config !== null) {
  3041. var parentConfig = baseConfig;
  3042. config.abbr = name;
  3043. if (locales[name] != null) {
  3044. deprecateSimple('defineLocaleOverride',
  3045. 'use moment.updateLocale(localeName, config) to change ' +
  3046. 'an existing locale. moment.defineLocale(localeName, ' +
  3047. 'config) should only be used for creating a new locale ' +
  3048. 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
  3049. parentConfig = locales[name]._config;
  3050. } else if (config.parentLocale != null) {
  3051. if (locales[config.parentLocale] != null) {
  3052. parentConfig = locales[config.parentLocale]._config;
  3053. } else {
  3054. if (!localeFamilies[config.parentLocale]) {
  3055. localeFamilies[config.parentLocale] = [];
  3056. }
  3057. localeFamilies[config.parentLocale].push({
  3058. name: name,
  3059. config: config
  3060. });
  3061. return null;
  3062. }
  3063. }
  3064. locales[name] = new Locale(mergeConfigs(parentConfig, config));
  3065. if (localeFamilies[name]) {
  3066. localeFamilies[name].forEach(function (x) {
  3067. defineLocale(x.name, x.config);
  3068. });
  3069. }
  3070. // backwards compat for now: also set the locale
  3071. // make sure we set the locale AFTER all child locales have been
  3072. // created, so we won't end up with the child locale set.
  3073. getSetGlobalLocale(name);
  3074. return locales[name];
  3075. } else {
  3076. // useful for testing
  3077. delete locales[name];
  3078. return null;
  3079. }
  3080. }
  3081. function updateLocale(name, config) {
  3082. if (config != null) {
  3083. var locale, tmpLocale, parentConfig = baseConfig;
  3084. // MERGE
  3085. tmpLocale = loadLocale(name);
  3086. if (tmpLocale != null) {
  3087. parentConfig = tmpLocale._config;
  3088. }
  3089. config = mergeConfigs(parentConfig, config);
  3090. locale = new Locale(config);
  3091. locale.parentLocale = locales[name];
  3092. locales[name] = locale;
  3093. // backwards compat for now: also set the locale
  3094. getSetGlobalLocale(name);
  3095. } else {
  3096. // pass null for config to unupdate, useful for tests
  3097. if (locales[name] != null) {
  3098. if (locales[name].parentLocale != null) {
  3099. locales[name] = locales[name].parentLocale;
  3100. } else if (locales[name] != null) {
  3101. delete locales[name];
  3102. }
  3103. }
  3104. }
  3105. return locales[name];
  3106. }
  3107. // returns locale data
  3108. function getLocale (key) {
  3109. var locale;
  3110. if (key && key._locale && key._locale._abbr) {
  3111. key = key._locale._abbr;
  3112. }
  3113. if (!key) {
  3114. return globalLocale;
  3115. }
  3116. if (!isArray(key)) {
  3117. //short-circuit everything else
  3118. locale = loadLocale(key);
  3119. if (locale) {
  3120. return locale;
  3121. }
  3122. key = [key];
  3123. }
  3124. return chooseLocale(key);
  3125. }
  3126. function listLocales() {
  3127. return keys(locales);
  3128. }
  3129. function checkOverflow (m) {
  3130. var overflow;
  3131. var a = m._a;
  3132. if (a && getParsingFlags(m).overflow === -2) {
  3133. overflow =
  3134. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  3135. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  3136. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  3137. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  3138. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  3139. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  3140. -1;
  3141. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  3142. overflow = DATE;
  3143. }
  3144. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  3145. overflow = WEEK;
  3146. }
  3147. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  3148. overflow = WEEKDAY;
  3149. }
  3150. getParsingFlags(m).overflow = overflow;
  3151. }
  3152. return m;
  3153. }
  3154. // Pick the first defined of two or three arguments.
  3155. function defaults(a, b, c) {
  3156. if (a != null) {
  3157. return a;
  3158. }
  3159. if (b != null) {
  3160. return b;
  3161. }
  3162. return c;
  3163. }
  3164. function currentDateArray(config) {
  3165. // hooks is actually the exported moment object
  3166. var nowValue = new Date(hooks.now());
  3167. if (config._useUTC) {
  3168. return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
  3169. }
  3170. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  3171. }
  3172. // convert an array to a date.
  3173. // the array should mirror the parameters below
  3174. // note: all values past the year are optional and will default to the lowest possible value.
  3175. // [year, month, day , hour, minute, second, millisecond]
  3176. function configFromArray (config) {
  3177. var i, date, input = [], currentDate, expectedWeekday, yearToUse;
  3178. if (config._d) {
  3179. return;
  3180. }
  3181. currentDate = currentDateArray(config);
  3182. //compute day of the year from weeks and weekdays
  3183. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  3184. dayOfYearFromWeekInfo(config);
  3185. }
  3186. //if the day of the year is set, figure out what it is
  3187. if (config._dayOfYear != null) {
  3188. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  3189. if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) {
  3190. getParsingFlags(config)._overflowDayOfYear = true;
  3191. }
  3192. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  3193. config._a[MONTH] = date.getUTCMonth();
  3194. config._a[DATE] = date.getUTCDate();
  3195. }
  3196. // Default to current date.
  3197. // * if no year, month, day of month are given, default to today
  3198. // * if day of month is given, default month and year
  3199. // * if month is given, default only year
  3200. // * if year is given, don't default anything
  3201. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  3202. config._a[i] = input[i] = currentDate[i];
  3203. }
  3204. // Zero out whatever was not defaulted, including time
  3205. for (; i < 7; i++) {
  3206. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  3207. }
  3208. // Check for 24:00:00.000
  3209. if (config._a[HOUR] === 24 &&
  3210. config._a[MINUTE] === 0 &&
  3211. config._a[SECOND] === 0 &&
  3212. config._a[MILLISECOND] === 0) {
  3213. config._nextDay = true;
  3214. config._a[HOUR] = 0;
  3215. }
  3216. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  3217. expectedWeekday = config._useUTC ? config._d.getUTCDay() : config._d.getDay();
  3218. // Apply timezone offset from input. The actual utcOffset can be changed
  3219. // with parseZone.
  3220. if (config._tzm != null) {
  3221. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  3222. }
  3223. if (config._nextDay) {
  3224. config._a[HOUR] = 24;
  3225. }
  3226. // check for mismatching day of week
  3227. if (config._w && typeof config._w.d !== 'undefined' && config._w.d !== expectedWeekday) {
  3228. getParsingFlags(config).weekdayMismatch = true;
  3229. }
  3230. }
  3231. function dayOfYearFromWeekInfo(config) {
  3232. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
  3233. w = config._w;
  3234. if (w.GG != null || w.W != null || w.E != null) {
  3235. dow = 1;
  3236. doy = 4;
  3237. // TODO: We need to take the current isoWeekYear, but that depends on
  3238. // how we interpret now (local, utc, fixed offset). So create
  3239. // a now version of current config (take local/utc/offset flags, and
  3240. // create now).
  3241. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(createLocal(), 1, 4).year);
  3242. week = defaults(w.W, 1);
  3243. weekday = defaults(w.E, 1);
  3244. if (weekday < 1 || weekday > 7) {
  3245. weekdayOverflow = true;
  3246. }
  3247. } else {
  3248. dow = config._locale._week.dow;
  3249. doy = config._locale._week.doy;
  3250. var curWeek = weekOfYear(createLocal(), dow, doy);
  3251. weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
  3252. // Default to current week.
  3253. week = defaults(w.w, curWeek.week);
  3254. if (w.d != null) {
  3255. // weekday -- low day numbers are considered next week
  3256. weekday = w.d;
  3257. if (weekday < 0 || weekday > 6) {
  3258. weekdayOverflow = true;
  3259. }
  3260. } else if (w.e != null) {
  3261. // local weekday -- counting starts from begining of week
  3262. weekday = w.e + dow;
  3263. if (w.e < 0 || w.e > 6) {
  3264. weekdayOverflow = true;
  3265. }
  3266. } else {
  3267. // default to begining of week
  3268. weekday = dow;
  3269. }
  3270. }
  3271. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  3272. getParsingFlags(config)._overflowWeeks = true;
  3273. } else if (weekdayOverflow != null) {
  3274. getParsingFlags(config)._overflowWeekday = true;
  3275. } else {
  3276. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  3277. config._a[YEAR] = temp.year;
  3278. config._dayOfYear = temp.dayOfYear;
  3279. }
  3280. }
  3281. // iso 8601 regex
  3282. // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  3283. var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
  3284. var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
  3285. var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  3286. var isoDates = [
  3287. ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  3288. ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  3289. ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  3290. ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  3291. ['YYYY-DDD', /\d{4}-\d{3}/],
  3292. ['YYYY-MM', /\d{4}-\d\d/, false],
  3293. ['YYYYYYMMDD', /[+-]\d{10}/],
  3294. ['YYYYMMDD', /\d{8}/],
  3295. // YYYYMM is NOT allowed by the standard
  3296. ['GGGG[W]WWE', /\d{4}W\d{3}/],
  3297. ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  3298. ['YYYYDDD', /\d{7}/]
  3299. ];
  3300. // iso time formats and regexes
  3301. var isoTimes = [
  3302. ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  3303. ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  3304. ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  3305. ['HH:mm', /\d\d:\d\d/],
  3306. ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  3307. ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  3308. ['HHmmss', /\d\d\d\d\d\d/],
  3309. ['HHmm', /\d\d\d\d/],
  3310. ['HH', /\d\d/]
  3311. ];
  3312. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  3313. // date from iso format
  3314. function configFromISO(config) {
  3315. var i, l,
  3316. string = config._i,
  3317. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  3318. allowTime, dateFormat, timeFormat, tzFormat;
  3319. if (match) {
  3320. getParsingFlags(config).iso = true;
  3321. for (i = 0, l = isoDates.length; i < l; i++) {
  3322. if (isoDates[i][1].exec(match[1])) {
  3323. dateFormat = isoDates[i][0];
  3324. allowTime = isoDates[i][2] !== false;
  3325. break;
  3326. }
  3327. }
  3328. if (dateFormat == null) {
  3329. config._isValid = false;
  3330. return;
  3331. }
  3332. if (match[3]) {
  3333. for (i = 0, l = isoTimes.length; i < l; i++) {
  3334. if (isoTimes[i][1].exec(match[3])) {
  3335. // match[2] should be 'T' or space
  3336. timeFormat = (match[2] || ' ') + isoTimes[i][0];
  3337. break;
  3338. }
  3339. }
  3340. if (timeFormat == null) {
  3341. config._isValid = false;
  3342. return;
  3343. }
  3344. }
  3345. if (!allowTime && timeFormat != null) {
  3346. config._isValid = false;
  3347. return;
  3348. }
  3349. if (match[4]) {
  3350. if (tzRegex.exec(match[4])) {
  3351. tzFormat = 'Z';
  3352. } else {
  3353. config._isValid = false;
  3354. return;
  3355. }
  3356. }
  3357. config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
  3358. configFromStringAndFormat(config);
  3359. } else {
  3360. config._isValid = false;
  3361. }
  3362. }
  3363. // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
  3364. var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/;
  3365. function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
  3366. var result = [
  3367. untruncateYear(yearStr),
  3368. defaultLocaleMonthsShort.indexOf(monthStr),
  3369. parseInt(dayStr, 10),
  3370. parseInt(hourStr, 10),
  3371. parseInt(minuteStr, 10)
  3372. ];
  3373. if (secondStr) {
  3374. result.push(parseInt(secondStr, 10));
  3375. }
  3376. return result;
  3377. }
  3378. function untruncateYear(yearStr) {
  3379. var year = parseInt(yearStr, 10);
  3380. if (year <= 49) {
  3381. return 2000 + year;
  3382. } else if (year <= 999) {
  3383. return 1900 + year;
  3384. }
  3385. return year;
  3386. }
  3387. function preprocessRFC2822(s) {
  3388. // Remove comments and folding whitespace and replace multiple-spaces with a single space
  3389. return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
  3390. }
  3391. function checkWeekday(weekdayStr, parsedInput, config) {
  3392. if (weekdayStr) {
  3393. // TODO: Replace the vanilla JS Date object with an indepentent day-of-week check.
  3394. var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
  3395. weekdayActual = new Date(parsedInput[0], parsedInput[1], parsedInput[2]).getDay();
  3396. if (weekdayProvided !== weekdayActual) {
  3397. getParsingFlags(config).weekdayMismatch = true;
  3398. config._isValid = false;
  3399. return false;
  3400. }
  3401. }
  3402. return true;
  3403. }
  3404. var obsOffsets = {
  3405. UT: 0,
  3406. GMT: 0,
  3407. EDT: -4 * 60,
  3408. EST: -5 * 60,
  3409. CDT: -5 * 60,
  3410. CST: -6 * 60,
  3411. MDT: -6 * 60,
  3412. MST: -7 * 60,
  3413. PDT: -7 * 60,
  3414. PST: -8 * 60
  3415. };
  3416. function calculateOffset(obsOffset, militaryOffset, numOffset) {
  3417. if (obsOffset) {
  3418. return obsOffsets[obsOffset];
  3419. } else if (militaryOffset) {
  3420. // the only allowed military tz is Z
  3421. return 0;
  3422. } else {
  3423. var hm = parseInt(numOffset, 10);
  3424. var m = hm % 100, h = (hm - m) / 100;
  3425. return h * 60 + m;
  3426. }
  3427. }
  3428. // date and time from ref 2822 format
  3429. function configFromRFC2822(config) {
  3430. var match = rfc2822.exec(preprocessRFC2822(config._i));
  3431. if (match) {
  3432. var parsedArray = extractFromRFC2822Strings(match[4], match[3], match[2], match[5], match[6], match[7]);
  3433. if (!checkWeekday(match[1], parsedArray, config)) {
  3434. return;
  3435. }
  3436. config._a = parsedArray;
  3437. config._tzm = calculateOffset(match[8], match[9], match[10]);
  3438. config._d = createUTCDate.apply(null, config._a);
  3439. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  3440. getParsingFlags(config).rfc2822 = true;
  3441. } else {
  3442. config._isValid = false;
  3443. }
  3444. }
  3445. // date from iso format or fallback
  3446. function configFromString(config) {
  3447. var matched = aspNetJsonRegex.exec(config._i);
  3448. if (matched !== null) {
  3449. config._d = new Date(+matched[1]);
  3450. return;
  3451. }
  3452. configFromISO(config);
  3453. if (config._isValid === false) {
  3454. delete config._isValid;
  3455. } else {
  3456. return;
  3457. }
  3458. configFromRFC2822(config);
  3459. if (config._isValid === false) {
  3460. delete config._isValid;
  3461. } else {
  3462. return;
  3463. }
  3464. // Final attempt, use Input Fallback
  3465. hooks.createFromInputFallback(config);
  3466. }
  3467. hooks.createFromInputFallback = deprecate(
  3468. 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
  3469. 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
  3470. 'discouraged and will be removed in an upcoming major release. Please refer to ' +
  3471. 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
  3472. function (config) {
  3473. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  3474. }
  3475. );
  3476. // constant that refers to the ISO standard
  3477. hooks.ISO_8601 = function () {};
  3478. // constant that refers to the RFC 2822 form
  3479. hooks.RFC_2822 = function () {};
  3480. // date from string and format string
  3481. function configFromStringAndFormat(config) {
  3482. // TODO: Move this to another part of the creation flow to prevent circular deps
  3483. if (config._f === hooks.ISO_8601) {
  3484. configFromISO(config);
  3485. return;
  3486. }
  3487. if (config._f === hooks.RFC_2822) {
  3488. configFromRFC2822(config);
  3489. return;
  3490. }
  3491. config._a = [];
  3492. getParsingFlags(config).empty = true;
  3493. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  3494. var string = '' + config._i,
  3495. i, parsedInput, tokens, token, skipped,
  3496. stringLength = string.length,
  3497. totalParsedInputLength = 0;
  3498. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  3499. for (i = 0; i < tokens.length; i++) {
  3500. token = tokens[i];
  3501. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  3502. // console.log('token', token, 'parsedInput', parsedInput,
  3503. // 'regex', getParseRegexForToken(token, config));
  3504. if (parsedInput) {
  3505. skipped = string.substr(0, string.indexOf(parsedInput));
  3506. if (skipped.length > 0) {
  3507. getParsingFlags(config).unusedInput.push(skipped);
  3508. }
  3509. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  3510. totalParsedInputLength += parsedInput.length;
  3511. }
  3512. // don't parse if it's not a known token
  3513. if (formatTokenFunctions[token]) {
  3514. if (parsedInput) {
  3515. getParsingFlags(config).empty = false;
  3516. }
  3517. else {
  3518. getParsingFlags(config).unusedTokens.push(token);
  3519. }
  3520. addTimeToArrayFromToken(token, parsedInput, config);
  3521. }
  3522. else if (config._strict && !parsedInput) {
  3523. getParsingFlags(config).unusedTokens.push(token);
  3524. }
  3525. }
  3526. // add remaining unparsed input length to the string
  3527. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  3528. if (string.length > 0) {
  3529. getParsingFlags(config).unusedInput.push(string);
  3530. }
  3531. // clear _12h flag if hour is <= 12
  3532. if (config._a[HOUR] <= 12 &&
  3533. getParsingFlags(config).bigHour === true &&
  3534. config._a[HOUR] > 0) {
  3535. getParsingFlags(config).bigHour = undefined;
  3536. }
  3537. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  3538. getParsingFlags(config).meridiem = config._meridiem;
  3539. // handle meridiem
  3540. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  3541. configFromArray(config);
  3542. checkOverflow(config);
  3543. }
  3544. function meridiemFixWrap (locale, hour, meridiem) {
  3545. var isPm;
  3546. if (meridiem == null) {
  3547. // nothing to do
  3548. return hour;
  3549. }
  3550. if (locale.meridiemHour != null) {
  3551. return locale.meridiemHour(hour, meridiem);
  3552. } else if (locale.isPM != null) {
  3553. // Fallback
  3554. isPm = locale.isPM(meridiem);
  3555. if (isPm && hour < 12) {
  3556. hour += 12;
  3557. }
  3558. if (!isPm && hour === 12) {
  3559. hour = 0;
  3560. }
  3561. return hour;
  3562. } else {
  3563. // this is not supposed to happen
  3564. return hour;
  3565. }
  3566. }
  3567. // date from string and array of format strings
  3568. function configFromStringAndArray(config) {
  3569. var tempConfig,
  3570. bestMoment,
  3571. scoreToBeat,
  3572. i,
  3573. currentScore;
  3574. if (config._f.length === 0) {
  3575. getParsingFlags(config).invalidFormat = true;
  3576. config._d = new Date(NaN);
  3577. return;
  3578. }
  3579. for (i = 0; i < config._f.length; i++) {
  3580. currentScore = 0;
  3581. tempConfig = copyConfig({}, config);
  3582. if (config._useUTC != null) {
  3583. tempConfig._useUTC = config._useUTC;
  3584. }
  3585. tempConfig._f = config._f[i];
  3586. configFromStringAndFormat(tempConfig);
  3587. if (!isValid(tempConfig)) {
  3588. continue;
  3589. }
  3590. // if there is any input that was not parsed add a penalty for that format
  3591. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  3592. //or tokens
  3593. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  3594. getParsingFlags(tempConfig).score = currentScore;
  3595. if (scoreToBeat == null || currentScore < scoreToBeat) {
  3596. scoreToBeat = currentScore;
  3597. bestMoment = tempConfig;
  3598. }
  3599. }
  3600. extend(config, bestMoment || tempConfig);
  3601. }
  3602. function configFromObject(config) {
  3603. if (config._d) {
  3604. return;
  3605. }
  3606. var i = normalizeObjectUnits(config._i);
  3607. config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  3608. return obj && parseInt(obj, 10);
  3609. });
  3610. configFromArray(config);
  3611. }
  3612. function createFromConfig (config) {
  3613. var res = new Moment(checkOverflow(prepareConfig(config)));
  3614. if (res._nextDay) {
  3615. // Adding is smart enough around DST
  3616. res.add(1, 'd');
  3617. res._nextDay = undefined;
  3618. }
  3619. return res;
  3620. }
  3621. function prepareConfig (config) {
  3622. var input = config._i,
  3623. format = config._f;
  3624. config._locale = config._locale || getLocale(config._l);
  3625. if (input === null || (format === undefined && input === '')) {
  3626. return createInvalid({nullInput: true});
  3627. }
  3628. if (typeof input === 'string') {
  3629. config._i = input = config._locale.preparse(input);
  3630. }
  3631. if (isMoment(input)) {
  3632. return new Moment(checkOverflow(input));
  3633. } else if (isDate(input)) {
  3634. config._d = input;
  3635. } else if (isArray(format)) {
  3636. configFromStringAndArray(config);
  3637. } else if (format) {
  3638. configFromStringAndFormat(config);
  3639. } else {
  3640. configFromInput(config);
  3641. }
  3642. if (!isValid(config)) {
  3643. config._d = null;
  3644. }
  3645. return config;
  3646. }
  3647. function configFromInput(config) {
  3648. var input = config._i;
  3649. if (isUndefined(input)) {
  3650. config._d = new Date(hooks.now());
  3651. } else if (isDate(input)) {
  3652. config._d = new Date(input.valueOf());
  3653. } else if (typeof input === 'string') {
  3654. configFromString(config);
  3655. } else if (isArray(input)) {
  3656. config._a = map(input.slice(0), function (obj) {
  3657. return parseInt(obj, 10);
  3658. });
  3659. configFromArray(config);
  3660. } else if (isObject(input)) {
  3661. configFromObject(config);
  3662. } else if (isNumber(input)) {
  3663. // from milliseconds
  3664. config._d = new Date(input);
  3665. } else {
  3666. hooks.createFromInputFallback(config);
  3667. }
  3668. }
  3669. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  3670. var c = {};
  3671. if (locale === true || locale === false) {
  3672. strict = locale;
  3673. locale = undefined;
  3674. }
  3675. if ((isObject(input) && isObjectEmpty(input)) ||
  3676. (isArray(input) && input.length === 0)) {
  3677. input = undefined;
  3678. }
  3679. // object construction must be done this way.
  3680. // https://github.com/moment/moment/issues/1423
  3681. c._isAMomentObject = true;
  3682. c._useUTC = c._isUTC = isUTC;
  3683. c._l = locale;
  3684. c._i = input;
  3685. c._f = format;
  3686. c._strict = strict;
  3687. return createFromConfig(c);
  3688. }
  3689. function createLocal (input, format, locale, strict) {
  3690. return createLocalOrUTC(input, format, locale, strict, false);
  3691. }
  3692. var prototypeMin = deprecate(
  3693. 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
  3694. function () {
  3695. var other = createLocal.apply(null, arguments);
  3696. if (this.isValid() && other.isValid()) {
  3697. return other < this ? this : other;
  3698. } else {
  3699. return createInvalid();
  3700. }
  3701. }
  3702. );
  3703. var prototypeMax = deprecate(
  3704. 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
  3705. function () {
  3706. var other = createLocal.apply(null, arguments);
  3707. if (this.isValid() && other.isValid()) {
  3708. return other > this ? this : other;
  3709. } else {
  3710. return createInvalid();
  3711. }
  3712. }
  3713. );
  3714. // Pick a moment m from moments so that m[fn](other) is true for all
  3715. // other. This relies on the function fn to be transitive.
  3716. //
  3717. // moments should either be an array of moment objects or an array, whose
  3718. // first element is an array of moment objects.
  3719. function pickBy(fn, moments) {
  3720. var res, i;
  3721. if (moments.length === 1 && isArray(moments[0])) {
  3722. moments = moments[0];
  3723. }
  3724. if (!moments.length) {
  3725. return createLocal();
  3726. }
  3727. res = moments[0];
  3728. for (i = 1; i < moments.length; ++i) {
  3729. if (!moments[i].isValid() || moments[i][fn](res)) {
  3730. res = moments[i];
  3731. }
  3732. }
  3733. return res;
  3734. }
  3735. // TODO: Use [].sort instead?
  3736. function min () {
  3737. var args = [].slice.call(arguments, 0);
  3738. return pickBy('isBefore', args);
  3739. }
  3740. function max () {
  3741. var args = [].slice.call(arguments, 0);
  3742. return pickBy('isAfter', args);
  3743. }
  3744. var now = function () {
  3745. return Date.now ? Date.now() : +(new Date());
  3746. };
  3747. var ordering = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond'];
  3748. function isDurationValid(m) {
  3749. for (var key in m) {
  3750. if (!(indexOf.call(ordering, key) !== -1 && (m[key] == null || !isNaN(m[key])))) {
  3751. return false;
  3752. }
  3753. }
  3754. var unitHasDecimal = false;
  3755. for (var i = 0; i < ordering.length; ++i) {
  3756. if (m[ordering[i]]) {
  3757. if (unitHasDecimal) {
  3758. return false; // only allow non-integers for smallest unit
  3759. }
  3760. if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
  3761. unitHasDecimal = true;
  3762. }
  3763. }
  3764. }
  3765. return true;
  3766. }
  3767. function isValid$1() {
  3768. return this._isValid;
  3769. }
  3770. function createInvalid$1() {
  3771. return createDuration(NaN);
  3772. }
  3773. function Duration (duration) {
  3774. var normalizedInput = normalizeObjectUnits(duration),
  3775. years = normalizedInput.year || 0,
  3776. quarters = normalizedInput.quarter || 0,
  3777. months = normalizedInput.month || 0,
  3778. weeks = normalizedInput.week || 0,
  3779. days = normalizedInput.day || 0,
  3780. hours = normalizedInput.hour || 0,
  3781. minutes = normalizedInput.minute || 0,
  3782. seconds = normalizedInput.second || 0,
  3783. milliseconds = normalizedInput.millisecond || 0;
  3784. this._isValid = isDurationValid(normalizedInput);
  3785. // representation for dateAddRemove
  3786. this._milliseconds = +milliseconds +
  3787. seconds * 1e3 + // 1000
  3788. minutes * 6e4 + // 1000 * 60
  3789. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  3790. // Because of dateAddRemove treats 24 hours as different from a
  3791. // day when working around DST, we need to store them separately
  3792. this._days = +days +
  3793. weeks * 7;
  3794. // It is impossible to translate months into days without knowing
  3795. // which months you are are talking about, so we have to store
  3796. // it separately.
  3797. this._months = +months +
  3798. quarters * 3 +
  3799. years * 12;
  3800. this._data = {};
  3801. this._locale = getLocale();
  3802. this._bubble();
  3803. }
  3804. function isDuration (obj) {
  3805. return obj instanceof Duration;
  3806. }
  3807. function absRound (number) {
  3808. if (number < 0) {
  3809. return Math.round(-1 * number) * -1;
  3810. } else {
  3811. return Math.round(number);
  3812. }
  3813. }
  3814. // FORMATTING
  3815. function offset (token, separator) {
  3816. addFormatToken(token, 0, 0, function () {
  3817. var offset = this.utcOffset();
  3818. var sign = '+';
  3819. if (offset < 0) {
  3820. offset = -offset;
  3821. sign = '-';
  3822. }
  3823. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  3824. });
  3825. }
  3826. offset('Z', ':');
  3827. offset('ZZ', '');
  3828. // PARSING
  3829. addRegexToken('Z', matchShortOffset);
  3830. addRegexToken('ZZ', matchShortOffset);
  3831. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  3832. config._useUTC = true;
  3833. config._tzm = offsetFromString(matchShortOffset, input);
  3834. });
  3835. // HELPERS
  3836. // timezone chunker
  3837. // '+10:00' > ['10', '00']
  3838. // '-1530' > ['-15', '30']
  3839. var chunkOffset = /([\+\-]|\d\d)/gi;
  3840. function offsetFromString(matcher, string) {
  3841. var matches = (string || '').match(matcher);
  3842. if (matches === null) {
  3843. return null;
  3844. }
  3845. var chunk = matches[matches.length - 1] || [];
  3846. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  3847. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  3848. return minutes === 0 ?
  3849. 0 :
  3850. parts[0] === '+' ? minutes : -minutes;
  3851. }
  3852. // Return a moment from input, that is local/utc/zone equivalent to model.
  3853. function cloneWithOffset(input, model) {
  3854. var res, diff;
  3855. if (model._isUTC) {
  3856. res = model.clone();
  3857. diff = (isMoment(input) || isDate(input) ? input.valueOf() : createLocal(input).valueOf()) - res.valueOf();
  3858. // Use low-level api, because this fn is low-level api.
  3859. res._d.setTime(res._d.valueOf() + diff);
  3860. hooks.updateOffset(res, false);
  3861. return res;
  3862. } else {
  3863. return createLocal(input).local();
  3864. }
  3865. }
  3866. function getDateOffset (m) {
  3867. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  3868. // https://github.com/moment/moment/pull/1871
  3869. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  3870. }
  3871. // HOOKS
  3872. // This function will be called whenever a moment is mutated.
  3873. // It is intended to keep the offset in sync with the timezone.
  3874. hooks.updateOffset = function () {};
  3875. // MOMENTS
  3876. // keepLocalTime = true means only change the timezone, without
  3877. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  3878. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  3879. // +0200, so we adjust the time as needed, to be valid.
  3880. //
  3881. // Keeping the time actually adds/subtracts (one hour)
  3882. // from the actual represented time. That is why we call updateOffset
  3883. // a second time. In case it wants us to change the offset again
  3884. // _changeInProgress == true case, then we have to adjust, because
  3885. // there is no such time in the given timezone.
  3886. function getSetOffset (input, keepLocalTime, keepMinutes) {
  3887. var offset = this._offset || 0,
  3888. localAdjust;
  3889. if (!this.isValid()) {
  3890. return input != null ? this : NaN;
  3891. }
  3892. if (input != null) {
  3893. if (typeof input === 'string') {
  3894. input = offsetFromString(matchShortOffset, input);
  3895. if (input === null) {
  3896. return this;
  3897. }
  3898. } else if (Math.abs(input) < 16 && !keepMinutes) {
  3899. input = input * 60;
  3900. }
  3901. if (!this._isUTC && keepLocalTime) {
  3902. localAdjust = getDateOffset(this);
  3903. }
  3904. this._offset = input;
  3905. this._isUTC = true;
  3906. if (localAdjust != null) {
  3907. this.add(localAdjust, 'm');
  3908. }
  3909. if (offset !== input) {
  3910. if (!keepLocalTime || this._changeInProgress) {
  3911. addSubtract(this, createDuration(input - offset, 'm'), 1, false);
  3912. } else if (!this._changeInProgress) {
  3913. this._changeInProgress = true;
  3914. hooks.updateOffset(this, true);
  3915. this._changeInProgress = null;
  3916. }
  3917. }
  3918. return this;
  3919. } else {
  3920. return this._isUTC ? offset : getDateOffset(this);
  3921. }
  3922. }
  3923. function getSetZone (input, keepLocalTime) {
  3924. if (input != null) {
  3925. if (typeof input !== 'string') {
  3926. input = -input;
  3927. }
  3928. this.utcOffset(input, keepLocalTime);
  3929. return this;
  3930. } else {
  3931. return -this.utcOffset();
  3932. }
  3933. }
  3934. function setOffsetToUTC (keepLocalTime) {
  3935. return this.utcOffset(0, keepLocalTime);
  3936. }
  3937. function setOffsetToLocal (keepLocalTime) {
  3938. if (this._isUTC) {
  3939. this.utcOffset(0, keepLocalTime);
  3940. this._isUTC = false;
  3941. if (keepLocalTime) {
  3942. this.subtract(getDateOffset(this), 'm');
  3943. }
  3944. }
  3945. return this;
  3946. }
  3947. function setOffsetToParsedOffset () {
  3948. if (this._tzm != null) {
  3949. this.utcOffset(this._tzm, false, true);
  3950. } else if (typeof this._i === 'string') {
  3951. var tZone = offsetFromString(matchOffset, this._i);
  3952. if (tZone != null) {
  3953. this.utcOffset(tZone);
  3954. }
  3955. else {
  3956. this.utcOffset(0, true);
  3957. }
  3958. }
  3959. return this;
  3960. }
  3961. function hasAlignedHourOffset (input) {
  3962. if (!this.isValid()) {
  3963. return false;
  3964. }
  3965. input = input ? createLocal(input).utcOffset() : 0;
  3966. return (this.utcOffset() - input) % 60 === 0;
  3967. }
  3968. function isDaylightSavingTime () {
  3969. return (
  3970. this.utcOffset() > this.clone().month(0).utcOffset() ||
  3971. this.utcOffset() > this.clone().month(5).utcOffset()
  3972. );
  3973. }
  3974. function isDaylightSavingTimeShifted () {
  3975. if (!isUndefined(this._isDSTShifted)) {
  3976. return this._isDSTShifted;
  3977. }
  3978. var c = {};
  3979. copyConfig(c, this);
  3980. c = prepareConfig(c);
  3981. if (c._a) {
  3982. var other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
  3983. this._isDSTShifted = this.isValid() &&
  3984. compareArrays(c._a, other.toArray()) > 0;
  3985. } else {
  3986. this._isDSTShifted = false;
  3987. }
  3988. return this._isDSTShifted;
  3989. }
  3990. function isLocal () {
  3991. return this.isValid() ? !this._isUTC : false;
  3992. }
  3993. function isUtcOffset () {
  3994. return this.isValid() ? this._isUTC : false;
  3995. }
  3996. function isUtc () {
  3997. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  3998. }
  3999. // ASP.NET json date format regex
  4000. var aspNetRegex = /^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/;
  4001. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  4002. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  4003. // and further modified to allow for strings containing both week and day
  4004. var isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
  4005. function createDuration (input, key) {
  4006. var duration = input,
  4007. // matching against regexp is expensive, do it on demand
  4008. match = null,
  4009. sign,
  4010. ret,
  4011. diffRes;
  4012. if (isDuration(input)) {
  4013. duration = {
  4014. ms : input._milliseconds,
  4015. d : input._days,
  4016. M : input._months
  4017. };
  4018. } else if (isNumber(input)) {
  4019. duration = {};
  4020. if (key) {
  4021. duration[key] = input;
  4022. } else {
  4023. duration.milliseconds = input;
  4024. }
  4025. } else if (!!(match = aspNetRegex.exec(input))) {
  4026. sign = (match[1] === '-') ? -1 : 1;
  4027. duration = {
  4028. y : 0,
  4029. d : toInt(match[DATE]) * sign,
  4030. h : toInt(match[HOUR]) * sign,
  4031. m : toInt(match[MINUTE]) * sign,
  4032. s : toInt(match[SECOND]) * sign,
  4033. ms : toInt(absRound(match[MILLISECOND] * 1000)) * sign // the millisecond decimal point is included in the match
  4034. };
  4035. } else if (!!(match = isoRegex.exec(input))) {
  4036. sign = (match[1] === '-') ? -1 : (match[1] === '+') ? 1 : 1;
  4037. duration = {
  4038. y : parseIso(match[2], sign),
  4039. M : parseIso(match[3], sign),
  4040. w : parseIso(match[4], sign),
  4041. d : parseIso(match[5], sign),
  4042. h : parseIso(match[6], sign),
  4043. m : parseIso(match[7], sign),
  4044. s : parseIso(match[8], sign)
  4045. };
  4046. } else if (duration == null) {// checks for null or undefined
  4047. duration = {};
  4048. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  4049. diffRes = momentsDifference(createLocal(duration.from), createLocal(duration.to));
  4050. duration = {};
  4051. duration.ms = diffRes.milliseconds;
  4052. duration.M = diffRes.months;
  4053. }
  4054. ret = new Duration(duration);
  4055. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  4056. ret._locale = input._locale;
  4057. }
  4058. return ret;
  4059. }
  4060. createDuration.fn = Duration.prototype;
  4061. createDuration.invalid = createInvalid$1;
  4062. function parseIso (inp, sign) {
  4063. // We'd normally use ~~inp for this, but unfortunately it also
  4064. // converts floats to ints.
  4065. // inp may be undefined, so careful calling replace on it.
  4066. var res = inp && parseFloat(inp.replace(',', '.'));
  4067. // apply sign while we're at it
  4068. return (isNaN(res) ? 0 : res) * sign;
  4069. }
  4070. function positiveMomentsDifference(base, other) {
  4071. var res = {milliseconds: 0, months: 0};
  4072. res.months = other.month() - base.month() +
  4073. (other.year() - base.year()) * 12;
  4074. if (base.clone().add(res.months, 'M').isAfter(other)) {
  4075. --res.months;
  4076. }
  4077. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  4078. return res;
  4079. }
  4080. function momentsDifference(base, other) {
  4081. var res;
  4082. if (!(base.isValid() && other.isValid())) {
  4083. return {milliseconds: 0, months: 0};
  4084. }
  4085. other = cloneWithOffset(other, base);
  4086. if (base.isBefore(other)) {
  4087. res = positiveMomentsDifference(base, other);
  4088. } else {
  4089. res = positiveMomentsDifference(other, base);
  4090. res.milliseconds = -res.milliseconds;
  4091. res.months = -res.months;
  4092. }
  4093. return res;
  4094. }
  4095. // TODO: remove 'name' arg after deprecation is removed
  4096. function createAdder(direction, name) {
  4097. return function (val, period) {
  4098. var dur, tmp;
  4099. //invert the arguments, but complain about it
  4100. if (period !== null && !isNaN(+period)) {
  4101. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' +
  4102. 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
  4103. tmp = val; val = period; period = tmp;
  4104. }
  4105. val = typeof val === 'string' ? +val : val;
  4106. dur = createDuration(val, period);
  4107. addSubtract(this, dur, direction);
  4108. return this;
  4109. };
  4110. }
  4111. function addSubtract (mom, duration, isAdding, updateOffset) {
  4112. var milliseconds = duration._milliseconds,
  4113. days = absRound(duration._days),
  4114. months = absRound(duration._months);
  4115. if (!mom.isValid()) {
  4116. // No op
  4117. return;
  4118. }
  4119. updateOffset = updateOffset == null ? true : updateOffset;
  4120. if (months) {
  4121. setMonth(mom, get(mom, 'Month') + months * isAdding);
  4122. }
  4123. if (days) {
  4124. set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
  4125. }
  4126. if (milliseconds) {
  4127. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  4128. }
  4129. if (updateOffset) {
  4130. hooks.updateOffset(mom, days || months);
  4131. }
  4132. }
  4133. var add = createAdder(1, 'add');
  4134. var subtract = createAdder(-1, 'subtract');
  4135. function getCalendarFormat(myMoment, now) {
  4136. var diff = myMoment.diff(now, 'days', true);
  4137. return diff < -6 ? 'sameElse' :
  4138. diff < -1 ? 'lastWeek' :
  4139. diff < 0 ? 'lastDay' :
  4140. diff < 1 ? 'sameDay' :
  4141. diff < 2 ? 'nextDay' :
  4142. diff < 7 ? 'nextWeek' : 'sameElse';
  4143. }
  4144. function calendar$1 (time, formats) {
  4145. // We want to compare the start of today, vs this.
  4146. // Getting start-of-today depends on whether we're local/utc/offset or not.
  4147. var now = time || createLocal(),
  4148. sod = cloneWithOffset(now, this).startOf('day'),
  4149. format = hooks.calendarFormat(this, sod) || 'sameElse';
  4150. var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
  4151. return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
  4152. }
  4153. function clone () {
  4154. return new Moment(this);
  4155. }
  4156. function isAfter (input, units) {
  4157. var localInput = isMoment(input) ? input : createLocal(input);
  4158. if (!(this.isValid() && localInput.isValid())) {
  4159. return false;
  4160. }
  4161. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  4162. if (units === 'millisecond') {
  4163. return this.valueOf() > localInput.valueOf();
  4164. } else {
  4165. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  4166. }
  4167. }
  4168. function isBefore (input, units) {
  4169. var localInput = isMoment(input) ? input : createLocal(input);
  4170. if (!(this.isValid() && localInput.isValid())) {
  4171. return false;
  4172. }
  4173. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  4174. if (units === 'millisecond') {
  4175. return this.valueOf() < localInput.valueOf();
  4176. } else {
  4177. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  4178. }
  4179. }
  4180. function isBetween (from, to, units, inclusivity) {
  4181. inclusivity = inclusivity || '()';
  4182. return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
  4183. (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
  4184. }
  4185. function isSame (input, units) {
  4186. var localInput = isMoment(input) ? input : createLocal(input),
  4187. inputMs;
  4188. if (!(this.isValid() && localInput.isValid())) {
  4189. return false;
  4190. }
  4191. units = normalizeUnits(units || 'millisecond');
  4192. if (units === 'millisecond') {
  4193. return this.valueOf() === localInput.valueOf();
  4194. } else {
  4195. inputMs = localInput.valueOf();
  4196. return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
  4197. }
  4198. }
  4199. function isSameOrAfter (input, units) {
  4200. return this.isSame(input, units) || this.isAfter(input,units);
  4201. }
  4202. function isSameOrBefore (input, units) {
  4203. return this.isSame(input, units) || this.isBefore(input,units);
  4204. }
  4205. function diff (input, units, asFloat) {
  4206. var that,
  4207. zoneDelta,
  4208. delta, output;
  4209. if (!this.isValid()) {
  4210. return NaN;
  4211. }
  4212. that = cloneWithOffset(input, this);
  4213. if (!that.isValid()) {
  4214. return NaN;
  4215. }
  4216. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  4217. units = normalizeUnits(units);
  4218. switch (units) {
  4219. case 'year': output = monthDiff(this, that) / 12; break;
  4220. case 'month': output = monthDiff(this, that); break;
  4221. case 'quarter': output = monthDiff(this, that) / 3; break;
  4222. case 'second': output = (this - that) / 1e3; break; // 1000
  4223. case 'minute': output = (this - that) / 6e4; break; // 1000 * 60
  4224. case 'hour': output = (this - that) / 36e5; break; // 1000 * 60 * 60
  4225. case 'day': output = (this - that - zoneDelta) / 864e5; break; // 1000 * 60 * 60 * 24, negate dst
  4226. case 'week': output = (this - that - zoneDelta) / 6048e5; break; // 1000 * 60 * 60 * 24 * 7, negate dst
  4227. default: output = this - that;
  4228. }
  4229. return asFloat ? output : absFloor(output);
  4230. }
  4231. function monthDiff (a, b) {
  4232. // difference in months
  4233. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  4234. // b is in (anchor - 1 month, anchor + 1 month)
  4235. anchor = a.clone().add(wholeMonthDiff, 'months'),
  4236. anchor2, adjust;
  4237. if (b - anchor < 0) {
  4238. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  4239. // linear across the month
  4240. adjust = (b - anchor) / (anchor - anchor2);
  4241. } else {
  4242. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  4243. // linear across the month
  4244. adjust = (b - anchor) / (anchor2 - anchor);
  4245. }
  4246. //check for negative zero, return zero if negative zero
  4247. return -(wholeMonthDiff + adjust) || 0;
  4248. }
  4249. hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  4250. hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  4251. function toString () {
  4252. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  4253. }
  4254. function toISOString(keepOffset) {
  4255. if (!this.isValid()) {
  4256. return null;
  4257. }
  4258. var utc = keepOffset !== true;
  4259. var m = utc ? this.clone().utc() : this;
  4260. if (m.year() < 0 || m.year() > 9999) {
  4261. return formatMoment(m, utc ? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ');
  4262. }
  4263. if (isFunction(Date.prototype.toISOString)) {
  4264. // native implementation is ~50x faster, use it when we can
  4265. if (utc) {
  4266. return this.toDate().toISOString();
  4267. } else {
  4268. return new Date(this._d.valueOf()).toISOString().replace('Z', formatMoment(m, 'Z'));
  4269. }
  4270. }
  4271. return formatMoment(m, utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ');
  4272. }
  4273. /**
  4274. * Return a human readable representation of a moment that can
  4275. * also be evaluated to get a new moment which is the same
  4276. *
  4277. * @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
  4278. */
  4279. function inspect () {
  4280. if (!this.isValid()) {
  4281. return 'moment.invalid(/* ' + this._i + ' */)';
  4282. }
  4283. var func = 'moment';
  4284. var zone = '';
  4285. if (!this.isLocal()) {
  4286. func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
  4287. zone = 'Z';
  4288. }
  4289. var prefix = '[' + func + '("]';
  4290. var year = (0 <= this.year() && this.year() <= 9999) ? 'YYYY' : 'YYYYYY';
  4291. var datetime = '-MM-DD[T]HH:mm:ss.SSS';
  4292. var suffix = zone + '[")]';
  4293. return this.format(prefix + year + datetime + suffix);
  4294. }
  4295. function format (inputString) {
  4296. if (!inputString) {
  4297. inputString = this.isUtc() ? hooks.defaultFormatUtc : hooks.defaultFormat;
  4298. }
  4299. var output = formatMoment(this, inputString);
  4300. return this.localeData().postformat(output);
  4301. }
  4302. function from (time, withoutSuffix) {
  4303. if (this.isValid() &&
  4304. ((isMoment(time) && time.isValid()) ||
  4305. createLocal(time).isValid())) {
  4306. return createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  4307. } else {
  4308. return this.localeData().invalidDate();
  4309. }
  4310. }
  4311. function fromNow (withoutSuffix) {
  4312. return this.from(createLocal(), withoutSuffix);
  4313. }
  4314. function to (time, withoutSuffix) {
  4315. if (this.isValid() &&
  4316. ((isMoment(time) && time.isValid()) ||
  4317. createLocal(time).isValid())) {
  4318. return createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  4319. } else {
  4320. return this.localeData().invalidDate();
  4321. }
  4322. }
  4323. function toNow (withoutSuffix) {
  4324. return this.to(createLocal(), withoutSuffix);
  4325. }
  4326. // If passed a locale key, it will set the locale for this
  4327. // instance. Otherwise, it will return the locale configuration
  4328. // variables for this instance.
  4329. function locale (key) {
  4330. var newLocaleData;
  4331. if (key === undefined) {
  4332. return this._locale._abbr;
  4333. } else {
  4334. newLocaleData = getLocale(key);
  4335. if (newLocaleData != null) {
  4336. this._locale = newLocaleData;
  4337. }
  4338. return this;
  4339. }
  4340. }
  4341. var lang = deprecate(
  4342. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  4343. function (key) {
  4344. if (key === undefined) {
  4345. return this.localeData();
  4346. } else {
  4347. return this.locale(key);
  4348. }
  4349. }
  4350. );
  4351. function localeData () {
  4352. return this._locale;
  4353. }
  4354. function startOf (units) {
  4355. units = normalizeUnits(units);
  4356. // the following switch intentionally omits break keywords
  4357. // to utilize falling through the cases.
  4358. switch (units) {
  4359. case 'year':
  4360. this.month(0);
  4361. /* falls through */
  4362. case 'quarter':
  4363. case 'month':
  4364. this.date(1);
  4365. /* falls through */
  4366. case 'week':
  4367. case 'isoWeek':
  4368. case 'day':
  4369. case 'date':
  4370. this.hours(0);
  4371. /* falls through */
  4372. case 'hour':
  4373. this.minutes(0);
  4374. /* falls through */
  4375. case 'minute':
  4376. this.seconds(0);
  4377. /* falls through */
  4378. case 'second':
  4379. this.milliseconds(0);
  4380. }
  4381. // weeks are a special case
  4382. if (units === 'week') {
  4383. this.weekday(0);
  4384. }
  4385. if (units === 'isoWeek') {
  4386. this.isoWeekday(1);
  4387. }
  4388. // quarters are also special
  4389. if (units === 'quarter') {
  4390. this.month(Math.floor(this.month() / 3) * 3);
  4391. }
  4392. return this;
  4393. }
  4394. function endOf (units) {
  4395. units = normalizeUnits(units);
  4396. if (units === undefined || units === 'millisecond') {
  4397. return this;
  4398. }
  4399. // 'date' is an alias for 'day', so it should be considered as such.
  4400. if (units === 'date') {
  4401. units = 'day';
  4402. }
  4403. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  4404. }
  4405. function valueOf () {
  4406. return this._d.valueOf() - ((this._offset || 0) * 60000);
  4407. }
  4408. function unix () {
  4409. return Math.floor(this.valueOf() / 1000);
  4410. }
  4411. function toDate () {
  4412. return new Date(this.valueOf());
  4413. }
  4414. function toArray () {
  4415. var m = this;
  4416. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  4417. }
  4418. function toObject () {
  4419. var m = this;
  4420. return {
  4421. years: m.year(),
  4422. months: m.month(),
  4423. date: m.date(),
  4424. hours: m.hours(),
  4425. minutes: m.minutes(),
  4426. seconds: m.seconds(),
  4427. milliseconds: m.milliseconds()
  4428. };
  4429. }
  4430. function toJSON () {
  4431. // new Date(NaN).toJSON() === null
  4432. return this.isValid() ? this.toISOString() : null;
  4433. }
  4434. function isValid$2 () {
  4435. return isValid(this);
  4436. }
  4437. function parsingFlags () {
  4438. return extend({}, getParsingFlags(this));
  4439. }
  4440. function invalidAt () {
  4441. return getParsingFlags(this).overflow;
  4442. }
  4443. function creationData() {
  4444. return {
  4445. input: this._i,
  4446. format: this._f,
  4447. locale: this._locale,
  4448. isUTC: this._isUTC,
  4449. strict: this._strict
  4450. };
  4451. }
  4452. // FORMATTING
  4453. addFormatToken(0, ['gg', 2], 0, function () {
  4454. return this.weekYear() % 100;
  4455. });
  4456. addFormatToken(0, ['GG', 2], 0, function () {
  4457. return this.isoWeekYear() % 100;
  4458. });
  4459. function addWeekYearFormatToken (token, getter) {
  4460. addFormatToken(0, [token, token.length], 0, getter);
  4461. }
  4462. addWeekYearFormatToken('gggg', 'weekYear');
  4463. addWeekYearFormatToken('ggggg', 'weekYear');
  4464. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  4465. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  4466. // ALIASES
  4467. addUnitAlias('weekYear', 'gg');
  4468. addUnitAlias('isoWeekYear', 'GG');
  4469. // PRIORITY
  4470. addUnitPriority('weekYear', 1);
  4471. addUnitPriority('isoWeekYear', 1);
  4472. // PARSING
  4473. addRegexToken('G', matchSigned);
  4474. addRegexToken('g', matchSigned);
  4475. addRegexToken('GG', match1to2, match2);
  4476. addRegexToken('gg', match1to2, match2);
  4477. addRegexToken('GGGG', match1to4, match4);
  4478. addRegexToken('gggg', match1to4, match4);
  4479. addRegexToken('GGGGG', match1to6, match6);
  4480. addRegexToken('ggggg', match1to6, match6);
  4481. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  4482. week[token.substr(0, 2)] = toInt(input);
  4483. });
  4484. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  4485. week[token] = hooks.parseTwoDigitYear(input);
  4486. });
  4487. // MOMENTS
  4488. function getSetWeekYear (input) {
  4489. return getSetWeekYearHelper.call(this,
  4490. input,
  4491. this.week(),
  4492. this.weekday(),
  4493. this.localeData()._week.dow,
  4494. this.localeData()._week.doy);
  4495. }
  4496. function getSetISOWeekYear (input) {
  4497. return getSetWeekYearHelper.call(this,
  4498. input, this.isoWeek(), this.isoWeekday(), 1, 4);
  4499. }
  4500. function getISOWeeksInYear () {
  4501. return weeksInYear(this.year(), 1, 4);
  4502. }
  4503. function getWeeksInYear () {
  4504. var weekInfo = this.localeData()._week;
  4505. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  4506. }
  4507. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  4508. var weeksTarget;
  4509. if (input == null) {
  4510. return weekOfYear(this, dow, doy).year;
  4511. } else {
  4512. weeksTarget = weeksInYear(input, dow, doy);
  4513. if (week > weeksTarget) {
  4514. week = weeksTarget;
  4515. }
  4516. return setWeekAll.call(this, input, week, weekday, dow, doy);
  4517. }
  4518. }
  4519. function setWeekAll(weekYear, week, weekday, dow, doy) {
  4520. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  4521. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  4522. this.year(date.getUTCFullYear());
  4523. this.month(date.getUTCMonth());
  4524. this.date(date.getUTCDate());
  4525. return this;
  4526. }
  4527. // FORMATTING
  4528. addFormatToken('Q', 0, 'Qo', 'quarter');
  4529. // ALIASES
  4530. addUnitAlias('quarter', 'Q');
  4531. // PRIORITY
  4532. addUnitPriority('quarter', 7);
  4533. // PARSING
  4534. addRegexToken('Q', match1);
  4535. addParseToken('Q', function (input, array) {
  4536. array[MONTH] = (toInt(input) - 1) * 3;
  4537. });
  4538. // MOMENTS
  4539. function getSetQuarter (input) {
  4540. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  4541. }
  4542. // FORMATTING
  4543. addFormatToken('D', ['DD', 2], 'Do', 'date');
  4544. // ALIASES
  4545. addUnitAlias('date', 'D');
  4546. // PRIOROITY
  4547. addUnitPriority('date', 9);
  4548. // PARSING
  4549. addRegexToken('D', match1to2);
  4550. addRegexToken('DD', match1to2, match2);
  4551. addRegexToken('Do', function (isStrict, locale) {
  4552. // TODO: Remove "ordinalParse" fallback in next major release.
  4553. return isStrict ?
  4554. (locale._dayOfMonthOrdinalParse || locale._ordinalParse) :
  4555. locale._dayOfMonthOrdinalParseLenient;
  4556. });
  4557. addParseToken(['D', 'DD'], DATE);
  4558. addParseToken('Do', function (input, array) {
  4559. array[DATE] = toInt(input.match(match1to2)[0]);
  4560. });
  4561. // MOMENTS
  4562. var getSetDayOfMonth = makeGetSet('Date', true);
  4563. // FORMATTING
  4564. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  4565. // ALIASES
  4566. addUnitAlias('dayOfYear', 'DDD');
  4567. // PRIORITY
  4568. addUnitPriority('dayOfYear', 4);
  4569. // PARSING
  4570. addRegexToken('DDD', match1to3);
  4571. addRegexToken('DDDD', match3);
  4572. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  4573. config._dayOfYear = toInt(input);
  4574. });
  4575. // HELPERS
  4576. // MOMENTS
  4577. function getSetDayOfYear (input) {
  4578. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  4579. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  4580. }
  4581. // FORMATTING
  4582. addFormatToken('m', ['mm', 2], 0, 'minute');
  4583. // ALIASES
  4584. addUnitAlias('minute', 'm');
  4585. // PRIORITY
  4586. addUnitPriority('minute', 14);
  4587. // PARSING
  4588. addRegexToken('m', match1to2);
  4589. addRegexToken('mm', match1to2, match2);
  4590. addParseToken(['m', 'mm'], MINUTE);
  4591. // MOMENTS
  4592. var getSetMinute = makeGetSet('Minutes', false);
  4593. // FORMATTING
  4594. addFormatToken('s', ['ss', 2], 0, 'second');
  4595. // ALIASES
  4596. addUnitAlias('second', 's');
  4597. // PRIORITY
  4598. addUnitPriority('second', 15);
  4599. // PARSING
  4600. addRegexToken('s', match1to2);
  4601. addRegexToken('ss', match1to2, match2);
  4602. addParseToken(['s', 'ss'], SECOND);
  4603. // MOMENTS
  4604. var getSetSecond = makeGetSet('Seconds', false);
  4605. // FORMATTING
  4606. addFormatToken('S', 0, 0, function () {
  4607. return ~~(this.millisecond() / 100);
  4608. });
  4609. addFormatToken(0, ['SS', 2], 0, function () {
  4610. return ~~(this.millisecond() / 10);
  4611. });
  4612. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  4613. addFormatToken(0, ['SSSS', 4], 0, function () {
  4614. return this.millisecond() * 10;
  4615. });
  4616. addFormatToken(0, ['SSSSS', 5], 0, function () {
  4617. return this.millisecond() * 100;
  4618. });
  4619. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  4620. return this.millisecond() * 1000;
  4621. });
  4622. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  4623. return this.millisecond() * 10000;
  4624. });
  4625. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  4626. return this.millisecond() * 100000;
  4627. });
  4628. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  4629. return this.millisecond() * 1000000;
  4630. });
  4631. // ALIASES
  4632. addUnitAlias('millisecond', 'ms');
  4633. // PRIORITY
  4634. addUnitPriority('millisecond', 16);
  4635. // PARSING
  4636. addRegexToken('S', match1to3, match1);
  4637. addRegexToken('SS', match1to3, match2);
  4638. addRegexToken('SSS', match1to3, match3);
  4639. var token;
  4640. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  4641. addRegexToken(token, matchUnsigned);
  4642. }
  4643. function parseMs(input, array) {
  4644. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  4645. }
  4646. for (token = 'S'; token.length <= 9; token += 'S') {
  4647. addParseToken(token, parseMs);
  4648. }
  4649. // MOMENTS
  4650. var getSetMillisecond = makeGetSet('Milliseconds', false);
  4651. // FORMATTING
  4652. addFormatToken('z', 0, 0, 'zoneAbbr');
  4653. addFormatToken('zz', 0, 0, 'zoneName');
  4654. // MOMENTS
  4655. function getZoneAbbr () {
  4656. return this._isUTC ? 'UTC' : '';
  4657. }
  4658. function getZoneName () {
  4659. return this._isUTC ? 'Coordinated Universal Time' : '';
  4660. }
  4661. var proto = Moment.prototype;
  4662. proto.add = add;
  4663. proto.calendar = calendar$1;
  4664. proto.clone = clone;
  4665. proto.diff = diff;
  4666. proto.endOf = endOf;
  4667. proto.format = format;
  4668. proto.from = from;
  4669. proto.fromNow = fromNow;
  4670. proto.to = to;
  4671. proto.toNow = toNow;
  4672. proto.get = stringGet;
  4673. proto.invalidAt = invalidAt;
  4674. proto.isAfter = isAfter;
  4675. proto.isBefore = isBefore;
  4676. proto.isBetween = isBetween;
  4677. proto.isSame = isSame;
  4678. proto.isSameOrAfter = isSameOrAfter;
  4679. proto.isSameOrBefore = isSameOrBefore;
  4680. proto.isValid = isValid$2;
  4681. proto.lang = lang;
  4682. proto.locale = locale;
  4683. proto.localeData = localeData;
  4684. proto.max = prototypeMax;
  4685. proto.min = prototypeMin;
  4686. proto.parsingFlags = parsingFlags;
  4687. proto.set = stringSet;
  4688. proto.startOf = startOf;
  4689. proto.subtract = subtract;
  4690. proto.toArray = toArray;
  4691. proto.toObject = toObject;
  4692. proto.toDate = toDate;
  4693. proto.toISOString = toISOString;
  4694. proto.inspect = inspect;
  4695. proto.toJSON = toJSON;
  4696. proto.toString = toString;
  4697. proto.unix = unix;
  4698. proto.valueOf = valueOf;
  4699. proto.creationData = creationData;
  4700. // Year
  4701. proto.year = getSetYear;
  4702. proto.isLeapYear = getIsLeapYear;
  4703. // Week Year
  4704. proto.weekYear = getSetWeekYear;
  4705. proto.isoWeekYear = getSetISOWeekYear;
  4706. // Quarter
  4707. proto.quarter = proto.quarters = getSetQuarter;
  4708. // Month
  4709. proto.month = getSetMonth;
  4710. proto.daysInMonth = getDaysInMonth;
  4711. // Week
  4712. proto.week = proto.weeks = getSetWeek;
  4713. proto.isoWeek = proto.isoWeeks = getSetISOWeek;
  4714. proto.weeksInYear = getWeeksInYear;
  4715. proto.isoWeeksInYear = getISOWeeksInYear;
  4716. // Day
  4717. proto.date = getSetDayOfMonth;
  4718. proto.day = proto.days = getSetDayOfWeek;
  4719. proto.weekday = getSetLocaleDayOfWeek;
  4720. proto.isoWeekday = getSetISODayOfWeek;
  4721. proto.dayOfYear = getSetDayOfYear;
  4722. // Hour
  4723. proto.hour = proto.hours = getSetHour;
  4724. // Minute
  4725. proto.minute = proto.minutes = getSetMinute;
  4726. // Second
  4727. proto.second = proto.seconds = getSetSecond;
  4728. // Millisecond
  4729. proto.millisecond = proto.milliseconds = getSetMillisecond;
  4730. // Offset
  4731. proto.utcOffset = getSetOffset;
  4732. proto.utc = setOffsetToUTC;
  4733. proto.local = setOffsetToLocal;
  4734. proto.parseZone = setOffsetToParsedOffset;
  4735. proto.hasAlignedHourOffset = hasAlignedHourOffset;
  4736. proto.isDST = isDaylightSavingTime;
  4737. proto.isLocal = isLocal;
  4738. proto.isUtcOffset = isUtcOffset;
  4739. proto.isUtc = isUtc;
  4740. proto.isUTC = isUtc;
  4741. // Timezone
  4742. proto.zoneAbbr = getZoneAbbr;
  4743. proto.zoneName = getZoneName;
  4744. // Deprecations
  4745. proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  4746. proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  4747. proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  4748. proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone);
  4749. proto.isDSTShifted = deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted);
  4750. function createUnix (input) {
  4751. return createLocal(input * 1000);
  4752. }
  4753. function createInZone () {
  4754. return createLocal.apply(null, arguments).parseZone();
  4755. }
  4756. function preParsePostFormat (string) {
  4757. return string;
  4758. }
  4759. var proto$1 = Locale.prototype;
  4760. proto$1.calendar = calendar;
  4761. proto$1.longDateFormat = longDateFormat;
  4762. proto$1.invalidDate = invalidDate;
  4763. proto$1.ordinal = ordinal;
  4764. proto$1.preparse = preParsePostFormat;
  4765. proto$1.postformat = preParsePostFormat;
  4766. proto$1.relativeTime = relativeTime;
  4767. proto$1.pastFuture = pastFuture;
  4768. proto$1.set = set;
  4769. // Month
  4770. proto$1.months = localeMonths;
  4771. proto$1.monthsShort = localeMonthsShort;
  4772. proto$1.monthsParse = localeMonthsParse;
  4773. proto$1.monthsRegex = monthsRegex;
  4774. proto$1.monthsShortRegex = monthsShortRegex;
  4775. // Week
  4776. proto$1.week = localeWeek;
  4777. proto$1.firstDayOfYear = localeFirstDayOfYear;
  4778. proto$1.firstDayOfWeek = localeFirstDayOfWeek;
  4779. // Day of Week
  4780. proto$1.weekdays = localeWeekdays;
  4781. proto$1.weekdaysMin = localeWeekdaysMin;
  4782. proto$1.weekdaysShort = localeWeekdaysShort;
  4783. proto$1.weekdaysParse = localeWeekdaysParse;
  4784. proto$1.weekdaysRegex = weekdaysRegex;
  4785. proto$1.weekdaysShortRegex = weekdaysShortRegex;
  4786. proto$1.weekdaysMinRegex = weekdaysMinRegex;
  4787. // Hours
  4788. proto$1.isPM = localeIsPM;
  4789. proto$1.meridiem = localeMeridiem;
  4790. function get$1 (format, index, field, setter) {
  4791. var locale = getLocale();
  4792. var utc = createUTC().set(setter, index);
  4793. return locale[field](utc, format);
  4794. }
  4795. function listMonthsImpl (format, index, field) {
  4796. if (isNumber(format)) {
  4797. index = format;
  4798. format = undefined;
  4799. }
  4800. format = format || '';
  4801. if (index != null) {
  4802. return get$1(format, index, field, 'month');
  4803. }
  4804. var i;
  4805. var out = [];
  4806. for (i = 0; i < 12; i++) {
  4807. out[i] = get$1(format, i, field, 'month');
  4808. }
  4809. return out;
  4810. }
  4811. // ()
  4812. // (5)
  4813. // (fmt, 5)
  4814. // (fmt)
  4815. // (true)
  4816. // (true, 5)
  4817. // (true, fmt, 5)
  4818. // (true, fmt)
  4819. function listWeekdaysImpl (localeSorted, format, index, field) {
  4820. if (typeof localeSorted === 'boolean') {
  4821. if (isNumber(format)) {
  4822. index = format;
  4823. format = undefined;
  4824. }
  4825. format = format || '';
  4826. } else {
  4827. format = localeSorted;
  4828. index = format;
  4829. localeSorted = false;
  4830. if (isNumber(format)) {
  4831. index = format;
  4832. format = undefined;
  4833. }
  4834. format = format || '';
  4835. }
  4836. var locale = getLocale(),
  4837. shift = localeSorted ? locale._week.dow : 0;
  4838. if (index != null) {
  4839. return get$1(format, (index + shift) % 7, field, 'day');
  4840. }
  4841. var i;
  4842. var out = [];
  4843. for (i = 0; i < 7; i++) {
  4844. out[i] = get$1(format, (i + shift) % 7, field, 'day');
  4845. }
  4846. return out;
  4847. }
  4848. function listMonths (format, index) {
  4849. return listMonthsImpl(format, index, 'months');
  4850. }
  4851. function listMonthsShort (format, index) {
  4852. return listMonthsImpl(format, index, 'monthsShort');
  4853. }
  4854. function listWeekdays (localeSorted, format, index) {
  4855. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  4856. }
  4857. function listWeekdaysShort (localeSorted, format, index) {
  4858. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  4859. }
  4860. function listWeekdaysMin (localeSorted, format, index) {
  4861. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  4862. }
  4863. getSetGlobalLocale('en', {
  4864. dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
  4865. ordinal : function (number) {
  4866. var b = number % 10,
  4867. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  4868. (b === 1) ? 'st' :
  4869. (b === 2) ? 'nd' :
  4870. (b === 3) ? 'rd' : 'th';
  4871. return number + output;
  4872. }
  4873. });
  4874. // Side effect imports
  4875. hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', getSetGlobalLocale);
  4876. hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', getLocale);
  4877. var mathAbs = Math.abs;
  4878. function abs () {
  4879. var data = this._data;
  4880. this._milliseconds = mathAbs(this._milliseconds);
  4881. this._days = mathAbs(this._days);
  4882. this._months = mathAbs(this._months);
  4883. data.milliseconds = mathAbs(data.milliseconds);
  4884. data.seconds = mathAbs(data.seconds);
  4885. data.minutes = mathAbs(data.minutes);
  4886. data.hours = mathAbs(data.hours);
  4887. data.months = mathAbs(data.months);
  4888. data.years = mathAbs(data.years);
  4889. return this;
  4890. }
  4891. function addSubtract$1 (duration, input, value, direction) {
  4892. var other = createDuration(input, value);
  4893. duration._milliseconds += direction * other._milliseconds;
  4894. duration._days += direction * other._days;
  4895. duration._months += direction * other._months;
  4896. return duration._bubble();
  4897. }
  4898. // supports only 2.0-style add(1, 's') or add(duration)
  4899. function add$1 (input, value) {
  4900. return addSubtract$1(this, input, value, 1);
  4901. }
  4902. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  4903. function subtract$1 (input, value) {
  4904. return addSubtract$1(this, input, value, -1);
  4905. }
  4906. function absCeil (number) {
  4907. if (number < 0) {
  4908. return Math.floor(number);
  4909. } else {
  4910. return Math.ceil(number);
  4911. }
  4912. }
  4913. function bubble () {
  4914. var milliseconds = this._milliseconds;
  4915. var days = this._days;
  4916. var months = this._months;
  4917. var data = this._data;
  4918. var seconds, minutes, hours, years, monthsFromDays;
  4919. // if we have a mix of positive and negative values, bubble down first
  4920. // check: https://github.com/moment/moment/issues/2166
  4921. if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  4922. (milliseconds <= 0 && days <= 0 && months <= 0))) {
  4923. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  4924. days = 0;
  4925. months = 0;
  4926. }
  4927. // The following code bubbles up values, see the tests for
  4928. // examples of what that means.
  4929. data.milliseconds = milliseconds % 1000;
  4930. seconds = absFloor(milliseconds / 1000);
  4931. data.seconds = seconds % 60;
  4932. minutes = absFloor(seconds / 60);
  4933. data.minutes = minutes % 60;
  4934. hours = absFloor(minutes / 60);
  4935. data.hours = hours % 24;
  4936. days += absFloor(hours / 24);
  4937. // convert days to months
  4938. monthsFromDays = absFloor(daysToMonths(days));
  4939. months += monthsFromDays;
  4940. days -= absCeil(monthsToDays(monthsFromDays));
  4941. // 12 months -> 1 year
  4942. years = absFloor(months / 12);
  4943. months %= 12;
  4944. data.days = days;
  4945. data.months = months;
  4946. data.years = years;
  4947. return this;
  4948. }
  4949. function daysToMonths (days) {
  4950. // 400 years have 146097 days (taking into account leap year rules)
  4951. // 400 years have 12 months === 4800
  4952. return days * 4800 / 146097;
  4953. }
  4954. function monthsToDays (months) {
  4955. // the reverse of daysToMonths
  4956. return months * 146097 / 4800;
  4957. }
  4958. function as (units) {
  4959. if (!this.isValid()) {
  4960. return NaN;
  4961. }
  4962. var days;
  4963. var months;
  4964. var milliseconds = this._milliseconds;
  4965. units = normalizeUnits(units);
  4966. if (units === 'month' || units === 'year') {
  4967. days = this._days + milliseconds / 864e5;
  4968. months = this._months + daysToMonths(days);
  4969. return units === 'month' ? months : months / 12;
  4970. } else {
  4971. // handle milliseconds separately because of floating point math errors (issue #1867)
  4972. days = this._days + Math.round(monthsToDays(this._months));
  4973. switch (units) {
  4974. case 'week' : return days / 7 + milliseconds / 6048e5;
  4975. case 'day' : return days + milliseconds / 864e5;
  4976. case 'hour' : return days * 24 + milliseconds / 36e5;
  4977. case 'minute' : return days * 1440 + milliseconds / 6e4;
  4978. case 'second' : return days * 86400 + milliseconds / 1000;
  4979. // Math.floor prevents floating point math errors here
  4980. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  4981. default: throw new Error('Unknown unit ' + units);
  4982. }
  4983. }
  4984. }
  4985. // TODO: Use this.as('ms')?
  4986. function valueOf$1 () {
  4987. if (!this.isValid()) {
  4988. return NaN;
  4989. }
  4990. return (
  4991. this._milliseconds +
  4992. this._days * 864e5 +
  4993. (this._months % 12) * 2592e6 +
  4994. toInt(this._months / 12) * 31536e6
  4995. );
  4996. }
  4997. function makeAs (alias) {
  4998. return function () {
  4999. return this.as(alias);
  5000. };
  5001. }
  5002. var asMilliseconds = makeAs('ms');
  5003. var asSeconds = makeAs('s');
  5004. var asMinutes = makeAs('m');
  5005. var asHours = makeAs('h');
  5006. var asDays = makeAs('d');
  5007. var asWeeks = makeAs('w');
  5008. var asMonths = makeAs('M');
  5009. var asYears = makeAs('y');
  5010. function clone$1 () {
  5011. return createDuration(this);
  5012. }
  5013. function get$2 (units) {
  5014. units = normalizeUnits(units);
  5015. return this.isValid() ? this[units + 's']() : NaN;
  5016. }
  5017. function makeGetter(name) {
  5018. return function () {
  5019. return this.isValid() ? this._data[name] : NaN;
  5020. };
  5021. }
  5022. var milliseconds = makeGetter('milliseconds');
  5023. var seconds = makeGetter('seconds');
  5024. var minutes = makeGetter('minutes');
  5025. var hours = makeGetter('hours');
  5026. var days = makeGetter('days');
  5027. var months = makeGetter('months');
  5028. var years = makeGetter('years');
  5029. function weeks () {
  5030. return absFloor(this.days() / 7);
  5031. }
  5032. var round = Math.round;
  5033. var thresholds = {
  5034. ss: 44, // a few seconds to seconds
  5035. s : 45, // seconds to minute
  5036. m : 45, // minutes to hour
  5037. h : 22, // hours to day
  5038. d : 26, // days to month
  5039. M : 11 // months to year
  5040. };
  5041. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  5042. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  5043. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  5044. }
  5045. function relativeTime$1 (posNegDuration, withoutSuffix, locale) {
  5046. var duration = createDuration(posNegDuration).abs();
  5047. var seconds = round(duration.as('s'));
  5048. var minutes = round(duration.as('m'));
  5049. var hours = round(duration.as('h'));
  5050. var days = round(duration.as('d'));
  5051. var months = round(duration.as('M'));
  5052. var years = round(duration.as('y'));
  5053. var a = seconds <= thresholds.ss && ['s', seconds] ||
  5054. seconds < thresholds.s && ['ss', seconds] ||
  5055. minutes <= 1 && ['m'] ||
  5056. minutes < thresholds.m && ['mm', minutes] ||
  5057. hours <= 1 && ['h'] ||
  5058. hours < thresholds.h && ['hh', hours] ||
  5059. days <= 1 && ['d'] ||
  5060. days < thresholds.d && ['dd', days] ||
  5061. months <= 1 && ['M'] ||
  5062. months < thresholds.M && ['MM', months] ||
  5063. years <= 1 && ['y'] || ['yy', years];
  5064. a[2] = withoutSuffix;
  5065. a[3] = +posNegDuration > 0;
  5066. a[4] = locale;
  5067. return substituteTimeAgo.apply(null, a);
  5068. }
  5069. // This function allows you to set the rounding function for relative time strings
  5070. function getSetRelativeTimeRounding (roundingFunction) {
  5071. if (roundingFunction === undefined) {
  5072. return round;
  5073. }
  5074. if (typeof(roundingFunction) === 'function') {
  5075. round = roundingFunction;
  5076. return true;
  5077. }
  5078. return false;
  5079. }
  5080. // This function allows you to set a threshold for relative time strings
  5081. function getSetRelativeTimeThreshold (threshold, limit) {
  5082. if (thresholds[threshold] === undefined) {
  5083. return false;
  5084. }
  5085. if (limit === undefined) {
  5086. return thresholds[threshold];
  5087. }
  5088. thresholds[threshold] = limit;
  5089. if (threshold === 's') {
  5090. thresholds.ss = limit - 1;
  5091. }
  5092. return true;
  5093. }
  5094. function humanize (withSuffix) {
  5095. if (!this.isValid()) {
  5096. return this.localeData().invalidDate();
  5097. }
  5098. var locale = this.localeData();
  5099. var output = relativeTime$1(this, !withSuffix, locale);
  5100. if (withSuffix) {
  5101. output = locale.pastFuture(+this, output);
  5102. }
  5103. return locale.postformat(output);
  5104. }
  5105. var abs$1 = Math.abs;
  5106. function sign(x) {
  5107. return ((x > 0) - (x < 0)) || +x;
  5108. }
  5109. function toISOString$1() {
  5110. // for ISO strings we do not use the normal bubbling rules:
  5111. // * milliseconds bubble up until they become hours
  5112. // * days do not bubble at all
  5113. // * months bubble up until they become years
  5114. // This is because there is no context-free conversion between hours and days
  5115. // (think of clock changes)
  5116. // and also not between days and months (28-31 days per month)
  5117. if (!this.isValid()) {
  5118. return this.localeData().invalidDate();
  5119. }
  5120. var seconds = abs$1(this._milliseconds) / 1000;
  5121. var days = abs$1(this._days);
  5122. var months = abs$1(this._months);
  5123. var minutes, hours, years;
  5124. // 3600 seconds -> 60 minutes -> 1 hour
  5125. minutes = absFloor(seconds / 60);
  5126. hours = absFloor(minutes / 60);
  5127. seconds %= 60;
  5128. minutes %= 60;
  5129. // 12 months -> 1 year
  5130. years = absFloor(months / 12);
  5131. months %= 12;
  5132. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  5133. var Y = years;
  5134. var M = months;
  5135. var D = days;
  5136. var h = hours;
  5137. var m = minutes;
  5138. var s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
  5139. var total = this.asSeconds();
  5140. if (!total) {
  5141. // this is the same as C#'s (Noda) and python (isodate)...
  5142. // but not other JS (goog.date)
  5143. return 'P0D';
  5144. }
  5145. var totalSign = total < 0 ? '-' : '';
  5146. var ymSign = sign(this._months) !== sign(total) ? '-' : '';
  5147. var daysSign = sign(this._days) !== sign(total) ? '-' : '';
  5148. var hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
  5149. return totalSign + 'P' +
  5150. (Y ? ymSign + Y + 'Y' : '') +
  5151. (M ? ymSign + M + 'M' : '') +
  5152. (D ? daysSign + D + 'D' : '') +
  5153. ((h || m || s) ? 'T' : '') +
  5154. (h ? hmsSign + h + 'H' : '') +
  5155. (m ? hmsSign + m + 'M' : '') +
  5156. (s ? hmsSign + s + 'S' : '');
  5157. }
  5158. var proto$2 = Duration.prototype;
  5159. proto$2.isValid = isValid$1;
  5160. proto$2.abs = abs;
  5161. proto$2.add = add$1;
  5162. proto$2.subtract = subtract$1;
  5163. proto$2.as = as;
  5164. proto$2.asMilliseconds = asMilliseconds;
  5165. proto$2.asSeconds = asSeconds;
  5166. proto$2.asMinutes = asMinutes;
  5167. proto$2.asHours = asHours;
  5168. proto$2.asDays = asDays;
  5169. proto$2.asWeeks = asWeeks;
  5170. proto$2.asMonths = asMonths;
  5171. proto$2.asYears = asYears;
  5172. proto$2.valueOf = valueOf$1;
  5173. proto$2._bubble = bubble;
  5174. proto$2.clone = clone$1;
  5175. proto$2.get = get$2;
  5176. proto$2.milliseconds = milliseconds;
  5177. proto$2.seconds = seconds;
  5178. proto$2.minutes = minutes;
  5179. proto$2.hours = hours;
  5180. proto$2.days = days;
  5181. proto$2.weeks = weeks;
  5182. proto$2.months = months;
  5183. proto$2.years = years;
  5184. proto$2.humanize = humanize;
  5185. proto$2.toISOString = toISOString$1;
  5186. proto$2.toString = toISOString$1;
  5187. proto$2.toJSON = toISOString$1;
  5188. proto$2.locale = locale;
  5189. proto$2.localeData = localeData;
  5190. // Deprecations
  5191. proto$2.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', toISOString$1);
  5192. proto$2.lang = lang;
  5193. // Side effect imports
  5194. // FORMATTING
  5195. addFormatToken('X', 0, 0, 'unix');
  5196. addFormatToken('x', 0, 0, 'valueOf');
  5197. // PARSING
  5198. addRegexToken('x', matchSigned);
  5199. addRegexToken('X', matchTimestamp);
  5200. addParseToken('X', function (input, array, config) {
  5201. config._d = new Date(parseFloat(input, 10) * 1000);
  5202. });
  5203. addParseToken('x', function (input, array, config) {
  5204. config._d = new Date(toInt(input));
  5205. });
  5206. // Side effect imports
  5207. hooks.version = '2.20.1';
  5208. setHookCallback(createLocal);
  5209. hooks.fn = proto;
  5210. hooks.min = min;
  5211. hooks.max = max;
  5212. hooks.now = now;
  5213. hooks.utc = createUTC;
  5214. hooks.unix = createUnix;
  5215. hooks.months = listMonths;
  5216. hooks.isDate = isDate;
  5217. hooks.locale = getSetGlobalLocale;
  5218. hooks.invalid = createInvalid;
  5219. hooks.duration = createDuration;
  5220. hooks.isMoment = isMoment;
  5221. hooks.weekdays = listWeekdays;
  5222. hooks.parseZone = createInZone;
  5223. hooks.localeData = getLocale;
  5224. hooks.isDuration = isDuration;
  5225. hooks.monthsShort = listMonthsShort;
  5226. hooks.weekdaysMin = listWeekdaysMin;
  5227. hooks.defineLocale = defineLocale;
  5228. hooks.updateLocale = updateLocale;
  5229. hooks.locales = listLocales;
  5230. hooks.weekdaysShort = listWeekdaysShort;
  5231. hooks.normalizeUnits = normalizeUnits;
  5232. hooks.relativeTimeRounding = getSetRelativeTimeRounding;
  5233. hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
  5234. hooks.calendarFormat = getCalendarFormat;
  5235. hooks.prototype = proto;
  5236. // currently HTML5 input type only supports 24-hour formats
  5237. hooks.HTML5_FMT = {
  5238. DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
  5239. DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
  5240. DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
  5241. DATE: 'YYYY-MM-DD', // <input type="date" />
  5242. TIME: 'HH:mm', // <input type="time" />
  5243. TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
  5244. TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
  5245. WEEK: 'YYYY-[W]WW', // <input type="week" />
  5246. MONTH: 'YYYY-MM' // <input type="month" />
  5247. };
  5248. return hooks;
  5249. })));
  5250. },{}],7:[function(require,module,exports){
  5251. /**
  5252. * @namespace Chart
  5253. */
  5254. var Chart = require(29)();
  5255. Chart.helpers = require(45);
  5256. // @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
  5257. require(27)(Chart);
  5258. Chart.defaults = require(25);
  5259. Chart.Element = require(26);
  5260. Chart.elements = require(40);
  5261. Chart.Interaction = require(28);
  5262. Chart.layouts = require(30);
  5263. Chart.platform = require(48);
  5264. Chart.plugins = require(31);
  5265. Chart.Ticks = require(34);
  5266. require(22)(Chart);
  5267. require(23)(Chart);
  5268. require(24)(Chart);
  5269. require(33)(Chart);
  5270. require(32)(Chart);
  5271. require(35)(Chart);
  5272. require(55)(Chart);
  5273. require(53)(Chart);
  5274. require(54)(Chart);
  5275. require(56)(Chart);
  5276. require(57)(Chart);
  5277. require(58)(Chart);
  5278. // Controllers must be loaded after elements
  5279. // See Chart.core.datasetController.dataElementType
  5280. require(15)(Chart);
  5281. require(16)(Chart);
  5282. require(17)(Chart);
  5283. require(18)(Chart);
  5284. require(19)(Chart);
  5285. require(20)(Chart);
  5286. require(21)(Chart);
  5287. require(8)(Chart);
  5288. require(9)(Chart);
  5289. require(10)(Chart);
  5290. require(11)(Chart);
  5291. require(12)(Chart);
  5292. require(13)(Chart);
  5293. require(14)(Chart);
  5294. // Loading built-it plugins
  5295. var plugins = require(49);
  5296. for (var k in plugins) {
  5297. if (plugins.hasOwnProperty(k)) {
  5298. Chart.plugins.register(plugins[k]);
  5299. }
  5300. }
  5301. Chart.platform.initialize();
  5302. module.exports = Chart;
  5303. if (typeof window !== 'undefined') {
  5304. window.Chart = Chart;
  5305. }
  5306. // DEPRECATIONS
  5307. /**
  5308. * Provided for backward compatibility, not available anymore
  5309. * @namespace Chart.Legend
  5310. * @deprecated since version 2.1.5
  5311. * @todo remove at version 3
  5312. * @private
  5313. */
  5314. Chart.Legend = plugins.legend._element;
  5315. /**
  5316. * Provided for backward compatibility, not available anymore
  5317. * @namespace Chart.Title
  5318. * @deprecated since version 2.1.5
  5319. * @todo remove at version 3
  5320. * @private
  5321. */
  5322. Chart.Title = plugins.title._element;
  5323. /**
  5324. * Provided for backward compatibility, use Chart.plugins instead
  5325. * @namespace Chart.pluginService
  5326. * @deprecated since version 2.1.5
  5327. * @todo remove at version 3
  5328. * @private
  5329. */
  5330. Chart.pluginService = Chart.plugins;
  5331. /**
  5332. * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
  5333. * effect, instead simply create/register plugins via plain JavaScript objects.
  5334. * @interface Chart.PluginBase
  5335. * @deprecated since version 2.5.0
  5336. * @todo remove at version 3
  5337. * @private
  5338. */
  5339. Chart.PluginBase = Chart.Element.extend({});
  5340. /**
  5341. * Provided for backward compatibility, use Chart.helpers.canvas instead.
  5342. * @namespace Chart.canvasHelpers
  5343. * @deprecated since version 2.6.0
  5344. * @todo remove at version 3
  5345. * @private
  5346. */
  5347. Chart.canvasHelpers = Chart.helpers.canvas;
  5348. /**
  5349. * Provided for backward compatibility, use Chart.layouts instead.
  5350. * @namespace Chart.layoutService
  5351. * @deprecated since version 2.8.0
  5352. * @todo remove at version 3
  5353. * @private
  5354. */
  5355. Chart.layoutService = Chart.layouts;
  5356. },{"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,"40":40,"45":45,"48":48,"49":49,"53":53,"54":54,"55":55,"56":56,"57":57,"58":58,"8":8,"9":9}],8:[function(require,module,exports){
  5357. 'use strict';
  5358. module.exports = function(Chart) {
  5359. Chart.Bar = function(context, config) {
  5360. config.type = 'bar';
  5361. return new Chart(context, config);
  5362. };
  5363. };
  5364. },{}],9:[function(require,module,exports){
  5365. 'use strict';
  5366. module.exports = function(Chart) {
  5367. Chart.Bubble = function(context, config) {
  5368. config.type = 'bubble';
  5369. return new Chart(context, config);
  5370. };
  5371. };
  5372. },{}],10:[function(require,module,exports){
  5373. 'use strict';
  5374. module.exports = function(Chart) {
  5375. Chart.Doughnut = function(context, config) {
  5376. config.type = 'doughnut';
  5377. return new Chart(context, config);
  5378. };
  5379. };
  5380. },{}],11:[function(require,module,exports){
  5381. 'use strict';
  5382. module.exports = function(Chart) {
  5383. Chart.Line = function(context, config) {
  5384. config.type = 'line';
  5385. return new Chart(context, config);
  5386. };
  5387. };
  5388. },{}],12:[function(require,module,exports){
  5389. 'use strict';
  5390. module.exports = function(Chart) {
  5391. Chart.PolarArea = function(context, config) {
  5392. config.type = 'polarArea';
  5393. return new Chart(context, config);
  5394. };
  5395. };
  5396. },{}],13:[function(require,module,exports){
  5397. 'use strict';
  5398. module.exports = function(Chart) {
  5399. Chart.Radar = function(context, config) {
  5400. config.type = 'radar';
  5401. return new Chart(context, config);
  5402. };
  5403. };
  5404. },{}],14:[function(require,module,exports){
  5405. 'use strict';
  5406. module.exports = function(Chart) {
  5407. Chart.Scatter = function(context, config) {
  5408. config.type = 'scatter';
  5409. return new Chart(context, config);
  5410. };
  5411. };
  5412. },{}],15:[function(require,module,exports){
  5413. 'use strict';
  5414. var defaults = require(25);
  5415. var elements = require(40);
  5416. var helpers = require(45);
  5417. defaults._set('bar', {
  5418. hover: {
  5419. mode: 'label'
  5420. },
  5421. scales: {
  5422. xAxes: [{
  5423. type: 'category',
  5424. // Specific to Bar Controller
  5425. categoryPercentage: 0.8,
  5426. barPercentage: 0.9,
  5427. // offset settings
  5428. offset: true,
  5429. // grid line settings
  5430. gridLines: {
  5431. offsetGridLines: true
  5432. }
  5433. }],
  5434. yAxes: [{
  5435. type: 'linear'
  5436. }]
  5437. }
  5438. });
  5439. defaults._set('horizontalBar', {
  5440. hover: {
  5441. mode: 'index',
  5442. axis: 'y'
  5443. },
  5444. scales: {
  5445. xAxes: [{
  5446. type: 'linear',
  5447. position: 'bottom'
  5448. }],
  5449. yAxes: [{
  5450. position: 'left',
  5451. type: 'category',
  5452. // Specific to Horizontal Bar Controller
  5453. categoryPercentage: 0.8,
  5454. barPercentage: 0.9,
  5455. // offset settings
  5456. offset: true,
  5457. // grid line settings
  5458. gridLines: {
  5459. offsetGridLines: true
  5460. }
  5461. }]
  5462. },
  5463. elements: {
  5464. rectangle: {
  5465. borderSkipped: 'left'
  5466. }
  5467. },
  5468. tooltips: {
  5469. callbacks: {
  5470. title: function(item, data) {
  5471. // Pick first xLabel for now
  5472. var title = '';
  5473. if (item.length > 0) {
  5474. if (item[0].yLabel) {
  5475. title = item[0].yLabel;
  5476. } else if (data.labels.length > 0 && item[0].index < data.labels.length) {
  5477. title = data.labels[item[0].index];
  5478. }
  5479. }
  5480. return title;
  5481. },
  5482. label: function(item, data) {
  5483. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  5484. return datasetLabel + ': ' + item.xLabel;
  5485. }
  5486. },
  5487. mode: 'index',
  5488. axis: 'y'
  5489. }
  5490. });
  5491. /**
  5492. * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  5493. * @private
  5494. */
  5495. function computeMinSampleSize(scale, pixels) {
  5496. var min = scale.isHorizontal() ? scale.width : scale.height;
  5497. var ticks = scale.getTicks();
  5498. var prev, curr, i, ilen;
  5499. for (i = 1, ilen = pixels.length; i < ilen; ++i) {
  5500. min = Math.min(min, pixels[i] - pixels[i - 1]);
  5501. }
  5502. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  5503. curr = scale.getPixelForTick(i);
  5504. min = i > 0 ? Math.min(min, curr - prev) : min;
  5505. prev = curr;
  5506. }
  5507. return min;
  5508. }
  5509. /**
  5510. * Computes an "ideal" category based on the absolute bar thickness or, if undefined or null,
  5511. * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This
  5512. * mode currently always generates bars equally sized (until we introduce scriptable options?).
  5513. * @private
  5514. */
  5515. function computeFitCategoryTraits(index, ruler, options) {
  5516. var thickness = options.barThickness;
  5517. var count = ruler.stackCount;
  5518. var curr = ruler.pixels[index];
  5519. var size, ratio;
  5520. if (helpers.isNullOrUndef(thickness)) {
  5521. size = ruler.min * options.categoryPercentage;
  5522. ratio = options.barPercentage;
  5523. } else {
  5524. // When bar thickness is enforced, category and bar percentages are ignored.
  5525. // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
  5526. // and deprecate barPercentage since this value is ignored when thickness is absolute.
  5527. size = thickness * count;
  5528. ratio = 1;
  5529. }
  5530. return {
  5531. chunk: size / count,
  5532. ratio: ratio,
  5533. start: curr - (size / 2)
  5534. };
  5535. }
  5536. /**
  5537. * Computes an "optimal" category that globally arranges bars side by side (no gap when
  5538. * percentage options are 1), based on the previous and following categories. This mode
  5539. * generates bars with different widths when data are not evenly spaced.
  5540. * @private
  5541. */
  5542. function computeFlexCategoryTraits(index, ruler, options) {
  5543. var pixels = ruler.pixels;
  5544. var curr = pixels[index];
  5545. var prev = index > 0 ? pixels[index - 1] : null;
  5546. var next = index < pixels.length - 1 ? pixels[index + 1] : null;
  5547. var percent = options.categoryPercentage;
  5548. var start, size;
  5549. if (prev === null) {
  5550. // first data: its size is double based on the next point or,
  5551. // if it's also the last data, we use the scale end extremity.
  5552. prev = curr - (next === null ? ruler.end - curr : next - curr);
  5553. }
  5554. if (next === null) {
  5555. // last data: its size is also double based on the previous point.
  5556. next = curr + curr - prev;
  5557. }
  5558. start = curr - ((curr - prev) / 2) * percent;
  5559. size = ((next - prev) / 2) * percent;
  5560. return {
  5561. chunk: size / ruler.stackCount,
  5562. ratio: options.barPercentage,
  5563. start: start
  5564. };
  5565. }
  5566. module.exports = function(Chart) {
  5567. Chart.controllers.bar = Chart.DatasetController.extend({
  5568. dataElementType: elements.Rectangle,
  5569. initialize: function() {
  5570. var me = this;
  5571. var meta;
  5572. Chart.DatasetController.prototype.initialize.apply(me, arguments);
  5573. meta = me.getMeta();
  5574. meta.stack = me.getDataset().stack;
  5575. meta.bar = true;
  5576. },
  5577. update: function(reset) {
  5578. var me = this;
  5579. var rects = me.getMeta().data;
  5580. var i, ilen;
  5581. me._ruler = me.getRuler();
  5582. for (i = 0, ilen = rects.length; i < ilen; ++i) {
  5583. me.updateElement(rects[i], i, reset);
  5584. }
  5585. },
  5586. updateElement: function(rectangle, index, reset) {
  5587. var me = this;
  5588. var chart = me.chart;
  5589. var meta = me.getMeta();
  5590. var dataset = me.getDataset();
  5591. var custom = rectangle.custom || {};
  5592. var rectangleOptions = chart.options.elements.rectangle;
  5593. rectangle._xScale = me.getScaleForId(meta.xAxisID);
  5594. rectangle._yScale = me.getScaleForId(meta.yAxisID);
  5595. rectangle._datasetIndex = me.index;
  5596. rectangle._index = index;
  5597. rectangle._model = {
  5598. datasetLabel: dataset.label,
  5599. label: chart.data.labels[index],
  5600. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped,
  5601. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor),
  5602. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor),
  5603. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth)
  5604. };
  5605. me.updateElementGeometry(rectangle, index, reset);
  5606. rectangle.pivot();
  5607. },
  5608. /**
  5609. * @private
  5610. */
  5611. updateElementGeometry: function(rectangle, index, reset) {
  5612. var me = this;
  5613. var model = rectangle._model;
  5614. var vscale = me.getValueScale();
  5615. var base = vscale.getBasePixel();
  5616. var horizontal = vscale.isHorizontal();
  5617. var ruler = me._ruler || me.getRuler();
  5618. var vpixels = me.calculateBarValuePixels(me.index, index);
  5619. var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
  5620. model.horizontal = horizontal;
  5621. model.base = reset ? base : vpixels.base;
  5622. model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
  5623. model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
  5624. model.height = horizontal ? ipixels.size : undefined;
  5625. model.width = horizontal ? undefined : ipixels.size;
  5626. },
  5627. /**
  5628. * @private
  5629. */
  5630. getValueScaleId: function() {
  5631. return this.getMeta().yAxisID;
  5632. },
  5633. /**
  5634. * @private
  5635. */
  5636. getIndexScaleId: function() {
  5637. return this.getMeta().xAxisID;
  5638. },
  5639. /**
  5640. * @private
  5641. */
  5642. getValueScale: function() {
  5643. return this.getScaleForId(this.getValueScaleId());
  5644. },
  5645. /**
  5646. * @private
  5647. */
  5648. getIndexScale: function() {
  5649. return this.getScaleForId(this.getIndexScaleId());
  5650. },
  5651. /**
  5652. * Returns the stacks based on groups and bar visibility.
  5653. * @param {Number} [last] - The dataset index
  5654. * @returns {Array} The stack list
  5655. * @private
  5656. */
  5657. _getStacks: function(last) {
  5658. var me = this;
  5659. var chart = me.chart;
  5660. var scale = me.getIndexScale();
  5661. var stacked = scale.options.stacked;
  5662. var ilen = last === undefined ? chart.data.datasets.length : last + 1;
  5663. var stacks = [];
  5664. var i, meta;
  5665. for (i = 0; i < ilen; ++i) {
  5666. meta = chart.getDatasetMeta(i);
  5667. if (meta.bar && chart.isDatasetVisible(i) &&
  5668. (stacked === false ||
  5669. (stacked === true && stacks.indexOf(meta.stack) === -1) ||
  5670. (stacked === undefined && (meta.stack === undefined || stacks.indexOf(meta.stack) === -1)))) {
  5671. stacks.push(meta.stack);
  5672. }
  5673. }
  5674. return stacks;
  5675. },
  5676. /**
  5677. * Returns the effective number of stacks based on groups and bar visibility.
  5678. * @private
  5679. */
  5680. getStackCount: function() {
  5681. return this._getStacks().length;
  5682. },
  5683. /**
  5684. * Returns the stack index for the given dataset based on groups and bar visibility.
  5685. * @param {Number} [datasetIndex] - The dataset index
  5686. * @param {String} [name] - The stack name to find
  5687. * @returns {Number} The stack index
  5688. * @private
  5689. */
  5690. getStackIndex: function(datasetIndex, name) {
  5691. var stacks = this._getStacks(datasetIndex);
  5692. var index = (name !== undefined)
  5693. ? stacks.indexOf(name)
  5694. : -1; // indexOf returns -1 if element is not present
  5695. return (index === -1)
  5696. ? stacks.length - 1
  5697. : index;
  5698. },
  5699. /**
  5700. * @private
  5701. */
  5702. getRuler: function() {
  5703. var me = this;
  5704. var scale = me.getIndexScale();
  5705. var stackCount = me.getStackCount();
  5706. var datasetIndex = me.index;
  5707. var isHorizontal = scale.isHorizontal();
  5708. var start = isHorizontal ? scale.left : scale.top;
  5709. var end = start + (isHorizontal ? scale.width : scale.height);
  5710. var pixels = [];
  5711. var i, ilen, min;
  5712. for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
  5713. pixels.push(scale.getPixelForValue(null, i, datasetIndex));
  5714. }
  5715. min = helpers.isNullOrUndef(scale.options.barThickness)
  5716. ? computeMinSampleSize(scale, pixels)
  5717. : -1;
  5718. return {
  5719. min: min,
  5720. pixels: pixels,
  5721. start: start,
  5722. end: end,
  5723. stackCount: stackCount,
  5724. scale: scale
  5725. };
  5726. },
  5727. /**
  5728. * Note: pixel values are not clamped to the scale area.
  5729. * @private
  5730. */
  5731. calculateBarValuePixels: function(datasetIndex, index) {
  5732. var me = this;
  5733. var chart = me.chart;
  5734. var meta = me.getMeta();
  5735. var scale = me.getValueScale();
  5736. var datasets = chart.data.datasets;
  5737. var value = scale.getRightValue(datasets[datasetIndex].data[index]);
  5738. var stacked = scale.options.stacked;
  5739. var stack = meta.stack;
  5740. var start = 0;
  5741. var i, imeta, ivalue, base, head, size;
  5742. if (stacked || (stacked === undefined && stack !== undefined)) {
  5743. for (i = 0; i < datasetIndex; ++i) {
  5744. imeta = chart.getDatasetMeta(i);
  5745. if (imeta.bar &&
  5746. imeta.stack === stack &&
  5747. imeta.controller.getValueScaleId() === scale.id &&
  5748. chart.isDatasetVisible(i)) {
  5749. ivalue = scale.getRightValue(datasets[i].data[index]);
  5750. if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
  5751. start += ivalue;
  5752. }
  5753. }
  5754. }
  5755. }
  5756. base = scale.getPixelForValue(start);
  5757. head = scale.getPixelForValue(start + value);
  5758. size = (head - base) / 2;
  5759. return {
  5760. size: size,
  5761. base: base,
  5762. head: head,
  5763. center: head + size / 2
  5764. };
  5765. },
  5766. /**
  5767. * @private
  5768. */
  5769. calculateBarIndexPixels: function(datasetIndex, index, ruler) {
  5770. var me = this;
  5771. var options = ruler.scale.options;
  5772. var range = options.barThickness === 'flex'
  5773. ? computeFlexCategoryTraits(index, ruler, options)
  5774. : computeFitCategoryTraits(index, ruler, options);
  5775. var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
  5776. var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
  5777. var size = Math.min(
  5778. helpers.valueOrDefault(options.maxBarThickness, Infinity),
  5779. range.chunk * range.ratio);
  5780. return {
  5781. base: center - size / 2,
  5782. head: center + size / 2,
  5783. center: center,
  5784. size: size
  5785. };
  5786. },
  5787. draw: function() {
  5788. var me = this;
  5789. var chart = me.chart;
  5790. var scale = me.getValueScale();
  5791. var rects = me.getMeta().data;
  5792. var dataset = me.getDataset();
  5793. var ilen = rects.length;
  5794. var i = 0;
  5795. helpers.canvas.clipArea(chart.ctx, chart.chartArea);
  5796. for (; i < ilen; ++i) {
  5797. if (!isNaN(scale.getRightValue(dataset.data[i]))) {
  5798. rects[i].draw();
  5799. }
  5800. }
  5801. helpers.canvas.unclipArea(chart.ctx);
  5802. },
  5803. setHoverStyle: function(rectangle) {
  5804. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  5805. var index = rectangle._index;
  5806. var custom = rectangle.custom || {};
  5807. var model = rectangle._model;
  5808. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  5809. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  5810. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  5811. },
  5812. removeHoverStyle: function(rectangle) {
  5813. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  5814. var index = rectangle._index;
  5815. var custom = rectangle.custom || {};
  5816. var model = rectangle._model;
  5817. var rectangleElementOptions = this.chart.options.elements.rectangle;
  5818. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor);
  5819. model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor);
  5820. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth);
  5821. }
  5822. });
  5823. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  5824. /**
  5825. * @private
  5826. */
  5827. getValueScaleId: function() {
  5828. return this.getMeta().xAxisID;
  5829. },
  5830. /**
  5831. * @private
  5832. */
  5833. getIndexScaleId: function() {
  5834. return this.getMeta().yAxisID;
  5835. }
  5836. });
  5837. };
  5838. },{"25":25,"40":40,"45":45}],16:[function(require,module,exports){
  5839. 'use strict';
  5840. var defaults = require(25);
  5841. var elements = require(40);
  5842. var helpers = require(45);
  5843. defaults._set('bubble', {
  5844. hover: {
  5845. mode: 'single'
  5846. },
  5847. scales: {
  5848. xAxes: [{
  5849. type: 'linear', // bubble should probably use a linear scale by default
  5850. position: 'bottom',
  5851. id: 'x-axis-0' // need an ID so datasets can reference the scale
  5852. }],
  5853. yAxes: [{
  5854. type: 'linear',
  5855. position: 'left',
  5856. id: 'y-axis-0'
  5857. }]
  5858. },
  5859. tooltips: {
  5860. callbacks: {
  5861. title: function() {
  5862. // Title doesn't make sense for scatter since we format the data as a point
  5863. return '';
  5864. },
  5865. label: function(item, data) {
  5866. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  5867. var dataPoint = data.datasets[item.datasetIndex].data[item.index];
  5868. return datasetLabel + ': (' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.r + ')';
  5869. }
  5870. }
  5871. }
  5872. });
  5873. module.exports = function(Chart) {
  5874. Chart.controllers.bubble = Chart.DatasetController.extend({
  5875. /**
  5876. * @protected
  5877. */
  5878. dataElementType: elements.Point,
  5879. /**
  5880. * @protected
  5881. */
  5882. update: function(reset) {
  5883. var me = this;
  5884. var meta = me.getMeta();
  5885. var points = meta.data;
  5886. // Update Points
  5887. helpers.each(points, function(point, index) {
  5888. me.updateElement(point, index, reset);
  5889. });
  5890. },
  5891. /**
  5892. * @protected
  5893. */
  5894. updateElement: function(point, index, reset) {
  5895. var me = this;
  5896. var meta = me.getMeta();
  5897. var custom = point.custom || {};
  5898. var xScale = me.getScaleForId(meta.xAxisID);
  5899. var yScale = me.getScaleForId(meta.yAxisID);
  5900. var options = me._resolveElementOptions(point, index);
  5901. var data = me.getDataset().data[index];
  5902. var dsIndex = me.index;
  5903. var x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex);
  5904. var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex);
  5905. point._xScale = xScale;
  5906. point._yScale = yScale;
  5907. point._options = options;
  5908. point._datasetIndex = dsIndex;
  5909. point._index = index;
  5910. point._model = {
  5911. backgroundColor: options.backgroundColor,
  5912. borderColor: options.borderColor,
  5913. borderWidth: options.borderWidth,
  5914. hitRadius: options.hitRadius,
  5915. pointStyle: options.pointStyle,
  5916. radius: reset ? 0 : options.radius,
  5917. skip: custom.skip || isNaN(x) || isNaN(y),
  5918. x: x,
  5919. y: y,
  5920. };
  5921. point.pivot();
  5922. },
  5923. /**
  5924. * @protected
  5925. */
  5926. setHoverStyle: function(point) {
  5927. var model = point._model;
  5928. var options = point._options;
  5929. model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
  5930. model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
  5931. model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
  5932. model.radius = options.radius + options.hoverRadius;
  5933. },
  5934. /**
  5935. * @protected
  5936. */
  5937. removeHoverStyle: function(point) {
  5938. var model = point._model;
  5939. var options = point._options;
  5940. model.backgroundColor = options.backgroundColor;
  5941. model.borderColor = options.borderColor;
  5942. model.borderWidth = options.borderWidth;
  5943. model.radius = options.radius;
  5944. },
  5945. /**
  5946. * @private
  5947. */
  5948. _resolveElementOptions: function(point, index) {
  5949. var me = this;
  5950. var chart = me.chart;
  5951. var datasets = chart.data.datasets;
  5952. var dataset = datasets[me.index];
  5953. var custom = point.custom || {};
  5954. var options = chart.options.elements.point;
  5955. var resolve = helpers.options.resolve;
  5956. var data = dataset.data[index];
  5957. var values = {};
  5958. var i, ilen, key;
  5959. // Scriptable options
  5960. var context = {
  5961. chart: chart,
  5962. dataIndex: index,
  5963. dataset: dataset,
  5964. datasetIndex: me.index
  5965. };
  5966. var keys = [
  5967. 'backgroundColor',
  5968. 'borderColor',
  5969. 'borderWidth',
  5970. 'hoverBackgroundColor',
  5971. 'hoverBorderColor',
  5972. 'hoverBorderWidth',
  5973. 'hoverRadius',
  5974. 'hitRadius',
  5975. 'pointStyle'
  5976. ];
  5977. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  5978. key = keys[i];
  5979. values[key] = resolve([
  5980. custom[key],
  5981. dataset[key],
  5982. options[key]
  5983. ], context, index);
  5984. }
  5985. // Custom radius resolution
  5986. values.radius = resolve([
  5987. custom.radius,
  5988. data ? data.r : undefined,
  5989. dataset.radius,
  5990. options.radius
  5991. ], context, index);
  5992. return values;
  5993. }
  5994. });
  5995. };
  5996. },{"25":25,"40":40,"45":45}],17:[function(require,module,exports){
  5997. 'use strict';
  5998. var defaults = require(25);
  5999. var elements = require(40);
  6000. var helpers = require(45);
  6001. defaults._set('doughnut', {
  6002. animation: {
  6003. // Boolean - Whether we animate the rotation of the Doughnut
  6004. animateRotate: true,
  6005. // Boolean - Whether we animate scaling the Doughnut from the centre
  6006. animateScale: false
  6007. },
  6008. hover: {
  6009. mode: 'single'
  6010. },
  6011. legendCallback: function(chart) {
  6012. var text = [];
  6013. text.push('<ul class="' + chart.id + '-legend">');
  6014. var data = chart.data;
  6015. var datasets = data.datasets;
  6016. var labels = data.labels;
  6017. if (datasets.length) {
  6018. for (var i = 0; i < datasets[0].data.length; ++i) {
  6019. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  6020. if (labels[i]) {
  6021. text.push(labels[i]);
  6022. }
  6023. text.push('</li>');
  6024. }
  6025. }
  6026. text.push('</ul>');
  6027. return text.join('');
  6028. },
  6029. legend: {
  6030. labels: {
  6031. generateLabels: function(chart) {
  6032. var data = chart.data;
  6033. if (data.labels.length && data.datasets.length) {
  6034. return data.labels.map(function(label, i) {
  6035. var meta = chart.getDatasetMeta(0);
  6036. var ds = data.datasets[0];
  6037. var arc = meta.data[i];
  6038. var custom = arc && arc.custom || {};
  6039. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  6040. var arcOpts = chart.options.elements.arc;
  6041. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  6042. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  6043. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  6044. return {
  6045. text: label,
  6046. fillStyle: fill,
  6047. strokeStyle: stroke,
  6048. lineWidth: bw,
  6049. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  6050. // Extra data used for toggling the correct item
  6051. index: i
  6052. };
  6053. });
  6054. }
  6055. return [];
  6056. }
  6057. },
  6058. onClick: function(e, legendItem) {
  6059. var index = legendItem.index;
  6060. var chart = this.chart;
  6061. var i, ilen, meta;
  6062. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  6063. meta = chart.getDatasetMeta(i);
  6064. // toggle visibility of index if exists
  6065. if (meta.data[index]) {
  6066. meta.data[index].hidden = !meta.data[index].hidden;
  6067. }
  6068. }
  6069. chart.update();
  6070. }
  6071. },
  6072. // The percentage of the chart that we cut out of the middle.
  6073. cutoutPercentage: 50,
  6074. // The rotation of the chart, where the first data arc begins.
  6075. rotation: Math.PI * -0.5,
  6076. // The total circumference of the chart.
  6077. circumference: Math.PI * 2.0,
  6078. // Need to override these to give a nice default
  6079. tooltips: {
  6080. callbacks: {
  6081. title: function() {
  6082. return '';
  6083. },
  6084. label: function(tooltipItem, data) {
  6085. var dataLabel = data.labels[tooltipItem.index];
  6086. var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  6087. if (helpers.isArray(dataLabel)) {
  6088. // show value on first line of multiline label
  6089. // need to clone because we are changing the value
  6090. dataLabel = dataLabel.slice();
  6091. dataLabel[0] += value;
  6092. } else {
  6093. dataLabel += value;
  6094. }
  6095. return dataLabel;
  6096. }
  6097. }
  6098. }
  6099. });
  6100. defaults._set('pie', helpers.clone(defaults.doughnut));
  6101. defaults._set('pie', {
  6102. cutoutPercentage: 0
  6103. });
  6104. module.exports = function(Chart) {
  6105. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  6106. dataElementType: elements.Arc,
  6107. linkScales: helpers.noop,
  6108. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  6109. getRingIndex: function(datasetIndex) {
  6110. var ringIndex = 0;
  6111. for (var j = 0; j < datasetIndex; ++j) {
  6112. if (this.chart.isDatasetVisible(j)) {
  6113. ++ringIndex;
  6114. }
  6115. }
  6116. return ringIndex;
  6117. },
  6118. update: function(reset) {
  6119. var me = this;
  6120. var chart = me.chart;
  6121. var chartArea = chart.chartArea;
  6122. var opts = chart.options;
  6123. var arcOpts = opts.elements.arc;
  6124. var availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth;
  6125. var availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth;
  6126. var minSize = Math.min(availableWidth, availableHeight);
  6127. var offset = {x: 0, y: 0};
  6128. var meta = me.getMeta();
  6129. var cutoutPercentage = opts.cutoutPercentage;
  6130. var circumference = opts.circumference;
  6131. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  6132. if (circumference < Math.PI * 2.0) {
  6133. var startAngle = opts.rotation % (Math.PI * 2.0);
  6134. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  6135. var endAngle = startAngle + circumference;
  6136. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  6137. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  6138. var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  6139. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  6140. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  6141. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  6142. var cutout = cutoutPercentage / 100.0;
  6143. 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))};
  6144. 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))};
  6145. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  6146. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  6147. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  6148. }
  6149. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  6150. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  6151. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
  6152. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  6153. chart.offsetX = offset.x * chart.outerRadius;
  6154. chart.offsetY = offset.y * chart.outerRadius;
  6155. meta.total = me.calculateTotal();
  6156. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  6157. me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
  6158. helpers.each(meta.data, function(arc, index) {
  6159. me.updateElement(arc, index, reset);
  6160. });
  6161. },
  6162. updateElement: function(arc, index, reset) {
  6163. var me = this;
  6164. var chart = me.chart;
  6165. var chartArea = chart.chartArea;
  6166. var opts = chart.options;
  6167. var animationOpts = opts.animation;
  6168. var centerX = (chartArea.left + chartArea.right) / 2;
  6169. var centerY = (chartArea.top + chartArea.bottom) / 2;
  6170. var startAngle = opts.rotation; // non reset case handled later
  6171. var endAngle = opts.rotation; // non reset case handled later
  6172. var dataset = me.getDataset();
  6173. var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI));
  6174. var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
  6175. var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
  6176. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  6177. helpers.extend(arc, {
  6178. // Utility
  6179. _datasetIndex: me.index,
  6180. _index: index,
  6181. // Desired view properties
  6182. _model: {
  6183. x: centerX + chart.offsetX,
  6184. y: centerY + chart.offsetY,
  6185. startAngle: startAngle,
  6186. endAngle: endAngle,
  6187. circumference: circumference,
  6188. outerRadius: outerRadius,
  6189. innerRadius: innerRadius,
  6190. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  6191. }
  6192. });
  6193. var model = arc._model;
  6194. // Resets the visual styles
  6195. this.removeHoverStyle(arc);
  6196. // Set correct angles if not resetting
  6197. if (!reset || !animationOpts.animateRotate) {
  6198. if (index === 0) {
  6199. model.startAngle = opts.rotation;
  6200. } else {
  6201. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  6202. }
  6203. model.endAngle = model.startAngle + model.circumference;
  6204. }
  6205. arc.pivot();
  6206. },
  6207. removeHoverStyle: function(arc) {
  6208. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  6209. },
  6210. calculateTotal: function() {
  6211. var dataset = this.getDataset();
  6212. var meta = this.getMeta();
  6213. var total = 0;
  6214. var value;
  6215. helpers.each(meta.data, function(element, index) {
  6216. value = dataset.data[index];
  6217. if (!isNaN(value) && !element.hidden) {
  6218. total += Math.abs(value);
  6219. }
  6220. });
  6221. /* if (total === 0) {
  6222. total = NaN;
  6223. }*/
  6224. return total;
  6225. },
  6226. calculateCircumference: function(value) {
  6227. var total = this.getMeta().total;
  6228. if (total > 0 && !isNaN(value)) {
  6229. return (Math.PI * 2.0) * (Math.abs(value) / total);
  6230. }
  6231. return 0;
  6232. },
  6233. // gets the max border or hover width to properly scale pie charts
  6234. getMaxBorderWidth: function(arcs) {
  6235. var max = 0;
  6236. var index = this.index;
  6237. var length = arcs.length;
  6238. var borderWidth;
  6239. var hoverWidth;
  6240. for (var i = 0; i < length; i++) {
  6241. borderWidth = arcs[i]._model ? arcs[i]._model.borderWidth : 0;
  6242. hoverWidth = arcs[i]._chart ? arcs[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  6243. max = borderWidth > max ? borderWidth : max;
  6244. max = hoverWidth > max ? hoverWidth : max;
  6245. }
  6246. return max;
  6247. }
  6248. });
  6249. };
  6250. },{"25":25,"40":40,"45":45}],18:[function(require,module,exports){
  6251. 'use strict';
  6252. var defaults = require(25);
  6253. var elements = require(40);
  6254. var helpers = require(45);
  6255. defaults._set('line', {
  6256. showLines: true,
  6257. spanGaps: false,
  6258. hover: {
  6259. mode: 'label'
  6260. },
  6261. scales: {
  6262. xAxes: [{
  6263. type: 'category',
  6264. id: 'x-axis-0'
  6265. }],
  6266. yAxes: [{
  6267. type: 'linear',
  6268. id: 'y-axis-0'
  6269. }]
  6270. }
  6271. });
  6272. module.exports = function(Chart) {
  6273. function lineEnabled(dataset, options) {
  6274. return helpers.valueOrDefault(dataset.showLine, options.showLines);
  6275. }
  6276. Chart.controllers.line = Chart.DatasetController.extend({
  6277. datasetElementType: elements.Line,
  6278. dataElementType: elements.Point,
  6279. update: function(reset) {
  6280. var me = this;
  6281. var meta = me.getMeta();
  6282. var line = meta.dataset;
  6283. var points = meta.data || [];
  6284. var options = me.chart.options;
  6285. var lineElementOptions = options.elements.line;
  6286. var scale = me.getScaleForId(meta.yAxisID);
  6287. var i, ilen, custom;
  6288. var dataset = me.getDataset();
  6289. var showLine = lineEnabled(dataset, options);
  6290. // Update Line
  6291. if (showLine) {
  6292. custom = line.custom || {};
  6293. // Compatibility: If the properties are defined with only the old name, use those values
  6294. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  6295. dataset.lineTension = dataset.tension;
  6296. }
  6297. // Utility
  6298. line._scale = scale;
  6299. line._datasetIndex = me.index;
  6300. // Data
  6301. line._children = points;
  6302. // Model
  6303. line._model = {
  6304. // Appearance
  6305. // The default behavior of lines is to break at null values, according
  6306. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  6307. // This option gives lines the ability to span gaps
  6308. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  6309. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  6310. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  6311. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  6312. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  6313. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  6314. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  6315. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  6316. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  6317. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  6318. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.valueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  6319. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.valueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  6320. };
  6321. line.pivot();
  6322. }
  6323. // Update Points
  6324. for (i = 0, ilen = points.length; i < ilen; ++i) {
  6325. me.updateElement(points[i], i, reset);
  6326. }
  6327. if (showLine && line._model.tension !== 0) {
  6328. me.updateBezierControlPoints();
  6329. }
  6330. // Now pivot the point for animation
  6331. for (i = 0, ilen = points.length; i < ilen; ++i) {
  6332. points[i].pivot();
  6333. }
  6334. },
  6335. getPointBackgroundColor: function(point, index) {
  6336. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  6337. var dataset = this.getDataset();
  6338. var custom = point.custom || {};
  6339. if (custom.backgroundColor) {
  6340. backgroundColor = custom.backgroundColor;
  6341. } else if (dataset.pointBackgroundColor) {
  6342. backgroundColor = helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  6343. } else if (dataset.backgroundColor) {
  6344. backgroundColor = dataset.backgroundColor;
  6345. }
  6346. return backgroundColor;
  6347. },
  6348. getPointBorderColor: function(point, index) {
  6349. var borderColor = this.chart.options.elements.point.borderColor;
  6350. var dataset = this.getDataset();
  6351. var custom = point.custom || {};
  6352. if (custom.borderColor) {
  6353. borderColor = custom.borderColor;
  6354. } else if (dataset.pointBorderColor) {
  6355. borderColor = helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  6356. } else if (dataset.borderColor) {
  6357. borderColor = dataset.borderColor;
  6358. }
  6359. return borderColor;
  6360. },
  6361. getPointBorderWidth: function(point, index) {
  6362. var borderWidth = this.chart.options.elements.point.borderWidth;
  6363. var dataset = this.getDataset();
  6364. var custom = point.custom || {};
  6365. if (!isNaN(custom.borderWidth)) {
  6366. borderWidth = custom.borderWidth;
  6367. } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
  6368. borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  6369. } else if (!isNaN(dataset.borderWidth)) {
  6370. borderWidth = dataset.borderWidth;
  6371. }
  6372. return borderWidth;
  6373. },
  6374. updateElement: function(point, index, reset) {
  6375. var me = this;
  6376. var meta = me.getMeta();
  6377. var custom = point.custom || {};
  6378. var dataset = me.getDataset();
  6379. var datasetIndex = me.index;
  6380. var value = dataset.data[index];
  6381. var yScale = me.getScaleForId(meta.yAxisID);
  6382. var xScale = me.getScaleForId(meta.xAxisID);
  6383. var pointOptions = me.chart.options.elements.point;
  6384. var x, y;
  6385. // Compatibility: If the properties are defined with only the old name, use those values
  6386. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  6387. dataset.pointRadius = dataset.radius;
  6388. }
  6389. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  6390. dataset.pointHitRadius = dataset.hitRadius;
  6391. }
  6392. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
  6393. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  6394. // Utility
  6395. point._xScale = xScale;
  6396. point._yScale = yScale;
  6397. point._datasetIndex = datasetIndex;
  6398. point._index = index;
  6399. // Desired view properties
  6400. point._model = {
  6401. x: x,
  6402. y: y,
  6403. skip: custom.skip || isNaN(x) || isNaN(y),
  6404. // Appearance
  6405. radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  6406. pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  6407. backgroundColor: me.getPointBackgroundColor(point, index),
  6408. borderColor: me.getPointBorderColor(point, index),
  6409. borderWidth: me.getPointBorderWidth(point, index),
  6410. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  6411. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  6412. // Tooltip
  6413. hitRadius: custom.hitRadius || helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  6414. };
  6415. },
  6416. calculatePointY: function(value, index, datasetIndex) {
  6417. var me = this;
  6418. var chart = me.chart;
  6419. var meta = me.getMeta();
  6420. var yScale = me.getScaleForId(meta.yAxisID);
  6421. var sumPos = 0;
  6422. var sumNeg = 0;
  6423. var i, ds, dsMeta;
  6424. if (yScale.options.stacked) {
  6425. for (i = 0; i < datasetIndex; i++) {
  6426. ds = chart.data.datasets[i];
  6427. dsMeta = chart.getDatasetMeta(i);
  6428. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  6429. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  6430. if (stackedRightValue < 0) {
  6431. sumNeg += stackedRightValue || 0;
  6432. } else {
  6433. sumPos += stackedRightValue || 0;
  6434. }
  6435. }
  6436. }
  6437. var rightValue = Number(yScale.getRightValue(value));
  6438. if (rightValue < 0) {
  6439. return yScale.getPixelForValue(sumNeg + rightValue);
  6440. }
  6441. return yScale.getPixelForValue(sumPos + rightValue);
  6442. }
  6443. return yScale.getPixelForValue(value);
  6444. },
  6445. updateBezierControlPoints: function() {
  6446. var me = this;
  6447. var meta = me.getMeta();
  6448. var area = me.chart.chartArea;
  6449. var points = (meta.data || []);
  6450. var i, ilen, point, model, controlPoints;
  6451. // Only consider points that are drawn in case the spanGaps option is used
  6452. if (meta.dataset._model.spanGaps) {
  6453. points = points.filter(function(pt) {
  6454. return !pt._model.skip;
  6455. });
  6456. }
  6457. function capControlPoint(pt, min, max) {
  6458. return Math.max(Math.min(pt, max), min);
  6459. }
  6460. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  6461. helpers.splineCurveMonotone(points);
  6462. } else {
  6463. for (i = 0, ilen = points.length; i < ilen; ++i) {
  6464. point = points[i];
  6465. model = point._model;
  6466. controlPoints = helpers.splineCurve(
  6467. helpers.previousItem(points, i)._model,
  6468. model,
  6469. helpers.nextItem(points, i)._model,
  6470. meta.dataset._model.tension
  6471. );
  6472. model.controlPointPreviousX = controlPoints.previous.x;
  6473. model.controlPointPreviousY = controlPoints.previous.y;
  6474. model.controlPointNextX = controlPoints.next.x;
  6475. model.controlPointNextY = controlPoints.next.y;
  6476. }
  6477. }
  6478. if (me.chart.options.elements.line.capBezierPoints) {
  6479. for (i = 0, ilen = points.length; i < ilen; ++i) {
  6480. model = points[i]._model;
  6481. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  6482. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  6483. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  6484. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  6485. }
  6486. }
  6487. },
  6488. draw: function() {
  6489. var me = this;
  6490. var chart = me.chart;
  6491. var meta = me.getMeta();
  6492. var points = meta.data || [];
  6493. var area = chart.chartArea;
  6494. var ilen = points.length;
  6495. var i = 0;
  6496. helpers.canvas.clipArea(chart.ctx, area);
  6497. if (lineEnabled(me.getDataset(), chart.options)) {
  6498. meta.dataset.draw();
  6499. }
  6500. helpers.canvas.unclipArea(chart.ctx);
  6501. // Draw the points
  6502. for (; i < ilen; ++i) {
  6503. points[i].draw(area);
  6504. }
  6505. },
  6506. setHoverStyle: function(point) {
  6507. // Point
  6508. var dataset = this.chart.data.datasets[point._datasetIndex];
  6509. var index = point._index;
  6510. var custom = point.custom || {};
  6511. var model = point._model;
  6512. model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  6513. model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  6514. model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  6515. model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  6516. },
  6517. removeHoverStyle: function(point) {
  6518. var me = this;
  6519. var dataset = me.chart.data.datasets[point._datasetIndex];
  6520. var index = point._index;
  6521. var custom = point.custom || {};
  6522. var model = point._model;
  6523. // Compatibility: If the properties are defined with only the old name, use those values
  6524. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  6525. dataset.pointRadius = dataset.radius;
  6526. }
  6527. model.radius = custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius);
  6528. model.backgroundColor = me.getPointBackgroundColor(point, index);
  6529. model.borderColor = me.getPointBorderColor(point, index);
  6530. model.borderWidth = me.getPointBorderWidth(point, index);
  6531. }
  6532. });
  6533. };
  6534. },{"25":25,"40":40,"45":45}],19:[function(require,module,exports){
  6535. 'use strict';
  6536. var defaults = require(25);
  6537. var elements = require(40);
  6538. var helpers = require(45);
  6539. defaults._set('polarArea', {
  6540. scale: {
  6541. type: 'radialLinear',
  6542. angleLines: {
  6543. display: false
  6544. },
  6545. gridLines: {
  6546. circular: true
  6547. },
  6548. pointLabels: {
  6549. display: false
  6550. },
  6551. ticks: {
  6552. beginAtZero: true
  6553. }
  6554. },
  6555. // Boolean - Whether to animate the rotation of the chart
  6556. animation: {
  6557. animateRotate: true,
  6558. animateScale: true
  6559. },
  6560. startAngle: -0.5 * Math.PI,
  6561. legendCallback: function(chart) {
  6562. var text = [];
  6563. text.push('<ul class="' + chart.id + '-legend">');
  6564. var data = chart.data;
  6565. var datasets = data.datasets;
  6566. var labels = data.labels;
  6567. if (datasets.length) {
  6568. for (var i = 0; i < datasets[0].data.length; ++i) {
  6569. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  6570. if (labels[i]) {
  6571. text.push(labels[i]);
  6572. }
  6573. text.push('</li>');
  6574. }
  6575. }
  6576. text.push('</ul>');
  6577. return text.join('');
  6578. },
  6579. legend: {
  6580. labels: {
  6581. generateLabels: function(chart) {
  6582. var data = chart.data;
  6583. if (data.labels.length && data.datasets.length) {
  6584. return data.labels.map(function(label, i) {
  6585. var meta = chart.getDatasetMeta(0);
  6586. var ds = data.datasets[0];
  6587. var arc = meta.data[i];
  6588. var custom = arc.custom || {};
  6589. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  6590. var arcOpts = chart.options.elements.arc;
  6591. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  6592. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  6593. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  6594. return {
  6595. text: label,
  6596. fillStyle: fill,
  6597. strokeStyle: stroke,
  6598. lineWidth: bw,
  6599. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  6600. // Extra data used for toggling the correct item
  6601. index: i
  6602. };
  6603. });
  6604. }
  6605. return [];
  6606. }
  6607. },
  6608. onClick: function(e, legendItem) {
  6609. var index = legendItem.index;
  6610. var chart = this.chart;
  6611. var i, ilen, meta;
  6612. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  6613. meta = chart.getDatasetMeta(i);
  6614. meta.data[index].hidden = !meta.data[index].hidden;
  6615. }
  6616. chart.update();
  6617. }
  6618. },
  6619. // Need to override these to give a nice default
  6620. tooltips: {
  6621. callbacks: {
  6622. title: function() {
  6623. return '';
  6624. },
  6625. label: function(item, data) {
  6626. return data.labels[item.index] + ': ' + item.yLabel;
  6627. }
  6628. }
  6629. }
  6630. });
  6631. module.exports = function(Chart) {
  6632. Chart.controllers.polarArea = Chart.DatasetController.extend({
  6633. dataElementType: elements.Arc,
  6634. linkScales: helpers.noop,
  6635. update: function(reset) {
  6636. var me = this;
  6637. var chart = me.chart;
  6638. var chartArea = chart.chartArea;
  6639. var meta = me.getMeta();
  6640. var opts = chart.options;
  6641. var arcOpts = opts.elements.arc;
  6642. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  6643. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  6644. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  6645. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  6646. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  6647. me.innerRadius = me.outerRadius - chart.radiusLength;
  6648. meta.count = me.countVisibleElements();
  6649. helpers.each(meta.data, function(arc, index) {
  6650. me.updateElement(arc, index, reset);
  6651. });
  6652. },
  6653. updateElement: function(arc, index, reset) {
  6654. var me = this;
  6655. var chart = me.chart;
  6656. var dataset = me.getDataset();
  6657. var opts = chart.options;
  6658. var animationOpts = opts.animation;
  6659. var scale = chart.scale;
  6660. var labels = chart.data.labels;
  6661. var circumference = me.calculateCircumference(dataset.data[index]);
  6662. var centerX = scale.xCenter;
  6663. var centerY = scale.yCenter;
  6664. // If there is NaN data before us, we need to calculate the starting angle correctly.
  6665. // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
  6666. var visibleCount = 0;
  6667. var meta = me.getMeta();
  6668. for (var i = 0; i < index; ++i) {
  6669. if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
  6670. ++visibleCount;
  6671. }
  6672. }
  6673. // var negHalfPI = -0.5 * Math.PI;
  6674. var datasetStartAngle = opts.startAngle;
  6675. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  6676. var startAngle = datasetStartAngle + (circumference * visibleCount);
  6677. var endAngle = startAngle + (arc.hidden ? 0 : circumference);
  6678. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  6679. helpers.extend(arc, {
  6680. // Utility
  6681. _datasetIndex: me.index,
  6682. _index: index,
  6683. _scale: scale,
  6684. // Desired view properties
  6685. _model: {
  6686. x: centerX,
  6687. y: centerY,
  6688. innerRadius: 0,
  6689. outerRadius: reset ? resetRadius : distance,
  6690. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  6691. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  6692. label: helpers.valueAtIndexOrDefault(labels, index, labels[index])
  6693. }
  6694. });
  6695. // Apply border and fill style
  6696. me.removeHoverStyle(arc);
  6697. arc.pivot();
  6698. },
  6699. removeHoverStyle: function(arc) {
  6700. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  6701. },
  6702. countVisibleElements: function() {
  6703. var dataset = this.getDataset();
  6704. var meta = this.getMeta();
  6705. var count = 0;
  6706. helpers.each(meta.data, function(element, index) {
  6707. if (!isNaN(dataset.data[index]) && !element.hidden) {
  6708. count++;
  6709. }
  6710. });
  6711. return count;
  6712. },
  6713. calculateCircumference: function(value) {
  6714. var count = this.getMeta().count;
  6715. if (count > 0 && !isNaN(value)) {
  6716. return (2 * Math.PI) / count;
  6717. }
  6718. return 0;
  6719. }
  6720. });
  6721. };
  6722. },{"25":25,"40":40,"45":45}],20:[function(require,module,exports){
  6723. 'use strict';
  6724. var defaults = require(25);
  6725. var elements = require(40);
  6726. var helpers = require(45);
  6727. defaults._set('radar', {
  6728. scale: {
  6729. type: 'radialLinear'
  6730. },
  6731. elements: {
  6732. line: {
  6733. tension: 0 // no bezier in radar
  6734. }
  6735. }
  6736. });
  6737. module.exports = function(Chart) {
  6738. Chart.controllers.radar = Chart.DatasetController.extend({
  6739. datasetElementType: elements.Line,
  6740. dataElementType: elements.Point,
  6741. linkScales: helpers.noop,
  6742. update: function(reset) {
  6743. var me = this;
  6744. var meta = me.getMeta();
  6745. var line = meta.dataset;
  6746. var points = meta.data;
  6747. var custom = line.custom || {};
  6748. var dataset = me.getDataset();
  6749. var lineElementOptions = me.chart.options.elements.line;
  6750. var scale = me.chart.scale;
  6751. // Compatibility: If the properties are defined with only the old name, use those values
  6752. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  6753. dataset.lineTension = dataset.tension;
  6754. }
  6755. helpers.extend(meta.dataset, {
  6756. // Utility
  6757. _datasetIndex: me.index,
  6758. _scale: scale,
  6759. // Data
  6760. _children: points,
  6761. _loop: true,
  6762. // Model
  6763. _model: {
  6764. // Appearance
  6765. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  6766. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  6767. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  6768. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  6769. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  6770. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  6771. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  6772. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  6773. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  6774. }
  6775. });
  6776. meta.dataset.pivot();
  6777. // Update Points
  6778. helpers.each(points, function(point, index) {
  6779. me.updateElement(point, index, reset);
  6780. }, me);
  6781. // Update bezier control points
  6782. me.updateBezierControlPoints();
  6783. },
  6784. updateElement: function(point, index, reset) {
  6785. var me = this;
  6786. var custom = point.custom || {};
  6787. var dataset = me.getDataset();
  6788. var scale = me.chart.scale;
  6789. var pointElementOptions = me.chart.options.elements.point;
  6790. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  6791. // Compatibility: If the properties are defined with only the old name, use those values
  6792. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  6793. dataset.pointRadius = dataset.radius;
  6794. }
  6795. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  6796. dataset.pointHitRadius = dataset.hitRadius;
  6797. }
  6798. helpers.extend(point, {
  6799. // Utility
  6800. _datasetIndex: me.index,
  6801. _index: index,
  6802. _scale: scale,
  6803. // Desired view properties
  6804. _model: {
  6805. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  6806. y: reset ? scale.yCenter : pointPosition.y,
  6807. // Appearance
  6808. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
  6809. radius: custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  6810. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  6811. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  6812. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  6813. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  6814. // Tooltip
  6815. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
  6816. }
  6817. });
  6818. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  6819. },
  6820. updateBezierControlPoints: function() {
  6821. var chartArea = this.chart.chartArea;
  6822. var meta = this.getMeta();
  6823. helpers.each(meta.data, function(point, index) {
  6824. var model = point._model;
  6825. var controlPoints = helpers.splineCurve(
  6826. helpers.previousItem(meta.data, index, true)._model,
  6827. model,
  6828. helpers.nextItem(meta.data, index, true)._model,
  6829. model.tension
  6830. );
  6831. // Prevent the bezier going outside of the bounds of the graph
  6832. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  6833. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  6834. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  6835. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  6836. // Now pivot the point for animation
  6837. point.pivot();
  6838. });
  6839. },
  6840. setHoverStyle: function(point) {
  6841. // Point
  6842. var dataset = this.chart.data.datasets[point._datasetIndex];
  6843. var custom = point.custom || {};
  6844. var index = point._index;
  6845. var model = point._model;
  6846. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  6847. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  6848. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  6849. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  6850. },
  6851. removeHoverStyle: function(point) {
  6852. var dataset = this.chart.data.datasets[point._datasetIndex];
  6853. var custom = point.custom || {};
  6854. var index = point._index;
  6855. var model = point._model;
  6856. var pointElementOptions = this.chart.options.elements.point;
  6857. model.radius = custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius);
  6858. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
  6859. model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
  6860. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);
  6861. }
  6862. });
  6863. };
  6864. },{"25":25,"40":40,"45":45}],21:[function(require,module,exports){
  6865. 'use strict';
  6866. var defaults = require(25);
  6867. defaults._set('scatter', {
  6868. hover: {
  6869. mode: 'single'
  6870. },
  6871. scales: {
  6872. xAxes: [{
  6873. id: 'x-axis-1', // need an ID so datasets can reference the scale
  6874. type: 'linear', // scatter should not use a category axis
  6875. position: 'bottom'
  6876. }],
  6877. yAxes: [{
  6878. id: 'y-axis-1',
  6879. type: 'linear',
  6880. position: 'left'
  6881. }]
  6882. },
  6883. showLines: false,
  6884. tooltips: {
  6885. callbacks: {
  6886. title: function() {
  6887. return ''; // doesn't make sense for scatter since data are formatted as a point
  6888. },
  6889. label: function(item) {
  6890. return '(' + item.xLabel + ', ' + item.yLabel + ')';
  6891. }
  6892. }
  6893. }
  6894. });
  6895. module.exports = function(Chart) {
  6896. // Scatter charts use line controllers
  6897. Chart.controllers.scatter = Chart.controllers.line;
  6898. };
  6899. },{"25":25}],22:[function(require,module,exports){
  6900. /* global window: false */
  6901. 'use strict';
  6902. var defaults = require(25);
  6903. var Element = require(26);
  6904. var helpers = require(45);
  6905. defaults._set('global', {
  6906. animation: {
  6907. duration: 1000,
  6908. easing: 'easeOutQuart',
  6909. onProgress: helpers.noop,
  6910. onComplete: helpers.noop
  6911. }
  6912. });
  6913. module.exports = function(Chart) {
  6914. Chart.Animation = Element.extend({
  6915. chart: null, // the animation associated chart instance
  6916. currentStep: 0, // the current animation step
  6917. numSteps: 60, // default number of steps
  6918. easing: '', // the easing to use for this animation
  6919. render: null, // render function used by the animation service
  6920. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  6921. onAnimationComplete: null, // user specified callback to fire when the animation finishes
  6922. });
  6923. Chart.animationService = {
  6924. frameDuration: 17,
  6925. animations: [],
  6926. dropFrames: 0,
  6927. request: null,
  6928. /**
  6929. * @param {Chart} chart - The chart to animate.
  6930. * @param {Chart.Animation} animation - The animation that we will animate.
  6931. * @param {Number} duration - The animation duration in ms.
  6932. * @param {Boolean} lazy - if true, the chart is not marked as animating to enable more responsive interactions
  6933. */
  6934. addAnimation: function(chart, animation, duration, lazy) {
  6935. var animations = this.animations;
  6936. var i, ilen;
  6937. animation.chart = chart;
  6938. if (!lazy) {
  6939. chart.animating = true;
  6940. }
  6941. for (i = 0, ilen = animations.length; i < ilen; ++i) {
  6942. if (animations[i].chart === chart) {
  6943. animations[i] = animation;
  6944. return;
  6945. }
  6946. }
  6947. animations.push(animation);
  6948. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  6949. if (animations.length === 1) {
  6950. this.requestAnimationFrame();
  6951. }
  6952. },
  6953. cancelAnimation: function(chart) {
  6954. var index = helpers.findIndex(this.animations, function(animation) {
  6955. return animation.chart === chart;
  6956. });
  6957. if (index !== -1) {
  6958. this.animations.splice(index, 1);
  6959. chart.animating = false;
  6960. }
  6961. },
  6962. requestAnimationFrame: function() {
  6963. var me = this;
  6964. if (me.request === null) {
  6965. // Skip animation frame requests until the active one is executed.
  6966. // This can happen when processing mouse events, e.g. 'mousemove'
  6967. // and 'mouseout' events will trigger multiple renders.
  6968. me.request = helpers.requestAnimFrame.call(window, function() {
  6969. me.request = null;
  6970. me.startDigest();
  6971. });
  6972. }
  6973. },
  6974. /**
  6975. * @private
  6976. */
  6977. startDigest: function() {
  6978. var me = this;
  6979. var startTime = Date.now();
  6980. var framesToDrop = 0;
  6981. if (me.dropFrames > 1) {
  6982. framesToDrop = Math.floor(me.dropFrames);
  6983. me.dropFrames = me.dropFrames % 1;
  6984. }
  6985. me.advance(1 + framesToDrop);
  6986. var endTime = Date.now();
  6987. me.dropFrames += (endTime - startTime) / me.frameDuration;
  6988. // Do we have more stuff to animate?
  6989. if (me.animations.length > 0) {
  6990. me.requestAnimationFrame();
  6991. }
  6992. },
  6993. /**
  6994. * @private
  6995. */
  6996. advance: function(count) {
  6997. var animations = this.animations;
  6998. var animation, chart;
  6999. var i = 0;
  7000. while (i < animations.length) {
  7001. animation = animations[i];
  7002. chart = animation.chart;
  7003. animation.currentStep = (animation.currentStep || 0) + count;
  7004. animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
  7005. helpers.callback(animation.render, [chart, animation], chart);
  7006. helpers.callback(animation.onAnimationProgress, [animation], chart);
  7007. if (animation.currentStep >= animation.numSteps) {
  7008. helpers.callback(animation.onAnimationComplete, [animation], chart);
  7009. chart.animating = false;
  7010. animations.splice(i, 1);
  7011. } else {
  7012. ++i;
  7013. }
  7014. }
  7015. }
  7016. };
  7017. /**
  7018. * Provided for backward compatibility, use Chart.Animation instead
  7019. * @prop Chart.Animation#animationObject
  7020. * @deprecated since version 2.6.0
  7021. * @todo remove at version 3
  7022. */
  7023. Object.defineProperty(Chart.Animation.prototype, 'animationObject', {
  7024. get: function() {
  7025. return this;
  7026. }
  7027. });
  7028. /**
  7029. * Provided for backward compatibility, use Chart.Animation#chart instead
  7030. * @prop Chart.Animation#chartInstance
  7031. * @deprecated since version 2.6.0
  7032. * @todo remove at version 3
  7033. */
  7034. Object.defineProperty(Chart.Animation.prototype, 'chartInstance', {
  7035. get: function() {
  7036. return this.chart;
  7037. },
  7038. set: function(value) {
  7039. this.chart = value;
  7040. }
  7041. });
  7042. };
  7043. },{"25":25,"26":26,"45":45}],23:[function(require,module,exports){
  7044. 'use strict';
  7045. var defaults = require(25);
  7046. var helpers = require(45);
  7047. var Interaction = require(28);
  7048. var layouts = require(30);
  7049. var platform = require(48);
  7050. var plugins = require(31);
  7051. module.exports = function(Chart) {
  7052. // Create a dictionary of chart types, to allow for extension of existing types
  7053. Chart.types = {};
  7054. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  7055. // Destroy method on the chart will remove the instance of the chart from this reference.
  7056. Chart.instances = {};
  7057. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  7058. Chart.controllers = {};
  7059. /**
  7060. * Initializes the given config with global and chart default values.
  7061. */
  7062. function initConfig(config) {
  7063. config = config || {};
  7064. // Do NOT use configMerge() for the data object because this method merges arrays
  7065. // and so would change references to labels and datasets, preventing data updates.
  7066. var data = config.data = config.data || {};
  7067. data.datasets = data.datasets || [];
  7068. data.labels = data.labels || [];
  7069. config.options = helpers.configMerge(
  7070. defaults.global,
  7071. defaults[config.type],
  7072. config.options || {});
  7073. return config;
  7074. }
  7075. /**
  7076. * Updates the config of the chart
  7077. * @param chart {Chart} chart to update the options for
  7078. */
  7079. function updateConfig(chart) {
  7080. var newOptions = chart.options;
  7081. helpers.each(chart.scales, function(scale) {
  7082. layouts.removeBox(chart, scale);
  7083. });
  7084. newOptions = helpers.configMerge(
  7085. Chart.defaults.global,
  7086. Chart.defaults[chart.config.type],
  7087. newOptions);
  7088. chart.options = chart.config.options = newOptions;
  7089. chart.ensureScalesHaveIDs();
  7090. chart.buildOrUpdateScales();
  7091. // Tooltip
  7092. chart.tooltip._options = newOptions.tooltips;
  7093. chart.tooltip.initialize();
  7094. }
  7095. function positionIsHorizontal(position) {
  7096. return position === 'top' || position === 'bottom';
  7097. }
  7098. helpers.extend(Chart.prototype, /** @lends Chart */ {
  7099. /**
  7100. * @private
  7101. */
  7102. construct: function(item, config) {
  7103. var me = this;
  7104. config = initConfig(config);
  7105. var context = platform.acquireContext(item, config);
  7106. var canvas = context && context.canvas;
  7107. var height = canvas && canvas.height;
  7108. var width = canvas && canvas.width;
  7109. me.id = helpers.uid();
  7110. me.ctx = context;
  7111. me.canvas = canvas;
  7112. me.config = config;
  7113. me.width = width;
  7114. me.height = height;
  7115. me.aspectRatio = height ? width / height : null;
  7116. me.options = config.options;
  7117. me._bufferedRender = false;
  7118. /**
  7119. * Provided for backward compatibility, Chart and Chart.Controller have been merged,
  7120. * the "instance" still need to be defined since it might be called from plugins.
  7121. * @prop Chart#chart
  7122. * @deprecated since version 2.6.0
  7123. * @todo remove at version 3
  7124. * @private
  7125. */
  7126. me.chart = me;
  7127. me.controller = me; // chart.chart.controller #inception
  7128. // Add the chart instance to the global namespace
  7129. Chart.instances[me.id] = me;
  7130. // Define alias to the config data: `chart.data === chart.config.data`
  7131. Object.defineProperty(me, 'data', {
  7132. get: function() {
  7133. return me.config.data;
  7134. },
  7135. set: function(value) {
  7136. me.config.data = value;
  7137. }
  7138. });
  7139. if (!context || !canvas) {
  7140. // The given item is not a compatible context2d element, let's return before finalizing
  7141. // the chart initialization but after setting basic chart / controller properties that
  7142. // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
  7143. // https://github.com/chartjs/Chart.js/issues/2807
  7144. console.error("Failed to create chart: can't acquire context from the given item");
  7145. return;
  7146. }
  7147. me.initialize();
  7148. me.update();
  7149. },
  7150. /**
  7151. * @private
  7152. */
  7153. initialize: function() {
  7154. var me = this;
  7155. // Before init plugin notification
  7156. plugins.notify(me, 'beforeInit');
  7157. helpers.retinaScale(me, me.options.devicePixelRatio);
  7158. me.bindEvents();
  7159. if (me.options.responsive) {
  7160. // Initial resize before chart draws (must be silent to preserve initial animations).
  7161. me.resize(true);
  7162. }
  7163. // Make sure scales have IDs and are built before we build any controllers.
  7164. me.ensureScalesHaveIDs();
  7165. me.buildOrUpdateScales();
  7166. me.initToolTip();
  7167. // After init plugin notification
  7168. plugins.notify(me, 'afterInit');
  7169. return me;
  7170. },
  7171. clear: function() {
  7172. helpers.canvas.clear(this);
  7173. return this;
  7174. },
  7175. stop: function() {
  7176. // Stops any current animation loop occurring
  7177. Chart.animationService.cancelAnimation(this);
  7178. return this;
  7179. },
  7180. resize: function(silent) {
  7181. var me = this;
  7182. var options = me.options;
  7183. var canvas = me.canvas;
  7184. var aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
  7185. // the canvas render width and height will be casted to integers so make sure that
  7186. // the canvas display style uses the same integer values to avoid blurring effect.
  7187. // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collased
  7188. var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
  7189. var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
  7190. if (me.width === newWidth && me.height === newHeight) {
  7191. return;
  7192. }
  7193. canvas.width = me.width = newWidth;
  7194. canvas.height = me.height = newHeight;
  7195. canvas.style.width = newWidth + 'px';
  7196. canvas.style.height = newHeight + 'px';
  7197. helpers.retinaScale(me, options.devicePixelRatio);
  7198. if (!silent) {
  7199. // Notify any plugins about the resize
  7200. var newSize = {width: newWidth, height: newHeight};
  7201. plugins.notify(me, 'resize', [newSize]);
  7202. // Notify of resize
  7203. if (me.options.onResize) {
  7204. me.options.onResize(me, newSize);
  7205. }
  7206. me.stop();
  7207. me.update(me.options.responsiveAnimationDuration);
  7208. }
  7209. },
  7210. ensureScalesHaveIDs: function() {
  7211. var options = this.options;
  7212. var scalesOptions = options.scales || {};
  7213. var scaleOptions = options.scale;
  7214. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  7215. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  7216. });
  7217. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  7218. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  7219. });
  7220. if (scaleOptions) {
  7221. scaleOptions.id = scaleOptions.id || 'scale';
  7222. }
  7223. },
  7224. /**
  7225. * Builds a map of scale ID to scale object for future lookup.
  7226. */
  7227. buildOrUpdateScales: function() {
  7228. var me = this;
  7229. var options = me.options;
  7230. var scales = me.scales || {};
  7231. var items = [];
  7232. var updated = Object.keys(scales).reduce(function(obj, id) {
  7233. obj[id] = false;
  7234. return obj;
  7235. }, {});
  7236. if (options.scales) {
  7237. items = items.concat(
  7238. (options.scales.xAxes || []).map(function(xAxisOptions) {
  7239. return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
  7240. }),
  7241. (options.scales.yAxes || []).map(function(yAxisOptions) {
  7242. return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
  7243. })
  7244. );
  7245. }
  7246. if (options.scale) {
  7247. items.push({
  7248. options: options.scale,
  7249. dtype: 'radialLinear',
  7250. isDefault: true,
  7251. dposition: 'chartArea'
  7252. });
  7253. }
  7254. helpers.each(items, function(item) {
  7255. var scaleOptions = item.options;
  7256. var id = scaleOptions.id;
  7257. var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
  7258. if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
  7259. scaleOptions.position = item.dposition;
  7260. }
  7261. updated[id] = true;
  7262. var scale = null;
  7263. if (id in scales && scales[id].type === scaleType) {
  7264. scale = scales[id];
  7265. scale.options = scaleOptions;
  7266. scale.ctx = me.ctx;
  7267. scale.chart = me;
  7268. } else {
  7269. var scaleClass = Chart.scaleService.getScaleConstructor(scaleType);
  7270. if (!scaleClass) {
  7271. return;
  7272. }
  7273. scale = new scaleClass({
  7274. id: id,
  7275. type: scaleType,
  7276. options: scaleOptions,
  7277. ctx: me.ctx,
  7278. chart: me
  7279. });
  7280. scales[scale.id] = scale;
  7281. }
  7282. scale.mergeTicksOptions();
  7283. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  7284. // and consider it as a regular scale part of the "scales"" map only! This would
  7285. // make the logic easier and remove some useless? custom code.
  7286. if (item.isDefault) {
  7287. me.scale = scale;
  7288. }
  7289. });
  7290. // clear up discarded scales
  7291. helpers.each(updated, function(hasUpdated, id) {
  7292. if (!hasUpdated) {
  7293. delete scales[id];
  7294. }
  7295. });
  7296. me.scales = scales;
  7297. Chart.scaleService.addScalesToLayout(this);
  7298. },
  7299. buildOrUpdateControllers: function() {
  7300. var me = this;
  7301. var types = [];
  7302. var newControllers = [];
  7303. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7304. var meta = me.getDatasetMeta(datasetIndex);
  7305. var type = dataset.type || me.config.type;
  7306. if (meta.type && meta.type !== type) {
  7307. me.destroyDatasetMeta(datasetIndex);
  7308. meta = me.getDatasetMeta(datasetIndex);
  7309. }
  7310. meta.type = type;
  7311. types.push(meta.type);
  7312. if (meta.controller) {
  7313. meta.controller.updateIndex(datasetIndex);
  7314. meta.controller.linkScales();
  7315. } else {
  7316. var ControllerClass = Chart.controllers[meta.type];
  7317. if (ControllerClass === undefined) {
  7318. throw new Error('"' + meta.type + '" is not a chart type.');
  7319. }
  7320. meta.controller = new ControllerClass(me, datasetIndex);
  7321. newControllers.push(meta.controller);
  7322. }
  7323. }, me);
  7324. return newControllers;
  7325. },
  7326. /**
  7327. * Reset the elements of all datasets
  7328. * @private
  7329. */
  7330. resetElements: function() {
  7331. var me = this;
  7332. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7333. me.getDatasetMeta(datasetIndex).controller.reset();
  7334. }, me);
  7335. },
  7336. /**
  7337. * Resets the chart back to it's state before the initial animation
  7338. */
  7339. reset: function() {
  7340. this.resetElements();
  7341. this.tooltip.initialize();
  7342. },
  7343. update: function(config) {
  7344. var me = this;
  7345. if (!config || typeof config !== 'object') {
  7346. // backwards compatibility
  7347. config = {
  7348. duration: config,
  7349. lazy: arguments[1]
  7350. };
  7351. }
  7352. updateConfig(me);
  7353. // plugins options references might have change, let's invalidate the cache
  7354. // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  7355. plugins._invalidate(me);
  7356. if (plugins.notify(me, 'beforeUpdate') === false) {
  7357. return;
  7358. }
  7359. // In case the entire data object changed
  7360. me.tooltip._data = me.data;
  7361. // Make sure dataset controllers are updated and new controllers are reset
  7362. var newControllers = me.buildOrUpdateControllers();
  7363. // Make sure all dataset controllers have correct meta data counts
  7364. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7365. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  7366. }, me);
  7367. me.updateLayout();
  7368. // Can only reset the new controllers after the scales have been updated
  7369. if (me.options.animation && me.options.animation.duration) {
  7370. helpers.each(newControllers, function(controller) {
  7371. controller.reset();
  7372. });
  7373. }
  7374. me.updateDatasets();
  7375. // Need to reset tooltip in case it is displayed with elements that are removed
  7376. // after update.
  7377. me.tooltip.initialize();
  7378. // Last active contains items that were previously in the tooltip.
  7379. // When we reset the tooltip, we need to clear it
  7380. me.lastActive = [];
  7381. // Do this before render so that any plugins that need final scale updates can use it
  7382. plugins.notify(me, 'afterUpdate');
  7383. if (me._bufferedRender) {
  7384. me._bufferedRequest = {
  7385. duration: config.duration,
  7386. easing: config.easing,
  7387. lazy: config.lazy
  7388. };
  7389. } else {
  7390. me.render(config);
  7391. }
  7392. },
  7393. /**
  7394. * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
  7395. * hook, in which case, plugins will not be called on `afterLayout`.
  7396. * @private
  7397. */
  7398. updateLayout: function() {
  7399. var me = this;
  7400. if (plugins.notify(me, 'beforeLayout') === false) {
  7401. return;
  7402. }
  7403. layouts.update(this, this.width, this.height);
  7404. /**
  7405. * Provided for backward compatibility, use `afterLayout` instead.
  7406. * @method IPlugin#afterScaleUpdate
  7407. * @deprecated since version 2.5.0
  7408. * @todo remove at version 3
  7409. * @private
  7410. */
  7411. plugins.notify(me, 'afterScaleUpdate');
  7412. plugins.notify(me, 'afterLayout');
  7413. },
  7414. /**
  7415. * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
  7416. * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
  7417. * @private
  7418. */
  7419. updateDatasets: function() {
  7420. var me = this;
  7421. if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
  7422. return;
  7423. }
  7424. for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  7425. me.updateDataset(i);
  7426. }
  7427. plugins.notify(me, 'afterDatasetsUpdate');
  7428. },
  7429. /**
  7430. * Updates dataset at index unless a plugin returns `false` to the `beforeDatasetUpdate`
  7431. * hook, in which case, plugins will not be called on `afterDatasetUpdate`.
  7432. * @private
  7433. */
  7434. updateDataset: function(index) {
  7435. var me = this;
  7436. var meta = me.getDatasetMeta(index);
  7437. var args = {
  7438. meta: meta,
  7439. index: index
  7440. };
  7441. if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
  7442. return;
  7443. }
  7444. meta.controller.update();
  7445. plugins.notify(me, 'afterDatasetUpdate', [args]);
  7446. },
  7447. render: function(config) {
  7448. var me = this;
  7449. if (!config || typeof config !== 'object') {
  7450. // backwards compatibility
  7451. config = {
  7452. duration: config,
  7453. lazy: arguments[1]
  7454. };
  7455. }
  7456. var duration = config.duration;
  7457. var lazy = config.lazy;
  7458. if (plugins.notify(me, 'beforeRender') === false) {
  7459. return;
  7460. }
  7461. var animationOptions = me.options.animation;
  7462. var onComplete = function(animation) {
  7463. plugins.notify(me, 'afterRender');
  7464. helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
  7465. };
  7466. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  7467. var animation = new Chart.Animation({
  7468. numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
  7469. easing: config.easing || animationOptions.easing,
  7470. render: function(chart, animationObject) {
  7471. var easingFunction = helpers.easing.effects[animationObject.easing];
  7472. var currentStep = animationObject.currentStep;
  7473. var stepDecimal = currentStep / animationObject.numSteps;
  7474. chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep);
  7475. },
  7476. onAnimationProgress: animationOptions.onProgress,
  7477. onAnimationComplete: onComplete
  7478. });
  7479. Chart.animationService.addAnimation(me, animation, duration, lazy);
  7480. } else {
  7481. me.draw();
  7482. // See https://github.com/chartjs/Chart.js/issues/3781
  7483. onComplete(new Chart.Animation({numSteps: 0, chart: me}));
  7484. }
  7485. return me;
  7486. },
  7487. draw: function(easingValue) {
  7488. var me = this;
  7489. me.clear();
  7490. if (helpers.isNullOrUndef(easingValue)) {
  7491. easingValue = 1;
  7492. }
  7493. me.transition(easingValue);
  7494. if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
  7495. return;
  7496. }
  7497. // Draw all the scales
  7498. helpers.each(me.boxes, function(box) {
  7499. box.draw(me.chartArea);
  7500. }, me);
  7501. if (me.scale) {
  7502. me.scale.draw();
  7503. }
  7504. me.drawDatasets(easingValue);
  7505. me._drawTooltip(easingValue);
  7506. plugins.notify(me, 'afterDraw', [easingValue]);
  7507. },
  7508. /**
  7509. * @private
  7510. */
  7511. transition: function(easingValue) {
  7512. var me = this;
  7513. for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
  7514. if (me.isDatasetVisible(i)) {
  7515. me.getDatasetMeta(i).controller.transition(easingValue);
  7516. }
  7517. }
  7518. me.tooltip.transition(easingValue);
  7519. },
  7520. /**
  7521. * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
  7522. * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
  7523. * @private
  7524. */
  7525. drawDatasets: function(easingValue) {
  7526. var me = this;
  7527. if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
  7528. return;
  7529. }
  7530. // Draw datasets reversed to support proper line stacking
  7531. for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
  7532. if (me.isDatasetVisible(i)) {
  7533. me.drawDataset(i, easingValue);
  7534. }
  7535. }
  7536. plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
  7537. },
  7538. /**
  7539. * Draws dataset at index unless a plugin returns `false` to the `beforeDatasetDraw`
  7540. * hook, in which case, plugins will not be called on `afterDatasetDraw`.
  7541. * @private
  7542. */
  7543. drawDataset: function(index, easingValue) {
  7544. var me = this;
  7545. var meta = me.getDatasetMeta(index);
  7546. var args = {
  7547. meta: meta,
  7548. index: index,
  7549. easingValue: easingValue
  7550. };
  7551. if (plugins.notify(me, 'beforeDatasetDraw', [args]) === false) {
  7552. return;
  7553. }
  7554. meta.controller.draw(easingValue);
  7555. plugins.notify(me, 'afterDatasetDraw', [args]);
  7556. },
  7557. /**
  7558. * Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
  7559. * hook, in which case, plugins will not be called on `afterTooltipDraw`.
  7560. * @private
  7561. */
  7562. _drawTooltip: function(easingValue) {
  7563. var me = this;
  7564. var tooltip = me.tooltip;
  7565. var args = {
  7566. tooltip: tooltip,
  7567. easingValue: easingValue
  7568. };
  7569. if (plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
  7570. return;
  7571. }
  7572. tooltip.draw();
  7573. plugins.notify(me, 'afterTooltipDraw', [args]);
  7574. },
  7575. // Get the single element that was clicked on
  7576. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  7577. getElementAtEvent: function(e) {
  7578. return Interaction.modes.single(this, e);
  7579. },
  7580. getElementsAtEvent: function(e) {
  7581. return Interaction.modes.label(this, e, {intersect: true});
  7582. },
  7583. getElementsAtXAxis: function(e) {
  7584. return Interaction.modes['x-axis'](this, e, {intersect: true});
  7585. },
  7586. getElementsAtEventForMode: function(e, mode, options) {
  7587. var method = Interaction.modes[mode];
  7588. if (typeof method === 'function') {
  7589. return method(this, e, options);
  7590. }
  7591. return [];
  7592. },
  7593. getDatasetAtEvent: function(e) {
  7594. return Interaction.modes.dataset(this, e, {intersect: true});
  7595. },
  7596. getDatasetMeta: function(datasetIndex) {
  7597. var me = this;
  7598. var dataset = me.data.datasets[datasetIndex];
  7599. if (!dataset._meta) {
  7600. dataset._meta = {};
  7601. }
  7602. var meta = dataset._meta[me.id];
  7603. if (!meta) {
  7604. meta = dataset._meta[me.id] = {
  7605. type: null,
  7606. data: [],
  7607. dataset: null,
  7608. controller: null,
  7609. hidden: null, // See isDatasetVisible() comment
  7610. xAxisID: null,
  7611. yAxisID: null
  7612. };
  7613. }
  7614. return meta;
  7615. },
  7616. getVisibleDatasetCount: function() {
  7617. var count = 0;
  7618. for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
  7619. if (this.isDatasetVisible(i)) {
  7620. count++;
  7621. }
  7622. }
  7623. return count;
  7624. },
  7625. isDatasetVisible: function(datasetIndex) {
  7626. var meta = this.getDatasetMeta(datasetIndex);
  7627. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  7628. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  7629. return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  7630. },
  7631. generateLegend: function() {
  7632. return this.options.legendCallback(this);
  7633. },
  7634. /**
  7635. * @private
  7636. */
  7637. destroyDatasetMeta: function(datasetIndex) {
  7638. var id = this.id;
  7639. var dataset = this.data.datasets[datasetIndex];
  7640. var meta = dataset._meta && dataset._meta[id];
  7641. if (meta) {
  7642. meta.controller.destroy();
  7643. delete dataset._meta[id];
  7644. }
  7645. },
  7646. destroy: function() {
  7647. var me = this;
  7648. var canvas = me.canvas;
  7649. var i, ilen;
  7650. me.stop();
  7651. // dataset controllers need to cleanup associated data
  7652. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  7653. me.destroyDatasetMeta(i);
  7654. }
  7655. if (canvas) {
  7656. me.unbindEvents();
  7657. helpers.canvas.clear(me);
  7658. platform.releaseContext(me.ctx);
  7659. me.canvas = null;
  7660. me.ctx = null;
  7661. }
  7662. plugins.notify(me, 'destroy');
  7663. delete Chart.instances[me.id];
  7664. },
  7665. toBase64Image: function() {
  7666. return this.canvas.toDataURL.apply(this.canvas, arguments);
  7667. },
  7668. initToolTip: function() {
  7669. var me = this;
  7670. me.tooltip = new Chart.Tooltip({
  7671. _chart: me,
  7672. _chartInstance: me, // deprecated, backward compatibility
  7673. _data: me.data,
  7674. _options: me.options.tooltips
  7675. }, me);
  7676. },
  7677. /**
  7678. * @private
  7679. */
  7680. bindEvents: function() {
  7681. var me = this;
  7682. var listeners = me._listeners = {};
  7683. var listener = function() {
  7684. me.eventHandler.apply(me, arguments);
  7685. };
  7686. helpers.each(me.options.events, function(type) {
  7687. platform.addEventListener(me, type, listener);
  7688. listeners[type] = listener;
  7689. });
  7690. // Elements used to detect size change should not be injected for non responsive charts.
  7691. // See https://github.com/chartjs/Chart.js/issues/2210
  7692. if (me.options.responsive) {
  7693. listener = function() {
  7694. me.resize();
  7695. };
  7696. platform.addEventListener(me, 'resize', listener);
  7697. listeners.resize = listener;
  7698. }
  7699. },
  7700. /**
  7701. * @private
  7702. */
  7703. unbindEvents: function() {
  7704. var me = this;
  7705. var listeners = me._listeners;
  7706. if (!listeners) {
  7707. return;
  7708. }
  7709. delete me._listeners;
  7710. helpers.each(listeners, function(listener, type) {
  7711. platform.removeEventListener(me, type, listener);
  7712. });
  7713. },
  7714. updateHoverStyle: function(elements, mode, enabled) {
  7715. var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
  7716. var element, i, ilen;
  7717. for (i = 0, ilen = elements.length; i < ilen; ++i) {
  7718. element = elements[i];
  7719. if (element) {
  7720. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  7721. }
  7722. }
  7723. },
  7724. /**
  7725. * @private
  7726. */
  7727. eventHandler: function(e) {
  7728. var me = this;
  7729. var tooltip = me.tooltip;
  7730. if (plugins.notify(me, 'beforeEvent', [e]) === false) {
  7731. return;
  7732. }
  7733. // Buffer any update calls so that renders do not occur
  7734. me._bufferedRender = true;
  7735. me._bufferedRequest = null;
  7736. var changed = me.handleEvent(e);
  7737. // for smooth tooltip animations issue #4989
  7738. // the tooltip should be the source of change
  7739. // Animation check workaround:
  7740. // tooltip._start will be null when tooltip isn't animating
  7741. if (tooltip) {
  7742. changed = tooltip._start
  7743. ? tooltip.handleEvent(e)
  7744. : changed | tooltip.handleEvent(e);
  7745. }
  7746. plugins.notify(me, 'afterEvent', [e]);
  7747. var bufferedRequest = me._bufferedRequest;
  7748. if (bufferedRequest) {
  7749. // If we have an update that was triggered, we need to do a normal render
  7750. me.render(bufferedRequest);
  7751. } else if (changed && !me.animating) {
  7752. // If entering, leaving, or changing elements, animate the change via pivot
  7753. me.stop();
  7754. // We only need to render at this point. Updating will cause scales to be
  7755. // recomputed generating flicker & using more memory than necessary.
  7756. me.render(me.options.hover.animationDuration, true);
  7757. }
  7758. me._bufferedRender = false;
  7759. me._bufferedRequest = null;
  7760. return me;
  7761. },
  7762. /**
  7763. * Handle an event
  7764. * @private
  7765. * @param {IEvent} event the event to handle
  7766. * @return {Boolean} true if the chart needs to re-render
  7767. */
  7768. handleEvent: function(e) {
  7769. var me = this;
  7770. var options = me.options || {};
  7771. var hoverOptions = options.hover;
  7772. var changed = false;
  7773. me.lastActive = me.lastActive || [];
  7774. // Find Active Elements for hover and tooltips
  7775. if (e.type === 'mouseout') {
  7776. me.active = [];
  7777. } else {
  7778. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
  7779. }
  7780. // Invoke onHover hook
  7781. // Need to call with native event here to not break backwards compatibility
  7782. helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
  7783. if (e.type === 'mouseup' || e.type === 'click') {
  7784. if (options.onClick) {
  7785. // Use e.native here for backwards compatibility
  7786. options.onClick.call(me, e.native, me.active);
  7787. }
  7788. }
  7789. // Remove styling for last active (even if it may still be active)
  7790. if (me.lastActive.length) {
  7791. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  7792. }
  7793. // Built in hover styling
  7794. if (me.active.length && hoverOptions.mode) {
  7795. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  7796. }
  7797. changed = !helpers.arrayEquals(me.active, me.lastActive);
  7798. // Remember Last Actives
  7799. me.lastActive = me.active;
  7800. return changed;
  7801. }
  7802. });
  7803. /**
  7804. * Provided for backward compatibility, use Chart instead.
  7805. * @class Chart.Controller
  7806. * @deprecated since version 2.6.0
  7807. * @todo remove at version 3
  7808. * @private
  7809. */
  7810. Chart.Controller = Chart;
  7811. };
  7812. },{"25":25,"28":28,"30":30,"31":31,"45":45,"48":48}],24:[function(require,module,exports){
  7813. 'use strict';
  7814. var helpers = require(45);
  7815. module.exports = function(Chart) {
  7816. var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  7817. /**
  7818. * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
  7819. * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
  7820. * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
  7821. */
  7822. function listenArrayEvents(array, listener) {
  7823. if (array._chartjs) {
  7824. array._chartjs.listeners.push(listener);
  7825. return;
  7826. }
  7827. Object.defineProperty(array, '_chartjs', {
  7828. configurable: true,
  7829. enumerable: false,
  7830. value: {
  7831. listeners: [listener]
  7832. }
  7833. });
  7834. arrayEvents.forEach(function(key) {
  7835. var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
  7836. var base = array[key];
  7837. Object.defineProperty(array, key, {
  7838. configurable: true,
  7839. enumerable: false,
  7840. value: function() {
  7841. var args = Array.prototype.slice.call(arguments);
  7842. var res = base.apply(this, args);
  7843. helpers.each(array._chartjs.listeners, function(object) {
  7844. if (typeof object[method] === 'function') {
  7845. object[method].apply(object, args);
  7846. }
  7847. });
  7848. return res;
  7849. }
  7850. });
  7851. });
  7852. }
  7853. /**
  7854. * Removes the given array event listener and cleanup extra attached properties (such as
  7855. * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
  7856. */
  7857. function unlistenArrayEvents(array, listener) {
  7858. var stub = array._chartjs;
  7859. if (!stub) {
  7860. return;
  7861. }
  7862. var listeners = stub.listeners;
  7863. var index = listeners.indexOf(listener);
  7864. if (index !== -1) {
  7865. listeners.splice(index, 1);
  7866. }
  7867. if (listeners.length > 0) {
  7868. return;
  7869. }
  7870. arrayEvents.forEach(function(key) {
  7871. delete array[key];
  7872. });
  7873. delete array._chartjs;
  7874. }
  7875. // Base class for all dataset controllers (line, bar, etc)
  7876. Chart.DatasetController = function(chart, datasetIndex) {
  7877. this.initialize(chart, datasetIndex);
  7878. };
  7879. helpers.extend(Chart.DatasetController.prototype, {
  7880. /**
  7881. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  7882. * @type {Chart.core.element}
  7883. */
  7884. datasetElementType: null,
  7885. /**
  7886. * Element type used to generate a meta data (e.g. Chart.element.Point).
  7887. * @type {Chart.core.element}
  7888. */
  7889. dataElementType: null,
  7890. initialize: function(chart, datasetIndex) {
  7891. var me = this;
  7892. me.chart = chart;
  7893. me.index = datasetIndex;
  7894. me.linkScales();
  7895. me.addElements();
  7896. },
  7897. updateIndex: function(datasetIndex) {
  7898. this.index = datasetIndex;
  7899. },
  7900. linkScales: function() {
  7901. var me = this;
  7902. var meta = me.getMeta();
  7903. var dataset = me.getDataset();
  7904. if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
  7905. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  7906. }
  7907. if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
  7908. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  7909. }
  7910. },
  7911. getDataset: function() {
  7912. return this.chart.data.datasets[this.index];
  7913. },
  7914. getMeta: function() {
  7915. return this.chart.getDatasetMeta(this.index);
  7916. },
  7917. getScaleForId: function(scaleID) {
  7918. return this.chart.scales[scaleID];
  7919. },
  7920. reset: function() {
  7921. this.update(true);
  7922. },
  7923. /**
  7924. * @private
  7925. */
  7926. destroy: function() {
  7927. if (this._data) {
  7928. unlistenArrayEvents(this._data, this);
  7929. }
  7930. },
  7931. createMetaDataset: function() {
  7932. var me = this;
  7933. var type = me.datasetElementType;
  7934. return type && new type({
  7935. _chart: me.chart,
  7936. _datasetIndex: me.index
  7937. });
  7938. },
  7939. createMetaData: function(index) {
  7940. var me = this;
  7941. var type = me.dataElementType;
  7942. return type && new type({
  7943. _chart: me.chart,
  7944. _datasetIndex: me.index,
  7945. _index: index
  7946. });
  7947. },
  7948. addElements: function() {
  7949. var me = this;
  7950. var meta = me.getMeta();
  7951. var data = me.getDataset().data || [];
  7952. var metaData = meta.data;
  7953. var i, ilen;
  7954. for (i = 0, ilen = data.length; i < ilen; ++i) {
  7955. metaData[i] = metaData[i] || me.createMetaData(i);
  7956. }
  7957. meta.dataset = meta.dataset || me.createMetaDataset();
  7958. },
  7959. addElementAndReset: function(index) {
  7960. var element = this.createMetaData(index);
  7961. this.getMeta().data.splice(index, 0, element);
  7962. this.updateElement(element, index, true);
  7963. },
  7964. buildOrUpdateElements: function() {
  7965. var me = this;
  7966. var dataset = me.getDataset();
  7967. var data = dataset.data || (dataset.data = []);
  7968. // In order to correctly handle data addition/deletion animation (an thus simulate
  7969. // real-time charts), we need to monitor these data modifications and synchronize
  7970. // the internal meta data accordingly.
  7971. if (me._data !== data) {
  7972. if (me._data) {
  7973. // This case happens when the user replaced the data array instance.
  7974. unlistenArrayEvents(me._data, me);
  7975. }
  7976. listenArrayEvents(data, me);
  7977. me._data = data;
  7978. }
  7979. // Re-sync meta data in case the user replaced the data array or if we missed
  7980. // any updates and so make sure that we handle number of datapoints changing.
  7981. me.resyncElements();
  7982. },
  7983. update: helpers.noop,
  7984. transition: function(easingValue) {
  7985. var meta = this.getMeta();
  7986. var elements = meta.data || [];
  7987. var ilen = elements.length;
  7988. var i = 0;
  7989. for (; i < ilen; ++i) {
  7990. elements[i].transition(easingValue);
  7991. }
  7992. if (meta.dataset) {
  7993. meta.dataset.transition(easingValue);
  7994. }
  7995. },
  7996. draw: function() {
  7997. var meta = this.getMeta();
  7998. var elements = meta.data || [];
  7999. var ilen = elements.length;
  8000. var i = 0;
  8001. if (meta.dataset) {
  8002. meta.dataset.draw();
  8003. }
  8004. for (; i < ilen; ++i) {
  8005. elements[i].draw();
  8006. }
  8007. },
  8008. removeHoverStyle: function(element, elementOpts) {
  8009. var dataset = this.chart.data.datasets[element._datasetIndex];
  8010. var index = element._index;
  8011. var custom = element.custom || {};
  8012. var valueOrDefault = helpers.valueAtIndexOrDefault;
  8013. var model = element._model;
  8014. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  8015. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  8016. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  8017. },
  8018. setHoverStyle: function(element) {
  8019. var dataset = this.chart.data.datasets[element._datasetIndex];
  8020. var index = element._index;
  8021. var custom = element.custom || {};
  8022. var valueOrDefault = helpers.valueAtIndexOrDefault;
  8023. var getHoverColor = helpers.getHoverColor;
  8024. var model = element._model;
  8025. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  8026. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  8027. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  8028. },
  8029. /**
  8030. * @private
  8031. */
  8032. resyncElements: function() {
  8033. var me = this;
  8034. var meta = me.getMeta();
  8035. var data = me.getDataset().data;
  8036. var numMeta = meta.data.length;
  8037. var numData = data.length;
  8038. if (numData < numMeta) {
  8039. meta.data.splice(numData, numMeta - numData);
  8040. } else if (numData > numMeta) {
  8041. me.insertElements(numMeta, numData - numMeta);
  8042. }
  8043. },
  8044. /**
  8045. * @private
  8046. */
  8047. insertElements: function(start, count) {
  8048. for (var i = 0; i < count; ++i) {
  8049. this.addElementAndReset(start + i);
  8050. }
  8051. },
  8052. /**
  8053. * @private
  8054. */
  8055. onDataPush: function() {
  8056. this.insertElements(this.getDataset().data.length - 1, arguments.length);
  8057. },
  8058. /**
  8059. * @private
  8060. */
  8061. onDataPop: function() {
  8062. this.getMeta().data.pop();
  8063. },
  8064. /**
  8065. * @private
  8066. */
  8067. onDataShift: function() {
  8068. this.getMeta().data.shift();
  8069. },
  8070. /**
  8071. * @private
  8072. */
  8073. onDataSplice: function(start, count) {
  8074. this.getMeta().data.splice(start, count);
  8075. this.insertElements(start, arguments.length - 2);
  8076. },
  8077. /**
  8078. * @private
  8079. */
  8080. onDataUnshift: function() {
  8081. this.insertElements(0, arguments.length);
  8082. }
  8083. });
  8084. Chart.DatasetController.extend = helpers.inherits;
  8085. };
  8086. },{"45":45}],25:[function(require,module,exports){
  8087. 'use strict';
  8088. var helpers = require(45);
  8089. module.exports = {
  8090. /**
  8091. * @private
  8092. */
  8093. _set: function(scope, values) {
  8094. return helpers.merge(this[scope] || (this[scope] = {}), values);
  8095. }
  8096. };
  8097. },{"45":45}],26:[function(require,module,exports){
  8098. 'use strict';
  8099. var color = require(2);
  8100. var helpers = require(45);
  8101. function interpolate(start, view, model, ease) {
  8102. var keys = Object.keys(model);
  8103. var i, ilen, key, actual, origin, target, type, c0, c1;
  8104. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  8105. key = keys[i];
  8106. target = model[key];
  8107. // if a value is added to the model after pivot() has been called, the view
  8108. // doesn't contain it, so let's initialize the view to the target value.
  8109. if (!view.hasOwnProperty(key)) {
  8110. view[key] = target;
  8111. }
  8112. actual = view[key];
  8113. if (actual === target || key[0] === '_') {
  8114. continue;
  8115. }
  8116. if (!start.hasOwnProperty(key)) {
  8117. start[key] = actual;
  8118. }
  8119. origin = start[key];
  8120. type = typeof target;
  8121. if (type === typeof origin) {
  8122. if (type === 'string') {
  8123. c0 = color(origin);
  8124. if (c0.valid) {
  8125. c1 = color(target);
  8126. if (c1.valid) {
  8127. view[key] = c1.mix(c0, ease).rgbString();
  8128. continue;
  8129. }
  8130. }
  8131. } else if (type === 'number' && isFinite(origin) && isFinite(target)) {
  8132. view[key] = origin + (target - origin) * ease;
  8133. continue;
  8134. }
  8135. }
  8136. view[key] = target;
  8137. }
  8138. }
  8139. var Element = function(configuration) {
  8140. helpers.extend(this, configuration);
  8141. this.initialize.apply(this, arguments);
  8142. };
  8143. helpers.extend(Element.prototype, {
  8144. initialize: function() {
  8145. this.hidden = false;
  8146. },
  8147. pivot: function() {
  8148. var me = this;
  8149. if (!me._view) {
  8150. me._view = helpers.clone(me._model);
  8151. }
  8152. me._start = {};
  8153. return me;
  8154. },
  8155. transition: function(ease) {
  8156. var me = this;
  8157. var model = me._model;
  8158. var start = me._start;
  8159. var view = me._view;
  8160. // No animation -> No Transition
  8161. if (!model || ease === 1) {
  8162. me._view = model;
  8163. me._start = null;
  8164. return me;
  8165. }
  8166. if (!view) {
  8167. view = me._view = {};
  8168. }
  8169. if (!start) {
  8170. start = me._start = {};
  8171. }
  8172. interpolate(start, view, model, ease);
  8173. return me;
  8174. },
  8175. tooltipPosition: function() {
  8176. return {
  8177. x: this._model.x,
  8178. y: this._model.y
  8179. };
  8180. },
  8181. hasValue: function() {
  8182. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  8183. }
  8184. });
  8185. Element.extend = helpers.inherits;
  8186. module.exports = Element;
  8187. },{"2":2,"45":45}],27:[function(require,module,exports){
  8188. /* global window: false */
  8189. /* global document: false */
  8190. 'use strict';
  8191. var color = require(2);
  8192. var defaults = require(25);
  8193. var helpers = require(45);
  8194. module.exports = function(Chart) {
  8195. // -- Basic js utility methods
  8196. helpers.configMerge = function(/* objects ... */) {
  8197. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  8198. merger: function(key, target, source, options) {
  8199. var tval = target[key] || {};
  8200. var sval = source[key];
  8201. if (key === 'scales') {
  8202. // scale config merging is complex. Add our own function here for that
  8203. target[key] = helpers.scaleMerge(tval, sval);
  8204. } else if (key === 'scale') {
  8205. // used in polar area & radar charts since there is only one scale
  8206. target[key] = helpers.merge(tval, [Chart.scaleService.getScaleDefaults(sval.type), sval]);
  8207. } else {
  8208. helpers._merger(key, target, source, options);
  8209. }
  8210. }
  8211. });
  8212. };
  8213. helpers.scaleMerge = function(/* objects ... */) {
  8214. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  8215. merger: function(key, target, source, options) {
  8216. if (key === 'xAxes' || key === 'yAxes') {
  8217. var slen = source[key].length;
  8218. var i, type, scale;
  8219. if (!target[key]) {
  8220. target[key] = [];
  8221. }
  8222. for (i = 0; i < slen; ++i) {
  8223. scale = source[key][i];
  8224. type = helpers.valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
  8225. if (i >= target[key].length) {
  8226. target[key].push({});
  8227. }
  8228. if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
  8229. // new/untyped scale or type changed: let's apply the new defaults
  8230. // then merge source scale to correctly overwrite the defaults.
  8231. helpers.merge(target[key][i], [Chart.scaleService.getScaleDefaults(type), scale]);
  8232. } else {
  8233. // scales type are the same
  8234. helpers.merge(target[key][i], scale);
  8235. }
  8236. }
  8237. } else {
  8238. helpers._merger(key, target, source, options);
  8239. }
  8240. }
  8241. });
  8242. };
  8243. helpers.where = function(collection, filterCallback) {
  8244. if (helpers.isArray(collection) && Array.prototype.filter) {
  8245. return collection.filter(filterCallback);
  8246. }
  8247. var filtered = [];
  8248. helpers.each(collection, function(item) {
  8249. if (filterCallback(item)) {
  8250. filtered.push(item);
  8251. }
  8252. });
  8253. return filtered;
  8254. };
  8255. helpers.findIndex = Array.prototype.findIndex ?
  8256. function(array, callback, scope) {
  8257. return array.findIndex(callback, scope);
  8258. } :
  8259. function(array, callback, scope) {
  8260. scope = scope === undefined ? array : scope;
  8261. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  8262. if (callback.call(scope, array[i], i, array)) {
  8263. return i;
  8264. }
  8265. }
  8266. return -1;
  8267. };
  8268. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  8269. // Default to start of the array
  8270. if (helpers.isNullOrUndef(startIndex)) {
  8271. startIndex = -1;
  8272. }
  8273. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  8274. var currentItem = arrayToSearch[i];
  8275. if (filterCallback(currentItem)) {
  8276. return currentItem;
  8277. }
  8278. }
  8279. };
  8280. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  8281. // Default to end of the array
  8282. if (helpers.isNullOrUndef(startIndex)) {
  8283. startIndex = arrayToSearch.length;
  8284. }
  8285. for (var i = startIndex - 1; i >= 0; i--) {
  8286. var currentItem = arrayToSearch[i];
  8287. if (filterCallback(currentItem)) {
  8288. return currentItem;
  8289. }
  8290. }
  8291. };
  8292. // -- Math methods
  8293. helpers.isNumber = function(n) {
  8294. return !isNaN(parseFloat(n)) && isFinite(n);
  8295. };
  8296. helpers.almostEquals = function(x, y, epsilon) {
  8297. return Math.abs(x - y) < epsilon;
  8298. };
  8299. helpers.almostWhole = function(x, epsilon) {
  8300. var rounded = Math.round(x);
  8301. return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
  8302. };
  8303. helpers.max = function(array) {
  8304. return array.reduce(function(max, value) {
  8305. if (!isNaN(value)) {
  8306. return Math.max(max, value);
  8307. }
  8308. return max;
  8309. }, Number.NEGATIVE_INFINITY);
  8310. };
  8311. helpers.min = function(array) {
  8312. return array.reduce(function(min, value) {
  8313. if (!isNaN(value)) {
  8314. return Math.min(min, value);
  8315. }
  8316. return min;
  8317. }, Number.POSITIVE_INFINITY);
  8318. };
  8319. helpers.sign = Math.sign ?
  8320. function(x) {
  8321. return Math.sign(x);
  8322. } :
  8323. function(x) {
  8324. x = +x; // convert to a number
  8325. if (x === 0 || isNaN(x)) {
  8326. return x;
  8327. }
  8328. return x > 0 ? 1 : -1;
  8329. };
  8330. helpers.log10 = Math.log10 ?
  8331. function(x) {
  8332. return Math.log10(x);
  8333. } :
  8334. function(x) {
  8335. var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
  8336. // Check for whole powers of 10,
  8337. // which due to floating point rounding error should be corrected.
  8338. var powerOf10 = Math.round(exponent);
  8339. var isPowerOf10 = x === Math.pow(10, powerOf10);
  8340. return isPowerOf10 ? powerOf10 : exponent;
  8341. };
  8342. helpers.toRadians = function(degrees) {
  8343. return degrees * (Math.PI / 180);
  8344. };
  8345. helpers.toDegrees = function(radians) {
  8346. return radians * (180 / Math.PI);
  8347. };
  8348. // Gets the angle from vertical upright to the point about a centre.
  8349. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  8350. var distanceFromXCenter = anglePoint.x - centrePoint.x;
  8351. var distanceFromYCenter = anglePoint.y - centrePoint.y;
  8352. var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  8353. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  8354. if (angle < (-0.5 * Math.PI)) {
  8355. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  8356. }
  8357. return {
  8358. angle: angle,
  8359. distance: radialDistanceFromCenter
  8360. };
  8361. };
  8362. helpers.distanceBetweenPoints = function(pt1, pt2) {
  8363. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  8364. };
  8365. helpers.aliasPixel = function(pixelWidth) {
  8366. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  8367. };
  8368. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  8369. // Props to Rob Spencer at scaled innovation for his post on splining between points
  8370. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  8371. // This function must also respect "skipped" points
  8372. var previous = firstPoint.skip ? middlePoint : firstPoint;
  8373. var current = middlePoint;
  8374. var next = afterPoint.skip ? middlePoint : afterPoint;
  8375. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  8376. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  8377. var s01 = d01 / (d01 + d12);
  8378. var s12 = d12 / (d01 + d12);
  8379. // If all points are the same, s01 & s02 will be inf
  8380. s01 = isNaN(s01) ? 0 : s01;
  8381. s12 = isNaN(s12) ? 0 : s12;
  8382. var fa = t * s01; // scaling factor for triangle Ta
  8383. var fb = t * s12;
  8384. return {
  8385. previous: {
  8386. x: current.x - fa * (next.x - previous.x),
  8387. y: current.y - fa * (next.y - previous.y)
  8388. },
  8389. next: {
  8390. x: current.x + fb * (next.x - previous.x),
  8391. y: current.y + fb * (next.y - previous.y)
  8392. }
  8393. };
  8394. };
  8395. helpers.EPSILON = Number.EPSILON || 1e-14;
  8396. helpers.splineCurveMonotone = function(points) {
  8397. // This function calculates Bézier control points in a similar way than |splineCurve|,
  8398. // but preserves monotonicity of the provided data and ensures no local extremums are added
  8399. // between the dataset discrete points due to the interpolation.
  8400. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  8401. var pointsWithTangents = (points || []).map(function(point) {
  8402. return {
  8403. model: point._model,
  8404. deltaK: 0,
  8405. mK: 0
  8406. };
  8407. });
  8408. // Calculate slopes (deltaK) and initialize tangents (mK)
  8409. var pointsLen = pointsWithTangents.length;
  8410. var i, pointBefore, pointCurrent, pointAfter;
  8411. for (i = 0; i < pointsLen; ++i) {
  8412. pointCurrent = pointsWithTangents[i];
  8413. if (pointCurrent.model.skip) {
  8414. continue;
  8415. }
  8416. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  8417. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  8418. if (pointAfter && !pointAfter.model.skip) {
  8419. var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
  8420. // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
  8421. pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
  8422. }
  8423. if (!pointBefore || pointBefore.model.skip) {
  8424. pointCurrent.mK = pointCurrent.deltaK;
  8425. } else if (!pointAfter || pointAfter.model.skip) {
  8426. pointCurrent.mK = pointBefore.deltaK;
  8427. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  8428. pointCurrent.mK = 0;
  8429. } else {
  8430. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  8431. }
  8432. }
  8433. // Adjust tangents to ensure monotonic properties
  8434. var alphaK, betaK, tauK, squaredMagnitude;
  8435. for (i = 0; i < pointsLen - 1; ++i) {
  8436. pointCurrent = pointsWithTangents[i];
  8437. pointAfter = pointsWithTangents[i + 1];
  8438. if (pointCurrent.model.skip || pointAfter.model.skip) {
  8439. continue;
  8440. }
  8441. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  8442. pointCurrent.mK = pointAfter.mK = 0;
  8443. continue;
  8444. }
  8445. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  8446. betaK = pointAfter.mK / pointCurrent.deltaK;
  8447. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  8448. if (squaredMagnitude <= 9) {
  8449. continue;
  8450. }
  8451. tauK = 3 / Math.sqrt(squaredMagnitude);
  8452. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  8453. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  8454. }
  8455. // Compute control points
  8456. var deltaX;
  8457. for (i = 0; i < pointsLen; ++i) {
  8458. pointCurrent = pointsWithTangents[i];
  8459. if (pointCurrent.model.skip) {
  8460. continue;
  8461. }
  8462. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  8463. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  8464. if (pointBefore && !pointBefore.model.skip) {
  8465. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  8466. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  8467. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  8468. }
  8469. if (pointAfter && !pointAfter.model.skip) {
  8470. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  8471. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  8472. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  8473. }
  8474. }
  8475. };
  8476. helpers.nextItem = function(collection, index, loop) {
  8477. if (loop) {
  8478. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  8479. }
  8480. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  8481. };
  8482. helpers.previousItem = function(collection, index, loop) {
  8483. if (loop) {
  8484. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  8485. }
  8486. return index <= 0 ? collection[0] : collection[index - 1];
  8487. };
  8488. // Implementation of the nice number algorithm used in determining where axis labels will go
  8489. helpers.niceNum = function(range, round) {
  8490. var exponent = Math.floor(helpers.log10(range));
  8491. var fraction = range / Math.pow(10, exponent);
  8492. var niceFraction;
  8493. if (round) {
  8494. if (fraction < 1.5) {
  8495. niceFraction = 1;
  8496. } else if (fraction < 3) {
  8497. niceFraction = 2;
  8498. } else if (fraction < 7) {
  8499. niceFraction = 5;
  8500. } else {
  8501. niceFraction = 10;
  8502. }
  8503. } else if (fraction <= 1.0) {
  8504. niceFraction = 1;
  8505. } else if (fraction <= 2) {
  8506. niceFraction = 2;
  8507. } else if (fraction <= 5) {
  8508. niceFraction = 5;
  8509. } else {
  8510. niceFraction = 10;
  8511. }
  8512. return niceFraction * Math.pow(10, exponent);
  8513. };
  8514. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  8515. helpers.requestAnimFrame = (function() {
  8516. if (typeof window === 'undefined') {
  8517. return function(callback) {
  8518. callback();
  8519. };
  8520. }
  8521. return window.requestAnimationFrame ||
  8522. window.webkitRequestAnimationFrame ||
  8523. window.mozRequestAnimationFrame ||
  8524. window.oRequestAnimationFrame ||
  8525. window.msRequestAnimationFrame ||
  8526. function(callback) {
  8527. return window.setTimeout(callback, 1000 / 60);
  8528. };
  8529. }());
  8530. // -- DOM methods
  8531. helpers.getRelativePosition = function(evt, chart) {
  8532. var mouseX, mouseY;
  8533. var e = evt.originalEvent || evt;
  8534. var canvas = evt.currentTarget || evt.srcElement;
  8535. var boundingRect = canvas.getBoundingClientRect();
  8536. var touches = e.touches;
  8537. if (touches && touches.length > 0) {
  8538. mouseX = touches[0].clientX;
  8539. mouseY = touches[0].clientY;
  8540. } else {
  8541. mouseX = e.clientX;
  8542. mouseY = e.clientY;
  8543. }
  8544. // Scale mouse coordinates into canvas coordinates
  8545. // by following the pattern laid out by 'jerryj' in the comments of
  8546. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  8547. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  8548. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  8549. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  8550. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  8551. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  8552. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  8553. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  8554. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  8555. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  8556. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  8557. return {
  8558. x: mouseX,
  8559. y: mouseY
  8560. };
  8561. };
  8562. // Private helper function to convert max-width/max-height values that may be percentages into a number
  8563. function parseMaxStyle(styleValue, node, parentProperty) {
  8564. var valueInPixels;
  8565. if (typeof styleValue === 'string') {
  8566. valueInPixels = parseInt(styleValue, 10);
  8567. if (styleValue.indexOf('%') !== -1) {
  8568. // percentage * size in dimension
  8569. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  8570. }
  8571. } else {
  8572. valueInPixels = styleValue;
  8573. }
  8574. return valueInPixels;
  8575. }
  8576. /**
  8577. * Returns if the given value contains an effective constraint.
  8578. * @private
  8579. */
  8580. function isConstrainedValue(value) {
  8581. return value !== undefined && value !== null && value !== 'none';
  8582. }
  8583. // Private helper to get a constraint dimension
  8584. // @param domNode : the node to check the constraint on
  8585. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  8586. // @param percentageProperty : property of parent to use when calculating width as a percentage
  8587. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  8588. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  8589. var view = document.defaultView;
  8590. var parentNode = domNode.parentNode;
  8591. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  8592. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  8593. var hasCNode = isConstrainedValue(constrainedNode);
  8594. var hasCContainer = isConstrainedValue(constrainedContainer);
  8595. var infinity = Number.POSITIVE_INFINITY;
  8596. if (hasCNode || hasCContainer) {
  8597. return Math.min(
  8598. hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  8599. hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  8600. }
  8601. return 'none';
  8602. }
  8603. // returns Number or undefined if no constraint
  8604. helpers.getConstraintWidth = function(domNode) {
  8605. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  8606. };
  8607. // returns Number or undefined if no constraint
  8608. helpers.getConstraintHeight = function(domNode) {
  8609. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  8610. };
  8611. helpers.getMaximumWidth = function(domNode) {
  8612. var container = domNode.parentNode;
  8613. if (!container) {
  8614. return domNode.clientWidth;
  8615. }
  8616. var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
  8617. var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
  8618. var w = container.clientWidth - paddingLeft - paddingRight;
  8619. var cw = helpers.getConstraintWidth(domNode);
  8620. return isNaN(cw) ? w : Math.min(w, cw);
  8621. };
  8622. helpers.getMaximumHeight = function(domNode) {
  8623. var container = domNode.parentNode;
  8624. if (!container) {
  8625. return domNode.clientHeight;
  8626. }
  8627. var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
  8628. var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
  8629. var h = container.clientHeight - paddingTop - paddingBottom;
  8630. var ch = helpers.getConstraintHeight(domNode);
  8631. return isNaN(ch) ? h : Math.min(h, ch);
  8632. };
  8633. helpers.getStyle = function(el, property) {
  8634. return el.currentStyle ?
  8635. el.currentStyle[property] :
  8636. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  8637. };
  8638. helpers.retinaScale = function(chart, forceRatio) {
  8639. var pixelRatio = chart.currentDevicePixelRatio = forceRatio || window.devicePixelRatio || 1;
  8640. if (pixelRatio === 1) {
  8641. return;
  8642. }
  8643. var canvas = chart.canvas;
  8644. var height = chart.height;
  8645. var width = chart.width;
  8646. canvas.height = height * pixelRatio;
  8647. canvas.width = width * pixelRatio;
  8648. chart.ctx.scale(pixelRatio, pixelRatio);
  8649. // If no style has been set on the canvas, the render size is used as display size,
  8650. // making the chart visually bigger, so let's enforce it to the "correct" values.
  8651. // See https://github.com/chartjs/Chart.js/issues/3575
  8652. if (!canvas.style.height && !canvas.style.width) {
  8653. canvas.style.height = height + 'px';
  8654. canvas.style.width = width + 'px';
  8655. }
  8656. };
  8657. // -- Canvas methods
  8658. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  8659. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  8660. };
  8661. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  8662. cache = cache || {};
  8663. var data = cache.data = cache.data || {};
  8664. var gc = cache.garbageCollect = cache.garbageCollect || [];
  8665. if (cache.font !== font) {
  8666. data = cache.data = {};
  8667. gc = cache.garbageCollect = [];
  8668. cache.font = font;
  8669. }
  8670. ctx.font = font;
  8671. var longest = 0;
  8672. helpers.each(arrayOfThings, function(thing) {
  8673. // Undefined strings and arrays should not be measured
  8674. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  8675. longest = helpers.measureText(ctx, data, gc, longest, thing);
  8676. } else if (helpers.isArray(thing)) {
  8677. // if it is an array lets measure each element
  8678. // to do maybe simplify this function a bit so we can do this more recursively?
  8679. helpers.each(thing, function(nestedThing) {
  8680. // Undefined strings and arrays should not be measured
  8681. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  8682. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  8683. }
  8684. });
  8685. }
  8686. });
  8687. var gcLen = gc.length / 2;
  8688. if (gcLen > arrayOfThings.length) {
  8689. for (var i = 0; i < gcLen; i++) {
  8690. delete data[gc[i]];
  8691. }
  8692. gc.splice(0, gcLen);
  8693. }
  8694. return longest;
  8695. };
  8696. helpers.measureText = function(ctx, data, gc, longest, string) {
  8697. var textWidth = data[string];
  8698. if (!textWidth) {
  8699. textWidth = data[string] = ctx.measureText(string).width;
  8700. gc.push(string);
  8701. }
  8702. if (textWidth > longest) {
  8703. longest = textWidth;
  8704. }
  8705. return longest;
  8706. };
  8707. helpers.numberOfLabelLines = function(arrayOfThings) {
  8708. var numberOfLines = 1;
  8709. helpers.each(arrayOfThings, function(thing) {
  8710. if (helpers.isArray(thing)) {
  8711. if (thing.length > numberOfLines) {
  8712. numberOfLines = thing.length;
  8713. }
  8714. }
  8715. });
  8716. return numberOfLines;
  8717. };
  8718. helpers.color = !color ?
  8719. function(value) {
  8720. console.error('Color.js not found!');
  8721. return value;
  8722. } :
  8723. function(value) {
  8724. /* global CanvasGradient */
  8725. if (value instanceof CanvasGradient) {
  8726. value = defaults.global.defaultColor;
  8727. }
  8728. return color(value);
  8729. };
  8730. helpers.getHoverColor = function(colorValue) {
  8731. /* global CanvasPattern */
  8732. return (colorValue instanceof CanvasPattern) ?
  8733. colorValue :
  8734. helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
  8735. };
  8736. };
  8737. },{"2":2,"25":25,"45":45}],28:[function(require,module,exports){
  8738. 'use strict';
  8739. var helpers = require(45);
  8740. /**
  8741. * Helper function to get relative position for an event
  8742. * @param {Event|IEvent} event - The event to get the position for
  8743. * @param {Chart} chart - The chart
  8744. * @returns {Point} the event position
  8745. */
  8746. function getRelativePosition(e, chart) {
  8747. if (e.native) {
  8748. return {
  8749. x: e.x,
  8750. y: e.y
  8751. };
  8752. }
  8753. return helpers.getRelativePosition(e, chart);
  8754. }
  8755. /**
  8756. * Helper function to traverse all of the visible elements in the chart
  8757. * @param chart {chart} the chart
  8758. * @param handler {Function} the callback to execute for each visible item
  8759. */
  8760. function parseVisibleItems(chart, handler) {
  8761. var datasets = chart.data.datasets;
  8762. var meta, i, j, ilen, jlen;
  8763. for (i = 0, ilen = datasets.length; i < ilen; ++i) {
  8764. if (!chart.isDatasetVisible(i)) {
  8765. continue;
  8766. }
  8767. meta = chart.getDatasetMeta(i);
  8768. for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
  8769. var element = meta.data[j];
  8770. if (!element._view.skip) {
  8771. handler(element);
  8772. }
  8773. }
  8774. }
  8775. }
  8776. /**
  8777. * Helper function to get the items that intersect the event position
  8778. * @param items {ChartElement[]} elements to filter
  8779. * @param position {Point} the point to be nearest to
  8780. * @return {ChartElement[]} the nearest items
  8781. */
  8782. function getIntersectItems(chart, position) {
  8783. var elements = [];
  8784. parseVisibleItems(chart, function(element) {
  8785. if (element.inRange(position.x, position.y)) {
  8786. elements.push(element);
  8787. }
  8788. });
  8789. return elements;
  8790. }
  8791. /**
  8792. * Helper function to get the items nearest to the event position considering all visible items in teh chart
  8793. * @param chart {Chart} the chart to look at elements from
  8794. * @param position {Point} the point to be nearest to
  8795. * @param intersect {Boolean} if true, only consider items that intersect the position
  8796. * @param distanceMetric {Function} function to provide the distance between points
  8797. * @return {ChartElement[]} the nearest items
  8798. */
  8799. function getNearestItems(chart, position, intersect, distanceMetric) {
  8800. var minDistance = Number.POSITIVE_INFINITY;
  8801. var nearestItems = [];
  8802. parseVisibleItems(chart, function(element) {
  8803. if (intersect && !element.inRange(position.x, position.y)) {
  8804. return;
  8805. }
  8806. var center = element.getCenterPoint();
  8807. var distance = distanceMetric(position, center);
  8808. if (distance < minDistance) {
  8809. nearestItems = [element];
  8810. minDistance = distance;
  8811. } else if (distance === minDistance) {
  8812. // Can have multiple items at the same distance in which case we sort by size
  8813. nearestItems.push(element);
  8814. }
  8815. });
  8816. return nearestItems;
  8817. }
  8818. /**
  8819. * Get a distance metric function for two points based on the
  8820. * axis mode setting
  8821. * @param {String} axis the axis mode. x|y|xy
  8822. */
  8823. function getDistanceMetricForAxis(axis) {
  8824. var useX = axis.indexOf('x') !== -1;
  8825. var useY = axis.indexOf('y') !== -1;
  8826. return function(pt1, pt2) {
  8827. var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0;
  8828. var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0;
  8829. return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
  8830. };
  8831. }
  8832. function indexMode(chart, e, options) {
  8833. var position = getRelativePosition(e, chart);
  8834. // Default axis for index mode is 'x' to match old behaviour
  8835. options.axis = options.axis || 'x';
  8836. var distanceMetric = getDistanceMetricForAxis(options.axis);
  8837. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  8838. var elements = [];
  8839. if (!items.length) {
  8840. return [];
  8841. }
  8842. chart.data.datasets.forEach(function(dataset, datasetIndex) {
  8843. if (chart.isDatasetVisible(datasetIndex)) {
  8844. var meta = chart.getDatasetMeta(datasetIndex);
  8845. var element = meta.data[items[0]._index];
  8846. // don't count items that are skipped (null data)
  8847. if (element && !element._view.skip) {
  8848. elements.push(element);
  8849. }
  8850. }
  8851. });
  8852. return elements;
  8853. }
  8854. /**
  8855. * @interface IInteractionOptions
  8856. */
  8857. /**
  8858. * If true, only consider items that intersect the point
  8859. * @name IInterfaceOptions#boolean
  8860. * @type Boolean
  8861. */
  8862. /**
  8863. * Contains interaction related functions
  8864. * @namespace Chart.Interaction
  8865. */
  8866. module.exports = {
  8867. // Helper function for different modes
  8868. modes: {
  8869. single: function(chart, e) {
  8870. var position = getRelativePosition(e, chart);
  8871. var elements = [];
  8872. parseVisibleItems(chart, function(element) {
  8873. if (element.inRange(position.x, position.y)) {
  8874. elements.push(element);
  8875. return elements;
  8876. }
  8877. });
  8878. return elements.slice(0, 1);
  8879. },
  8880. /**
  8881. * @function Chart.Interaction.modes.label
  8882. * @deprecated since version 2.4.0
  8883. * @todo remove at version 3
  8884. * @private
  8885. */
  8886. label: indexMode,
  8887. /**
  8888. * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
  8889. * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
  8890. * @function Chart.Interaction.modes.index
  8891. * @since v2.4.0
  8892. * @param chart {chart} the chart we are returning items from
  8893. * @param e {Event} the event we are find things at
  8894. * @param options {IInteractionOptions} options to use during interaction
  8895. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  8896. */
  8897. index: indexMode,
  8898. /**
  8899. * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
  8900. * If the options.intersect is false, we find the nearest item and return the items in that dataset
  8901. * @function Chart.Interaction.modes.dataset
  8902. * @param chart {chart} the chart we are returning items from
  8903. * @param e {Event} the event we are find things at
  8904. * @param options {IInteractionOptions} options to use during interaction
  8905. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  8906. */
  8907. dataset: function(chart, e, options) {
  8908. var position = getRelativePosition(e, chart);
  8909. options.axis = options.axis || 'xy';
  8910. var distanceMetric = getDistanceMetricForAxis(options.axis);
  8911. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  8912. if (items.length > 0) {
  8913. items = chart.getDatasetMeta(items[0]._datasetIndex).data;
  8914. }
  8915. return items;
  8916. },
  8917. /**
  8918. * @function Chart.Interaction.modes.x-axis
  8919. * @deprecated since version 2.4.0. Use index mode and intersect == true
  8920. * @todo remove at version 3
  8921. * @private
  8922. */
  8923. 'x-axis': function(chart, e) {
  8924. return indexMode(chart, e, {intersect: false});
  8925. },
  8926. /**
  8927. * Point mode returns all elements that hit test based on the event position
  8928. * of the event
  8929. * @function Chart.Interaction.modes.intersect
  8930. * @param chart {chart} the chart we are returning items from
  8931. * @param e {Event} the event we are find things at
  8932. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  8933. */
  8934. point: function(chart, e) {
  8935. var position = getRelativePosition(e, chart);
  8936. return getIntersectItems(chart, position);
  8937. },
  8938. /**
  8939. * nearest mode returns the element closest to the point
  8940. * @function Chart.Interaction.modes.intersect
  8941. * @param chart {chart} the chart we are returning items from
  8942. * @param e {Event} the event we are find things at
  8943. * @param options {IInteractionOptions} options to use
  8944. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  8945. */
  8946. nearest: function(chart, e, options) {
  8947. var position = getRelativePosition(e, chart);
  8948. options.axis = options.axis || 'xy';
  8949. var distanceMetric = getDistanceMetricForAxis(options.axis);
  8950. var nearestItems = getNearestItems(chart, position, options.intersect, distanceMetric);
  8951. // We have multiple items at the same distance from the event. Now sort by smallest
  8952. if (nearestItems.length > 1) {
  8953. nearestItems.sort(function(a, b) {
  8954. var sizeA = a.getArea();
  8955. var sizeB = b.getArea();
  8956. var ret = sizeA - sizeB;
  8957. if (ret === 0) {
  8958. // if equal sort by dataset index
  8959. ret = a._datasetIndex - b._datasetIndex;
  8960. }
  8961. return ret;
  8962. });
  8963. }
  8964. // Return only 1 item
  8965. return nearestItems.slice(0, 1);
  8966. },
  8967. /**
  8968. * x mode returns the elements that hit-test at the current x coordinate
  8969. * @function Chart.Interaction.modes.x
  8970. * @param chart {chart} the chart we are returning items from
  8971. * @param e {Event} the event we are find things at
  8972. * @param options {IInteractionOptions} options to use
  8973. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  8974. */
  8975. x: function(chart, e, options) {
  8976. var position = getRelativePosition(e, chart);
  8977. var items = [];
  8978. var intersectsItem = false;
  8979. parseVisibleItems(chart, function(element) {
  8980. if (element.inXRange(position.x)) {
  8981. items.push(element);
  8982. }
  8983. if (element.inRange(position.x, position.y)) {
  8984. intersectsItem = true;
  8985. }
  8986. });
  8987. // If we want to trigger on an intersect and we don't have any items
  8988. // that intersect the position, return nothing
  8989. if (options.intersect && !intersectsItem) {
  8990. items = [];
  8991. }
  8992. return items;
  8993. },
  8994. /**
  8995. * y mode returns the elements that hit-test at the current y coordinate
  8996. * @function Chart.Interaction.modes.y
  8997. * @param chart {chart} the chart we are returning items from
  8998. * @param e {Event} the event we are find things at
  8999. * @param options {IInteractionOptions} options to use
  9000. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  9001. */
  9002. y: function(chart, e, options) {
  9003. var position = getRelativePosition(e, chart);
  9004. var items = [];
  9005. var intersectsItem = false;
  9006. parseVisibleItems(chart, function(element) {
  9007. if (element.inYRange(position.y)) {
  9008. items.push(element);
  9009. }
  9010. if (element.inRange(position.x, position.y)) {
  9011. intersectsItem = true;
  9012. }
  9013. });
  9014. // If we want to trigger on an intersect and we don't have any items
  9015. // that intersect the position, return nothing
  9016. if (options.intersect && !intersectsItem) {
  9017. items = [];
  9018. }
  9019. return items;
  9020. }
  9021. }
  9022. };
  9023. },{"45":45}],29:[function(require,module,exports){
  9024. 'use strict';
  9025. var defaults = require(25);
  9026. defaults._set('global', {
  9027. responsive: true,
  9028. responsiveAnimationDuration: 0,
  9029. maintainAspectRatio: true,
  9030. events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
  9031. hover: {
  9032. onHover: null,
  9033. mode: 'nearest',
  9034. intersect: true,
  9035. animationDuration: 400
  9036. },
  9037. onClick: null,
  9038. defaultColor: 'rgba(0,0,0,0.1)',
  9039. defaultFontColor: '#666',
  9040. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  9041. defaultFontSize: 12,
  9042. defaultFontStyle: 'normal',
  9043. showLines: true,
  9044. // Element defaults defined in element extensions
  9045. elements: {},
  9046. // Layout options such as padding
  9047. layout: {
  9048. padding: {
  9049. top: 0,
  9050. right: 0,
  9051. bottom: 0,
  9052. left: 0
  9053. }
  9054. }
  9055. });
  9056. module.exports = function() {
  9057. // Occupy the global variable of Chart, and create a simple base class
  9058. var Chart = function(item, config) {
  9059. this.construct(item, config);
  9060. return this;
  9061. };
  9062. Chart.Chart = Chart;
  9063. return Chart;
  9064. };
  9065. },{"25":25}],30:[function(require,module,exports){
  9066. 'use strict';
  9067. var helpers = require(45);
  9068. function filterByPosition(array, position) {
  9069. return helpers.where(array, function(v) {
  9070. return v.position === position;
  9071. });
  9072. }
  9073. function sortByWeight(array, reverse) {
  9074. array.forEach(function(v, i) {
  9075. v._tmpIndex_ = i;
  9076. return v;
  9077. });
  9078. array.sort(function(a, b) {
  9079. var v0 = reverse ? b : a;
  9080. var v1 = reverse ? a : b;
  9081. return v0.weight === v1.weight ?
  9082. v0._tmpIndex_ - v1._tmpIndex_ :
  9083. v0.weight - v1.weight;
  9084. });
  9085. array.forEach(function(v) {
  9086. delete v._tmpIndex_;
  9087. });
  9088. }
  9089. /**
  9090. * @interface ILayoutItem
  9091. * @prop {String} position - The position of the item in the chart layout. Possible values are
  9092. * 'left', 'top', 'right', 'bottom', and 'chartArea'
  9093. * @prop {Number} weight - The weight used to sort the item. Higher weights are further away from the chart area
  9094. * @prop {Boolean} fullWidth - if true, and the item is horizontal, then push vertical boxes down
  9095. * @prop {Function} isHorizontal - returns true if the layout item is horizontal (ie. top or bottom)
  9096. * @prop {Function} update - Takes two parameters: width and height. Returns size of item
  9097. * @prop {Function} getPadding - Returns an object with padding on the edges
  9098. * @prop {Number} width - Width of item. Must be valid after update()
  9099. * @prop {Number} height - Height of item. Must be valid after update()
  9100. * @prop {Number} left - Left edge of the item. Set by layout system and cannot be used in update
  9101. * @prop {Number} top - Top edge of the item. Set by layout system and cannot be used in update
  9102. * @prop {Number} right - Right edge of the item. Set by layout system and cannot be used in update
  9103. * @prop {Number} bottom - Bottom edge of the item. Set by layout system and cannot be used in update
  9104. */
  9105. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  9106. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  9107. // It is this service's responsibility of carrying out that layout.
  9108. module.exports = {
  9109. defaults: {},
  9110. /**
  9111. * Register a box to a chart.
  9112. * A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
  9113. * @param {Chart} chart - the chart to use
  9114. * @param {ILayoutItem} item - the item to add to be layed out
  9115. */
  9116. addBox: function(chart, item) {
  9117. if (!chart.boxes) {
  9118. chart.boxes = [];
  9119. }
  9120. // initialize item with default values
  9121. item.fullWidth = item.fullWidth || false;
  9122. item.position = item.position || 'top';
  9123. item.weight = item.weight || 0;
  9124. chart.boxes.push(item);
  9125. },
  9126. /**
  9127. * Remove a layoutItem from a chart
  9128. * @param {Chart} chart - the chart to remove the box from
  9129. * @param {Object} layoutItem - the item to remove from the layout
  9130. */
  9131. removeBox: function(chart, layoutItem) {
  9132. var index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
  9133. if (index !== -1) {
  9134. chart.boxes.splice(index, 1);
  9135. }
  9136. },
  9137. /**
  9138. * Sets (or updates) options on the given `item`.
  9139. * @param {Chart} chart - the chart in which the item lives (or will be added to)
  9140. * @param {Object} item - the item to configure with the given options
  9141. * @param {Object} options - the new item options.
  9142. */
  9143. configure: function(chart, item, options) {
  9144. var props = ['fullWidth', 'position', 'weight'];
  9145. var ilen = props.length;
  9146. var i = 0;
  9147. var prop;
  9148. for (; i < ilen; ++i) {
  9149. prop = props[i];
  9150. if (options.hasOwnProperty(prop)) {
  9151. item[prop] = options[prop];
  9152. }
  9153. }
  9154. },
  9155. /**
  9156. * Fits boxes of the given chart into the given size by having each box measure itself
  9157. * then running a fitting algorithm
  9158. * @param {Chart} chart - the chart
  9159. * @param {Number} width - the width to fit into
  9160. * @param {Number} height - the height to fit into
  9161. */
  9162. update: function(chart, width, height) {
  9163. if (!chart) {
  9164. return;
  9165. }
  9166. var layoutOptions = chart.options.layout || {};
  9167. var padding = helpers.options.toPadding(layoutOptions.padding);
  9168. var leftPadding = padding.left;
  9169. var rightPadding = padding.right;
  9170. var topPadding = padding.top;
  9171. var bottomPadding = padding.bottom;
  9172. var leftBoxes = filterByPosition(chart.boxes, 'left');
  9173. var rightBoxes = filterByPosition(chart.boxes, 'right');
  9174. var topBoxes = filterByPosition(chart.boxes, 'top');
  9175. var bottomBoxes = filterByPosition(chart.boxes, 'bottom');
  9176. var chartAreaBoxes = filterByPosition(chart.boxes, 'chartArea');
  9177. // Sort boxes by weight. A higher weight is further away from the chart area
  9178. sortByWeight(leftBoxes, true);
  9179. sortByWeight(rightBoxes, false);
  9180. sortByWeight(topBoxes, true);
  9181. sortByWeight(bottomBoxes, false);
  9182. // Essentially we now have any number of boxes on each of the 4 sides.
  9183. // Our canvas looks like the following.
  9184. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  9185. // B1 is the bottom axis
  9186. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  9187. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  9188. // an error will be thrown.
  9189. //
  9190. // |----------------------------------------------------|
  9191. // | T1 (Full Width) |
  9192. // |----------------------------------------------------|
  9193. // | | | T2 | |
  9194. // | |----|-------------------------------------|----|
  9195. // | | | C1 | | C2 | |
  9196. // | | |----| |----| |
  9197. // | | | | |
  9198. // | L1 | L2 | ChartArea (C0) | R1 |
  9199. // | | | | |
  9200. // | | |----| |----| |
  9201. // | | | C3 | | C4 | |
  9202. // | |----|-------------------------------------|----|
  9203. // | | | B1 | |
  9204. // |----------------------------------------------------|
  9205. // | B2 (Full Width) |
  9206. // |----------------------------------------------------|
  9207. //
  9208. // What we do to find the best sizing, we do the following
  9209. // 1. Determine the minimum size of the chart area.
  9210. // 2. Split the remaining width equally between each vertical axis
  9211. // 3. Split the remaining height equally between each horizontal axis
  9212. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  9213. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  9214. // 6. Refit each axis
  9215. // 7. Position each axis in the final location
  9216. // 8. Tell the chart the final location of the chart area
  9217. // 9. Tell any axes that overlay the chart area the positions of the chart area
  9218. // Step 1
  9219. var chartWidth = width - leftPadding - rightPadding;
  9220. var chartHeight = height - topPadding - bottomPadding;
  9221. var chartAreaWidth = chartWidth / 2; // min 50%
  9222. var chartAreaHeight = chartHeight / 2; // min 50%
  9223. // Step 2
  9224. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  9225. // Step 3
  9226. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  9227. // Step 4
  9228. var maxChartAreaWidth = chartWidth;
  9229. var maxChartAreaHeight = chartHeight;
  9230. var minBoxSizes = [];
  9231. function getMinimumBoxSize(box) {
  9232. var minSize;
  9233. var isHorizontal = box.isHorizontal();
  9234. if (isHorizontal) {
  9235. minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  9236. maxChartAreaHeight -= minSize.height;
  9237. } else {
  9238. minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
  9239. maxChartAreaWidth -= minSize.width;
  9240. }
  9241. minBoxSizes.push({
  9242. horizontal: isHorizontal,
  9243. minSize: minSize,
  9244. box: box,
  9245. });
  9246. }
  9247. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  9248. // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
  9249. var maxHorizontalLeftPadding = 0;
  9250. var maxHorizontalRightPadding = 0;
  9251. var maxVerticalTopPadding = 0;
  9252. var maxVerticalBottomPadding = 0;
  9253. helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
  9254. if (horizontalBox.getPadding) {
  9255. var boxPadding = horizontalBox.getPadding();
  9256. maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
  9257. maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
  9258. }
  9259. });
  9260. helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
  9261. if (verticalBox.getPadding) {
  9262. var boxPadding = verticalBox.getPadding();
  9263. maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
  9264. maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
  9265. }
  9266. });
  9267. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  9268. // be if the axes are drawn at their minimum sizes.
  9269. // Steps 5 & 6
  9270. var totalLeftBoxesWidth = leftPadding;
  9271. var totalRightBoxesWidth = rightPadding;
  9272. var totalTopBoxesHeight = topPadding;
  9273. var totalBottomBoxesHeight = bottomPadding;
  9274. // Function to fit a box
  9275. function fitBox(box) {
  9276. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
  9277. return minBox.box === box;
  9278. });
  9279. if (minBoxSize) {
  9280. if (box.isHorizontal()) {
  9281. var scaleMargin = {
  9282. left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
  9283. right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
  9284. top: 0,
  9285. bottom: 0
  9286. };
  9287. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  9288. // on the margin. Sometimes they need to increase in size slightly
  9289. box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  9290. } else {
  9291. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  9292. }
  9293. }
  9294. }
  9295. // Update, and calculate the left and right margins for the horizontal boxes
  9296. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  9297. helpers.each(leftBoxes, function(box) {
  9298. totalLeftBoxesWidth += box.width;
  9299. });
  9300. helpers.each(rightBoxes, function(box) {
  9301. totalRightBoxesWidth += box.width;
  9302. });
  9303. // Set the Left and Right margins for the horizontal boxes
  9304. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  9305. // Figure out how much margin is on the top and bottom of the vertical boxes
  9306. helpers.each(topBoxes, function(box) {
  9307. totalTopBoxesHeight += box.height;
  9308. });
  9309. helpers.each(bottomBoxes, function(box) {
  9310. totalBottomBoxesHeight += box.height;
  9311. });
  9312. function finalFitVerticalBox(box) {
  9313. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
  9314. return minSize.box === box;
  9315. });
  9316. var scaleMargin = {
  9317. left: 0,
  9318. right: 0,
  9319. top: totalTopBoxesHeight,
  9320. bottom: totalBottomBoxesHeight
  9321. };
  9322. if (minBoxSize) {
  9323. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  9324. }
  9325. }
  9326. // Let the left layout know the final margin
  9327. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  9328. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  9329. totalLeftBoxesWidth = leftPadding;
  9330. totalRightBoxesWidth = rightPadding;
  9331. totalTopBoxesHeight = topPadding;
  9332. totalBottomBoxesHeight = bottomPadding;
  9333. helpers.each(leftBoxes, function(box) {
  9334. totalLeftBoxesWidth += box.width;
  9335. });
  9336. helpers.each(rightBoxes, function(box) {
  9337. totalRightBoxesWidth += box.width;
  9338. });
  9339. helpers.each(topBoxes, function(box) {
  9340. totalTopBoxesHeight += box.height;
  9341. });
  9342. helpers.each(bottomBoxes, function(box) {
  9343. totalBottomBoxesHeight += box.height;
  9344. });
  9345. // We may be adding some padding to account for rotated x axis labels
  9346. var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
  9347. totalLeftBoxesWidth += leftPaddingAddition;
  9348. totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
  9349. var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
  9350. totalTopBoxesHeight += topPaddingAddition;
  9351. totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
  9352. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  9353. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  9354. // without calling `fit` again
  9355. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  9356. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  9357. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  9358. helpers.each(leftBoxes, function(box) {
  9359. box.height = newMaxChartAreaHeight;
  9360. });
  9361. helpers.each(rightBoxes, function(box) {
  9362. box.height = newMaxChartAreaHeight;
  9363. });
  9364. helpers.each(topBoxes, function(box) {
  9365. if (!box.fullWidth) {
  9366. box.width = newMaxChartAreaWidth;
  9367. }
  9368. });
  9369. helpers.each(bottomBoxes, function(box) {
  9370. if (!box.fullWidth) {
  9371. box.width = newMaxChartAreaWidth;
  9372. }
  9373. });
  9374. maxChartAreaHeight = newMaxChartAreaHeight;
  9375. maxChartAreaWidth = newMaxChartAreaWidth;
  9376. }
  9377. // Step 7 - Position the boxes
  9378. var left = leftPadding + leftPaddingAddition;
  9379. var top = topPadding + topPaddingAddition;
  9380. function placeBox(box) {
  9381. if (box.isHorizontal()) {
  9382. box.left = box.fullWidth ? leftPadding : totalLeftBoxesWidth;
  9383. box.right = box.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  9384. box.top = top;
  9385. box.bottom = top + box.height;
  9386. // Move to next point
  9387. top = box.bottom;
  9388. } else {
  9389. box.left = left;
  9390. box.right = left + box.width;
  9391. box.top = totalTopBoxesHeight;
  9392. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  9393. // Move to next point
  9394. left = box.right;
  9395. }
  9396. }
  9397. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  9398. // Account for chart width and height
  9399. left += maxChartAreaWidth;
  9400. top += maxChartAreaHeight;
  9401. helpers.each(rightBoxes, placeBox);
  9402. helpers.each(bottomBoxes, placeBox);
  9403. // Step 8
  9404. chart.chartArea = {
  9405. left: totalLeftBoxesWidth,
  9406. top: totalTopBoxesHeight,
  9407. right: totalLeftBoxesWidth + maxChartAreaWidth,
  9408. bottom: totalTopBoxesHeight + maxChartAreaHeight
  9409. };
  9410. // Step 9
  9411. helpers.each(chartAreaBoxes, function(box) {
  9412. box.left = chart.chartArea.left;
  9413. box.top = chart.chartArea.top;
  9414. box.right = chart.chartArea.right;
  9415. box.bottom = chart.chartArea.bottom;
  9416. box.update(maxChartAreaWidth, maxChartAreaHeight);
  9417. });
  9418. }
  9419. };
  9420. },{"45":45}],31:[function(require,module,exports){
  9421. 'use strict';
  9422. var defaults = require(25);
  9423. var helpers = require(45);
  9424. defaults._set('global', {
  9425. plugins: {}
  9426. });
  9427. /**
  9428. * The plugin service singleton
  9429. * @namespace Chart.plugins
  9430. * @since 2.1.0
  9431. */
  9432. module.exports = {
  9433. /**
  9434. * Globally registered plugins.
  9435. * @private
  9436. */
  9437. _plugins: [],
  9438. /**
  9439. * This identifier is used to invalidate the descriptors cache attached to each chart
  9440. * when a global plugin is registered or unregistered. In this case, the cache ID is
  9441. * incremented and descriptors are regenerated during following API calls.
  9442. * @private
  9443. */
  9444. _cacheId: 0,
  9445. /**
  9446. * Registers the given plugin(s) if not already registered.
  9447. * @param {Array|Object} plugins plugin instance(s).
  9448. */
  9449. register: function(plugins) {
  9450. var p = this._plugins;
  9451. ([]).concat(plugins).forEach(function(plugin) {
  9452. if (p.indexOf(plugin) === -1) {
  9453. p.push(plugin);
  9454. }
  9455. });
  9456. this._cacheId++;
  9457. },
  9458. /**
  9459. * Unregisters the given plugin(s) only if registered.
  9460. * @param {Array|Object} plugins plugin instance(s).
  9461. */
  9462. unregister: function(plugins) {
  9463. var p = this._plugins;
  9464. ([]).concat(plugins).forEach(function(plugin) {
  9465. var idx = p.indexOf(plugin);
  9466. if (idx !== -1) {
  9467. p.splice(idx, 1);
  9468. }
  9469. });
  9470. this._cacheId++;
  9471. },
  9472. /**
  9473. * Remove all registered plugins.
  9474. * @since 2.1.5
  9475. */
  9476. clear: function() {
  9477. this._plugins = [];
  9478. this._cacheId++;
  9479. },
  9480. /**
  9481. * Returns the number of registered plugins?
  9482. * @returns {Number}
  9483. * @since 2.1.5
  9484. */
  9485. count: function() {
  9486. return this._plugins.length;
  9487. },
  9488. /**
  9489. * Returns all registered plugin instances.
  9490. * @returns {Array} array of plugin objects.
  9491. * @since 2.1.5
  9492. */
  9493. getAll: function() {
  9494. return this._plugins;
  9495. },
  9496. /**
  9497. * Calls enabled plugins for `chart` on the specified hook and with the given args.
  9498. * This method immediately returns as soon as a plugin explicitly returns false. The
  9499. * returned value can be used, for instance, to interrupt the current action.
  9500. * @param {Object} chart - The chart instance for which plugins should be called.
  9501. * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
  9502. * @param {Array} [args] - Extra arguments to apply to the hook call.
  9503. * @returns {Boolean} false if any of the plugins return false, else returns true.
  9504. */
  9505. notify: function(chart, hook, args) {
  9506. var descriptors = this.descriptors(chart);
  9507. var ilen = descriptors.length;
  9508. var i, descriptor, plugin, params, method;
  9509. for (i = 0; i < ilen; ++i) {
  9510. descriptor = descriptors[i];
  9511. plugin = descriptor.plugin;
  9512. method = plugin[hook];
  9513. if (typeof method === 'function') {
  9514. params = [chart].concat(args || []);
  9515. params.push(descriptor.options);
  9516. if (method.apply(plugin, params) === false) {
  9517. return false;
  9518. }
  9519. }
  9520. }
  9521. return true;
  9522. },
  9523. /**
  9524. * Returns descriptors of enabled plugins for the given chart.
  9525. * @returns {Array} [{ plugin, options }]
  9526. * @private
  9527. */
  9528. descriptors: function(chart) {
  9529. var cache = chart.$plugins || (chart.$plugins = {});
  9530. if (cache.id === this._cacheId) {
  9531. return cache.descriptors;
  9532. }
  9533. var plugins = [];
  9534. var descriptors = [];
  9535. var config = (chart && chart.config) || {};
  9536. var options = (config.options && config.options.plugins) || {};
  9537. this._plugins.concat(config.plugins || []).forEach(function(plugin) {
  9538. var idx = plugins.indexOf(plugin);
  9539. if (idx !== -1) {
  9540. return;
  9541. }
  9542. var id = plugin.id;
  9543. var opts = options[id];
  9544. if (opts === false) {
  9545. return;
  9546. }
  9547. if (opts === true) {
  9548. opts = helpers.clone(defaults.global.plugins[id]);
  9549. }
  9550. plugins.push(plugin);
  9551. descriptors.push({
  9552. plugin: plugin,
  9553. options: opts || {}
  9554. });
  9555. });
  9556. cache.descriptors = descriptors;
  9557. cache.id = this._cacheId;
  9558. return descriptors;
  9559. },
  9560. /**
  9561. * Invalidates cache for the given chart: descriptors hold a reference on plugin option,
  9562. * but in some cases, this reference can be changed by the user when updating options.
  9563. * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  9564. * @private
  9565. */
  9566. _invalidate: function(chart) {
  9567. delete chart.$plugins;
  9568. }
  9569. };
  9570. /**
  9571. * Plugin extension hooks.
  9572. * @interface IPlugin
  9573. * @since 2.1.0
  9574. */
  9575. /**
  9576. * @method IPlugin#beforeInit
  9577. * @desc Called before initializing `chart`.
  9578. * @param {Chart.Controller} chart - The chart instance.
  9579. * @param {Object} options - The plugin options.
  9580. */
  9581. /**
  9582. * @method IPlugin#afterInit
  9583. * @desc Called after `chart` has been initialized and before the first update.
  9584. * @param {Chart.Controller} chart - The chart instance.
  9585. * @param {Object} options - The plugin options.
  9586. */
  9587. /**
  9588. * @method IPlugin#beforeUpdate
  9589. * @desc Called before updating `chart`. If any plugin returns `false`, the update
  9590. * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
  9591. * @param {Chart.Controller} chart - The chart instance.
  9592. * @param {Object} options - The plugin options.
  9593. * @returns {Boolean} `false` to cancel the chart update.
  9594. */
  9595. /**
  9596. * @method IPlugin#afterUpdate
  9597. * @desc Called after `chart` has been updated and before rendering. Note that this
  9598. * hook will not be called if the chart update has been previously cancelled.
  9599. * @param {Chart.Controller} chart - The chart instance.
  9600. * @param {Object} options - The plugin options.
  9601. */
  9602. /**
  9603. * @method IPlugin#beforeDatasetsUpdate
  9604. * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  9605. * the datasets update is cancelled until another `update` is triggered.
  9606. * @param {Chart.Controller} chart - The chart instance.
  9607. * @param {Object} options - The plugin options.
  9608. * @returns {Boolean} false to cancel the datasets update.
  9609. * @since version 2.1.5
  9610. */
  9611. /**
  9612. * @method IPlugin#afterDatasetsUpdate
  9613. * @desc Called after the `chart` datasets have been updated. Note that this hook
  9614. * will not be called if the datasets update has been previously cancelled.
  9615. * @param {Chart.Controller} chart - The chart instance.
  9616. * @param {Object} options - The plugin options.
  9617. * @since version 2.1.5
  9618. */
  9619. /**
  9620. * @method IPlugin#beforeDatasetUpdate
  9621. * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
  9622. * returns `false`, the datasets update is cancelled until another `update` is triggered.
  9623. * @param {Chart} chart - The chart instance.
  9624. * @param {Object} args - The call arguments.
  9625. * @param {Number} args.index - The dataset index.
  9626. * @param {Object} args.meta - The dataset metadata.
  9627. * @param {Object} options - The plugin options.
  9628. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  9629. */
  9630. /**
  9631. * @method IPlugin#afterDatasetUpdate
  9632. * @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
  9633. * that this hook will not be called if the datasets update has been previously cancelled.
  9634. * @param {Chart} chart - The chart instance.
  9635. * @param {Object} args - The call arguments.
  9636. * @param {Number} args.index - The dataset index.
  9637. * @param {Object} args.meta - The dataset metadata.
  9638. * @param {Object} options - The plugin options.
  9639. */
  9640. /**
  9641. * @method IPlugin#beforeLayout
  9642. * @desc Called before laying out `chart`. If any plugin returns `false`,
  9643. * the layout update is cancelled until another `update` is triggered.
  9644. * @param {Chart.Controller} chart - The chart instance.
  9645. * @param {Object} options - The plugin options.
  9646. * @returns {Boolean} `false` to cancel the chart layout.
  9647. */
  9648. /**
  9649. * @method IPlugin#afterLayout
  9650. * @desc Called after the `chart` has been layed out. Note that this hook will not
  9651. * be called if the layout update has been previously cancelled.
  9652. * @param {Chart.Controller} chart - The chart instance.
  9653. * @param {Object} options - The plugin options.
  9654. */
  9655. /**
  9656. * @method IPlugin#beforeRender
  9657. * @desc Called before rendering `chart`. If any plugin returns `false`,
  9658. * the rendering is cancelled until another `render` is triggered.
  9659. * @param {Chart.Controller} chart - The chart instance.
  9660. * @param {Object} options - The plugin options.
  9661. * @returns {Boolean} `false` to cancel the chart rendering.
  9662. */
  9663. /**
  9664. * @method IPlugin#afterRender
  9665. * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  9666. * that this hook will not be called if the rendering has been previously cancelled.
  9667. * @param {Chart.Controller} chart - The chart instance.
  9668. * @param {Object} options - The plugin options.
  9669. */
  9670. /**
  9671. * @method IPlugin#beforeDraw
  9672. * @desc Called before drawing `chart` at every animation frame specified by the given
  9673. * easing value. If any plugin returns `false`, the frame drawing is cancelled until
  9674. * another `render` is triggered.
  9675. * @param {Chart.Controller} chart - The chart instance.
  9676. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  9677. * @param {Object} options - The plugin options.
  9678. * @returns {Boolean} `false` to cancel the chart drawing.
  9679. */
  9680. /**
  9681. * @method IPlugin#afterDraw
  9682. * @desc Called after the `chart` has been drawn for the specific easing value. Note
  9683. * that this hook will not be called if the drawing has been previously cancelled.
  9684. * @param {Chart.Controller} chart - The chart instance.
  9685. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  9686. * @param {Object} options - The plugin options.
  9687. */
  9688. /**
  9689. * @method IPlugin#beforeDatasetsDraw
  9690. * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  9691. * the datasets drawing is cancelled until another `render` is triggered.
  9692. * @param {Chart.Controller} chart - The chart instance.
  9693. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  9694. * @param {Object} options - The plugin options.
  9695. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  9696. */
  9697. /**
  9698. * @method IPlugin#afterDatasetsDraw
  9699. * @desc Called after the `chart` datasets have been drawn. Note that this hook
  9700. * will not be called if the datasets drawing has been previously cancelled.
  9701. * @param {Chart.Controller} chart - The chart instance.
  9702. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  9703. * @param {Object} options - The plugin options.
  9704. */
  9705. /**
  9706. * @method IPlugin#beforeDatasetDraw
  9707. * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
  9708. * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
  9709. * is cancelled until another `render` is triggered.
  9710. * @param {Chart} chart - The chart instance.
  9711. * @param {Object} args - The call arguments.
  9712. * @param {Number} args.index - The dataset index.
  9713. * @param {Object} args.meta - The dataset metadata.
  9714. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  9715. * @param {Object} options - The plugin options.
  9716. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  9717. */
  9718. /**
  9719. * @method IPlugin#afterDatasetDraw
  9720. * @desc Called after the `chart` datasets at the given `args.index` have been drawn
  9721. * (datasets are drawn in the reverse order). Note that this hook will not be called
  9722. * if the datasets drawing has been previously cancelled.
  9723. * @param {Chart} chart - The chart instance.
  9724. * @param {Object} args - The call arguments.
  9725. * @param {Number} args.index - The dataset index.
  9726. * @param {Object} args.meta - The dataset metadata.
  9727. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  9728. * @param {Object} options - The plugin options.
  9729. */
  9730. /**
  9731. * @method IPlugin#beforeTooltipDraw
  9732. * @desc Called before drawing the `tooltip`. If any plugin returns `false`,
  9733. * the tooltip drawing is cancelled until another `render` is triggered.
  9734. * @param {Chart} chart - The chart instance.
  9735. * @param {Object} args - The call arguments.
  9736. * @param {Object} args.tooltip - The tooltip.
  9737. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  9738. * @param {Object} options - The plugin options.
  9739. * @returns {Boolean} `false` to cancel the chart tooltip drawing.
  9740. */
  9741. /**
  9742. * @method IPlugin#afterTooltipDraw
  9743. * @desc Called after drawing the `tooltip`. Note that this hook will not
  9744. * be called if the tooltip drawing has been previously cancelled.
  9745. * @param {Chart} chart - The chart instance.
  9746. * @param {Object} args - The call arguments.
  9747. * @param {Object} args.tooltip - The tooltip.
  9748. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  9749. * @param {Object} options - The plugin options.
  9750. */
  9751. /**
  9752. * @method IPlugin#beforeEvent
  9753. * @desc Called before processing the specified `event`. If any plugin returns `false`,
  9754. * the event will be discarded.
  9755. * @param {Chart.Controller} chart - The chart instance.
  9756. * @param {IEvent} event - The event object.
  9757. * @param {Object} options - The plugin options.
  9758. */
  9759. /**
  9760. * @method IPlugin#afterEvent
  9761. * @desc Called after the `event` has been consumed. Note that this hook
  9762. * will not be called if the `event` has been previously discarded.
  9763. * @param {Chart.Controller} chart - The chart instance.
  9764. * @param {IEvent} event - The event object.
  9765. * @param {Object} options - The plugin options.
  9766. */
  9767. /**
  9768. * @method IPlugin#resize
  9769. * @desc Called after the chart as been resized.
  9770. * @param {Chart.Controller} chart - The chart instance.
  9771. * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
  9772. * @param {Object} options - The plugin options.
  9773. */
  9774. /**
  9775. * @method IPlugin#destroy
  9776. * @desc Called after the chart as been destroyed.
  9777. * @param {Chart.Controller} chart - The chart instance.
  9778. * @param {Object} options - The plugin options.
  9779. */
  9780. },{"25":25,"45":45}],32:[function(require,module,exports){
  9781. 'use strict';
  9782. var defaults = require(25);
  9783. var Element = require(26);
  9784. var helpers = require(45);
  9785. var Ticks = require(34);
  9786. defaults._set('scale', {
  9787. display: true,
  9788. position: 'left',
  9789. offset: false,
  9790. // grid line settings
  9791. gridLines: {
  9792. display: true,
  9793. color: 'rgba(0, 0, 0, 0.1)',
  9794. lineWidth: 1,
  9795. drawBorder: true,
  9796. drawOnChartArea: true,
  9797. drawTicks: true,
  9798. tickMarkLength: 10,
  9799. zeroLineWidth: 1,
  9800. zeroLineColor: 'rgba(0,0,0,0.25)',
  9801. zeroLineBorderDash: [],
  9802. zeroLineBorderDashOffset: 0.0,
  9803. offsetGridLines: false,
  9804. borderDash: [],
  9805. borderDashOffset: 0.0
  9806. },
  9807. // scale label
  9808. scaleLabel: {
  9809. // display property
  9810. display: false,
  9811. // actual label
  9812. labelString: '',
  9813. // line height
  9814. lineHeight: 1.2,
  9815. // top/bottom padding
  9816. padding: {
  9817. top: 4,
  9818. bottom: 4
  9819. }
  9820. },
  9821. // label settings
  9822. ticks: {
  9823. beginAtZero: false,
  9824. minRotation: 0,
  9825. maxRotation: 50,
  9826. mirror: false,
  9827. padding: 0,
  9828. reverse: false,
  9829. display: true,
  9830. autoSkip: true,
  9831. autoSkipPadding: 0,
  9832. labelOffset: 0,
  9833. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  9834. callback: Ticks.formatters.values,
  9835. minor: {},
  9836. major: {}
  9837. }
  9838. });
  9839. function labelsFromTicks(ticks) {
  9840. var labels = [];
  9841. var i, ilen;
  9842. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  9843. labels.push(ticks[i].label);
  9844. }
  9845. return labels;
  9846. }
  9847. function getLineValue(scale, index, offsetGridLines) {
  9848. var lineValue = scale.getPixelForTick(index);
  9849. if (offsetGridLines) {
  9850. if (index === 0) {
  9851. lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
  9852. } else {
  9853. lineValue -= (lineValue - scale.getPixelForTick(index - 1)) / 2;
  9854. }
  9855. }
  9856. return lineValue;
  9857. }
  9858. module.exports = function(Chart) {
  9859. function computeTextSize(context, tick, font) {
  9860. return helpers.isArray(tick) ?
  9861. helpers.longestText(context, font, tick) :
  9862. context.measureText(tick).width;
  9863. }
  9864. function parseFontOptions(options) {
  9865. var valueOrDefault = helpers.valueOrDefault;
  9866. var globalDefaults = defaults.global;
  9867. var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
  9868. var style = valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
  9869. var family = valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
  9870. return {
  9871. size: size,
  9872. style: style,
  9873. family: family,
  9874. font: helpers.fontString(size, style, family)
  9875. };
  9876. }
  9877. function parseLineHeight(options) {
  9878. return helpers.options.toLineHeight(
  9879. helpers.valueOrDefault(options.lineHeight, 1.2),
  9880. helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
  9881. }
  9882. Chart.Scale = Element.extend({
  9883. /**
  9884. * Get the padding needed for the scale
  9885. * @method getPadding
  9886. * @private
  9887. * @returns {Padding} the necessary padding
  9888. */
  9889. getPadding: function() {
  9890. var me = this;
  9891. return {
  9892. left: me.paddingLeft || 0,
  9893. top: me.paddingTop || 0,
  9894. right: me.paddingRight || 0,
  9895. bottom: me.paddingBottom || 0
  9896. };
  9897. },
  9898. /**
  9899. * Returns the scale tick objects ({label, major})
  9900. * @since 2.7
  9901. */
  9902. getTicks: function() {
  9903. return this._ticks;
  9904. },
  9905. // These methods are ordered by lifecyle. Utilities then follow.
  9906. // Any function defined here is inherited by all scale types.
  9907. // Any function can be extended by the scale type
  9908. mergeTicksOptions: function() {
  9909. var ticks = this.options.ticks;
  9910. if (ticks.minor === false) {
  9911. ticks.minor = {
  9912. display: false
  9913. };
  9914. }
  9915. if (ticks.major === false) {
  9916. ticks.major = {
  9917. display: false
  9918. };
  9919. }
  9920. for (var key in ticks) {
  9921. if (key !== 'major' && key !== 'minor') {
  9922. if (typeof ticks.minor[key] === 'undefined') {
  9923. ticks.minor[key] = ticks[key];
  9924. }
  9925. if (typeof ticks.major[key] === 'undefined') {
  9926. ticks.major[key] = ticks[key];
  9927. }
  9928. }
  9929. }
  9930. },
  9931. beforeUpdate: function() {
  9932. helpers.callback(this.options.beforeUpdate, [this]);
  9933. },
  9934. update: function(maxWidth, maxHeight, margins) {
  9935. var me = this;
  9936. var i, ilen, labels, label, ticks, tick;
  9937. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  9938. me.beforeUpdate();
  9939. // Absorb the master measurements
  9940. me.maxWidth = maxWidth;
  9941. me.maxHeight = maxHeight;
  9942. me.margins = helpers.extend({
  9943. left: 0,
  9944. right: 0,
  9945. top: 0,
  9946. bottom: 0
  9947. }, margins);
  9948. me.longestTextCache = me.longestTextCache || {};
  9949. // Dimensions
  9950. me.beforeSetDimensions();
  9951. me.setDimensions();
  9952. me.afterSetDimensions();
  9953. // Data min/max
  9954. me.beforeDataLimits();
  9955. me.determineDataLimits();
  9956. me.afterDataLimits();
  9957. // Ticks - `this.ticks` is now DEPRECATED!
  9958. // Internal ticks are now stored as objects in the PRIVATE `this._ticks` member
  9959. // and must not be accessed directly from outside this class. `this.ticks` being
  9960. // around for long time and not marked as private, we can't change its structure
  9961. // without unexpected breaking changes. If you need to access the scale ticks,
  9962. // use scale.getTicks() instead.
  9963. me.beforeBuildTicks();
  9964. // New implementations should return an array of objects but for BACKWARD COMPAT,
  9965. // we still support no return (`this.ticks` internally set by calling this method).
  9966. ticks = me.buildTicks() || [];
  9967. me.afterBuildTicks();
  9968. me.beforeTickToLabelConversion();
  9969. // New implementations should return the formatted tick labels but for BACKWARD
  9970. // COMPAT, we still support no return (`this.ticks` internally changed by calling
  9971. // this method and supposed to contain only string values).
  9972. labels = me.convertTicksToLabels(ticks) || me.ticks;
  9973. me.afterTickToLabelConversion();
  9974. me.ticks = labels; // BACKWARD COMPATIBILITY
  9975. // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
  9976. // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
  9977. for (i = 0, ilen = labels.length; i < ilen; ++i) {
  9978. label = labels[i];
  9979. tick = ticks[i];
  9980. if (!tick) {
  9981. ticks.push(tick = {
  9982. label: label,
  9983. major: false
  9984. });
  9985. } else {
  9986. tick.label = label;
  9987. }
  9988. }
  9989. me._ticks = ticks;
  9990. // Tick Rotation
  9991. me.beforeCalculateTickRotation();
  9992. me.calculateTickRotation();
  9993. me.afterCalculateTickRotation();
  9994. // Fit
  9995. me.beforeFit();
  9996. me.fit();
  9997. me.afterFit();
  9998. //
  9999. me.afterUpdate();
  10000. return me.minSize;
  10001. },
  10002. afterUpdate: function() {
  10003. helpers.callback(this.options.afterUpdate, [this]);
  10004. },
  10005. //
  10006. beforeSetDimensions: function() {
  10007. helpers.callback(this.options.beforeSetDimensions, [this]);
  10008. },
  10009. setDimensions: function() {
  10010. var me = this;
  10011. // Set the unconstrained dimension before label rotation
  10012. if (me.isHorizontal()) {
  10013. // Reset position before calculating rotation
  10014. me.width = me.maxWidth;
  10015. me.left = 0;
  10016. me.right = me.width;
  10017. } else {
  10018. me.height = me.maxHeight;
  10019. // Reset position before calculating rotation
  10020. me.top = 0;
  10021. me.bottom = me.height;
  10022. }
  10023. // Reset padding
  10024. me.paddingLeft = 0;
  10025. me.paddingTop = 0;
  10026. me.paddingRight = 0;
  10027. me.paddingBottom = 0;
  10028. },
  10029. afterSetDimensions: function() {
  10030. helpers.callback(this.options.afterSetDimensions, [this]);
  10031. },
  10032. // Data limits
  10033. beforeDataLimits: function() {
  10034. helpers.callback(this.options.beforeDataLimits, [this]);
  10035. },
  10036. determineDataLimits: helpers.noop,
  10037. afterDataLimits: function() {
  10038. helpers.callback(this.options.afterDataLimits, [this]);
  10039. },
  10040. //
  10041. beforeBuildTicks: function() {
  10042. helpers.callback(this.options.beforeBuildTicks, [this]);
  10043. },
  10044. buildTicks: helpers.noop,
  10045. afterBuildTicks: function() {
  10046. helpers.callback(this.options.afterBuildTicks, [this]);
  10047. },
  10048. beforeTickToLabelConversion: function() {
  10049. helpers.callback(this.options.beforeTickToLabelConversion, [this]);
  10050. },
  10051. convertTicksToLabels: function() {
  10052. var me = this;
  10053. // Convert ticks to strings
  10054. var tickOpts = me.options.ticks;
  10055. me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback, this);
  10056. },
  10057. afterTickToLabelConversion: function() {
  10058. helpers.callback(this.options.afterTickToLabelConversion, [this]);
  10059. },
  10060. //
  10061. beforeCalculateTickRotation: function() {
  10062. helpers.callback(this.options.beforeCalculateTickRotation, [this]);
  10063. },
  10064. calculateTickRotation: function() {
  10065. var me = this;
  10066. var context = me.ctx;
  10067. var tickOpts = me.options.ticks;
  10068. var labels = labelsFromTicks(me._ticks);
  10069. // Get the width of each grid by calculating the difference
  10070. // between x offsets between 0 and 1.
  10071. var tickFont = parseFontOptions(tickOpts);
  10072. context.font = tickFont.font;
  10073. var labelRotation = tickOpts.minRotation || 0;
  10074. if (labels.length && me.options.display && me.isHorizontal()) {
  10075. var originalLabelWidth = helpers.longestText(context, tickFont.font, labels, me.longestTextCache);
  10076. var labelWidth = originalLabelWidth;
  10077. var cosRotation, sinRotation;
  10078. // Allow 3 pixels x2 padding either side for label readability
  10079. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  10080. // Max label rotation can be set or default to 90 - also act as a loop counter
  10081. while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
  10082. var angleRadians = helpers.toRadians(labelRotation);
  10083. cosRotation = Math.cos(angleRadians);
  10084. sinRotation = Math.sin(angleRadians);
  10085. if (sinRotation * originalLabelWidth > me.maxHeight) {
  10086. // go back one step
  10087. labelRotation--;
  10088. break;
  10089. }
  10090. labelRotation++;
  10091. labelWidth = cosRotation * originalLabelWidth;
  10092. }
  10093. }
  10094. me.labelRotation = labelRotation;
  10095. },
  10096. afterCalculateTickRotation: function() {
  10097. helpers.callback(this.options.afterCalculateTickRotation, [this]);
  10098. },
  10099. //
  10100. beforeFit: function() {
  10101. helpers.callback(this.options.beforeFit, [this]);
  10102. },
  10103. fit: function() {
  10104. var me = this;
  10105. // Reset
  10106. var minSize = me.minSize = {
  10107. width: 0,
  10108. height: 0
  10109. };
  10110. var labels = labelsFromTicks(me._ticks);
  10111. var opts = me.options;
  10112. var tickOpts = opts.ticks;
  10113. var scaleLabelOpts = opts.scaleLabel;
  10114. var gridLineOpts = opts.gridLines;
  10115. var display = opts.display;
  10116. var isHorizontal = me.isHorizontal();
  10117. var tickFont = parseFontOptions(tickOpts);
  10118. var tickMarkLength = opts.gridLines.tickMarkLength;
  10119. // Width
  10120. if (isHorizontal) {
  10121. // subtract the margins to line up with the chartArea if we are a full width scale
  10122. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  10123. } else {
  10124. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  10125. }
  10126. // height
  10127. if (isHorizontal) {
  10128. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  10129. } else {
  10130. minSize.height = me.maxHeight; // fill all the height
  10131. }
  10132. // Are we showing a title for the scale?
  10133. if (scaleLabelOpts.display && display) {
  10134. var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
  10135. var scaleLabelPadding = helpers.options.toPadding(scaleLabelOpts.padding);
  10136. var deltaHeight = scaleLabelLineHeight + scaleLabelPadding.height;
  10137. if (isHorizontal) {
  10138. minSize.height += deltaHeight;
  10139. } else {
  10140. minSize.width += deltaHeight;
  10141. }
  10142. }
  10143. // Don't bother fitting the ticks if we are not showing them
  10144. if (tickOpts.display && display) {
  10145. var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, labels, me.longestTextCache);
  10146. var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
  10147. var lineSpace = tickFont.size * 0.5;
  10148. var tickPadding = me.options.ticks.padding;
  10149. if (isHorizontal) {
  10150. // A horizontal axis is more constrained by the height.
  10151. me.longestLabelWidth = largestTextWidth;
  10152. var angleRadians = helpers.toRadians(me.labelRotation);
  10153. var cosRotation = Math.cos(angleRadians);
  10154. var sinRotation = Math.sin(angleRadians);
  10155. // TODO - improve this calculation
  10156. var labelHeight = (sinRotation * largestTextWidth)
  10157. + (tickFont.size * tallestLabelHeightInLines)
  10158. + (lineSpace * (tallestLabelHeightInLines - 1))
  10159. + lineSpace; // padding
  10160. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);
  10161. me.ctx.font = tickFont.font;
  10162. var firstLabelWidth = computeTextSize(me.ctx, labels[0], tickFont.font);
  10163. var lastLabelWidth = computeTextSize(me.ctx, labels[labels.length - 1], tickFont.font);
  10164. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
  10165. // which means that the right padding is dominated by the font height
  10166. if (me.labelRotation !== 0) {
  10167. me.paddingLeft = opts.position === 'bottom' ? (cosRotation * firstLabelWidth) + 3 : (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
  10168. me.paddingRight = opts.position === 'bottom' ? (cosRotation * lineSpace) + 3 : (cosRotation * lastLabelWidth) + 3;
  10169. } else {
  10170. me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  10171. me.paddingRight = lastLabelWidth / 2 + 3;
  10172. }
  10173. } else {
  10174. // A vertical axis is more constrained by the width. Labels are the
  10175. // dominant factor here, so get that length first and account for padding
  10176. if (tickOpts.mirror) {
  10177. largestTextWidth = 0;
  10178. } else {
  10179. // use lineSpace for consistency with horizontal axis
  10180. // tickPadding is not implemented for horizontal
  10181. largestTextWidth += tickPadding + lineSpace;
  10182. }
  10183. minSize.width = Math.min(me.maxWidth, minSize.width + largestTextWidth);
  10184. me.paddingTop = tickFont.size / 2;
  10185. me.paddingBottom = tickFont.size / 2;
  10186. }
  10187. }
  10188. me.handleMargins();
  10189. me.width = minSize.width;
  10190. me.height = minSize.height;
  10191. },
  10192. /**
  10193. * Handle margins and padding interactions
  10194. * @private
  10195. */
  10196. handleMargins: function() {
  10197. var me = this;
  10198. if (me.margins) {
  10199. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  10200. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  10201. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  10202. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  10203. }
  10204. },
  10205. afterFit: function() {
  10206. helpers.callback(this.options.afterFit, [this]);
  10207. },
  10208. // Shared Methods
  10209. isHorizontal: function() {
  10210. return this.options.position === 'top' || this.options.position === 'bottom';
  10211. },
  10212. isFullWidth: function() {
  10213. return (this.options.fullWidth);
  10214. },
  10215. // 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
  10216. getRightValue: function(rawValue) {
  10217. // Null and undefined values first
  10218. if (helpers.isNullOrUndef(rawValue)) {
  10219. return NaN;
  10220. }
  10221. // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
  10222. if (typeof rawValue === 'number' && !isFinite(rawValue)) {
  10223. return NaN;
  10224. }
  10225. // If it is in fact an object, dive in one more level
  10226. if (rawValue) {
  10227. if (this.isHorizontal()) {
  10228. if (rawValue.x !== undefined) {
  10229. return this.getRightValue(rawValue.x);
  10230. }
  10231. } else if (rawValue.y !== undefined) {
  10232. return this.getRightValue(rawValue.y);
  10233. }
  10234. }
  10235. // Value is good, return it
  10236. return rawValue;
  10237. },
  10238. /**
  10239. * Used to get the value to display in the tooltip for the data at the given index
  10240. * @param index
  10241. * @param datasetIndex
  10242. */
  10243. getLabelForIndex: helpers.noop,
  10244. /**
  10245. * Returns the location of the given data point. Value can either be an index or a numerical value
  10246. * The coordinate (0, 0) is at the upper-left corner of the canvas
  10247. * @param value
  10248. * @param index
  10249. * @param datasetIndex
  10250. */
  10251. getPixelForValue: helpers.noop,
  10252. /**
  10253. * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  10254. * The coordinate (0, 0) is at the upper-left corner of the canvas
  10255. * @param pixel
  10256. */
  10257. getValueForPixel: helpers.noop,
  10258. /**
  10259. * Returns the location of the tick at the given index
  10260. * The coordinate (0, 0) is at the upper-left corner of the canvas
  10261. */
  10262. getPixelForTick: function(index) {
  10263. var me = this;
  10264. var offset = me.options.offset;
  10265. if (me.isHorizontal()) {
  10266. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  10267. var tickWidth = innerWidth / Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  10268. var pixel = (tickWidth * index) + me.paddingLeft;
  10269. if (offset) {
  10270. pixel += tickWidth / 2;
  10271. }
  10272. var finalVal = me.left + Math.round(pixel);
  10273. finalVal += me.isFullWidth() ? me.margins.left : 0;
  10274. return finalVal;
  10275. }
  10276. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  10277. return me.top + (index * (innerHeight / (me._ticks.length - 1)));
  10278. },
  10279. /**
  10280. * Utility for getting the pixel location of a percentage of scale
  10281. * The coordinate (0, 0) is at the upper-left corner of the canvas
  10282. */
  10283. getPixelForDecimal: function(decimal) {
  10284. var me = this;
  10285. if (me.isHorizontal()) {
  10286. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  10287. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  10288. var finalVal = me.left + Math.round(valueOffset);
  10289. finalVal += me.isFullWidth() ? me.margins.left : 0;
  10290. return finalVal;
  10291. }
  10292. return me.top + (decimal * me.height);
  10293. },
  10294. /**
  10295. * Returns the pixel for the minimum chart value
  10296. * The coordinate (0, 0) is at the upper-left corner of the canvas
  10297. */
  10298. getBasePixel: function() {
  10299. return this.getPixelForValue(this.getBaseValue());
  10300. },
  10301. getBaseValue: function() {
  10302. var me = this;
  10303. var min = me.min;
  10304. var max = me.max;
  10305. return me.beginAtZero ? 0 :
  10306. min < 0 && max < 0 ? max :
  10307. min > 0 && max > 0 ? min :
  10308. 0;
  10309. },
  10310. /**
  10311. * Returns a subset of ticks to be plotted to avoid overlapping labels.
  10312. * @private
  10313. */
  10314. _autoSkip: function(ticks) {
  10315. var skipRatio;
  10316. var me = this;
  10317. var isHorizontal = me.isHorizontal();
  10318. var optionTicks = me.options.ticks.minor;
  10319. var tickCount = ticks.length;
  10320. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  10321. var cosRotation = Math.cos(labelRotationRadians);
  10322. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  10323. var result = [];
  10324. var i, tick, shouldSkip;
  10325. // figure out the maximum number of gridlines to show
  10326. var maxTicks;
  10327. if (optionTicks.maxTicksLimit) {
  10328. maxTicks = optionTicks.maxTicksLimit;
  10329. }
  10330. if (isHorizontal) {
  10331. skipRatio = false;
  10332. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount > (me.width - (me.paddingLeft + me.paddingRight))) {
  10333. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount) / (me.width - (me.paddingLeft + me.paddingRight)));
  10334. }
  10335. // if they defined a max number of optionTicks,
  10336. // increase skipRatio until that number is met
  10337. if (maxTicks && tickCount > maxTicks) {
  10338. skipRatio = Math.max(skipRatio, Math.floor(tickCount / maxTicks));
  10339. }
  10340. }
  10341. for (i = 0; i < tickCount; i++) {
  10342. tick = ticks[i];
  10343. // Since we always show the last tick,we need may need to hide the last shown one before
  10344. shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
  10345. if (shouldSkip && i !== tickCount - 1) {
  10346. // leave tick in place but make sure it's not displayed (#4635)
  10347. delete tick.label;
  10348. }
  10349. result.push(tick);
  10350. }
  10351. return result;
  10352. },
  10353. // Actually draw the scale on the canvas
  10354. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  10355. draw: function(chartArea) {
  10356. var me = this;
  10357. var options = me.options;
  10358. if (!options.display) {
  10359. return;
  10360. }
  10361. var context = me.ctx;
  10362. var globalDefaults = defaults.global;
  10363. var optionTicks = options.ticks.minor;
  10364. var optionMajorTicks = options.ticks.major || optionTicks;
  10365. var gridLines = options.gridLines;
  10366. var scaleLabel = options.scaleLabel;
  10367. var isRotated = me.labelRotation !== 0;
  10368. var isHorizontal = me.isHorizontal();
  10369. var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
  10370. var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  10371. var tickFont = parseFontOptions(optionTicks);
  10372. var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, globalDefaults.defaultFontColor);
  10373. var majorTickFont = parseFontOptions(optionMajorTicks);
  10374. var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
  10375. var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  10376. var scaleLabelFont = parseFontOptions(scaleLabel);
  10377. var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
  10378. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  10379. var itemsToDraw = [];
  10380. var axisWidth = me.options.gridLines.lineWidth;
  10381. var xTickStart = options.position === 'right' ? me.right : me.right - axisWidth - tl;
  10382. var xTickEnd = options.position === 'right' ? me.right + tl : me.right;
  10383. var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
  10384. var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
  10385. helpers.each(ticks, function(tick, index) {
  10386. // autoskipper skipped this tick (#4635)
  10387. if (helpers.isNullOrUndef(tick.label)) {
  10388. return;
  10389. }
  10390. var label = tick.label;
  10391. var lineWidth, lineColor, borderDash, borderDashOffset;
  10392. if (index === me.zeroLineIndex && options.offset === gridLines.offsetGridLines) {
  10393. // Draw the first index specially
  10394. lineWidth = gridLines.zeroLineWidth;
  10395. lineColor = gridLines.zeroLineColor;
  10396. borderDash = gridLines.zeroLineBorderDash;
  10397. borderDashOffset = gridLines.zeroLineBorderDashOffset;
  10398. } else {
  10399. lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
  10400. lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
  10401. borderDash = helpers.valueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  10402. borderDashOffset = helpers.valueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  10403. }
  10404. // Common properties
  10405. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  10406. var textAlign = 'middle';
  10407. var textBaseline = 'middle';
  10408. var tickPadding = optionTicks.padding;
  10409. if (isHorizontal) {
  10410. var labelYOffset = tl + tickPadding;
  10411. if (options.position === 'bottom') {
  10412. // bottom
  10413. textBaseline = !isRotated ? 'top' : 'middle';
  10414. textAlign = !isRotated ? 'center' : 'right';
  10415. labelY = me.top + labelYOffset;
  10416. } else {
  10417. // top
  10418. textBaseline = !isRotated ? 'bottom' : 'middle';
  10419. textAlign = !isRotated ? 'center' : 'left';
  10420. labelY = me.bottom - labelYOffset;
  10421. }
  10422. var xLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  10423. if (xLineValue < me.left) {
  10424. lineColor = 'rgba(0,0,0,0)';
  10425. }
  10426. xLineValue += helpers.aliasPixel(lineWidth);
  10427. labelX = me.getPixelForTick(index) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  10428. tx1 = tx2 = x1 = x2 = xLineValue;
  10429. ty1 = yTickStart;
  10430. ty2 = yTickEnd;
  10431. y1 = chartArea.top;
  10432. y2 = chartArea.bottom + axisWidth;
  10433. } else {
  10434. var isLeft = options.position === 'left';
  10435. var labelXOffset;
  10436. if (optionTicks.mirror) {
  10437. textAlign = isLeft ? 'left' : 'right';
  10438. labelXOffset = tickPadding;
  10439. } else {
  10440. textAlign = isLeft ? 'right' : 'left';
  10441. labelXOffset = tl + tickPadding;
  10442. }
  10443. labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
  10444. var yLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  10445. if (yLineValue < me.top) {
  10446. lineColor = 'rgba(0,0,0,0)';
  10447. }
  10448. yLineValue += helpers.aliasPixel(lineWidth);
  10449. labelY = me.getPixelForTick(index) + optionTicks.labelOffset;
  10450. tx1 = xTickStart;
  10451. tx2 = xTickEnd;
  10452. x1 = chartArea.left;
  10453. x2 = chartArea.right + axisWidth;
  10454. ty1 = ty2 = y1 = y2 = yLineValue;
  10455. }
  10456. itemsToDraw.push({
  10457. tx1: tx1,
  10458. ty1: ty1,
  10459. tx2: tx2,
  10460. ty2: ty2,
  10461. x1: x1,
  10462. y1: y1,
  10463. x2: x2,
  10464. y2: y2,
  10465. labelX: labelX,
  10466. labelY: labelY,
  10467. glWidth: lineWidth,
  10468. glColor: lineColor,
  10469. glBorderDash: borderDash,
  10470. glBorderDashOffset: borderDashOffset,
  10471. rotation: -1 * labelRotationRadians,
  10472. label: label,
  10473. major: tick.major,
  10474. textBaseline: textBaseline,
  10475. textAlign: textAlign
  10476. });
  10477. });
  10478. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  10479. helpers.each(itemsToDraw, function(itemToDraw) {
  10480. if (gridLines.display) {
  10481. context.save();
  10482. context.lineWidth = itemToDraw.glWidth;
  10483. context.strokeStyle = itemToDraw.glColor;
  10484. if (context.setLineDash) {
  10485. context.setLineDash(itemToDraw.glBorderDash);
  10486. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  10487. }
  10488. context.beginPath();
  10489. if (gridLines.drawTicks) {
  10490. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  10491. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  10492. }
  10493. if (gridLines.drawOnChartArea) {
  10494. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  10495. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  10496. }
  10497. context.stroke();
  10498. context.restore();
  10499. }
  10500. if (optionTicks.display) {
  10501. // Make sure we draw text in the correct color and font
  10502. context.save();
  10503. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  10504. context.rotate(itemToDraw.rotation);
  10505. context.font = itemToDraw.major ? majorTickFont.font : tickFont.font;
  10506. context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
  10507. context.textBaseline = itemToDraw.textBaseline;
  10508. context.textAlign = itemToDraw.textAlign;
  10509. var label = itemToDraw.label;
  10510. if (helpers.isArray(label)) {
  10511. var lineCount = label.length;
  10512. var lineHeight = tickFont.size * 1.5;
  10513. var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
  10514. for (var i = 0; i < lineCount; ++i) {
  10515. // We just make sure the multiline element is a string here..
  10516. context.fillText('' + label[i], 0, y);
  10517. // apply same lineSpacing as calculated @ L#320
  10518. y += lineHeight;
  10519. }
  10520. } else {
  10521. context.fillText(label, 0, 0);
  10522. }
  10523. context.restore();
  10524. }
  10525. });
  10526. if (scaleLabel.display) {
  10527. // Draw the scale label
  10528. var scaleLabelX;
  10529. var scaleLabelY;
  10530. var rotation = 0;
  10531. var halfLineHeight = parseLineHeight(scaleLabel) / 2;
  10532. if (isHorizontal) {
  10533. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  10534. scaleLabelY = options.position === 'bottom'
  10535. ? me.bottom - halfLineHeight - scaleLabelPadding.bottom
  10536. : me.top + halfLineHeight + scaleLabelPadding.top;
  10537. } else {
  10538. var isLeft = options.position === 'left';
  10539. scaleLabelX = isLeft
  10540. ? me.left + halfLineHeight + scaleLabelPadding.top
  10541. : me.right - halfLineHeight - scaleLabelPadding.top;
  10542. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  10543. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  10544. }
  10545. context.save();
  10546. context.translate(scaleLabelX, scaleLabelY);
  10547. context.rotate(rotation);
  10548. context.textAlign = 'center';
  10549. context.textBaseline = 'middle';
  10550. context.fillStyle = scaleLabelFontColor; // render in correct colour
  10551. context.font = scaleLabelFont.font;
  10552. context.fillText(scaleLabel.labelString, 0, 0);
  10553. context.restore();
  10554. }
  10555. if (gridLines.drawBorder) {
  10556. // Draw the line at the edge of the axis
  10557. context.lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0);
  10558. context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
  10559. var x1 = me.left;
  10560. var x2 = me.right + axisWidth;
  10561. var y1 = me.top;
  10562. var y2 = me.bottom + axisWidth;
  10563. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  10564. if (isHorizontal) {
  10565. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  10566. y1 += aliasPixel;
  10567. y2 += aliasPixel;
  10568. } else {
  10569. x1 = x2 = options.position === 'left' ? me.right : me.left;
  10570. x1 += aliasPixel;
  10571. x2 += aliasPixel;
  10572. }
  10573. context.beginPath();
  10574. context.moveTo(x1, y1);
  10575. context.lineTo(x2, y2);
  10576. context.stroke();
  10577. }
  10578. }
  10579. });
  10580. };
  10581. },{"25":25,"26":26,"34":34,"45":45}],33:[function(require,module,exports){
  10582. 'use strict';
  10583. var defaults = require(25);
  10584. var helpers = require(45);
  10585. var layouts = require(30);
  10586. module.exports = function(Chart) {
  10587. Chart.scaleService = {
  10588. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  10589. // use the new chart options to grab the correct scale
  10590. constructors: {},
  10591. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  10592. // old browsers
  10593. // Scale config defaults
  10594. defaults: {},
  10595. registerScaleType: function(type, scaleConstructor, scaleDefaults) {
  10596. this.constructors[type] = scaleConstructor;
  10597. this.defaults[type] = helpers.clone(scaleDefaults);
  10598. },
  10599. getScaleConstructor: function(type) {
  10600. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  10601. },
  10602. getScaleDefaults: function(type) {
  10603. // Return the scale defaults merged with the global settings so that we always use the latest ones
  10604. return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
  10605. },
  10606. updateScaleDefaults: function(type, additions) {
  10607. var me = this;
  10608. if (me.defaults.hasOwnProperty(type)) {
  10609. me.defaults[type] = helpers.extend(me.defaults[type], additions);
  10610. }
  10611. },
  10612. addScalesToLayout: function(chart) {
  10613. // Adds each scale to the chart.boxes array to be sized accordingly
  10614. helpers.each(chart.scales, function(scale) {
  10615. // Set ILayoutItem parameters for backwards compatibility
  10616. scale.fullWidth = scale.options.fullWidth;
  10617. scale.position = scale.options.position;
  10618. scale.weight = scale.options.weight;
  10619. layouts.addBox(chart, scale);
  10620. });
  10621. }
  10622. };
  10623. };
  10624. },{"25":25,"30":30,"45":45}],34:[function(require,module,exports){
  10625. 'use strict';
  10626. var helpers = require(45);
  10627. /**
  10628. * Namespace to hold static tick generation functions
  10629. * @namespace Chart.Ticks
  10630. */
  10631. module.exports = {
  10632. /**
  10633. * Namespace to hold formatters for different types of ticks
  10634. * @namespace Chart.Ticks.formatters
  10635. */
  10636. formatters: {
  10637. /**
  10638. * Formatter for value labels
  10639. * @method Chart.Ticks.formatters.values
  10640. * @param value the value to display
  10641. * @return {String|Array} the label to display
  10642. */
  10643. values: function(value) {
  10644. return helpers.isArray(value) ? value : '' + value;
  10645. },
  10646. /**
  10647. * Formatter for linear numeric ticks
  10648. * @method Chart.Ticks.formatters.linear
  10649. * @param tickValue {Number} the value to be formatted
  10650. * @param index {Number} the position of the tickValue parameter in the ticks array
  10651. * @param ticks {Array<Number>} the list of ticks being converted
  10652. * @return {String} string representation of the tickValue parameter
  10653. */
  10654. linear: function(tickValue, index, ticks) {
  10655. // If we have lots of ticks, don't use the ones
  10656. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  10657. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  10658. if (Math.abs(delta) > 1) {
  10659. if (tickValue !== Math.floor(tickValue)) {
  10660. // not an integer
  10661. delta = tickValue - Math.floor(tickValue);
  10662. }
  10663. }
  10664. var logDelta = helpers.log10(Math.abs(delta));
  10665. var tickString = '';
  10666. if (tickValue !== 0) {
  10667. var numDecimal = -1 * Math.floor(logDelta);
  10668. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  10669. tickString = tickValue.toFixed(numDecimal);
  10670. } else {
  10671. tickString = '0'; // never show decimal places for 0
  10672. }
  10673. return tickString;
  10674. },
  10675. logarithmic: function(tickValue, index, ticks) {
  10676. var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
  10677. if (tickValue === 0) {
  10678. return '0';
  10679. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
  10680. return tickValue.toExponential();
  10681. }
  10682. return '';
  10683. }
  10684. }
  10685. };
  10686. },{"45":45}],35:[function(require,module,exports){
  10687. 'use strict';
  10688. var defaults = require(25);
  10689. var Element = require(26);
  10690. var helpers = require(45);
  10691. defaults._set('global', {
  10692. tooltips: {
  10693. enabled: true,
  10694. custom: null,
  10695. mode: 'nearest',
  10696. position: 'average',
  10697. intersect: true,
  10698. backgroundColor: 'rgba(0,0,0,0.8)',
  10699. titleFontStyle: 'bold',
  10700. titleSpacing: 2,
  10701. titleMarginBottom: 6,
  10702. titleFontColor: '#fff',
  10703. titleAlign: 'left',
  10704. bodySpacing: 2,
  10705. bodyFontColor: '#fff',
  10706. bodyAlign: 'left',
  10707. footerFontStyle: 'bold',
  10708. footerSpacing: 2,
  10709. footerMarginTop: 6,
  10710. footerFontColor: '#fff',
  10711. footerAlign: 'left',
  10712. yPadding: 6,
  10713. xPadding: 6,
  10714. caretPadding: 2,
  10715. caretSize: 5,
  10716. cornerRadius: 6,
  10717. multiKeyBackground: '#fff',
  10718. displayColors: true,
  10719. borderColor: 'rgba(0,0,0,0)',
  10720. borderWidth: 0,
  10721. callbacks: {
  10722. // Args are: (tooltipItems, data)
  10723. beforeTitle: helpers.noop,
  10724. title: function(tooltipItems, data) {
  10725. // Pick first xLabel for now
  10726. var title = '';
  10727. var labels = data.labels;
  10728. var labelCount = labels ? labels.length : 0;
  10729. if (tooltipItems.length > 0) {
  10730. var item = tooltipItems[0];
  10731. if (item.xLabel) {
  10732. title = item.xLabel;
  10733. } else if (labelCount > 0 && item.index < labelCount) {
  10734. title = labels[item.index];
  10735. }
  10736. }
  10737. return title;
  10738. },
  10739. afterTitle: helpers.noop,
  10740. // Args are: (tooltipItems, data)
  10741. beforeBody: helpers.noop,
  10742. // Args are: (tooltipItem, data)
  10743. beforeLabel: helpers.noop,
  10744. label: function(tooltipItem, data) {
  10745. var label = data.datasets[tooltipItem.datasetIndex].label || '';
  10746. if (label) {
  10747. label += ': ';
  10748. }
  10749. label += tooltipItem.yLabel;
  10750. return label;
  10751. },
  10752. labelColor: function(tooltipItem, chart) {
  10753. var meta = chart.getDatasetMeta(tooltipItem.datasetIndex);
  10754. var activeElement = meta.data[tooltipItem.index];
  10755. var view = activeElement._view;
  10756. return {
  10757. borderColor: view.borderColor,
  10758. backgroundColor: view.backgroundColor
  10759. };
  10760. },
  10761. labelTextColor: function() {
  10762. return this._options.bodyFontColor;
  10763. },
  10764. afterLabel: helpers.noop,
  10765. // Args are: (tooltipItems, data)
  10766. afterBody: helpers.noop,
  10767. // Args are: (tooltipItems, data)
  10768. beforeFooter: helpers.noop,
  10769. footer: helpers.noop,
  10770. afterFooter: helpers.noop
  10771. }
  10772. }
  10773. });
  10774. module.exports = function(Chart) {
  10775. /**
  10776. * Helper method to merge the opacity into a color
  10777. */
  10778. function mergeOpacity(colorString, opacity) {
  10779. var color = helpers.color(colorString);
  10780. return color.alpha(opacity * color.alpha()).rgbaString();
  10781. }
  10782. // Helper to push or concat based on if the 2nd parameter is an array or not
  10783. function pushOrConcat(base, toPush) {
  10784. if (toPush) {
  10785. if (helpers.isArray(toPush)) {
  10786. // base = base.concat(toPush);
  10787. Array.prototype.push.apply(base, toPush);
  10788. } else {
  10789. base.push(toPush);
  10790. }
  10791. }
  10792. return base;
  10793. }
  10794. // Private helper to create a tooltip item model
  10795. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  10796. // @return : new tooltip item
  10797. function createTooltipItem(element) {
  10798. var xScale = element._xScale;
  10799. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  10800. var index = element._index;
  10801. var datasetIndex = element._datasetIndex;
  10802. return {
  10803. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  10804. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  10805. index: index,
  10806. datasetIndex: datasetIndex,
  10807. x: element._model.x,
  10808. y: element._model.y
  10809. };
  10810. }
  10811. /**
  10812. * Helper to get the reset model for the tooltip
  10813. * @param tooltipOpts {Object} the tooltip options
  10814. */
  10815. function getBaseModel(tooltipOpts) {
  10816. var globalDefaults = defaults.global;
  10817. var valueOrDefault = helpers.valueOrDefault;
  10818. return {
  10819. // Positioning
  10820. xPadding: tooltipOpts.xPadding,
  10821. yPadding: tooltipOpts.yPadding,
  10822. xAlign: tooltipOpts.xAlign,
  10823. yAlign: tooltipOpts.yAlign,
  10824. // Body
  10825. bodyFontColor: tooltipOpts.bodyFontColor,
  10826. _bodyFontFamily: valueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  10827. _bodyFontStyle: valueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  10828. _bodyAlign: tooltipOpts.bodyAlign,
  10829. bodyFontSize: valueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  10830. bodySpacing: tooltipOpts.bodySpacing,
  10831. // Title
  10832. titleFontColor: tooltipOpts.titleFontColor,
  10833. _titleFontFamily: valueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  10834. _titleFontStyle: valueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  10835. titleFontSize: valueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  10836. _titleAlign: tooltipOpts.titleAlign,
  10837. titleSpacing: tooltipOpts.titleSpacing,
  10838. titleMarginBottom: tooltipOpts.titleMarginBottom,
  10839. // Footer
  10840. footerFontColor: tooltipOpts.footerFontColor,
  10841. _footerFontFamily: valueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  10842. _footerFontStyle: valueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  10843. footerFontSize: valueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  10844. _footerAlign: tooltipOpts.footerAlign,
  10845. footerSpacing: tooltipOpts.footerSpacing,
  10846. footerMarginTop: tooltipOpts.footerMarginTop,
  10847. // Appearance
  10848. caretSize: tooltipOpts.caretSize,
  10849. cornerRadius: tooltipOpts.cornerRadius,
  10850. backgroundColor: tooltipOpts.backgroundColor,
  10851. opacity: 0,
  10852. legendColorBackground: tooltipOpts.multiKeyBackground,
  10853. displayColors: tooltipOpts.displayColors,
  10854. borderColor: tooltipOpts.borderColor,
  10855. borderWidth: tooltipOpts.borderWidth
  10856. };
  10857. }
  10858. /**
  10859. * Get the size of the tooltip
  10860. */
  10861. function getTooltipSize(tooltip, model) {
  10862. var ctx = tooltip._chart.ctx;
  10863. var height = model.yPadding * 2; // Tooltip Padding
  10864. var width = 0;
  10865. // Count of all lines in the body
  10866. var body = model.body;
  10867. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  10868. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  10869. }, 0);
  10870. combinedBodyLength += model.beforeBody.length + model.afterBody.length;
  10871. var titleLineCount = model.title.length;
  10872. var footerLineCount = model.footer.length;
  10873. var titleFontSize = model.titleFontSize;
  10874. var bodyFontSize = model.bodyFontSize;
  10875. var footerFontSize = model.footerFontSize;
  10876. height += titleLineCount * titleFontSize; // Title Lines
  10877. height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
  10878. height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
  10879. height += combinedBodyLength * bodyFontSize; // Body Lines
  10880. height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
  10881. height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
  10882. height += footerLineCount * (footerFontSize); // Footer Lines
  10883. height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
  10884. // Title width
  10885. var widthPadding = 0;
  10886. var maxLineWidth = function(line) {
  10887. width = Math.max(width, ctx.measureText(line).width + widthPadding);
  10888. };
  10889. ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
  10890. helpers.each(model.title, maxLineWidth);
  10891. // Body width
  10892. ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
  10893. helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
  10894. // Body lines may include some extra width due to the color box
  10895. widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
  10896. helpers.each(body, function(bodyItem) {
  10897. helpers.each(bodyItem.before, maxLineWidth);
  10898. helpers.each(bodyItem.lines, maxLineWidth);
  10899. helpers.each(bodyItem.after, maxLineWidth);
  10900. });
  10901. // Reset back to 0
  10902. widthPadding = 0;
  10903. // Footer width
  10904. ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
  10905. helpers.each(model.footer, maxLineWidth);
  10906. // Add padding
  10907. width += 2 * model.xPadding;
  10908. return {
  10909. width: width,
  10910. height: height
  10911. };
  10912. }
  10913. /**
  10914. * Helper to get the alignment of a tooltip given the size
  10915. */
  10916. function determineAlignment(tooltip, size) {
  10917. var model = tooltip._model;
  10918. var chart = tooltip._chart;
  10919. var chartArea = tooltip._chart.chartArea;
  10920. var xAlign = 'center';
  10921. var yAlign = 'center';
  10922. if (model.y < size.height) {
  10923. yAlign = 'top';
  10924. } else if (model.y > (chart.height - size.height)) {
  10925. yAlign = 'bottom';
  10926. }
  10927. var lf, rf; // functions to determine left, right alignment
  10928. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  10929. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  10930. var midX = (chartArea.left + chartArea.right) / 2;
  10931. var midY = (chartArea.top + chartArea.bottom) / 2;
  10932. if (yAlign === 'center') {
  10933. lf = function(x) {
  10934. return x <= midX;
  10935. };
  10936. rf = function(x) {
  10937. return x > midX;
  10938. };
  10939. } else {
  10940. lf = function(x) {
  10941. return x <= (size.width / 2);
  10942. };
  10943. rf = function(x) {
  10944. return x >= (chart.width - (size.width / 2));
  10945. };
  10946. }
  10947. olf = function(x) {
  10948. return x + size.width + model.caretSize + model.caretPadding > chart.width;
  10949. };
  10950. orf = function(x) {
  10951. return x - size.width - model.caretSize - model.caretPadding < 0;
  10952. };
  10953. yf = function(y) {
  10954. return y <= midY ? 'top' : 'bottom';
  10955. };
  10956. if (lf(model.x)) {
  10957. xAlign = 'left';
  10958. // Is tooltip too wide and goes over the right side of the chart.?
  10959. if (olf(model.x)) {
  10960. xAlign = 'center';
  10961. yAlign = yf(model.y);
  10962. }
  10963. } else if (rf(model.x)) {
  10964. xAlign = 'right';
  10965. // Is tooltip too wide and goes outside left edge of canvas?
  10966. if (orf(model.x)) {
  10967. xAlign = 'center';
  10968. yAlign = yf(model.y);
  10969. }
  10970. }
  10971. var opts = tooltip._options;
  10972. return {
  10973. xAlign: opts.xAlign ? opts.xAlign : xAlign,
  10974. yAlign: opts.yAlign ? opts.yAlign : yAlign
  10975. };
  10976. }
  10977. /**
  10978. * @Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
  10979. */
  10980. function getBackgroundPoint(vm, size, alignment, chart) {
  10981. // Background Position
  10982. var x = vm.x;
  10983. var y = vm.y;
  10984. var caretSize = vm.caretSize;
  10985. var caretPadding = vm.caretPadding;
  10986. var cornerRadius = vm.cornerRadius;
  10987. var xAlign = alignment.xAlign;
  10988. var yAlign = alignment.yAlign;
  10989. var paddingAndSize = caretSize + caretPadding;
  10990. var radiusAndPadding = cornerRadius + caretPadding;
  10991. if (xAlign === 'right') {
  10992. x -= size.width;
  10993. } else if (xAlign === 'center') {
  10994. x -= (size.width / 2);
  10995. if (x + size.width > chart.width) {
  10996. x = chart.width - size.width;
  10997. }
  10998. if (x < 0) {
  10999. x = 0;
  11000. }
  11001. }
  11002. if (yAlign === 'top') {
  11003. y += paddingAndSize;
  11004. } else if (yAlign === 'bottom') {
  11005. y -= size.height + paddingAndSize;
  11006. } else {
  11007. y -= (size.height / 2);
  11008. }
  11009. if (yAlign === 'center') {
  11010. if (xAlign === 'left') {
  11011. x += paddingAndSize;
  11012. } else if (xAlign === 'right') {
  11013. x -= paddingAndSize;
  11014. }
  11015. } else if (xAlign === 'left') {
  11016. x -= radiusAndPadding;
  11017. } else if (xAlign === 'right') {
  11018. x += radiusAndPadding;
  11019. }
  11020. return {
  11021. x: x,
  11022. y: y
  11023. };
  11024. }
  11025. Chart.Tooltip = Element.extend({
  11026. initialize: function() {
  11027. this._model = getBaseModel(this._options);
  11028. this._lastActive = [];
  11029. },
  11030. // Get the title
  11031. // Args are: (tooltipItem, data)
  11032. getTitle: function() {
  11033. var me = this;
  11034. var opts = me._options;
  11035. var callbacks = opts.callbacks;
  11036. var beforeTitle = callbacks.beforeTitle.apply(me, arguments);
  11037. var title = callbacks.title.apply(me, arguments);
  11038. var afterTitle = callbacks.afterTitle.apply(me, arguments);
  11039. var lines = [];
  11040. lines = pushOrConcat(lines, beforeTitle);
  11041. lines = pushOrConcat(lines, title);
  11042. lines = pushOrConcat(lines, afterTitle);
  11043. return lines;
  11044. },
  11045. // Args are: (tooltipItem, data)
  11046. getBeforeBody: function() {
  11047. var lines = this._options.callbacks.beforeBody.apply(this, arguments);
  11048. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  11049. },
  11050. // Args are: (tooltipItem, data)
  11051. getBody: function(tooltipItems, data) {
  11052. var me = this;
  11053. var callbacks = me._options.callbacks;
  11054. var bodyItems = [];
  11055. helpers.each(tooltipItems, function(tooltipItem) {
  11056. var bodyItem = {
  11057. before: [],
  11058. lines: [],
  11059. after: []
  11060. };
  11061. pushOrConcat(bodyItem.before, callbacks.beforeLabel.call(me, tooltipItem, data));
  11062. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  11063. pushOrConcat(bodyItem.after, callbacks.afterLabel.call(me, tooltipItem, data));
  11064. bodyItems.push(bodyItem);
  11065. });
  11066. return bodyItems;
  11067. },
  11068. // Args are: (tooltipItem, data)
  11069. getAfterBody: function() {
  11070. var lines = this._options.callbacks.afterBody.apply(this, arguments);
  11071. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  11072. },
  11073. // Get the footer and beforeFooter and afterFooter lines
  11074. // Args are: (tooltipItem, data)
  11075. getFooter: function() {
  11076. var me = this;
  11077. var callbacks = me._options.callbacks;
  11078. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  11079. var footer = callbacks.footer.apply(me, arguments);
  11080. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  11081. var lines = [];
  11082. lines = pushOrConcat(lines, beforeFooter);
  11083. lines = pushOrConcat(lines, footer);
  11084. lines = pushOrConcat(lines, afterFooter);
  11085. return lines;
  11086. },
  11087. update: function(changed) {
  11088. var me = this;
  11089. var opts = me._options;
  11090. // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
  11091. // 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
  11092. // which breaks any animations.
  11093. var existingModel = me._model;
  11094. var model = me._model = getBaseModel(opts);
  11095. var active = me._active;
  11096. var data = me._data;
  11097. // In the case where active.length === 0 we need to keep these at existing values for good animations
  11098. var alignment = {
  11099. xAlign: existingModel.xAlign,
  11100. yAlign: existingModel.yAlign
  11101. };
  11102. var backgroundPoint = {
  11103. x: existingModel.x,
  11104. y: existingModel.y
  11105. };
  11106. var tooltipSize = {
  11107. width: existingModel.width,
  11108. height: existingModel.height
  11109. };
  11110. var tooltipPosition = {
  11111. x: existingModel.caretX,
  11112. y: existingModel.caretY
  11113. };
  11114. var i, len;
  11115. if (active.length) {
  11116. model.opacity = 1;
  11117. var labelColors = [];
  11118. var labelTextColors = [];
  11119. tooltipPosition = Chart.Tooltip.positioners[opts.position].call(me, active, me._eventPosition);
  11120. var tooltipItems = [];
  11121. for (i = 0, len = active.length; i < len; ++i) {
  11122. tooltipItems.push(createTooltipItem(active[i]));
  11123. }
  11124. // If the user provided a filter function, use it to modify the tooltip items
  11125. if (opts.filter) {
  11126. tooltipItems = tooltipItems.filter(function(a) {
  11127. return opts.filter(a, data);
  11128. });
  11129. }
  11130. // If the user provided a sorting function, use it to modify the tooltip items
  11131. if (opts.itemSort) {
  11132. tooltipItems = tooltipItems.sort(function(a, b) {
  11133. return opts.itemSort(a, b, data);
  11134. });
  11135. }
  11136. // Determine colors for boxes
  11137. helpers.each(tooltipItems, function(tooltipItem) {
  11138. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart));
  11139. labelTextColors.push(opts.callbacks.labelTextColor.call(me, tooltipItem, me._chart));
  11140. });
  11141. // Build the Text Lines
  11142. model.title = me.getTitle(tooltipItems, data);
  11143. model.beforeBody = me.getBeforeBody(tooltipItems, data);
  11144. model.body = me.getBody(tooltipItems, data);
  11145. model.afterBody = me.getAfterBody(tooltipItems, data);
  11146. model.footer = me.getFooter(tooltipItems, data);
  11147. // Initial positioning and colors
  11148. model.x = Math.round(tooltipPosition.x);
  11149. model.y = Math.round(tooltipPosition.y);
  11150. model.caretPadding = opts.caretPadding;
  11151. model.labelColors = labelColors;
  11152. model.labelTextColors = labelTextColors;
  11153. // data points
  11154. model.dataPoints = tooltipItems;
  11155. // We need to determine alignment of the tooltip
  11156. tooltipSize = getTooltipSize(this, model);
  11157. alignment = determineAlignment(this, tooltipSize);
  11158. // Final Size and Position
  11159. backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
  11160. } else {
  11161. model.opacity = 0;
  11162. }
  11163. model.xAlign = alignment.xAlign;
  11164. model.yAlign = alignment.yAlign;
  11165. model.x = backgroundPoint.x;
  11166. model.y = backgroundPoint.y;
  11167. model.width = tooltipSize.width;
  11168. model.height = tooltipSize.height;
  11169. // Point where the caret on the tooltip points to
  11170. model.caretX = tooltipPosition.x;
  11171. model.caretY = tooltipPosition.y;
  11172. me._model = model;
  11173. if (changed && opts.custom) {
  11174. opts.custom.call(me, model);
  11175. }
  11176. return me;
  11177. },
  11178. drawCaret: function(tooltipPoint, size) {
  11179. var ctx = this._chart.ctx;
  11180. var vm = this._view;
  11181. var caretPosition = this.getCaretPosition(tooltipPoint, size, vm);
  11182. ctx.lineTo(caretPosition.x1, caretPosition.y1);
  11183. ctx.lineTo(caretPosition.x2, caretPosition.y2);
  11184. ctx.lineTo(caretPosition.x3, caretPosition.y3);
  11185. },
  11186. getCaretPosition: function(tooltipPoint, size, vm) {
  11187. var x1, x2, x3, y1, y2, y3;
  11188. var caretSize = vm.caretSize;
  11189. var cornerRadius = vm.cornerRadius;
  11190. var xAlign = vm.xAlign;
  11191. var yAlign = vm.yAlign;
  11192. var ptX = tooltipPoint.x;
  11193. var ptY = tooltipPoint.y;
  11194. var width = size.width;
  11195. var height = size.height;
  11196. if (yAlign === 'center') {
  11197. y2 = ptY + (height / 2);
  11198. if (xAlign === 'left') {
  11199. x1 = ptX;
  11200. x2 = x1 - caretSize;
  11201. x3 = x1;
  11202. y1 = y2 + caretSize;
  11203. y3 = y2 - caretSize;
  11204. } else {
  11205. x1 = ptX + width;
  11206. x2 = x1 + caretSize;
  11207. x3 = x1;
  11208. y1 = y2 - caretSize;
  11209. y3 = y2 + caretSize;
  11210. }
  11211. } else {
  11212. if (xAlign === 'left') {
  11213. x2 = ptX + cornerRadius + (caretSize);
  11214. x1 = x2 - caretSize;
  11215. x3 = x2 + caretSize;
  11216. } else if (xAlign === 'right') {
  11217. x2 = ptX + width - cornerRadius - caretSize;
  11218. x1 = x2 - caretSize;
  11219. x3 = x2 + caretSize;
  11220. } else {
  11221. x2 = vm.caretX;
  11222. x1 = x2 - caretSize;
  11223. x3 = x2 + caretSize;
  11224. }
  11225. if (yAlign === 'top') {
  11226. y1 = ptY;
  11227. y2 = y1 - caretSize;
  11228. y3 = y1;
  11229. } else {
  11230. y1 = ptY + height;
  11231. y2 = y1 + caretSize;
  11232. y3 = y1;
  11233. // invert drawing order
  11234. var tmp = x3;
  11235. x3 = x1;
  11236. x1 = tmp;
  11237. }
  11238. }
  11239. return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3};
  11240. },
  11241. drawTitle: function(pt, vm, ctx, opacity) {
  11242. var title = vm.title;
  11243. if (title.length) {
  11244. ctx.textAlign = vm._titleAlign;
  11245. ctx.textBaseline = 'top';
  11246. var titleFontSize = vm.titleFontSize;
  11247. var titleSpacing = vm.titleSpacing;
  11248. ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
  11249. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  11250. var i, len;
  11251. for (i = 0, len = title.length; i < len; ++i) {
  11252. ctx.fillText(title[i], pt.x, pt.y);
  11253. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  11254. if (i + 1 === title.length) {
  11255. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  11256. }
  11257. }
  11258. }
  11259. },
  11260. drawBody: function(pt, vm, ctx, opacity) {
  11261. var bodyFontSize = vm.bodyFontSize;
  11262. var bodySpacing = vm.bodySpacing;
  11263. var body = vm.body;
  11264. ctx.textAlign = vm._bodyAlign;
  11265. ctx.textBaseline = 'top';
  11266. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  11267. // Before Body
  11268. var xLinePadding = 0;
  11269. var fillLineOfText = function(line) {
  11270. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  11271. pt.y += bodyFontSize + bodySpacing;
  11272. };
  11273. // Before body lines
  11274. ctx.fillStyle = mergeOpacity(vm.bodyFontColor, opacity);
  11275. helpers.each(vm.beforeBody, fillLineOfText);
  11276. var drawColorBoxes = vm.displayColors;
  11277. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  11278. // Draw body lines now
  11279. helpers.each(body, function(bodyItem, i) {
  11280. var textColor = mergeOpacity(vm.labelTextColors[i], opacity);
  11281. ctx.fillStyle = textColor;
  11282. helpers.each(bodyItem.before, fillLineOfText);
  11283. helpers.each(bodyItem.lines, function(line) {
  11284. // Draw Legend-like boxes if needed
  11285. if (drawColorBoxes) {
  11286. // Fill a white rect so that colours merge nicely if the opacity is < 1
  11287. ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
  11288. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  11289. // Border
  11290. ctx.lineWidth = 1;
  11291. ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
  11292. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  11293. // Inner square
  11294. ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
  11295. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  11296. ctx.fillStyle = textColor;
  11297. }
  11298. fillLineOfText(line);
  11299. });
  11300. helpers.each(bodyItem.after, fillLineOfText);
  11301. });
  11302. // Reset back to 0 for after body
  11303. xLinePadding = 0;
  11304. // After body lines
  11305. helpers.each(vm.afterBody, fillLineOfText);
  11306. pt.y -= bodySpacing; // Remove last body spacing
  11307. },
  11308. drawFooter: function(pt, vm, ctx, opacity) {
  11309. var footer = vm.footer;
  11310. if (footer.length) {
  11311. pt.y += vm.footerMarginTop;
  11312. ctx.textAlign = vm._footerAlign;
  11313. ctx.textBaseline = 'top';
  11314. ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
  11315. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  11316. helpers.each(footer, function(line) {
  11317. ctx.fillText(line, pt.x, pt.y);
  11318. pt.y += vm.footerFontSize + vm.footerSpacing;
  11319. });
  11320. }
  11321. },
  11322. drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
  11323. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  11324. ctx.strokeStyle = mergeOpacity(vm.borderColor, opacity);
  11325. ctx.lineWidth = vm.borderWidth;
  11326. var xAlign = vm.xAlign;
  11327. var yAlign = vm.yAlign;
  11328. var x = pt.x;
  11329. var y = pt.y;
  11330. var width = tooltipSize.width;
  11331. var height = tooltipSize.height;
  11332. var radius = vm.cornerRadius;
  11333. ctx.beginPath();
  11334. ctx.moveTo(x + radius, y);
  11335. if (yAlign === 'top') {
  11336. this.drawCaret(pt, tooltipSize);
  11337. }
  11338. ctx.lineTo(x + width - radius, y);
  11339. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  11340. if (yAlign === 'center' && xAlign === 'right') {
  11341. this.drawCaret(pt, tooltipSize);
  11342. }
  11343. ctx.lineTo(x + width, y + height - radius);
  11344. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  11345. if (yAlign === 'bottom') {
  11346. this.drawCaret(pt, tooltipSize);
  11347. }
  11348. ctx.lineTo(x + radius, y + height);
  11349. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  11350. if (yAlign === 'center' && xAlign === 'left') {
  11351. this.drawCaret(pt, tooltipSize);
  11352. }
  11353. ctx.lineTo(x, y + radius);
  11354. ctx.quadraticCurveTo(x, y, x + radius, y);
  11355. ctx.closePath();
  11356. ctx.fill();
  11357. if (vm.borderWidth > 0) {
  11358. ctx.stroke();
  11359. }
  11360. },
  11361. draw: function() {
  11362. var ctx = this._chart.ctx;
  11363. var vm = this._view;
  11364. if (vm.opacity === 0) {
  11365. return;
  11366. }
  11367. var tooltipSize = {
  11368. width: vm.width,
  11369. height: vm.height
  11370. };
  11371. var pt = {
  11372. x: vm.x,
  11373. y: vm.y
  11374. };
  11375. // IE11/Edge does not like very small opacities, so snap to 0
  11376. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  11377. // Truthy/falsey value for empty tooltip
  11378. var hasTooltipContent = vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length;
  11379. if (this._options.enabled && hasTooltipContent) {
  11380. // Draw Background
  11381. this.drawBackground(pt, vm, ctx, tooltipSize, opacity);
  11382. // Draw Title, Body, and Footer
  11383. pt.x += vm.xPadding;
  11384. pt.y += vm.yPadding;
  11385. // Titles
  11386. this.drawTitle(pt, vm, ctx, opacity);
  11387. // Body
  11388. this.drawBody(pt, vm, ctx, opacity);
  11389. // Footer
  11390. this.drawFooter(pt, vm, ctx, opacity);
  11391. }
  11392. },
  11393. /**
  11394. * Handle an event
  11395. * @private
  11396. * @param {IEvent} event - The event to handle
  11397. * @returns {Boolean} true if the tooltip changed
  11398. */
  11399. handleEvent: function(e) {
  11400. var me = this;
  11401. var options = me._options;
  11402. var changed = false;
  11403. me._lastActive = me._lastActive || [];
  11404. // Find Active Elements for tooltips
  11405. if (e.type === 'mouseout') {
  11406. me._active = [];
  11407. } else {
  11408. me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
  11409. }
  11410. // Remember Last Actives
  11411. changed = !helpers.arrayEquals(me._active, me._lastActive);
  11412. // Only handle target event on tooltip change
  11413. if (changed) {
  11414. me._lastActive = me._active;
  11415. if (options.enabled || options.custom) {
  11416. me._eventPosition = {
  11417. x: e.x,
  11418. y: e.y
  11419. };
  11420. me.update(true);
  11421. me.pivot();
  11422. }
  11423. }
  11424. return changed;
  11425. }
  11426. });
  11427. /**
  11428. * @namespace Chart.Tooltip.positioners
  11429. */
  11430. Chart.Tooltip.positioners = {
  11431. /**
  11432. * Average mode places the tooltip at the average position of the elements shown
  11433. * @function Chart.Tooltip.positioners.average
  11434. * @param elements {ChartElement[]} the elements being displayed in the tooltip
  11435. * @returns {Point} tooltip position
  11436. */
  11437. average: function(elements) {
  11438. if (!elements.length) {
  11439. return false;
  11440. }
  11441. var i, len;
  11442. var x = 0;
  11443. var y = 0;
  11444. var count = 0;
  11445. for (i = 0, len = elements.length; i < len; ++i) {
  11446. var el = elements[i];
  11447. if (el && el.hasValue()) {
  11448. var pos = el.tooltipPosition();
  11449. x += pos.x;
  11450. y += pos.y;
  11451. ++count;
  11452. }
  11453. }
  11454. return {
  11455. x: Math.round(x / count),
  11456. y: Math.round(y / count)
  11457. };
  11458. },
  11459. /**
  11460. * Gets the tooltip position nearest of the item nearest to the event position
  11461. * @function Chart.Tooltip.positioners.nearest
  11462. * @param elements {Chart.Element[]} the tooltip elements
  11463. * @param eventPosition {Point} the position of the event in canvas coordinates
  11464. * @returns {Point} the tooltip position
  11465. */
  11466. nearest: function(elements, eventPosition) {
  11467. var x = eventPosition.x;
  11468. var y = eventPosition.y;
  11469. var minDistance = Number.POSITIVE_INFINITY;
  11470. var i, len, nearestElement;
  11471. for (i = 0, len = elements.length; i < len; ++i) {
  11472. var el = elements[i];
  11473. if (el && el.hasValue()) {
  11474. var center = el.getCenterPoint();
  11475. var d = helpers.distanceBetweenPoints(eventPosition, center);
  11476. if (d < minDistance) {
  11477. minDistance = d;
  11478. nearestElement = el;
  11479. }
  11480. }
  11481. }
  11482. if (nearestElement) {
  11483. var tp = nearestElement.tooltipPosition();
  11484. x = tp.x;
  11485. y = tp.y;
  11486. }
  11487. return {
  11488. x: x,
  11489. y: y
  11490. };
  11491. }
  11492. };
  11493. };
  11494. },{"25":25,"26":26,"45":45}],36:[function(require,module,exports){
  11495. 'use strict';
  11496. var defaults = require(25);
  11497. var Element = require(26);
  11498. var helpers = require(45);
  11499. defaults._set('global', {
  11500. elements: {
  11501. arc: {
  11502. backgroundColor: defaults.global.defaultColor,
  11503. borderColor: '#fff',
  11504. borderWidth: 2
  11505. }
  11506. }
  11507. });
  11508. module.exports = Element.extend({
  11509. inLabelRange: function(mouseX) {
  11510. var vm = this._view;
  11511. if (vm) {
  11512. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  11513. }
  11514. return false;
  11515. },
  11516. inRange: function(chartX, chartY) {
  11517. var vm = this._view;
  11518. if (vm) {
  11519. var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
  11520. var angle = pointRelativePosition.angle;
  11521. var distance = pointRelativePosition.distance;
  11522. // Sanitise angle range
  11523. var startAngle = vm.startAngle;
  11524. var endAngle = vm.endAngle;
  11525. while (endAngle < startAngle) {
  11526. endAngle += 2.0 * Math.PI;
  11527. }
  11528. while (angle > endAngle) {
  11529. angle -= 2.0 * Math.PI;
  11530. }
  11531. while (angle < startAngle) {
  11532. angle += 2.0 * Math.PI;
  11533. }
  11534. // Check if within the range of the open/close angle
  11535. var betweenAngles = (angle >= startAngle && angle <= endAngle);
  11536. var withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  11537. return (betweenAngles && withinRadius);
  11538. }
  11539. return false;
  11540. },
  11541. getCenterPoint: function() {
  11542. var vm = this._view;
  11543. var halfAngle = (vm.startAngle + vm.endAngle) / 2;
  11544. var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
  11545. return {
  11546. x: vm.x + Math.cos(halfAngle) * halfRadius,
  11547. y: vm.y + Math.sin(halfAngle) * halfRadius
  11548. };
  11549. },
  11550. getArea: function() {
  11551. var vm = this._view;
  11552. return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
  11553. },
  11554. tooltipPosition: function() {
  11555. var vm = this._view;
  11556. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
  11557. var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  11558. return {
  11559. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  11560. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  11561. };
  11562. },
  11563. draw: function() {
  11564. var ctx = this._chart.ctx;
  11565. var vm = this._view;
  11566. var sA = vm.startAngle;
  11567. var eA = vm.endAngle;
  11568. ctx.beginPath();
  11569. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  11570. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  11571. ctx.closePath();
  11572. ctx.strokeStyle = vm.borderColor;
  11573. ctx.lineWidth = vm.borderWidth;
  11574. ctx.fillStyle = vm.backgroundColor;
  11575. ctx.fill();
  11576. ctx.lineJoin = 'bevel';
  11577. if (vm.borderWidth) {
  11578. ctx.stroke();
  11579. }
  11580. }
  11581. });
  11582. },{"25":25,"26":26,"45":45}],37:[function(require,module,exports){
  11583. 'use strict';
  11584. var defaults = require(25);
  11585. var Element = require(26);
  11586. var helpers = require(45);
  11587. var globalDefaults = defaults.global;
  11588. defaults._set('global', {
  11589. elements: {
  11590. line: {
  11591. tension: 0.4,
  11592. backgroundColor: globalDefaults.defaultColor,
  11593. borderWidth: 3,
  11594. borderColor: globalDefaults.defaultColor,
  11595. borderCapStyle: 'butt',
  11596. borderDash: [],
  11597. borderDashOffset: 0.0,
  11598. borderJoinStyle: 'miter',
  11599. capBezierPoints: true,
  11600. fill: true, // do we fill in the area between the line and its base axis
  11601. }
  11602. }
  11603. });
  11604. module.exports = Element.extend({
  11605. draw: function() {
  11606. var me = this;
  11607. var vm = me._view;
  11608. var ctx = me._chart.ctx;
  11609. var spanGaps = vm.spanGaps;
  11610. var points = me._children.slice(); // clone array
  11611. var globalOptionLineElements = globalDefaults.elements.line;
  11612. var lastDrawnIndex = -1;
  11613. var index, current, previous, currentVM;
  11614. // If we are looping, adding the first point again
  11615. if (me._loop && points.length) {
  11616. points.push(points[0]);
  11617. }
  11618. ctx.save();
  11619. // Stroke Line Options
  11620. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  11621. // IE 9 and 10 do not support line dash
  11622. if (ctx.setLineDash) {
  11623. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  11624. }
  11625. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  11626. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  11627. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  11628. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  11629. // Stroke Line
  11630. ctx.beginPath();
  11631. lastDrawnIndex = -1;
  11632. for (index = 0; index < points.length; ++index) {
  11633. current = points[index];
  11634. previous = helpers.previousItem(points, index);
  11635. currentVM = current._view;
  11636. // First point moves to it's starting position no matter what
  11637. if (index === 0) {
  11638. if (!currentVM.skip) {
  11639. ctx.moveTo(currentVM.x, currentVM.y);
  11640. lastDrawnIndex = index;
  11641. }
  11642. } else {
  11643. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  11644. if (!currentVM.skip) {
  11645. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  11646. // There was a gap and this is the first point after the gap
  11647. ctx.moveTo(currentVM.x, currentVM.y);
  11648. } else {
  11649. // Line to next point
  11650. helpers.canvas.lineTo(ctx, previous._view, current._view);
  11651. }
  11652. lastDrawnIndex = index;
  11653. }
  11654. }
  11655. }
  11656. ctx.stroke();
  11657. ctx.restore();
  11658. }
  11659. });
  11660. },{"25":25,"26":26,"45":45}],38:[function(require,module,exports){
  11661. 'use strict';
  11662. var defaults = require(25);
  11663. var Element = require(26);
  11664. var helpers = require(45);
  11665. var defaultColor = defaults.global.defaultColor;
  11666. defaults._set('global', {
  11667. elements: {
  11668. point: {
  11669. radius: 3,
  11670. pointStyle: 'circle',
  11671. backgroundColor: defaultColor,
  11672. borderColor: defaultColor,
  11673. borderWidth: 1,
  11674. // Hover
  11675. hitRadius: 1,
  11676. hoverRadius: 4,
  11677. hoverBorderWidth: 1
  11678. }
  11679. }
  11680. });
  11681. function xRange(mouseX) {
  11682. var vm = this._view;
  11683. return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
  11684. }
  11685. function yRange(mouseY) {
  11686. var vm = this._view;
  11687. return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false;
  11688. }
  11689. module.exports = Element.extend({
  11690. inRange: function(mouseX, mouseY) {
  11691. var vm = this._view;
  11692. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  11693. },
  11694. inLabelRange: xRange,
  11695. inXRange: xRange,
  11696. inYRange: yRange,
  11697. getCenterPoint: function() {
  11698. var vm = this._view;
  11699. return {
  11700. x: vm.x,
  11701. y: vm.y
  11702. };
  11703. },
  11704. getArea: function() {
  11705. return Math.PI * Math.pow(this._view.radius, 2);
  11706. },
  11707. tooltipPosition: function() {
  11708. var vm = this._view;
  11709. return {
  11710. x: vm.x,
  11711. y: vm.y,
  11712. padding: vm.radius + vm.borderWidth
  11713. };
  11714. },
  11715. draw: function(chartArea) {
  11716. var vm = this._view;
  11717. var model = this._model;
  11718. var ctx = this._chart.ctx;
  11719. var pointStyle = vm.pointStyle;
  11720. var radius = vm.radius;
  11721. var x = vm.x;
  11722. var y = vm.y;
  11723. var color = helpers.color;
  11724. var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)
  11725. var ratio = 0;
  11726. if (vm.skip) {
  11727. return;
  11728. }
  11729. ctx.strokeStyle = vm.borderColor || defaultColor;
  11730. ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
  11731. ctx.fillStyle = vm.backgroundColor || defaultColor;
  11732. // Cliping for Points.
  11733. // going out from inner charArea?
  11734. if ((chartArea !== undefined) && ((model.x < chartArea.left) || (chartArea.right * errMargin < model.x) || (model.y < chartArea.top) || (chartArea.bottom * errMargin < model.y))) {
  11735. // Point fade out
  11736. if (model.x < chartArea.left) {
  11737. ratio = (x - model.x) / (chartArea.left - model.x);
  11738. } else if (chartArea.right * errMargin < model.x) {
  11739. ratio = (model.x - x) / (model.x - chartArea.right);
  11740. } else if (model.y < chartArea.top) {
  11741. ratio = (y - model.y) / (chartArea.top - model.y);
  11742. } else if (chartArea.bottom * errMargin < model.y) {
  11743. ratio = (model.y - y) / (model.y - chartArea.bottom);
  11744. }
  11745. ratio = Math.round(ratio * 100) / 100;
  11746. ctx.strokeStyle = color(ctx.strokeStyle).alpha(ratio).rgbString();
  11747. ctx.fillStyle = color(ctx.fillStyle).alpha(ratio).rgbString();
  11748. }
  11749. helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y);
  11750. }
  11751. });
  11752. },{"25":25,"26":26,"45":45}],39:[function(require,module,exports){
  11753. 'use strict';
  11754. var defaults = require(25);
  11755. var Element = require(26);
  11756. defaults._set('global', {
  11757. elements: {
  11758. rectangle: {
  11759. backgroundColor: defaults.global.defaultColor,
  11760. borderColor: defaults.global.defaultColor,
  11761. borderSkipped: 'bottom',
  11762. borderWidth: 0
  11763. }
  11764. }
  11765. });
  11766. function isVertical(bar) {
  11767. return bar._view.width !== undefined;
  11768. }
  11769. /**
  11770. * Helper function to get the bounds of the bar regardless of the orientation
  11771. * @param bar {Chart.Element.Rectangle} the bar
  11772. * @return {Bounds} bounds of the bar
  11773. * @private
  11774. */
  11775. function getBarBounds(bar) {
  11776. var vm = bar._view;
  11777. var x1, x2, y1, y2;
  11778. if (isVertical(bar)) {
  11779. // vertical
  11780. var halfWidth = vm.width / 2;
  11781. x1 = vm.x - halfWidth;
  11782. x2 = vm.x + halfWidth;
  11783. y1 = Math.min(vm.y, vm.base);
  11784. y2 = Math.max(vm.y, vm.base);
  11785. } else {
  11786. // horizontal bar
  11787. var halfHeight = vm.height / 2;
  11788. x1 = Math.min(vm.x, vm.base);
  11789. x2 = Math.max(vm.x, vm.base);
  11790. y1 = vm.y - halfHeight;
  11791. y2 = vm.y + halfHeight;
  11792. }
  11793. return {
  11794. left: x1,
  11795. top: y1,
  11796. right: x2,
  11797. bottom: y2
  11798. };
  11799. }
  11800. module.exports = Element.extend({
  11801. draw: function() {
  11802. var ctx = this._chart.ctx;
  11803. var vm = this._view;
  11804. var left, right, top, bottom, signX, signY, borderSkipped;
  11805. var borderWidth = vm.borderWidth;
  11806. if (!vm.horizontal) {
  11807. // bar
  11808. left = vm.x - vm.width / 2;
  11809. right = vm.x + vm.width / 2;
  11810. top = vm.y;
  11811. bottom = vm.base;
  11812. signX = 1;
  11813. signY = bottom > top ? 1 : -1;
  11814. borderSkipped = vm.borderSkipped || 'bottom';
  11815. } else {
  11816. // horizontal bar
  11817. left = vm.base;
  11818. right = vm.x;
  11819. top = vm.y - vm.height / 2;
  11820. bottom = vm.y + vm.height / 2;
  11821. signX = right > left ? 1 : -1;
  11822. signY = 1;
  11823. borderSkipped = vm.borderSkipped || 'left';
  11824. }
  11825. // Canvas doesn't allow us to stroke inside the width so we can
  11826. // adjust the sizes to fit if we're setting a stroke on the line
  11827. if (borderWidth) {
  11828. // borderWidth shold be less than bar width and bar height.
  11829. var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
  11830. borderWidth = borderWidth > barSize ? barSize : borderWidth;
  11831. var halfStroke = borderWidth / 2;
  11832. // Adjust borderWidth when bar top position is near vm.base(zero).
  11833. var borderLeft = left + (borderSkipped !== 'left' ? halfStroke * signX : 0);
  11834. var borderRight = right + (borderSkipped !== 'right' ? -halfStroke * signX : 0);
  11835. var borderTop = top + (borderSkipped !== 'top' ? halfStroke * signY : 0);
  11836. var borderBottom = bottom + (borderSkipped !== 'bottom' ? -halfStroke * signY : 0);
  11837. // not become a vertical line?
  11838. if (borderLeft !== borderRight) {
  11839. top = borderTop;
  11840. bottom = borderBottom;
  11841. }
  11842. // not become a horizontal line?
  11843. if (borderTop !== borderBottom) {
  11844. left = borderLeft;
  11845. right = borderRight;
  11846. }
  11847. }
  11848. ctx.beginPath();
  11849. ctx.fillStyle = vm.backgroundColor;
  11850. ctx.strokeStyle = vm.borderColor;
  11851. ctx.lineWidth = borderWidth;
  11852. // Corner points, from bottom-left to bottom-right clockwise
  11853. // | 1 2 |
  11854. // | 0 3 |
  11855. var corners = [
  11856. [left, bottom],
  11857. [left, top],
  11858. [right, top],
  11859. [right, bottom]
  11860. ];
  11861. // Find first (starting) corner with fallback to 'bottom'
  11862. var borders = ['bottom', 'left', 'top', 'right'];
  11863. var startCorner = borders.indexOf(borderSkipped, 0);
  11864. if (startCorner === -1) {
  11865. startCorner = 0;
  11866. }
  11867. function cornerAt(index) {
  11868. return corners[(startCorner + index) % 4];
  11869. }
  11870. // Draw rectangle from 'startCorner'
  11871. var corner = cornerAt(0);
  11872. ctx.moveTo(corner[0], corner[1]);
  11873. for (var i = 1; i < 4; i++) {
  11874. corner = cornerAt(i);
  11875. ctx.lineTo(corner[0], corner[1]);
  11876. }
  11877. ctx.fill();
  11878. if (borderWidth) {
  11879. ctx.stroke();
  11880. }
  11881. },
  11882. height: function() {
  11883. var vm = this._view;
  11884. return vm.base - vm.y;
  11885. },
  11886. inRange: function(mouseX, mouseY) {
  11887. var inRange = false;
  11888. if (this._view) {
  11889. var bounds = getBarBounds(this);
  11890. inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
  11891. }
  11892. return inRange;
  11893. },
  11894. inLabelRange: function(mouseX, mouseY) {
  11895. var me = this;
  11896. if (!me._view) {
  11897. return false;
  11898. }
  11899. var inRange = false;
  11900. var bounds = getBarBounds(me);
  11901. if (isVertical(me)) {
  11902. inRange = mouseX >= bounds.left && mouseX <= bounds.right;
  11903. } else {
  11904. inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
  11905. }
  11906. return inRange;
  11907. },
  11908. inXRange: function(mouseX) {
  11909. var bounds = getBarBounds(this);
  11910. return mouseX >= bounds.left && mouseX <= bounds.right;
  11911. },
  11912. inYRange: function(mouseY) {
  11913. var bounds = getBarBounds(this);
  11914. return mouseY >= bounds.top && mouseY <= bounds.bottom;
  11915. },
  11916. getCenterPoint: function() {
  11917. var vm = this._view;
  11918. var x, y;
  11919. if (isVertical(this)) {
  11920. x = vm.x;
  11921. y = (vm.y + vm.base) / 2;
  11922. } else {
  11923. x = (vm.x + vm.base) / 2;
  11924. y = vm.y;
  11925. }
  11926. return {x: x, y: y};
  11927. },
  11928. getArea: function() {
  11929. var vm = this._view;
  11930. return vm.width * Math.abs(vm.y - vm.base);
  11931. },
  11932. tooltipPosition: function() {
  11933. var vm = this._view;
  11934. return {
  11935. x: vm.x,
  11936. y: vm.y
  11937. };
  11938. }
  11939. });
  11940. },{"25":25,"26":26}],40:[function(require,module,exports){
  11941. 'use strict';
  11942. module.exports = {};
  11943. module.exports.Arc = require(36);
  11944. module.exports.Line = require(37);
  11945. module.exports.Point = require(38);
  11946. module.exports.Rectangle = require(39);
  11947. },{"36":36,"37":37,"38":38,"39":39}],41:[function(require,module,exports){
  11948. 'use strict';
  11949. var helpers = require(42);
  11950. /**
  11951. * @namespace Chart.helpers.canvas
  11952. */
  11953. var exports = module.exports = {
  11954. /**
  11955. * Clears the entire canvas associated to the given `chart`.
  11956. * @param {Chart} chart - The chart for which to clear the canvas.
  11957. */
  11958. clear: function(chart) {
  11959. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  11960. },
  11961. /**
  11962. * Creates a "path" for a rectangle with rounded corners at position (x, y) with a
  11963. * given size (width, height) and the same `radius` for all corners.
  11964. * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context.
  11965. * @param {Number} x - The x axis of the coordinate for the rectangle starting point.
  11966. * @param {Number} y - The y axis of the coordinate for the rectangle starting point.
  11967. * @param {Number} width - The rectangle's width.
  11968. * @param {Number} height - The rectangle's height.
  11969. * @param {Number} radius - The rounded amount (in pixels) for the four corners.
  11970. * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
  11971. */
  11972. roundedRect: function(ctx, x, y, width, height, radius) {
  11973. if (radius) {
  11974. var rx = Math.min(radius, width / 2);
  11975. var ry = Math.min(radius, height / 2);
  11976. ctx.moveTo(x + rx, y);
  11977. ctx.lineTo(x + width - rx, y);
  11978. ctx.quadraticCurveTo(x + width, y, x + width, y + ry);
  11979. ctx.lineTo(x + width, y + height - ry);
  11980. ctx.quadraticCurveTo(x + width, y + height, x + width - rx, y + height);
  11981. ctx.lineTo(x + rx, y + height);
  11982. ctx.quadraticCurveTo(x, y + height, x, y + height - ry);
  11983. ctx.lineTo(x, y + ry);
  11984. ctx.quadraticCurveTo(x, y, x + rx, y);
  11985. } else {
  11986. ctx.rect(x, y, width, height);
  11987. }
  11988. },
  11989. drawPoint: function(ctx, style, radius, x, y) {
  11990. var type, edgeLength, xOffset, yOffset, height, size;
  11991. if (style && typeof style === 'object') {
  11992. type = style.toString();
  11993. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  11994. ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
  11995. return;
  11996. }
  11997. }
  11998. if (isNaN(radius) || radius <= 0) {
  11999. return;
  12000. }
  12001. switch (style) {
  12002. // Default includes circle
  12003. default:
  12004. ctx.beginPath();
  12005. ctx.arc(x, y, radius, 0, Math.PI * 2);
  12006. ctx.closePath();
  12007. ctx.fill();
  12008. break;
  12009. case 'triangle':
  12010. ctx.beginPath();
  12011. edgeLength = 3 * radius / Math.sqrt(3);
  12012. height = edgeLength * Math.sqrt(3) / 2;
  12013. ctx.moveTo(x - edgeLength / 2, y + height / 3);
  12014. ctx.lineTo(x + edgeLength / 2, y + height / 3);
  12015. ctx.lineTo(x, y - 2 * height / 3);
  12016. ctx.closePath();
  12017. ctx.fill();
  12018. break;
  12019. case 'rect':
  12020. size = 1 / Math.SQRT2 * radius;
  12021. ctx.beginPath();
  12022. ctx.fillRect(x - size, y - size, 2 * size, 2 * size);
  12023. ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
  12024. break;
  12025. case 'rectRounded':
  12026. var offset = radius / Math.SQRT2;
  12027. var leftX = x - offset;
  12028. var topY = y - offset;
  12029. var sideSize = Math.SQRT2 * radius;
  12030. ctx.beginPath();
  12031. this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius / 2);
  12032. ctx.closePath();
  12033. ctx.fill();
  12034. break;
  12035. case 'rectRot':
  12036. size = 1 / Math.SQRT2 * radius;
  12037. ctx.beginPath();
  12038. ctx.moveTo(x - size, y);
  12039. ctx.lineTo(x, y + size);
  12040. ctx.lineTo(x + size, y);
  12041. ctx.lineTo(x, y - size);
  12042. ctx.closePath();
  12043. ctx.fill();
  12044. break;
  12045. case 'cross':
  12046. ctx.beginPath();
  12047. ctx.moveTo(x, y + radius);
  12048. ctx.lineTo(x, y - radius);
  12049. ctx.moveTo(x - radius, y);
  12050. ctx.lineTo(x + radius, y);
  12051. ctx.closePath();
  12052. break;
  12053. case 'crossRot':
  12054. ctx.beginPath();
  12055. xOffset = Math.cos(Math.PI / 4) * radius;
  12056. yOffset = Math.sin(Math.PI / 4) * radius;
  12057. ctx.moveTo(x - xOffset, y - yOffset);
  12058. ctx.lineTo(x + xOffset, y + yOffset);
  12059. ctx.moveTo(x - xOffset, y + yOffset);
  12060. ctx.lineTo(x + xOffset, y - yOffset);
  12061. ctx.closePath();
  12062. break;
  12063. case 'star':
  12064. ctx.beginPath();
  12065. ctx.moveTo(x, y + radius);
  12066. ctx.lineTo(x, y - radius);
  12067. ctx.moveTo(x - radius, y);
  12068. ctx.lineTo(x + radius, y);
  12069. xOffset = Math.cos(Math.PI / 4) * radius;
  12070. yOffset = Math.sin(Math.PI / 4) * radius;
  12071. ctx.moveTo(x - xOffset, y - yOffset);
  12072. ctx.lineTo(x + xOffset, y + yOffset);
  12073. ctx.moveTo(x - xOffset, y + yOffset);
  12074. ctx.lineTo(x + xOffset, y - yOffset);
  12075. ctx.closePath();
  12076. break;
  12077. case 'line':
  12078. ctx.beginPath();
  12079. ctx.moveTo(x - radius, y);
  12080. ctx.lineTo(x + radius, y);
  12081. ctx.closePath();
  12082. break;
  12083. case 'dash':
  12084. ctx.beginPath();
  12085. ctx.moveTo(x, y);
  12086. ctx.lineTo(x + radius, y);
  12087. ctx.closePath();
  12088. break;
  12089. }
  12090. ctx.stroke();
  12091. },
  12092. clipArea: function(ctx, area) {
  12093. ctx.save();
  12094. ctx.beginPath();
  12095. ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
  12096. ctx.clip();
  12097. },
  12098. unclipArea: function(ctx) {
  12099. ctx.restore();
  12100. },
  12101. lineTo: function(ctx, previous, target, flip) {
  12102. if (target.steppedLine) {
  12103. if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
  12104. ctx.lineTo(previous.x, target.y);
  12105. } else {
  12106. ctx.lineTo(target.x, previous.y);
  12107. }
  12108. ctx.lineTo(target.x, target.y);
  12109. return;
  12110. }
  12111. if (!target.tension) {
  12112. ctx.lineTo(target.x, target.y);
  12113. return;
  12114. }
  12115. ctx.bezierCurveTo(
  12116. flip ? previous.controlPointPreviousX : previous.controlPointNextX,
  12117. flip ? previous.controlPointPreviousY : previous.controlPointNextY,
  12118. flip ? target.controlPointNextX : target.controlPointPreviousX,
  12119. flip ? target.controlPointNextY : target.controlPointPreviousY,
  12120. target.x,
  12121. target.y);
  12122. }
  12123. };
  12124. // DEPRECATIONS
  12125. /**
  12126. * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
  12127. * @namespace Chart.helpers.clear
  12128. * @deprecated since version 2.7.0
  12129. * @todo remove at version 3
  12130. * @private
  12131. */
  12132. helpers.clear = exports.clear;
  12133. /**
  12134. * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
  12135. * @namespace Chart.helpers.drawRoundedRectangle
  12136. * @deprecated since version 2.7.0
  12137. * @todo remove at version 3
  12138. * @private
  12139. */
  12140. helpers.drawRoundedRectangle = function(ctx) {
  12141. ctx.beginPath();
  12142. exports.roundedRect.apply(exports, arguments);
  12143. ctx.closePath();
  12144. };
  12145. },{"42":42}],42:[function(require,module,exports){
  12146. 'use strict';
  12147. /**
  12148. * @namespace Chart.helpers
  12149. */
  12150. var helpers = {
  12151. /**
  12152. * An empty function that can be used, for example, for optional callback.
  12153. */
  12154. noop: function() {},
  12155. /**
  12156. * Returns a unique id, sequentially generated from a global variable.
  12157. * @returns {Number}
  12158. * @function
  12159. */
  12160. uid: (function() {
  12161. var id = 0;
  12162. return function() {
  12163. return id++;
  12164. };
  12165. }()),
  12166. /**
  12167. * Returns true if `value` is neither null nor undefined, else returns false.
  12168. * @param {*} value - The value to test.
  12169. * @returns {Boolean}
  12170. * @since 2.7.0
  12171. */
  12172. isNullOrUndef: function(value) {
  12173. return value === null || typeof value === 'undefined';
  12174. },
  12175. /**
  12176. * Returns true if `value` is an array, else returns false.
  12177. * @param {*} value - The value to test.
  12178. * @returns {Boolean}
  12179. * @function
  12180. */
  12181. isArray: Array.isArray ? Array.isArray : function(value) {
  12182. return Object.prototype.toString.call(value) === '[object Array]';
  12183. },
  12184. /**
  12185. * Returns true if `value` is an object (excluding null), else returns false.
  12186. * @param {*} value - The value to test.
  12187. * @returns {Boolean}
  12188. * @since 2.7.0
  12189. */
  12190. isObject: function(value) {
  12191. return value !== null && Object.prototype.toString.call(value) === '[object Object]';
  12192. },
  12193. /**
  12194. * Returns `value` if defined, else returns `defaultValue`.
  12195. * @param {*} value - The value to return if defined.
  12196. * @param {*} defaultValue - The value to return if `value` is undefined.
  12197. * @returns {*}
  12198. */
  12199. valueOrDefault: function(value, defaultValue) {
  12200. return typeof value === 'undefined' ? defaultValue : value;
  12201. },
  12202. /**
  12203. * Returns value at the given `index` in array if defined, else returns `defaultValue`.
  12204. * @param {Array} value - The array to lookup for value at `index`.
  12205. * @param {Number} index - The index in `value` to lookup for value.
  12206. * @param {*} defaultValue - The value to return if `value[index]` is undefined.
  12207. * @returns {*}
  12208. */
  12209. valueAtIndexOrDefault: function(value, index, defaultValue) {
  12210. return helpers.valueOrDefault(helpers.isArray(value) ? value[index] : value, defaultValue);
  12211. },
  12212. /**
  12213. * Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
  12214. * value returned by `fn`. If `fn` is not a function, this method returns undefined.
  12215. * @param {Function} fn - The function to call.
  12216. * @param {Array|undefined|null} args - The arguments with which `fn` should be called.
  12217. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  12218. * @returns {*}
  12219. */
  12220. callback: function(fn, args, thisArg) {
  12221. if (fn && typeof fn.call === 'function') {
  12222. return fn.apply(thisArg, args);
  12223. }
  12224. },
  12225. /**
  12226. * Note(SB) for performance sake, this method should only be used when loopable type
  12227. * is unknown or in none intensive code (not called often and small loopable). Else
  12228. * it's preferable to use a regular for() loop and save extra function calls.
  12229. * @param {Object|Array} loopable - The object or array to be iterated.
  12230. * @param {Function} fn - The function to call for each item.
  12231. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  12232. * @param {Boolean} [reverse] - If true, iterates backward on the loopable.
  12233. */
  12234. each: function(loopable, fn, thisArg, reverse) {
  12235. var i, len, keys;
  12236. if (helpers.isArray(loopable)) {
  12237. len = loopable.length;
  12238. if (reverse) {
  12239. for (i = len - 1; i >= 0; i--) {
  12240. fn.call(thisArg, loopable[i], i);
  12241. }
  12242. } else {
  12243. for (i = 0; i < len; i++) {
  12244. fn.call(thisArg, loopable[i], i);
  12245. }
  12246. }
  12247. } else if (helpers.isObject(loopable)) {
  12248. keys = Object.keys(loopable);
  12249. len = keys.length;
  12250. for (i = 0; i < len; i++) {
  12251. fn.call(thisArg, loopable[keys[i]], keys[i]);
  12252. }
  12253. }
  12254. },
  12255. /**
  12256. * Returns true if the `a0` and `a1` arrays have the same content, else returns false.
  12257. * @see http://stackoverflow.com/a/14853974
  12258. * @param {Array} a0 - The array to compare
  12259. * @param {Array} a1 - The array to compare
  12260. * @returns {Boolean}
  12261. */
  12262. arrayEquals: function(a0, a1) {
  12263. var i, ilen, v0, v1;
  12264. if (!a0 || !a1 || a0.length !== a1.length) {
  12265. return false;
  12266. }
  12267. for (i = 0, ilen = a0.length; i < ilen; ++i) {
  12268. v0 = a0[i];
  12269. v1 = a1[i];
  12270. if (v0 instanceof Array && v1 instanceof Array) {
  12271. if (!helpers.arrayEquals(v0, v1)) {
  12272. return false;
  12273. }
  12274. } else if (v0 !== v1) {
  12275. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  12276. return false;
  12277. }
  12278. }
  12279. return true;
  12280. },
  12281. /**
  12282. * Returns a deep copy of `source` without keeping references on objects and arrays.
  12283. * @param {*} source - The value to clone.
  12284. * @returns {*}
  12285. */
  12286. clone: function(source) {
  12287. if (helpers.isArray(source)) {
  12288. return source.map(helpers.clone);
  12289. }
  12290. if (helpers.isObject(source)) {
  12291. var target = {};
  12292. var keys = Object.keys(source);
  12293. var klen = keys.length;
  12294. var k = 0;
  12295. for (; k < klen; ++k) {
  12296. target[keys[k]] = helpers.clone(source[keys[k]]);
  12297. }
  12298. return target;
  12299. }
  12300. return source;
  12301. },
  12302. /**
  12303. * The default merger when Chart.helpers.merge is called without merger option.
  12304. * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
  12305. * @private
  12306. */
  12307. _merger: function(key, target, source, options) {
  12308. var tval = target[key];
  12309. var sval = source[key];
  12310. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  12311. helpers.merge(tval, sval, options);
  12312. } else {
  12313. target[key] = helpers.clone(sval);
  12314. }
  12315. },
  12316. /**
  12317. * Merges source[key] in target[key] only if target[key] is undefined.
  12318. * @private
  12319. */
  12320. _mergerIf: function(key, target, source) {
  12321. var tval = target[key];
  12322. var sval = source[key];
  12323. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  12324. helpers.mergeIf(tval, sval);
  12325. } else if (!target.hasOwnProperty(key)) {
  12326. target[key] = helpers.clone(sval);
  12327. }
  12328. },
  12329. /**
  12330. * Recursively deep copies `source` properties into `target` with the given `options`.
  12331. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  12332. * @param {Object} target - The target object in which all sources are merged into.
  12333. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  12334. * @param {Object} [options] - Merging options:
  12335. * @param {Function} [options.merger] - The merge method (key, target, source, options)
  12336. * @returns {Object} The `target` object.
  12337. */
  12338. merge: function(target, source, options) {
  12339. var sources = helpers.isArray(source) ? source : [source];
  12340. var ilen = sources.length;
  12341. var merge, i, keys, klen, k;
  12342. if (!helpers.isObject(target)) {
  12343. return target;
  12344. }
  12345. options = options || {};
  12346. merge = options.merger || helpers._merger;
  12347. for (i = 0; i < ilen; ++i) {
  12348. source = sources[i];
  12349. if (!helpers.isObject(source)) {
  12350. continue;
  12351. }
  12352. keys = Object.keys(source);
  12353. for (k = 0, klen = keys.length; k < klen; ++k) {
  12354. merge(keys[k], target, source, options);
  12355. }
  12356. }
  12357. return target;
  12358. },
  12359. /**
  12360. * Recursively deep copies `source` properties into `target` *only* if not defined in target.
  12361. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  12362. * @param {Object} target - The target object in which all sources are merged into.
  12363. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  12364. * @returns {Object} The `target` object.
  12365. */
  12366. mergeIf: function(target, source) {
  12367. return helpers.merge(target, source, {merger: helpers._mergerIf});
  12368. },
  12369. /**
  12370. * Applies the contents of two or more objects together into the first object.
  12371. * @param {Object} target - The target object in which all objects are merged into.
  12372. * @param {Object} arg1 - Object containing additional properties to merge in target.
  12373. * @param {Object} argN - Additional objects containing properties to merge in target.
  12374. * @returns {Object} The `target` object.
  12375. */
  12376. extend: function(target) {
  12377. var setFn = function(value, key) {
  12378. target[key] = value;
  12379. };
  12380. for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
  12381. helpers.each(arguments[i], setFn);
  12382. }
  12383. return target;
  12384. },
  12385. /**
  12386. * Basic javascript inheritance based on the model created in Backbone.js
  12387. */
  12388. inherits: function(extensions) {
  12389. var me = this;
  12390. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
  12391. return me.apply(this, arguments);
  12392. };
  12393. var Surrogate = function() {
  12394. this.constructor = ChartElement;
  12395. };
  12396. Surrogate.prototype = me.prototype;
  12397. ChartElement.prototype = new Surrogate();
  12398. ChartElement.extend = helpers.inherits;
  12399. if (extensions) {
  12400. helpers.extend(ChartElement.prototype, extensions);
  12401. }
  12402. ChartElement.__super__ = me.prototype;
  12403. return ChartElement;
  12404. }
  12405. };
  12406. module.exports = helpers;
  12407. // DEPRECATIONS
  12408. /**
  12409. * Provided for backward compatibility, use Chart.helpers.callback instead.
  12410. * @function Chart.helpers.callCallback
  12411. * @deprecated since version 2.6.0
  12412. * @todo remove at version 3
  12413. * @private
  12414. */
  12415. helpers.callCallback = helpers.callback;
  12416. /**
  12417. * Provided for backward compatibility, use Array.prototype.indexOf instead.
  12418. * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
  12419. * @function Chart.helpers.indexOf
  12420. * @deprecated since version 2.7.0
  12421. * @todo remove at version 3
  12422. * @private
  12423. */
  12424. helpers.indexOf = function(array, item, fromIndex) {
  12425. return Array.prototype.indexOf.call(array, item, fromIndex);
  12426. };
  12427. /**
  12428. * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
  12429. * @function Chart.helpers.getValueOrDefault
  12430. * @deprecated since version 2.7.0
  12431. * @todo remove at version 3
  12432. * @private
  12433. */
  12434. helpers.getValueOrDefault = helpers.valueOrDefault;
  12435. /**
  12436. * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
  12437. * @function Chart.helpers.getValueAtIndexOrDefault
  12438. * @deprecated since version 2.7.0
  12439. * @todo remove at version 3
  12440. * @private
  12441. */
  12442. helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  12443. },{}],43:[function(require,module,exports){
  12444. 'use strict';
  12445. var helpers = require(42);
  12446. /**
  12447. * Easing functions adapted from Robert Penner's easing equations.
  12448. * @namespace Chart.helpers.easingEffects
  12449. * @see http://www.robertpenner.com/easing/
  12450. */
  12451. var effects = {
  12452. linear: function(t) {
  12453. return t;
  12454. },
  12455. easeInQuad: function(t) {
  12456. return t * t;
  12457. },
  12458. easeOutQuad: function(t) {
  12459. return -t * (t - 2);
  12460. },
  12461. easeInOutQuad: function(t) {
  12462. if ((t /= 0.5) < 1) {
  12463. return 0.5 * t * t;
  12464. }
  12465. return -0.5 * ((--t) * (t - 2) - 1);
  12466. },
  12467. easeInCubic: function(t) {
  12468. return t * t * t;
  12469. },
  12470. easeOutCubic: function(t) {
  12471. return (t = t - 1) * t * t + 1;
  12472. },
  12473. easeInOutCubic: function(t) {
  12474. if ((t /= 0.5) < 1) {
  12475. return 0.5 * t * t * t;
  12476. }
  12477. return 0.5 * ((t -= 2) * t * t + 2);
  12478. },
  12479. easeInQuart: function(t) {
  12480. return t * t * t * t;
  12481. },
  12482. easeOutQuart: function(t) {
  12483. return -((t = t - 1) * t * t * t - 1);
  12484. },
  12485. easeInOutQuart: function(t) {
  12486. if ((t /= 0.5) < 1) {
  12487. return 0.5 * t * t * t * t;
  12488. }
  12489. return -0.5 * ((t -= 2) * t * t * t - 2);
  12490. },
  12491. easeInQuint: function(t) {
  12492. return t * t * t * t * t;
  12493. },
  12494. easeOutQuint: function(t) {
  12495. return (t = t - 1) * t * t * t * t + 1;
  12496. },
  12497. easeInOutQuint: function(t) {
  12498. if ((t /= 0.5) < 1) {
  12499. return 0.5 * t * t * t * t * t;
  12500. }
  12501. return 0.5 * ((t -= 2) * t * t * t * t + 2);
  12502. },
  12503. easeInSine: function(t) {
  12504. return -Math.cos(t * (Math.PI / 2)) + 1;
  12505. },
  12506. easeOutSine: function(t) {
  12507. return Math.sin(t * (Math.PI / 2));
  12508. },
  12509. easeInOutSine: function(t) {
  12510. return -0.5 * (Math.cos(Math.PI * t) - 1);
  12511. },
  12512. easeInExpo: function(t) {
  12513. return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
  12514. },
  12515. easeOutExpo: function(t) {
  12516. return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
  12517. },
  12518. easeInOutExpo: function(t) {
  12519. if (t === 0) {
  12520. return 0;
  12521. }
  12522. if (t === 1) {
  12523. return 1;
  12524. }
  12525. if ((t /= 0.5) < 1) {
  12526. return 0.5 * Math.pow(2, 10 * (t - 1));
  12527. }
  12528. return 0.5 * (-Math.pow(2, -10 * --t) + 2);
  12529. },
  12530. easeInCirc: function(t) {
  12531. if (t >= 1) {
  12532. return t;
  12533. }
  12534. return -(Math.sqrt(1 - t * t) - 1);
  12535. },
  12536. easeOutCirc: function(t) {
  12537. return Math.sqrt(1 - (t = t - 1) * t);
  12538. },
  12539. easeInOutCirc: function(t) {
  12540. if ((t /= 0.5) < 1) {
  12541. return -0.5 * (Math.sqrt(1 - t * t) - 1);
  12542. }
  12543. return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  12544. },
  12545. easeInElastic: function(t) {
  12546. var s = 1.70158;
  12547. var p = 0;
  12548. var a = 1;
  12549. if (t === 0) {
  12550. return 0;
  12551. }
  12552. if (t === 1) {
  12553. return 1;
  12554. }
  12555. if (!p) {
  12556. p = 0.3;
  12557. }
  12558. if (a < 1) {
  12559. a = 1;
  12560. s = p / 4;
  12561. } else {
  12562. s = p / (2 * Math.PI) * Math.asin(1 / a);
  12563. }
  12564. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  12565. },
  12566. easeOutElastic: function(t) {
  12567. var s = 1.70158;
  12568. var p = 0;
  12569. var a = 1;
  12570. if (t === 0) {
  12571. return 0;
  12572. }
  12573. if (t === 1) {
  12574. return 1;
  12575. }
  12576. if (!p) {
  12577. p = 0.3;
  12578. }
  12579. if (a < 1) {
  12580. a = 1;
  12581. s = p / 4;
  12582. } else {
  12583. s = p / (2 * Math.PI) * Math.asin(1 / a);
  12584. }
  12585. return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
  12586. },
  12587. easeInOutElastic: function(t) {
  12588. var s = 1.70158;
  12589. var p = 0;
  12590. var a = 1;
  12591. if (t === 0) {
  12592. return 0;
  12593. }
  12594. if ((t /= 0.5) === 2) {
  12595. return 1;
  12596. }
  12597. if (!p) {
  12598. p = 0.45;
  12599. }
  12600. if (a < 1) {
  12601. a = 1;
  12602. s = p / 4;
  12603. } else {
  12604. s = p / (2 * Math.PI) * Math.asin(1 / a);
  12605. }
  12606. if (t < 1) {
  12607. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  12608. }
  12609. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
  12610. },
  12611. easeInBack: function(t) {
  12612. var s = 1.70158;
  12613. return t * t * ((s + 1) * t - s);
  12614. },
  12615. easeOutBack: function(t) {
  12616. var s = 1.70158;
  12617. return (t = t - 1) * t * ((s + 1) * t + s) + 1;
  12618. },
  12619. easeInOutBack: function(t) {
  12620. var s = 1.70158;
  12621. if ((t /= 0.5) < 1) {
  12622. return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
  12623. }
  12624. return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  12625. },
  12626. easeInBounce: function(t) {
  12627. return 1 - effects.easeOutBounce(1 - t);
  12628. },
  12629. easeOutBounce: function(t) {
  12630. if (t < (1 / 2.75)) {
  12631. return 7.5625 * t * t;
  12632. }
  12633. if (t < (2 / 2.75)) {
  12634. return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
  12635. }
  12636. if (t < (2.5 / 2.75)) {
  12637. return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
  12638. }
  12639. return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
  12640. },
  12641. easeInOutBounce: function(t) {
  12642. if (t < 0.5) {
  12643. return effects.easeInBounce(t * 2) * 0.5;
  12644. }
  12645. return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
  12646. }
  12647. };
  12648. module.exports = {
  12649. effects: effects
  12650. };
  12651. // DEPRECATIONS
  12652. /**
  12653. * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
  12654. * @function Chart.helpers.easingEffects
  12655. * @deprecated since version 2.7.0
  12656. * @todo remove at version 3
  12657. * @private
  12658. */
  12659. helpers.easingEffects = effects;
  12660. },{"42":42}],44:[function(require,module,exports){
  12661. 'use strict';
  12662. var helpers = require(42);
  12663. /**
  12664. * @alias Chart.helpers.options
  12665. * @namespace
  12666. */
  12667. module.exports = {
  12668. /**
  12669. * Converts the given line height `value` in pixels for a specific font `size`.
  12670. * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
  12671. * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
  12672. * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
  12673. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
  12674. * @since 2.7.0
  12675. */
  12676. toLineHeight: function(value, size) {
  12677. var matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
  12678. if (!matches || matches[1] === 'normal') {
  12679. return size * 1.2;
  12680. }
  12681. value = +matches[2];
  12682. switch (matches[3]) {
  12683. case 'px':
  12684. return value;
  12685. case '%':
  12686. value /= 100;
  12687. break;
  12688. default:
  12689. break;
  12690. }
  12691. return size * value;
  12692. },
  12693. /**
  12694. * Converts the given value into a padding object with pre-computed width/height.
  12695. * @param {Number|Object} value - If a number, set the value to all TRBL component,
  12696. * else, if and object, use defined properties and sets undefined ones to 0.
  12697. * @returns {Object} The padding values (top, right, bottom, left, width, height)
  12698. * @since 2.7.0
  12699. */
  12700. toPadding: function(value) {
  12701. var t, r, b, l;
  12702. if (helpers.isObject(value)) {
  12703. t = +value.top || 0;
  12704. r = +value.right || 0;
  12705. b = +value.bottom || 0;
  12706. l = +value.left || 0;
  12707. } else {
  12708. t = r = b = l = +value || 0;
  12709. }
  12710. return {
  12711. top: t,
  12712. right: r,
  12713. bottom: b,
  12714. left: l,
  12715. height: t + b,
  12716. width: l + r
  12717. };
  12718. },
  12719. /**
  12720. * Evaluates the given `inputs` sequentially and returns the first defined value.
  12721. * @param {Array[]} inputs - An array of values, falling back to the last value.
  12722. * @param {Object} [context] - If defined and the current value is a function, the value
  12723. * is called with `context` as first argument and the result becomes the new input.
  12724. * @param {Number} [index] - If defined and the current value is an array, the value
  12725. * at `index` become the new input.
  12726. * @since 2.7.0
  12727. */
  12728. resolve: function(inputs, context, index) {
  12729. var i, ilen, value;
  12730. for (i = 0, ilen = inputs.length; i < ilen; ++i) {
  12731. value = inputs[i];
  12732. if (value === undefined) {
  12733. continue;
  12734. }
  12735. if (context !== undefined && typeof value === 'function') {
  12736. value = value(context);
  12737. }
  12738. if (index !== undefined && helpers.isArray(value)) {
  12739. value = value[index];
  12740. }
  12741. if (value !== undefined) {
  12742. return value;
  12743. }
  12744. }
  12745. }
  12746. };
  12747. },{"42":42}],45:[function(require,module,exports){
  12748. 'use strict';
  12749. module.exports = require(42);
  12750. module.exports.easing = require(43);
  12751. module.exports.canvas = require(41);
  12752. module.exports.options = require(44);
  12753. },{"41":41,"42":42,"43":43,"44":44}],46:[function(require,module,exports){
  12754. /**
  12755. * Platform fallback implementation (minimal).
  12756. * @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
  12757. */
  12758. module.exports = {
  12759. acquireContext: function(item) {
  12760. if (item && item.canvas) {
  12761. // Support for any object associated to a canvas (including a context2d)
  12762. item = item.canvas;
  12763. }
  12764. return item && item.getContext('2d') || null;
  12765. }
  12766. };
  12767. },{}],47:[function(require,module,exports){
  12768. /**
  12769. * Chart.Platform implementation for targeting a web browser
  12770. */
  12771. 'use strict';
  12772. var helpers = require(45);
  12773. var EXPANDO_KEY = '$chartjs';
  12774. var CSS_PREFIX = 'chartjs-';
  12775. var CSS_RENDER_MONITOR = CSS_PREFIX + 'render-monitor';
  12776. var CSS_RENDER_ANIMATION = CSS_PREFIX + 'render-animation';
  12777. var ANIMATION_START_EVENTS = ['animationstart', 'webkitAnimationStart'];
  12778. /**
  12779. * DOM event types -> Chart.js event types.
  12780. * Note: only events with different types are mapped.
  12781. * @see https://developer.mozilla.org/en-US/docs/Web/Events
  12782. */
  12783. var EVENT_TYPES = {
  12784. touchstart: 'mousedown',
  12785. touchmove: 'mousemove',
  12786. touchend: 'mouseup',
  12787. pointerenter: 'mouseenter',
  12788. pointerdown: 'mousedown',
  12789. pointermove: 'mousemove',
  12790. pointerup: 'mouseup',
  12791. pointerleave: 'mouseout',
  12792. pointerout: 'mouseout'
  12793. };
  12794. /**
  12795. * The "used" size is the final value of a dimension property after all calculations have
  12796. * been performed. This method uses the computed style of `element` but returns undefined
  12797. * if the computed style is not expressed in pixels. That can happen in some cases where
  12798. * `element` has a size relative to its parent and this last one is not yet displayed,
  12799. * for example because of `display: none` on a parent node.
  12800. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
  12801. * @returns {Number} Size in pixels or undefined if unknown.
  12802. */
  12803. function readUsedSize(element, property) {
  12804. var value = helpers.getStyle(element, property);
  12805. var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
  12806. return matches ? Number(matches[1]) : undefined;
  12807. }
  12808. /**
  12809. * Initializes the canvas style and render size without modifying the canvas display size,
  12810. * since responsiveness is handled by the controller.resize() method. The config is used
  12811. * to determine the aspect ratio to apply in case no explicit height has been specified.
  12812. */
  12813. function initCanvas(canvas, config) {
  12814. var style = canvas.style;
  12815. // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
  12816. // returns null or '' if no explicit value has been set to the canvas attribute.
  12817. var renderHeight = canvas.getAttribute('height');
  12818. var renderWidth = canvas.getAttribute('width');
  12819. // Chart.js modifies some canvas values that we want to restore on destroy
  12820. canvas[EXPANDO_KEY] = {
  12821. initial: {
  12822. height: renderHeight,
  12823. width: renderWidth,
  12824. style: {
  12825. display: style.display,
  12826. height: style.height,
  12827. width: style.width
  12828. }
  12829. }
  12830. };
  12831. // Force canvas to display as block to avoid extra space caused by inline
  12832. // elements, which would interfere with the responsive resize process.
  12833. // https://github.com/chartjs/Chart.js/issues/2538
  12834. style.display = style.display || 'block';
  12835. if (renderWidth === null || renderWidth === '') {
  12836. var displayWidth = readUsedSize(canvas, 'width');
  12837. if (displayWidth !== undefined) {
  12838. canvas.width = displayWidth;
  12839. }
  12840. }
  12841. if (renderHeight === null || renderHeight === '') {
  12842. if (canvas.style.height === '') {
  12843. // If no explicit render height and style height, let's apply the aspect ratio,
  12844. // which one can be specified by the user but also by charts as default option
  12845. // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
  12846. canvas.height = canvas.width / (config.options.aspectRatio || 2);
  12847. } else {
  12848. var displayHeight = readUsedSize(canvas, 'height');
  12849. if (displayWidth !== undefined) {
  12850. canvas.height = displayHeight;
  12851. }
  12852. }
  12853. }
  12854. return canvas;
  12855. }
  12856. /**
  12857. * Detects support for options object argument in addEventListener.
  12858. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  12859. * @private
  12860. */
  12861. var supportsEventListenerOptions = (function() {
  12862. var supports = false;
  12863. try {
  12864. var options = Object.defineProperty({}, 'passive', {
  12865. get: function() {
  12866. supports = true;
  12867. }
  12868. });
  12869. window.addEventListener('e', null, options);
  12870. } catch (e) {
  12871. // continue regardless of error
  12872. }
  12873. return supports;
  12874. }());
  12875. // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  12876. // https://github.com/chartjs/Chart.js/issues/4287
  12877. var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
  12878. function addEventListener(node, type, listener) {
  12879. node.addEventListener(type, listener, eventListenerOptions);
  12880. }
  12881. function removeEventListener(node, type, listener) {
  12882. node.removeEventListener(type, listener, eventListenerOptions);
  12883. }
  12884. function createEvent(type, chart, x, y, nativeEvent) {
  12885. return {
  12886. type: type,
  12887. chart: chart,
  12888. native: nativeEvent || null,
  12889. x: x !== undefined ? x : null,
  12890. y: y !== undefined ? y : null,
  12891. };
  12892. }
  12893. function fromNativeEvent(event, chart) {
  12894. var type = EVENT_TYPES[event.type] || event.type;
  12895. var pos = helpers.getRelativePosition(event, chart);
  12896. return createEvent(type, chart, pos.x, pos.y, event);
  12897. }
  12898. function throttled(fn, thisArg) {
  12899. var ticking = false;
  12900. var args = [];
  12901. return function() {
  12902. args = Array.prototype.slice.call(arguments);
  12903. thisArg = thisArg || this;
  12904. if (!ticking) {
  12905. ticking = true;
  12906. helpers.requestAnimFrame.call(window, function() {
  12907. ticking = false;
  12908. fn.apply(thisArg, args);
  12909. });
  12910. }
  12911. };
  12912. }
  12913. // Implementation based on https://github.com/marcj/css-element-queries
  12914. function createResizer(handler) {
  12915. var resizer = document.createElement('div');
  12916. var cls = CSS_PREFIX + 'size-monitor';
  12917. var maxSize = 1000000;
  12918. var style =
  12919. 'position:absolute;' +
  12920. 'left:0;' +
  12921. 'top:0;' +
  12922. 'right:0;' +
  12923. 'bottom:0;' +
  12924. 'overflow:hidden;' +
  12925. 'pointer-events:none;' +
  12926. 'visibility:hidden;' +
  12927. 'z-index:-1;';
  12928. resizer.style.cssText = style;
  12929. resizer.className = cls;
  12930. resizer.innerHTML =
  12931. '<div class="' + cls + '-expand" style="' + style + '">' +
  12932. '<div style="' +
  12933. 'position:absolute;' +
  12934. 'width:' + maxSize + 'px;' +
  12935. 'height:' + maxSize + 'px;' +
  12936. 'left:0;' +
  12937. 'top:0">' +
  12938. '</div>' +
  12939. '</div>' +
  12940. '<div class="' + cls + '-shrink" style="' + style + '">' +
  12941. '<div style="' +
  12942. 'position:absolute;' +
  12943. 'width:200%;' +
  12944. 'height:200%;' +
  12945. 'left:0; ' +
  12946. 'top:0">' +
  12947. '</div>' +
  12948. '</div>';
  12949. var expand = resizer.childNodes[0];
  12950. var shrink = resizer.childNodes[1];
  12951. resizer._reset = function() {
  12952. expand.scrollLeft = maxSize;
  12953. expand.scrollTop = maxSize;
  12954. shrink.scrollLeft = maxSize;
  12955. shrink.scrollTop = maxSize;
  12956. };
  12957. var onScroll = function() {
  12958. resizer._reset();
  12959. handler();
  12960. };
  12961. addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
  12962. addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
  12963. return resizer;
  12964. }
  12965. // https://davidwalsh.name/detect-node-insertion
  12966. function watchForRender(node, handler) {
  12967. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  12968. var proxy = expando.renderProxy = function(e) {
  12969. if (e.animationName === CSS_RENDER_ANIMATION) {
  12970. handler();
  12971. }
  12972. };
  12973. helpers.each(ANIMATION_START_EVENTS, function(type) {
  12974. addEventListener(node, type, proxy);
  12975. });
  12976. // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
  12977. // is removed then added back immediately (same animation frame?). Accessing the
  12978. // `offsetParent` property will force a reflow and re-evaluate the CSS animation.
  12979. // https://gist.github.com/paulirish/5d52fb081b3570c81e3a#box-metrics
  12980. // https://github.com/chartjs/Chart.js/issues/4737
  12981. expando.reflow = !!node.offsetParent;
  12982. node.classList.add(CSS_RENDER_MONITOR);
  12983. }
  12984. function unwatchForRender(node) {
  12985. var expando = node[EXPANDO_KEY] || {};
  12986. var proxy = expando.renderProxy;
  12987. if (proxy) {
  12988. helpers.each(ANIMATION_START_EVENTS, function(type) {
  12989. removeEventListener(node, type, proxy);
  12990. });
  12991. delete expando.renderProxy;
  12992. }
  12993. node.classList.remove(CSS_RENDER_MONITOR);
  12994. }
  12995. function addResizeListener(node, listener, chart) {
  12996. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  12997. // Let's keep track of this added resizer and thus avoid DOM query when removing it.
  12998. var resizer = expando.resizer = createResizer(throttled(function() {
  12999. if (expando.resizer) {
  13000. return listener(createEvent('resize', chart));
  13001. }
  13002. }));
  13003. // The resizer needs to be attached to the node parent, so we first need to be
  13004. // sure that `node` is attached to the DOM before injecting the resizer element.
  13005. watchForRender(node, function() {
  13006. if (expando.resizer) {
  13007. var container = node.parentNode;
  13008. if (container && container !== resizer.parentNode) {
  13009. container.insertBefore(resizer, container.firstChild);
  13010. }
  13011. // The container size might have changed, let's reset the resizer state.
  13012. resizer._reset();
  13013. }
  13014. });
  13015. }
  13016. function removeResizeListener(node) {
  13017. var expando = node[EXPANDO_KEY] || {};
  13018. var resizer = expando.resizer;
  13019. delete expando.resizer;
  13020. unwatchForRender(node);
  13021. if (resizer && resizer.parentNode) {
  13022. resizer.parentNode.removeChild(resizer);
  13023. }
  13024. }
  13025. function injectCSS(platform, css) {
  13026. // http://stackoverflow.com/q/3922139
  13027. var style = platform._style || document.createElement('style');
  13028. if (!platform._style) {
  13029. platform._style = style;
  13030. css = '/* Chart.js */\n' + css;
  13031. style.setAttribute('type', 'text/css');
  13032. document.getElementsByTagName('head')[0].appendChild(style);
  13033. }
  13034. style.appendChild(document.createTextNode(css));
  13035. }
  13036. module.exports = {
  13037. /**
  13038. * This property holds whether this platform is enabled for the current environment.
  13039. * Currently used by platform.js to select the proper implementation.
  13040. * @private
  13041. */
  13042. _enabled: typeof window !== 'undefined' && typeof document !== 'undefined',
  13043. initialize: function() {
  13044. var keyframes = 'from{opacity:0.99}to{opacity:1}';
  13045. injectCSS(this,
  13046. // DOM rendering detection
  13047. // https://davidwalsh.name/detect-node-insertion
  13048. '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  13049. '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  13050. '.' + CSS_RENDER_MONITOR + '{' +
  13051. '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  13052. 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  13053. '}'
  13054. );
  13055. },
  13056. acquireContext: function(item, config) {
  13057. if (typeof item === 'string') {
  13058. item = document.getElementById(item);
  13059. } else if (item.length) {
  13060. // Support for array based queries (such as jQuery)
  13061. item = item[0];
  13062. }
  13063. if (item && item.canvas) {
  13064. // Support for any object associated to a canvas (including a context2d)
  13065. item = item.canvas;
  13066. }
  13067. // To prevent canvas fingerprinting, some add-ons undefine the getContext
  13068. // method, for example: https://github.com/kkapsner/CanvasBlocker
  13069. // https://github.com/chartjs/Chart.js/issues/2807
  13070. var context = item && item.getContext && item.getContext('2d');
  13071. // `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
  13072. // inside an iframe or when running in a protected environment. We could guess the
  13073. // types from their toString() value but let's keep things flexible and assume it's
  13074. // a sufficient condition if the item has a context2D which has item as `canvas`.
  13075. // https://github.com/chartjs/Chart.js/issues/3887
  13076. // https://github.com/chartjs/Chart.js/issues/4102
  13077. // https://github.com/chartjs/Chart.js/issues/4152
  13078. if (context && context.canvas === item) {
  13079. initCanvas(item, config);
  13080. return context;
  13081. }
  13082. return null;
  13083. },
  13084. releaseContext: function(context) {
  13085. var canvas = context.canvas;
  13086. if (!canvas[EXPANDO_KEY]) {
  13087. return;
  13088. }
  13089. var initial = canvas[EXPANDO_KEY].initial;
  13090. ['height', 'width'].forEach(function(prop) {
  13091. var value = initial[prop];
  13092. if (helpers.isNullOrUndef(value)) {
  13093. canvas.removeAttribute(prop);
  13094. } else {
  13095. canvas.setAttribute(prop, value);
  13096. }
  13097. });
  13098. helpers.each(initial.style || {}, function(value, key) {
  13099. canvas.style[key] = value;
  13100. });
  13101. // The canvas render size might have been changed (and thus the state stack discarded),
  13102. // we can't use save() and restore() to restore the initial state. So make sure that at
  13103. // least the canvas context is reset to the default state by setting the canvas width.
  13104. // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
  13105. canvas.width = canvas.width;
  13106. delete canvas[EXPANDO_KEY];
  13107. },
  13108. addEventListener: function(chart, type, listener) {
  13109. var canvas = chart.canvas;
  13110. if (type === 'resize') {
  13111. // Note: the resize event is not supported on all browsers.
  13112. addResizeListener(canvas, listener, chart);
  13113. return;
  13114. }
  13115. var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
  13116. var proxies = expando.proxies || (expando.proxies = {});
  13117. var proxy = proxies[chart.id + '_' + type] = function(event) {
  13118. listener(fromNativeEvent(event, chart));
  13119. };
  13120. addEventListener(canvas, type, proxy);
  13121. },
  13122. removeEventListener: function(chart, type, listener) {
  13123. var canvas = chart.canvas;
  13124. if (type === 'resize') {
  13125. // Note: the resize event is not supported on all browsers.
  13126. removeResizeListener(canvas, listener);
  13127. return;
  13128. }
  13129. var expando = listener[EXPANDO_KEY] || {};
  13130. var proxies = expando.proxies || {};
  13131. var proxy = proxies[chart.id + '_' + type];
  13132. if (!proxy) {
  13133. return;
  13134. }
  13135. removeEventListener(canvas, type, proxy);
  13136. }
  13137. };
  13138. // DEPRECATIONS
  13139. /**
  13140. * Provided for backward compatibility, use EventTarget.addEventListener instead.
  13141. * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  13142. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  13143. * @function Chart.helpers.addEvent
  13144. * @deprecated since version 2.7.0
  13145. * @todo remove at version 3
  13146. * @private
  13147. */
  13148. helpers.addEvent = addEventListener;
  13149. /**
  13150. * Provided for backward compatibility, use EventTarget.removeEventListener instead.
  13151. * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  13152. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
  13153. * @function Chart.helpers.removeEvent
  13154. * @deprecated since version 2.7.0
  13155. * @todo remove at version 3
  13156. * @private
  13157. */
  13158. helpers.removeEvent = removeEventListener;
  13159. },{"45":45}],48:[function(require,module,exports){
  13160. 'use strict';
  13161. var helpers = require(45);
  13162. var basic = require(46);
  13163. var dom = require(47);
  13164. // @TODO Make possible to select another platform at build time.
  13165. var implementation = dom._enabled ? dom : basic;
  13166. /**
  13167. * @namespace Chart.platform
  13168. * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
  13169. * @since 2.4.0
  13170. */
  13171. module.exports = helpers.extend({
  13172. /**
  13173. * @since 2.7.0
  13174. */
  13175. initialize: function() {},
  13176. /**
  13177. * Called at chart construction time, returns a context2d instance implementing
  13178. * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
  13179. * @param {*} item - The native item from which to acquire context (platform specific)
  13180. * @param {Object} options - The chart options
  13181. * @returns {CanvasRenderingContext2D} context2d instance
  13182. */
  13183. acquireContext: function() {},
  13184. /**
  13185. * Called at chart destruction time, releases any resources associated to the context
  13186. * previously returned by the acquireContext() method.
  13187. * @param {CanvasRenderingContext2D} context - The context2d instance
  13188. * @returns {Boolean} true if the method succeeded, else false
  13189. */
  13190. releaseContext: function() {},
  13191. /**
  13192. * Registers the specified listener on the given chart.
  13193. * @param {Chart} chart - Chart from which to listen for event
  13194. * @param {String} type - The ({@link IEvent}) type to listen for
  13195. * @param {Function} listener - Receives a notification (an object that implements
  13196. * the {@link IEvent} interface) when an event of the specified type occurs.
  13197. */
  13198. addEventListener: function() {},
  13199. /**
  13200. * Removes the specified listener previously registered with addEventListener.
  13201. * @param {Chart} chart -Chart from which to remove the listener
  13202. * @param {String} type - The ({@link IEvent}) type to remove
  13203. * @param {Function} listener - The listener function to remove from the event target.
  13204. */
  13205. removeEventListener: function() {}
  13206. }, implementation);
  13207. /**
  13208. * @interface IPlatform
  13209. * Allows abstracting platform dependencies away from the chart
  13210. * @borrows Chart.platform.acquireContext as acquireContext
  13211. * @borrows Chart.platform.releaseContext as releaseContext
  13212. * @borrows Chart.platform.addEventListener as addEventListener
  13213. * @borrows Chart.platform.removeEventListener as removeEventListener
  13214. */
  13215. /**
  13216. * @interface IEvent
  13217. * @prop {String} type - The event type name, possible values are:
  13218. * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
  13219. * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
  13220. * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
  13221. * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
  13222. * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
  13223. */
  13224. },{"45":45,"46":46,"47":47}],49:[function(require,module,exports){
  13225. 'use strict';
  13226. module.exports = {};
  13227. module.exports.filler = require(50);
  13228. module.exports.legend = require(51);
  13229. module.exports.title = require(52);
  13230. },{"50":50,"51":51,"52":52}],50:[function(require,module,exports){
  13231. /**
  13232. * Plugin based on discussion from the following Chart.js issues:
  13233. * @see https://github.com/chartjs/Chart.js/issues/2380#issuecomment-279961569
  13234. * @see https://github.com/chartjs/Chart.js/issues/2440#issuecomment-256461897
  13235. */
  13236. 'use strict';
  13237. var defaults = require(25);
  13238. var elements = require(40);
  13239. var helpers = require(45);
  13240. defaults._set('global', {
  13241. plugins: {
  13242. filler: {
  13243. propagate: true
  13244. }
  13245. }
  13246. });
  13247. var mappers = {
  13248. dataset: function(source) {
  13249. var index = source.fill;
  13250. var chart = source.chart;
  13251. var meta = chart.getDatasetMeta(index);
  13252. var visible = meta && chart.isDatasetVisible(index);
  13253. var points = (visible && meta.dataset._children) || [];
  13254. var length = points.length || 0;
  13255. return !length ? null : function(point, i) {
  13256. return (i < length && points[i]._view) || null;
  13257. };
  13258. },
  13259. boundary: function(source) {
  13260. var boundary = source.boundary;
  13261. var x = boundary ? boundary.x : null;
  13262. var y = boundary ? boundary.y : null;
  13263. return function(point) {
  13264. return {
  13265. x: x === null ? point.x : x,
  13266. y: y === null ? point.y : y,
  13267. };
  13268. };
  13269. }
  13270. };
  13271. // @todo if (fill[0] === '#')
  13272. function decodeFill(el, index, count) {
  13273. var model = el._model || {};
  13274. var fill = model.fill;
  13275. var target;
  13276. if (fill === undefined) {
  13277. fill = !!model.backgroundColor;
  13278. }
  13279. if (fill === false || fill === null) {
  13280. return false;
  13281. }
  13282. if (fill === true) {
  13283. return 'origin';
  13284. }
  13285. target = parseFloat(fill, 10);
  13286. if (isFinite(target) && Math.floor(target) === target) {
  13287. if (fill[0] === '-' || fill[0] === '+') {
  13288. target = index + target;
  13289. }
  13290. if (target === index || target < 0 || target >= count) {
  13291. return false;
  13292. }
  13293. return target;
  13294. }
  13295. switch (fill) {
  13296. // compatibility
  13297. case 'bottom':
  13298. return 'start';
  13299. case 'top':
  13300. return 'end';
  13301. case 'zero':
  13302. return 'origin';
  13303. // supported boundaries
  13304. case 'origin':
  13305. case 'start':
  13306. case 'end':
  13307. return fill;
  13308. // invalid fill values
  13309. default:
  13310. return false;
  13311. }
  13312. }
  13313. function computeBoundary(source) {
  13314. var model = source.el._model || {};
  13315. var scale = source.el._scale || {};
  13316. var fill = source.fill;
  13317. var target = null;
  13318. var horizontal;
  13319. if (isFinite(fill)) {
  13320. return null;
  13321. }
  13322. // Backward compatibility: until v3, we still need to support boundary values set on
  13323. // the model (scaleTop, scaleBottom and scaleZero) because some external plugins and
  13324. // controllers might still use it (e.g. the Smith chart).
  13325. if (fill === 'start') {
  13326. target = model.scaleBottom === undefined ? scale.bottom : model.scaleBottom;
  13327. } else if (fill === 'end') {
  13328. target = model.scaleTop === undefined ? scale.top : model.scaleTop;
  13329. } else if (model.scaleZero !== undefined) {
  13330. target = model.scaleZero;
  13331. } else if (scale.getBasePosition) {
  13332. target = scale.getBasePosition();
  13333. } else if (scale.getBasePixel) {
  13334. target = scale.getBasePixel();
  13335. }
  13336. if (target !== undefined && target !== null) {
  13337. if (target.x !== undefined && target.y !== undefined) {
  13338. return target;
  13339. }
  13340. if (typeof target === 'number' && isFinite(target)) {
  13341. horizontal = scale.isHorizontal();
  13342. return {
  13343. x: horizontal ? target : null,
  13344. y: horizontal ? null : target
  13345. };
  13346. }
  13347. }
  13348. return null;
  13349. }
  13350. function resolveTarget(sources, index, propagate) {
  13351. var source = sources[index];
  13352. var fill = source.fill;
  13353. var visited = [index];
  13354. var target;
  13355. if (!propagate) {
  13356. return fill;
  13357. }
  13358. while (fill !== false && visited.indexOf(fill) === -1) {
  13359. if (!isFinite(fill)) {
  13360. return fill;
  13361. }
  13362. target = sources[fill];
  13363. if (!target) {
  13364. return false;
  13365. }
  13366. if (target.visible) {
  13367. return fill;
  13368. }
  13369. visited.push(fill);
  13370. fill = target.fill;
  13371. }
  13372. return false;
  13373. }
  13374. function createMapper(source) {
  13375. var fill = source.fill;
  13376. var type = 'dataset';
  13377. if (fill === false) {
  13378. return null;
  13379. }
  13380. if (!isFinite(fill)) {
  13381. type = 'boundary';
  13382. }
  13383. return mappers[type](source);
  13384. }
  13385. function isDrawable(point) {
  13386. return point && !point.skip;
  13387. }
  13388. function drawArea(ctx, curve0, curve1, len0, len1) {
  13389. var i;
  13390. if (!len0 || !len1) {
  13391. return;
  13392. }
  13393. // building first area curve (normal)
  13394. ctx.moveTo(curve0[0].x, curve0[0].y);
  13395. for (i = 1; i < len0; ++i) {
  13396. helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
  13397. }
  13398. // joining the two area curves
  13399. ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
  13400. // building opposite area curve (reverse)
  13401. for (i = len1 - 1; i > 0; --i) {
  13402. helpers.canvas.lineTo(ctx, curve1[i], curve1[i - 1], true);
  13403. }
  13404. }
  13405. function doFill(ctx, points, mapper, view, color, loop) {
  13406. var count = points.length;
  13407. var span = view.spanGaps;
  13408. var curve0 = [];
  13409. var curve1 = [];
  13410. var len0 = 0;
  13411. var len1 = 0;
  13412. var i, ilen, index, p0, p1, d0, d1;
  13413. ctx.beginPath();
  13414. for (i = 0, ilen = (count + !!loop); i < ilen; ++i) {
  13415. index = i % count;
  13416. p0 = points[index]._view;
  13417. p1 = mapper(p0, index, view);
  13418. d0 = isDrawable(p0);
  13419. d1 = isDrawable(p1);
  13420. if (d0 && d1) {
  13421. len0 = curve0.push(p0);
  13422. len1 = curve1.push(p1);
  13423. } else if (len0 && len1) {
  13424. if (!span) {
  13425. drawArea(ctx, curve0, curve1, len0, len1);
  13426. len0 = len1 = 0;
  13427. curve0 = [];
  13428. curve1 = [];
  13429. } else {
  13430. if (d0) {
  13431. curve0.push(p0);
  13432. }
  13433. if (d1) {
  13434. curve1.push(p1);
  13435. }
  13436. }
  13437. }
  13438. }
  13439. drawArea(ctx, curve0, curve1, len0, len1);
  13440. ctx.closePath();
  13441. ctx.fillStyle = color;
  13442. ctx.fill();
  13443. }
  13444. module.exports = {
  13445. id: 'filler',
  13446. afterDatasetsUpdate: function(chart, options) {
  13447. var count = (chart.data.datasets || []).length;
  13448. var propagate = options.propagate;
  13449. var sources = [];
  13450. var meta, i, el, source;
  13451. for (i = 0; i < count; ++i) {
  13452. meta = chart.getDatasetMeta(i);
  13453. el = meta.dataset;
  13454. source = null;
  13455. if (el && el._model && el instanceof elements.Line) {
  13456. source = {
  13457. visible: chart.isDatasetVisible(i),
  13458. fill: decodeFill(el, i, count),
  13459. chart: chart,
  13460. el: el
  13461. };
  13462. }
  13463. meta.$filler = source;
  13464. sources.push(source);
  13465. }
  13466. for (i = 0; i < count; ++i) {
  13467. source = sources[i];
  13468. if (!source) {
  13469. continue;
  13470. }
  13471. source.fill = resolveTarget(sources, i, propagate);
  13472. source.boundary = computeBoundary(source);
  13473. source.mapper = createMapper(source);
  13474. }
  13475. },
  13476. beforeDatasetDraw: function(chart, args) {
  13477. var meta = args.meta.$filler;
  13478. if (!meta) {
  13479. return;
  13480. }
  13481. var ctx = chart.ctx;
  13482. var el = meta.el;
  13483. var view = el._view;
  13484. var points = el._children || [];
  13485. var mapper = meta.mapper;
  13486. var color = view.backgroundColor || defaults.global.defaultColor;
  13487. if (mapper && color && points.length) {
  13488. helpers.canvas.clipArea(ctx, chart.chartArea);
  13489. doFill(ctx, points, mapper, view, color, el._loop);
  13490. helpers.canvas.unclipArea(ctx);
  13491. }
  13492. }
  13493. };
  13494. },{"25":25,"40":40,"45":45}],51:[function(require,module,exports){
  13495. 'use strict';
  13496. var defaults = require(25);
  13497. var Element = require(26);
  13498. var helpers = require(45);
  13499. var layouts = require(30);
  13500. var noop = helpers.noop;
  13501. defaults._set('global', {
  13502. legend: {
  13503. display: true,
  13504. position: 'top',
  13505. fullWidth: true,
  13506. reverse: false,
  13507. weight: 1000,
  13508. // a callback that will handle
  13509. onClick: function(e, legendItem) {
  13510. var index = legendItem.datasetIndex;
  13511. var ci = this.chart;
  13512. var meta = ci.getDatasetMeta(index);
  13513. // See controller.isDatasetVisible comment
  13514. meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
  13515. // We hid a dataset ... rerender the chart
  13516. ci.update();
  13517. },
  13518. onHover: null,
  13519. labels: {
  13520. boxWidth: 40,
  13521. padding: 10,
  13522. // Generates labels shown in the legend
  13523. // Valid properties to return:
  13524. // text : text to display
  13525. // fillStyle : fill of coloured box
  13526. // strokeStyle: stroke of coloured box
  13527. // hidden : if this legend item refers to a hidden item
  13528. // lineCap : cap style for line
  13529. // lineDash
  13530. // lineDashOffset :
  13531. // lineJoin :
  13532. // lineWidth :
  13533. generateLabels: function(chart) {
  13534. var data = chart.data;
  13535. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  13536. return {
  13537. text: dataset.label,
  13538. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  13539. hidden: !chart.isDatasetVisible(i),
  13540. lineCap: dataset.borderCapStyle,
  13541. lineDash: dataset.borderDash,
  13542. lineDashOffset: dataset.borderDashOffset,
  13543. lineJoin: dataset.borderJoinStyle,
  13544. lineWidth: dataset.borderWidth,
  13545. strokeStyle: dataset.borderColor,
  13546. pointStyle: dataset.pointStyle,
  13547. // Below is extra data used for toggling the datasets
  13548. datasetIndex: i
  13549. };
  13550. }, this) : [];
  13551. }
  13552. }
  13553. },
  13554. legendCallback: function(chart) {
  13555. var text = [];
  13556. text.push('<ul class="' + chart.id + '-legend">');
  13557. for (var i = 0; i < chart.data.datasets.length; i++) {
  13558. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  13559. if (chart.data.datasets[i].label) {
  13560. text.push(chart.data.datasets[i].label);
  13561. }
  13562. text.push('</li>');
  13563. }
  13564. text.push('</ul>');
  13565. return text.join('');
  13566. }
  13567. });
  13568. /**
  13569. * Helper function to get the box width based on the usePointStyle option
  13570. * @param labelopts {Object} the label options on the legend
  13571. * @param fontSize {Number} the label font size
  13572. * @return {Number} width of the color box area
  13573. */
  13574. function getBoxWidth(labelOpts, fontSize) {
  13575. return labelOpts.usePointStyle ?
  13576. fontSize * Math.SQRT2 :
  13577. labelOpts.boxWidth;
  13578. }
  13579. /**
  13580. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  13581. */
  13582. var Legend = Element.extend({
  13583. initialize: function(config) {
  13584. helpers.extend(this, config);
  13585. // Contains hit boxes for each dataset (in dataset order)
  13586. this.legendHitBoxes = [];
  13587. // Are we in doughnut mode which has a different data type
  13588. this.doughnutMode = false;
  13589. },
  13590. // These methods are ordered by lifecycle. Utilities then follow.
  13591. // Any function defined here is inherited by all legend types.
  13592. // Any function can be extended by the legend type
  13593. beforeUpdate: noop,
  13594. update: function(maxWidth, maxHeight, margins) {
  13595. var me = this;
  13596. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  13597. me.beforeUpdate();
  13598. // Absorb the master measurements
  13599. me.maxWidth = maxWidth;
  13600. me.maxHeight = maxHeight;
  13601. me.margins = margins;
  13602. // Dimensions
  13603. me.beforeSetDimensions();
  13604. me.setDimensions();
  13605. me.afterSetDimensions();
  13606. // Labels
  13607. me.beforeBuildLabels();
  13608. me.buildLabels();
  13609. me.afterBuildLabels();
  13610. // Fit
  13611. me.beforeFit();
  13612. me.fit();
  13613. me.afterFit();
  13614. //
  13615. me.afterUpdate();
  13616. return me.minSize;
  13617. },
  13618. afterUpdate: noop,
  13619. //
  13620. beforeSetDimensions: noop,
  13621. setDimensions: function() {
  13622. var me = this;
  13623. // Set the unconstrained dimension before label rotation
  13624. if (me.isHorizontal()) {
  13625. // Reset position before calculating rotation
  13626. me.width = me.maxWidth;
  13627. me.left = 0;
  13628. me.right = me.width;
  13629. } else {
  13630. me.height = me.maxHeight;
  13631. // Reset position before calculating rotation
  13632. me.top = 0;
  13633. me.bottom = me.height;
  13634. }
  13635. // Reset padding
  13636. me.paddingLeft = 0;
  13637. me.paddingTop = 0;
  13638. me.paddingRight = 0;
  13639. me.paddingBottom = 0;
  13640. // Reset minSize
  13641. me.minSize = {
  13642. width: 0,
  13643. height: 0
  13644. };
  13645. },
  13646. afterSetDimensions: noop,
  13647. //
  13648. beforeBuildLabels: noop,
  13649. buildLabels: function() {
  13650. var me = this;
  13651. var labelOpts = me.options.labels || {};
  13652. var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];
  13653. if (labelOpts.filter) {
  13654. legendItems = legendItems.filter(function(item) {
  13655. return labelOpts.filter(item, me.chart.data);
  13656. });
  13657. }
  13658. if (me.options.reverse) {
  13659. legendItems.reverse();
  13660. }
  13661. me.legendItems = legendItems;
  13662. },
  13663. afterBuildLabels: noop,
  13664. //
  13665. beforeFit: noop,
  13666. fit: function() {
  13667. var me = this;
  13668. var opts = me.options;
  13669. var labelOpts = opts.labels;
  13670. var display = opts.display;
  13671. var ctx = me.ctx;
  13672. var globalDefault = defaults.global;
  13673. var valueOrDefault = helpers.valueOrDefault;
  13674. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  13675. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  13676. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  13677. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  13678. // Reset hit boxes
  13679. var hitboxes = me.legendHitBoxes = [];
  13680. var minSize = me.minSize;
  13681. var isHorizontal = me.isHorizontal();
  13682. if (isHorizontal) {
  13683. minSize.width = me.maxWidth; // fill all the width
  13684. minSize.height = display ? 10 : 0;
  13685. } else {
  13686. minSize.width = display ? 10 : 0;
  13687. minSize.height = me.maxHeight; // fill all the height
  13688. }
  13689. // Increase sizes here
  13690. if (display) {
  13691. ctx.font = labelFont;
  13692. if (isHorizontal) {
  13693. // Labels
  13694. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  13695. var lineWidths = me.lineWidths = [0];
  13696. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  13697. ctx.textAlign = 'left';
  13698. ctx.textBaseline = 'top';
  13699. helpers.each(me.legendItems, function(legendItem, i) {
  13700. var boxWidth = getBoxWidth(labelOpts, fontSize);
  13701. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  13702. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  13703. totalHeight += fontSize + (labelOpts.padding);
  13704. lineWidths[lineWidths.length] = me.left;
  13705. }
  13706. // Store the hitbox width and height here. Final position will be updated in `draw`
  13707. hitboxes[i] = {
  13708. left: 0,
  13709. top: 0,
  13710. width: width,
  13711. height: fontSize
  13712. };
  13713. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  13714. });
  13715. minSize.height += totalHeight;
  13716. } else {
  13717. var vPadding = labelOpts.padding;
  13718. var columnWidths = me.columnWidths = [];
  13719. var totalWidth = labelOpts.padding;
  13720. var currentColWidth = 0;
  13721. var currentColHeight = 0;
  13722. var itemHeight = fontSize + vPadding;
  13723. helpers.each(me.legendItems, function(legendItem, i) {
  13724. var boxWidth = getBoxWidth(labelOpts, fontSize);
  13725. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  13726. // If too tall, go to new column
  13727. if (currentColHeight + itemHeight > minSize.height) {
  13728. totalWidth += currentColWidth + labelOpts.padding;
  13729. columnWidths.push(currentColWidth); // previous column width
  13730. currentColWidth = 0;
  13731. currentColHeight = 0;
  13732. }
  13733. // Get max width
  13734. currentColWidth = Math.max(currentColWidth, itemWidth);
  13735. currentColHeight += itemHeight;
  13736. // Store the hitbox width and height here. Final position will be updated in `draw`
  13737. hitboxes[i] = {
  13738. left: 0,
  13739. top: 0,
  13740. width: itemWidth,
  13741. height: fontSize
  13742. };
  13743. });
  13744. totalWidth += currentColWidth;
  13745. columnWidths.push(currentColWidth);
  13746. minSize.width += totalWidth;
  13747. }
  13748. }
  13749. me.width = minSize.width;
  13750. me.height = minSize.height;
  13751. },
  13752. afterFit: noop,
  13753. // Shared Methods
  13754. isHorizontal: function() {
  13755. return this.options.position === 'top' || this.options.position === 'bottom';
  13756. },
  13757. // Actually draw the legend on the canvas
  13758. draw: function() {
  13759. var me = this;
  13760. var opts = me.options;
  13761. var labelOpts = opts.labels;
  13762. var globalDefault = defaults.global;
  13763. var lineDefault = globalDefault.elements.line;
  13764. var legendWidth = me.width;
  13765. var lineWidths = me.lineWidths;
  13766. if (opts.display) {
  13767. var ctx = me.ctx;
  13768. var valueOrDefault = helpers.valueOrDefault;
  13769. var fontColor = valueOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor);
  13770. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  13771. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  13772. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  13773. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  13774. var cursor;
  13775. // Canvas setup
  13776. ctx.textAlign = 'left';
  13777. ctx.textBaseline = 'middle';
  13778. ctx.lineWidth = 0.5;
  13779. ctx.strokeStyle = fontColor; // for strikethrough effect
  13780. ctx.fillStyle = fontColor; // render in correct colour
  13781. ctx.font = labelFont;
  13782. var boxWidth = getBoxWidth(labelOpts, fontSize);
  13783. var hitboxes = me.legendHitBoxes;
  13784. // current position
  13785. var drawLegendBox = function(x, y, legendItem) {
  13786. if (isNaN(boxWidth) || boxWidth <= 0) {
  13787. return;
  13788. }
  13789. // Set the ctx for the box
  13790. ctx.save();
  13791. ctx.fillStyle = valueOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  13792. ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  13793. ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  13794. ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  13795. ctx.lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  13796. ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  13797. var isLineWidthZero = (valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  13798. if (ctx.setLineDash) {
  13799. // IE 9 and 10 do not support line dash
  13800. ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
  13801. }
  13802. if (opts.labels && opts.labels.usePointStyle) {
  13803. // Recalculate x and y for drawPoint() because its expecting
  13804. // x and y to be center of figure (instead of top left)
  13805. var radius = fontSize * Math.SQRT2 / 2;
  13806. var offSet = radius / Math.SQRT2;
  13807. var centerX = x + offSet;
  13808. var centerY = y + offSet;
  13809. // Draw pointStyle as legend symbol
  13810. helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  13811. } else {
  13812. // Draw box as legend symbol
  13813. if (!isLineWidthZero) {
  13814. ctx.strokeRect(x, y, boxWidth, fontSize);
  13815. }
  13816. ctx.fillRect(x, y, boxWidth, fontSize);
  13817. }
  13818. ctx.restore();
  13819. };
  13820. var fillText = function(x, y, legendItem, textWidth) {
  13821. var halfFontSize = fontSize / 2;
  13822. var xLeft = boxWidth + halfFontSize + x;
  13823. var yMiddle = y + halfFontSize;
  13824. ctx.fillText(legendItem.text, xLeft, yMiddle);
  13825. if (legendItem.hidden) {
  13826. // Strikethrough the text if hidden
  13827. ctx.beginPath();
  13828. ctx.lineWidth = 2;
  13829. ctx.moveTo(xLeft, yMiddle);
  13830. ctx.lineTo(xLeft + textWidth, yMiddle);
  13831. ctx.stroke();
  13832. }
  13833. };
  13834. // Horizontal
  13835. var isHorizontal = me.isHorizontal();
  13836. if (isHorizontal) {
  13837. cursor = {
  13838. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  13839. y: me.top + labelOpts.padding,
  13840. line: 0
  13841. };
  13842. } else {
  13843. cursor = {
  13844. x: me.left + labelOpts.padding,
  13845. y: me.top + labelOpts.padding,
  13846. line: 0
  13847. };
  13848. }
  13849. var itemHeight = fontSize + labelOpts.padding;
  13850. helpers.each(me.legendItems, function(legendItem, i) {
  13851. var textWidth = ctx.measureText(legendItem.text).width;
  13852. var width = boxWidth + (fontSize / 2) + textWidth;
  13853. var x = cursor.x;
  13854. var y = cursor.y;
  13855. if (isHorizontal) {
  13856. if (x + width >= legendWidth) {
  13857. y = cursor.y += itemHeight;
  13858. cursor.line++;
  13859. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  13860. }
  13861. } else if (y + itemHeight > me.bottom) {
  13862. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  13863. y = cursor.y = me.top + labelOpts.padding;
  13864. cursor.line++;
  13865. }
  13866. drawLegendBox(x, y, legendItem);
  13867. hitboxes[i].left = x;
  13868. hitboxes[i].top = y;
  13869. // Fill the actual label
  13870. fillText(x, y, legendItem, textWidth);
  13871. if (isHorizontal) {
  13872. cursor.x += width + (labelOpts.padding);
  13873. } else {
  13874. cursor.y += itemHeight;
  13875. }
  13876. });
  13877. }
  13878. },
  13879. /**
  13880. * Handle an event
  13881. * @private
  13882. * @param {IEvent} event - The event to handle
  13883. * @return {Boolean} true if a change occured
  13884. */
  13885. handleEvent: function(e) {
  13886. var me = this;
  13887. var opts = me.options;
  13888. var type = e.type === 'mouseup' ? 'click' : e.type;
  13889. var changed = false;
  13890. if (type === 'mousemove') {
  13891. if (!opts.onHover) {
  13892. return;
  13893. }
  13894. } else if (type === 'click') {
  13895. if (!opts.onClick) {
  13896. return;
  13897. }
  13898. } else {
  13899. return;
  13900. }
  13901. // Chart event already has relative position in it
  13902. var x = e.x;
  13903. var y = e.y;
  13904. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  13905. // See if we are touching one of the dataset boxes
  13906. var lh = me.legendHitBoxes;
  13907. for (var i = 0; i < lh.length; ++i) {
  13908. var hitBox = lh[i];
  13909. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  13910. // Touching an element
  13911. if (type === 'click') {
  13912. // use e.native for backwards compatibility
  13913. opts.onClick.call(me, e.native, me.legendItems[i]);
  13914. changed = true;
  13915. break;
  13916. } else if (type === 'mousemove') {
  13917. // use e.native for backwards compatibility
  13918. opts.onHover.call(me, e.native, me.legendItems[i]);
  13919. changed = true;
  13920. break;
  13921. }
  13922. }
  13923. }
  13924. }
  13925. return changed;
  13926. }
  13927. });
  13928. function createNewLegendAndAttach(chart, legendOpts) {
  13929. var legend = new Legend({
  13930. ctx: chart.ctx,
  13931. options: legendOpts,
  13932. chart: chart
  13933. });
  13934. layouts.configure(chart, legend, legendOpts);
  13935. layouts.addBox(chart, legend);
  13936. chart.legend = legend;
  13937. }
  13938. module.exports = {
  13939. id: 'legend',
  13940. /**
  13941. * Backward compatibility: since 2.1.5, the legend is registered as a plugin, making
  13942. * Chart.Legend obsolete. To avoid a breaking change, we export the Legend as part of
  13943. * the plugin, which one will be re-exposed in the chart.js file.
  13944. * https://github.com/chartjs/Chart.js/pull/2640
  13945. * @private
  13946. */
  13947. _element: Legend,
  13948. beforeInit: function(chart) {
  13949. var legendOpts = chart.options.legend;
  13950. if (legendOpts) {
  13951. createNewLegendAndAttach(chart, legendOpts);
  13952. }
  13953. },
  13954. beforeUpdate: function(chart) {
  13955. var legendOpts = chart.options.legend;
  13956. var legend = chart.legend;
  13957. if (legendOpts) {
  13958. helpers.mergeIf(legendOpts, defaults.global.legend);
  13959. if (legend) {
  13960. layouts.configure(chart, legend, legendOpts);
  13961. legend.options = legendOpts;
  13962. } else {
  13963. createNewLegendAndAttach(chart, legendOpts);
  13964. }
  13965. } else if (legend) {
  13966. layouts.removeBox(chart, legend);
  13967. delete chart.legend;
  13968. }
  13969. },
  13970. afterEvent: function(chart, e) {
  13971. var legend = chart.legend;
  13972. if (legend) {
  13973. legend.handleEvent(e);
  13974. }
  13975. }
  13976. };
  13977. },{"25":25,"26":26,"30":30,"45":45}],52:[function(require,module,exports){
  13978. 'use strict';
  13979. var defaults = require(25);
  13980. var Element = require(26);
  13981. var helpers = require(45);
  13982. var layouts = require(30);
  13983. var noop = helpers.noop;
  13984. defaults._set('global', {
  13985. title: {
  13986. display: false,
  13987. fontStyle: 'bold',
  13988. fullWidth: true,
  13989. lineHeight: 1.2,
  13990. padding: 10,
  13991. position: 'top',
  13992. text: '',
  13993. weight: 2000 // by default greater than legend (1000) to be above
  13994. }
  13995. });
  13996. /**
  13997. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  13998. */
  13999. var Title = Element.extend({
  14000. initialize: function(config) {
  14001. var me = this;
  14002. helpers.extend(me, config);
  14003. // Contains hit boxes for each dataset (in dataset order)
  14004. me.legendHitBoxes = [];
  14005. },
  14006. // These methods are ordered by lifecycle. Utilities then follow.
  14007. beforeUpdate: noop,
  14008. update: function(maxWidth, maxHeight, margins) {
  14009. var me = this;
  14010. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  14011. me.beforeUpdate();
  14012. // Absorb the master measurements
  14013. me.maxWidth = maxWidth;
  14014. me.maxHeight = maxHeight;
  14015. me.margins = margins;
  14016. // Dimensions
  14017. me.beforeSetDimensions();
  14018. me.setDimensions();
  14019. me.afterSetDimensions();
  14020. // Labels
  14021. me.beforeBuildLabels();
  14022. me.buildLabels();
  14023. me.afterBuildLabels();
  14024. // Fit
  14025. me.beforeFit();
  14026. me.fit();
  14027. me.afterFit();
  14028. //
  14029. me.afterUpdate();
  14030. return me.minSize;
  14031. },
  14032. afterUpdate: noop,
  14033. //
  14034. beforeSetDimensions: noop,
  14035. setDimensions: function() {
  14036. var me = this;
  14037. // Set the unconstrained dimension before label rotation
  14038. if (me.isHorizontal()) {
  14039. // Reset position before calculating rotation
  14040. me.width = me.maxWidth;
  14041. me.left = 0;
  14042. me.right = me.width;
  14043. } else {
  14044. me.height = me.maxHeight;
  14045. // Reset position before calculating rotation
  14046. me.top = 0;
  14047. me.bottom = me.height;
  14048. }
  14049. // Reset padding
  14050. me.paddingLeft = 0;
  14051. me.paddingTop = 0;
  14052. me.paddingRight = 0;
  14053. me.paddingBottom = 0;
  14054. // Reset minSize
  14055. me.minSize = {
  14056. width: 0,
  14057. height: 0
  14058. };
  14059. },
  14060. afterSetDimensions: noop,
  14061. //
  14062. beforeBuildLabels: noop,
  14063. buildLabels: noop,
  14064. afterBuildLabels: noop,
  14065. //
  14066. beforeFit: noop,
  14067. fit: function() {
  14068. var me = this;
  14069. var valueOrDefault = helpers.valueOrDefault;
  14070. var opts = me.options;
  14071. var display = opts.display;
  14072. var fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize);
  14073. var minSize = me.minSize;
  14074. var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
  14075. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  14076. var textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
  14077. if (me.isHorizontal()) {
  14078. minSize.width = me.maxWidth; // fill all the width
  14079. minSize.height = textSize;
  14080. } else {
  14081. minSize.width = textSize;
  14082. minSize.height = me.maxHeight; // fill all the height
  14083. }
  14084. me.width = minSize.width;
  14085. me.height = minSize.height;
  14086. },
  14087. afterFit: noop,
  14088. // Shared Methods
  14089. isHorizontal: function() {
  14090. var pos = this.options.position;
  14091. return pos === 'top' || pos === 'bottom';
  14092. },
  14093. // Actually draw the title block on the canvas
  14094. draw: function() {
  14095. var me = this;
  14096. var ctx = me.ctx;
  14097. var valueOrDefault = helpers.valueOrDefault;
  14098. var opts = me.options;
  14099. var globalDefaults = defaults.global;
  14100. if (opts.display) {
  14101. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize);
  14102. var fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle);
  14103. var fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily);
  14104. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  14105. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  14106. var offset = lineHeight / 2 + opts.padding;
  14107. var rotation = 0;
  14108. var top = me.top;
  14109. var left = me.left;
  14110. var bottom = me.bottom;
  14111. var right = me.right;
  14112. var maxWidth, titleX, titleY;
  14113. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  14114. ctx.font = titleFont;
  14115. // Horizontal
  14116. if (me.isHorizontal()) {
  14117. titleX = left + ((right - left) / 2); // midpoint of the width
  14118. titleY = top + offset;
  14119. maxWidth = right - left;
  14120. } else {
  14121. titleX = opts.position === 'left' ? left + offset : right - offset;
  14122. titleY = top + ((bottom - top) / 2);
  14123. maxWidth = bottom - top;
  14124. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  14125. }
  14126. ctx.save();
  14127. ctx.translate(titleX, titleY);
  14128. ctx.rotate(rotation);
  14129. ctx.textAlign = 'center';
  14130. ctx.textBaseline = 'middle';
  14131. var text = opts.text;
  14132. if (helpers.isArray(text)) {
  14133. var y = 0;
  14134. for (var i = 0; i < text.length; ++i) {
  14135. ctx.fillText(text[i], 0, y, maxWidth);
  14136. y += lineHeight;
  14137. }
  14138. } else {
  14139. ctx.fillText(text, 0, 0, maxWidth);
  14140. }
  14141. ctx.restore();
  14142. }
  14143. }
  14144. });
  14145. function createNewTitleBlockAndAttach(chart, titleOpts) {
  14146. var title = new Title({
  14147. ctx: chart.ctx,
  14148. options: titleOpts,
  14149. chart: chart
  14150. });
  14151. layouts.configure(chart, title, titleOpts);
  14152. layouts.addBox(chart, title);
  14153. chart.titleBlock = title;
  14154. }
  14155. module.exports = {
  14156. id: 'title',
  14157. /**
  14158. * Backward compatibility: since 2.1.5, the title is registered as a plugin, making
  14159. * Chart.Title obsolete. To avoid a breaking change, we export the Title as part of
  14160. * the plugin, which one will be re-exposed in the chart.js file.
  14161. * https://github.com/chartjs/Chart.js/pull/2640
  14162. * @private
  14163. */
  14164. _element: Title,
  14165. beforeInit: function(chart) {
  14166. var titleOpts = chart.options.title;
  14167. if (titleOpts) {
  14168. createNewTitleBlockAndAttach(chart, titleOpts);
  14169. }
  14170. },
  14171. beforeUpdate: function(chart) {
  14172. var titleOpts = chart.options.title;
  14173. var titleBlock = chart.titleBlock;
  14174. if (titleOpts) {
  14175. helpers.mergeIf(titleOpts, defaults.global.title);
  14176. if (titleBlock) {
  14177. layouts.configure(chart, titleBlock, titleOpts);
  14178. titleBlock.options = titleOpts;
  14179. } else {
  14180. createNewTitleBlockAndAttach(chart, titleOpts);
  14181. }
  14182. } else if (titleBlock) {
  14183. layouts.removeBox(chart, titleBlock);
  14184. delete chart.titleBlock;
  14185. }
  14186. }
  14187. };
  14188. },{"25":25,"26":26,"30":30,"45":45}],53:[function(require,module,exports){
  14189. 'use strict';
  14190. module.exports = function(Chart) {
  14191. // Default config for a category scale
  14192. var defaultConfig = {
  14193. position: 'bottom'
  14194. };
  14195. var DatasetScale = Chart.Scale.extend({
  14196. /**
  14197. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
  14198. * else fall back to data.labels
  14199. * @private
  14200. */
  14201. getLabels: function() {
  14202. var data = this.chart.data;
  14203. return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  14204. },
  14205. determineDataLimits: function() {
  14206. var me = this;
  14207. var labels = me.getLabels();
  14208. me.minIndex = 0;
  14209. me.maxIndex = labels.length - 1;
  14210. var findIndex;
  14211. if (me.options.ticks.min !== undefined) {
  14212. // user specified min value
  14213. findIndex = labels.indexOf(me.options.ticks.min);
  14214. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  14215. }
  14216. if (me.options.ticks.max !== undefined) {
  14217. // user specified max value
  14218. findIndex = labels.indexOf(me.options.ticks.max);
  14219. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  14220. }
  14221. me.min = labels[me.minIndex];
  14222. me.max = labels[me.maxIndex];
  14223. },
  14224. buildTicks: function() {
  14225. var me = this;
  14226. var labels = me.getLabels();
  14227. // If we are viewing some subset of labels, slice the original array
  14228. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  14229. },
  14230. getLabelForIndex: function(index, datasetIndex) {
  14231. var me = this;
  14232. var data = me.chart.data;
  14233. var isHorizontal = me.isHorizontal();
  14234. if (data.yLabels && !isHorizontal) {
  14235. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  14236. }
  14237. return me.ticks[index - me.minIndex];
  14238. },
  14239. // Used to get data value locations. Value can either be an index or a numerical value
  14240. getPixelForValue: function(value, index) {
  14241. var me = this;
  14242. var offset = me.options.offset;
  14243. // 1 is added because we need the length but we have the indexes
  14244. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1)), 1);
  14245. // If value is a data object, then index is the index in the data array,
  14246. // not the index of the scale. We need to change that.
  14247. var valueCategory;
  14248. if (value !== undefined && value !== null) {
  14249. valueCategory = me.isHorizontal() ? value.x : value.y;
  14250. }
  14251. if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
  14252. var labels = me.getLabels();
  14253. value = valueCategory || value;
  14254. var idx = labels.indexOf(value);
  14255. index = idx !== -1 ? idx : index;
  14256. }
  14257. if (me.isHorizontal()) {
  14258. var valueWidth = me.width / offsetAmt;
  14259. var widthOffset = (valueWidth * (index - me.minIndex));
  14260. if (offset) {
  14261. widthOffset += (valueWidth / 2);
  14262. }
  14263. return me.left + Math.round(widthOffset);
  14264. }
  14265. var valueHeight = me.height / offsetAmt;
  14266. var heightOffset = (valueHeight * (index - me.minIndex));
  14267. if (offset) {
  14268. heightOffset += (valueHeight / 2);
  14269. }
  14270. return me.top + Math.round(heightOffset);
  14271. },
  14272. getPixelForTick: function(index) {
  14273. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null);
  14274. },
  14275. getValueForPixel: function(pixel) {
  14276. var me = this;
  14277. var offset = me.options.offset;
  14278. var value;
  14279. var offsetAmt = Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  14280. var horz = me.isHorizontal();
  14281. var valueDimension = (horz ? me.width : me.height) / offsetAmt;
  14282. pixel -= horz ? me.left : me.top;
  14283. if (offset) {
  14284. pixel -= (valueDimension / 2);
  14285. }
  14286. if (pixel <= 0) {
  14287. value = 0;
  14288. } else {
  14289. value = Math.round(pixel / valueDimension);
  14290. }
  14291. return value + me.minIndex;
  14292. },
  14293. getBasePixel: function() {
  14294. return this.bottom;
  14295. }
  14296. });
  14297. Chart.scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  14298. };
  14299. },{}],54:[function(require,module,exports){
  14300. 'use strict';
  14301. var defaults = require(25);
  14302. var helpers = require(45);
  14303. var Ticks = require(34);
  14304. module.exports = function(Chart) {
  14305. var defaultConfig = {
  14306. position: 'left',
  14307. ticks: {
  14308. callback: Ticks.formatters.linear
  14309. }
  14310. };
  14311. var LinearScale = Chart.LinearScaleBase.extend({
  14312. determineDataLimits: function() {
  14313. var me = this;
  14314. var opts = me.options;
  14315. var chart = me.chart;
  14316. var data = chart.data;
  14317. var datasets = data.datasets;
  14318. var isHorizontal = me.isHorizontal();
  14319. var DEFAULT_MIN = 0;
  14320. var DEFAULT_MAX = 1;
  14321. function IDMatches(meta) {
  14322. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  14323. }
  14324. // First Calculate the range
  14325. me.min = null;
  14326. me.max = null;
  14327. var hasStacks = opts.stacked;
  14328. if (hasStacks === undefined) {
  14329. helpers.each(datasets, function(dataset, datasetIndex) {
  14330. if (hasStacks) {
  14331. return;
  14332. }
  14333. var meta = chart.getDatasetMeta(datasetIndex);
  14334. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  14335. meta.stack !== undefined) {
  14336. hasStacks = true;
  14337. }
  14338. });
  14339. }
  14340. if (opts.stacked || hasStacks) {
  14341. var valuesPerStack = {};
  14342. helpers.each(datasets, function(dataset, datasetIndex) {
  14343. var meta = chart.getDatasetMeta(datasetIndex);
  14344. var key = [
  14345. meta.type,
  14346. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  14347. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  14348. meta.stack
  14349. ].join('.');
  14350. if (valuesPerStack[key] === undefined) {
  14351. valuesPerStack[key] = {
  14352. positiveValues: [],
  14353. negativeValues: []
  14354. };
  14355. }
  14356. // Store these per type
  14357. var positiveValues = valuesPerStack[key].positiveValues;
  14358. var negativeValues = valuesPerStack[key].negativeValues;
  14359. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  14360. helpers.each(dataset.data, function(rawValue, index) {
  14361. var value = +me.getRightValue(rawValue);
  14362. if (isNaN(value) || meta.data[index].hidden) {
  14363. return;
  14364. }
  14365. positiveValues[index] = positiveValues[index] || 0;
  14366. negativeValues[index] = negativeValues[index] || 0;
  14367. if (opts.relativePoints) {
  14368. positiveValues[index] = 100;
  14369. } else if (value < 0) {
  14370. negativeValues[index] += value;
  14371. } else {
  14372. positiveValues[index] += value;
  14373. }
  14374. });
  14375. }
  14376. });
  14377. helpers.each(valuesPerStack, function(valuesForType) {
  14378. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  14379. var minVal = helpers.min(values);
  14380. var maxVal = helpers.max(values);
  14381. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  14382. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  14383. });
  14384. } else {
  14385. helpers.each(datasets, function(dataset, datasetIndex) {
  14386. var meta = chart.getDatasetMeta(datasetIndex);
  14387. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  14388. helpers.each(dataset.data, function(rawValue, index) {
  14389. var value = +me.getRightValue(rawValue);
  14390. if (isNaN(value) || meta.data[index].hidden) {
  14391. return;
  14392. }
  14393. if (me.min === null) {
  14394. me.min = value;
  14395. } else if (value < me.min) {
  14396. me.min = value;
  14397. }
  14398. if (me.max === null) {
  14399. me.max = value;
  14400. } else if (value > me.max) {
  14401. me.max = value;
  14402. }
  14403. });
  14404. }
  14405. });
  14406. }
  14407. me.min = isFinite(me.min) && !isNaN(me.min) ? me.min : DEFAULT_MIN;
  14408. me.max = isFinite(me.max) && !isNaN(me.max) ? me.max : DEFAULT_MAX;
  14409. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  14410. this.handleTickRangeOptions();
  14411. },
  14412. getTickLimit: function() {
  14413. var maxTicks;
  14414. var me = this;
  14415. var tickOpts = me.options.ticks;
  14416. if (me.isHorizontal()) {
  14417. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  14418. } else {
  14419. // The factor of 2 used to scale the font size has been experimentally determined.
  14420. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
  14421. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  14422. }
  14423. return maxTicks;
  14424. },
  14425. // Called after the ticks are built. We need
  14426. handleDirectionalChanges: function() {
  14427. if (!this.isHorizontal()) {
  14428. // We are in a vertical orientation. The top value is the highest. So reverse the array
  14429. this.ticks.reverse();
  14430. }
  14431. },
  14432. getLabelForIndex: function(index, datasetIndex) {
  14433. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  14434. },
  14435. // Utils
  14436. getPixelForValue: function(value) {
  14437. // This must be called after fit has been run so that
  14438. // this.left, this.top, this.right, and this.bottom have been defined
  14439. var me = this;
  14440. var start = me.start;
  14441. var rightValue = +me.getRightValue(value);
  14442. var pixel;
  14443. var range = me.end - start;
  14444. if (me.isHorizontal()) {
  14445. pixel = me.left + (me.width / range * (rightValue - start));
  14446. } else {
  14447. pixel = me.bottom - (me.height / range * (rightValue - start));
  14448. }
  14449. return pixel;
  14450. },
  14451. getValueForPixel: function(pixel) {
  14452. var me = this;
  14453. var isHorizontal = me.isHorizontal();
  14454. var innerDimension = isHorizontal ? me.width : me.height;
  14455. var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
  14456. return me.start + ((me.end - me.start) * offset);
  14457. },
  14458. getPixelForTick: function(index) {
  14459. return this.getPixelForValue(this.ticksAsNumbers[index]);
  14460. }
  14461. });
  14462. Chart.scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  14463. };
  14464. },{"25":25,"34":34,"45":45}],55:[function(require,module,exports){
  14465. 'use strict';
  14466. var helpers = require(45);
  14467. /**
  14468. * Generate a set of linear ticks
  14469. * @param generationOptions the options used to generate the ticks
  14470. * @param dataRange the range of the data
  14471. * @returns {Array<Number>} array of tick values
  14472. */
  14473. function generateTicks(generationOptions, dataRange) {
  14474. var ticks = [];
  14475. // To get a "nice" value for the tick spacing, we will use the appropriately named
  14476. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  14477. // for details.
  14478. var spacing;
  14479. if (generationOptions.stepSize && generationOptions.stepSize > 0) {
  14480. spacing = generationOptions.stepSize;
  14481. } else {
  14482. var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
  14483. spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
  14484. }
  14485. var niceMin = Math.floor(dataRange.min / spacing) * spacing;
  14486. var niceMax = Math.ceil(dataRange.max / spacing) * spacing;
  14487. // If min, max and stepSize is set and they make an evenly spaced scale use it.
  14488. if (generationOptions.min && generationOptions.max && generationOptions.stepSize) {
  14489. // If very close to our whole number, use it.
  14490. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
  14491. niceMin = generationOptions.min;
  14492. niceMax = generationOptions.max;
  14493. }
  14494. }
  14495. var numSpaces = (niceMax - niceMin) / spacing;
  14496. // If very close to our rounded value, use it.
  14497. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  14498. numSpaces = Math.round(numSpaces);
  14499. } else {
  14500. numSpaces = Math.ceil(numSpaces);
  14501. }
  14502. var precision = 1;
  14503. if (spacing < 1) {
  14504. precision = Math.pow(10, spacing.toString().length - 2);
  14505. niceMin = Math.round(niceMin * precision) / precision;
  14506. niceMax = Math.round(niceMax * precision) / precision;
  14507. }
  14508. ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
  14509. for (var j = 1; j < numSpaces; ++j) {
  14510. ticks.push(Math.round((niceMin + j * spacing) * precision) / precision);
  14511. }
  14512. ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);
  14513. return ticks;
  14514. }
  14515. module.exports = function(Chart) {
  14516. var noop = helpers.noop;
  14517. Chart.LinearScaleBase = Chart.Scale.extend({
  14518. getRightValue: function(value) {
  14519. if (typeof value === 'string') {
  14520. return +value;
  14521. }
  14522. return Chart.Scale.prototype.getRightValue.call(this, value);
  14523. },
  14524. handleTickRangeOptions: function() {
  14525. var me = this;
  14526. var opts = me.options;
  14527. var tickOpts = opts.ticks;
  14528. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  14529. // do nothing since that would make the chart weird. If the user really wants a weird chart
  14530. // axis, they can manually override it
  14531. if (tickOpts.beginAtZero) {
  14532. var minSign = helpers.sign(me.min);
  14533. var maxSign = helpers.sign(me.max);
  14534. if (minSign < 0 && maxSign < 0) {
  14535. // move the top up to 0
  14536. me.max = 0;
  14537. } else if (minSign > 0 && maxSign > 0) {
  14538. // move the bottom down to 0
  14539. me.min = 0;
  14540. }
  14541. }
  14542. var setMin = tickOpts.min !== undefined || tickOpts.suggestedMin !== undefined;
  14543. var setMax = tickOpts.max !== undefined || tickOpts.suggestedMax !== undefined;
  14544. if (tickOpts.min !== undefined) {
  14545. me.min = tickOpts.min;
  14546. } else if (tickOpts.suggestedMin !== undefined) {
  14547. if (me.min === null) {
  14548. me.min = tickOpts.suggestedMin;
  14549. } else {
  14550. me.min = Math.min(me.min, tickOpts.suggestedMin);
  14551. }
  14552. }
  14553. if (tickOpts.max !== undefined) {
  14554. me.max = tickOpts.max;
  14555. } else if (tickOpts.suggestedMax !== undefined) {
  14556. if (me.max === null) {
  14557. me.max = tickOpts.suggestedMax;
  14558. } else {
  14559. me.max = Math.max(me.max, tickOpts.suggestedMax);
  14560. }
  14561. }
  14562. if (setMin !== setMax) {
  14563. // We set the min or the max but not both.
  14564. // So ensure that our range is good
  14565. // Inverted or 0 length range can happen when
  14566. // ticks.min is set, and no datasets are visible
  14567. if (me.min >= me.max) {
  14568. if (setMin) {
  14569. me.max = me.min + 1;
  14570. } else {
  14571. me.min = me.max - 1;
  14572. }
  14573. }
  14574. }
  14575. if (me.min === me.max) {
  14576. me.max++;
  14577. if (!tickOpts.beginAtZero) {
  14578. me.min--;
  14579. }
  14580. }
  14581. },
  14582. getTickLimit: noop,
  14583. handleDirectionalChanges: noop,
  14584. buildTicks: function() {
  14585. var me = this;
  14586. var opts = me.options;
  14587. var tickOpts = opts.ticks;
  14588. // Figure out what the max number of ticks we can support it is based on the size of
  14589. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  14590. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  14591. // the graph. Make sure we always have at least 2 ticks
  14592. var maxTicks = me.getTickLimit();
  14593. maxTicks = Math.max(2, maxTicks);
  14594. var numericGeneratorOptions = {
  14595. maxTicks: maxTicks,
  14596. min: tickOpts.min,
  14597. max: tickOpts.max,
  14598. stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
  14599. };
  14600. var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
  14601. me.handleDirectionalChanges();
  14602. // At this point, we need to update our max and min given the tick values since we have expanded the
  14603. // range of the scale
  14604. me.max = helpers.max(ticks);
  14605. me.min = helpers.min(ticks);
  14606. if (tickOpts.reverse) {
  14607. ticks.reverse();
  14608. me.start = me.max;
  14609. me.end = me.min;
  14610. } else {
  14611. me.start = me.min;
  14612. me.end = me.max;
  14613. }
  14614. },
  14615. convertTicksToLabels: function() {
  14616. var me = this;
  14617. me.ticksAsNumbers = me.ticks.slice();
  14618. me.zeroLineIndex = me.ticks.indexOf(0);
  14619. Chart.Scale.prototype.convertTicksToLabels.call(me);
  14620. }
  14621. });
  14622. };
  14623. },{"45":45}],56:[function(require,module,exports){
  14624. 'use strict';
  14625. var helpers = require(45);
  14626. var Ticks = require(34);
  14627. /**
  14628. * Generate a set of logarithmic ticks
  14629. * @param generationOptions the options used to generate the ticks
  14630. * @param dataRange the range of the data
  14631. * @returns {Array<Number>} array of tick values
  14632. */
  14633. function generateTicks(generationOptions, dataRange) {
  14634. var ticks = [];
  14635. var valueOrDefault = helpers.valueOrDefault;
  14636. // Figure out what the max number of ticks we can support it is based on the size of
  14637. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  14638. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  14639. // the graph
  14640. var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
  14641. var endExp = Math.floor(helpers.log10(dataRange.max));
  14642. var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
  14643. var exp, significand;
  14644. if (tickVal === 0) {
  14645. exp = Math.floor(helpers.log10(dataRange.minNotZero));
  14646. significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
  14647. ticks.push(tickVal);
  14648. tickVal = significand * Math.pow(10, exp);
  14649. } else {
  14650. exp = Math.floor(helpers.log10(tickVal));
  14651. significand = Math.floor(tickVal / Math.pow(10, exp));
  14652. }
  14653. var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
  14654. do {
  14655. ticks.push(tickVal);
  14656. ++significand;
  14657. if (significand === 10) {
  14658. significand = 1;
  14659. ++exp;
  14660. precision = exp >= 0 ? 1 : precision;
  14661. }
  14662. tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
  14663. } while (exp < endExp || (exp === endExp && significand < endSignificand));
  14664. var lastTick = valueOrDefault(generationOptions.max, tickVal);
  14665. ticks.push(lastTick);
  14666. return ticks;
  14667. }
  14668. module.exports = function(Chart) {
  14669. var defaultConfig = {
  14670. position: 'left',
  14671. // label settings
  14672. ticks: {
  14673. callback: Ticks.formatters.logarithmic
  14674. }
  14675. };
  14676. var LogarithmicScale = Chart.Scale.extend({
  14677. determineDataLimits: function() {
  14678. var me = this;
  14679. var opts = me.options;
  14680. var chart = me.chart;
  14681. var data = chart.data;
  14682. var datasets = data.datasets;
  14683. var isHorizontal = me.isHorizontal();
  14684. function IDMatches(meta) {
  14685. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  14686. }
  14687. // Calculate Range
  14688. me.min = null;
  14689. me.max = null;
  14690. me.minNotZero = null;
  14691. var hasStacks = opts.stacked;
  14692. if (hasStacks === undefined) {
  14693. helpers.each(datasets, function(dataset, datasetIndex) {
  14694. if (hasStacks) {
  14695. return;
  14696. }
  14697. var meta = chart.getDatasetMeta(datasetIndex);
  14698. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  14699. meta.stack !== undefined) {
  14700. hasStacks = true;
  14701. }
  14702. });
  14703. }
  14704. if (opts.stacked || hasStacks) {
  14705. var valuesPerStack = {};
  14706. helpers.each(datasets, function(dataset, datasetIndex) {
  14707. var meta = chart.getDatasetMeta(datasetIndex);
  14708. var key = [
  14709. meta.type,
  14710. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  14711. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  14712. meta.stack
  14713. ].join('.');
  14714. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  14715. if (valuesPerStack[key] === undefined) {
  14716. valuesPerStack[key] = [];
  14717. }
  14718. helpers.each(dataset.data, function(rawValue, index) {
  14719. var values = valuesPerStack[key];
  14720. var value = +me.getRightValue(rawValue);
  14721. // invalid, hidden and negative values are ignored
  14722. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  14723. return;
  14724. }
  14725. values[index] = values[index] || 0;
  14726. values[index] += value;
  14727. });
  14728. }
  14729. });
  14730. helpers.each(valuesPerStack, function(valuesForType) {
  14731. if (valuesForType.length > 0) {
  14732. var minVal = helpers.min(valuesForType);
  14733. var maxVal = helpers.max(valuesForType);
  14734. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  14735. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  14736. }
  14737. });
  14738. } else {
  14739. helpers.each(datasets, function(dataset, datasetIndex) {
  14740. var meta = chart.getDatasetMeta(datasetIndex);
  14741. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  14742. helpers.each(dataset.data, function(rawValue, index) {
  14743. var value = +me.getRightValue(rawValue);
  14744. // invalid, hidden and negative values are ignored
  14745. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  14746. return;
  14747. }
  14748. if (me.min === null) {
  14749. me.min = value;
  14750. } else if (value < me.min) {
  14751. me.min = value;
  14752. }
  14753. if (me.max === null) {
  14754. me.max = value;
  14755. } else if (value > me.max) {
  14756. me.max = value;
  14757. }
  14758. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  14759. me.minNotZero = value;
  14760. }
  14761. });
  14762. }
  14763. });
  14764. }
  14765. // Common base implementation to handle ticks.min, ticks.max
  14766. this.handleTickRangeOptions();
  14767. },
  14768. handleTickRangeOptions: function() {
  14769. var me = this;
  14770. var opts = me.options;
  14771. var tickOpts = opts.ticks;
  14772. var valueOrDefault = helpers.valueOrDefault;
  14773. var DEFAULT_MIN = 1;
  14774. var DEFAULT_MAX = 10;
  14775. me.min = valueOrDefault(tickOpts.min, me.min);
  14776. me.max = valueOrDefault(tickOpts.max, me.max);
  14777. if (me.min === me.max) {
  14778. if (me.min !== 0 && me.min !== null) {
  14779. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  14780. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  14781. } else {
  14782. me.min = DEFAULT_MIN;
  14783. me.max = DEFAULT_MAX;
  14784. }
  14785. }
  14786. if (me.min === null) {
  14787. me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
  14788. }
  14789. if (me.max === null) {
  14790. me.max = me.min !== 0
  14791. ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
  14792. : DEFAULT_MAX;
  14793. }
  14794. if (me.minNotZero === null) {
  14795. if (me.min > 0) {
  14796. me.minNotZero = me.min;
  14797. } else if (me.max < 1) {
  14798. me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
  14799. } else {
  14800. me.minNotZero = DEFAULT_MIN;
  14801. }
  14802. }
  14803. },
  14804. buildTicks: function() {
  14805. var me = this;
  14806. var opts = me.options;
  14807. var tickOpts = opts.ticks;
  14808. var reverse = !me.isHorizontal();
  14809. var generationOptions = {
  14810. min: tickOpts.min,
  14811. max: tickOpts.max
  14812. };
  14813. var ticks = me.ticks = generateTicks(generationOptions, me);
  14814. // At this point, we need to update our max and min given the tick values since we have expanded the
  14815. // range of the scale
  14816. me.max = helpers.max(ticks);
  14817. me.min = helpers.min(ticks);
  14818. if (tickOpts.reverse) {
  14819. reverse = !reverse;
  14820. me.start = me.max;
  14821. me.end = me.min;
  14822. } else {
  14823. me.start = me.min;
  14824. me.end = me.max;
  14825. }
  14826. if (reverse) {
  14827. ticks.reverse();
  14828. }
  14829. },
  14830. convertTicksToLabels: function() {
  14831. this.tickValues = this.ticks.slice();
  14832. Chart.Scale.prototype.convertTicksToLabels.call(this);
  14833. },
  14834. // Get the correct tooltip label
  14835. getLabelForIndex: function(index, datasetIndex) {
  14836. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  14837. },
  14838. getPixelForTick: function(index) {
  14839. return this.getPixelForValue(this.tickValues[index]);
  14840. },
  14841. /**
  14842. * Returns the value of the first tick.
  14843. * @param {Number} value - The minimum not zero value.
  14844. * @return {Number} The first tick value.
  14845. * @private
  14846. */
  14847. _getFirstTickValue: function(value) {
  14848. var exp = Math.floor(helpers.log10(value));
  14849. var significand = Math.floor(value / Math.pow(10, exp));
  14850. return significand * Math.pow(10, exp);
  14851. },
  14852. getPixelForValue: function(value) {
  14853. var me = this;
  14854. var reverse = me.options.ticks.reverse;
  14855. var log10 = helpers.log10;
  14856. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  14857. var offset = 0;
  14858. var innerDimension, pixel, start, end, sign;
  14859. value = +me.getRightValue(value);
  14860. if (reverse) {
  14861. start = me.end;
  14862. end = me.start;
  14863. sign = -1;
  14864. } else {
  14865. start = me.start;
  14866. end = me.end;
  14867. sign = 1;
  14868. }
  14869. if (me.isHorizontal()) {
  14870. innerDimension = me.width;
  14871. pixel = reverse ? me.right : me.left;
  14872. } else {
  14873. innerDimension = me.height;
  14874. sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
  14875. pixel = reverse ? me.top : me.bottom;
  14876. }
  14877. if (value !== start) {
  14878. if (start === 0) { // include zero tick
  14879. offset = helpers.getValueOrDefault(
  14880. me.options.ticks.fontSize,
  14881. Chart.defaults.global.defaultFontSize
  14882. );
  14883. innerDimension -= offset;
  14884. start = firstTickValue;
  14885. }
  14886. if (value !== 0) {
  14887. offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
  14888. }
  14889. pixel += sign * offset;
  14890. }
  14891. return pixel;
  14892. },
  14893. getValueForPixel: function(pixel) {
  14894. var me = this;
  14895. var reverse = me.options.ticks.reverse;
  14896. var log10 = helpers.log10;
  14897. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  14898. var innerDimension, start, end, value;
  14899. if (reverse) {
  14900. start = me.end;
  14901. end = me.start;
  14902. } else {
  14903. start = me.start;
  14904. end = me.end;
  14905. }
  14906. if (me.isHorizontal()) {
  14907. innerDimension = me.width;
  14908. value = reverse ? me.right - pixel : pixel - me.left;
  14909. } else {
  14910. innerDimension = me.height;
  14911. value = reverse ? pixel - me.top : me.bottom - pixel;
  14912. }
  14913. if (value !== start) {
  14914. if (start === 0) { // include zero tick
  14915. var offset = helpers.getValueOrDefault(
  14916. me.options.ticks.fontSize,
  14917. Chart.defaults.global.defaultFontSize
  14918. );
  14919. value -= offset;
  14920. innerDimension -= offset;
  14921. start = firstTickValue;
  14922. }
  14923. value *= log10(end) - log10(start);
  14924. value /= innerDimension;
  14925. value = Math.pow(10, log10(start) + value);
  14926. }
  14927. return value;
  14928. }
  14929. });
  14930. Chart.scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  14931. };
  14932. },{"34":34,"45":45}],57:[function(require,module,exports){
  14933. 'use strict';
  14934. var defaults = require(25);
  14935. var helpers = require(45);
  14936. var Ticks = require(34);
  14937. module.exports = function(Chart) {
  14938. var globalDefaults = defaults.global;
  14939. var defaultConfig = {
  14940. display: true,
  14941. // Boolean - Whether to animate scaling the chart from the centre
  14942. animate: true,
  14943. position: 'chartArea',
  14944. angleLines: {
  14945. display: true,
  14946. color: 'rgba(0, 0, 0, 0.1)',
  14947. lineWidth: 1
  14948. },
  14949. gridLines: {
  14950. circular: false
  14951. },
  14952. // label settings
  14953. ticks: {
  14954. // Boolean - Show a backdrop to the scale label
  14955. showLabelBackdrop: true,
  14956. // String - The colour of the label backdrop
  14957. backdropColor: 'rgba(255,255,255,0.75)',
  14958. // Number - The backdrop padding above & below the label in pixels
  14959. backdropPaddingY: 2,
  14960. // Number - The backdrop padding to the side of the label in pixels
  14961. backdropPaddingX: 2,
  14962. callback: Ticks.formatters.linear
  14963. },
  14964. pointLabels: {
  14965. // Boolean - if true, show point labels
  14966. display: true,
  14967. // Number - Point label font size in pixels
  14968. fontSize: 10,
  14969. // Function - Used to convert point labels
  14970. callback: function(label) {
  14971. return label;
  14972. }
  14973. }
  14974. };
  14975. function getValueCount(scale) {
  14976. var opts = scale.options;
  14977. return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
  14978. }
  14979. function getPointLabelFontOptions(scale) {
  14980. var pointLabelOptions = scale.options.pointLabels;
  14981. var fontSize = helpers.valueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
  14982. var fontStyle = helpers.valueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
  14983. var fontFamily = helpers.valueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
  14984. var font = helpers.fontString(fontSize, fontStyle, fontFamily);
  14985. return {
  14986. size: fontSize,
  14987. style: fontStyle,
  14988. family: fontFamily,
  14989. font: font
  14990. };
  14991. }
  14992. function measureLabelSize(ctx, fontSize, label) {
  14993. if (helpers.isArray(label)) {
  14994. return {
  14995. w: helpers.longestText(ctx, ctx.font, label),
  14996. h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
  14997. };
  14998. }
  14999. return {
  15000. w: ctx.measureText(label).width,
  15001. h: fontSize
  15002. };
  15003. }
  15004. function determineLimits(angle, pos, size, min, max) {
  15005. if (angle === min || angle === max) {
  15006. return {
  15007. start: pos - (size / 2),
  15008. end: pos + (size / 2)
  15009. };
  15010. } else if (angle < min || angle > max) {
  15011. return {
  15012. start: pos - size - 5,
  15013. end: pos
  15014. };
  15015. }
  15016. return {
  15017. start: pos,
  15018. end: pos + size + 5
  15019. };
  15020. }
  15021. /**
  15022. * Helper function to fit a radial linear scale with point labels
  15023. */
  15024. function fitWithPointLabels(scale) {
  15025. /*
  15026. * Right, this is really confusing and there is a lot of maths going on here
  15027. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  15028. *
  15029. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  15030. *
  15031. * Solution:
  15032. *
  15033. * We assume the radius of the polygon is half the size of the canvas at first
  15034. * at each index we check if the text overlaps.
  15035. *
  15036. * Where it does, we store that angle and that index.
  15037. *
  15038. * After finding the largest index and angle we calculate how much we need to remove
  15039. * from the shape radius to move the point inwards by that x.
  15040. *
  15041. * We average the left and right distances to get the maximum shape radius that can fit in the box
  15042. * along with labels.
  15043. *
  15044. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  15045. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  15046. *
  15047. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  15048. * and position it in the most space efficient manner
  15049. *
  15050. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  15051. */
  15052. var plFont = getPointLabelFontOptions(scale);
  15053. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  15054. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  15055. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  15056. var furthestLimits = {
  15057. r: scale.width,
  15058. l: 0,
  15059. t: scale.height,
  15060. b: 0
  15061. };
  15062. var furthestAngles = {};
  15063. var i, textSize, pointPosition;
  15064. scale.ctx.font = plFont.font;
  15065. scale._pointLabelSizes = [];
  15066. var valueCount = getValueCount(scale);
  15067. for (i = 0; i < valueCount; i++) {
  15068. pointPosition = scale.getPointPosition(i, largestPossibleRadius);
  15069. textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
  15070. scale._pointLabelSizes[i] = textSize;
  15071. // Add quarter circle to make degree 0 mean top of circle
  15072. var angleRadians = scale.getIndexAngle(i);
  15073. var angle = helpers.toDegrees(angleRadians) % 360;
  15074. var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
  15075. var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
  15076. if (hLimits.start < furthestLimits.l) {
  15077. furthestLimits.l = hLimits.start;
  15078. furthestAngles.l = angleRadians;
  15079. }
  15080. if (hLimits.end > furthestLimits.r) {
  15081. furthestLimits.r = hLimits.end;
  15082. furthestAngles.r = angleRadians;
  15083. }
  15084. if (vLimits.start < furthestLimits.t) {
  15085. furthestLimits.t = vLimits.start;
  15086. furthestAngles.t = angleRadians;
  15087. }
  15088. if (vLimits.end > furthestLimits.b) {
  15089. furthestLimits.b = vLimits.end;
  15090. furthestAngles.b = angleRadians;
  15091. }
  15092. }
  15093. scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
  15094. }
  15095. /**
  15096. * Helper function to fit a radial linear scale with no point labels
  15097. */
  15098. function fit(scale) {
  15099. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  15100. scale.drawingArea = Math.round(largestPossibleRadius);
  15101. scale.setCenterPoint(0, 0, 0, 0);
  15102. }
  15103. function getTextAlignForAngle(angle) {
  15104. if (angle === 0 || angle === 180) {
  15105. return 'center';
  15106. } else if (angle < 180) {
  15107. return 'left';
  15108. }
  15109. return 'right';
  15110. }
  15111. function fillText(ctx, text, position, fontSize) {
  15112. if (helpers.isArray(text)) {
  15113. var y = position.y;
  15114. var spacing = 1.5 * fontSize;
  15115. for (var i = 0; i < text.length; ++i) {
  15116. ctx.fillText(text[i], position.x, y);
  15117. y += spacing;
  15118. }
  15119. } else {
  15120. ctx.fillText(text, position.x, position.y);
  15121. }
  15122. }
  15123. function adjustPointPositionForLabelHeight(angle, textSize, position) {
  15124. if (angle === 90 || angle === 270) {
  15125. position.y -= (textSize.h / 2);
  15126. } else if (angle > 270 || angle < 90) {
  15127. position.y -= textSize.h;
  15128. }
  15129. }
  15130. function drawPointLabels(scale) {
  15131. var ctx = scale.ctx;
  15132. var opts = scale.options;
  15133. var angleLineOpts = opts.angleLines;
  15134. var pointLabelOpts = opts.pointLabels;
  15135. ctx.lineWidth = angleLineOpts.lineWidth;
  15136. ctx.strokeStyle = angleLineOpts.color;
  15137. var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
  15138. // Point Label Font
  15139. var plFont = getPointLabelFontOptions(scale);
  15140. ctx.textBaseline = 'top';
  15141. for (var i = getValueCount(scale) - 1; i >= 0; i--) {
  15142. if (angleLineOpts.display) {
  15143. var outerPosition = scale.getPointPosition(i, outerDistance);
  15144. ctx.beginPath();
  15145. ctx.moveTo(scale.xCenter, scale.yCenter);
  15146. ctx.lineTo(outerPosition.x, outerPosition.y);
  15147. ctx.stroke();
  15148. ctx.closePath();
  15149. }
  15150. if (pointLabelOpts.display) {
  15151. // Extra 3px out for some label spacing
  15152. var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
  15153. // Keep this in loop since we may support array properties here
  15154. var pointLabelFontColor = helpers.valueAtIndexOrDefault(pointLabelOpts.fontColor, i, globalDefaults.defaultFontColor);
  15155. ctx.font = plFont.font;
  15156. ctx.fillStyle = pointLabelFontColor;
  15157. var angleRadians = scale.getIndexAngle(i);
  15158. var angle = helpers.toDegrees(angleRadians);
  15159. ctx.textAlign = getTextAlignForAngle(angle);
  15160. adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
  15161. fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
  15162. }
  15163. }
  15164. }
  15165. function drawRadiusLine(scale, gridLineOpts, radius, index) {
  15166. var ctx = scale.ctx;
  15167. ctx.strokeStyle = helpers.valueAtIndexOrDefault(gridLineOpts.color, index - 1);
  15168. ctx.lineWidth = helpers.valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  15169. if (scale.options.gridLines.circular) {
  15170. // Draw circular arcs between the points
  15171. ctx.beginPath();
  15172. ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
  15173. ctx.closePath();
  15174. ctx.stroke();
  15175. } else {
  15176. // Draw straight lines connecting each index
  15177. var valueCount = getValueCount(scale);
  15178. if (valueCount === 0) {
  15179. return;
  15180. }
  15181. ctx.beginPath();
  15182. var pointPosition = scale.getPointPosition(0, radius);
  15183. ctx.moveTo(pointPosition.x, pointPosition.y);
  15184. for (var i = 1; i < valueCount; i++) {
  15185. pointPosition = scale.getPointPosition(i, radius);
  15186. ctx.lineTo(pointPosition.x, pointPosition.y);
  15187. }
  15188. ctx.closePath();
  15189. ctx.stroke();
  15190. }
  15191. }
  15192. function numberOrZero(param) {
  15193. return helpers.isNumber(param) ? param : 0;
  15194. }
  15195. var LinearRadialScale = Chart.LinearScaleBase.extend({
  15196. setDimensions: function() {
  15197. var me = this;
  15198. var opts = me.options;
  15199. var tickOpts = opts.ticks;
  15200. // Set the unconstrained dimension before label rotation
  15201. me.width = me.maxWidth;
  15202. me.height = me.maxHeight;
  15203. me.xCenter = Math.round(me.width / 2);
  15204. me.yCenter = Math.round(me.height / 2);
  15205. var minSize = helpers.min([me.height, me.width]);
  15206. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  15207. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  15208. },
  15209. determineDataLimits: function() {
  15210. var me = this;
  15211. var chart = me.chart;
  15212. var min = Number.POSITIVE_INFINITY;
  15213. var max = Number.NEGATIVE_INFINITY;
  15214. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  15215. if (chart.isDatasetVisible(datasetIndex)) {
  15216. var meta = chart.getDatasetMeta(datasetIndex);
  15217. helpers.each(dataset.data, function(rawValue, index) {
  15218. var value = +me.getRightValue(rawValue);
  15219. if (isNaN(value) || meta.data[index].hidden) {
  15220. return;
  15221. }
  15222. min = Math.min(value, min);
  15223. max = Math.max(value, max);
  15224. });
  15225. }
  15226. });
  15227. me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
  15228. me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
  15229. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  15230. me.handleTickRangeOptions();
  15231. },
  15232. getTickLimit: function() {
  15233. var tickOpts = this.options.ticks;
  15234. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  15235. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  15236. },
  15237. convertTicksToLabels: function() {
  15238. var me = this;
  15239. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  15240. // Point labels
  15241. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  15242. },
  15243. getLabelForIndex: function(index, datasetIndex) {
  15244. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  15245. },
  15246. fit: function() {
  15247. if (this.options.pointLabels.display) {
  15248. fitWithPointLabels(this);
  15249. } else {
  15250. fit(this);
  15251. }
  15252. },
  15253. /**
  15254. * Set radius reductions and determine new radius and center point
  15255. * @private
  15256. */
  15257. setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
  15258. var me = this;
  15259. var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
  15260. var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
  15261. var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
  15262. var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
  15263. radiusReductionLeft = numberOrZero(radiusReductionLeft);
  15264. radiusReductionRight = numberOrZero(radiusReductionRight);
  15265. radiusReductionTop = numberOrZero(radiusReductionTop);
  15266. radiusReductionBottom = numberOrZero(radiusReductionBottom);
  15267. me.drawingArea = Math.min(
  15268. Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
  15269. Math.round(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
  15270. me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
  15271. },
  15272. setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
  15273. var me = this;
  15274. var maxRight = me.width - rightMovement - me.drawingArea;
  15275. var maxLeft = leftMovement + me.drawingArea;
  15276. var maxTop = topMovement + me.drawingArea;
  15277. var maxBottom = me.height - bottomMovement - me.drawingArea;
  15278. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  15279. me.yCenter = Math.round(((maxTop + maxBottom) / 2) + me.top);
  15280. },
  15281. getIndexAngle: function(index) {
  15282. var angleMultiplier = (Math.PI * 2) / getValueCount(this);
  15283. var startAngle = this.chart.options && this.chart.options.startAngle ?
  15284. this.chart.options.startAngle :
  15285. 0;
  15286. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  15287. // Start from the top instead of right, so remove a quarter of the circle
  15288. return index * angleMultiplier + startAngleRadians;
  15289. },
  15290. getDistanceFromCenterForValue: function(value) {
  15291. var me = this;
  15292. if (value === null) {
  15293. return 0; // null always in center
  15294. }
  15295. // Take into account half font size + the yPadding of the top value
  15296. var scalingFactor = me.drawingArea / (me.max - me.min);
  15297. if (me.options.ticks.reverse) {
  15298. return (me.max - value) * scalingFactor;
  15299. }
  15300. return (value - me.min) * scalingFactor;
  15301. },
  15302. getPointPosition: function(index, distanceFromCenter) {
  15303. var me = this;
  15304. var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
  15305. return {
  15306. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  15307. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  15308. };
  15309. },
  15310. getPointPositionForValue: function(index, value) {
  15311. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  15312. },
  15313. getBasePosition: function() {
  15314. var me = this;
  15315. var min = me.min;
  15316. var max = me.max;
  15317. return me.getPointPositionForValue(0,
  15318. me.beginAtZero ? 0 :
  15319. min < 0 && max < 0 ? max :
  15320. min > 0 && max > 0 ? min :
  15321. 0);
  15322. },
  15323. draw: function() {
  15324. var me = this;
  15325. var opts = me.options;
  15326. var gridLineOpts = opts.gridLines;
  15327. var tickOpts = opts.ticks;
  15328. var valueOrDefault = helpers.valueOrDefault;
  15329. if (opts.display) {
  15330. var ctx = me.ctx;
  15331. var startAngle = this.getIndexAngle(0);
  15332. // Tick Font
  15333. var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  15334. var tickFontStyle = valueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  15335. var tickFontFamily = valueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  15336. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  15337. helpers.each(me.ticks, function(label, index) {
  15338. // Don't draw a centre value (if it is minimum)
  15339. if (index > 0 || tickOpts.reverse) {
  15340. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  15341. // Draw circular lines around the scale
  15342. if (gridLineOpts.display && index !== 0) {
  15343. drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
  15344. }
  15345. if (tickOpts.display) {
  15346. var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  15347. ctx.font = tickLabelFont;
  15348. ctx.save();
  15349. ctx.translate(me.xCenter, me.yCenter);
  15350. ctx.rotate(startAngle);
  15351. if (tickOpts.showLabelBackdrop) {
  15352. var labelWidth = ctx.measureText(label).width;
  15353. ctx.fillStyle = tickOpts.backdropColor;
  15354. ctx.fillRect(
  15355. -labelWidth / 2 - tickOpts.backdropPaddingX,
  15356. -yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
  15357. labelWidth + tickOpts.backdropPaddingX * 2,
  15358. tickFontSize + tickOpts.backdropPaddingY * 2
  15359. );
  15360. }
  15361. ctx.textAlign = 'center';
  15362. ctx.textBaseline = 'middle';
  15363. ctx.fillStyle = tickFontColor;
  15364. ctx.fillText(label, 0, -yCenterOffset);
  15365. ctx.restore();
  15366. }
  15367. }
  15368. });
  15369. if (opts.angleLines.display || opts.pointLabels.display) {
  15370. drawPointLabels(me);
  15371. }
  15372. }
  15373. }
  15374. });
  15375. Chart.scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  15376. };
  15377. },{"25":25,"34":34,"45":45}],58:[function(require,module,exports){
  15378. /* global window: false */
  15379. 'use strict';
  15380. var moment = require(6);
  15381. moment = typeof moment === 'function' ? moment : window.moment;
  15382. var defaults = require(25);
  15383. var helpers = require(45);
  15384. // Integer constants are from the ES6 spec.
  15385. var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
  15386. var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  15387. var INTERVALS = {
  15388. millisecond: {
  15389. common: true,
  15390. size: 1,
  15391. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  15392. },
  15393. second: {
  15394. common: true,
  15395. size: 1000,
  15396. steps: [1, 2, 5, 10, 30]
  15397. },
  15398. minute: {
  15399. common: true,
  15400. size: 60000,
  15401. steps: [1, 2, 5, 10, 30]
  15402. },
  15403. hour: {
  15404. common: true,
  15405. size: 3600000,
  15406. steps: [1, 2, 3, 6, 12]
  15407. },
  15408. day: {
  15409. common: true,
  15410. size: 86400000,
  15411. steps: [1, 2, 5]
  15412. },
  15413. week: {
  15414. common: false,
  15415. size: 604800000,
  15416. steps: [1, 2, 3, 4]
  15417. },
  15418. month: {
  15419. common: true,
  15420. size: 2.628e9,
  15421. steps: [1, 2, 3]
  15422. },
  15423. quarter: {
  15424. common: false,
  15425. size: 7.884e9,
  15426. steps: [1, 2, 3, 4]
  15427. },
  15428. year: {
  15429. common: true,
  15430. size: 3.154e10
  15431. }
  15432. };
  15433. var UNITS = Object.keys(INTERVALS);
  15434. function sorter(a, b) {
  15435. return a - b;
  15436. }
  15437. function arrayUnique(items) {
  15438. var hash = {};
  15439. var out = [];
  15440. var i, ilen, item;
  15441. for (i = 0, ilen = items.length; i < ilen; ++i) {
  15442. item = items[i];
  15443. if (!hash[item]) {
  15444. hash[item] = true;
  15445. out.push(item);
  15446. }
  15447. }
  15448. return out;
  15449. }
  15450. /**
  15451. * Returns an array of {time, pos} objects used to interpolate a specific `time` or position
  15452. * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
  15453. * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other
  15454. * extremity (left + width or top + height). Note that it would be more optimized to directly
  15455. * store pre-computed pixels, but the scale dimensions are not guaranteed at the time we need
  15456. * to create the lookup table. The table ALWAYS contains at least two items: min and max.
  15457. *
  15458. * @param {Number[]} timestamps - timestamps sorted from lowest to highest.
  15459. * @param {String} distribution - If 'linear', timestamps will be spread linearly along the min
  15460. * and max range, so basically, the table will contains only two items: {min, 0} and {max, 1}.
  15461. * If 'series', timestamps will be positioned at the same distance from each other. In this
  15462. * case, only timestamps that break the time linearity are registered, meaning that in the
  15463. * best case, all timestamps are linear, the table contains only min and max.
  15464. */
  15465. function buildLookupTable(timestamps, min, max, distribution) {
  15466. if (distribution === 'linear' || !timestamps.length) {
  15467. return [
  15468. {time: min, pos: 0},
  15469. {time: max, pos: 1}
  15470. ];
  15471. }
  15472. var table = [];
  15473. var items = [min];
  15474. var i, ilen, prev, curr, next;
  15475. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  15476. curr = timestamps[i];
  15477. if (curr > min && curr < max) {
  15478. items.push(curr);
  15479. }
  15480. }
  15481. items.push(max);
  15482. for (i = 0, ilen = items.length; i < ilen; ++i) {
  15483. next = items[i + 1];
  15484. prev = items[i - 1];
  15485. curr = items[i];
  15486. // only add points that breaks the scale linearity
  15487. if (prev === undefined || next === undefined || Math.round((next + prev) / 2) !== curr) {
  15488. table.push({time: curr, pos: i / (ilen - 1)});
  15489. }
  15490. }
  15491. return table;
  15492. }
  15493. // @see adapted from http://www.anujgakhar.com/2014/03/01/binary-search-in-javascript/
  15494. function lookup(table, key, value) {
  15495. var lo = 0;
  15496. var hi = table.length - 1;
  15497. var mid, i0, i1;
  15498. while (lo >= 0 && lo <= hi) {
  15499. mid = (lo + hi) >> 1;
  15500. i0 = table[mid - 1] || null;
  15501. i1 = table[mid];
  15502. if (!i0) {
  15503. // given value is outside table (before first item)
  15504. return {lo: null, hi: i1};
  15505. } else if (i1[key] < value) {
  15506. lo = mid + 1;
  15507. } else if (i0[key] > value) {
  15508. hi = mid - 1;
  15509. } else {
  15510. return {lo: i0, hi: i1};
  15511. }
  15512. }
  15513. // given value is outside table (after last item)
  15514. return {lo: i1, hi: null};
  15515. }
  15516. /**
  15517. * Linearly interpolates the given source `value` using the table items `skey` values and
  15518. * returns the associated `tkey` value. For example, interpolate(table, 'time', 42, 'pos')
  15519. * returns the position for a timestamp equal to 42. If value is out of bounds, values at
  15520. * index [0, 1] or [n - 1, n] are used for the interpolation.
  15521. */
  15522. function interpolate(table, skey, sval, tkey) {
  15523. var range = lookup(table, skey, sval);
  15524. // Note: the lookup table ALWAYS contains at least 2 items (min and max)
  15525. var prev = !range.lo ? table[0] : !range.hi ? table[table.length - 2] : range.lo;
  15526. var next = !range.lo ? table[1] : !range.hi ? table[table.length - 1] : range.hi;
  15527. var span = next[skey] - prev[skey];
  15528. var ratio = span ? (sval - prev[skey]) / span : 0;
  15529. var offset = (next[tkey] - prev[tkey]) * ratio;
  15530. return prev[tkey] + offset;
  15531. }
  15532. /**
  15533. * Convert the given value to a moment object using the given time options.
  15534. * @see http://momentjs.com/docs/#/parsing/
  15535. */
  15536. function momentify(value, options) {
  15537. var parser = options.parser;
  15538. var format = options.parser || options.format;
  15539. if (typeof parser === 'function') {
  15540. return parser(value);
  15541. }
  15542. if (typeof value === 'string' && typeof format === 'string') {
  15543. return moment(value, format);
  15544. }
  15545. if (!(value instanceof moment)) {
  15546. value = moment(value);
  15547. }
  15548. if (value.isValid()) {
  15549. return value;
  15550. }
  15551. // Labels are in an incompatible moment format and no `parser` has been provided.
  15552. // The user might still use the deprecated `format` option to convert his inputs.
  15553. if (typeof format === 'function') {
  15554. return format(value);
  15555. }
  15556. return value;
  15557. }
  15558. function parse(input, scale) {
  15559. if (helpers.isNullOrUndef(input)) {
  15560. return null;
  15561. }
  15562. var options = scale.options.time;
  15563. var value = momentify(scale.getRightValue(input), options);
  15564. if (!value.isValid()) {
  15565. return null;
  15566. }
  15567. if (options.round) {
  15568. value.startOf(options.round);
  15569. }
  15570. return value.valueOf();
  15571. }
  15572. /**
  15573. * Returns the number of unit to skip to be able to display up to `capacity` number of ticks
  15574. * in `unit` for the given `min` / `max` range and respecting the interval steps constraints.
  15575. */
  15576. function determineStepSize(min, max, unit, capacity) {
  15577. var range = max - min;
  15578. var interval = INTERVALS[unit];
  15579. var milliseconds = interval.size;
  15580. var steps = interval.steps;
  15581. var i, ilen, factor;
  15582. if (!steps) {
  15583. return Math.ceil(range / (capacity * milliseconds));
  15584. }
  15585. for (i = 0, ilen = steps.length; i < ilen; ++i) {
  15586. factor = steps[i];
  15587. if (Math.ceil(range / (milliseconds * factor)) <= capacity) {
  15588. break;
  15589. }
  15590. }
  15591. return factor;
  15592. }
  15593. /**
  15594. * Figures out what unit results in an appropriate number of auto-generated ticks
  15595. */
  15596. function determineUnitForAutoTicks(minUnit, min, max, capacity) {
  15597. var ilen = UNITS.length;
  15598. var i, interval, factor;
  15599. for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
  15600. interval = INTERVALS[UNITS[i]];
  15601. factor = interval.steps ? interval.steps[interval.steps.length - 1] : MAX_INTEGER;
  15602. if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
  15603. return UNITS[i];
  15604. }
  15605. }
  15606. return UNITS[ilen - 1];
  15607. }
  15608. /**
  15609. * Figures out what unit to format a set of ticks with
  15610. */
  15611. function determineUnitForFormatting(ticks, minUnit, min, max) {
  15612. var duration = moment.duration(moment(max).diff(moment(min)));
  15613. var ilen = UNITS.length;
  15614. var i, unit;
  15615. for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
  15616. unit = UNITS[i];
  15617. if (INTERVALS[unit].common && duration.as(unit) >= ticks.length) {
  15618. return unit;
  15619. }
  15620. }
  15621. return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
  15622. }
  15623. function determineMajorUnit(unit) {
  15624. for (var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i) {
  15625. if (INTERVALS[UNITS[i]].common) {
  15626. return UNITS[i];
  15627. }
  15628. }
  15629. }
  15630. /**
  15631. * Generates a maximum of `capacity` timestamps between min and max, rounded to the
  15632. * `minor` unit, aligned on the `major` unit and using the given scale time `options`.
  15633. * Important: this method can return ticks outside the min and max range, it's the
  15634. * responsibility of the calling code to clamp values if needed.
  15635. */
  15636. function generate(min, max, capacity, options) {
  15637. var timeOpts = options.time;
  15638. var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, capacity);
  15639. var major = determineMajorUnit(minor);
  15640. var stepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
  15641. var weekday = minor === 'week' ? timeOpts.isoWeekday : false;
  15642. var majorTicksEnabled = options.ticks.major.enabled;
  15643. var interval = INTERVALS[minor];
  15644. var first = moment(min);
  15645. var last = moment(max);
  15646. var ticks = [];
  15647. var time;
  15648. if (!stepSize) {
  15649. stepSize = determineStepSize(min, max, minor, capacity);
  15650. }
  15651. // For 'week' unit, handle the first day of week option
  15652. if (weekday) {
  15653. first = first.isoWeekday(weekday);
  15654. last = last.isoWeekday(weekday);
  15655. }
  15656. // Align first/last ticks on unit
  15657. first = first.startOf(weekday ? 'day' : minor);
  15658. last = last.startOf(weekday ? 'day' : minor);
  15659. // Make sure that the last tick include max
  15660. if (last < max) {
  15661. last.add(1, minor);
  15662. }
  15663. time = moment(first);
  15664. if (majorTicksEnabled && major && !weekday && !timeOpts.round) {
  15665. // Align the first tick on the previous `minor` unit aligned on the `major` unit:
  15666. // we first aligned time on the previous `major` unit then add the number of full
  15667. // stepSize there is between first and the previous major time.
  15668. time.startOf(major);
  15669. time.add(~~((first - time) / (interval.size * stepSize)) * stepSize, minor);
  15670. }
  15671. for (; time < last; time.add(stepSize, minor)) {
  15672. ticks.push(+time);
  15673. }
  15674. ticks.push(+time);
  15675. return ticks;
  15676. }
  15677. /**
  15678. * Returns the right and left offsets from edges in the form of {left, right}.
  15679. * Offsets are added when the `offset` option is true.
  15680. */
  15681. function computeOffsets(table, ticks, min, max, options) {
  15682. var left = 0;
  15683. var right = 0;
  15684. var upper, lower;
  15685. if (options.offset && ticks.length) {
  15686. if (!options.time.min) {
  15687. upper = ticks.length > 1 ? ticks[1] : max;
  15688. lower = ticks[0];
  15689. left = (
  15690. interpolate(table, 'time', upper, 'pos') -
  15691. interpolate(table, 'time', lower, 'pos')
  15692. ) / 2;
  15693. }
  15694. if (!options.time.max) {
  15695. upper = ticks[ticks.length - 1];
  15696. lower = ticks.length > 1 ? ticks[ticks.length - 2] : min;
  15697. right = (
  15698. interpolate(table, 'time', upper, 'pos') -
  15699. interpolate(table, 'time', lower, 'pos')
  15700. ) / 2;
  15701. }
  15702. }
  15703. return {left: left, right: right};
  15704. }
  15705. function ticksFromTimestamps(values, majorUnit) {
  15706. var ticks = [];
  15707. var i, ilen, value, major;
  15708. for (i = 0, ilen = values.length; i < ilen; ++i) {
  15709. value = values[i];
  15710. major = majorUnit ? value === +moment(value).startOf(majorUnit) : false;
  15711. ticks.push({
  15712. value: value,
  15713. major: major
  15714. });
  15715. }
  15716. return ticks;
  15717. }
  15718. function determineLabelFormat(data, timeOpts) {
  15719. var i, momentDate, hasTime;
  15720. var ilen = data.length;
  15721. // find the label with the most parts (milliseconds, minutes, etc.)
  15722. // format all labels with the same level of detail as the most specific label
  15723. for (i = 0; i < ilen; i++) {
  15724. momentDate = momentify(data[i], timeOpts);
  15725. if (momentDate.millisecond() !== 0) {
  15726. return 'MMM D, YYYY h:mm:ss.SSS a';
  15727. }
  15728. if (momentDate.second() !== 0 || momentDate.minute() !== 0 || momentDate.hour() !== 0) {
  15729. hasTime = true;
  15730. }
  15731. }
  15732. if (hasTime) {
  15733. return 'MMM D, YYYY h:mm:ss a';
  15734. }
  15735. return 'MMM D, YYYY';
  15736. }
  15737. module.exports = function(Chart) {
  15738. var defaultConfig = {
  15739. position: 'bottom',
  15740. /**
  15741. * Data distribution along the scale:
  15742. * - 'linear': data are spread according to their time (distances can vary),
  15743. * - 'series': data are spread at the same distance from each other.
  15744. * @see https://github.com/chartjs/Chart.js/pull/4507
  15745. * @since 2.7.0
  15746. */
  15747. distribution: 'linear',
  15748. /**
  15749. * Scale boundary strategy (bypassed by min/max time options)
  15750. * - `data`: make sure data are fully visible, ticks outside are removed
  15751. * - `ticks`: make sure ticks are fully visible, data outside are truncated
  15752. * @see https://github.com/chartjs/Chart.js/pull/4556
  15753. * @since 2.7.0
  15754. */
  15755. bounds: 'data',
  15756. time: {
  15757. 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
  15758. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  15759. unit: false, // false == automatic or override with week, month, year, etc.
  15760. round: false, // none, or override with week, month, year, etc.
  15761. displayFormat: false, // DEPRECATED
  15762. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  15763. minUnit: 'millisecond',
  15764. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  15765. displayFormats: {
  15766. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  15767. second: 'h:mm:ss a', // 11:20:01 AM
  15768. minute: 'h:mm a', // 11:20 AM
  15769. hour: 'hA', // 5PM
  15770. day: 'MMM D', // Sep 4
  15771. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  15772. month: 'MMM YYYY', // Sept 2015
  15773. quarter: '[Q]Q - YYYY', // Q3
  15774. year: 'YYYY' // 2015
  15775. },
  15776. },
  15777. ticks: {
  15778. autoSkip: false,
  15779. /**
  15780. * Ticks generation input values:
  15781. * - 'auto': generates "optimal" ticks based on scale size and time options.
  15782. * - 'data': generates ticks from data (including labels from data {t|x|y} objects).
  15783. * - 'labels': generates ticks from user given `data.labels` values ONLY.
  15784. * @see https://github.com/chartjs/Chart.js/pull/4507
  15785. * @since 2.7.0
  15786. */
  15787. source: 'auto',
  15788. major: {
  15789. enabled: false
  15790. }
  15791. }
  15792. };
  15793. var TimeScale = Chart.Scale.extend({
  15794. initialize: function() {
  15795. if (!moment) {
  15796. 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');
  15797. }
  15798. this.mergeTicksOptions();
  15799. Chart.Scale.prototype.initialize.call(this);
  15800. },
  15801. update: function() {
  15802. var me = this;
  15803. var options = me.options;
  15804. // DEPRECATIONS: output a message only one time per update
  15805. if (options.time && options.time.format) {
  15806. console.warn('options.time.format is deprecated and replaced by options.time.parser.');
  15807. }
  15808. return Chart.Scale.prototype.update.apply(me, arguments);
  15809. },
  15810. /**
  15811. * Allows data to be referenced via 't' attribute
  15812. */
  15813. getRightValue: function(rawValue) {
  15814. if (rawValue && rawValue.t !== undefined) {
  15815. rawValue = rawValue.t;
  15816. }
  15817. return Chart.Scale.prototype.getRightValue.call(this, rawValue);
  15818. },
  15819. determineDataLimits: function() {
  15820. var me = this;
  15821. var chart = me.chart;
  15822. var timeOpts = me.options.time;
  15823. var unit = timeOpts.unit || 'day';
  15824. var min = MAX_INTEGER;
  15825. var max = MIN_INTEGER;
  15826. var timestamps = [];
  15827. var datasets = [];
  15828. var labels = [];
  15829. var i, j, ilen, jlen, data, timestamp;
  15830. // Convert labels to timestamps
  15831. for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) {
  15832. labels.push(parse(chart.data.labels[i], me));
  15833. }
  15834. // Convert data to timestamps
  15835. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  15836. if (chart.isDatasetVisible(i)) {
  15837. data = chart.data.datasets[i].data;
  15838. // Let's consider that all data have the same format.
  15839. if (helpers.isObject(data[0])) {
  15840. datasets[i] = [];
  15841. for (j = 0, jlen = data.length; j < jlen; ++j) {
  15842. timestamp = parse(data[j], me);
  15843. timestamps.push(timestamp);
  15844. datasets[i][j] = timestamp;
  15845. }
  15846. } else {
  15847. timestamps.push.apply(timestamps, labels);
  15848. datasets[i] = labels.slice(0);
  15849. }
  15850. } else {
  15851. datasets[i] = [];
  15852. }
  15853. }
  15854. if (labels.length) {
  15855. // Sort labels **after** data have been converted
  15856. labels = arrayUnique(labels).sort(sorter);
  15857. min = Math.min(min, labels[0]);
  15858. max = Math.max(max, labels[labels.length - 1]);
  15859. }
  15860. if (timestamps.length) {
  15861. timestamps = arrayUnique(timestamps).sort(sorter);
  15862. min = Math.min(min, timestamps[0]);
  15863. max = Math.max(max, timestamps[timestamps.length - 1]);
  15864. }
  15865. min = parse(timeOpts.min, me) || min;
  15866. max = parse(timeOpts.max, me) || max;
  15867. // In case there is no valid min/max, set limits based on unit time option
  15868. min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
  15869. max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;
  15870. // Make sure that max is strictly higher than min (required by the lookup table)
  15871. me.min = Math.min(min, max);
  15872. me.max = Math.max(min + 1, max);
  15873. // PRIVATE
  15874. me._horizontal = me.isHorizontal();
  15875. me._table = [];
  15876. me._timestamps = {
  15877. data: timestamps,
  15878. datasets: datasets,
  15879. labels: labels
  15880. };
  15881. },
  15882. buildTicks: function() {
  15883. var me = this;
  15884. var min = me.min;
  15885. var max = me.max;
  15886. var options = me.options;
  15887. var timeOpts = options.time;
  15888. var timestamps = [];
  15889. var ticks = [];
  15890. var i, ilen, timestamp;
  15891. switch (options.ticks.source) {
  15892. case 'data':
  15893. timestamps = me._timestamps.data;
  15894. break;
  15895. case 'labels':
  15896. timestamps = me._timestamps.labels;
  15897. break;
  15898. case 'auto':
  15899. default:
  15900. timestamps = generate(min, max, me.getLabelCapacity(min), options);
  15901. }
  15902. if (options.bounds === 'ticks' && timestamps.length) {
  15903. min = timestamps[0];
  15904. max = timestamps[timestamps.length - 1];
  15905. }
  15906. // Enforce limits with user min/max options
  15907. min = parse(timeOpts.min, me) || min;
  15908. max = parse(timeOpts.max, me) || max;
  15909. // Remove ticks outside the min/max range
  15910. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  15911. timestamp = timestamps[i];
  15912. if (timestamp >= min && timestamp <= max) {
  15913. ticks.push(timestamp);
  15914. }
  15915. }
  15916. me.min = min;
  15917. me.max = max;
  15918. // PRIVATE
  15919. me._unit = timeOpts.unit || determineUnitForFormatting(ticks, timeOpts.minUnit, me.min, me.max);
  15920. me._majorUnit = determineMajorUnit(me._unit);
  15921. me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
  15922. me._offsets = computeOffsets(me._table, ticks, min, max, options);
  15923. me._labelFormat = determineLabelFormat(me._timestamps.data, timeOpts);
  15924. return ticksFromTimestamps(ticks, me._majorUnit);
  15925. },
  15926. getLabelForIndex: function(index, datasetIndex) {
  15927. var me = this;
  15928. var data = me.chart.data;
  15929. var timeOpts = me.options.time;
  15930. var label = data.labels && index < data.labels.length ? data.labels[index] : '';
  15931. var value = data.datasets[datasetIndex].data[index];
  15932. if (helpers.isObject(value)) {
  15933. label = me.getRightValue(value);
  15934. }
  15935. if (timeOpts.tooltipFormat) {
  15936. return momentify(label, timeOpts).format(timeOpts.tooltipFormat);
  15937. }
  15938. if (typeof label === 'string') {
  15939. return label;
  15940. }
  15941. return momentify(label, timeOpts).format(me._labelFormat);
  15942. },
  15943. /**
  15944. * Function to format an individual tick mark
  15945. * @private
  15946. */
  15947. tickFormatFunction: function(tick, index, ticks, formatOverride) {
  15948. var me = this;
  15949. var options = me.options;
  15950. var time = tick.valueOf();
  15951. var formats = options.time.displayFormats;
  15952. var minorFormat = formats[me._unit];
  15953. var majorUnit = me._majorUnit;
  15954. var majorFormat = formats[majorUnit];
  15955. var majorTime = tick.clone().startOf(majorUnit).valueOf();
  15956. var majorTickOpts = options.ticks.major;
  15957. var major = majorTickOpts.enabled && majorUnit && majorFormat && time === majorTime;
  15958. var label = tick.format(formatOverride ? formatOverride : major ? majorFormat : minorFormat);
  15959. var tickOpts = major ? majorTickOpts : options.ticks.minor;
  15960. var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
  15961. return formatter ? formatter(label, index, ticks) : label;
  15962. },
  15963. convertTicksToLabels: function(ticks) {
  15964. var labels = [];
  15965. var i, ilen;
  15966. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  15967. labels.push(this.tickFormatFunction(moment(ticks[i].value), i, ticks));
  15968. }
  15969. return labels;
  15970. },
  15971. /**
  15972. * @private
  15973. */
  15974. getPixelForOffset: function(time) {
  15975. var me = this;
  15976. var size = me._horizontal ? me.width : me.height;
  15977. var start = me._horizontal ? me.left : me.top;
  15978. var pos = interpolate(me._table, 'time', time, 'pos');
  15979. return start + size * (me._offsets.left + pos) / (me._offsets.left + 1 + me._offsets.right);
  15980. },
  15981. getPixelForValue: function(value, index, datasetIndex) {
  15982. var me = this;
  15983. var time = null;
  15984. if (index !== undefined && datasetIndex !== undefined) {
  15985. time = me._timestamps.datasets[datasetIndex][index];
  15986. }
  15987. if (time === null) {
  15988. time = parse(value, me);
  15989. }
  15990. if (time !== null) {
  15991. return me.getPixelForOffset(time);
  15992. }
  15993. },
  15994. getPixelForTick: function(index) {
  15995. var ticks = this.getTicks();
  15996. return index >= 0 && index < ticks.length ?
  15997. this.getPixelForOffset(ticks[index].value) :
  15998. null;
  15999. },
  16000. getValueForPixel: function(pixel) {
  16001. var me = this;
  16002. var size = me._horizontal ? me.width : me.height;
  16003. var start = me._horizontal ? me.left : me.top;
  16004. var pos = (size ? (pixel - start) / size : 0) * (me._offsets.left + 1 + me._offsets.left) - me._offsets.right;
  16005. var time = interpolate(me._table, 'pos', pos, 'time');
  16006. return moment(time);
  16007. },
  16008. /**
  16009. * Crude approximation of what the label width might be
  16010. * @private
  16011. */
  16012. getLabelWidth: function(label) {
  16013. var me = this;
  16014. var ticksOpts = me.options.ticks;
  16015. var tickLabelWidth = me.ctx.measureText(label).width;
  16016. var angle = helpers.toRadians(ticksOpts.maxRotation);
  16017. var cosRotation = Math.cos(angle);
  16018. var sinRotation = Math.sin(angle);
  16019. var tickFontSize = helpers.valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize);
  16020. return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  16021. },
  16022. /**
  16023. * @private
  16024. */
  16025. getLabelCapacity: function(exampleTime) {
  16026. var me = this;
  16027. var formatOverride = me.options.time.displayFormats.millisecond; // Pick the longest format for guestimation
  16028. var exampleLabel = me.tickFormatFunction(moment(exampleTime), 0, [], formatOverride);
  16029. var tickLabelWidth = me.getLabelWidth(exampleLabel);
  16030. var innerWidth = me.isHorizontal() ? me.width : me.height;
  16031. var capacity = Math.floor(innerWidth / tickLabelWidth);
  16032. return capacity > 0 ? capacity : 1;
  16033. }
  16034. });
  16035. Chart.scaleService.registerScaleType('time', TimeScale, defaultConfig);
  16036. };
  16037. },{"25":25,"45":45,"6":6}]},{},[7])(7)
  16038. });