accessibility.src.js 323 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279
  1. /**
  2. * @license Highcharts JS v8.1.2 (2020-06-16)
  3. *
  4. * Accessibility module
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Oystein Moseng
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/accessibility', ['highcharts'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'modules/accessibility/utils/htmlUtilities.js', [_modules['parts/Utilities.js'], _modules['parts/Globals.js']], function (U, H) {
  33. /* *
  34. *
  35. * (c) 2009-2020 Øystein Moseng
  36. *
  37. * Utility functions for accessibility module.
  38. *
  39. * License: www.highcharts.com/license
  40. *
  41. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  42. *
  43. * */
  44. var merge = U.merge;
  45. var win = H.win, doc = win.document;
  46. /* eslint-disable valid-jsdoc */
  47. /**
  48. * @private
  49. * @param {Highcharts.HTMLDOMElement} el
  50. * @param {string} className
  51. * @return {void}
  52. */
  53. function addClass(el, className) {
  54. if (el.classList) {
  55. el.classList.add(className);
  56. }
  57. else if (el.className.indexOf(className) < 0) {
  58. // Note: Dumb check for class name exists, should be fine for practical
  59. // use cases, but will return false positives if the element has a class
  60. // that contains the className.
  61. el.className += className;
  62. }
  63. }
  64. /**
  65. * @private
  66. * @param {string} str
  67. * @return {string}
  68. */
  69. function escapeStringForHTML(str) {
  70. return str
  71. .replace(/&/g, '&amp;')
  72. .replace(/</g, '&lt;')
  73. .replace(/>/g, '&gt;')
  74. .replace(/"/g, '&quot;')
  75. .replace(/'/g, '&#x27;')
  76. .replace(/\//g, '&#x2F;');
  77. }
  78. /**
  79. * Get an element by ID
  80. * @param {string} id
  81. * @private
  82. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|null}
  83. */
  84. function getElement(id) {
  85. return doc.getElementById(id);
  86. }
  87. /**
  88. * Get a fake mouse event of a given type
  89. * @param {string} type
  90. * @private
  91. * @return {global.MouseEvent}
  92. */
  93. function getFakeMouseEvent(type) {
  94. if (typeof win.MouseEvent === 'function') {
  95. return new win.MouseEvent(type);
  96. }
  97. // No MouseEvent support, try using initMouseEvent
  98. if (doc.createEvent) {
  99. var evt = doc.createEvent('MouseEvent');
  100. if (evt.initMouseEvent) {
  101. evt.initMouseEvent(type, true, // Bubble
  102. true, // Cancel
  103. win, // View
  104. type === 'click' ? 1 : 0, // Detail
  105. // Coords
  106. 0, 0, 0, 0,
  107. // Pressed keys
  108. false, false, false, false, 0, // button
  109. null // related target
  110. );
  111. return evt;
  112. }
  113. }
  114. return { type: type };
  115. }
  116. /**
  117. * Remove an element from the DOM.
  118. * @private
  119. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} [element]
  120. * @return {void}
  121. */
  122. function removeElement(element) {
  123. if (element && element.parentNode) {
  124. element.parentNode.removeChild(element);
  125. }
  126. }
  127. /**
  128. * Utility function. Reverses child nodes of a DOM element.
  129. * @private
  130. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} node
  131. * @return {void}
  132. */
  133. function reverseChildNodes(node) {
  134. var i = node.childNodes.length;
  135. while (i--) {
  136. node.appendChild(node.childNodes[i]);
  137. }
  138. }
  139. /**
  140. * Set attributes on element. Set to null to remove attribute.
  141. * @private
  142. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} el
  143. * @param {Highcharts.HTMLAttributes|Highcharts.SVGAttributes} attrs
  144. * @return {void}
  145. */
  146. function setElAttrs(el, attrs) {
  147. Object.keys(attrs).forEach(function (attr) {
  148. var val = attrs[attr];
  149. if (val === null) {
  150. el.removeAttribute(attr);
  151. }
  152. else {
  153. var cleanedVal = escapeStringForHTML('' + val);
  154. el.setAttribute(attr, cleanedVal);
  155. }
  156. });
  157. }
  158. /**
  159. * Used for aria-label attributes, painting on a canvas will fail if the
  160. * text contains tags.
  161. * @private
  162. * @param {string} str
  163. * @return {string}
  164. */
  165. function stripHTMLTagsFromString(str) {
  166. return typeof str === 'string' ?
  167. str.replace(/<\/?[^>]+(>|$)/g, '') : str;
  168. }
  169. /**
  170. * Utility function for hiding an element visually, but still keeping it
  171. * available to screen reader users.
  172. * @private
  173. * @param {Highcharts.HTMLDOMElement} element
  174. * @return {void}
  175. */
  176. function visuallyHideElement(element) {
  177. var hiddenStyle = {
  178. position: 'absolute',
  179. width: '1px',
  180. height: '1px',
  181. overflow: 'hidden',
  182. whiteSpace: 'nowrap',
  183. clip: 'rect(1px, 1px, 1px, 1px)',
  184. marginTop: '-3px',
  185. '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=1)',
  186. filter: 'alpha(opacity=1)',
  187. opacity: '0.01'
  188. };
  189. merge(true, element.style, hiddenStyle);
  190. }
  191. var HTMLUtilities = {
  192. addClass: addClass,
  193. escapeStringForHTML: escapeStringForHTML,
  194. getElement: getElement,
  195. getFakeMouseEvent: getFakeMouseEvent,
  196. removeElement: removeElement,
  197. reverseChildNodes: reverseChildNodes,
  198. setElAttrs: setElAttrs,
  199. stripHTMLTagsFromString: stripHTMLTagsFromString,
  200. visuallyHideElement: visuallyHideElement
  201. };
  202. return HTMLUtilities;
  203. });
  204. _registerModule(_modules, 'modules/accessibility/utils/chartUtilities.js', [_modules['modules/accessibility/utils/htmlUtilities.js'], _modules['parts/Utilities.js']], function (HTMLUtilities, U) {
  205. /* *
  206. *
  207. * (c) 2009-2020 Øystein Moseng
  208. *
  209. * Utils for dealing with charts.
  210. *
  211. * License: www.highcharts.com/license
  212. *
  213. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  214. *
  215. * */
  216. var stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  217. var defined = U.defined, find = U.find, fireEvent = U.fireEvent;
  218. /* eslint-disable valid-jsdoc */
  219. /**
  220. * @return {string}
  221. */
  222. function getChartTitle(chart) {
  223. return stripHTMLTags(chart.options.title.text ||
  224. chart.langFormat('accessibility.defaultChartTitle', { chart: chart }));
  225. }
  226. /**
  227. * @param {Highcharts.Axis} axis
  228. * @return {string}
  229. */
  230. function getAxisDescription(axis) {
  231. return stripHTMLTags(axis && (axis.userOptions && axis.userOptions.accessibility &&
  232. axis.userOptions.accessibility.description ||
  233. axis.axisTitle && axis.axisTitle.textStr ||
  234. axis.options.id ||
  235. axis.categories && 'categories' ||
  236. axis.dateTime && 'Time' ||
  237. 'values'));
  238. }
  239. /**
  240. * Get the DOM element for the first point in the series.
  241. * @private
  242. * @param {Highcharts.Series} series
  243. * The series to get element for.
  244. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined}
  245. * The DOM element for the point.
  246. */
  247. function getSeriesFirstPointElement(series) {
  248. if (series.points &&
  249. series.points.length &&
  250. series.points[0].graphic) {
  251. return series.points[0].graphic.element;
  252. }
  253. }
  254. /**
  255. * Get the DOM element for the series that we put accessibility info on.
  256. * @private
  257. * @param {Highcharts.Series} series
  258. * The series to get element for.
  259. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined}
  260. * The DOM element for the series
  261. */
  262. function getSeriesA11yElement(series) {
  263. var firstPointEl = getSeriesFirstPointElement(series);
  264. return (firstPointEl &&
  265. firstPointEl.parentNode || series.graph &&
  266. series.graph.element || series.group &&
  267. series.group.element); // Could be tracker series depending on series type
  268. }
  269. /**
  270. * Remove aria-hidden from element. Also unhides parents of the element, and
  271. * hides siblings that are not explicitly unhidden.
  272. * @private
  273. * @param {Highcharts.Chart} chart
  274. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} element
  275. */
  276. function unhideChartElementFromAT(chart, element) {
  277. element.setAttribute('aria-hidden', false);
  278. if (element === chart.renderTo || !element.parentNode) {
  279. return;
  280. }
  281. // Hide siblings unless their hidden state is already explicitly set
  282. Array.prototype.forEach.call(element.parentNode.childNodes, function (node) {
  283. if (!node.hasAttribute('aria-hidden')) {
  284. node.setAttribute('aria-hidden', true);
  285. }
  286. });
  287. // Repeat for parent
  288. unhideChartElementFromAT(chart, element.parentNode);
  289. }
  290. /**
  291. * Hide series from screen readers.
  292. * @private
  293. * @param {Highcharts.Series} series
  294. * The series to hide
  295. * @return {void}
  296. */
  297. function hideSeriesFromAT(series) {
  298. var seriesEl = getSeriesA11yElement(series);
  299. if (seriesEl) {
  300. seriesEl.setAttribute('aria-hidden', true);
  301. }
  302. }
  303. /**
  304. * Get series objects by series name.
  305. * @private
  306. * @param {Highcharts.Chart} chart
  307. * @param {string} name
  308. * @return {Array<Highcharts.Series>}
  309. */
  310. function getSeriesFromName(chart, name) {
  311. if (!name) {
  312. return chart.series;
  313. }
  314. return (chart.series || []).filter(function (s) {
  315. return s.name === name;
  316. });
  317. }
  318. /**
  319. * Get point in a series from x/y values.
  320. * @private
  321. * @param {Array<Highcharts.Series>} series
  322. * @param {number} x
  323. * @param {number} y
  324. * @return {Highcharts.Point|undefined}
  325. */
  326. function getPointFromXY(series, x, y) {
  327. var i = series.length, res;
  328. while (i--) {
  329. res = find(series[i].points || [], function (p) {
  330. return p.x === x && p.y === y;
  331. });
  332. if (res) {
  333. return res;
  334. }
  335. }
  336. }
  337. /**
  338. * Get relative position of point on an x/y axis from 0 to 1.
  339. * @private
  340. * @param {Highcharts.Axis} axis
  341. * @param {Highcharts.Point} point
  342. * @return {number}
  343. */
  344. function getRelativePointAxisPosition(axis, point) {
  345. if (!defined(axis.dataMin) || !defined(axis.dataMax)) {
  346. return 0;
  347. }
  348. var axisStart = axis.toPixels(axis.dataMin);
  349. var axisEnd = axis.toPixels(axis.dataMax);
  350. // We have to use pixel position because of axis breaks, log axis etc.
  351. var positionProp = axis.coll === 'xAxis' ? 'x' : 'y';
  352. var pointPos = axis.toPixels(point[positionProp] || 0);
  353. return (pointPos - axisStart) / (axisEnd - axisStart);
  354. }
  355. /**
  356. * Get relative position of point on an x/y axis from 0 to 1.
  357. * @private
  358. * @param {Highcharts.Point} point
  359. */
  360. function scrollToPoint(point) {
  361. var xAxis = point.series.xAxis;
  362. var yAxis = point.series.yAxis;
  363. var axis = (xAxis === null || xAxis === void 0 ? void 0 : xAxis.scrollbar) ? xAxis : yAxis;
  364. var scrollbar = axis === null || axis === void 0 ? void 0 : axis.scrollbar;
  365. if (scrollbar && defined(scrollbar.to) && defined(scrollbar.from)) {
  366. var range = scrollbar.to - scrollbar.from;
  367. var pos = getRelativePointAxisPosition(axis, point);
  368. scrollbar.updatePosition(pos - range / 2, pos + range / 2);
  369. fireEvent(scrollbar, 'changed', {
  370. from: scrollbar.from,
  371. to: scrollbar.to,
  372. trigger: 'scrollbar',
  373. DOMEvent: null
  374. });
  375. }
  376. }
  377. var ChartUtilities = {
  378. getChartTitle: getChartTitle,
  379. getAxisDescription: getAxisDescription,
  380. getPointFromXY: getPointFromXY,
  381. getSeriesFirstPointElement: getSeriesFirstPointElement,
  382. getSeriesFromName: getSeriesFromName,
  383. getSeriesA11yElement: getSeriesA11yElement,
  384. unhideChartElementFromAT: unhideChartElementFromAT,
  385. hideSeriesFromAT: hideSeriesFromAT,
  386. scrollToPoint: scrollToPoint
  387. };
  388. return ChartUtilities;
  389. });
  390. _registerModule(_modules, 'modules/accessibility/KeyboardNavigationHandler.js', [_modules['parts/Utilities.js']], function (U) {
  391. /* *
  392. *
  393. * (c) 2009-2020 Øystein Moseng
  394. *
  395. * Keyboard navigation handler base class definition
  396. *
  397. * License: www.highcharts.com/license
  398. *
  399. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  400. *
  401. * */
  402. var find = U.find;
  403. /**
  404. * Options for the keyboard navigation handler.
  405. *
  406. * @interface Highcharts.KeyboardNavigationHandlerOptionsObject
  407. */ /**
  408. * An array containing pairs of an array of keycodes, mapped to a handler
  409. * function. When the keycode is received, the handler is called with the
  410. * keycode as parameter.
  411. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#keyCodeMap
  412. * @type {Array<Array<Array<number>, Function>>}
  413. */ /**
  414. * Function to run on initialization of module.
  415. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#init
  416. * @type {Function}
  417. */ /**
  418. * Function to run before moving to next/prev module. Receives moving direction
  419. * as parameter: +1 for next, -1 for previous.
  420. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#terminate
  421. * @type {Function|undefined}
  422. */ /**
  423. * Function to run to validate module. Should return false if module should not
  424. * run, true otherwise. Receives chart as parameter.
  425. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#validate
  426. * @type {Function|undefined}
  427. */
  428. /* eslint-disable no-invalid-this, valid-jsdoc */
  429. /**
  430. * Define a keyboard navigation handler for use with a
  431. * Highcharts.AccessibilityComponent instance. This functions as an abstraction
  432. * layer for keyboard navigation, and defines a map of keyCodes to handler
  433. * functions.
  434. *
  435. * @requires module:modules/accessibility
  436. *
  437. * @sample highcharts/accessibility/custom-component
  438. * Custom accessibility component
  439. *
  440. * @class
  441. * @name Highcharts.KeyboardNavigationHandler
  442. *
  443. * @param {Highcharts.Chart} chart
  444. * The chart this module should act on.
  445. *
  446. * @param {Highcharts.KeyboardNavigationHandlerOptionsObject} options
  447. * Options for the keyboard navigation handler.
  448. */
  449. function KeyboardNavigationHandler(chart, options) {
  450. this.chart = chart;
  451. this.keyCodeMap = options.keyCodeMap || [];
  452. this.validate = options.validate;
  453. this.init = options.init;
  454. this.terminate = options.terminate;
  455. // Response enum
  456. this.response = {
  457. success: 1,
  458. prev: 2,
  459. next: 3,
  460. noHandler: 4,
  461. fail: 5 // Handler failed
  462. };
  463. }
  464. KeyboardNavigationHandler.prototype = {
  465. /**
  466. * Find handler function(s) for key code in the keyCodeMap and run it.
  467. *
  468. * @function KeyboardNavigationHandler#run
  469. * @param {global.KeyboardEvent} e
  470. * @return {number} Returns a response code indicating whether the run was
  471. * a success/fail/unhandled, or if we should move to next/prev module.
  472. */
  473. run: function (e) {
  474. var keyCode = e.which || e.keyCode, response = this.response.noHandler, handlerCodeSet = find(this.keyCodeMap, function (codeSet) {
  475. return codeSet[0].indexOf(keyCode) > -1;
  476. });
  477. if (handlerCodeSet) {
  478. response = handlerCodeSet[1].call(this, keyCode, e);
  479. }
  480. else if (keyCode === 9) {
  481. // Default tab handler, move to next/prev module
  482. response = this.response[e.shiftKey ? 'prev' : 'next'];
  483. }
  484. return response;
  485. }
  486. };
  487. return KeyboardNavigationHandler;
  488. });
  489. _registerModule(_modules, 'modules/accessibility/utils/EventProvider.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  490. /* *
  491. *
  492. * (c) 2009-2020 Øystein Moseng
  493. *
  494. * Class that can keep track of events added, and clean them up on destroy.
  495. *
  496. * License: www.highcharts.com/license
  497. *
  498. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  499. *
  500. * */
  501. var addEvent = U.addEvent, extend = U.extend;
  502. /* eslint-disable no-invalid-this, valid-jsdoc */
  503. /**
  504. * @private
  505. * @class
  506. */
  507. var EventProvider = function () {
  508. this.eventRemovers = [];
  509. };
  510. extend(EventProvider.prototype, {
  511. /**
  512. * Add an event to an element and keep track of it for later removal.
  513. * Same args as Highcharts.addEvent.
  514. * @private
  515. * @return {Function}
  516. */
  517. addEvent: function () {
  518. var remover = addEvent.apply(H, arguments);
  519. this.eventRemovers.push(remover);
  520. return remover;
  521. },
  522. /**
  523. * Remove all added events.
  524. * @private
  525. * @return {void}
  526. */
  527. removeAddedEvents: function () {
  528. this.eventRemovers.forEach(function (remover) {
  529. remover();
  530. });
  531. this.eventRemovers = [];
  532. }
  533. });
  534. return EventProvider;
  535. });
  536. _registerModule(_modules, 'modules/accessibility/utils/DOMElementProvider.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, U, HTMLUtilities) {
  537. /* *
  538. *
  539. * (c) 2009-2020 Øystein Moseng
  540. *
  541. * Class that can keep track of elements added to DOM and clean them up on
  542. * destroy.
  543. *
  544. * License: www.highcharts.com/license
  545. *
  546. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  547. *
  548. * */
  549. var doc = H.win.document;
  550. var extend = U.extend;
  551. var removeElement = HTMLUtilities.removeElement;
  552. /* eslint-disable no-invalid-this, valid-jsdoc */
  553. /**
  554. * @private
  555. * @class
  556. */
  557. var DOMElementProvider = function () {
  558. this.elements = [];
  559. };
  560. extend(DOMElementProvider.prototype, {
  561. /**
  562. * Create an element and keep track of it for later removal.
  563. * Same args as document.createElement
  564. * @private
  565. */
  566. createElement: function () {
  567. var el = doc.createElement.apply(doc, arguments);
  568. this.elements.push(el);
  569. return el;
  570. },
  571. /**
  572. * Destroy all created elements, removing them from the DOM.
  573. * @private
  574. */
  575. destroyCreatedElements: function () {
  576. this.elements.forEach(function (element) {
  577. removeElement(element);
  578. });
  579. this.elements = [];
  580. }
  581. });
  582. return DOMElementProvider;
  583. });
  584. _registerModule(_modules, 'modules/accessibility/AccessibilityComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/utils/EventProvider.js'], _modules['modules/accessibility/utils/DOMElementProvider.js']], function (H, U, HTMLUtilities, ChartUtilities, EventProvider, DOMElementProvider) {
  585. /* *
  586. *
  587. * (c) 2009-2020 Øystein Moseng
  588. *
  589. * Accessibility component class definition
  590. *
  591. * License: www.highcharts.com/license
  592. *
  593. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  594. *
  595. * */
  596. var win = H.win, doc = win.document;
  597. var extend = U.extend, fireEvent = U.fireEvent, merge = U.merge;
  598. var removeElement = HTMLUtilities.removeElement, getFakeMouseEvent = HTMLUtilities.getFakeMouseEvent;
  599. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  600. /* eslint-disable valid-jsdoc */
  601. /** @lends Highcharts.AccessibilityComponent */
  602. var functionsToOverrideByDerivedClasses = {
  603. /**
  604. * Called on component initialization.
  605. */
  606. init: function () { },
  607. /**
  608. * Get keyboard navigation handler for this component.
  609. * @return {Highcharts.KeyboardNavigationHandler}
  610. */
  611. getKeyboardNavigation: function () { },
  612. /**
  613. * Called on updates to the chart, including options changes.
  614. * Note that this is also called on first render of chart.
  615. */
  616. onChartUpdate: function () { },
  617. /**
  618. * Called on every chart render.
  619. */
  620. onChartRender: function () { },
  621. /**
  622. * Called when accessibility is disabled or chart is destroyed.
  623. */
  624. destroy: function () { }
  625. };
  626. /**
  627. * The AccessibilityComponent base class, representing a part of the chart that
  628. * has accessibility logic connected to it. This class can be inherited from to
  629. * create a custom accessibility component for a chart.
  630. *
  631. * Components should take care to destroy added elements and unregister event
  632. * handlers on destroy. This is handled automatically if using this.addEvent and
  633. * this.createElement.
  634. *
  635. * @sample highcharts/accessibility/custom-component
  636. * Custom accessibility component
  637. *
  638. * @requires module:modules/accessibility
  639. * @class
  640. * @name Highcharts.AccessibilityComponent
  641. */
  642. function AccessibilityComponent() { }
  643. /**
  644. * @lends Highcharts.AccessibilityComponent
  645. */
  646. AccessibilityComponent.prototype = {
  647. /**
  648. * Initialize the class
  649. * @private
  650. * @param {Highcharts.Chart} chart
  651. * Chart object
  652. */
  653. initBase: function (chart) {
  654. this.chart = chart;
  655. this.eventProvider = new EventProvider();
  656. this.domElementProvider = new DOMElementProvider();
  657. // Key code enum for common keys
  658. this.keyCodes = {
  659. left: 37,
  660. right: 39,
  661. up: 38,
  662. down: 40,
  663. enter: 13,
  664. space: 32,
  665. esc: 27,
  666. tab: 9
  667. };
  668. },
  669. /**
  670. * Add an event to an element and keep track of it for later removal.
  671. * See EventProvider for details.
  672. * @private
  673. */
  674. addEvent: function () {
  675. return this.eventProvider.addEvent
  676. .apply(this.eventProvider, arguments);
  677. },
  678. /**
  679. * Create an element and keep track of it for later removal.
  680. * See DOMElementProvider for details.
  681. * @private
  682. */
  683. createElement: function () {
  684. return this.domElementProvider.createElement.apply(this.domElementProvider, arguments);
  685. },
  686. /**
  687. * Fire an event on an element that is either wrapped by Highcharts,
  688. * or a DOM element
  689. * @private
  690. * @param {Highcharts.HTMLElement|Highcharts.HTMLDOMElement|
  691. * Highcharts.SVGDOMElement|Highcharts.SVGElement} el
  692. * @param {Event} eventObject
  693. */
  694. fireEventOnWrappedOrUnwrappedElement: function (el, eventObject) {
  695. var type = eventObject.type;
  696. if (doc.createEvent && (el.dispatchEvent || el.fireEvent)) {
  697. if (el.dispatchEvent) {
  698. el.dispatchEvent(eventObject);
  699. }
  700. else {
  701. el.fireEvent(type, eventObject);
  702. }
  703. }
  704. else {
  705. fireEvent(el, type, eventObject);
  706. }
  707. },
  708. /**
  709. * Utility function to attempt to fake a click event on an element.
  710. * @private
  711. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} element
  712. */
  713. fakeClickEvent: function (element) {
  714. if (element) {
  715. var fakeEventObject = getFakeMouseEvent('click');
  716. this.fireEventOnWrappedOrUnwrappedElement(element, fakeEventObject);
  717. }
  718. },
  719. /**
  720. * Add a new proxy group to the proxy container. Creates the proxy container
  721. * if it does not exist.
  722. * @private
  723. * @param {Highcharts.HTMLAttributes} [attrs]
  724. * The attributes to set on the new group div.
  725. * @return {Highcharts.HTMLDOMElement}
  726. * The new proxy group element.
  727. */
  728. addProxyGroup: function (attrs) {
  729. this.createOrUpdateProxyContainer();
  730. var groupDiv = this.createElement('div');
  731. Object.keys(attrs || {}).forEach(function (prop) {
  732. if (attrs[prop] !== null) {
  733. groupDiv.setAttribute(prop, attrs[prop]);
  734. }
  735. });
  736. this.chart.a11yProxyContainer.appendChild(groupDiv);
  737. return groupDiv;
  738. },
  739. /**
  740. * Creates and updates DOM position of proxy container
  741. * @private
  742. */
  743. createOrUpdateProxyContainer: function () {
  744. var chart = this.chart, rendererSVGEl = chart.renderer.box;
  745. chart.a11yProxyContainer = chart.a11yProxyContainer ||
  746. this.createProxyContainerElement();
  747. if (rendererSVGEl.nextSibling !== chart.a11yProxyContainer) {
  748. chart.container.insertBefore(chart.a11yProxyContainer, rendererSVGEl.nextSibling);
  749. }
  750. },
  751. /**
  752. * @private
  753. * @return {Highcharts.HTMLDOMElement} element
  754. */
  755. createProxyContainerElement: function () {
  756. var pc = doc.createElement('div');
  757. pc.className = 'highcharts-a11y-proxy-container';
  758. return pc;
  759. },
  760. /**
  761. * Create an invisible proxy HTML button in the same position as an SVG
  762. * element
  763. * @private
  764. * @param {Highcharts.SVGElement} svgElement
  765. * The wrapped svg el to proxy.
  766. * @param {Highcharts.HTMLDOMElement} parentGroup
  767. * The proxy group element in the proxy container to add this button to.
  768. * @param {Highcharts.SVGAttributes} [attributes]
  769. * Additional attributes to set.
  770. * @param {Highcharts.SVGElement} [posElement]
  771. * Element to use for positioning instead of svgElement.
  772. * @param {Function} [preClickEvent]
  773. * Function to call before click event fires.
  774. *
  775. * @return {Highcharts.HTMLDOMElement} The proxy button.
  776. */
  777. createProxyButton: function (svgElement, parentGroup, attributes, posElement, preClickEvent) {
  778. var svgEl = svgElement.element, proxy = this.createElement('button'), attrs = merge({
  779. 'aria-label': svgEl.getAttribute('aria-label')
  780. }, attributes);
  781. Object.keys(attrs).forEach(function (prop) {
  782. if (attrs[prop] !== null) {
  783. proxy.setAttribute(prop, attrs[prop]);
  784. }
  785. });
  786. proxy.className = 'highcharts-a11y-proxy-button';
  787. if (preClickEvent) {
  788. this.addEvent(proxy, 'click', preClickEvent);
  789. }
  790. this.setProxyButtonStyle(proxy);
  791. this.updateProxyButtonPosition(proxy, posElement || svgElement);
  792. this.proxyMouseEventsForButton(svgEl, proxy);
  793. // Add to chart div and unhide from screen readers
  794. parentGroup.appendChild(proxy);
  795. if (!attrs['aria-hidden']) {
  796. unhideChartElementFromAT(this.chart, proxy);
  797. }
  798. return proxy;
  799. },
  800. /**
  801. * Get the position relative to chart container for a wrapped SVG element.
  802. * @private
  803. * @param {Highcharts.SVGElement} element
  804. * The element to calculate position for.
  805. * @return {Highcharts.BBoxObject}
  806. * Object with x and y props for the position.
  807. */
  808. getElementPosition: function (element) {
  809. var el = element.element, div = this.chart.renderTo;
  810. if (div && el && el.getBoundingClientRect) {
  811. var rectEl = el.getBoundingClientRect(), rectDiv = div.getBoundingClientRect();
  812. return {
  813. x: rectEl.left - rectDiv.left,
  814. y: rectEl.top - rectDiv.top,
  815. width: rectEl.right - rectEl.left,
  816. height: rectEl.bottom - rectEl.top
  817. };
  818. }
  819. return { x: 0, y: 0, width: 1, height: 1 };
  820. },
  821. /**
  822. * @private
  823. * @param {Highcharts.HTMLElement} button The proxy element.
  824. */
  825. setProxyButtonStyle: function (button) {
  826. merge(true, button.style, {
  827. 'border-width': 0,
  828. 'background-color': 'transparent',
  829. cursor: 'pointer',
  830. outline: 'none',
  831. opacity: 0.001,
  832. filter: 'alpha(opacity=1)',
  833. '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=1)',
  834. zIndex: 999,
  835. overflow: 'hidden',
  836. padding: 0,
  837. margin: 0,
  838. display: 'block',
  839. position: 'absolute'
  840. });
  841. },
  842. /**
  843. * @private
  844. * @param {Highcharts.HTMLElement} proxy The proxy to update position of.
  845. * @param {Highcharts.SVGElement} posElement The element to overlay and take position from.
  846. */
  847. updateProxyButtonPosition: function (proxy, posElement) {
  848. var bBox = this.getElementPosition(posElement);
  849. merge(true, proxy.style, {
  850. width: (bBox.width || 1) + 'px',
  851. height: (bBox.height || 1) + 'px',
  852. left: (bBox.x || 0) + 'px',
  853. top: (bBox.y || 0) + 'px'
  854. });
  855. },
  856. /**
  857. * @private
  858. * @param {Highcharts.HTMLElement|Highcharts.HTMLDOMElement|
  859. * Highcharts.SVGDOMElement|Highcharts.SVGElement} source
  860. * @param {Highcharts.HTMLElement} button
  861. */
  862. proxyMouseEventsForButton: function (source, button) {
  863. var component = this;
  864. [
  865. 'click', 'touchstart', 'touchend', 'touchcancel', 'touchmove',
  866. 'mouseover', 'mouseenter', 'mouseleave', 'mouseout'
  867. ].forEach(function (evtType) {
  868. var isTouchEvent = evtType.indexOf('touch') === 0;
  869. component.addEvent(button, evtType, function (e) {
  870. var clonedEvent = isTouchEvent ?
  871. component.cloneTouchEvent(e) :
  872. component.cloneMouseEvent(e);
  873. if (source) {
  874. component.fireEventOnWrappedOrUnwrappedElement(source, clonedEvent);
  875. }
  876. e.stopPropagation();
  877. e.preventDefault();
  878. });
  879. });
  880. },
  881. /**
  882. * Utility function to clone a mouse event for re-dispatching.
  883. * @private
  884. * @param {global.MouseEvent} e The event to clone.
  885. * @return {global.MouseEvent} The cloned event
  886. */
  887. cloneMouseEvent: function (e) {
  888. if (typeof win.MouseEvent === 'function') {
  889. return new win.MouseEvent(e.type, e);
  890. }
  891. // No MouseEvent support, try using initMouseEvent
  892. if (doc.createEvent) {
  893. var evt = doc.createEvent('MouseEvent');
  894. if (evt.initMouseEvent) {
  895. evt.initMouseEvent(e.type, e.bubbles, // #10561, #12161
  896. e.cancelable, e.view || win, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
  897. return evt;
  898. }
  899. }
  900. return getFakeMouseEvent(e.type);
  901. },
  902. /**
  903. * Utility function to clone a touch event for re-dispatching.
  904. * @private
  905. * @param {global.TouchEvent} e The event to clone.
  906. * @return {global.TouchEvent} The cloned event
  907. */
  908. cloneTouchEvent: function (e) {
  909. var touchListToTouchArray = function (l) {
  910. var touchArray = [];
  911. for (var i = 0; i < l.length; ++i) {
  912. var item = l.item(i);
  913. if (item) {
  914. touchArray.push(item);
  915. }
  916. }
  917. return touchArray;
  918. };
  919. if (typeof win.TouchEvent === 'function') {
  920. var newEvent = new win.TouchEvent(e.type, {
  921. touches: touchListToTouchArray(e.touches),
  922. targetTouches: touchListToTouchArray(e.targetTouches),
  923. changedTouches: touchListToTouchArray(e.changedTouches),
  924. ctrlKey: e.ctrlKey,
  925. shiftKey: e.shiftKey,
  926. altKey: e.altKey,
  927. metaKey: e.metaKey,
  928. bubbles: e.bubbles,
  929. cancelable: e.cancelable,
  930. composed: e.composed,
  931. detail: e.detail,
  932. view: e.view
  933. });
  934. if (e.defaultPrevented) {
  935. newEvent.preventDefault();
  936. }
  937. return newEvent;
  938. }
  939. // Fallback to mouse event
  940. var fakeEvt = this.cloneMouseEvent(e);
  941. fakeEvt.touches = e.touches;
  942. fakeEvt.changedTouches = e.changedTouches;
  943. fakeEvt.targetTouches = e.targetTouches;
  944. return fakeEvt;
  945. },
  946. /**
  947. * Remove traces of the component.
  948. * @private
  949. */
  950. destroyBase: function () {
  951. removeElement(this.chart.a11yProxyContainer);
  952. this.domElementProvider.destroyCreatedElements();
  953. this.eventProvider.removeAddedEvents();
  954. }
  955. };
  956. extend(AccessibilityComponent.prototype, functionsToOverrideByDerivedClasses);
  957. return AccessibilityComponent;
  958. });
  959. _registerModule(_modules, 'modules/accessibility/KeyboardNavigation.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js'], _modules['modules/accessibility/utils/EventProvider.js']], function (H, U, HTMLUtilities, EventProvider) {
  960. /* *
  961. *
  962. * (c) 2009-2020 Øystein Moseng
  963. *
  964. * Main keyboard navigation handling.
  965. *
  966. * License: www.highcharts.com/license
  967. *
  968. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  969. *
  970. * */
  971. var doc = H.doc, win = H.win;
  972. var addEvent = U.addEvent, fireEvent = U.fireEvent;
  973. var getElement = HTMLUtilities.getElement;
  974. /* eslint-disable valid-jsdoc */
  975. // Add event listener to document to detect ESC key press and dismiss
  976. // hover/popup content.
  977. addEvent(doc, 'keydown', function (e) {
  978. var keycode = e.which || e.keyCode;
  979. var esc = 27;
  980. if (keycode === esc && H.charts) {
  981. H.charts.forEach(function (chart) {
  982. if (chart && chart.dismissPopupContent) {
  983. chart.dismissPopupContent();
  984. }
  985. });
  986. }
  987. });
  988. /**
  989. * Dismiss popup content in chart, including export menu and tooltip.
  990. */
  991. H.Chart.prototype.dismissPopupContent = function () {
  992. var chart = this;
  993. fireEvent(this, 'dismissPopupContent', {}, function () {
  994. if (chart.tooltip) {
  995. chart.tooltip.hide(0);
  996. }
  997. chart.hideExportMenu();
  998. });
  999. };
  1000. /**
  1001. * The KeyboardNavigation class, containing the overall keyboard navigation
  1002. * logic for the chart.
  1003. *
  1004. * @requires module:modules/accessibility
  1005. *
  1006. * @private
  1007. * @class
  1008. * @param {Highcharts.Chart} chart
  1009. * Chart object
  1010. * @param {object} components
  1011. * Map of component names to AccessibilityComponent objects.
  1012. * @name Highcharts.KeyboardNavigation
  1013. */
  1014. function KeyboardNavigation(chart, components) {
  1015. this.init(chart, components);
  1016. }
  1017. KeyboardNavigation.prototype = {
  1018. /**
  1019. * Initialize the class
  1020. * @private
  1021. * @param {Highcharts.Chart} chart
  1022. * Chart object
  1023. * @param {object} components
  1024. * Map of component names to AccessibilityComponent objects.
  1025. */
  1026. init: function (chart, components) {
  1027. var _this = this;
  1028. var ep = this.eventProvider = new EventProvider();
  1029. this.chart = chart;
  1030. this.components = components;
  1031. this.modules = [];
  1032. this.currentModuleIx = 0;
  1033. // Run an update to get all modules
  1034. this.update();
  1035. ep.addEvent(chart.renderTo, 'keydown', function (e) { return _this.onKeydown(e); });
  1036. ep.addEvent(this.tabindexContainer, 'focus', function (e) { return _this.onFocus(e); });
  1037. ep.addEvent(doc, 'mouseup', function () { return _this.onMouseUp(); });
  1038. ep.addEvent(chart.renderTo, 'mousedown', function () {
  1039. _this.isClickingChart = true;
  1040. });
  1041. ep.addEvent(chart.renderTo, 'mouseover', function () {
  1042. _this.pointerIsOverChart = true;
  1043. });
  1044. ep.addEvent(chart.renderTo, 'mouseout', function () {
  1045. _this.pointerIsOverChart = false;
  1046. });
  1047. // Init first module
  1048. if (this.modules.length) {
  1049. this.modules[0].init(1);
  1050. }
  1051. },
  1052. /**
  1053. * Update the modules for the keyboard navigation.
  1054. * @param {Array<string>} [order]
  1055. * Array specifying the tab order of the components.
  1056. */
  1057. update: function (order) {
  1058. var a11yOptions = this.chart.options.accessibility, keyboardOptions = a11yOptions && a11yOptions.keyboardNavigation, components = this.components;
  1059. this.updateContainerTabindex();
  1060. if (keyboardOptions &&
  1061. keyboardOptions.enabled &&
  1062. order &&
  1063. order.length) {
  1064. // We (still) have keyboard navigation. Update module list
  1065. this.modules = order.reduce(function (modules, componentName) {
  1066. var navModules = components[componentName].getKeyboardNavigation();
  1067. return modules.concat(navModules);
  1068. }, []);
  1069. this.updateExitAnchor();
  1070. }
  1071. else {
  1072. this.modules = [];
  1073. this.currentModuleIx = 0;
  1074. this.removeExitAnchor();
  1075. }
  1076. },
  1077. /**
  1078. * Function to run on container focus
  1079. * @private
  1080. * @param {global.FocusEvent} e Browser focus event.
  1081. */
  1082. onFocus: function (e) {
  1083. var _a;
  1084. var chart = this.chart;
  1085. var focusComesFromChart = (e.relatedTarget &&
  1086. chart.container.contains(e.relatedTarget));
  1087. // Init keyboard nav if tabbing into chart
  1088. if (!this.isClickingChart && !focusComesFromChart) {
  1089. (_a = this.modules[0]) === null || _a === void 0 ? void 0 : _a.init(1);
  1090. }
  1091. },
  1092. /**
  1093. * Reset chart navigation state if we click outside the chart and it's
  1094. * not already reset.
  1095. * @private
  1096. */
  1097. onMouseUp: function () {
  1098. delete this.isClickingChart;
  1099. if (!this.keyboardReset && !this.pointerIsOverChart) {
  1100. var chart = this.chart, curMod = this.modules &&
  1101. this.modules[this.currentModuleIx || 0];
  1102. if (curMod && curMod.terminate) {
  1103. curMod.terminate();
  1104. }
  1105. if (chart.focusElement) {
  1106. chart.focusElement.removeFocusBorder();
  1107. }
  1108. this.currentModuleIx = 0;
  1109. this.keyboardReset = true;
  1110. }
  1111. },
  1112. /**
  1113. * Function to run on keydown
  1114. * @private
  1115. * @param {global.KeyboardEvent} ev Browser keydown event.
  1116. */
  1117. onKeydown: function (ev) {
  1118. var e = ev || win.event, preventDefault, curNavModule = this.modules && this.modules.length &&
  1119. this.modules[this.currentModuleIx];
  1120. // Used for resetting nav state when clicking outside chart
  1121. this.keyboardReset = false;
  1122. // If there is a nav module for the current index, run it.
  1123. // Otherwise, we are outside of the chart in some direction.
  1124. if (curNavModule) {
  1125. var response = curNavModule.run(e);
  1126. if (response === curNavModule.response.success) {
  1127. preventDefault = true;
  1128. }
  1129. else if (response === curNavModule.response.prev) {
  1130. preventDefault = this.prev();
  1131. }
  1132. else if (response === curNavModule.response.next) {
  1133. preventDefault = this.next();
  1134. }
  1135. if (preventDefault) {
  1136. e.preventDefault();
  1137. e.stopPropagation();
  1138. }
  1139. }
  1140. },
  1141. /**
  1142. * Go to previous module.
  1143. * @private
  1144. */
  1145. prev: function () {
  1146. return this.move(-1);
  1147. },
  1148. /**
  1149. * Go to next module.
  1150. * @private
  1151. */
  1152. next: function () {
  1153. return this.move(1);
  1154. },
  1155. /**
  1156. * Move to prev/next module.
  1157. * @private
  1158. * @param {number} direction
  1159. * Direction to move. +1 for next, -1 for prev.
  1160. * @return {boolean}
  1161. * True if there was a valid module in direction.
  1162. */
  1163. move: function (direction) {
  1164. var curModule = this.modules && this.modules[this.currentModuleIx];
  1165. if (curModule && curModule.terminate) {
  1166. curModule.terminate(direction);
  1167. }
  1168. // Remove existing focus border if any
  1169. if (this.chart.focusElement) {
  1170. this.chart.focusElement.removeFocusBorder();
  1171. }
  1172. this.currentModuleIx += direction;
  1173. var newModule = this.modules && this.modules[this.currentModuleIx];
  1174. if (newModule) {
  1175. if (newModule.validate && !newModule.validate()) {
  1176. return this.move(direction); // Invalid module, recurse
  1177. }
  1178. if (newModule.init) {
  1179. newModule.init(direction); // Valid module, init it
  1180. return true;
  1181. }
  1182. }
  1183. // No module
  1184. this.currentModuleIx = 0; // Reset counter
  1185. // Set focus to chart or exit anchor depending on direction
  1186. if (direction > 0) {
  1187. this.exiting = true;
  1188. this.exitAnchor.focus();
  1189. }
  1190. else {
  1191. this.tabindexContainer.focus();
  1192. }
  1193. return false;
  1194. },
  1195. /**
  1196. * We use an exit anchor to move focus out of chart whenever we want, by
  1197. * setting focus to this div and not preventing the default tab action. We
  1198. * also use this when users come back into the chart by tabbing back, in
  1199. * order to navigate from the end of the chart.
  1200. * @private
  1201. */
  1202. updateExitAnchor: function () {
  1203. var endMarkerId = 'highcharts-end-of-chart-marker-' + this.chart.index, endMarker = getElement(endMarkerId);
  1204. this.removeExitAnchor();
  1205. if (endMarker) {
  1206. this.makeElementAnExitAnchor(endMarker);
  1207. this.exitAnchor = endMarker;
  1208. }
  1209. else {
  1210. this.createExitAnchor();
  1211. }
  1212. },
  1213. /**
  1214. * Chart container should have tabindex if navigation is enabled.
  1215. * @private
  1216. */
  1217. updateContainerTabindex: function () {
  1218. var a11yOptions = this.chart.options.accessibility, keyboardOptions = a11yOptions && a11yOptions.keyboardNavigation, shouldHaveTabindex = !(keyboardOptions && keyboardOptions.enabled === false), chart = this.chart, container = chart.container;
  1219. var tabindexContainer;
  1220. if (chart.renderTo.hasAttribute('tabindex')) {
  1221. container.removeAttribute('tabindex');
  1222. tabindexContainer = chart.renderTo;
  1223. }
  1224. else {
  1225. tabindexContainer = container;
  1226. }
  1227. this.tabindexContainer = tabindexContainer;
  1228. var curTabindex = tabindexContainer.getAttribute('tabindex');
  1229. if (shouldHaveTabindex && !curTabindex) {
  1230. tabindexContainer.setAttribute('tabindex', '0');
  1231. }
  1232. else if (!shouldHaveTabindex) {
  1233. chart.container.removeAttribute('tabindex');
  1234. }
  1235. },
  1236. /**
  1237. * @private
  1238. */
  1239. makeElementAnExitAnchor: function (el) {
  1240. var chartTabindex = this.tabindexContainer.getAttribute('tabindex') || 0;
  1241. el.setAttribute('class', 'highcharts-exit-anchor');
  1242. el.setAttribute('tabindex', chartTabindex);
  1243. el.setAttribute('aria-hidden', false);
  1244. // Handle focus
  1245. this.addExitAnchorEventsToEl(el);
  1246. },
  1247. /**
  1248. * Add new exit anchor to the chart.
  1249. *
  1250. * @private
  1251. */
  1252. createExitAnchor: function () {
  1253. var chart = this.chart, exitAnchor = this.exitAnchor = doc.createElement('div');
  1254. chart.renderTo.appendChild(exitAnchor);
  1255. this.makeElementAnExitAnchor(exitAnchor);
  1256. },
  1257. /**
  1258. * @private
  1259. */
  1260. removeExitAnchor: function () {
  1261. if (this.exitAnchor && this.exitAnchor.parentNode) {
  1262. this.exitAnchor.parentNode
  1263. .removeChild(this.exitAnchor);
  1264. delete this.exitAnchor;
  1265. }
  1266. },
  1267. /**
  1268. * @private
  1269. */
  1270. addExitAnchorEventsToEl: function (element) {
  1271. var chart = this.chart, keyboardNavigation = this;
  1272. this.eventProvider.addEvent(element, 'focus', function (ev) {
  1273. var e = ev || win.event, curModule, focusComesFromChart = (e.relatedTarget &&
  1274. chart.container.contains(e.relatedTarget)), comingInBackwards = !(focusComesFromChart || keyboardNavigation.exiting);
  1275. if (comingInBackwards) {
  1276. chart.renderTo.focus();
  1277. e.preventDefault();
  1278. // Move to last valid keyboard nav module
  1279. // Note the we don't run it, just set the index
  1280. if (keyboardNavigation.modules &&
  1281. keyboardNavigation.modules.length) {
  1282. keyboardNavigation.currentModuleIx =
  1283. keyboardNavigation.modules.length - 1;
  1284. curModule = keyboardNavigation.modules[keyboardNavigation.currentModuleIx];
  1285. // Validate the module
  1286. if (curModule &&
  1287. curModule.validate && !curModule.validate()) {
  1288. // Invalid. Try moving backwards to find next valid.
  1289. keyboardNavigation.prev();
  1290. }
  1291. else if (curModule) {
  1292. // We have a valid module, init it
  1293. curModule.init(-1);
  1294. }
  1295. }
  1296. }
  1297. else {
  1298. // Don't skip the next focus, we only skip once.
  1299. keyboardNavigation.exiting = false;
  1300. }
  1301. });
  1302. },
  1303. /**
  1304. * Remove all traces of keyboard navigation.
  1305. * @private
  1306. */
  1307. destroy: function () {
  1308. this.removeExitAnchor();
  1309. this.eventProvider.removeAddedEvents();
  1310. this.chart.container.removeAttribute('tabindex');
  1311. }
  1312. };
  1313. return KeyboardNavigation;
  1314. });
  1315. _registerModule(_modules, 'modules/accessibility/components/LegendComponent.js', [_modules['parts/Globals.js'], _modules['parts/Legend.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/KeyboardNavigationHandler.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, Legend, U, AccessibilityComponent, KeyboardNavigationHandler, HTMLUtilities) {
  1316. /* *
  1317. *
  1318. * (c) 2009-2020 Øystein Moseng
  1319. *
  1320. * Accessibility component for chart legend.
  1321. *
  1322. * License: www.highcharts.com/license
  1323. *
  1324. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1325. *
  1326. * */
  1327. var addEvent = U.addEvent, extend = U.extend, find = U.find, fireEvent = U.fireEvent;
  1328. var stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString, removeElement = HTMLUtilities.removeElement;
  1329. /* eslint-disable no-invalid-this, valid-jsdoc */
  1330. /**
  1331. * @private
  1332. */
  1333. function scrollLegendToItem(legend, itemIx) {
  1334. var itemPage = legend.allItems[itemIx].pageIx, curPage = legend.currentPage;
  1335. if (typeof itemPage !== 'undefined' && itemPage + 1 !== curPage) {
  1336. legend.scroll(1 + itemPage - curPage);
  1337. }
  1338. }
  1339. /**
  1340. * @private
  1341. */
  1342. function shouldDoLegendA11y(chart) {
  1343. var items = chart.legend && chart.legend.allItems, legendA11yOptions = (chart.options.legend.accessibility || {});
  1344. return !!(items && items.length &&
  1345. !(chart.colorAxis && chart.colorAxis.length) &&
  1346. legendA11yOptions.enabled !== false);
  1347. }
  1348. /**
  1349. * Highlight legend item by index.
  1350. *
  1351. * @private
  1352. * @function Highcharts.Chart#highlightLegendItem
  1353. *
  1354. * @param {number} ix
  1355. *
  1356. * @return {boolean}
  1357. */
  1358. H.Chart.prototype.highlightLegendItem = function (ix) {
  1359. var items = this.legend.allItems, oldIx = this.highlightedLegendItemIx;
  1360. if (items[ix]) {
  1361. if (items[oldIx]) {
  1362. fireEvent(items[oldIx].legendGroup.element, 'mouseout');
  1363. }
  1364. scrollLegendToItem(this.legend, ix);
  1365. this.setFocusToElement(items[ix].legendItem, items[ix].a11yProxyElement);
  1366. fireEvent(items[ix].legendGroup.element, 'mouseover');
  1367. return true;
  1368. }
  1369. return false;
  1370. };
  1371. // Keep track of pressed state for legend items
  1372. addEvent(Legend, 'afterColorizeItem', function (e) {
  1373. var chart = this.chart, a11yOptions = chart.options.accessibility, legendItem = e.item;
  1374. if (a11yOptions.enabled && legendItem && legendItem.a11yProxyElement) {
  1375. legendItem.a11yProxyElement.setAttribute('aria-pressed', e.visible ? 'false' : 'true');
  1376. }
  1377. });
  1378. /**
  1379. * The LegendComponent class
  1380. *
  1381. * @private
  1382. * @class
  1383. * @name Highcharts.LegendComponent
  1384. */
  1385. var LegendComponent = function () { };
  1386. LegendComponent.prototype = new AccessibilityComponent();
  1387. extend(LegendComponent.prototype, /** @lends Highcharts.LegendComponent */ {
  1388. /**
  1389. * Init the component
  1390. * @private
  1391. */
  1392. init: function () {
  1393. var component = this;
  1394. this.proxyElementsList = [];
  1395. this.recreateProxies();
  1396. // Note: Chart could create legend dynamically, so events can not be
  1397. // tied to the component's chart's current legend.
  1398. this.addEvent(Legend, 'afterScroll', function () {
  1399. if (this.chart === component.chart) {
  1400. component.updateProxiesPositions();
  1401. component.updateLegendItemProxyVisibility();
  1402. this.chart.highlightLegendItem(component.highlightedLegendItemIx);
  1403. }
  1404. });
  1405. this.addEvent(Legend, 'afterPositionItem', function (e) {
  1406. if (this.chart === component.chart && this.chart.renderer) {
  1407. component.updateProxyPositionForItem(e.item);
  1408. }
  1409. });
  1410. },
  1411. /**
  1412. * @private
  1413. */
  1414. updateLegendItemProxyVisibility: function () {
  1415. var legend = this.chart.legend, items = legend.allItems || [], curPage = legend.currentPage || 1, clipHeight = legend.clipHeight || 0;
  1416. items.forEach(function (item) {
  1417. var itemPage = item.pageIx || 0, y = item._legendItemPos ? item._legendItemPos[1] : 0, h = item.legendItem ? Math.round(item.legendItem.getBBox().height) : 0, hide = y + h - legend.pages[itemPage] > clipHeight || itemPage !== curPage - 1;
  1418. if (item.a11yProxyElement) {
  1419. item.a11yProxyElement.style.visibility = hide ?
  1420. 'hidden' : 'visible';
  1421. }
  1422. });
  1423. },
  1424. /**
  1425. * The legend needs updates on every render, in order to update positioning
  1426. * of the proxy overlays.
  1427. */
  1428. onChartRender: function () {
  1429. if (shouldDoLegendA11y(this.chart)) {
  1430. this.updateProxiesPositions();
  1431. }
  1432. else {
  1433. this.removeProxies();
  1434. }
  1435. },
  1436. /**
  1437. * @private
  1438. */
  1439. updateProxiesPositions: function () {
  1440. for (var _i = 0, _a = this.proxyElementsList; _i < _a.length; _i++) {
  1441. var _b = _a[_i], element = _b.element, posElement = _b.posElement;
  1442. this.updateProxyButtonPosition(element, posElement);
  1443. }
  1444. },
  1445. /**
  1446. * @private
  1447. */
  1448. updateProxyPositionForItem: function (item) {
  1449. var proxyRef = find(this.proxyElementsList, function (ref) { return ref.item === item; });
  1450. if (proxyRef) {
  1451. this.updateProxyButtonPosition(proxyRef.element, proxyRef.posElement);
  1452. }
  1453. },
  1454. /**
  1455. * @private
  1456. */
  1457. recreateProxies: function () {
  1458. this.removeProxies();
  1459. if (shouldDoLegendA11y(this.chart)) {
  1460. this.addLegendProxyGroup();
  1461. this.proxyLegendItems();
  1462. this.updateLegendItemProxyVisibility();
  1463. }
  1464. },
  1465. /**
  1466. * @private
  1467. */
  1468. removeProxies: function () {
  1469. removeElement(this.legendProxyGroup);
  1470. this.proxyElementsList = [];
  1471. },
  1472. /**
  1473. * @private
  1474. */
  1475. addLegendProxyGroup: function () {
  1476. var a11yOptions = this.chart.options.accessibility, groupLabel = this.chart.langFormat('accessibility.legend.legendLabel', {}), groupRole = a11yOptions.landmarkVerbosity === 'all' ?
  1477. 'region' : null;
  1478. this.legendProxyGroup = this.addProxyGroup({
  1479. 'aria-label': groupLabel,
  1480. 'role': groupRole
  1481. });
  1482. },
  1483. /**
  1484. * @private
  1485. */
  1486. proxyLegendItems: function () {
  1487. var component = this, items = (this.chart.legend &&
  1488. this.chart.legend.allItems || []);
  1489. items.forEach(function (item) {
  1490. if (item.legendItem && item.legendItem.element) {
  1491. component.proxyLegendItem(item);
  1492. }
  1493. });
  1494. },
  1495. /**
  1496. * @private
  1497. * @param {Highcharts.BubbleLegend|Point|Highcharts.Series} item
  1498. */
  1499. proxyLegendItem: function (item) {
  1500. if (!item.legendItem || !item.legendGroup) {
  1501. return;
  1502. }
  1503. var itemLabel = this.chart.langFormat('accessibility.legend.legendItem', {
  1504. chart: this.chart,
  1505. itemName: stripHTMLTags(item.name)
  1506. }), attribs = {
  1507. tabindex: -1,
  1508. 'aria-pressed': !item.visible,
  1509. 'aria-label': itemLabel
  1510. },
  1511. // Considers useHTML
  1512. proxyPositioningElement = item.legendGroup.div ?
  1513. item.legendItem : item.legendGroup;
  1514. item.a11yProxyElement = this.createProxyButton(item.legendItem, this.legendProxyGroup, attribs, proxyPositioningElement);
  1515. this.proxyElementsList.push({
  1516. item: item,
  1517. element: item.a11yProxyElement,
  1518. posElement: proxyPositioningElement
  1519. });
  1520. },
  1521. /**
  1522. * Get keyboard navigation handler for this component.
  1523. * @return {Highcharts.KeyboardNavigationHandler}
  1524. */
  1525. getKeyboardNavigation: function () {
  1526. var keys = this.keyCodes, component = this, chart = this.chart;
  1527. return new KeyboardNavigationHandler(chart, {
  1528. keyCodeMap: [
  1529. [
  1530. [keys.left, keys.right, keys.up, keys.down],
  1531. function (keyCode) {
  1532. return component.onKbdArrowKey(this, keyCode);
  1533. }
  1534. ],
  1535. [
  1536. [keys.enter, keys.space],
  1537. function () {
  1538. return component.onKbdClick(this);
  1539. }
  1540. ]
  1541. ],
  1542. validate: function () {
  1543. return component.shouldHaveLegendNavigation();
  1544. },
  1545. init: function (direction) {
  1546. return component.onKbdNavigationInit(direction);
  1547. }
  1548. });
  1549. },
  1550. /**
  1551. * @private
  1552. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1553. * @param {number} keyCode
  1554. * @return {number}
  1555. * Response code
  1556. */
  1557. onKbdArrowKey: function (keyboardNavigationHandler, keyCode) {
  1558. var keys = this.keyCodes, response = keyboardNavigationHandler.response, chart = this.chart, a11yOptions = chart.options.accessibility, numItems = chart.legend.allItems.length, direction = (keyCode === keys.left || keyCode === keys.up) ? -1 : 1;
  1559. var res = chart.highlightLegendItem(this.highlightedLegendItemIx + direction);
  1560. if (res) {
  1561. this.highlightedLegendItemIx += direction;
  1562. return response.success;
  1563. }
  1564. if (numItems > 1 &&
  1565. a11yOptions.keyboardNavigation.wrapAround) {
  1566. keyboardNavigationHandler.init(direction);
  1567. return response.success;
  1568. }
  1569. // No wrap, move
  1570. return response[direction > 0 ? 'next' : 'prev'];
  1571. },
  1572. /**
  1573. * @private
  1574. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1575. * @return {number}
  1576. * Response code
  1577. */
  1578. onKbdClick: function (keyboardNavigationHandler) {
  1579. var legendItem = this.chart.legend.allItems[this.highlightedLegendItemIx];
  1580. if (legendItem && legendItem.a11yProxyElement) {
  1581. fireEvent(legendItem.a11yProxyElement, 'click');
  1582. }
  1583. return keyboardNavigationHandler.response.success;
  1584. },
  1585. /**
  1586. * @private
  1587. * @return {boolean|undefined}
  1588. */
  1589. shouldHaveLegendNavigation: function () {
  1590. var chart = this.chart, legendOptions = chart.options.legend || {}, hasLegend = chart.legend && chart.legend.allItems, hasColorAxis = chart.colorAxis && chart.colorAxis.length, legendA11yOptions = (legendOptions.accessibility || {});
  1591. return !!(hasLegend &&
  1592. chart.legend.display &&
  1593. !hasColorAxis &&
  1594. legendA11yOptions.enabled &&
  1595. legendA11yOptions.keyboardNavigation &&
  1596. legendA11yOptions.keyboardNavigation.enabled);
  1597. },
  1598. /**
  1599. * @private
  1600. * @param {number} direction
  1601. */
  1602. onKbdNavigationInit: function (direction) {
  1603. var chart = this.chart, lastIx = chart.legend.allItems.length - 1, ixToHighlight = direction > 0 ? 0 : lastIx;
  1604. chart.highlightLegendItem(ixToHighlight);
  1605. this.highlightedLegendItemIx = ixToHighlight;
  1606. }
  1607. });
  1608. return LegendComponent;
  1609. });
  1610. _registerModule(_modules, 'modules/accessibility/components/MenuComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/KeyboardNavigationHandler.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, U, AccessibilityComponent, KeyboardNavigationHandler, ChartUtilities, HTMLUtilities) {
  1611. /* *
  1612. *
  1613. * (c) 2009-2020 Øystein Moseng
  1614. *
  1615. * Accessibility component for exporting menu.
  1616. *
  1617. * License: www.highcharts.com/license
  1618. *
  1619. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1620. *
  1621. * */
  1622. var extend = U.extend;
  1623. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  1624. var removeElement = HTMLUtilities.removeElement, getFakeMouseEvent = HTMLUtilities.getFakeMouseEvent;
  1625. /* eslint-disable no-invalid-this, valid-jsdoc */
  1626. /**
  1627. * Get the wrapped export button element of a chart.
  1628. *
  1629. * @private
  1630. * @param {Highcharts.Chart} chart
  1631. * @returns {Highcharts.SVGElement}
  1632. */
  1633. function getExportMenuButtonElement(chart) {
  1634. return chart.exportSVGElements && chart.exportSVGElements[0];
  1635. }
  1636. /**
  1637. * Show the export menu and focus the first item (if exists).
  1638. *
  1639. * @private
  1640. * @function Highcharts.Chart#showExportMenu
  1641. */
  1642. H.Chart.prototype.showExportMenu = function () {
  1643. var exportButton = getExportMenuButtonElement(this);
  1644. if (exportButton) {
  1645. var el = exportButton.element;
  1646. if (el.onclick) {
  1647. el.onclick(getFakeMouseEvent('click'));
  1648. }
  1649. }
  1650. };
  1651. /**
  1652. * @private
  1653. * @function Highcharts.Chart#hideExportMenu
  1654. */
  1655. H.Chart.prototype.hideExportMenu = function () {
  1656. var chart = this, exportList = chart.exportDivElements;
  1657. if (exportList && chart.exportContextMenu) {
  1658. // Reset hover states etc.
  1659. exportList.forEach(function (el) {
  1660. if (el.className === 'highcharts-menu-item' && el.onmouseout) {
  1661. el.onmouseout(getFakeMouseEvent('mouseout'));
  1662. }
  1663. });
  1664. chart.highlightedExportItemIx = 0;
  1665. // Hide the menu div
  1666. chart.exportContextMenu.hideMenu();
  1667. // Make sure the chart has focus and can capture keyboard events
  1668. chart.container.focus();
  1669. }
  1670. };
  1671. /**
  1672. * Highlight export menu item by index.
  1673. *
  1674. * @private
  1675. * @function Highcharts.Chart#highlightExportItem
  1676. *
  1677. * @param {number} ix
  1678. *
  1679. * @return {boolean}
  1680. */
  1681. H.Chart.prototype.highlightExportItem = function (ix) {
  1682. var listItem = this.exportDivElements && this.exportDivElements[ix], curHighlighted = this.exportDivElements &&
  1683. this.exportDivElements[this.highlightedExportItemIx], hasSVGFocusSupport;
  1684. if (listItem &&
  1685. listItem.tagName === 'LI' &&
  1686. !(listItem.children && listItem.children.length)) {
  1687. // Test if we have focus support for SVG elements
  1688. hasSVGFocusSupport = !!(this.renderTo.getElementsByTagName('g')[0] || {}).focus;
  1689. // Only focus if we can set focus back to the elements after
  1690. // destroying the menu (#7422)
  1691. if (listItem.focus && hasSVGFocusSupport) {
  1692. listItem.focus();
  1693. }
  1694. if (curHighlighted && curHighlighted.onmouseout) {
  1695. curHighlighted.onmouseout(getFakeMouseEvent('mouseout'));
  1696. }
  1697. if (listItem.onmouseover) {
  1698. listItem.onmouseover(getFakeMouseEvent('mouseover'));
  1699. }
  1700. this.highlightedExportItemIx = ix;
  1701. return true;
  1702. }
  1703. return false;
  1704. };
  1705. /**
  1706. * Try to highlight the last valid export menu item.
  1707. *
  1708. * @private
  1709. * @function Highcharts.Chart#highlightLastExportItem
  1710. * @return {boolean}
  1711. */
  1712. H.Chart.prototype.highlightLastExportItem = function () {
  1713. var chart = this, i;
  1714. if (chart.exportDivElements) {
  1715. i = chart.exportDivElements.length;
  1716. while (i--) {
  1717. if (chart.highlightExportItem(i)) {
  1718. return true;
  1719. }
  1720. }
  1721. }
  1722. return false;
  1723. };
  1724. /**
  1725. * @private
  1726. * @param {Highcharts.Chart} chart
  1727. */
  1728. function exportingShouldHaveA11y(chart) {
  1729. var exportingOpts = chart.options.exporting, exportButton = getExportMenuButtonElement(chart);
  1730. return !!(exportingOpts &&
  1731. exportingOpts.enabled !== false &&
  1732. exportingOpts.accessibility &&
  1733. exportingOpts.accessibility.enabled &&
  1734. exportButton &&
  1735. exportButton.element);
  1736. }
  1737. /**
  1738. * The MenuComponent class
  1739. *
  1740. * @private
  1741. * @class
  1742. * @name Highcharts.MenuComponent
  1743. */
  1744. var MenuComponent = function () { };
  1745. MenuComponent.prototype = new AccessibilityComponent();
  1746. extend(MenuComponent.prototype, /** @lends Highcharts.MenuComponent */ {
  1747. /**
  1748. * Init the component
  1749. */
  1750. init: function () {
  1751. var chart = this.chart, component = this;
  1752. this.addEvent(chart, 'exportMenuShown', function () {
  1753. component.onMenuShown();
  1754. });
  1755. this.addEvent(chart, 'exportMenuHidden', function () {
  1756. component.onMenuHidden();
  1757. });
  1758. },
  1759. /**
  1760. * @private
  1761. */
  1762. onMenuHidden: function () {
  1763. var menu = this.chart.exportContextMenu;
  1764. if (menu) {
  1765. menu.setAttribute('aria-hidden', 'true');
  1766. }
  1767. this.isExportMenuShown = false;
  1768. this.setExportButtonExpandedState('false');
  1769. },
  1770. /**
  1771. * @private
  1772. */
  1773. onMenuShown: function () {
  1774. var chart = this.chart, menu = chart.exportContextMenu;
  1775. if (menu) {
  1776. this.addAccessibleContextMenuAttribs();
  1777. unhideChartElementFromAT(chart, menu);
  1778. }
  1779. this.isExportMenuShown = true;
  1780. this.setExportButtonExpandedState('true');
  1781. },
  1782. /**
  1783. * @private
  1784. * @param {string} stateStr
  1785. */
  1786. setExportButtonExpandedState: function (stateStr) {
  1787. var button = this.exportButtonProxy;
  1788. if (button) {
  1789. button.setAttribute('aria-expanded', stateStr);
  1790. }
  1791. },
  1792. /**
  1793. * Called on each render of the chart. We need to update positioning of the
  1794. * proxy overlay.
  1795. */
  1796. onChartRender: function () {
  1797. var chart = this.chart, a11yOptions = chart.options.accessibility;
  1798. // Always start with a clean slate
  1799. removeElement(this.exportProxyGroup);
  1800. // Set screen reader properties on export menu
  1801. if (exportingShouldHaveA11y(chart)) {
  1802. // Proxy button and group
  1803. this.exportProxyGroup = this.addProxyGroup(
  1804. // Wrap in a region div if verbosity is high
  1805. a11yOptions.landmarkVerbosity === 'all' ? {
  1806. 'aria-label': chart.langFormat('accessibility.exporting.exportRegionLabel', { chart: chart }),
  1807. 'role': 'region'
  1808. } : {});
  1809. var button = getExportMenuButtonElement(this.chart);
  1810. this.exportButtonProxy = this.createProxyButton(button, this.exportProxyGroup, {
  1811. 'aria-label': chart.langFormat('accessibility.exporting.menuButtonLabel', { chart: chart }),
  1812. 'aria-expanded': 'false'
  1813. });
  1814. }
  1815. },
  1816. /**
  1817. * @private
  1818. */
  1819. addAccessibleContextMenuAttribs: function () {
  1820. var chart = this.chart, exportList = chart.exportDivElements;
  1821. if (exportList && exportList.length) {
  1822. // Set tabindex on the menu items to allow focusing by script
  1823. // Set role to give screen readers a chance to pick up the contents
  1824. exportList.forEach(function (item) {
  1825. if (item.tagName === 'LI' &&
  1826. !(item.children && item.children.length)) {
  1827. item.setAttribute('tabindex', -1);
  1828. }
  1829. else {
  1830. item.setAttribute('aria-hidden', 'true');
  1831. }
  1832. });
  1833. // Set accessibility properties on parent div
  1834. var parentDiv = exportList[0].parentNode;
  1835. parentDiv.removeAttribute('aria-hidden');
  1836. parentDiv.setAttribute('aria-label', chart.langFormat('accessibility.exporting.chartMenuLabel', { chart: chart }));
  1837. }
  1838. },
  1839. /**
  1840. * Get keyboard navigation handler for this component.
  1841. * @return {Highcharts.KeyboardNavigationHandler}
  1842. */
  1843. getKeyboardNavigation: function () {
  1844. var keys = this.keyCodes, chart = this.chart, component = this;
  1845. return new KeyboardNavigationHandler(chart, {
  1846. keyCodeMap: [
  1847. // Arrow prev handler
  1848. [
  1849. [keys.left, keys.up],
  1850. function () {
  1851. return component.onKbdPrevious(this);
  1852. }
  1853. ],
  1854. // Arrow next handler
  1855. [
  1856. [keys.right, keys.down],
  1857. function () {
  1858. return component.onKbdNext(this);
  1859. }
  1860. ],
  1861. // Click handler
  1862. [
  1863. [keys.enter, keys.space],
  1864. function () {
  1865. return component.onKbdClick(this);
  1866. }
  1867. ]
  1868. ],
  1869. // Only run exporting navigation if exporting support exists and is
  1870. // enabled on chart
  1871. validate: function () {
  1872. return chart.exportChart &&
  1873. chart.options.exporting.enabled !== false &&
  1874. chart.options.exporting.accessibility.enabled !==
  1875. false;
  1876. },
  1877. // Focus export menu button
  1878. init: function () {
  1879. var exportBtn = component.exportButtonProxy, exportGroup = chart.exportingGroup;
  1880. if (exportGroup && exportBtn) {
  1881. chart.setFocusToElement(exportGroup, exportBtn);
  1882. }
  1883. },
  1884. // Hide the menu
  1885. terminate: function () {
  1886. chart.hideExportMenu();
  1887. }
  1888. });
  1889. },
  1890. /**
  1891. * @private
  1892. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1893. * @return {number}
  1894. * Response code
  1895. */
  1896. onKbdPrevious: function (keyboardNavigationHandler) {
  1897. var chart = this.chart, a11yOptions = chart.options.accessibility, response = keyboardNavigationHandler.response, i = chart.highlightedExportItemIx || 0;
  1898. // Try to highlight prev item in list. Highlighting e.g.
  1899. // separators will fail.
  1900. while (i--) {
  1901. if (chart.highlightExportItem(i)) {
  1902. return response.success;
  1903. }
  1904. }
  1905. // We failed, so wrap around or move to prev module
  1906. if (a11yOptions.keyboardNavigation.wrapAround) {
  1907. chart.highlightLastExportItem();
  1908. return response.success;
  1909. }
  1910. return response.prev;
  1911. },
  1912. /**
  1913. * @private
  1914. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1915. * @return {number}
  1916. * Response code
  1917. */
  1918. onKbdNext: function (keyboardNavigationHandler) {
  1919. var chart = this.chart, a11yOptions = chart.options.accessibility, response = keyboardNavigationHandler.response, i = (chart.highlightedExportItemIx || 0) + 1;
  1920. // Try to highlight next item in list. Highlighting e.g.
  1921. // separators will fail.
  1922. for (; i < chart.exportDivElements.length; ++i) {
  1923. if (chart.highlightExportItem(i)) {
  1924. return response.success;
  1925. }
  1926. }
  1927. // We failed, so wrap around or move to next module
  1928. if (a11yOptions.keyboardNavigation.wrapAround) {
  1929. chart.highlightExportItem(0);
  1930. return response.success;
  1931. }
  1932. return response.next;
  1933. },
  1934. /**
  1935. * @private
  1936. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1937. * @return {number}
  1938. * Response code
  1939. */
  1940. onKbdClick: function (keyboardNavigationHandler) {
  1941. var chart = this.chart, curHighlightedItem = chart.exportDivElements[chart.highlightedExportItemIx], exportButtonElement = getExportMenuButtonElement(chart).element;
  1942. if (this.isExportMenuShown) {
  1943. this.fakeClickEvent(curHighlightedItem);
  1944. }
  1945. else {
  1946. this.fakeClickEvent(exportButtonElement);
  1947. chart.highlightExportItem(0);
  1948. }
  1949. return keyboardNavigationHandler.response.success;
  1950. }
  1951. });
  1952. return MenuComponent;
  1953. });
  1954. _registerModule(_modules, 'modules/accessibility/components/SeriesComponent/SeriesKeyboardNavigation.js', [_modules['parts/Chart.js'], _modules['parts/Globals.js'], _modules['parts/Point.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/KeyboardNavigationHandler.js'], _modules['modules/accessibility/utils/EventProvider.js'], _modules['modules/accessibility/utils/chartUtilities.js']], function (Chart, H, Point, U, KeyboardNavigationHandler, EventProvider, ChartUtilities) {
  1955. /* *
  1956. *
  1957. * (c) 2009-2020 Øystein Moseng
  1958. *
  1959. * Handle keyboard navigation for series.
  1960. *
  1961. * License: www.highcharts.com/license
  1962. *
  1963. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1964. *
  1965. * */
  1966. var defined = U.defined, extend = U.extend;
  1967. var getPointFromXY = ChartUtilities.getPointFromXY, getSeriesFromName = ChartUtilities.getSeriesFromName, scrollToPoint = ChartUtilities.scrollToPoint;
  1968. /* eslint-disable no-invalid-this, valid-jsdoc */
  1969. /*
  1970. * Set for which series types it makes sense to move to the closest point with
  1971. * up/down arrows, and which series types should just move to next series.
  1972. */
  1973. H.Series.prototype.keyboardMoveVertical = true;
  1974. ['column', 'pie'].forEach(function (type) {
  1975. if (H.seriesTypes[type]) {
  1976. H.seriesTypes[type].prototype.keyboardMoveVertical = false;
  1977. }
  1978. });
  1979. /**
  1980. * Get the index of a point in a series. This is needed when using e.g. data
  1981. * grouping.
  1982. *
  1983. * @private
  1984. * @function getPointIndex
  1985. *
  1986. * @param {Highcharts.AccessibilityPoint} point
  1987. * The point to find index of.
  1988. *
  1989. * @return {number|undefined}
  1990. * The index in the series.points array of the point.
  1991. */
  1992. function getPointIndex(point) {
  1993. var index = point.index, points = point.series.points, i = points.length;
  1994. if (points[index] !== point) {
  1995. while (i--) {
  1996. if (points[i] === point) {
  1997. return i;
  1998. }
  1999. }
  2000. }
  2001. else {
  2002. return index;
  2003. }
  2004. }
  2005. /**
  2006. * Determine if series navigation should be skipped
  2007. *
  2008. * @private
  2009. * @function isSkipSeries
  2010. *
  2011. * @param {Highcharts.Series} series
  2012. *
  2013. * @return {boolean|number|undefined}
  2014. */
  2015. function isSkipSeries(series) {
  2016. var a11yOptions = series.chart.options.accessibility, seriesNavOptions = a11yOptions.keyboardNavigation.seriesNavigation, seriesA11yOptions = series.options.accessibility || {}, seriesKbdNavOptions = seriesA11yOptions.keyboardNavigation;
  2017. return seriesKbdNavOptions && seriesKbdNavOptions.enabled === false ||
  2018. seriesA11yOptions.enabled === false ||
  2019. series.options.enableMouseTracking === false || // #8440
  2020. !series.visible ||
  2021. // Skip all points in a series where pointNavigationEnabledThreshold is
  2022. // reached
  2023. (seriesNavOptions.pointNavigationEnabledThreshold &&
  2024. seriesNavOptions.pointNavigationEnabledThreshold <=
  2025. series.points.length);
  2026. }
  2027. /**
  2028. * Determine if navigation for a point should be skipped
  2029. *
  2030. * @private
  2031. * @function isSkipPoint
  2032. *
  2033. * @param {Highcharts.Point} point
  2034. *
  2035. * @return {boolean|number|undefined}
  2036. */
  2037. function isSkipPoint(point) {
  2038. var a11yOptions = point.series.chart.options.accessibility;
  2039. return point.isNull &&
  2040. a11yOptions.keyboardNavigation.seriesNavigation.skipNullPoints ||
  2041. point.visible === false ||
  2042. isSkipSeries(point.series);
  2043. }
  2044. /**
  2045. * Get the point in a series that is closest (in pixel distance) to a reference
  2046. * point. Optionally supply weight factors for x and y directions.
  2047. *
  2048. * @private
  2049. * @function getClosestPoint
  2050. *
  2051. * @param {Highcharts.Point} point
  2052. * @param {Highcharts.Series} series
  2053. * @param {number} [xWeight]
  2054. * @param {number} [yWeight]
  2055. *
  2056. * @return {Highcharts.Point|undefined}
  2057. */
  2058. function getClosestPoint(point, series, xWeight, yWeight) {
  2059. var minDistance = Infinity, dPoint, minIx, distance, i = series.points.length, hasUndefinedPosition = function (point) {
  2060. return !(defined(point.plotX) && defined(point.plotY));
  2061. };
  2062. if (hasUndefinedPosition(point)) {
  2063. return;
  2064. }
  2065. while (i--) {
  2066. dPoint = series.points[i];
  2067. if (hasUndefinedPosition(dPoint)) {
  2068. continue;
  2069. }
  2070. distance = (point.plotX - dPoint.plotX) *
  2071. (point.plotX - dPoint.plotX) *
  2072. (xWeight || 1) +
  2073. (point.plotY - dPoint.plotY) *
  2074. (point.plotY - dPoint.plotY) *
  2075. (yWeight || 1);
  2076. if (distance < minDistance) {
  2077. minDistance = distance;
  2078. minIx = i;
  2079. }
  2080. }
  2081. return defined(minIx) ? series.points[minIx] : void 0;
  2082. }
  2083. /**
  2084. * Highlights a point (show tooltip and display hover state).
  2085. *
  2086. * @private
  2087. * @function Highcharts.Point#highlight
  2088. *
  2089. * @return {Highcharts.Point}
  2090. * This highlighted point.
  2091. */
  2092. Point.prototype.highlight = function () {
  2093. var chart = this.series.chart;
  2094. if (!this.isNull) {
  2095. this.onMouseOver(); // Show the hover marker and tooltip
  2096. }
  2097. else {
  2098. if (chart.tooltip) {
  2099. chart.tooltip.hide(0);
  2100. }
  2101. // Don't call blur on the element, as it messes up the chart div's focus
  2102. }
  2103. scrollToPoint(this);
  2104. // We focus only after calling onMouseOver because the state change can
  2105. // change z-index and mess up the element.
  2106. if (this.graphic) {
  2107. chart.setFocusToElement(this.graphic);
  2108. }
  2109. chart.highlightedPoint = this;
  2110. return this;
  2111. };
  2112. /**
  2113. * Function to highlight next/previous point in chart.
  2114. *
  2115. * @private
  2116. * @function Highcharts.Chart#highlightAdjacentPoint
  2117. *
  2118. * @param {boolean} next
  2119. * Flag for the direction.
  2120. *
  2121. * @return {Highcharts.Point|boolean}
  2122. * Returns highlighted point on success, false on failure (no adjacent
  2123. * point to highlight in chosen direction).
  2124. */
  2125. Chart.prototype.highlightAdjacentPoint = function (next) {
  2126. var chart = this, series = chart.series, curPoint = chart.highlightedPoint, curPointIndex = curPoint && getPointIndex(curPoint) || 0, curPoints = (curPoint && curPoint.series.points), lastSeries = chart.series && chart.series[chart.series.length - 1], lastPoint = lastSeries && lastSeries.points &&
  2127. lastSeries.points[lastSeries.points.length - 1], newSeries, newPoint;
  2128. // If no points, return false
  2129. if (!series[0] || !series[0].points) {
  2130. return false;
  2131. }
  2132. if (!curPoint) {
  2133. // No point is highlighted yet. Try first/last point depending on move
  2134. // direction
  2135. newPoint = next ? series[0].points[0] : lastPoint;
  2136. }
  2137. else {
  2138. // We have a highlighted point.
  2139. // Grab next/prev point & series
  2140. newSeries = series[curPoint.series.index + (next ? 1 : -1)];
  2141. newPoint = curPoints[curPointIndex + (next ? 1 : -1)];
  2142. if (!newPoint && newSeries) {
  2143. // Done with this series, try next one
  2144. newPoint = newSeries.points[next ? 0 : newSeries.points.length - 1];
  2145. }
  2146. // If there is no adjacent point, we return false
  2147. if (!newPoint) {
  2148. return false;
  2149. }
  2150. }
  2151. // Recursively skip points
  2152. if (isSkipPoint(newPoint)) {
  2153. // If we skip this whole series, move to the end of the series before we
  2154. // recurse, just to optimize
  2155. newSeries = newPoint.series;
  2156. if (isSkipSeries(newSeries)) {
  2157. chart.highlightedPoint = next ?
  2158. newSeries.points[newSeries.points.length - 1] :
  2159. newSeries.points[0];
  2160. }
  2161. else {
  2162. // Otherwise, just move one point
  2163. chart.highlightedPoint = newPoint;
  2164. }
  2165. // Retry
  2166. return chart.highlightAdjacentPoint(next);
  2167. }
  2168. // There is an adjacent point, highlight it
  2169. return newPoint.highlight();
  2170. };
  2171. /**
  2172. * Highlight first valid point in a series. Returns the point if successfully
  2173. * highlighted, otherwise false. If there is a highlighted point in the series,
  2174. * use that as starting point.
  2175. *
  2176. * @private
  2177. * @function Highcharts.Series#highlightFirstValidPoint
  2178. *
  2179. * @return {boolean|Highcharts.Point}
  2180. */
  2181. H.Series.prototype.highlightFirstValidPoint = function () {
  2182. var curPoint = this.chart.highlightedPoint, start = (curPoint && curPoint.series) === this ?
  2183. getPointIndex(curPoint) :
  2184. 0, points = this.points, len = points.length;
  2185. if (points && len) {
  2186. for (var i = start; i < len; ++i) {
  2187. if (!isSkipPoint(points[i])) {
  2188. return points[i].highlight();
  2189. }
  2190. }
  2191. for (var j = start; j >= 0; --j) {
  2192. if (!isSkipPoint(points[j])) {
  2193. return points[j].highlight();
  2194. }
  2195. }
  2196. }
  2197. return false;
  2198. };
  2199. /**
  2200. * Highlight next/previous series in chart. Returns false if no adjacent series
  2201. * in the direction, otherwise returns new highlighted point.
  2202. *
  2203. * @private
  2204. * @function Highcharts.Chart#highlightAdjacentSeries
  2205. *
  2206. * @param {boolean} down
  2207. *
  2208. * @return {Highcharts.Point|boolean}
  2209. */
  2210. Chart.prototype.highlightAdjacentSeries = function (down) {
  2211. var chart = this, newSeries, newPoint, adjacentNewPoint, curPoint = chart.highlightedPoint, lastSeries = chart.series && chart.series[chart.series.length - 1], lastPoint = lastSeries && lastSeries.points &&
  2212. lastSeries.points[lastSeries.points.length - 1];
  2213. // If no point is highlighted, highlight the first/last point
  2214. if (!chart.highlightedPoint) {
  2215. newSeries = down ? (chart.series && chart.series[0]) : lastSeries;
  2216. newPoint = down ?
  2217. (newSeries && newSeries.points && newSeries.points[0]) : lastPoint;
  2218. return newPoint ? newPoint.highlight() : false;
  2219. }
  2220. newSeries = chart.series[curPoint.series.index + (down ? -1 : 1)];
  2221. if (!newSeries) {
  2222. return false;
  2223. }
  2224. // We have a new series in this direction, find the right point
  2225. // Weigh xDistance as counting much higher than Y distance
  2226. newPoint = getClosestPoint(curPoint, newSeries, 4);
  2227. if (!newPoint) {
  2228. return false;
  2229. }
  2230. // New series and point exists, but we might want to skip it
  2231. if (isSkipSeries(newSeries)) {
  2232. // Skip the series
  2233. newPoint.highlight();
  2234. adjacentNewPoint = chart.highlightAdjacentSeries(down); // Try recurse
  2235. if (!adjacentNewPoint) {
  2236. // Recurse failed
  2237. curPoint.highlight();
  2238. return false;
  2239. }
  2240. // Recurse succeeded
  2241. return adjacentNewPoint;
  2242. }
  2243. // Highlight the new point or any first valid point back or forwards from it
  2244. newPoint.highlight();
  2245. return newPoint.series.highlightFirstValidPoint();
  2246. };
  2247. /**
  2248. * Highlight the closest point vertically.
  2249. *
  2250. * @private
  2251. * @function Highcharts.Chart#highlightAdjacentPointVertical
  2252. *
  2253. * @param {boolean} down
  2254. *
  2255. * @return {Highcharts.Point|boolean}
  2256. */
  2257. Chart.prototype.highlightAdjacentPointVertical = function (down) {
  2258. var curPoint = this.highlightedPoint, minDistance = Infinity, bestPoint;
  2259. if (!defined(curPoint.plotX) || !defined(curPoint.plotY)) {
  2260. return false;
  2261. }
  2262. this.series.forEach(function (series) {
  2263. if (isSkipSeries(series)) {
  2264. return;
  2265. }
  2266. series.points.forEach(function (point) {
  2267. if (!defined(point.plotY) || !defined(point.plotX) ||
  2268. point === curPoint) {
  2269. return;
  2270. }
  2271. var yDistance = point.plotY - curPoint.plotY, width = Math.abs(point.plotX - curPoint.plotX), distance = Math.abs(yDistance) * Math.abs(yDistance) +
  2272. width * width * 4; // Weigh horizontal distance highly
  2273. // Reverse distance number if axis is reversed
  2274. if (series.yAxis && series.yAxis.reversed) {
  2275. yDistance *= -1;
  2276. }
  2277. if (yDistance <= 0 && down || yDistance >= 0 && !down || // Chk dir
  2278. distance < 5 || // Points in same spot => infinite loop
  2279. isSkipPoint(point)) {
  2280. return;
  2281. }
  2282. if (distance < minDistance) {
  2283. minDistance = distance;
  2284. bestPoint = point;
  2285. }
  2286. });
  2287. });
  2288. return bestPoint ? bestPoint.highlight() : false;
  2289. };
  2290. /**
  2291. * @private
  2292. * @param {Highcharts.Chart} chart
  2293. * @return {Highcharts.Point|boolean}
  2294. */
  2295. function highlightFirstValidPointInChart(chart) {
  2296. var res = false;
  2297. delete chart.highlightedPoint;
  2298. res = chart.series.reduce(function (acc, cur) {
  2299. return acc || cur.highlightFirstValidPoint();
  2300. }, false);
  2301. return res;
  2302. }
  2303. /**
  2304. * @private
  2305. * @param {Highcharts.Chart} chart
  2306. * @return {Highcharts.Point|boolean}
  2307. */
  2308. function highlightLastValidPointInChart(chart) {
  2309. var numSeries = chart.series.length, i = numSeries, res = false;
  2310. while (i--) {
  2311. chart.highlightedPoint = chart.series[i].points[chart.series[i].points.length - 1];
  2312. // Highlight first valid point in the series will also
  2313. // look backwards. It always starts from currently
  2314. // highlighted point.
  2315. res = chart.series[i].highlightFirstValidPoint();
  2316. if (res) {
  2317. break;
  2318. }
  2319. }
  2320. return res;
  2321. }
  2322. /**
  2323. * @private
  2324. * @param {Highcharts.Chart} chart
  2325. */
  2326. function updateChartFocusAfterDrilling(chart) {
  2327. highlightFirstValidPointInChart(chart);
  2328. if (chart.focusElement) {
  2329. chart.focusElement.removeFocusBorder();
  2330. }
  2331. }
  2332. /**
  2333. * @private
  2334. * @class
  2335. * @name Highcharts.SeriesKeyboardNavigation
  2336. */
  2337. function SeriesKeyboardNavigation(chart, keyCodes) {
  2338. this.keyCodes = keyCodes;
  2339. this.chart = chart;
  2340. }
  2341. extend(SeriesKeyboardNavigation.prototype, /** @lends Highcharts.SeriesKeyboardNavigation */ {
  2342. /**
  2343. * Init the keyboard navigation
  2344. */
  2345. init: function () {
  2346. var keyboardNavigation = this, chart = this.chart, e = this.eventProvider = new EventProvider();
  2347. e.addEvent(H.Series, 'destroy', function () {
  2348. return keyboardNavigation.onSeriesDestroy(this);
  2349. });
  2350. e.addEvent(chart, 'afterDrilldown', function () {
  2351. updateChartFocusAfterDrilling(this);
  2352. });
  2353. e.addEvent(chart, 'drilldown', function (e) {
  2354. var point = e.point, series = point.series;
  2355. keyboardNavigation.lastDrilledDownPoint = {
  2356. x: point.x,
  2357. y: point.y,
  2358. seriesName: series ? series.name : ''
  2359. };
  2360. });
  2361. e.addEvent(chart, 'drillupall', function () {
  2362. setTimeout(function () {
  2363. keyboardNavigation.onDrillupAll();
  2364. }, 10);
  2365. });
  2366. },
  2367. onDrillupAll: function () {
  2368. // After drillup we want to find the point that was drilled down to and
  2369. // highlight it.
  2370. var last = this.lastDrilledDownPoint, chart = this.chart, series = last && getSeriesFromName(chart, last.seriesName), point;
  2371. if (last && series && defined(last.x) && defined(last.y)) {
  2372. point = getPointFromXY(series, last.x, last.y);
  2373. }
  2374. // Container focus can be lost on drillup due to deleted elements.
  2375. if (chart.container) {
  2376. chart.container.focus();
  2377. }
  2378. if (point && point.highlight) {
  2379. point.highlight();
  2380. }
  2381. if (chart.focusElement) {
  2382. chart.focusElement.removeFocusBorder();
  2383. }
  2384. },
  2385. /**
  2386. * @return {Highcharts.KeyboardNavigationHandler}
  2387. */
  2388. getKeyboardNavigationHandler: function () {
  2389. var keyboardNavigation = this, keys = this.keyCodes, chart = this.chart, inverted = chart.inverted;
  2390. return new KeyboardNavigationHandler(chart, {
  2391. keyCodeMap: [
  2392. [inverted ? [keys.up, keys.down] : [keys.left, keys.right], function (keyCode) {
  2393. return keyboardNavigation.onKbdSideways(this, keyCode);
  2394. }],
  2395. [inverted ? [keys.left, keys.right] : [keys.up, keys.down], function (keyCode) {
  2396. return keyboardNavigation.onKbdVertical(this, keyCode);
  2397. }],
  2398. [[keys.enter, keys.space], function () {
  2399. if (chart.highlightedPoint) {
  2400. chart.highlightedPoint.firePointEvent('click');
  2401. }
  2402. return this.response.success;
  2403. }]
  2404. ],
  2405. init: function (dir) {
  2406. return keyboardNavigation.onHandlerInit(this, dir);
  2407. },
  2408. terminate: function () {
  2409. return keyboardNavigation.onHandlerTerminate();
  2410. }
  2411. });
  2412. },
  2413. /**
  2414. * @private
  2415. * @param {Highcharts.KeyboardNavigationHandler} handler
  2416. * @param {number} keyCode
  2417. * @return {number}
  2418. * response
  2419. */
  2420. onKbdSideways: function (handler, keyCode) {
  2421. var keys = this.keyCodes, isNext = keyCode === keys.right || keyCode === keys.down;
  2422. return this.attemptHighlightAdjacentPoint(handler, isNext);
  2423. },
  2424. /**
  2425. * @private
  2426. * @param {Highcharts.KeyboardNavigationHandler} handler
  2427. * @param {number} keyCode
  2428. * @return {number}
  2429. * response
  2430. */
  2431. onKbdVertical: function (handler, keyCode) {
  2432. var chart = this.chart, keys = this.keyCodes, isNext = keyCode === keys.down || keyCode === keys.right, navOptions = chart.options.accessibility.keyboardNavigation
  2433. .seriesNavigation;
  2434. // Handle serialized mode, act like left/right
  2435. if (navOptions.mode && navOptions.mode === 'serialize') {
  2436. return this.attemptHighlightAdjacentPoint(handler, isNext);
  2437. }
  2438. // Normal mode, move between series
  2439. var highlightMethod = (chart.highlightedPoint &&
  2440. chart.highlightedPoint.series.keyboardMoveVertical) ?
  2441. 'highlightAdjacentPointVertical' :
  2442. 'highlightAdjacentSeries';
  2443. chart[highlightMethod](isNext);
  2444. return handler.response.success;
  2445. },
  2446. /**
  2447. * @private
  2448. * @param {Highcharts.KeyboardNavigationHandler} handler
  2449. * @param {number} initDirection
  2450. * @return {number}
  2451. * response
  2452. */
  2453. onHandlerInit: function (handler, initDirection) {
  2454. var chart = this.chart;
  2455. if (initDirection > 0) {
  2456. highlightFirstValidPointInChart(chart);
  2457. }
  2458. else {
  2459. highlightLastValidPointInChart(chart);
  2460. }
  2461. return handler.response.success;
  2462. },
  2463. /**
  2464. * @private
  2465. */
  2466. onHandlerTerminate: function () {
  2467. var _a, _b;
  2468. var chart = this.chart;
  2469. var curPoint = chart.highlightedPoint;
  2470. (_a = chart.tooltip) === null || _a === void 0 ? void 0 : _a.hide(0);
  2471. (_b = curPoint === null || curPoint === void 0 ? void 0 : curPoint.onMouseOut) === null || _b === void 0 ? void 0 : _b.call(curPoint);
  2472. delete chart.highlightedPoint;
  2473. },
  2474. /**
  2475. * Function that attempts to highlight next/prev point. Handles wrap around.
  2476. * @private
  2477. * @param {Highcharts.KeyboardNavigationHandler} handler
  2478. * @param {boolean} directionIsNext
  2479. * @return {number}
  2480. * response
  2481. */
  2482. attemptHighlightAdjacentPoint: function (handler, directionIsNext) {
  2483. var chart = this.chart, wrapAround = chart.options.accessibility.keyboardNavigation
  2484. .wrapAround, highlightSuccessful = chart.highlightAdjacentPoint(directionIsNext);
  2485. if (!highlightSuccessful) {
  2486. if (wrapAround) {
  2487. return handler.init(directionIsNext ? 1 : -1);
  2488. }
  2489. return handler.response[directionIsNext ? 'next' : 'prev'];
  2490. }
  2491. return handler.response.success;
  2492. },
  2493. /**
  2494. * @private
  2495. */
  2496. onSeriesDestroy: function (series) {
  2497. var chart = this.chart, currentHighlightedPointDestroyed = chart.highlightedPoint &&
  2498. chart.highlightedPoint.series === series;
  2499. if (currentHighlightedPointDestroyed) {
  2500. delete chart.highlightedPoint;
  2501. if (chart.focusElement) {
  2502. chart.focusElement.removeFocusBorder();
  2503. }
  2504. }
  2505. },
  2506. /**
  2507. * @private
  2508. */
  2509. destroy: function () {
  2510. this.eventProvider.removeAddedEvents();
  2511. }
  2512. });
  2513. return SeriesKeyboardNavigation;
  2514. });
  2515. _registerModule(_modules, 'modules/accessibility/components/AnnotationsA11y.js', [_modules['parts/Utilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (U, HTMLUtilities) {
  2516. /* *
  2517. *
  2518. * (c) 2009-2019 Øystein Moseng
  2519. *
  2520. * Annotations accessibility code.
  2521. *
  2522. * License: www.highcharts.com/license
  2523. *
  2524. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2525. *
  2526. * */
  2527. var inArray = U.inArray;
  2528. var escapeStringForHTML = HTMLUtilities.escapeStringForHTML, stripHTMLTagsFromString = HTMLUtilities.stripHTMLTagsFromString;
  2529. /**
  2530. * Get list of all annotation labels in the chart.
  2531. *
  2532. * @private
  2533. * @param {Highcharts.Chart} chart The chart to get annotation info on.
  2534. * @return {Array<object>} The labels, or empty array if none.
  2535. */
  2536. function getChartAnnotationLabels(chart) {
  2537. var annotations = chart.annotations || [];
  2538. return annotations.reduce(function (acc, cur) {
  2539. var _a;
  2540. if (((_a = cur.options) === null || _a === void 0 ? void 0 : _a.visible) !== false) {
  2541. acc = acc.concat(cur.labels);
  2542. }
  2543. return acc;
  2544. }, []);
  2545. }
  2546. /**
  2547. * Get the text of an annotation label.
  2548. *
  2549. * @private
  2550. * @param {object} label The annotation label object
  2551. * @return {string} The text in the label.
  2552. */
  2553. function getLabelText(label) {
  2554. var _a, _b, _c, _d;
  2555. var a11yDesc = (_b = (_a = label.options) === null || _a === void 0 ? void 0 : _a.accessibility) === null || _b === void 0 ? void 0 : _b.description;
  2556. return a11yDesc ? a11yDesc : ((_d = (_c = label.graphic) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.textStr) || '';
  2557. }
  2558. /**
  2559. * Describe an annotation label.
  2560. *
  2561. * @private
  2562. * @param {object} label The annotation label object to describe
  2563. * @return {string} The description for the label.
  2564. */
  2565. function getAnnotationLabelDescription(label) {
  2566. var _a, _b;
  2567. var a11yDesc = (_b = (_a = label.options) === null || _a === void 0 ? void 0 : _a.accessibility) === null || _b === void 0 ? void 0 : _b.description;
  2568. if (a11yDesc) {
  2569. return a11yDesc;
  2570. }
  2571. var chart = label.chart;
  2572. var labelText = getLabelText(label);
  2573. var points = label.points;
  2574. var getAriaLabel = function (point) { var _a, _b; return ((_b = (_a = point === null || point === void 0 ? void 0 : point.graphic) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.getAttribute('aria-label')) || ''; };
  2575. var getValueDesc = function (point) {
  2576. var _a;
  2577. var valDesc = ((_a = point === null || point === void 0 ? void 0 : point.accessibility) === null || _a === void 0 ? void 0 : _a.valueDescription) || getAriaLabel(point);
  2578. var seriesName = (point === null || point === void 0 ? void 0 : point.series.name) || '';
  2579. return (seriesName ? seriesName + ', ' : '') + 'data point ' + valDesc;
  2580. };
  2581. var pointValueDescriptions = points
  2582. .filter(function (p) { return !!p.graphic; }) // Filter out mock points
  2583. .map(getValueDesc)
  2584. .filter(function (desc) { return !!desc; }); // Filter out points we can't describe
  2585. var numPoints = pointValueDescriptions.length;
  2586. var pointsSelector = numPoints > 1 ? 'MultiplePoints' : numPoints ? 'SinglePoint' : 'NoPoints';
  2587. var langFormatStr = 'accessibility.screenReaderSection.annotations.description' + pointsSelector;
  2588. var context = {
  2589. annotationText: labelText,
  2590. numPoints: numPoints,
  2591. annotationPoint: pointValueDescriptions[0],
  2592. additionalAnnotationPoints: pointValueDescriptions.slice(1)
  2593. };
  2594. return chart.langFormat(langFormatStr, context);
  2595. }
  2596. /**
  2597. * Return array of HTML strings for each annotation label in the chart.
  2598. *
  2599. * @private
  2600. * @param {Highcharts.Chart} chart The chart to get annotation info on.
  2601. * @return {Array<string>} Array of strings with HTML content for each annotation label.
  2602. */
  2603. function getAnnotationListItems(chart) {
  2604. var labels = getChartAnnotationLabels(chart);
  2605. return labels.map(function (label) {
  2606. var desc = escapeStringForHTML(stripHTMLTagsFromString(getAnnotationLabelDescription(label)));
  2607. return desc ? "<li>" + desc + "</li>" : '';
  2608. });
  2609. }
  2610. /**
  2611. * Return the annotation info for a chart as string.
  2612. *
  2613. * @private
  2614. * @param {Highcharts.Chart} chart The chart to get annotation info on.
  2615. * @return {string} String with HTML content or empty string if no annotations.
  2616. */
  2617. function getAnnotationsInfoHTML(chart) {
  2618. var annotations = chart.annotations;
  2619. if (!(annotations && annotations.length)) {
  2620. return '';
  2621. }
  2622. var annotationItems = getAnnotationListItems(chart);
  2623. return "<ul>" + annotationItems.join(' ') + "</ul>";
  2624. }
  2625. /**
  2626. * Return the texts for the annotation(s) connected to a point, or empty array
  2627. * if none.
  2628. *
  2629. * @private
  2630. * @param {Highcharts.Point} point The data point to get the annotation info from.
  2631. * @return {Array<string>} Annotation texts
  2632. */
  2633. function getPointAnnotationTexts(point) {
  2634. var labels = getChartAnnotationLabels(point.series.chart);
  2635. var pointLabels = labels
  2636. .filter(function (label) { return inArray(point, label.points) > -1; });
  2637. if (!pointLabels.length) {
  2638. return [];
  2639. }
  2640. return pointLabels.map(function (label) { return "" + getLabelText(label); });
  2641. }
  2642. var AnnotationsA11y = {
  2643. getAnnotationsInfoHTML: getAnnotationsInfoHTML,
  2644. getAnnotationLabelDescription: getAnnotationLabelDescription,
  2645. getAnnotationListItems: getAnnotationListItems,
  2646. getPointAnnotationTexts: getPointAnnotationTexts
  2647. };
  2648. return AnnotationsA11y;
  2649. });
  2650. _registerModule(_modules, 'modules/accessibility/components/SeriesComponent/SeriesDescriber.js', [_modules['parts/Utilities.js'], _modules['modules/accessibility/components/AnnotationsA11y.js'], _modules['modules/accessibility/utils/htmlUtilities.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['parts/Tooltip.js']], function (U, AnnotationsA11y, HTMLUtilities, ChartUtilities, Tooltip) {
  2651. /* *
  2652. *
  2653. * (c) 2009-2020 Øystein Moseng
  2654. *
  2655. * Place desriptions on a series and its points.
  2656. *
  2657. * License: www.highcharts.com/license
  2658. *
  2659. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2660. *
  2661. * */
  2662. var find = U.find, format = U.format, isNumber = U.isNumber, numberFormat = U.numberFormat, pick = U.pick, defined = U.defined;
  2663. var getPointAnnotationTexts = AnnotationsA11y.getPointAnnotationTexts;
  2664. var escapeStringForHTML = HTMLUtilities.escapeStringForHTML, reverseChildNodes = HTMLUtilities.reverseChildNodes, stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  2665. var getAxisDescription = ChartUtilities.getAxisDescription, getSeriesFirstPointElement = ChartUtilities.getSeriesFirstPointElement, getSeriesA11yElement = ChartUtilities.getSeriesA11yElement, unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  2666. /* eslint-disable valid-jsdoc */
  2667. /**
  2668. * @private
  2669. */
  2670. function findFirstPointWithGraphic(point) {
  2671. var sourcePointIndex = point.index;
  2672. if (!point.series || !point.series.data || !defined(sourcePointIndex)) {
  2673. return null;
  2674. }
  2675. return find(point.series.data, function (p) {
  2676. return !!(p &&
  2677. typeof p.index !== 'undefined' &&
  2678. p.index > sourcePointIndex &&
  2679. p.graphic &&
  2680. p.graphic.element);
  2681. }) || null;
  2682. }
  2683. /**
  2684. * @private
  2685. */
  2686. function shouldAddDummyPoint(point) {
  2687. // Note: Sunburst series use isNull for hidden points on drilldown.
  2688. // Ignore these.
  2689. var isSunburst = point.series && point.series.is('sunburst'), isNull = point.isNull;
  2690. return isNull && !isSunburst;
  2691. }
  2692. /**
  2693. * @private
  2694. */
  2695. function makeDummyElement(point, pos) {
  2696. var renderer = point.series.chart.renderer, dummy = renderer.rect(pos.x, pos.y, 1, 1);
  2697. dummy.attr({
  2698. 'class': 'highcharts-a11y-dummy-point',
  2699. fill: 'none',
  2700. opacity: 0,
  2701. 'fill-opacity': 0,
  2702. 'stroke-opacity': 0
  2703. });
  2704. return dummy;
  2705. }
  2706. /**
  2707. * @private
  2708. * @param {Highcharts.Point} point
  2709. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined}
  2710. */
  2711. function addDummyPointElement(point) {
  2712. var series = point.series, firstPointWithGraphic = findFirstPointWithGraphic(point), firstGraphic = firstPointWithGraphic && firstPointWithGraphic.graphic, parentGroup = firstGraphic ?
  2713. firstGraphic.parentGroup :
  2714. series.graph || series.group, dummyPos = firstPointWithGraphic ? {
  2715. x: pick(point.plotX, firstPointWithGraphic.plotX, 0),
  2716. y: pick(point.plotY, firstPointWithGraphic.plotY, 0)
  2717. } : {
  2718. x: pick(point.plotX, 0),
  2719. y: pick(point.plotY, 0)
  2720. }, dummyElement = makeDummyElement(point, dummyPos);
  2721. if (parentGroup && parentGroup.element) {
  2722. point.graphic = dummyElement;
  2723. point.hasDummyGraphic = true;
  2724. dummyElement.add(parentGroup);
  2725. // Move to correct pos in DOM
  2726. parentGroup.element.insertBefore(dummyElement.element, firstGraphic ? firstGraphic.element : null);
  2727. return dummyElement.element;
  2728. }
  2729. }
  2730. /**
  2731. * @private
  2732. * @param {Highcharts.Series} series
  2733. * @return {boolean}
  2734. */
  2735. function hasMorePointsThanDescriptionThreshold(series) {
  2736. var chartA11yOptions = series.chart.options.accessibility, threshold = (chartA11yOptions.series.pointDescriptionEnabledThreshold);
  2737. return !!(threshold !== false &&
  2738. series.points &&
  2739. series.points.length >= threshold);
  2740. }
  2741. /**
  2742. * @private
  2743. * @param {Highcharts.Series} series
  2744. * @return {boolean}
  2745. */
  2746. function shouldSetScreenReaderPropsOnPoints(series) {
  2747. var seriesA11yOptions = series.options.accessibility || {};
  2748. return !hasMorePointsThanDescriptionThreshold(series) &&
  2749. !seriesA11yOptions.exposeAsGroupOnly;
  2750. }
  2751. /**
  2752. * @private
  2753. * @param {Highcharts.Series} series
  2754. * @return {boolean}
  2755. */
  2756. function shouldSetKeyboardNavPropsOnPoints(series) {
  2757. var chartA11yOptions = series.chart.options.accessibility, seriesNavOptions = chartA11yOptions.keyboardNavigation.seriesNavigation;
  2758. return !!(series.points && (series.points.length <
  2759. seriesNavOptions.pointNavigationEnabledThreshold ||
  2760. seriesNavOptions.pointNavigationEnabledThreshold === false));
  2761. }
  2762. /**
  2763. * @private
  2764. * @param {Highcharts.Series} series
  2765. * @return {boolean}
  2766. */
  2767. function shouldDescribeSeriesElement(series) {
  2768. var chart = series.chart, chartOptions = chart.options.chart || {}, chartHas3d = chartOptions.options3d && chartOptions.options3d.enabled, hasMultipleSeries = chart.series.length > 1, describeSingleSeriesOption = chart.options.accessibility.series.describeSingleSeries, exposeAsGroupOnlyOption = (series.options.accessibility || {}).exposeAsGroupOnly, noDescribe3D = chartHas3d && hasMultipleSeries;
  2769. return !noDescribe3D && (hasMultipleSeries || describeSingleSeriesOption ||
  2770. exposeAsGroupOnlyOption || hasMorePointsThanDescriptionThreshold(series));
  2771. }
  2772. /**
  2773. * @private
  2774. * @param {Highcharts.Point} point
  2775. * @param {number} value
  2776. * @return {string}
  2777. */
  2778. function pointNumberToString(point, value) {
  2779. var chart = point.series.chart, a11yPointOptions = chart.options.accessibility.point || {}, tooltipOptions = point.series.tooltipOptions || {}, lang = chart.options.lang;
  2780. if (isNumber(value)) {
  2781. return numberFormat(value, a11yPointOptions.valueDecimals ||
  2782. tooltipOptions.valueDecimals ||
  2783. -1, lang.decimalPoint, lang.accessibility.thousandsSep || lang.thousandsSep);
  2784. }
  2785. return value;
  2786. }
  2787. /**
  2788. * @private
  2789. * @param {Highcharts.Series} series
  2790. * @return {string}
  2791. */
  2792. function getSeriesDescriptionText(series) {
  2793. var seriesA11yOptions = series.options.accessibility || {}, descOpt = seriesA11yOptions.description;
  2794. return descOpt && series.chart.langFormat('accessibility.series.description', {
  2795. description: descOpt,
  2796. series: series
  2797. }) || '';
  2798. }
  2799. /**
  2800. * @private
  2801. * @param {Highcharts.series} series
  2802. * @param {string} axisCollection
  2803. * @return {string}
  2804. */
  2805. function getSeriesAxisDescriptionText(series, axisCollection) {
  2806. var axis = series[axisCollection];
  2807. return series.chart.langFormat('accessibility.series.' + axisCollection + 'Description', {
  2808. name: getAxisDescription(axis),
  2809. series: series
  2810. });
  2811. }
  2812. /**
  2813. * Get accessible time description for a point on a datetime axis.
  2814. *
  2815. * @private
  2816. * @function Highcharts.Point#getTimeDescription
  2817. * @param {Highcharts.Point} point
  2818. * @return {string|undefined}
  2819. * The description as string.
  2820. */
  2821. function getPointA11yTimeDescription(point) {
  2822. var series = point.series, chart = series.chart, a11yOptions = chart.options.accessibility.point || {}, hasDateXAxis = series.xAxis && series.xAxis.dateTime;
  2823. if (hasDateXAxis) {
  2824. var tooltipDateFormat = Tooltip.prototype.getXDateFormat.call({
  2825. getDateFormat: Tooltip.prototype.getDateFormat,
  2826. chart: chart
  2827. }, point, chart.options.tooltip, series.xAxis), dateFormat = a11yOptions.dateFormatter &&
  2828. a11yOptions.dateFormatter(point) ||
  2829. a11yOptions.dateFormat ||
  2830. tooltipDateFormat;
  2831. return chart.time.dateFormat(dateFormat, point.x, void 0);
  2832. }
  2833. }
  2834. /**
  2835. * @private
  2836. * @param {Highcharts.Point} point
  2837. * @return {string}
  2838. */
  2839. function getPointXDescription(point) {
  2840. var timeDesc = getPointA11yTimeDescription(point), xAxis = point.series.xAxis || {}, pointCategory = xAxis.categories && defined(point.category) &&
  2841. ('' + point.category).replace('<br/>', ' '), canUseId = point.id && point.id.indexOf('highcharts-') < 0, fallback = 'x, ' + point.x;
  2842. return point.name || timeDesc || pointCategory ||
  2843. (canUseId ? point.id : fallback);
  2844. }
  2845. /**
  2846. * @private
  2847. * @param {Highcharts.Point} point
  2848. * @param {string} prefix
  2849. * @param {string} suffix
  2850. * @return {string}
  2851. */
  2852. function getPointArrayMapValueDescription(point, prefix, suffix) {
  2853. var pre = prefix || '', suf = suffix || '', keyToValStr = function (key) {
  2854. var num = pointNumberToString(point, pick(point[key], point.options[key]));
  2855. return key + ': ' + pre + num + suf;
  2856. }, pointArrayMap = point.series.pointArrayMap;
  2857. return pointArrayMap.reduce(function (desc, key) {
  2858. return desc + (desc.length ? ', ' : '') + keyToValStr(key);
  2859. }, '');
  2860. }
  2861. /**
  2862. * @private
  2863. * @param {Highcharts.Point} point
  2864. * @return {string}
  2865. */
  2866. function getPointValue(point) {
  2867. var series = point.series, a11yPointOpts = series.chart.options.accessibility.point || {}, tooltipOptions = series.tooltipOptions || {}, valuePrefix = a11yPointOpts.valuePrefix ||
  2868. tooltipOptions.valuePrefix || '', valueSuffix = a11yPointOpts.valueSuffix ||
  2869. tooltipOptions.valueSuffix || '', fallbackKey = (typeof point.value !==
  2870. 'undefined' ?
  2871. 'value' : 'y'), fallbackDesc = pointNumberToString(point, point[fallbackKey]);
  2872. if (point.isNull) {
  2873. return series.chart.langFormat('accessibility.series.nullPointValue', {
  2874. point: point
  2875. });
  2876. }
  2877. if (series.pointArrayMap) {
  2878. return getPointArrayMapValueDescription(point, valuePrefix, valueSuffix);
  2879. }
  2880. return valuePrefix + fallbackDesc + valueSuffix;
  2881. }
  2882. /**
  2883. * Return the description for the annotation(s) connected to a point, or empty
  2884. * string if none.
  2885. *
  2886. * @private
  2887. * @param {Highcharts.Point} point The data point to get the annotation info from.
  2888. * @return {string} Annotation description
  2889. */
  2890. function getPointAnnotationDescription(point) {
  2891. var chart = point.series.chart;
  2892. var langKey = 'accessibility.series.pointAnnotationsDescription';
  2893. var annotations = getPointAnnotationTexts(point);
  2894. var context = { point: point, annotations: annotations };
  2895. return annotations.length ? chart.langFormat(langKey, context) : '';
  2896. }
  2897. /**
  2898. * Return string with information about point.
  2899. * @private
  2900. * @return {string}
  2901. */
  2902. function getPointValueDescription(point) {
  2903. var series = point.series, chart = series.chart, pointValueDescriptionFormat = chart.options.accessibility
  2904. .point.valueDescriptionFormat, showXDescription = pick(series.xAxis &&
  2905. series.xAxis.options.accessibility &&
  2906. series.xAxis.options.accessibility.enabled, !chart.angular), xDesc = showXDescription ? getPointXDescription(point) : '', context = {
  2907. point: point,
  2908. index: defined(point.index) ? (point.index + 1) : '',
  2909. xDescription: xDesc,
  2910. value: getPointValue(point),
  2911. separator: showXDescription ? ', ' : ''
  2912. };
  2913. return format(pointValueDescriptionFormat, context, chart);
  2914. }
  2915. /**
  2916. * Return string with information about point.
  2917. * @private
  2918. * @return {string}
  2919. */
  2920. function defaultPointDescriptionFormatter(point) {
  2921. var series = point.series, chart = series.chart, valText = getPointValueDescription(point), description = point.options && point.options.accessibility &&
  2922. point.options.accessibility.description, userDescText = description ? ' ' + description : '', seriesNameText = chart.series.length > 1 && series.name ?
  2923. ' ' + series.name + '.' : '', annotationsDesc = getPointAnnotationDescription(point), pointAnnotationsText = annotationsDesc ? ' ' + annotationsDesc : '';
  2924. point.accessibility = point.accessibility || {};
  2925. point.accessibility.valueDescription = valText;
  2926. return valText + userDescText + seriesNameText + pointAnnotationsText;
  2927. }
  2928. /**
  2929. * Set a11y props on a point element
  2930. * @private
  2931. * @param {Highcharts.Point} point
  2932. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} pointElement
  2933. */
  2934. function setPointScreenReaderAttribs(point, pointElement) {
  2935. var series = point.series, a11yPointOptions = series.chart.options.accessibility.point || {}, seriesA11yOptions = series.options.accessibility || {}, label = escapeStringForHTML(stripHTMLTags(seriesA11yOptions.pointDescriptionFormatter &&
  2936. seriesA11yOptions.pointDescriptionFormatter(point) ||
  2937. a11yPointOptions.descriptionFormatter &&
  2938. a11yPointOptions.descriptionFormatter(point) ||
  2939. defaultPointDescriptionFormatter(point)));
  2940. pointElement.setAttribute('role', 'img');
  2941. pointElement.setAttribute('aria-label', label);
  2942. }
  2943. /**
  2944. * Add accessible info to individual point elements of a series
  2945. * @private
  2946. * @param {Highcharts.Series} series
  2947. */
  2948. function describePointsInSeries(series) {
  2949. var setScreenReaderProps = shouldSetScreenReaderPropsOnPoints(series), setKeyboardProps = shouldSetKeyboardNavPropsOnPoints(series);
  2950. if (setScreenReaderProps || setKeyboardProps) {
  2951. series.points.forEach(function (point) {
  2952. var pointEl = point.graphic && point.graphic.element ||
  2953. shouldAddDummyPoint(point) && addDummyPointElement(point);
  2954. if (pointEl) {
  2955. // We always set tabindex, as long as we are setting props.
  2956. // When setting tabindex, also remove default outline to
  2957. // avoid ugly border on click.
  2958. pointEl.setAttribute('tabindex', '-1');
  2959. pointEl.style.outline = '0';
  2960. if (setScreenReaderProps) {
  2961. setPointScreenReaderAttribs(point, pointEl);
  2962. }
  2963. else {
  2964. pointEl.setAttribute('aria-hidden', true);
  2965. }
  2966. }
  2967. });
  2968. }
  2969. }
  2970. /**
  2971. * Return string with information about series.
  2972. * @private
  2973. * @return {string}
  2974. */
  2975. function defaultSeriesDescriptionFormatter(series) {
  2976. var chart = series.chart, chartTypes = chart.types || [], description = getSeriesDescriptionText(series), shouldDescribeAxis = function (coll) {
  2977. return chart[coll] && chart[coll].length > 1 && series[coll];
  2978. }, xAxisInfo = getSeriesAxisDescriptionText(series, 'xAxis'), yAxisInfo = getSeriesAxisDescriptionText(series, 'yAxis'), summaryContext = {
  2979. name: series.name || '',
  2980. ix: series.index + 1,
  2981. numSeries: chart.series && chart.series.length,
  2982. numPoints: series.points && series.points.length,
  2983. series: series
  2984. }, combinationSuffix = chartTypes.length > 1 ? 'Combination' : '', summary = chart.langFormat('accessibility.series.summary.' + series.type + combinationSuffix, summaryContext) || chart.langFormat('accessibility.series.summary.default' + combinationSuffix, summaryContext);
  2985. return summary + (description ? ' ' + description : '') + (shouldDescribeAxis('yAxis') ? ' ' + yAxisInfo : '') + (shouldDescribeAxis('xAxis') ? ' ' + xAxisInfo : '');
  2986. }
  2987. /**
  2988. * Set a11y props on a series element
  2989. * @private
  2990. * @param {Highcharts.Series} series
  2991. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} seriesElement
  2992. */
  2993. function describeSeriesElement(series, seriesElement) {
  2994. var seriesA11yOptions = series.options.accessibility || {}, a11yOptions = series.chart.options.accessibility, landmarkVerbosity = a11yOptions.landmarkVerbosity;
  2995. // Handle role attribute
  2996. if (seriesA11yOptions.exposeAsGroupOnly) {
  2997. seriesElement.setAttribute('role', 'img');
  2998. }
  2999. else if (landmarkVerbosity === 'all') {
  3000. seriesElement.setAttribute('role', 'region');
  3001. } /* else do not add role */
  3002. seriesElement.setAttribute('tabindex', '-1');
  3003. seriesElement.style.outline = '0'; // Don't show browser outline on click, despite tabindex
  3004. seriesElement.setAttribute('aria-label', escapeStringForHTML(stripHTMLTags(a11yOptions.series.descriptionFormatter &&
  3005. a11yOptions.series.descriptionFormatter(series) ||
  3006. defaultSeriesDescriptionFormatter(series))));
  3007. }
  3008. /**
  3009. * Put accessible info on series and points of a series.
  3010. * @param {Highcharts.Series} series The series to add info on.
  3011. */
  3012. function describeSeries(series) {
  3013. var chart = series.chart, firstPointEl = getSeriesFirstPointElement(series), seriesEl = getSeriesA11yElement(series), is3d = chart.is3d && chart.is3d();
  3014. if (seriesEl) {
  3015. // For some series types the order of elements do not match the
  3016. // order of points in series. In that case we have to reverse them
  3017. // in order for AT to read them out in an understandable order.
  3018. // Due to z-index issues we can not do this for 3D charts.
  3019. if (seriesEl.lastChild === firstPointEl && !is3d) {
  3020. reverseChildNodes(seriesEl);
  3021. }
  3022. describePointsInSeries(series);
  3023. unhideChartElementFromAT(chart, seriesEl);
  3024. if (shouldDescribeSeriesElement(series)) {
  3025. describeSeriesElement(series, seriesEl);
  3026. }
  3027. else {
  3028. seriesEl.setAttribute('aria-label', '');
  3029. }
  3030. }
  3031. }
  3032. var SeriesDescriber = {
  3033. describeSeries: describeSeries,
  3034. defaultPointDescriptionFormatter: defaultPointDescriptionFormatter,
  3035. defaultSeriesDescriptionFormatter: defaultSeriesDescriptionFormatter,
  3036. getPointA11yTimeDescription: getPointA11yTimeDescription,
  3037. getPointXDescription: getPointXDescription,
  3038. getPointValue: getPointValue,
  3039. getPointValueDescription: getPointValueDescription
  3040. };
  3041. return SeriesDescriber;
  3042. });
  3043. _registerModule(_modules, 'modules/accessibility/utils/Announcer.js', [_modules['parts/Globals.js'], _modules['modules/accessibility/utils/DOMElementProvider.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, DOMElementProvider, HTMLUtilities) {
  3044. /* *
  3045. *
  3046. * (c) 2009-2020 Øystein Moseng
  3047. *
  3048. * Create announcer to speak messages to screen readers and other AT.
  3049. *
  3050. * License: www.highcharts.com/license
  3051. *
  3052. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3053. *
  3054. * */
  3055. var visuallyHideElement = HTMLUtilities.visuallyHideElement;
  3056. var Announcer = /** @class */ (function () {
  3057. function Announcer(chart, type) {
  3058. this.chart = chart;
  3059. this.domElementProvider = new DOMElementProvider();
  3060. this.announceRegion = this.addAnnounceRegion(type);
  3061. }
  3062. Announcer.prototype.destroy = function () {
  3063. this.domElementProvider.destroyCreatedElements();
  3064. };
  3065. Announcer.prototype.announce = function (message) {
  3066. var _this = this;
  3067. this.announceRegion.innerHTML = message;
  3068. // Delete contents after a little while to avoid user finding the live
  3069. // region in the DOM.
  3070. if (this.clearAnnouncementRegionTimer) {
  3071. clearTimeout(this.clearAnnouncementRegionTimer);
  3072. }
  3073. this.clearAnnouncementRegionTimer = setTimeout(function () {
  3074. _this.announceRegion.innerHTML = '';
  3075. delete _this.clearAnnouncementRegionTimer;
  3076. }, 1000);
  3077. };
  3078. Announcer.prototype.addAnnounceRegion = function (type) {
  3079. var chartContainer = this.chart.renderTo;
  3080. var div = this.domElementProvider.createElement('div');
  3081. div.setAttribute('aria-hidden', false);
  3082. div.setAttribute('aria-live', type);
  3083. visuallyHideElement(div);
  3084. chartContainer.insertBefore(div, chartContainer.firstChild);
  3085. return div;
  3086. };
  3087. return Announcer;
  3088. }());
  3089. H.Announcer = Announcer;
  3090. return Announcer;
  3091. });
  3092. _registerModule(_modules, 'modules/accessibility/components/SeriesComponent/NewDataAnnouncer.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/components/SeriesComponent/SeriesDescriber.js'], _modules['modules/accessibility/utils/Announcer.js'], _modules['modules/accessibility/utils/EventProvider.js']], function (H, U, ChartUtilities, SeriesDescriber, Announcer, EventProvider) {
  3093. /* *
  3094. *
  3095. * (c) 2009-2020 Øystein Moseng
  3096. *
  3097. * Handle announcing new data for a chart.
  3098. *
  3099. * License: www.highcharts.com/license
  3100. *
  3101. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3102. *
  3103. * */
  3104. var extend = U.extend, defined = U.defined;
  3105. var getChartTitle = ChartUtilities.getChartTitle;
  3106. var defaultPointDescriptionFormatter = SeriesDescriber
  3107. .defaultPointDescriptionFormatter, defaultSeriesDescriptionFormatter = SeriesDescriber
  3108. .defaultSeriesDescriptionFormatter;
  3109. /* eslint-disable no-invalid-this, valid-jsdoc */
  3110. /**
  3111. * @private
  3112. */
  3113. function chartHasAnnounceEnabled(chart) {
  3114. return !!chart.options.accessibility.announceNewData.enabled;
  3115. }
  3116. /**
  3117. * @private
  3118. */
  3119. function findPointInDataArray(point) {
  3120. var candidates = point.series.data.filter(function (candidate) {
  3121. return point.x === candidate.x && point.y === candidate.y;
  3122. });
  3123. return candidates.length === 1 ? candidates[0] : point;
  3124. }
  3125. /**
  3126. * Get array of unique series from two arrays
  3127. * @private
  3128. */
  3129. function getUniqueSeries(arrayA, arrayB) {
  3130. var uniqueSeries = (arrayA || []).concat(arrayB || [])
  3131. .reduce(function (acc, cur) {
  3132. acc[cur.name + cur.index] = cur;
  3133. return acc;
  3134. }, {});
  3135. return Object.keys(uniqueSeries).map(function (ix) {
  3136. return uniqueSeries[ix];
  3137. });
  3138. }
  3139. /**
  3140. * @private
  3141. * @class
  3142. */
  3143. var NewDataAnnouncer = function (chart) {
  3144. this.chart = chart;
  3145. };
  3146. extend(NewDataAnnouncer.prototype, {
  3147. /**
  3148. * Initialize the new data announcer.
  3149. * @private
  3150. */
  3151. init: function () {
  3152. var chart = this.chart;
  3153. var announceOptions = chart.options.accessibility.announceNewData;
  3154. var announceType = announceOptions.interruptUser ? 'assertive' : 'polite';
  3155. this.lastAnnouncementTime = 0;
  3156. this.dirty = {
  3157. allSeries: {}
  3158. };
  3159. this.eventProvider = new EventProvider();
  3160. this.announcer = new Announcer(chart, announceType);
  3161. this.addEventListeners();
  3162. },
  3163. /**
  3164. * Remove traces of announcer.
  3165. * @private
  3166. */
  3167. destroy: function () {
  3168. this.eventProvider.removeAddedEvents();
  3169. this.announcer.destroy();
  3170. },
  3171. /**
  3172. * Add event listeners for the announcer
  3173. * @private
  3174. */
  3175. addEventListeners: function () {
  3176. var announcer = this, chart = this.chart, e = this.eventProvider;
  3177. e.addEvent(chart, 'afterDrilldown', function () {
  3178. announcer.lastAnnouncementTime = 0;
  3179. });
  3180. e.addEvent(H.Series, 'updatedData', function () {
  3181. announcer.onSeriesUpdatedData(this);
  3182. });
  3183. e.addEvent(chart, 'afterAddSeries', function (e) {
  3184. announcer.onSeriesAdded(e.series);
  3185. });
  3186. e.addEvent(H.Series, 'addPoint', function (e) {
  3187. announcer.onPointAdded(e.point);
  3188. });
  3189. e.addEvent(chart, 'redraw', function () {
  3190. announcer.announceDirtyData();
  3191. });
  3192. },
  3193. /**
  3194. * On new data in the series, make sure we add it to the dirty list.
  3195. * @private
  3196. * @param {Highcharts.Series} series
  3197. */
  3198. onSeriesUpdatedData: function (series) {
  3199. var chart = this.chart;
  3200. if (series.chart === chart && chartHasAnnounceEnabled(chart)) {
  3201. this.dirty.hasDirty = true;
  3202. this.dirty.allSeries[series.name + series.index] = series;
  3203. }
  3204. },
  3205. /**
  3206. * On new data series added, update dirty list.
  3207. * @private
  3208. * @param {Highcharts.Series} series
  3209. */
  3210. onSeriesAdded: function (series) {
  3211. if (chartHasAnnounceEnabled(this.chart)) {
  3212. this.dirty.hasDirty = true;
  3213. this.dirty.allSeries[series.name + series.index] = series;
  3214. // Add it to newSeries storage unless we already have one
  3215. this.dirty.newSeries = defined(this.dirty.newSeries) ?
  3216. void 0 : series;
  3217. }
  3218. },
  3219. /**
  3220. * On new point added, update dirty list.
  3221. * @private
  3222. * @param {Highcharts.Point} point
  3223. */
  3224. onPointAdded: function (point) {
  3225. var chart = point.series.chart;
  3226. if (this.chart === chart && chartHasAnnounceEnabled(chart)) {
  3227. // Add it to newPoint storage unless we already have one
  3228. this.dirty.newPoint = defined(this.dirty.newPoint) ?
  3229. void 0 : point;
  3230. }
  3231. },
  3232. /**
  3233. * Gather what we know and announce the data to user.
  3234. * @private
  3235. */
  3236. announceDirtyData: function () {
  3237. var chart = this.chart, announcer = this;
  3238. if (chart.options.accessibility.announceNewData &&
  3239. this.dirty.hasDirty) {
  3240. var newPoint = this.dirty.newPoint;
  3241. // If we have a single new point, see if we can find it in the
  3242. // data array. Otherwise we can only pass through options to
  3243. // the description builder, and it is a bit sparse in info.
  3244. if (newPoint) {
  3245. newPoint = findPointInDataArray(newPoint);
  3246. }
  3247. this.queueAnnouncement(Object.keys(this.dirty.allSeries).map(function (ix) {
  3248. return announcer.dirty.allSeries[ix];
  3249. }), this.dirty.newSeries, newPoint);
  3250. // Reset
  3251. this.dirty = {
  3252. allSeries: {}
  3253. };
  3254. }
  3255. },
  3256. /**
  3257. * Announce to user that there is new data.
  3258. * @private
  3259. * @param {Array<Highcharts.Series>} dirtySeries
  3260. * Array of series with new data.
  3261. * @param {Highcharts.Series} [newSeries]
  3262. * If a single new series was added, a reference to this series.
  3263. * @param {Highcharts.Point} [newPoint]
  3264. * If a single point was added, a reference to this point.
  3265. */
  3266. queueAnnouncement: function (dirtySeries, newSeries, newPoint) {
  3267. var _this = this;
  3268. var chart = this.chart;
  3269. var annOptions = chart.options.accessibility.announceNewData;
  3270. if (annOptions.enabled) {
  3271. var now = +new Date();
  3272. var dTime = now - this.lastAnnouncementTime;
  3273. var time = Math.max(0, annOptions.minAnnounceInterval - dTime);
  3274. // Add series from previously queued announcement.
  3275. var allSeries = getUniqueSeries(this.queuedAnnouncement && this.queuedAnnouncement.series, dirtySeries);
  3276. // Build message and announce
  3277. var message = this.buildAnnouncementMessage(allSeries, newSeries, newPoint);
  3278. if (message) {
  3279. // Is there already one queued?
  3280. if (this.queuedAnnouncement) {
  3281. clearTimeout(this.queuedAnnouncementTimer);
  3282. }
  3283. // Build the announcement
  3284. this.queuedAnnouncement = {
  3285. time: now,
  3286. message: message,
  3287. series: allSeries
  3288. };
  3289. // Queue the announcement
  3290. this.queuedAnnouncementTimer = setTimeout(function () {
  3291. if (_this && _this.announcer) {
  3292. _this.lastAnnouncementTime = +new Date();
  3293. _this.announcer.announce(_this.queuedAnnouncement.message);
  3294. delete _this.queuedAnnouncement;
  3295. delete _this.queuedAnnouncementTimer;
  3296. }
  3297. }, time);
  3298. }
  3299. }
  3300. },
  3301. /**
  3302. * Get announcement message for new data.
  3303. * @private
  3304. * @param {Array<Highcharts.Series>} dirtySeries
  3305. * Array of series with new data.
  3306. * @param {Highcharts.Series} [newSeries]
  3307. * If a single new series was added, a reference to this series.
  3308. * @param {Highcharts.Point} [newPoint]
  3309. * If a single point was added, a reference to this point.
  3310. *
  3311. * @return {string|null}
  3312. * The announcement message to give to user.
  3313. */
  3314. buildAnnouncementMessage: function (dirtySeries, newSeries, newPoint) {
  3315. var chart = this.chart, annOptions = chart.options.accessibility.announceNewData;
  3316. // User supplied formatter?
  3317. if (annOptions.announcementFormatter) {
  3318. var formatterRes = annOptions.announcementFormatter(dirtySeries, newSeries, newPoint);
  3319. if (formatterRes !== false) {
  3320. return formatterRes.length ? formatterRes : null;
  3321. }
  3322. }
  3323. // Default formatter - use lang options
  3324. var multiple = H.charts && H.charts.length > 1 ? 'Multiple' : 'Single', langKey = newSeries ? 'newSeriesAnnounce' + multiple :
  3325. newPoint ? 'newPointAnnounce' + multiple : 'newDataAnnounce', chartTitle = getChartTitle(chart);
  3326. return chart.langFormat('accessibility.announceNewData.' + langKey, {
  3327. chartTitle: chartTitle,
  3328. seriesDesc: newSeries ?
  3329. defaultSeriesDescriptionFormatter(newSeries) :
  3330. null,
  3331. pointDesc: newPoint ?
  3332. defaultPointDescriptionFormatter(newPoint) :
  3333. null,
  3334. point: newPoint,
  3335. series: newSeries
  3336. });
  3337. }
  3338. });
  3339. return NewDataAnnouncer;
  3340. });
  3341. _registerModule(_modules, 'modules/accessibility/components/SeriesComponent/forcedMarkers.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  3342. /* *
  3343. *
  3344. * (c) 2009-2020 Øystein Moseng
  3345. *
  3346. * Handle forcing series markers.
  3347. *
  3348. * License: www.highcharts.com/license
  3349. *
  3350. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3351. *
  3352. * */
  3353. var addEvent = U.addEvent, merge = U.merge;
  3354. /* eslint-disable no-invalid-this, valid-jsdoc */
  3355. /**
  3356. * @private
  3357. */
  3358. function isWithinDescriptionThreshold(series) {
  3359. var a11yOptions = series.chart.options.accessibility;
  3360. return series.points.length <
  3361. a11yOptions.series.pointDescriptionEnabledThreshold ||
  3362. a11yOptions.series.pointDescriptionEnabledThreshold === false;
  3363. }
  3364. /**
  3365. * @private
  3366. */
  3367. function shouldForceMarkers(series) {
  3368. var chart = series.chart, chartA11yEnabled = chart.options.accessibility.enabled, seriesA11yEnabled = (series.options.accessibility &&
  3369. series.options.accessibility.enabled) !== false;
  3370. return chartA11yEnabled && seriesA11yEnabled && isWithinDescriptionThreshold(series);
  3371. }
  3372. /**
  3373. * @private
  3374. */
  3375. function hasIndividualPointMarkerOptions(series) {
  3376. return !!(series._hasPointMarkers && series.points && series.points.length);
  3377. }
  3378. /**
  3379. * @private
  3380. */
  3381. function unforceSeriesMarkerOptions(series) {
  3382. var resetMarkerOptions = series.resetA11yMarkerOptions;
  3383. if (resetMarkerOptions) {
  3384. merge(true, series.options, {
  3385. marker: {
  3386. enabled: resetMarkerOptions.enabled,
  3387. states: {
  3388. normal: {
  3389. opacity: resetMarkerOptions.states &&
  3390. resetMarkerOptions.states.normal &&
  3391. resetMarkerOptions.states.normal.opacity
  3392. }
  3393. }
  3394. }
  3395. });
  3396. }
  3397. }
  3398. /**
  3399. * @private
  3400. */
  3401. function forceZeroOpacityMarkerOptions(options) {
  3402. merge(true, options, {
  3403. marker: {
  3404. enabled: true,
  3405. states: {
  3406. normal: {
  3407. opacity: 0
  3408. }
  3409. }
  3410. }
  3411. });
  3412. }
  3413. /**
  3414. * @private
  3415. */
  3416. function getPointMarkerOpacity(pointOptions) {
  3417. return pointOptions.marker.states &&
  3418. pointOptions.marker.states.normal &&
  3419. pointOptions.marker.states.normal.opacity || 1;
  3420. }
  3421. /**
  3422. * @private
  3423. */
  3424. function unforcePointMarkerOptions(pointOptions) {
  3425. merge(true, pointOptions.marker, {
  3426. states: {
  3427. normal: {
  3428. opacity: getPointMarkerOpacity(pointOptions)
  3429. }
  3430. }
  3431. });
  3432. }
  3433. /**
  3434. * @private
  3435. */
  3436. function handleForcePointMarkers(series) {
  3437. var i = series.points.length;
  3438. while (i--) {
  3439. var point = series.points[i];
  3440. var pointOptions = point.options;
  3441. delete point.hasForcedA11yMarker;
  3442. if (pointOptions.marker) {
  3443. if (pointOptions.marker.enabled) {
  3444. unforcePointMarkerOptions(pointOptions);
  3445. point.hasForcedA11yMarker = false;
  3446. }
  3447. else {
  3448. forceZeroOpacityMarkerOptions(pointOptions);
  3449. point.hasForcedA11yMarker = true;
  3450. }
  3451. }
  3452. }
  3453. }
  3454. /**
  3455. * @private
  3456. */
  3457. function addForceMarkersEvents() {
  3458. /**
  3459. * Keep track of forcing markers.
  3460. * @private
  3461. */
  3462. addEvent(H.Series, 'render', function () {
  3463. var series = this, options = series.options;
  3464. if (shouldForceMarkers(series)) {
  3465. if (options.marker && options.marker.enabled === false) {
  3466. series.a11yMarkersForced = true;
  3467. forceZeroOpacityMarkerOptions(series.options);
  3468. }
  3469. if (hasIndividualPointMarkerOptions(series)) {
  3470. handleForcePointMarkers(series);
  3471. }
  3472. }
  3473. else if (series.a11yMarkersForced) {
  3474. delete series.a11yMarkersForced;
  3475. unforceSeriesMarkerOptions(series);
  3476. }
  3477. });
  3478. /**
  3479. * Keep track of options to reset markers to if no longer forced.
  3480. * @private
  3481. */
  3482. addEvent(H.Series, 'afterSetOptions', function (e) {
  3483. this.resetA11yMarkerOptions = merge(e.options.marker || {}, this.userOptions.marker || {});
  3484. });
  3485. /**
  3486. * Process marker graphics after render
  3487. * @private
  3488. */
  3489. addEvent(H.Series, 'afterRender', function () {
  3490. var series = this;
  3491. // For styled mode the rendered graphic does not reflect the style
  3492. // options, and we need to add/remove classes to achieve the same.
  3493. if (series.chart.styledMode) {
  3494. if (series.markerGroup) {
  3495. series.markerGroup[series.a11yMarkersForced ? 'addClass' : 'removeClass']('highcharts-a11y-markers-hidden');
  3496. }
  3497. // Do we need to handle individual points?
  3498. if (hasIndividualPointMarkerOptions(series)) {
  3499. series.points.forEach(function (point) {
  3500. if (point.graphic) {
  3501. point.graphic[point.hasForcedA11yMarker ? 'addClass' : 'removeClass']('highcharts-a11y-marker-hidden');
  3502. point.graphic[point.hasForcedA11yMarker === false ? 'addClass' : 'removeClass']('highcharts-a11y-marker-visible');
  3503. }
  3504. });
  3505. }
  3506. }
  3507. });
  3508. }
  3509. return addForceMarkersEvents;
  3510. });
  3511. _registerModule(_modules, 'modules/accessibility/components/SeriesComponent/SeriesComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/components/SeriesComponent/SeriesKeyboardNavigation.js'], _modules['modules/accessibility/components/SeriesComponent/NewDataAnnouncer.js'], _modules['modules/accessibility/components/SeriesComponent/forcedMarkers.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/components/SeriesComponent/SeriesDescriber.js'], _modules['parts/Tooltip.js']], function (H, U, AccessibilityComponent, SeriesKeyboardNavigation, NewDataAnnouncer, addForceMarkersEvents, ChartUtilities, SeriesDescriber, Tooltip) {
  3512. /* *
  3513. *
  3514. * (c) 2009-2020 Øystein Moseng
  3515. *
  3516. * Accessibility component for series and points.
  3517. *
  3518. * License: www.highcharts.com/license
  3519. *
  3520. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3521. *
  3522. * */
  3523. var extend = U.extend;
  3524. var hideSeriesFromAT = ChartUtilities.hideSeriesFromAT;
  3525. var describeSeries = SeriesDescriber.describeSeries;
  3526. // Expose functionality to users
  3527. H.SeriesAccessibilityDescriber = SeriesDescriber;
  3528. // Handle forcing markers
  3529. addForceMarkersEvents();
  3530. /* eslint-disable no-invalid-this, valid-jsdoc */
  3531. /**
  3532. * The SeriesComponent class
  3533. *
  3534. * @private
  3535. * @class
  3536. * @name Highcharts.SeriesComponent
  3537. */
  3538. var SeriesComponent = function () { };
  3539. SeriesComponent.prototype = new AccessibilityComponent();
  3540. extend(SeriesComponent.prototype, /** @lends Highcharts.SeriesComponent */ {
  3541. /**
  3542. * Init the component.
  3543. */
  3544. init: function () {
  3545. this.newDataAnnouncer = new NewDataAnnouncer(this.chart);
  3546. this.newDataAnnouncer.init();
  3547. this.keyboardNavigation = new SeriesKeyboardNavigation(this.chart, this.keyCodes);
  3548. this.keyboardNavigation.init();
  3549. this.hideTooltipFromATWhenShown();
  3550. this.hideSeriesLabelsFromATWhenShown();
  3551. },
  3552. /**
  3553. * @private
  3554. */
  3555. hideTooltipFromATWhenShown: function () {
  3556. var component = this;
  3557. this.addEvent(Tooltip, 'refresh', function () {
  3558. if (this.chart === component.chart &&
  3559. this.label &&
  3560. this.label.element) {
  3561. this.label.element.setAttribute('aria-hidden', true);
  3562. }
  3563. });
  3564. },
  3565. /**
  3566. * @private
  3567. */
  3568. hideSeriesLabelsFromATWhenShown: function () {
  3569. this.addEvent(this.chart, 'afterDrawSeriesLabels', function () {
  3570. this.series.forEach(function (series) {
  3571. if (series.labelBySeries) {
  3572. series.labelBySeries.attr('aria-hidden', true);
  3573. }
  3574. });
  3575. });
  3576. },
  3577. /**
  3578. * Called on chart render. It is necessary to do this for render in case
  3579. * markers change on zoom/pixel density.
  3580. */
  3581. onChartRender: function () {
  3582. var chart = this.chart;
  3583. chart.series.forEach(function (series) {
  3584. var shouldDescribeSeries = (series.options.accessibility &&
  3585. series.options.accessibility.enabled) !== false &&
  3586. series.visible;
  3587. if (shouldDescribeSeries) {
  3588. describeSeries(series);
  3589. }
  3590. else {
  3591. hideSeriesFromAT(series);
  3592. }
  3593. });
  3594. },
  3595. /**
  3596. * Get keyboard navigation handler for this component.
  3597. * @return {Highcharts.KeyboardNavigationHandler}
  3598. */
  3599. getKeyboardNavigation: function () {
  3600. return this.keyboardNavigation.getKeyboardNavigationHandler();
  3601. },
  3602. /**
  3603. * Remove traces
  3604. */
  3605. destroy: function () {
  3606. this.newDataAnnouncer.destroy();
  3607. this.keyboardNavigation.destroy();
  3608. }
  3609. });
  3610. return SeriesComponent;
  3611. });
  3612. _registerModule(_modules, 'modules/accessibility/components/ZoomComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/KeyboardNavigationHandler.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, U, AccessibilityComponent, KeyboardNavigationHandler, ChartUtilities, HTMLUtilities) {
  3613. /* *
  3614. *
  3615. * (c) 2009-2020 Øystein Moseng
  3616. *
  3617. * Accessibility component for chart zoom.
  3618. *
  3619. * License: www.highcharts.com/license
  3620. *
  3621. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3622. *
  3623. * */
  3624. var extend = U.extend, pick = U.pick;
  3625. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  3626. var setElAttrs = HTMLUtilities.setElAttrs, removeElement = HTMLUtilities.removeElement;
  3627. /* eslint-disable no-invalid-this, valid-jsdoc */
  3628. /**
  3629. * @private
  3630. */
  3631. function chartHasMapZoom(chart) {
  3632. return !!(chart.mapZoom &&
  3633. chart.mapNavButtons &&
  3634. chart.mapNavButtons.length);
  3635. }
  3636. /**
  3637. * Pan along axis in a direction (1 or -1), optionally with a defined
  3638. * granularity (number of steps it takes to walk across current view)
  3639. *
  3640. * @private
  3641. * @function Highcharts.Axis#panStep
  3642. *
  3643. * @param {number} direction
  3644. * @param {number} [granularity]
  3645. */
  3646. H.Axis.prototype.panStep = function (direction, granularity) {
  3647. var gran = granularity || 3, extremes = this.getExtremes(), step = (extremes.max - extremes.min) / gran * direction, newMax = extremes.max + step, newMin = extremes.min + step, size = newMax - newMin;
  3648. if (direction < 0 && newMin < extremes.dataMin) {
  3649. newMin = extremes.dataMin;
  3650. newMax = newMin + size;
  3651. }
  3652. else if (direction > 0 && newMax > extremes.dataMax) {
  3653. newMax = extremes.dataMax;
  3654. newMin = newMax - size;
  3655. }
  3656. this.setExtremes(newMin, newMax);
  3657. };
  3658. /**
  3659. * The ZoomComponent class
  3660. *
  3661. * @private
  3662. * @class
  3663. * @name Highcharts.ZoomComponent
  3664. */
  3665. var ZoomComponent = function () { };
  3666. ZoomComponent.prototype = new AccessibilityComponent();
  3667. extend(ZoomComponent.prototype, /** @lends Highcharts.ZoomComponent */ {
  3668. /**
  3669. * Initialize the component
  3670. */
  3671. init: function () {
  3672. var component = this, chart = this.chart;
  3673. [
  3674. 'afterShowResetZoom', 'afterDrilldown', 'drillupall'
  3675. ].forEach(function (eventType) {
  3676. component.addEvent(chart, eventType, function () {
  3677. component.updateProxyOverlays();
  3678. });
  3679. });
  3680. },
  3681. /**
  3682. * Called when chart is updated
  3683. */
  3684. onChartUpdate: function () {
  3685. var chart = this.chart, component = this;
  3686. // Make map zoom buttons accessible
  3687. if (chart.mapNavButtons) {
  3688. chart.mapNavButtons.forEach(function (button, i) {
  3689. unhideChartElementFromAT(chart, button.element);
  3690. component.setMapNavButtonAttrs(button.element, 'accessibility.zoom.mapZoom' + (i ? 'Out' : 'In'));
  3691. });
  3692. }
  3693. },
  3694. /**
  3695. * @private
  3696. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} button
  3697. * @param {string} labelFormatKey
  3698. */
  3699. setMapNavButtonAttrs: function (button, labelFormatKey) {
  3700. var chart = this.chart, label = chart.langFormat(labelFormatKey, { chart: chart });
  3701. setElAttrs(button, {
  3702. tabindex: -1,
  3703. role: 'button',
  3704. 'aria-label': label
  3705. });
  3706. },
  3707. /**
  3708. * Update the proxy overlays on every new render to ensure positions are
  3709. * correct.
  3710. */
  3711. onChartRender: function () {
  3712. this.updateProxyOverlays();
  3713. },
  3714. /**
  3715. * Update proxy overlays, recreating the buttons.
  3716. */
  3717. updateProxyOverlays: function () {
  3718. var chart = this.chart;
  3719. // Always start with a clean slate
  3720. removeElement(this.drillUpProxyGroup);
  3721. removeElement(this.resetZoomProxyGroup);
  3722. if (chart.resetZoomButton) {
  3723. this.recreateProxyButtonAndGroup(chart.resetZoomButton, 'resetZoomProxyButton', 'resetZoomProxyGroup', chart.langFormat('accessibility.zoom.resetZoomButton', { chart: chart }));
  3724. }
  3725. if (chart.drillUpButton) {
  3726. this.recreateProxyButtonAndGroup(chart.drillUpButton, 'drillUpProxyButton', 'drillUpProxyGroup', chart.langFormat('accessibility.drillUpButton', {
  3727. chart: chart,
  3728. buttonText: chart.getDrilldownBackText()
  3729. }));
  3730. }
  3731. },
  3732. /**
  3733. * @private
  3734. * @param {Highcharts.SVGElement} buttonEl
  3735. * @param {string} buttonProp
  3736. * @param {string} groupProp
  3737. * @param {string} label
  3738. */
  3739. recreateProxyButtonAndGroup: function (buttonEl, buttonProp, groupProp, label) {
  3740. removeElement(this[groupProp]);
  3741. this[groupProp] = this.addProxyGroup();
  3742. this[buttonProp] = this.createProxyButton(buttonEl, this[groupProp], { 'aria-label': label, tabindex: -1 });
  3743. },
  3744. /**
  3745. * Get keyboard navigation handler for map zoom.
  3746. * @private
  3747. * @return {Highcharts.KeyboardNavigationHandler} The module object
  3748. */
  3749. getMapZoomNavigation: function () {
  3750. var keys = this.keyCodes, chart = this.chart, component = this;
  3751. return new KeyboardNavigationHandler(chart, {
  3752. keyCodeMap: [
  3753. [
  3754. [keys.up, keys.down, keys.left, keys.right],
  3755. function (keyCode) {
  3756. return component.onMapKbdArrow(this, keyCode);
  3757. }
  3758. ],
  3759. [
  3760. [keys.tab],
  3761. function (_keyCode, e) {
  3762. return component.onMapKbdTab(this, e);
  3763. }
  3764. ],
  3765. [
  3766. [keys.space, keys.enter],
  3767. function () {
  3768. return component.onMapKbdClick(this);
  3769. }
  3770. ]
  3771. ],
  3772. validate: function () {
  3773. return chartHasMapZoom(chart);
  3774. },
  3775. init: function (direction) {
  3776. return component.onMapNavInit(direction);
  3777. }
  3778. });
  3779. },
  3780. /**
  3781. * @private
  3782. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  3783. * @param {number} keyCode
  3784. * @return {number} Response code
  3785. */
  3786. onMapKbdArrow: function (keyboardNavigationHandler, keyCode) {
  3787. var keys = this.keyCodes, panAxis = (keyCode === keys.up || keyCode === keys.down) ?
  3788. 'yAxis' : 'xAxis', stepDirection = (keyCode === keys.left || keyCode === keys.up) ?
  3789. -1 : 1;
  3790. this.chart[panAxis][0].panStep(stepDirection);
  3791. return keyboardNavigationHandler.response.success;
  3792. },
  3793. /**
  3794. * @private
  3795. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  3796. * @param {global.KeyboardEvent} event
  3797. * @return {number} Response code
  3798. */
  3799. onMapKbdTab: function (keyboardNavigationHandler, event) {
  3800. var button, chart = this.chart, response = keyboardNavigationHandler.response, isBackwards = event.shiftKey, isMoveOutOfRange = isBackwards && !this.focusedMapNavButtonIx ||
  3801. !isBackwards && this.focusedMapNavButtonIx;
  3802. // Deselect old
  3803. chart.mapNavButtons[this.focusedMapNavButtonIx].setState(0);
  3804. if (isMoveOutOfRange) {
  3805. chart.mapZoom(); // Reset zoom
  3806. return response[isBackwards ? 'prev' : 'next'];
  3807. }
  3808. // Select other button
  3809. this.focusedMapNavButtonIx += isBackwards ? -1 : 1;
  3810. button = chart.mapNavButtons[this.focusedMapNavButtonIx];
  3811. chart.setFocusToElement(button.box, button.element);
  3812. button.setState(2);
  3813. return response.success;
  3814. },
  3815. /**
  3816. * @private
  3817. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  3818. * @return {number} Response code
  3819. */
  3820. onMapKbdClick: function (keyboardNavigationHandler) {
  3821. this.fakeClickEvent(this.chart.mapNavButtons[this.focusedMapNavButtonIx]
  3822. .element);
  3823. return keyboardNavigationHandler.response.success;
  3824. },
  3825. /**
  3826. * @private
  3827. * @param {number} direction
  3828. */
  3829. onMapNavInit: function (direction) {
  3830. var chart = this.chart, zoomIn = chart.mapNavButtons[0], zoomOut = chart.mapNavButtons[1], initialButton = direction > 0 ? zoomIn : zoomOut;
  3831. chart.setFocusToElement(initialButton.box, initialButton.element);
  3832. initialButton.setState(2);
  3833. this.focusedMapNavButtonIx = direction > 0 ? 0 : 1;
  3834. },
  3835. /**
  3836. * Get keyboard navigation handler for a simple chart button. Provide the
  3837. * button reference for the chart, and a function to call on click.
  3838. *
  3839. * @private
  3840. * @param {string} buttonProp The property on chart referencing the button.
  3841. * @return {Highcharts.KeyboardNavigationHandler} The module object
  3842. */
  3843. simpleButtonNavigation: function (buttonProp, proxyProp, onClick) {
  3844. var keys = this.keyCodes, component = this, chart = this.chart;
  3845. return new KeyboardNavigationHandler(chart, {
  3846. keyCodeMap: [
  3847. [
  3848. [keys.tab, keys.up, keys.down, keys.left, keys.right],
  3849. function (keyCode, e) {
  3850. var isBackwards = keyCode === keys.tab && e.shiftKey ||
  3851. keyCode === keys.left || keyCode === keys.up;
  3852. // Arrow/tab => just move
  3853. return this.response[isBackwards ? 'prev' : 'next'];
  3854. }
  3855. ],
  3856. [
  3857. [keys.space, keys.enter],
  3858. function () {
  3859. var res = onClick(this, chart);
  3860. return pick(res, this.response.success);
  3861. }
  3862. ]
  3863. ],
  3864. validate: function () {
  3865. var hasButton = (chart[buttonProp] &&
  3866. chart[buttonProp].box &&
  3867. component[proxyProp]);
  3868. return hasButton;
  3869. },
  3870. init: function () {
  3871. chart.setFocusToElement(chart[buttonProp].box, component[proxyProp]);
  3872. }
  3873. });
  3874. },
  3875. /**
  3876. * Get keyboard navigation handlers for this component.
  3877. * @return {Array<Highcharts.KeyboardNavigationHandler>}
  3878. * List of module objects
  3879. */
  3880. getKeyboardNavigation: function () {
  3881. return [
  3882. this.simpleButtonNavigation('resetZoomButton', 'resetZoomProxyButton', function (_handler, chart) {
  3883. chart.zoomOut();
  3884. }),
  3885. this.simpleButtonNavigation('drillUpButton', 'drillUpProxyButton', function (handler, chart) {
  3886. chart.drillUp();
  3887. return handler.response.prev;
  3888. }),
  3889. this.getMapZoomNavigation()
  3890. ];
  3891. }
  3892. });
  3893. return ZoomComponent;
  3894. });
  3895. _registerModule(_modules, 'modules/accessibility/components/RangeSelectorComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/KeyboardNavigationHandler.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, U, AccessibilityComponent, KeyboardNavigationHandler, ChartUtilities, HTMLUtilities) {
  3896. /* *
  3897. *
  3898. * (c) 2009-2020 Øystein Moseng
  3899. *
  3900. * Accessibility component for the range selector.
  3901. *
  3902. * License: www.highcharts.com/license
  3903. *
  3904. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3905. *
  3906. * */
  3907. var extend = U.extend;
  3908. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  3909. var setElAttrs = HTMLUtilities.setElAttrs;
  3910. /* eslint-disable no-invalid-this, valid-jsdoc */
  3911. /**
  3912. * @private
  3913. */
  3914. function shouldRunInputNavigation(chart) {
  3915. var inputVisible = (chart.rangeSelector &&
  3916. chart.rangeSelector.inputGroup &&
  3917. chart.rangeSelector.inputGroup.element
  3918. .getAttribute('visibility') !== 'hidden');
  3919. return (inputVisible &&
  3920. chart.options.rangeSelector.inputEnabled !== false &&
  3921. chart.rangeSelector.minInput &&
  3922. chart.rangeSelector.maxInput);
  3923. }
  3924. /**
  3925. * Highlight range selector button by index.
  3926. *
  3927. * @private
  3928. * @function Highcharts.Chart#highlightRangeSelectorButton
  3929. *
  3930. * @param {number} ix
  3931. *
  3932. * @return {boolean}
  3933. */
  3934. H.Chart.prototype.highlightRangeSelectorButton = function (ix) {
  3935. var buttons = this.rangeSelector.buttons, curSelectedIx = this.highlightedRangeSelectorItemIx;
  3936. // Deselect old
  3937. if (typeof curSelectedIx !== 'undefined' && buttons[curSelectedIx]) {
  3938. buttons[curSelectedIx].setState(this.oldRangeSelectorItemState || 0);
  3939. }
  3940. // Select new
  3941. this.highlightedRangeSelectorItemIx = ix;
  3942. if (buttons[ix]) {
  3943. this.setFocusToElement(buttons[ix].box, buttons[ix].element);
  3944. this.oldRangeSelectorItemState = buttons[ix].state;
  3945. buttons[ix].setState(2);
  3946. return true;
  3947. }
  3948. return false;
  3949. };
  3950. /**
  3951. * The RangeSelectorComponent class
  3952. *
  3953. * @private
  3954. * @class
  3955. * @name Highcharts.RangeSelectorComponent
  3956. */
  3957. var RangeSelectorComponent = function () { };
  3958. RangeSelectorComponent.prototype = new AccessibilityComponent();
  3959. extend(RangeSelectorComponent.prototype, /** @lends Highcharts.RangeSelectorComponent */ {
  3960. /**
  3961. * Called on first render/updates to the chart, including options changes.
  3962. */
  3963. onChartUpdate: function () {
  3964. var chart = this.chart, component = this, rangeSelector = chart.rangeSelector;
  3965. if (!rangeSelector) {
  3966. return;
  3967. }
  3968. if (rangeSelector.buttons && rangeSelector.buttons.length) {
  3969. rangeSelector.buttons.forEach(function (button) {
  3970. unhideChartElementFromAT(chart, button.element);
  3971. component.setRangeButtonAttrs(button);
  3972. });
  3973. }
  3974. // Make sure input boxes are accessible and focusable
  3975. if (rangeSelector.maxInput && rangeSelector.minInput) {
  3976. ['minInput', 'maxInput'].forEach(function (key, i) {
  3977. var input = rangeSelector[key];
  3978. if (input) {
  3979. unhideChartElementFromAT(chart, input);
  3980. component.setRangeInputAttrs(input, 'accessibility.rangeSelector.' + (i ? 'max' : 'min') +
  3981. 'InputLabel');
  3982. }
  3983. });
  3984. }
  3985. },
  3986. /**
  3987. * @private
  3988. * @param {Highcharts.SVGElement} button
  3989. */
  3990. setRangeButtonAttrs: function (button) {
  3991. var chart = this.chart, label = chart.langFormat('accessibility.rangeSelector.buttonText', {
  3992. chart: chart,
  3993. buttonText: button.text && button.text.textStr
  3994. });
  3995. setElAttrs(button.element, {
  3996. tabindex: -1,
  3997. role: 'button',
  3998. 'aria-label': label
  3999. });
  4000. },
  4001. /**
  4002. * @private
  4003. */
  4004. setRangeInputAttrs: function (input, langKey) {
  4005. var chart = this.chart;
  4006. setElAttrs(input, {
  4007. tabindex: -1,
  4008. role: 'textbox',
  4009. 'aria-label': chart.langFormat(langKey, { chart: chart })
  4010. });
  4011. },
  4012. /**
  4013. * Get navigation for the range selector buttons.
  4014. * @private
  4015. * @return {Highcharts.KeyboardNavigationHandler} The module object.
  4016. */
  4017. getRangeSelectorButtonNavigation: function () {
  4018. var chart = this.chart, keys = this.keyCodes, component = this;
  4019. return new KeyboardNavigationHandler(chart, {
  4020. keyCodeMap: [
  4021. [
  4022. [keys.left, keys.right, keys.up, keys.down],
  4023. function (keyCode) {
  4024. return component.onButtonNavKbdArrowKey(this, keyCode);
  4025. }
  4026. ],
  4027. [
  4028. [keys.enter, keys.space],
  4029. function () {
  4030. return component.onButtonNavKbdClick(this);
  4031. }
  4032. ]
  4033. ],
  4034. validate: function () {
  4035. var hasRangeSelector = chart.rangeSelector &&
  4036. chart.rangeSelector.buttons &&
  4037. chart.rangeSelector.buttons.length;
  4038. return hasRangeSelector;
  4039. },
  4040. init: function (direction) {
  4041. var lastButtonIx = (chart.rangeSelector.buttons.length - 1);
  4042. chart.highlightRangeSelectorButton(direction > 0 ? 0 : lastButtonIx);
  4043. }
  4044. });
  4045. },
  4046. /**
  4047. * @private
  4048. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  4049. * @param {number} keyCode
  4050. * @return {number} Response code
  4051. */
  4052. onButtonNavKbdArrowKey: function (keyboardNavigationHandler, keyCode) {
  4053. var response = keyboardNavigationHandler.response, keys = this.keyCodes, chart = this.chart, wrapAround = chart.options.accessibility
  4054. .keyboardNavigation.wrapAround, direction = (keyCode === keys.left || keyCode === keys.up) ? -1 : 1, didHighlight = chart.highlightRangeSelectorButton(chart.highlightedRangeSelectorItemIx + direction);
  4055. if (!didHighlight) {
  4056. if (wrapAround) {
  4057. keyboardNavigationHandler.init(direction);
  4058. return response.success;
  4059. }
  4060. return response[direction > 0 ? 'next' : 'prev'];
  4061. }
  4062. return response.success;
  4063. },
  4064. /**
  4065. * @private
  4066. */
  4067. onButtonNavKbdClick: function (keyboardNavigationHandler) {
  4068. var response = keyboardNavigationHandler.response, chart = this.chart, wasDisabled = chart.oldRangeSelectorItemState === 3;
  4069. if (!wasDisabled) {
  4070. this.fakeClickEvent(chart.rangeSelector.buttons[chart.highlightedRangeSelectorItemIx].element);
  4071. }
  4072. return response.success;
  4073. },
  4074. /**
  4075. * Get navigation for the range selector input boxes.
  4076. * @private
  4077. * @return {Highcharts.KeyboardNavigationHandler}
  4078. * The module object.
  4079. */
  4080. getRangeSelectorInputNavigation: function () {
  4081. var chart = this.chart, keys = this.keyCodes, component = this;
  4082. return new KeyboardNavigationHandler(chart, {
  4083. keyCodeMap: [
  4084. [
  4085. [
  4086. keys.tab, keys.up, keys.down
  4087. ],
  4088. function (keyCode, e) {
  4089. var direction = (keyCode === keys.tab && e.shiftKey ||
  4090. keyCode === keys.up) ? -1 : 1;
  4091. return component.onInputKbdMove(this, direction);
  4092. }
  4093. ]
  4094. ],
  4095. validate: function () {
  4096. return shouldRunInputNavigation(chart);
  4097. },
  4098. init: function (direction) {
  4099. component.onInputNavInit(direction);
  4100. },
  4101. terminate: function () {
  4102. component.onInputNavTerminate();
  4103. }
  4104. });
  4105. },
  4106. /**
  4107. * @private
  4108. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  4109. * @param {number} direction
  4110. * @return {number} Response code
  4111. */
  4112. onInputKbdMove: function (keyboardNavigationHandler, direction) {
  4113. var chart = this.chart, response = keyboardNavigationHandler.response, newIx = chart.highlightedInputRangeIx =
  4114. chart.highlightedInputRangeIx + direction, newIxOutOfRange = newIx > 1 || newIx < 0;
  4115. if (newIxOutOfRange) {
  4116. return response[direction > 0 ? 'next' : 'prev'];
  4117. }
  4118. chart.rangeSelector[newIx ? 'maxInput' : 'minInput'].focus();
  4119. return response.success;
  4120. },
  4121. /**
  4122. * @private
  4123. * @param {number} direction
  4124. */
  4125. onInputNavInit: function (direction) {
  4126. var chart = this.chart, buttonIxToHighlight = direction > 0 ? 0 : 1;
  4127. chart.highlightedInputRangeIx = buttonIxToHighlight;
  4128. chart.rangeSelector[buttonIxToHighlight ? 'maxInput' : 'minInput'].focus();
  4129. },
  4130. /**
  4131. * @private
  4132. */
  4133. onInputNavTerminate: function () {
  4134. var rangeSel = (this.chart.rangeSelector || {});
  4135. if (rangeSel.maxInput) {
  4136. rangeSel.hideInput('max');
  4137. }
  4138. if (rangeSel.minInput) {
  4139. rangeSel.hideInput('min');
  4140. }
  4141. },
  4142. /**
  4143. * Get keyboard navigation handlers for this component.
  4144. * @return {Array<Highcharts.KeyboardNavigationHandler>}
  4145. * List of module objects.
  4146. */
  4147. getKeyboardNavigation: function () {
  4148. return [
  4149. this.getRangeSelectorButtonNavigation(),
  4150. this.getRangeSelectorInputNavigation()
  4151. ];
  4152. }
  4153. });
  4154. return RangeSelectorComponent;
  4155. });
  4156. _registerModule(_modules, 'modules/accessibility/components/InfoRegionsComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/utils/Announcer.js'], _modules['modules/accessibility/components/AnnotationsA11y.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js']], function (H, U, AccessibilityComponent, Announcer, AnnotationsA11y, ChartUtilities, HTMLUtilities) {
  4157. /* *
  4158. *
  4159. * (c) 2009-2020 Øystein Moseng
  4160. *
  4161. * Accessibility component for chart info region and table.
  4162. *
  4163. * License: www.highcharts.com/license
  4164. *
  4165. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4166. *
  4167. * */
  4168. var doc = H.doc;
  4169. var extend = U.extend, format = U.format, pick = U.pick;
  4170. var getAnnotationsInfoHTML = AnnotationsA11y.getAnnotationsInfoHTML;
  4171. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT, getChartTitle = ChartUtilities.getChartTitle, getAxisDescription = ChartUtilities.getAxisDescription;
  4172. var addClass = HTMLUtilities.addClass, setElAttrs = HTMLUtilities.setElAttrs, escapeStringForHTML = HTMLUtilities.escapeStringForHTML, stripHTMLTagsFromString = HTMLUtilities.stripHTMLTagsFromString, getElement = HTMLUtilities.getElement, visuallyHideElement = HTMLUtilities.visuallyHideElement;
  4173. /* eslint-disable no-invalid-this, valid-jsdoc */
  4174. /**
  4175. * @private
  4176. */
  4177. function getTypeDescForMapChart(chart, formatContext) {
  4178. return formatContext.mapTitle ?
  4179. chart.langFormat('accessibility.chartTypes.mapTypeDescription', formatContext) :
  4180. chart.langFormat('accessibility.chartTypes.unknownMap', formatContext);
  4181. }
  4182. /**
  4183. * @private
  4184. */
  4185. function getTypeDescForCombinationChart(chart, formatContext) {
  4186. return chart.langFormat('accessibility.chartTypes.combinationChart', formatContext);
  4187. }
  4188. /**
  4189. * @private
  4190. */
  4191. function getTypeDescForEmptyChart(chart, formatContext) {
  4192. return chart.langFormat('accessibility.chartTypes.emptyChart', formatContext);
  4193. }
  4194. /**
  4195. * @private
  4196. */
  4197. function buildTypeDescriptionFromSeries(chart, types, context) {
  4198. var firstType = types[0], typeExplaination = chart.langFormat('accessibility.seriesTypeDescriptions.' + firstType, context), multi = chart.series && chart.series.length < 2 ? 'Single' : 'Multiple';
  4199. return (chart.langFormat('accessibility.chartTypes.' + firstType + multi, context) ||
  4200. chart.langFormat('accessibility.chartTypes.default' + multi, context)) + (typeExplaination ? ' ' + typeExplaination : '');
  4201. }
  4202. /**
  4203. * @private
  4204. */
  4205. function getTableSummary(chart) {
  4206. return chart.langFormat('accessibility.table.tableSummary', { chart: chart });
  4207. }
  4208. /**
  4209. * @private
  4210. */
  4211. function stripEmptyHTMLTags(str) {
  4212. return str.replace(/<(\w+)[^>]*?>\s*<\/\1>/g, '');
  4213. }
  4214. /**
  4215. * @private
  4216. */
  4217. function enableSimpleHTML(str) {
  4218. return str
  4219. .replace(/&lt;(h[1-7]|p|div|ul|ol|li)&gt;/g, '<$1>')
  4220. .replace(/&lt;&#x2F;(h[1-7]|p|div|ul|ol|li|a|button)&gt;/g, '</$1>')
  4221. .replace(/&lt;(div|a|button) id=&quot;([a-zA-Z\-0-9#]*?)&quot;&gt;/g, '<$1 id="$2">');
  4222. }
  4223. /**
  4224. * @private
  4225. */
  4226. function stringToSimpleHTML(str) {
  4227. return stripEmptyHTMLTags(enableSimpleHTML(escapeStringForHTML(str)));
  4228. }
  4229. /**
  4230. * Return simplified explaination of chart type. Some types will not be familiar
  4231. * to most users, but in those cases we try to add an explaination of the type.
  4232. *
  4233. * @private
  4234. * @function Highcharts.Chart#getTypeDescription
  4235. * @param {Array<string>} types The series types in this chart.
  4236. * @return {string} The text description of the chart type.
  4237. */
  4238. H.Chart.prototype.getTypeDescription = function (types) {
  4239. var firstType = types[0], firstSeries = this.series && this.series[0] || {}, formatContext = {
  4240. numSeries: this.series.length,
  4241. numPoints: firstSeries.points && firstSeries.points.length,
  4242. chart: this,
  4243. mapTitle: firstSeries.mapTitle
  4244. };
  4245. if (!firstType) {
  4246. return getTypeDescForEmptyChart(this, formatContext);
  4247. }
  4248. if (firstType === 'map') {
  4249. return getTypeDescForMapChart(this, formatContext);
  4250. }
  4251. if (this.types.length > 1) {
  4252. return getTypeDescForCombinationChart(this, formatContext);
  4253. }
  4254. return buildTypeDescriptionFromSeries(this, types, formatContext);
  4255. };
  4256. /**
  4257. * The InfoRegionsComponent class
  4258. *
  4259. * @private
  4260. * @class
  4261. * @name Highcharts.InfoRegionsComponent
  4262. */
  4263. var InfoRegionsComponent = function () { };
  4264. InfoRegionsComponent.prototype = new AccessibilityComponent();
  4265. extend(InfoRegionsComponent.prototype, /** @lends Highcharts.InfoRegionsComponent */ {
  4266. /**
  4267. * Init the component
  4268. * @private
  4269. */
  4270. init: function () {
  4271. var chart = this.chart;
  4272. var component = this;
  4273. this.initRegionsDefinitions();
  4274. this.addEvent(chart, 'afterGetTable', function (e) {
  4275. component.onDataTableCreated(e);
  4276. });
  4277. this.addEvent(chart, 'afterViewData', function (tableDiv) {
  4278. component.dataTableDiv = tableDiv;
  4279. // Use small delay to give browsers & AT time to register new table
  4280. setTimeout(function () {
  4281. component.focusDataTable();
  4282. }, 300);
  4283. });
  4284. this.announcer = new Announcer(chart, 'assertive');
  4285. },
  4286. /**
  4287. * @private
  4288. */
  4289. initRegionsDefinitions: function () {
  4290. var component = this;
  4291. this.screenReaderSections = {
  4292. before: {
  4293. element: null,
  4294. buildContent: function (chart) {
  4295. var formatter = chart.options.accessibility
  4296. .screenReaderSection.beforeChartFormatter;
  4297. return formatter ? formatter(chart) :
  4298. component.defaultBeforeChartFormatter(chart);
  4299. },
  4300. insertIntoDOM: function (el, chart) {
  4301. chart.renderTo.insertBefore(el, chart.renderTo.firstChild);
  4302. },
  4303. afterInserted: function () {
  4304. if (typeof component.sonifyButtonId !== 'undefined') {
  4305. component.initSonifyButton(component.sonifyButtonId);
  4306. }
  4307. if (typeof component.dataTableButtonId !== 'undefined') {
  4308. component.initDataTableButton(component.dataTableButtonId);
  4309. }
  4310. }
  4311. },
  4312. after: {
  4313. element: null,
  4314. buildContent: function (chart) {
  4315. var formatter = chart.options.accessibility.screenReaderSection
  4316. .afterChartFormatter;
  4317. return formatter ? formatter(chart) :
  4318. component.defaultAfterChartFormatter();
  4319. },
  4320. insertIntoDOM: function (el, chart) {
  4321. chart.renderTo.insertBefore(el, chart.container.nextSibling);
  4322. }
  4323. }
  4324. };
  4325. },
  4326. /**
  4327. * Called on chart render. Have to update the sections on render, in order
  4328. * to get a11y info from series.
  4329. */
  4330. onChartRender: function () {
  4331. var component = this;
  4332. this.linkedDescriptionElement = this.getLinkedDescriptionElement();
  4333. this.setLinkedDescriptionAttrs();
  4334. Object.keys(this.screenReaderSections).forEach(function (regionKey) {
  4335. component.updateScreenReaderSection(regionKey);
  4336. });
  4337. },
  4338. /**
  4339. * @private
  4340. */
  4341. getLinkedDescriptionElement: function () {
  4342. var chartOptions = this.chart.options, linkedDescOption = chartOptions.accessibility.linkedDescription;
  4343. if (!linkedDescOption) {
  4344. return;
  4345. }
  4346. if (typeof linkedDescOption !== 'string') {
  4347. return linkedDescOption;
  4348. }
  4349. var query = format(linkedDescOption, this.chart), queryMatch = doc.querySelectorAll(query);
  4350. if (queryMatch.length === 1) {
  4351. return queryMatch[0];
  4352. }
  4353. },
  4354. /**
  4355. * @private
  4356. */
  4357. setLinkedDescriptionAttrs: function () {
  4358. var el = this.linkedDescriptionElement;
  4359. if (el) {
  4360. el.setAttribute('aria-hidden', 'true');
  4361. addClass(el, 'highcharts-linked-description');
  4362. }
  4363. },
  4364. /**
  4365. * @private
  4366. * @param {string} regionKey The name/key of the region to update
  4367. */
  4368. updateScreenReaderSection: function (regionKey) {
  4369. var chart = this.chart, region = this.screenReaderSections[regionKey], content = region.buildContent(chart), sectionDiv = region.element = (region.element || this.createElement('div')), hiddenDiv = (sectionDiv.firstChild || this.createElement('div'));
  4370. this.setScreenReaderSectionAttribs(sectionDiv, regionKey);
  4371. hiddenDiv.innerHTML = content;
  4372. sectionDiv.appendChild(hiddenDiv);
  4373. region.insertIntoDOM(sectionDiv, chart);
  4374. visuallyHideElement(hiddenDiv);
  4375. unhideChartElementFromAT(chart, hiddenDiv);
  4376. if (region.afterInserted) {
  4377. region.afterInserted();
  4378. }
  4379. },
  4380. /**
  4381. * @private
  4382. * @param {Highcharts.HTMLDOMElement} sectionDiv The section element
  4383. * @param {string} regionKey Name/key of the region we are setting attrs for
  4384. */
  4385. setScreenReaderSectionAttribs: function (sectionDiv, regionKey) {
  4386. var labelLangKey = ('accessibility.screenReaderSection.' + regionKey + 'RegionLabel'), chart = this.chart, labelText = chart.langFormat(labelLangKey, { chart: chart }), sectionId = 'highcharts-screen-reader-region-' + regionKey + '-' +
  4387. chart.index;
  4388. setElAttrs(sectionDiv, {
  4389. id: sectionId,
  4390. 'aria-label': labelText
  4391. });
  4392. // Sections are wrapped to be positioned relatively to chart in case
  4393. // elements inside are tabbed to.
  4394. sectionDiv.style.position = 'relative';
  4395. if (chart.options.accessibility.landmarkVerbosity === 'all' &&
  4396. labelText) {
  4397. sectionDiv.setAttribute('role', 'region');
  4398. }
  4399. },
  4400. /**
  4401. * @private
  4402. * @return {string}
  4403. */
  4404. defaultBeforeChartFormatter: function () {
  4405. var _a;
  4406. var chart = this.chart, format = chart.options.accessibility
  4407. .screenReaderSection.beforeChartFormat, axesDesc = this.getAxesDescription(), shouldHaveSonifyBtn = chart.sonify && ((_a = chart.options.sonification) === null || _a === void 0 ? void 0 : _a.enabled), sonifyButtonId = 'highcharts-a11y-sonify-data-btn-' +
  4408. chart.index, dataTableButtonId = 'hc-linkto-highcharts-data-table-' +
  4409. chart.index, annotationsList = getAnnotationsInfoHTML(chart), annotationsTitleStr = chart.langFormat('accessibility.screenReaderSection.annotations.heading', { chart: chart }), context = {
  4410. chartTitle: getChartTitle(chart),
  4411. typeDescription: this.getTypeDescriptionText(),
  4412. chartSubtitle: this.getSubtitleText(),
  4413. chartLongdesc: this.getLongdescText(),
  4414. xAxisDescription: axesDesc.xAxis,
  4415. yAxisDescription: axesDesc.yAxis,
  4416. playAsSoundButton: shouldHaveSonifyBtn ?
  4417. this.getSonifyButtonText(sonifyButtonId) : '',
  4418. viewTableButton: chart.getCSV ?
  4419. this.getDataTableButtonText(dataTableButtonId) : '',
  4420. annotationsTitle: annotationsList ? annotationsTitleStr : '',
  4421. annotationsList: annotationsList
  4422. }, formattedString = H.i18nFormat(format, context, chart);
  4423. this.dataTableButtonId = dataTableButtonId;
  4424. this.sonifyButtonId = sonifyButtonId;
  4425. return stringToSimpleHTML(formattedString);
  4426. },
  4427. /**
  4428. * @private
  4429. * @return {string}
  4430. */
  4431. defaultAfterChartFormatter: function () {
  4432. var chart = this.chart, format = chart.options.accessibility
  4433. .screenReaderSection.afterChartFormat, context = {
  4434. endOfChartMarker: this.getEndOfChartMarkerText()
  4435. }, formattedString = H.i18nFormat(format, context, chart);
  4436. return stringToSimpleHTML(formattedString);
  4437. },
  4438. /**
  4439. * @private
  4440. * @return {string}
  4441. */
  4442. getLinkedDescription: function () {
  4443. var el = this.linkedDescriptionElement, content = el && el.innerHTML || '';
  4444. return stripHTMLTagsFromString(content);
  4445. },
  4446. /**
  4447. * @private
  4448. * @return {string}
  4449. */
  4450. getLongdescText: function () {
  4451. var chartOptions = this.chart.options, captionOptions = chartOptions.caption, captionText = captionOptions && captionOptions.text, linkedDescription = this.getLinkedDescription();
  4452. return (chartOptions.accessibility.description ||
  4453. linkedDescription ||
  4454. captionText ||
  4455. '');
  4456. },
  4457. /**
  4458. * @private
  4459. * @return {string}
  4460. */
  4461. getTypeDescriptionText: function () {
  4462. var chart = this.chart;
  4463. return chart.types ?
  4464. chart.options.accessibility.typeDescription ||
  4465. chart.getTypeDescription(chart.types) : '';
  4466. },
  4467. /**
  4468. * @private
  4469. * @param {string} buttonId
  4470. * @return {string}
  4471. */
  4472. getDataTableButtonText: function (buttonId) {
  4473. var chart = this.chart, buttonText = chart.langFormat('accessibility.table.viewAsDataTableButtonText', { chart: chart, chartTitle: getChartTitle(chart) });
  4474. return '<a id="' + buttonId + '">' + buttonText + '</a>';
  4475. },
  4476. /**
  4477. * @private
  4478. * @param {string} buttonId
  4479. * @return {string}
  4480. */
  4481. getSonifyButtonText: function (buttonId) {
  4482. var _a;
  4483. var chart = this.chart;
  4484. if (((_a = chart.options.sonification) === null || _a === void 0 ? void 0 : _a.enabled) === false) {
  4485. return '';
  4486. }
  4487. var buttonText = chart.langFormat('accessibility.sonification.playAsSoundButtonText', { chart: chart, chartTitle: getChartTitle(chart) });
  4488. return '<button id="' + buttonId + '">' + buttonText + '</button>';
  4489. },
  4490. /**
  4491. * @private
  4492. * @return {string}
  4493. */
  4494. getSubtitleText: function () {
  4495. var subtitle = (this.chart.options.subtitle);
  4496. return stripHTMLTagsFromString(subtitle && subtitle.text || '');
  4497. },
  4498. /**
  4499. * @private
  4500. * @return {string}
  4501. */
  4502. getEndOfChartMarkerText: function () {
  4503. var chart = this.chart, markerText = chart.langFormat('accessibility.screenReaderSection.endOfChartMarker', { chart: chart }), id = 'highcharts-end-of-chart-marker-' + chart.index;
  4504. return '<div id="' + id + '">' + markerText + '</div>';
  4505. },
  4506. /**
  4507. * @private
  4508. * @param {Highcharts.Dictionary<string>} e
  4509. */
  4510. onDataTableCreated: function (e) {
  4511. var chart = this.chart;
  4512. if (chart.options.accessibility.enabled) {
  4513. if (this.viewDataTableButton) {
  4514. this.viewDataTableButton.setAttribute('aria-expanded', 'true');
  4515. }
  4516. e.html = e.html.replace('<table ', '<table tabindex="-1" summary="' + getTableSummary(chart) + '"');
  4517. }
  4518. },
  4519. /**
  4520. * @private
  4521. */
  4522. focusDataTable: function () {
  4523. var tableDiv = this.dataTableDiv, table = tableDiv && tableDiv.getElementsByTagName('table')[0];
  4524. if (table && table.focus) {
  4525. table.focus();
  4526. }
  4527. },
  4528. /**
  4529. * @private
  4530. * @param {string} sonifyButtonId
  4531. */
  4532. initSonifyButton: function (sonifyButtonId) {
  4533. var _this = this;
  4534. var el = this.sonifyButton = getElement(sonifyButtonId);
  4535. var chart = this.chart;
  4536. var defaultHandler = function (e) {
  4537. el === null || el === void 0 ? void 0 : el.setAttribute('aria-hidden', 'true');
  4538. el === null || el === void 0 ? void 0 : el.setAttribute('aria-label', '');
  4539. e.preventDefault();
  4540. e.stopPropagation();
  4541. var announceMsg = chart.langFormat('accessibility.sonification.playAsSoundClickAnnouncement', { chart: chart });
  4542. _this.announcer.announce(announceMsg);
  4543. setTimeout(function () {
  4544. el === null || el === void 0 ? void 0 : el.removeAttribute('aria-hidden');
  4545. el === null || el === void 0 ? void 0 : el.removeAttribute('aria-label');
  4546. if (chart.sonify) {
  4547. chart.sonify();
  4548. }
  4549. }, 1000); // Delay to let screen reader speak the button press
  4550. };
  4551. if (el && chart) {
  4552. setElAttrs(el, {
  4553. tabindex: '-1'
  4554. });
  4555. el.onclick = function (e) {
  4556. var _a;
  4557. var onPlayAsSoundClick = (_a = chart.options.accessibility) === null || _a === void 0 ? void 0 : _a.screenReaderSection.onPlayAsSoundClick;
  4558. (onPlayAsSoundClick || defaultHandler).call(this, e, chart);
  4559. };
  4560. }
  4561. },
  4562. /**
  4563. * Set attribs and handlers for default viewAsDataTable button if exists.
  4564. * @private
  4565. * @param {string} tableButtonId
  4566. */
  4567. initDataTableButton: function (tableButtonId) {
  4568. var el = this.viewDataTableButton = getElement(tableButtonId), chart = this.chart, tableId = tableButtonId.replace('hc-linkto-', '');
  4569. if (el) {
  4570. setElAttrs(el, {
  4571. role: 'button',
  4572. tabindex: '-1',
  4573. 'aria-expanded': !!getElement(tableId),
  4574. href: '#' + tableId
  4575. });
  4576. el.onclick = chart.options.accessibility
  4577. .screenReaderSection.onViewDataTableClick ||
  4578. function () {
  4579. chart.viewData();
  4580. };
  4581. }
  4582. },
  4583. /**
  4584. * Return object with text description of each of the chart's axes.
  4585. * @private
  4586. * @return {Highcharts.Dictionary<string>}
  4587. */
  4588. getAxesDescription: function () {
  4589. var chart = this.chart, shouldDescribeColl = function (collectionKey, defaultCondition) {
  4590. var axes = chart[collectionKey];
  4591. return axes.length > 1 || axes[0] &&
  4592. pick(axes[0].options.accessibility &&
  4593. axes[0].options.accessibility.enabled, defaultCondition);
  4594. }, hasNoMap = !!chart.types && chart.types.indexOf('map') < 0, hasCartesian = !!chart.hasCartesianSeries, showXAxes = shouldDescribeColl('xAxis', !chart.angular && hasCartesian && hasNoMap), showYAxes = shouldDescribeColl('yAxis', hasCartesian && hasNoMap), desc = {};
  4595. if (showXAxes) {
  4596. desc.xAxis = this.getAxisDescriptionText('xAxis');
  4597. }
  4598. if (showYAxes) {
  4599. desc.yAxis = this.getAxisDescriptionText('yAxis');
  4600. }
  4601. return desc;
  4602. },
  4603. /**
  4604. * @private
  4605. * @param {string} collectionKey
  4606. * @return {string}
  4607. */
  4608. getAxisDescriptionText: function (collectionKey) {
  4609. var component = this, chart = this.chart, axes = chart[collectionKey];
  4610. return chart.langFormat('accessibility.axis.' + collectionKey + 'Description' + (axes.length > 1 ? 'Plural' : 'Singular'), {
  4611. chart: chart,
  4612. names: axes.map(function (axis) {
  4613. return getAxisDescription(axis);
  4614. }),
  4615. ranges: axes.map(function (axis) {
  4616. return component.getAxisRangeDescription(axis);
  4617. }),
  4618. numAxes: axes.length
  4619. });
  4620. },
  4621. /**
  4622. * Return string with text description of the axis range.
  4623. * @private
  4624. * @param {Highcharts.Axis} axis The axis to get range desc of.
  4625. * @return {string} A string with the range description for the axis.
  4626. */
  4627. getAxisRangeDescription: function (axis) {
  4628. var axisOptions = axis.options || {};
  4629. // Handle overridden range description
  4630. if (axisOptions.accessibility &&
  4631. typeof axisOptions.accessibility.rangeDescription !== 'undefined') {
  4632. return axisOptions.accessibility.rangeDescription;
  4633. }
  4634. // Handle category axes
  4635. if (axis.categories) {
  4636. return this.getCategoryAxisRangeDesc(axis);
  4637. }
  4638. // Use time range, not from-to?
  4639. if (axis.dateTime && (axis.min === 0 || axis.dataMin === 0)) {
  4640. return this.getAxisTimeLengthDesc(axis);
  4641. }
  4642. // Just use from and to.
  4643. // We have the range and the unit to use, find the desc format
  4644. return this.getAxisFromToDescription(axis);
  4645. },
  4646. /**
  4647. * @private
  4648. * @param {Highcharts.Axis} axis
  4649. * @return {string}
  4650. */
  4651. getCategoryAxisRangeDesc: function (axis) {
  4652. var chart = this.chart;
  4653. if (axis.dataMax && axis.dataMin) {
  4654. return chart.langFormat('accessibility.axis.rangeCategories', {
  4655. chart: chart,
  4656. axis: axis,
  4657. numCategories: axis.dataMax - axis.dataMin + 1
  4658. });
  4659. }
  4660. return '';
  4661. },
  4662. /**
  4663. * @private
  4664. * @param {Highcharts.Axis} axis
  4665. * @return {string}
  4666. */
  4667. getAxisTimeLengthDesc: function (axis) {
  4668. var chart = this.chart, range = {}, rangeUnit = 'Seconds';
  4669. range.Seconds = ((axis.max || 0) - (axis.min || 0)) / 1000;
  4670. range.Minutes = range.Seconds / 60;
  4671. range.Hours = range.Minutes / 60;
  4672. range.Days = range.Hours / 24;
  4673. ['Minutes', 'Hours', 'Days'].forEach(function (unit) {
  4674. if (range[unit] > 2) {
  4675. rangeUnit = unit;
  4676. }
  4677. });
  4678. var rangeValue = range[rangeUnit].toFixed(rangeUnit !== 'Seconds' &&
  4679. rangeUnit !== 'Minutes' ? 1 : 0 // Use decimals for days/hours
  4680. );
  4681. // We have the range and the unit to use, find the desc format
  4682. return chart.langFormat('accessibility.axis.timeRange' + rangeUnit, {
  4683. chart: chart,
  4684. axis: axis,
  4685. range: rangeValue.replace('.0', '')
  4686. });
  4687. },
  4688. /**
  4689. * @private
  4690. * @param {Highcharts.Axis} axis
  4691. * @return {string}
  4692. */
  4693. getAxisFromToDescription: function (axis) {
  4694. var chart = this.chart, dateRangeFormat = chart.options.accessibility
  4695. .screenReaderSection.axisRangeDateFormat, format = function (axisKey) {
  4696. return axis.dateTime ? chart.time.dateFormat(dateRangeFormat, axis[axisKey]) : axis[axisKey];
  4697. };
  4698. return chart.langFormat('accessibility.axis.rangeFromTo', {
  4699. chart: chart,
  4700. axis: axis,
  4701. rangeFrom: format('min'),
  4702. rangeTo: format('max')
  4703. });
  4704. },
  4705. /**
  4706. * Remove component traces
  4707. */
  4708. destroy: function () {
  4709. var _a;
  4710. (_a = this.announcer) === null || _a === void 0 ? void 0 : _a.destroy();
  4711. }
  4712. });
  4713. return InfoRegionsComponent;
  4714. });
  4715. _registerModule(_modules, 'modules/accessibility/components/ContainerComponent.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/utils/htmlUtilities.js'], _modules['modules/accessibility/utils/chartUtilities.js'], _modules['modules/accessibility/AccessibilityComponent.js']], function (H, U, HTMLUtilities, ChartUtilities, AccessibilityComponent) {
  4716. /* *
  4717. *
  4718. * (c) 2009-2020 Øystein Moseng
  4719. *
  4720. * Accessibility component for chart container.
  4721. *
  4722. * License: www.highcharts.com/license
  4723. *
  4724. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4725. *
  4726. * */
  4727. var doc = H.win.document;
  4728. var extend = U.extend;
  4729. var stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  4730. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT, getChartTitle = ChartUtilities.getChartTitle;
  4731. /* eslint-disable valid-jsdoc */
  4732. /**
  4733. * The ContainerComponent class
  4734. *
  4735. * @private
  4736. * @class
  4737. * @name Highcharts.ContainerComponent
  4738. */
  4739. var ContainerComponent = function () { };
  4740. ContainerComponent.prototype = new AccessibilityComponent();
  4741. extend(ContainerComponent.prototype, /** @lends Highcharts.ContainerComponent */ {
  4742. /**
  4743. * Called on first render/updates to the chart, including options changes.
  4744. */
  4745. onChartUpdate: function () {
  4746. this.handleSVGTitleElement();
  4747. this.setSVGContainerLabel();
  4748. this.setGraphicContainerAttrs();
  4749. this.setRenderToAttrs();
  4750. this.makeCreditsAccessible();
  4751. },
  4752. /**
  4753. * @private
  4754. */
  4755. handleSVGTitleElement: function () {
  4756. var chart = this.chart, titleId = 'highcharts-title-' + chart.index, titleContents = stripHTMLTags(chart.langFormat('accessibility.svgContainerTitle', {
  4757. chartTitle: getChartTitle(chart)
  4758. }));
  4759. if (titleContents.length) {
  4760. var titleElement = this.svgTitleElement =
  4761. this.svgTitleElement || doc.createElementNS('http://www.w3.org/2000/svg', 'title');
  4762. titleElement.textContent = titleContents;
  4763. titleElement.id = titleId;
  4764. chart.renderTo.insertBefore(titleElement, chart.renderTo.firstChild);
  4765. }
  4766. },
  4767. /**
  4768. * @private
  4769. */
  4770. setSVGContainerLabel: function () {
  4771. var chart = this.chart, svgContainerLabel = stripHTMLTags(chart.langFormat('accessibility.svgContainerLabel', {
  4772. chartTitle: getChartTitle(chart)
  4773. }));
  4774. if (chart.renderer.box && svgContainerLabel.length) {
  4775. chart.renderer.box.setAttribute('aria-label', svgContainerLabel);
  4776. }
  4777. },
  4778. /**
  4779. * @private
  4780. */
  4781. setGraphicContainerAttrs: function () {
  4782. var chart = this.chart, label = chart.langFormat('accessibility.graphicContainerLabel', {
  4783. chartTitle: getChartTitle(chart)
  4784. });
  4785. if (label.length) {
  4786. chart.container.setAttribute('aria-label', label);
  4787. }
  4788. },
  4789. /**
  4790. * @private
  4791. */
  4792. setRenderToAttrs: function () {
  4793. var chart = this.chart;
  4794. if (chart.options.accessibility.landmarkVerbosity !== 'disabled') {
  4795. chart.renderTo.setAttribute('role', 'region');
  4796. }
  4797. else {
  4798. chart.renderTo.removeAttribute('role');
  4799. }
  4800. chart.renderTo.setAttribute('aria-label', chart.langFormat('accessibility.chartContainerLabel', {
  4801. title: getChartTitle(chart),
  4802. chart: chart
  4803. }));
  4804. },
  4805. /**
  4806. * @private
  4807. */
  4808. makeCreditsAccessible: function () {
  4809. var chart = this.chart, credits = chart.credits;
  4810. if (credits) {
  4811. if (credits.textStr) {
  4812. credits.element.setAttribute('aria-label', stripHTMLTags(chart.langFormat('accessibility.credits', { creditsStr: credits.textStr })));
  4813. }
  4814. unhideChartElementFromAT(chart, credits.element);
  4815. }
  4816. },
  4817. /**
  4818. * Accessibility disabled/chart destroyed.
  4819. */
  4820. destroy: function () {
  4821. this.chart.renderTo.setAttribute('aria-hidden', true);
  4822. }
  4823. });
  4824. return ContainerComponent;
  4825. });
  4826. _registerModule(_modules, 'modules/accessibility/high-contrast-mode.js', [_modules['parts/Globals.js']], function (H) {
  4827. /* *
  4828. *
  4829. * (c) 2009-2020 Øystein Moseng
  4830. *
  4831. * Handling for Windows High Contrast Mode.
  4832. *
  4833. * License: www.highcharts.com/license
  4834. *
  4835. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4836. *
  4837. * */
  4838. var isMS = H.isMS, win = H.win, doc = win.document;
  4839. var whcm = {
  4840. /**
  4841. * Detect WHCM in the browser.
  4842. *
  4843. * @function Highcharts#isHighContrastModeActive
  4844. * @private
  4845. * @return {boolean} Returns true if the browser is in High Contrast mode.
  4846. */
  4847. isHighContrastModeActive: function () {
  4848. // Use media query on Edge, but not on IE
  4849. var isEdge = /(Edg)/.test(win.navigator.userAgent);
  4850. if (win.matchMedia && isEdge) {
  4851. return win.matchMedia('(-ms-high-contrast: active)').matches;
  4852. }
  4853. // Test BG image for IE
  4854. if (isMS && win.getComputedStyle) {
  4855. var testDiv = doc.createElement('div');
  4856. var imageSrc = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
  4857. testDiv.style.backgroundImage = "url(" + imageSrc + ")"; // #13071
  4858. doc.body.appendChild(testDiv);
  4859. var bi = (testDiv.currentStyle ||
  4860. win.getComputedStyle(testDiv)).backgroundImage;
  4861. doc.body.removeChild(testDiv);
  4862. return bi === 'none';
  4863. }
  4864. // Not used for other browsers
  4865. return false;
  4866. },
  4867. /**
  4868. * Force high contrast theme for the chart. The default theme is defined in
  4869. * a separate file.
  4870. *
  4871. * @function Highcharts#setHighContrastTheme
  4872. * @private
  4873. * @param {Highcharts.AccessibilityChart} chart The chart to set the theme of.
  4874. * @return {void}
  4875. */
  4876. setHighContrastTheme: function (chart) {
  4877. // We might want to add additional functionality here in the future for
  4878. // storing the old state so that we can reset the theme if HC mode is
  4879. // disabled. For now, the user will have to reload the page.
  4880. chart.highContrastModeActive = true;
  4881. // Apply theme to chart
  4882. var theme = (chart.options.accessibility.highContrastTheme);
  4883. chart.update(theme, false);
  4884. // Force series colors (plotOptions is not enough)
  4885. chart.series.forEach(function (s) {
  4886. var plotOpts = theme.plotOptions[s.type] || {};
  4887. s.update({
  4888. color: plotOpts.color || 'windowText',
  4889. colors: [plotOpts.color || 'windowText'],
  4890. borderColor: plotOpts.borderColor || 'window'
  4891. });
  4892. // Force point colors if existing
  4893. s.points.forEach(function (p) {
  4894. if (p.options && p.options.color) {
  4895. p.update({
  4896. color: plotOpts.color || 'windowText',
  4897. borderColor: plotOpts.borderColor || 'window'
  4898. }, false);
  4899. }
  4900. });
  4901. });
  4902. // The redraw for each series and after is required for 3D pie
  4903. // (workaround)
  4904. chart.redraw();
  4905. }
  4906. };
  4907. return whcm;
  4908. });
  4909. _registerModule(_modules, 'modules/accessibility/high-contrast-theme.js', [], function () {
  4910. /* *
  4911. *
  4912. * (c) 2009-2020 Øystein Moseng
  4913. *
  4914. * Default theme for Windows High Contrast Mode.
  4915. *
  4916. * License: www.highcharts.com/license
  4917. *
  4918. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4919. *
  4920. * */
  4921. var theme = {
  4922. chart: {
  4923. backgroundColor: 'window'
  4924. },
  4925. title: {
  4926. style: {
  4927. color: 'windowText'
  4928. }
  4929. },
  4930. subtitle: {
  4931. style: {
  4932. color: 'windowText'
  4933. }
  4934. },
  4935. colorAxis: {
  4936. minColor: 'windowText',
  4937. maxColor: 'windowText',
  4938. stops: []
  4939. },
  4940. colors: ['windowText'],
  4941. xAxis: {
  4942. gridLineColor: 'windowText',
  4943. labels: {
  4944. style: {
  4945. color: 'windowText'
  4946. }
  4947. },
  4948. lineColor: 'windowText',
  4949. minorGridLineColor: 'windowText',
  4950. tickColor: 'windowText',
  4951. title: {
  4952. style: {
  4953. color: 'windowText'
  4954. }
  4955. }
  4956. },
  4957. yAxis: {
  4958. gridLineColor: 'windowText',
  4959. labels: {
  4960. style: {
  4961. color: 'windowText'
  4962. }
  4963. },
  4964. lineColor: 'windowText',
  4965. minorGridLineColor: 'windowText',
  4966. tickColor: 'windowText',
  4967. title: {
  4968. style: {
  4969. color: 'windowText'
  4970. }
  4971. }
  4972. },
  4973. tooltip: {
  4974. backgroundColor: 'window',
  4975. borderColor: 'windowText',
  4976. style: {
  4977. color: 'windowText'
  4978. }
  4979. },
  4980. plotOptions: {
  4981. series: {
  4982. lineColor: 'windowText',
  4983. fillColor: 'window',
  4984. borderColor: 'windowText',
  4985. edgeColor: 'windowText',
  4986. borderWidth: 1,
  4987. dataLabels: {
  4988. connectorColor: 'windowText',
  4989. color: 'windowText',
  4990. style: {
  4991. color: 'windowText',
  4992. textOutline: 'none'
  4993. }
  4994. },
  4995. marker: {
  4996. lineColor: 'windowText',
  4997. fillColor: 'windowText'
  4998. }
  4999. },
  5000. pie: {
  5001. color: 'window',
  5002. colors: ['window'],
  5003. borderColor: 'windowText',
  5004. borderWidth: 1
  5005. },
  5006. boxplot: {
  5007. fillColor: 'window'
  5008. },
  5009. candlestick: {
  5010. lineColor: 'windowText',
  5011. fillColor: 'window'
  5012. },
  5013. errorbar: {
  5014. fillColor: 'window'
  5015. }
  5016. },
  5017. legend: {
  5018. backgroundColor: 'window',
  5019. itemStyle: {
  5020. color: 'windowText'
  5021. },
  5022. itemHoverStyle: {
  5023. color: 'windowText'
  5024. },
  5025. itemHiddenStyle: {
  5026. color: '#555'
  5027. },
  5028. title: {
  5029. style: {
  5030. color: 'windowText'
  5031. }
  5032. }
  5033. },
  5034. credits: {
  5035. style: {
  5036. color: 'windowText'
  5037. }
  5038. },
  5039. labels: {
  5040. style: {
  5041. color: 'windowText'
  5042. }
  5043. },
  5044. drilldown: {
  5045. activeAxisLabelStyle: {
  5046. color: 'windowText'
  5047. },
  5048. activeDataLabelStyle: {
  5049. color: 'windowText'
  5050. }
  5051. },
  5052. navigation: {
  5053. buttonOptions: {
  5054. symbolStroke: 'windowText',
  5055. theme: {
  5056. fill: 'window'
  5057. }
  5058. }
  5059. },
  5060. rangeSelector: {
  5061. buttonTheme: {
  5062. fill: 'window',
  5063. stroke: 'windowText',
  5064. style: {
  5065. color: 'windowText'
  5066. },
  5067. states: {
  5068. hover: {
  5069. fill: 'window',
  5070. stroke: 'windowText',
  5071. style: {
  5072. color: 'windowText'
  5073. }
  5074. },
  5075. select: {
  5076. fill: '#444',
  5077. stroke: 'windowText',
  5078. style: {
  5079. color: 'windowText'
  5080. }
  5081. }
  5082. }
  5083. },
  5084. inputBoxBorderColor: 'windowText',
  5085. inputStyle: {
  5086. backgroundColor: 'window',
  5087. color: 'windowText'
  5088. },
  5089. labelStyle: {
  5090. color: 'windowText'
  5091. }
  5092. },
  5093. navigator: {
  5094. handles: {
  5095. backgroundColor: 'window',
  5096. borderColor: 'windowText'
  5097. },
  5098. outlineColor: 'windowText',
  5099. maskFill: 'transparent',
  5100. series: {
  5101. color: 'windowText',
  5102. lineColor: 'windowText'
  5103. },
  5104. xAxis: {
  5105. gridLineColor: 'windowText'
  5106. }
  5107. },
  5108. scrollbar: {
  5109. barBackgroundColor: '#444',
  5110. barBorderColor: 'windowText',
  5111. buttonArrowColor: 'windowText',
  5112. buttonBackgroundColor: 'window',
  5113. buttonBorderColor: 'windowText',
  5114. rifleColor: 'windowText',
  5115. trackBackgroundColor: 'window',
  5116. trackBorderColor: 'windowText'
  5117. }
  5118. };
  5119. return theme;
  5120. });
  5121. _registerModule(_modules, 'modules/accessibility/options/options.js', [], function () {
  5122. /* *
  5123. *
  5124. * (c) 2009-2020 Øystein Moseng
  5125. *
  5126. * Default options for accessibility.
  5127. *
  5128. * License: www.highcharts.com/license
  5129. *
  5130. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5131. *
  5132. * */
  5133. /**
  5134. * Formatter callback for the accessibility announcement.
  5135. *
  5136. * @callback Highcharts.AccessibilityAnnouncementFormatter
  5137. *
  5138. * @param {Array<Highcharts.Series>} updatedSeries
  5139. * Array of all series that received updates. If an announcement is already
  5140. * queued, the series that received updates for that announcement are also
  5141. * included in this array.
  5142. *
  5143. * @param {Highcharts.Series} [addedSeries]
  5144. * This is provided if {@link Highcharts.Chart#addSeries} was called, and there
  5145. * is a new series. In that case, this argument is a reference to the new
  5146. * series.
  5147. *
  5148. * @param {Highcharts.Point} [addedPoint]
  5149. * This is provided if {@link Highcharts.Series#addPoint} was called, and there
  5150. * is a new point. In that case, this argument is a reference to the new point.
  5151. *
  5152. * @return {false|string}
  5153. * The function should return a string with the text to announce to the user.
  5154. * Return empty string to not announce anything. Return `false` to use the
  5155. * default announcement format.
  5156. */
  5157. /**
  5158. * @interface Highcharts.PointAccessibilityOptionsObject
  5159. */ /**
  5160. * Provide a description of the data point, announced to screen readers.
  5161. * @name Highcharts.PointAccessibilityOptionsObject#description
  5162. * @type {string|undefined}
  5163. * @requires modules/accessibility
  5164. * @since 7.1.0
  5165. */
  5166. /* *
  5167. * @interface Highcharts.PointOptionsObject in parts/Point.ts
  5168. */ /**
  5169. * @name Highcharts.PointOptionsObject#accessibility
  5170. * @type {Highcharts.PointAccessibilityOptionsObject|undefined}
  5171. * @requires modules/accessibility
  5172. * @since 7.1.0
  5173. */
  5174. /**
  5175. * @callback Highcharts.ScreenReaderClickCallbackFunction
  5176. *
  5177. * @param {global.MouseEvent} evt
  5178. * Mouse click event
  5179. *
  5180. * @return {void}
  5181. */
  5182. /**
  5183. * Creates a formatted string for the screen reader module.
  5184. *
  5185. * @callback Highcharts.ScreenReaderFormatterCallbackFunction<T>
  5186. *
  5187. * @param {T} context
  5188. * Context to format
  5189. *
  5190. * @return {string}
  5191. * Formatted string for the screen reader module.
  5192. */
  5193. var options = {
  5194. /**
  5195. * Options for configuring accessibility for the chart. Requires the
  5196. * [accessibility module](https://code.highcharts.com/modules/accessibility.js)
  5197. * to be loaded. For a description of the module and information
  5198. * on its features, see
  5199. * [Highcharts Accessibility](https://www.highcharts.com/docs/chart-concepts/accessibility).
  5200. *
  5201. * @since 5.0.0
  5202. * @requires modules/accessibility
  5203. * @optionparent accessibility
  5204. */
  5205. accessibility: {
  5206. /**
  5207. * Enable accessibility functionality for the chart.
  5208. *
  5209. * @since 5.0.0
  5210. */
  5211. enabled: true,
  5212. /**
  5213. * Accessibility options for the screen reader information sections
  5214. * added before and after the chart.
  5215. *
  5216. * @since 8.0.0
  5217. */
  5218. screenReaderSection: {
  5219. /**
  5220. * Function to run upon clicking the "View as Data Table" link in
  5221. * the screen reader region.
  5222. *
  5223. * By default Highcharts will insert and set focus to a data table
  5224. * representation of the chart.
  5225. *
  5226. * @type {Highcharts.ScreenReaderClickCallbackFunction}
  5227. * @since 8.0.0
  5228. * @apioption accessibility.screenReaderSection.onViewDataTableClick
  5229. */
  5230. /**
  5231. * Function to run upon clicking the "Play as sound" button in
  5232. * the screen reader region.
  5233. *
  5234. * By default Highcharts will call the `chart.sonify` function.
  5235. *
  5236. * @type {Highcharts.ScreenReaderClickCallbackFunction}
  5237. * @since 8.0.1
  5238. * @apioption accessibility.screenReaderSection.onPlayAsSoundClick
  5239. */
  5240. /**
  5241. * A formatter function to create the HTML contents of the hidden
  5242. * screen reader information region before the chart. Receives one
  5243. * argument, `chart`, referring to the chart object. Should return a
  5244. * string with the HTML content of the region. By default this
  5245. * returns an automatic description of the chart based on
  5246. * [beforeChartFormat](#accessibility.screenReaderSection.beforeChartFormat).
  5247. *
  5248. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Chart>}
  5249. * @since 8.0.0
  5250. * @apioption accessibility.screenReaderSection.beforeChartFormatter
  5251. */
  5252. /**
  5253. * Format for the screen reader information region before the chart.
  5254. * Supported HTML tags are `<h1-7>`, `<p>`, `<div>`, `<a>`, `<ul>`,
  5255. * `<ol>`, `<li>`, and `<button>`. Attributes are not supported,
  5256. * except for id on `<div>`, `<a>`, and `<button>`. Id is required
  5257. * on `<a>` and `<button>` in the format `<tag id="abcd">`. Numbers,
  5258. * lower- and uppercase letters, "-" and "#" are valid characters in
  5259. * IDs.
  5260. *
  5261. * @since 8.0.0
  5262. */
  5263. beforeChartFormat: '<h5>{chartTitle}</h5>' +
  5264. '<div>{typeDescription}</div>' +
  5265. '<div>{chartSubtitle}</div>' +
  5266. '<div>{chartLongdesc}</div>' +
  5267. '<div>{playAsSoundButton}</div>' +
  5268. '<div>{viewTableButton}</div>' +
  5269. '<div>{xAxisDescription}</div>' +
  5270. '<div>{yAxisDescription}</div>' +
  5271. '<div>{annotationsTitle}{annotationsList}</div>',
  5272. /**
  5273. * A formatter function to create the HTML contents of the hidden
  5274. * screen reader information region after the chart. Analogous to
  5275. * [beforeChartFormatter](#accessibility.screenReaderSection.beforeChartFormatter).
  5276. *
  5277. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Chart>}
  5278. * @since 8.0.0
  5279. * @apioption accessibility.screenReaderSection.afterChartFormatter
  5280. */
  5281. /**
  5282. * Format for the screen reader information region after the chart.
  5283. * Analogous to [beforeChartFormat](#accessibility.screenReaderSection.beforeChartFormat).
  5284. *
  5285. * @since 8.0.0
  5286. */
  5287. afterChartFormat: '{endOfChartMarker}',
  5288. /**
  5289. * Date format to use to describe range of datetime axes.
  5290. *
  5291. * For an overview of the replacement codes, see
  5292. * [dateFormat](/class-reference/Highcharts#dateFormat).
  5293. *
  5294. * @see [point.dateFormat](#accessibility.point.dateFormat)
  5295. *
  5296. * @since 8.0.0
  5297. */
  5298. axisRangeDateFormat: '%Y-%m-%d %H:%M:%S'
  5299. },
  5300. /**
  5301. * Accessibility options global to all data series. Individual series
  5302. * can also have specific [accessibility options](#plotOptions.series.accessibility)
  5303. * set.
  5304. *
  5305. * @since 8.0.0
  5306. */
  5307. series: {
  5308. /**
  5309. * Formatter function to use instead of the default for series
  5310. * descriptions. Receives one argument, `series`, referring to the
  5311. * series to describe. Should return a string with the description
  5312. * of the series for a screen reader user. If `false` is returned,
  5313. * the default formatter will be used for that series.
  5314. *
  5315. * @see [series.description](#plotOptions.series.description)
  5316. *
  5317. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Series>}
  5318. * @since 8.0.0
  5319. * @apioption accessibility.series.descriptionFormatter
  5320. */
  5321. /**
  5322. * Whether or not to add series descriptions to charts with a single
  5323. * series.
  5324. *
  5325. * @since 8.0.0
  5326. */
  5327. describeSingleSeries: false,
  5328. /**
  5329. * When a series contains more points than this, we no longer expose
  5330. * information about individual points to screen readers.
  5331. *
  5332. * Set to `false` to disable.
  5333. *
  5334. * @type {boolean|number}
  5335. * @since 8.0.0
  5336. */
  5337. pointDescriptionEnabledThreshold: 200
  5338. },
  5339. /**
  5340. * Options for descriptions of individual data points.
  5341. *
  5342. * @since 8.0.0
  5343. */
  5344. point: {
  5345. /**
  5346. * Date format to use for points on datetime axes when describing
  5347. * them to screen reader users.
  5348. *
  5349. * Defaults to the same format as in tooltip.
  5350. *
  5351. * For an overview of the replacement codes, see
  5352. * [dateFormat](/class-reference/Highcharts#dateFormat).
  5353. *
  5354. * @see [dateFormatter](#accessibility.point.dateFormatter)
  5355. *
  5356. * @type {string}
  5357. * @since 8.0.0
  5358. * @apioption accessibility.point.dateFormat
  5359. */
  5360. /**
  5361. * Formatter function to determine the date/time format used with
  5362. * points on datetime axes when describing them to screen reader
  5363. * users. Receives one argument, `point`, referring to the point
  5364. * to describe. Should return a date format string compatible with
  5365. * [dateFormat](/class-reference/Highcharts#dateFormat).
  5366. *
  5367. * @see [dateFormat](#accessibility.point.dateFormat)
  5368. *
  5369. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Point>}
  5370. * @since 8.0.0
  5371. * @apioption accessibility.point.dateFormatter
  5372. */
  5373. /**
  5374. * Prefix to add to the values in the point descriptions. Uses
  5375. * [tooltip.valuePrefix](#tooltip.valuePrefix) if not defined.
  5376. *
  5377. * @type {string}
  5378. * @since 8.0.0
  5379. * @apioption accessibility.point.valuePrefix
  5380. */
  5381. /**
  5382. * Suffix to add to the values in the point descriptions. Uses
  5383. * [tooltip.valueSuffix](#tooltip.valueSuffix) if not defined.
  5384. *
  5385. * @type {string}
  5386. * @since 8.0.0
  5387. * @apioption accessibility.point.valueSuffix
  5388. */
  5389. /**
  5390. * Decimals to use for the values in the point descriptions. Uses
  5391. * [tooltip.valueDecimals](#tooltip.valueDecimals) if not defined.
  5392. *
  5393. * @type {number}
  5394. * @since 8.0.0
  5395. * @apioption accessibility.point.valueDecimals
  5396. */
  5397. /**
  5398. * Formatter function to use instead of the default for point
  5399. * descriptions.
  5400. *
  5401. * Receives one argument, `point`, referring to the point to
  5402. * describe. Should return a string with the description of the
  5403. * point for a screen reader user. If `false` is returned, the
  5404. * default formatter will be used for that point.
  5405. *
  5406. * Note: Prefer using [accessibility.point.valueDescriptionFormat](#accessibility.point.valueDescriptionFormat)
  5407. * instead if possible, as default functionality such as describing
  5408. * annotations will be preserved.
  5409. *
  5410. * @see [accessibility.point.valueDescriptionFormat](#accessibility.point.valueDescriptionFormat)
  5411. * @see [point.accessibility.description](#series.line.data.accessibility.description)
  5412. *
  5413. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Point>}
  5414. * @since 8.0.0
  5415. * @apioption accessibility.point.descriptionFormatter
  5416. */
  5417. /**
  5418. * Format to use for describing the values of data points
  5419. * to assistive technology - including screen readers.
  5420. * The point context is available as `{point}`.
  5421. *
  5422. * Additionally, the series name, annotation info, and
  5423. * description added in `point.accessibility.description`
  5424. * is added by default if relevant. To override this, use the
  5425. * [accessibility.point.descriptionFormatter](#accessibility.point.descriptionFormatter)
  5426. * option.
  5427. *
  5428. * @see [point.accessibility.description](#series.line.data.accessibility.description)
  5429. * @see [accessibility.point.descriptionFormatter](#accessibility.point.descriptionFormatter)
  5430. *
  5431. * @type {string}
  5432. * @since 8.0.1
  5433. */
  5434. valueDescriptionFormat: '{index}. {xDescription}{separator}{value}.'
  5435. },
  5436. /**
  5437. * Amount of landmarks/regions to create for screen reader users. More
  5438. * landmarks can make navigation with screen readers easier, but can
  5439. * be distracting if there are lots of charts on the page. Three modes
  5440. * are available:
  5441. * - `all`: Adds regions for all series, legend, menu, information
  5442. * region.
  5443. * - `one`: Adds a single landmark per chart.
  5444. * - `disabled`: No landmarks are added.
  5445. *
  5446. * @since 7.1.0
  5447. * @validvalue ["all", "one", "disabled"]
  5448. */
  5449. landmarkVerbosity: 'all',
  5450. /**
  5451. * Link the chart to an HTML element describing the contents of the
  5452. * chart.
  5453. *
  5454. * It is always recommended to describe charts using visible text, to
  5455. * improve SEO as well as accessibility for users with disabilities.
  5456. * This option lets an HTML element with a description be linked to the
  5457. * chart, so that screen reader users can connect the two.
  5458. *
  5459. * By setting this option to a string, Highcharts runs the string as an
  5460. * HTML selector query on the entire document. If there is only a single
  5461. * match, this element is linked to the chart. The content of the linked
  5462. * element will be included in the chart description for screen reader
  5463. * users.
  5464. *
  5465. * By default, the chart looks for an adjacent sibling element with the
  5466. * `highcharts-description` class.
  5467. *
  5468. * The feature can be disabled by setting the option to an empty string,
  5469. * or overridden by providing the
  5470. * [accessibility.description](#accessibility.description) option.
  5471. * Alternatively, the HTML element to link can be passed in directly as
  5472. * an HTML node.
  5473. *
  5474. * If you need the description to be part of the exported image,
  5475. * consider using the [caption](#caption) feature.
  5476. *
  5477. * If you need the description to be hidden visually, use the
  5478. * [accessibility.description](#accessibility.description) option.
  5479. *
  5480. * @see [caption](#caption)
  5481. * @see [description](#accessibility.description)
  5482. * @see [typeDescription](#accessibility.typeDescription)
  5483. *
  5484. * @sample highcharts/accessibility/accessible-line
  5485. * Accessible line chart
  5486. *
  5487. * @type {string|Highcharts.HTMLDOMElement}
  5488. * @since 8.0.0
  5489. */
  5490. linkedDescription: '*[data-highcharts-chart="{index}"] + .highcharts-description',
  5491. /**
  5492. * A hook for adding custom components to the accessibility module.
  5493. * Should be an object mapping component names to instances of classes
  5494. * inheriting from the Highcharts.AccessibilityComponent base class.
  5495. * Remember to add the component to the
  5496. * [keyboardNavigation.order](#accessibility.keyboardNavigation.order)
  5497. * for the keyboard navigation to be usable.
  5498. *
  5499. * @sample highcharts/accessibility/custom-component
  5500. * Custom accessibility component
  5501. *
  5502. * @type {*}
  5503. * @since 7.1.0
  5504. * @apioption accessibility.customComponents
  5505. */
  5506. /**
  5507. * Theme to apply to the chart when Windows High Contrast Mode is
  5508. * detected. By default, a high contrast theme matching the high
  5509. * contrast system system colors is used.
  5510. *
  5511. * @type {*}
  5512. * @since 7.1.3
  5513. * @apioption accessibility.highContrastTheme
  5514. */
  5515. /**
  5516. * A text description of the chart.
  5517. *
  5518. * **Note: Prefer using [linkedDescription](#accessibility.linkedDescription)
  5519. * or [caption](#caption.text) instead.**
  5520. *
  5521. * If the Accessibility module is loaded, this option is included by
  5522. * default as a long description of the chart in the hidden screen
  5523. * reader information region.
  5524. *
  5525. * Note: Since Highcharts now supports captions and linked descriptions,
  5526. * it is preferred to define the description using those methods, as a
  5527. * visible caption/description benefits all users. If the
  5528. * `accessibility.description` option is defined, the linked description
  5529. * is ignored, and the caption is hidden from screen reader users.
  5530. *
  5531. * @see [linkedDescription](#accessibility.linkedDescription)
  5532. * @see [caption](#caption)
  5533. * @see [typeDescription](#accessibility.typeDescription)
  5534. *
  5535. * @type {string}
  5536. * @since 5.0.0
  5537. * @apioption accessibility.description
  5538. */
  5539. /**
  5540. * A text description of the chart type.
  5541. *
  5542. * If the Accessibility module is loaded, this will be included in the
  5543. * description of the chart in the screen reader information region.
  5544. *
  5545. * Highcharts will by default attempt to guess the chart type, but for
  5546. * more complex charts it is recommended to specify this property for
  5547. * clarity.
  5548. *
  5549. * @type {string}
  5550. * @since 5.0.0
  5551. * @apioption accessibility.typeDescription
  5552. */
  5553. /**
  5554. * Options for keyboard navigation.
  5555. *
  5556. * @declare Highcharts.KeyboardNavigationOptionsObject
  5557. * @since 5.0.0
  5558. */
  5559. keyboardNavigation: {
  5560. /**
  5561. * Enable keyboard navigation for the chart.
  5562. *
  5563. * @since 5.0.0
  5564. */
  5565. enabled: true,
  5566. /**
  5567. * Options for the focus border drawn around elements while
  5568. * navigating through them.
  5569. *
  5570. * @sample highcharts/accessibility/custom-focus
  5571. * Custom focus ring
  5572. *
  5573. * @declare Highcharts.KeyboardNavigationFocusBorderOptionsObject
  5574. * @since 6.0.3
  5575. */
  5576. focusBorder: {
  5577. /**
  5578. * Enable/disable focus border for chart.
  5579. *
  5580. * @since 6.0.3
  5581. */
  5582. enabled: true,
  5583. /**
  5584. * Hide the browser's default focus indicator.
  5585. *
  5586. * @since 6.0.4
  5587. */
  5588. hideBrowserFocusOutline: true,
  5589. /**
  5590. * Style options for the focus border drawn around elements
  5591. * while navigating through them. Note that some browsers in
  5592. * addition draw their own borders for focused elements. These
  5593. * automatic borders can not be styled by Highcharts.
  5594. *
  5595. * In styled mode, the border is given the
  5596. * `.highcharts-focus-border` class.
  5597. *
  5598. * @type {Highcharts.CSSObject}
  5599. * @since 6.0.3
  5600. */
  5601. style: {
  5602. /** @internal */
  5603. color: '#335cad',
  5604. /** @internal */
  5605. lineWidth: 2,
  5606. /** @internal */
  5607. borderRadius: 3
  5608. },
  5609. /**
  5610. * Focus border margin around the elements.
  5611. *
  5612. * @since 6.0.3
  5613. */
  5614. margin: 2
  5615. },
  5616. /**
  5617. * Order of tab navigation in the chart. Determines which elements
  5618. * are tabbed to first. Available elements are: `series`, `zoom`,
  5619. * `rangeSelector`, `chartMenu`, `legend`. In addition, any custom
  5620. * components can be added here.
  5621. *
  5622. * @type {Array<string>}
  5623. * @since 7.1.0
  5624. */
  5625. order: ['series', 'zoom', 'rangeSelector', 'legend', 'chartMenu'],
  5626. /**
  5627. * Whether or not to wrap around when reaching the end of arrow-key
  5628. * navigation for an element in the chart.
  5629. * @since 7.1.0
  5630. */
  5631. wrapAround: true,
  5632. /**
  5633. * Options for the keyboard navigation of data points and series.
  5634. *
  5635. * @declare Highcharts.KeyboardNavigationSeriesNavigationOptionsObject
  5636. * @since 8.0.0
  5637. */
  5638. seriesNavigation: {
  5639. /**
  5640. * Set the keyboard navigation mode for the chart. Can be
  5641. * "normal" or "serialize". In normal mode, left/right arrow
  5642. * keys move between points in a series, while up/down arrow
  5643. * keys move between series. Up/down navigation acts
  5644. * intelligently to figure out which series makes sense to move
  5645. * to from any given point.
  5646. *
  5647. * In "serialize" mode, points are instead navigated as a single
  5648. * list. Left/right behaves as in "normal" mode. Up/down arrow
  5649. * keys will behave like left/right. This can be useful for
  5650. * unifying navigation behavior with/without screen readers
  5651. * enabled.
  5652. *
  5653. * @type {string}
  5654. * @default normal
  5655. * @since 8.0.0
  5656. * @validvalue ["normal", "serialize"]
  5657. * @apioption accessibility.keyboardNavigation.seriesNavigation.mode
  5658. */
  5659. /**
  5660. * Skip null points when navigating through points with the
  5661. * keyboard.
  5662. *
  5663. * @since 8.0.0
  5664. */
  5665. skipNullPoints: true,
  5666. /**
  5667. * When a series contains more points than this, we no longer
  5668. * allow keyboard navigation for it.
  5669. *
  5670. * Set to `false` to disable.
  5671. *
  5672. * @type {boolean|number}
  5673. * @since 8.0.0
  5674. */
  5675. pointNavigationEnabledThreshold: false
  5676. }
  5677. },
  5678. /**
  5679. * Options for announcing new data to screen reader users. Useful
  5680. * for dynamic data applications and drilldown.
  5681. *
  5682. * Keep in mind that frequent announcements will not be useful to
  5683. * users, as they won't have time to explore the new data. For these
  5684. * applications, consider making snapshots of the data accessible, and
  5685. * do the announcements in batches.
  5686. *
  5687. * @declare Highcharts.AccessibilityAnnounceNewDataOptionsObject
  5688. * @since 7.1.0
  5689. */
  5690. announceNewData: {
  5691. /**
  5692. * Optional formatter callback for the announcement. Receives
  5693. * up to three arguments. The first argument is always an array
  5694. * of all series that received updates. If an announcement is
  5695. * already queued, the series that received updates for that
  5696. * announcement are also included in this array. The second
  5697. * argument is provided if `chart.addSeries` was called, and
  5698. * there is a new series. In that case, this argument is a
  5699. * reference to the new series. The third argument, similarly,
  5700. * is provided if `series.addPoint` was called, and there is a
  5701. * new point. In that case, this argument is a reference to the
  5702. * new point.
  5703. *
  5704. * The function should return a string with the text to announce
  5705. * to the user. Return empty string to not announce anything.
  5706. * Return `false` to use the default announcement format.
  5707. *
  5708. * @sample highcharts/accessibility/custom-dynamic
  5709. * High priority live alerts
  5710. *
  5711. * @type {Highcharts.AccessibilityAnnouncementFormatter}
  5712. * @apioption accessibility.announceNewData.announcementFormatter
  5713. */
  5714. /**
  5715. * Enable announcing new data to screen reader users
  5716. * @sample highcharts/accessibility/accessible-dynamic
  5717. * Dynamic data accessible
  5718. */
  5719. enabled: false,
  5720. /**
  5721. * Minimum interval between announcements in milliseconds. If
  5722. * new data arrives before this amount of time has passed, it is
  5723. * queued for announcement. If another new data event happens
  5724. * while an announcement is queued, the queued announcement is
  5725. * dropped, and the latest announcement is queued instead. Set
  5726. * to 0 to allow all announcements, but be warned that frequent
  5727. * announcements are disturbing to users.
  5728. */
  5729. minAnnounceInterval: 5000,
  5730. /**
  5731. * Choose whether or not the announcements should interrupt the
  5732. * screen reader. If not enabled, the user will be notified once
  5733. * idle. It is recommended not to enable this setting unless
  5734. * there is a specific reason to do so.
  5735. */
  5736. interruptUser: false
  5737. }
  5738. },
  5739. /**
  5740. * Accessibility options for a data point.
  5741. *
  5742. * @declare Highcharts.PointAccessibilityOptionsObject
  5743. * @since 7.1.0
  5744. * @apioption series.line.data.accessibility
  5745. */
  5746. /**
  5747. * Provide a description of the data point, announced to screen readers.
  5748. *
  5749. * @type {string}
  5750. * @since 7.1.0
  5751. * @apioption series.line.data.accessibility.description
  5752. */
  5753. /**
  5754. * Accessibility options for a series.
  5755. *
  5756. * @declare Highcharts.SeriesAccessibilityOptionsObject
  5757. * @since 7.1.0
  5758. * @requires modules/accessibility
  5759. * @apioption plotOptions.series.accessibility
  5760. */
  5761. /**
  5762. * Enable/disable accessibility functionality for a specific series.
  5763. *
  5764. * @type {boolean}
  5765. * @since 7.1.0
  5766. * @apioption plotOptions.series.accessibility.enabled
  5767. */
  5768. /**
  5769. * Provide a description of the series, announced to screen readers.
  5770. *
  5771. * @type {string}
  5772. * @since 7.1.0
  5773. * @apioption plotOptions.series.accessibility.description
  5774. */
  5775. /**
  5776. * Formatter function to use instead of the default for point
  5777. * descriptions. Same as `accessibility.point.descriptionFormatter`, but for
  5778. * a single series.
  5779. *
  5780. * @see [accessibility.point.descriptionFormatter](#accessibility.point.descriptionFormatter)
  5781. *
  5782. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Point>}
  5783. * @since 7.1.0
  5784. * @apioption plotOptions.series.accessibility.pointDescriptionFormatter
  5785. */
  5786. /**
  5787. * Expose only the series element to screen readers, not its points.
  5788. *
  5789. * @type {boolean}
  5790. * @since 7.1.0
  5791. * @apioption plotOptions.series.accessibility.exposeAsGroupOnly
  5792. */
  5793. /**
  5794. * Keyboard navigation for a series
  5795. *
  5796. * @declare Highcharts.SeriesAccessibilityKeyboardNavigationOptionsObject
  5797. * @since 7.1.0
  5798. * @apioption plotOptions.series.accessibility.keyboardNavigation
  5799. */
  5800. /**
  5801. * Enable/disable keyboard navigation support for a specific series.
  5802. *
  5803. * @type {boolean}
  5804. * @since 7.1.0
  5805. * @apioption plotOptions.series.accessibility.keyboardNavigation.enabled
  5806. */
  5807. /**
  5808. * Accessibility options for an annotation label.
  5809. *
  5810. * @declare Highcharts.AnnotationLabelAccessibilityOptionsObject
  5811. * @since 8.0.1
  5812. * @requires modules/accessibility
  5813. * @apioption annotations.labelOptions.accessibility
  5814. */
  5815. /**
  5816. * Description of an annotation label for screen readers and other assistive
  5817. * technology.
  5818. *
  5819. * @type {string}
  5820. * @since 8.0.1
  5821. * @apioption annotations.labelOptions.accessibility.description
  5822. */
  5823. /**
  5824. * Accessibility options for an axis. Requires the accessibility module.
  5825. *
  5826. * @declare Highcharts.AxisAccessibilityOptionsObject
  5827. * @since 7.1.0
  5828. * @requires modules/accessibility
  5829. * @apioption xAxis.accessibility
  5830. */
  5831. /**
  5832. * Enable axis accessibility features, including axis information in the
  5833. * screen reader information region. If this is disabled on the xAxis, the
  5834. * x values are not exposed to screen readers for the individual data points
  5835. * by default.
  5836. *
  5837. * @type {boolean}
  5838. * @since 7.1.0
  5839. * @apioption xAxis.accessibility.enabled
  5840. */
  5841. /**
  5842. * Description for an axis to expose to screen reader users.
  5843. *
  5844. * @type {string}
  5845. * @since 7.1.0
  5846. * @apioption xAxis.accessibility.description
  5847. */
  5848. /**
  5849. * Range description for an axis. Overrides the default range description.
  5850. * Set to empty to disable range description for this axis.
  5851. *
  5852. * @type {string}
  5853. * @since 7.1.0
  5854. * @apioption xAxis.accessibility.rangeDescription
  5855. */
  5856. /**
  5857. * @optionparent legend
  5858. */
  5859. legend: {
  5860. /**
  5861. * Accessibility options for the legend. Requires the Accessibility
  5862. * module.
  5863. *
  5864. * @since 7.1.0
  5865. * @requires modules/accessibility
  5866. */
  5867. accessibility: {
  5868. /**
  5869. * Enable accessibility support for the legend.
  5870. *
  5871. * @since 7.1.0
  5872. */
  5873. enabled: true,
  5874. /**
  5875. * Options for keyboard navigation for the legend.
  5876. *
  5877. * @since 7.1.0
  5878. * @requires modules/accessibility
  5879. */
  5880. keyboardNavigation: {
  5881. /**
  5882. * Enable keyboard navigation for the legend.
  5883. *
  5884. * @see [accessibility.keyboardNavigation](#accessibility.keyboardNavigation.enabled)
  5885. *
  5886. * @since 7.1.0
  5887. */
  5888. enabled: true
  5889. }
  5890. }
  5891. },
  5892. /**
  5893. * @optionparent exporting
  5894. */
  5895. exporting: {
  5896. /**
  5897. * Accessibility options for the exporting menu. Requires the
  5898. * Accessibility module.
  5899. *
  5900. * @since 7.1.0
  5901. * @requires modules/accessibility
  5902. */
  5903. accessibility: {
  5904. /**
  5905. * Enable accessibility support for the export menu.
  5906. *
  5907. * @since 7.1.0
  5908. */
  5909. enabled: true
  5910. }
  5911. }
  5912. };
  5913. return options;
  5914. });
  5915. _registerModule(_modules, 'modules/accessibility/options/langOptions.js', [], function () {
  5916. /* *
  5917. *
  5918. * (c) 2009-2020 Øystein Moseng
  5919. *
  5920. * Default lang/i18n options for accessibility.
  5921. *
  5922. * License: www.highcharts.com/license
  5923. *
  5924. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5925. *
  5926. * */
  5927. var langOptions = {
  5928. /**
  5929. * Configure the accessibility strings in the chart. Requires the
  5930. * [accessibility module](https://code.highcharts.com/modules/accessibility.js)
  5931. * to be loaded. For a description of the module and information on its
  5932. * features, see
  5933. * [Highcharts Accessibility](https://www.highcharts.com/docs/chart-concepts/accessibility).
  5934. *
  5935. * For more dynamic control over the accessibility functionality, see
  5936. * [accessibility.pointDescriptionFormatter](#accessibility.pointDescriptionFormatter),
  5937. * [accessibility.seriesDescriptionFormatter](#accessibility.seriesDescriptionFormatter),
  5938. * and
  5939. * [accessibility.screenReaderSectionFormatter](#accessibility.screenReaderSectionFormatter).
  5940. *
  5941. * @since 6.0.6
  5942. * @optionparent lang.accessibility
  5943. */
  5944. accessibility: {
  5945. defaultChartTitle: 'Chart',
  5946. chartContainerLabel: '{title}. Highcharts interactive chart.',
  5947. svgContainerLabel: 'Interactive chart',
  5948. drillUpButton: '{buttonText}',
  5949. credits: 'Chart credits: {creditsStr}',
  5950. /**
  5951. * Thousands separator to use when formatting numbers for screen
  5952. * readers. Note that many screen readers will not handle space as a
  5953. * thousands separator, and will consider "11 700" as two numbers.
  5954. *
  5955. * Set to `null` to use the separator defined in
  5956. * [lang.thousandsSep](lang.thousandsSep).
  5957. *
  5958. * @since 7.1.0
  5959. */
  5960. thousandsSep: ',',
  5961. /**
  5962. * Title element text for the chart SVG element. Leave this
  5963. * empty to disable adding the title element. Browsers will display
  5964. * this content when hovering over elements in the chart. Assistive
  5965. * technology may use this element to label the chart.
  5966. *
  5967. * @since 6.0.8
  5968. */
  5969. svgContainerTitle: '',
  5970. /**
  5971. * Set a label on the container wrapping the SVG.
  5972. *
  5973. * @see [chartContainerLabel](#lang.accessibility.chartContainerLabel)
  5974. *
  5975. * @since 8.0.0
  5976. */
  5977. graphicContainerLabel: '',
  5978. /**
  5979. * Language options for the screen reader information sections added
  5980. * before and after the charts.
  5981. *
  5982. * @since 8.0.0
  5983. */
  5984. screenReaderSection: {
  5985. beforeRegionLabel: 'Chart screen reader information.',
  5986. afterRegionLabel: '',
  5987. /**
  5988. * Language options for annotation descriptions.
  5989. *
  5990. * @since 8.0.1
  5991. */
  5992. annotations: {
  5993. heading: 'Chart annotations summary',
  5994. descriptionSinglePoint: '{annotationText}. Related to {annotationPoint}',
  5995. descriptionMultiplePoints: '{annotationText}. Related to {annotationPoint}' +
  5996. '{ Also related to, #each(additionalAnnotationPoints)}',
  5997. descriptionNoPoints: '{annotationText}'
  5998. },
  5999. /**
  6000. * Label for the end of the chart. Announced by screen readers.
  6001. *
  6002. * @since 8.0.0
  6003. */
  6004. endOfChartMarker: 'End of interactive chart.'
  6005. },
  6006. /**
  6007. * Language options for sonification.
  6008. *
  6009. * @since 8.0.1
  6010. */
  6011. sonification: {
  6012. playAsSoundButtonText: 'Play as sound, {chartTitle}',
  6013. playAsSoundClickAnnouncement: 'Play'
  6014. },
  6015. /**
  6016. * Language options for accessibility of the legend.
  6017. *
  6018. * @since 8.0.0
  6019. */
  6020. legend: {
  6021. legendLabel: 'Toggle series visibility',
  6022. legendItem: 'Toggle visibility of {itemName}'
  6023. },
  6024. /**
  6025. * Chart and map zoom accessibility language options.
  6026. *
  6027. * @since 8.0.0
  6028. */
  6029. zoom: {
  6030. mapZoomIn: 'Zoom chart',
  6031. mapZoomOut: 'Zoom out chart',
  6032. resetZoomButton: 'Reset zoom'
  6033. },
  6034. /**
  6035. * Range selector language options for accessibility.
  6036. *
  6037. * @since 8.0.0
  6038. */
  6039. rangeSelector: {
  6040. minInputLabel: 'Select start date.',
  6041. maxInputLabel: 'Select end date.',
  6042. buttonText: 'Select range {buttonText}'
  6043. },
  6044. /**
  6045. * Accessibility language options for the data table.
  6046. *
  6047. * @since 8.0.0
  6048. */
  6049. table: {
  6050. viewAsDataTableButtonText: 'View as data table, {chartTitle}',
  6051. tableSummary: 'Table representation of chart.'
  6052. },
  6053. /**
  6054. * Default announcement for new data in charts. If addPoint or
  6055. * addSeries is used, and only one series/point is added, the
  6056. * `newPointAnnounce` and `newSeriesAnnounce` strings are used.
  6057. * The `...Single` versions will be used if there is only one chart
  6058. * on the page, and the `...Multiple` versions will be used if there
  6059. * are multiple charts on the page. For all other new data events,
  6060. * the `newDataAnnounce` string will be used.
  6061. *
  6062. * @since 7.1.0
  6063. */
  6064. announceNewData: {
  6065. newDataAnnounce: 'Updated data for chart {chartTitle}',
  6066. newSeriesAnnounceSingle: 'New data series: {seriesDesc}',
  6067. newPointAnnounceSingle: 'New data point: {pointDesc}',
  6068. newSeriesAnnounceMultiple: 'New data series in chart {chartTitle}: {seriesDesc}',
  6069. newPointAnnounceMultiple: 'New data point in chart {chartTitle}: {pointDesc}'
  6070. },
  6071. /**
  6072. * Descriptions of lesser known series types. The relevant
  6073. * description is added to the screen reader information region
  6074. * when these series types are used.
  6075. *
  6076. * @since 6.0.6
  6077. */
  6078. seriesTypeDescriptions: {
  6079. boxplot: 'Box plot charts are typically used to display ' +
  6080. 'groups of statistical data. Each data point in the ' +
  6081. 'chart can have up to 5 values: minimum, lower quartile, ' +
  6082. 'median, upper quartile, and maximum.',
  6083. arearange: 'Arearange charts are line charts displaying a ' +
  6084. 'range between a lower and higher value for each point.',
  6085. areasplinerange: 'These charts are line charts displaying a ' +
  6086. 'range between a lower and higher value for each point.',
  6087. bubble: 'Bubble charts are scatter charts where each data ' +
  6088. 'point also has a size value.',
  6089. columnrange: 'Columnrange charts are column charts ' +
  6090. 'displaying a range between a lower and higher value for ' +
  6091. 'each point.',
  6092. errorbar: 'Errorbar series are used to display the ' +
  6093. 'variability of the data.',
  6094. funnel: 'Funnel charts are used to display reduction of data ' +
  6095. 'in stages.',
  6096. pyramid: 'Pyramid charts consist of a single pyramid with ' +
  6097. 'item heights corresponding to each point value.',
  6098. waterfall: 'A waterfall chart is a column chart where each ' +
  6099. 'column contributes towards a total end value.'
  6100. },
  6101. /**
  6102. * Chart type description strings. This is added to the chart
  6103. * information region.
  6104. *
  6105. * If there is only a single series type used in the chart, we use
  6106. * the format string for the series type, or default if missing.
  6107. * There is one format string for cases where there is only a single
  6108. * series in the chart, and one for multiple series of the same
  6109. * type.
  6110. *
  6111. * @since 6.0.6
  6112. */
  6113. chartTypes: {
  6114. /* eslint-disable max-len */
  6115. emptyChart: 'Empty chart',
  6116. mapTypeDescription: 'Map of {mapTitle} with {numSeries} data series.',
  6117. unknownMap: 'Map of unspecified region with {numSeries} data series.',
  6118. combinationChart: 'Combination chart with {numSeries} data series.',
  6119. defaultSingle: 'Chart with {numPoints} data {#plural(numPoints, points, point)}.',
  6120. defaultMultiple: 'Chart with {numSeries} data series.',
  6121. splineSingle: 'Line chart with {numPoints} data {#plural(numPoints, points, point)}.',
  6122. splineMultiple: 'Line chart with {numSeries} lines.',
  6123. lineSingle: 'Line chart with {numPoints} data {#plural(numPoints, points, point)}.',
  6124. lineMultiple: 'Line chart with {numSeries} lines.',
  6125. columnSingle: 'Bar chart with {numPoints} {#plural(numPoints, bars, bar)}.',
  6126. columnMultiple: 'Bar chart with {numSeries} data series.',
  6127. barSingle: 'Bar chart with {numPoints} {#plural(numPoints, bars, bar)}.',
  6128. barMultiple: 'Bar chart with {numSeries} data series.',
  6129. pieSingle: 'Pie chart with {numPoints} {#plural(numPoints, slices, slice)}.',
  6130. pieMultiple: 'Pie chart with {numSeries} pies.',
  6131. scatterSingle: 'Scatter chart with {numPoints} {#plural(numPoints, points, point)}.',
  6132. scatterMultiple: 'Scatter chart with {numSeries} data series.',
  6133. boxplotSingle: 'Boxplot with {numPoints} {#plural(numPoints, boxes, box)}.',
  6134. boxplotMultiple: 'Boxplot with {numSeries} data series.',
  6135. bubbleSingle: 'Bubble chart with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  6136. bubbleMultiple: 'Bubble chart with {numSeries} data series.'
  6137. },
  6138. /**
  6139. * Axis description format strings.
  6140. *
  6141. * @since 6.0.6
  6142. */
  6143. axis: {
  6144. /* eslint-disable max-len */
  6145. xAxisDescriptionSingular: 'The chart has 1 X axis displaying {names[0]}. {ranges[0]}',
  6146. xAxisDescriptionPlural: 'The chart has {numAxes} X axes displaying {#each(names, -1) }and {names[-1]}.',
  6147. yAxisDescriptionSingular: 'The chart has 1 Y axis displaying {names[0]}. {ranges[0]}',
  6148. yAxisDescriptionPlural: 'The chart has {numAxes} Y axes displaying {#each(names, -1) }and {names[-1]}.',
  6149. timeRangeDays: 'Range: {range} days.',
  6150. timeRangeHours: 'Range: {range} hours.',
  6151. timeRangeMinutes: 'Range: {range} minutes.',
  6152. timeRangeSeconds: 'Range: {range} seconds.',
  6153. rangeFromTo: 'Range: {rangeFrom} to {rangeTo}.',
  6154. rangeCategories: 'Range: {numCategories} categories.'
  6155. },
  6156. /**
  6157. * Exporting menu format strings for accessibility module.
  6158. *
  6159. * @since 6.0.6
  6160. */
  6161. exporting: {
  6162. chartMenuLabel: 'Chart menu',
  6163. menuButtonLabel: 'View chart menu',
  6164. exportRegionLabel: 'Chart menu'
  6165. },
  6166. /**
  6167. * Lang configuration for different series types. For more dynamic
  6168. * control over the series element descriptions, see
  6169. * [accessibility.seriesDescriptionFormatter](#accessibility.seriesDescriptionFormatter).
  6170. *
  6171. * @since 6.0.6
  6172. */
  6173. series: {
  6174. /**
  6175. * Lang configuration for the series main summary. Each series
  6176. * type has two modes:
  6177. *
  6178. * 1. This series type is the only series type used in the
  6179. * chart
  6180. *
  6181. * 2. This is a combination chart with multiple series types
  6182. *
  6183. * If a definition does not exist for the specific series type
  6184. * and mode, the 'default' lang definitions are used.
  6185. *
  6186. * @since 6.0.6
  6187. */
  6188. summary: {
  6189. /* eslint-disable max-len */
  6190. 'default': '{name}, series {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  6191. defaultCombination: '{name}, series {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  6192. line: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  6193. lineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
  6194. spline: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  6195. splineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
  6196. column: '{name}, bar series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bars, bar)}.',
  6197. columnCombination: '{name}, series {ix} of {numSeries}. Bar series with {numPoints} {#plural(numPoints, bars, bar)}.',
  6198. bar: '{name}, bar series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bars, bar)}.',
  6199. barCombination: '{name}, series {ix} of {numSeries}. Bar series with {numPoints} {#plural(numPoints, bars, bar)}.',
  6200. pie: '{name}, pie {ix} of {numSeries} with {numPoints} {#plural(numPoints, slices, slice)}.',
  6201. pieCombination: '{name}, series {ix} of {numSeries}. Pie with {numPoints} {#plural(numPoints, slices, slice)}.',
  6202. scatter: '{name}, scatter plot {ix} of {numSeries} with {numPoints} {#plural(numPoints, points, point)}.',
  6203. scatterCombination: '{name}, series {ix} of {numSeries}, scatter plot with {numPoints} {#plural(numPoints, points, point)}.',
  6204. boxplot: '{name}, boxplot {ix} of {numSeries} with {numPoints} {#plural(numPoints, boxes, box)}.',
  6205. boxplotCombination: '{name}, series {ix} of {numSeries}. Boxplot with {numPoints} {#plural(numPoints, boxes, box)}.',
  6206. bubble: '{name}, bubble series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  6207. bubbleCombination: '{name}, series {ix} of {numSeries}. Bubble series with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  6208. map: '{name}, map {ix} of {numSeries} with {numPoints} {#plural(numPoints, areas, area)}.',
  6209. mapCombination: '{name}, series {ix} of {numSeries}. Map with {numPoints} {#plural(numPoints, areas, area)}.',
  6210. mapline: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  6211. maplineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
  6212. mapbubble: '{name}, bubble series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  6213. mapbubbleCombination: '{name}, series {ix} of {numSeries}. Bubble series with {numPoints} {#plural(numPoints, bubbles, bubble)}.'
  6214. },
  6215. /**
  6216. * User supplied description text. This is added in the point
  6217. * comment description by default if present.
  6218. *
  6219. * @since 6.0.6
  6220. */
  6221. description: '{description}',
  6222. /**
  6223. * xAxis description for series if there are multiple xAxes in
  6224. * the chart.
  6225. *
  6226. * @since 6.0.6
  6227. */
  6228. xAxisDescription: 'X axis, {name}',
  6229. /**
  6230. * yAxis description for series if there are multiple yAxes in
  6231. * the chart.
  6232. *
  6233. * @since 6.0.6
  6234. */
  6235. yAxisDescription: 'Y axis, {name}',
  6236. /**
  6237. * Description for the value of null points.
  6238. *
  6239. * @since 8.0.0
  6240. */
  6241. nullPointValue: 'No value',
  6242. /**
  6243. * Description for annotations on a point, as it is made available
  6244. * to assistive technology.
  6245. *
  6246. * @since 8.0.1
  6247. */
  6248. pointAnnotationsDescription: '{Annotation: #each(annotations). }'
  6249. }
  6250. }
  6251. };
  6252. return langOptions;
  6253. });
  6254. _registerModule(_modules, 'modules/accessibility/options/deprecatedOptions.js', [_modules['parts/Utilities.js']], function (U) {
  6255. /* *
  6256. *
  6257. * (c) 2009-2020 Øystein Moseng
  6258. *
  6259. * Default options for accessibility.
  6260. *
  6261. * License: www.highcharts.com/license
  6262. *
  6263. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6264. *
  6265. * */
  6266. /* eslint-disable max-len */
  6267. /*
  6268. * List of deprecated options:
  6269. *
  6270. * chart.description -> accessibility.description
  6271. * chart.typeDescription -> accessibility.typeDescription
  6272. * series.description -> series.accessibility.description
  6273. * series.exposeElementToA11y -> series.accessibility.exposeAsGroupOnly
  6274. * series.pointDescriptionFormatter ->
  6275. * series.accessibility.pointDescriptionFormatter
  6276. * series.skipKeyboardNavigation ->
  6277. * series.accessibility.keyboardNavigation.enabled
  6278. * point.description -> point.accessibility.description !!!! WARNING: No longer deprecated and handled, removed for HC8.
  6279. * axis.description -> axis.accessibility.description
  6280. *
  6281. * accessibility.pointDateFormat -> accessibility.point.dateFormat
  6282. * accessibility.addTableShortcut -> Handled by screenReaderSection.beforeChartFormat
  6283. * accessibility.pointDateFormatter -> accessibility.point.dateFormatter
  6284. * accessibility.pointDescriptionFormatter -> accessibility.point.descriptionFormatter
  6285. * accessibility.pointDescriptionThreshold -> accessibility.series.pointDescriptionEnabledThreshold
  6286. * accessibility.pointNavigationThreshold -> accessibility.keyboardNavigation.seriesNavigation.pointNavigationEnabledThreshold
  6287. * accessibility.pointValueDecimals -> accessibility.point.valueDecimals
  6288. * accessibility.pointValuePrefix -> accessibility.point.valuePrefix
  6289. * accessibility.pointValueSuffix -> accessibility.point.valueSuffix
  6290. * accessibility.screenReaderSectionFormatter -> accessibility.screenReaderSection.beforeChartFormatter
  6291. * accessibility.describeSingleSeries -> accessibility.series.describeSingleSeries
  6292. * accessibility.seriesDescriptionFormatter -> accessibility.series.descriptionFormatter
  6293. * accessibility.onTableAnchorClick -> accessibility.screenReaderSection.onViewDataTableClick
  6294. * accessibility.axisRangeDateFormat -> accessibility.screenReaderSection.axisRangeDateFormat
  6295. * accessibility.keyboardNavigation.skipNullPoints -> accessibility.keyboardNavigation.seriesNavigation.skipNullPoints
  6296. * accessibility.keyboardNavigation.mode -> accessibility.keyboardNavigation.seriesNavigation.mode
  6297. *
  6298. * lang.accessibility.chartHeading -> no longer used, remove
  6299. * lang.accessibility.legendItem -> lang.accessibility.legend.legendItem
  6300. * lang.accessibility.legendLabel -> lang.accessibility.legend.legendLabel
  6301. * lang.accessibility.mapZoomIn -> lang.accessibility.zoom.mapZoomIn
  6302. * lang.accessibility.mapZoomOut -> lang.accessibility.zoom.mapZoomOut
  6303. * lang.accessibility.resetZoomButton -> lang.accessibility.zoom.resetZoomButton
  6304. * lang.accessibility.screenReaderRegionLabel -> lang.accessibility.screenReaderSection.beforeRegionLabel
  6305. * lang.accessibility.rangeSelectorButton -> lang.accessibility.rangeSelector.buttonText
  6306. * lang.accessibility.rangeSelectorMaxInput -> lang.accessibility.rangeSelector.maxInputLabel
  6307. * lang.accessibility.rangeSelectorMinInput -> lang.accessibility.rangeSelector.minInputLabel
  6308. * lang.accessibility.svgContainerEnd -> lang.accessibility.screenReaderSection.endOfChartMarker
  6309. * lang.accessibility.viewAsDataTable -> lang.accessibility.table.viewAsDataTableButtonText
  6310. * lang.accessibility.tableSummary -> lang.accessibility.table.tableSummary
  6311. *
  6312. */
  6313. /* eslint-enable max-len */
  6314. var error = U.error, pick = U.pick;
  6315. /* eslint-disable valid-jsdoc */
  6316. /**
  6317. * Set a new option on a root prop, where the option is defined as an array of
  6318. * suboptions.
  6319. * @private
  6320. * @param root
  6321. * @param {Array<string>} optionAsArray
  6322. * @param {*} val
  6323. * @return {void}
  6324. */
  6325. function traverseSetOption(root, optionAsArray, val) {
  6326. var opt = root, prop, i = 0;
  6327. for (; i < optionAsArray.length - 1; ++i) {
  6328. prop = optionAsArray[i];
  6329. opt = opt[prop] = pick(opt[prop], {});
  6330. }
  6331. opt[optionAsArray[optionAsArray.length - 1]] = val;
  6332. }
  6333. /**
  6334. * If we have a clear root option node for old and new options and a mapping
  6335. * between, we can use this generic function for the copy and warn logic.
  6336. */
  6337. function deprecateFromOptionsMap(chart, rootOldAsArray, rootNewAsArray, mapToNewOptions) {
  6338. /**
  6339. * @private
  6340. */
  6341. function getChildProp(root, propAsArray) {
  6342. return propAsArray.reduce(function (acc, cur) {
  6343. return acc[cur];
  6344. }, root);
  6345. }
  6346. var rootOld = getChildProp(chart.options, rootOldAsArray), rootNew = getChildProp(chart.options, rootNewAsArray);
  6347. Object.keys(mapToNewOptions).forEach(function (oldOptionKey) {
  6348. var _a;
  6349. var val = rootOld[oldOptionKey];
  6350. if (typeof val !== 'undefined') {
  6351. traverseSetOption(rootNew, mapToNewOptions[oldOptionKey], val);
  6352. error(32, false, chart, (_a = {},
  6353. _a[rootOldAsArray.join('.') + "." + oldOptionKey] = rootNewAsArray.join('.') + "." + mapToNewOptions[oldOptionKey].join('.'),
  6354. _a));
  6355. }
  6356. });
  6357. }
  6358. /**
  6359. * @private
  6360. */
  6361. function copyDeprecatedChartOptions(chart) {
  6362. var chartOptions = chart.options.chart || {}, a11yOptions = chart.options.accessibility || {};
  6363. ['description', 'typeDescription'].forEach(function (prop) {
  6364. var _a;
  6365. if (chartOptions[prop]) {
  6366. a11yOptions[prop] = chartOptions[prop];
  6367. error(32, false, chart, (_a = {}, _a["chart." + prop] = "use accessibility." + prop, _a));
  6368. }
  6369. });
  6370. }
  6371. /**
  6372. * @private
  6373. */
  6374. function copyDeprecatedAxisOptions(chart) {
  6375. chart.axes.forEach(function (axis) {
  6376. var opts = axis.options;
  6377. if (opts && opts.description) {
  6378. opts.accessibility = opts.accessibility || {};
  6379. opts.accessibility.description = opts.description;
  6380. error(32, false, chart, { 'axis.description': 'use axis.accessibility.description' });
  6381. }
  6382. });
  6383. }
  6384. /**
  6385. * @private
  6386. */
  6387. function copyDeprecatedSeriesOptions(chart) {
  6388. // Map of deprecated series options. New options are defined as
  6389. // arrays of paths under series.options.
  6390. var oldToNewSeriesOptions = {
  6391. description: ['accessibility', 'description'],
  6392. exposeElementToA11y: ['accessibility', 'exposeAsGroupOnly'],
  6393. pointDescriptionFormatter: [
  6394. 'accessibility', 'pointDescriptionFormatter'
  6395. ],
  6396. skipKeyboardNavigation: [
  6397. 'accessibility', 'keyboardNavigation', 'enabled'
  6398. ]
  6399. };
  6400. chart.series.forEach(function (series) {
  6401. // Handle series wide options
  6402. Object.keys(oldToNewSeriesOptions).forEach(function (oldOption) {
  6403. var _a;
  6404. var optionVal = series.options[oldOption];
  6405. if (typeof optionVal !== 'undefined') {
  6406. // Set the new option
  6407. traverseSetOption(series.options, oldToNewSeriesOptions[oldOption],
  6408. // Note that skipKeyboardNavigation has inverted option
  6409. // value, since we set enabled rather than disabled
  6410. oldOption === 'skipKeyboardNavigation' ?
  6411. !optionVal : optionVal);
  6412. error(32, false, chart, (_a = {}, _a["series." + oldOption] = "series." + oldToNewSeriesOptions[oldOption].join('.'), _a));
  6413. }
  6414. });
  6415. });
  6416. }
  6417. /**
  6418. * @private
  6419. */
  6420. function copyDeprecatedTopLevelAccessibilityOptions(chart) {
  6421. deprecateFromOptionsMap(chart, ['accessibility'], ['accessibility'], {
  6422. pointDateFormat: ['point', 'dateFormat'],
  6423. pointDateFormatter: ['point', 'dateFormatter'],
  6424. pointDescriptionFormatter: ['point', 'descriptionFormatter'],
  6425. pointDescriptionThreshold: ['series',
  6426. 'pointDescriptionEnabledThreshold'],
  6427. pointNavigationThreshold: ['keyboardNavigation', 'seriesNavigation',
  6428. 'pointNavigationEnabledThreshold'],
  6429. pointValueDecimals: ['point', 'valueDecimals'],
  6430. pointValuePrefix: ['point', 'valuePrefix'],
  6431. pointValueSuffix: ['point', 'valueSuffix'],
  6432. screenReaderSectionFormatter: ['screenReaderSection',
  6433. 'beforeChartFormatter'],
  6434. describeSingleSeries: ['series', 'describeSingleSeries'],
  6435. seriesDescriptionFormatter: ['series', 'descriptionFormatter'],
  6436. onTableAnchorClick: ['screenReaderSection', 'onViewDataTableClick'],
  6437. axisRangeDateFormat: ['screenReaderSection', 'axisRangeDateFormat']
  6438. });
  6439. }
  6440. /**
  6441. * @private
  6442. */
  6443. function copyDeprecatedKeyboardNavigationOptions(chart) {
  6444. deprecateFromOptionsMap(chart, ['accessibility', 'keyboardNavigation'], ['accessibility', 'keyboardNavigation', 'seriesNavigation'], {
  6445. skipNullPoints: ['skipNullPoints'],
  6446. mode: ['mode']
  6447. });
  6448. }
  6449. /**
  6450. * @private
  6451. */
  6452. function copyDeprecatedLangOptions(chart) {
  6453. deprecateFromOptionsMap(chart, ['lang', 'accessibility'], ['lang', 'accessibility'], {
  6454. legendItem: ['legend', 'legendItem'],
  6455. legendLabel: ['legend', 'legendLabel'],
  6456. mapZoomIn: ['zoom', 'mapZoomIn'],
  6457. mapZoomOut: ['zoom', 'mapZoomOut'],
  6458. resetZoomButton: ['zoom', 'resetZoomButton'],
  6459. screenReaderRegionLabel: ['screenReaderSection',
  6460. 'beforeRegionLabel'],
  6461. rangeSelectorButton: ['rangeSelector', 'buttonText'],
  6462. rangeSelectorMaxInput: ['rangeSelector', 'maxInputLabel'],
  6463. rangeSelectorMinInput: ['rangeSelector', 'minInputLabel'],
  6464. svgContainerEnd: ['screenReaderSection', 'endOfChartMarker'],
  6465. viewAsDataTable: ['table', 'viewAsDataTableButtonText'],
  6466. tableSummary: ['table', 'tableSummary']
  6467. });
  6468. }
  6469. /**
  6470. * Copy options that are deprecated over to new options. Logs warnings to
  6471. * console if deprecated options are used.
  6472. *
  6473. * @private
  6474. */
  6475. function copyDeprecatedOptions(chart) {
  6476. copyDeprecatedChartOptions(chart);
  6477. copyDeprecatedAxisOptions(chart);
  6478. if (chart.series) {
  6479. copyDeprecatedSeriesOptions(chart);
  6480. }
  6481. copyDeprecatedTopLevelAccessibilityOptions(chart);
  6482. copyDeprecatedKeyboardNavigationOptions(chart);
  6483. copyDeprecatedLangOptions(chart);
  6484. }
  6485. return copyDeprecatedOptions;
  6486. });
  6487. _registerModule(_modules, 'modules/accessibility/a11y-i18n.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  6488. /* *
  6489. *
  6490. * Accessibility module - internationalization support
  6491. *
  6492. * (c) 2010-2020 Highsoft AS
  6493. * Author: Øystein Moseng
  6494. *
  6495. * License: www.highcharts.com/license
  6496. *
  6497. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6498. *
  6499. * */
  6500. var format = U.format, pick = U.pick;
  6501. /* eslint-disable valid-jsdoc */
  6502. /**
  6503. * String trim that works for IE6-8 as well.
  6504. *
  6505. * @private
  6506. * @function stringTrim
  6507. *
  6508. * @param {string} str
  6509. * The input string
  6510. *
  6511. * @return {string}
  6512. * The trimmed string
  6513. */
  6514. function stringTrim(str) {
  6515. return str.trim && str.trim() || str.replace(/^\s+|\s+$/g, '');
  6516. }
  6517. /**
  6518. * i18n utility function. Format a single array or plural statement in a format
  6519. * string. If the statement is not an array or plural statement, returns the
  6520. * statement within brackets. Invalid array statements return an empty string.
  6521. *
  6522. * @private
  6523. * @function formatExtendedStatement
  6524. *
  6525. * @param {string} statement
  6526. *
  6527. * @param {Highcharts.Dictionary<*>} ctx
  6528. * Context to apply to the format string.
  6529. *
  6530. * @return {string}
  6531. */
  6532. function formatExtendedStatement(statement, ctx) {
  6533. var eachStart = statement.indexOf('#each('), pluralStart = statement.indexOf('#plural('), indexStart = statement.indexOf('['), indexEnd = statement.indexOf(']'), arr, result;
  6534. // Dealing with an each-function?
  6535. if (eachStart > -1) {
  6536. var eachEnd = statement.slice(eachStart).indexOf(')') + eachStart, preEach = statement.substring(0, eachStart), postEach = statement.substring(eachEnd + 1), eachStatement = statement.substring(eachStart + 6, eachEnd), eachArguments = eachStatement.split(','), lenArg = Number(eachArguments[1]), len;
  6537. result = '';
  6538. arr = ctx[eachArguments[0]];
  6539. if (arr) {
  6540. lenArg = isNaN(lenArg) ? arr.length : lenArg;
  6541. len = lenArg < 0 ?
  6542. arr.length + lenArg :
  6543. Math.min(lenArg, arr.length); // Overshoot
  6544. // Run through the array for the specified length
  6545. for (var i = 0; i < len; ++i) {
  6546. result += preEach + arr[i] + postEach;
  6547. }
  6548. }
  6549. return result.length ? result : '';
  6550. }
  6551. // Dealing with a plural-function?
  6552. if (pluralStart > -1) {
  6553. var pluralEnd = statement.slice(pluralStart).indexOf(')') + pluralStart, pluralStatement = statement.substring(pluralStart + 8, pluralEnd), pluralArguments = pluralStatement.split(','), num = Number(ctx[pluralArguments[0]]);
  6554. switch (num) {
  6555. case 0:
  6556. result = pick(pluralArguments[4], pluralArguments[1]);
  6557. break;
  6558. case 1:
  6559. result = pick(pluralArguments[2], pluralArguments[1]);
  6560. break;
  6561. case 2:
  6562. result = pick(pluralArguments[3], pluralArguments[1]);
  6563. break;
  6564. default:
  6565. result = pluralArguments[1];
  6566. }
  6567. return result ? stringTrim(result) : '';
  6568. }
  6569. // Array index
  6570. if (indexStart > -1) {
  6571. var arrayName = statement.substring(0, indexStart), ix = Number(statement.substring(indexStart + 1, indexEnd)), val;
  6572. arr = ctx[arrayName];
  6573. if (!isNaN(ix) && arr) {
  6574. if (ix < 0) {
  6575. val = arr[arr.length + ix];
  6576. // Handle negative overshoot
  6577. if (typeof val === 'undefined') {
  6578. val = arr[0];
  6579. }
  6580. }
  6581. else {
  6582. val = arr[ix];
  6583. // Handle positive overshoot
  6584. if (typeof val === 'undefined') {
  6585. val = arr[arr.length - 1];
  6586. }
  6587. }
  6588. }
  6589. return typeof val !== 'undefined' ? val : '';
  6590. }
  6591. // Standard substitution, delegate to format or similar
  6592. return '{' + statement + '}';
  6593. }
  6594. /**
  6595. * i18n formatting function. Extends Highcharts.format() functionality by also
  6596. * handling arrays and plural conditionals. Arrays can be indexed as follows:
  6597. *
  6598. * - Format: 'This is the first index: {myArray[0]}. The last: {myArray[-1]}.'
  6599. *
  6600. * - Context: { myArray: [0, 1, 2, 3, 4, 5] }
  6601. *
  6602. * - Result: 'This is the first index: 0. The last: 5.'
  6603. *
  6604. *
  6605. * They can also be iterated using the #each() function. This will repeat the
  6606. * contents of the bracket expression for each element. Example:
  6607. *
  6608. * - Format: 'List contains: {#each(myArray)cm }'
  6609. *
  6610. * - Context: { myArray: [0, 1, 2] }
  6611. *
  6612. * - Result: 'List contains: 0cm 1cm 2cm '
  6613. *
  6614. *
  6615. * The #each() function optionally takes a length parameter. If positive, this
  6616. * parameter specifies the max number of elements to iterate through. If
  6617. * negative, the function will subtract the number from the length of the array.
  6618. * Use this to stop iterating before the array ends. Example:
  6619. *
  6620. * - Format: 'List contains: {#each(myArray, -1) }and {myArray[-1]}.'
  6621. *
  6622. * - Context: { myArray: [0, 1, 2, 3] }
  6623. *
  6624. * - Result: 'List contains: 0, 1, 2, and 3.'
  6625. *
  6626. *
  6627. * Use the #plural() function to pick a string depending on whether or not a
  6628. * context object is 1. Arguments are #plural(obj, plural, singular). Example:
  6629. *
  6630. * - Format: 'Has {numPoints} {#plural(numPoints, points, point}.'
  6631. *
  6632. * - Context: { numPoints: 5 }
  6633. *
  6634. * - Result: 'Has 5 points.'
  6635. *
  6636. *
  6637. * Optionally there are additional parameters for dual and none: #plural(obj,
  6638. * plural, singular, dual, none). Example:
  6639. *
  6640. * - Format: 'Has {#plural(numPoints, many points, one point, two points,
  6641. * none}.'
  6642. *
  6643. * - Context: { numPoints: 2 }
  6644. *
  6645. * - Result: 'Has two points.'
  6646. *
  6647. *
  6648. * The dual or none parameters will take precedence if they are supplied.
  6649. *
  6650. * @requires modules/accessibility
  6651. *
  6652. * @function Highcharts.i18nFormat
  6653. *
  6654. * @param {string} formatString
  6655. * The string to format.
  6656. *
  6657. * @param {Highcharts.Dictionary<*>} context
  6658. * Context to apply to the format string.
  6659. *
  6660. * @param {Highcharts.Chart} chart
  6661. * A `Chart` instance with a time object and numberFormatter, passed on
  6662. * to format().
  6663. *
  6664. * @return {string}
  6665. * The formatted string.
  6666. */
  6667. H.i18nFormat = function (formatString, context, chart) {
  6668. var getFirstBracketStatement = function (sourceStr, offset) {
  6669. var str = sourceStr.slice(offset || 0), startBracket = str.indexOf('{'), endBracket = str.indexOf('}');
  6670. if (startBracket > -1 && endBracket > startBracket) {
  6671. return {
  6672. statement: str.substring(startBracket + 1, endBracket),
  6673. begin: offset + startBracket + 1,
  6674. end: offset + endBracket
  6675. };
  6676. }
  6677. }, tokens = [], bracketRes, constRes, cursor = 0;
  6678. // Tokenize format string into bracket statements and constants
  6679. do {
  6680. bracketRes = getFirstBracketStatement(formatString, cursor);
  6681. constRes = formatString.substring(cursor, bracketRes && bracketRes.begin - 1);
  6682. // If we have constant content before this bracket statement, add it
  6683. if (constRes.length) {
  6684. tokens.push({
  6685. value: constRes,
  6686. type: 'constant'
  6687. });
  6688. }
  6689. // Add the bracket statement
  6690. if (bracketRes) {
  6691. tokens.push({
  6692. value: bracketRes.statement,
  6693. type: 'statement'
  6694. });
  6695. }
  6696. cursor = bracketRes ? bracketRes.end + 1 : cursor + 1;
  6697. } while (bracketRes);
  6698. // Perform the formatting. The formatArrayStatement function returns the
  6699. // statement in brackets if it is not an array statement, which means it
  6700. // gets picked up by format below.
  6701. tokens.forEach(function (token) {
  6702. if (token.type === 'statement') {
  6703. token.value = formatExtendedStatement(token.value, context);
  6704. }
  6705. });
  6706. // Join string back together and pass to format to pick up non-array
  6707. // statements.
  6708. return format(tokens.reduce(function (acc, cur) {
  6709. return acc + cur.value;
  6710. }, ''), context, chart);
  6711. };
  6712. /**
  6713. * Apply context to a format string from lang options of the chart.
  6714. *
  6715. * @requires modules/accessibility
  6716. *
  6717. * @function Highcharts.Chart#langFormat
  6718. *
  6719. * @param {string} langKey
  6720. * Key (using dot notation) into lang option structure.
  6721. *
  6722. * @param {Highcharts.Dictionary<*>} context
  6723. * Context to apply to the format string.
  6724. *
  6725. * @return {string}
  6726. * The formatted string.
  6727. */
  6728. H.Chart.prototype.langFormat = function (langKey, context) {
  6729. var keys = langKey.split('.'), formatString = this.options.lang, i = 0;
  6730. for (; i < keys.length; ++i) {
  6731. formatString = formatString && formatString[keys[i]];
  6732. }
  6733. return typeof formatString === 'string' ?
  6734. H.i18nFormat(formatString, context, this) : '';
  6735. };
  6736. });
  6737. _registerModule(_modules, 'modules/accessibility/focusBorder.js', [_modules['parts/Globals.js'], _modules['parts/SVGElement.js'], _modules['parts/SVGLabel.js'], _modules['parts/Utilities.js']], function (H, SVGElement, SVGLabel, U) {
  6738. /* *
  6739. *
  6740. * (c) 2009-2020 Øystein Moseng
  6741. *
  6742. * Extend SVG and Chart classes with focus border capabilities.
  6743. *
  6744. * License: www.highcharts.com/license
  6745. *
  6746. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6747. *
  6748. * */
  6749. var addEvent = U.addEvent, extend = U.extend, pick = U.pick;
  6750. /* eslint-disable no-invalid-this, valid-jsdoc */
  6751. // Attributes that trigger a focus border update
  6752. var svgElementBorderUpdateTriggers = [
  6753. 'x', 'y', 'transform', 'width', 'height', 'r', 'd', 'stroke-width'
  6754. ];
  6755. /**
  6756. * Add hook to destroy focus border if SVG element is destroyed, unless
  6757. * hook already exists.
  6758. * @private
  6759. * @param el Element to add destroy hook to
  6760. */
  6761. function addDestroyFocusBorderHook(el) {
  6762. if (el.focusBorderDestroyHook) {
  6763. return;
  6764. }
  6765. var origDestroy = el.destroy;
  6766. el.destroy = function () {
  6767. var _a, _b;
  6768. (_b = (_a = el.focusBorder) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
  6769. return origDestroy.apply(el, arguments);
  6770. };
  6771. el.focusBorderDestroyHook = origDestroy;
  6772. }
  6773. /**
  6774. * Remove hook from SVG element added by addDestroyFocusBorderHook, if
  6775. * existing.
  6776. * @private
  6777. * @param el Element to remove destroy hook from
  6778. */
  6779. function removeDestroyFocusBorderHook(el) {
  6780. if (!el.focusBorderDestroyHook) {
  6781. return;
  6782. }
  6783. el.destroy = el.focusBorderDestroyHook;
  6784. delete el.focusBorderDestroyHook;
  6785. }
  6786. /**
  6787. * Add hooks to update the focus border of an element when the element
  6788. * size/position is updated, unless already added.
  6789. * @private
  6790. * @param el Element to add update hooks to
  6791. * @param updateParams Parameters to pass through to addFocusBorder when updating.
  6792. */
  6793. function addUpdateFocusBorderHooks(el) {
  6794. var updateParams = [];
  6795. for (var _i = 1; _i < arguments.length; _i++) {
  6796. updateParams[_i - 1] = arguments[_i];
  6797. }
  6798. if (el.focusBorderUpdateHooks) {
  6799. return;
  6800. }
  6801. el.focusBorderUpdateHooks = {};
  6802. svgElementBorderUpdateTriggers.forEach(function (trigger) {
  6803. var setterKey = trigger + 'Setter';
  6804. var origSetter = el[setterKey] || el._defaultSetter;
  6805. el.focusBorderUpdateHooks[setterKey] = origSetter;
  6806. el[setterKey] = function () {
  6807. var ret = origSetter.apply(el, arguments);
  6808. el.addFocusBorder.apply(el, updateParams);
  6809. return ret;
  6810. };
  6811. });
  6812. }
  6813. /**
  6814. * Remove hooks from SVG element added by addUpdateFocusBorderHooks, if
  6815. * existing.
  6816. * @private
  6817. * @param el Element to remove update hooks from
  6818. */
  6819. function removeUpdateFocusBorderHooks(el) {
  6820. if (!el.focusBorderUpdateHooks) {
  6821. return;
  6822. }
  6823. Object.keys(el.focusBorderUpdateHooks).forEach(function (setterKey) {
  6824. var origSetter = el.focusBorderUpdateHooks[setterKey];
  6825. if (origSetter === el._defaultSetter) {
  6826. delete el[setterKey];
  6827. }
  6828. else {
  6829. el[setterKey] = origSetter;
  6830. }
  6831. });
  6832. delete el.focusBorderUpdateHooks;
  6833. }
  6834. /*
  6835. * Add focus border functionality to SVGElements. Draws a new rect on top of
  6836. * element around its bounding box. This is used by multiple components.
  6837. */
  6838. extend(SVGElement.prototype, {
  6839. /**
  6840. * @private
  6841. * @function Highcharts.SVGElement#addFocusBorder
  6842. *
  6843. * @param {number} margin
  6844. *
  6845. * @param {Highcharts.CSSObject} style
  6846. */
  6847. addFocusBorder: function (margin, style) {
  6848. // Allow updating by just adding new border
  6849. if (this.focusBorder) {
  6850. this.removeFocusBorder();
  6851. }
  6852. // Add the border rect
  6853. var bb = this.getBBox(), pad = pick(margin, 3);
  6854. bb.x += this.translateX ? this.translateX : 0;
  6855. bb.y += this.translateY ? this.translateY : 0;
  6856. var borderPosX = bb.x - pad, borderPosY = bb.y - pad, borderWidth = bb.width + 2 * pad, borderHeight = bb.height + 2 * pad;
  6857. // For text elements, apply x and y offset, #11397.
  6858. /**
  6859. * @private
  6860. * @function
  6861. *
  6862. * @param {Highcharts.SVGElement} text
  6863. *
  6864. * @return {TextAnchorCorrectionObject}
  6865. */
  6866. function getTextAnchorCorrection(text) {
  6867. var posXCorrection = 0, posYCorrection = 0;
  6868. if (text.attr('text-anchor') === 'middle') {
  6869. posXCorrection = H.isFirefox && text.rotation ? 0.25 : 0.5;
  6870. posYCorrection = H.isFirefox && !text.rotation ? 0.75 : 0.5;
  6871. }
  6872. else if (!text.rotation) {
  6873. posYCorrection = 0.75;
  6874. }
  6875. else {
  6876. posXCorrection = 0.25;
  6877. }
  6878. return {
  6879. x: posXCorrection,
  6880. y: posYCorrection
  6881. };
  6882. }
  6883. var isLabel = this instanceof SVGLabel;
  6884. if (this.element.nodeName === 'text' || isLabel) {
  6885. var isRotated = !!this.rotation, correction = !isLabel ? getTextAnchorCorrection(this) :
  6886. {
  6887. x: isRotated ? 1 : 0,
  6888. y: 0
  6889. };
  6890. borderPosX = +this.attr('x') - (bb.width * correction.x) - pad;
  6891. borderPosY = +this.attr('y') - (bb.height * correction.y) - pad;
  6892. if (isLabel && isRotated) {
  6893. var temp = borderWidth;
  6894. borderWidth = borderHeight;
  6895. borderHeight = temp;
  6896. borderPosX = +this.attr('x') - (bb.height * correction.x) - pad;
  6897. borderPosY = +this.attr('y') - (bb.width * correction.y) - pad;
  6898. }
  6899. }
  6900. this.focusBorder = this.renderer.rect(borderPosX, borderPosY, borderWidth, borderHeight, parseInt((style && style.borderRadius || 0).toString(), 10))
  6901. .addClass('highcharts-focus-border')
  6902. .attr({
  6903. zIndex: 99
  6904. })
  6905. .add(this.parentGroup);
  6906. if (!this.renderer.styledMode) {
  6907. this.focusBorder.attr({
  6908. stroke: style && style.stroke,
  6909. 'stroke-width': style && style.strokeWidth
  6910. });
  6911. }
  6912. addUpdateFocusBorderHooks(this, margin, style);
  6913. addDestroyFocusBorderHook(this);
  6914. },
  6915. /**
  6916. * @private
  6917. * @function Highcharts.SVGElement#removeFocusBorder
  6918. */
  6919. removeFocusBorder: function () {
  6920. removeUpdateFocusBorderHooks(this);
  6921. removeDestroyFocusBorderHook(this);
  6922. if (this.focusBorder) {
  6923. this.focusBorder.destroy();
  6924. delete this.focusBorder;
  6925. }
  6926. }
  6927. });
  6928. /**
  6929. * Redraws the focus border on the currently focused element.
  6930. *
  6931. * @private
  6932. * @function Highcharts.Chart#renderFocusBorder
  6933. */
  6934. H.Chart.prototype.renderFocusBorder = function () {
  6935. var focusElement = this.focusElement, focusBorderOptions = this.options.accessibility.keyboardNavigation.focusBorder;
  6936. if (focusElement) {
  6937. focusElement.removeFocusBorder();
  6938. if (focusBorderOptions.enabled) {
  6939. focusElement.addFocusBorder(focusBorderOptions.margin, {
  6940. stroke: focusBorderOptions.style.color,
  6941. strokeWidth: focusBorderOptions.style.lineWidth,
  6942. borderRadius: focusBorderOptions.style.borderRadius
  6943. });
  6944. }
  6945. }
  6946. };
  6947. /**
  6948. * Set chart's focus to an SVGElement. Calls focus() on it, and draws the focus
  6949. * border. This is used by multiple components.
  6950. *
  6951. * @private
  6952. * @function Highcharts.Chart#setFocusToElement
  6953. *
  6954. * @param {Highcharts.SVGElement} svgElement
  6955. * Element to draw the border around.
  6956. *
  6957. * @param {SVGDOMElement|HTMLDOMElement} [focusElement]
  6958. * If supplied, it draws the border around svgElement and sets the focus
  6959. * to focusElement.
  6960. */
  6961. H.Chart.prototype.setFocusToElement = function (svgElement, focusElement) {
  6962. var focusBorderOptions = this.options.accessibility.keyboardNavigation.focusBorder, browserFocusElement = focusElement || svgElement.element;
  6963. // Set browser focus if possible
  6964. if (browserFocusElement &&
  6965. browserFocusElement.focus) {
  6966. // If there is no focusin-listener, add one to work around Edge issue
  6967. // where Narrator is not reading out points despite calling focus().
  6968. if (!(browserFocusElement.hcEvents &&
  6969. browserFocusElement.hcEvents.focusin)) {
  6970. addEvent(browserFocusElement, 'focusin', function () { });
  6971. }
  6972. browserFocusElement.focus();
  6973. // Hide default focus ring
  6974. if (focusBorderOptions.hideBrowserFocusOutline) {
  6975. browserFocusElement.style.outline = 'none';
  6976. }
  6977. }
  6978. if (this.focusElement) {
  6979. this.focusElement.removeFocusBorder();
  6980. }
  6981. this.focusElement = svgElement;
  6982. this.renderFocusBorder();
  6983. };
  6984. });
  6985. _registerModule(_modules, 'modules/accessibility/accessibility.js', [_modules['modules/accessibility/utils/chartUtilities.js'], _modules['parts/Globals.js'], _modules['modules/accessibility/KeyboardNavigationHandler.js'], _modules['parts/Options.js'], _modules['parts/Point.js'], _modules['parts/Utilities.js'], _modules['modules/accessibility/AccessibilityComponent.js'], _modules['modules/accessibility/KeyboardNavigation.js'], _modules['modules/accessibility/components/LegendComponent.js'], _modules['modules/accessibility/components/MenuComponent.js'], _modules['modules/accessibility/components/SeriesComponent/SeriesComponent.js'], _modules['modules/accessibility/components/ZoomComponent.js'], _modules['modules/accessibility/components/RangeSelectorComponent.js'], _modules['modules/accessibility/components/InfoRegionsComponent.js'], _modules['modules/accessibility/components/ContainerComponent.js'], _modules['modules/accessibility/high-contrast-mode.js'], _modules['modules/accessibility/high-contrast-theme.js'], _modules['modules/accessibility/options/options.js'], _modules['modules/accessibility/options/langOptions.js'], _modules['modules/accessibility/options/deprecatedOptions.js']], function (ChartUtilities, H, KeyboardNavigationHandler, O, Point, U, AccessibilityComponent, KeyboardNavigation, LegendComponent, MenuComponent, SeriesComponent, ZoomComponent, RangeSelectorComponent, InfoRegionsComponent, ContainerComponent, whcm, highContrastTheme, defaultOptionsA11Y, defaultLangOptions, copyDeprecatedOptions) {
  6986. /* *
  6987. *
  6988. * (c) 2009-2020 Øystein Moseng
  6989. *
  6990. * Accessibility module for Highcharts
  6991. *
  6992. * License: www.highcharts.com/license
  6993. *
  6994. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6995. *
  6996. * */
  6997. var defaultOptions = O.defaultOptions;
  6998. var addEvent = U.addEvent, extend = U.extend, fireEvent = U.fireEvent, merge = U.merge;
  6999. var doc = H.win.document;
  7000. // Add default options
  7001. merge(true, defaultOptions, defaultOptionsA11Y, {
  7002. accessibility: {
  7003. highContrastTheme: highContrastTheme
  7004. },
  7005. lang: defaultLangOptions
  7006. });
  7007. // Expose functionality on Highcharts namespace
  7008. H.A11yChartUtilities = ChartUtilities;
  7009. H.KeyboardNavigationHandler = KeyboardNavigationHandler;
  7010. H.AccessibilityComponent = AccessibilityComponent;
  7011. /* eslint-disable no-invalid-this, valid-jsdoc */
  7012. /**
  7013. * The Accessibility class
  7014. *
  7015. * @private
  7016. * @requires module:modules/accessibility
  7017. *
  7018. * @class
  7019. * @name Highcharts.Accessibility
  7020. *
  7021. * @param {Highcharts.Chart} chart
  7022. * Chart object
  7023. */
  7024. function Accessibility(chart) {
  7025. this.init(chart);
  7026. }
  7027. Accessibility.prototype = {
  7028. /**
  7029. * Initialize the accessibility class
  7030. * @private
  7031. * @param {Highcharts.Chart} chart
  7032. * Chart object
  7033. */
  7034. init: function (chart) {
  7035. this.chart = chart;
  7036. // Abort on old browsers
  7037. if (!doc.addEventListener || !chart.renderer.isSVG) {
  7038. chart.renderTo.setAttribute('aria-hidden', true);
  7039. return;
  7040. }
  7041. // Copy over any deprecated options that are used. We could do this on
  7042. // every update, but it is probably not needed.
  7043. copyDeprecatedOptions(chart);
  7044. this.initComponents();
  7045. this.keyboardNavigation = new KeyboardNavigation(chart, this.components);
  7046. this.update();
  7047. },
  7048. /**
  7049. * @private
  7050. */
  7051. initComponents: function () {
  7052. var chart = this.chart, a11yOptions = chart.options.accessibility;
  7053. this.components = {
  7054. container: new ContainerComponent(),
  7055. infoRegions: new InfoRegionsComponent(),
  7056. legend: new LegendComponent(),
  7057. chartMenu: new MenuComponent(),
  7058. rangeSelector: new RangeSelectorComponent(),
  7059. series: new SeriesComponent(),
  7060. zoom: new ZoomComponent()
  7061. };
  7062. if (a11yOptions.customComponents) {
  7063. extend(this.components, a11yOptions.customComponents);
  7064. }
  7065. var components = this.components;
  7066. this.getComponentOrder().forEach(function (componentName) {
  7067. components[componentName].initBase(chart);
  7068. components[componentName].init();
  7069. });
  7070. },
  7071. /**
  7072. * Get order to update components in.
  7073. * @private
  7074. */
  7075. getComponentOrder: function () {
  7076. if (!this.components) {
  7077. return []; // For zombie accessibility object on old browsers
  7078. }
  7079. if (!this.components.series) {
  7080. return Object.keys(this.components);
  7081. }
  7082. var componentsExceptSeries = Object.keys(this.components)
  7083. .filter(function (c) { return c !== 'series'; });
  7084. // Update series first, so that other components can read accessibility
  7085. // info on points.
  7086. return ['series'].concat(componentsExceptSeries);
  7087. },
  7088. /**
  7089. * Update all components.
  7090. */
  7091. update: function () {
  7092. var components = this.components, chart = this.chart, a11yOptions = chart.options.accessibility;
  7093. fireEvent(chart, 'beforeA11yUpdate');
  7094. // Update the chart type list as this is used by multiple modules
  7095. chart.types = this.getChartTypes();
  7096. // Update markup
  7097. this.getComponentOrder().forEach(function (componentName) {
  7098. components[componentName].onChartUpdate();
  7099. fireEvent(chart, 'afterA11yComponentUpdate', {
  7100. name: componentName,
  7101. component: components[componentName]
  7102. });
  7103. });
  7104. // Update keyboard navigation
  7105. this.keyboardNavigation.update(a11yOptions.keyboardNavigation.order);
  7106. // Handle high contrast mode
  7107. if (!chart.highContrastModeActive && // Only do this once
  7108. whcm.isHighContrastModeActive()) {
  7109. whcm.setHighContrastTheme(chart);
  7110. }
  7111. fireEvent(chart, 'afterA11yUpdate', {
  7112. accessibility: this
  7113. });
  7114. },
  7115. /**
  7116. * Destroy all elements.
  7117. */
  7118. destroy: function () {
  7119. var chart = this.chart || {};
  7120. // Destroy components
  7121. var components = this.components;
  7122. Object.keys(components).forEach(function (componentName) {
  7123. components[componentName].destroy();
  7124. components[componentName].destroyBase();
  7125. });
  7126. // Kill keyboard nav
  7127. if (this.keyboardNavigation) {
  7128. this.keyboardNavigation.destroy();
  7129. }
  7130. // Hide container from screen readers if it exists
  7131. if (chart.renderTo) {
  7132. chart.renderTo.setAttribute('aria-hidden', true);
  7133. }
  7134. // Remove focus border if it exists
  7135. if (chart.focusElement) {
  7136. chart.focusElement.removeFocusBorder();
  7137. }
  7138. },
  7139. /**
  7140. * Return a list of the types of series we have in the chart.
  7141. * @private
  7142. */
  7143. getChartTypes: function () {
  7144. var types = {};
  7145. this.chart.series.forEach(function (series) {
  7146. types[series.type] = 1;
  7147. });
  7148. return Object.keys(types);
  7149. }
  7150. };
  7151. /**
  7152. * @private
  7153. */
  7154. H.Chart.prototype.updateA11yEnabled = function () {
  7155. var a11y = this.accessibility, accessibilityOptions = this.options.accessibility;
  7156. if (accessibilityOptions && accessibilityOptions.enabled) {
  7157. if (a11y) {
  7158. a11y.update();
  7159. }
  7160. else {
  7161. this.accessibility = a11y = new Accessibility(this);
  7162. }
  7163. }
  7164. else if (a11y) {
  7165. // Destroy if after update we have a11y and it is disabled
  7166. if (a11y.destroy) {
  7167. a11y.destroy();
  7168. }
  7169. delete this.accessibility;
  7170. }
  7171. else {
  7172. // Just hide container
  7173. this.renderTo.setAttribute('aria-hidden', true);
  7174. }
  7175. };
  7176. // Handle updates to the module and send render updates to components
  7177. addEvent(H.Chart, 'render', function (e) {
  7178. // Update/destroy
  7179. if (this.a11yDirty && this.renderTo) {
  7180. delete this.a11yDirty;
  7181. this.updateA11yEnabled();
  7182. }
  7183. var a11y = this.accessibility;
  7184. if (a11y) {
  7185. a11y.getComponentOrder().forEach(function (componentName) {
  7186. a11y.components[componentName].onChartRender();
  7187. });
  7188. }
  7189. });
  7190. // Update with chart/series/point updates
  7191. addEvent(H.Chart, 'update', function (e) {
  7192. // Merge new options
  7193. var newOptions = e.options.accessibility;
  7194. if (newOptions) {
  7195. // Handle custom component updating specifically
  7196. if (newOptions.customComponents) {
  7197. this.options.accessibility.customComponents =
  7198. newOptions.customComponents;
  7199. delete newOptions.customComponents;
  7200. }
  7201. merge(true, this.options.accessibility, newOptions);
  7202. // Recreate from scratch
  7203. if (this.accessibility && this.accessibility.destroy) {
  7204. this.accessibility.destroy();
  7205. delete this.accessibility;
  7206. }
  7207. }
  7208. // Mark dirty for update
  7209. this.a11yDirty = true;
  7210. });
  7211. // Mark dirty for update
  7212. addEvent(Point, 'update', function () {
  7213. if (this.series.chart.accessibility) {
  7214. this.series.chart.a11yDirty = true;
  7215. }
  7216. });
  7217. ['addSeries', 'init'].forEach(function (event) {
  7218. addEvent(H.Chart, event, function () {
  7219. this.a11yDirty = true;
  7220. });
  7221. });
  7222. ['update', 'updatedData', 'remove'].forEach(function (event) {
  7223. addEvent(H.Series, event, function () {
  7224. if (this.chart.accessibility) {
  7225. this.chart.a11yDirty = true;
  7226. }
  7227. });
  7228. });
  7229. // Direct updates (events happen after render)
  7230. [
  7231. 'afterDrilldown', 'drillupall'
  7232. ].forEach(function (event) {
  7233. addEvent(H.Chart, event, function () {
  7234. if (this.accessibility) {
  7235. this.accessibility.update();
  7236. }
  7237. });
  7238. });
  7239. // Destroy with chart
  7240. addEvent(H.Chart, 'destroy', function () {
  7241. if (this.accessibility) {
  7242. this.accessibility.destroy();
  7243. }
  7244. });
  7245. });
  7246. _registerModule(_modules, 'masters/modules/accessibility.src.js', [], function () {
  7247. });
  7248. }));