chartjs.js 388 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. },{}],2:[function(require,module,exports){
  3. /* MIT license */
  4. module.exports = {
  5. rgb2hsl: rgb2hsl,
  6. rgb2hsv: rgb2hsv,
  7. rgb2hwb: rgb2hwb,
  8. rgb2cmyk: rgb2cmyk,
  9. rgb2keyword: rgb2keyword,
  10. rgb2xyz: rgb2xyz,
  11. rgb2lab: rgb2lab,
  12. rgb2lch: rgb2lch,
  13. hsl2rgb: hsl2rgb,
  14. hsl2hsv: hsl2hsv,
  15. hsl2hwb: hsl2hwb,
  16. hsl2cmyk: hsl2cmyk,
  17. hsl2keyword: hsl2keyword,
  18. hsv2rgb: hsv2rgb,
  19. hsv2hsl: hsv2hsl,
  20. hsv2hwb: hsv2hwb,
  21. hsv2cmyk: hsv2cmyk,
  22. hsv2keyword: hsv2keyword,
  23. hwb2rgb: hwb2rgb,
  24. hwb2hsl: hwb2hsl,
  25. hwb2hsv: hwb2hsv,
  26. hwb2cmyk: hwb2cmyk,
  27. hwb2keyword: hwb2keyword,
  28. cmyk2rgb: cmyk2rgb,
  29. cmyk2hsl: cmyk2hsl,
  30. cmyk2hsv: cmyk2hsv,
  31. cmyk2hwb: cmyk2hwb,
  32. cmyk2keyword: cmyk2keyword,
  33. keyword2rgb: keyword2rgb,
  34. keyword2hsl: keyword2hsl,
  35. keyword2hsv: keyword2hsv,
  36. keyword2hwb: keyword2hwb,
  37. keyword2cmyk: keyword2cmyk,
  38. keyword2lab: keyword2lab,
  39. keyword2xyz: keyword2xyz,
  40. xyz2rgb: xyz2rgb,
  41. xyz2lab: xyz2lab,
  42. xyz2lch: xyz2lch,
  43. lab2xyz: lab2xyz,
  44. lab2rgb: lab2rgb,
  45. lab2lch: lab2lch,
  46. lch2lab: lch2lab,
  47. lch2xyz: lch2xyz,
  48. lch2rgb: lch2rgb
  49. }
  50. function rgb2hsl(rgb) {
  51. var r = rgb[0]/255,
  52. g = rgb[1]/255,
  53. b = rgb[2]/255,
  54. min = Math.min(r, g, b),
  55. max = Math.max(r, g, b),
  56. delta = max - min,
  57. h, s, l;
  58. if (max == min)
  59. h = 0;
  60. else if (r == max)
  61. h = (g - b) / delta;
  62. else if (g == max)
  63. h = 2 + (b - r) / delta;
  64. else if (b == max)
  65. h = 4 + (r - g)/ delta;
  66. h = Math.min(h * 60, 360);
  67. if (h < 0)
  68. h += 360;
  69. l = (min + max) / 2;
  70. if (max == min)
  71. s = 0;
  72. else if (l <= 0.5)
  73. s = delta / (max + min);
  74. else
  75. s = delta / (2 - max - min);
  76. return [h, s * 100, l * 100];
  77. }
  78. function rgb2hsv(rgb) {
  79. var r = rgb[0],
  80. g = rgb[1],
  81. b = rgb[2],
  82. min = Math.min(r, g, b),
  83. max = Math.max(r, g, b),
  84. delta = max - min,
  85. h, s, v;
  86. if (max == 0)
  87. s = 0;
  88. else
  89. s = (delta/max * 1000)/10;
  90. if (max == min)
  91. h = 0;
  92. else if (r == max)
  93. h = (g - b) / delta;
  94. else if (g == max)
  95. h = 2 + (b - r) / delta;
  96. else if (b == max)
  97. h = 4 + (r - g) / delta;
  98. h = Math.min(h * 60, 360);
  99. if (h < 0)
  100. h += 360;
  101. v = ((max / 255) * 1000) / 10;
  102. return [h, s, v];
  103. }
  104. function rgb2hwb(rgb) {
  105. var r = rgb[0],
  106. g = rgb[1],
  107. b = rgb[2],
  108. h = rgb2hsl(rgb)[0],
  109. w = 1/255 * Math.min(r, Math.min(g, b)),
  110. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  111. return [h, w * 100, b * 100];
  112. }
  113. function rgb2cmyk(rgb) {
  114. var r = rgb[0] / 255,
  115. g = rgb[1] / 255,
  116. b = rgb[2] / 255,
  117. c, m, y, k;
  118. k = Math.min(1 - r, 1 - g, 1 - b);
  119. c = (1 - r - k) / (1 - k) || 0;
  120. m = (1 - g - k) / (1 - k) || 0;
  121. y = (1 - b - k) / (1 - k) || 0;
  122. return [c * 100, m * 100, y * 100, k * 100];
  123. }
  124. function rgb2keyword(rgb) {
  125. return reverseKeywords[JSON.stringify(rgb)];
  126. }
  127. function rgb2xyz(rgb) {
  128. var r = rgb[0] / 255,
  129. g = rgb[1] / 255,
  130. b = rgb[2] / 255;
  131. // assume sRGB
  132. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  133. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  134. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  135. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  136. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  137. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  138. return [x * 100, y *100, z * 100];
  139. }
  140. function rgb2lab(rgb) {
  141. var xyz = rgb2xyz(rgb),
  142. x = xyz[0],
  143. y = xyz[1],
  144. z = xyz[2],
  145. l, a, b;
  146. x /= 95.047;
  147. y /= 100;
  148. z /= 108.883;
  149. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  150. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  151. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  152. l = (116 * y) - 16;
  153. a = 500 * (x - y);
  154. b = 200 * (y - z);
  155. return [l, a, b];
  156. }
  157. function rgb2lch(args) {
  158. return lab2lch(rgb2lab(args));
  159. }
  160. function hsl2rgb(hsl) {
  161. var h = hsl[0] / 360,
  162. s = hsl[1] / 100,
  163. l = hsl[2] / 100,
  164. t1, t2, t3, rgb, val;
  165. if (s == 0) {
  166. val = l * 255;
  167. return [val, val, val];
  168. }
  169. if (l < 0.5)
  170. t2 = l * (1 + s);
  171. else
  172. t2 = l + s - l * s;
  173. t1 = 2 * l - t2;
  174. rgb = [0, 0, 0];
  175. for (var i = 0; i < 3; i++) {
  176. t3 = h + 1 / 3 * - (i - 1);
  177. t3 < 0 && t3++;
  178. t3 > 1 && t3--;
  179. if (6 * t3 < 1)
  180. val = t1 + (t2 - t1) * 6 * t3;
  181. else if (2 * t3 < 1)
  182. val = t2;
  183. else if (3 * t3 < 2)
  184. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  185. else
  186. val = t1;
  187. rgb[i] = val * 255;
  188. }
  189. return rgb;
  190. }
  191. function hsl2hsv(hsl) {
  192. var h = hsl[0],
  193. s = hsl[1] / 100,
  194. l = hsl[2] / 100,
  195. sv, v;
  196. if(l === 0) {
  197. // no need to do calc on black
  198. // also avoids divide by 0 error
  199. return [0, 0, 0];
  200. }
  201. l *= 2;
  202. s *= (l <= 1) ? l : 2 - l;
  203. v = (l + s) / 2;
  204. sv = (2 * s) / (l + s);
  205. return [h, sv * 100, v * 100];
  206. }
  207. function hsl2hwb(args) {
  208. return rgb2hwb(hsl2rgb(args));
  209. }
  210. function hsl2cmyk(args) {
  211. return rgb2cmyk(hsl2rgb(args));
  212. }
  213. function hsl2keyword(args) {
  214. return rgb2keyword(hsl2rgb(args));
  215. }
  216. function hsv2rgb(hsv) {
  217. var h = hsv[0] / 60,
  218. s = hsv[1] / 100,
  219. v = hsv[2] / 100,
  220. hi = Math.floor(h) % 6;
  221. var f = h - Math.floor(h),
  222. p = 255 * v * (1 - s),
  223. q = 255 * v * (1 - (s * f)),
  224. t = 255 * v * (1 - (s * (1 - f))),
  225. v = 255 * v;
  226. switch(hi) {
  227. case 0:
  228. return [v, t, p];
  229. case 1:
  230. return [q, v, p];
  231. case 2:
  232. return [p, v, t];
  233. case 3:
  234. return [p, q, v];
  235. case 4:
  236. return [t, p, v];
  237. case 5:
  238. return [v, p, q];
  239. }
  240. }
  241. function hsv2hsl(hsv) {
  242. var h = hsv[0],
  243. s = hsv[1] / 100,
  244. v = hsv[2] / 100,
  245. sl, l;
  246. l = (2 - s) * v;
  247. sl = s * v;
  248. sl /= (l <= 1) ? l : 2 - l;
  249. sl = sl || 0;
  250. l /= 2;
  251. return [h, sl * 100, l * 100];
  252. }
  253. function hsv2hwb(args) {
  254. return rgb2hwb(hsv2rgb(args))
  255. }
  256. function hsv2cmyk(args) {
  257. return rgb2cmyk(hsv2rgb(args));
  258. }
  259. function hsv2keyword(args) {
  260. return rgb2keyword(hsv2rgb(args));
  261. }
  262. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  263. function hwb2rgb(hwb) {
  264. var h = hwb[0] / 360,
  265. wh = hwb[1] / 100,
  266. bl = hwb[2] / 100,
  267. ratio = wh + bl,
  268. i, v, f, n;
  269. // wh + bl cant be > 1
  270. if (ratio > 1) {
  271. wh /= ratio;
  272. bl /= ratio;
  273. }
  274. i = Math.floor(6 * h);
  275. v = 1 - bl;
  276. f = 6 * h - i;
  277. if ((i & 0x01) != 0) {
  278. f = 1 - f;
  279. }
  280. n = wh + f * (v - wh); // linear interpolation
  281. switch (i) {
  282. default:
  283. case 6:
  284. case 0: r = v; g = n; b = wh; break;
  285. case 1: r = n; g = v; b = wh; break;
  286. case 2: r = wh; g = v; b = n; break;
  287. case 3: r = wh; g = n; b = v; break;
  288. case 4: r = n; g = wh; b = v; break;
  289. case 5: r = v; g = wh; b = n; break;
  290. }
  291. return [r * 255, g * 255, b * 255];
  292. }
  293. function hwb2hsl(args) {
  294. return rgb2hsl(hwb2rgb(args));
  295. }
  296. function hwb2hsv(args) {
  297. return rgb2hsv(hwb2rgb(args));
  298. }
  299. function hwb2cmyk(args) {
  300. return rgb2cmyk(hwb2rgb(args));
  301. }
  302. function hwb2keyword(args) {
  303. return rgb2keyword(hwb2rgb(args));
  304. }
  305. function cmyk2rgb(cmyk) {
  306. var c = cmyk[0] / 100,
  307. m = cmyk[1] / 100,
  308. y = cmyk[2] / 100,
  309. k = cmyk[3] / 100,
  310. r, g, b;
  311. r = 1 - Math.min(1, c * (1 - k) + k);
  312. g = 1 - Math.min(1, m * (1 - k) + k);
  313. b = 1 - Math.min(1, y * (1 - k) + k);
  314. return [r * 255, g * 255, b * 255];
  315. }
  316. function cmyk2hsl(args) {
  317. return rgb2hsl(cmyk2rgb(args));
  318. }
  319. function cmyk2hsv(args) {
  320. return rgb2hsv(cmyk2rgb(args));
  321. }
  322. function cmyk2hwb(args) {
  323. return rgb2hwb(cmyk2rgb(args));
  324. }
  325. function cmyk2keyword(args) {
  326. return rgb2keyword(cmyk2rgb(args));
  327. }
  328. function xyz2rgb(xyz) {
  329. var x = xyz[0] / 100,
  330. y = xyz[1] / 100,
  331. z = xyz[2] / 100,
  332. r, g, b;
  333. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  334. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  335. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  336. // assume sRGB
  337. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  338. : r = (r * 12.92);
  339. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  340. : g = (g * 12.92);
  341. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  342. : b = (b * 12.92);
  343. r = Math.min(Math.max(0, r), 1);
  344. g = Math.min(Math.max(0, g), 1);
  345. b = Math.min(Math.max(0, b), 1);
  346. return [r * 255, g * 255, b * 255];
  347. }
  348. function xyz2lab(xyz) {
  349. var x = xyz[0],
  350. y = xyz[1],
  351. z = xyz[2],
  352. l, a, b;
  353. x /= 95.047;
  354. y /= 100;
  355. z /= 108.883;
  356. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  357. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  358. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  359. l = (116 * y) - 16;
  360. a = 500 * (x - y);
  361. b = 200 * (y - z);
  362. return [l, a, b];
  363. }
  364. function xyz2lch(args) {
  365. return lab2lch(xyz2lab(args));
  366. }
  367. function lab2xyz(lab) {
  368. var l = lab[0],
  369. a = lab[1],
  370. b = lab[2],
  371. x, y, z, y2;
  372. if (l <= 8) {
  373. y = (l * 100) / 903.3;
  374. y2 = (7.787 * (y / 100)) + (16 / 116);
  375. } else {
  376. y = 100 * Math.pow((l + 16) / 116, 3);
  377. y2 = Math.pow(y / 100, 1/3);
  378. }
  379. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  380. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  381. return [x, y, z];
  382. }
  383. function lab2lch(lab) {
  384. var l = lab[0],
  385. a = lab[1],
  386. b = lab[2],
  387. hr, h, c;
  388. hr = Math.atan2(b, a);
  389. h = hr * 360 / 2 / Math.PI;
  390. if (h < 0) {
  391. h += 360;
  392. }
  393. c = Math.sqrt(a * a + b * b);
  394. return [l, c, h];
  395. }
  396. function lab2rgb(args) {
  397. return xyz2rgb(lab2xyz(args));
  398. }
  399. function lch2lab(lch) {
  400. var l = lch[0],
  401. c = lch[1],
  402. h = lch[2],
  403. a, b, hr;
  404. hr = h / 360 * 2 * Math.PI;
  405. a = c * Math.cos(hr);
  406. b = c * Math.sin(hr);
  407. return [l, a, b];
  408. }
  409. function lch2xyz(args) {
  410. return lab2xyz(lch2lab(args));
  411. }
  412. function lch2rgb(args) {
  413. return lab2rgb(lch2lab(args));
  414. }
  415. function keyword2rgb(keyword) {
  416. return cssKeywords[keyword];
  417. }
  418. function keyword2hsl(args) {
  419. return rgb2hsl(keyword2rgb(args));
  420. }
  421. function keyword2hsv(args) {
  422. return rgb2hsv(keyword2rgb(args));
  423. }
  424. function keyword2hwb(args) {
  425. return rgb2hwb(keyword2rgb(args));
  426. }
  427. function keyword2cmyk(args) {
  428. return rgb2cmyk(keyword2rgb(args));
  429. }
  430. function keyword2lab(args) {
  431. return rgb2lab(keyword2rgb(args));
  432. }
  433. function keyword2xyz(args) {
  434. return rgb2xyz(keyword2rgb(args));
  435. }
  436. var cssKeywords = {
  437. aliceblue: [240,248,255],
  438. antiquewhite: [250,235,215],
  439. aqua: [0,255,255],
  440. aquamarine: [127,255,212],
  441. azure: [240,255,255],
  442. beige: [245,245,220],
  443. bisque: [255,228,196],
  444. black: [0,0,0],
  445. blanchedalmond: [255,235,205],
  446. blue: [0,0,255],
  447. blueviolet: [138,43,226],
  448. brown: [165,42,42],
  449. burlywood: [222,184,135],
  450. cadetblue: [95,158,160],
  451. chartreuse: [127,255,0],
  452. chocolate: [210,105,30],
  453. coral: [255,127,80],
  454. cornflowerblue: [100,149,237],
  455. cornsilk: [255,248,220],
  456. crimson: [220,20,60],
  457. cyan: [0,255,255],
  458. darkblue: [0,0,139],
  459. darkcyan: [0,139,139],
  460. darkgoldenrod: [184,134,11],
  461. darkgray: [169,169,169],
  462. darkgreen: [0,100,0],
  463. darkgrey: [169,169,169],
  464. darkkhaki: [189,183,107],
  465. darkmagenta: [139,0,139],
  466. darkolivegreen: [85,107,47],
  467. darkorange: [255,140,0],
  468. darkorchid: [153,50,204],
  469. darkred: [139,0,0],
  470. darksalmon: [233,150,122],
  471. darkseagreen: [143,188,143],
  472. darkslateblue: [72,61,139],
  473. darkslategray: [47,79,79],
  474. darkslategrey: [47,79,79],
  475. darkturquoise: [0,206,209],
  476. darkviolet: [148,0,211],
  477. deeppink: [255,20,147],
  478. deepskyblue: [0,191,255],
  479. dimgray: [105,105,105],
  480. dimgrey: [105,105,105],
  481. dodgerblue: [30,144,255],
  482. firebrick: [178,34,34],
  483. floralwhite: [255,250,240],
  484. forestgreen: [34,139,34],
  485. fuchsia: [255,0,255],
  486. gainsboro: [220,220,220],
  487. ghostwhite: [248,248,255],
  488. gold: [255,215,0],
  489. goldenrod: [218,165,32],
  490. gray: [128,128,128],
  491. green: [0,128,0],
  492. greenyellow: [173,255,47],
  493. grey: [128,128,128],
  494. honeydew: [240,255,240],
  495. hotpink: [255,105,180],
  496. indianred: [205,92,92],
  497. indigo: [75,0,130],
  498. ivory: [255,255,240],
  499. khaki: [240,230,140],
  500. lavender: [230,230,250],
  501. lavenderblush: [255,240,245],
  502. lawngreen: [124,252,0],
  503. lemonchiffon: [255,250,205],
  504. lightblue: [173,216,230],
  505. lightcoral: [240,128,128],
  506. lightcyan: [224,255,255],
  507. lightgoldenrodyellow: [250,250,210],
  508. lightgray: [211,211,211],
  509. lightgreen: [144,238,144],
  510. lightgrey: [211,211,211],
  511. lightpink: [255,182,193],
  512. lightsalmon: [255,160,122],
  513. lightseagreen: [32,178,170],
  514. lightskyblue: [135,206,250],
  515. lightslategray: [119,136,153],
  516. lightslategrey: [119,136,153],
  517. lightsteelblue: [176,196,222],
  518. lightyellow: [255,255,224],
  519. lime: [0,255,0],
  520. limegreen: [50,205,50],
  521. linen: [250,240,230],
  522. magenta: [255,0,255],
  523. maroon: [128,0,0],
  524. mediumaquamarine: [102,205,170],
  525. mediumblue: [0,0,205],
  526. mediumorchid: [186,85,211],
  527. mediumpurple: [147,112,219],
  528. mediumseagreen: [60,179,113],
  529. mediumslateblue: [123,104,238],
  530. mediumspringgreen: [0,250,154],
  531. mediumturquoise: [72,209,204],
  532. mediumvioletred: [199,21,133],
  533. midnightblue: [25,25,112],
  534. mintcream: [245,255,250],
  535. mistyrose: [255,228,225],
  536. moccasin: [255,228,181],
  537. navajowhite: [255,222,173],
  538. navy: [0,0,128],
  539. oldlace: [253,245,230],
  540. olive: [128,128,0],
  541. olivedrab: [107,142,35],
  542. orange: [255,165,0],
  543. orangered: [255,69,0],
  544. orchid: [218,112,214],
  545. palegoldenrod: [238,232,170],
  546. palegreen: [152,251,152],
  547. paleturquoise: [175,238,238],
  548. palevioletred: [219,112,147],
  549. papayawhip: [255,239,213],
  550. peachpuff: [255,218,185],
  551. peru: [205,133,63],
  552. pink: [255,192,203],
  553. plum: [221,160,221],
  554. powderblue: [176,224,230],
  555. purple: [128,0,128],
  556. rebeccapurple: [102, 51, 153],
  557. red: [255,0,0],
  558. rosybrown: [188,143,143],
  559. royalblue: [65,105,225],
  560. saddlebrown: [139,69,19],
  561. salmon: [250,128,114],
  562. sandybrown: [244,164,96],
  563. seagreen: [46,139,87],
  564. seashell: [255,245,238],
  565. sienna: [160,82,45],
  566. silver: [192,192,192],
  567. skyblue: [135,206,235],
  568. slateblue: [106,90,205],
  569. slategray: [112,128,144],
  570. slategrey: [112,128,144],
  571. snow: [255,250,250],
  572. springgreen: [0,255,127],
  573. steelblue: [70,130,180],
  574. tan: [210,180,140],
  575. teal: [0,128,128],
  576. thistle: [216,191,216],
  577. tomato: [255,99,71],
  578. turquoise: [64,224,208],
  579. violet: [238,130,238],
  580. wheat: [245,222,179],
  581. white: [255,255,255],
  582. whitesmoke: [245,245,245],
  583. yellow: [255,255,0],
  584. yellowgreen: [154,205,50]
  585. };
  586. var reverseKeywords = {};
  587. for (var key in cssKeywords) {
  588. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  589. }
  590. },{}],3:[function(require,module,exports){
  591. var conversions = require("./conversions");
  592. var convert = function() {
  593. return new Converter();
  594. }
  595. for (var func in conversions) {
  596. // export Raw versions
  597. convert[func + "Raw"] = (function(func) {
  598. // accept array or plain args
  599. return function(arg) {
  600. if (typeof arg == "number")
  601. arg = Array.prototype.slice.call(arguments);
  602. return conversions[func](arg);
  603. }
  604. })(func);
  605. var pair = /(\w+)2(\w+)/.exec(func),
  606. from = pair[1],
  607. to = pair[2];
  608. // export rgb2hsl and ["rgb"]["hsl"]
  609. convert[from] = convert[from] || {};
  610. convert[from][to] = convert[func] = (function(func) {
  611. return function(arg) {
  612. if (typeof arg == "number")
  613. arg = Array.prototype.slice.call(arguments);
  614. var val = conversions[func](arg);
  615. if (typeof val == "string" || val === undefined)
  616. return val; // keyword
  617. for (var i = 0; i < val.length; i++)
  618. val[i] = Math.round(val[i]);
  619. return val;
  620. }
  621. })(func);
  622. }
  623. /* Converter does lazy conversion and caching */
  624. var Converter = function() {
  625. this.convs = {};
  626. };
  627. /* Either get the values for a space or
  628. set the values for a space, depending on args */
  629. Converter.prototype.routeSpace = function(space, args) {
  630. var values = args[0];
  631. if (values === undefined) {
  632. // color.rgb()
  633. return this.getValues(space);
  634. }
  635. // color.rgb(10, 10, 10)
  636. if (typeof values == "number") {
  637. values = Array.prototype.slice.call(args);
  638. }
  639. return this.setValues(space, values);
  640. };
  641. /* Set the values for a space, invalidating cache */
  642. Converter.prototype.setValues = function(space, values) {
  643. this.space = space;
  644. this.convs = {};
  645. this.convs[space] = values;
  646. return this;
  647. };
  648. /* Get the values for a space. If there's already
  649. a conversion for the space, fetch it, otherwise
  650. compute it */
  651. Converter.prototype.getValues = function(space) {
  652. var vals = this.convs[space];
  653. if (!vals) {
  654. var fspace = this.space,
  655. from = this.convs[fspace];
  656. vals = convert[fspace][space](from);
  657. this.convs[space] = vals;
  658. }
  659. return vals;
  660. };
  661. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  662. Converter.prototype[space] = function(vals) {
  663. return this.routeSpace(space, arguments);
  664. }
  665. });
  666. module.exports = convert;
  667. },{"./conversions":2}],4:[function(require,module,exports){
  668. /* MIT license */
  669. var colorNames = require('color-name');
  670. module.exports = {
  671. getRgba: getRgba,
  672. getHsla: getHsla,
  673. getRgb: getRgb,
  674. getHsl: getHsl,
  675. getHwb: getHwb,
  676. getAlpha: getAlpha,
  677. hexString: hexString,
  678. rgbString: rgbString,
  679. rgbaString: rgbaString,
  680. percentString: percentString,
  681. percentaString: percentaString,
  682. hslString: hslString,
  683. hslaString: hslaString,
  684. hwbString: hwbString,
  685. keyword: keyword
  686. }
  687. function getRgba(string) {
  688. if (!string) {
  689. return;
  690. }
  691. var abbr = /^#([a-fA-F0-9]{3})$/,
  692. hex = /^#([a-fA-F0-9]{6})$/,
  693. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  694. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  695. keyword = /(\w+)/;
  696. var rgb = [0, 0, 0],
  697. a = 1,
  698. match = string.match(abbr);
  699. if (match) {
  700. match = match[1];
  701. for (var i = 0; i < rgb.length; i++) {
  702. rgb[i] = parseInt(match[i] + match[i], 16);
  703. }
  704. }
  705. else if (match = string.match(hex)) {
  706. match = match[1];
  707. for (var i = 0; i < rgb.length; i++) {
  708. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  709. }
  710. }
  711. else if (match = string.match(rgba)) {
  712. for (var i = 0; i < rgb.length; i++) {
  713. rgb[i] = parseInt(match[i + 1]);
  714. }
  715. a = parseFloat(match[4]);
  716. }
  717. else if (match = string.match(per)) {
  718. for (var i = 0; i < rgb.length; i++) {
  719. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  720. }
  721. a = parseFloat(match[4]);
  722. }
  723. else if (match = string.match(keyword)) {
  724. if (match[1] == "transparent") {
  725. return [0, 0, 0, 0];
  726. }
  727. rgb = colorNames[match[1]];
  728. if (!rgb) {
  729. return;
  730. }
  731. }
  732. for (var i = 0; i < rgb.length; i++) {
  733. rgb[i] = scale(rgb[i], 0, 255);
  734. }
  735. if (!a && a != 0) {
  736. a = 1;
  737. }
  738. else {
  739. a = scale(a, 0, 1);
  740. }
  741. rgb[3] = a;
  742. return rgb;
  743. }
  744. function getHsla(string) {
  745. if (!string) {
  746. return;
  747. }
  748. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  749. var match = string.match(hsl);
  750. if (match) {
  751. var alpha = parseFloat(match[4]);
  752. var h = scale(parseInt(match[1]), 0, 360),
  753. s = scale(parseFloat(match[2]), 0, 100),
  754. l = scale(parseFloat(match[3]), 0, 100),
  755. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  756. return [h, s, l, a];
  757. }
  758. }
  759. function getHwb(string) {
  760. if (!string) {
  761. return;
  762. }
  763. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  764. var match = string.match(hwb);
  765. if (match) {
  766. var alpha = parseFloat(match[4]);
  767. var h = scale(parseInt(match[1]), 0, 360),
  768. w = scale(parseFloat(match[2]), 0, 100),
  769. b = scale(parseFloat(match[3]), 0, 100),
  770. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  771. return [h, w, b, a];
  772. }
  773. }
  774. function getRgb(string) {
  775. var rgba = getRgba(string);
  776. return rgba && rgba.slice(0, 3);
  777. }
  778. function getHsl(string) {
  779. var hsla = getHsla(string);
  780. return hsla && hsla.slice(0, 3);
  781. }
  782. function getAlpha(string) {
  783. var vals = getRgba(string);
  784. if (vals) {
  785. return vals[3];
  786. }
  787. else if (vals = getHsla(string)) {
  788. return vals[3];
  789. }
  790. else if (vals = getHwb(string)) {
  791. return vals[3];
  792. }
  793. }
  794. // generators
  795. function hexString(rgb) {
  796. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  797. + hexDouble(rgb[2]);
  798. }
  799. function rgbString(rgba, alpha) {
  800. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  801. return rgbaString(rgba, alpha);
  802. }
  803. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  804. }
  805. function rgbaString(rgba, alpha) {
  806. if (alpha === undefined) {
  807. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  808. }
  809. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  810. + ", " + alpha + ")";
  811. }
  812. function percentString(rgba, alpha) {
  813. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  814. return percentaString(rgba, alpha);
  815. }
  816. var r = Math.round(rgba[0]/255 * 100),
  817. g = Math.round(rgba[1]/255 * 100),
  818. b = Math.round(rgba[2]/255 * 100);
  819. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  820. }
  821. function percentaString(rgba, alpha) {
  822. var r = Math.round(rgba[0]/255 * 100),
  823. g = Math.round(rgba[1]/255 * 100),
  824. b = Math.round(rgba[2]/255 * 100);
  825. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  826. }
  827. function hslString(hsla, alpha) {
  828. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  829. return hslaString(hsla, alpha);
  830. }
  831. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  832. }
  833. function hslaString(hsla, alpha) {
  834. if (alpha === undefined) {
  835. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  836. }
  837. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  838. + alpha + ")";
  839. }
  840. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  841. // (hwb have alpha optional & 1 is default value)
  842. function hwbString(hwb, alpha) {
  843. if (alpha === undefined) {
  844. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  845. }
  846. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  847. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  848. }
  849. function keyword(rgb) {
  850. return reverseNames[rgb.slice(0, 3)];
  851. }
  852. // helpers
  853. function scale(num, min, max) {
  854. return Math.min(Math.max(min, num), max);
  855. }
  856. function hexDouble(num) {
  857. var str = num.toString(16).toUpperCase();
  858. return (str.length < 2) ? "0" + str : str;
  859. }
  860. //create a list of reverse color names
  861. var reverseNames = {};
  862. for (var name in colorNames) {
  863. reverseNames[colorNames[name]] = name;
  864. }
  865. },{"color-name":5}],5:[function(require,module,exports){
  866. module.exports = {
  867. "aliceblue": [240, 248, 255],
  868. "antiquewhite": [250, 235, 215],
  869. "aqua": [0, 255, 255],
  870. "aquamarine": [127, 255, 212],
  871. "azure": [240, 255, 255],
  872. "beige": [245, 245, 220],
  873. "bisque": [255, 228, 196],
  874. "black": [0, 0, 0],
  875. "blanchedalmond": [255, 235, 205],
  876. "blue": [0, 0, 255],
  877. "blueviolet": [138, 43, 226],
  878. "brown": [165, 42, 42],
  879. "burlywood": [222, 184, 135],
  880. "cadetblue": [95, 158, 160],
  881. "chartreuse": [127, 255, 0],
  882. "chocolate": [210, 105, 30],
  883. "coral": [255, 127, 80],
  884. "cornflowerblue": [100, 149, 237],
  885. "cornsilk": [255, 248, 220],
  886. "crimson": [220, 20, 60],
  887. "cyan": [0, 255, 255],
  888. "darkblue": [0, 0, 139],
  889. "darkcyan": [0, 139, 139],
  890. "darkgoldenrod": [184, 134, 11],
  891. "darkgray": [169, 169, 169],
  892. "darkgreen": [0, 100, 0],
  893. "darkgrey": [169, 169, 169],
  894. "darkkhaki": [189, 183, 107],
  895. "darkmagenta": [139, 0, 139],
  896. "darkolivegreen": [85, 107, 47],
  897. "darkorange": [255, 140, 0],
  898. "darkorchid": [153, 50, 204],
  899. "darkred": [139, 0, 0],
  900. "darksalmon": [233, 150, 122],
  901. "darkseagreen": [143, 188, 143],
  902. "darkslateblue": [72, 61, 139],
  903. "darkslategray": [47, 79, 79],
  904. "darkslategrey": [47, 79, 79],
  905. "darkturquoise": [0, 206, 209],
  906. "darkviolet": [148, 0, 211],
  907. "deeppink": [255, 20, 147],
  908. "deepskyblue": [0, 191, 255],
  909. "dimgray": [105, 105, 105],
  910. "dimgrey": [105, 105, 105],
  911. "dodgerblue": [30, 144, 255],
  912. "firebrick": [178, 34, 34],
  913. "floralwhite": [255, 250, 240],
  914. "forestgreen": [34, 139, 34],
  915. "fuchsia": [255, 0, 255],
  916. "gainsboro": [220, 220, 220],
  917. "ghostwhite": [248, 248, 255],
  918. "gold": [255, 215, 0],
  919. "goldenrod": [218, 165, 32],
  920. "gray": [128, 128, 128],
  921. "green": [0, 128, 0],
  922. "greenyellow": [173, 255, 47],
  923. "grey": [128, 128, 128],
  924. "honeydew": [240, 255, 240],
  925. "hotpink": [255, 105, 180],
  926. "indianred": [205, 92, 92],
  927. "indigo": [75, 0, 130],
  928. "ivory": [255, 255, 240],
  929. "khaki": [240, 230, 140],
  930. "lavender": [230, 230, 250],
  931. "lavenderblush": [255, 240, 245],
  932. "lawngreen": [124, 252, 0],
  933. "lemonchiffon": [255, 250, 205],
  934. "lightblue": [173, 216, 230],
  935. "lightcoral": [240, 128, 128],
  936. "lightcyan": [224, 255, 255],
  937. "lightgoldenrodyellow": [250, 250, 210],
  938. "lightgray": [211, 211, 211],
  939. "lightgreen": [144, 238, 144],
  940. "lightgrey": [211, 211, 211],
  941. "lightpink": [255, 182, 193],
  942. "lightsalmon": [255, 160, 122],
  943. "lightseagreen": [32, 178, 170],
  944. "lightskyblue": [135, 206, 250],
  945. "lightslategray": [119, 136, 153],
  946. "lightslategrey": [119, 136, 153],
  947. "lightsteelblue": [176, 196, 222],
  948. "lightyellow": [255, 255, 224],
  949. "lime": [0, 255, 0],
  950. "limegreen": [50, 205, 50],
  951. "linen": [250, 240, 230],
  952. "magenta": [255, 0, 255],
  953. "maroon": [128, 0, 0],
  954. "mediumaquamarine": [102, 205, 170],
  955. "mediumblue": [0, 0, 205],
  956. "mediumorchid": [186, 85, 211],
  957. "mediumpurple": [147, 112, 219],
  958. "mediumseagreen": [60, 179, 113],
  959. "mediumslateblue": [123, 104, 238],
  960. "mediumspringgreen": [0, 250, 154],
  961. "mediumturquoise": [72, 209, 204],
  962. "mediumvioletred": [199, 21, 133],
  963. "midnightblue": [25, 25, 112],
  964. "mintcream": [245, 255, 250],
  965. "mistyrose": [255, 228, 225],
  966. "moccasin": [255, 228, 181],
  967. "navajowhite": [255, 222, 173],
  968. "navy": [0, 0, 128],
  969. "oldlace": [253, 245, 230],
  970. "olive": [128, 128, 0],
  971. "olivedrab": [107, 142, 35],
  972. "orange": [255, 165, 0],
  973. "orangered": [255, 69, 0],
  974. "orchid": [218, 112, 214],
  975. "palegoldenrod": [238, 232, 170],
  976. "palegreen": [152, 251, 152],
  977. "paleturquoise": [175, 238, 238],
  978. "palevioletred": [219, 112, 147],
  979. "papayawhip": [255, 239, 213],
  980. "peachpuff": [255, 218, 185],
  981. "peru": [205, 133, 63],
  982. "pink": [255, 192, 203],
  983. "plum": [221, 160, 221],
  984. "powderblue": [176, 224, 230],
  985. "purple": [128, 0, 128],
  986. "rebeccapurple": [102, 51, 153],
  987. "red": [255, 0, 0],
  988. "rosybrown": [188, 143, 143],
  989. "royalblue": [65, 105, 225],
  990. "saddlebrown": [139, 69, 19],
  991. "salmon": [250, 128, 114],
  992. "sandybrown": [244, 164, 96],
  993. "seagreen": [46, 139, 87],
  994. "seashell": [255, 245, 238],
  995. "sienna": [160, 82, 45],
  996. "silver": [192, 192, 192],
  997. "skyblue": [135, 206, 235],
  998. "slateblue": [106, 90, 205],
  999. "slategray": [112, 128, 144],
  1000. "slategrey": [112, 128, 144],
  1001. "snow": [255, 250, 250],
  1002. "springgreen": [0, 255, 127],
  1003. "steelblue": [70, 130, 180],
  1004. "tan": [210, 180, 140],
  1005. "teal": [0, 128, 128],
  1006. "thistle": [216, 191, 216],
  1007. "tomato": [255, 99, 71],
  1008. "turquoise": [64, 224, 208],
  1009. "violet": [238, 130, 238],
  1010. "wheat": [245, 222, 179],
  1011. "white": [255, 255, 255],
  1012. "whitesmoke": [245, 245, 245],
  1013. "yellow": [255, 255, 0],
  1014. "yellowgreen": [154, 205, 50]
  1015. };
  1016. },{}],6:[function(require,module,exports){
  1017. /* MIT license */
  1018. var convert = require("color-convert"),
  1019. string = require("color-string");
  1020. var Color = function(obj) {
  1021. if (obj instanceof Color) return obj;
  1022. if (!(this instanceof Color)) return new Color(obj);
  1023. this.values = {
  1024. rgb: [0, 0, 0],
  1025. hsl: [0, 0, 0],
  1026. hsv: [0, 0, 0],
  1027. hwb: [0, 0, 0],
  1028. cmyk: [0, 0, 0, 0],
  1029. alpha: 1
  1030. }
  1031. // parse Color() argument
  1032. if (typeof obj == "string") {
  1033. var vals = string.getRgba(obj);
  1034. if (vals) {
  1035. this.setValues("rgb", vals);
  1036. } else if (vals = string.getHsla(obj)) {
  1037. this.setValues("hsl", vals);
  1038. } else if (vals = string.getHwb(obj)) {
  1039. this.setValues("hwb", vals);
  1040. } else {
  1041. throw new Error("Unable to parse color from string \"" + obj + "\"");
  1042. }
  1043. } else if (typeof obj == "object") {
  1044. var vals = obj;
  1045. if (vals["r"] !== undefined || vals["red"] !== undefined) {
  1046. this.setValues("rgb", vals)
  1047. } else if (vals["l"] !== undefined || vals["lightness"] !== undefined) {
  1048. this.setValues("hsl", vals)
  1049. } else if (vals["v"] !== undefined || vals["value"] !== undefined) {
  1050. this.setValues("hsv", vals)
  1051. } else if (vals["w"] !== undefined || vals["whiteness"] !== undefined) {
  1052. this.setValues("hwb", vals)
  1053. } else if (vals["c"] !== undefined || vals["cyan"] !== undefined) {
  1054. this.setValues("cmyk", vals)
  1055. } else {
  1056. throw new Error("Unable to parse color from object " + JSON.stringify(obj));
  1057. }
  1058. }
  1059. }
  1060. Color.prototype = {
  1061. rgb: function(vals) {
  1062. return this.setSpace("rgb", arguments);
  1063. },
  1064. hsl: function(vals) {
  1065. return this.setSpace("hsl", arguments);
  1066. },
  1067. hsv: function(vals) {
  1068. return this.setSpace("hsv", arguments);
  1069. },
  1070. hwb: function(vals) {
  1071. return this.setSpace("hwb", arguments);
  1072. },
  1073. cmyk: function(vals) {
  1074. return this.setSpace("cmyk", arguments);
  1075. },
  1076. rgbArray: function() {
  1077. return this.values.rgb;
  1078. },
  1079. hslArray: function() {
  1080. return this.values.hsl;
  1081. },
  1082. hsvArray: function() {
  1083. return this.values.hsv;
  1084. },
  1085. hwbArray: function() {
  1086. if (this.values.alpha !== 1) {
  1087. return this.values.hwb.concat([this.values.alpha])
  1088. }
  1089. return this.values.hwb;
  1090. },
  1091. cmykArray: function() {
  1092. return this.values.cmyk;
  1093. },
  1094. rgbaArray: function() {
  1095. var rgb = this.values.rgb;
  1096. return rgb.concat([this.values.alpha]);
  1097. },
  1098. hslaArray: function() {
  1099. var hsl = this.values.hsl;
  1100. return hsl.concat([this.values.alpha]);
  1101. },
  1102. alpha: function(val) {
  1103. if (val === undefined) {
  1104. return this.values.alpha;
  1105. }
  1106. this.setValues("alpha", val);
  1107. return this;
  1108. },
  1109. red: function(val) {
  1110. return this.setChannel("rgb", 0, val);
  1111. },
  1112. green: function(val) {
  1113. return this.setChannel("rgb", 1, val);
  1114. },
  1115. blue: function(val) {
  1116. return this.setChannel("rgb", 2, val);
  1117. },
  1118. hue: function(val) {
  1119. return this.setChannel("hsl", 0, val);
  1120. },
  1121. saturation: function(val) {
  1122. return this.setChannel("hsl", 1, val);
  1123. },
  1124. lightness: function(val) {
  1125. return this.setChannel("hsl", 2, val);
  1126. },
  1127. saturationv: function(val) {
  1128. return this.setChannel("hsv", 1, val);
  1129. },
  1130. whiteness: function(val) {
  1131. return this.setChannel("hwb", 1, val);
  1132. },
  1133. blackness: function(val) {
  1134. return this.setChannel("hwb", 2, val);
  1135. },
  1136. value: function(val) {
  1137. return this.setChannel("hsv", 2, val);
  1138. },
  1139. cyan: function(val) {
  1140. return this.setChannel("cmyk", 0, val);
  1141. },
  1142. magenta: function(val) {
  1143. return this.setChannel("cmyk", 1, val);
  1144. },
  1145. yellow: function(val) {
  1146. return this.setChannel("cmyk", 2, val);
  1147. },
  1148. black: function(val) {
  1149. return this.setChannel("cmyk", 3, val);
  1150. },
  1151. hexString: function() {
  1152. return string.hexString(this.values.rgb);
  1153. },
  1154. rgbString: function() {
  1155. return string.rgbString(this.values.rgb, this.values.alpha);
  1156. },
  1157. rgbaString: function() {
  1158. return string.rgbaString(this.values.rgb, this.values.alpha);
  1159. },
  1160. percentString: function() {
  1161. return string.percentString(this.values.rgb, this.values.alpha);
  1162. },
  1163. hslString: function() {
  1164. return string.hslString(this.values.hsl, this.values.alpha);
  1165. },
  1166. hslaString: function() {
  1167. return string.hslaString(this.values.hsl, this.values.alpha);
  1168. },
  1169. hwbString: function() {
  1170. return string.hwbString(this.values.hwb, this.values.alpha);
  1171. },
  1172. keyword: function() {
  1173. return string.keyword(this.values.rgb, this.values.alpha);
  1174. },
  1175. rgbNumber: function() {
  1176. return (this.values.rgb[0] << 16) | (this.values.rgb[1] << 8) | this.values.rgb[2];
  1177. },
  1178. luminosity: function() {
  1179. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  1180. var rgb = this.values.rgb;
  1181. var lum = [];
  1182. for (var i = 0; i < rgb.length; i++) {
  1183. var chan = rgb[i] / 255;
  1184. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4)
  1185. }
  1186. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  1187. },
  1188. contrast: function(color2) {
  1189. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  1190. var lum1 = this.luminosity();
  1191. var lum2 = color2.luminosity();
  1192. if (lum1 > lum2) {
  1193. return (lum1 + 0.05) / (lum2 + 0.05)
  1194. };
  1195. return (lum2 + 0.05) / (lum1 + 0.05);
  1196. },
  1197. level: function(color2) {
  1198. var contrastRatio = this.contrast(color2);
  1199. return (contrastRatio >= 7.1) ? 'AAA' : (contrastRatio >= 4.5) ? 'AA' : '';
  1200. },
  1201. dark: function() {
  1202. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  1203. var rgb = this.values.rgb,
  1204. yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  1205. return yiq < 128;
  1206. },
  1207. light: function() {
  1208. return !this.dark();
  1209. },
  1210. negate: function() {
  1211. var rgb = []
  1212. for (var i = 0; i < 3; i++) {
  1213. rgb[i] = 255 - this.values.rgb[i];
  1214. }
  1215. this.setValues("rgb", rgb);
  1216. return this;
  1217. },
  1218. lighten: function(ratio) {
  1219. this.values.hsl[2] += this.values.hsl[2] * ratio;
  1220. this.setValues("hsl", this.values.hsl);
  1221. return this;
  1222. },
  1223. darken: function(ratio) {
  1224. this.values.hsl[2] -= this.values.hsl[2] * ratio;
  1225. this.setValues("hsl", this.values.hsl);
  1226. return this;
  1227. },
  1228. saturate: function(ratio) {
  1229. this.values.hsl[1] += this.values.hsl[1] * ratio;
  1230. this.setValues("hsl", this.values.hsl);
  1231. return this;
  1232. },
  1233. desaturate: function(ratio) {
  1234. this.values.hsl[1] -= this.values.hsl[1] * ratio;
  1235. this.setValues("hsl", this.values.hsl);
  1236. return this;
  1237. },
  1238. whiten: function(ratio) {
  1239. this.values.hwb[1] += this.values.hwb[1] * ratio;
  1240. this.setValues("hwb", this.values.hwb);
  1241. return this;
  1242. },
  1243. blacken: function(ratio) {
  1244. this.values.hwb[2] += this.values.hwb[2] * ratio;
  1245. this.setValues("hwb", this.values.hwb);
  1246. return this;
  1247. },
  1248. greyscale: function() {
  1249. var rgb = this.values.rgb;
  1250. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  1251. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  1252. this.setValues("rgb", [val, val, val]);
  1253. return this;
  1254. },
  1255. clearer: function(ratio) {
  1256. this.setValues("alpha", this.values.alpha - (this.values.alpha * ratio));
  1257. return this;
  1258. },
  1259. opaquer: function(ratio) {
  1260. this.setValues("alpha", this.values.alpha + (this.values.alpha * ratio));
  1261. return this;
  1262. },
  1263. rotate: function(degrees) {
  1264. var hue = this.values.hsl[0];
  1265. hue = (hue + degrees) % 360;
  1266. hue = hue < 0 ? 360 + hue : hue;
  1267. this.values.hsl[0] = hue;
  1268. this.setValues("hsl", this.values.hsl);
  1269. return this;
  1270. },
  1271. mix: function(color2, weight) {
  1272. weight = 1 - (weight == null ? 0.5 : weight);
  1273. // algorithm from Sass's mix(). Ratio of first color in mix is
  1274. // determined by the alphas of both colors and the weight
  1275. var t1 = weight * 2 - 1,
  1276. d = this.alpha() - color2.alpha();
  1277. var weight1 = (((t1 * d == -1) ? t1 : (t1 + d) / (1 + t1 * d)) + 1) / 2;
  1278. var weight2 = 1 - weight1;
  1279. var rgb = this.rgbArray();
  1280. var rgb2 = color2.rgbArray();
  1281. for (var i = 0; i < rgb.length; i++) {
  1282. rgb[i] = rgb[i] * weight1 + rgb2[i] * weight2;
  1283. }
  1284. this.setValues("rgb", rgb);
  1285. var alpha = this.alpha() * weight + color2.alpha() * (1 - weight);
  1286. this.setValues("alpha", alpha);
  1287. return this;
  1288. },
  1289. toJSON: function() {
  1290. return this.rgb();
  1291. },
  1292. clone: function() {
  1293. return new Color(this.rgb());
  1294. }
  1295. }
  1296. Color.prototype.getValues = function(space) {
  1297. var vals = {};
  1298. for (var i = 0; i < space.length; i++) {
  1299. vals[space.charAt(i)] = this.values[space][i];
  1300. }
  1301. if (this.values.alpha != 1) {
  1302. vals["a"] = this.values.alpha;
  1303. }
  1304. // {r: 255, g: 255, b: 255, a: 0.4}
  1305. return vals;
  1306. }
  1307. Color.prototype.setValues = function(space, vals) {
  1308. var spaces = {
  1309. "rgb": ["red", "green", "blue"],
  1310. "hsl": ["hue", "saturation", "lightness"],
  1311. "hsv": ["hue", "saturation", "value"],
  1312. "hwb": ["hue", "whiteness", "blackness"],
  1313. "cmyk": ["cyan", "magenta", "yellow", "black"]
  1314. };
  1315. var maxes = {
  1316. "rgb": [255, 255, 255],
  1317. "hsl": [360, 100, 100],
  1318. "hsv": [360, 100, 100],
  1319. "hwb": [360, 100, 100],
  1320. "cmyk": [100, 100, 100, 100]
  1321. };
  1322. var alpha = 1;
  1323. if (space == "alpha") {
  1324. alpha = vals;
  1325. } else if (vals.length) {
  1326. // [10, 10, 10]
  1327. this.values[space] = vals.slice(0, space.length);
  1328. alpha = vals[space.length];
  1329. } else if (vals[space.charAt(0)] !== undefined) {
  1330. // {r: 10, g: 10, b: 10}
  1331. for (var i = 0; i < space.length; i++) {
  1332. this.values[space][i] = vals[space.charAt(i)];
  1333. }
  1334. alpha = vals.a;
  1335. } else if (vals[spaces[space][0]] !== undefined) {
  1336. // {red: 10, green: 10, blue: 10}
  1337. var chans = spaces[space];
  1338. for (var i = 0; i < space.length; i++) {
  1339. this.values[space][i] = vals[chans[i]];
  1340. }
  1341. alpha = vals.alpha;
  1342. }
  1343. this.values.alpha = Math.max(0, Math.min(1, (alpha !== undefined ? alpha : this.values.alpha)));
  1344. if (space == "alpha") {
  1345. return;
  1346. }
  1347. // cap values of the space prior converting all values
  1348. for (var i = 0; i < space.length; i++) {
  1349. var capped = Math.max(0, Math.min(maxes[space][i], this.values[space][i]));
  1350. this.values[space][i] = Math.round(capped);
  1351. }
  1352. // convert to all the other color spaces
  1353. for (var sname in spaces) {
  1354. if (sname != space) {
  1355. this.values[sname] = convert[space][sname](this.values[space])
  1356. }
  1357. // cap values
  1358. for (var i = 0; i < sname.length; i++) {
  1359. var capped = Math.max(0, Math.min(maxes[sname][i], this.values[sname][i]));
  1360. this.values[sname][i] = Math.round(capped);
  1361. }
  1362. }
  1363. return true;
  1364. }
  1365. Color.prototype.setSpace = function(space, args) {
  1366. var vals = args[0];
  1367. if (vals === undefined) {
  1368. // color.rgb()
  1369. return this.getValues(space);
  1370. }
  1371. // color.rgb(10, 10, 10)
  1372. if (typeof vals == "number") {
  1373. vals = Array.prototype.slice.call(args);
  1374. }
  1375. this.setValues(space, vals);
  1376. return this;
  1377. }
  1378. Color.prototype.setChannel = function(space, index, val) {
  1379. if (val === undefined) {
  1380. // color.red()
  1381. return this.values[space][index];
  1382. }
  1383. // color.red(100)
  1384. this.values[space][index] = val;
  1385. this.setValues(space, this.values[space]);
  1386. return this;
  1387. }
  1388. window.Color = module.exports = Color
  1389. },{"color-convert":3,"color-string":4}],7:[function(require,module,exports){
  1390. /*!
  1391. * Chart.js
  1392. * http://chartjs.org/
  1393. * Version: 2.0.2
  1394. *
  1395. * Copyright 2015 Nick Downie
  1396. * Released under the MIT license
  1397. * https://github.com/nnnick/Chart.js/blob/master/LICENSE.md
  1398. */
  1399. var Chart = require('./core/core.js')();
  1400. require('./core/core.helpers')(Chart);
  1401. require('./core/core.element')(Chart);
  1402. require('./core/core.animation')(Chart);
  1403. require('./core/core.controller')(Chart);
  1404. require('./core/core.datasetController')(Chart);
  1405. require('./core/core.layoutService')(Chart);
  1406. require('./core/core.legend')(Chart);
  1407. require('./core/core.scale')(Chart);
  1408. require('./core/core.scaleService')(Chart);
  1409. require('./core/core.title')(Chart);
  1410. require('./core/core.tooltip')(Chart);
  1411. require('./controllers/controller.bar')(Chart);
  1412. require('./controllers/controller.bubble')(Chart);
  1413. require('./controllers/controller.doughnut')(Chart);
  1414. require('./controllers/controller.line')(Chart);
  1415. require('./controllers/controller.polarArea')(Chart);
  1416. require('./controllers/controller.radar')(Chart);
  1417. require('./scales/scale.category')(Chart);
  1418. require('./scales/scale.linear')(Chart);
  1419. require('./scales/scale.logarithmic')(Chart);
  1420. require('./scales/scale.radialLinear')(Chart);
  1421. require('./scales/scale.time')(Chart);
  1422. require('./elements/element.arc')(Chart);
  1423. require('./elements/element.line')(Chart);
  1424. require('./elements/element.point')(Chart);
  1425. require('./elements/element.rectangle')(Chart);
  1426. require('./charts/Chart.Bar')(Chart);
  1427. require('./charts/Chart.Bubble')(Chart);
  1428. require('./charts/Chart.Doughnut')(Chart);
  1429. require('./charts/Chart.Line')(Chart);
  1430. require('./charts/Chart.PolarArea')(Chart);
  1431. require('./charts/Chart.Radar')(Chart);
  1432. require('./charts/Chart.Scatter')(Chart);
  1433. window.Chart = module.exports = Chart;
  1434. },{"./charts/Chart.Bar":8,"./charts/Chart.Bubble":9,"./charts/Chart.Doughnut":10,"./charts/Chart.Line":11,"./charts/Chart.PolarArea":12,"./charts/Chart.Radar":13,"./charts/Chart.Scatter":14,"./controllers/controller.bar":15,"./controllers/controller.bubble":16,"./controllers/controller.doughnut":17,"./controllers/controller.line":18,"./controllers/controller.polarArea":19,"./controllers/controller.radar":20,"./core/core.animation":21,"./core/core.controller":22,"./core/core.datasetController":23,"./core/core.element":24,"./core/core.helpers":25,"./core/core.js":26,"./core/core.layoutService":27,"./core/core.legend":28,"./core/core.scale":29,"./core/core.scaleService":30,"./core/core.title":31,"./core/core.tooltip":32,"./elements/element.arc":33,"./elements/element.line":34,"./elements/element.point":35,"./elements/element.rectangle":36,"./scales/scale.category":37,"./scales/scale.linear":38,"./scales/scale.logarithmic":39,"./scales/scale.radialLinear":40,"./scales/scale.time":41}],8:[function(require,module,exports){
  1435. "use strict";
  1436. module.exports = function(Chart) {
  1437. Chart.Bar = function(context, config) {
  1438. config.type = 'bar';
  1439. return new Chart(context, config);
  1440. };
  1441. };
  1442. },{}],9:[function(require,module,exports){
  1443. "use strict";
  1444. module.exports = function(Chart) {
  1445. Chart.Bubble = function(context, config) {
  1446. config.type = 'bubble';
  1447. return new Chart(context, config);
  1448. };
  1449. };
  1450. },{}],10:[function(require,module,exports){
  1451. "use strict";
  1452. module.exports = function(Chart) {
  1453. Chart.Doughnut = function(context, config) {
  1454. config.type = 'doughnut';
  1455. return new Chart(context, config);
  1456. };
  1457. };
  1458. },{}],11:[function(require,module,exports){
  1459. "use strict";
  1460. module.exports = function(Chart) {
  1461. Chart.Line = function(context, config) {
  1462. config.type = 'line';
  1463. return new Chart(context, config);
  1464. };
  1465. };
  1466. },{}],12:[function(require,module,exports){
  1467. "use strict";
  1468. module.exports = function(Chart) {
  1469. Chart.PolarArea = function(context, config) {
  1470. config.type = 'polarArea';
  1471. return new Chart(context, config);
  1472. };
  1473. };
  1474. },{}],13:[function(require,module,exports){
  1475. "use strict";
  1476. module.exports = function(Chart) {
  1477. var helpers = Chart.helpers;
  1478. var defaultConfig = {
  1479. aspectRatio: 1
  1480. };
  1481. Chart.Radar = function(context, config) {
  1482. config.options = helpers.configMerge(defaultConfig, config.options);
  1483. config.type = 'radar';
  1484. return new Chart(context, config);
  1485. };
  1486. };
  1487. },{}],14:[function(require,module,exports){
  1488. "use strict";
  1489. module.exports = function(Chart) {
  1490. var defaultConfig = {
  1491. hover: {
  1492. mode: 'single'
  1493. },
  1494. scales: {
  1495. xAxes: [{
  1496. type: "linear", // scatter should not use a category axis
  1497. position: "bottom",
  1498. id: "x-axis-1" // need an ID so datasets can reference the scale
  1499. }],
  1500. yAxes: [{
  1501. type: "linear",
  1502. position: "left",
  1503. id: "y-axis-1"
  1504. }]
  1505. },
  1506. tooltips: {
  1507. callbacks: {
  1508. title: function(tooltipItems, data) {
  1509. // Title doesn't make sense for scatter since we format the data as a point
  1510. return '';
  1511. },
  1512. label: function(tooltipItem, data) {
  1513. return '(' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ')';
  1514. }
  1515. }
  1516. }
  1517. };
  1518. // Register the default config for this type
  1519. Chart.defaults.scatter = defaultConfig;
  1520. // Scatter charts use line controllers
  1521. Chart.controllers.scatter = Chart.controllers.line;
  1522. Chart.Scatter = function(context, config) {
  1523. config.type = 'scatter';
  1524. return new Chart(context, config);
  1525. };
  1526. };
  1527. },{}],15:[function(require,module,exports){
  1528. "use strict";
  1529. module.exports = function(Chart) {
  1530. var helpers = Chart.helpers;
  1531. Chart.defaults.bar = {
  1532. hover: {
  1533. mode: "label"
  1534. },
  1535. scales: {
  1536. xAxes: [{
  1537. type: "category",
  1538. // Specific to Bar Controller
  1539. categoryPercentage: 0.8,
  1540. barPercentage: 0.9,
  1541. // grid line settings
  1542. gridLines: {
  1543. offsetGridLines: true
  1544. }
  1545. }],
  1546. yAxes: [{
  1547. type: "linear"
  1548. }]
  1549. }
  1550. };
  1551. Chart.controllers.bar = Chart.DatasetController.extend({
  1552. initialize: function(chart, datasetIndex) {
  1553. Chart.DatasetController.prototype.initialize.call(this, chart, datasetIndex);
  1554. // Use this to indicate that this is a bar dataset.
  1555. this.getDataset().bar = true;
  1556. },
  1557. // Get the number of datasets that display bars. We use this to correctly calculate the bar width
  1558. getBarCount: function getBarCount() {
  1559. var barCount = 0;
  1560. helpers.each(this.chart.data.datasets, function(dataset) {
  1561. if (helpers.isDatasetVisible(dataset) && dataset.bar) {
  1562. ++barCount;
  1563. }
  1564. });
  1565. return barCount;
  1566. },
  1567. addElements: function() {
  1568. this.getDataset().metaData = this.getDataset().metaData || [];
  1569. helpers.each(this.getDataset().data, function(value, index) {
  1570. this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Rectangle({
  1571. _chart: this.chart.chart,
  1572. _datasetIndex: this.index,
  1573. _index: index
  1574. });
  1575. }, this);
  1576. },
  1577. addElementAndReset: function(index) {
  1578. this.getDataset().metaData = this.getDataset().metaData || [];
  1579. var rectangle = new Chart.elements.Rectangle({
  1580. _chart: this.chart.chart,
  1581. _datasetIndex: this.index,
  1582. _index: index
  1583. });
  1584. var numBars = this.getBarCount();
  1585. this.updateElement(rectangle, index, true, numBars);
  1586. this.getDataset().metaData.splice(index, 0, rectangle);
  1587. },
  1588. update: function update(reset) {
  1589. var numBars = this.getBarCount();
  1590. helpers.each(this.getDataset().metaData, function(rectangle, index) {
  1591. this.updateElement(rectangle, index, reset, numBars);
  1592. }, this);
  1593. },
  1594. updateElement: function updateElement(rectangle, index, reset, numBars) {
  1595. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1596. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1597. var yScalePoint;
  1598. if (yScale.min < 0 && yScale.max < 0) {
  1599. // all less than 0. use the top
  1600. yScalePoint = yScale.getPixelForValue(yScale.max);
  1601. } else if (yScale.min > 0 && yScale.max > 0) {
  1602. yScalePoint = yScale.getPixelForValue(yScale.min);
  1603. } else {
  1604. yScalePoint = yScale.getPixelForValue(0);
  1605. }
  1606. helpers.extend(rectangle, {
  1607. // Utility
  1608. _chart: this.chart.chart,
  1609. _xScale: xScale,
  1610. _yScale: yScale,
  1611. _datasetIndex: this.index,
  1612. _index: index,
  1613. // Desired view properties
  1614. _model: {
  1615. x: this.calculateBarX(index, this.index),
  1616. y: reset ? yScalePoint : this.calculateBarY(index, this.index),
  1617. // Tooltip
  1618. label: this.chart.data.labels[index],
  1619. datasetLabel: this.getDataset().label,
  1620. // Appearance
  1621. base: reset ? yScalePoint : this.calculateBarBase(this.index, index),
  1622. width: this.calculateBarWidth(numBars),
  1623. backgroundColor: rectangle.custom && rectangle.custom.backgroundColor ? rectangle.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.rectangle.backgroundColor),
  1624. borderSkipped: rectangle.custom && rectangle.custom.borderSkipped ? rectangle.custom.borderSkipped : this.chart.options.elements.rectangle.borderSkipped,
  1625. borderColor: rectangle.custom && rectangle.custom.borderColor ? rectangle.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.rectangle.borderColor),
  1626. borderWidth: rectangle.custom && rectangle.custom.borderWidth ? rectangle.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.rectangle.borderWidth)
  1627. }
  1628. });
  1629. rectangle.pivot();
  1630. },
  1631. calculateBarBase: function(datasetIndex, index) {
  1632. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1633. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1634. var base = 0;
  1635. if (yScale.options.stacked) {
  1636. var value = this.chart.data.datasets[datasetIndex].data[index];
  1637. if (value < 0) {
  1638. for (var i = 0; i < datasetIndex; i++) {
  1639. var negDS = this.chart.data.datasets[i];
  1640. if (helpers.isDatasetVisible(negDS) && negDS.yAxisID === yScale.id && negDS.bar) {
  1641. base += negDS.data[index] < 0 ? negDS.data[index] : 0;
  1642. }
  1643. }
  1644. } else {
  1645. for (var j = 0; j < datasetIndex; j++) {
  1646. var posDS = this.chart.data.datasets[j];
  1647. if (helpers.isDatasetVisible(posDS) && posDS.yAxisID === yScale.id && posDS.bar) {
  1648. base += posDS.data[index] > 0 ? posDS.data[index] : 0;
  1649. }
  1650. }
  1651. }
  1652. return yScale.getPixelForValue(base);
  1653. }
  1654. base = yScale.getPixelForValue(yScale.min);
  1655. if (yScale.beginAtZero || ((yScale.min <= 0 && yScale.max >= 0) || (yScale.min >= 0 && yScale.max <= 0))) {
  1656. base = yScale.getPixelForValue(0, 0);
  1657. //base += yScale.options.gridLines.lineWidth;
  1658. } else if (yScale.min < 0 && yScale.max < 0) {
  1659. // All values are negative. Use the top as the base
  1660. base = yScale.getPixelForValue(yScale.max);
  1661. }
  1662. return base;
  1663. },
  1664. getRuler: function() {
  1665. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1666. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1667. var datasetCount = this.getBarCount();
  1668. var tickWidth = (function() {
  1669. var min = xScale.getPixelForTick(1) - xScale.getPixelForTick(0);
  1670. for (var i = 2; i < this.getDataset().data.length; i++) {
  1671. min = Math.min(xScale.getPixelForTick(i) - xScale.getPixelForTick(i - 1), min);
  1672. }
  1673. return min;
  1674. }).call(this);
  1675. var categoryWidth = tickWidth * xScale.options.categoryPercentage;
  1676. var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2;
  1677. var fullBarWidth = categoryWidth / datasetCount;
  1678. var barWidth = fullBarWidth * xScale.options.barPercentage;
  1679. var barSpacing = fullBarWidth - (fullBarWidth * xScale.options.barPercentage);
  1680. return {
  1681. datasetCount: datasetCount,
  1682. tickWidth: tickWidth,
  1683. categoryWidth: categoryWidth,
  1684. categorySpacing: categorySpacing,
  1685. fullBarWidth: fullBarWidth,
  1686. barWidth: barWidth,
  1687. barSpacing: barSpacing
  1688. };
  1689. },
  1690. calculateBarWidth: function() {
  1691. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1692. var ruler = this.getRuler();
  1693. return xScale.options.stacked ? ruler.categoryWidth : ruler.barWidth;
  1694. },
  1695. // Get bar index from the given dataset index accounting for the fact that not all bars are visible
  1696. getBarIndex: function(datasetIndex) {
  1697. var barIndex = 0;
  1698. for (var j = 0; j < datasetIndex; ++j) {
  1699. if (helpers.isDatasetVisible(this.chart.data.datasets[j]) && this.chart.data.datasets[j].bar) {
  1700. ++barIndex;
  1701. }
  1702. }
  1703. return barIndex;
  1704. },
  1705. calculateBarX: function(index, datasetIndex) {
  1706. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1707. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1708. var barIndex = this.getBarIndex(datasetIndex);
  1709. var ruler = this.getRuler();
  1710. var leftTick = xScale.getPixelForValue(null, index, datasetIndex, this.chart.isCombo);
  1711. leftTick -= this.chart.isCombo ? (ruler.tickWidth / 2) : 0;
  1712. if (xScale.options.stacked) {
  1713. return leftTick + (ruler.categoryWidth / 2) + ruler.categorySpacing;
  1714. }
  1715. return leftTick +
  1716. (ruler.barWidth / 2) +
  1717. ruler.categorySpacing +
  1718. (ruler.barWidth * barIndex) +
  1719. (ruler.barSpacing / 2) +
  1720. (ruler.barSpacing * barIndex);
  1721. },
  1722. calculateBarY: function(index, datasetIndex) {
  1723. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1724. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1725. var value = this.getDataset().data[index];
  1726. if (yScale.options.stacked) {
  1727. var sumPos = 0,
  1728. sumNeg = 0;
  1729. for (var i = 0; i < datasetIndex; i++) {
  1730. var ds = this.chart.data.datasets[i];
  1731. if (helpers.isDatasetVisible(ds) && ds.bar && ds.yAxisID === yScale.id) {
  1732. if (ds.data[index] < 0) {
  1733. sumNeg += ds.data[index] || 0;
  1734. } else {
  1735. sumPos += ds.data[index] || 0;
  1736. }
  1737. }
  1738. }
  1739. if (value < 0) {
  1740. return yScale.getPixelForValue(sumNeg + value);
  1741. } else {
  1742. return yScale.getPixelForValue(sumPos + value);
  1743. }
  1744. return yScale.getPixelForValue(value);
  1745. }
  1746. return yScale.getPixelForValue(value);
  1747. },
  1748. draw: function(ease) {
  1749. var easingDecimal = ease || 1;
  1750. helpers.each(this.getDataset().metaData, function(rectangle, index) {
  1751. var d = this.getDataset().data[index];
  1752. if (d !== null && d !== undefined && !isNaN(d)) {
  1753. rectangle.transition(easingDecimal).draw();
  1754. }
  1755. }, this);
  1756. },
  1757. setHoverStyle: function(rectangle) {
  1758. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1759. var index = rectangle._index;
  1760. rectangle._model.backgroundColor = rectangle.custom && rectangle.custom.hoverBackgroundColor ? rectangle.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(rectangle._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
  1761. rectangle._model.borderColor = rectangle.custom && rectangle.custom.hoverBorderColor ? rectangle.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(rectangle._model.borderColor).saturate(0.5).darken(0.1).rgbString());
  1762. rectangle._model.borderWidth = rectangle.custom && rectangle.custom.hoverBorderWidth ? rectangle.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, rectangle._model.borderWidth);
  1763. },
  1764. removeHoverStyle: function(rectangle) {
  1765. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1766. var index = rectangle._index;
  1767. rectangle._model.backgroundColor = rectangle.custom && rectangle.custom.backgroundColor ? rectangle.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.rectangle.backgroundColor);
  1768. rectangle._model.borderColor = rectangle.custom && rectangle.custom.borderColor ? rectangle.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.rectangle.borderColor);
  1769. rectangle._model.borderWidth = rectangle.custom && rectangle.custom.borderWidth ? rectangle.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.rectangle.borderWidth);
  1770. }
  1771. });
  1772. };
  1773. },{}],16:[function(require,module,exports){
  1774. "use strict";
  1775. module.exports = function(Chart) {
  1776. var helpers = Chart.helpers;
  1777. Chart.defaults.bubble = {
  1778. hover: {
  1779. mode: "single"
  1780. },
  1781. scales: {
  1782. xAxes: [{
  1783. type: "linear", // bubble should probably use a linear scale by default
  1784. position: "bottom",
  1785. id: "x-axis-0" // need an ID so datasets can reference the scale
  1786. }],
  1787. yAxes: [{
  1788. type: "linear",
  1789. position: "left",
  1790. id: "y-axis-0"
  1791. }]
  1792. },
  1793. tooltips: {
  1794. callbacks: {
  1795. title: function(tooltipItems, data) {
  1796. // Title doesn't make sense for scatter since we format the data as a point
  1797. return '';
  1798. },
  1799. label: function(tooltipItem, data) {
  1800. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  1801. var dataPoint = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  1802. return datasetLabel + ': (' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.r + ')';
  1803. }
  1804. }
  1805. }
  1806. };
  1807. Chart.controllers.bubble = Chart.DatasetController.extend({
  1808. addElements: function() {
  1809. this.getDataset().metaData = this.getDataset().metaData || [];
  1810. helpers.each(this.getDataset().data, function(value, index) {
  1811. this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Point({
  1812. _chart: this.chart.chart,
  1813. _datasetIndex: this.index,
  1814. _index: index
  1815. });
  1816. }, this);
  1817. },
  1818. addElementAndReset: function(index) {
  1819. this.getDataset().metaData = this.getDataset().metaData || [];
  1820. var point = new Chart.elements.Point({
  1821. _chart: this.chart.chart,
  1822. _datasetIndex: this.index,
  1823. _index: index
  1824. });
  1825. // Reset the point
  1826. this.updateElement(point, index, true);
  1827. // Add to the points array
  1828. this.getDataset().metaData.splice(index, 0, point);
  1829. },
  1830. update: function update(reset) {
  1831. var points = this.getDataset().metaData;
  1832. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1833. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1834. var scaleBase;
  1835. if (yScale.min < 0 && yScale.max < 0) {
  1836. scaleBase = yScale.getPixelForValue(yScale.max);
  1837. } else if (yScale.min > 0 && yScale.max > 0) {
  1838. scaleBase = yScale.getPixelForValue(yScale.min);
  1839. } else {
  1840. scaleBase = yScale.getPixelForValue(0);
  1841. }
  1842. // Update Points
  1843. helpers.each(points, function(point, index) {
  1844. this.updateElement(point, index, reset);
  1845. }, this);
  1846. },
  1847. updateElement: function(point, index, reset) {
  1848. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  1849. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  1850. var scaleBase;
  1851. if (yScale.min < 0 && yScale.max < 0) {
  1852. scaleBase = yScale.getPixelForValue(yScale.max);
  1853. } else if (yScale.min > 0 && yScale.max > 0) {
  1854. scaleBase = yScale.getPixelForValue(yScale.min);
  1855. } else {
  1856. scaleBase = yScale.getPixelForValue(0);
  1857. }
  1858. helpers.extend(point, {
  1859. // Utility
  1860. _chart: this.chart.chart,
  1861. _xScale: xScale,
  1862. _yScale: yScale,
  1863. _datasetIndex: this.index,
  1864. _index: index,
  1865. // Desired view properties
  1866. _model: {
  1867. x: reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(this.getDataset().data[index], index, this.index, this.chart.isCombo),
  1868. y: reset ? scaleBase : yScale.getPixelForValue(this.getDataset().data[index], index, this.index),
  1869. // Appearance
  1870. radius: reset ? 0 : point.custom && point.custom.radius ? point.custom.radius : this.getRadius(this.getDataset().data[index]),
  1871. backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.point.backgroundColor),
  1872. borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.point.borderColor),
  1873. borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.point.borderWidth),
  1874. // Tooltip
  1875. hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().hitRadius, index, this.chart.options.elements.point.hitRadius)
  1876. }
  1877. });
  1878. point._model.skip = point.custom && point.custom.skip ? point.custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  1879. point.pivot();
  1880. },
  1881. getRadius: function(value) {
  1882. return value.r || this.chart.options.elements.point.radius;
  1883. },
  1884. draw: function(ease) {
  1885. var easingDecimal = ease || 1;
  1886. // Transition and Draw the Points
  1887. helpers.each(this.getDataset().metaData, function(point, index) {
  1888. point.transition(easingDecimal);
  1889. point.draw();
  1890. });
  1891. },
  1892. setHoverStyle: function(point) {
  1893. // Point
  1894. var dataset = this.chart.data.datasets[point._datasetIndex];
  1895. var index = point._index;
  1896. point._model.radius = point.custom && point.custom.hoverRadius ? point.custom.hoverRadius : (helpers.getValueAtIndexOrDefault(dataset.hoverRadius, index, this.chart.options.elements.point.hoverRadius)) + this.getRadius(this.getDataset().data[point._index]);
  1897. point._model.backgroundColor = point.custom && point.custom.hoverBackgroundColor ? point.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(point._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
  1898. point._model.borderColor = point.custom && point.custom.hoverBorderColor ? point.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(point._model.borderColor).saturate(0.5).darken(0.1).rgbString());
  1899. point._model.borderWidth = point.custom && point.custom.hoverBorderWidth ? point.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, point._model.borderWidth);
  1900. },
  1901. removeHoverStyle: function(point) {
  1902. var dataset = this.chart.data.datasets[point._datasetIndex];
  1903. var index = point._index;
  1904. point._model.radius = point.custom && point.custom.radius ? point.custom.radius : this.getRadius(this.getDataset().data[point._index]);
  1905. point._model.backgroundColor = point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.point.backgroundColor);
  1906. point._model.borderColor = point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.point.borderColor);
  1907. point._model.borderWidth = point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.point.borderWidth);
  1908. }
  1909. });
  1910. };
  1911. },{}],17:[function(require,module,exports){
  1912. "use strict";
  1913. module.exports = function(Chart) {
  1914. var helpers = Chart.helpers;
  1915. Chart.defaults.doughnut = {
  1916. animation: {
  1917. //Boolean - Whether we animate the rotation of the Doughnut
  1918. animateRotate: true,
  1919. //Boolean - Whether we animate scaling the Doughnut from the centre
  1920. animateScale: false
  1921. },
  1922. aspectRatio: 1,
  1923. hover: {
  1924. mode: 'single'
  1925. },
  1926. legendCallback: function(chart) {
  1927. var text = [];
  1928. text.push('<ul class="' + chart.id + '-legend">');
  1929. if (chart.data.datasets.length) {
  1930. for (var i = 0; i < chart.data.datasets[0].data.length; ++i) {
  1931. text.push('<li><span style="background-color:' + chart.data.datasets[0].backgroundColor[i] + '">');
  1932. if (chart.data.labels[i]) {
  1933. text.push(chart.data.labels[i]);
  1934. }
  1935. text.push('</span></li>');
  1936. }
  1937. }
  1938. text.push('</ul>');
  1939. return text.join("");
  1940. },
  1941. legend: {
  1942. labels: {
  1943. generateLabels: function(data) {
  1944. if (data.labels.length && data.datasets.length) {
  1945. return data.labels.map(function(label, i) {
  1946. return {
  1947. text: label,
  1948. fillStyle: data.datasets[0].backgroundColor[i],
  1949. hidden: isNaN(data.datasets[0].data[i]),
  1950. // Extra data used for toggling the correct item
  1951. index: i
  1952. };
  1953. });
  1954. } else {
  1955. return [];
  1956. }
  1957. }
  1958. },
  1959. onClick: function(e, legendItem) {
  1960. helpers.each(this.chart.data.datasets, function(dataset) {
  1961. dataset.metaHiddenData = dataset.metaHiddenData || [];
  1962. var idx = legendItem.index;
  1963. if (!isNaN(dataset.data[idx])) {
  1964. dataset.metaHiddenData[idx] = dataset.data[idx];
  1965. dataset.data[idx] = NaN;
  1966. } else if (!isNaN(dataset.metaHiddenData[idx])) {
  1967. dataset.data[idx] = dataset.metaHiddenData[idx];
  1968. }
  1969. });
  1970. this.chart.update();
  1971. }
  1972. },
  1973. //The percentage of the chart that we cut out of the middle.
  1974. cutoutPercentage: 50,
  1975. //The rotation of the chart, where the first data arc begins.
  1976. rotation: Math.PI * -0.5,
  1977. //The total circumference of the chart.
  1978. circumference: Math.PI * 2.0,
  1979. // Need to override these to give a nice default
  1980. tooltips: {
  1981. callbacks: {
  1982. title: function() {
  1983. return '';
  1984. },
  1985. label: function(tooltipItem, data) {
  1986. return data.labels[tooltipItem.index] + ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  1987. }
  1988. }
  1989. }
  1990. };
  1991. Chart.defaults.pie = helpers.clone(Chart.defaults.doughnut);
  1992. helpers.extend(Chart.defaults.pie, {
  1993. cutoutPercentage: 0
  1994. });
  1995. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  1996. linkScales: function() {
  1997. // no scales for doughnut
  1998. },
  1999. addElements: function() {
  2000. this.getDataset().metaData = this.getDataset().metaData || [];
  2001. helpers.each(this.getDataset().data, function(value, index) {
  2002. this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Arc({
  2003. _chart: this.chart.chart,
  2004. _datasetIndex: this.index,
  2005. _index: index
  2006. });
  2007. }, this);
  2008. },
  2009. addElementAndReset: function(index, colorForNewElement) {
  2010. this.getDataset().metaData = this.getDataset().metaData || [];
  2011. var arc = new Chart.elements.Arc({
  2012. _chart: this.chart.chart,
  2013. _datasetIndex: this.index,
  2014. _index: index
  2015. });
  2016. if (colorForNewElement && helpers.isArray(this.getDataset().backgroundColor)) {
  2017. this.getDataset().backgroundColor.splice(index, 0, colorForNewElement);
  2018. }
  2019. // Reset the point
  2020. this.updateElement(arc, index, true);
  2021. // Add to the points array
  2022. this.getDataset().metaData.splice(index, 0, arc);
  2023. },
  2024. getVisibleDatasetCount: function getVisibleDatasetCount() {
  2025. return helpers.where(this.chart.data.datasets, function(ds) {
  2026. return helpers.isDatasetVisible(ds);
  2027. }).length;
  2028. },
  2029. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2030. getRingIndex: function getRingIndex(datasetIndex) {
  2031. var ringIndex = 0;
  2032. for (var j = 0; j < datasetIndex; ++j) {
  2033. if (helpers.isDatasetVisible(this.chart.data.datasets[j])) {
  2034. ++ringIndex;
  2035. }
  2036. }
  2037. return ringIndex;
  2038. },
  2039. update: function update(reset) {
  2040. var availableWidth = this.chart.chartArea.right - this.chart.chartArea.left - this.chart.options.elements.arc.borderWidth;
  2041. var availableHeight = this.chart.chartArea.bottom - this.chart.chartArea.top - this.chart.options.elements.arc.borderWidth;
  2042. var minSize = Math.min(availableWidth, availableHeight);
  2043. var offset = {x: 0, y: 0};
  2044. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2045. if (this.chart.options.circumference && this.chart.options.circumference < Math.PI * 2.0) {
  2046. var startAngle = this.chart.options.rotation % (Math.PI * 2.0);
  2047. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2048. var endAngle = startAngle + this.chart.options.circumference;
  2049. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2050. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2051. var contains0 = (startAngle <= 0 && 0 <= endAngle) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2052. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2053. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2054. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2055. var cutout = this.chart.options.cutoutPercentage / 100.0;
  2056. 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))};
  2057. 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))};
  2058. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2059. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2060. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2061. }
  2062. this.chart.outerRadius = Math.max(minSize / 2, 0);
  2063. this.chart.innerRadius = Math.max(this.chart.options.cutoutPercentage ? (this.chart.outerRadius / 100) * (this.chart.options.cutoutPercentage) : 1, 0);
  2064. this.chart.radiusLength = (this.chart.outerRadius - this.chart.innerRadius) / this.getVisibleDatasetCount();
  2065. this.chart.offsetX = offset.x * this.chart.outerRadius;
  2066. this.chart.offsetY = offset.y * this.chart.outerRadius;
  2067. this.getDataset().total = 0;
  2068. helpers.each(this.getDataset().data, function(value) {
  2069. if (!isNaN(value)) {
  2070. this.getDataset().total += Math.abs(value);
  2071. }
  2072. }, this);
  2073. this.outerRadius = this.chart.outerRadius - (this.chart.radiusLength * this.getRingIndex(this.index));
  2074. this.innerRadius = this.outerRadius - this.chart.radiusLength;
  2075. helpers.each(this.getDataset().metaData, function(arc, index) {
  2076. this.updateElement(arc, index, reset);
  2077. }, this);
  2078. },
  2079. updateElement: function(arc, index, reset) {
  2080. var centerX = (this.chart.chartArea.left + this.chart.chartArea.right) / 2;
  2081. var centerY = (this.chart.chartArea.top + this.chart.chartArea.bottom) / 2;
  2082. var startAngle = this.chart.options.rotation || (Math.PI * -0.5); // non reset case handled later
  2083. var endAngle = this.chart.options.rotation || (Math.PI * -0.5); // non reset case handled later
  2084. var circumference = reset && this.chart.options.animation.animateRotate ? 0 : this.calculateCircumference(this.getDataset().data[index]) * ((this.chart.options.circumference || (2.0 * Math.PI)) / (2.0 * Math.PI));
  2085. var innerRadius = reset && this.chart.options.animation.animateScale ? 0 : this.innerRadius;
  2086. var outerRadius = reset && this.chart.options.animation.animateScale ? 0 : this.outerRadius;
  2087. helpers.extend(arc, {
  2088. // Utility
  2089. _chart: this.chart.chart,
  2090. _datasetIndex: this.index,
  2091. _index: index,
  2092. // Desired view properties
  2093. _model: {
  2094. x: centerX + this.chart.offsetX,
  2095. y: centerY + this.chart.offsetY,
  2096. startAngle: startAngle,
  2097. endAngle: endAngle,
  2098. circumference: circumference,
  2099. outerRadius: outerRadius,
  2100. innerRadius: innerRadius,
  2101. backgroundColor: arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor),
  2102. hoverBackgroundColor: arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor, index, this.chart.options.elements.arc.hoverBackgroundColor),
  2103. borderWidth: arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth),
  2104. borderColor: arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor),
  2105. label: helpers.getValueAtIndexOrDefault(this.getDataset().label, index, this.chart.data.labels[index])
  2106. }
  2107. });
  2108. // Set correct angles if not resetting
  2109. if (!reset) {
  2110. if (index === 0) {
  2111. arc._model.startAngle = this.chart.options.rotation || (Math.PI * -0.5);
  2112. } else {
  2113. arc._model.startAngle = this.getDataset().metaData[index - 1]._model.endAngle;
  2114. }
  2115. arc._model.endAngle = arc._model.startAngle + arc._model.circumference;
  2116. }
  2117. arc.pivot();
  2118. },
  2119. draw: function(ease) {
  2120. var easingDecimal = ease || 1;
  2121. helpers.each(this.getDataset().metaData, function(arc, index) {
  2122. arc.transition(easingDecimal).draw();
  2123. });
  2124. },
  2125. setHoverStyle: function(arc) {
  2126. var dataset = this.chart.data.datasets[arc._datasetIndex];
  2127. var index = arc._index;
  2128. arc._model.backgroundColor = arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(arc._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
  2129. arc._model.borderColor = arc.custom && arc.custom.hoverBorderColor ? arc.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(arc._model.borderColor).saturate(0.5).darken(0.1).rgbString());
  2130. arc._model.borderWidth = arc.custom && arc.custom.hoverBorderWidth ? arc.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, arc._model.borderWidth);
  2131. },
  2132. removeHoverStyle: function(arc) {
  2133. var dataset = this.chart.data.datasets[arc._datasetIndex];
  2134. var index = arc._index;
  2135. arc._model.backgroundColor = arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor);
  2136. arc._model.borderColor = arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor);
  2137. arc._model.borderWidth = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth);
  2138. },
  2139. calculateCircumference: function(value) {
  2140. if (this.getDataset().total > 0 && !isNaN(value)) {
  2141. return (Math.PI * 1.999999) * (value / this.getDataset().total);
  2142. } else {
  2143. return 0;
  2144. }
  2145. }
  2146. });
  2147. };
  2148. },{}],18:[function(require,module,exports){
  2149. "use strict";
  2150. module.exports = function(Chart) {
  2151. var helpers = Chart.helpers;
  2152. Chart.defaults.line = {
  2153. showLines: true,
  2154. hover: {
  2155. mode: "label"
  2156. },
  2157. scales: {
  2158. xAxes: [{
  2159. type: "category",
  2160. id: 'x-axis-0'
  2161. }],
  2162. yAxes: [{
  2163. type: "linear",
  2164. id: 'y-axis-0'
  2165. }]
  2166. }
  2167. };
  2168. Chart.controllers.line = Chart.DatasetController.extend({
  2169. addElements: function() {
  2170. this.getDataset().metaData = this.getDataset().metaData || [];
  2171. this.getDataset().metaDataset = this.getDataset().metaDataset || new Chart.elements.Line({
  2172. _chart: this.chart.chart,
  2173. _datasetIndex: this.index,
  2174. _points: this.getDataset().metaData
  2175. });
  2176. helpers.each(this.getDataset().data, function(value, index) {
  2177. this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Point({
  2178. _chart: this.chart.chart,
  2179. _datasetIndex: this.index,
  2180. _index: index
  2181. });
  2182. }, this);
  2183. },
  2184. addElementAndReset: function(index) {
  2185. this.getDataset().metaData = this.getDataset().metaData || [];
  2186. var point = new Chart.elements.Point({
  2187. _chart: this.chart.chart,
  2188. _datasetIndex: this.index,
  2189. _index: index
  2190. });
  2191. // Reset the point
  2192. this.updateElement(point, index, true);
  2193. // Add to the points array
  2194. this.getDataset().metaData.splice(index, 0, point);
  2195. // Make sure bezier control points are updated
  2196. if (this.chart.options.showLines && this.chart.options.elements.line.tension !== 0)
  2197. this.updateBezierControlPoints();
  2198. },
  2199. update: function update(reset) {
  2200. var line = this.getDataset().metaDataset;
  2201. var points = this.getDataset().metaData;
  2202. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  2203. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  2204. var scaleBase;
  2205. if (yScale.min < 0 && yScale.max < 0) {
  2206. scaleBase = yScale.getPixelForValue(yScale.max);
  2207. } else if (yScale.min > 0 && yScale.max > 0) {
  2208. scaleBase = yScale.getPixelForValue(yScale.min);
  2209. } else {
  2210. scaleBase = yScale.getPixelForValue(0);
  2211. }
  2212. // Update Line
  2213. if (this.chart.options.showLines) {
  2214. // Utility
  2215. line._scale = yScale;
  2216. line._datasetIndex = this.index;
  2217. // Data
  2218. line._children = points;
  2219. // Model
  2220. line._model = {
  2221. // Appearance
  2222. tension: line.custom && line.custom.tension ? line.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
  2223. backgroundColor: line.custom && line.custom.backgroundColor ? line.custom.backgroundColor : (this.getDataset().backgroundColor || this.chart.options.elements.line.backgroundColor),
  2224. borderWidth: line.custom && line.custom.borderWidth ? line.custom.borderWidth : (this.getDataset().borderWidth || this.chart.options.elements.line.borderWidth),
  2225. borderColor: line.custom && line.custom.borderColor ? line.custom.borderColor : (this.getDataset().borderColor || this.chart.options.elements.line.borderColor),
  2226. borderCapStyle: line.custom && line.custom.borderCapStyle ? line.custom.borderCapStyle : (this.getDataset().borderCapStyle || this.chart.options.elements.line.borderCapStyle),
  2227. borderDash: line.custom && line.custom.borderDash ? line.custom.borderDash : (this.getDataset().borderDash || this.chart.options.elements.line.borderDash),
  2228. borderDashOffset: line.custom && line.custom.borderDashOffset ? line.custom.borderDashOffset : (this.getDataset().borderDashOffset || this.chart.options.elements.line.borderDashOffset),
  2229. borderJoinStyle: line.custom && line.custom.borderJoinStyle ? line.custom.borderJoinStyle : (this.getDataset().borderJoinStyle || this.chart.options.elements.line.borderJoinStyle),
  2230. fill: line.custom && line.custom.fill ? line.custom.fill : (this.getDataset().fill !== undefined ? this.getDataset().fill : this.chart.options.elements.line.fill),
  2231. // Scale
  2232. scaleTop: yScale.top,
  2233. scaleBottom: yScale.bottom,
  2234. scaleZero: scaleBase
  2235. };
  2236. line.pivot();
  2237. }
  2238. // Update Points
  2239. helpers.each(points, function(point, index) {
  2240. this.updateElement(point, index, reset);
  2241. }, this);
  2242. if (this.chart.options.showLines && this.chart.options.elements.line.tension !== 0)
  2243. this.updateBezierControlPoints();
  2244. },
  2245. getPointBackgroundColor: function(point, index) {
  2246. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2247. var dataset = this.getDataset();
  2248. if (point.custom && point.custom.backgroundColor) {
  2249. backgroundColor = point.custom.backgroundColor;
  2250. } else if (dataset.pointBackgroundColor) {
  2251. backgroundColor = helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2252. } else if (dataset.backgroundColor) {
  2253. backgroundColor = dataset.backgroundColor;
  2254. }
  2255. return backgroundColor;
  2256. },
  2257. getPointBorderColor: function(point, index) {
  2258. var borderColor = this.chart.options.elements.point.borderColor;
  2259. var dataset = this.getDataset();
  2260. if (point.custom && point.custom.borderColor) {
  2261. borderColor = point.custom.borderColor;
  2262. } else if (dataset.pointBorderColor) {
  2263. borderColor = helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, borderColor);
  2264. } else if (dataset.borderColor) {
  2265. borderColor = dataset.borderColor;
  2266. }
  2267. return borderColor;
  2268. },
  2269. getPointBorderWidth: function(point, index) {
  2270. var borderWidth = this.chart.options.elements.point.borderWidth;
  2271. var dataset = this.getDataset();
  2272. if (point.custom && point.custom.borderWidth !== undefined) {
  2273. borderWidth = point.custom.borderWidth;
  2274. } else if (dataset.pointBorderWidth !== undefined) {
  2275. borderWidth = helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2276. } else if (dataset.borderWidth !== undefined) {
  2277. borderWidth = dataset.borderWidth;
  2278. }
  2279. return borderWidth;
  2280. },
  2281. updateElement: function(point, index, reset) {
  2282. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  2283. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  2284. var scaleBase;
  2285. if (yScale.min < 0 && yScale.max < 0) {
  2286. scaleBase = yScale.getPixelForValue(yScale.max);
  2287. } else if (yScale.min > 0 && yScale.max > 0) {
  2288. scaleBase = yScale.getPixelForValue(yScale.min);
  2289. } else {
  2290. scaleBase = yScale.getPixelForValue(0);
  2291. }
  2292. // Utility
  2293. point._chart = this.chart.chart;
  2294. point._xScale = xScale;
  2295. point._yScale = yScale;
  2296. point._datasetIndex = this.index;
  2297. point._index = index;
  2298. // Desired view properties
  2299. point._model = {
  2300. x: xScale.getPixelForValue(this.getDataset().data[index], index, this.index, this.chart.isCombo),
  2301. y: reset ? scaleBase : this.calculatePointY(this.getDataset().data[index], index, this.index, this.chart.isCombo),
  2302. // Appearance
  2303. tension: point.custom && point.custom.tension ? point.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
  2304. radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius),
  2305. pointStyle: point.custom && point.custom.pointStyle ? point.custom.pointStyle : helpers.getValueAtIndexOrDefault(this.getDataset().pointStyle, index, this.chart.options.elements.point.pointStyle),
  2306. backgroundColor: this.getPointBackgroundColor(point, index),
  2307. borderColor: this.getPointBorderColor(point, index),
  2308. borderWidth: this.getPointBorderWidth(point, index),
  2309. // Tooltip
  2310. hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().hitRadius, index, this.chart.options.elements.point.hitRadius)
  2311. };
  2312. point._model.skip = point.custom && point.custom.skip ? point.custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  2313. },
  2314. calculatePointY: function(value, index, datasetIndex, isCombo) {
  2315. var xScale = this.getScaleForId(this.getDataset().xAxisID);
  2316. var yScale = this.getScaleForId(this.getDataset().yAxisID);
  2317. if (yScale.options.stacked) {
  2318. var sumPos = 0,
  2319. sumNeg = 0;
  2320. for (var i = 0; i < datasetIndex; i++) {
  2321. var ds = this.chart.data.datasets[i];
  2322. if (ds.type === 'line' && helpers.isDatasetVisible(ds)) {
  2323. if (ds.data[index] < 0) {
  2324. sumNeg += ds.data[index] || 0;
  2325. } else {
  2326. sumPos += ds.data[index] || 0;
  2327. }
  2328. }
  2329. }
  2330. if (value < 0) {
  2331. return yScale.getPixelForValue(sumNeg + value);
  2332. } else {
  2333. return yScale.getPixelForValue(sumPos + value);
  2334. }
  2335. }
  2336. return yScale.getPixelForValue(value);
  2337. },
  2338. updateBezierControlPoints: function() {
  2339. // Update bezier control points
  2340. helpers.each(this.getDataset().metaData, function(point, index) {
  2341. var controlPoints = helpers.splineCurve(
  2342. helpers.previousItem(this.getDataset().metaData, index)._model,
  2343. point._model,
  2344. helpers.nextItem(this.getDataset().metaData, index)._model,
  2345. point._model.tension
  2346. );
  2347. // Prevent the bezier going outside of the bounds of the graph
  2348. point._model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, this.chart.chartArea.right), this.chart.chartArea.left);
  2349. point._model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
  2350. point._model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, this.chart.chartArea.right), this.chart.chartArea.left);
  2351. point._model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
  2352. // Now pivot the point for animation
  2353. point.pivot();
  2354. }, this);
  2355. },
  2356. draw: function(ease) {
  2357. var easingDecimal = ease || 1;
  2358. // Transition Point Locations
  2359. helpers.each(this.getDataset().metaData, function(point) {
  2360. point.transition(easingDecimal);
  2361. });
  2362. // Transition and Draw the line
  2363. if (this.chart.options.showLines)
  2364. this.getDataset().metaDataset.transition(easingDecimal).draw();
  2365. // Draw the points
  2366. helpers.each(this.getDataset().metaData, function(point) {
  2367. point.draw();
  2368. });
  2369. },
  2370. setHoverStyle: function(point) {
  2371. // Point
  2372. var dataset = this.chart.data.datasets[point._datasetIndex];
  2373. var index = point._index;
  2374. point._model.radius = point.custom && point.custom.hoverRadius ? point.custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2375. point._model.backgroundColor = point.custom && point.custom.hoverBackgroundColor ? point.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(point._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
  2376. point._model.borderColor = point.custom && point.custom.hoverBorderColor ? point.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(point._model.borderColor).saturate(0.5).darken(0.1).rgbString());
  2377. point._model.borderWidth = point.custom && point.custom.hoverBorderWidth ? point.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, point._model.borderWidth);
  2378. },
  2379. removeHoverStyle: function(point) {
  2380. var dataset = this.chart.data.datasets[point._datasetIndex];
  2381. var index = point._index;
  2382. point._model.radius = point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius);
  2383. point._model.backgroundColor = this.getPointBackgroundColor(point, index);
  2384. point._model.borderColor = this.getPointBorderColor(point, index);
  2385. point._model.borderWidth = this.getPointBorderWidth(point, index);
  2386. }
  2387. });
  2388. };
  2389. },{}],19:[function(require,module,exports){
  2390. "use strict";
  2391. module.exports = function(Chart) {
  2392. var helpers = Chart.helpers;
  2393. Chart.defaults.polarArea = {
  2394. scale: {
  2395. type: "radialLinear",
  2396. lineArc: true // so that lines are circular
  2397. },
  2398. //Boolean - Whether to animate the rotation of the chart
  2399. animateRotate: true,
  2400. animateScale: true,
  2401. aspectRatio: 1,
  2402. legendCallback: function(chart) {
  2403. var text = [];
  2404. text.push('<ul class="' + chart.id + '-legend">');
  2405. if (chart.data.datasets.length) {
  2406. for (var i = 0; i < chart.data.datasets[0].data.length; ++i) {
  2407. text.push('<li><span style="background-color:' + chart.data.datasets[0].backgroundColor[i] + '">');
  2408. if (chart.data.labels[i]) {
  2409. text.push(chart.data.labels[i]);
  2410. }
  2411. text.push('</span></li>');
  2412. }
  2413. }
  2414. text.push('</ul>');
  2415. return text.join("");
  2416. },
  2417. legend: {
  2418. labels: {
  2419. generateLabels: function(data) {
  2420. if (data.labels.length && data.datasets.length) {
  2421. return data.labels.map(function(label, i) {
  2422. return {
  2423. text: label,
  2424. fillStyle: data.datasets[0].backgroundColor[i],
  2425. hidden: isNaN(data.datasets[0].data[i]),
  2426. // Extra data used for toggling the correct item
  2427. index: i
  2428. };
  2429. });
  2430. } else {
  2431. return [];
  2432. }
  2433. }
  2434. },
  2435. onClick: function(e, legendItem) {
  2436. helpers.each(this.chart.data.datasets, function(dataset) {
  2437. dataset.metaHiddenData = dataset.metaHiddenData || [];
  2438. var idx = legendItem.index;
  2439. if (!isNaN(dataset.data[idx])) {
  2440. dataset.metaHiddenData[idx] = dataset.data[idx];
  2441. dataset.data[idx] = NaN;
  2442. } else if (!isNaN(dataset.metaHiddenData[idx])) {
  2443. dataset.data[idx] = dataset.metaHiddenData[idx];
  2444. }
  2445. });
  2446. this.chart.update();
  2447. }
  2448. },
  2449. // Need to override these to give a nice default
  2450. tooltips: {
  2451. callbacks: {
  2452. title: function() {
  2453. return '';
  2454. },
  2455. label: function(tooltipItem, data) {
  2456. return data.labels[tooltipItem.index] + ': ' + tooltipItem.yLabel;
  2457. }
  2458. }
  2459. }
  2460. };
  2461. Chart.controllers.polarArea = Chart.DatasetController.extend({
  2462. linkScales: function() {
  2463. // no scales for doughnut
  2464. },
  2465. addElements: function() {
  2466. this.getDataset().metaData = this.getDataset().metaData || [];
  2467. helpers.each(this.getDataset().data, function(value, index) {
  2468. this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Arc({
  2469. _chart: this.chart.chart,
  2470. _datasetIndex: this.index,
  2471. _index: index
  2472. });
  2473. }, this);
  2474. },
  2475. addElementAndReset: function(index) {
  2476. this.getDataset().metaData = this.getDataset().metaData || [];
  2477. var arc = new Chart.elements.Arc({
  2478. _chart: this.chart.chart,
  2479. _datasetIndex: this.index,
  2480. _index: index
  2481. });
  2482. // Reset the point
  2483. this.updateElement(arc, index, true);
  2484. // Add to the points array
  2485. this.getDataset().metaData.splice(index, 0, arc);
  2486. },
  2487. getVisibleDatasetCount: function getVisibleDatasetCount() {
  2488. return helpers.where(this.chart.data.datasets, function(ds) {
  2489. return helpers.isDatasetVisible(ds);
  2490. }).length;
  2491. },
  2492. update: function update(reset) {
  2493. var minSize = Math.min(this.chart.chartArea.right - this.chart.chartArea.left, this.chart.chartArea.bottom - this.chart.chartArea.top);
  2494. this.chart.outerRadius = Math.max((minSize - this.chart.options.elements.arc.borderWidth / 2) / 2, 0);
  2495. this.chart.innerRadius = Math.max(this.chart.options.cutoutPercentage ? (this.chart.outerRadius / 100) * (this.chart.options.cutoutPercentage) : 1, 0);
  2496. this.chart.radiusLength = (this.chart.outerRadius - this.chart.innerRadius) / this.getVisibleDatasetCount();
  2497. this.getDataset().total = 0;
  2498. helpers.each(this.getDataset().data, function(value) {
  2499. this.getDataset().total += Math.abs(value);
  2500. }, this);
  2501. this.outerRadius = this.chart.outerRadius - (this.chart.radiusLength * this.index);
  2502. this.innerRadius = this.outerRadius - this.chart.radiusLength;
  2503. helpers.each(this.getDataset().metaData, function(arc, index) {
  2504. this.updateElement(arc, index, reset);
  2505. }, this);
  2506. },
  2507. updateElement: function(arc, index, reset) {
  2508. var circumference = this.calculateCircumference(this.getDataset().data[index]);
  2509. var centerX = (this.chart.chartArea.left + this.chart.chartArea.right) / 2;
  2510. var centerY = (this.chart.chartArea.top + this.chart.chartArea.bottom) / 2;
  2511. // If there is NaN data before us, we need to calculate the starting angle correctly.
  2512. // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
  2513. var notNullIndex = 0;
  2514. for (var i = 0; i < index; ++i) {
  2515. if (!isNaN(this.getDataset().data[i])) {
  2516. ++notNullIndex;
  2517. }
  2518. }
  2519. var startAngle = (-0.5 * Math.PI) + (circumference * notNullIndex);
  2520. var endAngle = startAngle + circumference;
  2521. var resetModel = {
  2522. x: centerX,
  2523. y: centerY,
  2524. innerRadius: 0,
  2525. outerRadius: this.chart.options.animateScale ? 0 : this.chart.scale.getDistanceFromCenterForValue(this.getDataset().data[index]),
  2526. startAngle: this.chart.options.animateRotate ? Math.PI * -0.5 : startAngle,
  2527. endAngle: this.chart.options.animateRotate ? Math.PI * -0.5 : endAngle,
  2528. backgroundColor: arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor),
  2529. borderWidth: arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth),
  2530. borderColor: arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor),
  2531. label: helpers.getValueAtIndexOrDefault(this.chart.data.labels, index, this.chart.data.labels[index])
  2532. };
  2533. helpers.extend(arc, {
  2534. // Utility
  2535. _chart: this.chart.chart,
  2536. _datasetIndex: this.index,
  2537. _index: index,
  2538. _scale: this.chart.scale,
  2539. // Desired view properties
  2540. _model: reset ? resetModel : {
  2541. x: centerX,
  2542. y: centerY,
  2543. innerRadius: 0,
  2544. outerRadius: this.chart.scale.getDistanceFromCenterForValue(this.getDataset().data[index]),
  2545. startAngle: startAngle,
  2546. endAngle: endAngle,
  2547. backgroundColor: arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor),
  2548. borderWidth: arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth),
  2549. borderColor: arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor),
  2550. label: helpers.getValueAtIndexOrDefault(this.chart.data.labels, index, this.chart.data.labels[index])
  2551. }
  2552. });
  2553. arc.pivot();
  2554. },
  2555. draw: function(ease) {
  2556. var easingDecimal = ease || 1;
  2557. helpers.each(this.getDataset().metaData, function(arc, index) {
  2558. arc.transition(easingDecimal).draw();
  2559. });
  2560. },
  2561. setHoverStyle: function(arc) {
  2562. var dataset = this.chart.data.datasets[arc._datasetIndex];
  2563. var index = arc._index;
  2564. arc._model.backgroundColor = arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(arc._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
  2565. arc._model.borderColor = arc.custom && arc.custom.hoverBorderColor ? arc.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(arc._model.borderColor).saturate(0.5).darken(0.1).rgbString());
  2566. arc._model.borderWidth = arc.custom && arc.custom.hoverBorderWidth ? arc.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, arc._model.borderWidth);
  2567. },
  2568. removeHoverStyle: function(arc) {
  2569. var dataset = this.chart.data.datasets[arc._datasetIndex];
  2570. var index = arc._index;
  2571. arc._model.backgroundColor = arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor);
  2572. arc._model.borderColor = arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor);
  2573. arc._model.borderWidth = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth);
  2574. },
  2575. calculateCircumference: function(value) {
  2576. if (isNaN(value)) {
  2577. return 0;
  2578. } else {
  2579. // Count the number of NaN values
  2580. var numNaN = helpers.where(this.getDataset().data, function(data) {
  2581. return isNaN(data);
  2582. }).length;
  2583. return (2 * Math.PI) / (this.getDataset().data.length - numNaN);
  2584. }
  2585. }
  2586. });
  2587. };
  2588. },{}],20:[function(require,module,exports){
  2589. "use strict";
  2590. module.exports = function(Chart) {
  2591. var helpers = Chart.helpers;
  2592. Chart.defaults.radar = {
  2593. scale: {
  2594. type: "radialLinear"
  2595. },
  2596. elements: {
  2597. line: {
  2598. tension: 0 // no bezier in radar
  2599. }
  2600. }
  2601. };
  2602. Chart.controllers.radar = Chart.DatasetController.extend({
  2603. linkScales: function() {
  2604. // No need. Single scale only
  2605. },
  2606. addElements: function() {
  2607. this.getDataset().metaData = this.getDataset().metaData || [];
  2608. this.getDataset().metaDataset = this.getDataset().metaDataset || new Chart.elements.Line({
  2609. _chart: this.chart.chart,
  2610. _datasetIndex: this.index,
  2611. _points: this.getDataset().metaData,
  2612. _loop: true
  2613. });
  2614. helpers.each(this.getDataset().data, function(value, index) {
  2615. this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Point({
  2616. _chart: this.chart.chart,
  2617. _datasetIndex: this.index,
  2618. _index: index,
  2619. _model: {
  2620. x: 0, //xScale.getPixelForValue(null, index, true),
  2621. y: 0 //this.chartArea.bottom,
  2622. }
  2623. });
  2624. }, this);
  2625. },
  2626. addElementAndReset: function(index) {
  2627. this.getDataset().metaData = this.getDataset().metaData || [];
  2628. var point = new Chart.elements.Point({
  2629. _chart: this.chart.chart,
  2630. _datasetIndex: this.index,
  2631. _index: index
  2632. });
  2633. // Reset the point
  2634. this.updateElement(point, index, true);
  2635. // Add to the points array
  2636. this.getDataset().metaData.splice(index, 0, point);
  2637. // Make sure bezier control points are updated
  2638. this.updateBezierControlPoints();
  2639. },
  2640. update: function update(reset) {
  2641. var line = this.getDataset().metaDataset;
  2642. var points = this.getDataset().metaData;
  2643. var scale = this.chart.scale;
  2644. var scaleBase;
  2645. if (scale.min < 0 && scale.max < 0) {
  2646. scaleBase = scale.getPointPositionForValue(0, scale.max);
  2647. } else if (scale.min > 0 && scale.max > 0) {
  2648. scaleBase = scale.getPointPositionForValue(0, scale.min);
  2649. } else {
  2650. scaleBase = scale.getPointPositionForValue(0, 0);
  2651. }
  2652. helpers.extend(this.getDataset().metaDataset, {
  2653. // Utility
  2654. _datasetIndex: this.index,
  2655. // Data
  2656. _children: this.getDataset().metaData,
  2657. // Model
  2658. _model: {
  2659. // Appearance
  2660. tension: line.custom && line.custom.tension ? line.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
  2661. backgroundColor: line.custom && line.custom.backgroundColor ? line.custom.backgroundColor : (this.getDataset().backgroundColor || this.chart.options.elements.line.backgroundColor),
  2662. borderWidth: line.custom && line.custom.borderWidth ? line.custom.borderWidth : (this.getDataset().borderWidth || this.chart.options.elements.line.borderWidth),
  2663. borderColor: line.custom && line.custom.borderColor ? line.custom.borderColor : (this.getDataset().borderColor || this.chart.options.elements.line.borderColor),
  2664. fill: line.custom && line.custom.fill ? line.custom.fill : (this.getDataset().fill !== undefined ? this.getDataset().fill : this.chart.options.elements.line.fill),
  2665. borderCapStyle: line.custom && line.custom.borderCapStyle ? line.custom.borderCapStyle : (this.getDataset().borderCapStyle || this.chart.options.elements.line.borderCapStyle),
  2666. borderDash: line.custom && line.custom.borderDash ? line.custom.borderDash : (this.getDataset().borderDash || this.chart.options.elements.line.borderDash),
  2667. borderDashOffset: line.custom && line.custom.borderDashOffset ? line.custom.borderDashOffset : (this.getDataset().borderDashOffset || this.chart.options.elements.line.borderDashOffset),
  2668. borderJoinStyle: line.custom && line.custom.borderJoinStyle ? line.custom.borderJoinStyle : (this.getDataset().borderJoinStyle || this.chart.options.elements.line.borderJoinStyle),
  2669. // Scale
  2670. scaleTop: scale.top,
  2671. scaleBottom: scale.bottom,
  2672. scaleZero: scaleBase
  2673. }
  2674. });
  2675. this.getDataset().metaDataset.pivot();
  2676. // Update Points
  2677. helpers.each(points, function(point, index) {
  2678. this.updateElement(point, index, reset);
  2679. }, this);
  2680. // Update bezier control points
  2681. this.updateBezierControlPoints();
  2682. },
  2683. updateElement: function(point, index, reset) {
  2684. var pointPosition = this.chart.scale.getPointPositionForValue(index, this.getDataset().data[index]);
  2685. helpers.extend(point, {
  2686. // Utility
  2687. _datasetIndex: this.index,
  2688. _index: index,
  2689. _scale: this.chart.scale,
  2690. // Desired view properties
  2691. _model: {
  2692. x: reset ? this.chart.scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  2693. y: reset ? this.chart.scale.yCenter : pointPosition.y,
  2694. // Appearance
  2695. tension: point.custom && point.custom.tension ? point.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
  2696. radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().pointRadius, index, this.chart.options.elements.point.radius),
  2697. backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor, index, this.chart.options.elements.point.backgroundColor),
  2698. borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, this.chart.options.elements.point.borderColor),
  2699. borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth, index, this.chart.options.elements.point.borderWidth),
  2700. pointStyle: point.custom && point.custom.pointStyle ? point.custom.pointStyle : helpers.getValueAtIndexOrDefault(this.getDataset().pointStyle, index, this.chart.options.elements.point.pointStyle),
  2701. // Tooltip
  2702. hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().hitRadius, index, this.chart.options.elements.point.hitRadius)
  2703. }
  2704. });
  2705. point._model.skip = point.custom && point.custom.skip ? point.custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  2706. },
  2707. updateBezierControlPoints: function() {
  2708. helpers.each(this.getDataset().metaData, function(point, index) {
  2709. var controlPoints = helpers.splineCurve(
  2710. helpers.previousItem(this.getDataset().metaData, index, true)._model,
  2711. point._model,
  2712. helpers.nextItem(this.getDataset().metaData, index, true)._model,
  2713. point._model.tension
  2714. );
  2715. // Prevent the bezier going outside of the bounds of the graph
  2716. point._model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, this.chart.chartArea.right), this.chart.chartArea.left);
  2717. point._model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
  2718. point._model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, this.chart.chartArea.right), this.chart.chartArea.left);
  2719. point._model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
  2720. // Now pivot the point for animation
  2721. point.pivot();
  2722. }, this);
  2723. },
  2724. draw: function(ease) {
  2725. var easingDecimal = ease || 1;
  2726. // Transition Point Locations
  2727. helpers.each(this.getDataset().metaData, function(point, index) {
  2728. point.transition(easingDecimal);
  2729. });
  2730. // Transition and Draw the line
  2731. this.getDataset().metaDataset.transition(easingDecimal).draw();
  2732. // Draw the points
  2733. helpers.each(this.getDataset().metaData, function(point) {
  2734. point.draw();
  2735. });
  2736. },
  2737. setHoverStyle: function(point) {
  2738. // Point
  2739. var dataset = this.chart.data.datasets[point._datasetIndex];
  2740. var index = point._index;
  2741. point._model.radius = point.custom && point.custom.hoverRadius ? point.custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2742. point._model.backgroundColor = point.custom && point.custom.hoverBackgroundColor ? point.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(point._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
  2743. point._model.borderColor = point.custom && point.custom.hoverBorderColor ? point.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(point._model.borderColor).saturate(0.5).darken(0.1).rgbString());
  2744. point._model.borderWidth = point.custom && point.custom.hoverBorderWidth ? point.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, point._model.borderWidth);
  2745. },
  2746. removeHoverStyle: function(point) {
  2747. var dataset = this.chart.data.datasets[point._datasetIndex];
  2748. var index = point._index;
  2749. point._model.radius = point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius);
  2750. point._model.backgroundColor = point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor, index, this.chart.options.elements.point.backgroundColor);
  2751. point._model.borderColor = point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, this.chart.options.elements.point.borderColor);
  2752. point._model.borderWidth = point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth, index, this.chart.options.elements.point.borderWidth);
  2753. }
  2754. });
  2755. };
  2756. },{}],21:[function(require,module,exports){
  2757. /*global window: false */
  2758. "use strict";
  2759. module.exports = function(Chart) {
  2760. var helpers = Chart.helpers;
  2761. Chart.defaults.global.animation = {
  2762. duration: 1000,
  2763. easing: "easeOutQuart",
  2764. onProgress: helpers.noop,
  2765. onComplete: helpers.noop
  2766. };
  2767. Chart.Animation = Chart.Element.extend({
  2768. currentStep: null, // the current animation step
  2769. numSteps: 60, // default number of steps
  2770. easing: "", // the easing to use for this animation
  2771. render: null, // render function used by the animation service
  2772. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  2773. onAnimationComplete: null // user specified callback to fire when the animation finishes
  2774. });
  2775. Chart.animationService = {
  2776. frameDuration: 17,
  2777. animations: [],
  2778. dropFrames: 0,
  2779. request: null,
  2780. addAnimation: function(chartInstance, animationObject, duration, lazy) {
  2781. if (!lazy) {
  2782. chartInstance.animating = true;
  2783. }
  2784. for (var index = 0; index < this.animations.length; ++index) {
  2785. if (this.animations[index].chartInstance === chartInstance) {
  2786. // replacing an in progress animation
  2787. this.animations[index].animationObject = animationObject;
  2788. return;
  2789. }
  2790. }
  2791. this.animations.push({
  2792. chartInstance: chartInstance,
  2793. animationObject: animationObject
  2794. });
  2795. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  2796. if (this.animations.length === 1) {
  2797. this.requestAnimationFrame();
  2798. }
  2799. },
  2800. // Cancel the animation for a given chart instance
  2801. cancelAnimation: function(chartInstance) {
  2802. var index = helpers.findIndex(this.animations, function(animationWrapper) {
  2803. return animationWrapper.chartInstance === chartInstance;
  2804. });
  2805. if (index !== -1) {
  2806. this.animations.splice(index, 1);
  2807. chartInstance.animating = false;
  2808. }
  2809. },
  2810. requestAnimationFrame: function() {
  2811. var me = this;
  2812. if (me.request === null) {
  2813. // Skip animation frame requests until the active one is executed.
  2814. // This can happen when processing mouse events, e.g. 'mousemove'
  2815. // and 'mouseout' events will trigger multiple renders.
  2816. me.request = helpers.requestAnimFrame.call(window, function() {
  2817. me.request = null;
  2818. me.startDigest();
  2819. });
  2820. }
  2821. },
  2822. startDigest: function() {
  2823. var startTime = Date.now();
  2824. var framesToDrop = 0;
  2825. if (this.dropFrames > 1) {
  2826. framesToDrop = Math.floor(this.dropFrames);
  2827. this.dropFrames = this.dropFrames % 1;
  2828. }
  2829. var i = 0;
  2830. while (i < this.animations.length) {
  2831. if (this.animations[i].animationObject.currentStep === null) {
  2832. this.animations[i].animationObject.currentStep = 0;
  2833. }
  2834. this.animations[i].animationObject.currentStep += 1 + framesToDrop;
  2835. if (this.animations[i].animationObject.currentStep > this.animations[i].animationObject.numSteps) {
  2836. this.animations[i].animationObject.currentStep = this.animations[i].animationObject.numSteps;
  2837. }
  2838. this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject);
  2839. if (this.animations[i].animationObject.onAnimationProgress && this.animations[i].animationObject.onAnimationProgress.call) {
  2840. this.animations[i].animationObject.onAnimationProgress.call(this.animations[i].chartInstance, this.animations[i]);
  2841. }
  2842. if (this.animations[i].animationObject.currentStep === this.animations[i].animationObject.numSteps) {
  2843. if (this.animations[i].animationObject.onAnimationComplete && this.animations[i].animationObject.onAnimationComplete.call) {
  2844. this.animations[i].animationObject.onAnimationComplete.call(this.animations[i].chartInstance, this.animations[i]);
  2845. }
  2846. // executed the last frame. Remove the animation.
  2847. this.animations[i].chartInstance.animating = false;
  2848. this.animations.splice(i, 1);
  2849. } else {
  2850. ++i;
  2851. }
  2852. }
  2853. var endTime = Date.now();
  2854. var dropFrames = (endTime - startTime) / this.frameDuration;
  2855. this.dropFrames += dropFrames;
  2856. // Do we have more stuff to animate?
  2857. if (this.animations.length > 0) {
  2858. this.requestAnimationFrame();
  2859. }
  2860. }
  2861. };
  2862. };
  2863. },{}],22:[function(require,module,exports){
  2864. "use strict";
  2865. module.exports = function(Chart) {
  2866. var helpers = Chart.helpers;
  2867. //Create a dictionary of chart types, to allow for extension of existing types
  2868. Chart.types = {};
  2869. //Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  2870. //Destroy method on the chart will remove the instance of the chart from this reference.
  2871. Chart.instances = {};
  2872. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  2873. Chart.controllers = {};
  2874. // The main controller of a chart
  2875. Chart.Controller = function(instance) {
  2876. this.chart = instance;
  2877. this.config = instance.config;
  2878. this.options = this.config.options = helpers.configMerge(Chart.defaults.global, Chart.defaults[this.config.type], this.config.options || {});
  2879. this.id = helpers.uid();
  2880. Object.defineProperty(this, 'data', {
  2881. get: function() {
  2882. return this.config.data;
  2883. }
  2884. });
  2885. //Add the chart instance to the global namespace
  2886. Chart.instances[this.id] = this;
  2887. if (this.options.responsive) {
  2888. // Silent resize before chart draws
  2889. this.resize(true);
  2890. }
  2891. this.initialize();
  2892. return this;
  2893. };
  2894. helpers.extend(Chart.Controller.prototype, {
  2895. initialize: function initialize() {
  2896. // TODO
  2897. // If BeforeInit(this) doesn't return false, proceed
  2898. this.bindEvents();
  2899. // Make sure controllers are built first so that each dataset is bound to an axis before the scales
  2900. // are built
  2901. this.ensureScalesHaveIDs();
  2902. this.buildOrUpdateControllers();
  2903. this.buildScales();
  2904. this.buildSurroundingItems();
  2905. this.updateLayout();
  2906. this.resetElements();
  2907. this.initToolTip();
  2908. this.update();
  2909. // TODO
  2910. // If AfterInit(this) doesn't return false, proceed
  2911. return this;
  2912. },
  2913. clear: function clear() {
  2914. helpers.clear(this.chart);
  2915. return this;
  2916. },
  2917. stop: function stop() {
  2918. // Stops any current animation loop occuring
  2919. Chart.animationService.cancelAnimation(this);
  2920. return this;
  2921. },
  2922. resize: function resize(silent) {
  2923. var canvas = this.chart.canvas;
  2924. var newWidth = helpers.getMaximumWidth(this.chart.canvas);
  2925. var newHeight = (this.options.maintainAspectRatio && isNaN(this.chart.aspectRatio) === false && isFinite(this.chart.aspectRatio) && this.chart.aspectRatio !== 0) ? newWidth / this.chart.aspectRatio : helpers.getMaximumHeight(this.chart.canvas);
  2926. var sizeChanged = this.chart.width !== newWidth || this.chart.height !== newHeight;
  2927. if (!sizeChanged)
  2928. return this;
  2929. canvas.width = this.chart.width = newWidth;
  2930. canvas.height = this.chart.height = newHeight;
  2931. helpers.retinaScale(this.chart);
  2932. if (!silent) {
  2933. this.stop();
  2934. this.update(this.options.responsiveAnimationDuration);
  2935. }
  2936. return this;
  2937. },
  2938. ensureScalesHaveIDs: function ensureScalesHaveIDs() {
  2939. var defaultXAxisID = 'x-axis-';
  2940. var defaultYAxisID = 'y-axis-';
  2941. if (this.options.scales) {
  2942. if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
  2943. helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
  2944. xAxisOptions.id = xAxisOptions.id || (defaultXAxisID + index);
  2945. });
  2946. }
  2947. if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
  2948. // Build the y axes
  2949. helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
  2950. yAxisOptions.id = yAxisOptions.id || (defaultYAxisID + index);
  2951. });
  2952. }
  2953. }
  2954. },
  2955. buildScales: function buildScales() {
  2956. // Map of scale ID to scale object so we can lookup later
  2957. this.scales = {};
  2958. // Build the x axes
  2959. if (this.options.scales) {
  2960. if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
  2961. helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
  2962. var xType = helpers.getValueOrDefault(xAxisOptions.type, 'category');
  2963. var ScaleClass = Chart.scaleService.getScaleConstructor(xType);
  2964. if (ScaleClass) {
  2965. var scale = new ScaleClass({
  2966. ctx: this.chart.ctx,
  2967. options: xAxisOptions,
  2968. chart: this,
  2969. id: xAxisOptions.id
  2970. });
  2971. this.scales[scale.id] = scale;
  2972. }
  2973. }, this);
  2974. }
  2975. if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
  2976. // Build the y axes
  2977. helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
  2978. var yType = helpers.getValueOrDefault(yAxisOptions.type, 'linear');
  2979. var ScaleClass = Chart.scaleService.getScaleConstructor(yType);
  2980. if (ScaleClass) {
  2981. var scale = new ScaleClass({
  2982. ctx: this.chart.ctx,
  2983. options: yAxisOptions,
  2984. chart: this,
  2985. id: yAxisOptions.id
  2986. });
  2987. this.scales[scale.id] = scale;
  2988. }
  2989. }, this);
  2990. }
  2991. }
  2992. if (this.options.scale) {
  2993. // Build radial axes
  2994. var ScaleClass = Chart.scaleService.getScaleConstructor(this.options.scale.type);
  2995. if (ScaleClass) {
  2996. var scale = new ScaleClass({
  2997. ctx: this.chart.ctx,
  2998. options: this.options.scale,
  2999. chart: this
  3000. });
  3001. this.scale = scale;
  3002. this.scales.radialScale = scale;
  3003. }
  3004. }
  3005. Chart.scaleService.addScalesToLayout(this);
  3006. },
  3007. buildSurroundingItems: function() {
  3008. if (this.options.title) {
  3009. this.titleBlock = new Chart.Title({
  3010. ctx: this.chart.ctx,
  3011. options: this.options.title,
  3012. chart: this
  3013. });
  3014. Chart.layoutService.addBox(this, this.titleBlock);
  3015. }
  3016. if (this.options.legend) {
  3017. this.legend = new Chart.Legend({
  3018. ctx: this.chart.ctx,
  3019. options: this.options.legend,
  3020. chart: this
  3021. });
  3022. Chart.layoutService.addBox(this, this.legend);
  3023. }
  3024. },
  3025. updateLayout: function() {
  3026. Chart.layoutService.update(this, this.chart.width, this.chart.height);
  3027. },
  3028. buildOrUpdateControllers: function buildOrUpdateControllers() {
  3029. var types = [];
  3030. var newControllers = [];
  3031. helpers.each(this.data.datasets, function(dataset, datasetIndex) {
  3032. if (!dataset.type) {
  3033. dataset.type = this.config.type;
  3034. }
  3035. var type = dataset.type;
  3036. types.push(type);
  3037. if (dataset.controller) {
  3038. dataset.controller.updateIndex(datasetIndex);
  3039. } else {
  3040. dataset.controller = new Chart.controllers[type](this, datasetIndex);
  3041. newControllers.push(dataset.controller);
  3042. }
  3043. }, this);
  3044. if (types.length > 1) {
  3045. for (var i = 1; i < types.length; i++) {
  3046. if (types[i] !== types[i - 1]) {
  3047. this.isCombo = true;
  3048. break;
  3049. }
  3050. }
  3051. }
  3052. return newControllers;
  3053. },
  3054. resetElements: function resetElements() {
  3055. helpers.each(this.data.datasets, function(dataset, datasetIndex) {
  3056. dataset.controller.reset();
  3057. });
  3058. },
  3059. update: function update(animationDuration, lazy) {
  3060. // In case the entire data object changed
  3061. this.tooltip._data = this.data;
  3062. // Make sure dataset controllers are updated and new controllers are reset
  3063. var newControllers = this.buildOrUpdateControllers();
  3064. Chart.layoutService.update(this, this.chart.width, this.chart.height);
  3065. // Can only reset the new controllers after the scales have been updated
  3066. helpers.each(newControllers, function(controller) {
  3067. controller.reset();
  3068. });
  3069. // Make sure all dataset controllers have correct meta data counts
  3070. helpers.each(this.data.datasets, function(dataset, datasetIndex) {
  3071. dataset.controller.buildOrUpdateElements();
  3072. });
  3073. // This will loop through any data and do the appropriate element update for the type
  3074. helpers.each(this.data.datasets, function(dataset, datasetIndex) {
  3075. dataset.controller.update();
  3076. });
  3077. this.render(animationDuration, lazy);
  3078. },
  3079. render: function render(duration, lazy) {
  3080. if (this.options.animation && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && this.options.animation.duration !== 0))) {
  3081. var animation = new Chart.Animation();
  3082. animation.numSteps = (duration || this.options.animation.duration) / 16.66; //60 fps
  3083. animation.easing = this.options.animation.easing;
  3084. // render function
  3085. animation.render = function(chartInstance, animationObject) {
  3086. var easingFunction = helpers.easingEffects[animationObject.easing];
  3087. var stepDecimal = animationObject.currentStep / animationObject.numSteps;
  3088. var easeDecimal = easingFunction(stepDecimal);
  3089. chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
  3090. };
  3091. // user events
  3092. animation.onAnimationProgress = this.options.animation.onProgress;
  3093. animation.onAnimationComplete = this.options.animation.onComplete;
  3094. Chart.animationService.addAnimation(this, animation, duration, lazy);
  3095. } else {
  3096. this.draw();
  3097. if (this.options.animation && this.options.animation.onComplete && this.options.animation.onComplete.call) {
  3098. this.options.animation.onComplete.call(this);
  3099. }
  3100. }
  3101. return this;
  3102. },
  3103. draw: function(ease) {
  3104. var easingDecimal = ease || 1;
  3105. this.clear();
  3106. // Draw all the scales
  3107. helpers.each(this.boxes, function(box) {
  3108. box.draw(this.chartArea);
  3109. }, this);
  3110. if (this.scale) {
  3111. this.scale.draw();
  3112. }
  3113. // Clip out the chart area so that anything outside does not draw. This is necessary for zoom and pan to function
  3114. this.chart.ctx.save();
  3115. this.chart.ctx.beginPath();
  3116. this.chart.ctx.rect(this.chartArea.left, this.chartArea.top, this.chartArea.right - this.chartArea.left, this.chartArea.bottom - this.chartArea.top);
  3117. this.chart.ctx.clip();
  3118. // Draw each dataset via its respective controller (reversed to support proper line stacking)
  3119. helpers.each(this.data.datasets, function(dataset, datasetIndex) {
  3120. if (helpers.isDatasetVisible(dataset)) {
  3121. dataset.controller.draw(ease);
  3122. }
  3123. }, null, true);
  3124. // Restore from the clipping operation
  3125. this.chart.ctx.restore();
  3126. // Finally draw the tooltip
  3127. this.tooltip.transition(easingDecimal).draw();
  3128. },
  3129. // Get the single element that was clicked on
  3130. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3131. getElementAtEvent: function(e) {
  3132. var eventPosition = helpers.getRelativePosition(e, this.chart);
  3133. var elementsArray = [];
  3134. helpers.each(this.data.datasets, function(dataset, datasetIndex) {
  3135. if (helpers.isDatasetVisible(dataset)) {
  3136. helpers.each(dataset.metaData, function(element, index) {
  3137. if (element.inRange(eventPosition.x, eventPosition.y)) {
  3138. elementsArray.push(element);
  3139. return elementsArray;
  3140. }
  3141. });
  3142. }
  3143. });
  3144. return elementsArray;
  3145. },
  3146. getElementsAtEvent: function(e) {
  3147. var eventPosition = helpers.getRelativePosition(e, this.chart);
  3148. var elementsArray = [];
  3149. var found = (function() {
  3150. if (this.data.datasets) {
  3151. for (var i = 0; i < this.data.datasets.length; i++) {
  3152. if (helpers.isDatasetVisible(this.data.datasets[i])) {
  3153. for (var j = 0; j < this.data.datasets[i].metaData.length; j++) {
  3154. if (this.data.datasets[i].metaData[j].inRange(eventPosition.x, eventPosition.y)) {
  3155. return this.data.datasets[i].metaData[j];
  3156. }
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }).call(this);
  3162. if (!found) {
  3163. return elementsArray;
  3164. }
  3165. helpers.each(this.data.datasets, function(dataset, dsIndex) {
  3166. if (helpers.isDatasetVisible(dataset)) {
  3167. elementsArray.push(dataset.metaData[found._index]);
  3168. }
  3169. });
  3170. return elementsArray;
  3171. },
  3172. getDatasetAtEvent: function(e) {
  3173. var elementsArray = this.getElementAtEvent(e);
  3174. if (elementsArray.length > 0) {
  3175. elementsArray = this.data.datasets[elementsArray[0]._datasetIndex].metaData;
  3176. }
  3177. return elementsArray;
  3178. },
  3179. generateLegend: function generateLegend() {
  3180. return this.options.legendCallback(this);
  3181. },
  3182. destroy: function destroy() {
  3183. this.clear();
  3184. helpers.unbindEvents(this, this.events);
  3185. helpers.removeResizeListener(this.chart.canvas.parentNode);
  3186. // Reset canvas height/width attributes
  3187. var canvas = this.chart.canvas;
  3188. canvas.width = this.chart.width;
  3189. canvas.height = this.chart.height;
  3190. // if we scaled the canvas in response to a devicePixelRatio !== 1, we need to undo that transform here
  3191. if (this.chart.originalDevicePixelRatio !== undefined) {
  3192. this.chart.ctx.scale(1 / this.chart.originalDevicePixelRatio, 1 / this.chart.originalDevicePixelRatio);
  3193. }
  3194. // Reset to the old style since it may have been changed by the device pixel ratio changes
  3195. canvas.style.width = this.chart.originalCanvasStyleWidth;
  3196. canvas.style.height = this.chart.originalCanvasStyleHeight;
  3197. delete Chart.instances[this.id];
  3198. },
  3199. toBase64Image: function toBase64Image() {
  3200. return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
  3201. },
  3202. initToolTip: function initToolTip() {
  3203. this.tooltip = new Chart.Tooltip({
  3204. _chart: this.chart,
  3205. _chartInstance: this,
  3206. _data: this.data,
  3207. _options: this.options
  3208. }, this);
  3209. },
  3210. bindEvents: function bindEvents() {
  3211. helpers.bindEvents(this, this.options.events, function(evt) {
  3212. this.eventHandler(evt);
  3213. });
  3214. },
  3215. eventHandler: function eventHandler(e) {
  3216. this.lastActive = this.lastActive || [];
  3217. this.lastTooltipActive = this.lastTooltipActive || [];
  3218. // Find Active Elements for hover and tooltips
  3219. if (e.type === 'mouseout') {
  3220. this.active = [];
  3221. this.tooltipActive = [];
  3222. } else {
  3223. var _this = this;
  3224. var getItemsForMode = function(mode) {
  3225. switch (mode) {
  3226. case 'single':
  3227. return _this.getElementAtEvent(e);
  3228. case 'label':
  3229. return _this.getElementsAtEvent(e);
  3230. case 'dataset':
  3231. return _this.getDatasetAtEvent(e);
  3232. default:
  3233. return e;
  3234. }
  3235. };
  3236. this.active = getItemsForMode(this.options.hover.mode);
  3237. this.tooltipActive = getItemsForMode(this.options.tooltips.mode);
  3238. }
  3239. // On Hover hook
  3240. if (this.options.hover.onHover) {
  3241. this.options.hover.onHover.call(this, this.active);
  3242. }
  3243. if (e.type === 'mouseup' || e.type === 'click') {
  3244. if (this.options.onClick) {
  3245. this.options.onClick.call(this, e, this.active);
  3246. }
  3247. if (this.legend && this.legend.handleEvent) {
  3248. this.legend.handleEvent(e);
  3249. }
  3250. }
  3251. var dataset;
  3252. var index;
  3253. // Remove styling for last active (even if it may still be active)
  3254. if (this.lastActive.length) {
  3255. switch (this.options.hover.mode) {
  3256. case 'single':
  3257. this.data.datasets[this.lastActive[0]._datasetIndex].controller.removeHoverStyle(this.lastActive[0], this.lastActive[0]._datasetIndex, this.lastActive[0]._index);
  3258. break;
  3259. case 'label':
  3260. case 'dataset':
  3261. for (var i = 0; i < this.lastActive.length; i++) {
  3262. if (this.lastActive[i])
  3263. this.data.datasets[this.lastActive[i]._datasetIndex].controller.removeHoverStyle(this.lastActive[i], this.lastActive[i]._datasetIndex, this.lastActive[i]._index);
  3264. }
  3265. break;
  3266. default:
  3267. // Don't change anything
  3268. }
  3269. }
  3270. // Built in hover styling
  3271. if (this.active.length && this.options.hover.mode) {
  3272. switch (this.options.hover.mode) {
  3273. case 'single':
  3274. this.data.datasets[this.active[0]._datasetIndex].controller.setHoverStyle(this.active[0]);
  3275. break;
  3276. case 'label':
  3277. case 'dataset':
  3278. for (var j = 0; j < this.active.length; j++) {
  3279. if (this.active[j])
  3280. this.data.datasets[this.active[j]._datasetIndex].controller.setHoverStyle(this.active[j]);
  3281. }
  3282. break;
  3283. default:
  3284. // Don't change anything
  3285. }
  3286. }
  3287. // Built in Tooltips
  3288. if (this.options.tooltips.enabled || this.options.tooltips.custom) {
  3289. // The usual updates
  3290. this.tooltip.initialize();
  3291. this.tooltip._active = this.tooltipActive;
  3292. this.tooltip.update();
  3293. }
  3294. // Hover animations
  3295. this.tooltip.pivot();
  3296. if (!this.animating) {
  3297. var changed;
  3298. helpers.each(this.active, function(element, index) {
  3299. if (element !== this.lastActive[index]) {
  3300. changed = true;
  3301. }
  3302. }, this);
  3303. helpers.each(this.tooltipActive, function(element, index) {
  3304. if (element !== this.lastTooltipActive[index]) {
  3305. changed = true;
  3306. }
  3307. }, this);
  3308. // If entering, leaving, or changing elements, animate the change via pivot
  3309. if ((this.lastActive.length !== this.active.length) ||
  3310. (this.lastTooltipActive.length !== this.tooltipActive.length) ||
  3311. changed) {
  3312. this.stop();
  3313. if (this.options.tooltips.enabled || this.options.tooltips.custom) {
  3314. this.tooltip.update(true);
  3315. }
  3316. // We only need to render at this point. Updating will cause scales to be recomputed generating flicker & using more
  3317. // memory than necessary.
  3318. this.render(this.options.hover.animationDuration, true);
  3319. }
  3320. }
  3321. // Remember Last Actives
  3322. this.lastActive = this.active;
  3323. this.lastTooltipActive = this.tooltipActive;
  3324. return this;
  3325. }
  3326. });
  3327. };
  3328. },{}],23:[function(require,module,exports){
  3329. "use strict";
  3330. module.exports = function(Chart) {
  3331. var helpers = Chart.helpers;
  3332. // Base class for all dataset controllers (line, bar, etc)
  3333. Chart.DatasetController = function(chart, datasetIndex) {
  3334. this.initialize.call(this, chart, datasetIndex);
  3335. };
  3336. helpers.extend(Chart.DatasetController.prototype, {
  3337. initialize: function(chart, datasetIndex) {
  3338. this.chart = chart;
  3339. this.index = datasetIndex;
  3340. this.linkScales();
  3341. this.addElements();
  3342. },
  3343. updateIndex: function(datasetIndex) {
  3344. this.index = datasetIndex;
  3345. },
  3346. linkScales: function() {
  3347. if (!this.getDataset().xAxisID) {
  3348. this.getDataset().xAxisID = this.chart.options.scales.xAxes[0].id;
  3349. }
  3350. if (!this.getDataset().yAxisID) {
  3351. this.getDataset().yAxisID = this.chart.options.scales.yAxes[0].id;
  3352. }
  3353. },
  3354. getDataset: function() {
  3355. return this.chart.data.datasets[this.index];
  3356. },
  3357. getScaleForId: function(scaleID) {
  3358. return this.chart.scales[scaleID];
  3359. },
  3360. reset: function() {
  3361. this.update(true);
  3362. },
  3363. buildOrUpdateElements: function buildOrUpdateElements() {
  3364. // Handle the number of data points changing
  3365. var numData = this.getDataset().data.length;
  3366. var numMetaData = this.getDataset().metaData.length;
  3367. // Make sure that we handle number of datapoints changing
  3368. if (numData < numMetaData) {
  3369. // Remove excess bars for data points that have been removed
  3370. this.getDataset().metaData.splice(numData, numMetaData - numData);
  3371. } else if (numData > numMetaData) {
  3372. // Add new elements
  3373. for (var index = numMetaData; index < numData; ++index) {
  3374. this.addElementAndReset(index);
  3375. }
  3376. }
  3377. },
  3378. // Controllers should implement the following
  3379. addElements: helpers.noop,
  3380. addElementAndReset: helpers.noop,
  3381. draw: helpers.noop,
  3382. removeHoverStyle: helpers.noop,
  3383. setHoverStyle: helpers.noop,
  3384. update: helpers.noop
  3385. });
  3386. Chart.DatasetController.extend = helpers.inherits;
  3387. };
  3388. },{}],24:[function(require,module,exports){
  3389. "use strict";
  3390. module.exports = function(Chart) {
  3391. var helpers = Chart.helpers;
  3392. Chart.elements = {};
  3393. Chart.Element = function(configuration) {
  3394. helpers.extend(this, configuration);
  3395. this.initialize.apply(this, arguments);
  3396. };
  3397. helpers.extend(Chart.Element.prototype, {
  3398. initialize: function() {},
  3399. pivot: function() {
  3400. if (!this._view) {
  3401. this._view = helpers.clone(this._model);
  3402. }
  3403. this._start = helpers.clone(this._view);
  3404. return this;
  3405. },
  3406. transition: function(ease) {
  3407. if (!this._view) {
  3408. this._view = helpers.clone(this._model);
  3409. }
  3410. // No animation -> No Transition
  3411. if (ease === 1) {
  3412. this._view = this._model;
  3413. this._start = null;
  3414. return this;
  3415. }
  3416. if (!this._start) {
  3417. this.pivot();
  3418. }
  3419. helpers.each(this._model, function(value, key) {
  3420. if (key[0] === '_' || !this._model.hasOwnProperty(key)) {
  3421. // Only non-underscored properties
  3422. }
  3423. // Init if doesn't exist
  3424. else if (!this._view.hasOwnProperty(key)) {
  3425. if (typeof value === 'number' && !isNaN(this._view[key])) {
  3426. this._view[key] = value * ease;
  3427. } else {
  3428. this._view[key] = value;
  3429. }
  3430. }
  3431. // No unnecessary computations
  3432. else if (value === this._view[key]) {
  3433. // It's the same! Woohoo!
  3434. }
  3435. // Color transitions if possible
  3436. else if (typeof value === 'string') {
  3437. try {
  3438. var color = helpers.color(this._start[key]).mix(helpers.color(this._model[key]), ease);
  3439. this._view[key] = color.rgbString();
  3440. } catch (err) {
  3441. this._view[key] = value;
  3442. }
  3443. }
  3444. // Number transitions
  3445. else if (typeof value === 'number') {
  3446. var startVal = this._start[key] !== undefined && isNaN(this._start[key]) === false ? this._start[key] : 0;
  3447. this._view[key] = ((this._model[key] - startVal) * ease) + startVal;
  3448. }
  3449. // Everything else
  3450. else {
  3451. this._view[key] = value;
  3452. }
  3453. }, this);
  3454. return this;
  3455. },
  3456. tooltipPosition: function() {
  3457. return {
  3458. x: this._model.x,
  3459. y: this._model.y
  3460. };
  3461. },
  3462. hasValue: function() {
  3463. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  3464. }
  3465. });
  3466. Chart.Element.extend = helpers.inherits;
  3467. };
  3468. },{}],25:[function(require,module,exports){
  3469. /*global window: false */
  3470. /*global document: false */
  3471. "use strict";
  3472. var color = require('chartjs-color');
  3473. module.exports = function(Chart) {
  3474. //Global Chart helpers object for utility methods and classes
  3475. var helpers = Chart.helpers = {};
  3476. //-- Basic js utility methods
  3477. helpers.each = function(loopable, callback, self, reverse) {
  3478. // Check to see if null or undefined firstly.
  3479. var i, len;
  3480. if (helpers.isArray(loopable)) {
  3481. len = loopable.length;
  3482. if (reverse) {
  3483. for (i = len - 1; i >= 0; i--) {
  3484. callback.call(self, loopable[i], i);
  3485. }
  3486. } else {
  3487. for (i = 0; i < len; i++) {
  3488. callback.call(self, loopable[i], i);
  3489. }
  3490. }
  3491. } else if (typeof loopable === 'object') {
  3492. var keys = Object.keys(loopable);
  3493. len = keys.length;
  3494. for (i = 0; i < len; i++) {
  3495. callback.call(self, loopable[keys[i]], keys[i]);
  3496. }
  3497. }
  3498. };
  3499. helpers.clone = function(obj) {
  3500. var objClone = {};
  3501. helpers.each(obj, function(value, key) {
  3502. if (obj.hasOwnProperty(key)) {
  3503. if (helpers.isArray(value)) {
  3504. objClone[key] = value.slice(0);
  3505. } else if (typeof value === 'object' && value !== null) {
  3506. objClone[key] = helpers.clone(value);
  3507. } else {
  3508. objClone[key] = value;
  3509. }
  3510. }
  3511. });
  3512. return objClone;
  3513. };
  3514. helpers.extend = function(base) {
  3515. var len = arguments.length;
  3516. var additionalArgs = [];
  3517. for (var i = 1; i < len; i++) {
  3518. additionalArgs.push(arguments[i]);
  3519. }
  3520. helpers.each(additionalArgs, function(extensionObject) {
  3521. helpers.each(extensionObject, function(value, key) {
  3522. if (extensionObject.hasOwnProperty(key)) {
  3523. base[key] = value;
  3524. }
  3525. });
  3526. });
  3527. return base;
  3528. };
  3529. // Need a special merge function to chart configs since they are now grouped
  3530. helpers.configMerge = function(_base) {
  3531. var base = helpers.clone(_base);
  3532. helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
  3533. helpers.each(extension, function(value, key) {
  3534. if (extension.hasOwnProperty(key)) {
  3535. if (key === 'scales') {
  3536. // Scale config merging is complex. Add out own function here for that
  3537. base[key] = helpers.scaleMerge(base.hasOwnProperty(key) ? base[key] : {}, value);
  3538. } else if (key === 'scale') {
  3539. // Used in polar area & radar charts since there is only one scale
  3540. base[key] = helpers.configMerge(base.hasOwnProperty(key) ? base[key] : {}, Chart.scaleService.getScaleDefaults(value.type), value);
  3541. } else if (base.hasOwnProperty(key) && helpers.isArray(base[key]) && helpers.isArray(value)) {
  3542. // In this case we have an array of objects replacing another array. Rather than doing a strict replace,
  3543. // merge. This allows easy scale option merging
  3544. var baseArray = base[key];
  3545. helpers.each(value, function(valueObj, index) {
  3546. if (index < baseArray.length) {
  3547. if (typeof baseArray[index] === 'object' && baseArray[index] !== null && typeof valueObj === 'object' && valueObj !== null) {
  3548. // Two objects are coming together. Do a merge of them.
  3549. baseArray[index] = helpers.configMerge(baseArray[index], valueObj);
  3550. } else {
  3551. // Just overwrite in this case since there is nothing to merge
  3552. baseArray[index] = valueObj;
  3553. }
  3554. } else {
  3555. baseArray.push(valueObj); // nothing to merge
  3556. }
  3557. });
  3558. } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
  3559. // If we are overwriting an object with an object, do a merge of the properties.
  3560. base[key] = helpers.configMerge(base[key], value);
  3561. } else {
  3562. // can just overwrite the value in this case
  3563. base[key] = value;
  3564. }
  3565. }
  3566. });
  3567. });
  3568. return base;
  3569. };
  3570. helpers.extendDeep = function(_base) {
  3571. return _extendDeep.apply(this, arguments);
  3572. function _extendDeep(dst) {
  3573. helpers.each(arguments, function(obj) {
  3574. if (obj !== dst) {
  3575. helpers.each(obj, function(value, key) {
  3576. if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
  3577. _extendDeep(dst[key], value);
  3578. } else {
  3579. dst[key] = value;
  3580. }
  3581. });
  3582. }
  3583. });
  3584. return dst;
  3585. }
  3586. };
  3587. helpers.scaleMerge = function(_base, extension) {
  3588. var base = helpers.clone(_base);
  3589. helpers.each(extension, function(value, key) {
  3590. if (extension.hasOwnProperty(key)) {
  3591. if (key === 'xAxes' || key === 'yAxes') {
  3592. // These properties are arrays of items
  3593. if (base.hasOwnProperty(key)) {
  3594. helpers.each(value, function(valueObj, index) {
  3595. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  3596. var axisDefaults = Chart.scaleService.getScaleDefaults(axisType);
  3597. if (index >= base[key].length || !base[key][index].type) {
  3598. base[key].push(helpers.configMerge(axisDefaults, valueObj));
  3599. } else if (valueObj.type && valueObj.type !== base[key][index].type) {
  3600. // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
  3601. base[key][index] = helpers.configMerge(base[key][index], axisDefaults, valueObj);
  3602. } else {
  3603. // Type is the same
  3604. base[key][index] = helpers.configMerge(base[key][index], valueObj);
  3605. }
  3606. });
  3607. } else {
  3608. base[key] = [];
  3609. helpers.each(value, function(valueObj) {
  3610. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  3611. base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
  3612. });
  3613. }
  3614. } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
  3615. // If we are overwriting an object with an object, do a merge of the properties.
  3616. base[key] = helpers.configMerge(base[key], value);
  3617. } else {
  3618. // can just overwrite the value in this case
  3619. base[key] = value;
  3620. }
  3621. }
  3622. });
  3623. return base;
  3624. };
  3625. helpers.getValueAtIndexOrDefault = function(value, index, defaultValue) {
  3626. if (value === undefined || value === null) {
  3627. return defaultValue;
  3628. }
  3629. if (helpers.isArray(value)) {
  3630. return index < value.length ? value[index] : defaultValue;
  3631. }
  3632. return value;
  3633. };
  3634. helpers.getValueOrDefault = function(value, defaultValue) {
  3635. return value === undefined ? defaultValue : value;
  3636. };
  3637. helpers.indexOf = function(arrayToSearch, item) {
  3638. if (Array.prototype.indexOf) {
  3639. return arrayToSearch.indexOf(item);
  3640. } else {
  3641. for (var i = 0; i < arrayToSearch.length; i++) {
  3642. if (arrayToSearch[i] === item)
  3643. return i;
  3644. }
  3645. return -1;
  3646. }
  3647. };
  3648. helpers.where = function(collection, filterCallback) {
  3649. var filtered = [];
  3650. helpers.each(collection, function(item) {
  3651. if (filterCallback(item)) {
  3652. filtered.push(item);
  3653. }
  3654. });
  3655. return filtered;
  3656. };
  3657. helpers.findIndex = function(arrayToSearch, callback, thisArg) {
  3658. var index = -1;
  3659. if (Array.prototype.findIndex) {
  3660. index = arrayToSearch.findIndex(callback, thisArg);
  3661. } else {
  3662. for (var i = 0; i < arrayToSearch.length; ++i) {
  3663. thisArg = thisArg !== undefined ? thisArg : arrayToSearch;
  3664. if (callback.call(thisArg, arrayToSearch[i], i, arrayToSearch)) {
  3665. index = i;
  3666. break;
  3667. }
  3668. }
  3669. }
  3670. return index;
  3671. };
  3672. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  3673. // Default to start of the array
  3674. if (startIndex === undefined || startIndex === null) {
  3675. startIndex = -1;
  3676. }
  3677. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  3678. var currentItem = arrayToSearch[i];
  3679. if (filterCallback(currentItem)) {
  3680. return currentItem;
  3681. }
  3682. }
  3683. };
  3684. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  3685. // Default to end of the array
  3686. if (startIndex === undefined || startIndex === null) {
  3687. startIndex = arrayToSearch.length;
  3688. }
  3689. for (var i = startIndex - 1; i >= 0; i--) {
  3690. var currentItem = arrayToSearch[i];
  3691. if (filterCallback(currentItem)) {
  3692. return currentItem;
  3693. }
  3694. }
  3695. };
  3696. helpers.inherits = function(extensions) {
  3697. //Basic javascript inheritance based on the model created in Backbone.js
  3698. var parent = this;
  3699. var ChartElement = (extensions && extensions.hasOwnProperty("constructor")) ? extensions.constructor : function() {
  3700. return parent.apply(this, arguments);
  3701. };
  3702. var Surrogate = function() {
  3703. this.constructor = ChartElement;
  3704. };
  3705. Surrogate.prototype = parent.prototype;
  3706. ChartElement.prototype = new Surrogate();
  3707. ChartElement.extend = helpers.inherits;
  3708. if (extensions) {
  3709. helpers.extend(ChartElement.prototype, extensions);
  3710. }
  3711. ChartElement.__super__ = parent.prototype;
  3712. return ChartElement;
  3713. };
  3714. helpers.noop = function() {};
  3715. helpers.uid = (function() {
  3716. var id = 0;
  3717. return function() {
  3718. return "chart-" + id++;
  3719. };
  3720. })();
  3721. helpers.warn = function(str) {
  3722. //Method for warning of errors
  3723. if (console && typeof console.warn === "function") {
  3724. console.warn(str);
  3725. }
  3726. };
  3727. //-- Math methods
  3728. helpers.isNumber = function(n) {
  3729. return !isNaN(parseFloat(n)) && isFinite(n);
  3730. };
  3731. helpers.almostEquals = function(x, y, epsilon) {
  3732. return Math.abs(x - y) < epsilon;
  3733. };
  3734. helpers.max = function(array) {
  3735. return array.reduce(function(max, value) {
  3736. if (!isNaN(value)) {
  3737. return Math.max(max, value);
  3738. } else {
  3739. return max;
  3740. }
  3741. }, Number.NEGATIVE_INFINITY);
  3742. };
  3743. helpers.min = function(array) {
  3744. return array.reduce(function(min, value) {
  3745. if (!isNaN(value)) {
  3746. return Math.min(min, value);
  3747. } else {
  3748. return min;
  3749. }
  3750. }, Number.POSITIVE_INFINITY);
  3751. };
  3752. helpers.sign = function(x) {
  3753. if (Math.sign) {
  3754. return Math.sign(x);
  3755. } else {
  3756. x = +x; // convert to a number
  3757. if (x === 0 || isNaN(x)) {
  3758. return x;
  3759. }
  3760. return x > 0 ? 1 : -1;
  3761. }
  3762. };
  3763. helpers.log10 = function(x) {
  3764. if (Math.log10) {
  3765. return Math.log10(x);
  3766. } else {
  3767. return Math.log(x) / Math.LN10;
  3768. }
  3769. };
  3770. helpers.toRadians = function(degrees) {
  3771. return degrees * (Math.PI / 180);
  3772. };
  3773. helpers.toDegrees = function(radians) {
  3774. return radians * (180 / Math.PI);
  3775. };
  3776. // Gets the angle from vertical upright to the point about a centre.
  3777. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  3778. var distanceFromXCenter = anglePoint.x - centrePoint.x,
  3779. distanceFromYCenter = anglePoint.y - centrePoint.y,
  3780. radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  3781. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  3782. if (angle < (-0.5 * Math.PI)) {
  3783. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  3784. }
  3785. return {
  3786. angle: angle,
  3787. distance: radialDistanceFromCenter
  3788. };
  3789. };
  3790. helpers.aliasPixel = function(pixelWidth) {
  3791. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  3792. };
  3793. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  3794. //Props to Rob Spencer at scaled innovation for his post on splining between points
  3795. //http://scaledinnovation.com/analytics/splines/aboutSplines.html
  3796. // This function must also respect "skipped" points
  3797. var previous = firstPoint.skip ? middlePoint : firstPoint,
  3798. current = middlePoint,
  3799. next = afterPoint.skip ? middlePoint : afterPoint;
  3800. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  3801. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  3802. var s01 = d01 / (d01 + d12);
  3803. var s12 = d12 / (d01 + d12);
  3804. // If all points are the same, s01 & s02 will be inf
  3805. s01 = isNaN(s01) ? 0 : s01;
  3806. s12 = isNaN(s12) ? 0 : s12;
  3807. var fa = t * s01; // scaling factor for triangle Ta
  3808. var fb = t * s12;
  3809. return {
  3810. previous: {
  3811. x: current.x - fa * (next.x - previous.x),
  3812. y: current.y - fa * (next.y - previous.y)
  3813. },
  3814. next: {
  3815. x: current.x + fb * (next.x - previous.x),
  3816. y: current.y + fb * (next.y - previous.y)
  3817. }
  3818. };
  3819. };
  3820. helpers.nextItem = function(collection, index, loop) {
  3821. if (loop) {
  3822. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  3823. }
  3824. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  3825. };
  3826. helpers.previousItem = function(collection, index, loop) {
  3827. if (loop) {
  3828. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  3829. }
  3830. return index <= 0 ? collection[0] : collection[index - 1];
  3831. };
  3832. // Implementation of the nice number algorithm used in determining where axis labels will go
  3833. helpers.niceNum = function(range, round) {
  3834. var exponent = Math.floor(helpers.log10(range));
  3835. var fraction = range / Math.pow(10, exponent);
  3836. var niceFraction;
  3837. if (round) {
  3838. if (fraction < 1.5) {
  3839. niceFraction = 1;
  3840. } else if (fraction < 3) {
  3841. niceFraction = 2;
  3842. } else if (fraction < 7) {
  3843. niceFraction = 5;
  3844. } else {
  3845. niceFraction = 10;
  3846. }
  3847. } else {
  3848. if (fraction <= 1.0) {
  3849. niceFraction = 1;
  3850. } else if (fraction <= 2) {
  3851. niceFraction = 2;
  3852. } else if (fraction <= 5) {
  3853. niceFraction = 5;
  3854. } else {
  3855. niceFraction = 10;
  3856. }
  3857. }
  3858. return niceFraction * Math.pow(10, exponent);
  3859. };
  3860. //Easing functions adapted from Robert Penner's easing equations
  3861. //http://www.robertpenner.com/easing/
  3862. var easingEffects = helpers.easingEffects = {
  3863. linear: function(t) {
  3864. return t;
  3865. },
  3866. easeInQuad: function(t) {
  3867. return t * t;
  3868. },
  3869. easeOutQuad: function(t) {
  3870. return -1 * t * (t - 2);
  3871. },
  3872. easeInOutQuad: function(t) {
  3873. if ((t /= 1 / 2) < 1) {
  3874. return 1 / 2 * t * t;
  3875. }
  3876. return -1 / 2 * ((--t) * (t - 2) - 1);
  3877. },
  3878. easeInCubic: function(t) {
  3879. return t * t * t;
  3880. },
  3881. easeOutCubic: function(t) {
  3882. return 1 * ((t = t / 1 - 1) * t * t + 1);
  3883. },
  3884. easeInOutCubic: function(t) {
  3885. if ((t /= 1 / 2) < 1) {
  3886. return 1 / 2 * t * t * t;
  3887. }
  3888. return 1 / 2 * ((t -= 2) * t * t + 2);
  3889. },
  3890. easeInQuart: function(t) {
  3891. return t * t * t * t;
  3892. },
  3893. easeOutQuart: function(t) {
  3894. return -1 * ((t = t / 1 - 1) * t * t * t - 1);
  3895. },
  3896. easeInOutQuart: function(t) {
  3897. if ((t /= 1 / 2) < 1) {
  3898. return 1 / 2 * t * t * t * t;
  3899. }
  3900. return -1 / 2 * ((t -= 2) * t * t * t - 2);
  3901. },
  3902. easeInQuint: function(t) {
  3903. return 1 * (t /= 1) * t * t * t * t;
  3904. },
  3905. easeOutQuint: function(t) {
  3906. return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
  3907. },
  3908. easeInOutQuint: function(t) {
  3909. if ((t /= 1 / 2) < 1) {
  3910. return 1 / 2 * t * t * t * t * t;
  3911. }
  3912. return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
  3913. },
  3914. easeInSine: function(t) {
  3915. return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
  3916. },
  3917. easeOutSine: function(t) {
  3918. return 1 * Math.sin(t / 1 * (Math.PI / 2));
  3919. },
  3920. easeInOutSine: function(t) {
  3921. return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
  3922. },
  3923. easeInExpo: function(t) {
  3924. return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
  3925. },
  3926. easeOutExpo: function(t) {
  3927. return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
  3928. },
  3929. easeInOutExpo: function(t) {
  3930. if (t === 0) {
  3931. return 0;
  3932. }
  3933. if (t === 1) {
  3934. return 1;
  3935. }
  3936. if ((t /= 1 / 2) < 1) {
  3937. return 1 / 2 * Math.pow(2, 10 * (t - 1));
  3938. }
  3939. return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
  3940. },
  3941. easeInCirc: function(t) {
  3942. if (t >= 1) {
  3943. return t;
  3944. }
  3945. return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
  3946. },
  3947. easeOutCirc: function(t) {
  3948. return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
  3949. },
  3950. easeInOutCirc: function(t) {
  3951. if ((t /= 1 / 2) < 1) {
  3952. return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
  3953. }
  3954. return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  3955. },
  3956. easeInElastic: function(t) {
  3957. var s = 1.70158;
  3958. var p = 0;
  3959. var a = 1;
  3960. if (t === 0) {
  3961. return 0;
  3962. }
  3963. if ((t /= 1) === 1) {
  3964. return 1;
  3965. }
  3966. if (!p) {
  3967. p = 1 * 0.3;
  3968. }
  3969. if (a < Math.abs(1)) {
  3970. a = 1;
  3971. s = p / 4;
  3972. } else {
  3973. s = p / (2 * Math.PI) * Math.asin(1 / a);
  3974. }
  3975. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  3976. },
  3977. easeOutElastic: function(t) {
  3978. var s = 1.70158;
  3979. var p = 0;
  3980. var a = 1;
  3981. if (t === 0) {
  3982. return 0;
  3983. }
  3984. if ((t /= 1) === 1) {
  3985. return 1;
  3986. }
  3987. if (!p) {
  3988. p = 1 * 0.3;
  3989. }
  3990. if (a < Math.abs(1)) {
  3991. a = 1;
  3992. s = p / 4;
  3993. } else {
  3994. s = p / (2 * Math.PI) * Math.asin(1 / a);
  3995. }
  3996. return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
  3997. },
  3998. easeInOutElastic: function(t) {
  3999. var s = 1.70158;
  4000. var p = 0;
  4001. var a = 1;
  4002. if (t === 0) {
  4003. return 0;
  4004. }
  4005. if ((t /= 1 / 2) === 2) {
  4006. return 1;
  4007. }
  4008. if (!p) {
  4009. p = 1 * (0.3 * 1.5);
  4010. }
  4011. if (a < Math.abs(1)) {
  4012. a = 1;
  4013. s = p / 4;
  4014. } else {
  4015. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4016. }
  4017. if (t < 1) {
  4018. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4019. }
  4020. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
  4021. },
  4022. easeInBack: function(t) {
  4023. var s = 1.70158;
  4024. return 1 * (t /= 1) * t * ((s + 1) * t - s);
  4025. },
  4026. easeOutBack: function(t) {
  4027. var s = 1.70158;
  4028. return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
  4029. },
  4030. easeInOutBack: function(t) {
  4031. var s = 1.70158;
  4032. if ((t /= 1 / 2) < 1) {
  4033. return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
  4034. }
  4035. return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  4036. },
  4037. easeInBounce: function(t) {
  4038. return 1 - easingEffects.easeOutBounce(1 - t);
  4039. },
  4040. easeOutBounce: function(t) {
  4041. if ((t /= 1) < (1 / 2.75)) {
  4042. return 1 * (7.5625 * t * t);
  4043. } else if (t < (2 / 2.75)) {
  4044. return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
  4045. } else if (t < (2.5 / 2.75)) {
  4046. return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
  4047. } else {
  4048. return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
  4049. }
  4050. },
  4051. easeInOutBounce: function(t) {
  4052. if (t < 1 / 2) {
  4053. return easingEffects.easeInBounce(t * 2) * 0.5;
  4054. }
  4055. return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
  4056. }
  4057. };
  4058. //Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4059. helpers.requestAnimFrame = (function() {
  4060. return window.requestAnimationFrame ||
  4061. window.webkitRequestAnimationFrame ||
  4062. window.mozRequestAnimationFrame ||
  4063. window.oRequestAnimationFrame ||
  4064. window.msRequestAnimationFrame ||
  4065. function(callback) {
  4066. return window.setTimeout(callback, 1000 / 60);
  4067. };
  4068. })();
  4069. helpers.cancelAnimFrame = (function() {
  4070. return window.cancelAnimationFrame ||
  4071. window.webkitCancelAnimationFrame ||
  4072. window.mozCancelAnimationFrame ||
  4073. window.oCancelAnimationFrame ||
  4074. window.msCancelAnimationFrame ||
  4075. function(callback) {
  4076. return window.clearTimeout(callback, 1000 / 60);
  4077. };
  4078. })();
  4079. //-- DOM methods
  4080. helpers.getRelativePosition = function(evt, chart) {
  4081. var mouseX, mouseY;
  4082. var e = evt.originalEvent || evt,
  4083. canvas = evt.currentTarget || evt.srcElement,
  4084. boundingRect = canvas.getBoundingClientRect();
  4085. if (e.touches && e.touches.length > 0) {
  4086. mouseX = e.touches[0].clientX;
  4087. mouseY = e.touches[0].clientY;
  4088. } else {
  4089. mouseX = e.clientX;
  4090. mouseY = e.clientY;
  4091. }
  4092. // Scale mouse coordinates into canvas coordinates
  4093. // by following the pattern laid out by 'jerryj' in the comments of
  4094. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4095. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4096. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4097. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4098. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4099. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4100. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4101. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4102. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4103. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4104. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4105. return {
  4106. x: mouseX,
  4107. y: mouseY
  4108. };
  4109. };
  4110. helpers.addEvent = function(node, eventType, method) {
  4111. if (node.addEventListener) {
  4112. node.addEventListener(eventType, method);
  4113. } else if (node.attachEvent) {
  4114. node.attachEvent("on" + eventType, method);
  4115. } else {
  4116. node["on" + eventType] = method;
  4117. }
  4118. };
  4119. helpers.removeEvent = function(node, eventType, handler) {
  4120. if (node.removeEventListener) {
  4121. node.removeEventListener(eventType, handler, false);
  4122. } else if (node.detachEvent) {
  4123. node.detachEvent("on" + eventType, handler);
  4124. } else {
  4125. node["on" + eventType] = helpers.noop;
  4126. }
  4127. };
  4128. helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
  4129. // Create the events object if it's not already present
  4130. if (!chartInstance.events)
  4131. chartInstance.events = {};
  4132. helpers.each(arrayOfEvents, function(eventName) {
  4133. chartInstance.events[eventName] = function() {
  4134. handler.apply(chartInstance, arguments);
  4135. };
  4136. helpers.addEvent(chartInstance.chart.canvas, eventName, chartInstance.events[eventName]);
  4137. });
  4138. };
  4139. helpers.unbindEvents = function(chartInstance, arrayOfEvents) {
  4140. helpers.each(arrayOfEvents, function(handler, eventName) {
  4141. helpers.removeEvent(chartInstance.chart.canvas, eventName, handler);
  4142. });
  4143. };
  4144. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4145. function parseMaxStyle(styleValue, node, parentProperty) {
  4146. var valueInPixels;
  4147. if (typeof(styleValue) === 'string') {
  4148. valueInPixels = parseInt(styleValue, 10);
  4149. if (styleValue.indexOf('%') != -1) {
  4150. // percentage * size in dimension
  4151. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4152. }
  4153. } else {
  4154. valueInPixels = styleValue;
  4155. }
  4156. return valueInPixels;
  4157. }
  4158. // Private helper to get a constraint dimension
  4159. // @param domNode : the node to check the constraint on
  4160. // @param maxStyle : the style that defines the maximum for the direction we are using (max-width / max-height)
  4161. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4162. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4163. var constrainedDimension;
  4164. var constrainedNode = document.defaultView.getComputedStyle(domNode)[maxStyle];
  4165. var constrainedContainer = document.defaultView.getComputedStyle(domNode.parentNode)[maxStyle];
  4166. var hasCNode = constrainedNode !== null && constrainedNode !== "none";
  4167. var hasCContainer = constrainedContainer !== null && constrainedContainer !== "none";
  4168. if (hasCNode || hasCContainer) {
  4169. constrainedDimension = Math.min((hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : Number.POSITIVE_INFINITY), (hasCContainer ? parseMaxStyle(constrainedContainer, domNode.parentNode, percentageProperty) : Number.POSITIVE_INFINITY));
  4170. }
  4171. return constrainedDimension;
  4172. }
  4173. // returns Number or undefined if no constraint
  4174. helpers.getConstraintWidth = function(domNode) {
  4175. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4176. };
  4177. // returns Number or undefined if no constraint
  4178. helpers.getConstraintHeight = function(domNode) {
  4179. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4180. };
  4181. helpers.getMaximumWidth = function(domNode) {
  4182. var container = domNode.parentNode;
  4183. var padding = parseInt(helpers.getStyle(container, 'padding-left')) + parseInt(helpers.getStyle(container, 'padding-right'));
  4184. var w = container.clientWidth - padding;
  4185. var cw = helpers.getConstraintWidth(domNode);
  4186. if (cw !== undefined) {
  4187. w = Math.min(w, cw);
  4188. }
  4189. return w;
  4190. };
  4191. helpers.getMaximumHeight = function(domNode) {
  4192. var container = domNode.parentNode;
  4193. var padding = parseInt(helpers.getStyle(container, 'padding-top')) + parseInt(helpers.getStyle(container, 'padding-bottom'));
  4194. var h = container.clientHeight - padding;
  4195. var ch = helpers.getConstraintHeight(domNode);
  4196. if (ch !== undefined) {
  4197. h = Math.min(h, ch);
  4198. }
  4199. return h;
  4200. };
  4201. helpers.getStyle = function(el, property) {
  4202. return el.currentStyle ?
  4203. el.currentStyle[property] :
  4204. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4205. };
  4206. helpers.retinaScale = function(chart) {
  4207. var ctx = chart.ctx;
  4208. var width = chart.canvas.width;
  4209. var height = chart.canvas.height;
  4210. var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1;
  4211. if (pixelRatio !== 1) {
  4212. ctx.canvas.height = height * pixelRatio;
  4213. ctx.canvas.width = width * pixelRatio;
  4214. ctx.scale(pixelRatio, pixelRatio);
  4215. // Store the device pixel ratio so that we can go backwards in `destroy`.
  4216. // The devicePixelRatio changes with zoom, so there are no guarantees that it is the same
  4217. // when destroy is called
  4218. chart.originalDevicePixelRatio = chart.originalDevicePixelRatio || pixelRatio;
  4219. }
  4220. ctx.canvas.style.width = width + 'px';
  4221. ctx.canvas.style.height = height + 'px';
  4222. };
  4223. //-- Canvas methods
  4224. helpers.clear = function(chart) {
  4225. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  4226. };
  4227. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  4228. return fontStyle + " " + pixelSize + "px " + fontFamily;
  4229. };
  4230. helpers.longestText = function(ctx, font, arrayOfStrings, cache) {
  4231. cache = cache || {};
  4232. cache.data = cache.data || {};
  4233. cache.garbageCollect = cache.garbageCollect || [];
  4234. if (cache.font !== font) {
  4235. cache.data = {};
  4236. cache.garbageCollect = [];
  4237. cache.font = font;
  4238. }
  4239. ctx.font = font;
  4240. var longest = 0;
  4241. helpers.each(arrayOfStrings, function(string) {
  4242. // Undefined strings should not be measured
  4243. if (string !== undefined && string !== null) {
  4244. var textWidth = cache.data[string];
  4245. if (!textWidth) {
  4246. textWidth = cache.data[string] = ctx.measureText(string).width;
  4247. cache.garbageCollect.push(string);
  4248. }
  4249. if (textWidth > longest) {
  4250. longest = textWidth;
  4251. }
  4252. }
  4253. });
  4254. var gcLen = cache.garbageCollect.length / 2;
  4255. if (gcLen > arrayOfStrings.length) {
  4256. for (var i = 0; i < gcLen; i++) {
  4257. delete cache.data[cache.garbageCollect[i]];
  4258. }
  4259. cache.garbageCollect.splice(0, gcLen);
  4260. }
  4261. return longest;
  4262. };
  4263. helpers.drawRoundedRectangle = function(ctx, x, y, width, height, radius) {
  4264. ctx.beginPath();
  4265. ctx.moveTo(x + radius, y);
  4266. ctx.lineTo(x + width - radius, y);
  4267. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  4268. ctx.lineTo(x + width, y + height - radius);
  4269. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  4270. ctx.lineTo(x + radius, y + height);
  4271. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  4272. ctx.lineTo(x, y + radius);
  4273. ctx.quadraticCurveTo(x, y, x + radius, y);
  4274. ctx.closePath();
  4275. };
  4276. helpers.color = function(c) {
  4277. if (!color) {
  4278. console.log('Color.js not found!');
  4279. return c;
  4280. }
  4281. /* global CanvasGradient */
  4282. if (c instanceof CanvasGradient) {
  4283. return color(Chart.defaults.global.defaultColor);
  4284. }
  4285. return color(c);
  4286. };
  4287. helpers.addResizeListener = function(node, callback) {
  4288. // Hide an iframe before the node
  4289. var hiddenIframe = document.createElement('iframe');
  4290. var hiddenIframeClass = 'chartjs-hidden-iframe';
  4291. if (hiddenIframe.classlist) {
  4292. // can use classlist
  4293. hiddenIframe.classlist.add(hiddenIframeClass);
  4294. } else {
  4295. hiddenIframe.setAttribute('class', hiddenIframeClass);
  4296. }
  4297. // Set the style
  4298. hiddenIframe.style.width = '100%';
  4299. hiddenIframe.style.display = 'block';
  4300. hiddenIframe.style.border = 0;
  4301. hiddenIframe.style.height = 0;
  4302. hiddenIframe.style.margin = 0;
  4303. hiddenIframe.style.position = 'absolute';
  4304. hiddenIframe.style.left = 0;
  4305. hiddenIframe.style.right = 0;
  4306. hiddenIframe.style.top = 0;
  4307. hiddenIframe.style.bottom = 0;
  4308. // Insert the iframe so that contentWindow is available
  4309. node.insertBefore(hiddenIframe, node.firstChild);
  4310. (hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
  4311. if (callback) {
  4312. callback();
  4313. }
  4314. };
  4315. };
  4316. helpers.removeResizeListener = function(node) {
  4317. var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');
  4318. // Remove the resize detect iframe
  4319. if (hiddenIframe) {
  4320. hiddenIframe.parentNode.removeChild(hiddenIframe);
  4321. }
  4322. };
  4323. helpers.isArray = function(obj) {
  4324. if (!Array.isArray) {
  4325. return Object.prototype.toString.call(obj) === '[object Array]';
  4326. }
  4327. return Array.isArray(obj);
  4328. };
  4329. helpers.pushAllIfDefined = function(element, array) {
  4330. if (typeof element === "undefined") {
  4331. return;
  4332. }
  4333. if (helpers.isArray(element)) {
  4334. array.push.apply(array, element);
  4335. } else {
  4336. array.push(element);
  4337. }
  4338. };
  4339. helpers.isDatasetVisible = function(dataset) {
  4340. return !dataset.hidden;
  4341. };
  4342. helpers.callCallback = function(fn, args, _tArg) {
  4343. if (fn && typeof fn.call === 'function') {
  4344. fn.apply(_tArg, args);
  4345. }
  4346. };
  4347. };
  4348. },{"chartjs-color":6}],26:[function(require,module,exports){
  4349. "use strict";
  4350. module.exports = function() {
  4351. //Occupy the global variable of Chart, and create a simple base class
  4352. var Chart = function(context, config) {
  4353. this.config = config;
  4354. // Support a jQuery'd canvas element
  4355. if (context.length && context[0].getContext) {
  4356. context = context[0];
  4357. }
  4358. // Support a canvas domnode
  4359. if (context.getContext) {
  4360. context = context.getContext("2d");
  4361. }
  4362. this.ctx = context;
  4363. this.canvas = context.canvas;
  4364. // Figure out what the size of the chart will be.
  4365. // If the canvas has a specified width and height, we use those else
  4366. // we look to see if the canvas node has a CSS width and height.
  4367. // If there is still no height, fill the parent container
  4368. this.width = context.canvas.width || parseInt(Chart.helpers.getStyle(context.canvas, 'width')) || Chart.helpers.getMaximumWidth(context.canvas);
  4369. this.height = context.canvas.height || parseInt(Chart.helpers.getStyle(context.canvas, 'height')) || Chart.helpers.getMaximumHeight(context.canvas);
  4370. this.aspectRatio = this.width / this.height;
  4371. if (isNaN(this.aspectRatio) || isFinite(this.aspectRatio) === false) {
  4372. // If the canvas has no size, try and figure out what the aspect ratio will be.
  4373. // Some charts prefer square canvases (pie, radar, etc). If that is specified, use that
  4374. // else use the canvas default ratio of 2
  4375. this.aspectRatio = config.aspectRatio !== undefined ? config.aspectRatio : 2;
  4376. }
  4377. // Store the original style of the element so we can set it back
  4378. this.originalCanvasStyleWidth = context.canvas.style.width;
  4379. this.originalCanvasStyleHeight = context.canvas.style.height;
  4380. // High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
  4381. Chart.helpers.retinaScale(this);
  4382. if (config) {
  4383. this.controller = new Chart.Controller(this);
  4384. }
  4385. // Always bind this so that if the responsive state changes we still work
  4386. var _this = this;
  4387. Chart.helpers.addResizeListener(context.canvas.parentNode, function() {
  4388. if (_this.controller && _this.controller.config.options.responsive) {
  4389. _this.controller.resize();
  4390. }
  4391. });
  4392. return this.controller ? this.controller : this;
  4393. };
  4394. //Globally expose the defaults to allow for user updating/changing
  4395. Chart.defaults = {
  4396. global: {
  4397. responsive: true,
  4398. responsiveAnimationDuration: 0,
  4399. maintainAspectRatio: true,
  4400. events: ["mousemove", "mouseout", "click", "touchstart", "touchmove"],
  4401. hover: {
  4402. onHover: null,
  4403. mode: 'single',
  4404. animationDuration: 400
  4405. },
  4406. onClick: null,
  4407. defaultColor: 'rgba(0,0,0,0.1)',
  4408. defaultFontColor: '#666',
  4409. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  4410. defaultFontSize: 12,
  4411. defaultFontStyle: 'normal',
  4412. showLines: true,
  4413. // Element defaults defined in element extensions
  4414. elements: {},
  4415. // Legend callback string
  4416. legendCallback: function(chart) {
  4417. var text = [];
  4418. text.push('<ul class="' + chart.id + '-legend">');
  4419. for (var i = 0; i < chart.data.datasets.length; i++) {
  4420. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  4421. if (chart.data.datasets[i].label) {
  4422. text.push(chart.data.datasets[i].label);
  4423. }
  4424. text.push('</li>');
  4425. }
  4426. text.push('</ul>');
  4427. return text.join("");
  4428. }
  4429. }
  4430. };
  4431. return Chart;
  4432. };
  4433. },{}],27:[function(require,module,exports){
  4434. "use strict";
  4435. module.exports = function(Chart) {
  4436. var helpers = Chart.helpers;
  4437. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  4438. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  4439. // It is this service's responsibility of carrying out that layout.
  4440. Chart.layoutService = {
  4441. defaults: {},
  4442. // Register a box to a chartInstance. A box is simply a reference to an object that requires layout. eg. Scales, Legend, Plugins.
  4443. addBox: function(chartInstance, box) {
  4444. if (!chartInstance.boxes) {
  4445. chartInstance.boxes = [];
  4446. }
  4447. chartInstance.boxes.push(box);
  4448. },
  4449. removeBox: function(chartInstance, box) {
  4450. if (!chartInstance.boxes) {
  4451. return;
  4452. }
  4453. chartInstance.boxes.splice(chartInstance.boxes.indexOf(box), 1);
  4454. },
  4455. // The most important function
  4456. update: function(chartInstance, width, height) {
  4457. if (!chartInstance) {
  4458. return;
  4459. }
  4460. var xPadding = 0;
  4461. var yPadding = 0;
  4462. var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
  4463. return box.options.position === "left";
  4464. });
  4465. var rightBoxes = helpers.where(chartInstance.boxes, function(box) {
  4466. return box.options.position === "right";
  4467. });
  4468. var topBoxes = helpers.where(chartInstance.boxes, function(box) {
  4469. return box.options.position === "top";
  4470. });
  4471. var bottomBoxes = helpers.where(chartInstance.boxes, function(box) {
  4472. return box.options.position === "bottom";
  4473. });
  4474. // Boxes that overlay the chartarea such as the radialLinear scale
  4475. var chartAreaBoxes = helpers.where(chartInstance.boxes, function(box) {
  4476. return box.options.position === "chartArea";
  4477. });
  4478. function fullWidthSorter(a, b) {
  4479. }
  4480. // Ensure that full width boxes are at the very top / bottom
  4481. topBoxes.sort(function(a, b) {
  4482. return (b.options.fullWidth ? 1 : 0) - (a.options.fullWidth ? 1 : 0);
  4483. });
  4484. bottomBoxes.sort(function(a, b) {
  4485. return (a.options.fullWidth ? 1 : 0) - (b.options.fullWidth ? 1 : 0);
  4486. });
  4487. // Essentially we now have any number of boxes on each of the 4 sides.
  4488. // Our canvas looks like the following.
  4489. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  4490. // B1 is the bottom axis
  4491. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  4492. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  4493. // an error will be thrown.
  4494. //
  4495. // |----------------------------------------------------|
  4496. // | T1 (Full Width) |
  4497. // |----------------------------------------------------|
  4498. // | | | T2 | |
  4499. // | |----|-------------------------------------|----|
  4500. // | | | C1 | | C2 | |
  4501. // | | |----| |----| |
  4502. // | | | | |
  4503. // | L1 | L2 | ChartArea (C0) | R1 |
  4504. // | | | | |
  4505. // | | |----| |----| |
  4506. // | | | C3 | | C4 | |
  4507. // | |----|-------------------------------------|----|
  4508. // | | | B1 | |
  4509. // |----------------------------------------------------|
  4510. // | B2 (Full Width) |
  4511. // |----------------------------------------------------|
  4512. //
  4513. // What we do to find the best sizing, we do the following
  4514. // 1. Determine the minimum size of the chart area.
  4515. // 2. Split the remaining width equally between each vertical axis
  4516. // 3. Split the remaining height equally between each horizontal axis
  4517. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  4518. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  4519. // 6. Refit each axis
  4520. // 7. Position each axis in the final location
  4521. // 8. Tell the chart the final location of the chart area
  4522. // 9. Tell any axes that overlay the chart area the positions of the chart area
  4523. // Step 1
  4524. var chartWidth = width - (2 * xPadding);
  4525. var chartHeight = height - (2 * yPadding);
  4526. var chartAreaWidth = chartWidth / 2; // min 50%
  4527. var chartAreaHeight = chartHeight / 2; // min 50%
  4528. // Step 2
  4529. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  4530. // Step 3
  4531. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  4532. // Step 4
  4533. var maxChartAreaWidth = chartWidth;
  4534. var maxChartAreaHeight = chartHeight;
  4535. var minBoxSizes = [];
  4536. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  4537. function getMinimumBoxSize(box) {
  4538. var minSize;
  4539. var isHorizontal = box.isHorizontal();
  4540. if (isHorizontal) {
  4541. minSize = box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  4542. maxChartAreaHeight -= minSize.height;
  4543. } else {
  4544. minSize = box.update(verticalBoxWidth, chartAreaHeight);
  4545. maxChartAreaWidth -= minSize.width;
  4546. }
  4547. minBoxSizes.push({
  4548. horizontal: isHorizontal,
  4549. minSize: minSize,
  4550. box: box
  4551. });
  4552. }
  4553. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  4554. // be if the axes are drawn at their minimum sizes.
  4555. // Steps 5 & 6
  4556. var totalLeftBoxesWidth = xPadding;
  4557. var totalRightBoxesWidth = xPadding;
  4558. var totalTopBoxesHeight = yPadding;
  4559. var totalBottomBoxesHeight = yPadding;
  4560. // Update, and calculate the left and right margins for the horizontal boxes
  4561. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  4562. helpers.each(leftBoxes, function(box) {
  4563. totalLeftBoxesWidth += box.width;
  4564. });
  4565. helpers.each(rightBoxes, function(box) {
  4566. totalRightBoxesWidth += box.width;
  4567. });
  4568. // Set the Left and Right margins for the horizontal boxes
  4569. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  4570. // Function to fit a box
  4571. function fitBox(box) {
  4572. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
  4573. return minBoxSize.box === box;
  4574. });
  4575. if (minBoxSize) {
  4576. if (box.isHorizontal()) {
  4577. var scaleMargin = {
  4578. left: totalLeftBoxesWidth,
  4579. right: totalRightBoxesWidth,
  4580. top: 0,
  4581. bottom: 0
  4582. };
  4583. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  4584. // on the margin. Sometimes they need to increase in size slightly
  4585. box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  4586. } else {
  4587. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  4588. }
  4589. }
  4590. }
  4591. // Figure out how much margin is on the top and bottom of the vertical boxes
  4592. helpers.each(topBoxes, function(box) {
  4593. totalTopBoxesHeight += box.height;
  4594. });
  4595. helpers.each(bottomBoxes, function(box) {
  4596. totalBottomBoxesHeight += box.height;
  4597. });
  4598. // Let the left layout know the final margin
  4599. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  4600. function finalFitVerticalBox(box) {
  4601. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
  4602. return minBoxSize.box === box;
  4603. });
  4604. var scaleMargin = {
  4605. left: 0,
  4606. right: 0,
  4607. top: totalTopBoxesHeight,
  4608. bottom: totalBottomBoxesHeight
  4609. };
  4610. if (minBoxSize) {
  4611. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  4612. }
  4613. }
  4614. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  4615. totalLeftBoxesWidth = xPadding;
  4616. totalRightBoxesWidth = xPadding;
  4617. totalTopBoxesHeight = yPadding;
  4618. totalBottomBoxesHeight = yPadding;
  4619. helpers.each(leftBoxes, function(box) {
  4620. totalLeftBoxesWidth += box.width;
  4621. });
  4622. helpers.each(rightBoxes, function(box) {
  4623. totalRightBoxesWidth += box.width;
  4624. });
  4625. helpers.each(topBoxes, function(box) {
  4626. totalTopBoxesHeight += box.height;
  4627. });
  4628. helpers.each(bottomBoxes, function(box) {
  4629. totalBottomBoxesHeight += box.height;
  4630. });
  4631. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  4632. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  4633. // without calling `fit` again
  4634. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  4635. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  4636. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  4637. helpers.each(leftBoxes, function(box) {
  4638. box.height = newMaxChartAreaHeight;
  4639. });
  4640. helpers.each(rightBoxes, function(box) {
  4641. box.height = newMaxChartAreaHeight;
  4642. });
  4643. helpers.each(topBoxes, function(box) {
  4644. box.width = newMaxChartAreaWidth;
  4645. });
  4646. helpers.each(bottomBoxes, function(box) {
  4647. box.width = newMaxChartAreaWidth;
  4648. });
  4649. maxChartAreaHeight = newMaxChartAreaHeight;
  4650. maxChartAreaWidth = newMaxChartAreaWidth;
  4651. }
  4652. // Step 7 - Position the boxes
  4653. var left = xPadding;
  4654. var top = yPadding;
  4655. var right = 0;
  4656. var bottom = 0;
  4657. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  4658. // Account for chart width and height
  4659. left += maxChartAreaWidth;
  4660. top += maxChartAreaHeight;
  4661. helpers.each(rightBoxes, placeBox);
  4662. helpers.each(bottomBoxes, placeBox);
  4663. function placeBox(box) {
  4664. if (box.isHorizontal()) {
  4665. box.left = box.options.fullWidth ? xPadding : totalLeftBoxesWidth;
  4666. box.right = box.options.fullWidth ? width - xPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  4667. box.top = top;
  4668. box.bottom = top + box.height;
  4669. // Move to next point
  4670. top = box.bottom;
  4671. } else {
  4672. box.left = left;
  4673. box.right = left + box.width;
  4674. box.top = totalTopBoxesHeight;
  4675. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  4676. // Move to next point
  4677. left = box.right;
  4678. }
  4679. }
  4680. // Step 8
  4681. chartInstance.chartArea = {
  4682. left: totalLeftBoxesWidth,
  4683. top: totalTopBoxesHeight,
  4684. right: totalLeftBoxesWidth + maxChartAreaWidth,
  4685. bottom: totalTopBoxesHeight + maxChartAreaHeight
  4686. };
  4687. // Step 9
  4688. helpers.each(chartAreaBoxes, function(box) {
  4689. box.left = chartInstance.chartArea.left;
  4690. box.top = chartInstance.chartArea.top;
  4691. box.right = chartInstance.chartArea.right;
  4692. box.bottom = chartInstance.chartArea.bottom;
  4693. box.update(maxChartAreaWidth, maxChartAreaHeight);
  4694. });
  4695. }
  4696. };
  4697. };
  4698. },{}],28:[function(require,module,exports){
  4699. "use strict";
  4700. module.exports = function(Chart) {
  4701. var helpers = Chart.helpers;
  4702. Chart.defaults.global.legend = {
  4703. display: true,
  4704. position: 'top',
  4705. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  4706. reverse: false,
  4707. // a callback that will handle
  4708. onClick: function(e, legendItem) {
  4709. var dataset = this.chart.data.datasets[legendItem.datasetIndex];
  4710. dataset.hidden = !dataset.hidden;
  4711. // We hid a dataset ... rerender the chart
  4712. this.chart.update();
  4713. },
  4714. labels: {
  4715. boxWidth: 40,
  4716. padding: 10,
  4717. // Generates labels shown in the legend
  4718. // Valid properties to return:
  4719. // text : text to display
  4720. // fillStyle : fill of coloured box
  4721. // strokeStyle: stroke of coloured box
  4722. // hidden : if this legend item refers to a hidden item
  4723. // lineCap : cap style for line
  4724. // lineDash
  4725. // lineDashOffset :
  4726. // lineJoin :
  4727. // lineWidth :
  4728. generateLabels: function(data) {
  4729. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  4730. return {
  4731. text: dataset.label,
  4732. fillStyle: dataset.backgroundColor,
  4733. hidden: dataset.hidden,
  4734. lineCap: dataset.borderCapStyle,
  4735. lineDash: dataset.borderDash,
  4736. lineDashOffset: dataset.borderDashOffset,
  4737. lineJoin: dataset.borderJoinStyle,
  4738. lineWidth: dataset.borderWidth,
  4739. strokeStyle: dataset.borderColor,
  4740. // Below is extra data used for toggling the datasets
  4741. datasetIndex: i
  4742. };
  4743. }, this) : [];
  4744. }
  4745. }
  4746. };
  4747. Chart.Legend = Chart.Element.extend({
  4748. initialize: function(config) {
  4749. helpers.extend(this, config);
  4750. // Contains hit boxes for each dataset (in dataset order)
  4751. this.legendHitBoxes = [];
  4752. // Are we in doughnut mode which has a different data type
  4753. this.doughnutMode = false;
  4754. },
  4755. // These methods are ordered by lifecyle. Utilities then follow.
  4756. // Any function defined here is inherited by all legend types.
  4757. // Any function can be extended by the legend type
  4758. beforeUpdate: helpers.noop,
  4759. update: function(maxWidth, maxHeight, margins) {
  4760. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  4761. this.beforeUpdate();
  4762. // Absorb the master measurements
  4763. this.maxWidth = maxWidth;
  4764. this.maxHeight = maxHeight;
  4765. this.margins = margins;
  4766. // Dimensions
  4767. this.beforeSetDimensions();
  4768. this.setDimensions();
  4769. this.afterSetDimensions();
  4770. // Labels
  4771. this.beforeBuildLabels();
  4772. this.buildLabels();
  4773. this.afterBuildLabels();
  4774. // Fit
  4775. this.beforeFit();
  4776. this.fit();
  4777. this.afterFit();
  4778. //
  4779. this.afterUpdate();
  4780. return this.minSize;
  4781. },
  4782. afterUpdate: helpers.noop,
  4783. //
  4784. beforeSetDimensions: helpers.noop,
  4785. setDimensions: function() {
  4786. // Set the unconstrained dimension before label rotation
  4787. if (this.isHorizontal()) {
  4788. // Reset position before calculating rotation
  4789. this.width = this.maxWidth;
  4790. this.left = 0;
  4791. this.right = this.width;
  4792. } else {
  4793. this.height = this.maxHeight;
  4794. // Reset position before calculating rotation
  4795. this.top = 0;
  4796. this.bottom = this.height;
  4797. }
  4798. // Reset padding
  4799. this.paddingLeft = 0;
  4800. this.paddingTop = 0;
  4801. this.paddingRight = 0;
  4802. this.paddingBottom = 0;
  4803. // Reset minSize
  4804. this.minSize = {
  4805. width: 0,
  4806. height: 0
  4807. };
  4808. },
  4809. afterSetDimensions: helpers.noop,
  4810. //
  4811. beforeBuildLabels: helpers.noop,
  4812. buildLabels: function() {
  4813. this.legendItems = this.options.labels.generateLabels.call(this, this.chart.data);
  4814. if(this.options.reverse){
  4815. this.legendItems.reverse();
  4816. }
  4817. },
  4818. afterBuildLabels: helpers.noop,
  4819. //
  4820. beforeFit: helpers.noop,
  4821. fit: function() {
  4822. var ctx = this.ctx;
  4823. var fontSize = helpers.getValueOrDefault(this.options.labels.fontSize, Chart.defaults.global.defaultFontSize);
  4824. var fontStyle = helpers.getValueOrDefault(this.options.labels.fontStyle, Chart.defaults.global.defaultFontStyle);
  4825. var fontFamily = helpers.getValueOrDefault(this.options.labels.fontFamily, Chart.defaults.global.defaultFontFamily);
  4826. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  4827. // Reset hit boxes
  4828. this.legendHitBoxes = [];
  4829. // Width
  4830. if (this.isHorizontal()) {
  4831. this.minSize.width = this.maxWidth; // fill all the width
  4832. } else {
  4833. this.minSize.width = this.options.display ? 10 : 0;
  4834. }
  4835. // height
  4836. if (this.isHorizontal()) {
  4837. this.minSize.height = this.options.display ? 10 : 0;
  4838. } else {
  4839. this.minSize.height = this.maxHeight; // fill all the height
  4840. }
  4841. // Increase sizes here
  4842. if (this.options.display) {
  4843. if (this.isHorizontal()) {
  4844. // Labels
  4845. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  4846. this.lineWidths = [0];
  4847. var totalHeight = this.legendItems.length ? fontSize + (this.options.labels.padding) : 0;
  4848. ctx.textAlign = "left";
  4849. ctx.textBaseline = 'top';
  4850. ctx.font = labelFont;
  4851. helpers.each(this.legendItems, function(legendItem, i) {
  4852. var width = this.options.labels.boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  4853. if (this.lineWidths[this.lineWidths.length - 1] + width + this.options.labels.padding >= this.width) {
  4854. totalHeight += fontSize + (this.options.labels.padding);
  4855. this.lineWidths[this.lineWidths.length] = this.left;
  4856. }
  4857. // Store the hitbox width and height here. Final position will be updated in `draw`
  4858. this.legendHitBoxes[i] = {
  4859. left: 0,
  4860. top: 0,
  4861. width: width,
  4862. height: fontSize
  4863. };
  4864. this.lineWidths[this.lineWidths.length - 1] += width + this.options.labels.padding;
  4865. }, this);
  4866. this.minSize.height += totalHeight;
  4867. } else {
  4868. // TODO vertical
  4869. }
  4870. }
  4871. this.width = this.minSize.width;
  4872. this.height = this.minSize.height;
  4873. },
  4874. afterFit: helpers.noop,
  4875. // Shared Methods
  4876. isHorizontal: function() {
  4877. return this.options.position === "top" || this.options.position === "bottom";
  4878. },
  4879. // Actualy draw the legend on the canvas
  4880. draw: function() {
  4881. if (this.options.display) {
  4882. var ctx = this.ctx;
  4883. var cursor = {
  4884. x: this.left + ((this.width - this.lineWidths[0]) / 2),
  4885. y: this.top + this.options.labels.padding,
  4886. line: 0
  4887. };
  4888. var fontColor = helpers.getValueOrDefault(this.options.labels.fontColor, Chart.defaults.global.defaultFontColor);
  4889. var fontSize = helpers.getValueOrDefault(this.options.labels.fontSize, Chart.defaults.global.defaultFontSize);
  4890. var fontStyle = helpers.getValueOrDefault(this.options.labels.fontStyle, Chart.defaults.global.defaultFontStyle);
  4891. var fontFamily = helpers.getValueOrDefault(this.options.labels.fontFamily, Chart.defaults.global.defaultFontFamily);
  4892. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  4893. // Horizontal
  4894. if (this.isHorizontal()) {
  4895. // Labels
  4896. ctx.textAlign = "left";
  4897. ctx.textBaseline = 'top';
  4898. ctx.lineWidth = 0.5;
  4899. ctx.strokeStyle = fontColor; // for strikethrough effect
  4900. ctx.fillStyle = fontColor; // render in correct colour
  4901. ctx.font = labelFont;
  4902. helpers.each(this.legendItems, function(legendItem, i) {
  4903. var textWidth = ctx.measureText(legendItem.text).width;
  4904. var width = this.options.labels.boxWidth + (fontSize / 2) + textWidth;
  4905. if (cursor.x + width >= this.width) {
  4906. cursor.y += fontSize + (this.options.labels.padding);
  4907. cursor.line++;
  4908. cursor.x = this.left + ((this.width - this.lineWidths[cursor.line]) / 2);
  4909. }
  4910. // Set the ctx for the box
  4911. ctx.save();
  4912. var itemOrDefault = function(item, defaulVal) {
  4913. return item !== undefined ? item : defaulVal;
  4914. };
  4915. ctx.fillStyle = itemOrDefault(legendItem.fillStyle, Chart.defaults.global.defaultColor);
  4916. ctx.lineCap = itemOrDefault(legendItem.lineCap, Chart.defaults.global.elements.line.borderCapStyle);
  4917. ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, Chart.defaults.global.elements.line.borderDashOffset);
  4918. ctx.lineJoin = itemOrDefault(legendItem.lineJoin, Chart.defaults.global.elements.line.borderJoinStyle);
  4919. ctx.lineWidth = itemOrDefault(legendItem.lineWidth, Chart.defaults.global.elements.line.borderWidth);
  4920. ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, Chart.defaults.global.defaultColor);
  4921. if (ctx.setLineDash) {
  4922. // IE 9 and 10 do not support line dash
  4923. ctx.setLineDash(itemOrDefault(legendItem.lineDash, Chart.defaults.global.elements.line.borderDash));
  4924. }
  4925. // Draw the box
  4926. ctx.strokeRect(cursor.x, cursor.y, this.options.labels.boxWidth, fontSize);
  4927. ctx.fillRect(cursor.x, cursor.y, this.options.labels.boxWidth, fontSize);
  4928. ctx.restore();
  4929. this.legendHitBoxes[i].left = cursor.x;
  4930. this.legendHitBoxes[i].top = cursor.y;
  4931. // Fill the actual label
  4932. ctx.fillText(legendItem.text, this.options.labels.boxWidth + (fontSize / 2) + cursor.x, cursor.y);
  4933. if (legendItem.hidden) {
  4934. // Strikethrough the text if hidden
  4935. ctx.beginPath();
  4936. ctx.lineWidth = 2;
  4937. ctx.moveTo(this.options.labels.boxWidth + (fontSize / 2) + cursor.x, cursor.y + (fontSize / 2));
  4938. ctx.lineTo(this.options.labels.boxWidth + (fontSize / 2) + cursor.x + textWidth, cursor.y + (fontSize / 2));
  4939. ctx.stroke();
  4940. }
  4941. cursor.x += width + (this.options.labels.padding);
  4942. }, this);
  4943. } else {
  4944. }
  4945. }
  4946. },
  4947. // Handle an event
  4948. handleEvent: function(e) {
  4949. var position = helpers.getRelativePosition(e, this.chart.chart);
  4950. if (position.x >= this.left && position.x <= this.right && position.y >= this.top && position.y <= this.bottom) {
  4951. // See if we are touching one of the dataset boxes
  4952. for (var i = 0; i < this.legendHitBoxes.length; ++i) {
  4953. var hitBox = this.legendHitBoxes[i];
  4954. if (position.x >= hitBox.left && position.x <= hitBox.left + hitBox.width && position.y >= hitBox.top && position.y <= hitBox.top + hitBox.height) {
  4955. // Touching an element
  4956. if (this.options.onClick) {
  4957. this.options.onClick.call(this, e, this.legendItems[i]);
  4958. }
  4959. break;
  4960. }
  4961. }
  4962. }
  4963. }
  4964. });
  4965. };
  4966. },{}],29:[function(require,module,exports){
  4967. "use strict";
  4968. module.exports = function(Chart) {
  4969. var helpers = Chart.helpers;
  4970. Chart.defaults.scale = {
  4971. display: true,
  4972. // grid line settings
  4973. gridLines: {
  4974. display: true,
  4975. color: "rgba(0, 0, 0, 0.1)",
  4976. lineWidth: 1,
  4977. drawOnChartArea: true,
  4978. drawTicks: true,
  4979. zeroLineWidth: 1,
  4980. zeroLineColor: "rgba(0,0,0,0.25)",
  4981. offsetGridLines: false
  4982. },
  4983. // scale label
  4984. scaleLabel: {
  4985. // actual label
  4986. labelString: '',
  4987. // display property
  4988. display: false
  4989. },
  4990. // label settings
  4991. ticks: {
  4992. beginAtZero: false,
  4993. maxRotation: 50,
  4994. mirror: false,
  4995. padding: 10,
  4996. reverse: false,
  4997. display: true,
  4998. autoSkip: true,
  4999. autoSkipPadding: 0,
  5000. callback: function(value) {
  5001. return '' + value;
  5002. }
  5003. }
  5004. };
  5005. Chart.Scale = Chart.Element.extend({
  5006. // These methods are ordered by lifecyle. Utilities then follow.
  5007. // Any function defined here is inherited by all scale types.
  5008. // Any function can be extended by the scale type
  5009. beforeUpdate: function() {
  5010. helpers.callCallback(this.options.beforeUpdate, [this]);
  5011. },
  5012. update: function(maxWidth, maxHeight, margins) {
  5013. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  5014. this.beforeUpdate();
  5015. // Absorb the master measurements
  5016. this.maxWidth = maxWidth;
  5017. this.maxHeight = maxHeight;
  5018. this.margins = helpers.extend({
  5019. left: 0,
  5020. right: 0,
  5021. top: 0,
  5022. bottom: 0
  5023. }, margins);
  5024. // Dimensions
  5025. this.beforeSetDimensions();
  5026. this.setDimensions();
  5027. this.afterSetDimensions();
  5028. // Data min/max
  5029. this.beforeDataLimits();
  5030. this.determineDataLimits();
  5031. this.afterDataLimits();
  5032. // Ticks
  5033. this.beforeBuildTicks();
  5034. this.buildTicks();
  5035. this.afterBuildTicks();
  5036. this.beforeTickToLabelConversion();
  5037. this.convertTicksToLabels();
  5038. this.afterTickToLabelConversion();
  5039. // Tick Rotation
  5040. this.beforeCalculateTickRotation();
  5041. this.calculateTickRotation();
  5042. this.afterCalculateTickRotation();
  5043. // Fit
  5044. this.beforeFit();
  5045. this.fit();
  5046. this.afterFit();
  5047. //
  5048. this.afterUpdate();
  5049. return this.minSize;
  5050. },
  5051. afterUpdate: function() {
  5052. helpers.callCallback(this.options.afterUpdate, [this]);
  5053. },
  5054. //
  5055. beforeSetDimensions: function() {
  5056. helpers.callCallback(this.options.beforeSetDimensions, [this]);
  5057. },
  5058. setDimensions: function() {
  5059. // Set the unconstrained dimension before label rotation
  5060. if (this.isHorizontal()) {
  5061. // Reset position before calculating rotation
  5062. this.width = this.maxWidth;
  5063. this.left = 0;
  5064. this.right = this.width;
  5065. } else {
  5066. this.height = this.maxHeight;
  5067. // Reset position before calculating rotation
  5068. this.top = 0;
  5069. this.bottom = this.height;
  5070. }
  5071. // Reset padding
  5072. this.paddingLeft = 0;
  5073. this.paddingTop = 0;
  5074. this.paddingRight = 0;
  5075. this.paddingBottom = 0;
  5076. },
  5077. afterSetDimensions: function() {
  5078. helpers.callCallback(this.options.afterSetDimensions, [this]);
  5079. },
  5080. // Data limits
  5081. beforeDataLimits: function() {
  5082. helpers.callCallback(this.options.beforeDataLimits, [this]);
  5083. },
  5084. determineDataLimits: helpers.noop,
  5085. afterDataLimits: function() {
  5086. helpers.callCallback(this.options.afterDataLimits, [this]);
  5087. },
  5088. //
  5089. beforeBuildTicks: function() {
  5090. helpers.callCallback(this.options.beforeBuildTicks, [this]);
  5091. },
  5092. buildTicks: helpers.noop,
  5093. afterBuildTicks: function() {
  5094. helpers.callCallback(this.options.afterBuildTicks, [this]);
  5095. },
  5096. beforeTickToLabelConversion: function() {
  5097. helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
  5098. },
  5099. convertTicksToLabels: function() {
  5100. // Convert ticks to strings
  5101. this.ticks = this.ticks.map(function(numericalTick, index, ticks) {
  5102. if (this.options.ticks.userCallback) {
  5103. return this.options.ticks.userCallback(numericalTick, index, ticks);
  5104. }
  5105. return this.options.ticks.callback(numericalTick, index, ticks);
  5106. },
  5107. this);
  5108. },
  5109. afterTickToLabelConversion: function() {
  5110. helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
  5111. },
  5112. //
  5113. beforeCalculateTickRotation: function() {
  5114. helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
  5115. },
  5116. calculateTickRotation: function() {
  5117. //Get the width of each grid by calculating the difference
  5118. //between x offsets between 0 and 1.
  5119. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  5120. var tickFontStyle = helpers.getValueOrDefault(this.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  5121. var tickFontFamily = helpers.getValueOrDefault(this.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  5122. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  5123. this.ctx.font = tickLabelFont;
  5124. var firstWidth = this.ctx.measureText(this.ticks[0]).width;
  5125. var lastWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
  5126. var firstRotated;
  5127. this.labelRotation = 0;
  5128. this.paddingRight = 0;
  5129. this.paddingLeft = 0;
  5130. if (this.options.display) {
  5131. if (this.isHorizontal()) {
  5132. this.paddingRight = lastWidth / 2 + 3;
  5133. this.paddingLeft = firstWidth / 2 + 3;
  5134. if (!this.longestTextCache) {
  5135. this.longestTextCache = {};
  5136. }
  5137. var originalLabelWidth = helpers.longestText(this.ctx, tickLabelFont, this.ticks, this.longestTextCache);
  5138. var labelWidth = originalLabelWidth;
  5139. var cosRotation;
  5140. var sinRotation;
  5141. // Allow 3 pixels x2 padding either side for label readability
  5142. // only the index matters for a dataset scale, but we want a consistent interface between scales
  5143. var tickWidth = this.getPixelForTick(1) - this.getPixelForTick(0) - 6;
  5144. //Max label rotation can be set or default to 90 - also act as a loop counter
  5145. while (labelWidth > tickWidth && this.labelRotation < this.options.ticks.maxRotation) {
  5146. cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
  5147. sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
  5148. firstRotated = cosRotation * firstWidth;
  5149. // We're right aligning the text now.
  5150. if (firstRotated + tickFontSize / 2 > this.yLabelWidth) {
  5151. this.paddingLeft = firstRotated + tickFontSize / 2;
  5152. }
  5153. this.paddingRight = tickFontSize / 2;
  5154. if (sinRotation * originalLabelWidth > this.maxHeight) {
  5155. // go back one step
  5156. this.labelRotation--;
  5157. break;
  5158. }
  5159. this.labelRotation++;
  5160. labelWidth = cosRotation * originalLabelWidth;
  5161. }
  5162. }
  5163. }
  5164. if (this.margins) {
  5165. this.paddingLeft = Math.max(this.paddingLeft - this.margins.left, 0);
  5166. this.paddingRight = Math.max(this.paddingRight - this.margins.right, 0);
  5167. }
  5168. },
  5169. afterCalculateTickRotation: function() {
  5170. helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
  5171. },
  5172. //
  5173. beforeFit: function() {
  5174. helpers.callCallback(this.options.beforeFit, [this]);
  5175. },
  5176. fit: function() {
  5177. this.minSize = {
  5178. width: 0,
  5179. height: 0
  5180. };
  5181. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  5182. var tickFontStyle = helpers.getValueOrDefault(this.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  5183. var tickFontFamily = helpers.getValueOrDefault(this.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  5184. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  5185. var scaleLabelFontSize = helpers.getValueOrDefault(this.options.scaleLabel.fontSize, Chart.defaults.global.defaultFontSize);
  5186. var scaleLabelFontStyle = helpers.getValueOrDefault(this.options.scaleLabel.fontStyle, Chart.defaults.global.defaultFontStyle);
  5187. var scaleLabelFontFamily = helpers.getValueOrDefault(this.options.scaleLabel.fontFamily, Chart.defaults.global.defaultFontFamily);
  5188. var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
  5189. // Width
  5190. if (this.isHorizontal()) {
  5191. // subtract the margins to line up with the chartArea if we are a full width scale
  5192. this.minSize.width = this.isFullWidth() ? this.maxWidth - this.margins.left - this.margins.right : this.maxWidth;
  5193. } else {
  5194. this.minSize.width = this.options.gridLines.display && this.options.display ? 10 : 0;
  5195. }
  5196. // height
  5197. if (this.isHorizontal()) {
  5198. this.minSize.height = this.options.gridLines.display && this.options.display ? 10 : 0;
  5199. } else {
  5200. this.minSize.height = this.maxHeight; // fill all the height
  5201. }
  5202. // Are we showing a title for the scale?
  5203. if (this.options.scaleLabel.display) {
  5204. if (this.isHorizontal()) {
  5205. this.minSize.height += (scaleLabelFontSize * 1.5);
  5206. } else {
  5207. this.minSize.width += (scaleLabelFontSize * 1.5);
  5208. }
  5209. }
  5210. if (this.options.ticks.display && this.options.display) {
  5211. // Don't bother fitting the ticks if we are not showing them
  5212. if (!this.longestTextCache) {
  5213. this.longestTextCache = {};
  5214. }
  5215. var largestTextWidth = helpers.longestText(this.ctx, tickLabelFont, this.ticks, this.longestTextCache);
  5216. if (this.isHorizontal()) {
  5217. // A horizontal axis is more constrained by the height.
  5218. this.longestLabelWidth = largestTextWidth;
  5219. // TODO - improve this calculation
  5220. var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * this.longestLabelWidth) + 1.5 * tickFontSize;
  5221. this.minSize.height = Math.min(this.maxHeight, this.minSize.height + labelHeight);
  5222. this.ctx.font = tickLabelFont;
  5223. var firstLabelWidth = this.ctx.measureText(this.ticks[0]).width;
  5224. var lastLabelWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
  5225. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
  5226. // by the font height
  5227. var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
  5228. var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
  5229. this.paddingLeft = this.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  5230. this.paddingRight = this.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
  5231. } else {
  5232. // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
  5233. var maxLabelWidth = this.maxWidth - this.minSize.width;
  5234. // Account for padding
  5235. if (!this.options.ticks.mirror) {
  5236. largestTextWidth += this.options.ticks.padding;
  5237. }
  5238. if (largestTextWidth < maxLabelWidth) {
  5239. // We don't need all the room
  5240. this.minSize.width += largestTextWidth;
  5241. } else {
  5242. // Expand to max size
  5243. this.minSize.width = this.maxWidth;
  5244. }
  5245. this.paddingTop = tickFontSize / 2;
  5246. this.paddingBottom = tickFontSize / 2;
  5247. }
  5248. }
  5249. if (this.margins) {
  5250. this.paddingLeft = Math.max(this.paddingLeft - this.margins.left, 0);
  5251. this.paddingTop = Math.max(this.paddingTop - this.margins.top, 0);
  5252. this.paddingRight = Math.max(this.paddingRight - this.margins.right, 0);
  5253. this.paddingBottom = Math.max(this.paddingBottom - this.margins.bottom, 0);
  5254. }
  5255. this.width = this.minSize.width;
  5256. this.height = this.minSize.height;
  5257. },
  5258. afterFit: function() {
  5259. helpers.callCallback(this.options.afterFit, [this]);
  5260. },
  5261. // Shared Methods
  5262. isHorizontal: function() {
  5263. return this.options.position === "top" || this.options.position === "bottom";
  5264. },
  5265. isFullWidth: function() {
  5266. return (this.options.fullWidth);
  5267. },
  5268. // 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
  5269. getRightValue: function getRightValue(rawValue) {
  5270. // Null and undefined values first
  5271. if (rawValue === null || typeof(rawValue) === 'undefined') {
  5272. return NaN;
  5273. }
  5274. // isNaN(object) returns true, so make sure NaN is checking for a number
  5275. if (typeof(rawValue) === 'number' && isNaN(rawValue)) {
  5276. return NaN;
  5277. }
  5278. // If it is in fact an object, dive in one more level
  5279. if (typeof(rawValue) === "object") {
  5280. if (rawValue instanceof Date) {
  5281. return rawValue;
  5282. } else {
  5283. return getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
  5284. }
  5285. }
  5286. // Value is good, return it
  5287. return rawValue;
  5288. },
  5289. // Used to get the value to display in the tooltip for the data at the given index
  5290. // function getLabelForIndex(index, datasetIndex)
  5291. getLabelForIndex: helpers.noop,
  5292. // Used to get data value locations. Value can either be an index or a numerical value
  5293. getPixelForValue: helpers.noop,
  5294. // Used for tick location, should
  5295. getPixelForTick: function(index, includeOffset) {
  5296. if (this.isHorizontal()) {
  5297. var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
  5298. var tickWidth = innerWidth / Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  5299. var pixel = (tickWidth * index) + this.paddingLeft;
  5300. if (includeOffset) {
  5301. pixel += tickWidth / 2;
  5302. }
  5303. var finalVal = this.left + Math.round(pixel);
  5304. finalVal += this.isFullWidth() ? this.margins.left : 0;
  5305. return finalVal;
  5306. } else {
  5307. var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
  5308. return this.top + (index * (innerHeight / (this.ticks.length - 1)));
  5309. }
  5310. },
  5311. // Utility for getting the pixel location of a percentage of scale
  5312. getPixelForDecimal: function(decimal /*, includeOffset*/ ) {
  5313. if (this.isHorizontal()) {
  5314. var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
  5315. var valueOffset = (innerWidth * decimal) + this.paddingLeft;
  5316. var finalVal = this.left + Math.round(valueOffset);
  5317. finalVal += this.isFullWidth() ? this.margins.left : 0;
  5318. return finalVal;
  5319. } else {
  5320. return this.top + (decimal * this.height);
  5321. }
  5322. },
  5323. // Actualy draw the scale on the canvas
  5324. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  5325. draw: function(chartArea) {
  5326. if (this.options.display) {
  5327. var setContextLineSettings;
  5328. var isRotated = this.labelRotation !== 0;
  5329. var skipRatio;
  5330. var scaleLabelX;
  5331. var scaleLabelY;
  5332. var useAutoskipper = this.options.ticks.autoSkip;
  5333. // figure out the maximum number of gridlines to show
  5334. var maxTicks;
  5335. if (this.options.ticks.maxTicksLimit) {
  5336. maxTicks = this.options.ticks.maxTicksLimit;
  5337. }
  5338. var tickFontColor = helpers.getValueOrDefault(this.options.ticks.fontColor, Chart.defaults.global.defaultFontColor);
  5339. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  5340. var tickFontStyle = helpers.getValueOrDefault(this.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  5341. var tickFontFamily = helpers.getValueOrDefault(this.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  5342. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  5343. var scaleLabelFontColor = helpers.getValueOrDefault(this.options.scaleLabel.fontColor, Chart.defaults.global.defaultFontColor);
  5344. var scaleLabelFontSize = helpers.getValueOrDefault(this.options.scaleLabel.fontSize, Chart.defaults.global.defaultFontSize);
  5345. var scaleLabelFontStyle = helpers.getValueOrDefault(this.options.scaleLabel.fontStyle, Chart.defaults.global.defaultFontStyle);
  5346. var scaleLabelFontFamily = helpers.getValueOrDefault(this.options.scaleLabel.fontFamily, Chart.defaults.global.defaultFontFamily);
  5347. var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
  5348. var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
  5349. var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
  5350. var longestRotatedLabel = this.longestLabelWidth * cosRotation;
  5351. var rotatedLabelHeight = tickFontSize * sinRotation;
  5352. // Make sure we draw text in the correct color and font
  5353. this.ctx.fillStyle = tickFontColor;
  5354. if (this.isHorizontal()) {
  5355. setContextLineSettings = true;
  5356. var yTickStart = this.options.position === "bottom" ? this.top : this.bottom - 10;
  5357. var yTickEnd = this.options.position === "bottom" ? this.top + 10 : this.bottom;
  5358. skipRatio = false;
  5359. if (((longestRotatedLabel / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
  5360. skipRatio = 1 + Math.floor((((longestRotatedLabel / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
  5361. }
  5362. // if they defined a max number of ticks,
  5363. // increase skipRatio until that number is met
  5364. if (maxTicks && this.ticks.length > maxTicks) {
  5365. while (!skipRatio || this.ticks.length / (skipRatio || 1) > maxTicks) {
  5366. if (!skipRatio) {
  5367. skipRatio = 1;
  5368. }
  5369. skipRatio += 1;
  5370. }
  5371. }
  5372. if (!useAutoskipper) {
  5373. skipRatio = false;
  5374. }
  5375. helpers.each(this.ticks, function(label, index) {
  5376. // Blank ticks
  5377. var isLastTick = this.ticks.length === index + 1;
  5378. // Since we always show the last tick,we need may need to hide the last shown one before
  5379. var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio > this.ticks.length);
  5380. if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
  5381. return;
  5382. }
  5383. var xLineValue = this.getPixelForTick(index); // xvalues for grid lines
  5384. var xLabelValue = this.getPixelForTick(index, this.options.gridLines.offsetGridLines); // x values for ticks (need to consider offsetLabel option)
  5385. if (this.options.gridLines.display) {
  5386. if (index === (typeof this.zeroLineIndex !== 'undefined' ? this.zeroLineIndex : 0)) {
  5387. // Draw the first index specially
  5388. this.ctx.lineWidth = this.options.gridLines.zeroLineWidth;
  5389. this.ctx.strokeStyle = this.options.gridLines.zeroLineColor;
  5390. setContextLineSettings = true; // reset next time
  5391. } else if (setContextLineSettings) {
  5392. this.ctx.lineWidth = this.options.gridLines.lineWidth;
  5393. this.ctx.strokeStyle = this.options.gridLines.color;
  5394. setContextLineSettings = false;
  5395. }
  5396. xLineValue += helpers.aliasPixel(this.ctx.lineWidth);
  5397. // Draw the label area
  5398. this.ctx.beginPath();
  5399. if (this.options.gridLines.drawTicks) {
  5400. this.ctx.moveTo(xLineValue, yTickStart);
  5401. this.ctx.lineTo(xLineValue, yTickEnd);
  5402. }
  5403. // Draw the chart area
  5404. if (this.options.gridLines.drawOnChartArea) {
  5405. this.ctx.moveTo(xLineValue, chartArea.top);
  5406. this.ctx.lineTo(xLineValue, chartArea.bottom);
  5407. }
  5408. // Need to stroke in the loop because we are potentially changing line widths & colours
  5409. this.ctx.stroke();
  5410. }
  5411. if (this.options.ticks.display) {
  5412. this.ctx.save();
  5413. this.ctx.translate(xLabelValue, (isRotated) ? this.top + 12 : this.options.position === "top" ? this.bottom - 10 : this.top + 10);
  5414. this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1);
  5415. this.ctx.font = tickLabelFont;
  5416. this.ctx.textAlign = (isRotated) ? "right" : "center";
  5417. this.ctx.textBaseline = (isRotated) ? "middle" : this.options.position === "top" ? "bottom" : "top";
  5418. this.ctx.fillText(label, 0, 0);
  5419. this.ctx.restore();
  5420. }
  5421. }, this);
  5422. if (this.options.scaleLabel.display) {
  5423. // Draw the scale label
  5424. this.ctx.textAlign = "center";
  5425. this.ctx.textBaseline = 'middle';
  5426. this.ctx.fillStyle = scaleLabelFontColor; // render in correct colour
  5427. this.ctx.font = scaleLabelFont;
  5428. scaleLabelX = this.left + ((this.right - this.left) / 2); // midpoint of the width
  5429. scaleLabelY = this.options.position === 'bottom' ? this.bottom - (scaleLabelFontSize / 2) : this.top + (scaleLabelFontSize / 2);
  5430. this.ctx.fillText(this.options.scaleLabel.labelString, scaleLabelX, scaleLabelY);
  5431. }
  5432. } else {
  5433. setContextLineSettings = true;
  5434. var xTickStart = this.options.position === "right" ? this.left : this.right - 5;
  5435. var xTickEnd = this.options.position === "right" ? this.left + 5 : this.right;
  5436. helpers.each(this.ticks, function(label, index) {
  5437. // If the callback returned a null or undefined value, do not draw this line
  5438. if (label === undefined || label === null) {
  5439. return;
  5440. }
  5441. var yLineValue = this.getPixelForTick(index); // xvalues for grid lines
  5442. if (this.options.gridLines.display) {
  5443. if (index === (typeof this.zeroLineIndex !== 'undefined' ? this.zeroLineIndex : 0)) {
  5444. // Draw the first index specially
  5445. this.ctx.lineWidth = this.options.gridLines.zeroLineWidth;
  5446. this.ctx.strokeStyle = this.options.gridLines.zeroLineColor;
  5447. setContextLineSettings = true; // reset next time
  5448. } else if (setContextLineSettings) {
  5449. this.ctx.lineWidth = this.options.gridLines.lineWidth;
  5450. this.ctx.strokeStyle = this.options.gridLines.color;
  5451. setContextLineSettings = false;
  5452. }
  5453. yLineValue += helpers.aliasPixel(this.ctx.lineWidth);
  5454. // Draw the label area
  5455. this.ctx.beginPath();
  5456. if (this.options.gridLines.drawTicks) {
  5457. this.ctx.moveTo(xTickStart, yLineValue);
  5458. this.ctx.lineTo(xTickEnd, yLineValue);
  5459. }
  5460. // Draw the chart area
  5461. if (this.options.gridLines.drawOnChartArea) {
  5462. this.ctx.moveTo(chartArea.left, yLineValue);
  5463. this.ctx.lineTo(chartArea.right, yLineValue);
  5464. }
  5465. // Need to stroke in the loop because we are potentially changing line widths & colours
  5466. this.ctx.stroke();
  5467. }
  5468. if (this.options.ticks.display) {
  5469. var xLabelValue;
  5470. var yLabelValue = this.getPixelForTick(index, this.options.gridLines.offsetGridLines); // x values for ticks (need to consider offsetLabel option)
  5471. this.ctx.save();
  5472. if (this.options.position === "left") {
  5473. if (this.options.ticks.mirror) {
  5474. xLabelValue = this.right + this.options.ticks.padding;
  5475. this.ctx.textAlign = "left";
  5476. } else {
  5477. xLabelValue = this.right - this.options.ticks.padding;
  5478. this.ctx.textAlign = "right";
  5479. }
  5480. } else {
  5481. // right side
  5482. if (this.options.ticks.mirror) {
  5483. xLabelValue = this.left - this.options.ticks.padding;
  5484. this.ctx.textAlign = "right";
  5485. } else {
  5486. xLabelValue = this.left + this.options.ticks.padding;
  5487. this.ctx.textAlign = "left";
  5488. }
  5489. }
  5490. this.ctx.translate(xLabelValue, yLabelValue);
  5491. this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1);
  5492. this.ctx.font = tickLabelFont;
  5493. this.ctx.textBaseline = "middle";
  5494. this.ctx.fillText(label, 0, 0);
  5495. this.ctx.restore();
  5496. }
  5497. }, this);
  5498. if (this.options.scaleLabel.display) {
  5499. // Draw the scale label
  5500. scaleLabelX = this.options.position === 'left' ? this.left + (scaleLabelFontSize / 2) : this.right - (scaleLabelFontSize / 2);
  5501. scaleLabelY = this.top + ((this.bottom - this.top) / 2);
  5502. var rotation = this.options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
  5503. this.ctx.save();
  5504. this.ctx.translate(scaleLabelX, scaleLabelY);
  5505. this.ctx.rotate(rotation);
  5506. this.ctx.textAlign = "center";
  5507. this.ctx.fillStyle =scaleLabelFontColor; // render in correct colour
  5508. this.ctx.font = scaleLabelFont;
  5509. this.ctx.textBaseline = 'middle';
  5510. this.ctx.fillText(this.options.scaleLabel.labelString, 0, 0);
  5511. this.ctx.restore();
  5512. }
  5513. }
  5514. // Draw the line at the edge of the axis
  5515. this.ctx.lineWidth = this.options.gridLines.lineWidth;
  5516. this.ctx.strokeStyle = this.options.gridLines.color;
  5517. var x1 = this.left,
  5518. x2 = this.right,
  5519. y1 = this.top,
  5520. y2 = this.bottom;
  5521. if (this.isHorizontal()) {
  5522. y1 = y2 = this.options.position === 'top' ? this.bottom : this.top;
  5523. y1 += helpers.aliasPixel(this.ctx.lineWidth);
  5524. y2 += helpers.aliasPixel(this.ctx.lineWidth);
  5525. } else {
  5526. x1 = x2 = this.options.position === 'left' ? this.right : this.left;
  5527. x1 += helpers.aliasPixel(this.ctx.lineWidth);
  5528. x2 += helpers.aliasPixel(this.ctx.lineWidth);
  5529. }
  5530. this.ctx.beginPath();
  5531. this.ctx.moveTo(x1, y1);
  5532. this.ctx.lineTo(x2, y2);
  5533. this.ctx.stroke();
  5534. }
  5535. }
  5536. });
  5537. };
  5538. },{}],30:[function(require,module,exports){
  5539. "use strict";
  5540. module.exports = function(Chart) {
  5541. var helpers = Chart.helpers;
  5542. Chart.scaleService = {
  5543. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  5544. // use the new chart options to grab the correct scale
  5545. constructors: {},
  5546. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  5547. // old browsers
  5548. // Scale config defaults
  5549. defaults: {},
  5550. registerScaleType: function(type, scaleConstructor, defaults) {
  5551. this.constructors[type] = scaleConstructor;
  5552. this.defaults[type] = helpers.clone(defaults);
  5553. },
  5554. getScaleConstructor: function(type) {
  5555. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  5556. },
  5557. getScaleDefaults: function(type) {
  5558. // Return the scale defaults merged with the global settings so that we always use the latest ones
  5559. return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
  5560. },
  5561. addScalesToLayout: function(chartInstance) {
  5562. // Adds each scale to the chart.boxes array to be sized accordingly
  5563. helpers.each(chartInstance.scales, function(scale) {
  5564. Chart.layoutService.addBox(chartInstance, scale);
  5565. });
  5566. }
  5567. };
  5568. };
  5569. },{}],31:[function(require,module,exports){
  5570. "use strict";
  5571. module.exports = function(Chart) {
  5572. var helpers = Chart.helpers;
  5573. Chart.defaults.global.title = {
  5574. display: false,
  5575. position: 'top',
  5576. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  5577. fontStyle: 'bold',
  5578. padding: 10,
  5579. // actual title
  5580. text: ''
  5581. };
  5582. Chart.Title = Chart.Element.extend({
  5583. initialize: function(config) {
  5584. helpers.extend(this, config);
  5585. this.options = helpers.configMerge(Chart.defaults.global.title, config.options);
  5586. // Contains hit boxes for each dataset (in dataset order)
  5587. this.legendHitBoxes = [];
  5588. },
  5589. // These methods are ordered by lifecyle. Utilities then follow.
  5590. beforeUpdate: helpers.noop,
  5591. update: function(maxWidth, maxHeight, margins) {
  5592. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  5593. this.beforeUpdate();
  5594. // Absorb the master measurements
  5595. this.maxWidth = maxWidth;
  5596. this.maxHeight = maxHeight;
  5597. this.margins = margins;
  5598. // Dimensions
  5599. this.beforeSetDimensions();
  5600. this.setDimensions();
  5601. this.afterSetDimensions();
  5602. // Labels
  5603. this.beforeBuildLabels();
  5604. this.buildLabels();
  5605. this.afterBuildLabels();
  5606. // Fit
  5607. this.beforeFit();
  5608. this.fit();
  5609. this.afterFit();
  5610. //
  5611. this.afterUpdate();
  5612. return this.minSize;
  5613. },
  5614. afterUpdate: helpers.noop,
  5615. //
  5616. beforeSetDimensions: helpers.noop,
  5617. setDimensions: function() {
  5618. // Set the unconstrained dimension before label rotation
  5619. if (this.isHorizontal()) {
  5620. // Reset position before calculating rotation
  5621. this.width = this.maxWidth;
  5622. this.left = 0;
  5623. this.right = this.width;
  5624. } else {
  5625. this.height = this.maxHeight;
  5626. // Reset position before calculating rotation
  5627. this.top = 0;
  5628. this.bottom = this.height;
  5629. }
  5630. // Reset padding
  5631. this.paddingLeft = 0;
  5632. this.paddingTop = 0;
  5633. this.paddingRight = 0;
  5634. this.paddingBottom = 0;
  5635. // Reset minSize
  5636. this.minSize = {
  5637. width: 0,
  5638. height: 0
  5639. };
  5640. },
  5641. afterSetDimensions: helpers.noop,
  5642. //
  5643. beforeBuildLabels: helpers.noop,
  5644. buildLabels: helpers.noop,
  5645. afterBuildLabels: helpers.noop,
  5646. //
  5647. beforeFit: helpers.noop,
  5648. fit: function() {
  5649. var ctx = this.ctx;
  5650. var fontSize = helpers.getValueOrDefault(this.options.fontSize, Chart.defaults.global.defaultFontSize);
  5651. var fontStyle = helpers.getValueOrDefault(this.options.fontStyle, Chart.defaults.global.defaultFontStyle);
  5652. var fontFamily = helpers.getValueOrDefault(this.options.fontFamily, Chart.defaults.global.defaultFontFamily);
  5653. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  5654. // Width
  5655. if (this.isHorizontal()) {
  5656. this.minSize.width = this.maxWidth; // fill all the width
  5657. } else {
  5658. this.minSize.width = 0;
  5659. }
  5660. // height
  5661. if (this.isHorizontal()) {
  5662. this.minSize.height = 0;
  5663. } else {
  5664. this.minSize.height = this.maxHeight; // fill all the height
  5665. }
  5666. // Increase sizes here
  5667. if (this.isHorizontal()) {
  5668. // Title
  5669. if (this.options.display) {
  5670. this.minSize.height += fontSize + (this.options.padding * 2);
  5671. }
  5672. } else {
  5673. if (this.options.display) {
  5674. this.minSize.width += fontSize + (this.options.padding * 2);
  5675. }
  5676. }
  5677. this.width = this.minSize.width;
  5678. this.height = this.minSize.height;
  5679. },
  5680. afterFit: helpers.noop,
  5681. // Shared Methods
  5682. isHorizontal: function() {
  5683. return this.options.position === "top" || this.options.position === "bottom";
  5684. },
  5685. // Actualy draw the title block on the canvas
  5686. draw: function() {
  5687. if (this.options.display) {
  5688. var ctx = this.ctx;
  5689. var titleX, titleY;
  5690. var fontColor = helpers.getValueOrDefault(this.options.fontColor, Chart.defaults.global.defaultFontColor);
  5691. var fontSize = helpers.getValueOrDefault(this.options.fontSize, Chart.defaults.global.defaultFontSize);
  5692. var fontStyle = helpers.getValueOrDefault(this.options.fontStyle, Chart.defaults.global.defaultFontStyle);
  5693. var fontFamily = helpers.getValueOrDefault(this.options.fontFamily, Chart.defaults.global.defaultFontFamily);
  5694. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  5695. ctx.fillStyle = fontColor; // render in correct colour
  5696. ctx.font = titleFont;
  5697. // Horizontal
  5698. if (this.isHorizontal()) {
  5699. // Title
  5700. ctx.textAlign = "center";
  5701. ctx.textBaseline = 'middle';
  5702. titleX = this.left + ((this.right - this.left) / 2); // midpoint of the width
  5703. titleY = this.top + ((this.bottom - this.top) / 2); // midpoint of the height
  5704. ctx.fillText(this.options.text, titleX, titleY);
  5705. } else {
  5706. // Title
  5707. titleX = this.options.position === 'left' ? this.left + (fontSize / 2) : this.right - (fontSize / 2);
  5708. titleY = this.top + ((this.bottom - this.top) / 2);
  5709. var rotation = this.options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
  5710. ctx.save();
  5711. ctx.translate(titleX, titleY);
  5712. ctx.rotate(rotation);
  5713. ctx.textAlign = "center";
  5714. ctx.textBaseline = 'middle';
  5715. ctx.fillText(this.options.text, 0, 0);
  5716. ctx.restore();
  5717. }
  5718. }
  5719. }
  5720. });
  5721. };
  5722. },{}],32:[function(require,module,exports){
  5723. "use strict";
  5724. module.exports = function(Chart) {
  5725. var helpers = Chart.helpers;
  5726. Chart.defaults.global.tooltips = {
  5727. enabled: true,
  5728. custom: null,
  5729. mode: 'single',
  5730. backgroundColor: "rgba(0,0,0,0.8)",
  5731. titleFontStyle: "bold",
  5732. titleSpacing: 2,
  5733. titleMarginBottom: 6,
  5734. titleColor: "#fff",
  5735. titleAlign: "left",
  5736. bodySpacing: 2,
  5737. bodyColor: "#fff",
  5738. bodyAlign: "left",
  5739. footerFontStyle: "bold",
  5740. footerSpacing: 2,
  5741. footerMarginTop: 6,
  5742. footerColor: "#fff",
  5743. footerAlign: "left",
  5744. yPadding: 6,
  5745. xPadding: 6,
  5746. yAlign : 'center',
  5747. xAlign : 'center',
  5748. caretSize: 5,
  5749. cornerRadius: 6,
  5750. multiKeyBackground: '#fff',
  5751. callbacks: {
  5752. // Args are: (tooltipItems, data)
  5753. beforeTitle: helpers.noop,
  5754. title: function(tooltipItems, data) {
  5755. // Pick first xLabel for now
  5756. var title = '';
  5757. if (tooltipItems.length > 0) {
  5758. if (tooltipItems[0].xLabel) {
  5759. title = tooltipItems[0].xLabel;
  5760. } else if (data.labels.length > 0 && tooltipItems[0].index < data.labels.length) {
  5761. title = data.labels[tooltipItems[0].index];
  5762. }
  5763. }
  5764. return title;
  5765. },
  5766. afterTitle: helpers.noop,
  5767. // Args are: (tooltipItems, data)
  5768. beforeBody: helpers.noop,
  5769. // Args are: (tooltipItem, data)
  5770. beforeLabel: helpers.noop,
  5771. label: function(tooltipItem, data) {
  5772. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  5773. return datasetLabel + ': ' + tooltipItem.yLabel;
  5774. },
  5775. afterLabel: helpers.noop,
  5776. // Args are: (tooltipItems, data)
  5777. afterBody: helpers.noop,
  5778. // Args are: (tooltipItems, data)
  5779. beforeFooter: helpers.noop,
  5780. footer: helpers.noop,
  5781. afterFooter: helpers.noop
  5782. }
  5783. };
  5784. // Helper to push or concat based on if the 2nd parameter is an array or not
  5785. function pushOrConcat(base, toPush) {
  5786. if (toPush) {
  5787. if (helpers.isArray(toPush)) {
  5788. base = base.concat(toPush);
  5789. } else {
  5790. base.push(toPush);
  5791. }
  5792. }
  5793. return base;
  5794. }
  5795. Chart.Tooltip = Chart.Element.extend({
  5796. initialize: function() {
  5797. var options = this._options;
  5798. helpers.extend(this, {
  5799. _model: {
  5800. // Positioning
  5801. xPadding: options.tooltips.xPadding,
  5802. yPadding: options.tooltips.yPadding,
  5803. xAlign : options.tooltips.yAlign,
  5804. yAlign : options.tooltips.xAlign,
  5805. // Body
  5806. bodyColor: options.tooltips.bodyColor,
  5807. _bodyFontFamily: helpers.getValueOrDefault(options.tooltips.bodyFontFamily, Chart.defaults.global.defaultFontFamily),
  5808. _bodyFontStyle: helpers.getValueOrDefault(options.tooltips.bodyFontStyle, Chart.defaults.global.defaultFontStyle),
  5809. _bodyAlign: options.tooltips.bodyAlign,
  5810. bodyFontSize: helpers.getValueOrDefault(options.tooltips.bodyFontSize, Chart.defaults.global.defaultFontSize),
  5811. bodySpacing: options.tooltips.bodySpacing,
  5812. // Title
  5813. titleColor: options.tooltips.titleColor,
  5814. _titleFontFamily: helpers.getValueOrDefault(options.tooltips.titleFontFamily, Chart.defaults.global.defaultFontFamily),
  5815. _titleFontStyle: helpers.getValueOrDefault(options.tooltips.titleFontStyle, Chart.defaults.global.defaultFontStyle),
  5816. titleFontSize: helpers.getValueOrDefault(options.tooltips.titleFontSize, Chart.defaults.global.defaultFontSize),
  5817. _titleAlign: options.tooltips.titleAlign,
  5818. titleSpacing: options.tooltips.titleSpacing,
  5819. titleMarginBottom: options.tooltips.titleMarginBottom,
  5820. // Footer
  5821. footerColor: options.tooltips.footerColor,
  5822. _footerFontFamily: helpers.getValueOrDefault(options.tooltips.footerFontFamily, Chart.defaults.global.defaultFontFamily),
  5823. _footerFontStyle: helpers.getValueOrDefault(options.tooltips.footerFontStyle, Chart.defaults.global.defaultFontStyle),
  5824. footerFontSize: helpers.getValueOrDefault(options.tooltips.footerFontSize, Chart.defaults.global.defaultFontSize),
  5825. _footerAlign: options.tooltips.footerAlign,
  5826. footerSpacing: options.tooltips.footerSpacing,
  5827. footerMarginTop: options.tooltips.footerMarginTop,
  5828. // Appearance
  5829. caretSize: options.tooltips.caretSize,
  5830. cornerRadius: options.tooltips.cornerRadius,
  5831. backgroundColor: options.tooltips.backgroundColor,
  5832. opacity: 0,
  5833. legendColorBackground: options.tooltips.multiKeyBackground
  5834. }
  5835. });
  5836. },
  5837. // Get the title
  5838. // Args are: (tooltipItem, data)
  5839. getTitle: function() {
  5840. var beforeTitle = this._options.tooltips.callbacks.beforeTitle.apply(this, arguments),
  5841. title = this._options.tooltips.callbacks.title.apply(this, arguments),
  5842. afterTitle = this._options.tooltips.callbacks.afterTitle.apply(this, arguments);
  5843. var lines = [];
  5844. lines = pushOrConcat(lines, beforeTitle);
  5845. lines = pushOrConcat(lines, title);
  5846. lines = pushOrConcat(lines, afterTitle);
  5847. return lines;
  5848. },
  5849. // Args are: (tooltipItem, data)
  5850. getBeforeBody: function() {
  5851. var lines = this._options.tooltips.callbacks.beforeBody.apply(this, arguments);
  5852. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  5853. },
  5854. // Args are: (tooltipItem, data)
  5855. getBody: function(tooltipItems, data) {
  5856. var lines = [];
  5857. helpers.each(tooltipItems, function(bodyItem) {
  5858. helpers.pushAllIfDefined(this._options.tooltips.callbacks.beforeLabel.call(this, bodyItem, data), lines);
  5859. helpers.pushAllIfDefined(this._options.tooltips.callbacks.label.call(this, bodyItem, data), lines);
  5860. helpers.pushAllIfDefined(this._options.tooltips.callbacks.afterLabel.call(this, bodyItem, data), lines);
  5861. }, this);
  5862. return lines;
  5863. },
  5864. // Args are: (tooltipItem, data)
  5865. getAfterBody: function() {
  5866. var lines = this._options.tooltips.callbacks.afterBody.apply(this, arguments);
  5867. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  5868. },
  5869. // Get the footer and beforeFooter and afterFooter lines
  5870. // Args are: (tooltipItem, data)
  5871. getFooter: function() {
  5872. var beforeFooter = this._options.tooltips.callbacks.beforeFooter.apply(this, arguments);
  5873. var footer = this._options.tooltips.callbacks.footer.apply(this, arguments);
  5874. var afterFooter = this._options.tooltips.callbacks.afterFooter.apply(this, arguments);
  5875. var lines = [];
  5876. lines = pushOrConcat(lines, beforeFooter);
  5877. lines = pushOrConcat(lines, footer);
  5878. lines = pushOrConcat(lines, afterFooter);
  5879. return lines;
  5880. },
  5881. getAveragePosition: function(elements) {
  5882. if (!elements.length) {
  5883. return false;
  5884. }
  5885. var xPositions = [];
  5886. var yPositions = [];
  5887. helpers.each(elements, function(el) {
  5888. if (el) {
  5889. var pos = el.tooltipPosition();
  5890. xPositions.push(pos.x);
  5891. yPositions.push(pos.y);
  5892. }
  5893. });
  5894. var x = 0,
  5895. y = 0;
  5896. for (var i = 0; i < xPositions.length; i++) {
  5897. x += xPositions[i];
  5898. y += yPositions[i];
  5899. }
  5900. return {
  5901. x: Math.round(x / xPositions.length),
  5902. y: Math.round(y / xPositions.length)
  5903. };
  5904. },
  5905. update: function(changed) {
  5906. if (this._active.length) {
  5907. this._model.opacity = 1;
  5908. var element = this._active[0],
  5909. labelColors = [],
  5910. tooltipPosition;
  5911. var tooltipItems = [];
  5912. if (this._options.tooltips.mode === 'single') {
  5913. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  5914. tooltipItems.push({
  5915. xLabel: element._xScale ? element._xScale.getLabelForIndex(element._index, element._datasetIndex) : '',
  5916. yLabel: yScale ? yScale.getLabelForIndex(element._index, element._datasetIndex) : '',
  5917. index: element._index,
  5918. datasetIndex: element._datasetIndex
  5919. });
  5920. tooltipPosition = this.getAveragePosition(this._active);
  5921. } else {
  5922. helpers.each(this._data.datasets, function(dataset, datasetIndex) {
  5923. if (!helpers.isDatasetVisible(dataset)) {
  5924. return;
  5925. }
  5926. var currentElement = dataset.metaData[element._index];
  5927. if (currentElement) {
  5928. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  5929. tooltipItems.push({
  5930. xLabel: currentElement._xScale ? currentElement._xScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
  5931. yLabel: yScale ? yScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
  5932. index: element._index,
  5933. datasetIndex: datasetIndex
  5934. });
  5935. }
  5936. }, null, element._yScale.options.stacked);
  5937. helpers.each(this._active, function(active) {
  5938. if (active) {
  5939. labelColors.push({
  5940. borderColor: active._view.borderColor,
  5941. backgroundColor: active._view.backgroundColor
  5942. });
  5943. }
  5944. }, null, element._yScale.options.stacked);
  5945. tooltipPosition = this.getAveragePosition(this._active);
  5946. tooltipPosition.y = this._active[0]._yScale.getPixelForDecimal(0.5);
  5947. }
  5948. // Build the Text Lines
  5949. helpers.extend(this._model, {
  5950. title: this.getTitle(tooltipItems, this._data),
  5951. beforeBody: this.getBeforeBody(tooltipItems, this._data),
  5952. body: this.getBody(tooltipItems, this._data),
  5953. afterBody: this.getAfterBody(tooltipItems, this._data),
  5954. footer: this.getFooter(tooltipItems, this._data)
  5955. });
  5956. helpers.extend(this._model, {
  5957. x: Math.round(tooltipPosition.x),
  5958. y: Math.round(tooltipPosition.y),
  5959. caretPadding: helpers.getValueOrDefault(tooltipPosition.padding, 2),
  5960. labelColors: labelColors
  5961. });
  5962. // We need to determine alignment of
  5963. var tooltipSize = this.getTooltipSize(this._model);
  5964. this.determineAlignment(tooltipSize); // Smart Tooltip placement to stay on the canvas
  5965. helpers.extend(this._model, this.getBackgroundPoint(this._model, tooltipSize));
  5966. } else {
  5967. this._model.opacity = 0;
  5968. }
  5969. if (changed && this._options.tooltips.custom) {
  5970. this._options.tooltips.custom.call(this, this._model);
  5971. }
  5972. return this;
  5973. },
  5974. getTooltipSize: function getTooltipSize(vm) {
  5975. var ctx = this._chart.ctx;
  5976. var size = {
  5977. height: vm.yPadding * 2, // Tooltip Padding
  5978. width: 0
  5979. };
  5980. var combinedBodyLength = vm.body.length + vm.beforeBody.length + vm.afterBody.length;
  5981. size.height += vm.title.length * vm.titleFontSize; // Title Lines
  5982. size.height += (vm.title.length - 1) * vm.titleSpacing; // Title Line Spacing
  5983. size.height += vm.title.length ? vm.titleMarginBottom : 0; // Title's bottom Margin
  5984. size.height += combinedBodyLength * vm.bodyFontSize; // Body Lines
  5985. size.height += combinedBodyLength ? (combinedBodyLength - 1) * vm.bodySpacing : 0; // Body Line Spacing
  5986. size.height += vm.footer.length ? vm.footerMarginTop : 0; // Footer Margin
  5987. size.height += vm.footer.length * (vm.footerFontSize); // Footer Lines
  5988. size.height += vm.footer.length ? (vm.footer.length - 1) * vm.footerSpacing : 0; // Footer Line Spacing
  5989. // Width
  5990. ctx.font = helpers.fontString(vm.titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  5991. helpers.each(vm.title, function(line) {
  5992. size.width = Math.max(size.width, ctx.measureText(line).width);
  5993. });
  5994. ctx.font = helpers.fontString(vm.bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  5995. helpers.each(vm.beforeBody.concat(vm.afterBody), function(line) {
  5996. size.width = Math.max(size.width, ctx.measureText(line).width);
  5997. });
  5998. helpers.each(vm.body, function(line) {
  5999. size.width = Math.max(size.width, ctx.measureText(line).width + (this._options.tooltips.mode !== 'single' ? (vm.bodyFontSize + 2) : 0));
  6000. }, this);
  6001. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  6002. helpers.each(vm.footer, function(line) {
  6003. size.width = Math.max(size.width, ctx.measureText(line).width);
  6004. });
  6005. size.width += 2 * vm.xPadding;
  6006. return size;
  6007. },
  6008. determineAlignment: function determineAlignment(size) {
  6009. if (this._model.y < size.height) {
  6010. this._model.yAlign = 'top';
  6011. } else if (this._model.y > (this._chart.height - size.height)) {
  6012. this._model.yAlign = 'bottom';
  6013. }
  6014. var lf, rf; // functions to determine left, right alignment
  6015. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  6016. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  6017. var _this = this;
  6018. var midX = (this._chartInstance.chartArea.left + this._chartInstance.chartArea.right) / 2;
  6019. var midY = (this._chartInstance.chartArea.top + this._chartInstance.chartArea.bottom) / 2;
  6020. if (this._model.yAlign === 'center') {
  6021. lf = function(x) {
  6022. return x <= midX;
  6023. };
  6024. rf = function(x) {
  6025. return x > midX;
  6026. };
  6027. } else {
  6028. lf = function(x) {
  6029. return x <= (size.width / 2);
  6030. };
  6031. rf = function(x) {
  6032. return x >= (_this._chart.width - (size.width / 2));
  6033. };
  6034. }
  6035. olf = function(x) {
  6036. return x + size.width > _this._chart.width;
  6037. };
  6038. orf = function(x) {
  6039. return x - size.width < 0;
  6040. };
  6041. yf = function(y) {
  6042. return y <= midY ? 'top' : 'bottom';
  6043. };
  6044. if (lf(this._model.x)) {
  6045. this._model.xAlign = 'left';
  6046. // Is tooltip too wide and goes over the right side of the chart.?
  6047. if (olf(this._model.x)) {
  6048. this._model.xAlign = 'center';
  6049. this._model.yAlign = yf(this._model.y);
  6050. }
  6051. } else if (rf(this._model.x)) {
  6052. this._model.xAlign = 'right';
  6053. // Is tooltip too wide and goes outside left edge of canvas?
  6054. if (orf(this._model.x)) {
  6055. this._model.xAlign = 'center';
  6056. this._model.yAlign = yf(this._model.y);
  6057. }
  6058. }
  6059. },
  6060. getBackgroundPoint: function getBackgroundPoint(vm, size) {
  6061. // Background Position
  6062. var pt = {
  6063. x: vm.x,
  6064. y: vm.y
  6065. };
  6066. if (vm.xAlign === 'right') {
  6067. pt.x -= size.width;
  6068. } else if (vm.xAlign === 'center') {
  6069. pt.x -= (size.width / 2);
  6070. }
  6071. if (vm.yAlign === 'top') {
  6072. pt.y += vm.caretPadding + vm.caretSize;
  6073. } else if (vm.yAlign === 'bottom') {
  6074. pt.y -= size.height + vm.caretPadding + vm.caretSize;
  6075. } else {
  6076. pt.y -= (size.height / 2);
  6077. }
  6078. if (vm.yAlign === 'center') {
  6079. if (vm.xAlign === 'left') {
  6080. pt.x += vm.caretPadding + vm.caretSize;
  6081. } else if (vm.xAlign === 'right') {
  6082. pt.x -= vm.caretPadding + vm.caretSize;
  6083. }
  6084. } else {
  6085. if (vm.xAlign === 'left') {
  6086. pt.x -= vm.cornerRadius + vm.caretPadding;
  6087. } else if (vm.xAlign === 'right') {
  6088. pt.x += vm.cornerRadius + vm.caretPadding;
  6089. }
  6090. }
  6091. return pt;
  6092. },
  6093. drawCaret: function drawCaret(tooltipPoint, size, opacity, caretPadding) {
  6094. var vm = this._view;
  6095. var ctx = this._chart.ctx;
  6096. var x1, x2, x3;
  6097. var y1, y2, y3;
  6098. if (vm.yAlign === 'center') {
  6099. // Left or right side
  6100. if (vm.xAlign === 'left') {
  6101. x1 = tooltipPoint.x;
  6102. x2 = x1 - vm.caretSize;
  6103. x3 = x1;
  6104. } else {
  6105. x1 = tooltipPoint.x + size.width;
  6106. x2 = x1 + vm.caretSize;
  6107. x3 = x1;
  6108. }
  6109. y2 = tooltipPoint.y + (size.height / 2);
  6110. y1 = y2 - vm.caretSize;
  6111. y3 = y2 + vm.caretSize;
  6112. } else {
  6113. if (vm.xAlign === 'left') {
  6114. x1 = tooltipPoint.x + vm.cornerRadius;
  6115. x2 = x1 + vm.caretSize;
  6116. x3 = x2 + vm.caretSize;
  6117. } else if (vm.xAlign === 'right') {
  6118. x1 = tooltipPoint.x + size.width - vm.cornerRadius;
  6119. x2 = x1 - vm.caretSize;
  6120. x3 = x2 - vm.caretSize;
  6121. } else {
  6122. x2 = tooltipPoint.x + (size.width / 2);
  6123. x1 = x2 - vm.caretSize;
  6124. x3 = x2 + vm.caretSize;
  6125. }
  6126. if (vm.yAlign === 'top') {
  6127. y1 = tooltipPoint.y;
  6128. y2 = y1 - vm.caretSize;
  6129. y3 = y1;
  6130. } else {
  6131. y1 = tooltipPoint.y + size.height;
  6132. y2 = y1 + vm.caretSize;
  6133. y3 = y1;
  6134. }
  6135. }
  6136. var bgColor = helpers.color(vm.backgroundColor);
  6137. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  6138. ctx.beginPath();
  6139. ctx.moveTo(x1, y1);
  6140. ctx.lineTo(x2, y2);
  6141. ctx.lineTo(x3, y3);
  6142. ctx.closePath();
  6143. ctx.fill();
  6144. },
  6145. drawTitle: function drawTitle(pt, vm, ctx, opacity) {
  6146. if (vm.title.length) {
  6147. ctx.textAlign = vm._titleAlign;
  6148. ctx.textBaseline = "top";
  6149. var titleColor = helpers.color(vm.titleColor);
  6150. ctx.fillStyle = titleColor.alpha(opacity * titleColor.alpha()).rgbString();
  6151. ctx.font = helpers.fontString(vm.titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  6152. helpers.each(vm.title, function(title, i) {
  6153. ctx.fillText(title, pt.x, pt.y);
  6154. pt.y += vm.titleFontSize + vm.titleSpacing; // Line Height and spacing
  6155. if (i + 1 === vm.title.length) {
  6156. pt.y += vm.titleMarginBottom - vm.titleSpacing; // If Last, add margin, remove spacing
  6157. }
  6158. });
  6159. }
  6160. },
  6161. drawBody: function drawBody(pt, vm, ctx, opacity) {
  6162. ctx.textAlign = vm._bodyAlign;
  6163. ctx.textBaseline = "top";
  6164. var bodyColor = helpers.color(vm.bodyColor);
  6165. ctx.fillStyle = bodyColor.alpha(opacity * bodyColor.alpha()).rgbString();
  6166. ctx.font = helpers.fontString(vm.bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  6167. // Before Body
  6168. helpers.each(vm.beforeBody, function(beforeBody) {
  6169. ctx.fillText(beforeBody, pt.x, pt.y);
  6170. pt.y += vm.bodyFontSize + vm.bodySpacing;
  6171. });
  6172. helpers.each(vm.body, function(body, i) {
  6173. // Draw Legend-like boxes if needed
  6174. if (this._options.tooltips.mode !== 'single') {
  6175. // Fill a white rect so that colours merge nicely if the opacity is < 1
  6176. ctx.fillStyle = helpers.color(vm.legendColorBackground).alpha(opacity).rgbaString();
  6177. ctx.fillRect(pt.x, pt.y, vm.bodyFontSize, vm.bodyFontSize);
  6178. // Border
  6179. ctx.strokeStyle = helpers.color(vm.labelColors[i].borderColor).alpha(opacity).rgbaString();
  6180. ctx.strokeRect(pt.x, pt.y, vm.bodyFontSize, vm.bodyFontSize);
  6181. // Inner square
  6182. ctx.fillStyle = helpers.color(vm.labelColors[i].backgroundColor).alpha(opacity).rgbaString();
  6183. ctx.fillRect(pt.x + 1, pt.y + 1, vm.bodyFontSize - 2, vm.bodyFontSize - 2);
  6184. ctx.fillStyle = helpers.color(vm.bodyColor).alpha(opacity).rgbaString(); // Return fill style for text
  6185. }
  6186. // Body Line
  6187. ctx.fillText(body, pt.x + (this._options.tooltips.mode !== 'single' ? (vm.bodyFontSize + 2) : 0), pt.y);
  6188. pt.y += vm.bodyFontSize + vm.bodySpacing;
  6189. }, this);
  6190. // After Body
  6191. helpers.each(vm.afterBody, function(afterBody) {
  6192. ctx.fillText(afterBody, pt.x, pt.y);
  6193. pt.y += vm.bodyFontSize;
  6194. });
  6195. pt.y -= vm.bodySpacing; // Remove last body spacing
  6196. },
  6197. drawFooter: function drawFooter(pt, vm, ctx, opacity) {
  6198. if (vm.footer.length) {
  6199. pt.y += vm.footerMarginTop;
  6200. ctx.textAlign = vm._footerAlign;
  6201. ctx.textBaseline = "top";
  6202. var footerColor = helpers.color(vm.footerColor);
  6203. ctx.fillStyle = footerColor.alpha(opacity * footerColor.alpha()).rgbString();
  6204. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  6205. helpers.each(vm.footer, function(footer) {
  6206. ctx.fillText(footer, pt.x, pt.y);
  6207. pt.y += vm.footerFontSize + vm.footerSpacing;
  6208. });
  6209. }
  6210. },
  6211. draw: function draw() {
  6212. var ctx = this._chart.ctx;
  6213. var vm = this._view;
  6214. if (vm.opacity === 0) {
  6215. return;
  6216. }
  6217. var caretPadding = vm.caretPadding;
  6218. var tooltipSize = this.getTooltipSize(vm);
  6219. var pt = {
  6220. x: vm.x,
  6221. y: vm.y
  6222. };
  6223. // IE11/Edge does not like very small opacities, so snap to 0
  6224. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  6225. if (this._options.tooltips.enabled) {
  6226. // Draw Background
  6227. var bgColor = helpers.color(vm.backgroundColor);
  6228. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  6229. helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
  6230. ctx.fill();
  6231. // Draw Caret
  6232. this.drawCaret(pt, tooltipSize, opacity, caretPadding);
  6233. // Draw Title, Body, and Footer
  6234. pt.x += vm.xPadding;
  6235. pt.y += vm.yPadding;
  6236. // Titles
  6237. this.drawTitle(pt, vm, ctx, opacity);
  6238. // Body
  6239. this.drawBody(pt, vm, ctx, opacity);
  6240. // Footer
  6241. this.drawFooter(pt, vm, ctx, opacity);
  6242. }
  6243. }
  6244. });
  6245. };
  6246. },{}],33:[function(require,module,exports){
  6247. "use strict";
  6248. module.exports = function(Chart, moment) {
  6249. var helpers = Chart.helpers;
  6250. Chart.defaults.global.elements.arc = {
  6251. backgroundColor: Chart.defaults.global.defaultColor,
  6252. borderColor: "#fff",
  6253. borderWidth: 2
  6254. };
  6255. Chart.elements.Arc = Chart.Element.extend({
  6256. inLabelRange: function(mouseX) {
  6257. var vm = this._view;
  6258. if (vm) {
  6259. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  6260. } else {
  6261. return false;
  6262. }
  6263. },
  6264. inRange: function(chartX, chartY) {
  6265. var vm = this._view;
  6266. if (vm) {
  6267. var pointRelativePosition = helpers.getAngleFromPoint(vm, {
  6268. x: chartX,
  6269. y: chartY
  6270. });
  6271. //Sanitise angle range
  6272. var startAngle = vm.startAngle;
  6273. var endAngle = vm.endAngle;
  6274. while (endAngle < startAngle) {
  6275. endAngle += 2.0 * Math.PI;
  6276. }
  6277. while (pointRelativePosition.angle > endAngle) {
  6278. pointRelativePosition.angle -= 2.0 * Math.PI;
  6279. }
  6280. while (pointRelativePosition.angle < startAngle) {
  6281. pointRelativePosition.angle += 2.0 * Math.PI;
  6282. }
  6283. //Check if within the range of the open/close angle
  6284. var betweenAngles = (pointRelativePosition.angle >= startAngle && pointRelativePosition.angle <= endAngle),
  6285. withinRadius = (pointRelativePosition.distance >= vm.innerRadius && pointRelativePosition.distance <= vm.outerRadius);
  6286. return (betweenAngles && withinRadius);
  6287. } else {
  6288. return false;
  6289. }
  6290. },
  6291. tooltipPosition: function() {
  6292. var vm = this._view;
  6293. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
  6294. rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  6295. return {
  6296. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  6297. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  6298. };
  6299. },
  6300. draw: function() {
  6301. var ctx = this._chart.ctx;
  6302. var vm = this._view;
  6303. ctx.beginPath();
  6304. ctx.arc(vm.x, vm.y, vm.outerRadius, vm.startAngle, vm.endAngle);
  6305. ctx.arc(vm.x, vm.y, vm.innerRadius, vm.endAngle, vm.startAngle, true);
  6306. ctx.closePath();
  6307. ctx.strokeStyle = vm.borderColor;
  6308. ctx.lineWidth = vm.borderWidth;
  6309. ctx.fillStyle = vm.backgroundColor;
  6310. ctx.fill();
  6311. ctx.lineJoin = 'bevel';
  6312. if (vm.borderWidth) {
  6313. ctx.stroke();
  6314. }
  6315. }
  6316. });
  6317. };
  6318. },{}],34:[function(require,module,exports){
  6319. "use strict";
  6320. module.exports = function(Chart) {
  6321. var helpers = Chart.helpers;
  6322. Chart.defaults.global.elements.line = {
  6323. tension: 0.4,
  6324. backgroundColor: Chart.defaults.global.defaultColor,
  6325. borderWidth: 3,
  6326. borderColor: Chart.defaults.global.defaultColor,
  6327. borderCapStyle: 'butt',
  6328. borderDash: [],
  6329. borderDashOffset: 0.0,
  6330. borderJoinStyle: 'miter',
  6331. fill: true // do we fill in the area between the line and its base axis
  6332. };
  6333. Chart.elements.Line = Chart.Element.extend({
  6334. lineToNextPoint: function(previousPoint, point, nextPoint, skipHandler, previousSkipHandler) {
  6335. var ctx = this._chart.ctx;
  6336. if (point._view.skip) {
  6337. skipHandler.call(this, previousPoint, point, nextPoint);
  6338. } else if (previousPoint._view.skip) {
  6339. previousSkipHandler.call(this, previousPoint, point, nextPoint);
  6340. } else if (point._view.tension === 0) {
  6341. ctx.lineTo(point._view.x, point._view.y);
  6342. } else {
  6343. // Line between points
  6344. ctx.bezierCurveTo(
  6345. previousPoint._view.controlPointNextX,
  6346. previousPoint._view.controlPointNextY,
  6347. point._view.controlPointPreviousX,
  6348. point._view.controlPointPreviousY,
  6349. point._view.x,
  6350. point._view.y
  6351. );
  6352. }
  6353. },
  6354. draw: function() {
  6355. var _this = this;
  6356. var vm = this._view;
  6357. var ctx = this._chart.ctx;
  6358. var first = this._children[0];
  6359. var last = this._children[this._children.length - 1];
  6360. function loopBackToStart(drawLineToCenter) {
  6361. if (!first._view.skip && !last._view.skip) {
  6362. // Draw a bezier line from last to first
  6363. ctx.bezierCurveTo(
  6364. last._view.controlPointNextX,
  6365. last._view.controlPointNextY,
  6366. first._view.controlPointPreviousX,
  6367. first._view.controlPointPreviousY,
  6368. first._view.x,
  6369. first._view.y
  6370. );
  6371. } else if (drawLineToCenter) {
  6372. // Go to center
  6373. ctx.lineTo(_this._view.scaleZero.x, _this._view.scaleZero.y);
  6374. }
  6375. }
  6376. ctx.save();
  6377. // If we had points and want to fill this line, do so.
  6378. if (this._children.length > 0 && vm.fill) {
  6379. // Draw the background first (so the border is always on top)
  6380. ctx.beginPath();
  6381. helpers.each(this._children, function(point, index) {
  6382. var previous = helpers.previousItem(this._children, index);
  6383. var next = helpers.nextItem(this._children, index);
  6384. // First point moves to it's starting position no matter what
  6385. if (index === 0) {
  6386. if (this._loop) {
  6387. ctx.moveTo(vm.scaleZero.x, vm.scaleZero.y);
  6388. } else {
  6389. ctx.moveTo(point._view.x, vm.scaleZero);
  6390. }
  6391. if (point._view.skip) {
  6392. if (!this._loop) {
  6393. ctx.moveTo(next._view.x, this._view.scaleZero);
  6394. }
  6395. } else {
  6396. ctx.lineTo(point._view.x, point._view.y);
  6397. }
  6398. } else {
  6399. this.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
  6400. if (this._loop) {
  6401. // Go to center
  6402. ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
  6403. } else {
  6404. ctx.lineTo(previousPoint._view.x, this._view.scaleZero);
  6405. ctx.moveTo(nextPoint._view.x, this._view.scaleZero);
  6406. }
  6407. }, function(previousPoint, point) {
  6408. // If we skipped the last point, draw a line to ourselves so that the fill is nice
  6409. ctx.lineTo(point._view.x, point._view.y);
  6410. });
  6411. }
  6412. }, this);
  6413. // For radial scales, loop back around to the first point
  6414. if (this._loop) {
  6415. loopBackToStart(true);
  6416. } else {
  6417. //Round off the line by going to the base of the chart, back to the start, then fill.
  6418. ctx.lineTo(this._children[this._children.length - 1]._view.x, vm.scaleZero);
  6419. ctx.lineTo(this._children[0]._view.x, vm.scaleZero);
  6420. }
  6421. ctx.fillStyle = vm.backgroundColor || Chart.defaults.global.defaultColor;
  6422. ctx.closePath();
  6423. ctx.fill();
  6424. }
  6425. // Now draw the line between all the points with any borders
  6426. ctx.lineCap = vm.borderCapStyle || Chart.defaults.global.elements.line.borderCapStyle;
  6427. // IE 9 and 10 do not support line dash
  6428. if (ctx.setLineDash) {
  6429. ctx.setLineDash(vm.borderDash || Chart.defaults.global.elements.line.borderDash);
  6430. }
  6431. ctx.lineDashOffset = vm.borderDashOffset || Chart.defaults.global.elements.line.borderDashOffset;
  6432. ctx.lineJoin = vm.borderJoinStyle || Chart.defaults.global.elements.line.borderJoinStyle;
  6433. ctx.lineWidth = vm.borderWidth || Chart.defaults.global.elements.line.borderWidth;
  6434. ctx.strokeStyle = vm.borderColor || Chart.defaults.global.defaultColor;
  6435. ctx.beginPath();
  6436. helpers.each(this._children, function(point, index) {
  6437. var previous = helpers.previousItem(this._children, index);
  6438. var next = helpers.nextItem(this._children, index);
  6439. if (index === 0) {
  6440. ctx.moveTo(point._view.x, point._view.y);
  6441. } else {
  6442. this.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
  6443. ctx.moveTo(nextPoint._view.x, nextPoint._view.y);
  6444. }, function(previousPoint, point) {
  6445. // If we skipped the last point, move up to our point preventing a line from being drawn
  6446. ctx.moveTo(point._view.x, point._view.y);
  6447. });
  6448. }
  6449. }, this);
  6450. if (this._loop && this._children.length > 0) {
  6451. loopBackToStart();
  6452. }
  6453. ctx.stroke();
  6454. ctx.restore();
  6455. }
  6456. });
  6457. };
  6458. },{}],35:[function(require,module,exports){
  6459. "use strict";
  6460. module.exports = function(Chart) {
  6461. var helpers = Chart.helpers;
  6462. Chart.defaults.global.elements.point = {
  6463. radius: 3,
  6464. pointStyle: 'circle',
  6465. backgroundColor: Chart.defaults.global.defaultColor,
  6466. borderWidth: 1,
  6467. borderColor: Chart.defaults.global.defaultColor,
  6468. // Hover
  6469. hitRadius: 1,
  6470. hoverRadius: 4,
  6471. hoverBorderWidth: 1
  6472. };
  6473. Chart.elements.Point = Chart.Element.extend({
  6474. inRange: function(mouseX, mouseY) {
  6475. var vm = this._view;
  6476. if (vm) {
  6477. var hoverRange = vm.hitRadius + vm.radius;
  6478. return ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(hoverRange, 2));
  6479. } else {
  6480. return false;
  6481. }
  6482. },
  6483. inLabelRange: function(mouseX) {
  6484. var vm = this._view;
  6485. if (vm) {
  6486. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2));
  6487. } else {
  6488. return false;
  6489. }
  6490. },
  6491. tooltipPosition: function() {
  6492. var vm = this._view;
  6493. return {
  6494. x: vm.x,
  6495. y: vm.y,
  6496. padding: vm.radius + vm.borderWidth
  6497. };
  6498. },
  6499. draw: function() {
  6500. var vm = this._view;
  6501. var ctx = this._chart.ctx;
  6502. if (vm.skip) {
  6503. return;
  6504. }
  6505. if (typeof vm.pointStyle === 'object' && ((vm.pointStyle.toString() === '[object HTMLImageElement]') || (vm.pointStyle.toString() === '[object HTMLCanvasElement]'))) {
  6506. ctx.drawImage(vm.pointStyle, vm.x - vm.pointStyle.width / 2, vm.y - vm.pointStyle.height / 2);
  6507. return;
  6508. }
  6509. if (!isNaN(vm.radius) && vm.radius > 0) {
  6510. ctx.strokeStyle = vm.borderColor || Chart.defaults.global.defaultColor;
  6511. ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, Chart.defaults.global.elements.point.borderWidth);
  6512. ctx.fillStyle = vm.backgroundColor || Chart.defaults.global.defaultColor;
  6513. var radius = vm.radius;
  6514. var xOffset;
  6515. var yOffset;
  6516. switch (vm.pointStyle) {
  6517. // Default includes circle
  6518. default: ctx.beginPath();
  6519. ctx.arc(vm.x, vm.y, radius, 0, Math.PI * 2);
  6520. ctx.closePath();
  6521. ctx.fill();
  6522. break;
  6523. case 'triangle':
  6524. ctx.beginPath();
  6525. var edgeLength = 3 * radius / Math.sqrt(3);
  6526. var height = edgeLength * Math.sqrt(3) / 2;
  6527. ctx.moveTo(vm.x - edgeLength / 2, vm.y + height / 3);
  6528. ctx.lineTo(vm.x + edgeLength / 2, vm.y + height / 3);
  6529. ctx.lineTo(vm.x, vm.y - 2 * height / 3);
  6530. ctx.closePath();
  6531. ctx.fill();
  6532. break;
  6533. case 'rect':
  6534. ctx.fillRect(vm.x - 1 / Math.SQRT2 * radius, vm.y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
  6535. ctx.strokeRect(vm.x - 1 / Math.SQRT2 * radius, vm.y - 1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
  6536. break;
  6537. case 'rectRot':
  6538. ctx.translate(vm.x, vm.y);
  6539. ctx.rotate(Math.PI / 4);
  6540. ctx.fillRect(-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
  6541. ctx.strokeRect(-1 / Math.SQRT2 * radius, -1 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius, 2 / Math.SQRT2 * radius);
  6542. ctx.setTransform(1, 0, 0, 1, 0, 0);
  6543. break;
  6544. case 'cross':
  6545. ctx.beginPath();
  6546. ctx.moveTo(vm.x, vm.y + radius);
  6547. ctx.lineTo(vm.x, vm.y - radius);
  6548. ctx.moveTo(vm.x - radius, vm.y);
  6549. ctx.lineTo(vm.x + radius, vm.y);
  6550. ctx.closePath();
  6551. break;
  6552. case 'crossRot':
  6553. ctx.beginPath();
  6554. xOffset = Math.cos(Math.PI / 4) * radius;
  6555. yOffset = Math.sin(Math.PI / 4) * radius;
  6556. ctx.moveTo(vm.x - xOffset, vm.y - yOffset);
  6557. ctx.lineTo(vm.x + xOffset, vm.y + yOffset);
  6558. ctx.moveTo(vm.x - xOffset, vm.y + yOffset);
  6559. ctx.lineTo(vm.x + xOffset, vm.y - yOffset);
  6560. ctx.closePath();
  6561. break;
  6562. case 'star':
  6563. ctx.beginPath();
  6564. ctx.moveTo(vm.x, vm.y + radius);
  6565. ctx.lineTo(vm.x, vm.y - radius);
  6566. ctx.moveTo(vm.x - radius, vm.y);
  6567. ctx.lineTo(vm.x + radius, vm.y);
  6568. xOffset = Math.cos(Math.PI / 4) * radius;
  6569. yOffset = Math.sin(Math.PI / 4) * radius;
  6570. ctx.moveTo(vm.x - xOffset, vm.y - yOffset);
  6571. ctx.lineTo(vm.x + xOffset, vm.y + yOffset);
  6572. ctx.moveTo(vm.x - xOffset, vm.y + yOffset);
  6573. ctx.lineTo(vm.x + xOffset, vm.y - yOffset);
  6574. ctx.closePath();
  6575. break;
  6576. case 'line':
  6577. ctx.beginPath();
  6578. ctx.moveTo(vm.x - radius, vm.y);
  6579. ctx.lineTo(vm.x + radius, vm.y);
  6580. ctx.closePath();
  6581. break;
  6582. case 'dash':
  6583. ctx.beginPath();
  6584. ctx.moveTo(vm.x, vm.y);
  6585. ctx.lineTo(vm.x + radius, vm.y);
  6586. ctx.closePath();
  6587. break;
  6588. }
  6589. ctx.stroke();
  6590. }
  6591. }
  6592. });
  6593. };
  6594. },{}],36:[function(require,module,exports){
  6595. "use strict";
  6596. module.exports = function(Chart) {
  6597. var helpers = Chart.helpers;
  6598. Chart.defaults.global.elements.rectangle = {
  6599. backgroundColor: Chart.defaults.global.defaultColor,
  6600. borderWidth: 0,
  6601. borderColor: Chart.defaults.global.defaultColor,
  6602. borderSkipped: 'bottom'
  6603. };
  6604. Chart.elements.Rectangle = Chart.Element.extend({
  6605. draw: function() {
  6606. var ctx = this._chart.ctx;
  6607. var vm = this._view;
  6608. var halfWidth = vm.width / 2,
  6609. leftX = vm.x - halfWidth,
  6610. rightX = vm.x + halfWidth,
  6611. top = vm.base - (vm.base - vm.y),
  6612. halfStroke = vm.borderWidth / 2;
  6613. // Canvas doesn't allow us to stroke inside the width so we can
  6614. // adjust the sizes to fit if we're setting a stroke on the line
  6615. if (vm.borderWidth) {
  6616. leftX += halfStroke;
  6617. rightX -= halfStroke;
  6618. top += halfStroke;
  6619. }
  6620. ctx.beginPath();
  6621. ctx.fillStyle = vm.backgroundColor;
  6622. ctx.strokeStyle = vm.borderColor;
  6623. ctx.lineWidth = vm.borderWidth;
  6624. // Corner points, from bottom-left to bottom-right clockwise
  6625. // | 1 2 |
  6626. // | 0 3 |
  6627. var corners = [
  6628. [leftX, vm.base],
  6629. [leftX, top],
  6630. [rightX, top],
  6631. [rightX, vm.base]
  6632. ];
  6633. // Find first (starting) corner with fallback to 'bottom'
  6634. var borders = ['bottom', 'left', 'top', 'right'];
  6635. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  6636. if (startCorner === -1)
  6637. startCorner = 0;
  6638. function cornerAt(index) {
  6639. return corners[(startCorner + index) % 4];
  6640. }
  6641. // Draw rectangle from 'startCorner'
  6642. ctx.moveTo.apply(ctx, cornerAt(0));
  6643. for (var i = 1; i < 4; i++)
  6644. ctx.lineTo.apply(ctx, cornerAt(i));
  6645. ctx.fill();
  6646. if (vm.borderWidth) {
  6647. ctx.stroke();
  6648. }
  6649. },
  6650. height: function() {
  6651. var vm = this._view;
  6652. return vm.base - vm.y;
  6653. },
  6654. inRange: function(mouseX, mouseY) {
  6655. var vm = this._view;
  6656. var inRange = false;
  6657. if (vm) {
  6658. if (vm.y < vm.base) {
  6659. inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base);
  6660. } else {
  6661. inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y);
  6662. }
  6663. }
  6664. return inRange;
  6665. },
  6666. inLabelRange: function(mouseX) {
  6667. var vm = this._view;
  6668. if (vm) {
  6669. return (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2);
  6670. } else {
  6671. return false;
  6672. }
  6673. },
  6674. tooltipPosition: function() {
  6675. var vm = this._view;
  6676. return {
  6677. x: vm.x,
  6678. y: vm.y
  6679. };
  6680. }
  6681. });
  6682. };
  6683. },{}],37:[function(require,module,exports){
  6684. "use strict";
  6685. module.exports = function(Chart) {
  6686. var helpers = Chart.helpers;
  6687. // Default config for a category scale
  6688. var defaultConfig = {
  6689. position: "bottom"
  6690. };
  6691. var DatasetScale = Chart.Scale.extend({
  6692. buildTicks: function(index) {
  6693. this.startIndex = 0;
  6694. this.endIndex = this.chart.data.labels.length;
  6695. var findIndex;
  6696. if (this.options.ticks.min !== undefined) {
  6697. // user specified min value
  6698. findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min);
  6699. this.startIndex = findIndex !== -1 ? findIndex : this.startIndex;
  6700. }
  6701. if (this.options.ticks.max !== undefined) {
  6702. // user specified max value
  6703. findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.max);
  6704. this.endIndex = findIndex !== -1 ? findIndex : this.endIndex;
  6705. }
  6706. // If we are viewing some subset of labels, slice the original array
  6707. this.ticks = (this.startIndex === 0 && this.endIndex === this.chart.data.labels.length) ? this.chart.data.labels : this.chart.data.labels.slice(this.startIndex, this.endIndex + 1);
  6708. },
  6709. getLabelForIndex: function(index, datasetIndex) {
  6710. return this.ticks[index];
  6711. },
  6712. // Used to get data value locations. Value can either be an index or a numerical value
  6713. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  6714. // 1 is added because we need the length but we have the indexes
  6715. var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  6716. if (this.isHorizontal()) {
  6717. var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
  6718. var valueWidth = innerWidth / offsetAmt;
  6719. var widthOffset = (valueWidth * (index - this.startIndex)) + this.paddingLeft;
  6720. if (this.options.gridLines.offsetGridLines && includeOffset) {
  6721. widthOffset += (valueWidth / 2);
  6722. }
  6723. return this.left + Math.round(widthOffset);
  6724. } else {
  6725. var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
  6726. var valueHeight = innerHeight / offsetAmt;
  6727. var heightOffset = (valueHeight * (index - this.startIndex)) + this.paddingTop;
  6728. if (this.options.gridLines.offsetGridLines && includeOffset) {
  6729. heightOffset += (valueHeight / 2);
  6730. }
  6731. return this.top + Math.round(heightOffset);
  6732. }
  6733. },
  6734. getPixelForTick: function(index, includeOffset) {
  6735. return this.getPixelForValue(this.ticks[index], index + this.startIndex, null, includeOffset);
  6736. }
  6737. });
  6738. Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig);
  6739. };
  6740. },{}],38:[function(require,module,exports){
  6741. "use strict";
  6742. module.exports = function(Chart) {
  6743. var helpers = Chart.helpers;
  6744. var defaultConfig = {
  6745. position: "left",
  6746. ticks: {
  6747. callback: function(tickValue, index, ticks) {
  6748. var delta = ticks[1] - ticks[0];
  6749. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  6750. if (Math.abs(delta) > 1) {
  6751. if (tickValue !== Math.floor(tickValue)) {
  6752. // not an integer
  6753. delta = tickValue - Math.floor(tickValue);
  6754. }
  6755. }
  6756. var logDelta = helpers.log10(Math.abs(delta));
  6757. var tickString = '';
  6758. if (tickValue !== 0) {
  6759. var numDecimal = -1 * Math.floor(logDelta);
  6760. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  6761. tickString = tickValue.toFixed(numDecimal);
  6762. } else {
  6763. tickString = '0'; // never show decimal places for 0
  6764. }
  6765. return tickString;
  6766. }
  6767. }
  6768. };
  6769. var LinearScale = Chart.Scale.extend({
  6770. determineDataLimits: function() {
  6771. // First Calculate the range
  6772. this.min = null;
  6773. this.max = null;
  6774. if (this.options.stacked) {
  6775. var valuesPerType = {};
  6776. var hasPositiveValues = false;
  6777. var hasNegativeValues = false;
  6778. helpers.each(this.chart.data.datasets, function(dataset) {
  6779. if (valuesPerType[dataset.type] === undefined) {
  6780. valuesPerType[dataset.type] = {
  6781. positiveValues: [],
  6782. negativeValues: []
  6783. };
  6784. }
  6785. // Store these per type
  6786. var positiveValues = valuesPerType[dataset.type].positiveValues;
  6787. var negativeValues = valuesPerType[dataset.type].negativeValues;
  6788. if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
  6789. helpers.each(dataset.data, function(rawValue, index) {
  6790. var value = +this.getRightValue(rawValue);
  6791. if (isNaN(value)) {
  6792. return;
  6793. }
  6794. positiveValues[index] = positiveValues[index] || 0;
  6795. negativeValues[index] = negativeValues[index] || 0;
  6796. if (this.options.relativePoints) {
  6797. positiveValues[index] = 100;
  6798. } else {
  6799. if (value < 0) {
  6800. hasNegativeValues = true;
  6801. negativeValues[index] += value;
  6802. } else {
  6803. hasPositiveValues = true;
  6804. positiveValues[index] += value;
  6805. }
  6806. }
  6807. }, this);
  6808. }
  6809. }, this);
  6810. helpers.each(valuesPerType, function(valuesForType) {
  6811. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  6812. var minVal = helpers.min(values);
  6813. var maxVal = helpers.max(values);
  6814. this.min = this.min === null ? minVal : Math.min(this.min, minVal);
  6815. this.max = this.max === null ? maxVal : Math.max(this.max, maxVal);
  6816. }, this);
  6817. } else {
  6818. helpers.each(this.chart.data.datasets, function(dataset) {
  6819. if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
  6820. helpers.each(dataset.data, function(rawValue, index) {
  6821. var value = +this.getRightValue(rawValue);
  6822. if (isNaN(value)) {
  6823. return;
  6824. }
  6825. if (this.min === null) {
  6826. this.min = value;
  6827. } else if (value < this.min) {
  6828. this.min = value;
  6829. }
  6830. if (this.max === null) {
  6831. this.max = value;
  6832. } else if (value > this.max) {
  6833. this.max = value;
  6834. }
  6835. }, this);
  6836. }
  6837. }, this);
  6838. }
  6839. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  6840. // do nothing since that would make the chart weird. If the user really wants a weird chart
  6841. // axis, they can manually override it
  6842. if (this.options.ticks.beginAtZero) {
  6843. var minSign = helpers.sign(this.min);
  6844. var maxSign = helpers.sign(this.max);
  6845. if (minSign < 0 && maxSign < 0) {
  6846. // move the top up to 0
  6847. this.max = 0;
  6848. } else if (minSign > 0 && maxSign > 0) {
  6849. // move the botttom down to 0
  6850. this.min = 0;
  6851. }
  6852. }
  6853. if (this.options.ticks.min !== undefined) {
  6854. this.min = this.options.ticks.min;
  6855. } else if (this.options.ticks.suggestedMin !== undefined) {
  6856. this.min = Math.min(this.min, this.options.ticks.suggestedMin);
  6857. }
  6858. if (this.options.ticks.max !== undefined) {
  6859. this.max = this.options.ticks.max;
  6860. } else if (this.options.ticks.suggestedMax !== undefined) {
  6861. this.max = Math.max(this.max, this.options.ticks.suggestedMax);
  6862. }
  6863. if (this.min === this.max) {
  6864. this.min--;
  6865. this.max++;
  6866. }
  6867. },
  6868. buildTicks: function() {
  6869. // Then calulate the ticks
  6870. this.ticks = [];
  6871. // Figure out what the max number of ticks we can support it is based on the size of
  6872. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  6873. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  6874. // the graph
  6875. var maxTicks;
  6876. if (this.isHorizontal()) {
  6877. maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11, Math.ceil(this.width / 50));
  6878. } else {
  6879. // The factor of 2 used to scale the font size has been experimentally determined.
  6880. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  6881. maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11, Math.ceil(this.height / (2 * tickFontSize)));
  6882. }
  6883. // Make sure we always have at least 2 ticks
  6884. maxTicks = Math.max(2, maxTicks);
  6885. // To get a "nice" value for the tick spacing, we will use the appropriately named
  6886. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  6887. // for details.
  6888. var spacing;
  6889. var fixedStepSizeSet = (this.options.ticks.fixedStepSize && this.options.ticks.fixedStepSize > 0) || (this.options.ticks.stepSize && this.options.ticks.stepSize > 0);
  6890. if (fixedStepSizeSet) {
  6891. spacing = helpers.getValueOrDefault(this.options.ticks.fixedStepSize, this.options.ticks.stepSize);
  6892. } else {
  6893. var niceRange = helpers.niceNum(this.max - this.min, false);
  6894. spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
  6895. }
  6896. var niceMin = Math.floor(this.min / spacing) * spacing;
  6897. var niceMax = Math.ceil(this.max / spacing) * spacing;
  6898. var numSpaces = (niceMax - niceMin) / spacing;
  6899. // If very close to our rounded value, use it.
  6900. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  6901. numSpaces = Math.round(numSpaces);
  6902. } else {
  6903. numSpaces = Math.ceil(numSpaces);
  6904. }
  6905. // Put the values into the ticks array
  6906. this.ticks.push(this.options.ticks.min !== undefined ? this.options.ticks.min : niceMin);
  6907. for (var j = 1; j < numSpaces; ++j) {
  6908. this.ticks.push(niceMin + (j * spacing));
  6909. }
  6910. this.ticks.push(this.options.ticks.max !== undefined ? this.options.ticks.max : niceMax);
  6911. if (this.options.position === "left" || this.options.position === "right") {
  6912. // We are in a vertical orientation. The top value is the highest. So reverse the array
  6913. this.ticks.reverse();
  6914. }
  6915. // At this point, we need to update our max and min given the tick values since we have expanded the
  6916. // range of the scale
  6917. this.max = helpers.max(this.ticks);
  6918. this.min = helpers.min(this.ticks);
  6919. if (this.options.ticks.reverse) {
  6920. this.ticks.reverse();
  6921. this.start = this.max;
  6922. this.end = this.min;
  6923. } else {
  6924. this.start = this.min;
  6925. this.end = this.max;
  6926. }
  6927. },
  6928. getLabelForIndex: function(index, datasetIndex) {
  6929. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  6930. },
  6931. convertTicksToLabels: function() {
  6932. this.ticksAsNumbers = this.ticks.slice();
  6933. this.zeroLineIndex = this.ticks.indexOf(0);
  6934. Chart.Scale.prototype.convertTicksToLabels.call(this);
  6935. },
  6936. // Utils
  6937. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  6938. // This must be called after fit has been run so that
  6939. // this.left, this.top, this.right, and this.bottom have been defined
  6940. var rightValue = +this.getRightValue(value);
  6941. var pixel;
  6942. var range = this.end - this.start;
  6943. if (this.isHorizontal()) {
  6944. var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
  6945. pixel = this.left + (innerWidth / range * (rightValue - this.start));
  6946. return Math.round(pixel + this.paddingLeft);
  6947. } else {
  6948. var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
  6949. pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (rightValue - this.start));
  6950. return Math.round(pixel);
  6951. }
  6952. },
  6953. getPixelForTick: function(index, includeOffset) {
  6954. return this.getPixelForValue(this.ticksAsNumbers[index], null, null, includeOffset);
  6955. }
  6956. });
  6957. Chart.scaleService.registerScaleType("linear", LinearScale, defaultConfig);
  6958. };
  6959. },{}],39:[function(require,module,exports){
  6960. "use strict";
  6961. module.exports = function(Chart) {
  6962. var helpers = Chart.helpers;
  6963. var defaultConfig = {
  6964. position: "left",
  6965. // label settings
  6966. ticks: {
  6967. callback: function(value, index, arr) {
  6968. var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));
  6969. if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
  6970. return value.toExponential();
  6971. } else {
  6972. return '';
  6973. }
  6974. }
  6975. }
  6976. };
  6977. var LogarithmicScale = Chart.Scale.extend({
  6978. determineDataLimits: function() {
  6979. // Calculate Range
  6980. this.min = null;
  6981. this.max = null;
  6982. if (this.options.stacked) {
  6983. var valuesPerType = {};
  6984. helpers.each(this.chart.data.datasets, function(dataset) {
  6985. if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
  6986. if (valuesPerType[dataset.type] === undefined) {
  6987. valuesPerType[dataset.type] = [];
  6988. }
  6989. helpers.each(dataset.data, function(rawValue, index) {
  6990. var values = valuesPerType[dataset.type];
  6991. var value = +this.getRightValue(rawValue);
  6992. if (isNaN(value)) {
  6993. return;
  6994. }
  6995. values[index] = values[index] || 0;
  6996. if (this.options.relativePoints) {
  6997. values[index] = 100;
  6998. } else {
  6999. // Don't need to split positive and negative since the log scale can't handle a 0 crossing
  7000. values[index] += value;
  7001. }
  7002. }, this);
  7003. }
  7004. }, this);
  7005. helpers.each(valuesPerType, function(valuesForType) {
  7006. var minVal = helpers.min(valuesForType);
  7007. var maxVal = helpers.max(valuesForType);
  7008. this.min = this.min === null ? minVal : Math.min(this.min, minVal);
  7009. this.max = this.max === null ? maxVal : Math.max(this.max, maxVal);
  7010. }, this);
  7011. } else {
  7012. helpers.each(this.chart.data.datasets, function(dataset) {
  7013. if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
  7014. helpers.each(dataset.data, function(rawValue, index) {
  7015. var value = +this.getRightValue(rawValue);
  7016. if (isNaN(value)) {
  7017. return;
  7018. }
  7019. if (this.min === null) {
  7020. this.min = value;
  7021. } else if (value < this.min) {
  7022. this.min = value;
  7023. }
  7024. if (this.max === null) {
  7025. this.max = value;
  7026. } else if (value > this.max) {
  7027. this.max = value;
  7028. }
  7029. }, this);
  7030. }
  7031. }, this);
  7032. }
  7033. this.min = this.options.ticks.min !== undefined ? this.options.ticks.min : this.min;
  7034. this.max = this.options.ticks.max !== undefined ? this.options.ticks.max : this.max;
  7035. if (this.min === this.max) {
  7036. if (this.min !== 0 && this.min !== null) {
  7037. this.min = Math.pow(10, Math.floor(helpers.log10(this.min)) - 1);
  7038. this.max = Math.pow(10, Math.floor(helpers.log10(this.max)) + 1);
  7039. } else {
  7040. this.min = 1;
  7041. this.max = 10;
  7042. }
  7043. }
  7044. },
  7045. buildTicks: function() {
  7046. // Reset the ticks array. Later on, we will draw a grid line at these positions
  7047. // The array simply contains the numerical value of the spots where ticks will be
  7048. this.ticks = [];
  7049. // Figure out what the max number of ticks we can support it is based on the size of
  7050. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  7051. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  7052. // the graph
  7053. var tickVal = this.options.ticks.min !== undefined ? this.options.ticks.min : Math.pow(10, Math.floor(helpers.log10(this.min)));
  7054. while (tickVal < this.max) {
  7055. this.ticks.push(tickVal);
  7056. var exp = Math.floor(helpers.log10(tickVal));
  7057. var significand = Math.floor(tickVal / Math.pow(10, exp)) + 1;
  7058. if (significand === 10) {
  7059. significand = 1;
  7060. ++exp;
  7061. }
  7062. tickVal = significand * Math.pow(10, exp);
  7063. }
  7064. var lastTick = this.options.ticks.max !== undefined ? this.options.ticks.max : tickVal;
  7065. this.ticks.push(lastTick);
  7066. if (this.options.position === "left" || this.options.position === "right") {
  7067. // We are in a vertical orientation. The top value is the highest. So reverse the array
  7068. this.ticks.reverse();
  7069. }
  7070. // At this point, we need to update our max and min given the tick values since we have expanded the
  7071. // range of the scale
  7072. this.max = helpers.max(this.ticks);
  7073. this.min = helpers.min(this.ticks);
  7074. if (this.options.ticks.reverse) {
  7075. this.ticks.reverse();
  7076. this.start = this.max;
  7077. this.end = this.min;
  7078. } else {
  7079. this.start = this.min;
  7080. this.end = this.max;
  7081. }
  7082. },
  7083. convertTicksToLabels: function() {
  7084. this.tickValues = this.ticks.slice();
  7085. Chart.Scale.prototype.convertTicksToLabels.call(this);
  7086. },
  7087. // Get the correct tooltip label
  7088. getLabelForIndex: function(index, datasetIndex) {
  7089. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  7090. },
  7091. getPixelForTick: function(index, includeOffset) {
  7092. return this.getPixelForValue(this.tickValues[index], null, null, includeOffset);
  7093. },
  7094. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  7095. var pixel;
  7096. var newVal = +this.getRightValue(value);
  7097. var range = helpers.log10(this.end) - helpers.log10(this.start);
  7098. if (this.isHorizontal()) {
  7099. if (newVal === 0) {
  7100. pixel = this.left + this.paddingLeft;
  7101. } else {
  7102. var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
  7103. pixel = this.left + (innerWidth / range * (helpers.log10(newVal) - helpers.log10(this.start)));
  7104. pixel += this.paddingLeft;
  7105. }
  7106. } else {
  7107. // Bottom - top since pixels increase downard on a screen
  7108. if (newVal === 0) {
  7109. pixel = this.top + this.paddingTop;
  7110. } else {
  7111. var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
  7112. pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (helpers.log10(newVal) - helpers.log10(this.start)));
  7113. }
  7114. }
  7115. return pixel;
  7116. }
  7117. });
  7118. Chart.scaleService.registerScaleType("logarithmic", LogarithmicScale, defaultConfig);
  7119. };
  7120. },{}],40:[function(require,module,exports){
  7121. "use strict";
  7122. module.exports = function(Chart) {
  7123. var helpers = Chart.helpers;
  7124. var defaultConfig = {
  7125. display: true,
  7126. //Boolean - Whether to animate scaling the chart from the centre
  7127. animate: true,
  7128. lineArc: false,
  7129. position: "chartArea",
  7130. angleLines: {
  7131. display: true,
  7132. color: "rgba(0, 0, 0, 0.1)",
  7133. lineWidth: 1
  7134. },
  7135. // label settings
  7136. ticks: {
  7137. //Boolean - Show a backdrop to the scale label
  7138. showLabelBackdrop: true,
  7139. //String - The colour of the label backdrop
  7140. backdropColor: "rgba(255,255,255,0.75)",
  7141. //Number - The backdrop padding above & below the label in pixels
  7142. backdropPaddingY: 2,
  7143. //Number - The backdrop padding to the side of the label in pixels
  7144. backdropPaddingX: 2
  7145. },
  7146. pointLabels: {
  7147. //Number - Point label font size in pixels
  7148. fontSize: 10,
  7149. //Function - Used to convert point labels
  7150. callback: function(label) {
  7151. return label;
  7152. }
  7153. }
  7154. };
  7155. var LinearRadialScale = Chart.Scale.extend({
  7156. getValueCount: function() {
  7157. return this.chart.data.labels.length;
  7158. },
  7159. setDimensions: function() {
  7160. // Set the unconstrained dimension before label rotation
  7161. this.width = this.maxWidth;
  7162. this.height = this.maxHeight;
  7163. this.xCenter = Math.round(this.width / 2);
  7164. this.yCenter = Math.round(this.height / 2);
  7165. var minSize = helpers.min([this.height, this.width]);
  7166. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  7167. this.drawingArea = (this.options.display) ? (minSize / 2) - (tickFontSize / 2 + this.options.ticks.backdropPaddingY) : (minSize / 2);
  7168. },
  7169. determineDataLimits: function() {
  7170. this.min = null;
  7171. this.max = null;
  7172. helpers.each(this.chart.data.datasets, function(dataset) {
  7173. if (helpers.isDatasetVisible(dataset)) {
  7174. helpers.each(dataset.data, function(rawValue, index) {
  7175. var value = +this.getRightValue(rawValue);
  7176. if (isNaN(value)) {
  7177. return;
  7178. }
  7179. if (this.min === null) {
  7180. this.min = value;
  7181. } else if (value < this.min) {
  7182. this.min = value;
  7183. }
  7184. if (this.max === null) {
  7185. this.max = value;
  7186. } else if (value > this.max) {
  7187. this.max = value;
  7188. }
  7189. }, this);
  7190. }
  7191. }, this);
  7192. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  7193. // do nothing since that would make the chart weird. If the user really wants a weird chart
  7194. // axis, they can manually override it
  7195. if (this.options.ticks.beginAtZero) {
  7196. var minSign = helpers.sign(this.min);
  7197. var maxSign = helpers.sign(this.max);
  7198. if (minSign < 0 && maxSign < 0) {
  7199. // move the top up to 0
  7200. this.max = 0;
  7201. } else if (minSign > 0 && maxSign > 0) {
  7202. // move the botttom down to 0
  7203. this.min = 0;
  7204. }
  7205. }
  7206. if (this.options.ticks.min !== undefined) {
  7207. this.min = this.options.ticks.min;
  7208. } else if (this.options.ticks.suggestedMin !== undefined) {
  7209. this.min = Math.min(this.min, this.options.ticks.suggestedMin);
  7210. }
  7211. if (this.options.ticks.max !== undefined) {
  7212. this.max = this.options.ticks.max;
  7213. } else if (this.options.ticks.suggestedMax !== undefined) {
  7214. this.max = Math.max(this.max, this.options.ticks.suggestedMax);
  7215. }
  7216. if (this.min === this.max) {
  7217. this.min--;
  7218. this.max++;
  7219. }
  7220. },
  7221. buildTicks: function() {
  7222. this.ticks = [];
  7223. // Figure out what the max number of ticks we can support it is based on the size of
  7224. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  7225. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  7226. // the graph
  7227. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  7228. var maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  7229. maxTicks = Math.max(2, maxTicks); // Make sure we always have at least 2 ticks
  7230. // To get a "nice" value for the tick spacing, we will use the appropriately named
  7231. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  7232. // for details.
  7233. var niceRange = helpers.niceNum(this.max - this.min, false);
  7234. var spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
  7235. var niceMin = Math.floor(this.min / spacing) * spacing;
  7236. var niceMax = Math.ceil(this.max / spacing) * spacing;
  7237. var numSpaces = Math.ceil((niceMax - niceMin) / spacing);
  7238. // Put the values into the ticks array
  7239. this.ticks.push(this.options.ticks.min !== undefined ? this.options.ticks.min : niceMin);
  7240. for (var j = 1; j < numSpaces; ++j) {
  7241. this.ticks.push(niceMin + (j * spacing));
  7242. }
  7243. this.ticks.push(this.options.ticks.max !== undefined ? this.options.ticks.max : niceMax);
  7244. // At this point, we need to update our max and min given the tick values since we have expanded the
  7245. // range of the scale
  7246. this.max = helpers.max(this.ticks);
  7247. this.min = helpers.min(this.ticks);
  7248. if (this.options.ticks.reverse) {
  7249. this.ticks.reverse();
  7250. this.start = this.max;
  7251. this.end = this.min;
  7252. } else {
  7253. this.start = this.min;
  7254. this.end = this.max;
  7255. }
  7256. this.zeroLineIndex = this.ticks.indexOf(0);
  7257. },
  7258. convertTicksToLabels: function() {
  7259. Chart.Scale.prototype.convertTicksToLabels.call(this);
  7260. // Point labels
  7261. this.pointLabels = this.chart.data.labels.map(this.options.pointLabels.callback, this);
  7262. },
  7263. getLabelForIndex: function(index, datasetIndex) {
  7264. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  7265. },
  7266. fit: function() {
  7267. /*
  7268. * Right, this is really confusing and there is a lot of maths going on here
  7269. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  7270. *
  7271. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  7272. *
  7273. * Solution:
  7274. *
  7275. * We assume the radius of the polygon is half the size of the canvas at first
  7276. * at each index we check if the text overlaps.
  7277. *
  7278. * Where it does, we store that angle and that index.
  7279. *
  7280. * After finding the largest index and angle we calculate how much we need to remove
  7281. * from the shape radius to move the point inwards by that x.
  7282. *
  7283. * We average the left and right distances to get the maximum shape radius that can fit in the box
  7284. * along with labels.
  7285. *
  7286. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  7287. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  7288. *
  7289. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  7290. * and position it in the most space efficient manner
  7291. *
  7292. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  7293. */
  7294. var pointLabelFontSize = helpers.getValueOrDefault(this.options.pointLabels.fontSize, Chart.defaults.global.defaultFontSize);
  7295. var pointLabeFontStyle = helpers.getValueOrDefault(this.options.pointLabels.fontStyle, Chart.defaults.global.defaultFontStyle);
  7296. var pointLabeFontFamily = helpers.getValueOrDefault(this.options.pointLabels.fontFamily, Chart.defaults.global.defaultFontFamily);
  7297. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  7298. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  7299. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  7300. var largestPossibleRadius = helpers.min([(this.height / 2 - pointLabelFontSize - 5), this.width / 2]),
  7301. pointPosition,
  7302. i,
  7303. textWidth,
  7304. halfTextWidth,
  7305. furthestRight = this.width,
  7306. furthestRightIndex,
  7307. furthestRightAngle,
  7308. furthestLeft = 0,
  7309. furthestLeftIndex,
  7310. furthestLeftAngle,
  7311. xProtrusionLeft,
  7312. xProtrusionRight,
  7313. radiusReductionRight,
  7314. radiusReductionLeft,
  7315. maxWidthRadius;
  7316. this.ctx.font = pointLabeFont;
  7317. for (i = 0; i < this.getValueCount(); i++) {
  7318. // 5px to space the text slightly out - similar to what we do in the draw function.
  7319. pointPosition = this.getPointPosition(i, largestPossibleRadius);
  7320. textWidth = this.ctx.measureText(this.pointLabels[i] ? this.pointLabels[i] : '').width + 5;
  7321. if (i === 0 || i === this.getValueCount() / 2) {
  7322. // If we're at index zero, or exactly the middle, we're at exactly the top/bottom
  7323. // of the radar chart, so text will be aligned centrally, so we'll half it and compare
  7324. // w/left and right text sizes
  7325. halfTextWidth = textWidth / 2;
  7326. if (pointPosition.x + halfTextWidth > furthestRight) {
  7327. furthestRight = pointPosition.x + halfTextWidth;
  7328. furthestRightIndex = i;
  7329. }
  7330. if (pointPosition.x - halfTextWidth < furthestLeft) {
  7331. furthestLeft = pointPosition.x - halfTextWidth;
  7332. furthestLeftIndex = i;
  7333. }
  7334. } else if (i < this.getValueCount() / 2) {
  7335. // Less than half the values means we'll left align the text
  7336. if (pointPosition.x + textWidth > furthestRight) {
  7337. furthestRight = pointPosition.x + textWidth;
  7338. furthestRightIndex = i;
  7339. }
  7340. } else if (i > this.getValueCount() / 2) {
  7341. // More than half the values means we'll right align the text
  7342. if (pointPosition.x - textWidth < furthestLeft) {
  7343. furthestLeft = pointPosition.x - textWidth;
  7344. furthestLeftIndex = i;
  7345. }
  7346. }
  7347. }
  7348. xProtrusionLeft = furthestLeft;
  7349. xProtrusionRight = Math.ceil(furthestRight - this.width);
  7350. furthestRightAngle = this.getIndexAngle(furthestRightIndex);
  7351. furthestLeftAngle = this.getIndexAngle(furthestLeftIndex);
  7352. radiusReductionRight = xProtrusionRight / Math.sin(furthestRightAngle + Math.PI / 2);
  7353. radiusReductionLeft = xProtrusionLeft / Math.sin(furthestLeftAngle + Math.PI / 2);
  7354. // Ensure we actually need to reduce the size of the chart
  7355. radiusReductionRight = (helpers.isNumber(radiusReductionRight)) ? radiusReductionRight : 0;
  7356. radiusReductionLeft = (helpers.isNumber(radiusReductionLeft)) ? radiusReductionLeft : 0;
  7357. this.drawingArea = Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2);
  7358. this.setCenterPoint(radiusReductionLeft, radiusReductionRight);
  7359. },
  7360. setCenterPoint: function(leftMovement, rightMovement) {
  7361. var maxRight = this.width - rightMovement - this.drawingArea,
  7362. maxLeft = leftMovement + this.drawingArea;
  7363. this.xCenter = Math.round(((maxLeft + maxRight) / 2) + this.left);
  7364. // Always vertically in the centre as the text height doesn't change
  7365. this.yCenter = Math.round((this.height / 2) + this.top);
  7366. },
  7367. getIndexAngle: function(index) {
  7368. var angleMultiplier = (Math.PI * 2) / this.getValueCount();
  7369. // Start from the top instead of right, so remove a quarter of the circle
  7370. return index * angleMultiplier - (Math.PI / 2);
  7371. },
  7372. getDistanceFromCenterForValue: function(value) {
  7373. if (value === null) {
  7374. return 0; // null always in center
  7375. }
  7376. // Take into account half font size + the yPadding of the top value
  7377. var scalingFactor = this.drawingArea / (this.max - this.min);
  7378. if (this.options.reverse) {
  7379. return (this.max - value) * scalingFactor;
  7380. } else {
  7381. return (value - this.min) * scalingFactor;
  7382. }
  7383. },
  7384. getPointPosition: function(index, distanceFromCenter) {
  7385. var thisAngle = this.getIndexAngle(index);
  7386. return {
  7387. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + this.xCenter,
  7388. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + this.yCenter
  7389. };
  7390. },
  7391. getPointPositionForValue: function(index, value) {
  7392. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  7393. },
  7394. draw: function() {
  7395. if (this.options.display) {
  7396. var ctx = this.ctx;
  7397. helpers.each(this.ticks, function(label, index) {
  7398. // Don't draw a centre value (if it is minimum)
  7399. if (index > 0 || this.options.reverse) {
  7400. var yCenterOffset = this.getDistanceFromCenterForValue(this.ticks[index]);
  7401. var yHeight = this.yCenter - yCenterOffset;
  7402. // Draw circular lines around the scale
  7403. if (this.options.gridLines.display) {
  7404. ctx.strokeStyle = this.options.gridLines.color;
  7405. ctx.lineWidth = this.options.gridLines.lineWidth;
  7406. if (this.options.lineArc) {
  7407. // Draw circular arcs between the points
  7408. ctx.beginPath();
  7409. ctx.arc(this.xCenter, this.yCenter, yCenterOffset, 0, Math.PI * 2);
  7410. ctx.closePath();
  7411. ctx.stroke();
  7412. } else {
  7413. // Draw straight lines connecting each index
  7414. ctx.beginPath();
  7415. for (var i = 0; i < this.getValueCount(); i++) {
  7416. var pointPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.ticks[index]));
  7417. if (i === 0) {
  7418. ctx.moveTo(pointPosition.x, pointPosition.y);
  7419. } else {
  7420. ctx.lineTo(pointPosition.x, pointPosition.y);
  7421. }
  7422. }
  7423. ctx.closePath();
  7424. ctx.stroke();
  7425. }
  7426. }
  7427. if (this.options.ticks.display) {
  7428. var tickFontColor = helpers.getValueOrDefault(this.options.ticks.fontColor, Chart.defaults.global.defaultFontColor);
  7429. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  7430. var tickFontStyle = helpers.getValueOrDefault(this.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  7431. var tickFontFamily = helpers.getValueOrDefault(this.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  7432. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  7433. ctx.font = tickLabelFont;
  7434. if (this.options.ticks.showLabelBackdrop) {
  7435. var labelWidth = ctx.measureText(label).width;
  7436. ctx.fillStyle = this.options.ticks.backdropColor;
  7437. ctx.fillRect(
  7438. this.xCenter - labelWidth / 2 - this.options.ticks.backdropPaddingX,
  7439. yHeight - tickFontSize / 2 - this.options.ticks.backdropPaddingY,
  7440. labelWidth + this.options.ticks.backdropPaddingX * 2,
  7441. tickFontSize + this.options.ticks.backdropPaddingY * 2
  7442. );
  7443. }
  7444. ctx.textAlign = 'center';
  7445. ctx.textBaseline = "middle";
  7446. ctx.fillStyle = tickFontColor;
  7447. ctx.fillText(label, this.xCenter, yHeight);
  7448. }
  7449. }
  7450. }, this);
  7451. if (!this.options.lineArc) {
  7452. ctx.lineWidth = this.options.angleLines.lineWidth;
  7453. ctx.strokeStyle = this.options.angleLines.color;
  7454. for (var i = this.getValueCount() - 1; i >= 0; i--) {
  7455. if (this.options.angleLines.display) {
  7456. var outerPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max));
  7457. ctx.beginPath();
  7458. ctx.moveTo(this.xCenter, this.yCenter);
  7459. ctx.lineTo(outerPosition.x, outerPosition.y);
  7460. ctx.stroke();
  7461. ctx.closePath();
  7462. }
  7463. // Extra 3px out for some label spacing
  7464. var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max) + 5);
  7465. var pointLabelFontColor = helpers.getValueOrDefault(this.options.pointLabels.fontColor, Chart.defaults.global.defaultFontColor);
  7466. var pointLabelFontSize = helpers.getValueOrDefault(this.options.pointLabels.fontSize, Chart.defaults.global.defaultFontSize);
  7467. var pointLabeFontStyle = helpers.getValueOrDefault(this.options.pointLabels.fontStyle, Chart.defaults.global.defaultFontStyle);
  7468. var pointLabeFontFamily = helpers.getValueOrDefault(this.options.pointLabels.fontFamily, Chart.defaults.global.defaultFontFamily);
  7469. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  7470. ctx.font = pointLabeFont;
  7471. ctx.fillStyle = pointLabelFontColor;
  7472. var labelsCount = this.pointLabels.length,
  7473. halfLabelsCount = this.pointLabels.length / 2,
  7474. quarterLabelsCount = halfLabelsCount / 2,
  7475. upperHalf = (i < quarterLabelsCount || i > labelsCount - quarterLabelsCount),
  7476. exactQuarter = (i === quarterLabelsCount || i === labelsCount - quarterLabelsCount);
  7477. if (i === 0) {
  7478. ctx.textAlign = 'center';
  7479. } else if (i === halfLabelsCount) {
  7480. ctx.textAlign = 'center';
  7481. } else if (i < halfLabelsCount) {
  7482. ctx.textAlign = 'left';
  7483. } else {
  7484. ctx.textAlign = 'right';
  7485. }
  7486. // Set the correct text baseline based on outer positioning
  7487. if (exactQuarter) {
  7488. ctx.textBaseline = 'middle';
  7489. } else if (upperHalf) {
  7490. ctx.textBaseline = 'bottom';
  7491. } else {
  7492. ctx.textBaseline = 'top';
  7493. }
  7494. ctx.fillText(this.pointLabels[i] ? this.pointLabels[i] : '', pointLabelPosition.x, pointLabelPosition.y);
  7495. }
  7496. }
  7497. }
  7498. }
  7499. });
  7500. Chart.scaleService.registerScaleType("radialLinear", LinearRadialScale, defaultConfig);
  7501. };
  7502. },{}],41:[function(require,module,exports){
  7503. /*global window: false */
  7504. "use strict";
  7505. var moment = require('moment');
  7506. moment = typeof(moment) === 'function' ? moment : window.moment;
  7507. module.exports = function(Chart) {
  7508. var helpers = Chart.helpers;
  7509. var time = {
  7510. units: [{
  7511. name: 'millisecond',
  7512. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  7513. }, {
  7514. name: 'second',
  7515. steps: [1, 2, 5, 10, 30]
  7516. }, {
  7517. name: 'minute',
  7518. steps: [1, 2, 5, 10, 30]
  7519. }, {
  7520. name: 'hour',
  7521. steps: [1, 2, 3, 6, 12]
  7522. }, {
  7523. name: 'day',
  7524. steps: [1, 2, 5]
  7525. }, {
  7526. name: 'week',
  7527. maxStep: 4
  7528. }, {
  7529. name: 'month',
  7530. maxStep: 3
  7531. }, {
  7532. name: 'quarter',
  7533. maxStep: 4
  7534. }, {
  7535. name: 'year',
  7536. maxStep: false
  7537. }]
  7538. };
  7539. var defaultConfig = {
  7540. position: "bottom",
  7541. time: {
  7542. 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
  7543. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  7544. unit: false, // false == automatic or override with week, month, year, etc.
  7545. round: false, // none, or override with week, month, year, etc.
  7546. displayFormat: false, // DEPRECATED
  7547. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  7548. displayFormats: {
  7549. 'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  7550. 'second': 'h:mm:ss a', // 11:20:01 AM
  7551. 'minute': 'h:mm:ss a', // 11:20:01 AM
  7552. 'hour': 'MMM D, hA', // Sept 4, 5PM
  7553. 'day': 'll', // Sep 4 2015
  7554. 'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  7555. 'month': 'MMM YYYY', // Sept 2015
  7556. 'quarter': '[Q]Q - YYYY', // Q3
  7557. 'year': 'YYYY' // 2015
  7558. }
  7559. },
  7560. ticks: {
  7561. autoSkip: false
  7562. }
  7563. };
  7564. var TimeScale = Chart.Scale.extend({
  7565. initialize: function() {
  7566. if (!moment) {
  7567. 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');
  7568. }
  7569. Chart.Scale.prototype.initialize.call(this);
  7570. },
  7571. getLabelMoment: function(datasetIndex, index) {
  7572. return this.labelMoments[datasetIndex][index];
  7573. },
  7574. determineDataLimits: function() {
  7575. this.labelMoments = [];
  7576. // Only parse these once. If the dataset does not have data as x,y pairs, we will use
  7577. // these
  7578. var scaleLabelMoments = [];
  7579. if (this.chart.data.labels && this.chart.data.labels.length > 0) {
  7580. helpers.each(this.chart.data.labels, function(label, index) {
  7581. var labelMoment = this.parseTime(label);
  7582. if (this.options.time.round) {
  7583. labelMoment.startOf(this.options.time.round);
  7584. }
  7585. scaleLabelMoments.push(labelMoment);
  7586. }, this);
  7587. this.firstTick = moment.min.call(this, scaleLabelMoments);
  7588. this.lastTick = moment.max.call(this, scaleLabelMoments);
  7589. } else {
  7590. this.firstTick = null;
  7591. this.lastTick = null;
  7592. }
  7593. helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
  7594. var momentsForDataset = [];
  7595. if (typeof dataset.data[0] === 'object') {
  7596. helpers.each(dataset.data, function(value, index) {
  7597. var labelMoment = this.parseTime(this.getRightValue(value));
  7598. if (this.options.time.round) {
  7599. labelMoment.startOf(this.options.time.round);
  7600. }
  7601. momentsForDataset.push(labelMoment);
  7602. // May have gone outside the scale ranges, make sure we keep the first and last ticks updated
  7603. this.firstTick = this.firstTick !== null ? moment.min(this.firstTick, labelMoment) : labelMoment;
  7604. this.lastTick = this.lastTick !== null ? moment.max(this.lastTick, labelMoment) : labelMoment;
  7605. }, this);
  7606. } else {
  7607. // We have no labels. Use the ones from the scale
  7608. momentsForDataset = scaleLabelMoments;
  7609. }
  7610. this.labelMoments.push(momentsForDataset);
  7611. }, this);
  7612. // Set these after we've done all the data
  7613. if (this.options.time.min) {
  7614. this.firstTick = this.parseTime(this.options.time.min);
  7615. }
  7616. if (this.options.time.max) {
  7617. this.lastTick = this.parseTime(this.options.time.max);
  7618. }
  7619. // We will modify these, so clone for later
  7620. this.firstTick = (this.firstTick || moment()).clone();
  7621. this.lastTick = (this.lastTick || moment()).clone();
  7622. },
  7623. buildTicks: function(index) {
  7624. this.ctx.save();
  7625. var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  7626. var tickFontStyle = helpers.getValueOrDefault(this.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  7627. var tickFontFamily = helpers.getValueOrDefault(this.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  7628. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  7629. this.ctx.font = tickLabelFont;
  7630. this.ticks = [];
  7631. this.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
  7632. this.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
  7633. // Set unit override if applicable
  7634. if (this.options.time.unit) {
  7635. this.tickUnit = this.options.time.unit || 'day';
  7636. this.displayFormat = this.options.time.displayFormats[this.tickUnit];
  7637. this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
  7638. this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, 1);
  7639. } else {
  7640. // Determine the smallest needed unit of the time
  7641. var innerWidth = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
  7642. // Crude approximation of what the label length might be
  7643. var tempFirstLabel = this.tickFormatFunction(this.firstTick, 0, []);
  7644. var tickLabelWidth = this.ctx.measureText(tempFirstLabel).width;
  7645. var cosRotation = Math.cos(helpers.toRadians(this.options.ticks.maxRotation));
  7646. var sinRotation = Math.sin(helpers.toRadians(this.options.ticks.maxRotation));
  7647. tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  7648. var labelCapacity = innerWidth / (tickLabelWidth);
  7649. // Start as small as possible
  7650. this.tickUnit = 'millisecond';
  7651. this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
  7652. this.displayFormat = this.options.time.displayFormats[this.tickUnit];
  7653. var unitDefinitionIndex = 0;
  7654. var unitDefinition = time.units[unitDefinitionIndex];
  7655. // While we aren't ideal and we don't have units left
  7656. while (unitDefinitionIndex < time.units.length) {
  7657. // Can we scale this unit. If `false` we can scale infinitely
  7658. this.unitScale = 1;
  7659. if (helpers.isArray(unitDefinition.steps) && Math.ceil(this.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
  7660. // Use one of the prefedined steps
  7661. for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
  7662. if (unitDefinition.steps[idx] >= Math.ceil(this.scaleSizeInUnits / labelCapacity)) {
  7663. this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, unitDefinition.steps[idx]);
  7664. break;
  7665. }
  7666. }
  7667. break;
  7668. } else if ((unitDefinition.maxStep === false) || (Math.ceil(this.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
  7669. // We have a max step. Scale this unit
  7670. this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, Math.ceil(this.scaleSizeInUnits / labelCapacity));
  7671. break;
  7672. } else {
  7673. // Move to the next unit up
  7674. ++unitDefinitionIndex;
  7675. unitDefinition = time.units[unitDefinitionIndex];
  7676. this.tickUnit = unitDefinition.name;
  7677. this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
  7678. this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
  7679. }
  7680. }
  7681. }
  7682. var roundedStart;
  7683. // Only round the first tick if we have no hard minimum
  7684. if (!this.options.time.min) {
  7685. this.firstTick.startOf(this.tickUnit);
  7686. roundedStart = this.firstTick;
  7687. } else {
  7688. roundedStart = this.firstTick.clone().startOf(this.tickUnit);
  7689. }
  7690. // Only round the last tick if we have no hard maximum
  7691. if (!this.options.time.max) {
  7692. this.lastTick.endOf(this.tickUnit);
  7693. }
  7694. this.smallestLabelSeparation = this.width;
  7695. helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
  7696. for (var i = 1; i < this.labelMoments[datasetIndex].length; i++) {
  7697. this.smallestLabelSeparation = Math.min(this.smallestLabelSeparation, this.labelMoments[datasetIndex][i].diff(this.labelMoments[datasetIndex][i - 1], this.tickUnit, true));
  7698. }
  7699. }, this);
  7700. // Tick displayFormat override
  7701. if (this.options.time.displayFormat) {
  7702. this.displayFormat = this.options.time.displayFormat;
  7703. }
  7704. // first tick. will have been rounded correctly if options.time.min is not specified
  7705. this.ticks.push(this.firstTick.clone());
  7706. // For every unit in between the first and last moment, create a moment and add it to the ticks tick
  7707. for (var i = 1; i < this.scaleSizeInUnits; ++i) {
  7708. var newTick = roundedStart.clone().add(i, this.tickUnit);
  7709. // Are we greater than the max time
  7710. if (this.options.time.max && newTick.diff(this.lastTick, this.tickUnit, true) >= 0) {
  7711. break;
  7712. }
  7713. if (i % this.unitScale === 0) {
  7714. this.ticks.push(newTick);
  7715. }
  7716. }
  7717. // Always show the right tick
  7718. if (this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit) !== 0 || this.scaleSizeInUnits === 0) {
  7719. // this is a weird case. If the <max> option is the same as the end option, we can't just diff the times because the tick was created from the roundedStart
  7720. // but the last tick was not rounded.
  7721. if (this.options.time.max) {
  7722. this.ticks.push(this.lastTick.clone());
  7723. this.scaleSizeInUnits = this.lastTick.diff(this.ticks[0], this.tickUnit, true);
  7724. } else {
  7725. this.scaleSizeInUnits = Math.ceil(this.scaleSizeInUnits / this.unitScale) * this.unitScale;
  7726. this.ticks.push(this.firstTick.clone().add(this.scaleSizeInUnits, this.tickUnit));
  7727. this.lastTick = this.ticks[this.ticks.length - 1].clone();
  7728. }
  7729. }
  7730. this.ctx.restore();
  7731. },
  7732. // Get tooltip label
  7733. getLabelForIndex: function(index, datasetIndex) {
  7734. var label = this.chart.data.labels && index < this.chart.data.labels.length ? this.chart.data.labels[index] : '';
  7735. if (typeof this.chart.data.datasets[datasetIndex].data[0] === 'object') {
  7736. label = this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  7737. }
  7738. // Format nicely
  7739. if (this.options.time.tooltipFormat) {
  7740. label = this.parseTime(label).format(this.options.time.tooltipFormat);
  7741. }
  7742. return label;
  7743. },
  7744. // Function to format an individual tick mark
  7745. tickFormatFunction: function tickFormatFunction(tick, index, ticks) {
  7746. var formattedTick = tick.format(this.displayFormat);
  7747. if (this.options.ticks.userCallback) {
  7748. return this.options.ticks.userCallback(formattedTick, index, ticks);
  7749. } else {
  7750. return formattedTick;
  7751. }
  7752. },
  7753. convertTicksToLabels: function() {
  7754. this.ticks = this.ticks.map(this.tickFormatFunction, this);
  7755. },
  7756. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  7757. var labelMoment = this.getLabelMoment(datasetIndex, index);
  7758. if (labelMoment) {
  7759. var offset = labelMoment.diff(this.firstTick, this.tickUnit, true);
  7760. var decimal = offset / this.scaleSizeInUnits;
  7761. if (this.isHorizontal()) {
  7762. var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
  7763. var valueWidth = innerWidth / Math.max(this.ticks.length - 1, 1);
  7764. var valueOffset = (innerWidth * decimal) + this.paddingLeft;
  7765. return this.left + Math.round(valueOffset);
  7766. } else {
  7767. var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
  7768. var valueHeight = innerHeight / Math.max(this.ticks.length - 1, 1);
  7769. var heightOffset = (innerHeight * decimal) + this.paddingTop;
  7770. return this.top + Math.round(heightOffset);
  7771. }
  7772. }
  7773. },
  7774. parseTime: function(label) {
  7775. if (typeof this.options.time.parser === 'string') {
  7776. return moment(label, this.options.time.parser);
  7777. }
  7778. if (typeof this.options.time.parser === 'function') {
  7779. return this.options.time.parser(label);
  7780. }
  7781. // Date objects
  7782. if (typeof label.getMonth === 'function' || typeof label === 'number') {
  7783. return moment(label);
  7784. }
  7785. // Moment support
  7786. if (label.isValid && label.isValid()) {
  7787. return label;
  7788. }
  7789. // Custom parsing (return an instance of moment)
  7790. if (typeof this.options.time.format !== 'string' && this.options.time.format.call) {
  7791. console.warn("options.time.format is deprecated and replaced by options.time.parser. See http://nnnick.github.io/Chart.js/docs-v2/#scales-time-scale");
  7792. return this.options.time.format(label);
  7793. }
  7794. // Moment format parsing
  7795. return moment(label, this.options.time.format);
  7796. }
  7797. });
  7798. Chart.scaleService.registerScaleType("time", TimeScale, defaultConfig);
  7799. };
  7800. },{"moment":1}]},{},[7]);