mdb.js 472 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923
  1. /*!
  2. * Material Design for Bootstrap 4
  3. * Version: MDB FREE: 4.8.2
  4. *
  5. *
  6. * Copyright: Material Design for Bootstrap
  7. * https://mdbootstrap.com/
  8. *
  9. * Read the license: https://mdbootstrap.com/general/license/
  10. *
  11. *
  12. * Documentation: https://mdbootstrap.com/
  13. *
  14. * Getting started: https://mdbootstrap.com/docs/jquery/getting-started/download/
  15. *
  16. * Tutorials: https://mdbootstrap.com/education/bootstrap/
  17. *
  18. * Templates: https://mdbootstrap.com/templates/
  19. *
  20. * Support: https://mdbootstrap.com/forums/forum/support/
  21. *
  22. * Contact: office@mdbootstrap.com
  23. *
  24. * Attribution: Animate CSS, Twitter Bootstrap, Materialize CSS, Normalize CSS, Waves JS, WOW JS, Toastr, Chart.jss
  25. *
  26. */
  27. /*
  28. jquery.easing.js
  29. velocity.min.js
  30. chart.js
  31. wow.js
  32. scrolling-navbar.js
  33. waves.js
  34. forms-free.js
  35. enhanced-modals.js
  36. treeview.js
  37. */
  38. /*
  39. * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
  40. *
  41. * Uses the built in easing capabilities added In jQuery 1.1
  42. * to offer multiple easing options
  43. *
  44. * TERMS OF USE - jQuery Easing
  45. *
  46. * Open source under the BSD License.
  47. *
  48. * Copyright © 2008 George McGinley Smith
  49. * All rights reserved.
  50. *
  51. * Redistribution and use in source and binary forms, with or without modification,
  52. * are permitted provided that the following conditions are met:
  53. *
  54. * Redistributions of source code must retain the above copyright notice, this list of
  55. * conditions and the following disclaimer.
  56. * Redistributions in binary form must reproduce the above copyright notice, this list
  57. * of conditions and the following disclaimer in the documentation and/or other materials
  58. * provided with the distribution.
  59. *
  60. * Neither the name of the author nor the names of contributors may be used to endorse
  61. * or promote products derived from this software without specific prior written permission.
  62. *
  63. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  64. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  65. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  66. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  67. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  68. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  69. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  70. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  71. * OF THE POSSIBILITY OF SUCH DAMAGE.
  72. *
  73. */
  74. // t: current time, b: begInnIng value, c: change In value, d: duration
  75. jQuery.easing['jswing'] = jQuery.easing['swing'];
  76. jQuery.extend( jQuery.easing,
  77. {
  78. def: 'easeOutQuad',
  79. swing: function (x, t, b, c, d) {
  80. //alert(jQuery.easing.default);
  81. return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
  82. },
  83. easeInQuad: function (x, t, b, c, d) {
  84. return c*(t/=d)*t + b;
  85. },
  86. easeOutQuad: function (x, t, b, c, d) {
  87. return -c *(t/=d)*(t-2) + b;
  88. },
  89. easeInOutQuad: function (x, t, b, c, d) {
  90. if ((t/=d/2) < 1) return c/2*t*t + b;
  91. return -c/2 * ((--t)*(t-2) - 1) + b;
  92. },
  93. easeInCubic: function (x, t, b, c, d) {
  94. return c*(t/=d)*t*t + b;
  95. },
  96. easeOutCubic: function (x, t, b, c, d) {
  97. return c*((t=t/d-1)*t*t + 1) + b;
  98. },
  99. easeInOutCubic: function (x, t, b, c, d) {
  100. if ((t/=d/2) < 1) return c/2*t*t*t + b;
  101. return c/2*((t-=2)*t*t + 2) + b;
  102. },
  103. easeInQuart: function (x, t, b, c, d) {
  104. return c*(t/=d)*t*t*t + b;
  105. },
  106. easeOutQuart: function (x, t, b, c, d) {
  107. return -c * ((t=t/d-1)*t*t*t - 1) + b;
  108. },
  109. easeInOutQuart: function (x, t, b, c, d) {
  110. if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
  111. return -c/2 * ((t-=2)*t*t*t - 2) + b;
  112. },
  113. easeInQuint: function (x, t, b, c, d) {
  114. return c*(t/=d)*t*t*t*t + b;
  115. },
  116. easeOutQuint: function (x, t, b, c, d) {
  117. return c*((t=t/d-1)*t*t*t*t + 1) + b;
  118. },
  119. easeInOutQuint: function (x, t, b, c, d) {
  120. if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
  121. return c/2*((t-=2)*t*t*t*t + 2) + b;
  122. },
  123. easeInSine: function (x, t, b, c, d) {
  124. return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
  125. },
  126. easeOutSine: function (x, t, b, c, d) {
  127. return c * Math.sin(t/d * (Math.PI/2)) + b;
  128. },
  129. easeInOutSine: function (x, t, b, c, d) {
  130. return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
  131. },
  132. easeInExpo: function (x, t, b, c, d) {
  133. return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
  134. },
  135. easeOutExpo: function (x, t, b, c, d) {
  136. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  137. },
  138. easeInOutExpo: function (x, t, b, c, d) {
  139. if (t==0) return b;
  140. if (t==d) return b+c;
  141. if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
  142. return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  143. },
  144. easeInCirc: function (x, t, b, c, d) {
  145. return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
  146. },
  147. easeOutCirc: function (x, t, b, c, d) {
  148. return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
  149. },
  150. easeInOutCirc: function (x, t, b, c, d) {
  151. if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
  152. return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
  153. },
  154. easeInElastic: function (x, t, b, c, d) {
  155. var s=1.70158;var p=0;var a=c;
  156. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  157. if (a < Math.abs(c)) { a=c; var s=p/4; }
  158. else var s = p/(2*Math.PI) * Math.asin (c/a);
  159. return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  160. },
  161. easeOutElastic: function (x, t, b, c, d) {
  162. var s=1.70158;var p=0;var a=c;
  163. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  164. if (a < Math.abs(c)) { a=c; var s=p/4; }
  165. else var s = p/(2*Math.PI) * Math.asin (c/a);
  166. return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  167. },
  168. easeInOutElastic: function (x, t, b, c, d) {
  169. var s=1.70158;var p=0;var a=c;
  170. if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
  171. if (a < Math.abs(c)) { a=c; var s=p/4; }
  172. else var s = p/(2*Math.PI) * Math.asin (c/a);
  173. if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  174. return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
  175. },
  176. easeInBack: function (x, t, b, c, d, s) {
  177. if (s == undefined) s = 1.70158;
  178. return c*(t/=d)*t*((s+1)*t - s) + b;
  179. },
  180. easeOutBack: function (x, t, b, c, d, s) {
  181. if (s == undefined) s = 1.70158;
  182. return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
  183. },
  184. easeInOutBack: function (x, t, b, c, d, s) {
  185. if (s == undefined) s = 1.70158;
  186. if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
  187. return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  188. },
  189. easeInBounce: function (x, t, b, c, d) {
  190. return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
  191. },
  192. easeOutBounce: function (x, t, b, c, d) {
  193. if ((t/=d) < (1/2.75)) {
  194. return c*(7.5625*t*t) + b;
  195. } else if (t < (2/2.75)) {
  196. return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  197. } else if (t < (2.5/2.75)) {
  198. return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  199. } else {
  200. return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  201. }
  202. },
  203. easeInOutBounce: function (x, t, b, c, d) {
  204. if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
  205. return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
  206. }
  207. });
  208. /*
  209. *
  210. * TERMS OF USE - EASING EQUATIONS
  211. *
  212. * Open source under the BSD License.
  213. *
  214. * Copyright © 2001 Robert Penner
  215. * All rights reserved.
  216. *
  217. * Redistribution and use in source and binary forms, with or without modification,
  218. * are permitted provided that the following conditions are met:
  219. *
  220. * Redistributions of source code must retain the above copyright notice, this list of
  221. * conditions and the following disclaimer.
  222. * Redistributions in binary form must reproduce the above copyright notice, this list
  223. * of conditions and the following disclaimer in the documentation and/or other materials
  224. * provided with the distribution.
  225. *
  226. * Neither the name of the author nor the names of contributors may be used to endorse
  227. * or promote products derived from this software without specific prior written permission.
  228. *
  229. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  230. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  231. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  232. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  233. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  234. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  235. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  236. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  237. * OF THE POSSIBILITY OF SUCH DAMAGE.
  238. *
  239. */
  240. /*! VelocityJS.org (1.2.3). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License */
  241. /*! VelocityJS.org jQuery Shim (1.0.1). (C) 2014 The jQuery Foundation. MIT @license: en.wikipedia.org/wiki/MIT_License. */
  242. /*! Note that this has been modified by Materialize to confirm that Velocity is not already being imported. */
  243. jQuery.Velocity?console.log("Velocity is already loaded. You may be needlessly importing Velocity again; note that Materialize includes Velocity."):(!function(e){function t(e){var t=e.length,a=r.type(e);return"function"===a||r.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===a||0===t||"number"==typeof t&&t>0&&t-1 in e}if(!e.jQuery){var r=function(e,t){return new r.fn.init(e,t)};r.isWindow=function(e){return null!=e&&e==e.window},r.type=function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[i.call(e)]||"object":typeof e},r.isArray=Array.isArray||function(e){return"array"===r.type(e)},r.isPlainObject=function(e){var t;if(!e||"object"!==r.type(e)||e.nodeType||r.isWindow(e))return!1;try{if(e.constructor&&!o.call(e,"constructor")&&!o.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(a){return!1}for(t in e);return void 0===t||o.call(e,t)},r.each=function(e,r,a){var n,o=0,i=e.length,s=t(e);if(a){if(s)for(;i>o&&(n=r.apply(e[o],a),n!==!1);o++);else for(o in e)if(n=r.apply(e[o],a),n===!1)break}else if(s)for(;i>o&&(n=r.call(e[o],o,e[o]),n!==!1);o++);else for(o in e)if(n=r.call(e[o],o,e[o]),n===!1)break;return e},r.data=function(e,t,n){if(void 0===n){var o=e[r.expando],i=o&&a[o];if(void 0===t)return i;if(i&&t in i)return i[t]}else if(void 0!==t){var o=e[r.expando]||(e[r.expando]=++r.uuid);return a[o]=a[o]||{},a[o][t]=n,n}},r.removeData=function(e,t){var n=e[r.expando],o=n&&a[n];o&&r.each(t,function(e,t){delete o[t]})},r.extend=function(){var e,t,a,n,o,i,s=arguments[0]||{},l=1,u=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[l]||{},l++),"object"!=typeof s&&"function"!==r.type(s)&&(s={}),l===u&&(s=this,l--);u>l;l++)if(null!=(o=arguments[l]))for(n in o)e=s[n],a=o[n],s!==a&&(c&&a&&(r.isPlainObject(a)||(t=r.isArray(a)))?(t?(t=!1,i=e&&r.isArray(e)?e:[]):i=e&&r.isPlainObject(e)?e:{},s[n]=r.extend(c,i,a)):void 0!==a&&(s[n]=a));return s},r.queue=function(e,a,n){function o(e,r){var a=r||[];return null!=e&&(t(Object(e))?!function(e,t){for(var r=+t.length,a=0,n=e.length;r>a;)e[n++]=t[a++];if(r!==r)for(;void 0!==t[a];)e[n++]=t[a++];return e.length=n,e}(a,"string"==typeof e?[e]:e):[].push.call(a,e)),a}if(e){a=(a||"fx")+"queue";var i=r.data(e,a);return n?(!i||r.isArray(n)?i=r.data(e,a,o(n)):i.push(n),i):i||[]}},r.dequeue=function(e,t){r.each(e.nodeType?[e]:e,function(e,a){t=t||"fx";var n=r.queue(a,t),o=n.shift();"inprogress"===o&&(o=n.shift()),o&&("fx"===t&&n.unshift("inprogress"),o.call(a,function(){r.dequeue(a,t)}))})},r.fn=r.prototype={init:function(e){if(e.nodeType)return this[0]=e,this;throw new Error("Not a DOM node.")},offset:function(){var t=this[0].getBoundingClientRect?this[0].getBoundingClientRect():{top:0,left:0};return{top:t.top+(e.pageYOffset||document.scrollTop||0)-(document.clientTop||0),left:t.left+(e.pageXOffset||document.scrollLeft||0)-(document.clientLeft||0)}},position:function(){function e(){for(var e=this.offsetParent||document;e&&"html"===!e.nodeType.toLowerCase&&"static"===e.style.position;)e=e.offsetParent;return e||document}var t=this[0],e=e.apply(t),a=this.offset(),n=/^(?:body|html)$/i.test(e.nodeName)?{top:0,left:0}:r(e).offset();return a.top-=parseFloat(t.style.marginTop)||0,a.left-=parseFloat(t.style.marginLeft)||0,e.style&&(n.top+=parseFloat(e.style.borderTopWidth)||0,n.left+=parseFloat(e.style.borderLeftWidth)||0),{top:a.top-n.top,left:a.left-n.left}}};var a={};r.expando="velocity"+(new Date).getTime(),r.uuid=0;for(var n={},o=n.hasOwnProperty,i=n.toString,s="Boolean Number String Function Array Date RegExp Object Error".split(" "),l=0;l<s.length;l++)n["[object "+s[l]+"]"]=s[l].toLowerCase();r.fn.init.prototype=r.fn,e.Velocity={Utilities:r}}}(window),function(e){"object"==typeof module&&"object"==typeof module.exports?module.exports=e():"function"==typeof define&&define.amd?define(e):e()}(function(){return function(e,t,r,a){function n(e){for(var t=-1,r=e?e.length:0,a=[];++t<r;){var n=e[t];n&&a.push(n)}return a}function o(e){return m.isWrapped(e)?e=[].slice.call(e):m.isNode(e)&&(e=[e]),e}function i(e){var t=f.data(e,"velocity");return null===t?a:t}function s(e){return function(t){return Math.round(t*e)*(1/e)}}function l(e,r,a,n){function o(e,t){return 1-3*t+3*e}function i(e,t){return 3*t-6*e}function s(e){return 3*e}function l(e,t,r){return((o(t,r)*e+i(t,r))*e+s(t))*e}function u(e,t,r){return 3*o(t,r)*e*e+2*i(t,r)*e+s(t)}function c(t,r){for(var n=0;m>n;++n){var o=u(r,e,a);if(0===o)return r;var i=l(r,e,a)-t;r-=i/o}return r}function p(){for(var t=0;b>t;++t)w[t]=l(t*x,e,a)}function f(t,r,n){var o,i,s=0;do i=r+(n-r)/2,o=l(i,e,a)-t,o>0?n=i:r=i;while(Math.abs(o)>h&&++s<v);return i}function d(t){for(var r=0,n=1,o=b-1;n!=o&&w[n]<=t;++n)r+=x;--n;var i=(t-w[n])/(w[n+1]-w[n]),s=r+i*x,l=u(s,e,a);return l>=y?c(t,s):0==l?s:f(t,r,r+x)}function g(){V=!0,(e!=r||a!=n)&&p()}var m=4,y=.001,h=1e-7,v=10,b=11,x=1/(b-1),S="Float32Array"in t;if(4!==arguments.length)return!1;for(var P=0;4>P;++P)if("number"!=typeof arguments[P]||isNaN(arguments[P])||!isFinite(arguments[P]))return!1;e=Math.min(e,1),a=Math.min(a,1),e=Math.max(e,0),a=Math.max(a,0);var w=S?new Float32Array(b):new Array(b),V=!1,C=function(t){return V||g(),e===r&&a===n?t:0===t?0:1===t?1:l(d(t),r,n)};C.getControlPoints=function(){return[{x:e,y:r},{x:a,y:n}]};var T="generateBezier("+[e,r,a,n]+")";return C.toString=function(){return T},C}function u(e,t){var r=e;return m.isString(e)?b.Easings[e]||(r=!1):r=m.isArray(e)&&1===e.length?s.apply(null,e):m.isArray(e)&&2===e.length?x.apply(null,e.concat([t])):m.isArray(e)&&4===e.length?l.apply(null,e):!1,r===!1&&(r=b.Easings[b.defaults.easing]?b.defaults.easing:v),r}function c(e){if(e){var t=(new Date).getTime(),r=b.State.calls.length;r>1e4&&(b.State.calls=n(b.State.calls));for(var o=0;r>o;o++)if(b.State.calls[o]){var s=b.State.calls[o],l=s[0],u=s[2],d=s[3],g=!!d,y=null;d||(d=b.State.calls[o][3]=t-16);for(var h=Math.min((t-d)/u.duration,1),v=0,x=l.length;x>v;v++){var P=l[v],V=P.element;if(i(V)){var C=!1;if(u.display!==a&&null!==u.display&&"none"!==u.display){if("flex"===u.display){var T=["-webkit-box","-moz-box","-ms-flexbox","-webkit-flex"];f.each(T,function(e,t){S.setPropertyValue(V,"display",t)})}S.setPropertyValue(V,"display",u.display)}u.visibility!==a&&"hidden"!==u.visibility&&S.setPropertyValue(V,"visibility",u.visibility);for(var k in P)if("element"!==k){var A,F=P[k],j=m.isString(F.easing)?b.Easings[F.easing]:F.easing;if(1===h)A=F.endValue;else{var E=F.endValue-F.startValue;if(A=F.startValue+E*j(h,u,E),!g&&A===F.currentValue)continue}if(F.currentValue=A,"tween"===k)y=A;else{if(S.Hooks.registered[k]){var H=S.Hooks.getRoot(k),N=i(V).rootPropertyValueCache[H];N&&(F.rootPropertyValue=N)}var L=S.setPropertyValue(V,k,F.currentValue+(0===parseFloat(A)?"":F.unitType),F.rootPropertyValue,F.scrollData);S.Hooks.registered[k]&&(i(V).rootPropertyValueCache[H]=S.Normalizations.registered[H]?S.Normalizations.registered[H]("extract",null,L[1]):L[1]),"transform"===L[0]&&(C=!0)}}u.mobileHA&&i(V).transformCache.translate3d===a&&(i(V).transformCache.translate3d="(0px, 0px, 0px)",C=!0),C&&S.flushTransformCache(V)}}u.display!==a&&"none"!==u.display&&(b.State.calls[o][2].display=!1),u.visibility!==a&&"hidden"!==u.visibility&&(b.State.calls[o][2].visibility=!1),u.progress&&u.progress.call(s[1],s[1],h,Math.max(0,d+u.duration-t),d,y),1===h&&p(o)}}b.State.isTicking&&w(c)}function p(e,t){if(!b.State.calls[e])return!1;for(var r=b.State.calls[e][0],n=b.State.calls[e][1],o=b.State.calls[e][2],s=b.State.calls[e][4],l=!1,u=0,c=r.length;c>u;u++){var p=r[u].element;if(t||o.loop||("none"===o.display&&S.setPropertyValue(p,"display",o.display),"hidden"===o.visibility&&S.setPropertyValue(p,"visibility",o.visibility)),o.loop!==!0&&(f.queue(p)[1]===a||!/\.velocityQueueEntryFlag/i.test(f.queue(p)[1]))&&i(p)){i(p).isAnimating=!1,i(p).rootPropertyValueCache={};var d=!1;f.each(S.Lists.transforms3D,function(e,t){var r=/^scale/.test(t)?1:0,n=i(p).transformCache[t];i(p).transformCache[t]!==a&&new RegExp("^\\("+r+"[^.]").test(n)&&(d=!0,delete i(p).transformCache[t])}),o.mobileHA&&(d=!0,delete i(p).transformCache.translate3d),d&&S.flushTransformCache(p),S.Values.removeClass(p,"velocity-animating")}if(!t&&o.complete&&!o.loop&&u===c-1)try{o.complete.call(n,n)}catch(g){setTimeout(function(){throw g},1)}s&&o.loop!==!0&&s(n),i(p)&&o.loop===!0&&!t&&(f.each(i(p).tweensContainer,function(e,t){/^rotate/.test(e)&&360===parseFloat(t.endValue)&&(t.endValue=0,t.startValue=360),/^backgroundPosition/.test(e)&&100===parseFloat(t.endValue)&&"%"===t.unitType&&(t.endValue=0,t.startValue=100)}),b(p,"reverse",{loop:!0,delay:o.delay})),o.queue!==!1&&f.dequeue(p,o.queue)}b.State.calls[e]=!1;for(var m=0,y=b.State.calls.length;y>m;m++)if(b.State.calls[m]!==!1){l=!0;break}l===!1&&(b.State.isTicking=!1,delete b.State.calls,b.State.calls=[])}var f,d=function(){if(r.documentMode)return r.documentMode;for(var e=7;e>4;e--){var t=r.createElement("div");if(t.innerHTML="<!--[if IE "+e+"]><span></span><![endif]-->",t.getElementsByTagName("span").length)return t=null,e}return a}(),g=function(){var e=0;return t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||function(t){var r,a=(new Date).getTime();return r=Math.max(0,16-(a-e)),e=a+r,setTimeout(function(){t(a+r)},r)}}(),m={isString:function(e){return"string"==typeof e},isArray:Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},isFunction:function(e){return"[object Function]"===Object.prototype.toString.call(e)},isNode:function(e){return e&&e.nodeType},isNodeList:function(e){return"object"==typeof e&&/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(e))&&e.length!==a&&(0===e.length||"object"==typeof e[0]&&e[0].nodeType>0)},isWrapped:function(e){return e&&(e.jquery||t.Zepto&&t.Zepto.zepto.isZ(e))},isSVG:function(e){return t.SVGElement&&e instanceof t.SVGElement},isEmptyObject:function(e){for(var t in e)return!1;return!0}},y=!1;if(e.fn&&e.fn.jquery?(f=e,y=!0):f=t.Velocity.Utilities,8>=d&&!y)throw new Error("Velocity: IE8 and below require jQuery to be loaded before Velocity.");if(7>=d)return void(jQuery.fn.velocity=jQuery.fn.animate);var h=400,v="swing",b={State:{isMobile:/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),isAndroid:/Android/i.test(navigator.userAgent),isGingerbread:/Android 2\.3\.[3-7]/i.test(navigator.userAgent),isChrome:t.chrome,isFirefox:/Firefox/i.test(navigator.userAgent),prefixElement:r.createElement("div"),prefixMatches:{},scrollAnchor:null,scrollPropertyLeft:null,scrollPropertyTop:null,isTicking:!1,calls:[]},CSS:{},Utilities:f,Redirects:{},Easings:{},Promise:t.Promise,defaults:{queue:"",duration:h,easing:v,begin:a,complete:a,progress:a,display:a,visibility:a,loop:!1,delay:!1,mobileHA:!0,_cacheValues:!0},init:function(e){f.data(e,"velocity",{isSVG:m.isSVG(e),isAnimating:!1,computedStyle:null,tweensContainer:null,rootPropertyValueCache:{},transformCache:{}})},hook:null,mock:!1,version:{major:1,minor:2,patch:2},debug:!1};t.pageYOffset!==a?(b.State.scrollAnchor=t,b.State.scrollPropertyLeft="pageXOffset",b.State.scrollPropertyTop="pageYOffset"):(b.State.scrollAnchor=r.documentElement||r.body.parentNode||r.body,b.State.scrollPropertyLeft="scrollLeft",b.State.scrollPropertyTop="scrollTop");var x=function(){function e(e){return-e.tension*e.x-e.friction*e.v}function t(t,r,a){var n={x:t.x+a.dx*r,v:t.v+a.dv*r,tension:t.tension,friction:t.friction};return{dx:n.v,dv:e(n)}}function r(r,a){var n={dx:r.v,dv:e(r)},o=t(r,.5*a,n),i=t(r,.5*a,o),s=t(r,a,i),l=1/6*(n.dx+2*(o.dx+i.dx)+s.dx),u=1/6*(n.dv+2*(o.dv+i.dv)+s.dv);return r.x=r.x+l*a,r.v=r.v+u*a,r}return function a(e,t,n){var o,i,s,l={x:-1,v:0,tension:null,friction:null},u=[0],c=0,p=1e-4,f=.016;for(e=parseFloat(e)||500,t=parseFloat(t)||20,n=n||null,l.tension=e,l.friction=t,o=null!==n,o?(c=a(e,t),i=c/n*f):i=f;s=r(s||l,i),u.push(1+s.x),c+=16,Math.abs(s.x)>p&&Math.abs(s.v)>p;);return o?function(e){return u[e*(u.length-1)|0]}:c}}();b.Easings={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2},spring:function(e){return 1-Math.cos(4.5*e*Math.PI)*Math.exp(6*-e)}},f.each([["ease",[.25,.1,.25,1]],["ease-in",[.42,0,1,1]],["ease-out",[0,0,.58,1]],["ease-in-out",[.42,0,.58,1]],["easeInSine",[.47,0,.745,.715]],["easeOutSine",[.39,.575,.565,1]],["easeInOutSine",[.445,.05,.55,.95]],["easeInQuad",[.55,.085,.68,.53]],["easeOutQuad",[.25,.46,.45,.94]],["easeInOutQuad",[.455,.03,.515,.955]],["easeInCubic",[.55,.055,.675,.19]],["easeOutCubic",[.215,.61,.355,1]],["easeInOutCubic",[.645,.045,.355,1]],["easeInQuart",[.895,.03,.685,.22]],["easeOutQuart",[.165,.84,.44,1]],["easeInOutQuart",[.77,0,.175,1]],["easeInQuint",[.755,.05,.855,.06]],["easeOutQuint",[.23,1,.32,1]],["easeInOutQuint",[.86,0,.07,1]],["easeInExpo",[.95,.05,.795,.035]],["easeOutExpo",[.19,1,.22,1]],["easeInOutExpo",[1,0,0,1]],["easeInCirc",[.6,.04,.98,.335]],["easeOutCirc",[.075,.82,.165,1]],["easeInOutCirc",[.785,.135,.15,.86]]],function(e,t){b.Easings[t[0]]=l.apply(null,t[1])});var S=b.CSS={RegEx:{isHex:/^#([A-f\d]{3}){1,2}$/i,valueUnwrap:/^[A-z]+\((.*)\)$/i,wrappedValueAlreadyExtracted:/[0-9.]+ [0-9.]+ [0-9.]+( [0-9.]+)?/,valueSplit:/([A-z]+\(.+\))|(([A-z0-9#-.]+?)(?=\s|$))/gi},Lists:{colors:["fill","stroke","stopColor","color","backgroundColor","borderColor","borderTopColor","borderRightColor","borderBottomColor","borderLeftColor","outlineColor"],transformsBase:["translateX","translateY","scale","scaleX","scaleY","skewX","skewY","rotateZ"],transforms3D:["transformPerspective","translateZ","scaleZ","rotateX","rotateY"]},Hooks:{templates:{textShadow:["Color X Y Blur","black 0px 0px 0px"],boxShadow:["Color X Y Blur Spread","black 0px 0px 0px 0px"],clip:["Top Right Bottom Left","0px 0px 0px 0px"],backgroundPosition:["X Y","0% 0%"],transformOrigin:["X Y Z","50% 50% 0px"],perspectiveOrigin:["X Y","50% 50%"]},registered:{},register:function(){for(var e=0;e<S.Lists.colors.length;e++){var t="color"===S.Lists.colors[e]?"0 0 0 1":"255 255 255 1";S.Hooks.templates[S.Lists.colors[e]]=["Red Green Blue Alpha",t]}var r,a,n;if(d)for(r in S.Hooks.templates){a=S.Hooks.templates[r],n=a[0].split(" ");var o=a[1].match(S.RegEx.valueSplit);"Color"===n[0]&&(n.push(n.shift()),o.push(o.shift()),S.Hooks.templates[r]=[n.join(" "),o.join(" ")])}for(r in S.Hooks.templates){a=S.Hooks.templates[r],n=a[0].split(" ");for(var e in n){var i=r+n[e],s=e;S.Hooks.registered[i]=[r,s]}}},getRoot:function(e){var t=S.Hooks.registered[e];return t?t[0]:e},cleanRootPropertyValue:function(e,t){return S.RegEx.valueUnwrap.test(t)&&(t=t.match(S.RegEx.valueUnwrap)[1]),S.Values.isCSSNullValue(t)&&(t=S.Hooks.templates[e][1]),t},extractValue:function(e,t){var r=S.Hooks.registered[e];if(r){var a=r[0],n=r[1];return t=S.Hooks.cleanRootPropertyValue(a,t),t.toString().match(S.RegEx.valueSplit)[n]}return t},injectValue:function(e,t,r){var a=S.Hooks.registered[e];if(a){var n,o,i=a[0],s=a[1];return r=S.Hooks.cleanRootPropertyValue(i,r),n=r.toString().match(S.RegEx.valueSplit),n[s]=t,o=n.join(" ")}return r}},Normalizations:{registered:{clip:function(e,t,r){switch(e){case"name":return"clip";case"extract":var a;return S.RegEx.wrappedValueAlreadyExtracted.test(r)?a=r:(a=r.toString().match(S.RegEx.valueUnwrap),a=a?a[1].replace(/,(\s+)?/g," "):r),a;case"inject":return"rect("+r+")"}},blur:function(e,t,r){switch(e){case"name":return b.State.isFirefox?"filter":"-webkit-filter";case"extract":var a=parseFloat(r);if(!a&&0!==a){var n=r.toString().match(/blur\(([0-9]+[A-z]+)\)/i);a=n?n[1]:0}return a;case"inject":return parseFloat(r)?"blur("+r+")":"none"}},opacity:function(e,t,r){if(8>=d)switch(e){case"name":return"filter";case"extract":var a=r.toString().match(/alpha\(opacity=(.*)\)/i);return r=a?a[1]/100:1;case"inject":return t.style.zoom=1,parseFloat(r)>=1?"":"alpha(opacity="+parseInt(100*parseFloat(r),10)+")"}else switch(e){case"name":return"opacity";case"extract":return r;case"inject":return r}}},register:function(){9>=d||b.State.isGingerbread||(S.Lists.transformsBase=S.Lists.transformsBase.concat(S.Lists.transforms3D));for(var e=0;e<S.Lists.transformsBase.length;e++)!function(){var t=S.Lists.transformsBase[e];S.Normalizations.registered[t]=function(e,r,n){switch(e){case"name":return"transform";case"extract":return i(r)===a||i(r).transformCache[t]===a?/^scale/i.test(t)?1:0:i(r).transformCache[t].replace(/[()]/g,"");case"inject":var o=!1;switch(t.substr(0,t.length-1)){case"translate":o=!/(%|px|em|rem|vw|vh|\d)$/i.test(n);break;case"scal":case"scale":b.State.isAndroid&&i(r).transformCache[t]===a&&1>n&&(n=1),o=!/(\d)$/i.test(n);break;case"skew":o=!/(deg|\d)$/i.test(n);break;case"rotate":o=!/(deg|\d)$/i.test(n)}return o||(i(r).transformCache[t]="("+n+")"),i(r).transformCache[t]}}}();for(var e=0;e<S.Lists.colors.length;e++)!function(){var t=S.Lists.colors[e];S.Normalizations.registered[t]=function(e,r,n){switch(e){case"name":return t;case"extract":var o;if(S.RegEx.wrappedValueAlreadyExtracted.test(n))o=n;else{var i,s={black:"rgb(0, 0, 0)",blue:"rgb(0, 0, 255)",gray:"rgb(128, 128, 128)",green:"rgb(0, 128, 0)",red:"rgb(255, 0, 0)",white:"rgb(255, 255, 255)"};/^[A-z]+$/i.test(n)?i=s[n]!==a?s[n]:s.black:S.RegEx.isHex.test(n)?i="rgb("+S.Values.hexToRgb(n).join(" ")+")":/^rgba?\(/i.test(n)||(i=s.black),o=(i||n).toString().match(S.RegEx.valueUnwrap)[1].replace(/,(\s+)?/g," ")}return 8>=d||3!==o.split(" ").length||(o+=" 1"),o;case"inject":return 8>=d?4===n.split(" ").length&&(n=n.split(/\s+/).slice(0,3).join(" ")):3===n.split(" ").length&&(n+=" 1"),(8>=d?"rgb":"rgba")+"("+n.replace(/\s+/g,",").replace(/\.(\d)+(?=,)/g,"")+")"}}}()}},Names:{camelCase:function(e){return e.replace(/-(\w)/g,function(e,t){return t.toUpperCase()})},SVGAttribute:function(e){var t="width|height|x|y|cx|cy|r|rx|ry|x1|x2|y1|y2";return(d||b.State.isAndroid&&!b.State.isChrome)&&(t+="|transform"),new RegExp("^("+t+")$","i").test(e)},prefixCheck:function(e){if(b.State.prefixMatches[e])return[b.State.prefixMatches[e],!0];for(var t=["","Webkit","Moz","ms","O"],r=0,a=t.length;a>r;r++){var n;if(n=0===r?e:t[r]+e.replace(/^\w/,function(e){return e.toUpperCase()}),m.isString(b.State.prefixElement.style[n]))return b.State.prefixMatches[e]=n,[n,!0]}return[e,!1]}},Values:{hexToRgb:function(e){var t,r=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;return e=e.replace(r,function(e,t,r,a){return t+t+r+r+a+a}),t=a.exec(e),t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:[0,0,0]},isCSSNullValue:function(e){return 0==e||/^(none|auto|transparent|(rgba\(0, ?0, ?0, ?0\)))$/i.test(e)},getUnitType:function(e){return/^(rotate|skew)/i.test(e)?"deg":/(^(scale|scaleX|scaleY|scaleZ|alpha|flexGrow|flexHeight|zIndex|fontWeight)$)|((opacity|red|green|blue|alpha)$)/i.test(e)?"":"px"},getDisplayType:function(e){var t=e&&e.tagName.toString().toLowerCase();return/^(b|big|i|small|tt|abbr|acronym|cite|code|dfn|em|kbd|strong|samp|var|a|bdo|br|img|map|object|q|script|span|sub|sup|button|input|label|select|textarea)$/i.test(t)?"inline":/^(li)$/i.test(t)?"list-item":/^(tr)$/i.test(t)?"table-row":/^(table)$/i.test(t)?"table":/^(tbody)$/i.test(t)?"table-row-group":"block"},addClass:function(e,t){e.classList?e.classList.add(t):e.className+=(e.className.length?" ":"")+t},removeClass:function(e,t){e.classList?e.classList.remove(t):e.className=e.className.toString().replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," ")}},getPropertyValue:function(e,r,n,o){function s(e,r){function n(){u&&S.setPropertyValue(e,"display","none")}var l=0;if(8>=d)l=f.css(e,r);else{var u=!1;if(/^(width|height)$/.test(r)&&0===S.getPropertyValue(e,"display")&&(u=!0,S.setPropertyValue(e,"display",S.Values.getDisplayType(e))),!o){if("height"===r&&"border-box"!==S.getPropertyValue(e,"boxSizing").toString().toLowerCase()){var c=e.offsetHeight-(parseFloat(S.getPropertyValue(e,"borderTopWidth"))||0)-(parseFloat(S.getPropertyValue(e,"borderBottomWidth"))||0)-(parseFloat(S.getPropertyValue(e,"paddingTop"))||0)-(parseFloat(S.getPropertyValue(e,"paddingBottom"))||0);return n(),c}if("width"===r&&"border-box"!==S.getPropertyValue(e,"boxSizing").toString().toLowerCase()){var p=e.offsetWidth-(parseFloat(S.getPropertyValue(e,"borderLeftWidth"))||0)-(parseFloat(S.getPropertyValue(e,"borderRightWidth"))||0)-(parseFloat(S.getPropertyValue(e,"paddingLeft"))||0)-(parseFloat(S.getPropertyValue(e,"paddingRight"))||0);return n(),p}}var g;g=i(e)===a?t.getComputedStyle(e,null):i(e).computedStyle?i(e).computedStyle:i(e).computedStyle=t.getComputedStyle(e,null),"borderColor"===r&&(r="borderTopColor"),l=9===d&&"filter"===r?g.getPropertyValue(r):g[r],(""===l||null===l)&&(l=e.style[r]),n()}if("auto"===l&&/^(top|right|bottom|left)$/i.test(r)){var m=s(e,"position");("fixed"===m||"absolute"===m&&/top|left/i.test(r))&&(l=f(e).position()[r]+"px")}return l}var l;if(S.Hooks.registered[r]){var u=r,c=S.Hooks.getRoot(u);n===a&&(n=S.getPropertyValue(e,S.Names.prefixCheck(c)[0])),S.Normalizations.registered[c]&&(n=S.Normalizations.registered[c]("extract",e,n)),l=S.Hooks.extractValue(u,n)}else if(S.Normalizations.registered[r]){var p,g;p=S.Normalizations.registered[r]("name",e),"transform"!==p&&(g=s(e,S.Names.prefixCheck(p)[0]),S.Values.isCSSNullValue(g)&&S.Hooks.templates[r]&&(g=S.Hooks.templates[r][1])),l=S.Normalizations.registered[r]("extract",e,g)}if(!/^[\d-]/.test(l))if(i(e)&&i(e).isSVG&&S.Names.SVGAttribute(r))if(/^(height|width)$/i.test(r))try{l=e.getBBox()[r]}catch(m){l=0}else l=e.getAttribute(r);else l=s(e,S.Names.prefixCheck(r)[0]);return S.Values.isCSSNullValue(l)&&(l=0),b.debug>=2&&console.log("Get "+r+": "+l),l},setPropertyValue:function(e,r,a,n,o){var s=r;if("scroll"===r)o.container?o.container["scroll"+o.direction]=a:"Left"===o.direction?t.scrollTo(a,o.alternateValue):t.scrollTo(o.alternateValue,a);else if(S.Normalizations.registered[r]&&"transform"===S.Normalizations.registered[r]("name",e))S.Normalizations.registered[r]("inject",e,a),s="transform",a=i(e).transformCache[r];else{if(S.Hooks.registered[r]){var l=r,u=S.Hooks.getRoot(r);n=n||S.getPropertyValue(e,u),a=S.Hooks.injectValue(l,a,n),r=u}if(S.Normalizations.registered[r]&&(a=S.Normalizations.registered[r]("inject",e,a),r=S.Normalizations.registered[r]("name",e)),s=S.Names.prefixCheck(r)[0],8>=d)try{e.style[s]=a}catch(c){b.debug&&console.log("Browser does not support ["+a+"] for ["+s+"]")}else i(e)&&i(e).isSVG&&S.Names.SVGAttribute(r)?e.setAttribute(r,a):e.style[s]=a;b.debug>=2&&console.log("Set "+r+" ("+s+"): "+a)}return[s,a]},flushTransformCache:function(e){function t(t){return parseFloat(S.getPropertyValue(e,t))}var r="";if((d||b.State.isAndroid&&!b.State.isChrome)&&i(e).isSVG){var a={translate:[t("translateX"),t("translateY")],skewX:[t("skewX")],skewY:[t("skewY")],scale:1!==t("scale")?[t("scale"),t("scale")]:[t("scaleX"),t("scaleY")],rotate:[t("rotateZ"),0,0]};f.each(i(e).transformCache,function(e){/^translate/i.test(e)?e="translate":/^scale/i.test(e)?e="scale":/^rotate/i.test(e)&&(e="rotate"),a[e]&&(r+=e+"("+a[e].join(" ")+") ",delete a[e])})}else{var n,o;f.each(i(e).transformCache,function(t){return n=i(e).transformCache[t],"transformPerspective"===t?(o=n,!0):(9===d&&"rotateZ"===t&&(t="rotate"),void(r+=t+n+" "))}),o&&(r="perspective"+o+" "+r)}S.setPropertyValue(e,"transform",r)}};S.Hooks.register(),S.Normalizations.register(),b.hook=function(e,t,r){var n=a;return e=o(e),f.each(e,function(e,o){if(i(o)===a&&b.init(o),r===a)n===a&&(n=b.CSS.getPropertyValue(o,t));else{var s=b.CSS.setPropertyValue(o,t,r);"transform"===s[0]&&b.CSS.flushTransformCache(o),n=s}}),n};var P=function(){function e(){return s?k.promise||null:l}function n(){function e(e){function p(e,t){var r=a,n=a,i=a;return m.isArray(e)?(r=e[0],!m.isArray(e[1])&&/^[\d-]/.test(e[1])||m.isFunction(e[1])||S.RegEx.isHex.test(e[1])?i=e[1]:(m.isString(e[1])&&!S.RegEx.isHex.test(e[1])||m.isArray(e[1]))&&(n=t?e[1]:u(e[1],s.duration),e[2]!==a&&(i=e[2]))):r=e,t||(n=n||s.easing),m.isFunction(r)&&(r=r.call(o,V,w)),m.isFunction(i)&&(i=i.call(o,V,w)),[r||0,n,i]}function d(e,t){var r,a;return a=(t||"0").toString().toLowerCase().replace(/[%A-z]+$/,function(e){return r=e,""}),r||(r=S.Values.getUnitType(e)),[a,r]}function h(){var e={myParent:o.parentNode||r.body,position:S.getPropertyValue(o,"position"),fontSize:S.getPropertyValue(o,"fontSize")},a=e.position===L.lastPosition&&e.myParent===L.lastParent,n=e.fontSize===L.lastFontSize;L.lastParent=e.myParent,L.lastPosition=e.position,L.lastFontSize=e.fontSize;var s=100,l={};if(n&&a)l.emToPx=L.lastEmToPx,l.percentToPxWidth=L.lastPercentToPxWidth,l.percentToPxHeight=L.lastPercentToPxHeight;else{var u=i(o).isSVG?r.createElementNS("http://www.w3.org/2000/svg","rect"):r.createElement("div");b.init(u),e.myParent.appendChild(u),f.each(["overflow","overflowX","overflowY"],function(e,t){b.CSS.setPropertyValue(u,t,"hidden")}),b.CSS.setPropertyValue(u,"position",e.position),b.CSS.setPropertyValue(u,"fontSize",e.fontSize),b.CSS.setPropertyValue(u,"boxSizing","content-box"),f.each(["minWidth","maxWidth","width","minHeight","maxHeight","height"],function(e,t){b.CSS.setPropertyValue(u,t,s+"%")}),b.CSS.setPropertyValue(u,"paddingLeft",s+"em"),l.percentToPxWidth=L.lastPercentToPxWidth=(parseFloat(S.getPropertyValue(u,"width",null,!0))||1)/s,l.percentToPxHeight=L.lastPercentToPxHeight=(parseFloat(S.getPropertyValue(u,"height",null,!0))||1)/s,l.emToPx=L.lastEmToPx=(parseFloat(S.getPropertyValue(u,"paddingLeft"))||1)/s,e.myParent.removeChild(u)}return null===L.remToPx&&(L.remToPx=parseFloat(S.getPropertyValue(r.body,"fontSize"))||16),null===L.vwToPx&&(L.vwToPx=parseFloat(t.innerWidth)/100,L.vhToPx=parseFloat(t.innerHeight)/100),l.remToPx=L.remToPx,l.vwToPx=L.vwToPx,l.vhToPx=L.vhToPx,b.debug>=1&&console.log("Unit ratios: "+JSON.stringify(l),o),l}if(s.begin&&0===V)try{s.begin.call(g,g)}catch(x){setTimeout(function(){throw x},1)}if("scroll"===A){var P,C,T,F=/^x$/i.test(s.axis)?"Left":"Top",j=parseFloat(s.offset)||0;s.container?m.isWrapped(s.container)||m.isNode(s.container)?(s.container=s.container[0]||s.container,P=s.container["scroll"+F],T=P+f(o).position()[F.toLowerCase()]+j):s.container=null:(P=b.State.scrollAnchor[b.State["scrollProperty"+F]],C=b.State.scrollAnchor[b.State["scrollProperty"+("Left"===F?"Top":"Left")]],T=f(o).offset()[F.toLowerCase()]+j),l={scroll:{rootPropertyValue:!1,startValue:P,currentValue:P,endValue:T,unitType:"",easing:s.easing,scrollData:{container:s.container,direction:F,alternateValue:C}},element:o},b.debug&&console.log("tweensContainer (scroll): ",l.scroll,o)}else if("reverse"===A){if(!i(o).tweensContainer)return void f.dequeue(o,s.queue);"none"===i(o).opts.display&&(i(o).opts.display="auto"),"hidden"===i(o).opts.visibility&&(i(o).opts.visibility="visible"),i(o).opts.loop=!1,i(o).opts.begin=null,i(o).opts.complete=null,v.easing||delete s.easing,v.duration||delete s.duration,s=f.extend({},i(o).opts,s);var E=f.extend(!0,{},i(o).tweensContainer);for(var H in E)if("element"!==H){var N=E[H].startValue;E[H].startValue=E[H].currentValue=E[H].endValue,E[H].endValue=N,m.isEmptyObject(v)||(E[H].easing=s.easing),b.debug&&console.log("reverse tweensContainer ("+H+"): "+JSON.stringify(E[H]),o)}l=E}else if("start"===A){var E;i(o).tweensContainer&&i(o).isAnimating===!0&&(E=i(o).tweensContainer),f.each(y,function(e,t){if(RegExp("^"+S.Lists.colors.join("$|^")+"$").test(e)){var r=p(t,!0),n=r[0],o=r[1],i=r[2];if(S.RegEx.isHex.test(n)){for(var s=["Red","Green","Blue"],l=S.Values.hexToRgb(n),u=i?S.Values.hexToRgb(i):a,c=0;c<s.length;c++){var f=[l[c]];o&&f.push(o),u!==a&&f.push(u[c]),y[e+s[c]]=f}delete y[e]}}});for(var z in y){var O=p(y[z]),q=O[0],$=O[1],M=O[2];z=S.Names.camelCase(z);var I=S.Hooks.getRoot(z),B=!1;if(i(o).isSVG||"tween"===I||S.Names.prefixCheck(I)[1]!==!1||S.Normalizations.registered[I]!==a){(s.display!==a&&null!==s.display&&"none"!==s.display||s.visibility!==a&&"hidden"!==s.visibility)&&/opacity|filter/.test(z)&&!M&&0!==q&&(M=0),s._cacheValues&&E&&E[z]?(M===a&&(M=E[z].endValue+E[z].unitType),B=i(o).rootPropertyValueCache[I]):S.Hooks.registered[z]?M===a?(B=S.getPropertyValue(o,I),M=S.getPropertyValue(o,z,B)):B=S.Hooks.templates[I][1]:M===a&&(M=S.getPropertyValue(o,z));var W,G,Y,D=!1;if(W=d(z,M),M=W[0],Y=W[1],W=d(z,q),q=W[0].replace(/^([+-\/*])=/,function(e,t){return D=t,""}),G=W[1],M=parseFloat(M)||0,q=parseFloat(q)||0,"%"===G&&(/^(fontSize|lineHeight)$/.test(z)?(q/=100,G="em"):/^scale/.test(z)?(q/=100,G=""):/(Red|Green|Blue)$/i.test(z)&&(q=q/100*255,G="")),/[\/*]/.test(D))G=Y;else if(Y!==G&&0!==M)if(0===q)G=Y;else{n=n||h();var Q=/margin|padding|left|right|width|text|word|letter/i.test(z)||/X$/.test(z)||"x"===z?"x":"y";switch(Y){case"%":M*="x"===Q?n.percentToPxWidth:n.percentToPxHeight;break;case"px":break;default:M*=n[Y+"ToPx"]}switch(G){case"%":M*=1/("x"===Q?n.percentToPxWidth:n.percentToPxHeight);break;case"px":break;default:M*=1/n[G+"ToPx"]}}switch(D){case"+":q=M+q;break;case"-":q=M-q;break;case"*":q=M*q;break;case"/":q=M/q}l[z]={rootPropertyValue:B,startValue:M,currentValue:M,endValue:q,unitType:G,easing:$},b.debug&&console.log("tweensContainer ("+z+"): "+JSON.stringify(l[z]),o)}else b.debug&&console.log("Skipping ["+I+"] due to a lack of browser support.")}l.element=o}l.element&&(S.Values.addClass(o,"velocity-animating"),R.push(l),""===s.queue&&(i(o).tweensContainer=l,i(o).opts=s),i(o).isAnimating=!0,V===w-1?(b.State.calls.push([R,g,s,null,k.resolver]),b.State.isTicking===!1&&(b.State.isTicking=!0,c())):V++)}var n,o=this,s=f.extend({},b.defaults,v),l={};switch(i(o)===a&&b.init(o),parseFloat(s.delay)&&s.queue!==!1&&f.queue(o,s.queue,function(e){b.velocityQueueEntryFlag=!0,i(o).delayTimer={setTimeout:setTimeout(e,parseFloat(s.delay)),next:e}}),s.duration.toString().toLowerCase()){case"fast":s.duration=200;break;case"normal":s.duration=h;break;case"slow":s.duration=600;break;default:s.duration=parseFloat(s.duration)||1}b.mock!==!1&&(b.mock===!0?s.duration=s.delay=1:(s.duration*=parseFloat(b.mock)||1,s.delay*=parseFloat(b.mock)||1)),s.easing=u(s.easing,s.duration),s.begin&&!m.isFunction(s.begin)&&(s.begin=null),s.progress&&!m.isFunction(s.progress)&&(s.progress=null),s.complete&&!m.isFunction(s.complete)&&(s.complete=null),s.display!==a&&null!==s.display&&(s.display=s.display.toString().toLowerCase(),"auto"===s.display&&(s.display=b.CSS.Values.getDisplayType(o))),s.visibility!==a&&null!==s.visibility&&(s.visibility=s.visibility.toString().toLowerCase()),s.mobileHA=s.mobileHA&&b.State.isMobile&&!b.State.isGingerbread,s.queue===!1?s.delay?setTimeout(e,s.delay):e():f.queue(o,s.queue,function(t,r){return r===!0?(k.promise&&k.resolver(g),!0):(b.velocityQueueEntryFlag=!0,void e(t))}),""!==s.queue&&"fx"!==s.queue||"inprogress"===f.queue(o)[0]||f.dequeue(o)}var s,l,d,g,y,v,x=arguments[0]&&(arguments[0].p||f.isPlainObject(arguments[0].properties)&&!arguments[0].properties.names||m.isString(arguments[0].properties));if(m.isWrapped(this)?(s=!1,d=0,g=this,l=this):(s=!0,d=1,g=x?arguments[0].elements||arguments[0].e:arguments[0]),g=o(g)){x?(y=arguments[0].properties||arguments[0].p,v=arguments[0].options||arguments[0].o):(y=arguments[d],v=arguments[d+1]);var w=g.length,V=0;if(!/^(stop|finish)$/i.test(y)&&!f.isPlainObject(v)){var C=d+1;v={};for(var T=C;T<arguments.length;T++)m.isArray(arguments[T])||!/^(fast|normal|slow)$/i.test(arguments[T])&&!/^\d/.test(arguments[T])?m.isString(arguments[T])||m.isArray(arguments[T])?v.easing=arguments[T]:m.isFunction(arguments[T])&&(v.complete=arguments[T]):v.duration=arguments[T]}var k={promise:null,resolver:null,rejecter:null};s&&b.Promise&&(k.promise=new b.Promise(function(e,t){k.resolver=e,k.rejecter=t}));var A;switch(y){case"scroll":A="scroll";break;case"reverse":A="reverse";break;case"finish":case"stop":f.each(g,function(e,t){i(t)&&i(t).delayTimer&&(clearTimeout(i(t).delayTimer.setTimeout),i(t).delayTimer.next&&i(t).delayTimer.next(),delete i(t).delayTimer)});var F=[];return f.each(b.State.calls,function(e,t){t&&f.each(t[1],function(r,n){var o=v===a?"":v;return o===!0||t[2].queue===o||v===a&&t[2].queue===!1?void f.each(g,function(r,a){a===n&&((v===!0||m.isString(v))&&(f.each(f.queue(a,m.isString(v)?v:""),function(e,t){
  244. m.isFunction(t)&&t(null,!0)}),f.queue(a,m.isString(v)?v:"",[])),"stop"===y?(i(a)&&i(a).tweensContainer&&o!==!1&&f.each(i(a).tweensContainer,function(e,t){t.endValue=t.currentValue}),F.push(e)):"finish"===y&&(t[2].duration=1))}):!0})}),"stop"===y&&(f.each(F,function(e,t){p(t,!0)}),k.promise&&k.resolver(g)),e();default:if(!f.isPlainObject(y)||m.isEmptyObject(y)){if(m.isString(y)&&b.Redirects[y]){var j=f.extend({},v),E=j.duration,H=j.delay||0;return j.backwards===!0&&(g=f.extend(!0,[],g).reverse()),f.each(g,function(e,t){parseFloat(j.stagger)?j.delay=H+parseFloat(j.stagger)*e:m.isFunction(j.stagger)&&(j.delay=H+j.stagger.call(t,e,w)),j.drag&&(j.duration=parseFloat(E)||(/^(callout|transition)/.test(y)?1e3:h),j.duration=Math.max(j.duration*(j.backwards?1-e/w:(e+1)/w),.75*j.duration,200)),b.Redirects[y].call(t,t,j||{},e,w,g,k.promise?k:a)}),e()}var N="Velocity: First argument ("+y+") was not a property map, a known action, or a registered redirect. Aborting.";return k.promise?k.rejecter(new Error(N)):console.log(N),e()}A="start"}var L={lastParent:null,lastPosition:null,lastFontSize:null,lastPercentToPxWidth:null,lastPercentToPxHeight:null,lastEmToPx:null,remToPx:null,vwToPx:null,vhToPx:null},R=[];f.each(g,function(e,t){m.isNode(t)&&n.call(t)});var z,j=f.extend({},b.defaults,v);if(j.loop=parseInt(j.loop),z=2*j.loop-1,j.loop)for(var O=0;z>O;O++){var q={delay:j.delay,progress:j.progress};O===z-1&&(q.display=j.display,q.visibility=j.visibility,q.complete=j.complete),P(g,"reverse",q)}return e()}};b=f.extend(P,b),b.animate=P;var w=t.requestAnimationFrame||g;return b.State.isMobile||r.hidden===a||r.addEventListener("visibilitychange",function(){r.hidden?(w=function(e){return setTimeout(function(){e(!0)},16)},c()):w=t.requestAnimationFrame||g}),e.Velocity=b,e!==t&&(e.fn.velocity=P,e.fn.velocity.defaults=b.defaults),f.each(["Down","Up"],function(e,t){b.Redirects["slide"+t]=function(e,r,n,o,i,s){var l=f.extend({},r),u=l.begin,c=l.complete,p={height:"",marginTop:"",marginBottom:"",paddingTop:"",paddingBottom:""},d={};l.display===a&&(l.display="Down"===t?"inline"===b.CSS.Values.getDisplayType(e)?"inline-block":"block":"none"),l.begin=function(){u&&u.call(i,i);for(var r in p){d[r]=e.style[r];var a=b.CSS.getPropertyValue(e,r);p[r]="Down"===t?[a,0]:[0,a]}d.overflow=e.style.overflow,e.style.overflow="hidden"},l.complete=function(){for(var t in d)e.style[t]=d[t];c&&c.call(i,i),s&&s.resolver(i)},b(e,p,l)}}),f.each(["In","Out"],function(e,t){b.Redirects["fade"+t]=function(e,r,n,o,i,s){var l=f.extend({},r),u={opacity:"In"===t?1:0},c=l.complete;l.complete=n!==o-1?l.begin=null:function(){c&&c.call(i,i),s&&s.resolver(i)},l.display===a&&(l.display="In"===t?"auto":"none"),b(this,u,l)}}),b}(window.jQuery||window.Zepto||window,window,document)}));
  245. /*!
  246. * Chart.js
  247. * http://chartjs.org/
  248. * Version: 2.7.3
  249. *
  250. * Copyright 2018 Chart.js Contributors
  251. * Released under the MIT license
  252. * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md
  253. */
  254. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Chart = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  255. },{}],2:[function(require,module,exports){
  256. /* MIT license */
  257. var colorNames = require(6);
  258. module.exports = {
  259. getRgba: getRgba,
  260. getHsla: getHsla,
  261. getRgb: getRgb,
  262. getHsl: getHsl,
  263. getHwb: getHwb,
  264. getAlpha: getAlpha,
  265. hexString: hexString,
  266. rgbString: rgbString,
  267. rgbaString: rgbaString,
  268. percentString: percentString,
  269. percentaString: percentaString,
  270. hslString: hslString,
  271. hslaString: hslaString,
  272. hwbString: hwbString,
  273. keyword: keyword
  274. }
  275. function getRgba(string) {
  276. if (!string) {
  277. return;
  278. }
  279. var abbr = /^#([a-fA-F0-9]{3})$/i,
  280. hex = /^#([a-fA-F0-9]{6})$/i,
  281. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  282. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  283. keyword = /(\w+)/;
  284. var rgb = [0, 0, 0],
  285. a = 1,
  286. match = string.match(abbr);
  287. if (match) {
  288. match = match[1];
  289. for (var i = 0; i < rgb.length; i++) {
  290. rgb[i] = parseInt(match[i] + match[i], 16);
  291. }
  292. }
  293. else if (match = string.match(hex)) {
  294. match = match[1];
  295. for (var i = 0; i < rgb.length; i++) {
  296. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  297. }
  298. }
  299. else if (match = string.match(rgba)) {
  300. for (var i = 0; i < rgb.length; i++) {
  301. rgb[i] = parseInt(match[i + 1]);
  302. }
  303. a = parseFloat(match[4]);
  304. }
  305. else if (match = string.match(per)) {
  306. for (var i = 0; i < rgb.length; i++) {
  307. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  308. }
  309. a = parseFloat(match[4]);
  310. }
  311. else if (match = string.match(keyword)) {
  312. if (match[1] == "transparent") {
  313. return [0, 0, 0, 0];
  314. }
  315. rgb = colorNames[match[1]];
  316. if (!rgb) {
  317. return;
  318. }
  319. }
  320. for (var i = 0; i < rgb.length; i++) {
  321. rgb[i] = scale(rgb[i], 0, 255);
  322. }
  323. if (!a && a != 0) {
  324. a = 1;
  325. }
  326. else {
  327. a = scale(a, 0, 1);
  328. }
  329. rgb[3] = a;
  330. return rgb;
  331. }
  332. function getHsla(string) {
  333. if (!string) {
  334. return;
  335. }
  336. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  337. var match = string.match(hsl);
  338. if (match) {
  339. var alpha = parseFloat(match[4]);
  340. var h = scale(parseInt(match[1]), 0, 360),
  341. s = scale(parseFloat(match[2]), 0, 100),
  342. l = scale(parseFloat(match[3]), 0, 100),
  343. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  344. return [h, s, l, a];
  345. }
  346. }
  347. function getHwb(string) {
  348. if (!string) {
  349. return;
  350. }
  351. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  352. var match = string.match(hwb);
  353. if (match) {
  354. var alpha = parseFloat(match[4]);
  355. var h = scale(parseInt(match[1]), 0, 360),
  356. w = scale(parseFloat(match[2]), 0, 100),
  357. b = scale(parseFloat(match[3]), 0, 100),
  358. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  359. return [h, w, b, a];
  360. }
  361. }
  362. function getRgb(string) {
  363. var rgba = getRgba(string);
  364. return rgba && rgba.slice(0, 3);
  365. }
  366. function getHsl(string) {
  367. var hsla = getHsla(string);
  368. return hsla && hsla.slice(0, 3);
  369. }
  370. function getAlpha(string) {
  371. var vals = getRgba(string);
  372. if (vals) {
  373. return vals[3];
  374. }
  375. else if (vals = getHsla(string)) {
  376. return vals[3];
  377. }
  378. else if (vals = getHwb(string)) {
  379. return vals[3];
  380. }
  381. }
  382. // generators
  383. function hexString(rgb) {
  384. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  385. + hexDouble(rgb[2]);
  386. }
  387. function rgbString(rgba, alpha) {
  388. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  389. return rgbaString(rgba, alpha);
  390. }
  391. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  392. }
  393. function rgbaString(rgba, alpha) {
  394. if (alpha === undefined) {
  395. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  396. }
  397. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  398. + ", " + alpha + ")";
  399. }
  400. function percentString(rgba, alpha) {
  401. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  402. return percentaString(rgba, alpha);
  403. }
  404. var r = Math.round(rgba[0]/255 * 100),
  405. g = Math.round(rgba[1]/255 * 100),
  406. b = Math.round(rgba[2]/255 * 100);
  407. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  408. }
  409. function percentaString(rgba, alpha) {
  410. var r = Math.round(rgba[0]/255 * 100),
  411. g = Math.round(rgba[1]/255 * 100),
  412. b = Math.round(rgba[2]/255 * 100);
  413. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  414. }
  415. function hslString(hsla, alpha) {
  416. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  417. return hslaString(hsla, alpha);
  418. }
  419. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  420. }
  421. function hslaString(hsla, alpha) {
  422. if (alpha === undefined) {
  423. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  424. }
  425. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  426. + alpha + ")";
  427. }
  428. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  429. // (hwb have alpha optional & 1 is default value)
  430. function hwbString(hwb, alpha) {
  431. if (alpha === undefined) {
  432. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  433. }
  434. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  435. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  436. }
  437. function keyword(rgb) {
  438. return reverseNames[rgb.slice(0, 3)];
  439. }
  440. // helpers
  441. function scale(num, min, max) {
  442. return Math.min(Math.max(min, num), max);
  443. }
  444. function hexDouble(num) {
  445. var str = num.toString(16).toUpperCase();
  446. return (str.length < 2) ? "0" + str : str;
  447. }
  448. //create a list of reverse color names
  449. var reverseNames = {};
  450. for (var name in colorNames) {
  451. reverseNames[colorNames[name]] = name;
  452. }
  453. },{"6":6}],3:[function(require,module,exports){
  454. /* MIT license */
  455. var convert = require(5);
  456. var string = require(2);
  457. var Color = function (obj) {
  458. if (obj instanceof Color) {
  459. return obj;
  460. }
  461. if (!(this instanceof Color)) {
  462. return new Color(obj);
  463. }
  464. this.valid = false;
  465. this.values = {
  466. rgb: [0, 0, 0],
  467. hsl: [0, 0, 0],
  468. hsv: [0, 0, 0],
  469. hwb: [0, 0, 0],
  470. cmyk: [0, 0, 0, 0],
  471. alpha: 1
  472. };
  473. // parse Color() argument
  474. var vals;
  475. if (typeof obj === 'string') {
  476. vals = string.getRgba(obj);
  477. if (vals) {
  478. this.setValues('rgb', vals);
  479. } else if (vals = string.getHsla(obj)) {
  480. this.setValues('hsl', vals);
  481. } else if (vals = string.getHwb(obj)) {
  482. this.setValues('hwb', vals);
  483. }
  484. } else if (typeof obj === 'object') {
  485. vals = obj;
  486. if (vals.r !== undefined || vals.red !== undefined) {
  487. this.setValues('rgb', vals);
  488. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  489. this.setValues('hsl', vals);
  490. } else if (vals.v !== undefined || vals.value !== undefined) {
  491. this.setValues('hsv', vals);
  492. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  493. this.setValues('hwb', vals);
  494. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  495. this.setValues('cmyk', vals);
  496. }
  497. }
  498. };
  499. Color.prototype = {
  500. isValid: function () {
  501. return this.valid;
  502. },
  503. rgb: function () {
  504. return this.setSpace('rgb', arguments);
  505. },
  506. hsl: function () {
  507. return this.setSpace('hsl', arguments);
  508. },
  509. hsv: function () {
  510. return this.setSpace('hsv', arguments);
  511. },
  512. hwb: function () {
  513. return this.setSpace('hwb', arguments);
  514. },
  515. cmyk: function () {
  516. return this.setSpace('cmyk', arguments);
  517. },
  518. rgbArray: function () {
  519. return this.values.rgb;
  520. },
  521. hslArray: function () {
  522. return this.values.hsl;
  523. },
  524. hsvArray: function () {
  525. return this.values.hsv;
  526. },
  527. hwbArray: function () {
  528. var values = this.values;
  529. if (values.alpha !== 1) {
  530. return values.hwb.concat([values.alpha]);
  531. }
  532. return values.hwb;
  533. },
  534. cmykArray: function () {
  535. return this.values.cmyk;
  536. },
  537. rgbaArray: function () {
  538. var values = this.values;
  539. return values.rgb.concat([values.alpha]);
  540. },
  541. hslaArray: function () {
  542. var values = this.values;
  543. return values.hsl.concat([values.alpha]);
  544. },
  545. alpha: function (val) {
  546. if (val === undefined) {
  547. return this.values.alpha;
  548. }
  549. this.setValues('alpha', val);
  550. return this;
  551. },
  552. red: function (val) {
  553. return this.setChannel('rgb', 0, val);
  554. },
  555. green: function (val) {
  556. return this.setChannel('rgb', 1, val);
  557. },
  558. blue: function (val) {
  559. return this.setChannel('rgb', 2, val);
  560. },
  561. hue: function (val) {
  562. if (val) {
  563. val %= 360;
  564. val = val < 0 ? 360 + val : val;
  565. }
  566. return this.setChannel('hsl', 0, val);
  567. },
  568. saturation: function (val) {
  569. return this.setChannel('hsl', 1, val);
  570. },
  571. lightness: function (val) {
  572. return this.setChannel('hsl', 2, val);
  573. },
  574. saturationv: function (val) {
  575. return this.setChannel('hsv', 1, val);
  576. },
  577. whiteness: function (val) {
  578. return this.setChannel('hwb', 1, val);
  579. },
  580. blackness: function (val) {
  581. return this.setChannel('hwb', 2, val);
  582. },
  583. value: function (val) {
  584. return this.setChannel('hsv', 2, val);
  585. },
  586. cyan: function (val) {
  587. return this.setChannel('cmyk', 0, val);
  588. },
  589. magenta: function (val) {
  590. return this.setChannel('cmyk', 1, val);
  591. },
  592. yellow: function (val) {
  593. return this.setChannel('cmyk', 2, val);
  594. },
  595. black: function (val) {
  596. return this.setChannel('cmyk', 3, val);
  597. },
  598. hexString: function () {
  599. return string.hexString(this.values.rgb);
  600. },
  601. rgbString: function () {
  602. return string.rgbString(this.values.rgb, this.values.alpha);
  603. },
  604. rgbaString: function () {
  605. return string.rgbaString(this.values.rgb, this.values.alpha);
  606. },
  607. percentString: function () {
  608. return string.percentString(this.values.rgb, this.values.alpha);
  609. },
  610. hslString: function () {
  611. return string.hslString(this.values.hsl, this.values.alpha);
  612. },
  613. hslaString: function () {
  614. return string.hslaString(this.values.hsl, this.values.alpha);
  615. },
  616. hwbString: function () {
  617. return string.hwbString(this.values.hwb, this.values.alpha);
  618. },
  619. keyword: function () {
  620. return string.keyword(this.values.rgb, this.values.alpha);
  621. },
  622. rgbNumber: function () {
  623. var rgb = this.values.rgb;
  624. return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
  625. },
  626. luminosity: function () {
  627. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  628. var rgb = this.values.rgb;
  629. var lum = [];
  630. for (var i = 0; i < rgb.length; i++) {
  631. var chan = rgb[i] / 255;
  632. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
  633. }
  634. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  635. },
  636. contrast: function (color2) {
  637. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  638. var lum1 = this.luminosity();
  639. var lum2 = color2.luminosity();
  640. if (lum1 > lum2) {
  641. return (lum1 + 0.05) / (lum2 + 0.05);
  642. }
  643. return (lum2 + 0.05) / (lum1 + 0.05);
  644. },
  645. level: function (color2) {
  646. var contrastRatio = this.contrast(color2);
  647. if (contrastRatio >= 7.1) {
  648. return 'AAA';
  649. }
  650. return (contrastRatio >= 4.5) ? 'AA' : '';
  651. },
  652. dark: function () {
  653. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  654. var rgb = this.values.rgb;
  655. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  656. return yiq < 128;
  657. },
  658. light: function () {
  659. return !this.dark();
  660. },
  661. negate: function () {
  662. var rgb = [];
  663. for (var i = 0; i < 3; i++) {
  664. rgb[i] = 255 - this.values.rgb[i];
  665. }
  666. this.setValues('rgb', rgb);
  667. return this;
  668. },
  669. lighten: function (ratio) {
  670. var hsl = this.values.hsl;
  671. hsl[2] += hsl[2] * ratio;
  672. this.setValues('hsl', hsl);
  673. return this;
  674. },
  675. darken: function (ratio) {
  676. var hsl = this.values.hsl;
  677. hsl[2] -= hsl[2] * ratio;
  678. this.setValues('hsl', hsl);
  679. return this;
  680. },
  681. saturate: function (ratio) {
  682. var hsl = this.values.hsl;
  683. hsl[1] += hsl[1] * ratio;
  684. this.setValues('hsl', hsl);
  685. return this;
  686. },
  687. desaturate: function (ratio) {
  688. var hsl = this.values.hsl;
  689. hsl[1] -= hsl[1] * ratio;
  690. this.setValues('hsl', hsl);
  691. return this;
  692. },
  693. whiten: function (ratio) {
  694. var hwb = this.values.hwb;
  695. hwb[1] += hwb[1] * ratio;
  696. this.setValues('hwb', hwb);
  697. return this;
  698. },
  699. blacken: function (ratio) {
  700. var hwb = this.values.hwb;
  701. hwb[2] += hwb[2] * ratio;
  702. this.setValues('hwb', hwb);
  703. return this;
  704. },
  705. greyscale: function () {
  706. var rgb = this.values.rgb;
  707. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  708. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  709. this.setValues('rgb', [val, val, val]);
  710. return this;
  711. },
  712. clearer: function (ratio) {
  713. var alpha = this.values.alpha;
  714. this.setValues('alpha', alpha - (alpha * ratio));
  715. return this;
  716. },
  717. opaquer: function (ratio) {
  718. var alpha = this.values.alpha;
  719. this.setValues('alpha', alpha + (alpha * ratio));
  720. return this;
  721. },
  722. rotate: function (degrees) {
  723. var hsl = this.values.hsl;
  724. var hue = (hsl[0] + degrees) % 360;
  725. hsl[0] = hue < 0 ? 360 + hue : hue;
  726. this.setValues('hsl', hsl);
  727. return this;
  728. },
  729. /**
  730. * Ported from sass implementation in C
  731. * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
  732. */
  733. mix: function (mixinColor, weight) {
  734. var color1 = this;
  735. var color2 = mixinColor;
  736. var p = weight === undefined ? 0.5 : weight;
  737. var w = 2 * p - 1;
  738. var a = color1.alpha() - color2.alpha();
  739. var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  740. var w2 = 1 - w1;
  741. return this
  742. .rgb(
  743. w1 * color1.red() + w2 * color2.red(),
  744. w1 * color1.green() + w2 * color2.green(),
  745. w1 * color1.blue() + w2 * color2.blue()
  746. )
  747. .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
  748. },
  749. toJSON: function () {
  750. return this.rgb();
  751. },
  752. clone: function () {
  753. // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
  754. // making the final build way to big to embed in Chart.js. So let's do it manually,
  755. // assuming that values to clone are 1 dimension arrays containing only numbers,
  756. // except 'alpha' which is a number.
  757. var result = new Color();
  758. var source = this.values;
  759. var target = result.values;
  760. var value, type;
  761. for (var prop in source) {
  762. if (source.hasOwnProperty(prop)) {
  763. value = source[prop];
  764. type = ({}).toString.call(value);
  765. if (type === '[object Array]') {
  766. target[prop] = value.slice(0);
  767. } else if (type === '[object Number]') {
  768. target[prop] = value;
  769. } else {
  770. console.error('unexpected color value:', value);
  771. }
  772. }
  773. }
  774. return result;
  775. }
  776. };
  777. Color.prototype.spaces = {
  778. rgb: ['red', 'green', 'blue'],
  779. hsl: ['hue', 'saturation', 'lightness'],
  780. hsv: ['hue', 'saturation', 'value'],
  781. hwb: ['hue', 'whiteness', 'blackness'],
  782. cmyk: ['cyan', 'magenta', 'yellow', 'black']
  783. };
  784. Color.prototype.maxes = {
  785. rgb: [255, 255, 255],
  786. hsl: [360, 100, 100],
  787. hsv: [360, 100, 100],
  788. hwb: [360, 100, 100],
  789. cmyk: [100, 100, 100, 100]
  790. };
  791. Color.prototype.getValues = function (space) {
  792. var values = this.values;
  793. var vals = {};
  794. for (var i = 0; i < space.length; i++) {
  795. vals[space.charAt(i)] = values[space][i];
  796. }
  797. if (values.alpha !== 1) {
  798. vals.a = values.alpha;
  799. }
  800. // {r: 255, g: 255, b: 255, a: 0.4}
  801. return vals;
  802. };
  803. Color.prototype.setValues = function (space, vals) {
  804. var values = this.values;
  805. var spaces = this.spaces;
  806. var maxes = this.maxes;
  807. var alpha = 1;
  808. var i;
  809. this.valid = true;
  810. if (space === 'alpha') {
  811. alpha = vals;
  812. } else if (vals.length) {
  813. // [10, 10, 10]
  814. values[space] = vals.slice(0, space.length);
  815. alpha = vals[space.length];
  816. } else if (vals[space.charAt(0)] !== undefined) {
  817. // {r: 10, g: 10, b: 10}
  818. for (i = 0; i < space.length; i++) {
  819. values[space][i] = vals[space.charAt(i)];
  820. }
  821. alpha = vals.a;
  822. } else if (vals[spaces[space][0]] !== undefined) {
  823. // {red: 10, green: 10, blue: 10}
  824. var chans = spaces[space];
  825. for (i = 0; i < space.length; i++) {
  826. values[space][i] = vals[chans[i]];
  827. }
  828. alpha = vals.alpha;
  829. }
  830. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  831. if (space === 'alpha') {
  832. return false;
  833. }
  834. var capped;
  835. // cap values of the space prior converting all values
  836. for (i = 0; i < space.length; i++) {
  837. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  838. values[space][i] = Math.round(capped);
  839. }
  840. // convert to all the other color spaces
  841. for (var sname in spaces) {
  842. if (sname !== space) {
  843. values[sname] = convert[space][sname](values[space]);
  844. }
  845. }
  846. return true;
  847. };
  848. Color.prototype.setSpace = function (space, args) {
  849. var vals = args[0];
  850. if (vals === undefined) {
  851. // color.rgb()
  852. return this.getValues(space);
  853. }
  854. // color.rgb(10, 10, 10)
  855. if (typeof vals === 'number') {
  856. vals = Array.prototype.slice.call(args);
  857. }
  858. this.setValues(space, vals);
  859. return this;
  860. };
  861. Color.prototype.setChannel = function (space, index, val) {
  862. var svalues = this.values[space];
  863. if (val === undefined) {
  864. // color.red()
  865. return svalues[index];
  866. } else if (val === svalues[index]) {
  867. // color.red(color.red())
  868. return this;
  869. }
  870. // color.red(100)
  871. svalues[index] = val;
  872. this.setValues(space, svalues);
  873. return this;
  874. };
  875. if (typeof window !== 'undefined') {
  876. window.Color = Color;
  877. }
  878. module.exports = Color;
  879. },{"2":2,"5":5}],4:[function(require,module,exports){
  880. /* MIT license */
  881. module.exports = {
  882. rgb2hsl: rgb2hsl,
  883. rgb2hsv: rgb2hsv,
  884. rgb2hwb: rgb2hwb,
  885. rgb2cmyk: rgb2cmyk,
  886. rgb2keyword: rgb2keyword,
  887. rgb2xyz: rgb2xyz,
  888. rgb2lab: rgb2lab,
  889. rgb2lch: rgb2lch,
  890. hsl2rgb: hsl2rgb,
  891. hsl2hsv: hsl2hsv,
  892. hsl2hwb: hsl2hwb,
  893. hsl2cmyk: hsl2cmyk,
  894. hsl2keyword: hsl2keyword,
  895. hsv2rgb: hsv2rgb,
  896. hsv2hsl: hsv2hsl,
  897. hsv2hwb: hsv2hwb,
  898. hsv2cmyk: hsv2cmyk,
  899. hsv2keyword: hsv2keyword,
  900. hwb2rgb: hwb2rgb,
  901. hwb2hsl: hwb2hsl,
  902. hwb2hsv: hwb2hsv,
  903. hwb2cmyk: hwb2cmyk,
  904. hwb2keyword: hwb2keyword,
  905. cmyk2rgb: cmyk2rgb,
  906. cmyk2hsl: cmyk2hsl,
  907. cmyk2hsv: cmyk2hsv,
  908. cmyk2hwb: cmyk2hwb,
  909. cmyk2keyword: cmyk2keyword,
  910. keyword2rgb: keyword2rgb,
  911. keyword2hsl: keyword2hsl,
  912. keyword2hsv: keyword2hsv,
  913. keyword2hwb: keyword2hwb,
  914. keyword2cmyk: keyword2cmyk,
  915. keyword2lab: keyword2lab,
  916. keyword2xyz: keyword2xyz,
  917. xyz2rgb: xyz2rgb,
  918. xyz2lab: xyz2lab,
  919. xyz2lch: xyz2lch,
  920. lab2xyz: lab2xyz,
  921. lab2rgb: lab2rgb,
  922. lab2lch: lab2lch,
  923. lch2lab: lch2lab,
  924. lch2xyz: lch2xyz,
  925. lch2rgb: lch2rgb
  926. }
  927. function rgb2hsl(rgb) {
  928. var r = rgb[0]/255,
  929. g = rgb[1]/255,
  930. b = rgb[2]/255,
  931. min = Math.min(r, g, b),
  932. max = Math.max(r, g, b),
  933. delta = max - min,
  934. h, s, l;
  935. if (max == min)
  936. h = 0;
  937. else if (r == max)
  938. h = (g - b) / delta;
  939. else if (g == max)
  940. h = 2 + (b - r) / delta;
  941. else if (b == max)
  942. h = 4 + (r - g)/ delta;
  943. h = Math.min(h * 60, 360);
  944. if (h < 0)
  945. h += 360;
  946. l = (min + max) / 2;
  947. if (max == min)
  948. s = 0;
  949. else if (l <= 0.5)
  950. s = delta / (max + min);
  951. else
  952. s = delta / (2 - max - min);
  953. return [h, s * 100, l * 100];
  954. }
  955. function rgb2hsv(rgb) {
  956. var r = rgb[0],
  957. g = rgb[1],
  958. b = rgb[2],
  959. min = Math.min(r, g, b),
  960. max = Math.max(r, g, b),
  961. delta = max - min,
  962. h, s, v;
  963. if (max == 0)
  964. s = 0;
  965. else
  966. s = (delta/max * 1000)/10;
  967. if (max == min)
  968. h = 0;
  969. else if (r == max)
  970. h = (g - b) / delta;
  971. else if (g == max)
  972. h = 2 + (b - r) / delta;
  973. else if (b == max)
  974. h = 4 + (r - g) / delta;
  975. h = Math.min(h * 60, 360);
  976. if (h < 0)
  977. h += 360;
  978. v = ((max / 255) * 1000) / 10;
  979. return [h, s, v];
  980. }
  981. function rgb2hwb(rgb) {
  982. var r = rgb[0],
  983. g = rgb[1],
  984. b = rgb[2],
  985. h = rgb2hsl(rgb)[0],
  986. w = 1/255 * Math.min(r, Math.min(g, b)),
  987. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  988. return [h, w * 100, b * 100];
  989. }
  990. function rgb2cmyk(rgb) {
  991. var r = rgb[0] / 255,
  992. g = rgb[1] / 255,
  993. b = rgb[2] / 255,
  994. c, m, y, k;
  995. k = Math.min(1 - r, 1 - g, 1 - b);
  996. c = (1 - r - k) / (1 - k) || 0;
  997. m = (1 - g - k) / (1 - k) || 0;
  998. y = (1 - b - k) / (1 - k) || 0;
  999. return [c * 100, m * 100, y * 100, k * 100];
  1000. }
  1001. function rgb2keyword(rgb) {
  1002. return reverseKeywords[JSON.stringify(rgb)];
  1003. }
  1004. function rgb2xyz(rgb) {
  1005. var r = rgb[0] / 255,
  1006. g = rgb[1] / 255,
  1007. b = rgb[2] / 255;
  1008. // assume sRGB
  1009. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  1010. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  1011. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  1012. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  1013. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  1014. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  1015. return [x * 100, y *100, z * 100];
  1016. }
  1017. function rgb2lab(rgb) {
  1018. var xyz = rgb2xyz(rgb),
  1019. x = xyz[0],
  1020. y = xyz[1],
  1021. z = xyz[2],
  1022. l, a, b;
  1023. x /= 95.047;
  1024. y /= 100;
  1025. z /= 108.883;
  1026. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  1027. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  1028. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  1029. l = (116 * y) - 16;
  1030. a = 500 * (x - y);
  1031. b = 200 * (y - z);
  1032. return [l, a, b];
  1033. }
  1034. function rgb2lch(args) {
  1035. return lab2lch(rgb2lab(args));
  1036. }
  1037. function hsl2rgb(hsl) {
  1038. var h = hsl[0] / 360,
  1039. s = hsl[1] / 100,
  1040. l = hsl[2] / 100,
  1041. t1, t2, t3, rgb, val;
  1042. if (s == 0) {
  1043. val = l * 255;
  1044. return [val, val, val];
  1045. }
  1046. if (l < 0.5)
  1047. t2 = l * (1 + s);
  1048. else
  1049. t2 = l + s - l * s;
  1050. t1 = 2 * l - t2;
  1051. rgb = [0, 0, 0];
  1052. for (var i = 0; i < 3; i++) {
  1053. t3 = h + 1 / 3 * - (i - 1);
  1054. t3 < 0 && t3++;
  1055. t3 > 1 && t3--;
  1056. if (6 * t3 < 1)
  1057. val = t1 + (t2 - t1) * 6 * t3;
  1058. else if (2 * t3 < 1)
  1059. val = t2;
  1060. else if (3 * t3 < 2)
  1061. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  1062. else
  1063. val = t1;
  1064. rgb[i] = val * 255;
  1065. }
  1066. return rgb;
  1067. }
  1068. function hsl2hsv(hsl) {
  1069. var h = hsl[0],
  1070. s = hsl[1] / 100,
  1071. l = hsl[2] / 100,
  1072. sv, v;
  1073. if(l === 0) {
  1074. // no need to do calc on black
  1075. // also avoids divide by 0 error
  1076. return [0, 0, 0];
  1077. }
  1078. l *= 2;
  1079. s *= (l <= 1) ? l : 2 - l;
  1080. v = (l + s) / 2;
  1081. sv = (2 * s) / (l + s);
  1082. return [h, sv * 100, v * 100];
  1083. }
  1084. function hsl2hwb(args) {
  1085. return rgb2hwb(hsl2rgb(args));
  1086. }
  1087. function hsl2cmyk(args) {
  1088. return rgb2cmyk(hsl2rgb(args));
  1089. }
  1090. function hsl2keyword(args) {
  1091. return rgb2keyword(hsl2rgb(args));
  1092. }
  1093. function hsv2rgb(hsv) {
  1094. var h = hsv[0] / 60,
  1095. s = hsv[1] / 100,
  1096. v = hsv[2] / 100,
  1097. hi = Math.floor(h) % 6;
  1098. var f = h - Math.floor(h),
  1099. p = 255 * v * (1 - s),
  1100. q = 255 * v * (1 - (s * f)),
  1101. t = 255 * v * (1 - (s * (1 - f))),
  1102. v = 255 * v;
  1103. switch(hi) {
  1104. case 0:
  1105. return [v, t, p];
  1106. case 1:
  1107. return [q, v, p];
  1108. case 2:
  1109. return [p, v, t];
  1110. case 3:
  1111. return [p, q, v];
  1112. case 4:
  1113. return [t, p, v];
  1114. case 5:
  1115. return [v, p, q];
  1116. }
  1117. }
  1118. function hsv2hsl(hsv) {
  1119. var h = hsv[0],
  1120. s = hsv[1] / 100,
  1121. v = hsv[2] / 100,
  1122. sl, l;
  1123. l = (2 - s) * v;
  1124. sl = s * v;
  1125. sl /= (l <= 1) ? l : 2 - l;
  1126. sl = sl || 0;
  1127. l /= 2;
  1128. return [h, sl * 100, l * 100];
  1129. }
  1130. function hsv2hwb(args) {
  1131. return rgb2hwb(hsv2rgb(args))
  1132. }
  1133. function hsv2cmyk(args) {
  1134. return rgb2cmyk(hsv2rgb(args));
  1135. }
  1136. function hsv2keyword(args) {
  1137. return rgb2keyword(hsv2rgb(args));
  1138. }
  1139. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  1140. function hwb2rgb(hwb) {
  1141. var h = hwb[0] / 360,
  1142. wh = hwb[1] / 100,
  1143. bl = hwb[2] / 100,
  1144. ratio = wh + bl,
  1145. i, v, f, n;
  1146. // wh + bl cant be > 1
  1147. if (ratio > 1) {
  1148. wh /= ratio;
  1149. bl /= ratio;
  1150. }
  1151. i = Math.floor(6 * h);
  1152. v = 1 - bl;
  1153. f = 6 * h - i;
  1154. if ((i & 0x01) != 0) {
  1155. f = 1 - f;
  1156. }
  1157. n = wh + f * (v - wh); // linear interpolation
  1158. switch (i) {
  1159. default:
  1160. case 6:
  1161. case 0: r = v; g = n; b = wh; break;
  1162. case 1: r = n; g = v; b = wh; break;
  1163. case 2: r = wh; g = v; b = n; break;
  1164. case 3: r = wh; g = n; b = v; break;
  1165. case 4: r = n; g = wh; b = v; break;
  1166. case 5: r = v; g = wh; b = n; break;
  1167. }
  1168. return [r * 255, g * 255, b * 255];
  1169. }
  1170. function hwb2hsl(args) {
  1171. return rgb2hsl(hwb2rgb(args));
  1172. }
  1173. function hwb2hsv(args) {
  1174. return rgb2hsv(hwb2rgb(args));
  1175. }
  1176. function hwb2cmyk(args) {
  1177. return rgb2cmyk(hwb2rgb(args));
  1178. }
  1179. function hwb2keyword(args) {
  1180. return rgb2keyword(hwb2rgb(args));
  1181. }
  1182. function cmyk2rgb(cmyk) {
  1183. var c = cmyk[0] / 100,
  1184. m = cmyk[1] / 100,
  1185. y = cmyk[2] / 100,
  1186. k = cmyk[3] / 100,
  1187. r, g, b;
  1188. r = 1 - Math.min(1, c * (1 - k) + k);
  1189. g = 1 - Math.min(1, m * (1 - k) + k);
  1190. b = 1 - Math.min(1, y * (1 - k) + k);
  1191. return [r * 255, g * 255, b * 255];
  1192. }
  1193. function cmyk2hsl(args) {
  1194. return rgb2hsl(cmyk2rgb(args));
  1195. }
  1196. function cmyk2hsv(args) {
  1197. return rgb2hsv(cmyk2rgb(args));
  1198. }
  1199. function cmyk2hwb(args) {
  1200. return rgb2hwb(cmyk2rgb(args));
  1201. }
  1202. function cmyk2keyword(args) {
  1203. return rgb2keyword(cmyk2rgb(args));
  1204. }
  1205. function xyz2rgb(xyz) {
  1206. var x = xyz[0] / 100,
  1207. y = xyz[1] / 100,
  1208. z = xyz[2] / 100,
  1209. r, g, b;
  1210. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  1211. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  1212. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  1213. // assume sRGB
  1214. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  1215. : r = (r * 12.92);
  1216. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  1217. : g = (g * 12.92);
  1218. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  1219. : b = (b * 12.92);
  1220. r = Math.min(Math.max(0, r), 1);
  1221. g = Math.min(Math.max(0, g), 1);
  1222. b = Math.min(Math.max(0, b), 1);
  1223. return [r * 255, g * 255, b * 255];
  1224. }
  1225. function xyz2lab(xyz) {
  1226. var x = xyz[0],
  1227. y = xyz[1],
  1228. z = xyz[2],
  1229. l, a, b;
  1230. x /= 95.047;
  1231. y /= 100;
  1232. z /= 108.883;
  1233. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  1234. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  1235. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  1236. l = (116 * y) - 16;
  1237. a = 500 * (x - y);
  1238. b = 200 * (y - z);
  1239. return [l, a, b];
  1240. }
  1241. function xyz2lch(args) {
  1242. return lab2lch(xyz2lab(args));
  1243. }
  1244. function lab2xyz(lab) {
  1245. var l = lab[0],
  1246. a = lab[1],
  1247. b = lab[2],
  1248. x, y, z, y2;
  1249. if (l <= 8) {
  1250. y = (l * 100) / 903.3;
  1251. y2 = (7.787 * (y / 100)) + (16 / 116);
  1252. } else {
  1253. y = 100 * Math.pow((l + 16) / 116, 3);
  1254. y2 = Math.pow(y / 100, 1/3);
  1255. }
  1256. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1257. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1258. return [x, y, z];
  1259. }
  1260. function lab2lch(lab) {
  1261. var l = lab[0],
  1262. a = lab[1],
  1263. b = lab[2],
  1264. hr, h, c;
  1265. hr = Math.atan2(b, a);
  1266. h = hr * 360 / 2 / Math.PI;
  1267. if (h < 0) {
  1268. h += 360;
  1269. }
  1270. c = Math.sqrt(a * a + b * b);
  1271. return [l, c, h];
  1272. }
  1273. function lab2rgb(args) {
  1274. return xyz2rgb(lab2xyz(args));
  1275. }
  1276. function lch2lab(lch) {
  1277. var l = lch[0],
  1278. c = lch[1],
  1279. h = lch[2],
  1280. a, b, hr;
  1281. hr = h / 360 * 2 * Math.PI;
  1282. a = c * Math.cos(hr);
  1283. b = c * Math.sin(hr);
  1284. return [l, a, b];
  1285. }
  1286. function lch2xyz(args) {
  1287. return lab2xyz(lch2lab(args));
  1288. }
  1289. function lch2rgb(args) {
  1290. return lab2rgb(lch2lab(args));
  1291. }
  1292. function keyword2rgb(keyword) {
  1293. return cssKeywords[keyword];
  1294. }
  1295. function keyword2hsl(args) {
  1296. return rgb2hsl(keyword2rgb(args));
  1297. }
  1298. function keyword2hsv(args) {
  1299. return rgb2hsv(keyword2rgb(args));
  1300. }
  1301. function keyword2hwb(args) {
  1302. return rgb2hwb(keyword2rgb(args));
  1303. }
  1304. function keyword2cmyk(args) {
  1305. return rgb2cmyk(keyword2rgb(args));
  1306. }
  1307. function keyword2lab(args) {
  1308. return rgb2lab(keyword2rgb(args));
  1309. }
  1310. function keyword2xyz(args) {
  1311. return rgb2xyz(keyword2rgb(args));
  1312. }
  1313. var cssKeywords = {
  1314. aliceblue: [240,248,255],
  1315. antiquewhite: [250,235,215],
  1316. aqua: [0,255,255],
  1317. aquamarine: [127,255,212],
  1318. azure: [240,255,255],
  1319. beige: [245,245,220],
  1320. bisque: [255,228,196],
  1321. black: [0,0,0],
  1322. blanchedalmond: [255,235,205],
  1323. blue: [0,0,255],
  1324. blueviolet: [138,43,226],
  1325. brown: [165,42,42],
  1326. burlywood: [222,184,135],
  1327. cadetblue: [95,158,160],
  1328. chartreuse: [127,255,0],
  1329. chocolate: [210,105,30],
  1330. coral: [255,127,80],
  1331. cornflowerblue: [100,149,237],
  1332. cornsilk: [255,248,220],
  1333. crimson: [220,20,60],
  1334. cyan: [0,255,255],
  1335. darkblue: [0,0,139],
  1336. darkcyan: [0,139,139],
  1337. darkgoldenrod: [184,134,11],
  1338. darkgray: [169,169,169],
  1339. darkgreen: [0,100,0],
  1340. darkgrey: [169,169,169],
  1341. darkkhaki: [189,183,107],
  1342. darkmagenta: [139,0,139],
  1343. darkolivegreen: [85,107,47],
  1344. darkorange: [255,140,0],
  1345. darkorchid: [153,50,204],
  1346. darkred: [139,0,0],
  1347. darksalmon: [233,150,122],
  1348. darkseagreen: [143,188,143],
  1349. darkslateblue: [72,61,139],
  1350. darkslategray: [47,79,79],
  1351. darkslategrey: [47,79,79],
  1352. darkturquoise: [0,206,209],
  1353. darkviolet: [148,0,211],
  1354. deeppink: [255,20,147],
  1355. deepskyblue: [0,191,255],
  1356. dimgray: [105,105,105],
  1357. dimgrey: [105,105,105],
  1358. dodgerblue: [30,144,255],
  1359. firebrick: [178,34,34],
  1360. floralwhite: [255,250,240],
  1361. forestgreen: [34,139,34],
  1362. fuchsia: [255,0,255],
  1363. gainsboro: [220,220,220],
  1364. ghostwhite: [248,248,255],
  1365. gold: [255,215,0],
  1366. goldenrod: [218,165,32],
  1367. gray: [128,128,128],
  1368. green: [0,128,0],
  1369. greenyellow: [173,255,47],
  1370. grey: [128,128,128],
  1371. honeydew: [240,255,240],
  1372. hotpink: [255,105,180],
  1373. indianred: [205,92,92],
  1374. indigo: [75,0,130],
  1375. ivory: [255,255,240],
  1376. khaki: [240,230,140],
  1377. lavender: [230,230,250],
  1378. lavenderblush: [255,240,245],
  1379. lawngreen: [124,252,0],
  1380. lemonchiffon: [255,250,205],
  1381. lightblue: [173,216,230],
  1382. lightcoral: [240,128,128],
  1383. lightcyan: [224,255,255],
  1384. lightgoldenrodyellow: [250,250,210],
  1385. lightgray: [211,211,211],
  1386. lightgreen: [144,238,144],
  1387. lightgrey: [211,211,211],
  1388. lightpink: [255,182,193],
  1389. lightsalmon: [255,160,122],
  1390. lightseagreen: [32,178,170],
  1391. lightskyblue: [135,206,250],
  1392. lightslategray: [119,136,153],
  1393. lightslategrey: [119,136,153],
  1394. lightsteelblue: [176,196,222],
  1395. lightyellow: [255,255,224],
  1396. lime: [0,255,0],
  1397. limegreen: [50,205,50],
  1398. linen: [250,240,230],
  1399. magenta: [255,0,255],
  1400. maroon: [128,0,0],
  1401. mediumaquamarine: [102,205,170],
  1402. mediumblue: [0,0,205],
  1403. mediumorchid: [186,85,211],
  1404. mediumpurple: [147,112,219],
  1405. mediumseagreen: [60,179,113],
  1406. mediumslateblue: [123,104,238],
  1407. mediumspringgreen: [0,250,154],
  1408. mediumturquoise: [72,209,204],
  1409. mediumvioletred: [199,21,133],
  1410. midnightblue: [25,25,112],
  1411. mintcream: [245,255,250],
  1412. mistyrose: [255,228,225],
  1413. moccasin: [255,228,181],
  1414. navajowhite: [255,222,173],
  1415. navy: [0,0,128],
  1416. oldlace: [253,245,230],
  1417. olive: [128,128,0],
  1418. olivedrab: [107,142,35],
  1419. orange: [255,165,0],
  1420. orangered: [255,69,0],
  1421. orchid: [218,112,214],
  1422. palegoldenrod: [238,232,170],
  1423. palegreen: [152,251,152],
  1424. paleturquoise: [175,238,238],
  1425. palevioletred: [219,112,147],
  1426. papayawhip: [255,239,213],
  1427. peachpuff: [255,218,185],
  1428. peru: [205,133,63],
  1429. pink: [255,192,203],
  1430. plum: [221,160,221],
  1431. powderblue: [176,224,230],
  1432. purple: [128,0,128],
  1433. rebeccapurple: [102, 51, 153],
  1434. red: [255,0,0],
  1435. rosybrown: [188,143,143],
  1436. royalblue: [65,105,225],
  1437. saddlebrown: [139,69,19],
  1438. salmon: [250,128,114],
  1439. sandybrown: [244,164,96],
  1440. seagreen: [46,139,87],
  1441. seashell: [255,245,238],
  1442. sienna: [160,82,45],
  1443. silver: [192,192,192],
  1444. skyblue: [135,206,235],
  1445. slateblue: [106,90,205],
  1446. slategray: [112,128,144],
  1447. slategrey: [112,128,144],
  1448. snow: [255,250,250],
  1449. springgreen: [0,255,127],
  1450. steelblue: [70,130,180],
  1451. tan: [210,180,140],
  1452. teal: [0,128,128],
  1453. thistle: [216,191,216],
  1454. tomato: [255,99,71],
  1455. turquoise: [64,224,208],
  1456. violet: [238,130,238],
  1457. wheat: [245,222,179],
  1458. white: [255,255,255],
  1459. whitesmoke: [245,245,245],
  1460. yellow: [255,255,0],
  1461. yellowgreen: [154,205,50]
  1462. };
  1463. var reverseKeywords = {};
  1464. for (var key in cssKeywords) {
  1465. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1466. }
  1467. },{}],5:[function(require,module,exports){
  1468. var conversions = require(4);
  1469. var convert = function() {
  1470. return new Converter();
  1471. }
  1472. for (var func in conversions) {
  1473. // export Raw versions
  1474. convert[func + "Raw"] = (function(func) {
  1475. // accept array or plain args
  1476. return function(arg) {
  1477. if (typeof arg == "number")
  1478. arg = Array.prototype.slice.call(arguments);
  1479. return conversions[func](arg);
  1480. }
  1481. })(func);
  1482. var pair = /(\w+)2(\w+)/.exec(func),
  1483. from = pair[1],
  1484. to = pair[2];
  1485. // export rgb2hsl and ["rgb"]["hsl"]
  1486. convert[from] = convert[from] || {};
  1487. convert[from][to] = convert[func] = (function(func) {
  1488. return function(arg) {
  1489. if (typeof arg == "number")
  1490. arg = Array.prototype.slice.call(arguments);
  1491. var val = conversions[func](arg);
  1492. if (typeof val == "string" || val === undefined)
  1493. return val; // keyword
  1494. for (var i = 0; i < val.length; i++)
  1495. val[i] = Math.round(val[i]);
  1496. return val;
  1497. }
  1498. })(func);
  1499. }
  1500. /* Converter does lazy conversion and caching */
  1501. var Converter = function() {
  1502. this.convs = {};
  1503. };
  1504. /* Either get the values for a space or
  1505. set the values for a space, depending on args */
  1506. Converter.prototype.routeSpace = function(space, args) {
  1507. var values = args[0];
  1508. if (values === undefined) {
  1509. // color.rgb()
  1510. return this.getValues(space);
  1511. }
  1512. // color.rgb(10, 10, 10)
  1513. if (typeof values == "number") {
  1514. values = Array.prototype.slice.call(args);
  1515. }
  1516. return this.setValues(space, values);
  1517. };
  1518. /* Set the values for a space, invalidating cache */
  1519. Converter.prototype.setValues = function(space, values) {
  1520. this.space = space;
  1521. this.convs = {};
  1522. this.convs[space] = values;
  1523. return this;
  1524. };
  1525. /* Get the values for a space. If there's already
  1526. a conversion for the space, fetch it, otherwise
  1527. compute it */
  1528. Converter.prototype.getValues = function(space) {
  1529. var vals = this.convs[space];
  1530. if (!vals) {
  1531. var fspace = this.space,
  1532. from = this.convs[fspace];
  1533. vals = convert[fspace][space](from);
  1534. this.convs[space] = vals;
  1535. }
  1536. return vals;
  1537. };
  1538. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  1539. Converter.prototype[space] = function(vals) {
  1540. return this.routeSpace(space, arguments);
  1541. }
  1542. });
  1543. module.exports = convert;
  1544. },{"4":4}],6:[function(require,module,exports){
  1545. 'use strict'
  1546. module.exports = {
  1547. "aliceblue": [240, 248, 255],
  1548. "antiquewhite": [250, 235, 215],
  1549. "aqua": [0, 255, 255],
  1550. "aquamarine": [127, 255, 212],
  1551. "azure": [240, 255, 255],
  1552. "beige": [245, 245, 220],
  1553. "bisque": [255, 228, 196],
  1554. "black": [0, 0, 0],
  1555. "blanchedalmond": [255, 235, 205],
  1556. "blue": [0, 0, 255],
  1557. "blueviolet": [138, 43, 226],
  1558. "brown": [165, 42, 42],
  1559. "burlywood": [222, 184, 135],
  1560. "cadetblue": [95, 158, 160],
  1561. "chartreuse": [127, 255, 0],
  1562. "chocolate": [210, 105, 30],
  1563. "coral": [255, 127, 80],
  1564. "cornflowerblue": [100, 149, 237],
  1565. "cornsilk": [255, 248, 220],
  1566. "crimson": [220, 20, 60],
  1567. "cyan": [0, 255, 255],
  1568. "darkblue": [0, 0, 139],
  1569. "darkcyan": [0, 139, 139],
  1570. "darkgoldenrod": [184, 134, 11],
  1571. "darkgray": [169, 169, 169],
  1572. "darkgreen": [0, 100, 0],
  1573. "darkgrey": [169, 169, 169],
  1574. "darkkhaki": [189, 183, 107],
  1575. "darkmagenta": [139, 0, 139],
  1576. "darkolivegreen": [85, 107, 47],
  1577. "darkorange": [255, 140, 0],
  1578. "darkorchid": [153, 50, 204],
  1579. "darkred": [139, 0, 0],
  1580. "darksalmon": [233, 150, 122],
  1581. "darkseagreen": [143, 188, 143],
  1582. "darkslateblue": [72, 61, 139],
  1583. "darkslategray": [47, 79, 79],
  1584. "darkslategrey": [47, 79, 79],
  1585. "darkturquoise": [0, 206, 209],
  1586. "darkviolet": [148, 0, 211],
  1587. "deeppink": [255, 20, 147],
  1588. "deepskyblue": [0, 191, 255],
  1589. "dimgray": [105, 105, 105],
  1590. "dimgrey": [105, 105, 105],
  1591. "dodgerblue": [30, 144, 255],
  1592. "firebrick": [178, 34, 34],
  1593. "floralwhite": [255, 250, 240],
  1594. "forestgreen": [34, 139, 34],
  1595. "fuchsia": [255, 0, 255],
  1596. "gainsboro": [220, 220, 220],
  1597. "ghostwhite": [248, 248, 255],
  1598. "gold": [255, 215, 0],
  1599. "goldenrod": [218, 165, 32],
  1600. "gray": [128, 128, 128],
  1601. "green": [0, 128, 0],
  1602. "greenyellow": [173, 255, 47],
  1603. "grey": [128, 128, 128],
  1604. "honeydew": [240, 255, 240],
  1605. "hotpink": [255, 105, 180],
  1606. "indianred": [205, 92, 92],
  1607. "indigo": [75, 0, 130],
  1608. "ivory": [255, 255, 240],
  1609. "khaki": [240, 230, 140],
  1610. "lavender": [230, 230, 250],
  1611. "lavenderblush": [255, 240, 245],
  1612. "lawngreen": [124, 252, 0],
  1613. "lemonchiffon": [255, 250, 205],
  1614. "lightblue": [173, 216, 230],
  1615. "lightcoral": [240, 128, 128],
  1616. "lightcyan": [224, 255, 255],
  1617. "lightgoldenrodyellow": [250, 250, 210],
  1618. "lightgray": [211, 211, 211],
  1619. "lightgreen": [144, 238, 144],
  1620. "lightgrey": [211, 211, 211],
  1621. "lightpink": [255, 182, 193],
  1622. "lightsalmon": [255, 160, 122],
  1623. "lightseagreen": [32, 178, 170],
  1624. "lightskyblue": [135, 206, 250],
  1625. "lightslategray": [119, 136, 153],
  1626. "lightslategrey": [119, 136, 153],
  1627. "lightsteelblue": [176, 196, 222],
  1628. "lightyellow": [255, 255, 224],
  1629. "lime": [0, 255, 0],
  1630. "limegreen": [50, 205, 50],
  1631. "linen": [250, 240, 230],
  1632. "magenta": [255, 0, 255],
  1633. "maroon": [128, 0, 0],
  1634. "mediumaquamarine": [102, 205, 170],
  1635. "mediumblue": [0, 0, 205],
  1636. "mediumorchid": [186, 85, 211],
  1637. "mediumpurple": [147, 112, 219],
  1638. "mediumseagreen": [60, 179, 113],
  1639. "mediumslateblue": [123, 104, 238],
  1640. "mediumspringgreen": [0, 250, 154],
  1641. "mediumturquoise": [72, 209, 204],
  1642. "mediumvioletred": [199, 21, 133],
  1643. "midnightblue": [25, 25, 112],
  1644. "mintcream": [245, 255, 250],
  1645. "mistyrose": [255, 228, 225],
  1646. "moccasin": [255, 228, 181],
  1647. "navajowhite": [255, 222, 173],
  1648. "navy": [0, 0, 128],
  1649. "oldlace": [253, 245, 230],
  1650. "olive": [128, 128, 0],
  1651. "olivedrab": [107, 142, 35],
  1652. "orange": [255, 165, 0],
  1653. "orangered": [255, 69, 0],
  1654. "orchid": [218, 112, 214],
  1655. "palegoldenrod": [238, 232, 170],
  1656. "palegreen": [152, 251, 152],
  1657. "paleturquoise": [175, 238, 238],
  1658. "palevioletred": [219, 112, 147],
  1659. "papayawhip": [255, 239, 213],
  1660. "peachpuff": [255, 218, 185],
  1661. "peru": [205, 133, 63],
  1662. "pink": [255, 192, 203],
  1663. "plum": [221, 160, 221],
  1664. "powderblue": [176, 224, 230],
  1665. "purple": [128, 0, 128],
  1666. "rebeccapurple": [102, 51, 153],
  1667. "red": [255, 0, 0],
  1668. "rosybrown": [188, 143, 143],
  1669. "royalblue": [65, 105, 225],
  1670. "saddlebrown": [139, 69, 19],
  1671. "salmon": [250, 128, 114],
  1672. "sandybrown": [244, 164, 96],
  1673. "seagreen": [46, 139, 87],
  1674. "seashell": [255, 245, 238],
  1675. "sienna": [160, 82, 45],
  1676. "silver": [192, 192, 192],
  1677. "skyblue": [135, 206, 235],
  1678. "slateblue": [106, 90, 205],
  1679. "slategray": [112, 128, 144],
  1680. "slategrey": [112, 128, 144],
  1681. "snow": [255, 250, 250],
  1682. "springgreen": [0, 255, 127],
  1683. "steelblue": [70, 130, 180],
  1684. "tan": [210, 180, 140],
  1685. "teal": [0, 128, 128],
  1686. "thistle": [216, 191, 216],
  1687. "tomato": [255, 99, 71],
  1688. "turquoise": [64, 224, 208],
  1689. "violet": [238, 130, 238],
  1690. "wheat": [245, 222, 179],
  1691. "white": [255, 255, 255],
  1692. "whitesmoke": [245, 245, 245],
  1693. "yellow": [255, 255, 0],
  1694. "yellowgreen": [154, 205, 50]
  1695. };
  1696. },{}],7:[function(require,module,exports){
  1697. /**
  1698. * @namespace Chart
  1699. */
  1700. var Chart = require(30)();
  1701. Chart.helpers = require(46);
  1702. // @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
  1703. require(28)(Chart);
  1704. Chart.Animation = require(22);
  1705. Chart.animationService = require(23);
  1706. Chart.defaults = require(26);
  1707. Chart.Element = require(27);
  1708. Chart.elements = require(41);
  1709. Chart.Interaction = require(29);
  1710. Chart.layouts = require(31);
  1711. Chart.platform = require(49);
  1712. Chart.plugins = require(32);
  1713. Chart.Scale = require(33);
  1714. Chart.scaleService = require(34);
  1715. Chart.Ticks = require(35);
  1716. Chart.Tooltip = require(36);
  1717. require(24)(Chart);
  1718. require(25)(Chart);
  1719. require(56)(Chart);
  1720. require(54)(Chart);
  1721. require(55)(Chart);
  1722. require(57)(Chart);
  1723. require(58)(Chart);
  1724. require(59)(Chart);
  1725. // Controllers must be loaded after elements
  1726. // See Chart.core.datasetController.dataElementType
  1727. require(15)(Chart);
  1728. require(16)(Chart);
  1729. require(17)(Chart);
  1730. require(18)(Chart);
  1731. require(19)(Chart);
  1732. require(20)(Chart);
  1733. require(21)(Chart);
  1734. require(8)(Chart);
  1735. require(9)(Chart);
  1736. require(10)(Chart);
  1737. require(11)(Chart);
  1738. require(12)(Chart);
  1739. require(13)(Chart);
  1740. require(14)(Chart);
  1741. // Loading built-in plugins
  1742. var plugins = require(50);
  1743. for (var k in plugins) {
  1744. if (plugins.hasOwnProperty(k)) {
  1745. Chart.plugins.register(plugins[k]);
  1746. }
  1747. }
  1748. Chart.platform.initialize();
  1749. module.exports = Chart;
  1750. if (typeof window !== 'undefined') {
  1751. window.Chart = Chart;
  1752. }
  1753. // DEPRECATIONS
  1754. /**
  1755. * Provided for backward compatibility, not available anymore
  1756. * @namespace Chart.Legend
  1757. * @deprecated since version 2.1.5
  1758. * @todo remove at version 3
  1759. * @private
  1760. */
  1761. Chart.Legend = plugins.legend._element;
  1762. /**
  1763. * Provided for backward compatibility, not available anymore
  1764. * @namespace Chart.Title
  1765. * @deprecated since version 2.1.5
  1766. * @todo remove at version 3
  1767. * @private
  1768. */
  1769. Chart.Title = plugins.title._element;
  1770. /**
  1771. * Provided for backward compatibility, use Chart.plugins instead
  1772. * @namespace Chart.pluginService
  1773. * @deprecated since version 2.1.5
  1774. * @todo remove at version 3
  1775. * @private
  1776. */
  1777. Chart.pluginService = Chart.plugins;
  1778. /**
  1779. * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
  1780. * effect, instead simply create/register plugins via plain JavaScript objects.
  1781. * @interface Chart.PluginBase
  1782. * @deprecated since version 2.5.0
  1783. * @todo remove at version 3
  1784. * @private
  1785. */
  1786. Chart.PluginBase = Chart.Element.extend({});
  1787. /**
  1788. * Provided for backward compatibility, use Chart.helpers.canvas instead.
  1789. * @namespace Chart.canvasHelpers
  1790. * @deprecated since version 2.6.0
  1791. * @todo remove at version 3
  1792. * @private
  1793. */
  1794. Chart.canvasHelpers = Chart.helpers.canvas;
  1795. /**
  1796. * Provided for backward compatibility, use Chart.layouts instead.
  1797. * @namespace Chart.layoutService
  1798. * @deprecated since version 2.8.0
  1799. * @todo remove at version 3
  1800. * @private
  1801. */
  1802. Chart.layoutService = Chart.layouts;
  1803. },{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"33":33,"34":34,"35":35,"36":36,"41":41,"46":46,"49":49,"50":50,"54":54,"55":55,"56":56,"57":57,"58":58,"59":59,"8":8,"9":9}],8:[function(require,module,exports){
  1804. 'use strict';
  1805. module.exports = function(Chart) {
  1806. Chart.Bar = function(context, config) {
  1807. config.type = 'bar';
  1808. return new Chart(context, config);
  1809. };
  1810. };
  1811. },{}],9:[function(require,module,exports){
  1812. 'use strict';
  1813. module.exports = function(Chart) {
  1814. Chart.Bubble = function(context, config) {
  1815. config.type = 'bubble';
  1816. return new Chart(context, config);
  1817. };
  1818. };
  1819. },{}],10:[function(require,module,exports){
  1820. 'use strict';
  1821. module.exports = function(Chart) {
  1822. Chart.Doughnut = function(context, config) {
  1823. config.type = 'doughnut';
  1824. return new Chart(context, config);
  1825. };
  1826. };
  1827. },{}],11:[function(require,module,exports){
  1828. 'use strict';
  1829. module.exports = function(Chart) {
  1830. Chart.Line = function(context, config) {
  1831. config.type = 'line';
  1832. return new Chart(context, config);
  1833. };
  1834. };
  1835. },{}],12:[function(require,module,exports){
  1836. 'use strict';
  1837. module.exports = function(Chart) {
  1838. Chart.PolarArea = function(context, config) {
  1839. config.type = 'polarArea';
  1840. return new Chart(context, config);
  1841. };
  1842. };
  1843. },{}],13:[function(require,module,exports){
  1844. 'use strict';
  1845. module.exports = function(Chart) {
  1846. Chart.Radar = function(context, config) {
  1847. config.type = 'radar';
  1848. return new Chart(context, config);
  1849. };
  1850. };
  1851. },{}],14:[function(require,module,exports){
  1852. 'use strict';
  1853. module.exports = function(Chart) {
  1854. Chart.Scatter = function(context, config) {
  1855. config.type = 'scatter';
  1856. return new Chart(context, config);
  1857. };
  1858. };
  1859. },{}],15:[function(require,module,exports){
  1860. 'use strict';
  1861. var defaults = require(26);
  1862. var elements = require(41);
  1863. var helpers = require(46);
  1864. defaults._set('bar', {
  1865. hover: {
  1866. mode: 'label'
  1867. },
  1868. scales: {
  1869. xAxes: [{
  1870. type: 'category',
  1871. // Specific to Bar Controller
  1872. categoryPercentage: 0.8,
  1873. barPercentage: 0.9,
  1874. // offset settings
  1875. offset: true,
  1876. // grid line settings
  1877. gridLines: {
  1878. offsetGridLines: true
  1879. }
  1880. }],
  1881. yAxes: [{
  1882. type: 'linear'
  1883. }]
  1884. }
  1885. });
  1886. defaults._set('horizontalBar', {
  1887. hover: {
  1888. mode: 'index',
  1889. axis: 'y'
  1890. },
  1891. scales: {
  1892. xAxes: [{
  1893. type: 'linear',
  1894. position: 'bottom'
  1895. }],
  1896. yAxes: [{
  1897. position: 'left',
  1898. type: 'category',
  1899. // Specific to Horizontal Bar Controller
  1900. categoryPercentage: 0.8,
  1901. barPercentage: 0.9,
  1902. // offset settings
  1903. offset: true,
  1904. // grid line settings
  1905. gridLines: {
  1906. offsetGridLines: true
  1907. }
  1908. }]
  1909. },
  1910. elements: {
  1911. rectangle: {
  1912. borderSkipped: 'left'
  1913. }
  1914. },
  1915. tooltips: {
  1916. callbacks: {
  1917. title: function(item, data) {
  1918. // Pick first xLabel for now
  1919. var title = '';
  1920. if (item.length > 0) {
  1921. if (item[0].yLabel) {
  1922. title = item[0].yLabel;
  1923. } else if (data.labels.length > 0 && item[0].index < data.labels.length) {
  1924. title = data.labels[item[0].index];
  1925. }
  1926. }
  1927. return title;
  1928. },
  1929. label: function(item, data) {
  1930. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  1931. return datasetLabel + ': ' + item.xLabel;
  1932. }
  1933. },
  1934. mode: 'index',
  1935. axis: 'y'
  1936. }
  1937. });
  1938. /**
  1939. * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  1940. * @private
  1941. */
  1942. function computeMinSampleSize(scale, pixels) {
  1943. var min = scale.isHorizontal() ? scale.width : scale.height;
  1944. var ticks = scale.getTicks();
  1945. var prev, curr, i, ilen;
  1946. for (i = 1, ilen = pixels.length; i < ilen; ++i) {
  1947. min = Math.min(min, pixels[i] - pixels[i - 1]);
  1948. }
  1949. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  1950. curr = scale.getPixelForTick(i);
  1951. min = i > 0 ? Math.min(min, curr - prev) : min;
  1952. prev = curr;
  1953. }
  1954. return min;
  1955. }
  1956. /**
  1957. * Computes an "ideal" category based on the absolute bar thickness or, if undefined or null,
  1958. * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This
  1959. * mode currently always generates bars equally sized (until we introduce scriptable options?).
  1960. * @private
  1961. */
  1962. function computeFitCategoryTraits(index, ruler, options) {
  1963. var thickness = options.barThickness;
  1964. var count = ruler.stackCount;
  1965. var curr = ruler.pixels[index];
  1966. var size, ratio;
  1967. if (helpers.isNullOrUndef(thickness)) {
  1968. size = ruler.min * options.categoryPercentage;
  1969. ratio = options.barPercentage;
  1970. } else {
  1971. // When bar thickness is enforced, category and bar percentages are ignored.
  1972. // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
  1973. // and deprecate barPercentage since this value is ignored when thickness is absolute.
  1974. size = thickness * count;
  1975. ratio = 1;
  1976. }
  1977. return {
  1978. chunk: size / count,
  1979. ratio: ratio,
  1980. start: curr - (size / 2)
  1981. };
  1982. }
  1983. /**
  1984. * Computes an "optimal" category that globally arranges bars side by side (no gap when
  1985. * percentage options are 1), based on the previous and following categories. This mode
  1986. * generates bars with different widths when data are not evenly spaced.
  1987. * @private
  1988. */
  1989. function computeFlexCategoryTraits(index, ruler, options) {
  1990. var pixels = ruler.pixels;
  1991. var curr = pixels[index];
  1992. var prev = index > 0 ? pixels[index - 1] : null;
  1993. var next = index < pixels.length - 1 ? pixels[index + 1] : null;
  1994. var percent = options.categoryPercentage;
  1995. var start, size;
  1996. if (prev === null) {
  1997. // first data: its size is double based on the next point or,
  1998. // if it's also the last data, we use the scale end extremity.
  1999. prev = curr - (next === null ? ruler.end - curr : next - curr);
  2000. }
  2001. if (next === null) {
  2002. // last data: its size is also double based on the previous point.
  2003. next = curr + curr - prev;
  2004. }
  2005. start = curr - ((curr - prev) / 2) * percent;
  2006. size = ((next - prev) / 2) * percent;
  2007. return {
  2008. chunk: size / ruler.stackCount,
  2009. ratio: options.barPercentage,
  2010. start: start
  2011. };
  2012. }
  2013. module.exports = function(Chart) {
  2014. Chart.controllers.bar = Chart.DatasetController.extend({
  2015. dataElementType: elements.Rectangle,
  2016. initialize: function() {
  2017. var me = this;
  2018. var meta;
  2019. Chart.DatasetController.prototype.initialize.apply(me, arguments);
  2020. meta = me.getMeta();
  2021. meta.stack = me.getDataset().stack;
  2022. meta.bar = true;
  2023. },
  2024. update: function(reset) {
  2025. var me = this;
  2026. var rects = me.getMeta().data;
  2027. var i, ilen;
  2028. me._ruler = me.getRuler();
  2029. for (i = 0, ilen = rects.length; i < ilen; ++i) {
  2030. me.updateElement(rects[i], i, reset);
  2031. }
  2032. },
  2033. updateElement: function(rectangle, index, reset) {
  2034. var me = this;
  2035. var chart = me.chart;
  2036. var meta = me.getMeta();
  2037. var dataset = me.getDataset();
  2038. var custom = rectangle.custom || {};
  2039. var rectangleOptions = chart.options.elements.rectangle;
  2040. rectangle._xScale = me.getScaleForId(meta.xAxisID);
  2041. rectangle._yScale = me.getScaleForId(meta.yAxisID);
  2042. rectangle._datasetIndex = me.index;
  2043. rectangle._index = index;
  2044. rectangle._model = {
  2045. datasetLabel: dataset.label,
  2046. label: chart.data.labels[index],
  2047. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped,
  2048. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor),
  2049. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor),
  2050. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth)
  2051. };
  2052. me.updateElementGeometry(rectangle, index, reset);
  2053. rectangle.pivot();
  2054. },
  2055. /**
  2056. * @private
  2057. */
  2058. updateElementGeometry: function(rectangle, index, reset) {
  2059. var me = this;
  2060. var model = rectangle._model;
  2061. var vscale = me.getValueScale();
  2062. var base = vscale.getBasePixel();
  2063. var horizontal = vscale.isHorizontal();
  2064. var ruler = me._ruler || me.getRuler();
  2065. var vpixels = me.calculateBarValuePixels(me.index, index);
  2066. var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
  2067. model.horizontal = horizontal;
  2068. model.base = reset ? base : vpixels.base;
  2069. model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
  2070. model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
  2071. model.height = horizontal ? ipixels.size : undefined;
  2072. model.width = horizontal ? undefined : ipixels.size;
  2073. },
  2074. /**
  2075. * @private
  2076. */
  2077. getValueScaleId: function() {
  2078. return this.getMeta().yAxisID;
  2079. },
  2080. /**
  2081. * @private
  2082. */
  2083. getIndexScaleId: function() {
  2084. return this.getMeta().xAxisID;
  2085. },
  2086. /**
  2087. * @private
  2088. */
  2089. getValueScale: function() {
  2090. return this.getScaleForId(this.getValueScaleId());
  2091. },
  2092. /**
  2093. * @private
  2094. */
  2095. getIndexScale: function() {
  2096. return this.getScaleForId(this.getIndexScaleId());
  2097. },
  2098. /**
  2099. * Returns the stacks based on groups and bar visibility.
  2100. * @param {Number} [last] - The dataset index
  2101. * @returns {Array} The stack list
  2102. * @private
  2103. */
  2104. _getStacks: function(last) {
  2105. var me = this;
  2106. var chart = me.chart;
  2107. var scale = me.getIndexScale();
  2108. var stacked = scale.options.stacked;
  2109. var ilen = last === undefined ? chart.data.datasets.length : last + 1;
  2110. var stacks = [];
  2111. var i, meta;
  2112. for (i = 0; i < ilen; ++i) {
  2113. meta = chart.getDatasetMeta(i);
  2114. if (meta.bar && chart.isDatasetVisible(i) &&
  2115. (stacked === false ||
  2116. (stacked === true && stacks.indexOf(meta.stack) === -1) ||
  2117. (stacked === undefined && (meta.stack === undefined || stacks.indexOf(meta.stack) === -1)))) {
  2118. stacks.push(meta.stack);
  2119. }
  2120. }
  2121. return stacks;
  2122. },
  2123. /**
  2124. * Returns the effective number of stacks based on groups and bar visibility.
  2125. * @private
  2126. */
  2127. getStackCount: function() {
  2128. return this._getStacks().length;
  2129. },
  2130. /**
  2131. * Returns the stack index for the given dataset based on groups and bar visibility.
  2132. * @param {Number} [datasetIndex] - The dataset index
  2133. * @param {String} [name] - The stack name to find
  2134. * @returns {Number} The stack index
  2135. * @private
  2136. */
  2137. getStackIndex: function(datasetIndex, name) {
  2138. var stacks = this._getStacks(datasetIndex);
  2139. var index = (name !== undefined)
  2140. ? stacks.indexOf(name)
  2141. : -1; // indexOf returns -1 if element is not present
  2142. return (index === -1)
  2143. ? stacks.length - 1
  2144. : index;
  2145. },
  2146. /**
  2147. * @private
  2148. */
  2149. getRuler: function() {
  2150. var me = this;
  2151. var scale = me.getIndexScale();
  2152. var stackCount = me.getStackCount();
  2153. var datasetIndex = me.index;
  2154. var isHorizontal = scale.isHorizontal();
  2155. var start = isHorizontal ? scale.left : scale.top;
  2156. var end = start + (isHorizontal ? scale.width : scale.height);
  2157. var pixels = [];
  2158. var i, ilen, min;
  2159. for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
  2160. pixels.push(scale.getPixelForValue(null, i, datasetIndex));
  2161. }
  2162. min = helpers.isNullOrUndef(scale.options.barThickness)
  2163. ? computeMinSampleSize(scale, pixels)
  2164. : -1;
  2165. return {
  2166. min: min,
  2167. pixels: pixels,
  2168. start: start,
  2169. end: end,
  2170. stackCount: stackCount,
  2171. scale: scale
  2172. };
  2173. },
  2174. /**
  2175. * Note: pixel values are not clamped to the scale area.
  2176. * @private
  2177. */
  2178. calculateBarValuePixels: function(datasetIndex, index) {
  2179. var me = this;
  2180. var chart = me.chart;
  2181. var meta = me.getMeta();
  2182. var scale = me.getValueScale();
  2183. var datasets = chart.data.datasets;
  2184. var value = scale.getRightValue(datasets[datasetIndex].data[index]);
  2185. var stacked = scale.options.stacked;
  2186. var stack = meta.stack;
  2187. var start = 0;
  2188. var i, imeta, ivalue, base, head, size;
  2189. if (stacked || (stacked === undefined && stack !== undefined)) {
  2190. for (i = 0; i < datasetIndex; ++i) {
  2191. imeta = chart.getDatasetMeta(i);
  2192. if (imeta.bar &&
  2193. imeta.stack === stack &&
  2194. imeta.controller.getValueScaleId() === scale.id &&
  2195. chart.isDatasetVisible(i)) {
  2196. ivalue = scale.getRightValue(datasets[i].data[index]);
  2197. if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
  2198. start += ivalue;
  2199. }
  2200. }
  2201. }
  2202. }
  2203. base = scale.getPixelForValue(start);
  2204. head = scale.getPixelForValue(start + value);
  2205. size = (head - base) / 2;
  2206. return {
  2207. size: size,
  2208. base: base,
  2209. head: head,
  2210. center: head + size / 2
  2211. };
  2212. },
  2213. /**
  2214. * @private
  2215. */
  2216. calculateBarIndexPixels: function(datasetIndex, index, ruler) {
  2217. var me = this;
  2218. var options = ruler.scale.options;
  2219. var range = options.barThickness === 'flex'
  2220. ? computeFlexCategoryTraits(index, ruler, options)
  2221. : computeFitCategoryTraits(index, ruler, options);
  2222. var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
  2223. var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
  2224. var size = Math.min(
  2225. helpers.valueOrDefault(options.maxBarThickness, Infinity),
  2226. range.chunk * range.ratio);
  2227. return {
  2228. base: center - size / 2,
  2229. head: center + size / 2,
  2230. center: center,
  2231. size: size
  2232. };
  2233. },
  2234. draw: function() {
  2235. var me = this;
  2236. var chart = me.chart;
  2237. var scale = me.getValueScale();
  2238. var rects = me.getMeta().data;
  2239. var dataset = me.getDataset();
  2240. var ilen = rects.length;
  2241. var i = 0;
  2242. helpers.canvas.clipArea(chart.ctx, chart.chartArea);
  2243. for (; i < ilen; ++i) {
  2244. if (!isNaN(scale.getRightValue(dataset.data[i]))) {
  2245. rects[i].draw();
  2246. }
  2247. }
  2248. helpers.canvas.unclipArea(chart.ctx);
  2249. },
  2250. });
  2251. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  2252. /**
  2253. * @private
  2254. */
  2255. getValueScaleId: function() {
  2256. return this.getMeta().xAxisID;
  2257. },
  2258. /**
  2259. * @private
  2260. */
  2261. getIndexScaleId: function() {
  2262. return this.getMeta().yAxisID;
  2263. }
  2264. });
  2265. };
  2266. },{"26":26,"41":41,"46":46}],16:[function(require,module,exports){
  2267. 'use strict';
  2268. var defaults = require(26);
  2269. var elements = require(41);
  2270. var helpers = require(46);
  2271. defaults._set('bubble', {
  2272. hover: {
  2273. mode: 'single'
  2274. },
  2275. scales: {
  2276. xAxes: [{
  2277. type: 'linear', // bubble should probably use a linear scale by default
  2278. position: 'bottom',
  2279. id: 'x-axis-0' // need an ID so datasets can reference the scale
  2280. }],
  2281. yAxes: [{
  2282. type: 'linear',
  2283. position: 'left',
  2284. id: 'y-axis-0'
  2285. }]
  2286. },
  2287. tooltips: {
  2288. callbacks: {
  2289. title: function() {
  2290. // Title doesn't make sense for scatter since we format the data as a point
  2291. return '';
  2292. },
  2293. label: function(item, data) {
  2294. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  2295. var dataPoint = data.datasets[item.datasetIndex].data[item.index];
  2296. return datasetLabel + ': (' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.r + ')';
  2297. }
  2298. }
  2299. }
  2300. });
  2301. module.exports = function(Chart) {
  2302. Chart.controllers.bubble = Chart.DatasetController.extend({
  2303. /**
  2304. * @protected
  2305. */
  2306. dataElementType: elements.Point,
  2307. /**
  2308. * @protected
  2309. */
  2310. update: function(reset) {
  2311. var me = this;
  2312. var meta = me.getMeta();
  2313. var points = meta.data;
  2314. // Update Points
  2315. helpers.each(points, function(point, index) {
  2316. me.updateElement(point, index, reset);
  2317. });
  2318. },
  2319. /**
  2320. * @protected
  2321. */
  2322. updateElement: function(point, index, reset) {
  2323. var me = this;
  2324. var meta = me.getMeta();
  2325. var custom = point.custom || {};
  2326. var xScale = me.getScaleForId(meta.xAxisID);
  2327. var yScale = me.getScaleForId(meta.yAxisID);
  2328. var options = me._resolveElementOptions(point, index);
  2329. var data = me.getDataset().data[index];
  2330. var dsIndex = me.index;
  2331. var x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex);
  2332. var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex);
  2333. point._xScale = xScale;
  2334. point._yScale = yScale;
  2335. point._options = options;
  2336. point._datasetIndex = dsIndex;
  2337. point._index = index;
  2338. point._model = {
  2339. backgroundColor: options.backgroundColor,
  2340. borderColor: options.borderColor,
  2341. borderWidth: options.borderWidth,
  2342. hitRadius: options.hitRadius,
  2343. pointStyle: options.pointStyle,
  2344. rotation: options.rotation,
  2345. radius: reset ? 0 : options.radius,
  2346. skip: custom.skip || isNaN(x) || isNaN(y),
  2347. x: x,
  2348. y: y,
  2349. };
  2350. point.pivot();
  2351. },
  2352. /**
  2353. * @protected
  2354. */
  2355. setHoverStyle: function(point) {
  2356. var model = point._model;
  2357. var options = point._options;
  2358. point.$previousStyle = {
  2359. backgroundColor: model.backgroundColor,
  2360. borderColor: model.borderColor,
  2361. borderWidth: model.borderWidth,
  2362. radius: model.radius
  2363. };
  2364. model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
  2365. model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
  2366. model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
  2367. model.radius = options.radius + options.hoverRadius;
  2368. },
  2369. /**
  2370. * @private
  2371. */
  2372. _resolveElementOptions: function(point, index) {
  2373. var me = this;
  2374. var chart = me.chart;
  2375. var datasets = chart.data.datasets;
  2376. var dataset = datasets[me.index];
  2377. var custom = point.custom || {};
  2378. var options = chart.options.elements.point;
  2379. var resolve = helpers.options.resolve;
  2380. var data = dataset.data[index];
  2381. var values = {};
  2382. var i, ilen, key;
  2383. // Scriptable options
  2384. var context = {
  2385. chart: chart,
  2386. dataIndex: index,
  2387. dataset: dataset,
  2388. datasetIndex: me.index
  2389. };
  2390. var keys = [
  2391. 'backgroundColor',
  2392. 'borderColor',
  2393. 'borderWidth',
  2394. 'hoverBackgroundColor',
  2395. 'hoverBorderColor',
  2396. 'hoverBorderWidth',
  2397. 'hoverRadius',
  2398. 'hitRadius',
  2399. 'pointStyle',
  2400. 'rotation'
  2401. ];
  2402. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  2403. key = keys[i];
  2404. values[key] = resolve([
  2405. custom[key],
  2406. dataset[key],
  2407. options[key]
  2408. ], context, index);
  2409. }
  2410. // Custom radius resolution
  2411. values.radius = resolve([
  2412. custom.radius,
  2413. data ? data.r : undefined,
  2414. dataset.radius,
  2415. options.radius
  2416. ], context, index);
  2417. return values;
  2418. }
  2419. });
  2420. };
  2421. },{"26":26,"41":41,"46":46}],17:[function(require,module,exports){
  2422. 'use strict';
  2423. var defaults = require(26);
  2424. var elements = require(41);
  2425. var helpers = require(46);
  2426. defaults._set('doughnut', {
  2427. animation: {
  2428. // Boolean - Whether we animate the rotation of the Doughnut
  2429. animateRotate: true,
  2430. // Boolean - Whether we animate scaling the Doughnut from the centre
  2431. animateScale: false
  2432. },
  2433. hover: {
  2434. mode: 'single'
  2435. },
  2436. legendCallback: function(chart) {
  2437. var text = [];
  2438. text.push('<ul class="' + chart.id + '-legend">');
  2439. var data = chart.data;
  2440. var datasets = data.datasets;
  2441. var labels = data.labels;
  2442. if (datasets.length) {
  2443. for (var i = 0; i < datasets[0].data.length; ++i) {
  2444. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2445. if (labels[i]) {
  2446. text.push(labels[i]);
  2447. }
  2448. text.push('</li>');
  2449. }
  2450. }
  2451. text.push('</ul>');
  2452. return text.join('');
  2453. },
  2454. legend: {
  2455. labels: {
  2456. generateLabels: function(chart) {
  2457. var data = chart.data;
  2458. if (data.labels.length && data.datasets.length) {
  2459. return data.labels.map(function(label, i) {
  2460. var meta = chart.getDatasetMeta(0);
  2461. var ds = data.datasets[0];
  2462. var arc = meta.data[i];
  2463. var custom = arc && arc.custom || {};
  2464. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2465. var arcOpts = chart.options.elements.arc;
  2466. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2467. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2468. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2469. return {
  2470. text: label,
  2471. fillStyle: fill,
  2472. strokeStyle: stroke,
  2473. lineWidth: bw,
  2474. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2475. // Extra data used for toggling the correct item
  2476. index: i
  2477. };
  2478. });
  2479. }
  2480. return [];
  2481. }
  2482. },
  2483. onClick: function(e, legendItem) {
  2484. var index = legendItem.index;
  2485. var chart = this.chart;
  2486. var i, ilen, meta;
  2487. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2488. meta = chart.getDatasetMeta(i);
  2489. // toggle visibility of index if exists
  2490. if (meta.data[index]) {
  2491. meta.data[index].hidden = !meta.data[index].hidden;
  2492. }
  2493. }
  2494. chart.update();
  2495. }
  2496. },
  2497. // The percentage of the chart that we cut out of the middle.
  2498. cutoutPercentage: 50,
  2499. // The rotation of the chart, where the first data arc begins.
  2500. rotation: Math.PI * -0.5,
  2501. // The total circumference of the chart.
  2502. circumference: Math.PI * 2.0,
  2503. // Need to override these to give a nice default
  2504. tooltips: {
  2505. callbacks: {
  2506. title: function() {
  2507. return '';
  2508. },
  2509. label: function(tooltipItem, data) {
  2510. var dataLabel = data.labels[tooltipItem.index];
  2511. var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2512. if (helpers.isArray(dataLabel)) {
  2513. // show value on first line of multiline label
  2514. // need to clone because we are changing the value
  2515. dataLabel = dataLabel.slice();
  2516. dataLabel[0] += value;
  2517. } else {
  2518. dataLabel += value;
  2519. }
  2520. return dataLabel;
  2521. }
  2522. }
  2523. }
  2524. });
  2525. defaults._set('pie', helpers.clone(defaults.doughnut));
  2526. defaults._set('pie', {
  2527. cutoutPercentage: 0
  2528. });
  2529. module.exports = function(Chart) {
  2530. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  2531. dataElementType: elements.Arc,
  2532. linkScales: helpers.noop,
  2533. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2534. getRingIndex: function(datasetIndex) {
  2535. var ringIndex = 0;
  2536. for (var j = 0; j < datasetIndex; ++j) {
  2537. if (this.chart.isDatasetVisible(j)) {
  2538. ++ringIndex;
  2539. }
  2540. }
  2541. return ringIndex;
  2542. },
  2543. update: function(reset) {
  2544. var me = this;
  2545. var chart = me.chart;
  2546. var chartArea = chart.chartArea;
  2547. var opts = chart.options;
  2548. var arcOpts = opts.elements.arc;
  2549. var availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth;
  2550. var availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth;
  2551. var minSize = Math.min(availableWidth, availableHeight);
  2552. var offset = {x: 0, y: 0};
  2553. var meta = me.getMeta();
  2554. var cutoutPercentage = opts.cutoutPercentage;
  2555. var circumference = opts.circumference;
  2556. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2557. if (circumference < Math.PI * 2.0) {
  2558. var startAngle = opts.rotation % (Math.PI * 2.0);
  2559. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2560. var endAngle = startAngle + circumference;
  2561. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2562. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2563. var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2564. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2565. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2566. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2567. var cutout = cutoutPercentage / 100.0;
  2568. 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))};
  2569. 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))};
  2570. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2571. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2572. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2573. }
  2574. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  2575. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  2576. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
  2577. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2578. chart.offsetX = offset.x * chart.outerRadius;
  2579. chart.offsetY = offset.y * chart.outerRadius;
  2580. meta.total = me.calculateTotal();
  2581. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  2582. me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
  2583. helpers.each(meta.data, function(arc, index) {
  2584. me.updateElement(arc, index, reset);
  2585. });
  2586. },
  2587. updateElement: function(arc, index, reset) {
  2588. var me = this;
  2589. var chart = me.chart;
  2590. var chartArea = chart.chartArea;
  2591. var opts = chart.options;
  2592. var animationOpts = opts.animation;
  2593. var centerX = (chartArea.left + chartArea.right) / 2;
  2594. var centerY = (chartArea.top + chartArea.bottom) / 2;
  2595. var startAngle = opts.rotation; // non reset case handled later
  2596. var endAngle = opts.rotation; // non reset case handled later
  2597. var dataset = me.getDataset();
  2598. var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI));
  2599. var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
  2600. var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
  2601. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2602. helpers.extend(arc, {
  2603. // Utility
  2604. _datasetIndex: me.index,
  2605. _index: index,
  2606. // Desired view properties
  2607. _model: {
  2608. x: centerX + chart.offsetX,
  2609. y: centerY + chart.offsetY,
  2610. startAngle: startAngle,
  2611. endAngle: endAngle,
  2612. circumference: circumference,
  2613. outerRadius: outerRadius,
  2614. innerRadius: innerRadius,
  2615. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  2616. }
  2617. });
  2618. var model = arc._model;
  2619. // Resets the visual styles
  2620. var custom = arc.custom || {};
  2621. var valueOrDefault = helpers.valueAtIndexOrDefault;
  2622. var elementOpts = this.chart.options.elements.arc;
  2623. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  2624. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  2625. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  2626. // Set correct angles if not resetting
  2627. if (!reset || !animationOpts.animateRotate) {
  2628. if (index === 0) {
  2629. model.startAngle = opts.rotation;
  2630. } else {
  2631. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  2632. }
  2633. model.endAngle = model.startAngle + model.circumference;
  2634. }
  2635. arc.pivot();
  2636. },
  2637. calculateTotal: function() {
  2638. var dataset = this.getDataset();
  2639. var meta = this.getMeta();
  2640. var total = 0;
  2641. var value;
  2642. helpers.each(meta.data, function(element, index) {
  2643. value = dataset.data[index];
  2644. if (!isNaN(value) && !element.hidden) {
  2645. total += Math.abs(value);
  2646. }
  2647. });
  2648. /* if (total === 0) {
  2649. total = NaN;
  2650. }*/
  2651. return total;
  2652. },
  2653. calculateCircumference: function(value) {
  2654. var total = this.getMeta().total;
  2655. if (total > 0 && !isNaN(value)) {
  2656. return (Math.PI * 2.0) * (Math.abs(value) / total);
  2657. }
  2658. return 0;
  2659. },
  2660. // gets the max border or hover width to properly scale pie charts
  2661. getMaxBorderWidth: function(arcs) {
  2662. var max = 0;
  2663. var index = this.index;
  2664. var length = arcs.length;
  2665. var borderWidth;
  2666. var hoverWidth;
  2667. for (var i = 0; i < length; i++) {
  2668. borderWidth = arcs[i]._model ? arcs[i]._model.borderWidth : 0;
  2669. hoverWidth = arcs[i]._chart ? arcs[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2670. max = borderWidth > max ? borderWidth : max;
  2671. max = hoverWidth > max ? hoverWidth : max;
  2672. }
  2673. return max;
  2674. }
  2675. });
  2676. };
  2677. },{"26":26,"41":41,"46":46}],18:[function(require,module,exports){
  2678. 'use strict';
  2679. var defaults = require(26);
  2680. var elements = require(41);
  2681. var helpers = require(46);
  2682. defaults._set('line', {
  2683. showLines: true,
  2684. spanGaps: false,
  2685. hover: {
  2686. mode: 'label'
  2687. },
  2688. scales: {
  2689. xAxes: [{
  2690. type: 'category',
  2691. id: 'x-axis-0'
  2692. }],
  2693. yAxes: [{
  2694. type: 'linear',
  2695. id: 'y-axis-0'
  2696. }]
  2697. }
  2698. });
  2699. module.exports = function(Chart) {
  2700. function lineEnabled(dataset, options) {
  2701. return helpers.valueOrDefault(dataset.showLine, options.showLines);
  2702. }
  2703. Chart.controllers.line = Chart.DatasetController.extend({
  2704. datasetElementType: elements.Line,
  2705. dataElementType: elements.Point,
  2706. update: function(reset) {
  2707. var me = this;
  2708. var meta = me.getMeta();
  2709. var line = meta.dataset;
  2710. var points = meta.data || [];
  2711. var options = me.chart.options;
  2712. var lineElementOptions = options.elements.line;
  2713. var scale = me.getScaleForId(meta.yAxisID);
  2714. var i, ilen, custom;
  2715. var dataset = me.getDataset();
  2716. var showLine = lineEnabled(dataset, options);
  2717. // Update Line
  2718. if (showLine) {
  2719. custom = line.custom || {};
  2720. // Compatibility: If the properties are defined with only the old name, use those values
  2721. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2722. dataset.lineTension = dataset.tension;
  2723. }
  2724. // Utility
  2725. line._scale = scale;
  2726. line._datasetIndex = me.index;
  2727. // Data
  2728. line._children = points;
  2729. // Model
  2730. line._model = {
  2731. // Appearance
  2732. // The default behavior of lines is to break at null values, according
  2733. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2734. // This option gives lines the ability to span gaps
  2735. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2736. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2737. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2738. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2739. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2740. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2741. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2742. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2743. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2744. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2745. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.valueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2746. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.valueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2747. };
  2748. line.pivot();
  2749. }
  2750. // Update Points
  2751. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2752. me.updateElement(points[i], i, reset);
  2753. }
  2754. if (showLine && line._model.tension !== 0) {
  2755. me.updateBezierControlPoints();
  2756. }
  2757. // Now pivot the point for animation
  2758. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2759. points[i].pivot();
  2760. }
  2761. },
  2762. getPointBackgroundColor: function(point, index) {
  2763. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2764. var dataset = this.getDataset();
  2765. var custom = point.custom || {};
  2766. if (custom.backgroundColor) {
  2767. backgroundColor = custom.backgroundColor;
  2768. } else if (dataset.pointBackgroundColor) {
  2769. backgroundColor = helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2770. } else if (dataset.backgroundColor) {
  2771. backgroundColor = dataset.backgroundColor;
  2772. }
  2773. return backgroundColor;
  2774. },
  2775. getPointBorderColor: function(point, index) {
  2776. var borderColor = this.chart.options.elements.point.borderColor;
  2777. var dataset = this.getDataset();
  2778. var custom = point.custom || {};
  2779. if (custom.borderColor) {
  2780. borderColor = custom.borderColor;
  2781. } else if (dataset.pointBorderColor) {
  2782. borderColor = helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2783. } else if (dataset.borderColor) {
  2784. borderColor = dataset.borderColor;
  2785. }
  2786. return borderColor;
  2787. },
  2788. getPointBorderWidth: function(point, index) {
  2789. var borderWidth = this.chart.options.elements.point.borderWidth;
  2790. var dataset = this.getDataset();
  2791. var custom = point.custom || {};
  2792. if (!isNaN(custom.borderWidth)) {
  2793. borderWidth = custom.borderWidth;
  2794. } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
  2795. borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2796. } else if (!isNaN(dataset.borderWidth)) {
  2797. borderWidth = dataset.borderWidth;
  2798. }
  2799. return borderWidth;
  2800. },
  2801. getPointRotation: function(point, index) {
  2802. var pointRotation = this.chart.options.elements.point.rotation;
  2803. var dataset = this.getDataset();
  2804. var custom = point.custom || {};
  2805. if (!isNaN(custom.rotation)) {
  2806. pointRotation = custom.rotation;
  2807. } else if (!isNaN(dataset.pointRotation) || helpers.isArray(dataset.pointRotation)) {
  2808. pointRotation = helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointRotation);
  2809. }
  2810. return pointRotation;
  2811. },
  2812. updateElement: function(point, index, reset) {
  2813. var me = this;
  2814. var meta = me.getMeta();
  2815. var custom = point.custom || {};
  2816. var dataset = me.getDataset();
  2817. var datasetIndex = me.index;
  2818. var value = dataset.data[index];
  2819. var yScale = me.getScaleForId(meta.yAxisID);
  2820. var xScale = me.getScaleForId(meta.xAxisID);
  2821. var pointOptions = me.chart.options.elements.point;
  2822. var x, y;
  2823. // Compatibility: If the properties are defined with only the old name, use those values
  2824. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2825. dataset.pointRadius = dataset.radius;
  2826. }
  2827. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2828. dataset.pointHitRadius = dataset.hitRadius;
  2829. }
  2830. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
  2831. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2832. // Utility
  2833. point._xScale = xScale;
  2834. point._yScale = yScale;
  2835. point._datasetIndex = datasetIndex;
  2836. point._index = index;
  2837. // Desired view properties
  2838. point._model = {
  2839. x: x,
  2840. y: y,
  2841. skip: custom.skip || isNaN(x) || isNaN(y),
  2842. // Appearance
  2843. radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2844. pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2845. rotation: me.getPointRotation(point, index),
  2846. backgroundColor: me.getPointBackgroundColor(point, index),
  2847. borderColor: me.getPointBorderColor(point, index),
  2848. borderWidth: me.getPointBorderWidth(point, index),
  2849. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2850. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2851. // Tooltip
  2852. hitRadius: custom.hitRadius || helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2853. };
  2854. },
  2855. calculatePointY: function(value, index, datasetIndex) {
  2856. var me = this;
  2857. var chart = me.chart;
  2858. var meta = me.getMeta();
  2859. var yScale = me.getScaleForId(meta.yAxisID);
  2860. var sumPos = 0;
  2861. var sumNeg = 0;
  2862. var i, ds, dsMeta;
  2863. if (yScale.options.stacked) {
  2864. for (i = 0; i < datasetIndex; i++) {
  2865. ds = chart.data.datasets[i];
  2866. dsMeta = chart.getDatasetMeta(i);
  2867. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2868. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2869. if (stackedRightValue < 0) {
  2870. sumNeg += stackedRightValue || 0;
  2871. } else {
  2872. sumPos += stackedRightValue || 0;
  2873. }
  2874. }
  2875. }
  2876. var rightValue = Number(yScale.getRightValue(value));
  2877. if (rightValue < 0) {
  2878. return yScale.getPixelForValue(sumNeg + rightValue);
  2879. }
  2880. return yScale.getPixelForValue(sumPos + rightValue);
  2881. }
  2882. return yScale.getPixelForValue(value);
  2883. },
  2884. updateBezierControlPoints: function() {
  2885. var me = this;
  2886. var meta = me.getMeta();
  2887. var area = me.chart.chartArea;
  2888. var points = (meta.data || []);
  2889. var i, ilen, point, model, controlPoints;
  2890. // Only consider points that are drawn in case the spanGaps option is used
  2891. if (meta.dataset._model.spanGaps) {
  2892. points = points.filter(function(pt) {
  2893. return !pt._model.skip;
  2894. });
  2895. }
  2896. function capControlPoint(pt, min, max) {
  2897. return Math.max(Math.min(pt, max), min);
  2898. }
  2899. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2900. helpers.splineCurveMonotone(points);
  2901. } else {
  2902. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2903. point = points[i];
  2904. model = point._model;
  2905. controlPoints = helpers.splineCurve(
  2906. helpers.previousItem(points, i)._model,
  2907. model,
  2908. helpers.nextItem(points, i)._model,
  2909. meta.dataset._model.tension
  2910. );
  2911. model.controlPointPreviousX = controlPoints.previous.x;
  2912. model.controlPointPreviousY = controlPoints.previous.y;
  2913. model.controlPointNextX = controlPoints.next.x;
  2914. model.controlPointNextY = controlPoints.next.y;
  2915. }
  2916. }
  2917. if (me.chart.options.elements.line.capBezierPoints) {
  2918. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2919. model = points[i]._model;
  2920. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2921. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2922. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2923. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2924. }
  2925. }
  2926. },
  2927. draw: function() {
  2928. var me = this;
  2929. var chart = me.chart;
  2930. var meta = me.getMeta();
  2931. var points = meta.data || [];
  2932. var area = chart.chartArea;
  2933. var ilen = points.length;
  2934. var halfBorderWidth;
  2935. var i = 0;
  2936. if (lineEnabled(me.getDataset(), chart.options)) {
  2937. halfBorderWidth = (meta.dataset._model.borderWidth || 0) / 2;
  2938. helpers.canvas.clipArea(chart.ctx, {
  2939. left: area.left,
  2940. right: area.right,
  2941. top: area.top - halfBorderWidth,
  2942. bottom: area.bottom + halfBorderWidth
  2943. });
  2944. meta.dataset.draw();
  2945. helpers.canvas.unclipArea(chart.ctx);
  2946. }
  2947. // Draw the points
  2948. for (; i < ilen; ++i) {
  2949. points[i].draw(area);
  2950. }
  2951. },
  2952. setHoverStyle: function(element) {
  2953. // Point
  2954. var dataset = this.chart.data.datasets[element._datasetIndex];
  2955. var index = element._index;
  2956. var custom = element.custom || {};
  2957. var model = element._model;
  2958. element.$previousStyle = {
  2959. backgroundColor: model.backgroundColor,
  2960. borderColor: model.borderColor,
  2961. borderWidth: model.borderWidth,
  2962. radius: model.radius
  2963. };
  2964. model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2965. model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2966. model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2967. model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2968. },
  2969. });
  2970. };
  2971. },{"26":26,"41":41,"46":46}],19:[function(require,module,exports){
  2972. 'use strict';
  2973. var defaults = require(26);
  2974. var elements = require(41);
  2975. var helpers = require(46);
  2976. defaults._set('polarArea', {
  2977. scale: {
  2978. type: 'radialLinear',
  2979. angleLines: {
  2980. display: false
  2981. },
  2982. gridLines: {
  2983. circular: true
  2984. },
  2985. pointLabels: {
  2986. display: false
  2987. },
  2988. ticks: {
  2989. beginAtZero: true
  2990. }
  2991. },
  2992. // Boolean - Whether to animate the rotation of the chart
  2993. animation: {
  2994. animateRotate: true,
  2995. animateScale: true
  2996. },
  2997. startAngle: -0.5 * Math.PI,
  2998. legendCallback: function(chart) {
  2999. var text = [];
  3000. text.push('<ul class="' + chart.id + '-legend">');
  3001. var data = chart.data;
  3002. var datasets = data.datasets;
  3003. var labels = data.labels;
  3004. if (datasets.length) {
  3005. for (var i = 0; i < datasets[0].data.length; ++i) {
  3006. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  3007. if (labels[i]) {
  3008. text.push(labels[i]);
  3009. }
  3010. text.push('</li>');
  3011. }
  3012. }
  3013. text.push('</ul>');
  3014. return text.join('');
  3015. },
  3016. legend: {
  3017. labels: {
  3018. generateLabels: function(chart) {
  3019. var data = chart.data;
  3020. if (data.labels.length && data.datasets.length) {
  3021. return data.labels.map(function(label, i) {
  3022. var meta = chart.getDatasetMeta(0);
  3023. var ds = data.datasets[0];
  3024. var arc = meta.data[i];
  3025. var custom = arc.custom || {};
  3026. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  3027. var arcOpts = chart.options.elements.arc;
  3028. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  3029. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  3030. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  3031. return {
  3032. text: label,
  3033. fillStyle: fill,
  3034. strokeStyle: stroke,
  3035. lineWidth: bw,
  3036. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  3037. // Extra data used for toggling the correct item
  3038. index: i
  3039. };
  3040. });
  3041. }
  3042. return [];
  3043. }
  3044. },
  3045. onClick: function(e, legendItem) {
  3046. var index = legendItem.index;
  3047. var chart = this.chart;
  3048. var i, ilen, meta;
  3049. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  3050. meta = chart.getDatasetMeta(i);
  3051. meta.data[index].hidden = !meta.data[index].hidden;
  3052. }
  3053. chart.update();
  3054. }
  3055. },
  3056. // Need to override these to give a nice default
  3057. tooltips: {
  3058. callbacks: {
  3059. title: function() {
  3060. return '';
  3061. },
  3062. label: function(item, data) {
  3063. return data.labels[item.index] + ': ' + item.yLabel;
  3064. }
  3065. }
  3066. }
  3067. });
  3068. module.exports = function(Chart) {
  3069. Chart.controllers.polarArea = Chart.DatasetController.extend({
  3070. dataElementType: elements.Arc,
  3071. linkScales: helpers.noop,
  3072. update: function(reset) {
  3073. var me = this;
  3074. var dataset = me.getDataset();
  3075. var meta = me.getMeta();
  3076. var start = me.chart.options.startAngle || 0;
  3077. var starts = me._starts = [];
  3078. var angles = me._angles = [];
  3079. var i, ilen, angle;
  3080. me._updateRadius();
  3081. meta.count = me.countVisibleElements();
  3082. for (i = 0, ilen = dataset.data.length; i < ilen; i++) {
  3083. starts[i] = start;
  3084. angle = me._computeAngle(i);
  3085. angles[i] = angle;
  3086. start += angle;
  3087. }
  3088. helpers.each(meta.data, function(arc, index) {
  3089. me.updateElement(arc, index, reset);
  3090. });
  3091. },
  3092. /**
  3093. * @private
  3094. */
  3095. _updateRadius: function() {
  3096. var me = this;
  3097. var chart = me.chart;
  3098. var chartArea = chart.chartArea;
  3099. var opts = chart.options;
  3100. var arcOpts = opts.elements.arc;
  3101. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  3102. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  3103. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  3104. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  3105. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  3106. me.innerRadius = me.outerRadius - chart.radiusLength;
  3107. },
  3108. updateElement: function(arc, index, reset) {
  3109. var me = this;
  3110. var chart = me.chart;
  3111. var dataset = me.getDataset();
  3112. var opts = chart.options;
  3113. var animationOpts = opts.animation;
  3114. var scale = chart.scale;
  3115. var labels = chart.data.labels;
  3116. var centerX = scale.xCenter;
  3117. var centerY = scale.yCenter;
  3118. // var negHalfPI = -0.5 * Math.PI;
  3119. var datasetStartAngle = opts.startAngle;
  3120. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  3121. var startAngle = me._starts[index];
  3122. var endAngle = startAngle + (arc.hidden ? 0 : me._angles[index]);
  3123. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  3124. helpers.extend(arc, {
  3125. // Utility
  3126. _datasetIndex: me.index,
  3127. _index: index,
  3128. _scale: scale,
  3129. // Desired view properties
  3130. _model: {
  3131. x: centerX,
  3132. y: centerY,
  3133. innerRadius: 0,
  3134. outerRadius: reset ? resetRadius : distance,
  3135. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  3136. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  3137. label: helpers.valueAtIndexOrDefault(labels, index, labels[index])
  3138. }
  3139. });
  3140. // Apply border and fill style
  3141. var elementOpts = this.chart.options.elements.arc;
  3142. var custom = arc.custom || {};
  3143. var valueOrDefault = helpers.valueAtIndexOrDefault;
  3144. var model = arc._model;
  3145. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  3146. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  3147. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  3148. arc.pivot();
  3149. },
  3150. countVisibleElements: function() {
  3151. var dataset = this.getDataset();
  3152. var meta = this.getMeta();
  3153. var count = 0;
  3154. helpers.each(meta.data, function(element, index) {
  3155. if (!isNaN(dataset.data[index]) && !element.hidden) {
  3156. count++;
  3157. }
  3158. });
  3159. return count;
  3160. },
  3161. /**
  3162. * @private
  3163. */
  3164. _computeAngle: function(index) {
  3165. var me = this;
  3166. var count = this.getMeta().count;
  3167. var dataset = me.getDataset();
  3168. var meta = me.getMeta();
  3169. if (isNaN(dataset.data[index]) || meta.data[index].hidden) {
  3170. return 0;
  3171. }
  3172. // Scriptable options
  3173. var context = {
  3174. chart: me.chart,
  3175. dataIndex: index,
  3176. dataset: dataset,
  3177. datasetIndex: me.index
  3178. };
  3179. return helpers.options.resolve([
  3180. me.chart.options.elements.arc.angle,
  3181. (2 * Math.PI) / count
  3182. ], context, index);
  3183. }
  3184. });
  3185. };
  3186. },{"26":26,"41":41,"46":46}],20:[function(require,module,exports){
  3187. 'use strict';
  3188. var defaults = require(26);
  3189. var elements = require(41);
  3190. var helpers = require(46);
  3191. defaults._set('radar', {
  3192. scale: {
  3193. type: 'radialLinear'
  3194. },
  3195. elements: {
  3196. line: {
  3197. tension: 0 // no bezier in radar
  3198. }
  3199. }
  3200. });
  3201. module.exports = function(Chart) {
  3202. Chart.controllers.radar = Chart.DatasetController.extend({
  3203. datasetElementType: elements.Line,
  3204. dataElementType: elements.Point,
  3205. linkScales: helpers.noop,
  3206. update: function(reset) {
  3207. var me = this;
  3208. var meta = me.getMeta();
  3209. var line = meta.dataset;
  3210. var points = meta.data;
  3211. var custom = line.custom || {};
  3212. var dataset = me.getDataset();
  3213. var lineElementOptions = me.chart.options.elements.line;
  3214. var scale = me.chart.scale;
  3215. // Compatibility: If the properties are defined with only the old name, use those values
  3216. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  3217. dataset.lineTension = dataset.tension;
  3218. }
  3219. helpers.extend(meta.dataset, {
  3220. // Utility
  3221. _datasetIndex: me.index,
  3222. _scale: scale,
  3223. // Data
  3224. _children: points,
  3225. _loop: true,
  3226. // Model
  3227. _model: {
  3228. // Appearance
  3229. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  3230. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  3231. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  3232. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  3233. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  3234. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  3235. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  3236. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  3237. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  3238. }
  3239. });
  3240. meta.dataset.pivot();
  3241. // Update Points
  3242. helpers.each(points, function(point, index) {
  3243. me.updateElement(point, index, reset);
  3244. }, me);
  3245. // Update bezier control points
  3246. me.updateBezierControlPoints();
  3247. },
  3248. updateElement: function(point, index, reset) {
  3249. var me = this;
  3250. var custom = point.custom || {};
  3251. var dataset = me.getDataset();
  3252. var scale = me.chart.scale;
  3253. var pointElementOptions = me.chart.options.elements.point;
  3254. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  3255. // Compatibility: If the properties are defined with only the old name, use those values
  3256. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  3257. dataset.pointRadius = dataset.radius;
  3258. }
  3259. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  3260. dataset.pointHitRadius = dataset.hitRadius;
  3261. }
  3262. helpers.extend(point, {
  3263. // Utility
  3264. _datasetIndex: me.index,
  3265. _index: index,
  3266. _scale: scale,
  3267. // Desired view properties
  3268. _model: {
  3269. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  3270. y: reset ? scale.yCenter : pointPosition.y,
  3271. // Appearance
  3272. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
  3273. radius: custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  3274. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  3275. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  3276. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  3277. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  3278. rotation: custom.rotation ? custom.rotation : helpers.valueAtIndexOrDefault(dataset.pointRotation, index, pointElementOptions.rotation),
  3279. // Tooltip
  3280. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
  3281. }
  3282. });
  3283. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  3284. },
  3285. updateBezierControlPoints: function() {
  3286. var chartArea = this.chart.chartArea;
  3287. var meta = this.getMeta();
  3288. helpers.each(meta.data, function(point, index) {
  3289. var model = point._model;
  3290. var controlPoints = helpers.splineCurve(
  3291. helpers.previousItem(meta.data, index, true)._model,
  3292. model,
  3293. helpers.nextItem(meta.data, index, true)._model,
  3294. model.tension
  3295. );
  3296. // Prevent the bezier going outside of the bounds of the graph
  3297. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  3298. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  3299. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  3300. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  3301. // Now pivot the point for animation
  3302. point.pivot();
  3303. });
  3304. },
  3305. setHoverStyle: function(point) {
  3306. // Point
  3307. var dataset = this.chart.data.datasets[point._datasetIndex];
  3308. var custom = point.custom || {};
  3309. var index = point._index;
  3310. var model = point._model;
  3311. point.$previousStyle = {
  3312. backgroundColor: model.backgroundColor,
  3313. borderColor: model.borderColor,
  3314. borderWidth: model.borderWidth,
  3315. radius: model.radius
  3316. };
  3317. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3318. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3319. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3320. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3321. },
  3322. });
  3323. };
  3324. },{"26":26,"41":41,"46":46}],21:[function(require,module,exports){
  3325. 'use strict';
  3326. var defaults = require(26);
  3327. defaults._set('scatter', {
  3328. hover: {
  3329. mode: 'single'
  3330. },
  3331. scales: {
  3332. xAxes: [{
  3333. id: 'x-axis-1', // need an ID so datasets can reference the scale
  3334. type: 'linear', // scatter should not use a category axis
  3335. position: 'bottom'
  3336. }],
  3337. yAxes: [{
  3338. id: 'y-axis-1',
  3339. type: 'linear',
  3340. position: 'left'
  3341. }]
  3342. },
  3343. showLines: false,
  3344. tooltips: {
  3345. callbacks: {
  3346. title: function() {
  3347. return ''; // doesn't make sense for scatter since data are formatted as a point
  3348. },
  3349. label: function(item) {
  3350. return '(' + item.xLabel + ', ' + item.yLabel + ')';
  3351. }
  3352. }
  3353. }
  3354. });
  3355. module.exports = function(Chart) {
  3356. // Scatter charts use line controllers
  3357. Chart.controllers.scatter = Chart.controllers.line;
  3358. };
  3359. },{"26":26}],22:[function(require,module,exports){
  3360. 'use strict';
  3361. var Element = require(27);
  3362. var exports = module.exports = Element.extend({
  3363. chart: null, // the animation associated chart instance
  3364. currentStep: 0, // the current animation step
  3365. numSteps: 60, // default number of steps
  3366. easing: '', // the easing to use for this animation
  3367. render: null, // render function used by the animation service
  3368. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3369. onAnimationComplete: null, // user specified callback to fire when the animation finishes
  3370. });
  3371. // DEPRECATIONS
  3372. /**
  3373. * Provided for backward compatibility, use Chart.Animation instead
  3374. * @prop Chart.Animation#animationObject
  3375. * @deprecated since version 2.6.0
  3376. * @todo remove at version 3
  3377. */
  3378. Object.defineProperty(exports.prototype, 'animationObject', {
  3379. get: function() {
  3380. return this;
  3381. }
  3382. });
  3383. /**
  3384. * Provided for backward compatibility, use Chart.Animation#chart instead
  3385. * @prop Chart.Animation#chartInstance
  3386. * @deprecated since version 2.6.0
  3387. * @todo remove at version 3
  3388. */
  3389. Object.defineProperty(exports.prototype, 'chartInstance', {
  3390. get: function() {
  3391. return this.chart;
  3392. },
  3393. set: function(value) {
  3394. this.chart = value;
  3395. }
  3396. });
  3397. },{"27":27}],23:[function(require,module,exports){
  3398. /* global window: false */
  3399. 'use strict';
  3400. var defaults = require(26);
  3401. var helpers = require(46);
  3402. defaults._set('global', {
  3403. animation: {
  3404. duration: 1000,
  3405. easing: 'easeOutQuart',
  3406. onProgress: helpers.noop,
  3407. onComplete: helpers.noop
  3408. }
  3409. });
  3410. module.exports = {
  3411. frameDuration: 17,
  3412. animations: [],
  3413. dropFrames: 0,
  3414. request: null,
  3415. /**
  3416. * @param {Chart} chart - The chart to animate.
  3417. * @param {Chart.Animation} animation - The animation that we will animate.
  3418. * @param {Number} duration - The animation duration in ms.
  3419. * @param {Boolean} lazy - if true, the chart is not marked as animating to enable more responsive interactions
  3420. */
  3421. addAnimation: function(chart, animation, duration, lazy) {
  3422. var animations = this.animations;
  3423. var i, ilen;
  3424. animation.chart = chart;
  3425. if (!lazy) {
  3426. chart.animating = true;
  3427. }
  3428. for (i = 0, ilen = animations.length; i < ilen; ++i) {
  3429. if (animations[i].chart === chart) {
  3430. animations[i] = animation;
  3431. return;
  3432. }
  3433. }
  3434. animations.push(animation);
  3435. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3436. if (animations.length === 1) {
  3437. this.requestAnimationFrame();
  3438. }
  3439. },
  3440. cancelAnimation: function(chart) {
  3441. var index = helpers.findIndex(this.animations, function(animation) {
  3442. return animation.chart === chart;
  3443. });
  3444. if (index !== -1) {
  3445. this.animations.splice(index, 1);
  3446. chart.animating = false;
  3447. }
  3448. },
  3449. requestAnimationFrame: function() {
  3450. var me = this;
  3451. if (me.request === null) {
  3452. // Skip animation frame requests until the active one is executed.
  3453. // This can happen when processing mouse events, e.g. 'mousemove'
  3454. // and 'mouseout' events will trigger multiple renders.
  3455. me.request = helpers.requestAnimFrame.call(window, function() {
  3456. me.request = null;
  3457. me.startDigest();
  3458. });
  3459. }
  3460. },
  3461. /**
  3462. * @private
  3463. */
  3464. startDigest: function() {
  3465. var me = this;
  3466. var startTime = Date.now();
  3467. var framesToDrop = 0;
  3468. if (me.dropFrames > 1) {
  3469. framesToDrop = Math.floor(me.dropFrames);
  3470. me.dropFrames = me.dropFrames % 1;
  3471. }
  3472. me.advance(1 + framesToDrop);
  3473. var endTime = Date.now();
  3474. me.dropFrames += (endTime - startTime) / me.frameDuration;
  3475. // Do we have more stuff to animate?
  3476. if (me.animations.length > 0) {
  3477. me.requestAnimationFrame();
  3478. }
  3479. },
  3480. /**
  3481. * @private
  3482. */
  3483. advance: function(count) {
  3484. var animations = this.animations;
  3485. var animation, chart;
  3486. var i = 0;
  3487. while (i < animations.length) {
  3488. animation = animations[i];
  3489. chart = animation.chart;
  3490. animation.currentStep = (animation.currentStep || 0) + count;
  3491. animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
  3492. helpers.callback(animation.render, [chart, animation], chart);
  3493. helpers.callback(animation.onAnimationProgress, [animation], chart);
  3494. if (animation.currentStep >= animation.numSteps) {
  3495. helpers.callback(animation.onAnimationComplete, [animation], chart);
  3496. chart.animating = false;
  3497. animations.splice(i, 1);
  3498. } else {
  3499. ++i;
  3500. }
  3501. }
  3502. }
  3503. };
  3504. },{"26":26,"46":46}],24:[function(require,module,exports){
  3505. 'use strict';
  3506. var Animation = require(22);
  3507. var animations = require(23);
  3508. var defaults = require(26);
  3509. var helpers = require(46);
  3510. var Interaction = require(29);
  3511. var layouts = require(31);
  3512. var platform = require(49);
  3513. var plugins = require(32);
  3514. var scaleService = require(34);
  3515. var Tooltip = require(36);
  3516. module.exports = function(Chart) {
  3517. // Create a dictionary of chart types, to allow for extension of existing types
  3518. Chart.types = {};
  3519. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3520. // Destroy method on the chart will remove the instance of the chart from this reference.
  3521. Chart.instances = {};
  3522. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3523. Chart.controllers = {};
  3524. /**
  3525. * Initializes the given config with global and chart default values.
  3526. */
  3527. function initConfig(config) {
  3528. config = config || {};
  3529. // Do NOT use configMerge() for the data object because this method merges arrays
  3530. // and so would change references to labels and datasets, preventing data updates.
  3531. var data = config.data = config.data || {};
  3532. data.datasets = data.datasets || [];
  3533. data.labels = data.labels || [];
  3534. config.options = helpers.configMerge(
  3535. defaults.global,
  3536. defaults[config.type],
  3537. config.options || {});
  3538. return config;
  3539. }
  3540. /**
  3541. * Updates the config of the chart
  3542. * @param chart {Chart} chart to update the options for
  3543. */
  3544. function updateConfig(chart) {
  3545. var newOptions = chart.options;
  3546. helpers.each(chart.scales, function(scale) {
  3547. layouts.removeBox(chart, scale);
  3548. });
  3549. newOptions = helpers.configMerge(
  3550. Chart.defaults.global,
  3551. Chart.defaults[chart.config.type],
  3552. newOptions);
  3553. chart.options = chart.config.options = newOptions;
  3554. chart.ensureScalesHaveIDs();
  3555. chart.buildOrUpdateScales();
  3556. // Tooltip
  3557. chart.tooltip._options = newOptions.tooltips;
  3558. chart.tooltip.initialize();
  3559. }
  3560. function positionIsHorizontal(position) {
  3561. return position === 'top' || position === 'bottom';
  3562. }
  3563. helpers.extend(Chart.prototype, /** @lends Chart */ {
  3564. /**
  3565. * @private
  3566. */
  3567. construct: function(item, config) {
  3568. var me = this;
  3569. config = initConfig(config);
  3570. var context = platform.acquireContext(item, config);
  3571. var canvas = context && context.canvas;
  3572. var height = canvas && canvas.height;
  3573. var width = canvas && canvas.width;
  3574. me.id = helpers.uid();
  3575. me.ctx = context;
  3576. me.canvas = canvas;
  3577. me.config = config;
  3578. me.width = width;
  3579. me.height = height;
  3580. me.aspectRatio = height ? width / height : null;
  3581. me.options = config.options;
  3582. me._bufferedRender = false;
  3583. /**
  3584. * Provided for backward compatibility, Chart and Chart.Controller have been merged,
  3585. * the "instance" still need to be defined since it might be called from plugins.
  3586. * @prop Chart#chart
  3587. * @deprecated since version 2.6.0
  3588. * @todo remove at version 3
  3589. * @private
  3590. */
  3591. me.chart = me;
  3592. me.controller = me; // chart.chart.controller #inception
  3593. // Add the chart instance to the global namespace
  3594. Chart.instances[me.id] = me;
  3595. // Define alias to the config data: `chart.data === chart.config.data`
  3596. Object.defineProperty(me, 'data', {
  3597. get: function() {
  3598. return me.config.data;
  3599. },
  3600. set: function(value) {
  3601. me.config.data = value;
  3602. }
  3603. });
  3604. if (!context || !canvas) {
  3605. // The given item is not a compatible context2d element, let's return before finalizing
  3606. // the chart initialization but after setting basic chart / controller properties that
  3607. // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
  3608. // https://github.com/chartjs/Chart.js/issues/2807
  3609. console.error("Failed to create chart: can't acquire context from the given item");
  3610. return;
  3611. }
  3612. me.initialize();
  3613. me.update();
  3614. },
  3615. /**
  3616. * @private
  3617. */
  3618. initialize: function() {
  3619. var me = this;
  3620. // Before init plugin notification
  3621. plugins.notify(me, 'beforeInit');
  3622. helpers.retinaScale(me, me.options.devicePixelRatio);
  3623. me.bindEvents();
  3624. if (me.options.responsive) {
  3625. // Initial resize before chart draws (must be silent to preserve initial animations).
  3626. me.resize(true);
  3627. }
  3628. // Make sure scales have IDs and are built before we build any controllers.
  3629. me.ensureScalesHaveIDs();
  3630. me.buildOrUpdateScales();
  3631. me.initToolTip();
  3632. // After init plugin notification
  3633. plugins.notify(me, 'afterInit');
  3634. return me;
  3635. },
  3636. clear: function() {
  3637. helpers.canvas.clear(this);
  3638. return this;
  3639. },
  3640. stop: function() {
  3641. // Stops any current animation loop occurring
  3642. animations.cancelAnimation(this);
  3643. return this;
  3644. },
  3645. resize: function(silent) {
  3646. var me = this;
  3647. var options = me.options;
  3648. var canvas = me.canvas;
  3649. var aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
  3650. // the canvas render width and height will be casted to integers so make sure that
  3651. // the canvas display style uses the same integer values to avoid blurring effect.
  3652. // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
  3653. var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
  3654. var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
  3655. if (me.width === newWidth && me.height === newHeight) {
  3656. return;
  3657. }
  3658. canvas.width = me.width = newWidth;
  3659. canvas.height = me.height = newHeight;
  3660. canvas.style.width = newWidth + 'px';
  3661. canvas.style.height = newHeight + 'px';
  3662. helpers.retinaScale(me, options.devicePixelRatio);
  3663. if (!silent) {
  3664. // Notify any plugins about the resize
  3665. var newSize = {width: newWidth, height: newHeight};
  3666. plugins.notify(me, 'resize', [newSize]);
  3667. // Notify of resize
  3668. if (me.options.onResize) {
  3669. me.options.onResize(me, newSize);
  3670. }
  3671. me.stop();
  3672. me.update({
  3673. duration: me.options.responsiveAnimationDuration
  3674. });
  3675. }
  3676. },
  3677. ensureScalesHaveIDs: function() {
  3678. var options = this.options;
  3679. var scalesOptions = options.scales || {};
  3680. var scaleOptions = options.scale;
  3681. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  3682. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3683. });
  3684. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  3685. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3686. });
  3687. if (scaleOptions) {
  3688. scaleOptions.id = scaleOptions.id || 'scale';
  3689. }
  3690. },
  3691. /**
  3692. * Builds a map of scale ID to scale object for future lookup.
  3693. */
  3694. buildOrUpdateScales: function() {
  3695. var me = this;
  3696. var options = me.options;
  3697. var scales = me.scales || {};
  3698. var items = [];
  3699. var updated = Object.keys(scales).reduce(function(obj, id) {
  3700. obj[id] = false;
  3701. return obj;
  3702. }, {});
  3703. if (options.scales) {
  3704. items = items.concat(
  3705. (options.scales.xAxes || []).map(function(xAxisOptions) {
  3706. return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
  3707. }),
  3708. (options.scales.yAxes || []).map(function(yAxisOptions) {
  3709. return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
  3710. })
  3711. );
  3712. }
  3713. if (options.scale) {
  3714. items.push({
  3715. options: options.scale,
  3716. dtype: 'radialLinear',
  3717. isDefault: true,
  3718. dposition: 'chartArea'
  3719. });
  3720. }
  3721. helpers.each(items, function(item) {
  3722. var scaleOptions = item.options;
  3723. var id = scaleOptions.id;
  3724. var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
  3725. if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
  3726. scaleOptions.position = item.dposition;
  3727. }
  3728. updated[id] = true;
  3729. var scale = null;
  3730. if (id in scales && scales[id].type === scaleType) {
  3731. scale = scales[id];
  3732. scale.options = scaleOptions;
  3733. scale.ctx = me.ctx;
  3734. scale.chart = me;
  3735. } else {
  3736. var scaleClass = scaleService.getScaleConstructor(scaleType);
  3737. if (!scaleClass) {
  3738. return;
  3739. }
  3740. scale = new scaleClass({
  3741. id: id,
  3742. type: scaleType,
  3743. options: scaleOptions,
  3744. ctx: me.ctx,
  3745. chart: me
  3746. });
  3747. scales[scale.id] = scale;
  3748. }
  3749. scale.mergeTicksOptions();
  3750. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3751. // and consider it as a regular scale part of the "scales"" map only! This would
  3752. // make the logic easier and remove some useless? custom code.
  3753. if (item.isDefault) {
  3754. me.scale = scale;
  3755. }
  3756. });
  3757. // clear up discarded scales
  3758. helpers.each(updated, function(hasUpdated, id) {
  3759. if (!hasUpdated) {
  3760. delete scales[id];
  3761. }
  3762. });
  3763. me.scales = scales;
  3764. scaleService.addScalesToLayout(this);
  3765. },
  3766. buildOrUpdateControllers: function() {
  3767. var me = this;
  3768. var types = [];
  3769. var newControllers = [];
  3770. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3771. var meta = me.getDatasetMeta(datasetIndex);
  3772. var type = dataset.type || me.config.type;
  3773. if (meta.type && meta.type !== type) {
  3774. me.destroyDatasetMeta(datasetIndex);
  3775. meta = me.getDatasetMeta(datasetIndex);
  3776. }
  3777. meta.type = type;
  3778. types.push(meta.type);
  3779. if (meta.controller) {
  3780. meta.controller.updateIndex(datasetIndex);
  3781. meta.controller.linkScales();
  3782. } else {
  3783. var ControllerClass = Chart.controllers[meta.type];
  3784. if (ControllerClass === undefined) {
  3785. throw new Error('"' + meta.type + '" is not a chart type.');
  3786. }
  3787. meta.controller = new ControllerClass(me, datasetIndex);
  3788. newControllers.push(meta.controller);
  3789. }
  3790. }, me);
  3791. return newControllers;
  3792. },
  3793. /**
  3794. * Reset the elements of all datasets
  3795. * @private
  3796. */
  3797. resetElements: function() {
  3798. var me = this;
  3799. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3800. me.getDatasetMeta(datasetIndex).controller.reset();
  3801. }, me);
  3802. },
  3803. /**
  3804. * Resets the chart back to it's state before the initial animation
  3805. */
  3806. reset: function() {
  3807. this.resetElements();
  3808. this.tooltip.initialize();
  3809. },
  3810. update: function(config) {
  3811. var me = this;
  3812. if (!config || typeof config !== 'object') {
  3813. // backwards compatibility
  3814. config = {
  3815. duration: config,
  3816. lazy: arguments[1]
  3817. };
  3818. }
  3819. updateConfig(me);
  3820. // plugins options references might have change, let's invalidate the cache
  3821. // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  3822. plugins._invalidate(me);
  3823. if (plugins.notify(me, 'beforeUpdate') === false) {
  3824. return;
  3825. }
  3826. // In case the entire data object changed
  3827. me.tooltip._data = me.data;
  3828. // Make sure dataset controllers are updated and new controllers are reset
  3829. var newControllers = me.buildOrUpdateControllers();
  3830. // Make sure all dataset controllers have correct meta data counts
  3831. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3832. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3833. }, me);
  3834. me.updateLayout();
  3835. // Can only reset the new controllers after the scales have been updated
  3836. if (me.options.animation && me.options.animation.duration) {
  3837. helpers.each(newControllers, function(controller) {
  3838. controller.reset();
  3839. });
  3840. }
  3841. me.updateDatasets();
  3842. // Need to reset tooltip in case it is displayed with elements that are removed
  3843. // after update.
  3844. me.tooltip.initialize();
  3845. // Last active contains items that were previously in the tooltip.
  3846. // When we reset the tooltip, we need to clear it
  3847. me.lastActive = [];
  3848. // Do this before render so that any plugins that need final scale updates can use it
  3849. plugins.notify(me, 'afterUpdate');
  3850. if (me._bufferedRender) {
  3851. me._bufferedRequest = {
  3852. duration: config.duration,
  3853. easing: config.easing,
  3854. lazy: config.lazy
  3855. };
  3856. } else {
  3857. me.render(config);
  3858. }
  3859. },
  3860. /**
  3861. * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
  3862. * hook, in which case, plugins will not be called on `afterLayout`.
  3863. * @private
  3864. */
  3865. updateLayout: function() {
  3866. var me = this;
  3867. if (plugins.notify(me, 'beforeLayout') === false) {
  3868. return;
  3869. }
  3870. layouts.update(this, this.width, this.height);
  3871. /**
  3872. * Provided for backward compatibility, use `afterLayout` instead.
  3873. * @method IPlugin#afterScaleUpdate
  3874. * @deprecated since version 2.5.0
  3875. * @todo remove at version 3
  3876. * @private
  3877. */
  3878. plugins.notify(me, 'afterScaleUpdate');
  3879. plugins.notify(me, 'afterLayout');
  3880. },
  3881. /**
  3882. * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
  3883. * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
  3884. * @private
  3885. */
  3886. updateDatasets: function() {
  3887. var me = this;
  3888. if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
  3889. return;
  3890. }
  3891. for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3892. me.updateDataset(i);
  3893. }
  3894. plugins.notify(me, 'afterDatasetsUpdate');
  3895. },
  3896. /**
  3897. * Updates dataset at index unless a plugin returns `false` to the `beforeDatasetUpdate`
  3898. * hook, in which case, plugins will not be called on `afterDatasetUpdate`.
  3899. * @private
  3900. */
  3901. updateDataset: function(index) {
  3902. var me = this;
  3903. var meta = me.getDatasetMeta(index);
  3904. var args = {
  3905. meta: meta,
  3906. index: index
  3907. };
  3908. if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
  3909. return;
  3910. }
  3911. meta.controller.update();
  3912. plugins.notify(me, 'afterDatasetUpdate', [args]);
  3913. },
  3914. render: function(config) {
  3915. var me = this;
  3916. if (!config || typeof config !== 'object') {
  3917. // backwards compatibility
  3918. config = {
  3919. duration: config,
  3920. lazy: arguments[1]
  3921. };
  3922. }
  3923. var duration = config.duration;
  3924. var lazy = config.lazy;
  3925. if (plugins.notify(me, 'beforeRender') === false) {
  3926. return;
  3927. }
  3928. var animationOptions = me.options.animation;
  3929. var onComplete = function(animation) {
  3930. plugins.notify(me, 'afterRender');
  3931. helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
  3932. };
  3933. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3934. var animation = new Animation({
  3935. numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
  3936. easing: config.easing || animationOptions.easing,
  3937. render: function(chart, animationObject) {
  3938. var easingFunction = helpers.easing.effects[animationObject.easing];
  3939. var currentStep = animationObject.currentStep;
  3940. var stepDecimal = currentStep / animationObject.numSteps;
  3941. chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep);
  3942. },
  3943. onAnimationProgress: animationOptions.onProgress,
  3944. onAnimationComplete: onComplete
  3945. });
  3946. animations.addAnimation(me, animation, duration, lazy);
  3947. } else {
  3948. me.draw();
  3949. // See https://github.com/chartjs/Chart.js/issues/3781
  3950. onComplete(new Animation({numSteps: 0, chart: me}));
  3951. }
  3952. return me;
  3953. },
  3954. draw: function(easingValue) {
  3955. var me = this;
  3956. me.clear();
  3957. if (helpers.isNullOrUndef(easingValue)) {
  3958. easingValue = 1;
  3959. }
  3960. me.transition(easingValue);
  3961. if (me.width <= 0 || me.height <= 0) {
  3962. return;
  3963. }
  3964. if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
  3965. return;
  3966. }
  3967. // Draw all the scales
  3968. helpers.each(me.boxes, function(box) {
  3969. box.draw(me.chartArea);
  3970. }, me);
  3971. if (me.scale) {
  3972. me.scale.draw();
  3973. }
  3974. me.drawDatasets(easingValue);
  3975. me._drawTooltip(easingValue);
  3976. plugins.notify(me, 'afterDraw', [easingValue]);
  3977. },
  3978. /**
  3979. * @private
  3980. */
  3981. transition: function(easingValue) {
  3982. var me = this;
  3983. for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
  3984. if (me.isDatasetVisible(i)) {
  3985. me.getDatasetMeta(i).controller.transition(easingValue);
  3986. }
  3987. }
  3988. me.tooltip.transition(easingValue);
  3989. },
  3990. /**
  3991. * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
  3992. * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
  3993. * @private
  3994. */
  3995. drawDatasets: function(easingValue) {
  3996. var me = this;
  3997. if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
  3998. return;
  3999. }
  4000. // Draw datasets reversed to support proper line stacking
  4001. for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
  4002. if (me.isDatasetVisible(i)) {
  4003. me.drawDataset(i, easingValue);
  4004. }
  4005. }
  4006. plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
  4007. },
  4008. /**
  4009. * Draws dataset at index unless a plugin returns `false` to the `beforeDatasetDraw`
  4010. * hook, in which case, plugins will not be called on `afterDatasetDraw`.
  4011. * @private
  4012. */
  4013. drawDataset: function(index, easingValue) {
  4014. var me = this;
  4015. var meta = me.getDatasetMeta(index);
  4016. var args = {
  4017. meta: meta,
  4018. index: index,
  4019. easingValue: easingValue
  4020. };
  4021. if (plugins.notify(me, 'beforeDatasetDraw', [args]) === false) {
  4022. return;
  4023. }
  4024. meta.controller.draw(easingValue);
  4025. plugins.notify(me, 'afterDatasetDraw', [args]);
  4026. },
  4027. /**
  4028. * Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
  4029. * hook, in which case, plugins will not be called on `afterTooltipDraw`.
  4030. * @private
  4031. */
  4032. _drawTooltip: function(easingValue) {
  4033. var me = this;
  4034. var tooltip = me.tooltip;
  4035. var args = {
  4036. tooltip: tooltip,
  4037. easingValue: easingValue
  4038. };
  4039. if (plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
  4040. return;
  4041. }
  4042. tooltip.draw();
  4043. plugins.notify(me, 'afterTooltipDraw', [args]);
  4044. },
  4045. // Get the single element that was clicked on
  4046. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  4047. getElementAtEvent: function(e) {
  4048. return Interaction.modes.single(this, e);
  4049. },
  4050. getElementsAtEvent: function(e) {
  4051. return Interaction.modes.label(this, e, {intersect: true});
  4052. },
  4053. getElementsAtXAxis: function(e) {
  4054. return Interaction.modes['x-axis'](this, e, {intersect: true});
  4055. },
  4056. getElementsAtEventForMode: function(e, mode, options) {
  4057. var method = Interaction.modes[mode];
  4058. if (typeof method === 'function') {
  4059. return method(this, e, options);
  4060. }
  4061. return [];
  4062. },
  4063. getDatasetAtEvent: function(e) {
  4064. return Interaction.modes.dataset(this, e, {intersect: true});
  4065. },
  4066. getDatasetMeta: function(datasetIndex) {
  4067. var me = this;
  4068. var dataset = me.data.datasets[datasetIndex];
  4069. if (!dataset._meta) {
  4070. dataset._meta = {};
  4071. }
  4072. var meta = dataset._meta[me.id];
  4073. if (!meta) {
  4074. meta = dataset._meta[me.id] = {
  4075. type: null,
  4076. data: [],
  4077. dataset: null,
  4078. controller: null,
  4079. hidden: null, // See isDatasetVisible() comment
  4080. xAxisID: null,
  4081. yAxisID: null
  4082. };
  4083. }
  4084. return meta;
  4085. },
  4086. getVisibleDatasetCount: function() {
  4087. var count = 0;
  4088. for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
  4089. if (this.isDatasetVisible(i)) {
  4090. count++;
  4091. }
  4092. }
  4093. return count;
  4094. },
  4095. isDatasetVisible: function(datasetIndex) {
  4096. var meta = this.getDatasetMeta(datasetIndex);
  4097. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  4098. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  4099. return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  4100. },
  4101. generateLegend: function() {
  4102. return this.options.legendCallback(this);
  4103. },
  4104. /**
  4105. * @private
  4106. */
  4107. destroyDatasetMeta: function(datasetIndex) {
  4108. var id = this.id;
  4109. var dataset = this.data.datasets[datasetIndex];
  4110. var meta = dataset._meta && dataset._meta[id];
  4111. if (meta) {
  4112. meta.controller.destroy();
  4113. delete dataset._meta[id];
  4114. }
  4115. },
  4116. destroy: function() {
  4117. var me = this;
  4118. var canvas = me.canvas;
  4119. var i, ilen;
  4120. me.stop();
  4121. // dataset controllers need to cleanup associated data
  4122. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  4123. me.destroyDatasetMeta(i);
  4124. }
  4125. if (canvas) {
  4126. me.unbindEvents();
  4127. helpers.canvas.clear(me);
  4128. platform.releaseContext(me.ctx);
  4129. me.canvas = null;
  4130. me.ctx = null;
  4131. }
  4132. plugins.notify(me, 'destroy');
  4133. delete Chart.instances[me.id];
  4134. },
  4135. toBase64Image: function() {
  4136. return this.canvas.toDataURL.apply(this.canvas, arguments);
  4137. },
  4138. initToolTip: function() {
  4139. var me = this;
  4140. me.tooltip = new Tooltip({
  4141. _chart: me,
  4142. _chartInstance: me, // deprecated, backward compatibility
  4143. _data: me.data,
  4144. _options: me.options.tooltips
  4145. }, me);
  4146. },
  4147. /**
  4148. * @private
  4149. */
  4150. bindEvents: function() {
  4151. var me = this;
  4152. var listeners = me._listeners = {};
  4153. var listener = function() {
  4154. me.eventHandler.apply(me, arguments);
  4155. };
  4156. helpers.each(me.options.events, function(type) {
  4157. platform.addEventListener(me, type, listener);
  4158. listeners[type] = listener;
  4159. });
  4160. // Elements used to detect size change should not be injected for non responsive charts.
  4161. // See https://github.com/chartjs/Chart.js/issues/2210
  4162. if (me.options.responsive) {
  4163. listener = function() {
  4164. me.resize();
  4165. };
  4166. platform.addEventListener(me, 'resize', listener);
  4167. listeners.resize = listener;
  4168. }
  4169. },
  4170. /**
  4171. * @private
  4172. */
  4173. unbindEvents: function() {
  4174. var me = this;
  4175. var listeners = me._listeners;
  4176. if (!listeners) {
  4177. return;
  4178. }
  4179. delete me._listeners;
  4180. helpers.each(listeners, function(listener, type) {
  4181. platform.removeEventListener(me, type, listener);
  4182. });
  4183. },
  4184. updateHoverStyle: function(elements, mode, enabled) {
  4185. var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
  4186. var element, i, ilen;
  4187. for (i = 0, ilen = elements.length; i < ilen; ++i) {
  4188. element = elements[i];
  4189. if (element) {
  4190. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  4191. }
  4192. }
  4193. },
  4194. /**
  4195. * @private
  4196. */
  4197. eventHandler: function(e) {
  4198. var me = this;
  4199. var tooltip = me.tooltip;
  4200. if (plugins.notify(me, 'beforeEvent', [e]) === false) {
  4201. return;
  4202. }
  4203. // Buffer any update calls so that renders do not occur
  4204. me._bufferedRender = true;
  4205. me._bufferedRequest = null;
  4206. var changed = me.handleEvent(e);
  4207. // for smooth tooltip animations issue #4989
  4208. // the tooltip should be the source of change
  4209. // Animation check workaround:
  4210. // tooltip._start will be null when tooltip isn't animating
  4211. if (tooltip) {
  4212. changed = tooltip._start
  4213. ? tooltip.handleEvent(e)
  4214. : changed | tooltip.handleEvent(e);
  4215. }
  4216. plugins.notify(me, 'afterEvent', [e]);
  4217. var bufferedRequest = me._bufferedRequest;
  4218. if (bufferedRequest) {
  4219. // If we have an update that was triggered, we need to do a normal render
  4220. me.render(bufferedRequest);
  4221. } else if (changed && !me.animating) {
  4222. // If entering, leaving, or changing elements, animate the change via pivot
  4223. me.stop();
  4224. // We only need to render at this point. Updating will cause scales to be
  4225. // recomputed generating flicker & using more memory than necessary.
  4226. me.render({
  4227. duration: me.options.hover.animationDuration,
  4228. lazy: true
  4229. });
  4230. }
  4231. me._bufferedRender = false;
  4232. me._bufferedRequest = null;
  4233. return me;
  4234. },
  4235. /**
  4236. * Handle an event
  4237. * @private
  4238. * @param {IEvent} event the event to handle
  4239. * @return {Boolean} true if the chart needs to re-render
  4240. */
  4241. handleEvent: function(e) {
  4242. var me = this;
  4243. var options = me.options || {};
  4244. var hoverOptions = options.hover;
  4245. var changed = false;
  4246. me.lastActive = me.lastActive || [];
  4247. // Find Active Elements for hover and tooltips
  4248. if (e.type === 'mouseout') {
  4249. me.active = [];
  4250. } else {
  4251. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
  4252. }
  4253. // Invoke onHover hook
  4254. // Need to call with native event here to not break backwards compatibility
  4255. helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
  4256. if (e.type === 'mouseup' || e.type === 'click') {
  4257. if (options.onClick) {
  4258. // Use e.native here for backwards compatibility
  4259. options.onClick.call(me, e.native, me.active);
  4260. }
  4261. }
  4262. // Remove styling for last active (even if it may still be active)
  4263. if (me.lastActive.length) {
  4264. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  4265. }
  4266. // Built in hover styling
  4267. if (me.active.length && hoverOptions.mode) {
  4268. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  4269. }
  4270. changed = !helpers.arrayEquals(me.active, me.lastActive);
  4271. // Remember Last Actives
  4272. me.lastActive = me.active;
  4273. return changed;
  4274. }
  4275. });
  4276. /**
  4277. * Provided for backward compatibility, use Chart instead.
  4278. * @class Chart.Controller
  4279. * @deprecated since version 2.6.0
  4280. * @todo remove at version 3
  4281. * @private
  4282. */
  4283. Chart.Controller = Chart;
  4284. };
  4285. },{"22":22,"23":23,"26":26,"29":29,"31":31,"32":32,"34":34,"36":36,"46":46,"49":49}],25:[function(require,module,exports){
  4286. 'use strict';
  4287. var helpers = require(46);
  4288. module.exports = function(Chart) {
  4289. var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  4290. /**
  4291. * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
  4292. * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
  4293. * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
  4294. */
  4295. function listenArrayEvents(array, listener) {
  4296. if (array._chartjs) {
  4297. array._chartjs.listeners.push(listener);
  4298. return;
  4299. }
  4300. Object.defineProperty(array, '_chartjs', {
  4301. configurable: true,
  4302. enumerable: false,
  4303. value: {
  4304. listeners: [listener]
  4305. }
  4306. });
  4307. arrayEvents.forEach(function(key) {
  4308. var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
  4309. var base = array[key];
  4310. Object.defineProperty(array, key, {
  4311. configurable: true,
  4312. enumerable: false,
  4313. value: function() {
  4314. var args = Array.prototype.slice.call(arguments);
  4315. var res = base.apply(this, args);
  4316. helpers.each(array._chartjs.listeners, function(object) {
  4317. if (typeof object[method] === 'function') {
  4318. object[method].apply(object, args);
  4319. }
  4320. });
  4321. return res;
  4322. }
  4323. });
  4324. });
  4325. }
  4326. /**
  4327. * Removes the given array event listener and cleanup extra attached properties (such as
  4328. * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
  4329. */
  4330. function unlistenArrayEvents(array, listener) {
  4331. var stub = array._chartjs;
  4332. if (!stub) {
  4333. return;
  4334. }
  4335. var listeners = stub.listeners;
  4336. var index = listeners.indexOf(listener);
  4337. if (index !== -1) {
  4338. listeners.splice(index, 1);
  4339. }
  4340. if (listeners.length > 0) {
  4341. return;
  4342. }
  4343. arrayEvents.forEach(function(key) {
  4344. delete array[key];
  4345. });
  4346. delete array._chartjs;
  4347. }
  4348. // Base class for all dataset controllers (line, bar, etc)
  4349. Chart.DatasetController = function(chart, datasetIndex) {
  4350. this.initialize(chart, datasetIndex);
  4351. };
  4352. helpers.extend(Chart.DatasetController.prototype, {
  4353. /**
  4354. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  4355. * @type {Chart.core.element}
  4356. */
  4357. datasetElementType: null,
  4358. /**
  4359. * Element type used to generate a meta data (e.g. Chart.element.Point).
  4360. * @type {Chart.core.element}
  4361. */
  4362. dataElementType: null,
  4363. initialize: function(chart, datasetIndex) {
  4364. var me = this;
  4365. me.chart = chart;
  4366. me.index = datasetIndex;
  4367. me.linkScales();
  4368. me.addElements();
  4369. },
  4370. updateIndex: function(datasetIndex) {
  4371. this.index = datasetIndex;
  4372. },
  4373. linkScales: function() {
  4374. var me = this;
  4375. var meta = me.getMeta();
  4376. var dataset = me.getDataset();
  4377. if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
  4378. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  4379. }
  4380. if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
  4381. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  4382. }
  4383. },
  4384. getDataset: function() {
  4385. return this.chart.data.datasets[this.index];
  4386. },
  4387. getMeta: function() {
  4388. return this.chart.getDatasetMeta(this.index);
  4389. },
  4390. getScaleForId: function(scaleID) {
  4391. return this.chart.scales[scaleID];
  4392. },
  4393. reset: function() {
  4394. this.update(true);
  4395. },
  4396. /**
  4397. * @private
  4398. */
  4399. destroy: function() {
  4400. if (this._data) {
  4401. unlistenArrayEvents(this._data, this);
  4402. }
  4403. },
  4404. createMetaDataset: function() {
  4405. var me = this;
  4406. var type = me.datasetElementType;
  4407. return type && new type({
  4408. _chart: me.chart,
  4409. _datasetIndex: me.index
  4410. });
  4411. },
  4412. createMetaData: function(index) {
  4413. var me = this;
  4414. var type = me.dataElementType;
  4415. return type && new type({
  4416. _chart: me.chart,
  4417. _datasetIndex: me.index,
  4418. _index: index
  4419. });
  4420. },
  4421. addElements: function() {
  4422. var me = this;
  4423. var meta = me.getMeta();
  4424. var data = me.getDataset().data || [];
  4425. var metaData = meta.data;
  4426. var i, ilen;
  4427. for (i = 0, ilen = data.length; i < ilen; ++i) {
  4428. metaData[i] = metaData[i] || me.createMetaData(i);
  4429. }
  4430. meta.dataset = meta.dataset || me.createMetaDataset();
  4431. },
  4432. addElementAndReset: function(index) {
  4433. var element = this.createMetaData(index);
  4434. this.getMeta().data.splice(index, 0, element);
  4435. this.updateElement(element, index, true);
  4436. },
  4437. buildOrUpdateElements: function() {
  4438. var me = this;
  4439. var dataset = me.getDataset();
  4440. var data = dataset.data || (dataset.data = []);
  4441. // In order to correctly handle data addition/deletion animation (an thus simulate
  4442. // real-time charts), we need to monitor these data modifications and synchronize
  4443. // the internal meta data accordingly.
  4444. if (me._data !== data) {
  4445. if (me._data) {
  4446. // This case happens when the user replaced the data array instance.
  4447. unlistenArrayEvents(me._data, me);
  4448. }
  4449. listenArrayEvents(data, me);
  4450. me._data = data;
  4451. }
  4452. // Re-sync meta data in case the user replaced the data array or if we missed
  4453. // any updates and so make sure that we handle number of datapoints changing.
  4454. me.resyncElements();
  4455. },
  4456. update: helpers.noop,
  4457. transition: function(easingValue) {
  4458. var meta = this.getMeta();
  4459. var elements = meta.data || [];
  4460. var ilen = elements.length;
  4461. var i = 0;
  4462. for (; i < ilen; ++i) {
  4463. elements[i].transition(easingValue);
  4464. }
  4465. if (meta.dataset) {
  4466. meta.dataset.transition(easingValue);
  4467. }
  4468. },
  4469. draw: function() {
  4470. var meta = this.getMeta();
  4471. var elements = meta.data || [];
  4472. var ilen = elements.length;
  4473. var i = 0;
  4474. if (meta.dataset) {
  4475. meta.dataset.draw();
  4476. }
  4477. for (; i < ilen; ++i) {
  4478. elements[i].draw();
  4479. }
  4480. },
  4481. removeHoverStyle: function(element) {
  4482. helpers.merge(element._model, element.$previousStyle || {});
  4483. delete element.$previousStyle;
  4484. },
  4485. setHoverStyle: function(element) {
  4486. var dataset = this.chart.data.datasets[element._datasetIndex];
  4487. var index = element._index;
  4488. var custom = element.custom || {};
  4489. var valueOrDefault = helpers.valueAtIndexOrDefault;
  4490. var getHoverColor = helpers.getHoverColor;
  4491. var model = element._model;
  4492. element.$previousStyle = {
  4493. backgroundColor: model.backgroundColor,
  4494. borderColor: model.borderColor,
  4495. borderWidth: model.borderWidth
  4496. };
  4497. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  4498. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  4499. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  4500. },
  4501. /**
  4502. * @private
  4503. */
  4504. resyncElements: function() {
  4505. var me = this;
  4506. var meta = me.getMeta();
  4507. var data = me.getDataset().data;
  4508. var numMeta = meta.data.length;
  4509. var numData = data.length;
  4510. if (numData < numMeta) {
  4511. meta.data.splice(numData, numMeta - numData);
  4512. } else if (numData > numMeta) {
  4513. me.insertElements(numMeta, numData - numMeta);
  4514. }
  4515. },
  4516. /**
  4517. * @private
  4518. */
  4519. insertElements: function(start, count) {
  4520. for (var i = 0; i < count; ++i) {
  4521. this.addElementAndReset(start + i);
  4522. }
  4523. },
  4524. /**
  4525. * @private
  4526. */
  4527. onDataPush: function() {
  4528. this.insertElements(this.getDataset().data.length - 1, arguments.length);
  4529. },
  4530. /**
  4531. * @private
  4532. */
  4533. onDataPop: function() {
  4534. this.getMeta().data.pop();
  4535. },
  4536. /**
  4537. * @private
  4538. */
  4539. onDataShift: function() {
  4540. this.getMeta().data.shift();
  4541. },
  4542. /**
  4543. * @private
  4544. */
  4545. onDataSplice: function(start, count) {
  4546. this.getMeta().data.splice(start, count);
  4547. this.insertElements(start, arguments.length - 2);
  4548. },
  4549. /**
  4550. * @private
  4551. */
  4552. onDataUnshift: function() {
  4553. this.insertElements(0, arguments.length);
  4554. }
  4555. });
  4556. Chart.DatasetController.extend = helpers.inherits;
  4557. };
  4558. },{"46":46}],26:[function(require,module,exports){
  4559. 'use strict';
  4560. var helpers = require(46);
  4561. module.exports = {
  4562. /**
  4563. * @private
  4564. */
  4565. _set: function(scope, values) {
  4566. return helpers.merge(this[scope] || (this[scope] = {}), values);
  4567. }
  4568. };
  4569. },{"46":46}],27:[function(require,module,exports){
  4570. 'use strict';
  4571. var color = require(3);
  4572. var helpers = require(46);
  4573. function interpolate(start, view, model, ease) {
  4574. var keys = Object.keys(model);
  4575. var i, ilen, key, actual, origin, target, type, c0, c1;
  4576. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  4577. key = keys[i];
  4578. target = model[key];
  4579. // if a value is added to the model after pivot() has been called, the view
  4580. // doesn't contain it, so let's initialize the view to the target value.
  4581. if (!view.hasOwnProperty(key)) {
  4582. view[key] = target;
  4583. }
  4584. actual = view[key];
  4585. if (actual === target || key[0] === '_') {
  4586. continue;
  4587. }
  4588. if (!start.hasOwnProperty(key)) {
  4589. start[key] = actual;
  4590. }
  4591. origin = start[key];
  4592. type = typeof target;
  4593. if (type === typeof origin) {
  4594. if (type === 'string') {
  4595. c0 = color(origin);
  4596. if (c0.valid) {
  4597. c1 = color(target);
  4598. if (c1.valid) {
  4599. view[key] = c1.mix(c0, ease).rgbString();
  4600. continue;
  4601. }
  4602. }
  4603. } else if (type === 'number' && isFinite(origin) && isFinite(target)) {
  4604. view[key] = origin + (target - origin) * ease;
  4605. continue;
  4606. }
  4607. }
  4608. view[key] = target;
  4609. }
  4610. }
  4611. var Element = function(configuration) {
  4612. helpers.extend(this, configuration);
  4613. this.initialize.apply(this, arguments);
  4614. };
  4615. helpers.extend(Element.prototype, {
  4616. initialize: function() {
  4617. this.hidden = false;
  4618. },
  4619. pivot: function() {
  4620. var me = this;
  4621. if (!me._view) {
  4622. me._view = helpers.clone(me._model);
  4623. }
  4624. me._start = {};
  4625. return me;
  4626. },
  4627. transition: function(ease) {
  4628. var me = this;
  4629. var model = me._model;
  4630. var start = me._start;
  4631. var view = me._view;
  4632. // No animation -> No Transition
  4633. if (!model || ease === 1) {
  4634. me._view = model;
  4635. me._start = null;
  4636. return me;
  4637. }
  4638. if (!view) {
  4639. view = me._view = {};
  4640. }
  4641. if (!start) {
  4642. start = me._start = {};
  4643. }
  4644. interpolate(start, view, model, ease);
  4645. return me;
  4646. },
  4647. tooltipPosition: function() {
  4648. return {
  4649. x: this._model.x,
  4650. y: this._model.y
  4651. };
  4652. },
  4653. hasValue: function() {
  4654. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4655. }
  4656. });
  4657. Element.extend = helpers.inherits;
  4658. module.exports = Element;
  4659. },{"3":3,"46":46}],28:[function(require,module,exports){
  4660. /* global window: false */
  4661. /* global document: false */
  4662. 'use strict';
  4663. var color = require(3);
  4664. var defaults = require(26);
  4665. var helpers = require(46);
  4666. var scaleService = require(34);
  4667. module.exports = function() {
  4668. // -- Basic js utility methods
  4669. helpers.configMerge = function(/* objects ... */) {
  4670. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4671. merger: function(key, target, source, options) {
  4672. var tval = target[key] || {};
  4673. var sval = source[key];
  4674. if (key === 'scales') {
  4675. // scale config merging is complex. Add our own function here for that
  4676. target[key] = helpers.scaleMerge(tval, sval);
  4677. } else if (key === 'scale') {
  4678. // used in polar area & radar charts since there is only one scale
  4679. target[key] = helpers.merge(tval, [scaleService.getScaleDefaults(sval.type), sval]);
  4680. } else {
  4681. helpers._merger(key, target, source, options);
  4682. }
  4683. }
  4684. });
  4685. };
  4686. helpers.scaleMerge = function(/* objects ... */) {
  4687. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4688. merger: function(key, target, source, options) {
  4689. if (key === 'xAxes' || key === 'yAxes') {
  4690. var slen = source[key].length;
  4691. var i, type, scale;
  4692. if (!target[key]) {
  4693. target[key] = [];
  4694. }
  4695. for (i = 0; i < slen; ++i) {
  4696. scale = source[key][i];
  4697. type = helpers.valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
  4698. if (i >= target[key].length) {
  4699. target[key].push({});
  4700. }
  4701. if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
  4702. // new/untyped scale or type changed: let's apply the new defaults
  4703. // then merge source scale to correctly overwrite the defaults.
  4704. helpers.merge(target[key][i], [scaleService.getScaleDefaults(type), scale]);
  4705. } else {
  4706. // scales type are the same
  4707. helpers.merge(target[key][i], scale);
  4708. }
  4709. }
  4710. } else {
  4711. helpers._merger(key, target, source, options);
  4712. }
  4713. }
  4714. });
  4715. };
  4716. helpers.where = function(collection, filterCallback) {
  4717. if (helpers.isArray(collection) && Array.prototype.filter) {
  4718. return collection.filter(filterCallback);
  4719. }
  4720. var filtered = [];
  4721. helpers.each(collection, function(item) {
  4722. if (filterCallback(item)) {
  4723. filtered.push(item);
  4724. }
  4725. });
  4726. return filtered;
  4727. };
  4728. helpers.findIndex = Array.prototype.findIndex ?
  4729. function(array, callback, scope) {
  4730. return array.findIndex(callback, scope);
  4731. } :
  4732. function(array, callback, scope) {
  4733. scope = scope === undefined ? array : scope;
  4734. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4735. if (callback.call(scope, array[i], i, array)) {
  4736. return i;
  4737. }
  4738. }
  4739. return -1;
  4740. };
  4741. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  4742. // Default to start of the array
  4743. if (helpers.isNullOrUndef(startIndex)) {
  4744. startIndex = -1;
  4745. }
  4746. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4747. var currentItem = arrayToSearch[i];
  4748. if (filterCallback(currentItem)) {
  4749. return currentItem;
  4750. }
  4751. }
  4752. };
  4753. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  4754. // Default to end of the array
  4755. if (helpers.isNullOrUndef(startIndex)) {
  4756. startIndex = arrayToSearch.length;
  4757. }
  4758. for (var i = startIndex - 1; i >= 0; i--) {
  4759. var currentItem = arrayToSearch[i];
  4760. if (filterCallback(currentItem)) {
  4761. return currentItem;
  4762. }
  4763. }
  4764. };
  4765. // -- Math methods
  4766. helpers.isNumber = function(n) {
  4767. return !isNaN(parseFloat(n)) && isFinite(n);
  4768. };
  4769. helpers.almostEquals = function(x, y, epsilon) {
  4770. return Math.abs(x - y) < epsilon;
  4771. };
  4772. helpers.almostWhole = function(x, epsilon) {
  4773. var rounded = Math.round(x);
  4774. return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
  4775. };
  4776. helpers.max = function(array) {
  4777. return array.reduce(function(max, value) {
  4778. if (!isNaN(value)) {
  4779. return Math.max(max, value);
  4780. }
  4781. return max;
  4782. }, Number.NEGATIVE_INFINITY);
  4783. };
  4784. helpers.min = function(array) {
  4785. return array.reduce(function(min, value) {
  4786. if (!isNaN(value)) {
  4787. return Math.min(min, value);
  4788. }
  4789. return min;
  4790. }, Number.POSITIVE_INFINITY);
  4791. };
  4792. helpers.sign = Math.sign ?
  4793. function(x) {
  4794. return Math.sign(x);
  4795. } :
  4796. function(x) {
  4797. x = +x; // convert to a number
  4798. if (x === 0 || isNaN(x)) {
  4799. return x;
  4800. }
  4801. return x > 0 ? 1 : -1;
  4802. };
  4803. helpers.log10 = Math.log10 ?
  4804. function(x) {
  4805. return Math.log10(x);
  4806. } :
  4807. function(x) {
  4808. var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
  4809. // Check for whole powers of 10,
  4810. // which due to floating point rounding error should be corrected.
  4811. var powerOf10 = Math.round(exponent);
  4812. var isPowerOf10 = x === Math.pow(10, powerOf10);
  4813. return isPowerOf10 ? powerOf10 : exponent;
  4814. };
  4815. helpers.toRadians = function(degrees) {
  4816. return degrees * (Math.PI / 180);
  4817. };
  4818. helpers.toDegrees = function(radians) {
  4819. return radians * (180 / Math.PI);
  4820. };
  4821. // Gets the angle from vertical upright to the point about a centre.
  4822. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  4823. var distanceFromXCenter = anglePoint.x - centrePoint.x;
  4824. var distanceFromYCenter = anglePoint.y - centrePoint.y;
  4825. var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4826. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4827. if (angle < (-0.5 * Math.PI)) {
  4828. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4829. }
  4830. return {
  4831. angle: angle,
  4832. distance: radialDistanceFromCenter
  4833. };
  4834. };
  4835. helpers.distanceBetweenPoints = function(pt1, pt2) {
  4836. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  4837. };
  4838. helpers.aliasPixel = function(pixelWidth) {
  4839. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4840. };
  4841. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  4842. // Props to Rob Spencer at scaled innovation for his post on splining between points
  4843. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4844. // This function must also respect "skipped" points
  4845. var previous = firstPoint.skip ? middlePoint : firstPoint;
  4846. var current = middlePoint;
  4847. var next = afterPoint.skip ? middlePoint : afterPoint;
  4848. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4849. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4850. var s01 = d01 / (d01 + d12);
  4851. var s12 = d12 / (d01 + d12);
  4852. // If all points are the same, s01 & s02 will be inf
  4853. s01 = isNaN(s01) ? 0 : s01;
  4854. s12 = isNaN(s12) ? 0 : s12;
  4855. var fa = t * s01; // scaling factor for triangle Ta
  4856. var fb = t * s12;
  4857. return {
  4858. previous: {
  4859. x: current.x - fa * (next.x - previous.x),
  4860. y: current.y - fa * (next.y - previous.y)
  4861. },
  4862. next: {
  4863. x: current.x + fb * (next.x - previous.x),
  4864. y: current.y + fb * (next.y - previous.y)
  4865. }
  4866. };
  4867. };
  4868. helpers.EPSILON = Number.EPSILON || 1e-14;
  4869. helpers.splineCurveMonotone = function(points) {
  4870. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4871. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4872. // between the dataset discrete points due to the interpolation.
  4873. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4874. var pointsWithTangents = (points || []).map(function(point) {
  4875. return {
  4876. model: point._model,
  4877. deltaK: 0,
  4878. mK: 0
  4879. };
  4880. });
  4881. // Calculate slopes (deltaK) and initialize tangents (mK)
  4882. var pointsLen = pointsWithTangents.length;
  4883. var i, pointBefore, pointCurrent, pointAfter;
  4884. for (i = 0; i < pointsLen; ++i) {
  4885. pointCurrent = pointsWithTangents[i];
  4886. if (pointCurrent.model.skip) {
  4887. continue;
  4888. }
  4889. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4890. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4891. if (pointAfter && !pointAfter.model.skip) {
  4892. var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
  4893. // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
  4894. pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
  4895. }
  4896. if (!pointBefore || pointBefore.model.skip) {
  4897. pointCurrent.mK = pointCurrent.deltaK;
  4898. } else if (!pointAfter || pointAfter.model.skip) {
  4899. pointCurrent.mK = pointBefore.deltaK;
  4900. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4901. pointCurrent.mK = 0;
  4902. } else {
  4903. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4904. }
  4905. }
  4906. // Adjust tangents to ensure monotonic properties
  4907. var alphaK, betaK, tauK, squaredMagnitude;
  4908. for (i = 0; i < pointsLen - 1; ++i) {
  4909. pointCurrent = pointsWithTangents[i];
  4910. pointAfter = pointsWithTangents[i + 1];
  4911. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4912. continue;
  4913. }
  4914. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4915. pointCurrent.mK = pointAfter.mK = 0;
  4916. continue;
  4917. }
  4918. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4919. betaK = pointAfter.mK / pointCurrent.deltaK;
  4920. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4921. if (squaredMagnitude <= 9) {
  4922. continue;
  4923. }
  4924. tauK = 3 / Math.sqrt(squaredMagnitude);
  4925. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4926. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4927. }
  4928. // Compute control points
  4929. var deltaX;
  4930. for (i = 0; i < pointsLen; ++i) {
  4931. pointCurrent = pointsWithTangents[i];
  4932. if (pointCurrent.model.skip) {
  4933. continue;
  4934. }
  4935. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4936. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4937. if (pointBefore && !pointBefore.model.skip) {
  4938. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4939. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4940. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4941. }
  4942. if (pointAfter && !pointAfter.model.skip) {
  4943. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4944. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4945. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4946. }
  4947. }
  4948. };
  4949. helpers.nextItem = function(collection, index, loop) {
  4950. if (loop) {
  4951. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4952. }
  4953. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4954. };
  4955. helpers.previousItem = function(collection, index, loop) {
  4956. if (loop) {
  4957. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4958. }
  4959. return index <= 0 ? collection[0] : collection[index - 1];
  4960. };
  4961. // Implementation of the nice number algorithm used in determining where axis labels will go
  4962. helpers.niceNum = function(range, round) {
  4963. var exponent = Math.floor(helpers.log10(range));
  4964. var fraction = range / Math.pow(10, exponent);
  4965. var niceFraction;
  4966. if (round) {
  4967. if (fraction < 1.5) {
  4968. niceFraction = 1;
  4969. } else if (fraction < 3) {
  4970. niceFraction = 2;
  4971. } else if (fraction < 7) {
  4972. niceFraction = 5;
  4973. } else {
  4974. niceFraction = 10;
  4975. }
  4976. } else if (fraction <= 1.0) {
  4977. niceFraction = 1;
  4978. } else if (fraction <= 2) {
  4979. niceFraction = 2;
  4980. } else if (fraction <= 5) {
  4981. niceFraction = 5;
  4982. } else {
  4983. niceFraction = 10;
  4984. }
  4985. return niceFraction * Math.pow(10, exponent);
  4986. };
  4987. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4988. helpers.requestAnimFrame = (function() {
  4989. if (typeof window === 'undefined') {
  4990. return function(callback) {
  4991. callback();
  4992. };
  4993. }
  4994. return window.requestAnimationFrame ||
  4995. window.webkitRequestAnimationFrame ||
  4996. window.mozRequestAnimationFrame ||
  4997. window.oRequestAnimationFrame ||
  4998. window.msRequestAnimationFrame ||
  4999. function(callback) {
  5000. return window.setTimeout(callback, 1000 / 60);
  5001. };
  5002. }());
  5003. // -- DOM methods
  5004. helpers.getRelativePosition = function(evt, chart) {
  5005. var mouseX, mouseY;
  5006. var e = evt.originalEvent || evt;
  5007. var canvas = evt.target || evt.srcElement;
  5008. var boundingRect = canvas.getBoundingClientRect();
  5009. var touches = e.touches;
  5010. if (touches && touches.length > 0) {
  5011. mouseX = touches[0].clientX;
  5012. mouseY = touches[0].clientY;
  5013. } else {
  5014. mouseX = e.clientX;
  5015. mouseY = e.clientY;
  5016. }
  5017. // Scale mouse coordinates into canvas coordinates
  5018. // by following the pattern laid out by 'jerryj' in the comments of
  5019. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  5020. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  5021. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  5022. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  5023. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  5024. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  5025. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  5026. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  5027. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  5028. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  5029. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  5030. return {
  5031. x: mouseX,
  5032. y: mouseY
  5033. };
  5034. };
  5035. // Private helper function to convert max-width/max-height values that may be percentages into a number
  5036. function parseMaxStyle(styleValue, node, parentProperty) {
  5037. var valueInPixels;
  5038. if (typeof styleValue === 'string') {
  5039. valueInPixels = parseInt(styleValue, 10);
  5040. if (styleValue.indexOf('%') !== -1) {
  5041. // percentage * size in dimension
  5042. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  5043. }
  5044. } else {
  5045. valueInPixels = styleValue;
  5046. }
  5047. return valueInPixels;
  5048. }
  5049. /**
  5050. * Returns if the given value contains an effective constraint.
  5051. * @private
  5052. */
  5053. function isConstrainedValue(value) {
  5054. return value !== undefined && value !== null && value !== 'none';
  5055. }
  5056. // Private helper to get a constraint dimension
  5057. // @param domNode : the node to check the constraint on
  5058. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  5059. // @param percentageProperty : property of parent to use when calculating width as a percentage
  5060. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  5061. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  5062. var view = document.defaultView;
  5063. var parentNode = helpers._getParentNode(domNode);
  5064. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  5065. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  5066. var hasCNode = isConstrainedValue(constrainedNode);
  5067. var hasCContainer = isConstrainedValue(constrainedContainer);
  5068. var infinity = Number.POSITIVE_INFINITY;
  5069. if (hasCNode || hasCContainer) {
  5070. return Math.min(
  5071. hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  5072. hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  5073. }
  5074. return 'none';
  5075. }
  5076. // returns Number or undefined if no constraint
  5077. helpers.getConstraintWidth = function(domNode) {
  5078. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  5079. };
  5080. // returns Number or undefined if no constraint
  5081. helpers.getConstraintHeight = function(domNode) {
  5082. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  5083. };
  5084. /**
  5085. * @private
  5086. */
  5087. helpers._calculatePadding = function(container, padding, parentDimension) {
  5088. padding = helpers.getStyle(container, padding);
  5089. return padding.indexOf('%') > -1 ? parentDimension / parseInt(padding, 10) : parseInt(padding, 10);
  5090. };
  5091. /**
  5092. * @private
  5093. */
  5094. helpers._getParentNode = function(domNode) {
  5095. var parent = domNode.parentNode;
  5096. if (parent && parent.host) {
  5097. parent = parent.host;
  5098. }
  5099. return parent;
  5100. };
  5101. helpers.getMaximumWidth = function(domNode) {
  5102. var container = helpers._getParentNode(domNode);
  5103. if (!container) {
  5104. return domNode.clientWidth;
  5105. }
  5106. var clientWidth = container.clientWidth;
  5107. var paddingLeft = helpers._calculatePadding(container, 'padding-left', clientWidth);
  5108. var paddingRight = helpers._calculatePadding(container, 'padding-right', clientWidth);
  5109. var w = clientWidth - paddingLeft - paddingRight;
  5110. var cw = helpers.getConstraintWidth(domNode);
  5111. return isNaN(cw) ? w : Math.min(w, cw);
  5112. };
  5113. helpers.getMaximumHeight = function(domNode) {
  5114. var container = helpers._getParentNode(domNode);
  5115. if (!container) {
  5116. return domNode.clientHeight;
  5117. }
  5118. var clientHeight = container.clientHeight;
  5119. var paddingTop = helpers._calculatePadding(container, 'padding-top', clientHeight);
  5120. var paddingBottom = helpers._calculatePadding(container, 'padding-bottom', clientHeight);
  5121. var h = clientHeight - paddingTop - paddingBottom;
  5122. var ch = helpers.getConstraintHeight(domNode);
  5123. return isNaN(ch) ? h : Math.min(h, ch);
  5124. };
  5125. helpers.getStyle = function(el, property) {
  5126. return el.currentStyle ?
  5127. el.currentStyle[property] :
  5128. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  5129. };
  5130. helpers.retinaScale = function(chart, forceRatio) {
  5131. var pixelRatio = chart.currentDevicePixelRatio = forceRatio || (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
  5132. if (pixelRatio === 1) {
  5133. return;
  5134. }
  5135. var canvas = chart.canvas;
  5136. var height = chart.height;
  5137. var width = chart.width;
  5138. canvas.height = height * pixelRatio;
  5139. canvas.width = width * pixelRatio;
  5140. chart.ctx.scale(pixelRatio, pixelRatio);
  5141. // If no style has been set on the canvas, the render size is used as display size,
  5142. // making the chart visually bigger, so let's enforce it to the "correct" values.
  5143. // See https://github.com/chartjs/Chart.js/issues/3575
  5144. if (!canvas.style.height && !canvas.style.width) {
  5145. canvas.style.height = height + 'px';
  5146. canvas.style.width = width + 'px';
  5147. }
  5148. };
  5149. // -- Canvas methods
  5150. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  5151. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  5152. };
  5153. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  5154. cache = cache || {};
  5155. var data = cache.data = cache.data || {};
  5156. var gc = cache.garbageCollect = cache.garbageCollect || [];
  5157. if (cache.font !== font) {
  5158. data = cache.data = {};
  5159. gc = cache.garbageCollect = [];
  5160. cache.font = font;
  5161. }
  5162. ctx.font = font;
  5163. var longest = 0;
  5164. helpers.each(arrayOfThings, function(thing) {
  5165. // Undefined strings and arrays should not be measured
  5166. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  5167. longest = helpers.measureText(ctx, data, gc, longest, thing);
  5168. } else if (helpers.isArray(thing)) {
  5169. // if it is an array lets measure each element
  5170. // to do maybe simplify this function a bit so we can do this more recursively?
  5171. helpers.each(thing, function(nestedThing) {
  5172. // Undefined strings and arrays should not be measured
  5173. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  5174. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  5175. }
  5176. });
  5177. }
  5178. });
  5179. var gcLen = gc.length / 2;
  5180. if (gcLen > arrayOfThings.length) {
  5181. for (var i = 0; i < gcLen; i++) {
  5182. delete data[gc[i]];
  5183. }
  5184. gc.splice(0, gcLen);
  5185. }
  5186. return longest;
  5187. };
  5188. helpers.measureText = function(ctx, data, gc, longest, string) {
  5189. var textWidth = data[string];
  5190. if (!textWidth) {
  5191. textWidth = data[string] = ctx.measureText(string).width;
  5192. gc.push(string);
  5193. }
  5194. if (textWidth > longest) {
  5195. longest = textWidth;
  5196. }
  5197. return longest;
  5198. };
  5199. helpers.numberOfLabelLines = function(arrayOfThings) {
  5200. var numberOfLines = 1;
  5201. helpers.each(arrayOfThings, function(thing) {
  5202. if (helpers.isArray(thing)) {
  5203. if (thing.length > numberOfLines) {
  5204. numberOfLines = thing.length;
  5205. }
  5206. }
  5207. });
  5208. return numberOfLines;
  5209. };
  5210. helpers.color = !color ?
  5211. function(value) {
  5212. console.error('Color.js not found!');
  5213. return value;
  5214. } :
  5215. function(value) {
  5216. /* global CanvasGradient */
  5217. if (value instanceof CanvasGradient) {
  5218. value = defaults.global.defaultColor;
  5219. }
  5220. return color(value);
  5221. };
  5222. helpers.getHoverColor = function(colorValue) {
  5223. /* global CanvasPattern */
  5224. return (colorValue instanceof CanvasPattern) ?
  5225. colorValue :
  5226. helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
  5227. };
  5228. };
  5229. },{"26":26,"3":3,"34":34,"46":46}],29:[function(require,module,exports){
  5230. 'use strict';
  5231. var helpers = require(46);
  5232. /**
  5233. * Helper function to get relative position for an event
  5234. * @param {Event|IEvent} event - The event to get the position for
  5235. * @param {Chart} chart - The chart
  5236. * @returns {Point} the event position
  5237. */
  5238. function getRelativePosition(e, chart) {
  5239. if (e.native) {
  5240. return {
  5241. x: e.x,
  5242. y: e.y
  5243. };
  5244. }
  5245. return helpers.getRelativePosition(e, chart);
  5246. }
  5247. /**
  5248. * Helper function to traverse all of the visible elements in the chart
  5249. * @param chart {chart} the chart
  5250. * @param handler {Function} the callback to execute for each visible item
  5251. */
  5252. function parseVisibleItems(chart, handler) {
  5253. var datasets = chart.data.datasets;
  5254. var meta, i, j, ilen, jlen;
  5255. for (i = 0, ilen = datasets.length; i < ilen; ++i) {
  5256. if (!chart.isDatasetVisible(i)) {
  5257. continue;
  5258. }
  5259. meta = chart.getDatasetMeta(i);
  5260. for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
  5261. var element = meta.data[j];
  5262. if (!element._view.skip) {
  5263. handler(element);
  5264. }
  5265. }
  5266. }
  5267. }
  5268. /**
  5269. * Helper function to get the items that intersect the event position
  5270. * @param items {ChartElement[]} elements to filter
  5271. * @param position {Point} the point to be nearest to
  5272. * @return {ChartElement[]} the nearest items
  5273. */
  5274. function getIntersectItems(chart, position) {
  5275. var elements = [];
  5276. parseVisibleItems(chart, function(element) {
  5277. if (element.inRange(position.x, position.y)) {
  5278. elements.push(element);
  5279. }
  5280. });
  5281. return elements;
  5282. }
  5283. /**
  5284. * Helper function to get the items nearest to the event position considering all visible items in teh chart
  5285. * @param chart {Chart} the chart to look at elements from
  5286. * @param position {Point} the point to be nearest to
  5287. * @param intersect {Boolean} if true, only consider items that intersect the position
  5288. * @param distanceMetric {Function} function to provide the distance between points
  5289. * @return {ChartElement[]} the nearest items
  5290. */
  5291. function getNearestItems(chart, position, intersect, distanceMetric) {
  5292. var minDistance = Number.POSITIVE_INFINITY;
  5293. var nearestItems = [];
  5294. parseVisibleItems(chart, function(element) {
  5295. if (intersect && !element.inRange(position.x, position.y)) {
  5296. return;
  5297. }
  5298. var center = element.getCenterPoint();
  5299. var distance = distanceMetric(position, center);
  5300. if (distance < minDistance) {
  5301. nearestItems = [element];
  5302. minDistance = distance;
  5303. } else if (distance === minDistance) {
  5304. // Can have multiple items at the same distance in which case we sort by size
  5305. nearestItems.push(element);
  5306. }
  5307. });
  5308. return nearestItems;
  5309. }
  5310. /**
  5311. * Get a distance metric function for two points based on the
  5312. * axis mode setting
  5313. * @param {String} axis the axis mode. x|y|xy
  5314. */
  5315. function getDistanceMetricForAxis(axis) {
  5316. var useX = axis.indexOf('x') !== -1;
  5317. var useY = axis.indexOf('y') !== -1;
  5318. return function(pt1, pt2) {
  5319. var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0;
  5320. var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0;
  5321. return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
  5322. };
  5323. }
  5324. function indexMode(chart, e, options) {
  5325. var position = getRelativePosition(e, chart);
  5326. // Default axis for index mode is 'x' to match old behaviour
  5327. options.axis = options.axis || 'x';
  5328. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5329. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5330. var elements = [];
  5331. if (!items.length) {
  5332. return [];
  5333. }
  5334. chart.data.datasets.forEach(function(dataset, datasetIndex) {
  5335. if (chart.isDatasetVisible(datasetIndex)) {
  5336. var meta = chart.getDatasetMeta(datasetIndex);
  5337. var element = meta.data[items[0]._index];
  5338. // don't count items that are skipped (null data)
  5339. if (element && !element._view.skip) {
  5340. elements.push(element);
  5341. }
  5342. }
  5343. });
  5344. return elements;
  5345. }
  5346. /**
  5347. * @interface IInteractionOptions
  5348. */
  5349. /**
  5350. * If true, only consider items that intersect the point
  5351. * @name IInterfaceOptions#boolean
  5352. * @type Boolean
  5353. */
  5354. /**
  5355. * Contains interaction related functions
  5356. * @namespace Chart.Interaction
  5357. */
  5358. module.exports = {
  5359. // Helper function for different modes
  5360. modes: {
  5361. single: function(chart, e) {
  5362. var position = getRelativePosition(e, chart);
  5363. var elements = [];
  5364. parseVisibleItems(chart, function(element) {
  5365. if (element.inRange(position.x, position.y)) {
  5366. elements.push(element);
  5367. return elements;
  5368. }
  5369. });
  5370. return elements.slice(0, 1);
  5371. },
  5372. /**
  5373. * @function Chart.Interaction.modes.label
  5374. * @deprecated since version 2.4.0
  5375. * @todo remove at version 3
  5376. * @private
  5377. */
  5378. label: indexMode,
  5379. /**
  5380. * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
  5381. * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
  5382. * @function Chart.Interaction.modes.index
  5383. * @since v2.4.0
  5384. * @param chart {chart} the chart we are returning items from
  5385. * @param e {Event} the event we are find things at
  5386. * @param options {IInteractionOptions} options to use during interaction
  5387. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5388. */
  5389. index: indexMode,
  5390. /**
  5391. * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
  5392. * If the options.intersect is false, we find the nearest item and return the items in that dataset
  5393. * @function Chart.Interaction.modes.dataset
  5394. * @param chart {chart} the chart we are returning items from
  5395. * @param e {Event} the event we are find things at
  5396. * @param options {IInteractionOptions} options to use during interaction
  5397. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5398. */
  5399. dataset: function(chart, e, options) {
  5400. var position = getRelativePosition(e, chart);
  5401. options.axis = options.axis || 'xy';
  5402. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5403. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5404. if (items.length > 0) {
  5405. items = chart.getDatasetMeta(items[0]._datasetIndex).data;
  5406. }
  5407. return items;
  5408. },
  5409. /**
  5410. * @function Chart.Interaction.modes.x-axis
  5411. * @deprecated since version 2.4.0. Use index mode and intersect == true
  5412. * @todo remove at version 3
  5413. * @private
  5414. */
  5415. 'x-axis': function(chart, e) {
  5416. return indexMode(chart, e, {intersect: false});
  5417. },
  5418. /**
  5419. * Point mode returns all elements that hit test based on the event position
  5420. * of the event
  5421. * @function Chart.Interaction.modes.intersect
  5422. * @param chart {chart} the chart we are returning items from
  5423. * @param e {Event} the event we are find things at
  5424. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5425. */
  5426. point: function(chart, e) {
  5427. var position = getRelativePosition(e, chart);
  5428. return getIntersectItems(chart, position);
  5429. },
  5430. /**
  5431. * nearest mode returns the element closest to the point
  5432. * @function Chart.Interaction.modes.intersect
  5433. * @param chart {chart} the chart we are returning items from
  5434. * @param e {Event} the event we are find things at
  5435. * @param options {IInteractionOptions} options to use
  5436. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5437. */
  5438. nearest: function(chart, e, options) {
  5439. var position = getRelativePosition(e, chart);
  5440. options.axis = options.axis || 'xy';
  5441. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5442. var nearestItems = getNearestItems(chart, position, options.intersect, distanceMetric);
  5443. // We have multiple items at the same distance from the event. Now sort by smallest
  5444. if (nearestItems.length > 1) {
  5445. nearestItems.sort(function(a, b) {
  5446. var sizeA = a.getArea();
  5447. var sizeB = b.getArea();
  5448. var ret = sizeA - sizeB;
  5449. if (ret === 0) {
  5450. // if equal sort by dataset index
  5451. ret = a._datasetIndex - b._datasetIndex;
  5452. }
  5453. return ret;
  5454. });
  5455. }
  5456. // Return only 1 item
  5457. return nearestItems.slice(0, 1);
  5458. },
  5459. /**
  5460. * x mode returns the elements that hit-test at the current x coordinate
  5461. * @function Chart.Interaction.modes.x
  5462. * @param chart {chart} the chart we are returning items from
  5463. * @param e {Event} the event we are find things at
  5464. * @param options {IInteractionOptions} options to use
  5465. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5466. */
  5467. x: function(chart, e, options) {
  5468. var position = getRelativePosition(e, chart);
  5469. var items = [];
  5470. var intersectsItem = false;
  5471. parseVisibleItems(chart, function(element) {
  5472. if (element.inXRange(position.x)) {
  5473. items.push(element);
  5474. }
  5475. if (element.inRange(position.x, position.y)) {
  5476. intersectsItem = true;
  5477. }
  5478. });
  5479. // If we want to trigger on an intersect and we don't have any items
  5480. // that intersect the position, return nothing
  5481. if (options.intersect && !intersectsItem) {
  5482. items = [];
  5483. }
  5484. return items;
  5485. },
  5486. /**
  5487. * y mode returns the elements that hit-test at the current y coordinate
  5488. * @function Chart.Interaction.modes.y
  5489. * @param chart {chart} the chart we are returning items from
  5490. * @param e {Event} the event we are find things at
  5491. * @param options {IInteractionOptions} options to use
  5492. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5493. */
  5494. y: function(chart, e, options) {
  5495. var position = getRelativePosition(e, chart);
  5496. var items = [];
  5497. var intersectsItem = false;
  5498. parseVisibleItems(chart, function(element) {
  5499. if (element.inYRange(position.y)) {
  5500. items.push(element);
  5501. }
  5502. if (element.inRange(position.x, position.y)) {
  5503. intersectsItem = true;
  5504. }
  5505. });
  5506. // If we want to trigger on an intersect and we don't have any items
  5507. // that intersect the position, return nothing
  5508. if (options.intersect && !intersectsItem) {
  5509. items = [];
  5510. }
  5511. return items;
  5512. }
  5513. }
  5514. };
  5515. },{"46":46}],30:[function(require,module,exports){
  5516. 'use strict';
  5517. var defaults = require(26);
  5518. defaults._set('global', {
  5519. responsive: true,
  5520. responsiveAnimationDuration: 0,
  5521. maintainAspectRatio: true,
  5522. events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
  5523. hover: {
  5524. onHover: null,
  5525. mode: 'nearest',
  5526. intersect: true,
  5527. animationDuration: 400
  5528. },
  5529. onClick: null,
  5530. defaultColor: 'rgba(0,0,0,0.1)',
  5531. defaultFontColor: '#666',
  5532. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  5533. defaultFontSize: 12,
  5534. defaultFontStyle: 'normal',
  5535. showLines: true,
  5536. // Element defaults defined in element extensions
  5537. elements: {},
  5538. // Layout options such as padding
  5539. layout: {
  5540. padding: {
  5541. top: 0,
  5542. right: 0,
  5543. bottom: 0,
  5544. left: 0
  5545. }
  5546. }
  5547. });
  5548. module.exports = function() {
  5549. // Occupy the global variable of Chart, and create a simple base class
  5550. var Chart = function(item, config) {
  5551. this.construct(item, config);
  5552. return this;
  5553. };
  5554. Chart.Chart = Chart;
  5555. return Chart;
  5556. };
  5557. },{"26":26}],31:[function(require,module,exports){
  5558. 'use strict';
  5559. var helpers = require(46);
  5560. function filterByPosition(array, position) {
  5561. return helpers.where(array, function(v) {
  5562. return v.position === position;
  5563. });
  5564. }
  5565. function sortByWeight(array, reverse) {
  5566. array.forEach(function(v, i) {
  5567. v._tmpIndex_ = i;
  5568. return v;
  5569. });
  5570. array.sort(function(a, b) {
  5571. var v0 = reverse ? b : a;
  5572. var v1 = reverse ? a : b;
  5573. return v0.weight === v1.weight ?
  5574. v0._tmpIndex_ - v1._tmpIndex_ :
  5575. v0.weight - v1.weight;
  5576. });
  5577. array.forEach(function(v) {
  5578. delete v._tmpIndex_;
  5579. });
  5580. }
  5581. /**
  5582. * @interface ILayoutItem
  5583. * @prop {String} position - The position of the item in the chart layout. Possible values are
  5584. * 'left', 'top', 'right', 'bottom', and 'chartArea'
  5585. * @prop {Number} weight - The weight used to sort the item. Higher weights are further away from the chart area
  5586. * @prop {Boolean} fullWidth - if true, and the item is horizontal, then push vertical boxes down
  5587. * @prop {Function} isHorizontal - returns true if the layout item is horizontal (ie. top or bottom)
  5588. * @prop {Function} update - Takes two parameters: width and height. Returns size of item
  5589. * @prop {Function} getPadding - Returns an object with padding on the edges
  5590. * @prop {Number} width - Width of item. Must be valid after update()
  5591. * @prop {Number} height - Height of item. Must be valid after update()
  5592. * @prop {Number} left - Left edge of the item. Set by layout system and cannot be used in update
  5593. * @prop {Number} top - Top edge of the item. Set by layout system and cannot be used in update
  5594. * @prop {Number} right - Right edge of the item. Set by layout system and cannot be used in update
  5595. * @prop {Number} bottom - Bottom edge of the item. Set by layout system and cannot be used in update
  5596. */
  5597. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  5598. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  5599. // It is this service's responsibility of carrying out that layout.
  5600. module.exports = {
  5601. defaults: {},
  5602. /**
  5603. * Register a box to a chart.
  5604. * A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
  5605. * @param {Chart} chart - the chart to use
  5606. * @param {ILayoutItem} item - the item to add to be layed out
  5607. */
  5608. addBox: function(chart, item) {
  5609. if (!chart.boxes) {
  5610. chart.boxes = [];
  5611. }
  5612. // initialize item with default values
  5613. item.fullWidth = item.fullWidth || false;
  5614. item.position = item.position || 'top';
  5615. item.weight = item.weight || 0;
  5616. chart.boxes.push(item);
  5617. },
  5618. /**
  5619. * Remove a layoutItem from a chart
  5620. * @param {Chart} chart - the chart to remove the box from
  5621. * @param {Object} layoutItem - the item to remove from the layout
  5622. */
  5623. removeBox: function(chart, layoutItem) {
  5624. var index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
  5625. if (index !== -1) {
  5626. chart.boxes.splice(index, 1);
  5627. }
  5628. },
  5629. /**
  5630. * Sets (or updates) options on the given `item`.
  5631. * @param {Chart} chart - the chart in which the item lives (or will be added to)
  5632. * @param {Object} item - the item to configure with the given options
  5633. * @param {Object} options - the new item options.
  5634. */
  5635. configure: function(chart, item, options) {
  5636. var props = ['fullWidth', 'position', 'weight'];
  5637. var ilen = props.length;
  5638. var i = 0;
  5639. var prop;
  5640. for (; i < ilen; ++i) {
  5641. prop = props[i];
  5642. if (options.hasOwnProperty(prop)) {
  5643. item[prop] = options[prop];
  5644. }
  5645. }
  5646. },
  5647. /**
  5648. * Fits boxes of the given chart into the given size by having each box measure itself
  5649. * then running a fitting algorithm
  5650. * @param {Chart} chart - the chart
  5651. * @param {Number} width - the width to fit into
  5652. * @param {Number} height - the height to fit into
  5653. */
  5654. update: function(chart, width, height) {
  5655. if (!chart) {
  5656. return;
  5657. }
  5658. var layoutOptions = chart.options.layout || {};
  5659. var padding = helpers.options.toPadding(layoutOptions.padding);
  5660. var leftPadding = padding.left;
  5661. var rightPadding = padding.right;
  5662. var topPadding = padding.top;
  5663. var bottomPadding = padding.bottom;
  5664. var leftBoxes = filterByPosition(chart.boxes, 'left');
  5665. var rightBoxes = filterByPosition(chart.boxes, 'right');
  5666. var topBoxes = filterByPosition(chart.boxes, 'top');
  5667. var bottomBoxes = filterByPosition(chart.boxes, 'bottom');
  5668. var chartAreaBoxes = filterByPosition(chart.boxes, 'chartArea');
  5669. // Sort boxes by weight. A higher weight is further away from the chart area
  5670. sortByWeight(leftBoxes, true);
  5671. sortByWeight(rightBoxes, false);
  5672. sortByWeight(topBoxes, true);
  5673. sortByWeight(bottomBoxes, false);
  5674. // Essentially we now have any number of boxes on each of the 4 sides.
  5675. // Our canvas looks like the following.
  5676. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  5677. // B1 is the bottom axis
  5678. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  5679. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  5680. // an error will be thrown.
  5681. //
  5682. // |----------------------------------------------------|
  5683. // | T1 (Full Width) |
  5684. // |----------------------------------------------------|
  5685. // | | | T2 | |
  5686. // | |----|-------------------------------------|----|
  5687. // | | | C1 | | C2 | |
  5688. // | | |----| |----| |
  5689. // | | | | |
  5690. // | L1 | L2 | ChartArea (C0) | R1 |
  5691. // | | | | |
  5692. // | | |----| |----| |
  5693. // | | | C3 | | C4 | |
  5694. // | |----|-------------------------------------|----|
  5695. // | | | B1 | |
  5696. // |----------------------------------------------------|
  5697. // | B2 (Full Width) |
  5698. // |----------------------------------------------------|
  5699. //
  5700. // What we do to find the best sizing, we do the following
  5701. // 1. Determine the minimum size of the chart area.
  5702. // 2. Split the remaining width equally between each vertical axis
  5703. // 3. Split the remaining height equally between each horizontal axis
  5704. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  5705. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  5706. // 6. Refit each axis
  5707. // 7. Position each axis in the final location
  5708. // 8. Tell the chart the final location of the chart area
  5709. // 9. Tell any axes that overlay the chart area the positions of the chart area
  5710. // Step 1
  5711. var chartWidth = width - leftPadding - rightPadding;
  5712. var chartHeight = height - topPadding - bottomPadding;
  5713. var chartAreaWidth = chartWidth / 2; // min 50%
  5714. var chartAreaHeight = chartHeight / 2; // min 50%
  5715. // Step 2
  5716. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  5717. // Step 3
  5718. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  5719. // Step 4
  5720. var maxChartAreaWidth = chartWidth;
  5721. var maxChartAreaHeight = chartHeight;
  5722. var minBoxSizes = [];
  5723. function getMinimumBoxSize(box) {
  5724. var minSize;
  5725. var isHorizontal = box.isHorizontal();
  5726. if (isHorizontal) {
  5727. minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5728. maxChartAreaHeight -= minSize.height;
  5729. } else {
  5730. minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
  5731. maxChartAreaWidth -= minSize.width;
  5732. }
  5733. minBoxSizes.push({
  5734. horizontal: isHorizontal,
  5735. minSize: minSize,
  5736. box: box,
  5737. });
  5738. }
  5739. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  5740. // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
  5741. var maxHorizontalLeftPadding = 0;
  5742. var maxHorizontalRightPadding = 0;
  5743. var maxVerticalTopPadding = 0;
  5744. var maxVerticalBottomPadding = 0;
  5745. helpers.each(topBoxes.concat(bottomBoxes), function(horizontalBox) {
  5746. if (horizontalBox.getPadding) {
  5747. var boxPadding = horizontalBox.getPadding();
  5748. maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
  5749. maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
  5750. }
  5751. });
  5752. helpers.each(leftBoxes.concat(rightBoxes), function(verticalBox) {
  5753. if (verticalBox.getPadding) {
  5754. var boxPadding = verticalBox.getPadding();
  5755. maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
  5756. maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
  5757. }
  5758. });
  5759. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  5760. // be if the axes are drawn at their minimum sizes.
  5761. // Steps 5 & 6
  5762. var totalLeftBoxesWidth = leftPadding;
  5763. var totalRightBoxesWidth = rightPadding;
  5764. var totalTopBoxesHeight = topPadding;
  5765. var totalBottomBoxesHeight = bottomPadding;
  5766. // Function to fit a box
  5767. function fitBox(box) {
  5768. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
  5769. return minBox.box === box;
  5770. });
  5771. if (minBoxSize) {
  5772. if (box.isHorizontal()) {
  5773. var scaleMargin = {
  5774. left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
  5775. right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
  5776. top: 0,
  5777. bottom: 0
  5778. };
  5779. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5780. // on the margin. Sometimes they need to increase in size slightly
  5781. box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5782. } else {
  5783. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5784. }
  5785. }
  5786. }
  5787. // Update, and calculate the left and right margins for the horizontal boxes
  5788. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5789. helpers.each(leftBoxes, function(box) {
  5790. totalLeftBoxesWidth += box.width;
  5791. });
  5792. helpers.each(rightBoxes, function(box) {
  5793. totalRightBoxesWidth += box.width;
  5794. });
  5795. // Set the Left and Right margins for the horizontal boxes
  5796. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  5797. // Figure out how much margin is on the top and bottom of the vertical boxes
  5798. helpers.each(topBoxes, function(box) {
  5799. totalTopBoxesHeight += box.height;
  5800. });
  5801. helpers.each(bottomBoxes, function(box) {
  5802. totalBottomBoxesHeight += box.height;
  5803. });
  5804. function finalFitVerticalBox(box) {
  5805. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
  5806. return minSize.box === box;
  5807. });
  5808. var scaleMargin = {
  5809. left: 0,
  5810. right: 0,
  5811. top: totalTopBoxesHeight,
  5812. bottom: totalBottomBoxesHeight
  5813. };
  5814. if (minBoxSize) {
  5815. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5816. }
  5817. }
  5818. // Let the left layout know the final margin
  5819. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  5820. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  5821. totalLeftBoxesWidth = leftPadding;
  5822. totalRightBoxesWidth = rightPadding;
  5823. totalTopBoxesHeight = topPadding;
  5824. totalBottomBoxesHeight = bottomPadding;
  5825. helpers.each(leftBoxes, function(box) {
  5826. totalLeftBoxesWidth += box.width;
  5827. });
  5828. helpers.each(rightBoxes, function(box) {
  5829. totalRightBoxesWidth += box.width;
  5830. });
  5831. helpers.each(topBoxes, function(box) {
  5832. totalTopBoxesHeight += box.height;
  5833. });
  5834. helpers.each(bottomBoxes, function(box) {
  5835. totalBottomBoxesHeight += box.height;
  5836. });
  5837. // We may be adding some padding to account for rotated x axis labels
  5838. var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
  5839. totalLeftBoxesWidth += leftPaddingAddition;
  5840. totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
  5841. var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
  5842. totalTopBoxesHeight += topPaddingAddition;
  5843. totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
  5844. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  5845. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  5846. // without calling `fit` again
  5847. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  5848. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  5849. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  5850. helpers.each(leftBoxes, function(box) {
  5851. box.height = newMaxChartAreaHeight;
  5852. });
  5853. helpers.each(rightBoxes, function(box) {
  5854. box.height = newMaxChartAreaHeight;
  5855. });
  5856. helpers.each(topBoxes, function(box) {
  5857. if (!box.fullWidth) {
  5858. box.width = newMaxChartAreaWidth;
  5859. }
  5860. });
  5861. helpers.each(bottomBoxes, function(box) {
  5862. if (!box.fullWidth) {
  5863. box.width = newMaxChartAreaWidth;
  5864. }
  5865. });
  5866. maxChartAreaHeight = newMaxChartAreaHeight;
  5867. maxChartAreaWidth = newMaxChartAreaWidth;
  5868. }
  5869. // Step 7 - Position the boxes
  5870. var left = leftPadding + leftPaddingAddition;
  5871. var top = topPadding + topPaddingAddition;
  5872. function placeBox(box) {
  5873. if (box.isHorizontal()) {
  5874. box.left = box.fullWidth ? leftPadding : totalLeftBoxesWidth;
  5875. box.right = box.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5876. box.top = top;
  5877. box.bottom = top + box.height;
  5878. // Move to next point
  5879. top = box.bottom;
  5880. } else {
  5881. box.left = left;
  5882. box.right = left + box.width;
  5883. box.top = totalTopBoxesHeight;
  5884. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5885. // Move to next point
  5886. left = box.right;
  5887. }
  5888. }
  5889. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5890. // Account for chart width and height
  5891. left += maxChartAreaWidth;
  5892. top += maxChartAreaHeight;
  5893. helpers.each(rightBoxes, placeBox);
  5894. helpers.each(bottomBoxes, placeBox);
  5895. // Step 8
  5896. chart.chartArea = {
  5897. left: totalLeftBoxesWidth,
  5898. top: totalTopBoxesHeight,
  5899. right: totalLeftBoxesWidth + maxChartAreaWidth,
  5900. bottom: totalTopBoxesHeight + maxChartAreaHeight
  5901. };
  5902. // Step 9
  5903. helpers.each(chartAreaBoxes, function(box) {
  5904. box.left = chart.chartArea.left;
  5905. box.top = chart.chartArea.top;
  5906. box.right = chart.chartArea.right;
  5907. box.bottom = chart.chartArea.bottom;
  5908. box.update(maxChartAreaWidth, maxChartAreaHeight);
  5909. });
  5910. }
  5911. };
  5912. },{"46":46}],32:[function(require,module,exports){
  5913. 'use strict';
  5914. var defaults = require(26);
  5915. var helpers = require(46);
  5916. defaults._set('global', {
  5917. plugins: {}
  5918. });
  5919. /**
  5920. * The plugin service singleton
  5921. * @namespace Chart.plugins
  5922. * @since 2.1.0
  5923. */
  5924. module.exports = {
  5925. /**
  5926. * Globally registered plugins.
  5927. * @private
  5928. */
  5929. _plugins: [],
  5930. /**
  5931. * This identifier is used to invalidate the descriptors cache attached to each chart
  5932. * when a global plugin is registered or unregistered. In this case, the cache ID is
  5933. * incremented and descriptors are regenerated during following API calls.
  5934. * @private
  5935. */
  5936. _cacheId: 0,
  5937. /**
  5938. * Registers the given plugin(s) if not already registered.
  5939. * @param {Array|Object} plugins plugin instance(s).
  5940. */
  5941. register: function(plugins) {
  5942. var p = this._plugins;
  5943. ([]).concat(plugins).forEach(function(plugin) {
  5944. if (p.indexOf(plugin) === -1) {
  5945. p.push(plugin);
  5946. }
  5947. });
  5948. this._cacheId++;
  5949. },
  5950. /**
  5951. * Unregisters the given plugin(s) only if registered.
  5952. * @param {Array|Object} plugins plugin instance(s).
  5953. */
  5954. unregister: function(plugins) {
  5955. var p = this._plugins;
  5956. ([]).concat(plugins).forEach(function(plugin) {
  5957. var idx = p.indexOf(plugin);
  5958. if (idx !== -1) {
  5959. p.splice(idx, 1);
  5960. }
  5961. });
  5962. this._cacheId++;
  5963. },
  5964. /**
  5965. * Remove all registered plugins.
  5966. * @since 2.1.5
  5967. */
  5968. clear: function() {
  5969. this._plugins = [];
  5970. this._cacheId++;
  5971. },
  5972. /**
  5973. * Returns the number of registered plugins?
  5974. * @returns {Number}
  5975. * @since 2.1.5
  5976. */
  5977. count: function() {
  5978. return this._plugins.length;
  5979. },
  5980. /**
  5981. * Returns all registered plugin instances.
  5982. * @returns {Array} array of plugin objects.
  5983. * @since 2.1.5
  5984. */
  5985. getAll: function() {
  5986. return this._plugins;
  5987. },
  5988. /**
  5989. * Calls enabled plugins for `chart` on the specified hook and with the given args.
  5990. * This method immediately returns as soon as a plugin explicitly returns false. The
  5991. * returned value can be used, for instance, to interrupt the current action.
  5992. * @param {Object} chart - The chart instance for which plugins should be called.
  5993. * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
  5994. * @param {Array} [args] - Extra arguments to apply to the hook call.
  5995. * @returns {Boolean} false if any of the plugins return false, else returns true.
  5996. */
  5997. notify: function(chart, hook, args) {
  5998. var descriptors = this.descriptors(chart);
  5999. var ilen = descriptors.length;
  6000. var i, descriptor, plugin, params, method;
  6001. for (i = 0; i < ilen; ++i) {
  6002. descriptor = descriptors[i];
  6003. plugin = descriptor.plugin;
  6004. method = plugin[hook];
  6005. if (typeof method === 'function') {
  6006. params = [chart].concat(args || []);
  6007. params.push(descriptor.options);
  6008. if (method.apply(plugin, params) === false) {
  6009. return false;
  6010. }
  6011. }
  6012. }
  6013. return true;
  6014. },
  6015. /**
  6016. * Returns descriptors of enabled plugins for the given chart.
  6017. * @returns {Array} [{ plugin, options }]
  6018. * @private
  6019. */
  6020. descriptors: function(chart) {
  6021. var cache = chart.$plugins || (chart.$plugins = {});
  6022. if (cache.id === this._cacheId) {
  6023. return cache.descriptors;
  6024. }
  6025. var plugins = [];
  6026. var descriptors = [];
  6027. var config = (chart && chart.config) || {};
  6028. var options = (config.options && config.options.plugins) || {};
  6029. this._plugins.concat(config.plugins || []).forEach(function(plugin) {
  6030. var idx = plugins.indexOf(plugin);
  6031. if (idx !== -1) {
  6032. return;
  6033. }
  6034. var id = plugin.id;
  6035. var opts = options[id];
  6036. if (opts === false) {
  6037. return;
  6038. }
  6039. if (opts === true) {
  6040. opts = helpers.clone(defaults.global.plugins[id]);
  6041. }
  6042. plugins.push(plugin);
  6043. descriptors.push({
  6044. plugin: plugin,
  6045. options: opts || {}
  6046. });
  6047. });
  6048. cache.descriptors = descriptors;
  6049. cache.id = this._cacheId;
  6050. return descriptors;
  6051. },
  6052. /**
  6053. * Invalidates cache for the given chart: descriptors hold a reference on plugin option,
  6054. * but in some cases, this reference can be changed by the user when updating options.
  6055. * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  6056. * @private
  6057. */
  6058. _invalidate: function(chart) {
  6059. delete chart.$plugins;
  6060. }
  6061. };
  6062. /**
  6063. * Plugin extension hooks.
  6064. * @interface IPlugin
  6065. * @since 2.1.0
  6066. */
  6067. /**
  6068. * @method IPlugin#beforeInit
  6069. * @desc Called before initializing `chart`.
  6070. * @param {Chart.Controller} chart - The chart instance.
  6071. * @param {Object} options - The plugin options.
  6072. */
  6073. /**
  6074. * @method IPlugin#afterInit
  6075. * @desc Called after `chart` has been initialized and before the first update.
  6076. * @param {Chart.Controller} chart - The chart instance.
  6077. * @param {Object} options - The plugin options.
  6078. */
  6079. /**
  6080. * @method IPlugin#beforeUpdate
  6081. * @desc Called before updating `chart`. If any plugin returns `false`, the update
  6082. * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
  6083. * @param {Chart.Controller} chart - The chart instance.
  6084. * @param {Object} options - The plugin options.
  6085. * @returns {Boolean} `false` to cancel the chart update.
  6086. */
  6087. /**
  6088. * @method IPlugin#afterUpdate
  6089. * @desc Called after `chart` has been updated and before rendering. Note that this
  6090. * hook will not be called if the chart update has been previously cancelled.
  6091. * @param {Chart.Controller} chart - The chart instance.
  6092. * @param {Object} options - The plugin options.
  6093. */
  6094. /**
  6095. * @method IPlugin#beforeDatasetsUpdate
  6096. * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  6097. * the datasets update is cancelled until another `update` is triggered.
  6098. * @param {Chart.Controller} chart - The chart instance.
  6099. * @param {Object} options - The plugin options.
  6100. * @returns {Boolean} false to cancel the datasets update.
  6101. * @since version 2.1.5
  6102. */
  6103. /**
  6104. * @method IPlugin#afterDatasetsUpdate
  6105. * @desc Called after the `chart` datasets have been updated. Note that this hook
  6106. * will not be called if the datasets update has been previously cancelled.
  6107. * @param {Chart.Controller} chart - The chart instance.
  6108. * @param {Object} options - The plugin options.
  6109. * @since version 2.1.5
  6110. */
  6111. /**
  6112. * @method IPlugin#beforeDatasetUpdate
  6113. * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
  6114. * returns `false`, the datasets update is cancelled until another `update` is triggered.
  6115. * @param {Chart} chart - The chart instance.
  6116. * @param {Object} args - The call arguments.
  6117. * @param {Number} args.index - The dataset index.
  6118. * @param {Object} args.meta - The dataset metadata.
  6119. * @param {Object} options - The plugin options.
  6120. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  6121. */
  6122. /**
  6123. * @method IPlugin#afterDatasetUpdate
  6124. * @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
  6125. * that this hook will not be called if the datasets update has been previously cancelled.
  6126. * @param {Chart} chart - The chart instance.
  6127. * @param {Object} args - The call arguments.
  6128. * @param {Number} args.index - The dataset index.
  6129. * @param {Object} args.meta - The dataset metadata.
  6130. * @param {Object} options - The plugin options.
  6131. */
  6132. /**
  6133. * @method IPlugin#beforeLayout
  6134. * @desc Called before laying out `chart`. If any plugin returns `false`,
  6135. * the layout update is cancelled until another `update` is triggered.
  6136. * @param {Chart.Controller} chart - The chart instance.
  6137. * @param {Object} options - The plugin options.
  6138. * @returns {Boolean} `false` to cancel the chart layout.
  6139. */
  6140. /**
  6141. * @method IPlugin#afterLayout
  6142. * @desc Called after the `chart` has been layed out. Note that this hook will not
  6143. * be called if the layout update has been previously cancelled.
  6144. * @param {Chart.Controller} chart - The chart instance.
  6145. * @param {Object} options - The plugin options.
  6146. */
  6147. /**
  6148. * @method IPlugin#beforeRender
  6149. * @desc Called before rendering `chart`. If any plugin returns `false`,
  6150. * the rendering is cancelled until another `render` is triggered.
  6151. * @param {Chart.Controller} chart - The chart instance.
  6152. * @param {Object} options - The plugin options.
  6153. * @returns {Boolean} `false` to cancel the chart rendering.
  6154. */
  6155. /**
  6156. * @method IPlugin#afterRender
  6157. * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  6158. * that this hook will not be called if the rendering has been previously cancelled.
  6159. * @param {Chart.Controller} chart - The chart instance.
  6160. * @param {Object} options - The plugin options.
  6161. */
  6162. /**
  6163. * @method IPlugin#beforeDraw
  6164. * @desc Called before drawing `chart` at every animation frame specified by the given
  6165. * easing value. If any plugin returns `false`, the frame drawing is cancelled until
  6166. * another `render` is triggered.
  6167. * @param {Chart.Controller} chart - The chart instance.
  6168. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6169. * @param {Object} options - The plugin options.
  6170. * @returns {Boolean} `false` to cancel the chart drawing.
  6171. */
  6172. /**
  6173. * @method IPlugin#afterDraw
  6174. * @desc Called after the `chart` has been drawn for the specific easing value. Note
  6175. * that this hook will not be called if the drawing has been previously cancelled.
  6176. * @param {Chart.Controller} chart - The chart instance.
  6177. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6178. * @param {Object} options - The plugin options.
  6179. */
  6180. /**
  6181. * @method IPlugin#beforeDatasetsDraw
  6182. * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  6183. * the datasets drawing is cancelled until another `render` is triggered.
  6184. * @param {Chart.Controller} chart - The chart instance.
  6185. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6186. * @param {Object} options - The plugin options.
  6187. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  6188. */
  6189. /**
  6190. * @method IPlugin#afterDatasetsDraw
  6191. * @desc Called after the `chart` datasets have been drawn. Note that this hook
  6192. * will not be called if the datasets drawing has been previously cancelled.
  6193. * @param {Chart.Controller} chart - The chart instance.
  6194. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  6195. * @param {Object} options - The plugin options.
  6196. */
  6197. /**
  6198. * @method IPlugin#beforeDatasetDraw
  6199. * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
  6200. * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
  6201. * is cancelled until another `render` is triggered.
  6202. * @param {Chart} chart - The chart instance.
  6203. * @param {Object} args - The call arguments.
  6204. * @param {Number} args.index - The dataset index.
  6205. * @param {Object} args.meta - The dataset metadata.
  6206. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  6207. * @param {Object} options - The plugin options.
  6208. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  6209. */
  6210. /**
  6211. * @method IPlugin#afterDatasetDraw
  6212. * @desc Called after the `chart` datasets at the given `args.index` have been drawn
  6213. * (datasets are drawn in the reverse order). Note that this hook will not be called
  6214. * if the datasets drawing has been previously cancelled.
  6215. * @param {Chart} chart - The chart instance.
  6216. * @param {Object} args - The call arguments.
  6217. * @param {Number} args.index - The dataset index.
  6218. * @param {Object} args.meta - The dataset metadata.
  6219. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  6220. * @param {Object} options - The plugin options.
  6221. */
  6222. /**
  6223. * @method IPlugin#beforeTooltipDraw
  6224. * @desc Called before drawing the `tooltip`. If any plugin returns `false`,
  6225. * the tooltip drawing is cancelled until another `render` is triggered.
  6226. * @param {Chart} chart - The chart instance.
  6227. * @param {Object} args - The call arguments.
  6228. * @param {Object} args.tooltip - The tooltip.
  6229. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  6230. * @param {Object} options - The plugin options.
  6231. * @returns {Boolean} `false` to cancel the chart tooltip drawing.
  6232. */
  6233. /**
  6234. * @method IPlugin#afterTooltipDraw
  6235. * @desc Called after drawing the `tooltip`. Note that this hook will not
  6236. * be called if the tooltip drawing has been previously cancelled.
  6237. * @param {Chart} chart - The chart instance.
  6238. * @param {Object} args - The call arguments.
  6239. * @param {Object} args.tooltip - The tooltip.
  6240. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  6241. * @param {Object} options - The plugin options.
  6242. */
  6243. /**
  6244. * @method IPlugin#beforeEvent
  6245. * @desc Called before processing the specified `event`. If any plugin returns `false`,
  6246. * the event will be discarded.
  6247. * @param {Chart.Controller} chart - The chart instance.
  6248. * @param {IEvent} event - The event object.
  6249. * @param {Object} options - The plugin options.
  6250. */
  6251. /**
  6252. * @method IPlugin#afterEvent
  6253. * @desc Called after the `event` has been consumed. Note that this hook
  6254. * will not be called if the `event` has been previously discarded.
  6255. * @param {Chart.Controller} chart - The chart instance.
  6256. * @param {IEvent} event - The event object.
  6257. * @param {Object} options - The plugin options.
  6258. */
  6259. /**
  6260. * @method IPlugin#resize
  6261. * @desc Called after the chart as been resized.
  6262. * @param {Chart.Controller} chart - The chart instance.
  6263. * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
  6264. * @param {Object} options - The plugin options.
  6265. */
  6266. /**
  6267. * @method IPlugin#destroy
  6268. * @desc Called after the chart as been destroyed.
  6269. * @param {Chart.Controller} chart - The chart instance.
  6270. * @param {Object} options - The plugin options.
  6271. */
  6272. },{"26":26,"46":46}],33:[function(require,module,exports){
  6273. 'use strict';
  6274. var defaults = require(26);
  6275. var Element = require(27);
  6276. var helpers = require(46);
  6277. var Ticks = require(35);
  6278. defaults._set('scale', {
  6279. display: true,
  6280. position: 'left',
  6281. offset: false,
  6282. // grid line settings
  6283. gridLines: {
  6284. display: true,
  6285. color: 'rgba(0, 0, 0, 0.1)',
  6286. lineWidth: 1,
  6287. drawBorder: true,
  6288. drawOnChartArea: true,
  6289. drawTicks: true,
  6290. tickMarkLength: 10,
  6291. zeroLineWidth: 1,
  6292. zeroLineColor: 'rgba(0,0,0,0.25)',
  6293. zeroLineBorderDash: [],
  6294. zeroLineBorderDashOffset: 0.0,
  6295. offsetGridLines: false,
  6296. borderDash: [],
  6297. borderDashOffset: 0.0
  6298. },
  6299. // scale label
  6300. scaleLabel: {
  6301. // display property
  6302. display: false,
  6303. // actual label
  6304. labelString: '',
  6305. // line height
  6306. lineHeight: 1.2,
  6307. // top/bottom padding
  6308. padding: {
  6309. top: 4,
  6310. bottom: 4
  6311. }
  6312. },
  6313. // label settings
  6314. ticks: {
  6315. beginAtZero: false,
  6316. minRotation: 0,
  6317. maxRotation: 50,
  6318. mirror: false,
  6319. padding: 0,
  6320. reverse: false,
  6321. display: true,
  6322. autoSkip: true,
  6323. autoSkipPadding: 0,
  6324. labelOffset: 0,
  6325. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  6326. callback: Ticks.formatters.values,
  6327. minor: {},
  6328. major: {}
  6329. }
  6330. });
  6331. function labelsFromTicks(ticks) {
  6332. var labels = [];
  6333. var i, ilen;
  6334. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  6335. labels.push(ticks[i].label);
  6336. }
  6337. return labels;
  6338. }
  6339. function getLineValue(scale, index, offsetGridLines) {
  6340. var lineValue = scale.getPixelForTick(index);
  6341. if (offsetGridLines) {
  6342. if (index === 0) {
  6343. lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
  6344. } else {
  6345. lineValue -= (lineValue - scale.getPixelForTick(index - 1)) / 2;
  6346. }
  6347. }
  6348. return lineValue;
  6349. }
  6350. function computeTextSize(context, tick, font) {
  6351. return helpers.isArray(tick) ?
  6352. helpers.longestText(context, font, tick) :
  6353. context.measureText(tick).width;
  6354. }
  6355. function parseFontOptions(options) {
  6356. var valueOrDefault = helpers.valueOrDefault;
  6357. var globalDefaults = defaults.global;
  6358. var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
  6359. var style = valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
  6360. var family = valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
  6361. return {
  6362. size: size,
  6363. style: style,
  6364. family: family,
  6365. font: helpers.fontString(size, style, family)
  6366. };
  6367. }
  6368. function parseLineHeight(options) {
  6369. return helpers.options.toLineHeight(
  6370. helpers.valueOrDefault(options.lineHeight, 1.2),
  6371. helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
  6372. }
  6373. module.exports = Element.extend({
  6374. /**
  6375. * Get the padding needed for the scale
  6376. * @method getPadding
  6377. * @private
  6378. * @returns {Padding} the necessary padding
  6379. */
  6380. getPadding: function() {
  6381. var me = this;
  6382. return {
  6383. left: me.paddingLeft || 0,
  6384. top: me.paddingTop || 0,
  6385. right: me.paddingRight || 0,
  6386. bottom: me.paddingBottom || 0
  6387. };
  6388. },
  6389. /**
  6390. * Returns the scale tick objects ({label, major})
  6391. * @since 2.7
  6392. */
  6393. getTicks: function() {
  6394. return this._ticks;
  6395. },
  6396. // These methods are ordered by lifecyle. Utilities then follow.
  6397. // Any function defined here is inherited by all scale types.
  6398. // Any function can be extended by the scale type
  6399. mergeTicksOptions: function() {
  6400. var ticks = this.options.ticks;
  6401. if (ticks.minor === false) {
  6402. ticks.minor = {
  6403. display: false
  6404. };
  6405. }
  6406. if (ticks.major === false) {
  6407. ticks.major = {
  6408. display: false
  6409. };
  6410. }
  6411. for (var key in ticks) {
  6412. if (key !== 'major' && key !== 'minor') {
  6413. if (typeof ticks.minor[key] === 'undefined') {
  6414. ticks.minor[key] = ticks[key];
  6415. }
  6416. if (typeof ticks.major[key] === 'undefined') {
  6417. ticks.major[key] = ticks[key];
  6418. }
  6419. }
  6420. }
  6421. },
  6422. beforeUpdate: function() {
  6423. helpers.callback(this.options.beforeUpdate, [this]);
  6424. },
  6425. update: function(maxWidth, maxHeight, margins) {
  6426. var me = this;
  6427. var i, ilen, labels, label, ticks, tick;
  6428. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6429. me.beforeUpdate();
  6430. // Absorb the master measurements
  6431. me.maxWidth = maxWidth;
  6432. me.maxHeight = maxHeight;
  6433. me.margins = helpers.extend({
  6434. left: 0,
  6435. right: 0,
  6436. top: 0,
  6437. bottom: 0
  6438. }, margins);
  6439. me.longestTextCache = me.longestTextCache || {};
  6440. // Dimensions
  6441. me.beforeSetDimensions();
  6442. me.setDimensions();
  6443. me.afterSetDimensions();
  6444. // Data min/max
  6445. me.beforeDataLimits();
  6446. me.determineDataLimits();
  6447. me.afterDataLimits();
  6448. // Ticks - `this.ticks` is now DEPRECATED!
  6449. // Internal ticks are now stored as objects in the PRIVATE `this._ticks` member
  6450. // and must not be accessed directly from outside this class. `this.ticks` being
  6451. // around for long time and not marked as private, we can't change its structure
  6452. // without unexpected breaking changes. If you need to access the scale ticks,
  6453. // use scale.getTicks() instead.
  6454. me.beforeBuildTicks();
  6455. // New implementations should return an array of objects but for BACKWARD COMPAT,
  6456. // we still support no return (`this.ticks` internally set by calling this method).
  6457. ticks = me.buildTicks() || [];
  6458. me.afterBuildTicks();
  6459. me.beforeTickToLabelConversion();
  6460. // New implementations should return the formatted tick labels but for BACKWARD
  6461. // COMPAT, we still support no return (`this.ticks` internally changed by calling
  6462. // this method and supposed to contain only string values).
  6463. labels = me.convertTicksToLabels(ticks) || me.ticks;
  6464. me.afterTickToLabelConversion();
  6465. me.ticks = labels; // BACKWARD COMPATIBILITY
  6466. // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
  6467. // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
  6468. for (i = 0, ilen = labels.length; i < ilen; ++i) {
  6469. label = labels[i];
  6470. tick = ticks[i];
  6471. if (!tick) {
  6472. ticks.push(tick = {
  6473. label: label,
  6474. major: false
  6475. });
  6476. } else {
  6477. tick.label = label;
  6478. }
  6479. }
  6480. me._ticks = ticks;
  6481. // Tick Rotation
  6482. me.beforeCalculateTickRotation();
  6483. me.calculateTickRotation();
  6484. me.afterCalculateTickRotation();
  6485. // Fit
  6486. me.beforeFit();
  6487. me.fit();
  6488. me.afterFit();
  6489. //
  6490. me.afterUpdate();
  6491. return me.minSize;
  6492. },
  6493. afterUpdate: function() {
  6494. helpers.callback(this.options.afterUpdate, [this]);
  6495. },
  6496. //
  6497. beforeSetDimensions: function() {
  6498. helpers.callback(this.options.beforeSetDimensions, [this]);
  6499. },
  6500. setDimensions: function() {
  6501. var me = this;
  6502. // Set the unconstrained dimension before label rotation
  6503. if (me.isHorizontal()) {
  6504. // Reset position before calculating rotation
  6505. me.width = me.maxWidth;
  6506. me.left = 0;
  6507. me.right = me.width;
  6508. } else {
  6509. me.height = me.maxHeight;
  6510. // Reset position before calculating rotation
  6511. me.top = 0;
  6512. me.bottom = me.height;
  6513. }
  6514. // Reset padding
  6515. me.paddingLeft = 0;
  6516. me.paddingTop = 0;
  6517. me.paddingRight = 0;
  6518. me.paddingBottom = 0;
  6519. },
  6520. afterSetDimensions: function() {
  6521. helpers.callback(this.options.afterSetDimensions, [this]);
  6522. },
  6523. // Data limits
  6524. beforeDataLimits: function() {
  6525. helpers.callback(this.options.beforeDataLimits, [this]);
  6526. },
  6527. determineDataLimits: helpers.noop,
  6528. afterDataLimits: function() {
  6529. helpers.callback(this.options.afterDataLimits, [this]);
  6530. },
  6531. //
  6532. beforeBuildTicks: function() {
  6533. helpers.callback(this.options.beforeBuildTicks, [this]);
  6534. },
  6535. buildTicks: helpers.noop,
  6536. afterBuildTicks: function() {
  6537. helpers.callback(this.options.afterBuildTicks, [this]);
  6538. },
  6539. beforeTickToLabelConversion: function() {
  6540. helpers.callback(this.options.beforeTickToLabelConversion, [this]);
  6541. },
  6542. convertTicksToLabels: function() {
  6543. var me = this;
  6544. // Convert ticks to strings
  6545. var tickOpts = me.options.ticks;
  6546. me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback, this);
  6547. },
  6548. afterTickToLabelConversion: function() {
  6549. helpers.callback(this.options.afterTickToLabelConversion, [this]);
  6550. },
  6551. //
  6552. beforeCalculateTickRotation: function() {
  6553. helpers.callback(this.options.beforeCalculateTickRotation, [this]);
  6554. },
  6555. calculateTickRotation: function() {
  6556. var me = this;
  6557. var context = me.ctx;
  6558. var tickOpts = me.options.ticks;
  6559. var labels = labelsFromTicks(me._ticks);
  6560. // Get the width of each grid by calculating the difference
  6561. // between x offsets between 0 and 1.
  6562. var tickFont = parseFontOptions(tickOpts);
  6563. context.font = tickFont.font;
  6564. var labelRotation = tickOpts.minRotation || 0;
  6565. if (labels.length && me.options.display && me.isHorizontal()) {
  6566. var originalLabelWidth = helpers.longestText(context, tickFont.font, labels, me.longestTextCache);
  6567. var labelWidth = originalLabelWidth;
  6568. var cosRotation, sinRotation;
  6569. // Allow 3 pixels x2 padding either side for label readability
  6570. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6571. // Max label rotation can be set or default to 90 - also act as a loop counter
  6572. while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
  6573. var angleRadians = helpers.toRadians(labelRotation);
  6574. cosRotation = Math.cos(angleRadians);
  6575. sinRotation = Math.sin(angleRadians);
  6576. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6577. // go back one step
  6578. labelRotation--;
  6579. break;
  6580. }
  6581. labelRotation++;
  6582. labelWidth = cosRotation * originalLabelWidth;
  6583. }
  6584. }
  6585. me.labelRotation = labelRotation;
  6586. },
  6587. afterCalculateTickRotation: function() {
  6588. helpers.callback(this.options.afterCalculateTickRotation, [this]);
  6589. },
  6590. //
  6591. beforeFit: function() {
  6592. helpers.callback(this.options.beforeFit, [this]);
  6593. },
  6594. fit: function() {
  6595. var me = this;
  6596. // Reset
  6597. var minSize = me.minSize = {
  6598. width: 0,
  6599. height: 0
  6600. };
  6601. var labels = labelsFromTicks(me._ticks);
  6602. var opts = me.options;
  6603. var tickOpts = opts.ticks;
  6604. var scaleLabelOpts = opts.scaleLabel;
  6605. var gridLineOpts = opts.gridLines;
  6606. var display = opts.display;
  6607. var isHorizontal = me.isHorizontal();
  6608. var tickFont = parseFontOptions(tickOpts);
  6609. var tickMarkLength = opts.gridLines.tickMarkLength;
  6610. // Width
  6611. if (isHorizontal) {
  6612. // subtract the margins to line up with the chartArea if we are a full width scale
  6613. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6614. } else {
  6615. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6616. }
  6617. // height
  6618. if (isHorizontal) {
  6619. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6620. } else {
  6621. minSize.height = me.maxHeight; // fill all the height
  6622. }
  6623. // Are we showing a title for the scale?
  6624. if (scaleLabelOpts.display && display) {
  6625. var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
  6626. var scaleLabelPadding = helpers.options.toPadding(scaleLabelOpts.padding);
  6627. var deltaHeight = scaleLabelLineHeight + scaleLabelPadding.height;
  6628. if (isHorizontal) {
  6629. minSize.height += deltaHeight;
  6630. } else {
  6631. minSize.width += deltaHeight;
  6632. }
  6633. }
  6634. // Don't bother fitting the ticks if we are not showing them
  6635. if (tickOpts.display && display) {
  6636. var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, labels, me.longestTextCache);
  6637. var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
  6638. var lineSpace = tickFont.size * 0.5;
  6639. var tickPadding = me.options.ticks.padding;
  6640. if (isHorizontal) {
  6641. // A horizontal axis is more constrained by the height.
  6642. me.longestLabelWidth = largestTextWidth;
  6643. var angleRadians = helpers.toRadians(me.labelRotation);
  6644. var cosRotation = Math.cos(angleRadians);
  6645. var sinRotation = Math.sin(angleRadians);
  6646. // TODO - improve this calculation
  6647. var labelHeight = (sinRotation * largestTextWidth)
  6648. + (tickFont.size * tallestLabelHeightInLines)
  6649. + (lineSpace * (tallestLabelHeightInLines - 1))
  6650. + lineSpace; // padding
  6651. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);
  6652. me.ctx.font = tickFont.font;
  6653. var firstLabelWidth = computeTextSize(me.ctx, labels[0], tickFont.font);
  6654. var lastLabelWidth = computeTextSize(me.ctx, labels[labels.length - 1], tickFont.font);
  6655. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
  6656. // which means that the right padding is dominated by the font height
  6657. if (me.labelRotation !== 0) {
  6658. me.paddingLeft = opts.position === 'bottom' ? (cosRotation * firstLabelWidth) + 3 : (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
  6659. me.paddingRight = opts.position === 'bottom' ? (cosRotation * lineSpace) + 3 : (cosRotation * lastLabelWidth) + 3;
  6660. } else {
  6661. me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6662. me.paddingRight = lastLabelWidth / 2 + 3;
  6663. }
  6664. } else {
  6665. // A vertical axis is more constrained by the width. Labels are the
  6666. // dominant factor here, so get that length first and account for padding
  6667. if (tickOpts.mirror) {
  6668. largestTextWidth = 0;
  6669. } else {
  6670. // use lineSpace for consistency with horizontal axis
  6671. // tickPadding is not implemented for horizontal
  6672. largestTextWidth += tickPadding + lineSpace;
  6673. }
  6674. minSize.width = Math.min(me.maxWidth, minSize.width + largestTextWidth);
  6675. me.paddingTop = tickFont.size / 2;
  6676. me.paddingBottom = tickFont.size / 2;
  6677. }
  6678. }
  6679. me.handleMargins();
  6680. me.width = minSize.width;
  6681. me.height = minSize.height;
  6682. },
  6683. /**
  6684. * Handle margins and padding interactions
  6685. * @private
  6686. */
  6687. handleMargins: function() {
  6688. var me = this;
  6689. if (me.margins) {
  6690. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6691. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6692. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6693. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6694. }
  6695. },
  6696. afterFit: function() {
  6697. helpers.callback(this.options.afterFit, [this]);
  6698. },
  6699. // Shared Methods
  6700. isHorizontal: function() {
  6701. return this.options.position === 'top' || this.options.position === 'bottom';
  6702. },
  6703. isFullWidth: function() {
  6704. return (this.options.fullWidth);
  6705. },
  6706. // 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
  6707. getRightValue: function(rawValue) {
  6708. // Null and undefined values first
  6709. if (helpers.isNullOrUndef(rawValue)) {
  6710. return NaN;
  6711. }
  6712. // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
  6713. if (typeof rawValue === 'number' && !isFinite(rawValue)) {
  6714. return NaN;
  6715. }
  6716. // If it is in fact an object, dive in one more level
  6717. if (rawValue) {
  6718. if (this.isHorizontal()) {
  6719. if (rawValue.x !== undefined) {
  6720. return this.getRightValue(rawValue.x);
  6721. }
  6722. } else if (rawValue.y !== undefined) {
  6723. return this.getRightValue(rawValue.y);
  6724. }
  6725. }
  6726. // Value is good, return it
  6727. return rawValue;
  6728. },
  6729. /**
  6730. * Used to get the value to display in the tooltip for the data at the given index
  6731. * @param index
  6732. * @param datasetIndex
  6733. */
  6734. getLabelForIndex: helpers.noop,
  6735. /**
  6736. * Returns the location of the given data point. Value can either be an index or a numerical value
  6737. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6738. * @param value
  6739. * @param index
  6740. * @param datasetIndex
  6741. */
  6742. getPixelForValue: helpers.noop,
  6743. /**
  6744. * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6745. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6746. * @param pixel
  6747. */
  6748. getValueForPixel: helpers.noop,
  6749. /**
  6750. * Returns the location of the tick at the given index
  6751. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6752. */
  6753. getPixelForTick: function(index) {
  6754. var me = this;
  6755. var offset = me.options.offset;
  6756. if (me.isHorizontal()) {
  6757. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6758. var tickWidth = innerWidth / Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  6759. var pixel = (tickWidth * index) + me.paddingLeft;
  6760. if (offset) {
  6761. pixel += tickWidth / 2;
  6762. }
  6763. var finalVal = me.left + Math.round(pixel);
  6764. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6765. return finalVal;
  6766. }
  6767. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6768. return me.top + (index * (innerHeight / (me._ticks.length - 1)));
  6769. },
  6770. /**
  6771. * Utility for getting the pixel location of a percentage of scale
  6772. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6773. */
  6774. getPixelForDecimal: function(decimal) {
  6775. var me = this;
  6776. if (me.isHorizontal()) {
  6777. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6778. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6779. var finalVal = me.left + Math.round(valueOffset);
  6780. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6781. return finalVal;
  6782. }
  6783. return me.top + (decimal * me.height);
  6784. },
  6785. /**
  6786. * Returns the pixel for the minimum chart value
  6787. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6788. */
  6789. getBasePixel: function() {
  6790. return this.getPixelForValue(this.getBaseValue());
  6791. },
  6792. getBaseValue: function() {
  6793. var me = this;
  6794. var min = me.min;
  6795. var max = me.max;
  6796. return me.beginAtZero ? 0 :
  6797. min < 0 && max < 0 ? max :
  6798. min > 0 && max > 0 ? min :
  6799. 0;
  6800. },
  6801. /**
  6802. * Returns a subset of ticks to be plotted to avoid overlapping labels.
  6803. * @private
  6804. */
  6805. _autoSkip: function(ticks) {
  6806. var skipRatio;
  6807. var me = this;
  6808. var isHorizontal = me.isHorizontal();
  6809. var optionTicks = me.options.ticks.minor;
  6810. var tickCount = ticks.length;
  6811. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6812. var cosRotation = Math.cos(labelRotationRadians);
  6813. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6814. var result = [];
  6815. var i, tick, shouldSkip;
  6816. // figure out the maximum number of gridlines to show
  6817. var maxTicks;
  6818. if (optionTicks.maxTicksLimit) {
  6819. maxTicks = optionTicks.maxTicksLimit;
  6820. }
  6821. if (isHorizontal) {
  6822. skipRatio = false;
  6823. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount > (me.width - (me.paddingLeft + me.paddingRight))) {
  6824. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount) / (me.width - (me.paddingLeft + me.paddingRight)));
  6825. }
  6826. // if they defined a max number of optionTicks,
  6827. // increase skipRatio until that number is met
  6828. if (maxTicks && tickCount > maxTicks) {
  6829. skipRatio = Math.max(skipRatio, Math.floor(tickCount / maxTicks));
  6830. }
  6831. }
  6832. for (i = 0; i < tickCount; i++) {
  6833. tick = ticks[i];
  6834. // Since we always show the last tick,we need may need to hide the last shown one before
  6835. shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
  6836. if (shouldSkip && i !== tickCount - 1) {
  6837. // leave tick in place but make sure it's not displayed (#4635)
  6838. delete tick.label;
  6839. }
  6840. result.push(tick);
  6841. }
  6842. return result;
  6843. },
  6844. // Actually draw the scale on the canvas
  6845. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6846. draw: function(chartArea) {
  6847. var me = this;
  6848. var options = me.options;
  6849. if (!options.display) {
  6850. return;
  6851. }
  6852. var context = me.ctx;
  6853. var globalDefaults = defaults.global;
  6854. var optionTicks = options.ticks.minor;
  6855. var optionMajorTicks = options.ticks.major || optionTicks;
  6856. var gridLines = options.gridLines;
  6857. var scaleLabel = options.scaleLabel;
  6858. var isRotated = me.labelRotation !== 0;
  6859. var isHorizontal = me.isHorizontal();
  6860. var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
  6861. var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6862. var tickFont = parseFontOptions(optionTicks);
  6863. var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, globalDefaults.defaultFontColor);
  6864. var majorTickFont = parseFontOptions(optionMajorTicks);
  6865. var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
  6866. var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6867. var scaleLabelFont = parseFontOptions(scaleLabel);
  6868. var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
  6869. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6870. var itemsToDraw = [];
  6871. var axisWidth = me.options.gridLines.lineWidth;
  6872. var xTickStart = options.position === 'right' ? me.left : me.right - axisWidth - tl;
  6873. var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
  6874. var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
  6875. var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
  6876. helpers.each(ticks, function(tick, index) {
  6877. // autoskipper skipped this tick (#4635)
  6878. if (helpers.isNullOrUndef(tick.label)) {
  6879. return;
  6880. }
  6881. var label = tick.label;
  6882. var lineWidth, lineColor, borderDash, borderDashOffset;
  6883. if (index === me.zeroLineIndex && options.offset === gridLines.offsetGridLines) {
  6884. // Draw the first index specially
  6885. lineWidth = gridLines.zeroLineWidth;
  6886. lineColor = gridLines.zeroLineColor;
  6887. borderDash = gridLines.zeroLineBorderDash;
  6888. borderDashOffset = gridLines.zeroLineBorderDashOffset;
  6889. } else {
  6890. lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
  6891. lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
  6892. borderDash = helpers.valueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6893. borderDashOffset = helpers.valueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6894. }
  6895. // Common properties
  6896. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6897. var textAlign = 'middle';
  6898. var textBaseline = 'middle';
  6899. var tickPadding = optionTicks.padding;
  6900. if (isHorizontal) {
  6901. var labelYOffset = tl + tickPadding;
  6902. if (options.position === 'bottom') {
  6903. // bottom
  6904. textBaseline = !isRotated ? 'top' : 'middle';
  6905. textAlign = !isRotated ? 'center' : 'right';
  6906. labelY = me.top + labelYOffset;
  6907. } else {
  6908. // top
  6909. textBaseline = !isRotated ? 'bottom' : 'middle';
  6910. textAlign = !isRotated ? 'center' : 'left';
  6911. labelY = me.bottom - labelYOffset;
  6912. }
  6913. var xLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6914. if (xLineValue < me.left) {
  6915. lineColor = 'rgba(0,0,0,0)';
  6916. }
  6917. xLineValue += helpers.aliasPixel(lineWidth);
  6918. labelX = me.getPixelForTick(index) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6919. tx1 = tx2 = x1 = x2 = xLineValue;
  6920. ty1 = yTickStart;
  6921. ty2 = yTickEnd;
  6922. y1 = chartArea.top;
  6923. y2 = chartArea.bottom + axisWidth;
  6924. } else {
  6925. var isLeft = options.position === 'left';
  6926. var labelXOffset;
  6927. if (optionTicks.mirror) {
  6928. textAlign = isLeft ? 'left' : 'right';
  6929. labelXOffset = tickPadding;
  6930. } else {
  6931. textAlign = isLeft ? 'right' : 'left';
  6932. labelXOffset = tl + tickPadding;
  6933. }
  6934. labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
  6935. var yLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6936. if (yLineValue < me.top) {
  6937. lineColor = 'rgba(0,0,0,0)';
  6938. }
  6939. yLineValue += helpers.aliasPixel(lineWidth);
  6940. labelY = me.getPixelForTick(index) + optionTicks.labelOffset;
  6941. tx1 = xTickStart;
  6942. tx2 = xTickEnd;
  6943. x1 = chartArea.left;
  6944. x2 = chartArea.right + axisWidth;
  6945. ty1 = ty2 = y1 = y2 = yLineValue;
  6946. }
  6947. itemsToDraw.push({
  6948. tx1: tx1,
  6949. ty1: ty1,
  6950. tx2: tx2,
  6951. ty2: ty2,
  6952. x1: x1,
  6953. y1: y1,
  6954. x2: x2,
  6955. y2: y2,
  6956. labelX: labelX,
  6957. labelY: labelY,
  6958. glWidth: lineWidth,
  6959. glColor: lineColor,
  6960. glBorderDash: borderDash,
  6961. glBorderDashOffset: borderDashOffset,
  6962. rotation: -1 * labelRotationRadians,
  6963. label: label,
  6964. major: tick.major,
  6965. textBaseline: textBaseline,
  6966. textAlign: textAlign
  6967. });
  6968. });
  6969. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  6970. helpers.each(itemsToDraw, function(itemToDraw) {
  6971. if (gridLines.display) {
  6972. context.save();
  6973. context.lineWidth = itemToDraw.glWidth;
  6974. context.strokeStyle = itemToDraw.glColor;
  6975. if (context.setLineDash) {
  6976. context.setLineDash(itemToDraw.glBorderDash);
  6977. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  6978. }
  6979. context.beginPath();
  6980. if (gridLines.drawTicks) {
  6981. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  6982. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  6983. }
  6984. if (gridLines.drawOnChartArea) {
  6985. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  6986. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  6987. }
  6988. context.stroke();
  6989. context.restore();
  6990. }
  6991. if (optionTicks.display) {
  6992. // Make sure we draw text in the correct color and font
  6993. context.save();
  6994. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  6995. context.rotate(itemToDraw.rotation);
  6996. context.font = itemToDraw.major ? majorTickFont.font : tickFont.font;
  6997. context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
  6998. context.textBaseline = itemToDraw.textBaseline;
  6999. context.textAlign = itemToDraw.textAlign;
  7000. var label = itemToDraw.label;
  7001. if (helpers.isArray(label)) {
  7002. var lineCount = label.length;
  7003. var lineHeight = tickFont.size * 1.5;
  7004. var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
  7005. for (var i = 0; i < lineCount; ++i) {
  7006. // We just make sure the multiline element is a string here..
  7007. context.fillText('' + label[i], 0, y);
  7008. // apply same lineSpacing as calculated @ L#320
  7009. y += lineHeight;
  7010. }
  7011. } else {
  7012. context.fillText(label, 0, 0);
  7013. }
  7014. context.restore();
  7015. }
  7016. });
  7017. if (scaleLabel.display) {
  7018. // Draw the scale label
  7019. var scaleLabelX;
  7020. var scaleLabelY;
  7021. var rotation = 0;
  7022. var halfLineHeight = parseLineHeight(scaleLabel) / 2;
  7023. if (isHorizontal) {
  7024. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  7025. scaleLabelY = options.position === 'bottom'
  7026. ? me.bottom - halfLineHeight - scaleLabelPadding.bottom
  7027. : me.top + halfLineHeight + scaleLabelPadding.top;
  7028. } else {
  7029. var isLeft = options.position === 'left';
  7030. scaleLabelX = isLeft
  7031. ? me.left + halfLineHeight + scaleLabelPadding.top
  7032. : me.right - halfLineHeight - scaleLabelPadding.top;
  7033. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  7034. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  7035. }
  7036. context.save();
  7037. context.translate(scaleLabelX, scaleLabelY);
  7038. context.rotate(rotation);
  7039. context.textAlign = 'center';
  7040. context.textBaseline = 'middle';
  7041. context.fillStyle = scaleLabelFontColor; // render in correct colour
  7042. context.font = scaleLabelFont.font;
  7043. context.fillText(scaleLabel.labelString, 0, 0);
  7044. context.restore();
  7045. }
  7046. if (gridLines.drawBorder) {
  7047. // Draw the line at the edge of the axis
  7048. context.lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0);
  7049. context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
  7050. var x1 = me.left;
  7051. var x2 = me.right + axisWidth;
  7052. var y1 = me.top;
  7053. var y2 = me.bottom + axisWidth;
  7054. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  7055. if (isHorizontal) {
  7056. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  7057. y1 += aliasPixel;
  7058. y2 += aliasPixel;
  7059. } else {
  7060. x1 = x2 = options.position === 'left' ? me.right : me.left;
  7061. x1 += aliasPixel;
  7062. x2 += aliasPixel;
  7063. }
  7064. context.beginPath();
  7065. context.moveTo(x1, y1);
  7066. context.lineTo(x2, y2);
  7067. context.stroke();
  7068. }
  7069. }
  7070. });
  7071. },{"26":26,"27":27,"35":35,"46":46}],34:[function(require,module,exports){
  7072. 'use strict';
  7073. var defaults = require(26);
  7074. var helpers = require(46);
  7075. var layouts = require(31);
  7076. module.exports = {
  7077. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  7078. // use the new chart options to grab the correct scale
  7079. constructors: {},
  7080. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  7081. // old browsers
  7082. // Scale config defaults
  7083. defaults: {},
  7084. registerScaleType: function(type, scaleConstructor, scaleDefaults) {
  7085. this.constructors[type] = scaleConstructor;
  7086. this.defaults[type] = helpers.clone(scaleDefaults);
  7087. },
  7088. getScaleConstructor: function(type) {
  7089. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  7090. },
  7091. getScaleDefaults: function(type) {
  7092. // Return the scale defaults merged with the global settings so that we always use the latest ones
  7093. return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
  7094. },
  7095. updateScaleDefaults: function(type, additions) {
  7096. var me = this;
  7097. if (me.defaults.hasOwnProperty(type)) {
  7098. me.defaults[type] = helpers.extend(me.defaults[type], additions);
  7099. }
  7100. },
  7101. addScalesToLayout: function(chart) {
  7102. // Adds each scale to the chart.boxes array to be sized accordingly
  7103. helpers.each(chart.scales, function(scale) {
  7104. // Set ILayoutItem parameters for backwards compatibility
  7105. scale.fullWidth = scale.options.fullWidth;
  7106. scale.position = scale.options.position;
  7107. scale.weight = scale.options.weight;
  7108. layouts.addBox(chart, scale);
  7109. });
  7110. }
  7111. };
  7112. },{"26":26,"31":31,"46":46}],35:[function(require,module,exports){
  7113. 'use strict';
  7114. var helpers = require(46);
  7115. /**
  7116. * Namespace to hold static tick generation functions
  7117. * @namespace Chart.Ticks
  7118. */
  7119. module.exports = {
  7120. /**
  7121. * Namespace to hold formatters for different types of ticks
  7122. * @namespace Chart.Ticks.formatters
  7123. */
  7124. formatters: {
  7125. /**
  7126. * Formatter for value labels
  7127. * @method Chart.Ticks.formatters.values
  7128. * @param value the value to display
  7129. * @return {String|Array} the label to display
  7130. */
  7131. values: function(value) {
  7132. return helpers.isArray(value) ? value : '' + value;
  7133. },
  7134. /**
  7135. * Formatter for linear numeric ticks
  7136. * @method Chart.Ticks.formatters.linear
  7137. * @param tickValue {Number} the value to be formatted
  7138. * @param index {Number} the position of the tickValue parameter in the ticks array
  7139. * @param ticks {Array<Number>} the list of ticks being converted
  7140. * @return {String} string representation of the tickValue parameter
  7141. */
  7142. linear: function(tickValue, index, ticks) {
  7143. // If we have lots of ticks, don't use the ones
  7144. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  7145. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  7146. if (Math.abs(delta) > 1) {
  7147. if (tickValue !== Math.floor(tickValue)) {
  7148. // not an integer
  7149. delta = tickValue - Math.floor(tickValue);
  7150. }
  7151. }
  7152. var logDelta = helpers.log10(Math.abs(delta));
  7153. var tickString = '';
  7154. if (tickValue !== 0) {
  7155. var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1]));
  7156. if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation
  7157. var logTick = helpers.log10(Math.abs(tickValue));
  7158. tickString = tickValue.toExponential(Math.floor(logTick) - Math.floor(logDelta));
  7159. } else {
  7160. var numDecimal = -1 * Math.floor(logDelta);
  7161. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  7162. tickString = tickValue.toFixed(numDecimal);
  7163. }
  7164. } else {
  7165. tickString = '0'; // never show decimal places for 0
  7166. }
  7167. return tickString;
  7168. },
  7169. logarithmic: function(tickValue, index, ticks) {
  7170. var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
  7171. if (tickValue === 0) {
  7172. return '0';
  7173. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
  7174. return tickValue.toExponential();
  7175. }
  7176. return '';
  7177. }
  7178. }
  7179. };
  7180. },{"46":46}],36:[function(require,module,exports){
  7181. 'use strict';
  7182. var defaults = require(26);
  7183. var Element = require(27);
  7184. var helpers = require(46);
  7185. defaults._set('global', {
  7186. tooltips: {
  7187. enabled: true,
  7188. custom: null,
  7189. mode: 'nearest',
  7190. position: 'average',
  7191. intersect: true,
  7192. backgroundColor: 'rgba(0,0,0,0.8)',
  7193. titleFontStyle: 'bold',
  7194. titleSpacing: 2,
  7195. titleMarginBottom: 6,
  7196. titleFontColor: '#fff',
  7197. titleAlign: 'left',
  7198. bodySpacing: 2,
  7199. bodyFontColor: '#fff',
  7200. bodyAlign: 'left',
  7201. footerFontStyle: 'bold',
  7202. footerSpacing: 2,
  7203. footerMarginTop: 6,
  7204. footerFontColor: '#fff',
  7205. footerAlign: 'left',
  7206. yPadding: 6,
  7207. xPadding: 6,
  7208. caretPadding: 2,
  7209. caretSize: 5,
  7210. cornerRadius: 6,
  7211. multiKeyBackground: '#fff',
  7212. displayColors: true,
  7213. borderColor: 'rgba(0,0,0,0)',
  7214. borderWidth: 0,
  7215. callbacks: {
  7216. // Args are: (tooltipItems, data)
  7217. beforeTitle: helpers.noop,
  7218. title: function(tooltipItems, data) {
  7219. // Pick first xLabel for now
  7220. var title = '';
  7221. var labels = data.labels;
  7222. var labelCount = labels ? labels.length : 0;
  7223. if (tooltipItems.length > 0) {
  7224. var item = tooltipItems[0];
  7225. if (item.xLabel) {
  7226. title = item.xLabel;
  7227. } else if (labelCount > 0 && item.index < labelCount) {
  7228. title = labels[item.index];
  7229. }
  7230. }
  7231. return title;
  7232. },
  7233. afterTitle: helpers.noop,
  7234. // Args are: (tooltipItems, data)
  7235. beforeBody: helpers.noop,
  7236. // Args are: (tooltipItem, data)
  7237. beforeLabel: helpers.noop,
  7238. label: function(tooltipItem, data) {
  7239. var label = data.datasets[tooltipItem.datasetIndex].label || '';
  7240. if (label) {
  7241. label += ': ';
  7242. }
  7243. label += tooltipItem.yLabel;
  7244. return label;
  7245. },
  7246. labelColor: function(tooltipItem, chart) {
  7247. var meta = chart.getDatasetMeta(tooltipItem.datasetIndex);
  7248. var activeElement = meta.data[tooltipItem.index];
  7249. var view = activeElement._view;
  7250. return {
  7251. borderColor: view.borderColor,
  7252. backgroundColor: view.backgroundColor
  7253. };
  7254. },
  7255. labelTextColor: function() {
  7256. return this._options.bodyFontColor;
  7257. },
  7258. afterLabel: helpers.noop,
  7259. // Args are: (tooltipItems, data)
  7260. afterBody: helpers.noop,
  7261. // Args are: (tooltipItems, data)
  7262. beforeFooter: helpers.noop,
  7263. footer: helpers.noop,
  7264. afterFooter: helpers.noop
  7265. }
  7266. }
  7267. });
  7268. var positioners = {
  7269. /**
  7270. * Average mode places the tooltip at the average position of the elements shown
  7271. * @function Chart.Tooltip.positioners.average
  7272. * @param elements {ChartElement[]} the elements being displayed in the tooltip
  7273. * @returns {Point} tooltip position
  7274. */
  7275. average: function(elements) {
  7276. if (!elements.length) {
  7277. return false;
  7278. }
  7279. var i, len;
  7280. var x = 0;
  7281. var y = 0;
  7282. var count = 0;
  7283. for (i = 0, len = elements.length; i < len; ++i) {
  7284. var el = elements[i];
  7285. if (el && el.hasValue()) {
  7286. var pos = el.tooltipPosition();
  7287. x += pos.x;
  7288. y += pos.y;
  7289. ++count;
  7290. }
  7291. }
  7292. return {
  7293. x: Math.round(x / count),
  7294. y: Math.round(y / count)
  7295. };
  7296. },
  7297. /**
  7298. * Gets the tooltip position nearest of the item nearest to the event position
  7299. * @function Chart.Tooltip.positioners.nearest
  7300. * @param elements {Chart.Element[]} the tooltip elements
  7301. * @param eventPosition {Point} the position of the event in canvas coordinates
  7302. * @returns {Point} the tooltip position
  7303. */
  7304. nearest: function(elements, eventPosition) {
  7305. var x = eventPosition.x;
  7306. var y = eventPosition.y;
  7307. var minDistance = Number.POSITIVE_INFINITY;
  7308. var i, len, nearestElement;
  7309. for (i = 0, len = elements.length; i < len; ++i) {
  7310. var el = elements[i];
  7311. if (el && el.hasValue()) {
  7312. var center = el.getCenterPoint();
  7313. var d = helpers.distanceBetweenPoints(eventPosition, center);
  7314. if (d < minDistance) {
  7315. minDistance = d;
  7316. nearestElement = el;
  7317. }
  7318. }
  7319. }
  7320. if (nearestElement) {
  7321. var tp = nearestElement.tooltipPosition();
  7322. x = tp.x;
  7323. y = tp.y;
  7324. }
  7325. return {
  7326. x: x,
  7327. y: y
  7328. };
  7329. }
  7330. };
  7331. /**
  7332. * Helper method to merge the opacity into a color
  7333. */
  7334. function mergeOpacity(colorString, opacity) {
  7335. var color = helpers.color(colorString);
  7336. return color.alpha(opacity * color.alpha()).rgbaString();
  7337. }
  7338. // Helper to push or concat based on if the 2nd parameter is an array or not
  7339. function pushOrConcat(base, toPush) {
  7340. if (toPush) {
  7341. if (helpers.isArray(toPush)) {
  7342. // base = base.concat(toPush);
  7343. Array.prototype.push.apply(base, toPush);
  7344. } else {
  7345. base.push(toPush);
  7346. }
  7347. }
  7348. return base;
  7349. }
  7350. /**
  7351. * Returns array of strings split by newline
  7352. * @param {String} value - The value to split by newline.
  7353. * @returns {Array} value if newline present - Returned from String split() method
  7354. * @function
  7355. */
  7356. function splitNewlines(str) {
  7357. if ((typeof str === 'string' || str instanceof String) && str.indexOf('\n') > -1) {
  7358. return str.split('\n');
  7359. }
  7360. return str;
  7361. }
  7362. // Private helper to create a tooltip item model
  7363. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  7364. // @return : new tooltip item
  7365. function createTooltipItem(element) {
  7366. var xScale = element._xScale;
  7367. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  7368. var index = element._index;
  7369. var datasetIndex = element._datasetIndex;
  7370. return {
  7371. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  7372. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  7373. index: index,
  7374. datasetIndex: datasetIndex,
  7375. x: element._model.x,
  7376. y: element._model.y
  7377. };
  7378. }
  7379. /**
  7380. * Helper to get the reset model for the tooltip
  7381. * @param tooltipOpts {Object} the tooltip options
  7382. */
  7383. function getBaseModel(tooltipOpts) {
  7384. var globalDefaults = defaults.global;
  7385. var valueOrDefault = helpers.valueOrDefault;
  7386. return {
  7387. // Positioning
  7388. xPadding: tooltipOpts.xPadding,
  7389. yPadding: tooltipOpts.yPadding,
  7390. xAlign: tooltipOpts.xAlign,
  7391. yAlign: tooltipOpts.yAlign,
  7392. // Body
  7393. bodyFontColor: tooltipOpts.bodyFontColor,
  7394. _bodyFontFamily: valueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  7395. _bodyFontStyle: valueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  7396. _bodyAlign: tooltipOpts.bodyAlign,
  7397. bodyFontSize: valueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  7398. bodySpacing: tooltipOpts.bodySpacing,
  7399. // Title
  7400. titleFontColor: tooltipOpts.titleFontColor,
  7401. _titleFontFamily: valueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  7402. _titleFontStyle: valueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  7403. titleFontSize: valueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  7404. _titleAlign: tooltipOpts.titleAlign,
  7405. titleSpacing: tooltipOpts.titleSpacing,
  7406. titleMarginBottom: tooltipOpts.titleMarginBottom,
  7407. // Footer
  7408. footerFontColor: tooltipOpts.footerFontColor,
  7409. _footerFontFamily: valueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  7410. _footerFontStyle: valueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  7411. footerFontSize: valueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  7412. _footerAlign: tooltipOpts.footerAlign,
  7413. footerSpacing: tooltipOpts.footerSpacing,
  7414. footerMarginTop: tooltipOpts.footerMarginTop,
  7415. // Appearance
  7416. caretSize: tooltipOpts.caretSize,
  7417. cornerRadius: tooltipOpts.cornerRadius,
  7418. backgroundColor: tooltipOpts.backgroundColor,
  7419. opacity: 0,
  7420. legendColorBackground: tooltipOpts.multiKeyBackground,
  7421. displayColors: tooltipOpts.displayColors,
  7422. borderColor: tooltipOpts.borderColor,
  7423. borderWidth: tooltipOpts.borderWidth
  7424. };
  7425. }
  7426. /**
  7427. * Get the size of the tooltip
  7428. */
  7429. function getTooltipSize(tooltip, model) {
  7430. var ctx = tooltip._chart.ctx;
  7431. var height = model.yPadding * 2; // Tooltip Padding
  7432. var width = 0;
  7433. // Count of all lines in the body
  7434. var body = model.body;
  7435. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  7436. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7437. }, 0);
  7438. combinedBodyLength += model.beforeBody.length + model.afterBody.length;
  7439. var titleLineCount = model.title.length;
  7440. var footerLineCount = model.footer.length;
  7441. var titleFontSize = model.titleFontSize;
  7442. var bodyFontSize = model.bodyFontSize;
  7443. var footerFontSize = model.footerFontSize;
  7444. height += titleLineCount * titleFontSize; // Title Lines
  7445. height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
  7446. height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
  7447. height += combinedBodyLength * bodyFontSize; // Body Lines
  7448. height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
  7449. height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
  7450. height += footerLineCount * (footerFontSize); // Footer Lines
  7451. height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
  7452. // Title width
  7453. var widthPadding = 0;
  7454. var maxLineWidth = function(line) {
  7455. width = Math.max(width, ctx.measureText(line).width + widthPadding);
  7456. };
  7457. ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
  7458. helpers.each(model.title, maxLineWidth);
  7459. // Body width
  7460. ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
  7461. helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
  7462. // Body lines may include some extra width due to the color box
  7463. widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
  7464. helpers.each(body, function(bodyItem) {
  7465. helpers.each(bodyItem.before, maxLineWidth);
  7466. helpers.each(bodyItem.lines, maxLineWidth);
  7467. helpers.each(bodyItem.after, maxLineWidth);
  7468. });
  7469. // Reset back to 0
  7470. widthPadding = 0;
  7471. // Footer width
  7472. ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
  7473. helpers.each(model.footer, maxLineWidth);
  7474. // Add padding
  7475. width += 2 * model.xPadding;
  7476. return {
  7477. width: width,
  7478. height: height
  7479. };
  7480. }
  7481. /**
  7482. * Helper to get the alignment of a tooltip given the size
  7483. */
  7484. function determineAlignment(tooltip, size) {
  7485. var model = tooltip._model;
  7486. var chart = tooltip._chart;
  7487. var chartArea = tooltip._chart.chartArea;
  7488. var xAlign = 'center';
  7489. var yAlign = 'center';
  7490. if (model.y < size.height) {
  7491. yAlign = 'top';
  7492. } else if (model.y > (chart.height - size.height)) {
  7493. yAlign = 'bottom';
  7494. }
  7495. var lf, rf; // functions to determine left, right alignment
  7496. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7497. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7498. var midX = (chartArea.left + chartArea.right) / 2;
  7499. var midY = (chartArea.top + chartArea.bottom) / 2;
  7500. if (yAlign === 'center') {
  7501. lf = function(x) {
  7502. return x <= midX;
  7503. };
  7504. rf = function(x) {
  7505. return x > midX;
  7506. };
  7507. } else {
  7508. lf = function(x) {
  7509. return x <= (size.width / 2);
  7510. };
  7511. rf = function(x) {
  7512. return x >= (chart.width - (size.width / 2));
  7513. };
  7514. }
  7515. olf = function(x) {
  7516. return x + size.width + model.caretSize + model.caretPadding > chart.width;
  7517. };
  7518. orf = function(x) {
  7519. return x - size.width - model.caretSize - model.caretPadding < 0;
  7520. };
  7521. yf = function(y) {
  7522. return y <= midY ? 'top' : 'bottom';
  7523. };
  7524. if (lf(model.x)) {
  7525. xAlign = 'left';
  7526. // Is tooltip too wide and goes over the right side of the chart.?
  7527. if (olf(model.x)) {
  7528. xAlign = 'center';
  7529. yAlign = yf(model.y);
  7530. }
  7531. } else if (rf(model.x)) {
  7532. xAlign = 'right';
  7533. // Is tooltip too wide and goes outside left edge of canvas?
  7534. if (orf(model.x)) {
  7535. xAlign = 'center';
  7536. yAlign = yf(model.y);
  7537. }
  7538. }
  7539. var opts = tooltip._options;
  7540. return {
  7541. xAlign: opts.xAlign ? opts.xAlign : xAlign,
  7542. yAlign: opts.yAlign ? opts.yAlign : yAlign
  7543. };
  7544. }
  7545. /**
  7546. * Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
  7547. */
  7548. function getBackgroundPoint(vm, size, alignment, chart) {
  7549. // Background Position
  7550. var x = vm.x;
  7551. var y = vm.y;
  7552. var caretSize = vm.caretSize;
  7553. var caretPadding = vm.caretPadding;
  7554. var cornerRadius = vm.cornerRadius;
  7555. var xAlign = alignment.xAlign;
  7556. var yAlign = alignment.yAlign;
  7557. var paddingAndSize = caretSize + caretPadding;
  7558. var radiusAndPadding = cornerRadius + caretPadding;
  7559. if (xAlign === 'right') {
  7560. x -= size.width;
  7561. } else if (xAlign === 'center') {
  7562. x -= (size.width / 2);
  7563. if (x + size.width > chart.width) {
  7564. x = chart.width - size.width;
  7565. }
  7566. if (x < 0) {
  7567. x = 0;
  7568. }
  7569. }
  7570. if (yAlign === 'top') {
  7571. y += paddingAndSize;
  7572. } else if (yAlign === 'bottom') {
  7573. y -= size.height + paddingAndSize;
  7574. } else {
  7575. y -= (size.height / 2);
  7576. }
  7577. if (yAlign === 'center') {
  7578. if (xAlign === 'left') {
  7579. x += paddingAndSize;
  7580. } else if (xAlign === 'right') {
  7581. x -= paddingAndSize;
  7582. }
  7583. } else if (xAlign === 'left') {
  7584. x -= radiusAndPadding;
  7585. } else if (xAlign === 'right') {
  7586. x += radiusAndPadding;
  7587. }
  7588. return {
  7589. x: x,
  7590. y: y
  7591. };
  7592. }
  7593. /**
  7594. * Helper to build before and after body lines
  7595. */
  7596. function getBeforeAfterBodyLines(callback) {
  7597. return pushOrConcat([], splitNewlines(callback));
  7598. }
  7599. var exports = module.exports = Element.extend({
  7600. initialize: function() {
  7601. this._model = getBaseModel(this._options);
  7602. this._lastActive = [];
  7603. },
  7604. // Get the title
  7605. // Args are: (tooltipItem, data)
  7606. getTitle: function() {
  7607. var me = this;
  7608. var opts = me._options;
  7609. var callbacks = opts.callbacks;
  7610. var beforeTitle = callbacks.beforeTitle.apply(me, arguments);
  7611. var title = callbacks.title.apply(me, arguments);
  7612. var afterTitle = callbacks.afterTitle.apply(me, arguments);
  7613. var lines = [];
  7614. lines = pushOrConcat(lines, splitNewlines(beforeTitle));
  7615. lines = pushOrConcat(lines, splitNewlines(title));
  7616. lines = pushOrConcat(lines, splitNewlines(afterTitle));
  7617. return lines;
  7618. },
  7619. // Args are: (tooltipItem, data)
  7620. getBeforeBody: function() {
  7621. return getBeforeAfterBodyLines(this._options.callbacks.beforeBody.apply(this, arguments));
  7622. },
  7623. // Args are: (tooltipItem, data)
  7624. getBody: function(tooltipItems, data) {
  7625. var me = this;
  7626. var callbacks = me._options.callbacks;
  7627. var bodyItems = [];
  7628. helpers.each(tooltipItems, function(tooltipItem) {
  7629. var bodyItem = {
  7630. before: [],
  7631. lines: [],
  7632. after: []
  7633. };
  7634. pushOrConcat(bodyItem.before, splitNewlines(callbacks.beforeLabel.call(me, tooltipItem, data)));
  7635. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  7636. pushOrConcat(bodyItem.after, splitNewlines(callbacks.afterLabel.call(me, tooltipItem, data)));
  7637. bodyItems.push(bodyItem);
  7638. });
  7639. return bodyItems;
  7640. },
  7641. // Args are: (tooltipItem, data)
  7642. getAfterBody: function() {
  7643. return getBeforeAfterBodyLines(this._options.callbacks.afterBody.apply(this, arguments));
  7644. },
  7645. // Get the footer and beforeFooter and afterFooter lines
  7646. // Args are: (tooltipItem, data)
  7647. getFooter: function() {
  7648. var me = this;
  7649. var callbacks = me._options.callbacks;
  7650. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  7651. var footer = callbacks.footer.apply(me, arguments);
  7652. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  7653. var lines = [];
  7654. lines = pushOrConcat(lines, splitNewlines(beforeFooter));
  7655. lines = pushOrConcat(lines, splitNewlines(footer));
  7656. lines = pushOrConcat(lines, splitNewlines(afterFooter));
  7657. return lines;
  7658. },
  7659. update: function(changed) {
  7660. var me = this;
  7661. var opts = me._options;
  7662. // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
  7663. // 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
  7664. // which breaks any animations.
  7665. var existingModel = me._model;
  7666. var model = me._model = getBaseModel(opts);
  7667. var active = me._active;
  7668. var data = me._data;
  7669. // In the case where active.length === 0 we need to keep these at existing values for good animations
  7670. var alignment = {
  7671. xAlign: existingModel.xAlign,
  7672. yAlign: existingModel.yAlign
  7673. };
  7674. var backgroundPoint = {
  7675. x: existingModel.x,
  7676. y: existingModel.y
  7677. };
  7678. var tooltipSize = {
  7679. width: existingModel.width,
  7680. height: existingModel.height
  7681. };
  7682. var tooltipPosition = {
  7683. x: existingModel.caretX,
  7684. y: existingModel.caretY
  7685. };
  7686. var i, len;
  7687. if (active.length) {
  7688. model.opacity = 1;
  7689. var labelColors = [];
  7690. var labelTextColors = [];
  7691. tooltipPosition = positioners[opts.position].call(me, active, me._eventPosition);
  7692. var tooltipItems = [];
  7693. for (i = 0, len = active.length; i < len; ++i) {
  7694. tooltipItems.push(createTooltipItem(active[i]));
  7695. }
  7696. // If the user provided a filter function, use it to modify the tooltip items
  7697. if (opts.filter) {
  7698. tooltipItems = tooltipItems.filter(function(a) {
  7699. return opts.filter(a, data);
  7700. });
  7701. }
  7702. // If the user provided a sorting function, use it to modify the tooltip items
  7703. if (opts.itemSort) {
  7704. tooltipItems = tooltipItems.sort(function(a, b) {
  7705. return opts.itemSort(a, b, data);
  7706. });
  7707. }
  7708. // Determine colors for boxes
  7709. helpers.each(tooltipItems, function(tooltipItem) {
  7710. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart));
  7711. labelTextColors.push(opts.callbacks.labelTextColor.call(me, tooltipItem, me._chart));
  7712. });
  7713. // Build the Text Lines
  7714. model.title = me.getTitle(tooltipItems, data);
  7715. model.beforeBody = me.getBeforeBody(tooltipItems, data);
  7716. model.body = me.getBody(tooltipItems, data);
  7717. model.afterBody = me.getAfterBody(tooltipItems, data);
  7718. model.footer = me.getFooter(tooltipItems, data);
  7719. // Initial positioning and colors
  7720. model.x = Math.round(tooltipPosition.x);
  7721. model.y = Math.round(tooltipPosition.y);
  7722. model.caretPadding = opts.caretPadding;
  7723. model.labelColors = labelColors;
  7724. model.labelTextColors = labelTextColors;
  7725. // data points
  7726. model.dataPoints = tooltipItems;
  7727. // We need to determine alignment of the tooltip
  7728. tooltipSize = getTooltipSize(this, model);
  7729. alignment = determineAlignment(this, tooltipSize);
  7730. // Final Size and Position
  7731. backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
  7732. } else {
  7733. model.opacity = 0;
  7734. }
  7735. model.xAlign = alignment.xAlign;
  7736. model.yAlign = alignment.yAlign;
  7737. model.x = backgroundPoint.x;
  7738. model.y = backgroundPoint.y;
  7739. model.width = tooltipSize.width;
  7740. model.height = tooltipSize.height;
  7741. // Point where the caret on the tooltip points to
  7742. model.caretX = tooltipPosition.x;
  7743. model.caretY = tooltipPosition.y;
  7744. me._model = model;
  7745. if (changed && opts.custom) {
  7746. opts.custom.call(me, model);
  7747. }
  7748. return me;
  7749. },
  7750. drawCaret: function(tooltipPoint, size) {
  7751. var ctx = this._chart.ctx;
  7752. var vm = this._view;
  7753. var caretPosition = this.getCaretPosition(tooltipPoint, size, vm);
  7754. ctx.lineTo(caretPosition.x1, caretPosition.y1);
  7755. ctx.lineTo(caretPosition.x2, caretPosition.y2);
  7756. ctx.lineTo(caretPosition.x3, caretPosition.y3);
  7757. },
  7758. getCaretPosition: function(tooltipPoint, size, vm) {
  7759. var x1, x2, x3, y1, y2, y3;
  7760. var caretSize = vm.caretSize;
  7761. var cornerRadius = vm.cornerRadius;
  7762. var xAlign = vm.xAlign;
  7763. var yAlign = vm.yAlign;
  7764. var ptX = tooltipPoint.x;
  7765. var ptY = tooltipPoint.y;
  7766. var width = size.width;
  7767. var height = size.height;
  7768. if (yAlign === 'center') {
  7769. y2 = ptY + (height / 2);
  7770. if (xAlign === 'left') {
  7771. x1 = ptX;
  7772. x2 = x1 - caretSize;
  7773. x3 = x1;
  7774. y1 = y2 + caretSize;
  7775. y3 = y2 - caretSize;
  7776. } else {
  7777. x1 = ptX + width;
  7778. x2 = x1 + caretSize;
  7779. x3 = x1;
  7780. y1 = y2 - caretSize;
  7781. y3 = y2 + caretSize;
  7782. }
  7783. } else {
  7784. if (xAlign === 'left') {
  7785. x2 = ptX + cornerRadius + (caretSize);
  7786. x1 = x2 - caretSize;
  7787. x3 = x2 + caretSize;
  7788. } else if (xAlign === 'right') {
  7789. x2 = ptX + width - cornerRadius - caretSize;
  7790. x1 = x2 - caretSize;
  7791. x3 = x2 + caretSize;
  7792. } else {
  7793. x2 = vm.caretX;
  7794. x1 = x2 - caretSize;
  7795. x3 = x2 + caretSize;
  7796. }
  7797. if (yAlign === 'top') {
  7798. y1 = ptY;
  7799. y2 = y1 - caretSize;
  7800. y3 = y1;
  7801. } else {
  7802. y1 = ptY + height;
  7803. y2 = y1 + caretSize;
  7804. y3 = y1;
  7805. // invert drawing order
  7806. var tmp = x3;
  7807. x3 = x1;
  7808. x1 = tmp;
  7809. }
  7810. }
  7811. return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3};
  7812. },
  7813. drawTitle: function(pt, vm, ctx, opacity) {
  7814. var title = vm.title;
  7815. if (title.length) {
  7816. ctx.textAlign = vm._titleAlign;
  7817. ctx.textBaseline = 'top';
  7818. var titleFontSize = vm.titleFontSize;
  7819. var titleSpacing = vm.titleSpacing;
  7820. ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
  7821. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7822. var i, len;
  7823. for (i = 0, len = title.length; i < len; ++i) {
  7824. ctx.fillText(title[i], pt.x, pt.y);
  7825. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  7826. if (i + 1 === title.length) {
  7827. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  7828. }
  7829. }
  7830. }
  7831. },
  7832. drawBody: function(pt, vm, ctx, opacity) {
  7833. var bodyFontSize = vm.bodyFontSize;
  7834. var bodySpacing = vm.bodySpacing;
  7835. var body = vm.body;
  7836. ctx.textAlign = vm._bodyAlign;
  7837. ctx.textBaseline = 'top';
  7838. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7839. // Before Body
  7840. var xLinePadding = 0;
  7841. var fillLineOfText = function(line) {
  7842. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  7843. pt.y += bodyFontSize + bodySpacing;
  7844. };
  7845. // Before body lines
  7846. ctx.fillStyle = mergeOpacity(vm.bodyFontColor, opacity);
  7847. helpers.each(vm.beforeBody, fillLineOfText);
  7848. var drawColorBoxes = vm.displayColors;
  7849. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  7850. // Draw body lines now
  7851. helpers.each(body, function(bodyItem, i) {
  7852. var textColor = mergeOpacity(vm.labelTextColors[i], opacity);
  7853. ctx.fillStyle = textColor;
  7854. helpers.each(bodyItem.before, fillLineOfText);
  7855. helpers.each(bodyItem.lines, function(line) {
  7856. // Draw Legend-like boxes if needed
  7857. if (drawColorBoxes) {
  7858. // Fill a white rect so that colours merge nicely if the opacity is < 1
  7859. ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
  7860. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7861. // Border
  7862. ctx.lineWidth = 1;
  7863. ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
  7864. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7865. // Inner square
  7866. ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
  7867. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  7868. ctx.fillStyle = textColor;
  7869. }
  7870. fillLineOfText(line);
  7871. });
  7872. helpers.each(bodyItem.after, fillLineOfText);
  7873. });
  7874. // Reset back to 0 for after body
  7875. xLinePadding = 0;
  7876. // After body lines
  7877. helpers.each(vm.afterBody, fillLineOfText);
  7878. pt.y -= bodySpacing; // Remove last body spacing
  7879. },
  7880. drawFooter: function(pt, vm, ctx, opacity) {
  7881. var footer = vm.footer;
  7882. if (footer.length) {
  7883. pt.y += vm.footerMarginTop;
  7884. ctx.textAlign = vm._footerAlign;
  7885. ctx.textBaseline = 'top';
  7886. ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
  7887. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7888. helpers.each(footer, function(line) {
  7889. ctx.fillText(line, pt.x, pt.y);
  7890. pt.y += vm.footerFontSize + vm.footerSpacing;
  7891. });
  7892. }
  7893. },
  7894. drawBackground: function(pt, vm, ctx, tooltipSize, opacity) {
  7895. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  7896. ctx.strokeStyle = mergeOpacity(vm.borderColor, opacity);
  7897. ctx.lineWidth = vm.borderWidth;
  7898. var xAlign = vm.xAlign;
  7899. var yAlign = vm.yAlign;
  7900. var x = pt.x;
  7901. var y = pt.y;
  7902. var width = tooltipSize.width;
  7903. var height = tooltipSize.height;
  7904. var radius = vm.cornerRadius;
  7905. ctx.beginPath();
  7906. ctx.moveTo(x + radius, y);
  7907. if (yAlign === 'top') {
  7908. this.drawCaret(pt, tooltipSize);
  7909. }
  7910. ctx.lineTo(x + width - radius, y);
  7911. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  7912. if (yAlign === 'center' && xAlign === 'right') {
  7913. this.drawCaret(pt, tooltipSize);
  7914. }
  7915. ctx.lineTo(x + width, y + height - radius);
  7916. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  7917. if (yAlign === 'bottom') {
  7918. this.drawCaret(pt, tooltipSize);
  7919. }
  7920. ctx.lineTo(x + radius, y + height);
  7921. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  7922. if (yAlign === 'center' && xAlign === 'left') {
  7923. this.drawCaret(pt, tooltipSize);
  7924. }
  7925. ctx.lineTo(x, y + radius);
  7926. ctx.quadraticCurveTo(x, y, x + radius, y);
  7927. ctx.closePath();
  7928. ctx.fill();
  7929. if (vm.borderWidth > 0) {
  7930. ctx.stroke();
  7931. }
  7932. },
  7933. draw: function() {
  7934. var ctx = this._chart.ctx;
  7935. var vm = this._view;
  7936. if (vm.opacity === 0) {
  7937. return;
  7938. }
  7939. var tooltipSize = {
  7940. width: vm.width,
  7941. height: vm.height
  7942. };
  7943. var pt = {
  7944. x: vm.x,
  7945. y: vm.y
  7946. };
  7947. // IE11/Edge does not like very small opacities, so snap to 0
  7948. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  7949. // Truthy/falsey value for empty tooltip
  7950. var hasTooltipContent = vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length;
  7951. if (this._options.enabled && hasTooltipContent) {
  7952. // Draw Background
  7953. this.drawBackground(pt, vm, ctx, tooltipSize, opacity);
  7954. // Draw Title, Body, and Footer
  7955. pt.x += vm.xPadding;
  7956. pt.y += vm.yPadding;
  7957. // Titles
  7958. this.drawTitle(pt, vm, ctx, opacity);
  7959. // Body
  7960. this.drawBody(pt, vm, ctx, opacity);
  7961. // Footer
  7962. this.drawFooter(pt, vm, ctx, opacity);
  7963. }
  7964. },
  7965. /**
  7966. * Handle an event
  7967. * @private
  7968. * @param {IEvent} event - The event to handle
  7969. * @returns {Boolean} true if the tooltip changed
  7970. */
  7971. handleEvent: function(e) {
  7972. var me = this;
  7973. var options = me._options;
  7974. var changed = false;
  7975. me._lastActive = me._lastActive || [];
  7976. // Find Active Elements for tooltips
  7977. if (e.type === 'mouseout') {
  7978. me._active = [];
  7979. } else {
  7980. me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
  7981. }
  7982. // Remember Last Actives
  7983. changed = !helpers.arrayEquals(me._active, me._lastActive);
  7984. // Only handle target event on tooltip change
  7985. if (changed) {
  7986. me._lastActive = me._active;
  7987. if (options.enabled || options.custom) {
  7988. me._eventPosition = {
  7989. x: e.x,
  7990. y: e.y
  7991. };
  7992. me.update(true);
  7993. me.pivot();
  7994. }
  7995. }
  7996. return changed;
  7997. }
  7998. });
  7999. /**
  8000. * @namespace Chart.Tooltip.positioners
  8001. */
  8002. exports.positioners = positioners;
  8003. },{"26":26,"27":27,"46":46}],37:[function(require,module,exports){
  8004. 'use strict';
  8005. var defaults = require(26);
  8006. var Element = require(27);
  8007. var helpers = require(46);
  8008. defaults._set('global', {
  8009. elements: {
  8010. arc: {
  8011. backgroundColor: defaults.global.defaultColor,
  8012. borderColor: '#fff',
  8013. borderWidth: 2
  8014. }
  8015. }
  8016. });
  8017. module.exports = Element.extend({
  8018. inLabelRange: function(mouseX) {
  8019. var vm = this._view;
  8020. if (vm) {
  8021. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  8022. }
  8023. return false;
  8024. },
  8025. inRange: function(chartX, chartY) {
  8026. var vm = this._view;
  8027. if (vm) {
  8028. var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
  8029. var angle = pointRelativePosition.angle;
  8030. var distance = pointRelativePosition.distance;
  8031. // Sanitise angle range
  8032. var startAngle = vm.startAngle;
  8033. var endAngle = vm.endAngle;
  8034. while (endAngle < startAngle) {
  8035. endAngle += 2.0 * Math.PI;
  8036. }
  8037. while (angle > endAngle) {
  8038. angle -= 2.0 * Math.PI;
  8039. }
  8040. while (angle < startAngle) {
  8041. angle += 2.0 * Math.PI;
  8042. }
  8043. // Check if within the range of the open/close angle
  8044. var betweenAngles = (angle >= startAngle && angle <= endAngle);
  8045. var withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  8046. return (betweenAngles && withinRadius);
  8047. }
  8048. return false;
  8049. },
  8050. getCenterPoint: function() {
  8051. var vm = this._view;
  8052. var halfAngle = (vm.startAngle + vm.endAngle) / 2;
  8053. var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
  8054. return {
  8055. x: vm.x + Math.cos(halfAngle) * halfRadius,
  8056. y: vm.y + Math.sin(halfAngle) * halfRadius
  8057. };
  8058. },
  8059. getArea: function() {
  8060. var vm = this._view;
  8061. return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
  8062. },
  8063. tooltipPosition: function() {
  8064. var vm = this._view;
  8065. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
  8066. var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  8067. return {
  8068. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  8069. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  8070. };
  8071. },
  8072. draw: function() {
  8073. var ctx = this._chart.ctx;
  8074. var vm = this._view;
  8075. var sA = vm.startAngle;
  8076. var eA = vm.endAngle;
  8077. ctx.beginPath();
  8078. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  8079. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  8080. ctx.closePath();
  8081. ctx.strokeStyle = vm.borderColor;
  8082. ctx.lineWidth = vm.borderWidth;
  8083. ctx.fillStyle = vm.backgroundColor;
  8084. ctx.fill();
  8085. ctx.lineJoin = 'bevel';
  8086. if (vm.borderWidth) {
  8087. ctx.stroke();
  8088. }
  8089. }
  8090. });
  8091. },{"26":26,"27":27,"46":46}],38:[function(require,module,exports){
  8092. 'use strict';
  8093. var defaults = require(26);
  8094. var Element = require(27);
  8095. var helpers = require(46);
  8096. var globalDefaults = defaults.global;
  8097. defaults._set('global', {
  8098. elements: {
  8099. line: {
  8100. tension: 0.4,
  8101. backgroundColor: globalDefaults.defaultColor,
  8102. borderWidth: 3,
  8103. borderColor: globalDefaults.defaultColor,
  8104. borderCapStyle: 'butt',
  8105. borderDash: [],
  8106. borderDashOffset: 0.0,
  8107. borderJoinStyle: 'miter',
  8108. capBezierPoints: true,
  8109. fill: true, // do we fill in the area between the line and its base axis
  8110. }
  8111. }
  8112. });
  8113. module.exports = Element.extend({
  8114. draw: function() {
  8115. var me = this;
  8116. var vm = me._view;
  8117. var ctx = me._chart.ctx;
  8118. var spanGaps = vm.spanGaps;
  8119. var points = me._children.slice(); // clone array
  8120. var globalOptionLineElements = globalDefaults.elements.line;
  8121. var lastDrawnIndex = -1;
  8122. var index, current, previous, currentVM;
  8123. // If we are looping, adding the first point again
  8124. if (me._loop && points.length) {
  8125. points.push(points[0]);
  8126. }
  8127. ctx.save();
  8128. // Stroke Line Options
  8129. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  8130. // IE 9 and 10 do not support line dash
  8131. if (ctx.setLineDash) {
  8132. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  8133. }
  8134. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  8135. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  8136. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  8137. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  8138. // Stroke Line
  8139. ctx.beginPath();
  8140. lastDrawnIndex = -1;
  8141. for (index = 0; index < points.length; ++index) {
  8142. current = points[index];
  8143. previous = helpers.previousItem(points, index);
  8144. currentVM = current._view;
  8145. // First point moves to it's starting position no matter what
  8146. if (index === 0) {
  8147. if (!currentVM.skip) {
  8148. ctx.moveTo(currentVM.x, currentVM.y);
  8149. lastDrawnIndex = index;
  8150. }
  8151. } else {
  8152. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  8153. if (!currentVM.skip) {
  8154. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  8155. // There was a gap and this is the first point after the gap
  8156. ctx.moveTo(currentVM.x, currentVM.y);
  8157. } else {
  8158. // Line to next point
  8159. helpers.canvas.lineTo(ctx, previous._view, current._view);
  8160. }
  8161. lastDrawnIndex = index;
  8162. }
  8163. }
  8164. }
  8165. ctx.stroke();
  8166. ctx.restore();
  8167. }
  8168. });
  8169. },{"26":26,"27":27,"46":46}],39:[function(require,module,exports){
  8170. 'use strict';
  8171. var defaults = require(26);
  8172. var Element = require(27);
  8173. var helpers = require(46);
  8174. var defaultColor = defaults.global.defaultColor;
  8175. defaults._set('global', {
  8176. elements: {
  8177. point: {
  8178. radius: 3,
  8179. pointStyle: 'circle',
  8180. backgroundColor: defaultColor,
  8181. borderColor: defaultColor,
  8182. borderWidth: 1,
  8183. // Hover
  8184. hitRadius: 1,
  8185. hoverRadius: 4,
  8186. hoverBorderWidth: 1
  8187. }
  8188. }
  8189. });
  8190. function xRange(mouseX) {
  8191. var vm = this._view;
  8192. return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
  8193. }
  8194. function yRange(mouseY) {
  8195. var vm = this._view;
  8196. return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false;
  8197. }
  8198. module.exports = Element.extend({
  8199. inRange: function(mouseX, mouseY) {
  8200. var vm = this._view;
  8201. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  8202. },
  8203. inLabelRange: xRange,
  8204. inXRange: xRange,
  8205. inYRange: yRange,
  8206. getCenterPoint: function() {
  8207. var vm = this._view;
  8208. return {
  8209. x: vm.x,
  8210. y: vm.y
  8211. };
  8212. },
  8213. getArea: function() {
  8214. return Math.PI * Math.pow(this._view.radius, 2);
  8215. },
  8216. tooltipPosition: function() {
  8217. var vm = this._view;
  8218. return {
  8219. x: vm.x,
  8220. y: vm.y,
  8221. padding: vm.radius + vm.borderWidth
  8222. };
  8223. },
  8224. draw: function(chartArea) {
  8225. var vm = this._view;
  8226. var model = this._model;
  8227. var ctx = this._chart.ctx;
  8228. var pointStyle = vm.pointStyle;
  8229. var rotation = vm.rotation;
  8230. var radius = vm.radius;
  8231. var x = vm.x;
  8232. var y = vm.y;
  8233. var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)
  8234. if (vm.skip) {
  8235. return;
  8236. }
  8237. // Clipping for Points.
  8238. if (chartArea === undefined || (model.x >= chartArea.left && chartArea.right * errMargin >= model.x && model.y >= chartArea.top && chartArea.bottom * errMargin >= model.y)) {
  8239. ctx.strokeStyle = vm.borderColor || defaultColor;
  8240. ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
  8241. ctx.fillStyle = vm.backgroundColor || defaultColor;
  8242. helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y, rotation);
  8243. }
  8244. }
  8245. });
  8246. },{"26":26,"27":27,"46":46}],40:[function(require,module,exports){
  8247. 'use strict';
  8248. var defaults = require(26);
  8249. var Element = require(27);
  8250. defaults._set('global', {
  8251. elements: {
  8252. rectangle: {
  8253. backgroundColor: defaults.global.defaultColor,
  8254. borderColor: defaults.global.defaultColor,
  8255. borderSkipped: 'bottom',
  8256. borderWidth: 0
  8257. }
  8258. }
  8259. });
  8260. function isVertical(bar) {
  8261. return bar._view.width !== undefined;
  8262. }
  8263. /**
  8264. * Helper function to get the bounds of the bar regardless of the orientation
  8265. * @param bar {Chart.Element.Rectangle} the bar
  8266. * @return {Bounds} bounds of the bar
  8267. * @private
  8268. */
  8269. function getBarBounds(bar) {
  8270. var vm = bar._view;
  8271. var x1, x2, y1, y2;
  8272. if (isVertical(bar)) {
  8273. // vertical
  8274. var halfWidth = vm.width / 2;
  8275. x1 = vm.x - halfWidth;
  8276. x2 = vm.x + halfWidth;
  8277. y1 = Math.min(vm.y, vm.base);
  8278. y2 = Math.max(vm.y, vm.base);
  8279. } else {
  8280. // horizontal bar
  8281. var halfHeight = vm.height / 2;
  8282. x1 = Math.min(vm.x, vm.base);
  8283. x2 = Math.max(vm.x, vm.base);
  8284. y1 = vm.y - halfHeight;
  8285. y2 = vm.y + halfHeight;
  8286. }
  8287. return {
  8288. left: x1,
  8289. top: y1,
  8290. right: x2,
  8291. bottom: y2
  8292. };
  8293. }
  8294. module.exports = Element.extend({
  8295. draw: function() {
  8296. var ctx = this._chart.ctx;
  8297. var vm = this._view;
  8298. var left, right, top, bottom, signX, signY, borderSkipped;
  8299. var borderWidth = vm.borderWidth;
  8300. if (!vm.horizontal) {
  8301. // bar
  8302. left = vm.x - vm.width / 2;
  8303. right = vm.x + vm.width / 2;
  8304. top = vm.y;
  8305. bottom = vm.base;
  8306. signX = 1;
  8307. signY = bottom > top ? 1 : -1;
  8308. borderSkipped = vm.borderSkipped || 'bottom';
  8309. } else {
  8310. // horizontal bar
  8311. left = vm.base;
  8312. right = vm.x;
  8313. top = vm.y - vm.height / 2;
  8314. bottom = vm.y + vm.height / 2;
  8315. signX = right > left ? 1 : -1;
  8316. signY = 1;
  8317. borderSkipped = vm.borderSkipped || 'left';
  8318. }
  8319. // Canvas doesn't allow us to stroke inside the width so we can
  8320. // adjust the sizes to fit if we're setting a stroke on the line
  8321. if (borderWidth) {
  8322. // borderWidth shold be less than bar width and bar height.
  8323. var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
  8324. borderWidth = borderWidth > barSize ? barSize : borderWidth;
  8325. var halfStroke = borderWidth / 2;
  8326. // Adjust borderWidth when bar top position is near vm.base(zero).
  8327. var borderLeft = left + (borderSkipped !== 'left' ? halfStroke * signX : 0);
  8328. var borderRight = right + (borderSkipped !== 'right' ? -halfStroke * signX : 0);
  8329. var borderTop = top + (borderSkipped !== 'top' ? halfStroke * signY : 0);
  8330. var borderBottom = bottom + (borderSkipped !== 'bottom' ? -halfStroke * signY : 0);
  8331. // not become a vertical line?
  8332. if (borderLeft !== borderRight) {
  8333. top = borderTop;
  8334. bottom = borderBottom;
  8335. }
  8336. // not become a horizontal line?
  8337. if (borderTop !== borderBottom) {
  8338. left = borderLeft;
  8339. right = borderRight;
  8340. }
  8341. }
  8342. ctx.beginPath();
  8343. ctx.fillStyle = vm.backgroundColor;
  8344. ctx.strokeStyle = vm.borderColor;
  8345. ctx.lineWidth = borderWidth;
  8346. // Corner points, from bottom-left to bottom-right clockwise
  8347. // | 1 2 |
  8348. // | 0 3 |
  8349. var corners = [
  8350. [left, bottom],
  8351. [left, top],
  8352. [right, top],
  8353. [right, bottom]
  8354. ];
  8355. // Find first (starting) corner with fallback to 'bottom'
  8356. var borders = ['bottom', 'left', 'top', 'right'];
  8357. var startCorner = borders.indexOf(borderSkipped, 0);
  8358. if (startCorner === -1) {
  8359. startCorner = 0;
  8360. }
  8361. function cornerAt(index) {
  8362. return corners[(startCorner + index) % 4];
  8363. }
  8364. // Draw rectangle from 'startCorner'
  8365. var corner = cornerAt(0);
  8366. ctx.moveTo(corner[0], corner[1]);
  8367. for (var i = 1; i < 4; i++) {
  8368. corner = cornerAt(i);
  8369. ctx.lineTo(corner[0], corner[1]);
  8370. }
  8371. ctx.fill();
  8372. if (borderWidth) {
  8373. ctx.stroke();
  8374. }
  8375. },
  8376. height: function() {
  8377. var vm = this._view;
  8378. return vm.base - vm.y;
  8379. },
  8380. inRange: function(mouseX, mouseY) {
  8381. var inRange = false;
  8382. if (this._view) {
  8383. var bounds = getBarBounds(this);
  8384. inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
  8385. }
  8386. return inRange;
  8387. },
  8388. inLabelRange: function(mouseX, mouseY) {
  8389. var me = this;
  8390. if (!me._view) {
  8391. return false;
  8392. }
  8393. var inRange = false;
  8394. var bounds = getBarBounds(me);
  8395. if (isVertical(me)) {
  8396. inRange = mouseX >= bounds.left && mouseX <= bounds.right;
  8397. } else {
  8398. inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
  8399. }
  8400. return inRange;
  8401. },
  8402. inXRange: function(mouseX) {
  8403. var bounds = getBarBounds(this);
  8404. return mouseX >= bounds.left && mouseX <= bounds.right;
  8405. },
  8406. inYRange: function(mouseY) {
  8407. var bounds = getBarBounds(this);
  8408. return mouseY >= bounds.top && mouseY <= bounds.bottom;
  8409. },
  8410. getCenterPoint: function() {
  8411. var vm = this._view;
  8412. var x, y;
  8413. if (isVertical(this)) {
  8414. x = vm.x;
  8415. y = (vm.y + vm.base) / 2;
  8416. } else {
  8417. x = (vm.x + vm.base) / 2;
  8418. y = vm.y;
  8419. }
  8420. return {x: x, y: y};
  8421. },
  8422. getArea: function() {
  8423. var vm = this._view;
  8424. return vm.width * Math.abs(vm.y - vm.base);
  8425. },
  8426. tooltipPosition: function() {
  8427. var vm = this._view;
  8428. return {
  8429. x: vm.x,
  8430. y: vm.y
  8431. };
  8432. }
  8433. });
  8434. },{"26":26,"27":27}],41:[function(require,module,exports){
  8435. 'use strict';
  8436. module.exports = {};
  8437. module.exports.Arc = require(37);
  8438. module.exports.Line = require(38);
  8439. module.exports.Point = require(39);
  8440. module.exports.Rectangle = require(40);
  8441. },{"37":37,"38":38,"39":39,"40":40}],42:[function(require,module,exports){
  8442. 'use strict';
  8443. var helpers = require(43);
  8444. /**
  8445. * @namespace Chart.helpers.canvas
  8446. */
  8447. var exports = module.exports = {
  8448. /**
  8449. * Clears the entire canvas associated to the given `chart`.
  8450. * @param {Chart} chart - The chart for which to clear the canvas.
  8451. */
  8452. clear: function(chart) {
  8453. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  8454. },
  8455. /**
  8456. * Creates a "path" for a rectangle with rounded corners at position (x, y) with a
  8457. * given size (width, height) and the same `radius` for all corners.
  8458. * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context.
  8459. * @param {Number} x - The x axis of the coordinate for the rectangle starting point.
  8460. * @param {Number} y - The y axis of the coordinate for the rectangle starting point.
  8461. * @param {Number} width - The rectangle's width.
  8462. * @param {Number} height - The rectangle's height.
  8463. * @param {Number} radius - The rounded amount (in pixels) for the four corners.
  8464. * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
  8465. */
  8466. roundedRect: function(ctx, x, y, width, height, radius) {
  8467. if (radius) {
  8468. // NOTE(SB) `epsilon` helps to prevent minor artifacts appearing
  8469. // on Chrome when `r` is exactly half the height or the width.
  8470. var epsilon = 0.0000001;
  8471. var r = Math.min(radius, (height / 2) - epsilon, (width / 2) - epsilon);
  8472. ctx.moveTo(x + r, y);
  8473. ctx.lineTo(x + width - r, y);
  8474. ctx.arcTo(x + width, y, x + width, y + r, r);
  8475. ctx.lineTo(x + width, y + height - r);
  8476. ctx.arcTo(x + width, y + height, x + width - r, y + height, r);
  8477. ctx.lineTo(x + r, y + height);
  8478. ctx.arcTo(x, y + height, x, y + height - r, r);
  8479. ctx.lineTo(x, y + r);
  8480. ctx.arcTo(x, y, x + r, y, r);
  8481. ctx.closePath();
  8482. ctx.moveTo(x, y);
  8483. } else {
  8484. ctx.rect(x, y, width, height);
  8485. }
  8486. },
  8487. drawPoint: function(ctx, style, radius, x, y, rotation) {
  8488. var type, edgeLength, xOffset, yOffset, height, size;
  8489. rotation = rotation || 0;
  8490. if (style && typeof style === 'object') {
  8491. type = style.toString();
  8492. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  8493. ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
  8494. return;
  8495. }
  8496. }
  8497. if (isNaN(radius) || radius <= 0) {
  8498. return;
  8499. }
  8500. ctx.save();
  8501. ctx.translate(x, y);
  8502. ctx.rotate(rotation * Math.PI / 180);
  8503. ctx.beginPath();
  8504. switch (style) {
  8505. // Default includes circle
  8506. default:
  8507. ctx.arc(0, 0, radius, 0, Math.PI * 2);
  8508. ctx.closePath();
  8509. break;
  8510. case 'triangle':
  8511. edgeLength = 3 * radius / Math.sqrt(3);
  8512. height = edgeLength * Math.sqrt(3) / 2;
  8513. ctx.moveTo(-edgeLength / 2, height / 3);
  8514. ctx.lineTo(edgeLength / 2, height / 3);
  8515. ctx.lineTo(0, -2 * height / 3);
  8516. ctx.closePath();
  8517. break;
  8518. case 'rect':
  8519. size = 1 / Math.SQRT2 * radius;
  8520. ctx.rect(-size, -size, 2 * size, 2 * size);
  8521. break;
  8522. case 'rectRounded':
  8523. var offset = radius / Math.SQRT2;
  8524. var leftX = -offset;
  8525. var topY = -offset;
  8526. var sideSize = Math.SQRT2 * radius;
  8527. // NOTE(SB) the rounded rect implementation changed to use `arcTo`
  8528. // instead of `quadraticCurveTo` since it generates better results
  8529. // when rect is almost a circle. 0.425 (instead of 0.5) produces
  8530. // results visually closer to the previous impl.
  8531. this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius * 0.425);
  8532. break;
  8533. case 'rectRot':
  8534. size = 1 / Math.SQRT2 * radius;
  8535. ctx.moveTo(-size, 0);
  8536. ctx.lineTo(0, size);
  8537. ctx.lineTo(size, 0);
  8538. ctx.lineTo(0, -size);
  8539. ctx.closePath();
  8540. break;
  8541. case 'cross':
  8542. ctx.moveTo(0, radius);
  8543. ctx.lineTo(0, -radius);
  8544. ctx.moveTo(-radius, 0);
  8545. ctx.lineTo(radius, 0);
  8546. break;
  8547. case 'crossRot':
  8548. xOffset = Math.cos(Math.PI / 4) * radius;
  8549. yOffset = Math.sin(Math.PI / 4) * radius;
  8550. ctx.moveTo(-xOffset, -yOffset);
  8551. ctx.lineTo(xOffset, yOffset);
  8552. ctx.moveTo(-xOffset, yOffset);
  8553. ctx.lineTo(xOffset, -yOffset);
  8554. break;
  8555. case 'star':
  8556. ctx.moveTo(0, radius);
  8557. ctx.lineTo(0, -radius);
  8558. ctx.moveTo(-radius, 0);
  8559. ctx.lineTo(radius, 0);
  8560. xOffset = Math.cos(Math.PI / 4) * radius;
  8561. yOffset = Math.sin(Math.PI / 4) * radius;
  8562. ctx.moveTo(-xOffset, -yOffset);
  8563. ctx.lineTo(xOffset, yOffset);
  8564. ctx.moveTo(-xOffset, yOffset);
  8565. ctx.lineTo(xOffset, -yOffset);
  8566. break;
  8567. case 'line':
  8568. ctx.moveTo(-radius, 0);
  8569. ctx.lineTo(radius, 0);
  8570. break;
  8571. case 'dash':
  8572. ctx.moveTo(0, 0);
  8573. ctx.lineTo(radius, 0);
  8574. break;
  8575. }
  8576. ctx.fill();
  8577. ctx.stroke();
  8578. ctx.restore();
  8579. },
  8580. clipArea: function(ctx, area) {
  8581. ctx.save();
  8582. ctx.beginPath();
  8583. ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
  8584. ctx.clip();
  8585. },
  8586. unclipArea: function(ctx) {
  8587. ctx.restore();
  8588. },
  8589. lineTo: function(ctx, previous, target, flip) {
  8590. if (target.steppedLine) {
  8591. if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
  8592. ctx.lineTo(previous.x, target.y);
  8593. } else {
  8594. ctx.lineTo(target.x, previous.y);
  8595. }
  8596. ctx.lineTo(target.x, target.y);
  8597. return;
  8598. }
  8599. if (!target.tension) {
  8600. ctx.lineTo(target.x, target.y);
  8601. return;
  8602. }
  8603. ctx.bezierCurveTo(
  8604. flip ? previous.controlPointPreviousX : previous.controlPointNextX,
  8605. flip ? previous.controlPointPreviousY : previous.controlPointNextY,
  8606. flip ? target.controlPointNextX : target.controlPointPreviousX,
  8607. flip ? target.controlPointNextY : target.controlPointPreviousY,
  8608. target.x,
  8609. target.y);
  8610. }
  8611. };
  8612. // DEPRECATIONS
  8613. /**
  8614. * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
  8615. * @namespace Chart.helpers.clear
  8616. * @deprecated since version 2.7.0
  8617. * @todo remove at version 3
  8618. * @private
  8619. */
  8620. helpers.clear = exports.clear;
  8621. /**
  8622. * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
  8623. * @namespace Chart.helpers.drawRoundedRectangle
  8624. * @deprecated since version 2.7.0
  8625. * @todo remove at version 3
  8626. * @private
  8627. */
  8628. helpers.drawRoundedRectangle = function(ctx) {
  8629. ctx.beginPath();
  8630. exports.roundedRect.apply(exports, arguments);
  8631. };
  8632. },{"43":43}],43:[function(require,module,exports){
  8633. 'use strict';
  8634. /**
  8635. * @namespace Chart.helpers
  8636. */
  8637. var helpers = {
  8638. /**
  8639. * An empty function that can be used, for example, for optional callback.
  8640. */
  8641. noop: function() {},
  8642. /**
  8643. * Returns a unique id, sequentially generated from a global variable.
  8644. * @returns {Number}
  8645. * @function
  8646. */
  8647. uid: (function() {
  8648. var id = 0;
  8649. return function() {
  8650. return id++;
  8651. };
  8652. }()),
  8653. /**
  8654. * Returns true if `value` is neither null nor undefined, else returns false.
  8655. * @param {*} value - The value to test.
  8656. * @returns {Boolean}
  8657. * @since 2.7.0
  8658. */
  8659. isNullOrUndef: function(value) {
  8660. return value === null || typeof value === 'undefined';
  8661. },
  8662. /**
  8663. * Returns true if `value` is an array, else returns false.
  8664. * @param {*} value - The value to test.
  8665. * @returns {Boolean}
  8666. * @function
  8667. */
  8668. isArray: Array.isArray ? Array.isArray : function(value) {
  8669. return Object.prototype.toString.call(value) === '[object Array]';
  8670. },
  8671. /**
  8672. * Returns true if `value` is an object (excluding null), else returns false.
  8673. * @param {*} value - The value to test.
  8674. * @returns {Boolean}
  8675. * @since 2.7.0
  8676. */
  8677. isObject: function(value) {
  8678. return value !== null && Object.prototype.toString.call(value) === '[object Object]';
  8679. },
  8680. /**
  8681. * Returns `value` if defined, else returns `defaultValue`.
  8682. * @param {*} value - The value to return if defined.
  8683. * @param {*} defaultValue - The value to return if `value` is undefined.
  8684. * @returns {*}
  8685. */
  8686. valueOrDefault: function(value, defaultValue) {
  8687. return typeof value === 'undefined' ? defaultValue : value;
  8688. },
  8689. /**
  8690. * Returns value at the given `index` in array if defined, else returns `defaultValue`.
  8691. * @param {Array} value - The array to lookup for value at `index`.
  8692. * @param {Number} index - The index in `value` to lookup for value.
  8693. * @param {*} defaultValue - The value to return if `value[index]` is undefined.
  8694. * @returns {*}
  8695. */
  8696. valueAtIndexOrDefault: function(value, index, defaultValue) {
  8697. return helpers.valueOrDefault(helpers.isArray(value) ? value[index] : value, defaultValue);
  8698. },
  8699. /**
  8700. * Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
  8701. * value returned by `fn`. If `fn` is not a function, this method returns undefined.
  8702. * @param {Function} fn - The function to call.
  8703. * @param {Array|undefined|null} args - The arguments with which `fn` should be called.
  8704. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8705. * @returns {*}
  8706. */
  8707. callback: function(fn, args, thisArg) {
  8708. if (fn && typeof fn.call === 'function') {
  8709. return fn.apply(thisArg, args);
  8710. }
  8711. },
  8712. /**
  8713. * Note(SB) for performance sake, this method should only be used when loopable type
  8714. * is unknown or in none intensive code (not called often and small loopable). Else
  8715. * it's preferable to use a regular for() loop and save extra function calls.
  8716. * @param {Object|Array} loopable - The object or array to be iterated.
  8717. * @param {Function} fn - The function to call for each item.
  8718. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8719. * @param {Boolean} [reverse] - If true, iterates backward on the loopable.
  8720. */
  8721. each: function(loopable, fn, thisArg, reverse) {
  8722. var i, len, keys;
  8723. if (helpers.isArray(loopable)) {
  8724. len = loopable.length;
  8725. if (reverse) {
  8726. for (i = len - 1; i >= 0; i--) {
  8727. fn.call(thisArg, loopable[i], i);
  8728. }
  8729. } else {
  8730. for (i = 0; i < len; i++) {
  8731. fn.call(thisArg, loopable[i], i);
  8732. }
  8733. }
  8734. } else if (helpers.isObject(loopable)) {
  8735. keys = Object.keys(loopable);
  8736. len = keys.length;
  8737. for (i = 0; i < len; i++) {
  8738. fn.call(thisArg, loopable[keys[i]], keys[i]);
  8739. }
  8740. }
  8741. },
  8742. /**
  8743. * Returns true if the `a0` and `a1` arrays have the same content, else returns false.
  8744. * @see http://stackoverflow.com/a/14853974
  8745. * @param {Array} a0 - The array to compare
  8746. * @param {Array} a1 - The array to compare
  8747. * @returns {Boolean}
  8748. */
  8749. arrayEquals: function(a0, a1) {
  8750. var i, ilen, v0, v1;
  8751. if (!a0 || !a1 || a0.length !== a1.length) {
  8752. return false;
  8753. }
  8754. for (i = 0, ilen = a0.length; i < ilen; ++i) {
  8755. v0 = a0[i];
  8756. v1 = a1[i];
  8757. if (v0 instanceof Array && v1 instanceof Array) {
  8758. if (!helpers.arrayEquals(v0, v1)) {
  8759. return false;
  8760. }
  8761. } else if (v0 !== v1) {
  8762. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  8763. return false;
  8764. }
  8765. }
  8766. return true;
  8767. },
  8768. /**
  8769. * Returns a deep copy of `source` without keeping references on objects and arrays.
  8770. * @param {*} source - The value to clone.
  8771. * @returns {*}
  8772. */
  8773. clone: function(source) {
  8774. if (helpers.isArray(source)) {
  8775. return source.map(helpers.clone);
  8776. }
  8777. if (helpers.isObject(source)) {
  8778. var target = {};
  8779. var keys = Object.keys(source);
  8780. var klen = keys.length;
  8781. var k = 0;
  8782. for (; k < klen; ++k) {
  8783. target[keys[k]] = helpers.clone(source[keys[k]]);
  8784. }
  8785. return target;
  8786. }
  8787. return source;
  8788. },
  8789. /**
  8790. * The default merger when Chart.helpers.merge is called without merger option.
  8791. * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
  8792. * @private
  8793. */
  8794. _merger: function(key, target, source, options) {
  8795. var tval = target[key];
  8796. var sval = source[key];
  8797. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8798. helpers.merge(tval, sval, options);
  8799. } else {
  8800. target[key] = helpers.clone(sval);
  8801. }
  8802. },
  8803. /**
  8804. * Merges source[key] in target[key] only if target[key] is undefined.
  8805. * @private
  8806. */
  8807. _mergerIf: function(key, target, source) {
  8808. var tval = target[key];
  8809. var sval = source[key];
  8810. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8811. helpers.mergeIf(tval, sval);
  8812. } else if (!target.hasOwnProperty(key)) {
  8813. target[key] = helpers.clone(sval);
  8814. }
  8815. },
  8816. /**
  8817. * Recursively deep copies `source` properties into `target` with the given `options`.
  8818. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8819. * @param {Object} target - The target object in which all sources are merged into.
  8820. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8821. * @param {Object} [options] - Merging options:
  8822. * @param {Function} [options.merger] - The merge method (key, target, source, options)
  8823. * @returns {Object} The `target` object.
  8824. */
  8825. merge: function(target, source, options) {
  8826. var sources = helpers.isArray(source) ? source : [source];
  8827. var ilen = sources.length;
  8828. var merge, i, keys, klen, k;
  8829. if (!helpers.isObject(target)) {
  8830. return target;
  8831. }
  8832. options = options || {};
  8833. merge = options.merger || helpers._merger;
  8834. for (i = 0; i < ilen; ++i) {
  8835. source = sources[i];
  8836. if (!helpers.isObject(source)) {
  8837. continue;
  8838. }
  8839. keys = Object.keys(source);
  8840. for (k = 0, klen = keys.length; k < klen; ++k) {
  8841. merge(keys[k], target, source, options);
  8842. }
  8843. }
  8844. return target;
  8845. },
  8846. /**
  8847. * Recursively deep copies `source` properties into `target` *only* if not defined in target.
  8848. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8849. * @param {Object} target - The target object in which all sources are merged into.
  8850. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8851. * @returns {Object} The `target` object.
  8852. */
  8853. mergeIf: function(target, source) {
  8854. return helpers.merge(target, source, {merger: helpers._mergerIf});
  8855. },
  8856. /**
  8857. * Applies the contents of two or more objects together into the first object.
  8858. * @param {Object} target - The target object in which all objects are merged into.
  8859. * @param {Object} arg1 - Object containing additional properties to merge in target.
  8860. * @param {Object} argN - Additional objects containing properties to merge in target.
  8861. * @returns {Object} The `target` object.
  8862. */
  8863. extend: function(target) {
  8864. var setFn = function(value, key) {
  8865. target[key] = value;
  8866. };
  8867. for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
  8868. helpers.each(arguments[i], setFn);
  8869. }
  8870. return target;
  8871. },
  8872. /**
  8873. * Basic javascript inheritance based on the model created in Backbone.js
  8874. */
  8875. inherits: function(extensions) {
  8876. var me = this;
  8877. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
  8878. return me.apply(this, arguments);
  8879. };
  8880. var Surrogate = function() {
  8881. this.constructor = ChartElement;
  8882. };
  8883. Surrogate.prototype = me.prototype;
  8884. ChartElement.prototype = new Surrogate();
  8885. ChartElement.extend = helpers.inherits;
  8886. if (extensions) {
  8887. helpers.extend(ChartElement.prototype, extensions);
  8888. }
  8889. ChartElement.__super__ = me.prototype;
  8890. return ChartElement;
  8891. }
  8892. };
  8893. module.exports = helpers;
  8894. // DEPRECATIONS
  8895. /**
  8896. * Provided for backward compatibility, use Chart.helpers.callback instead.
  8897. * @function Chart.helpers.callCallback
  8898. * @deprecated since version 2.6.0
  8899. * @todo remove at version 3
  8900. * @private
  8901. */
  8902. helpers.callCallback = helpers.callback;
  8903. /**
  8904. * Provided for backward compatibility, use Array.prototype.indexOf instead.
  8905. * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
  8906. * @function Chart.helpers.indexOf
  8907. * @deprecated since version 2.7.0
  8908. * @todo remove at version 3
  8909. * @private
  8910. */
  8911. helpers.indexOf = function(array, item, fromIndex) {
  8912. return Array.prototype.indexOf.call(array, item, fromIndex);
  8913. };
  8914. /**
  8915. * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
  8916. * @function Chart.helpers.getValueOrDefault
  8917. * @deprecated since version 2.7.0
  8918. * @todo remove at version 3
  8919. * @private
  8920. */
  8921. helpers.getValueOrDefault = helpers.valueOrDefault;
  8922. /**
  8923. * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
  8924. * @function Chart.helpers.getValueAtIndexOrDefault
  8925. * @deprecated since version 2.7.0
  8926. * @todo remove at version 3
  8927. * @private
  8928. */
  8929. helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  8930. },{}],44:[function(require,module,exports){
  8931. 'use strict';
  8932. var helpers = require(43);
  8933. /**
  8934. * Easing functions adapted from Robert Penner's easing equations.
  8935. * @namespace Chart.helpers.easingEffects
  8936. * @see http://www.robertpenner.com/easing/
  8937. */
  8938. var effects = {
  8939. linear: function(t) {
  8940. return t;
  8941. },
  8942. easeInQuad: function(t) {
  8943. return t * t;
  8944. },
  8945. easeOutQuad: function(t) {
  8946. return -t * (t - 2);
  8947. },
  8948. easeInOutQuad: function(t) {
  8949. if ((t /= 0.5) < 1) {
  8950. return 0.5 * t * t;
  8951. }
  8952. return -0.5 * ((--t) * (t - 2) - 1);
  8953. },
  8954. easeInCubic: function(t) {
  8955. return t * t * t;
  8956. },
  8957. easeOutCubic: function(t) {
  8958. return (t = t - 1) * t * t + 1;
  8959. },
  8960. easeInOutCubic: function(t) {
  8961. if ((t /= 0.5) < 1) {
  8962. return 0.5 * t * t * t;
  8963. }
  8964. return 0.5 * ((t -= 2) * t * t + 2);
  8965. },
  8966. easeInQuart: function(t) {
  8967. return t * t * t * t;
  8968. },
  8969. easeOutQuart: function(t) {
  8970. return -((t = t - 1) * t * t * t - 1);
  8971. },
  8972. easeInOutQuart: function(t) {
  8973. if ((t /= 0.5) < 1) {
  8974. return 0.5 * t * t * t * t;
  8975. }
  8976. return -0.5 * ((t -= 2) * t * t * t - 2);
  8977. },
  8978. easeInQuint: function(t) {
  8979. return t * t * t * t * t;
  8980. },
  8981. easeOutQuint: function(t) {
  8982. return (t = t - 1) * t * t * t * t + 1;
  8983. },
  8984. easeInOutQuint: function(t) {
  8985. if ((t /= 0.5) < 1) {
  8986. return 0.5 * t * t * t * t * t;
  8987. }
  8988. return 0.5 * ((t -= 2) * t * t * t * t + 2);
  8989. },
  8990. easeInSine: function(t) {
  8991. return -Math.cos(t * (Math.PI / 2)) + 1;
  8992. },
  8993. easeOutSine: function(t) {
  8994. return Math.sin(t * (Math.PI / 2));
  8995. },
  8996. easeInOutSine: function(t) {
  8997. return -0.5 * (Math.cos(Math.PI * t) - 1);
  8998. },
  8999. easeInExpo: function(t) {
  9000. return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
  9001. },
  9002. easeOutExpo: function(t) {
  9003. return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
  9004. },
  9005. easeInOutExpo: function(t) {
  9006. if (t === 0) {
  9007. return 0;
  9008. }
  9009. if (t === 1) {
  9010. return 1;
  9011. }
  9012. if ((t /= 0.5) < 1) {
  9013. return 0.5 * Math.pow(2, 10 * (t - 1));
  9014. }
  9015. return 0.5 * (-Math.pow(2, -10 * --t) + 2);
  9016. },
  9017. easeInCirc: function(t) {
  9018. if (t >= 1) {
  9019. return t;
  9020. }
  9021. return -(Math.sqrt(1 - t * t) - 1);
  9022. },
  9023. easeOutCirc: function(t) {
  9024. return Math.sqrt(1 - (t = t - 1) * t);
  9025. },
  9026. easeInOutCirc: function(t) {
  9027. if ((t /= 0.5) < 1) {
  9028. return -0.5 * (Math.sqrt(1 - t * t) - 1);
  9029. }
  9030. return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  9031. },
  9032. easeInElastic: function(t) {
  9033. var s = 1.70158;
  9034. var p = 0;
  9035. var a = 1;
  9036. if (t === 0) {
  9037. return 0;
  9038. }
  9039. if (t === 1) {
  9040. return 1;
  9041. }
  9042. if (!p) {
  9043. p = 0.3;
  9044. }
  9045. if (a < 1) {
  9046. a = 1;
  9047. s = p / 4;
  9048. } else {
  9049. s = p / (2 * Math.PI) * Math.asin(1 / a);
  9050. }
  9051. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  9052. },
  9053. easeOutElastic: function(t) {
  9054. var s = 1.70158;
  9055. var p = 0;
  9056. var a = 1;
  9057. if (t === 0) {
  9058. return 0;
  9059. }
  9060. if (t === 1) {
  9061. return 1;
  9062. }
  9063. if (!p) {
  9064. p = 0.3;
  9065. }
  9066. if (a < 1) {
  9067. a = 1;
  9068. s = p / 4;
  9069. } else {
  9070. s = p / (2 * Math.PI) * Math.asin(1 / a);
  9071. }
  9072. return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
  9073. },
  9074. easeInOutElastic: function(t) {
  9075. var s = 1.70158;
  9076. var p = 0;
  9077. var a = 1;
  9078. if (t === 0) {
  9079. return 0;
  9080. }
  9081. if ((t /= 0.5) === 2) {
  9082. return 1;
  9083. }
  9084. if (!p) {
  9085. p = 0.45;
  9086. }
  9087. if (a < 1) {
  9088. a = 1;
  9089. s = p / 4;
  9090. } else {
  9091. s = p / (2 * Math.PI) * Math.asin(1 / a);
  9092. }
  9093. if (t < 1) {
  9094. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  9095. }
  9096. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
  9097. },
  9098. easeInBack: function(t) {
  9099. var s = 1.70158;
  9100. return t * t * ((s + 1) * t - s);
  9101. },
  9102. easeOutBack: function(t) {
  9103. var s = 1.70158;
  9104. return (t = t - 1) * t * ((s + 1) * t + s) + 1;
  9105. },
  9106. easeInOutBack: function(t) {
  9107. var s = 1.70158;
  9108. if ((t /= 0.5) < 1) {
  9109. return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
  9110. }
  9111. return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  9112. },
  9113. easeInBounce: function(t) {
  9114. return 1 - effects.easeOutBounce(1 - t);
  9115. },
  9116. easeOutBounce: function(t) {
  9117. if (t < (1 / 2.75)) {
  9118. return 7.5625 * t * t;
  9119. }
  9120. if (t < (2 / 2.75)) {
  9121. return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
  9122. }
  9123. if (t < (2.5 / 2.75)) {
  9124. return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
  9125. }
  9126. return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
  9127. },
  9128. easeInOutBounce: function(t) {
  9129. if (t < 0.5) {
  9130. return effects.easeInBounce(t * 2) * 0.5;
  9131. }
  9132. return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
  9133. }
  9134. };
  9135. module.exports = {
  9136. effects: effects
  9137. };
  9138. // DEPRECATIONS
  9139. /**
  9140. * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
  9141. * @function Chart.helpers.easingEffects
  9142. * @deprecated since version 2.7.0
  9143. * @todo remove at version 3
  9144. * @private
  9145. */
  9146. helpers.easingEffects = effects;
  9147. },{"43":43}],45:[function(require,module,exports){
  9148. 'use strict';
  9149. var helpers = require(43);
  9150. /**
  9151. * @alias Chart.helpers.options
  9152. * @namespace
  9153. */
  9154. module.exports = {
  9155. /**
  9156. * Converts the given line height `value` in pixels for a specific font `size`.
  9157. * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
  9158. * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
  9159. * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
  9160. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
  9161. * @since 2.7.0
  9162. */
  9163. toLineHeight: function(value, size) {
  9164. var matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
  9165. if (!matches || matches[1] === 'normal') {
  9166. return size * 1.2;
  9167. }
  9168. value = +matches[2];
  9169. switch (matches[3]) {
  9170. case 'px':
  9171. return value;
  9172. case '%':
  9173. value /= 100;
  9174. break;
  9175. default:
  9176. break;
  9177. }
  9178. return size * value;
  9179. },
  9180. /**
  9181. * Converts the given value into a padding object with pre-computed width/height.
  9182. * @param {Number|Object} value - If a number, set the value to all TRBL component,
  9183. * else, if and object, use defined properties and sets undefined ones to 0.
  9184. * @returns {Object} The padding values (top, right, bottom, left, width, height)
  9185. * @since 2.7.0
  9186. */
  9187. toPadding: function(value) {
  9188. var t, r, b, l;
  9189. if (helpers.isObject(value)) {
  9190. t = +value.top || 0;
  9191. r = +value.right || 0;
  9192. b = +value.bottom || 0;
  9193. l = +value.left || 0;
  9194. } else {
  9195. t = r = b = l = +value || 0;
  9196. }
  9197. return {
  9198. top: t,
  9199. right: r,
  9200. bottom: b,
  9201. left: l,
  9202. height: t + b,
  9203. width: l + r
  9204. };
  9205. },
  9206. /**
  9207. * Evaluates the given `inputs` sequentially and returns the first defined value.
  9208. * @param {Array[]} inputs - An array of values, falling back to the last value.
  9209. * @param {Object} [context] - If defined and the current value is a function, the value
  9210. * is called with `context` as first argument and the result becomes the new input.
  9211. * @param {Number} [index] - If defined and the current value is an array, the value
  9212. * at `index` become the new input.
  9213. * @since 2.7.0
  9214. */
  9215. resolve: function(inputs, context, index) {
  9216. var i, ilen, value;
  9217. for (i = 0, ilen = inputs.length; i < ilen; ++i) {
  9218. value = inputs[i];
  9219. if (value === undefined) {
  9220. continue;
  9221. }
  9222. if (context !== undefined && typeof value === 'function') {
  9223. value = value(context);
  9224. }
  9225. if (index !== undefined && helpers.isArray(value)) {
  9226. value = value[index];
  9227. }
  9228. if (value !== undefined) {
  9229. return value;
  9230. }
  9231. }
  9232. }
  9233. };
  9234. },{"43":43}],46:[function(require,module,exports){
  9235. 'use strict';
  9236. module.exports = require(43);
  9237. module.exports.easing = require(44);
  9238. module.exports.canvas = require(42);
  9239. module.exports.options = require(45);
  9240. },{"42":42,"43":43,"44":44,"45":45}],47:[function(require,module,exports){
  9241. /**
  9242. * Platform fallback implementation (minimal).
  9243. * @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
  9244. */
  9245. module.exports = {
  9246. acquireContext: function(item) {
  9247. if (item && item.canvas) {
  9248. // Support for any object associated to a canvas (including a context2d)
  9249. item = item.canvas;
  9250. }
  9251. return item && item.getContext('2d') || null;
  9252. }
  9253. };
  9254. },{}],48:[function(require,module,exports){
  9255. /**
  9256. * Chart.Platform implementation for targeting a web browser
  9257. */
  9258. 'use strict';
  9259. var helpers = require(46);
  9260. var EXPANDO_KEY = '$chartjs';
  9261. var CSS_PREFIX = 'chartjs-';
  9262. var CSS_RENDER_MONITOR = CSS_PREFIX + 'render-monitor';
  9263. var CSS_RENDER_ANIMATION = CSS_PREFIX + 'render-animation';
  9264. var ANIMATION_START_EVENTS = ['animationstart', 'webkitAnimationStart'];
  9265. /**
  9266. * DOM event types -> Chart.js event types.
  9267. * Note: only events with different types are mapped.
  9268. * @see https://developer.mozilla.org/en-US/docs/Web/Events
  9269. */
  9270. var EVENT_TYPES = {
  9271. touchstart: 'mousedown',
  9272. touchmove: 'mousemove',
  9273. touchend: 'mouseup',
  9274. pointerenter: 'mouseenter',
  9275. pointerdown: 'mousedown',
  9276. pointermove: 'mousemove',
  9277. pointerup: 'mouseup',
  9278. pointerleave: 'mouseout',
  9279. pointerout: 'mouseout'
  9280. };
  9281. /**
  9282. * The "used" size is the final value of a dimension property after all calculations have
  9283. * been performed. This method uses the computed style of `element` but returns undefined
  9284. * if the computed style is not expressed in pixels. That can happen in some cases where
  9285. * `element` has a size relative to its parent and this last one is not yet displayed,
  9286. * for example because of `display: none` on a parent node.
  9287. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
  9288. * @returns {Number} Size in pixels or undefined if unknown.
  9289. */
  9290. function readUsedSize(element, property) {
  9291. var value = helpers.getStyle(element, property);
  9292. var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
  9293. return matches ? Number(matches[1]) : undefined;
  9294. }
  9295. /**
  9296. * Initializes the canvas style and render size without modifying the canvas display size,
  9297. * since responsiveness is handled by the controller.resize() method. The config is used
  9298. * to determine the aspect ratio to apply in case no explicit height has been specified.
  9299. */
  9300. function initCanvas(canvas, config) {
  9301. var style = canvas.style;
  9302. // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
  9303. // returns null or '' if no explicit value has been set to the canvas attribute.
  9304. var renderHeight = canvas.getAttribute('height');
  9305. var renderWidth = canvas.getAttribute('width');
  9306. // Chart.js modifies some canvas values that we want to restore on destroy
  9307. canvas[EXPANDO_KEY] = {
  9308. initial: {
  9309. height: renderHeight,
  9310. width: renderWidth,
  9311. style: {
  9312. display: style.display,
  9313. height: style.height,
  9314. width: style.width
  9315. }
  9316. }
  9317. };
  9318. // Force canvas to display as block to avoid extra space caused by inline
  9319. // elements, which would interfere with the responsive resize process.
  9320. // https://github.com/chartjs/Chart.js/issues/2538
  9321. style.display = style.display || 'block';
  9322. if (renderWidth === null || renderWidth === '') {
  9323. var displayWidth = readUsedSize(canvas, 'width');
  9324. if (displayWidth !== undefined) {
  9325. canvas.width = displayWidth;
  9326. }
  9327. }
  9328. if (renderHeight === null || renderHeight === '') {
  9329. if (canvas.style.height === '') {
  9330. // If no explicit render height and style height, let's apply the aspect ratio,
  9331. // which one can be specified by the user but also by charts as default option
  9332. // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
  9333. canvas.height = canvas.width / (config.options.aspectRatio || 2);
  9334. } else {
  9335. var displayHeight = readUsedSize(canvas, 'height');
  9336. if (displayWidth !== undefined) {
  9337. canvas.height = displayHeight;
  9338. }
  9339. }
  9340. }
  9341. return canvas;
  9342. }
  9343. /**
  9344. * Detects support for options object argument in addEventListener.
  9345. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  9346. * @private
  9347. */
  9348. var supportsEventListenerOptions = (function() {
  9349. var supports = false;
  9350. try {
  9351. var options = Object.defineProperty({}, 'passive', {
  9352. get: function() {
  9353. supports = true;
  9354. }
  9355. });
  9356. window.addEventListener('e', null, options);
  9357. } catch (e) {
  9358. // continue regardless of error
  9359. }
  9360. return supports;
  9361. }());
  9362. // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  9363. // https://github.com/chartjs/Chart.js/issues/4287
  9364. var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
  9365. function addEventListener(node, type, listener) {
  9366. node.addEventListener(type, listener, eventListenerOptions);
  9367. }
  9368. function removeEventListener(node, type, listener) {
  9369. node.removeEventListener(type, listener, eventListenerOptions);
  9370. }
  9371. function createEvent(type, chart, x, y, nativeEvent) {
  9372. return {
  9373. type: type,
  9374. chart: chart,
  9375. native: nativeEvent || null,
  9376. x: x !== undefined ? x : null,
  9377. y: y !== undefined ? y : null,
  9378. };
  9379. }
  9380. function fromNativeEvent(event, chart) {
  9381. var type = EVENT_TYPES[event.type] || event.type;
  9382. var pos = helpers.getRelativePosition(event, chart);
  9383. return createEvent(type, chart, pos.x, pos.y, event);
  9384. }
  9385. function throttled(fn, thisArg) {
  9386. var ticking = false;
  9387. var args = [];
  9388. return function() {
  9389. args = Array.prototype.slice.call(arguments);
  9390. thisArg = thisArg || this;
  9391. if (!ticking) {
  9392. ticking = true;
  9393. helpers.requestAnimFrame.call(window, function() {
  9394. ticking = false;
  9395. fn.apply(thisArg, args);
  9396. });
  9397. }
  9398. };
  9399. }
  9400. // Implementation based on https://github.com/marcj/css-element-queries
  9401. function createResizer(handler) {
  9402. var resizer = document.createElement('div');
  9403. var cls = CSS_PREFIX + 'size-monitor';
  9404. var maxSize = 1000000;
  9405. var style =
  9406. 'position:absolute;' +
  9407. 'left:0;' +
  9408. 'top:0;' +
  9409. 'right:0;' +
  9410. 'bottom:0;' +
  9411. 'overflow:hidden;' +
  9412. 'pointer-events:none;' +
  9413. 'visibility:hidden;' +
  9414. 'z-index:-1;';
  9415. resizer.style.cssText = style;
  9416. resizer.className = cls;
  9417. resizer.innerHTML =
  9418. '<div class="' + cls + '-expand" style="' + style + '">' +
  9419. '<div style="' +
  9420. 'position:absolute;' +
  9421. 'width:' + maxSize + 'px;' +
  9422. 'height:' + maxSize + 'px;' +
  9423. 'left:0;' +
  9424. 'top:0">' +
  9425. '</div>' +
  9426. '</div>' +
  9427. '<div class="' + cls + '-shrink" style="' + style + '">' +
  9428. '<div style="' +
  9429. 'position:absolute;' +
  9430. 'width:200%;' +
  9431. 'height:200%;' +
  9432. 'left:0; ' +
  9433. 'top:0">' +
  9434. '</div>' +
  9435. '</div>';
  9436. var expand = resizer.childNodes[0];
  9437. var shrink = resizer.childNodes[1];
  9438. resizer._reset = function() {
  9439. expand.scrollLeft = maxSize;
  9440. expand.scrollTop = maxSize;
  9441. shrink.scrollLeft = maxSize;
  9442. shrink.scrollTop = maxSize;
  9443. };
  9444. var onScroll = function() {
  9445. resizer._reset();
  9446. handler();
  9447. };
  9448. addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
  9449. addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
  9450. return resizer;
  9451. }
  9452. // https://davidwalsh.name/detect-node-insertion
  9453. function watchForRender(node, handler) {
  9454. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9455. var proxy = expando.renderProxy = function(e) {
  9456. if (e.animationName === CSS_RENDER_ANIMATION) {
  9457. handler();
  9458. }
  9459. };
  9460. helpers.each(ANIMATION_START_EVENTS, function(type) {
  9461. addEventListener(node, type, proxy);
  9462. });
  9463. // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
  9464. // is removed then added back immediately (same animation frame?). Accessing the
  9465. // `offsetParent` property will force a reflow and re-evaluate the CSS animation.
  9466. // https://gist.github.com/paulirish/5d52fb081b3570c81e3a#box-metrics
  9467. // https://github.com/chartjs/Chart.js/issues/4737
  9468. expando.reflow = !!node.offsetParent;
  9469. node.classList.add(CSS_RENDER_MONITOR);
  9470. }
  9471. function unwatchForRender(node) {
  9472. var expando = node[EXPANDO_KEY] || {};
  9473. var proxy = expando.renderProxy;
  9474. if (proxy) {
  9475. helpers.each(ANIMATION_START_EVENTS, function(type) {
  9476. removeEventListener(node, type, proxy);
  9477. });
  9478. delete expando.renderProxy;
  9479. }
  9480. node.classList.remove(CSS_RENDER_MONITOR);
  9481. }
  9482. function addResizeListener(node, listener, chart) {
  9483. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9484. // Let's keep track of this added resizer and thus avoid DOM query when removing it.
  9485. var resizer = expando.resizer = createResizer(throttled(function() {
  9486. if (expando.resizer) {
  9487. return listener(createEvent('resize', chart));
  9488. }
  9489. }));
  9490. // The resizer needs to be attached to the node parent, so we first need to be
  9491. // sure that `node` is attached to the DOM before injecting the resizer element.
  9492. watchForRender(node, function() {
  9493. if (expando.resizer) {
  9494. var container = node.parentNode;
  9495. if (container && container !== resizer.parentNode) {
  9496. container.insertBefore(resizer, container.firstChild);
  9497. }
  9498. // The container size might have changed, let's reset the resizer state.
  9499. resizer._reset();
  9500. }
  9501. });
  9502. }
  9503. function removeResizeListener(node) {
  9504. var expando = node[EXPANDO_KEY] || {};
  9505. var resizer = expando.resizer;
  9506. delete expando.resizer;
  9507. unwatchForRender(node);
  9508. if (resizer && resizer.parentNode) {
  9509. resizer.parentNode.removeChild(resizer);
  9510. }
  9511. }
  9512. function injectCSS(platform, css) {
  9513. // http://stackoverflow.com/q/3922139
  9514. var style = platform._style || document.createElement('style');
  9515. if (!platform._style) {
  9516. platform._style = style;
  9517. css = '/* Chart.js */\n' + css;
  9518. style.setAttribute('type', 'text/css');
  9519. document.getElementsByTagName('head')[0].appendChild(style);
  9520. }
  9521. style.appendChild(document.createTextNode(css));
  9522. }
  9523. module.exports = {
  9524. /**
  9525. * This property holds whether this platform is enabled for the current environment.
  9526. * Currently used by platform.js to select the proper implementation.
  9527. * @private
  9528. */
  9529. _enabled: typeof window !== 'undefined' && typeof document !== 'undefined',
  9530. initialize: function() {
  9531. var keyframes = 'from{opacity:0.99}to{opacity:1}';
  9532. injectCSS(this,
  9533. // DOM rendering detection
  9534. // https://davidwalsh.name/detect-node-insertion
  9535. '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9536. '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9537. '.' + CSS_RENDER_MONITOR + '{' +
  9538. '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9539. 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9540. '}'
  9541. );
  9542. },
  9543. acquireContext: function(item, config) {
  9544. if (typeof item === 'string') {
  9545. item = document.getElementById(item);
  9546. } else if (item.length) {
  9547. // Support for array based queries (such as jQuery)
  9548. item = item[0];
  9549. }
  9550. if (item && item.canvas) {
  9551. // Support for any object associated to a canvas (including a context2d)
  9552. item = item.canvas;
  9553. }
  9554. // To prevent canvas fingerprinting, some add-ons undefine the getContext
  9555. // method, for example: https://github.com/kkapsner/CanvasBlocker
  9556. // https://github.com/chartjs/Chart.js/issues/2807
  9557. var context = item && item.getContext && item.getContext('2d');
  9558. // `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
  9559. // inside an iframe or when running in a protected environment. We could guess the
  9560. // types from their toString() value but let's keep things flexible and assume it's
  9561. // a sufficient condition if the item has a context2D which has item as `canvas`.
  9562. // https://github.com/chartjs/Chart.js/issues/3887
  9563. // https://github.com/chartjs/Chart.js/issues/4102
  9564. // https://github.com/chartjs/Chart.js/issues/4152
  9565. if (context && context.canvas === item) {
  9566. initCanvas(item, config);
  9567. return context;
  9568. }
  9569. return null;
  9570. },
  9571. releaseContext: function(context) {
  9572. var canvas = context.canvas;
  9573. if (!canvas[EXPANDO_KEY]) {
  9574. return;
  9575. }
  9576. var initial = canvas[EXPANDO_KEY].initial;
  9577. ['height', 'width'].forEach(function(prop) {
  9578. var value = initial[prop];
  9579. if (helpers.isNullOrUndef(value)) {
  9580. canvas.removeAttribute(prop);
  9581. } else {
  9582. canvas.setAttribute(prop, value);
  9583. }
  9584. });
  9585. helpers.each(initial.style || {}, function(value, key) {
  9586. canvas.style[key] = value;
  9587. });
  9588. // The canvas render size might have been changed (and thus the state stack discarded),
  9589. // we can't use save() and restore() to restore the initial state. So make sure that at
  9590. // least the canvas context is reset to the default state by setting the canvas width.
  9591. // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
  9592. canvas.width = canvas.width;
  9593. delete canvas[EXPANDO_KEY];
  9594. },
  9595. addEventListener: function(chart, type, listener) {
  9596. var canvas = chart.canvas;
  9597. if (type === 'resize') {
  9598. // Note: the resize event is not supported on all browsers.
  9599. addResizeListener(canvas, listener, chart);
  9600. return;
  9601. }
  9602. var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
  9603. var proxies = expando.proxies || (expando.proxies = {});
  9604. var proxy = proxies[chart.id + '_' + type] = function(event) {
  9605. listener(fromNativeEvent(event, chart));
  9606. };
  9607. addEventListener(canvas, type, proxy);
  9608. },
  9609. removeEventListener: function(chart, type, listener) {
  9610. var canvas = chart.canvas;
  9611. if (type === 'resize') {
  9612. // Note: the resize event is not supported on all browsers.
  9613. removeResizeListener(canvas, listener);
  9614. return;
  9615. }
  9616. var expando = listener[EXPANDO_KEY] || {};
  9617. var proxies = expando.proxies || {};
  9618. var proxy = proxies[chart.id + '_' + type];
  9619. if (!proxy) {
  9620. return;
  9621. }
  9622. removeEventListener(canvas, type, proxy);
  9623. }
  9624. };
  9625. // DEPRECATIONS
  9626. /**
  9627. * Provided for backward compatibility, use EventTarget.addEventListener instead.
  9628. * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9629. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  9630. * @function Chart.helpers.addEvent
  9631. * @deprecated since version 2.7.0
  9632. * @todo remove at version 3
  9633. * @private
  9634. */
  9635. helpers.addEvent = addEventListener;
  9636. /**
  9637. * Provided for backward compatibility, use EventTarget.removeEventListener instead.
  9638. * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9639. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
  9640. * @function Chart.helpers.removeEvent
  9641. * @deprecated since version 2.7.0
  9642. * @todo remove at version 3
  9643. * @private
  9644. */
  9645. helpers.removeEvent = removeEventListener;
  9646. },{"46":46}],49:[function(require,module,exports){
  9647. 'use strict';
  9648. var helpers = require(46);
  9649. var basic = require(47);
  9650. var dom = require(48);
  9651. // @TODO Make possible to select another platform at build time.
  9652. var implementation = dom._enabled ? dom : basic;
  9653. /**
  9654. * @namespace Chart.platform
  9655. * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
  9656. * @since 2.4.0
  9657. */
  9658. module.exports = helpers.extend({
  9659. /**
  9660. * @since 2.7.0
  9661. */
  9662. initialize: function() {},
  9663. /**
  9664. * Called at chart construction time, returns a context2d instance implementing
  9665. * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
  9666. * @param {*} item - The native item from which to acquire context (platform specific)
  9667. * @param {Object} options - The chart options
  9668. * @returns {CanvasRenderingContext2D} context2d instance
  9669. */
  9670. acquireContext: function() {},
  9671. /**
  9672. * Called at chart destruction time, releases any resources associated to the context
  9673. * previously returned by the acquireContext() method.
  9674. * @param {CanvasRenderingContext2D} context - The context2d instance
  9675. * @returns {Boolean} true if the method succeeded, else false
  9676. */
  9677. releaseContext: function() {},
  9678. /**
  9679. * Registers the specified listener on the given chart.
  9680. * @param {Chart} chart - Chart from which to listen for event
  9681. * @param {String} type - The ({@link IEvent}) type to listen for
  9682. * @param {Function} listener - Receives a notification (an object that implements
  9683. * the {@link IEvent} interface) when an event of the specified type occurs.
  9684. */
  9685. addEventListener: function() {},
  9686. /**
  9687. * Removes the specified listener previously registered with addEventListener.
  9688. * @param {Chart} chart -Chart from which to remove the listener
  9689. * @param {String} type - The ({@link IEvent}) type to remove
  9690. * @param {Function} listener - The listener function to remove from the event target.
  9691. */
  9692. removeEventListener: function() {}
  9693. }, implementation);
  9694. /**
  9695. * @interface IPlatform
  9696. * Allows abstracting platform dependencies away from the chart
  9697. * @borrows Chart.platform.acquireContext as acquireContext
  9698. * @borrows Chart.platform.releaseContext as releaseContext
  9699. * @borrows Chart.platform.addEventListener as addEventListener
  9700. * @borrows Chart.platform.removeEventListener as removeEventListener
  9701. */
  9702. /**
  9703. * @interface IEvent
  9704. * @prop {String} type - The event type name, possible values are:
  9705. * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
  9706. * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
  9707. * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
  9708. * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
  9709. * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
  9710. */
  9711. },{"46":46,"47":47,"48":48}],50:[function(require,module,exports){
  9712. 'use strict';
  9713. module.exports = {};
  9714. module.exports.filler = require(51);
  9715. module.exports.legend = require(52);
  9716. module.exports.title = require(53);
  9717. },{"51":51,"52":52,"53":53}],51:[function(require,module,exports){
  9718. /**
  9719. * Plugin based on discussion from the following Chart.js issues:
  9720. * @see https://github.com/chartjs/Chart.js/issues/2380#issuecomment-279961569
  9721. * @see https://github.com/chartjs/Chart.js/issues/2440#issuecomment-256461897
  9722. */
  9723. 'use strict';
  9724. var defaults = require(26);
  9725. var elements = require(41);
  9726. var helpers = require(46);
  9727. defaults._set('global', {
  9728. plugins: {
  9729. filler: {
  9730. propagate: true
  9731. }
  9732. }
  9733. });
  9734. var mappers = {
  9735. dataset: function(source) {
  9736. var index = source.fill;
  9737. var chart = source.chart;
  9738. var meta = chart.getDatasetMeta(index);
  9739. var visible = meta && chart.isDatasetVisible(index);
  9740. var points = (visible && meta.dataset._children) || [];
  9741. var length = points.length || 0;
  9742. return !length ? null : function(point, i) {
  9743. return (i < length && points[i]._view) || null;
  9744. };
  9745. },
  9746. boundary: function(source) {
  9747. var boundary = source.boundary;
  9748. var x = boundary ? boundary.x : null;
  9749. var y = boundary ? boundary.y : null;
  9750. return function(point) {
  9751. return {
  9752. x: x === null ? point.x : x,
  9753. y: y === null ? point.y : y,
  9754. };
  9755. };
  9756. }
  9757. };
  9758. // @todo if (fill[0] === '#')
  9759. function decodeFill(el, index, count) {
  9760. var model = el._model || {};
  9761. var fill = model.fill;
  9762. var target;
  9763. if (fill === undefined) {
  9764. fill = !!model.backgroundColor;
  9765. }
  9766. if (fill === false || fill === null) {
  9767. return false;
  9768. }
  9769. if (fill === true) {
  9770. return 'origin';
  9771. }
  9772. target = parseFloat(fill, 10);
  9773. if (isFinite(target) && Math.floor(target) === target) {
  9774. if (fill[0] === '-' || fill[0] === '+') {
  9775. target = index + target;
  9776. }
  9777. if (target === index || target < 0 || target >= count) {
  9778. return false;
  9779. }
  9780. return target;
  9781. }
  9782. switch (fill) {
  9783. // compatibility
  9784. case 'bottom':
  9785. return 'start';
  9786. case 'top':
  9787. return 'end';
  9788. case 'zero':
  9789. return 'origin';
  9790. // supported boundaries
  9791. case 'origin':
  9792. case 'start':
  9793. case 'end':
  9794. return fill;
  9795. // invalid fill values
  9796. default:
  9797. return false;
  9798. }
  9799. }
  9800. function computeBoundary(source) {
  9801. var model = source.el._model || {};
  9802. var scale = source.el._scale || {};
  9803. var fill = source.fill;
  9804. var target = null;
  9805. var horizontal;
  9806. if (isFinite(fill)) {
  9807. return null;
  9808. }
  9809. // Backward compatibility: until v3, we still need to support boundary values set on
  9810. // the model (scaleTop, scaleBottom and scaleZero) because some external plugins and
  9811. // controllers might still use it (e.g. the Smith chart).
  9812. if (fill === 'start') {
  9813. target = model.scaleBottom === undefined ? scale.bottom : model.scaleBottom;
  9814. } else if (fill === 'end') {
  9815. target = model.scaleTop === undefined ? scale.top : model.scaleTop;
  9816. } else if (model.scaleZero !== undefined) {
  9817. target = model.scaleZero;
  9818. } else if (scale.getBasePosition) {
  9819. target = scale.getBasePosition();
  9820. } else if (scale.getBasePixel) {
  9821. target = scale.getBasePixel();
  9822. }
  9823. if (target !== undefined && target !== null) {
  9824. if (target.x !== undefined && target.y !== undefined) {
  9825. return target;
  9826. }
  9827. if (typeof target === 'number' && isFinite(target)) {
  9828. horizontal = scale.isHorizontal();
  9829. return {
  9830. x: horizontal ? target : null,
  9831. y: horizontal ? null : target
  9832. };
  9833. }
  9834. }
  9835. return null;
  9836. }
  9837. function resolveTarget(sources, index, propagate) {
  9838. var source = sources[index];
  9839. var fill = source.fill;
  9840. var visited = [index];
  9841. var target;
  9842. if (!propagate) {
  9843. return fill;
  9844. }
  9845. while (fill !== false && visited.indexOf(fill) === -1) {
  9846. if (!isFinite(fill)) {
  9847. return fill;
  9848. }
  9849. target = sources[fill];
  9850. if (!target) {
  9851. return false;
  9852. }
  9853. if (target.visible) {
  9854. return fill;
  9855. }
  9856. visited.push(fill);
  9857. fill = target.fill;
  9858. }
  9859. return false;
  9860. }
  9861. function createMapper(source) {
  9862. var fill = source.fill;
  9863. var type = 'dataset';
  9864. if (fill === false) {
  9865. return null;
  9866. }
  9867. if (!isFinite(fill)) {
  9868. type = 'boundary';
  9869. }
  9870. return mappers[type](source);
  9871. }
  9872. function isDrawable(point) {
  9873. return point && !point.skip;
  9874. }
  9875. function drawArea(ctx, curve0, curve1, len0, len1) {
  9876. var i;
  9877. if (!len0 || !len1) {
  9878. return;
  9879. }
  9880. // building first area curve (normal)
  9881. ctx.moveTo(curve0[0].x, curve0[0].y);
  9882. for (i = 1; i < len0; ++i) {
  9883. helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
  9884. }
  9885. // joining the two area curves
  9886. ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
  9887. // building opposite area curve (reverse)
  9888. for (i = len1 - 1; i > 0; --i) {
  9889. helpers.canvas.lineTo(ctx, curve1[i], curve1[i - 1], true);
  9890. }
  9891. }
  9892. function doFill(ctx, points, mapper, view, color, loop) {
  9893. var count = points.length;
  9894. var span = view.spanGaps;
  9895. var curve0 = [];
  9896. var curve1 = [];
  9897. var len0 = 0;
  9898. var len1 = 0;
  9899. var i, ilen, index, p0, p1, d0, d1;
  9900. ctx.beginPath();
  9901. for (i = 0, ilen = (count + !!loop); i < ilen; ++i) {
  9902. index = i % count;
  9903. p0 = points[index]._view;
  9904. p1 = mapper(p0, index, view);
  9905. d0 = isDrawable(p0);
  9906. d1 = isDrawable(p1);
  9907. if (d0 && d1) {
  9908. len0 = curve0.push(p0);
  9909. len1 = curve1.push(p1);
  9910. } else if (len0 && len1) {
  9911. if (!span) {
  9912. drawArea(ctx, curve0, curve1, len0, len1);
  9913. len0 = len1 = 0;
  9914. curve0 = [];
  9915. curve1 = [];
  9916. } else {
  9917. if (d0) {
  9918. curve0.push(p0);
  9919. }
  9920. if (d1) {
  9921. curve1.push(p1);
  9922. }
  9923. }
  9924. }
  9925. }
  9926. drawArea(ctx, curve0, curve1, len0, len1);
  9927. ctx.closePath();
  9928. ctx.fillStyle = color;
  9929. ctx.fill();
  9930. }
  9931. module.exports = {
  9932. id: 'filler',
  9933. afterDatasetsUpdate: function(chart, options) {
  9934. var count = (chart.data.datasets || []).length;
  9935. var propagate = options.propagate;
  9936. var sources = [];
  9937. var meta, i, el, source;
  9938. for (i = 0; i < count; ++i) {
  9939. meta = chart.getDatasetMeta(i);
  9940. el = meta.dataset;
  9941. source = null;
  9942. if (el && el._model && el instanceof elements.Line) {
  9943. source = {
  9944. visible: chart.isDatasetVisible(i),
  9945. fill: decodeFill(el, i, count),
  9946. chart: chart,
  9947. el: el
  9948. };
  9949. }
  9950. meta.$filler = source;
  9951. sources.push(source);
  9952. }
  9953. for (i = 0; i < count; ++i) {
  9954. source = sources[i];
  9955. if (!source) {
  9956. continue;
  9957. }
  9958. source.fill = resolveTarget(sources, i, propagate);
  9959. source.boundary = computeBoundary(source);
  9960. source.mapper = createMapper(source);
  9961. }
  9962. },
  9963. beforeDatasetDraw: function(chart, args) {
  9964. var meta = args.meta.$filler;
  9965. if (!meta) {
  9966. return;
  9967. }
  9968. var ctx = chart.ctx;
  9969. var el = meta.el;
  9970. var view = el._view;
  9971. var points = el._children || [];
  9972. var mapper = meta.mapper;
  9973. var color = view.backgroundColor || defaults.global.defaultColor;
  9974. if (mapper && color && points.length) {
  9975. helpers.canvas.clipArea(ctx, chart.chartArea);
  9976. doFill(ctx, points, mapper, view, color, el._loop);
  9977. helpers.canvas.unclipArea(ctx);
  9978. }
  9979. }
  9980. };
  9981. },{"26":26,"41":41,"46":46}],52:[function(require,module,exports){
  9982. 'use strict';
  9983. var defaults = require(26);
  9984. var Element = require(27);
  9985. var helpers = require(46);
  9986. var layouts = require(31);
  9987. var noop = helpers.noop;
  9988. defaults._set('global', {
  9989. legend: {
  9990. display: true,
  9991. position: 'top',
  9992. fullWidth: true,
  9993. reverse: false,
  9994. weight: 1000,
  9995. // a callback that will handle
  9996. onClick: function(e, legendItem) {
  9997. var index = legendItem.datasetIndex;
  9998. var ci = this.chart;
  9999. var meta = ci.getDatasetMeta(index);
  10000. // See controller.isDatasetVisible comment
  10001. meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
  10002. // We hid a dataset ... rerender the chart
  10003. ci.update();
  10004. },
  10005. onHover: null,
  10006. labels: {
  10007. boxWidth: 40,
  10008. padding: 10,
  10009. // Generates labels shown in the legend
  10010. // Valid properties to return:
  10011. // text : text to display
  10012. // fillStyle : fill of coloured box
  10013. // strokeStyle: stroke of coloured box
  10014. // hidden : if this legend item refers to a hidden item
  10015. // lineCap : cap style for line
  10016. // lineDash
  10017. // lineDashOffset :
  10018. // lineJoin :
  10019. // lineWidth :
  10020. generateLabels: function(chart) {
  10021. var data = chart.data;
  10022. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  10023. return {
  10024. text: dataset.label,
  10025. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  10026. hidden: !chart.isDatasetVisible(i),
  10027. lineCap: dataset.borderCapStyle,
  10028. lineDash: dataset.borderDash,
  10029. lineDashOffset: dataset.borderDashOffset,
  10030. lineJoin: dataset.borderJoinStyle,
  10031. lineWidth: dataset.borderWidth,
  10032. strokeStyle: dataset.borderColor,
  10033. pointStyle: dataset.pointStyle,
  10034. // Below is extra data used for toggling the datasets
  10035. datasetIndex: i
  10036. };
  10037. }, this) : [];
  10038. }
  10039. }
  10040. },
  10041. legendCallback: function(chart) {
  10042. var text = [];
  10043. text.push('<ul class="' + chart.id + '-legend">');
  10044. for (var i = 0; i < chart.data.datasets.length; i++) {
  10045. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  10046. if (chart.data.datasets[i].label) {
  10047. text.push(chart.data.datasets[i].label);
  10048. }
  10049. text.push('</li>');
  10050. }
  10051. text.push('</ul>');
  10052. return text.join('');
  10053. }
  10054. });
  10055. /**
  10056. * Helper function to get the box width based on the usePointStyle option
  10057. * @param labelopts {Object} the label options on the legend
  10058. * @param fontSize {Number} the label font size
  10059. * @return {Number} width of the color box area
  10060. */
  10061. function getBoxWidth(labelOpts, fontSize) {
  10062. return labelOpts.usePointStyle ?
  10063. fontSize * Math.SQRT2 :
  10064. labelOpts.boxWidth;
  10065. }
  10066. /**
  10067. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  10068. */
  10069. var Legend = Element.extend({
  10070. initialize: function(config) {
  10071. helpers.extend(this, config);
  10072. // Contains hit boxes for each dataset (in dataset order)
  10073. this.legendHitBoxes = [];
  10074. // Are we in doughnut mode which has a different data type
  10075. this.doughnutMode = false;
  10076. },
  10077. // These methods are ordered by lifecycle. Utilities then follow.
  10078. // Any function defined here is inherited by all legend types.
  10079. // Any function can be extended by the legend type
  10080. beforeUpdate: noop,
  10081. update: function(maxWidth, maxHeight, margins) {
  10082. var me = this;
  10083. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  10084. me.beforeUpdate();
  10085. // Absorb the master measurements
  10086. me.maxWidth = maxWidth;
  10087. me.maxHeight = maxHeight;
  10088. me.margins = margins;
  10089. // Dimensions
  10090. me.beforeSetDimensions();
  10091. me.setDimensions();
  10092. me.afterSetDimensions();
  10093. // Labels
  10094. me.beforeBuildLabels();
  10095. me.buildLabels();
  10096. me.afterBuildLabels();
  10097. // Fit
  10098. me.beforeFit();
  10099. me.fit();
  10100. me.afterFit();
  10101. //
  10102. me.afterUpdate();
  10103. return me.minSize;
  10104. },
  10105. afterUpdate: noop,
  10106. //
  10107. beforeSetDimensions: noop,
  10108. setDimensions: function() {
  10109. var me = this;
  10110. // Set the unconstrained dimension before label rotation
  10111. if (me.isHorizontal()) {
  10112. // Reset position before calculating rotation
  10113. me.width = me.maxWidth;
  10114. me.left = 0;
  10115. me.right = me.width;
  10116. } else {
  10117. me.height = me.maxHeight;
  10118. // Reset position before calculating rotation
  10119. me.top = 0;
  10120. me.bottom = me.height;
  10121. }
  10122. // Reset padding
  10123. me.paddingLeft = 0;
  10124. me.paddingTop = 0;
  10125. me.paddingRight = 0;
  10126. me.paddingBottom = 0;
  10127. // Reset minSize
  10128. me.minSize = {
  10129. width: 0,
  10130. height: 0
  10131. };
  10132. },
  10133. afterSetDimensions: noop,
  10134. //
  10135. beforeBuildLabels: noop,
  10136. buildLabels: function() {
  10137. var me = this;
  10138. var labelOpts = me.options.labels || {};
  10139. var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];
  10140. if (labelOpts.filter) {
  10141. legendItems = legendItems.filter(function(item) {
  10142. return labelOpts.filter(item, me.chart.data);
  10143. });
  10144. }
  10145. if (me.options.reverse) {
  10146. legendItems.reverse();
  10147. }
  10148. me.legendItems = legendItems;
  10149. },
  10150. afterBuildLabels: noop,
  10151. //
  10152. beforeFit: noop,
  10153. fit: function() {
  10154. var me = this;
  10155. var opts = me.options;
  10156. var labelOpts = opts.labels;
  10157. var display = opts.display;
  10158. var ctx = me.ctx;
  10159. var globalDefault = defaults.global;
  10160. var valueOrDefault = helpers.valueOrDefault;
  10161. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  10162. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  10163. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  10164. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10165. // Reset hit boxes
  10166. var hitboxes = me.legendHitBoxes = [];
  10167. var minSize = me.minSize;
  10168. var isHorizontal = me.isHorizontal();
  10169. if (isHorizontal) {
  10170. minSize.width = me.maxWidth; // fill all the width
  10171. minSize.height = display ? 10 : 0;
  10172. } else {
  10173. minSize.width = display ? 10 : 0;
  10174. minSize.height = me.maxHeight; // fill all the height
  10175. }
  10176. // Increase sizes here
  10177. if (display) {
  10178. ctx.font = labelFont;
  10179. if (isHorizontal) {
  10180. // Labels
  10181. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  10182. var lineWidths = me.lineWidths = [0];
  10183. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  10184. ctx.textAlign = 'left';
  10185. ctx.textBaseline = 'top';
  10186. helpers.each(me.legendItems, function(legendItem, i) {
  10187. var boxWidth = getBoxWidth(labelOpts, fontSize);
  10188. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  10189. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  10190. totalHeight += fontSize + (labelOpts.padding);
  10191. lineWidths[lineWidths.length] = me.left;
  10192. }
  10193. // Store the hitbox width and height here. Final position will be updated in `draw`
  10194. hitboxes[i] = {
  10195. left: 0,
  10196. top: 0,
  10197. width: width,
  10198. height: fontSize
  10199. };
  10200. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  10201. });
  10202. minSize.height += totalHeight;
  10203. } else {
  10204. var vPadding = labelOpts.padding;
  10205. var columnWidths = me.columnWidths = [];
  10206. var totalWidth = labelOpts.padding;
  10207. var currentColWidth = 0;
  10208. var currentColHeight = 0;
  10209. var itemHeight = fontSize + vPadding;
  10210. helpers.each(me.legendItems, function(legendItem, i) {
  10211. var boxWidth = getBoxWidth(labelOpts, fontSize);
  10212. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  10213. // If too tall, go to new column
  10214. if (currentColHeight + itemHeight > minSize.height) {
  10215. totalWidth += currentColWidth + labelOpts.padding;
  10216. columnWidths.push(currentColWidth); // previous column width
  10217. currentColWidth = 0;
  10218. currentColHeight = 0;
  10219. }
  10220. // Get max width
  10221. currentColWidth = Math.max(currentColWidth, itemWidth);
  10222. currentColHeight += itemHeight;
  10223. // Store the hitbox width and height here. Final position will be updated in `draw`
  10224. hitboxes[i] = {
  10225. left: 0,
  10226. top: 0,
  10227. width: itemWidth,
  10228. height: fontSize
  10229. };
  10230. });
  10231. totalWidth += currentColWidth;
  10232. columnWidths.push(currentColWidth);
  10233. minSize.width += totalWidth;
  10234. }
  10235. }
  10236. me.width = minSize.width;
  10237. me.height = minSize.height;
  10238. },
  10239. afterFit: noop,
  10240. // Shared Methods
  10241. isHorizontal: function() {
  10242. return this.options.position === 'top' || this.options.position === 'bottom';
  10243. },
  10244. // Actually draw the legend on the canvas
  10245. draw: function() {
  10246. var me = this;
  10247. var opts = me.options;
  10248. var labelOpts = opts.labels;
  10249. var globalDefault = defaults.global;
  10250. var lineDefault = globalDefault.elements.line;
  10251. var legendWidth = me.width;
  10252. var lineWidths = me.lineWidths;
  10253. if (opts.display) {
  10254. var ctx = me.ctx;
  10255. var valueOrDefault = helpers.valueOrDefault;
  10256. var fontColor = valueOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor);
  10257. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  10258. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  10259. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  10260. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10261. var cursor;
  10262. // Canvas setup
  10263. ctx.textAlign = 'left';
  10264. ctx.textBaseline = 'middle';
  10265. ctx.lineWidth = 0.5;
  10266. ctx.strokeStyle = fontColor; // for strikethrough effect
  10267. ctx.fillStyle = fontColor; // render in correct colour
  10268. ctx.font = labelFont;
  10269. var boxWidth = getBoxWidth(labelOpts, fontSize);
  10270. var hitboxes = me.legendHitBoxes;
  10271. // current position
  10272. var drawLegendBox = function(x, y, legendItem) {
  10273. if (isNaN(boxWidth) || boxWidth <= 0) {
  10274. return;
  10275. }
  10276. // Set the ctx for the box
  10277. ctx.save();
  10278. ctx.fillStyle = valueOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  10279. ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  10280. ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  10281. ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  10282. ctx.lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  10283. ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  10284. var isLineWidthZero = (valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  10285. if (ctx.setLineDash) {
  10286. // IE 9 and 10 do not support line dash
  10287. ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
  10288. }
  10289. if (opts.labels && opts.labels.usePointStyle) {
  10290. // Recalculate x and y for drawPoint() because its expecting
  10291. // x and y to be center of figure (instead of top left)
  10292. var radius = fontSize * Math.SQRT2 / 2;
  10293. var offSet = radius / Math.SQRT2;
  10294. var centerX = x + offSet;
  10295. var centerY = y + offSet;
  10296. // Draw pointStyle as legend symbol
  10297. helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  10298. } else {
  10299. // Draw box as legend symbol
  10300. if (!isLineWidthZero) {
  10301. ctx.strokeRect(x, y, boxWidth, fontSize);
  10302. }
  10303. ctx.fillRect(x, y, boxWidth, fontSize);
  10304. }
  10305. ctx.restore();
  10306. };
  10307. var fillText = function(x, y, legendItem, textWidth) {
  10308. var halfFontSize = fontSize / 2;
  10309. var xLeft = boxWidth + halfFontSize + x;
  10310. var yMiddle = y + halfFontSize;
  10311. ctx.fillText(legendItem.text, xLeft, yMiddle);
  10312. if (legendItem.hidden) {
  10313. // Strikethrough the text if hidden
  10314. ctx.beginPath();
  10315. ctx.lineWidth = 2;
  10316. ctx.moveTo(xLeft, yMiddle);
  10317. ctx.lineTo(xLeft + textWidth, yMiddle);
  10318. ctx.stroke();
  10319. }
  10320. };
  10321. // Horizontal
  10322. var isHorizontal = me.isHorizontal();
  10323. if (isHorizontal) {
  10324. cursor = {
  10325. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  10326. y: me.top + labelOpts.padding,
  10327. line: 0
  10328. };
  10329. } else {
  10330. cursor = {
  10331. x: me.left + labelOpts.padding,
  10332. y: me.top + labelOpts.padding,
  10333. line: 0
  10334. };
  10335. }
  10336. var itemHeight = fontSize + labelOpts.padding;
  10337. helpers.each(me.legendItems, function(legendItem, i) {
  10338. var textWidth = ctx.measureText(legendItem.text).width;
  10339. var width = boxWidth + (fontSize / 2) + textWidth;
  10340. var x = cursor.x;
  10341. var y = cursor.y;
  10342. if (isHorizontal) {
  10343. if (x + width >= legendWidth) {
  10344. y = cursor.y += itemHeight;
  10345. cursor.line++;
  10346. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  10347. }
  10348. } else if (y + itemHeight > me.bottom) {
  10349. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  10350. y = cursor.y = me.top + labelOpts.padding;
  10351. cursor.line++;
  10352. }
  10353. drawLegendBox(x, y, legendItem);
  10354. hitboxes[i].left = x;
  10355. hitboxes[i].top = y;
  10356. // Fill the actual label
  10357. fillText(x, y, legendItem, textWidth);
  10358. if (isHorizontal) {
  10359. cursor.x += width + (labelOpts.padding);
  10360. } else {
  10361. cursor.y += itemHeight;
  10362. }
  10363. });
  10364. }
  10365. },
  10366. /**
  10367. * Handle an event
  10368. * @private
  10369. * @param {IEvent} event - The event to handle
  10370. * @return {Boolean} true if a change occured
  10371. */
  10372. handleEvent: function(e) {
  10373. var me = this;
  10374. var opts = me.options;
  10375. var type = e.type === 'mouseup' ? 'click' : e.type;
  10376. var changed = false;
  10377. if (type === 'mousemove') {
  10378. if (!opts.onHover) {
  10379. return;
  10380. }
  10381. } else if (type === 'click') {
  10382. if (!opts.onClick) {
  10383. return;
  10384. }
  10385. } else {
  10386. return;
  10387. }
  10388. // Chart event already has relative position in it
  10389. var x = e.x;
  10390. var y = e.y;
  10391. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  10392. // See if we are touching one of the dataset boxes
  10393. var lh = me.legendHitBoxes;
  10394. for (var i = 0; i < lh.length; ++i) {
  10395. var hitBox = lh[i];
  10396. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  10397. // Touching an element
  10398. if (type === 'click') {
  10399. // use e.native for backwards compatibility
  10400. opts.onClick.call(me, e.native, me.legendItems[i]);
  10401. changed = true;
  10402. break;
  10403. } else if (type === 'mousemove') {
  10404. // use e.native for backwards compatibility
  10405. opts.onHover.call(me, e.native, me.legendItems[i]);
  10406. changed = true;
  10407. break;
  10408. }
  10409. }
  10410. }
  10411. }
  10412. return changed;
  10413. }
  10414. });
  10415. function createNewLegendAndAttach(chart, legendOpts) {
  10416. var legend = new Legend({
  10417. ctx: chart.ctx,
  10418. options: legendOpts,
  10419. chart: chart
  10420. });
  10421. layouts.configure(chart, legend, legendOpts);
  10422. layouts.addBox(chart, legend);
  10423. chart.legend = legend;
  10424. }
  10425. module.exports = {
  10426. id: 'legend',
  10427. /**
  10428. * Backward compatibility: since 2.1.5, the legend is registered as a plugin, making
  10429. * Chart.Legend obsolete. To avoid a breaking change, we export the Legend as part of
  10430. * the plugin, which one will be re-exposed in the chart.js file.
  10431. * https://github.com/chartjs/Chart.js/pull/2640
  10432. * @private
  10433. */
  10434. _element: Legend,
  10435. beforeInit: function(chart) {
  10436. var legendOpts = chart.options.legend;
  10437. if (legendOpts) {
  10438. createNewLegendAndAttach(chart, legendOpts);
  10439. }
  10440. },
  10441. beforeUpdate: function(chart) {
  10442. var legendOpts = chart.options.legend;
  10443. var legend = chart.legend;
  10444. if (legendOpts) {
  10445. helpers.mergeIf(legendOpts, defaults.global.legend);
  10446. if (legend) {
  10447. layouts.configure(chart, legend, legendOpts);
  10448. legend.options = legendOpts;
  10449. } else {
  10450. createNewLegendAndAttach(chart, legendOpts);
  10451. }
  10452. } else if (legend) {
  10453. layouts.removeBox(chart, legend);
  10454. delete chart.legend;
  10455. }
  10456. },
  10457. afterEvent: function(chart, e) {
  10458. var legend = chart.legend;
  10459. if (legend) {
  10460. legend.handleEvent(e);
  10461. }
  10462. }
  10463. };
  10464. },{"26":26,"27":27,"31":31,"46":46}],53:[function(require,module,exports){
  10465. 'use strict';
  10466. var defaults = require(26);
  10467. var Element = require(27);
  10468. var helpers = require(46);
  10469. var layouts = require(31);
  10470. var noop = helpers.noop;
  10471. defaults._set('global', {
  10472. title: {
  10473. display: false,
  10474. fontStyle: 'bold',
  10475. fullWidth: true,
  10476. lineHeight: 1.2,
  10477. padding: 10,
  10478. position: 'top',
  10479. text: '',
  10480. weight: 2000 // by default greater than legend (1000) to be above
  10481. }
  10482. });
  10483. /**
  10484. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  10485. */
  10486. var Title = Element.extend({
  10487. initialize: function(config) {
  10488. var me = this;
  10489. helpers.extend(me, config);
  10490. // Contains hit boxes for each dataset (in dataset order)
  10491. me.legendHitBoxes = [];
  10492. },
  10493. // These methods are ordered by lifecycle. Utilities then follow.
  10494. beforeUpdate: noop,
  10495. update: function(maxWidth, maxHeight, margins) {
  10496. var me = this;
  10497. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  10498. me.beforeUpdate();
  10499. // Absorb the master measurements
  10500. me.maxWidth = maxWidth;
  10501. me.maxHeight = maxHeight;
  10502. me.margins = margins;
  10503. // Dimensions
  10504. me.beforeSetDimensions();
  10505. me.setDimensions();
  10506. me.afterSetDimensions();
  10507. // Labels
  10508. me.beforeBuildLabels();
  10509. me.buildLabels();
  10510. me.afterBuildLabels();
  10511. // Fit
  10512. me.beforeFit();
  10513. me.fit();
  10514. me.afterFit();
  10515. //
  10516. me.afterUpdate();
  10517. return me.minSize;
  10518. },
  10519. afterUpdate: noop,
  10520. //
  10521. beforeSetDimensions: noop,
  10522. setDimensions: function() {
  10523. var me = this;
  10524. // Set the unconstrained dimension before label rotation
  10525. if (me.isHorizontal()) {
  10526. // Reset position before calculating rotation
  10527. me.width = me.maxWidth;
  10528. me.left = 0;
  10529. me.right = me.width;
  10530. } else {
  10531. me.height = me.maxHeight;
  10532. // Reset position before calculating rotation
  10533. me.top = 0;
  10534. me.bottom = me.height;
  10535. }
  10536. // Reset padding
  10537. me.paddingLeft = 0;
  10538. me.paddingTop = 0;
  10539. me.paddingRight = 0;
  10540. me.paddingBottom = 0;
  10541. // Reset minSize
  10542. me.minSize = {
  10543. width: 0,
  10544. height: 0
  10545. };
  10546. },
  10547. afterSetDimensions: noop,
  10548. //
  10549. beforeBuildLabels: noop,
  10550. buildLabels: noop,
  10551. afterBuildLabels: noop,
  10552. //
  10553. beforeFit: noop,
  10554. fit: function() {
  10555. var me = this;
  10556. var valueOrDefault = helpers.valueOrDefault;
  10557. var opts = me.options;
  10558. var display = opts.display;
  10559. var fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize);
  10560. var minSize = me.minSize;
  10561. var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
  10562. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10563. var textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
  10564. if (me.isHorizontal()) {
  10565. minSize.width = me.maxWidth; // fill all the width
  10566. minSize.height = textSize;
  10567. } else {
  10568. minSize.width = textSize;
  10569. minSize.height = me.maxHeight; // fill all the height
  10570. }
  10571. me.width = minSize.width;
  10572. me.height = minSize.height;
  10573. },
  10574. afterFit: noop,
  10575. // Shared Methods
  10576. isHorizontal: function() {
  10577. var pos = this.options.position;
  10578. return pos === 'top' || pos === 'bottom';
  10579. },
  10580. // Actually draw the title block on the canvas
  10581. draw: function() {
  10582. var me = this;
  10583. var ctx = me.ctx;
  10584. var valueOrDefault = helpers.valueOrDefault;
  10585. var opts = me.options;
  10586. var globalDefaults = defaults.global;
  10587. if (opts.display) {
  10588. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize);
  10589. var fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle);
  10590. var fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily);
  10591. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10592. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10593. var offset = lineHeight / 2 + opts.padding;
  10594. var rotation = 0;
  10595. var top = me.top;
  10596. var left = me.left;
  10597. var bottom = me.bottom;
  10598. var right = me.right;
  10599. var maxWidth, titleX, titleY;
  10600. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  10601. ctx.font = titleFont;
  10602. // Horizontal
  10603. if (me.isHorizontal()) {
  10604. titleX = left + ((right - left) / 2); // midpoint of the width
  10605. titleY = top + offset;
  10606. maxWidth = right - left;
  10607. } else {
  10608. titleX = opts.position === 'left' ? left + offset : right - offset;
  10609. titleY = top + ((bottom - top) / 2);
  10610. maxWidth = bottom - top;
  10611. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  10612. }
  10613. ctx.save();
  10614. ctx.translate(titleX, titleY);
  10615. ctx.rotate(rotation);
  10616. ctx.textAlign = 'center';
  10617. ctx.textBaseline = 'middle';
  10618. var text = opts.text;
  10619. if (helpers.isArray(text)) {
  10620. var y = 0;
  10621. for (var i = 0; i < text.length; ++i) {
  10622. ctx.fillText(text[i], 0, y, maxWidth);
  10623. y += lineHeight;
  10624. }
  10625. } else {
  10626. ctx.fillText(text, 0, 0, maxWidth);
  10627. }
  10628. ctx.restore();
  10629. }
  10630. }
  10631. });
  10632. function createNewTitleBlockAndAttach(chart, titleOpts) {
  10633. var title = new Title({
  10634. ctx: chart.ctx,
  10635. options: titleOpts,
  10636. chart: chart
  10637. });
  10638. layouts.configure(chart, title, titleOpts);
  10639. layouts.addBox(chart, title);
  10640. chart.titleBlock = title;
  10641. }
  10642. module.exports = {
  10643. id: 'title',
  10644. /**
  10645. * Backward compatibility: since 2.1.5, the title is registered as a plugin, making
  10646. * Chart.Title obsolete. To avoid a breaking change, we export the Title as part of
  10647. * the plugin, which one will be re-exposed in the chart.js file.
  10648. * https://github.com/chartjs/Chart.js/pull/2640
  10649. * @private
  10650. */
  10651. _element: Title,
  10652. beforeInit: function(chart) {
  10653. var titleOpts = chart.options.title;
  10654. if (titleOpts) {
  10655. createNewTitleBlockAndAttach(chart, titleOpts);
  10656. }
  10657. },
  10658. beforeUpdate: function(chart) {
  10659. var titleOpts = chart.options.title;
  10660. var titleBlock = chart.titleBlock;
  10661. if (titleOpts) {
  10662. helpers.mergeIf(titleOpts, defaults.global.title);
  10663. if (titleBlock) {
  10664. layouts.configure(chart, titleBlock, titleOpts);
  10665. titleBlock.options = titleOpts;
  10666. } else {
  10667. createNewTitleBlockAndAttach(chart, titleOpts);
  10668. }
  10669. } else if (titleBlock) {
  10670. layouts.removeBox(chart, titleBlock);
  10671. delete chart.titleBlock;
  10672. }
  10673. }
  10674. };
  10675. },{"26":26,"27":27,"31":31,"46":46}],54:[function(require,module,exports){
  10676. 'use strict';
  10677. var Scale = require(33);
  10678. var scaleService = require(34);
  10679. module.exports = function() {
  10680. // Default config for a category scale
  10681. var defaultConfig = {
  10682. position: 'bottom'
  10683. };
  10684. var DatasetScale = Scale.extend({
  10685. /**
  10686. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
  10687. * else fall back to data.labels
  10688. * @private
  10689. */
  10690. getLabels: function() {
  10691. var data = this.chart.data;
  10692. return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  10693. },
  10694. determineDataLimits: function() {
  10695. var me = this;
  10696. var labels = me.getLabels();
  10697. me.minIndex = 0;
  10698. me.maxIndex = labels.length - 1;
  10699. var findIndex;
  10700. if (me.options.ticks.min !== undefined) {
  10701. // user specified min value
  10702. findIndex = labels.indexOf(me.options.ticks.min);
  10703. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  10704. }
  10705. if (me.options.ticks.max !== undefined) {
  10706. // user specified max value
  10707. findIndex = labels.indexOf(me.options.ticks.max);
  10708. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  10709. }
  10710. me.min = labels[me.minIndex];
  10711. me.max = labels[me.maxIndex];
  10712. },
  10713. buildTicks: function() {
  10714. var me = this;
  10715. var labels = me.getLabels();
  10716. // If we are viewing some subset of labels, slice the original array
  10717. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  10718. },
  10719. getLabelForIndex: function(index, datasetIndex) {
  10720. var me = this;
  10721. var data = me.chart.data;
  10722. var isHorizontal = me.isHorizontal();
  10723. if (data.yLabels && !isHorizontal) {
  10724. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  10725. }
  10726. return me.ticks[index - me.minIndex];
  10727. },
  10728. // Used to get data value locations. Value can either be an index or a numerical value
  10729. getPixelForValue: function(value, index) {
  10730. var me = this;
  10731. var offset = me.options.offset;
  10732. // 1 is added because we need the length but we have the indexes
  10733. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1)), 1);
  10734. // If value is a data object, then index is the index in the data array,
  10735. // not the index of the scale. We need to change that.
  10736. var valueCategory;
  10737. if (value !== undefined && value !== null) {
  10738. valueCategory = me.isHorizontal() ? value.x : value.y;
  10739. }
  10740. if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
  10741. var labels = me.getLabels();
  10742. value = valueCategory || value;
  10743. var idx = labels.indexOf(value);
  10744. index = idx !== -1 ? idx : index;
  10745. }
  10746. if (me.isHorizontal()) {
  10747. var valueWidth = me.width / offsetAmt;
  10748. var widthOffset = (valueWidth * (index - me.minIndex));
  10749. if (offset) {
  10750. widthOffset += (valueWidth / 2);
  10751. }
  10752. return me.left + Math.round(widthOffset);
  10753. }
  10754. var valueHeight = me.height / offsetAmt;
  10755. var heightOffset = (valueHeight * (index - me.minIndex));
  10756. if (offset) {
  10757. heightOffset += (valueHeight / 2);
  10758. }
  10759. return me.top + Math.round(heightOffset);
  10760. },
  10761. getPixelForTick: function(index) {
  10762. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null);
  10763. },
  10764. getValueForPixel: function(pixel) {
  10765. var me = this;
  10766. var offset = me.options.offset;
  10767. var value;
  10768. var offsetAmt = Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  10769. var horz = me.isHorizontal();
  10770. var valueDimension = (horz ? me.width : me.height) / offsetAmt;
  10771. pixel -= horz ? me.left : me.top;
  10772. if (offset) {
  10773. pixel -= (valueDimension / 2);
  10774. }
  10775. if (pixel <= 0) {
  10776. value = 0;
  10777. } else {
  10778. value = Math.round(pixel / valueDimension);
  10779. }
  10780. return value + me.minIndex;
  10781. },
  10782. getBasePixel: function() {
  10783. return this.bottom;
  10784. }
  10785. });
  10786. scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  10787. };
  10788. },{"33":33,"34":34}],55:[function(require,module,exports){
  10789. 'use strict';
  10790. var defaults = require(26);
  10791. var helpers = require(46);
  10792. var scaleService = require(34);
  10793. var Ticks = require(35);
  10794. module.exports = function(Chart) {
  10795. var defaultConfig = {
  10796. position: 'left',
  10797. ticks: {
  10798. callback: Ticks.formatters.linear
  10799. }
  10800. };
  10801. var LinearScale = Chart.LinearScaleBase.extend({
  10802. determineDataLimits: function() {
  10803. var me = this;
  10804. var opts = me.options;
  10805. var chart = me.chart;
  10806. var data = chart.data;
  10807. var datasets = data.datasets;
  10808. var isHorizontal = me.isHorizontal();
  10809. var DEFAULT_MIN = 0;
  10810. var DEFAULT_MAX = 1;
  10811. function IDMatches(meta) {
  10812. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10813. }
  10814. // First Calculate the range
  10815. me.min = null;
  10816. me.max = null;
  10817. var hasStacks = opts.stacked;
  10818. if (hasStacks === undefined) {
  10819. helpers.each(datasets, function(dataset, datasetIndex) {
  10820. if (hasStacks) {
  10821. return;
  10822. }
  10823. var meta = chart.getDatasetMeta(datasetIndex);
  10824. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10825. meta.stack !== undefined) {
  10826. hasStacks = true;
  10827. }
  10828. });
  10829. }
  10830. if (opts.stacked || hasStacks) {
  10831. var valuesPerStack = {};
  10832. helpers.each(datasets, function(dataset, datasetIndex) {
  10833. var meta = chart.getDatasetMeta(datasetIndex);
  10834. var key = [
  10835. meta.type,
  10836. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10837. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10838. meta.stack
  10839. ].join('.');
  10840. if (valuesPerStack[key] === undefined) {
  10841. valuesPerStack[key] = {
  10842. positiveValues: [],
  10843. negativeValues: []
  10844. };
  10845. }
  10846. // Store these per type
  10847. var positiveValues = valuesPerStack[key].positiveValues;
  10848. var negativeValues = valuesPerStack[key].negativeValues;
  10849. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10850. helpers.each(dataset.data, function(rawValue, index) {
  10851. var value = +me.getRightValue(rawValue);
  10852. if (isNaN(value) || meta.data[index].hidden) {
  10853. return;
  10854. }
  10855. positiveValues[index] = positiveValues[index] || 0;
  10856. negativeValues[index] = negativeValues[index] || 0;
  10857. if (opts.relativePoints) {
  10858. positiveValues[index] = 100;
  10859. } else if (value < 0) {
  10860. negativeValues[index] += value;
  10861. } else {
  10862. positiveValues[index] += value;
  10863. }
  10864. });
  10865. }
  10866. });
  10867. helpers.each(valuesPerStack, function(valuesForType) {
  10868. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  10869. var minVal = helpers.min(values);
  10870. var maxVal = helpers.max(values);
  10871. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  10872. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  10873. });
  10874. } else {
  10875. helpers.each(datasets, function(dataset, datasetIndex) {
  10876. var meta = chart.getDatasetMeta(datasetIndex);
  10877. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10878. helpers.each(dataset.data, function(rawValue, index) {
  10879. var value = +me.getRightValue(rawValue);
  10880. if (isNaN(value) || meta.data[index].hidden) {
  10881. return;
  10882. }
  10883. if (me.min === null) {
  10884. me.min = value;
  10885. } else if (value < me.min) {
  10886. me.min = value;
  10887. }
  10888. if (me.max === null) {
  10889. me.max = value;
  10890. } else if (value > me.max) {
  10891. me.max = value;
  10892. }
  10893. });
  10894. }
  10895. });
  10896. }
  10897. me.min = isFinite(me.min) && !isNaN(me.min) ? me.min : DEFAULT_MIN;
  10898. me.max = isFinite(me.max) && !isNaN(me.max) ? me.max : DEFAULT_MAX;
  10899. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  10900. this.handleTickRangeOptions();
  10901. },
  10902. getTickLimit: function() {
  10903. var maxTicks;
  10904. var me = this;
  10905. var tickOpts = me.options.ticks;
  10906. if (me.isHorizontal()) {
  10907. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  10908. } else {
  10909. // The factor of 2 used to scale the font size has been experimentally determined.
  10910. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
  10911. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  10912. }
  10913. return maxTicks;
  10914. },
  10915. // Called after the ticks are built. We need
  10916. handleDirectionalChanges: function() {
  10917. if (!this.isHorizontal()) {
  10918. // We are in a vertical orientation. The top value is the highest. So reverse the array
  10919. this.ticks.reverse();
  10920. }
  10921. },
  10922. getLabelForIndex: function(index, datasetIndex) {
  10923. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  10924. },
  10925. // Utils
  10926. getPixelForValue: function(value) {
  10927. // This must be called after fit has been run so that
  10928. // this.left, this.top, this.right, and this.bottom have been defined
  10929. var me = this;
  10930. var start = me.start;
  10931. var rightValue = +me.getRightValue(value);
  10932. var pixel;
  10933. var range = me.end - start;
  10934. if (me.isHorizontal()) {
  10935. pixel = me.left + (me.width / range * (rightValue - start));
  10936. } else {
  10937. pixel = me.bottom - (me.height / range * (rightValue - start));
  10938. }
  10939. return pixel;
  10940. },
  10941. getValueForPixel: function(pixel) {
  10942. var me = this;
  10943. var isHorizontal = me.isHorizontal();
  10944. var innerDimension = isHorizontal ? me.width : me.height;
  10945. var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
  10946. return me.start + ((me.end - me.start) * offset);
  10947. },
  10948. getPixelForTick: function(index) {
  10949. return this.getPixelForValue(this.ticksAsNumbers[index]);
  10950. }
  10951. });
  10952. scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  10953. };
  10954. },{"26":26,"34":34,"35":35,"46":46}],56:[function(require,module,exports){
  10955. 'use strict';
  10956. var helpers = require(46);
  10957. var Scale = require(33);
  10958. /**
  10959. * Generate a set of linear ticks
  10960. * @param generationOptions the options used to generate the ticks
  10961. * @param dataRange the range of the data
  10962. * @returns {Array<Number>} array of tick values
  10963. */
  10964. function generateTicks(generationOptions, dataRange) {
  10965. var ticks = [];
  10966. // To get a "nice" value for the tick spacing, we will use the appropriately named
  10967. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  10968. // for details.
  10969. var factor;
  10970. var precision;
  10971. var spacing;
  10972. if (generationOptions.stepSize && generationOptions.stepSize > 0) {
  10973. spacing = generationOptions.stepSize;
  10974. } else {
  10975. var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
  10976. spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
  10977. precision = generationOptions.precision;
  10978. if (precision !== undefined) {
  10979. // If the user specified a precision, round to that number of decimal places
  10980. factor = Math.pow(10, precision);
  10981. spacing = Math.ceil(spacing * factor) / factor;
  10982. }
  10983. }
  10984. var niceMin = Math.floor(dataRange.min / spacing) * spacing;
  10985. var niceMax = Math.ceil(dataRange.max / spacing) * spacing;
  10986. // If min, max and stepSize is set and they make an evenly spaced scale use it.
  10987. if (!helpers.isNullOrUndef(generationOptions.min) && !helpers.isNullOrUndef(generationOptions.max) && generationOptions.stepSize) {
  10988. // If very close to our whole number, use it.
  10989. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
  10990. niceMin = generationOptions.min;
  10991. niceMax = generationOptions.max;
  10992. }
  10993. }
  10994. var numSpaces = (niceMax - niceMin) / spacing;
  10995. // If very close to our rounded value, use it.
  10996. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  10997. numSpaces = Math.round(numSpaces);
  10998. } else {
  10999. numSpaces = Math.ceil(numSpaces);
  11000. }
  11001. precision = 1;
  11002. if (spacing < 1) {
  11003. precision = Math.pow(10, 1 - Math.floor(helpers.log10(spacing)));
  11004. niceMin = Math.round(niceMin * precision) / precision;
  11005. niceMax = Math.round(niceMax * precision) / precision;
  11006. }
  11007. ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
  11008. for (var j = 1; j < numSpaces; ++j) {
  11009. ticks.push(Math.round((niceMin + j * spacing) * precision) / precision);
  11010. }
  11011. ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);
  11012. return ticks;
  11013. }
  11014. module.exports = function(Chart) {
  11015. var noop = helpers.noop;
  11016. Chart.LinearScaleBase = Scale.extend({
  11017. getRightValue: function(value) {
  11018. if (typeof value === 'string') {
  11019. return +value;
  11020. }
  11021. return Scale.prototype.getRightValue.call(this, value);
  11022. },
  11023. handleTickRangeOptions: function() {
  11024. var me = this;
  11025. var opts = me.options;
  11026. var tickOpts = opts.ticks;
  11027. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  11028. // do nothing since that would make the chart weird. If the user really wants a weird chart
  11029. // axis, they can manually override it
  11030. if (tickOpts.beginAtZero) {
  11031. var minSign = helpers.sign(me.min);
  11032. var maxSign = helpers.sign(me.max);
  11033. if (minSign < 0 && maxSign < 0) {
  11034. // move the top up to 0
  11035. me.max = 0;
  11036. } else if (minSign > 0 && maxSign > 0) {
  11037. // move the bottom down to 0
  11038. me.min = 0;
  11039. }
  11040. }
  11041. var setMin = tickOpts.min !== undefined || tickOpts.suggestedMin !== undefined;
  11042. var setMax = tickOpts.max !== undefined || tickOpts.suggestedMax !== undefined;
  11043. if (tickOpts.min !== undefined) {
  11044. me.min = tickOpts.min;
  11045. } else if (tickOpts.suggestedMin !== undefined) {
  11046. if (me.min === null) {
  11047. me.min = tickOpts.suggestedMin;
  11048. } else {
  11049. me.min = Math.min(me.min, tickOpts.suggestedMin);
  11050. }
  11051. }
  11052. if (tickOpts.max !== undefined) {
  11053. me.max = tickOpts.max;
  11054. } else if (tickOpts.suggestedMax !== undefined) {
  11055. if (me.max === null) {
  11056. me.max = tickOpts.suggestedMax;
  11057. } else {
  11058. me.max = Math.max(me.max, tickOpts.suggestedMax);
  11059. }
  11060. }
  11061. if (setMin !== setMax) {
  11062. // We set the min or the max but not both.
  11063. // So ensure that our range is good
  11064. // Inverted or 0 length range can happen when
  11065. // ticks.min is set, and no datasets are visible
  11066. if (me.min >= me.max) {
  11067. if (setMin) {
  11068. me.max = me.min + 1;
  11069. } else {
  11070. me.min = me.max - 1;
  11071. }
  11072. }
  11073. }
  11074. if (me.min === me.max) {
  11075. me.max++;
  11076. if (!tickOpts.beginAtZero) {
  11077. me.min--;
  11078. }
  11079. }
  11080. },
  11081. getTickLimit: noop,
  11082. handleDirectionalChanges: noop,
  11083. buildTicks: function() {
  11084. var me = this;
  11085. var opts = me.options;
  11086. var tickOpts = opts.ticks;
  11087. // Figure out what the max number of ticks we can support it is based on the size of
  11088. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  11089. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  11090. // the graph. Make sure we always have at least 2 ticks
  11091. var maxTicks = me.getTickLimit();
  11092. maxTicks = Math.max(2, maxTicks);
  11093. var numericGeneratorOptions = {
  11094. maxTicks: maxTicks,
  11095. min: tickOpts.min,
  11096. max: tickOpts.max,
  11097. precision: tickOpts.precision,
  11098. stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
  11099. };
  11100. var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
  11101. me.handleDirectionalChanges();
  11102. // At this point, we need to update our max and min given the tick values since we have expanded the
  11103. // range of the scale
  11104. me.max = helpers.max(ticks);
  11105. me.min = helpers.min(ticks);
  11106. if (tickOpts.reverse) {
  11107. ticks.reverse();
  11108. me.start = me.max;
  11109. me.end = me.min;
  11110. } else {
  11111. me.start = me.min;
  11112. me.end = me.max;
  11113. }
  11114. },
  11115. convertTicksToLabels: function() {
  11116. var me = this;
  11117. me.ticksAsNumbers = me.ticks.slice();
  11118. me.zeroLineIndex = me.ticks.indexOf(0);
  11119. Scale.prototype.convertTicksToLabels.call(me);
  11120. }
  11121. });
  11122. };
  11123. },{"33":33,"46":46}],57:[function(require,module,exports){
  11124. 'use strict';
  11125. var helpers = require(46);
  11126. var Scale = require(33);
  11127. var scaleService = require(34);
  11128. var Ticks = require(35);
  11129. /**
  11130. * Generate a set of logarithmic ticks
  11131. * @param generationOptions the options used to generate the ticks
  11132. * @param dataRange the range of the data
  11133. * @returns {Array<Number>} array of tick values
  11134. */
  11135. function generateTicks(generationOptions, dataRange) {
  11136. var ticks = [];
  11137. var valueOrDefault = helpers.valueOrDefault;
  11138. // Figure out what the max number of ticks we can support it is based on the size of
  11139. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  11140. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  11141. // the graph
  11142. var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
  11143. var endExp = Math.floor(helpers.log10(dataRange.max));
  11144. var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
  11145. var exp, significand;
  11146. if (tickVal === 0) {
  11147. exp = Math.floor(helpers.log10(dataRange.minNotZero));
  11148. significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
  11149. ticks.push(tickVal);
  11150. tickVal = significand * Math.pow(10, exp);
  11151. } else {
  11152. exp = Math.floor(helpers.log10(tickVal));
  11153. significand = Math.floor(tickVal / Math.pow(10, exp));
  11154. }
  11155. var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
  11156. do {
  11157. ticks.push(tickVal);
  11158. ++significand;
  11159. if (significand === 10) {
  11160. significand = 1;
  11161. ++exp;
  11162. precision = exp >= 0 ? 1 : precision;
  11163. }
  11164. tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
  11165. } while (exp < endExp || (exp === endExp && significand < endSignificand));
  11166. var lastTick = valueOrDefault(generationOptions.max, tickVal);
  11167. ticks.push(lastTick);
  11168. return ticks;
  11169. }
  11170. module.exports = function(Chart) {
  11171. var defaultConfig = {
  11172. position: 'left',
  11173. // label settings
  11174. ticks: {
  11175. callback: Ticks.formatters.logarithmic
  11176. }
  11177. };
  11178. var LogarithmicScale = Scale.extend({
  11179. determineDataLimits: function() {
  11180. var me = this;
  11181. var opts = me.options;
  11182. var chart = me.chart;
  11183. var data = chart.data;
  11184. var datasets = data.datasets;
  11185. var isHorizontal = me.isHorizontal();
  11186. function IDMatches(meta) {
  11187. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  11188. }
  11189. // Calculate Range
  11190. me.min = null;
  11191. me.max = null;
  11192. me.minNotZero = null;
  11193. var hasStacks = opts.stacked;
  11194. if (hasStacks === undefined) {
  11195. helpers.each(datasets, function(dataset, datasetIndex) {
  11196. if (hasStacks) {
  11197. return;
  11198. }
  11199. var meta = chart.getDatasetMeta(datasetIndex);
  11200. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  11201. meta.stack !== undefined) {
  11202. hasStacks = true;
  11203. }
  11204. });
  11205. }
  11206. if (opts.stacked || hasStacks) {
  11207. var valuesPerStack = {};
  11208. helpers.each(datasets, function(dataset, datasetIndex) {
  11209. var meta = chart.getDatasetMeta(datasetIndex);
  11210. var key = [
  11211. meta.type,
  11212. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  11213. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  11214. meta.stack
  11215. ].join('.');
  11216. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11217. if (valuesPerStack[key] === undefined) {
  11218. valuesPerStack[key] = [];
  11219. }
  11220. helpers.each(dataset.data, function(rawValue, index) {
  11221. var values = valuesPerStack[key];
  11222. var value = +me.getRightValue(rawValue);
  11223. // invalid, hidden and negative values are ignored
  11224. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  11225. return;
  11226. }
  11227. values[index] = values[index] || 0;
  11228. values[index] += value;
  11229. });
  11230. }
  11231. });
  11232. helpers.each(valuesPerStack, function(valuesForType) {
  11233. if (valuesForType.length > 0) {
  11234. var minVal = helpers.min(valuesForType);
  11235. var maxVal = helpers.max(valuesForType);
  11236. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  11237. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  11238. }
  11239. });
  11240. } else {
  11241. helpers.each(datasets, function(dataset, datasetIndex) {
  11242. var meta = chart.getDatasetMeta(datasetIndex);
  11243. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11244. helpers.each(dataset.data, function(rawValue, index) {
  11245. var value = +me.getRightValue(rawValue);
  11246. // invalid, hidden and negative values are ignored
  11247. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  11248. return;
  11249. }
  11250. if (me.min === null) {
  11251. me.min = value;
  11252. } else if (value < me.min) {
  11253. me.min = value;
  11254. }
  11255. if (me.max === null) {
  11256. me.max = value;
  11257. } else if (value > me.max) {
  11258. me.max = value;
  11259. }
  11260. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  11261. me.minNotZero = value;
  11262. }
  11263. });
  11264. }
  11265. });
  11266. }
  11267. // Common base implementation to handle ticks.min, ticks.max
  11268. this.handleTickRangeOptions();
  11269. },
  11270. handleTickRangeOptions: function() {
  11271. var me = this;
  11272. var opts = me.options;
  11273. var tickOpts = opts.ticks;
  11274. var valueOrDefault = helpers.valueOrDefault;
  11275. var DEFAULT_MIN = 1;
  11276. var DEFAULT_MAX = 10;
  11277. me.min = valueOrDefault(tickOpts.min, me.min);
  11278. me.max = valueOrDefault(tickOpts.max, me.max);
  11279. if (me.min === me.max) {
  11280. if (me.min !== 0 && me.min !== null) {
  11281. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  11282. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  11283. } else {
  11284. me.min = DEFAULT_MIN;
  11285. me.max = DEFAULT_MAX;
  11286. }
  11287. }
  11288. if (me.min === null) {
  11289. me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
  11290. }
  11291. if (me.max === null) {
  11292. me.max = me.min !== 0
  11293. ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
  11294. : DEFAULT_MAX;
  11295. }
  11296. if (me.minNotZero === null) {
  11297. if (me.min > 0) {
  11298. me.minNotZero = me.min;
  11299. } else if (me.max < 1) {
  11300. me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
  11301. } else {
  11302. me.minNotZero = DEFAULT_MIN;
  11303. }
  11304. }
  11305. },
  11306. buildTicks: function() {
  11307. var me = this;
  11308. var opts = me.options;
  11309. var tickOpts = opts.ticks;
  11310. var reverse = !me.isHorizontal();
  11311. var generationOptions = {
  11312. min: tickOpts.min,
  11313. max: tickOpts.max
  11314. };
  11315. var ticks = me.ticks = generateTicks(generationOptions, me);
  11316. // At this point, we need to update our max and min given the tick values since we have expanded the
  11317. // range of the scale
  11318. me.max = helpers.max(ticks);
  11319. me.min = helpers.min(ticks);
  11320. if (tickOpts.reverse) {
  11321. reverse = !reverse;
  11322. me.start = me.max;
  11323. me.end = me.min;
  11324. } else {
  11325. me.start = me.min;
  11326. me.end = me.max;
  11327. }
  11328. if (reverse) {
  11329. ticks.reverse();
  11330. }
  11331. },
  11332. convertTicksToLabels: function() {
  11333. this.tickValues = this.ticks.slice();
  11334. Scale.prototype.convertTicksToLabels.call(this);
  11335. },
  11336. // Get the correct tooltip label
  11337. getLabelForIndex: function(index, datasetIndex) {
  11338. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11339. },
  11340. getPixelForTick: function(index) {
  11341. return this.getPixelForValue(this.tickValues[index]);
  11342. },
  11343. /**
  11344. * Returns the value of the first tick.
  11345. * @param {Number} value - The minimum not zero value.
  11346. * @return {Number} The first tick value.
  11347. * @private
  11348. */
  11349. _getFirstTickValue: function(value) {
  11350. var exp = Math.floor(helpers.log10(value));
  11351. var significand = Math.floor(value / Math.pow(10, exp));
  11352. return significand * Math.pow(10, exp);
  11353. },
  11354. getPixelForValue: function(value) {
  11355. var me = this;
  11356. var reverse = me.options.ticks.reverse;
  11357. var log10 = helpers.log10;
  11358. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11359. var offset = 0;
  11360. var innerDimension, pixel, start, end, sign;
  11361. value = +me.getRightValue(value);
  11362. if (reverse) {
  11363. start = me.end;
  11364. end = me.start;
  11365. sign = -1;
  11366. } else {
  11367. start = me.start;
  11368. end = me.end;
  11369. sign = 1;
  11370. }
  11371. if (me.isHorizontal()) {
  11372. innerDimension = me.width;
  11373. pixel = reverse ? me.right : me.left;
  11374. } else {
  11375. innerDimension = me.height;
  11376. sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
  11377. pixel = reverse ? me.top : me.bottom;
  11378. }
  11379. if (value !== start) {
  11380. if (start === 0) { // include zero tick
  11381. offset = helpers.getValueOrDefault(
  11382. me.options.ticks.fontSize,
  11383. Chart.defaults.global.defaultFontSize
  11384. );
  11385. innerDimension -= offset;
  11386. start = firstTickValue;
  11387. }
  11388. if (value !== 0) {
  11389. offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
  11390. }
  11391. pixel += sign * offset;
  11392. }
  11393. return pixel;
  11394. },
  11395. getValueForPixel: function(pixel) {
  11396. var me = this;
  11397. var reverse = me.options.ticks.reverse;
  11398. var log10 = helpers.log10;
  11399. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11400. var innerDimension, start, end, value;
  11401. if (reverse) {
  11402. start = me.end;
  11403. end = me.start;
  11404. } else {
  11405. start = me.start;
  11406. end = me.end;
  11407. }
  11408. if (me.isHorizontal()) {
  11409. innerDimension = me.width;
  11410. value = reverse ? me.right - pixel : pixel - me.left;
  11411. } else {
  11412. innerDimension = me.height;
  11413. value = reverse ? pixel - me.top : me.bottom - pixel;
  11414. }
  11415. if (value !== start) {
  11416. if (start === 0) { // include zero tick
  11417. var offset = helpers.getValueOrDefault(
  11418. me.options.ticks.fontSize,
  11419. Chart.defaults.global.defaultFontSize
  11420. );
  11421. value -= offset;
  11422. innerDimension -= offset;
  11423. start = firstTickValue;
  11424. }
  11425. value *= log10(end) - log10(start);
  11426. value /= innerDimension;
  11427. value = Math.pow(10, log10(start) + value);
  11428. }
  11429. return value;
  11430. }
  11431. });
  11432. scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  11433. };
  11434. },{"33":33,"34":34,"35":35,"46":46}],58:[function(require,module,exports){
  11435. 'use strict';
  11436. var defaults = require(26);
  11437. var helpers = require(46);
  11438. var scaleService = require(34);
  11439. var Ticks = require(35);
  11440. module.exports = function(Chart) {
  11441. var globalDefaults = defaults.global;
  11442. var defaultConfig = {
  11443. display: true,
  11444. // Boolean - Whether to animate scaling the chart from the centre
  11445. animate: true,
  11446. position: 'chartArea',
  11447. angleLines: {
  11448. display: true,
  11449. color: 'rgba(0, 0, 0, 0.1)',
  11450. lineWidth: 1
  11451. },
  11452. gridLines: {
  11453. circular: false
  11454. },
  11455. // label settings
  11456. ticks: {
  11457. // Boolean - Show a backdrop to the scale label
  11458. showLabelBackdrop: true,
  11459. // String - The colour of the label backdrop
  11460. backdropColor: 'rgba(255,255,255,0.75)',
  11461. // Number - The backdrop padding above & below the label in pixels
  11462. backdropPaddingY: 2,
  11463. // Number - The backdrop padding to the side of the label in pixels
  11464. backdropPaddingX: 2,
  11465. callback: Ticks.formatters.linear
  11466. },
  11467. pointLabels: {
  11468. // Boolean - if true, show point labels
  11469. display: true,
  11470. // Number - Point label font size in pixels
  11471. fontSize: 10,
  11472. // Function - Used to convert point labels
  11473. callback: function(label) {
  11474. return label;
  11475. }
  11476. }
  11477. };
  11478. function getValueCount(scale) {
  11479. var opts = scale.options;
  11480. return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
  11481. }
  11482. function getPointLabelFontOptions(scale) {
  11483. var pointLabelOptions = scale.options.pointLabels;
  11484. var fontSize = helpers.valueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
  11485. var fontStyle = helpers.valueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
  11486. var fontFamily = helpers.valueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
  11487. var font = helpers.fontString(fontSize, fontStyle, fontFamily);
  11488. return {
  11489. size: fontSize,
  11490. style: fontStyle,
  11491. family: fontFamily,
  11492. font: font
  11493. };
  11494. }
  11495. function measureLabelSize(ctx, fontSize, label) {
  11496. if (helpers.isArray(label)) {
  11497. return {
  11498. w: helpers.longestText(ctx, ctx.font, label),
  11499. h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
  11500. };
  11501. }
  11502. return {
  11503. w: ctx.measureText(label).width,
  11504. h: fontSize
  11505. };
  11506. }
  11507. function determineLimits(angle, pos, size, min, max) {
  11508. if (angle === min || angle === max) {
  11509. return {
  11510. start: pos - (size / 2),
  11511. end: pos + (size / 2)
  11512. };
  11513. } else if (angle < min || angle > max) {
  11514. return {
  11515. start: pos - size - 5,
  11516. end: pos
  11517. };
  11518. }
  11519. return {
  11520. start: pos,
  11521. end: pos + size + 5
  11522. };
  11523. }
  11524. /**
  11525. * Helper function to fit a radial linear scale with point labels
  11526. */
  11527. function fitWithPointLabels(scale) {
  11528. /*
  11529. * Right, this is really confusing and there is a lot of maths going on here
  11530. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  11531. *
  11532. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  11533. *
  11534. * Solution:
  11535. *
  11536. * We assume the radius of the polygon is half the size of the canvas at first
  11537. * at each index we check if the text overlaps.
  11538. *
  11539. * Where it does, we store that angle and that index.
  11540. *
  11541. * After finding the largest index and angle we calculate how much we need to remove
  11542. * from the shape radius to move the point inwards by that x.
  11543. *
  11544. * We average the left and right distances to get the maximum shape radius that can fit in the box
  11545. * along with labels.
  11546. *
  11547. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  11548. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  11549. *
  11550. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  11551. * and position it in the most space efficient manner
  11552. *
  11553. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  11554. */
  11555. var plFont = getPointLabelFontOptions(scale);
  11556. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  11557. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  11558. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11559. var furthestLimits = {
  11560. r: scale.width,
  11561. l: 0,
  11562. t: scale.height,
  11563. b: 0
  11564. };
  11565. var furthestAngles = {};
  11566. var i, textSize, pointPosition;
  11567. scale.ctx.font = plFont.font;
  11568. scale._pointLabelSizes = [];
  11569. var valueCount = getValueCount(scale);
  11570. for (i = 0; i < valueCount; i++) {
  11571. pointPosition = scale.getPointPosition(i, largestPossibleRadius);
  11572. textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
  11573. scale._pointLabelSizes[i] = textSize;
  11574. // Add quarter circle to make degree 0 mean top of circle
  11575. var angleRadians = scale.getIndexAngle(i);
  11576. var angle = helpers.toDegrees(angleRadians) % 360;
  11577. var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
  11578. var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
  11579. if (hLimits.start < furthestLimits.l) {
  11580. furthestLimits.l = hLimits.start;
  11581. furthestAngles.l = angleRadians;
  11582. }
  11583. if (hLimits.end > furthestLimits.r) {
  11584. furthestLimits.r = hLimits.end;
  11585. furthestAngles.r = angleRadians;
  11586. }
  11587. if (vLimits.start < furthestLimits.t) {
  11588. furthestLimits.t = vLimits.start;
  11589. furthestAngles.t = angleRadians;
  11590. }
  11591. if (vLimits.end > furthestLimits.b) {
  11592. furthestLimits.b = vLimits.end;
  11593. furthestAngles.b = angleRadians;
  11594. }
  11595. }
  11596. scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
  11597. }
  11598. /**
  11599. * Helper function to fit a radial linear scale with no point labels
  11600. */
  11601. function fit(scale) {
  11602. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11603. scale.drawingArea = Math.round(largestPossibleRadius);
  11604. scale.setCenterPoint(0, 0, 0, 0);
  11605. }
  11606. function getTextAlignForAngle(angle) {
  11607. if (angle === 0 || angle === 180) {
  11608. return 'center';
  11609. } else if (angle < 180) {
  11610. return 'left';
  11611. }
  11612. return 'right';
  11613. }
  11614. function fillText(ctx, text, position, fontSize) {
  11615. if (helpers.isArray(text)) {
  11616. var y = position.y;
  11617. var spacing = 1.5 * fontSize;
  11618. for (var i = 0; i < text.length; ++i) {
  11619. ctx.fillText(text[i], position.x, y);
  11620. y += spacing;
  11621. }
  11622. } else {
  11623. ctx.fillText(text, position.x, position.y);
  11624. }
  11625. }
  11626. function adjustPointPositionForLabelHeight(angle, textSize, position) {
  11627. if (angle === 90 || angle === 270) {
  11628. position.y -= (textSize.h / 2);
  11629. } else if (angle > 270 || angle < 90) {
  11630. position.y -= textSize.h;
  11631. }
  11632. }
  11633. function drawPointLabels(scale) {
  11634. var ctx = scale.ctx;
  11635. var opts = scale.options;
  11636. var angleLineOpts = opts.angleLines;
  11637. var pointLabelOpts = opts.pointLabels;
  11638. ctx.lineWidth = angleLineOpts.lineWidth;
  11639. ctx.strokeStyle = angleLineOpts.color;
  11640. var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
  11641. // Point Label Font
  11642. var plFont = getPointLabelFontOptions(scale);
  11643. ctx.textBaseline = 'top';
  11644. for (var i = getValueCount(scale) - 1; i >= 0; i--) {
  11645. if (angleLineOpts.display) {
  11646. var outerPosition = scale.getPointPosition(i, outerDistance);
  11647. ctx.beginPath();
  11648. ctx.moveTo(scale.xCenter, scale.yCenter);
  11649. ctx.lineTo(outerPosition.x, outerPosition.y);
  11650. ctx.stroke();
  11651. ctx.closePath();
  11652. }
  11653. if (pointLabelOpts.display) {
  11654. // Extra 3px out for some label spacing
  11655. var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
  11656. // Keep this in loop since we may support array properties here
  11657. var pointLabelFontColor = helpers.valueAtIndexOrDefault(pointLabelOpts.fontColor, i, globalDefaults.defaultFontColor);
  11658. ctx.font = plFont.font;
  11659. ctx.fillStyle = pointLabelFontColor;
  11660. var angleRadians = scale.getIndexAngle(i);
  11661. var angle = helpers.toDegrees(angleRadians);
  11662. ctx.textAlign = getTextAlignForAngle(angle);
  11663. adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
  11664. fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
  11665. }
  11666. }
  11667. }
  11668. function drawRadiusLine(scale, gridLineOpts, radius, index) {
  11669. var ctx = scale.ctx;
  11670. ctx.strokeStyle = helpers.valueAtIndexOrDefault(gridLineOpts.color, index - 1);
  11671. ctx.lineWidth = helpers.valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  11672. if (scale.options.gridLines.circular) {
  11673. // Draw circular arcs between the points
  11674. ctx.beginPath();
  11675. ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
  11676. ctx.closePath();
  11677. ctx.stroke();
  11678. } else {
  11679. // Draw straight lines connecting each index
  11680. var valueCount = getValueCount(scale);
  11681. if (valueCount === 0) {
  11682. return;
  11683. }
  11684. ctx.beginPath();
  11685. var pointPosition = scale.getPointPosition(0, radius);
  11686. ctx.moveTo(pointPosition.x, pointPosition.y);
  11687. for (var i = 1; i < valueCount; i++) {
  11688. pointPosition = scale.getPointPosition(i, radius);
  11689. ctx.lineTo(pointPosition.x, pointPosition.y);
  11690. }
  11691. ctx.closePath();
  11692. ctx.stroke();
  11693. }
  11694. }
  11695. function numberOrZero(param) {
  11696. return helpers.isNumber(param) ? param : 0;
  11697. }
  11698. var LinearRadialScale = Chart.LinearScaleBase.extend({
  11699. setDimensions: function() {
  11700. var me = this;
  11701. var opts = me.options;
  11702. var tickOpts = opts.ticks;
  11703. // Set the unconstrained dimension before label rotation
  11704. me.width = me.maxWidth;
  11705. me.height = me.maxHeight;
  11706. me.xCenter = Math.round(me.width / 2);
  11707. me.yCenter = Math.round(me.height / 2);
  11708. var minSize = helpers.min([me.height, me.width]);
  11709. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11710. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  11711. },
  11712. determineDataLimits: function() {
  11713. var me = this;
  11714. var chart = me.chart;
  11715. var min = Number.POSITIVE_INFINITY;
  11716. var max = Number.NEGATIVE_INFINITY;
  11717. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  11718. if (chart.isDatasetVisible(datasetIndex)) {
  11719. var meta = chart.getDatasetMeta(datasetIndex);
  11720. helpers.each(dataset.data, function(rawValue, index) {
  11721. var value = +me.getRightValue(rawValue);
  11722. if (isNaN(value) || meta.data[index].hidden) {
  11723. return;
  11724. }
  11725. min = Math.min(value, min);
  11726. max = Math.max(value, max);
  11727. });
  11728. }
  11729. });
  11730. me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
  11731. me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
  11732. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  11733. me.handleTickRangeOptions();
  11734. },
  11735. getTickLimit: function() {
  11736. var tickOpts = this.options.ticks;
  11737. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11738. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  11739. },
  11740. convertTicksToLabels: function() {
  11741. var me = this;
  11742. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  11743. // Point labels
  11744. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  11745. },
  11746. getLabelForIndex: function(index, datasetIndex) {
  11747. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11748. },
  11749. fit: function() {
  11750. if (this.options.pointLabels.display) {
  11751. fitWithPointLabels(this);
  11752. } else {
  11753. fit(this);
  11754. }
  11755. },
  11756. /**
  11757. * Set radius reductions and determine new radius and center point
  11758. * @private
  11759. */
  11760. setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) {
  11761. var me = this;
  11762. var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
  11763. var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
  11764. var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
  11765. var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
  11766. radiusReductionLeft = numberOrZero(radiusReductionLeft);
  11767. radiusReductionRight = numberOrZero(radiusReductionRight);
  11768. radiusReductionTop = numberOrZero(radiusReductionTop);
  11769. radiusReductionBottom = numberOrZero(radiusReductionBottom);
  11770. me.drawingArea = Math.min(
  11771. Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
  11772. Math.round(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
  11773. me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
  11774. },
  11775. setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) {
  11776. var me = this;
  11777. var maxRight = me.width - rightMovement - me.drawingArea;
  11778. var maxLeft = leftMovement + me.drawingArea;
  11779. var maxTop = topMovement + me.drawingArea;
  11780. var maxBottom = me.height - bottomMovement - me.drawingArea;
  11781. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  11782. me.yCenter = Math.round(((maxTop + maxBottom) / 2) + me.top);
  11783. },
  11784. getIndexAngle: function(index) {
  11785. var angleMultiplier = (Math.PI * 2) / getValueCount(this);
  11786. var startAngle = this.chart.options && this.chart.options.startAngle ?
  11787. this.chart.options.startAngle :
  11788. 0;
  11789. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  11790. // Start from the top instead of right, so remove a quarter of the circle
  11791. return index * angleMultiplier + startAngleRadians;
  11792. },
  11793. getDistanceFromCenterForValue: function(value) {
  11794. var me = this;
  11795. if (value === null) {
  11796. return 0; // null always in center
  11797. }
  11798. // Take into account half font size + the yPadding of the top value
  11799. var scalingFactor = me.drawingArea / (me.max - me.min);
  11800. if (me.options.ticks.reverse) {
  11801. return (me.max - value) * scalingFactor;
  11802. }
  11803. return (value - me.min) * scalingFactor;
  11804. },
  11805. getPointPosition: function(index, distanceFromCenter) {
  11806. var me = this;
  11807. var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
  11808. return {
  11809. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  11810. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  11811. };
  11812. },
  11813. getPointPositionForValue: function(index, value) {
  11814. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  11815. },
  11816. getBasePosition: function() {
  11817. var me = this;
  11818. var min = me.min;
  11819. var max = me.max;
  11820. return me.getPointPositionForValue(0,
  11821. me.beginAtZero ? 0 :
  11822. min < 0 && max < 0 ? max :
  11823. min > 0 && max > 0 ? min :
  11824. 0);
  11825. },
  11826. draw: function() {
  11827. var me = this;
  11828. var opts = me.options;
  11829. var gridLineOpts = opts.gridLines;
  11830. var tickOpts = opts.ticks;
  11831. var valueOrDefault = helpers.valueOrDefault;
  11832. if (opts.display) {
  11833. var ctx = me.ctx;
  11834. var startAngle = this.getIndexAngle(0);
  11835. // Tick Font
  11836. var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11837. var tickFontStyle = valueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  11838. var tickFontFamily = valueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  11839. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  11840. helpers.each(me.ticks, function(label, index) {
  11841. // Don't draw a centre value (if it is minimum)
  11842. if (index > 0 || tickOpts.reverse) {
  11843. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  11844. // Draw circular lines around the scale
  11845. if (gridLineOpts.display && index !== 0) {
  11846. drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
  11847. }
  11848. if (tickOpts.display) {
  11849. var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  11850. ctx.font = tickLabelFont;
  11851. ctx.save();
  11852. ctx.translate(me.xCenter, me.yCenter);
  11853. ctx.rotate(startAngle);
  11854. if (tickOpts.showLabelBackdrop) {
  11855. var labelWidth = ctx.measureText(label).width;
  11856. ctx.fillStyle = tickOpts.backdropColor;
  11857. ctx.fillRect(
  11858. -labelWidth / 2 - tickOpts.backdropPaddingX,
  11859. -yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
  11860. labelWidth + tickOpts.backdropPaddingX * 2,
  11861. tickFontSize + tickOpts.backdropPaddingY * 2
  11862. );
  11863. }
  11864. ctx.textAlign = 'center';
  11865. ctx.textBaseline = 'middle';
  11866. ctx.fillStyle = tickFontColor;
  11867. ctx.fillText(label, 0, -yCenterOffset);
  11868. ctx.restore();
  11869. }
  11870. }
  11871. });
  11872. if (opts.angleLines.display || opts.pointLabels.display) {
  11873. drawPointLabels(me);
  11874. }
  11875. }
  11876. }
  11877. });
  11878. scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  11879. };
  11880. },{"26":26,"34":34,"35":35,"46":46}],59:[function(require,module,exports){
  11881. /* global window: false */
  11882. 'use strict';
  11883. var moment = require(1);
  11884. moment = typeof moment === 'function' ? moment : window.moment;
  11885. var defaults = require(26);
  11886. var helpers = require(46);
  11887. var Scale = require(33);
  11888. var scaleService = require(34);
  11889. // Integer constants are from the ES6 spec.
  11890. var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
  11891. var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  11892. var INTERVALS = {
  11893. millisecond: {
  11894. common: true,
  11895. size: 1,
  11896. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  11897. },
  11898. second: {
  11899. common: true,
  11900. size: 1000,
  11901. steps: [1, 2, 5, 10, 15, 30]
  11902. },
  11903. minute: {
  11904. common: true,
  11905. size: 60000,
  11906. steps: [1, 2, 5, 10, 15, 30]
  11907. },
  11908. hour: {
  11909. common: true,
  11910. size: 3600000,
  11911. steps: [1, 2, 3, 6, 12]
  11912. },
  11913. day: {
  11914. common: true,
  11915. size: 86400000,
  11916. steps: [1, 2, 5]
  11917. },
  11918. week: {
  11919. common: false,
  11920. size: 604800000,
  11921. steps: [1, 2, 3, 4]
  11922. },
  11923. month: {
  11924. common: true,
  11925. size: 2.628e9,
  11926. steps: [1, 2, 3]
  11927. },
  11928. quarter: {
  11929. common: false,
  11930. size: 7.884e9,
  11931. steps: [1, 2, 3, 4]
  11932. },
  11933. year: {
  11934. common: true,
  11935. size: 3.154e10
  11936. }
  11937. };
  11938. var UNITS = Object.keys(INTERVALS);
  11939. function sorter(a, b) {
  11940. return a - b;
  11941. }
  11942. function arrayUnique(items) {
  11943. var hash = {};
  11944. var out = [];
  11945. var i, ilen, item;
  11946. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11947. item = items[i];
  11948. if (!hash[item]) {
  11949. hash[item] = true;
  11950. out.push(item);
  11951. }
  11952. }
  11953. return out;
  11954. }
  11955. /**
  11956. * Returns an array of {time, pos} objects used to interpolate a specific `time` or position
  11957. * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
  11958. * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other
  11959. * extremity (left + width or top + height). Note that it would be more optimized to directly
  11960. * store pre-computed pixels, but the scale dimensions are not guaranteed at the time we need
  11961. * to create the lookup table. The table ALWAYS contains at least two items: min and max.
  11962. *
  11963. * @param {Number[]} timestamps - timestamps sorted from lowest to highest.
  11964. * @param {String} distribution - If 'linear', timestamps will be spread linearly along the min
  11965. * and max range, so basically, the table will contains only two items: {min, 0} and {max, 1}.
  11966. * If 'series', timestamps will be positioned at the same distance from each other. In this
  11967. * case, only timestamps that break the time linearity are registered, meaning that in the
  11968. * best case, all timestamps are linear, the table contains only min and max.
  11969. */
  11970. function buildLookupTable(timestamps, min, max, distribution) {
  11971. if (distribution === 'linear' || !timestamps.length) {
  11972. return [
  11973. {time: min, pos: 0},
  11974. {time: max, pos: 1}
  11975. ];
  11976. }
  11977. var table = [];
  11978. var items = [min];
  11979. var i, ilen, prev, curr, next;
  11980. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  11981. curr = timestamps[i];
  11982. if (curr > min && curr < max) {
  11983. items.push(curr);
  11984. }
  11985. }
  11986. items.push(max);
  11987. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11988. next = items[i + 1];
  11989. prev = items[i - 1];
  11990. curr = items[i];
  11991. // only add points that breaks the scale linearity
  11992. if (prev === undefined || next === undefined || Math.round((next + prev) / 2) !== curr) {
  11993. table.push({time: curr, pos: i / (ilen - 1)});
  11994. }
  11995. }
  11996. return table;
  11997. }
  11998. // @see adapted from http://www.anujgakhar.com/2014/03/01/binary-search-in-javascript/
  11999. function lookup(table, key, value) {
  12000. var lo = 0;
  12001. var hi = table.length - 1;
  12002. var mid, i0, i1;
  12003. while (lo >= 0 && lo <= hi) {
  12004. mid = (lo + hi) >> 1;
  12005. i0 = table[mid - 1] || null;
  12006. i1 = table[mid];
  12007. if (!i0) {
  12008. // given value is outside table (before first item)
  12009. return {lo: null, hi: i1};
  12010. } else if (i1[key] < value) {
  12011. lo = mid + 1;
  12012. } else if (i0[key] > value) {
  12013. hi = mid - 1;
  12014. } else {
  12015. return {lo: i0, hi: i1};
  12016. }
  12017. }
  12018. // given value is outside table (after last item)
  12019. return {lo: i1, hi: null};
  12020. }
  12021. /**
  12022. * Linearly interpolates the given source `value` using the table items `skey` values and
  12023. * returns the associated `tkey` value. For example, interpolate(table, 'time', 42, 'pos')
  12024. * returns the position for a timestamp equal to 42. If value is out of bounds, values at
  12025. * index [0, 1] or [n - 1, n] are used for the interpolation.
  12026. */
  12027. function interpolate(table, skey, sval, tkey) {
  12028. var range = lookup(table, skey, sval);
  12029. // Note: the lookup table ALWAYS contains at least 2 items (min and max)
  12030. var prev = !range.lo ? table[0] : !range.hi ? table[table.length - 2] : range.lo;
  12031. var next = !range.lo ? table[1] : !range.hi ? table[table.length - 1] : range.hi;
  12032. var span = next[skey] - prev[skey];
  12033. var ratio = span ? (sval - prev[skey]) / span : 0;
  12034. var offset = (next[tkey] - prev[tkey]) * ratio;
  12035. return prev[tkey] + offset;
  12036. }
  12037. /**
  12038. * Convert the given value to a moment object using the given time options.
  12039. * @see http://momentjs.com/docs/#/parsing/
  12040. */
  12041. function momentify(value, options) {
  12042. var parser = options.parser;
  12043. var format = options.parser || options.format;
  12044. if (typeof parser === 'function') {
  12045. return parser(value);
  12046. }
  12047. if (typeof value === 'string' && typeof format === 'string') {
  12048. return moment(value, format);
  12049. }
  12050. if (!(value instanceof moment)) {
  12051. value = moment(value);
  12052. }
  12053. if (value.isValid()) {
  12054. return value;
  12055. }
  12056. // Labels are in an incompatible moment format and no `parser` has been provided.
  12057. // The user might still use the deprecated `format` option to convert his inputs.
  12058. if (typeof format === 'function') {
  12059. return format(value);
  12060. }
  12061. return value;
  12062. }
  12063. function parse(input, scale) {
  12064. if (helpers.isNullOrUndef(input)) {
  12065. return null;
  12066. }
  12067. var options = scale.options.time;
  12068. var value = momentify(scale.getRightValue(input), options);
  12069. if (!value.isValid()) {
  12070. return null;
  12071. }
  12072. if (options.round) {
  12073. value.startOf(options.round);
  12074. }
  12075. return value.valueOf();
  12076. }
  12077. /**
  12078. * Returns the number of unit to skip to be able to display up to `capacity` number of ticks
  12079. * in `unit` for the given `min` / `max` range and respecting the interval steps constraints.
  12080. */
  12081. function determineStepSize(min, max, unit, capacity) {
  12082. var range = max - min;
  12083. var interval = INTERVALS[unit];
  12084. var milliseconds = interval.size;
  12085. var steps = interval.steps;
  12086. var i, ilen, factor;
  12087. if (!steps) {
  12088. return Math.ceil(range / (capacity * milliseconds));
  12089. }
  12090. for (i = 0, ilen = steps.length; i < ilen; ++i) {
  12091. factor = steps[i];
  12092. if (Math.ceil(range / (milliseconds * factor)) <= capacity) {
  12093. break;
  12094. }
  12095. }
  12096. return factor;
  12097. }
  12098. /**
  12099. * Figures out what unit results in an appropriate number of auto-generated ticks
  12100. */
  12101. function determineUnitForAutoTicks(minUnit, min, max, capacity) {
  12102. var ilen = UNITS.length;
  12103. var i, interval, factor;
  12104. for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
  12105. interval = INTERVALS[UNITS[i]];
  12106. factor = interval.steps ? interval.steps[interval.steps.length - 1] : MAX_INTEGER;
  12107. if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
  12108. return UNITS[i];
  12109. }
  12110. }
  12111. return UNITS[ilen - 1];
  12112. }
  12113. /**
  12114. * Figures out what unit to format a set of ticks with
  12115. */
  12116. function determineUnitForFormatting(ticks, minUnit, min, max) {
  12117. var duration = moment.duration(moment(max).diff(moment(min)));
  12118. var ilen = UNITS.length;
  12119. var i, unit;
  12120. for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
  12121. unit = UNITS[i];
  12122. if (INTERVALS[unit].common && duration.as(unit) >= ticks.length) {
  12123. return unit;
  12124. }
  12125. }
  12126. return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
  12127. }
  12128. function determineMajorUnit(unit) {
  12129. for (var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i) {
  12130. if (INTERVALS[UNITS[i]].common) {
  12131. return UNITS[i];
  12132. }
  12133. }
  12134. }
  12135. /**
  12136. * Generates a maximum of `capacity` timestamps between min and max, rounded to the
  12137. * `minor` unit, aligned on the `major` unit and using the given scale time `options`.
  12138. * Important: this method can return ticks outside the min and max range, it's the
  12139. * responsibility of the calling code to clamp values if needed.
  12140. */
  12141. function generate(min, max, capacity, options) {
  12142. var timeOpts = options.time;
  12143. var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, capacity);
  12144. var major = determineMajorUnit(minor);
  12145. var stepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
  12146. var weekday = minor === 'week' ? timeOpts.isoWeekday : false;
  12147. var majorTicksEnabled = options.ticks.major.enabled;
  12148. var interval = INTERVALS[minor];
  12149. var first = moment(min);
  12150. var last = moment(max);
  12151. var ticks = [];
  12152. var time;
  12153. if (!stepSize) {
  12154. stepSize = determineStepSize(min, max, minor, capacity);
  12155. }
  12156. // For 'week' unit, handle the first day of week option
  12157. if (weekday) {
  12158. first = first.isoWeekday(weekday);
  12159. last = last.isoWeekday(weekday);
  12160. }
  12161. // Align first/last ticks on unit
  12162. first = first.startOf(weekday ? 'day' : minor);
  12163. last = last.startOf(weekday ? 'day' : minor);
  12164. // Make sure that the last tick include max
  12165. if (last < max) {
  12166. last.add(1, minor);
  12167. }
  12168. time = moment(first);
  12169. if (majorTicksEnabled && major && !weekday && !timeOpts.round) {
  12170. // Align the first tick on the previous `minor` unit aligned on the `major` unit:
  12171. // we first aligned time on the previous `major` unit then add the number of full
  12172. // stepSize there is between first and the previous major time.
  12173. time.startOf(major);
  12174. time.add(~~((first - time) / (interval.size * stepSize)) * stepSize, minor);
  12175. }
  12176. for (; time < last; time.add(stepSize, minor)) {
  12177. ticks.push(+time);
  12178. }
  12179. ticks.push(+time);
  12180. return ticks;
  12181. }
  12182. /**
  12183. * Returns the right and left offsets from edges in the form of {left, right}.
  12184. * Offsets are added when the `offset` option is true.
  12185. */
  12186. function computeOffsets(table, ticks, min, max, options) {
  12187. var left = 0;
  12188. var right = 0;
  12189. var upper, lower;
  12190. if (options.offset && ticks.length) {
  12191. if (!options.time.min) {
  12192. upper = ticks.length > 1 ? ticks[1] : max;
  12193. lower = ticks[0];
  12194. left = (
  12195. interpolate(table, 'time', upper, 'pos') -
  12196. interpolate(table, 'time', lower, 'pos')
  12197. ) / 2;
  12198. }
  12199. if (!options.time.max) {
  12200. upper = ticks[ticks.length - 1];
  12201. lower = ticks.length > 1 ? ticks[ticks.length - 2] : min;
  12202. right = (
  12203. interpolate(table, 'time', upper, 'pos') -
  12204. interpolate(table, 'time', lower, 'pos')
  12205. ) / 2;
  12206. }
  12207. }
  12208. return {left: left, right: right};
  12209. }
  12210. function ticksFromTimestamps(values, majorUnit) {
  12211. var ticks = [];
  12212. var i, ilen, value, major;
  12213. for (i = 0, ilen = values.length; i < ilen; ++i) {
  12214. value = values[i];
  12215. major = majorUnit ? value === +moment(value).startOf(majorUnit) : false;
  12216. ticks.push({
  12217. value: value,
  12218. major: major
  12219. });
  12220. }
  12221. return ticks;
  12222. }
  12223. function determineLabelFormat(data, timeOpts) {
  12224. var i, momentDate, hasTime;
  12225. var ilen = data.length;
  12226. // find the label with the most parts (milliseconds, minutes, etc.)
  12227. // format all labels with the same level of detail as the most specific label
  12228. for (i = 0; i < ilen; i++) {
  12229. momentDate = momentify(data[i], timeOpts);
  12230. if (momentDate.millisecond() !== 0) {
  12231. return 'MMM D, YYYY h:mm:ss.SSS a';
  12232. }
  12233. if (momentDate.second() !== 0 || momentDate.minute() !== 0 || momentDate.hour() !== 0) {
  12234. hasTime = true;
  12235. }
  12236. }
  12237. if (hasTime) {
  12238. return 'MMM D, YYYY h:mm:ss a';
  12239. }
  12240. return 'MMM D, YYYY';
  12241. }
  12242. module.exports = function() {
  12243. var defaultConfig = {
  12244. position: 'bottom',
  12245. /**
  12246. * Data distribution along the scale:
  12247. * - 'linear': data are spread according to their time (distances can vary),
  12248. * - 'series': data are spread at the same distance from each other.
  12249. * @see https://github.com/chartjs/Chart.js/pull/4507
  12250. * @since 2.7.0
  12251. */
  12252. distribution: 'linear',
  12253. /**
  12254. * Scale boundary strategy (bypassed by min/max time options)
  12255. * - `data`: make sure data are fully visible, ticks outside are removed
  12256. * - `ticks`: make sure ticks are fully visible, data outside are truncated
  12257. * @see https://github.com/chartjs/Chart.js/pull/4556
  12258. * @since 2.7.0
  12259. */
  12260. bounds: 'data',
  12261. time: {
  12262. 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
  12263. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  12264. unit: false, // false == automatic or override with week, month, year, etc.
  12265. round: false, // none, or override with week, month, year, etc.
  12266. displayFormat: false, // DEPRECATED
  12267. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  12268. minUnit: 'millisecond',
  12269. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  12270. displayFormats: {
  12271. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  12272. second: 'h:mm:ss a', // 11:20:01 AM
  12273. minute: 'h:mm a', // 11:20 AM
  12274. hour: 'hA', // 5PM
  12275. day: 'MMM D', // Sep 4
  12276. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  12277. month: 'MMM YYYY', // Sept 2015
  12278. quarter: '[Q]Q - YYYY', // Q3
  12279. year: 'YYYY' // 2015
  12280. },
  12281. },
  12282. ticks: {
  12283. autoSkip: false,
  12284. /**
  12285. * Ticks generation input values:
  12286. * - 'auto': generates "optimal" ticks based on scale size and time options.
  12287. * - 'data': generates ticks from data (including labels from data {t|x|y} objects).
  12288. * - 'labels': generates ticks from user given `data.labels` values ONLY.
  12289. * @see https://github.com/chartjs/Chart.js/pull/4507
  12290. * @since 2.7.0
  12291. */
  12292. source: 'auto',
  12293. major: {
  12294. enabled: false
  12295. }
  12296. }
  12297. };
  12298. var TimeScale = Scale.extend({
  12299. initialize: function() {
  12300. if (!moment) {
  12301. 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');
  12302. }
  12303. this.mergeTicksOptions();
  12304. Scale.prototype.initialize.call(this);
  12305. },
  12306. update: function() {
  12307. var me = this;
  12308. var options = me.options;
  12309. // DEPRECATIONS: output a message only one time per update
  12310. if (options.time && options.time.format) {
  12311. console.warn('options.time.format is deprecated and replaced by options.time.parser.');
  12312. }
  12313. return Scale.prototype.update.apply(me, arguments);
  12314. },
  12315. /**
  12316. * Allows data to be referenced via 't' attribute
  12317. */
  12318. getRightValue: function(rawValue) {
  12319. if (rawValue && rawValue.t !== undefined) {
  12320. rawValue = rawValue.t;
  12321. }
  12322. return Scale.prototype.getRightValue.call(this, rawValue);
  12323. },
  12324. determineDataLimits: function() {
  12325. var me = this;
  12326. var chart = me.chart;
  12327. var timeOpts = me.options.time;
  12328. var unit = timeOpts.unit || 'day';
  12329. var min = MAX_INTEGER;
  12330. var max = MIN_INTEGER;
  12331. var timestamps = [];
  12332. var datasets = [];
  12333. var labels = [];
  12334. var i, j, ilen, jlen, data, timestamp;
  12335. // Convert labels to timestamps
  12336. for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) {
  12337. labels.push(parse(chart.data.labels[i], me));
  12338. }
  12339. // Convert data to timestamps
  12340. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  12341. if (chart.isDatasetVisible(i)) {
  12342. data = chart.data.datasets[i].data;
  12343. // Let's consider that all data have the same format.
  12344. if (helpers.isObject(data[0])) {
  12345. datasets[i] = [];
  12346. for (j = 0, jlen = data.length; j < jlen; ++j) {
  12347. timestamp = parse(data[j], me);
  12348. timestamps.push(timestamp);
  12349. datasets[i][j] = timestamp;
  12350. }
  12351. } else {
  12352. timestamps.push.apply(timestamps, labels);
  12353. datasets[i] = labels.slice(0);
  12354. }
  12355. } else {
  12356. datasets[i] = [];
  12357. }
  12358. }
  12359. if (labels.length) {
  12360. // Sort labels **after** data have been converted
  12361. labels = arrayUnique(labels).sort(sorter);
  12362. min = Math.min(min, labels[0]);
  12363. max = Math.max(max, labels[labels.length - 1]);
  12364. }
  12365. if (timestamps.length) {
  12366. timestamps = arrayUnique(timestamps).sort(sorter);
  12367. min = Math.min(min, timestamps[0]);
  12368. max = Math.max(max, timestamps[timestamps.length - 1]);
  12369. }
  12370. min = parse(timeOpts.min, me) || min;
  12371. max = parse(timeOpts.max, me) || max;
  12372. // In case there is no valid min/max, set limits based on unit time option
  12373. min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
  12374. max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;
  12375. // Make sure that max is strictly higher than min (required by the lookup table)
  12376. me.min = Math.min(min, max);
  12377. me.max = Math.max(min + 1, max);
  12378. // PRIVATE
  12379. me._horizontal = me.isHorizontal();
  12380. me._table = [];
  12381. me._timestamps = {
  12382. data: timestamps,
  12383. datasets: datasets,
  12384. labels: labels
  12385. };
  12386. },
  12387. buildTicks: function() {
  12388. var me = this;
  12389. var min = me.min;
  12390. var max = me.max;
  12391. var options = me.options;
  12392. var timeOpts = options.time;
  12393. var timestamps = [];
  12394. var ticks = [];
  12395. var i, ilen, timestamp;
  12396. switch (options.ticks.source) {
  12397. case 'data':
  12398. timestamps = me._timestamps.data;
  12399. break;
  12400. case 'labels':
  12401. timestamps = me._timestamps.labels;
  12402. break;
  12403. case 'auto':
  12404. default:
  12405. timestamps = generate(min, max, me.getLabelCapacity(min), options);
  12406. }
  12407. if (options.bounds === 'ticks' && timestamps.length) {
  12408. min = timestamps[0];
  12409. max = timestamps[timestamps.length - 1];
  12410. }
  12411. // Enforce limits with user min/max options
  12412. min = parse(timeOpts.min, me) || min;
  12413. max = parse(timeOpts.max, me) || max;
  12414. // Remove ticks outside the min/max range
  12415. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  12416. timestamp = timestamps[i];
  12417. if (timestamp >= min && timestamp <= max) {
  12418. ticks.push(timestamp);
  12419. }
  12420. }
  12421. me.min = min;
  12422. me.max = max;
  12423. // PRIVATE
  12424. me._unit = timeOpts.unit || determineUnitForFormatting(ticks, timeOpts.minUnit, me.min, me.max);
  12425. me._majorUnit = determineMajorUnit(me._unit);
  12426. me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
  12427. me._offsets = computeOffsets(me._table, ticks, min, max, options);
  12428. me._labelFormat = determineLabelFormat(me._timestamps.data, timeOpts);
  12429. return ticksFromTimestamps(ticks, me._majorUnit);
  12430. },
  12431. getLabelForIndex: function(index, datasetIndex) {
  12432. var me = this;
  12433. var data = me.chart.data;
  12434. var timeOpts = me.options.time;
  12435. var label = data.labels && index < data.labels.length ? data.labels[index] : '';
  12436. var value = data.datasets[datasetIndex].data[index];
  12437. if (helpers.isObject(value)) {
  12438. label = me.getRightValue(value);
  12439. }
  12440. if (timeOpts.tooltipFormat) {
  12441. return momentify(label, timeOpts).format(timeOpts.tooltipFormat);
  12442. }
  12443. if (typeof label === 'string') {
  12444. return label;
  12445. }
  12446. return momentify(label, timeOpts).format(me._labelFormat);
  12447. },
  12448. /**
  12449. * Function to format an individual tick mark
  12450. * @private
  12451. */
  12452. tickFormatFunction: function(tick, index, ticks, formatOverride) {
  12453. var me = this;
  12454. var options = me.options;
  12455. var time = tick.valueOf();
  12456. var formats = options.time.displayFormats;
  12457. var minorFormat = formats[me._unit];
  12458. var majorUnit = me._majorUnit;
  12459. var majorFormat = formats[majorUnit];
  12460. var majorTime = tick.clone().startOf(majorUnit).valueOf();
  12461. var majorTickOpts = options.ticks.major;
  12462. var major = majorTickOpts.enabled && majorUnit && majorFormat && time === majorTime;
  12463. var label = tick.format(formatOverride ? formatOverride : major ? majorFormat : minorFormat);
  12464. var tickOpts = major ? majorTickOpts : options.ticks.minor;
  12465. var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
  12466. return formatter ? formatter(label, index, ticks) : label;
  12467. },
  12468. convertTicksToLabels: function(ticks) {
  12469. var labels = [];
  12470. var i, ilen;
  12471. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  12472. labels.push(this.tickFormatFunction(moment(ticks[i].value), i, ticks));
  12473. }
  12474. return labels;
  12475. },
  12476. /**
  12477. * @private
  12478. */
  12479. getPixelForOffset: function(time) {
  12480. var me = this;
  12481. var size = me._horizontal ? me.width : me.height;
  12482. var start = me._horizontal ? me.left : me.top;
  12483. var pos = interpolate(me._table, 'time', time, 'pos');
  12484. return start + size * (me._offsets.left + pos) / (me._offsets.left + 1 + me._offsets.right);
  12485. },
  12486. getPixelForValue: function(value, index, datasetIndex) {
  12487. var me = this;
  12488. var time = null;
  12489. if (index !== undefined && datasetIndex !== undefined) {
  12490. time = me._timestamps.datasets[datasetIndex][index];
  12491. }
  12492. if (time === null) {
  12493. time = parse(value, me);
  12494. }
  12495. if (time !== null) {
  12496. return me.getPixelForOffset(time);
  12497. }
  12498. },
  12499. getPixelForTick: function(index) {
  12500. var ticks = this.getTicks();
  12501. return index >= 0 && index < ticks.length ?
  12502. this.getPixelForOffset(ticks[index].value) :
  12503. null;
  12504. },
  12505. getValueForPixel: function(pixel) {
  12506. var me = this;
  12507. var size = me._horizontal ? me.width : me.height;
  12508. var start = me._horizontal ? me.left : me.top;
  12509. var pos = (size ? (pixel - start) / size : 0) * (me._offsets.left + 1 + me._offsets.left) - me._offsets.right;
  12510. var time = interpolate(me._table, 'pos', pos, 'time');
  12511. return moment(time);
  12512. },
  12513. /**
  12514. * Crude approximation of what the label width might be
  12515. * @private
  12516. */
  12517. getLabelWidth: function(label) {
  12518. var me = this;
  12519. var ticksOpts = me.options.ticks;
  12520. var tickLabelWidth = me.ctx.measureText(label).width;
  12521. var angle = helpers.toRadians(ticksOpts.maxRotation);
  12522. var cosRotation = Math.cos(angle);
  12523. var sinRotation = Math.sin(angle);
  12524. var tickFontSize = helpers.valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize);
  12525. return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  12526. },
  12527. /**
  12528. * @private
  12529. */
  12530. getLabelCapacity: function(exampleTime) {
  12531. var me = this;
  12532. var formatOverride = me.options.time.displayFormats.millisecond; // Pick the longest format for guestimation
  12533. var exampleLabel = me.tickFormatFunction(moment(exampleTime), 0, [], formatOverride);
  12534. var tickLabelWidth = me.getLabelWidth(exampleLabel);
  12535. var innerWidth = me.isHorizontal() ? me.width : me.height;
  12536. var capacity = Math.floor(innerWidth / tickLabelWidth);
  12537. return capacity > 0 ? capacity : 1;
  12538. }
  12539. });
  12540. scaleService.registerScaleType('time', TimeScale, defaultConfig);
  12541. };
  12542. },{"1":1,"26":26,"33":33,"34":34,"46":46}]},{},[7])(7)
  12543. });
  12544. 'use strict';
  12545. var WOW;
  12546. (function ($) {
  12547. WOW = function WOW() {
  12548. return {
  12549. init: function init() {
  12550. var animationName = [];
  12551. var once = 1;
  12552. function mdbWow() {
  12553. var windowHeight = window.innerHeight;
  12554. var scroll = window.scrollY;
  12555. $('.wow').each(function () {
  12556. if ($(this).css('visibility') == 'visible') {
  12557. return;
  12558. }
  12559. if (windowHeight + scroll - 100 > getOffset(this) && scroll < getOffset(this) || windowHeight + scroll - 100 > getOffset(this) + $(this).height() && scroll < getOffset(this) + $(this).height() || windowHeight + scroll == $(document).height() && getOffset(this) + 100 > $(document).height()) {
  12560. var index = $(this).index('.wow');
  12561. var delay = $(this).attr('data-wow-delay');
  12562. if (delay) {
  12563. delay = $(this).attr('data-wow-delay').slice(0, -1
  12564. );
  12565. var self = this;
  12566. var timeout = parseFloat(delay) * 1000;
  12567. $(self).addClass('animated');
  12568. $(self).css({
  12569. 'visibility': 'visible'
  12570. });
  12571. $(self).css({
  12572. 'animation-delay': delay
  12573. });
  12574. $(self).css({
  12575. 'animation-name': animationName[index]
  12576. });
  12577. var removeTime = $(this).css('animation-duration').slice(0, -1) * 1000;
  12578. if ($(this).attr('data-wow-delay')) {
  12579. removeTime += $(this).attr('data-wow-delay').slice(0, -1) * 1000;
  12580. }
  12581. var self = this;
  12582. setTimeout(function () {
  12583. $(self).removeClass('animated');
  12584. }, removeTime);
  12585. } else {
  12586. $(this).addClass('animated');
  12587. $(this).css({
  12588. 'visibility': 'visible'
  12589. });
  12590. $(this).css({
  12591. 'animation-name': animationName[index]
  12592. });
  12593. var removeTime = $(this).css('animation-duration').slice(0, -1) * 1000;
  12594. var self = this;
  12595. setTimeout(function () {
  12596. $(self).removeClass('animated');
  12597. }, removeTime);
  12598. }
  12599. }
  12600. });
  12601. }
  12602. function appear() {
  12603. $('.wow').each(function () {
  12604. var index = $(this).index('.wow');
  12605. var delay = $(this).attr('data-wow-delay');
  12606. if (delay) {
  12607. delay = $(this).attr('data-wow-delay').slice(0, -1);
  12608. var timeout = parseFloat(delay) * 1000;
  12609. $(this).addClass('animated');
  12610. $(this).css({
  12611. 'visibility': 'visible'
  12612. });
  12613. $(this).css({
  12614. 'animation-delay': delay + 's'
  12615. });
  12616. $(this).css({
  12617. 'animation-name': animationName[index]
  12618. });
  12619. } else {
  12620. $(this).addClass('animated');
  12621. $(this).css({
  12622. 'visibility': 'visible'
  12623. });
  12624. $(this).css({
  12625. 'animation-name': animationName[index]
  12626. });
  12627. }
  12628. });
  12629. }
  12630. function hide() {
  12631. var windowHeight = window.innerHeight;
  12632. var scroll = window.scrollY;
  12633. $('.wow.animated').each(function () {
  12634. if (windowHeight + scroll - 100 > getOffset(this) && scroll > getOffset(this) + 100 || windowHeight + scroll - 100 < getOffset(this) && scroll < getOffset(this) + 100 || getOffset(this) + $(this).height > $(document).height() - 100) {
  12635. $(this).removeClass('animated');
  12636. $(this).css({
  12637. 'animation-name': 'none'
  12638. });
  12639. $(this).css({
  12640. 'visibility': 'hidden'
  12641. });
  12642. } else {
  12643. var removeTime = $(this).css('animation-duration').slice(0, -1) * 1000;
  12644. if ($(this).attr('data-wow-delay')) {
  12645. removeTime += $(this).attr('data-wow-delay').slice(0, -1) * 1000;
  12646. }
  12647. var self = this;
  12648. setTimeout(function () {
  12649. $(self).removeClass('animated');
  12650. }, removeTime);
  12651. }
  12652. });
  12653. mdbWow();
  12654. once--;
  12655. }
  12656. function getOffset(elem) {
  12657. var box = elem.getBoundingClientRect();
  12658. var body = document.body;
  12659. var docEl = document.documentElement;
  12660. var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
  12661. var clientTop = docEl.clientTop || body.clientTop || 0;
  12662. var top = box.top + scrollTop - clientTop;
  12663. return Math.round(top);
  12664. }
  12665. $('.wow').each(function () {
  12666. $(this).css({
  12667. 'visibility': 'hidden'
  12668. });
  12669. animationName[$(this).index('.wow')] = $(this).css('animation-name');
  12670. $(this).css({
  12671. 'animation-name': 'none'
  12672. });
  12673. });
  12674. $(window).scroll(function () {
  12675. if (once) {
  12676. hide();
  12677. } else {
  12678. mdbWow();
  12679. }
  12680. });
  12681. appear();
  12682. }
  12683. };
  12684. };
  12685. })(jQuery);
  12686. "use strict";
  12687. (function ($) {
  12688. var SCROLLING_NAVBAR_OFFSET_TOP = 50;
  12689. $(window).on('scroll', function () {
  12690. var $navbar = $('.navbar');
  12691. if ($navbar.length) {
  12692. if ($navbar.offset().top > SCROLLING_NAVBAR_OFFSET_TOP) {
  12693. $('.scrolling-navbar').addClass('top-nav-collapse');
  12694. } else {
  12695. $('.scrolling-navbar').removeClass('top-nav-collapse');
  12696. }
  12697. }
  12698. });
  12699. })(jQuery);
  12700. /*!
  12701. * Waves v0.7.6
  12702. * http://fian.my.id/Waves
  12703. *
  12704. * Copyright 2014-2018 Alfiana E. Sibuea and other contributors
  12705. * Released under the MIT license
  12706. * https://github.com/fians/Waves/blob/master/LICENSE
  12707. */
  12708. ;(function(window, factory) {
  12709. 'use strict';
  12710. // AMD. Register as an anonymous module. Wrap in function so we have access
  12711. // to root via `this`.
  12712. if (typeof define === 'function' && define.amd) {
  12713. define([], function() {
  12714. window.Waves = factory.call(window);
  12715. return window.Waves;
  12716. });
  12717. }
  12718. // Node. Does not work with strict CommonJS, but only CommonJS-like
  12719. // environments that support module.exports, like Node.
  12720. else if (typeof exports === 'object') {
  12721. module.exports = factory.call(window);
  12722. }
  12723. // Browser globals.
  12724. else {
  12725. window.Waves = factory.call(window);
  12726. }
  12727. })(typeof global === 'object' ? global : this, function() {
  12728. 'use strict';
  12729. var Waves = Waves || {};
  12730. var $$ = document.querySelectorAll.bind(document);
  12731. var toString = Object.prototype.toString;
  12732. var isTouchAvailable = 'ontouchstart' in window;
  12733. // Find exact position of element
  12734. function isWindow(obj) {
  12735. return obj !== null && obj === obj.window;
  12736. }
  12737. function getWindow(elem) {
  12738. return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView;
  12739. }
  12740. function isObject(value) {
  12741. var type = typeof value;
  12742. return type === 'function' || type === 'object' && !!value;
  12743. }
  12744. function isDOMNode(obj) {
  12745. return isObject(obj) && obj.nodeType > 0;
  12746. }
  12747. function getWavesElements(nodes) {
  12748. var stringRepr = toString.call(nodes);
  12749. if (stringRepr === '[object String]') {
  12750. return $$(nodes);
  12751. } else if (isObject(nodes) && /^\[object (Array|HTMLCollection|NodeList|Object)\]$/.test(stringRepr) && nodes.hasOwnProperty('length')) {
  12752. return nodes;
  12753. } else if (isDOMNode(nodes)) {
  12754. return [nodes];
  12755. }
  12756. return [];
  12757. }
  12758. function offset(elem) {
  12759. var docElem, win,
  12760. box = { top: 0, left: 0 },
  12761. doc = elem && elem.ownerDocument;
  12762. docElem = doc.documentElement;
  12763. if (typeof elem.getBoundingClientRect !== typeof undefined) {
  12764. box = elem.getBoundingClientRect();
  12765. }
  12766. win = getWindow(doc);
  12767. return {
  12768. top: box.top + win.pageYOffset - docElem.clientTop,
  12769. left: box.left + win.pageXOffset - docElem.clientLeft
  12770. };
  12771. }
  12772. function convertStyle(styleObj) {
  12773. var style = '';
  12774. for (var prop in styleObj) {
  12775. if (styleObj.hasOwnProperty(prop)) {
  12776. style += (prop + ':' + styleObj[prop] + ';');
  12777. }
  12778. }
  12779. return style;
  12780. }
  12781. var Effect = {
  12782. // Effect duration
  12783. duration: 750,
  12784. // Effect delay (check for scroll before showing effect)
  12785. delay: 200,
  12786. show: function(e, element, velocity) {
  12787. // Disable right click
  12788. if (e.button === 2) {
  12789. return false;
  12790. }
  12791. element = element || this;
  12792. // Create ripple
  12793. var ripple = document.createElement('div');
  12794. ripple.className = 'waves-ripple waves-rippling';
  12795. element.appendChild(ripple);
  12796. // Get click coordinate and element width
  12797. var pos = offset(element);
  12798. var relativeY = 0;
  12799. var relativeX = 0;
  12800. // Support for touch devices
  12801. if('touches' in e && e.touches.length) {
  12802. relativeY = (e.touches[0].pageY - pos.top);
  12803. relativeX = (e.touches[0].pageX - pos.left);
  12804. }
  12805. //Normal case
  12806. else {
  12807. relativeY = (e.pageY - pos.top);
  12808. relativeX = (e.pageX - pos.left);
  12809. }
  12810. // Support for synthetic events
  12811. relativeX = relativeX >= 0 ? relativeX : 0;
  12812. relativeY = relativeY >= 0 ? relativeY : 0;
  12813. var scale = 'scale(' + ((element.clientWidth / 100) * 3) + ')';
  12814. var translate = 'translate(0,0)';
  12815. if (velocity) {
  12816. translate = 'translate(' + (velocity.x) + 'px, ' + (velocity.y) + 'px)';
  12817. }
  12818. // Attach data to element
  12819. ripple.setAttribute('data-hold', Date.now());
  12820. ripple.setAttribute('data-x', relativeX);
  12821. ripple.setAttribute('data-y', relativeY);
  12822. ripple.setAttribute('data-scale', scale);
  12823. ripple.setAttribute('data-translate', translate);
  12824. // Set ripple position
  12825. var rippleStyle = {
  12826. top: relativeY + 'px',
  12827. left: relativeX + 'px'
  12828. };
  12829. ripple.classList.add('waves-notransition');
  12830. ripple.setAttribute('style', convertStyle(rippleStyle));
  12831. ripple.classList.remove('waves-notransition');
  12832. // Scale the ripple
  12833. rippleStyle['-webkit-transform'] = scale + ' ' + translate;
  12834. rippleStyle['-moz-transform'] = scale + ' ' + translate;
  12835. rippleStyle['-ms-transform'] = scale + ' ' + translate;
  12836. rippleStyle['-o-transform'] = scale + ' ' + translate;
  12837. rippleStyle.transform = scale + ' ' + translate;
  12838. rippleStyle.opacity = '1';
  12839. var duration = e.type === 'mousemove' ? 2500 : Effect.duration;
  12840. rippleStyle['-webkit-transition-duration'] = duration + 'ms';
  12841. rippleStyle['-moz-transition-duration'] = duration + 'ms';
  12842. rippleStyle['-o-transition-duration'] = duration + 'ms';
  12843. rippleStyle['transition-duration'] = duration + 'ms';
  12844. ripple.setAttribute('style', convertStyle(rippleStyle));
  12845. },
  12846. hide: function(e, element) {
  12847. element = element || this;
  12848. var ripples = element.getElementsByClassName('waves-rippling');
  12849. for (var i = 0, len = ripples.length; i < len; i++) {
  12850. removeRipple(e, element, ripples[i]);
  12851. }
  12852. if (isTouchAvailable) {
  12853. element.removeEventListener('touchend', Effect.hide);
  12854. element.removeEventListener('touchcancel', Effect.hide);
  12855. }
  12856. element.removeEventListener('mouseup', Effect.hide);
  12857. element.removeEventListener('mouseleave', Effect.hide);
  12858. }
  12859. };
  12860. /**
  12861. * Collection of wrapper for HTML element that only have single tag
  12862. * like <input> and <img>
  12863. */
  12864. var TagWrapper = {
  12865. // Wrap <input> tag so it can perform the effect
  12866. input: function(element) {
  12867. var parent = element.parentNode;
  12868. // If input already have parent just pass through
  12869. if (parent.tagName.toLowerCase() === 'span' && parent.classList.contains('waves-effect')) {
  12870. return;
  12871. }
  12872. // Put element class and style to the specified parent
  12873. var wrapper = document.createElement('span');
  12874. wrapper.className = 'waves-input-wrapper';
  12875. // element.className = 'waves-button-input';
  12876. // Put element as child
  12877. parent.replaceChild(wrapper, element);
  12878. wrapper.appendChild(element);
  12879. },
  12880. // Wrap <img> tag so it can perform the effect
  12881. img: function(element) {
  12882. var parent = element.parentNode;
  12883. // If input already have parent just pass through
  12884. if (parent.tagName.toLowerCase() === 'i' && parent.classList.contains('waves-effect')) {
  12885. return;
  12886. }
  12887. // Put element as child
  12888. var wrapper = document.createElement('i');
  12889. parent.replaceChild(wrapper, element);
  12890. wrapper.appendChild(element);
  12891. }
  12892. };
  12893. /**
  12894. * Hide the effect and remove the ripple. Must be
  12895. * a separate function to pass the JSLint...
  12896. */
  12897. function removeRipple(e, el, ripple) {
  12898. // Check if the ripple still exist
  12899. if (!ripple) {
  12900. return;
  12901. }
  12902. ripple.classList.remove('waves-rippling');
  12903. var relativeX = ripple.getAttribute('data-x');
  12904. var relativeY = ripple.getAttribute('data-y');
  12905. var scale = ripple.getAttribute('data-scale');
  12906. var translate = ripple.getAttribute('data-translate');
  12907. // Get delay beetween mousedown and mouse leave
  12908. var diff = Date.now() - Number(ripple.getAttribute('data-hold'));
  12909. var delay = 350 - diff;
  12910. if (delay < 0) {
  12911. delay = 0;
  12912. }
  12913. if (e.type === 'mousemove') {
  12914. delay = 150;
  12915. }
  12916. // Fade out ripple after delay
  12917. var duration = e.type === 'mousemove' ? 2500 : Effect.duration;
  12918. setTimeout(function() {
  12919. var style = {
  12920. top: relativeY + 'px',
  12921. left: relativeX + 'px',
  12922. opacity: '0',
  12923. // Duration
  12924. '-webkit-transition-duration': duration + 'ms',
  12925. '-moz-transition-duration': duration + 'ms',
  12926. '-o-transition-duration': duration + 'ms',
  12927. 'transition-duration': duration + 'ms',
  12928. '-webkit-transform': scale + ' ' + translate,
  12929. '-moz-transform': scale + ' ' + translate,
  12930. '-ms-transform': scale + ' ' + translate,
  12931. '-o-transform': scale + ' ' + translate,
  12932. 'transform': scale + ' ' + translate
  12933. };
  12934. ripple.setAttribute('style', convertStyle(style));
  12935. setTimeout(function() {
  12936. try {
  12937. el.removeChild(ripple);
  12938. } catch (e) {
  12939. return false;
  12940. }
  12941. }, duration);
  12942. }, delay);
  12943. }
  12944. /**
  12945. * Disable mousedown event for 500ms during and after touch
  12946. */
  12947. var TouchHandler = {
  12948. /* uses an integer rather than bool so there's no issues with
  12949. * needing to clear timeouts if another touch event occurred
  12950. * within the 500ms. Cannot mouseup between touchstart and
  12951. * touchend, nor in the 500ms after touchend. */
  12952. touches: 0,
  12953. allowEvent: function(e) {
  12954. var allow = true;
  12955. if (/^(mousedown|mousemove)$/.test(e.type) && TouchHandler.touches) {
  12956. allow = false;
  12957. }
  12958. return allow;
  12959. },
  12960. registerEvent: function(e) {
  12961. var eType = e.type;
  12962. if (eType === 'touchstart') {
  12963. TouchHandler.touches += 1; // push
  12964. } else if (/^(touchend|touchcancel)$/.test(eType)) {
  12965. setTimeout(function() {
  12966. if (TouchHandler.touches) {
  12967. TouchHandler.touches -= 1; // pop after 500ms
  12968. }
  12969. }, 500);
  12970. }
  12971. }
  12972. };
  12973. /**
  12974. * Delegated click handler for .waves-effect element.
  12975. * returns null when .waves-effect element not in "click tree"
  12976. */
  12977. function getWavesEffectElement(e) {
  12978. if (TouchHandler.allowEvent(e) === false) {
  12979. return null;
  12980. }
  12981. var element = null;
  12982. var target = e.target || e.srcElement;
  12983. while (target.parentElement) {
  12984. if ( (!(target instanceof SVGElement)) && target.classList.contains('waves-effect')) {
  12985. element = target;
  12986. break;
  12987. }
  12988. target = target.parentElement;
  12989. }
  12990. return element;
  12991. }
  12992. /**
  12993. * Bubble the click and show effect if .waves-effect elem was found
  12994. */
  12995. function showEffect(e) {
  12996. // Disable effect if element has "disabled" property on it
  12997. // In some cases, the event is not triggered by the current element
  12998. // if (e.target.getAttribute('disabled') !== null) {
  12999. // return;
  13000. // }
  13001. var element = getWavesEffectElement(e);
  13002. if (element !== null) {
  13003. // Make it sure the element has either disabled property, disabled attribute or 'disabled' class
  13004. if (element.disabled || element.getAttribute('disabled') || element.classList.contains('disabled')) {
  13005. return;
  13006. }
  13007. TouchHandler.registerEvent(e);
  13008. if (e.type === 'touchstart' && Effect.delay) {
  13009. var hidden = false;
  13010. var timer = setTimeout(function () {
  13011. timer = null;
  13012. Effect.show(e, element);
  13013. }, Effect.delay);
  13014. var hideEffect = function(hideEvent) {
  13015. // if touch hasn't moved, and effect not yet started: start effect now
  13016. if (timer) {
  13017. clearTimeout(timer);
  13018. timer = null;
  13019. Effect.show(e, element);
  13020. }
  13021. if (!hidden) {
  13022. hidden = true;
  13023. Effect.hide(hideEvent, element);
  13024. }
  13025. removeListeners();
  13026. };
  13027. var touchMove = function(moveEvent) {
  13028. if (timer) {
  13029. clearTimeout(timer);
  13030. timer = null;
  13031. }
  13032. hideEffect(moveEvent);
  13033. removeListeners();
  13034. };
  13035. element.addEventListener('touchmove', touchMove, false);
  13036. element.addEventListener('touchend', hideEffect, false);
  13037. element.addEventListener('touchcancel', hideEffect, false);
  13038. var removeListeners = function() {
  13039. element.removeEventListener('touchmove', touchMove);
  13040. element.removeEventListener('touchend', hideEffect);
  13041. element.removeEventListener('touchcancel', hideEffect);
  13042. };
  13043. } else {
  13044. Effect.show(e, element);
  13045. if (isTouchAvailable) {
  13046. element.addEventListener('touchend', Effect.hide, false);
  13047. element.addEventListener('touchcancel', Effect.hide, false);
  13048. }
  13049. element.addEventListener('mouseup', Effect.hide, false);
  13050. element.addEventListener('mouseleave', Effect.hide, false);
  13051. }
  13052. }
  13053. }
  13054. Waves.init = function(options) {
  13055. var body = document.body;
  13056. options = options || {};
  13057. if ('duration' in options) {
  13058. Effect.duration = options.duration;
  13059. }
  13060. if ('delay' in options) {
  13061. Effect.delay = options.delay;
  13062. }
  13063. if (isTouchAvailable) {
  13064. body.addEventListener('touchstart', showEffect, false);
  13065. body.addEventListener('touchcancel', TouchHandler.registerEvent, false);
  13066. body.addEventListener('touchend', TouchHandler.registerEvent, false);
  13067. }
  13068. body.addEventListener('mousedown', showEffect, false);
  13069. };
  13070. /**
  13071. * Attach Waves to dynamically loaded inputs, or add .waves-effect and other
  13072. * waves classes to a set of elements. Set drag to true if the ripple mouseover
  13073. * or skimming effect should be applied to the elements.
  13074. */
  13075. Waves.attach = function(elements, classes) {
  13076. elements = getWavesElements(elements);
  13077. if (toString.call(classes) === '[object Array]') {
  13078. classes = classes.join(' ');
  13079. }
  13080. classes = classes ? ' ' + classes : '';
  13081. var element, tagName;
  13082. for (var i = 0, len = elements.length; i < len; i++) {
  13083. element = elements[i];
  13084. tagName = element.tagName.toLowerCase();
  13085. if (['input', 'img'].indexOf(tagName) !== -1) {
  13086. TagWrapper[tagName](element);
  13087. element = element.parentElement;
  13088. }
  13089. if (element.className.indexOf('waves-effect') === -1) {
  13090. element.className += ' waves-effect' + classes;
  13091. }
  13092. }
  13093. };
  13094. /**
  13095. * Cause a ripple to appear in an element via code.
  13096. */
  13097. Waves.ripple = function(elements, options) {
  13098. elements = getWavesElements(elements);
  13099. var elementsLen = elements.length;
  13100. options = options || {};
  13101. options.wait = options.wait || 0;
  13102. options.position = options.position || null; // default = centre of element
  13103. if (elementsLen) {
  13104. var element, pos, off, centre = {}, i = 0;
  13105. var mousedown = {
  13106. type: 'mousedown',
  13107. button: 1
  13108. };
  13109. var hideRipple = function(mouseup, element) {
  13110. return function() {
  13111. Effect.hide(mouseup, element);
  13112. };
  13113. };
  13114. for (; i < elementsLen; i++) {
  13115. element = elements[i];
  13116. pos = options.position || {
  13117. x: element.clientWidth / 2,
  13118. y: element.clientHeight / 2
  13119. };
  13120. off = offset(element);
  13121. centre.x = off.left + pos.x;
  13122. centre.y = off.top + pos.y;
  13123. mousedown.pageX = centre.x;
  13124. mousedown.pageY = centre.y;
  13125. Effect.show(mousedown, element);
  13126. if (options.wait >= 0 && options.wait !== null) {
  13127. var mouseup = {
  13128. type: 'mouseup',
  13129. button: 1
  13130. };
  13131. setTimeout(hideRipple(mouseup, element), options.wait);
  13132. }
  13133. }
  13134. }
  13135. };
  13136. /**
  13137. * Remove all ripples from an element.
  13138. */
  13139. Waves.calm = function(elements) {
  13140. elements = getWavesElements(elements);
  13141. var mouseup = {
  13142. type: 'mouseup',
  13143. button: 1
  13144. };
  13145. for (var i = 0, len = elements.length; i < len; i++) {
  13146. Effect.hide(mouseup, elements[i]);
  13147. }
  13148. };
  13149. /**
  13150. * Deprecated API fallback
  13151. */
  13152. Waves.displayEffect = function(options) {
  13153. console.error('Waves.displayEffect() has been deprecated and will be removed in future version. Please use Waves.init() to initialize Waves effect');
  13154. Waves.init(options);
  13155. };
  13156. return Waves;
  13157. });
  13158. //Initialization
  13159. Waves.attach('.btn:not(.btn-flat), .btn-floating', ['waves-light']);
  13160. Waves.attach('.btn-flat', ['waves-effect']);
  13161. Waves.attach('.chip', ['waves-effect']);
  13162. Waves.attach('.view a .mask', ['waves-light']);
  13163. Waves.attach('.waves-light', ['waves-light']);
  13164. Waves.attach('.navbar-nav a:not(.navbar-brand), .nav-icons li a, .nav-tabs .nav-item:not(.dropdown)', ['waves-light']);
  13165. Waves.attach('.pager li a', ['waves-light']);
  13166. Waves.attach('.pagination .page-item .page-link', ['waves-effect']);
  13167. Waves.init();
  13168. "use strict";
  13169. var _this = void 0;
  13170. (function ($) {
  13171. var inputSelector = "".concat(['text', 'password', 'email', 'url', 'tel', 'number', 'search', 'search-md'].map(function (selector) {
  13172. return "input[type=".concat(selector, "]");
  13173. }).join(', '), ", textarea");
  13174. var textAreaSelector = '.materialize-textarea';
  13175. var updateTextFields = function updateTextFields($input) {
  13176. var $labelAndIcon = $input.siblings('label, i');
  13177. var hasValue = $input.val().length;
  13178. var hasPlaceholder = $input.attr('placeholder');
  13179. var addOrRemove = "".concat(hasValue || hasPlaceholder ? 'add' : 'remove', "Class");
  13180. $labelAndIcon[addOrRemove]('active');
  13181. };
  13182. var validateField = function validateField($input) {
  13183. if ($input.hasClass('validate')) {
  13184. var value = $input.val();
  13185. var noValue = !value.length;
  13186. var isValid = !$input[0].validity.badInput;
  13187. if (noValue && isValid) {
  13188. $input.removeClass('valid').removeClass('invalid');
  13189. } else {
  13190. var valid = $input.is(':valid');
  13191. var length = Number($input.attr('length')) || 0;
  13192. if (valid && (!length || length > value.length)) {
  13193. $input.removeClass('invalid').addClass('valid');
  13194. } else {
  13195. $input.removeClass('valid').addClass('invalid');
  13196. }
  13197. }
  13198. }
  13199. };
  13200. var textAreaAutoResize = function textAreaAutoResize() {
  13201. var $textarea = $(_this);
  13202. if ($textarea.val().length) {
  13203. var $hiddenDiv = $('.hiddendiv');
  13204. var fontFamily = $textarea.css('font-family');
  13205. var fontSize = $textarea.css('font-size');
  13206. if (fontSize) {
  13207. $hiddenDiv.css('font-size', fontSize);
  13208. }
  13209. if (fontFamily) {
  13210. $hiddenDiv.css('font-family', fontFamily);
  13211. }
  13212. if ($textarea.attr('wrap') === 'off') {
  13213. $hiddenDiv.css('overflow-wrap', 'normal').css('white-space', 'pre');
  13214. }
  13215. $hiddenDiv.text("".concat($textarea.val(), "\n"));
  13216. var content = $hiddenDiv.html().replace(/\n/g, '<br>');
  13217. $hiddenDiv.html(content); // When textarea is hidden, width goes crazy.
  13218. // Approximate with half of window size
  13219. $hiddenDiv.css('width', $textarea.is(':visible') ? $textarea.width() : $(window).width() / 2);
  13220. $textarea.css('height', $hiddenDiv.height());
  13221. }
  13222. };
  13223. $(inputSelector).each(function (index, input) {
  13224. var $this = $(input);
  13225. var $labelAndIcon = $this.siblings('label, i');
  13226. updateTextFields($this);
  13227. var isValid = input.validity.badInput;
  13228. if (isValid) {
  13229. $labelAndIcon.addClass('active');
  13230. }
  13231. });
  13232. $(document).on('focus', inputSelector, function (e) {
  13233. $(e.target).siblings('label, i').addClass('active');
  13234. });
  13235. $(document).on('blur', inputSelector, function (e) {
  13236. var $this = $(e.target);
  13237. var noValue = !$this.val();
  13238. var invalid = !e.target.validity.badInput;
  13239. var noPlaceholder = $this.attr('placeholder') === undefined;
  13240. if (noValue && invalid && noPlaceholder) {
  13241. $this.siblings('label, i').removeClass('active');
  13242. }
  13243. validateField($this);
  13244. });
  13245. $(document).on('change', inputSelector, function (e) {
  13246. var $this = $(e.target);
  13247. updateTextFields($this);
  13248. validateField($this);
  13249. });
  13250. $('input[autofocus]').siblings('label, i').addClass('active');
  13251. $(document).on('reset', function (e) {
  13252. var $formReset = $(e.target);
  13253. if ($formReset.is('form')) {
  13254. var $formInputs = $formReset.find(inputSelector);
  13255. $formInputs.removeClass('valid').removeClass('invalid').each(function (index, input) {
  13256. var $this = $(input);
  13257. var noDefaultValue = !$this.val();
  13258. var noPlaceholder = !$this.attr('placeholder');
  13259. if (noDefaultValue && noPlaceholder) {
  13260. $this.siblings('label, i').removeClass('active');
  13261. }
  13262. });
  13263. $formReset.find('select.initialized').each(function (index, select) {
  13264. var $select = $(select);
  13265. var $visibleInput = $select.siblings('input.select-dropdown');
  13266. var defaultValue = $select.children('[selected]').val();
  13267. $select.val(defaultValue);
  13268. $visibleInput.val(defaultValue);
  13269. });
  13270. }
  13271. });
  13272. function init() {
  13273. var $text = $('.md-textarea-auto');
  13274. if ($text.length) {
  13275. var observe;
  13276. if (window.attachEvent) {
  13277. observe = function observe(element, event, handler) {
  13278. element.attachEvent("on".concat(event), handler);
  13279. };
  13280. } else {
  13281. observe = function observe(element, event, handler) {
  13282. element.addEventListener(event, handler, false);
  13283. };
  13284. }
  13285. $text.each(function () {
  13286. var self = this;
  13287. function resize() {
  13288. self.style.height = 'auto';
  13289. self.style.height = "".concat(self.scrollHeight, "px");
  13290. }
  13291. function delayedResize() {
  13292. window.setTimeout(resize, 0);
  13293. }
  13294. observe(self, 'change', resize);
  13295. observe(self, 'cut', delayedResize);
  13296. observe(self, 'paste', delayedResize);
  13297. observe(self, 'drop', delayedResize);
  13298. observe(self, 'keydown', delayedResize);
  13299. resize();
  13300. });
  13301. }
  13302. }
  13303. init();
  13304. var $body = $('body');
  13305. if (!$('.hiddendiv').first().length) {
  13306. var $hiddenDiv = $('<div class="hiddendiv common"></div>');
  13307. $body.append($hiddenDiv);
  13308. }
  13309. $(textAreaSelector).each(textAreaAutoResize);
  13310. $body.on('keyup keydown', textAreaSelector, textAreaAutoResize);
  13311. })(jQuery);
  13312. /*
  13313. Enhanced Bootstrap Modals
  13314. https://mdbootstrap.com
  13315. office@mdbootstrap.com
  13316. */
  13317. (function($){
  13318. $('body').on('shown.bs.modal', '.modal', function() {
  13319. if(!$('.modal-backdrop').length) {
  13320. $modal_dialog = $(this).children('.modal-dialog')
  13321. if($modal_dialog.hasClass('modal-side')) {
  13322. $(this).addClass('modal-scrolling');
  13323. $('body').addClass('scrollable');
  13324. }
  13325. if($modal_dialog.hasClass('modal-frame')) {
  13326. $(this).addClass('modal-content-clickable');
  13327. $('body').addClass('scrollable');
  13328. }
  13329. }
  13330. });
  13331. $('body').on('hidden.bs.modal', '.modal', function() {
  13332. $('body').removeClass('scrollable');
  13333. });
  13334. })(jQuery);
  13335. "use strict";
  13336. var toggler = document.getElementsByClassName("rotate");
  13337. var i;
  13338. for (i = 0; i < toggler.length; i++) {
  13339. toggler[i].addEventListener("click", function () {
  13340. this.parentElement.querySelector(".nested").classList.toggle("active");
  13341. this.classList.toggle("down");
  13342. });
  13343. }
  13344. /*!
  13345. * bsCustomFileInput v1.3.2 (https://github.com/Johann-S/bs-custom-file-input)
  13346. * Copyright 2018 - 2019 Johann-S <johann.servoire@gmail.com>
  13347. * Licensed under MIT (https://github.com/Johann-S/bs-custom-file-input/blob/master/LICENSE)
  13348. */
  13349. (function (global, factory) {
  13350. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  13351. typeof define === 'function' && define.amd ? define(factory) :
  13352. (global = global || self, global.bsCustomFileInput = factory());
  13353. }(this, function () {
  13354. 'use strict';
  13355. var Selector = {
  13356. CUSTOMFILE: '.custom-file input[type="file"]',
  13357. CUSTOMFILELABEL: '.custom-file-label',
  13358. FORM: 'form',
  13359. INPUT: 'input'
  13360. };
  13361. var textNodeType = 3;
  13362. var getDefaultText = function getDefaultText(input) {
  13363. var defaultText = '';
  13364. var label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL);
  13365. if (label) {
  13366. defaultText = label.innerHTML;
  13367. }
  13368. return defaultText;
  13369. };
  13370. var findFirstChildNode = function findFirstChildNode(element) {
  13371. if (element.childNodes.length > 0) {
  13372. var childNodes = [].slice.call(element.childNodes);
  13373. for (var i = 0; i < childNodes.length; i++) {
  13374. var node = childNodes[i];
  13375. if (node.nodeType !== textNodeType) {
  13376. return node;
  13377. }
  13378. }
  13379. }
  13380. return element;
  13381. };
  13382. var restoreDefaultText = function restoreDefaultText(input) {
  13383. var defaultText = input.bsCustomFileInput.defaultText;
  13384. var label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL);
  13385. if (label) {
  13386. var element = findFirstChildNode(label);
  13387. element.innerHTML = defaultText;
  13388. }
  13389. };
  13390. var fileApi = !!window.File;
  13391. var FAKE_PATH = 'fakepath';
  13392. var FAKE_PATH_SEPARATOR = '\\';
  13393. var getSelectedFiles = function getSelectedFiles(input) {
  13394. if (input.hasAttribute('multiple') && fileApi) {
  13395. return [].slice.call(input.files).map(function (file) {
  13396. return file.name;
  13397. }).join(', ');
  13398. }
  13399. if (input.value.indexOf(FAKE_PATH) !== -1) {
  13400. var splittedValue = input.value.split(FAKE_PATH_SEPARATOR);
  13401. return splittedValue[splittedValue.length - 1];
  13402. }
  13403. return input.value;
  13404. };
  13405. function handleInputChange() {
  13406. var label = this.parentNode.querySelector(Selector.CUSTOMFILELABEL);
  13407. if (label) {
  13408. var element = findFirstChildNode(label);
  13409. var inputValue = getSelectedFiles(this);
  13410. if (inputValue.length) {
  13411. element.innerHTML = inputValue;
  13412. } else {
  13413. restoreDefaultText(this);
  13414. }
  13415. }
  13416. }
  13417. function handleFormReset() {
  13418. var customFileList = [].slice.call(this.querySelectorAll(Selector.INPUT)).filter(function (input) {
  13419. return !!input.bsCustomFileInput;
  13420. });
  13421. for (var i = 0, len = customFileList.length; i < len; i++) {
  13422. restoreDefaultText(customFileList[i]);
  13423. }
  13424. }
  13425. var customProperty = 'bsCustomFileInput';
  13426. var Event = {
  13427. FORMRESET: 'reset',
  13428. INPUTCHANGE: 'change'
  13429. };
  13430. var bsCustomFileInput = {
  13431. init: function init(inputSelector, formSelector) {
  13432. if (inputSelector === void 0) {
  13433. inputSelector = Selector.CUSTOMFILE;
  13434. }
  13435. if (formSelector === void 0) {
  13436. formSelector = Selector.FORM;
  13437. }
  13438. var customFileInputList = [].slice.call(document.querySelectorAll(inputSelector));
  13439. var formList = [].slice.call(document.querySelectorAll(formSelector));
  13440. for (var i = 0, len = customFileInputList.length; i < len; i++) {
  13441. var input = customFileInputList[i];
  13442. Object.defineProperty(input, customProperty, {
  13443. value: {
  13444. defaultText: getDefaultText(input)
  13445. },
  13446. writable: true
  13447. });
  13448. handleInputChange.call(input);
  13449. input.addEventListener(Event.INPUTCHANGE, handleInputChange);
  13450. }
  13451. for (var _i = 0, _len = formList.length; _i < _len; _i++) {
  13452. formList[_i].addEventListener(Event.FORMRESET, handleFormReset);
  13453. Object.defineProperty(formList[_i], customProperty, {
  13454. value: true,
  13455. writable: true
  13456. });
  13457. }
  13458. },
  13459. destroy: function destroy() {
  13460. var formList = [].slice.call(document.querySelectorAll(Selector.FORM)).filter(function (form) {
  13461. return !!form.bsCustomFileInput;
  13462. });
  13463. var customFileInputList = [].slice.call(document.querySelectorAll(Selector.INPUT)).filter(function (input) {
  13464. return !!input.bsCustomFileInput;
  13465. });
  13466. for (var i = 0, len = customFileInputList.length; i < len; i++) {
  13467. var input = customFileInputList[i];
  13468. restoreDefaultText(input);
  13469. input[customProperty] = undefined;
  13470. input.removeEventListener(Event.INPUTCHANGE, handleInputChange);
  13471. }
  13472. for (var _i2 = 0, _len2 = formList.length; _i2 < _len2; _i2++) {
  13473. formList[_i2].removeEventListener(Event.FORMRESET, handleFormReset);
  13474. formList[_i2][customProperty] = undefined;
  13475. }
  13476. }
  13477. };
  13478. return bsCustomFileInput;
  13479. }));
  13480. //# sourceMappingURL=bs-custom-file-input.js.map
  13481. document.addEventListener("DOMContentLoaded", function () {
  13482. bsCustomFileInput.init()
  13483. });