accessibility.src.js 452 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282
  1. /**
  2. * @license Highcharts JS v9.0.1 (2021-02-16)
  3. *
  4. * Accessibility module
  5. *
  6. * (c) 2010-2021 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, 'Accessibility/Utils/HTMLUtilities.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  33. /* *
  34. *
  35. * (c) 2009-2021 Ø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 doc = H.doc,
  45. win = H.win;
  46. var merge = U.merge;
  47. /* eslint-disable valid-jsdoc */
  48. /**
  49. * @private
  50. * @param {Highcharts.HTMLDOMElement} el
  51. * @param {string} className
  52. * @return {void}
  53. */
  54. function addClass(el, className) {
  55. if (el.classList) {
  56. el.classList.add(className);
  57. }
  58. else if (el.className.indexOf(className) < 0) {
  59. // Note: Dumb check for class name exists, should be fine for practical
  60. // use cases, but will return false positives if the element has a class
  61. // that contains the className.
  62. el.className += className;
  63. }
  64. }
  65. /**
  66. * @private
  67. * @param {string} str
  68. * @return {string}
  69. */
  70. function escapeStringForHTML(str) {
  71. return str
  72. .replace(/&/g, '&amp;')
  73. .replace(/</g, '&lt;')
  74. .replace(/>/g, '&gt;')
  75. .replace(/"/g, '&quot;')
  76. .replace(/'/g, '&#x27;')
  77. .replace(/\//g, '&#x2F;');
  78. }
  79. /**
  80. * Get an element by ID
  81. * @param {string} id
  82. * @private
  83. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|null}
  84. */
  85. function getElement(id) {
  86. return doc.getElementById(id);
  87. }
  88. /**
  89. * Get a fake mouse event of a given type
  90. * @param {string} type
  91. * @private
  92. * @return {global.MouseEvent}
  93. */
  94. function getFakeMouseEvent(type) {
  95. if (typeof win.MouseEvent === 'function') {
  96. return new win.MouseEvent(type);
  97. }
  98. // No MouseEvent support, try using initMouseEvent
  99. if (doc.createEvent) {
  100. var evt = doc.createEvent('MouseEvent');
  101. if (evt.initMouseEvent) {
  102. evt.initMouseEvent(type, true, // Bubble
  103. true, // Cancel
  104. win, // View
  105. type === 'click' ? 1 : 0, // Detail
  106. // Coords
  107. 0, 0, 0, 0,
  108. // Pressed keys
  109. false, false, false, false, 0, // button
  110. null // related target
  111. );
  112. return evt;
  113. }
  114. }
  115. return { type: type };
  116. }
  117. /**
  118. * Get an appropriate heading level for an element. Corresponds to the
  119. * heading level below the previous heading in the DOM.
  120. *
  121. * Note: Only detects previous headings in the DOM that are siblings,
  122. * ancestors, or previous siblings of ancestors. Headings that are nested below
  123. * siblings of ancestors (cousins et.al) are not picked up. This is because it
  124. * is ambiguous whether or not the nesting is for layout purposes or indicates a
  125. * separate section.
  126. *
  127. * @private
  128. * @param {Highcharts.HTMLDOMElement} [element]
  129. * @return {string} The heading tag name (h1, h2 etc).
  130. * If no nearest heading is found, "p" is returned.
  131. */
  132. function getHeadingTagNameForElement(element) {
  133. var getIncreasedHeadingLevel = function (tagName) {
  134. var headingLevel = parseInt(tagName.slice(1), 10);
  135. var newLevel = Math.min(6,
  136. headingLevel + 1);
  137. return 'h' + newLevel;
  138. };
  139. var isHeading = function (tagName) { return /H[1-6]/.test(tagName); };
  140. var getPreviousSiblingsHeading = function (el) {
  141. var sibling = el;
  142. while (sibling = sibling.previousSibling) { // eslint-disable-line
  143. var tagName = sibling.tagName || '';
  144. if (isHeading(tagName)) {
  145. return tagName;
  146. }
  147. }
  148. return '';
  149. };
  150. var getHeadingRecursive = function (el) {
  151. var prevSiblingsHeading = getPreviousSiblingsHeading(el);
  152. if (prevSiblingsHeading) {
  153. return getIncreasedHeadingLevel(prevSiblingsHeading);
  154. }
  155. // No previous siblings are headings, try parent node
  156. var parent = el.parentElement;
  157. if (!parent) {
  158. return 'p';
  159. }
  160. var parentTagName = parent.tagName;
  161. if (isHeading(parentTagName)) {
  162. return getIncreasedHeadingLevel(parentTagName);
  163. }
  164. return getHeadingRecursive(parent);
  165. };
  166. return getHeadingRecursive(element);
  167. }
  168. /**
  169. * Remove an element from the DOM.
  170. * @private
  171. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} [element]
  172. * @return {void}
  173. */
  174. function removeElement(element) {
  175. if (element && element.parentNode) {
  176. element.parentNode.removeChild(element);
  177. }
  178. }
  179. /**
  180. * Utility function. Reverses child nodes of a DOM element.
  181. * @private
  182. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} node
  183. * @return {void}
  184. */
  185. function reverseChildNodes(node) {
  186. var i = node.childNodes.length;
  187. while (i--) {
  188. node.appendChild(node.childNodes[i]);
  189. }
  190. }
  191. /**
  192. * Set attributes on element. Set to null to remove attribute.
  193. * @private
  194. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} el
  195. * @param {Highcharts.HTMLAttributes|Highcharts.SVGAttributes} attrs
  196. * @return {void}
  197. */
  198. function setElAttrs(el, attrs) {
  199. Object.keys(attrs).forEach(function (attr) {
  200. var val = attrs[attr];
  201. if (val === null) {
  202. el.removeAttribute(attr);
  203. }
  204. else {
  205. el.setAttribute(attr, val);
  206. }
  207. });
  208. }
  209. /**
  210. * Used for aria-label attributes, painting on a canvas will fail if the
  211. * text contains tags.
  212. * @private
  213. * @param {string} str
  214. * @return {string}
  215. */
  216. function stripHTMLTagsFromString(str) {
  217. return typeof str === 'string' ?
  218. str.replace(/<\/?[^>]+(>|$)/g, '') : str;
  219. }
  220. /**
  221. * Utility function for hiding an element visually, but still keeping it
  222. * available to screen reader users.
  223. * @private
  224. * @param {Highcharts.HTMLDOMElement} element
  225. * @return {void}
  226. */
  227. function visuallyHideElement(element) {
  228. var hiddenStyle = {
  229. position: 'absolute',
  230. width: '1px',
  231. height: '1px',
  232. overflow: 'hidden',
  233. whiteSpace: 'nowrap',
  234. clip: 'rect(1px, 1px, 1px, 1px)',
  235. marginTop: '-3px',
  236. '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=1)',
  237. filter: 'alpha(opacity=1)',
  238. opacity: '0.01'
  239. };
  240. merge(true, element.style, hiddenStyle);
  241. }
  242. var HTMLUtilities = {
  243. addClass: addClass,
  244. escapeStringForHTML: escapeStringForHTML,
  245. getElement: getElement,
  246. getFakeMouseEvent: getFakeMouseEvent,
  247. getHeadingTagNameForElement: getHeadingTagNameForElement,
  248. removeElement: removeElement,
  249. reverseChildNodes: reverseChildNodes,
  250. setElAttrs: setElAttrs,
  251. stripHTMLTagsFromString: stripHTMLTagsFromString,
  252. visuallyHideElement: visuallyHideElement
  253. };
  254. return HTMLUtilities;
  255. });
  256. _registerModule(_modules, 'Accessibility/Utils/ChartUtilities.js', [_modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Utilities.js']], function (HTMLUtilities, U) {
  257. /* *
  258. *
  259. * (c) 2009-2021 Øystein Moseng
  260. *
  261. * Utils for dealing with charts.
  262. *
  263. * License: www.highcharts.com/license
  264. *
  265. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  266. *
  267. * */
  268. var stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  269. var defined = U.defined,
  270. find = U.find,
  271. fireEvent = U.fireEvent;
  272. /* eslint-disable valid-jsdoc */
  273. /**
  274. * @return {string}
  275. */
  276. function getChartTitle(chart) {
  277. return stripHTMLTags(chart.options.title.text ||
  278. chart.langFormat('accessibility.defaultChartTitle', { chart: chart }));
  279. }
  280. /**
  281. * Return string with the axis name/title.
  282. * @param {Highcharts.Axis} axis
  283. * @return {string}
  284. */
  285. function getAxisDescription(axis) {
  286. return axis && (axis.userOptions && axis.userOptions.accessibility &&
  287. axis.userOptions.accessibility.description ||
  288. axis.axisTitle && axis.axisTitle.textStr ||
  289. axis.options.id ||
  290. axis.categories && 'categories' ||
  291. axis.dateTime && 'Time' ||
  292. 'values');
  293. }
  294. /**
  295. * Return string with text description of the axis range.
  296. * @param {Highcharts.Axis} axis The axis to get range desc of.
  297. * @return {string} A string with the range description for the axis.
  298. */
  299. function getAxisRangeDescription(axis) {
  300. var axisOptions = axis.options || {};
  301. // Handle overridden range description
  302. if (axisOptions.accessibility &&
  303. typeof axisOptions.accessibility.rangeDescription !== 'undefined') {
  304. return axisOptions.accessibility.rangeDescription;
  305. }
  306. // Handle category axes
  307. if (axis.categories) {
  308. return getCategoryAxisRangeDesc(axis);
  309. }
  310. // Use time range, not from-to?
  311. if (axis.dateTime && (axis.min === 0 || axis.dataMin === 0)) {
  312. return getAxisTimeLengthDesc(axis);
  313. }
  314. // Just use from and to.
  315. // We have the range and the unit to use, find the desc format
  316. return getAxisFromToDescription(axis);
  317. }
  318. /**
  319. * Describe the range of a category axis.
  320. * @param {Highcharts.Axis} axis
  321. * @return {string}
  322. */
  323. function getCategoryAxisRangeDesc(axis) {
  324. var chart = axis.chart;
  325. if (axis.dataMax && axis.dataMin) {
  326. return chart.langFormat('accessibility.axis.rangeCategories', {
  327. chart: chart,
  328. axis: axis,
  329. numCategories: axis.dataMax - axis.dataMin + 1
  330. });
  331. }
  332. return '';
  333. }
  334. /**
  335. * Describe the length of the time window shown on an axis.
  336. * @param {Highcharts.Axis} axis
  337. * @return {string}
  338. */
  339. function getAxisTimeLengthDesc(axis) {
  340. var chart = axis.chart;
  341. var range = {};
  342. var rangeUnit = 'Seconds';
  343. range.Seconds = ((axis.max || 0) - (axis.min || 0)) / 1000;
  344. range.Minutes = range.Seconds / 60;
  345. range.Hours = range.Minutes / 60;
  346. range.Days = range.Hours / 24;
  347. ['Minutes', 'Hours', 'Days'].forEach(function (unit) {
  348. if (range[unit] > 2) {
  349. rangeUnit = unit;
  350. }
  351. });
  352. var rangeValue = range[rangeUnit].toFixed(rangeUnit !== 'Seconds' &&
  353. rangeUnit !== 'Minutes' ? 1 : 0 // Use decimals for days/hours
  354. );
  355. // We have the range and the unit to use, find the desc format
  356. return chart.langFormat('accessibility.axis.timeRange' + rangeUnit, {
  357. chart: chart,
  358. axis: axis,
  359. range: rangeValue.replace('.0', '')
  360. });
  361. }
  362. /**
  363. * Describe an axis from-to range.
  364. * @param {Highcharts.Axis} axis
  365. * @return {string}
  366. */
  367. function getAxisFromToDescription(axis) {
  368. var _a,
  369. _b;
  370. var chart = axis.chart;
  371. var dateRangeFormat = ((_b = (_a = chart.options) === null || _a === void 0 ? void 0 : _a.accessibility) === null || _b === void 0 ? void 0 : _b.screenReaderSection.axisRangeDateFormat) || '';
  372. var format = function (axisKey) {
  373. return axis.dateTime ? chart.time.dateFormat(dateRangeFormat,
  374. axis[axisKey]) : axis[axisKey];
  375. };
  376. return chart.langFormat('accessibility.axis.rangeFromTo', {
  377. chart: chart,
  378. axis: axis,
  379. rangeFrom: format('min'),
  380. rangeTo: format('max')
  381. });
  382. }
  383. /**
  384. * Get the DOM element for the first point in the series.
  385. * @private
  386. * @param {Highcharts.Series} series
  387. * The series to get element for.
  388. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined}
  389. * The DOM element for the point.
  390. */
  391. function getSeriesFirstPointElement(series) {
  392. var _a,
  393. _b;
  394. if ((_a = series.points) === null || _a === void 0 ? void 0 : _a.length) {
  395. var firstPointWithGraphic = find(series.points,
  396. function (p) { return !!p.graphic; });
  397. return (_b = firstPointWithGraphic === null || firstPointWithGraphic === void 0 ? void 0 : firstPointWithGraphic.graphic) === null || _b === void 0 ? void 0 : _b.element;
  398. }
  399. }
  400. /**
  401. * Get the DOM element for the series that we put accessibility info on.
  402. * @private
  403. * @param {Highcharts.Series} series
  404. * The series to get element for.
  405. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined}
  406. * The DOM element for the series
  407. */
  408. function getSeriesA11yElement(series) {
  409. var firstPointEl = getSeriesFirstPointElement(series);
  410. return (firstPointEl &&
  411. firstPointEl.parentNode || series.graph &&
  412. series.graph.element || series.group &&
  413. series.group.element); // Could be tracker series depending on series type
  414. }
  415. /**
  416. * Remove aria-hidden from element. Also unhides parents of the element, and
  417. * hides siblings that are not explicitly unhidden.
  418. * @private
  419. * @param {Highcharts.Chart} chart
  420. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} element
  421. */
  422. function unhideChartElementFromAT(chart, element) {
  423. element.setAttribute('aria-hidden', false);
  424. if (element === chart.renderTo || !element.parentNode) {
  425. return;
  426. }
  427. // Hide siblings unless their hidden state is already explicitly set
  428. Array.prototype.forEach.call(element.parentNode.childNodes, function (node) {
  429. if (!node.hasAttribute('aria-hidden')) {
  430. node.setAttribute('aria-hidden', true);
  431. }
  432. });
  433. // Repeat for parent
  434. unhideChartElementFromAT(chart, element.parentNode);
  435. }
  436. /**
  437. * Hide series from screen readers.
  438. * @private
  439. * @param {Highcharts.Series} series
  440. * The series to hide
  441. * @return {void}
  442. */
  443. function hideSeriesFromAT(series) {
  444. var seriesEl = getSeriesA11yElement(series);
  445. if (seriesEl) {
  446. seriesEl.setAttribute('aria-hidden', true);
  447. }
  448. }
  449. /**
  450. * Get series objects by series name.
  451. * @private
  452. * @param {Highcharts.Chart} chart
  453. * @param {string} name
  454. * @return {Array<Highcharts.Series>}
  455. */
  456. function getSeriesFromName(chart, name) {
  457. if (!name) {
  458. return chart.series;
  459. }
  460. return (chart.series || []).filter(function (s) {
  461. return s.name === name;
  462. });
  463. }
  464. /**
  465. * Get point in a series from x/y values.
  466. * @private
  467. * @param {Array<Highcharts.Series>} series
  468. * @param {number} x
  469. * @param {number} y
  470. * @return {Highcharts.Point|undefined}
  471. */
  472. function getPointFromXY(series, x, y) {
  473. var i = series.length,
  474. res;
  475. while (i--) {
  476. res = find(series[i].points || [], function (p) {
  477. return p.x === x && p.y === y;
  478. });
  479. if (res) {
  480. return res;
  481. }
  482. }
  483. }
  484. /**
  485. * Get relative position of point on an x/y axis from 0 to 1.
  486. * @private
  487. * @param {Highcharts.Axis} axis
  488. * @param {Highcharts.Point} point
  489. * @return {number}
  490. */
  491. function getRelativePointAxisPosition(axis, point) {
  492. if (!defined(axis.dataMin) || !defined(axis.dataMax)) {
  493. return 0;
  494. }
  495. var axisStart = axis.toPixels(axis.dataMin);
  496. var axisEnd = axis.toPixels(axis.dataMax);
  497. // We have to use pixel position because of axis breaks, log axis etc.
  498. var positionProp = axis.coll === 'xAxis' ? 'x' : 'y';
  499. var pointPos = axis.toPixels(point[positionProp] || 0);
  500. return (pointPos - axisStart) / (axisEnd - axisStart);
  501. }
  502. /**
  503. * Get relative position of point on an x/y axis from 0 to 1.
  504. * @private
  505. * @param {Highcharts.Point} point
  506. */
  507. function scrollToPoint(point) {
  508. var xAxis = point.series.xAxis;
  509. var yAxis = point.series.yAxis;
  510. var axis = (xAxis === null || xAxis === void 0 ? void 0 : xAxis.scrollbar) ? xAxis : yAxis;
  511. var scrollbar = axis === null || axis === void 0 ? void 0 : axis.scrollbar;
  512. if (scrollbar && defined(scrollbar.to) && defined(scrollbar.from)) {
  513. var range = scrollbar.to - scrollbar.from;
  514. var pos = getRelativePointAxisPosition(axis,
  515. point);
  516. scrollbar.updatePosition(pos - range / 2, pos + range / 2);
  517. fireEvent(scrollbar, 'changed', {
  518. from: scrollbar.from,
  519. to: scrollbar.to,
  520. trigger: 'scrollbar',
  521. DOMEvent: null
  522. });
  523. }
  524. }
  525. var ChartUtilities = {
  526. getChartTitle: getChartTitle,
  527. getAxisDescription: getAxisDescription,
  528. getAxisRangeDescription: getAxisRangeDescription,
  529. getPointFromXY: getPointFromXY,
  530. getSeriesFirstPointElement: getSeriesFirstPointElement,
  531. getSeriesFromName: getSeriesFromName,
  532. getSeriesA11yElement: getSeriesA11yElement,
  533. unhideChartElementFromAT: unhideChartElementFromAT,
  534. hideSeriesFromAT: hideSeriesFromAT,
  535. scrollToPoint: scrollToPoint
  536. };
  537. return ChartUtilities;
  538. });
  539. _registerModule(_modules, 'Accessibility/KeyboardNavigationHandler.js', [_modules['Core/Utilities.js']], function (U) {
  540. /* *
  541. *
  542. * (c) 2009-2021 Øystein Moseng
  543. *
  544. * Keyboard navigation handler base class definition
  545. *
  546. * License: www.highcharts.com/license
  547. *
  548. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  549. *
  550. * */
  551. var find = U.find;
  552. /**
  553. * Options for the keyboard navigation handler.
  554. *
  555. * @interface Highcharts.KeyboardNavigationHandlerOptionsObject
  556. */ /**
  557. * An array containing pairs of an array of keycodes, mapped to a handler
  558. * function. When the keycode is received, the handler is called with the
  559. * keycode as parameter.
  560. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#keyCodeMap
  561. * @type {Array<Array<Array<number>, Function>>}
  562. */ /**
  563. * Function to run on initialization of module.
  564. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#init
  565. * @type {Function}
  566. */ /**
  567. * Function to run before moving to next/prev module. Receives moving direction
  568. * as parameter: +1 for next, -1 for previous.
  569. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#terminate
  570. * @type {Function|undefined}
  571. */ /**
  572. * Function to run to validate module. Should return false if module should not
  573. * run, true otherwise. Receives chart as parameter.
  574. * @name Highcharts.KeyboardNavigationHandlerOptionsObject#validate
  575. * @type {Function|undefined}
  576. */
  577. /* eslint-disable no-invalid-this, valid-jsdoc */
  578. /**
  579. * Define a keyboard navigation handler for use with a
  580. * Highcharts.AccessibilityComponent instance. This functions as an abstraction
  581. * layer for keyboard navigation, and defines a map of keyCodes to handler
  582. * functions.
  583. *
  584. * @requires module:modules/accessibility
  585. *
  586. * @sample highcharts/accessibility/custom-component
  587. * Custom accessibility component
  588. *
  589. * @class
  590. * @name Highcharts.KeyboardNavigationHandler
  591. *
  592. * @param {Highcharts.Chart} chart
  593. * The chart this module should act on.
  594. *
  595. * @param {Highcharts.KeyboardNavigationHandlerOptionsObject} options
  596. * Options for the keyboard navigation handler.
  597. */
  598. function KeyboardNavigationHandler(chart, options) {
  599. this.chart = chart;
  600. this.keyCodeMap = options.keyCodeMap || [];
  601. this.validate = options.validate;
  602. this.init = options.init;
  603. this.terminate = options.terminate;
  604. // Response enum
  605. this.response = {
  606. success: 1,
  607. prev: 2,
  608. next: 3,
  609. noHandler: 4,
  610. fail: 5 // Handler failed
  611. };
  612. }
  613. KeyboardNavigationHandler.prototype = {
  614. /**
  615. * Find handler function(s) for key code in the keyCodeMap and run it.
  616. *
  617. * @function KeyboardNavigationHandler#run
  618. * @param {global.KeyboardEvent} e
  619. * @return {number} Returns a response code indicating whether the run was
  620. * a success/fail/unhandled, or if we should move to next/prev module.
  621. */
  622. run: function (e) {
  623. var keyCode = e.which || e.keyCode,
  624. response = this.response.noHandler,
  625. handlerCodeSet = find(this.keyCodeMap,
  626. function (codeSet) {
  627. return codeSet[0].indexOf(keyCode) > -1;
  628. });
  629. if (handlerCodeSet) {
  630. response = handlerCodeSet[1].call(this, keyCode, e);
  631. }
  632. else if (keyCode === 9) {
  633. // Default tab handler, move to next/prev module
  634. response = this.response[e.shiftKey ? 'prev' : 'next'];
  635. }
  636. return response;
  637. }
  638. };
  639. return KeyboardNavigationHandler;
  640. });
  641. _registerModule(_modules, 'Accessibility/Utils/DOMElementProvider.js', [_modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Utilities.js']], function (H, HTMLUtilities, U) {
  642. /* *
  643. *
  644. * (c) 2009-2021 Øystein Moseng
  645. *
  646. * Class that can keep track of elements added to DOM and clean them up on
  647. * destroy.
  648. *
  649. * License: www.highcharts.com/license
  650. *
  651. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  652. *
  653. * */
  654. var doc = H.doc;
  655. var removeElement = HTMLUtilities.removeElement;
  656. var extend = U.extend;
  657. /* eslint-disable no-invalid-this, valid-jsdoc */
  658. /**
  659. * @private
  660. * @class
  661. */
  662. var DOMElementProvider = function () {
  663. this.elements = [];
  664. };
  665. extend(DOMElementProvider.prototype, {
  666. /**
  667. * Create an element and keep track of it for later removal.
  668. * Same args as document.createElement
  669. * @private
  670. */
  671. createElement: function () {
  672. var el = doc.createElement.apply(doc,
  673. arguments);
  674. this.elements.push(el);
  675. return el;
  676. },
  677. /**
  678. * Destroy all created elements, removing them from the DOM.
  679. * @private
  680. */
  681. destroyCreatedElements: function () {
  682. this.elements.forEach(function (element) {
  683. removeElement(element);
  684. });
  685. this.elements = [];
  686. }
  687. });
  688. return DOMElementProvider;
  689. });
  690. _registerModule(_modules, 'Accessibility/Utils/EventProvider.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  691. /* *
  692. *
  693. * (c) 2009-2021 Øystein Moseng
  694. *
  695. * Class that can keep track of events added, and clean them up on destroy.
  696. *
  697. * License: www.highcharts.com/license
  698. *
  699. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  700. *
  701. * */
  702. var addEvent = U.addEvent,
  703. extend = U.extend;
  704. /* eslint-disable no-invalid-this, valid-jsdoc */
  705. /**
  706. * @private
  707. * @class
  708. */
  709. var EventProvider = function () {
  710. this.eventRemovers = [];
  711. };
  712. extend(EventProvider.prototype, {
  713. /**
  714. * Add an event to an element and keep track of it for later removal.
  715. * Same args as Highcharts.addEvent.
  716. * @private
  717. * @return {Function}
  718. */
  719. addEvent: function () {
  720. var remover = addEvent.apply(H,
  721. arguments);
  722. this.eventRemovers.push(remover);
  723. return remover;
  724. },
  725. /**
  726. * Remove all added events.
  727. * @private
  728. * @return {void}
  729. */
  730. removeAddedEvents: function () {
  731. this.eventRemovers.forEach(function (remover) {
  732. remover();
  733. });
  734. this.eventRemovers = [];
  735. }
  736. });
  737. return EventProvider;
  738. });
  739. _registerModule(_modules, 'Accessibility/AccessibilityComponent.js', [_modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Utils/DOMElementProvider.js'], _modules['Accessibility/Utils/EventProvider.js'], _modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Utilities.js']], function (ChartUtilities, DOMElementProvider, EventProvider, H, HTMLUtilities, U) {
  740. /* *
  741. *
  742. * (c) 2009-2021 Øystein Moseng
  743. *
  744. * Accessibility component class definition
  745. *
  746. * License: www.highcharts.com/license
  747. *
  748. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  749. *
  750. * */
  751. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  752. var doc = H.doc,
  753. win = H.win;
  754. var removeElement = HTMLUtilities.removeElement,
  755. getFakeMouseEvent = HTMLUtilities.getFakeMouseEvent;
  756. var extend = U.extend,
  757. fireEvent = U.fireEvent,
  758. merge = U.merge;
  759. /* eslint-disable valid-jsdoc */
  760. /** @lends Highcharts.AccessibilityComponent */
  761. var functionsToOverrideByDerivedClasses = {
  762. /**
  763. * Called on component initialization.
  764. */
  765. init: function () { },
  766. /**
  767. * Get keyboard navigation handler for this component.
  768. * @return {Highcharts.KeyboardNavigationHandler}
  769. */
  770. getKeyboardNavigation: function () { },
  771. /**
  772. * Called on updates to the chart,
  773. including options changes.
  774. * Note that this is also called on first render of chart.
  775. */
  776. onChartUpdate: function () { },
  777. /**
  778. * Called on every chart render.
  779. */
  780. onChartRender: function () { },
  781. /**
  782. * Called when accessibility is disabled or chart is destroyed.
  783. */
  784. destroy: function () { }
  785. };
  786. /**
  787. * The AccessibilityComponent base class, representing a part of the chart that
  788. * has accessibility logic connected to it. This class can be inherited from to
  789. * create a custom accessibility component for a chart.
  790. *
  791. * Components should take care to destroy added elements and unregister event
  792. * handlers on destroy. This is handled automatically if using this.addEvent and
  793. * this.createElement.
  794. *
  795. * @sample highcharts/accessibility/custom-component
  796. * Custom accessibility component
  797. *
  798. * @requires module:modules/accessibility
  799. * @class
  800. * @name Highcharts.AccessibilityComponent
  801. */
  802. function AccessibilityComponent() { }
  803. /**
  804. * @lends Highcharts.AccessibilityComponent
  805. */
  806. AccessibilityComponent.prototype = {
  807. /**
  808. * Initialize the class
  809. * @private
  810. * @param {Highcharts.Chart} chart
  811. * Chart object
  812. */
  813. initBase: function (chart) {
  814. this.chart = chart;
  815. this.eventProvider = new EventProvider();
  816. this.domElementProvider = new DOMElementProvider();
  817. // Key code enum for common keys
  818. this.keyCodes = {
  819. left: 37,
  820. right: 39,
  821. up: 38,
  822. down: 40,
  823. enter: 13,
  824. space: 32,
  825. esc: 27,
  826. tab: 9
  827. };
  828. },
  829. /**
  830. * Add an event to an element and keep track of it for later removal.
  831. * See EventProvider for details.
  832. * @private
  833. */
  834. addEvent: function () {
  835. return this.eventProvider.addEvent
  836. .apply(this.eventProvider, arguments);
  837. },
  838. /**
  839. * Create an element and keep track of it for later removal.
  840. * See DOMElementProvider for details.
  841. * @private
  842. */
  843. createElement: function () {
  844. return this.domElementProvider.createElement.apply(this.domElementProvider, arguments);
  845. },
  846. /**
  847. * Fire an event on an element that is either wrapped by Highcharts,
  848. * or a DOM element
  849. * @private
  850. * @param {Highcharts.HTMLElement|Highcharts.HTMLDOMElement|
  851. * Highcharts.SVGDOMElement|Highcharts.SVGElement} el
  852. * @param {Event} eventObject
  853. */
  854. fireEventOnWrappedOrUnwrappedElement: function (el, eventObject) {
  855. var type = eventObject.type;
  856. if (doc.createEvent && (el.dispatchEvent || el.fireEvent)) {
  857. if (el.dispatchEvent) {
  858. el.dispatchEvent(eventObject);
  859. }
  860. else {
  861. el.fireEvent(type, eventObject);
  862. }
  863. }
  864. else {
  865. fireEvent(el, type, eventObject);
  866. }
  867. },
  868. /**
  869. * Utility function to attempt to fake a click event on an element.
  870. * @private
  871. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} element
  872. */
  873. fakeClickEvent: function (element) {
  874. if (element) {
  875. var fakeEventObject = getFakeMouseEvent('click');
  876. this.fireEventOnWrappedOrUnwrappedElement(element, fakeEventObject);
  877. }
  878. },
  879. /**
  880. * Add a new proxy group to the proxy container. Creates the proxy container
  881. * if it does not exist.
  882. * @private
  883. * @param {Highcharts.HTMLAttributes} [attrs]
  884. * The attributes to set on the new group div.
  885. * @return {Highcharts.HTMLDOMElement}
  886. * The new proxy group element.
  887. */
  888. addProxyGroup: function (attrs) {
  889. this.createOrUpdateProxyContainer();
  890. var groupDiv = this.createElement('div');
  891. Object.keys(attrs || {}).forEach(function (prop) {
  892. if (attrs[prop] !== null) {
  893. groupDiv.setAttribute(prop, attrs[prop]);
  894. }
  895. });
  896. this.chart.a11yProxyContainer.appendChild(groupDiv);
  897. return groupDiv;
  898. },
  899. /**
  900. * Creates and updates DOM position of proxy container
  901. * @private
  902. */
  903. createOrUpdateProxyContainer: function () {
  904. var chart = this.chart,
  905. rendererSVGEl = chart.renderer.box;
  906. chart.a11yProxyContainer = chart.a11yProxyContainer ||
  907. this.createProxyContainerElement();
  908. if (rendererSVGEl.nextSibling !== chart.a11yProxyContainer) {
  909. chart.container.insertBefore(chart.a11yProxyContainer, rendererSVGEl.nextSibling);
  910. }
  911. },
  912. /**
  913. * @private
  914. * @return {Highcharts.HTMLDOMElement} element
  915. */
  916. createProxyContainerElement: function () {
  917. var pc = doc.createElement('div');
  918. pc.className = 'highcharts-a11y-proxy-container';
  919. return pc;
  920. },
  921. /**
  922. * Create an invisible proxy HTML button in the same position as an SVG
  923. * element
  924. * @private
  925. * @param {Highcharts.SVGElement} svgElement
  926. * The wrapped svg el to proxy.
  927. * @param {Highcharts.HTMLDOMElement} parentGroup
  928. * The proxy group element in the proxy container to add this button to.
  929. * @param {Highcharts.SVGAttributes} [attributes]
  930. * Additional attributes to set.
  931. * @param {Highcharts.SVGElement} [posElement]
  932. * Element to use for positioning instead of svgElement.
  933. * @param {Function} [preClickEvent]
  934. * Function to call before click event fires.
  935. *
  936. * @return {Highcharts.HTMLDOMElement} The proxy button.
  937. */
  938. createProxyButton: function (svgElement, parentGroup, attributes, posElement, preClickEvent) {
  939. var svgEl = svgElement.element,
  940. proxy = this.createElement('button'),
  941. attrs = merge({
  942. 'aria-label': svgEl.getAttribute('aria-label')
  943. },
  944. attributes);
  945. Object.keys(attrs).forEach(function (prop) {
  946. if (attrs[prop] !== null) {
  947. proxy.setAttribute(prop, attrs[prop]);
  948. }
  949. });
  950. proxy.className = 'highcharts-a11y-proxy-button';
  951. if (preClickEvent) {
  952. this.addEvent(proxy, 'click', preClickEvent);
  953. }
  954. this.setProxyButtonStyle(proxy);
  955. this.updateProxyButtonPosition(proxy, posElement || svgElement);
  956. this.proxyMouseEventsForButton(svgEl, proxy);
  957. // Add to chart div and unhide from screen readers
  958. parentGroup.appendChild(proxy);
  959. if (!attrs['aria-hidden']) {
  960. unhideChartElementFromAT(this.chart, proxy);
  961. }
  962. return proxy;
  963. },
  964. /**
  965. * Get the position relative to chart container for a wrapped SVG element.
  966. * @private
  967. * @param {Highcharts.SVGElement} element
  968. * The element to calculate position for.
  969. * @return {Highcharts.BBoxObject}
  970. * Object with x and y props for the position.
  971. */
  972. getElementPosition: function (element) {
  973. var el = element.element,
  974. div = this.chart.renderTo;
  975. if (div && el && el.getBoundingClientRect) {
  976. var rectEl = el.getBoundingClientRect(),
  977. rectDiv = div.getBoundingClientRect();
  978. return {
  979. x: rectEl.left - rectDiv.left,
  980. y: rectEl.top - rectDiv.top,
  981. width: rectEl.right - rectEl.left,
  982. height: rectEl.bottom - rectEl.top
  983. };
  984. }
  985. return { x: 0, y: 0, width: 1, height: 1 };
  986. },
  987. /**
  988. * @private
  989. * @param {Highcharts.HTMLElement} button The proxy element.
  990. */
  991. setProxyButtonStyle: function (button) {
  992. merge(true, button.style, {
  993. 'border-width': 0,
  994. 'background-color': 'transparent',
  995. cursor: 'pointer',
  996. outline: 'none',
  997. opacity: 0.001,
  998. filter: 'alpha(opacity=1)',
  999. '-ms-filter': 'progid:DXImageTransform.Microsoft.Alpha(Opacity=1)',
  1000. zIndex: 999,
  1001. overflow: 'hidden',
  1002. padding: 0,
  1003. margin: 0,
  1004. display: 'block',
  1005. position: 'absolute'
  1006. });
  1007. },
  1008. /**
  1009. * @private
  1010. * @param {Highcharts.HTMLElement} proxy The proxy to update position of.
  1011. * @param {Highcharts.SVGElement} posElement The element to overlay and take position from.
  1012. */
  1013. updateProxyButtonPosition: function (proxy, posElement) {
  1014. var bBox = this.getElementPosition(posElement);
  1015. merge(true, proxy.style, {
  1016. width: (bBox.width || 1) + 'px',
  1017. height: (bBox.height || 1) + 'px',
  1018. left: (bBox.x || 0) + 'px',
  1019. top: (bBox.y || 0) + 'px'
  1020. });
  1021. },
  1022. /**
  1023. * @private
  1024. * @param {Highcharts.HTMLElement|Highcharts.HTMLDOMElement|
  1025. * Highcharts.SVGDOMElement|Highcharts.SVGElement} source
  1026. * @param {Highcharts.HTMLElement} button
  1027. */
  1028. proxyMouseEventsForButton: function (source, button) {
  1029. var component = this;
  1030. [
  1031. 'click', 'touchstart', 'touchend', 'touchcancel', 'touchmove',
  1032. 'mouseover', 'mouseenter', 'mouseleave', 'mouseout'
  1033. ].forEach(function (evtType) {
  1034. var isTouchEvent = evtType.indexOf('touch') === 0;
  1035. component.addEvent(button, evtType, function (e) {
  1036. var clonedEvent = isTouchEvent ?
  1037. component.cloneTouchEvent(e) :
  1038. component.cloneMouseEvent(e);
  1039. if (source) {
  1040. component.fireEventOnWrappedOrUnwrappedElement(source, clonedEvent);
  1041. }
  1042. e.stopPropagation();
  1043. e.preventDefault();
  1044. }, { passive: false });
  1045. });
  1046. },
  1047. /**
  1048. * Utility function to clone a mouse event for re-dispatching.
  1049. * @private
  1050. * @param {global.MouseEvent} e The event to clone.
  1051. * @return {global.MouseEvent} The cloned event
  1052. */
  1053. cloneMouseEvent: function (e) {
  1054. if (typeof win.MouseEvent === 'function') {
  1055. return new win.MouseEvent(e.type, e);
  1056. }
  1057. // No MouseEvent support, try using initMouseEvent
  1058. if (doc.createEvent) {
  1059. var evt = doc.createEvent('MouseEvent');
  1060. if (evt.initMouseEvent) {
  1061. evt.initMouseEvent(e.type, e.bubbles, // #10561, #12161
  1062. 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);
  1063. return evt;
  1064. }
  1065. }
  1066. return getFakeMouseEvent(e.type);
  1067. },
  1068. /**
  1069. * Utility function to clone a touch event for re-dispatching.
  1070. * @private
  1071. * @param {global.TouchEvent} e The event to clone.
  1072. * @return {global.TouchEvent} The cloned event
  1073. */
  1074. cloneTouchEvent: function (e) {
  1075. var touchListToTouchArray = function (l) {
  1076. var touchArray = [];
  1077. for (var i = 0; i < l.length; ++i) {
  1078. var item = l.item(i);
  1079. if (item) {
  1080. touchArray.push(item);
  1081. }
  1082. }
  1083. return touchArray;
  1084. };
  1085. if (typeof win.TouchEvent === 'function') {
  1086. var newEvent = new win.TouchEvent(e.type, {
  1087. touches: touchListToTouchArray(e.touches),
  1088. targetTouches: touchListToTouchArray(e.targetTouches),
  1089. changedTouches: touchListToTouchArray(e.changedTouches),
  1090. ctrlKey: e.ctrlKey,
  1091. shiftKey: e.shiftKey,
  1092. altKey: e.altKey,
  1093. metaKey: e.metaKey,
  1094. bubbles: e.bubbles,
  1095. cancelable: e.cancelable,
  1096. composed: e.composed,
  1097. detail: e.detail,
  1098. view: e.view
  1099. });
  1100. if (e.defaultPrevented) {
  1101. newEvent.preventDefault();
  1102. }
  1103. return newEvent;
  1104. }
  1105. // Fallback to mouse event
  1106. var fakeEvt = this.cloneMouseEvent(e);
  1107. fakeEvt.touches = e.touches;
  1108. fakeEvt.changedTouches = e.changedTouches;
  1109. fakeEvt.targetTouches = e.targetTouches;
  1110. return fakeEvt;
  1111. },
  1112. /**
  1113. * Remove traces of the component.
  1114. * @private
  1115. */
  1116. destroyBase: function () {
  1117. removeElement(this.chart.a11yProxyContainer);
  1118. this.domElementProvider.destroyCreatedElements();
  1119. this.eventProvider.removeAddedEvents();
  1120. }
  1121. };
  1122. extend(AccessibilityComponent.prototype, functionsToOverrideByDerivedClasses);
  1123. return AccessibilityComponent;
  1124. });
  1125. _registerModule(_modules, 'Accessibility/KeyboardNavigation.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Accessibility/Utils/EventProvider.js']], function (H, U, HTMLUtilities, EventProvider) {
  1126. /* *
  1127. *
  1128. * (c) 2009-2021 Øystein Moseng
  1129. *
  1130. * Main keyboard navigation handling.
  1131. *
  1132. * License: www.highcharts.com/license
  1133. *
  1134. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1135. *
  1136. * */
  1137. var doc = H.doc,
  1138. win = H.win;
  1139. var addEvent = U.addEvent,
  1140. fireEvent = U.fireEvent;
  1141. var getElement = HTMLUtilities.getElement;
  1142. /* eslint-disable valid-jsdoc */
  1143. // Add event listener to document to detect ESC key press and dismiss
  1144. // hover/popup content.
  1145. addEvent(doc, 'keydown', function (e) {
  1146. var keycode = e.which || e.keyCode;
  1147. var esc = 27;
  1148. if (keycode === esc && H.charts) {
  1149. H.charts.forEach(function (chart) {
  1150. if (chart && chart.dismissPopupContent) {
  1151. chart.dismissPopupContent();
  1152. }
  1153. });
  1154. }
  1155. });
  1156. /**
  1157. * Dismiss popup content in chart, including export menu and tooltip.
  1158. */
  1159. H.Chart.prototype.dismissPopupContent = function () {
  1160. var chart = this;
  1161. fireEvent(this, 'dismissPopupContent', {}, function () {
  1162. if (chart.tooltip) {
  1163. chart.tooltip.hide(0);
  1164. }
  1165. chart.hideExportMenu();
  1166. });
  1167. };
  1168. /**
  1169. * The KeyboardNavigation class, containing the overall keyboard navigation
  1170. * logic for the chart.
  1171. *
  1172. * @requires module:modules/accessibility
  1173. *
  1174. * @private
  1175. * @class
  1176. * @param {Highcharts.Chart} chart
  1177. * Chart object
  1178. * @param {object} components
  1179. * Map of component names to AccessibilityComponent objects.
  1180. * @name Highcharts.KeyboardNavigation
  1181. */
  1182. function KeyboardNavigation(chart, components) {
  1183. this.init(chart, components);
  1184. }
  1185. KeyboardNavigation.prototype = {
  1186. /**
  1187. * Initialize the class
  1188. * @private
  1189. * @param {Highcharts.Chart} chart
  1190. * Chart object
  1191. * @param {object} components
  1192. * Map of component names to AccessibilityComponent objects.
  1193. */
  1194. init: function (chart, components) {
  1195. var _this = this;
  1196. var ep = this.eventProvider = new EventProvider();
  1197. this.chart = chart;
  1198. this.components = components;
  1199. this.modules = [];
  1200. this.currentModuleIx = 0;
  1201. // Run an update to get all modules
  1202. this.update();
  1203. ep.addEvent(this.tabindexContainer, 'keydown', function (e) { return _this.onKeydown(e); });
  1204. ep.addEvent(this.tabindexContainer, 'focus', function (e) { return _this.onFocus(e); });
  1205. ['mouseup', 'touchend'].forEach(function (eventName) {
  1206. return ep.addEvent(doc, eventName, function () { return _this.onMouseUp(); });
  1207. });
  1208. ['mousedown', 'touchstart'].forEach(function (eventName) {
  1209. return ep.addEvent(chart.renderTo, eventName, function () {
  1210. _this.isClickingChart = true;
  1211. });
  1212. });
  1213. ep.addEvent(chart.renderTo, 'mouseover', function () {
  1214. _this.pointerIsOverChart = true;
  1215. });
  1216. ep.addEvent(chart.renderTo, 'mouseout', function () {
  1217. _this.pointerIsOverChart = false;
  1218. });
  1219. // Init first module
  1220. if (this.modules.length) {
  1221. this.modules[0].init(1);
  1222. }
  1223. },
  1224. /**
  1225. * Update the modules for the keyboard navigation.
  1226. * @param {Array<string>} [order]
  1227. * Array specifying the tab order of the components.
  1228. */
  1229. update: function (order) {
  1230. var a11yOptions = this.chart.options.accessibility,
  1231. keyboardOptions = a11yOptions && a11yOptions.keyboardNavigation,
  1232. components = this.components;
  1233. this.updateContainerTabindex();
  1234. if (keyboardOptions &&
  1235. keyboardOptions.enabled &&
  1236. order &&
  1237. order.length) {
  1238. // We (still) have keyboard navigation. Update module list
  1239. this.modules = order.reduce(function (modules, componentName) {
  1240. var navModules = components[componentName].getKeyboardNavigation();
  1241. return modules.concat(navModules);
  1242. }, []);
  1243. this.updateExitAnchor();
  1244. }
  1245. else {
  1246. this.modules = [];
  1247. this.currentModuleIx = 0;
  1248. this.removeExitAnchor();
  1249. }
  1250. },
  1251. /**
  1252. * Function to run on container focus
  1253. * @private
  1254. * @param {global.FocusEvent} e Browser focus event.
  1255. */
  1256. onFocus: function (e) {
  1257. var _a;
  1258. var chart = this.chart;
  1259. var focusComesFromChart = (e.relatedTarget &&
  1260. chart.container.contains(e.relatedTarget));
  1261. // Init keyboard nav if tabbing into chart
  1262. if (!this.isClickingChart && !focusComesFromChart) {
  1263. (_a = this.modules[0]) === null || _a === void 0 ? void 0 : _a.init(1);
  1264. }
  1265. },
  1266. /**
  1267. * Reset chart navigation state if we click outside the chart and it's
  1268. * not already reset.
  1269. * @private
  1270. */
  1271. onMouseUp: function () {
  1272. delete this.isClickingChart;
  1273. if (!this.keyboardReset && !this.pointerIsOverChart) {
  1274. var chart = this.chart,
  1275. curMod = this.modules &&
  1276. this.modules[this.currentModuleIx || 0];
  1277. if (curMod && curMod.terminate) {
  1278. curMod.terminate();
  1279. }
  1280. if (chart.focusElement) {
  1281. chart.focusElement.removeFocusBorder();
  1282. }
  1283. this.currentModuleIx = 0;
  1284. this.keyboardReset = true;
  1285. }
  1286. },
  1287. /**
  1288. * Function to run on keydown
  1289. * @private
  1290. * @param {global.KeyboardEvent} ev Browser keydown event.
  1291. */
  1292. onKeydown: function (ev) {
  1293. var e = ev || win.event,
  1294. preventDefault,
  1295. curNavModule = this.modules && this.modules.length &&
  1296. this.modules[this.currentModuleIx];
  1297. // Used for resetting nav state when clicking outside chart
  1298. this.keyboardReset = false;
  1299. // If there is a nav module for the current index, run it.
  1300. // Otherwise, we are outside of the chart in some direction.
  1301. if (curNavModule) {
  1302. var response = curNavModule.run(e);
  1303. if (response === curNavModule.response.success) {
  1304. preventDefault = true;
  1305. }
  1306. else if (response === curNavModule.response.prev) {
  1307. preventDefault = this.prev();
  1308. }
  1309. else if (response === curNavModule.response.next) {
  1310. preventDefault = this.next();
  1311. }
  1312. if (preventDefault) {
  1313. e.preventDefault();
  1314. e.stopPropagation();
  1315. }
  1316. }
  1317. },
  1318. /**
  1319. * Go to previous module.
  1320. * @private
  1321. */
  1322. prev: function () {
  1323. return this.move(-1);
  1324. },
  1325. /**
  1326. * Go to next module.
  1327. * @private
  1328. */
  1329. next: function () {
  1330. return this.move(1);
  1331. },
  1332. /**
  1333. * Move to prev/next module.
  1334. * @private
  1335. * @param {number} direction
  1336. * Direction to move. +1 for next, -1 for prev.
  1337. * @return {boolean}
  1338. * True if there was a valid module in direction.
  1339. */
  1340. move: function (direction) {
  1341. var curModule = this.modules && this.modules[this.currentModuleIx];
  1342. if (curModule && curModule.terminate) {
  1343. curModule.terminate(direction);
  1344. }
  1345. // Remove existing focus border if any
  1346. if (this.chart.focusElement) {
  1347. this.chart.focusElement.removeFocusBorder();
  1348. }
  1349. this.currentModuleIx += direction;
  1350. var newModule = this.modules && this.modules[this.currentModuleIx];
  1351. if (newModule) {
  1352. if (newModule.validate && !newModule.validate()) {
  1353. return this.move(direction); // Invalid module, recurse
  1354. }
  1355. if (newModule.init) {
  1356. newModule.init(direction); // Valid module, init it
  1357. return true;
  1358. }
  1359. }
  1360. // No module
  1361. this.currentModuleIx = 0; // Reset counter
  1362. // Set focus to chart or exit anchor depending on direction
  1363. if (direction > 0) {
  1364. this.exiting = true;
  1365. this.exitAnchor.focus();
  1366. }
  1367. else {
  1368. this.tabindexContainer.focus();
  1369. }
  1370. return false;
  1371. },
  1372. /**
  1373. * We use an exit anchor to move focus out of chart whenever we want, by
  1374. * setting focus to this div and not preventing the default tab action. We
  1375. * also use this when users come back into the chart by tabbing back, in
  1376. * order to navigate from the end of the chart.
  1377. * @private
  1378. */
  1379. updateExitAnchor: function () {
  1380. var endMarkerId = 'highcharts-end-of-chart-marker-' + this.chart.index,
  1381. endMarker = getElement(endMarkerId);
  1382. this.removeExitAnchor();
  1383. if (endMarker) {
  1384. this.makeElementAnExitAnchor(endMarker);
  1385. this.exitAnchor = endMarker;
  1386. }
  1387. else {
  1388. this.createExitAnchor();
  1389. }
  1390. },
  1391. /**
  1392. * Chart container should have tabindex if navigation is enabled.
  1393. * @private
  1394. */
  1395. updateContainerTabindex: function () {
  1396. var a11yOptions = this.chart.options.accessibility,
  1397. keyboardOptions = a11yOptions && a11yOptions.keyboardNavigation,
  1398. shouldHaveTabindex = !(keyboardOptions && keyboardOptions.enabled === false),
  1399. chart = this.chart,
  1400. container = chart.container;
  1401. var tabindexContainer;
  1402. if (chart.renderTo.hasAttribute('tabindex')) {
  1403. container.removeAttribute('tabindex');
  1404. tabindexContainer = chart.renderTo;
  1405. }
  1406. else {
  1407. tabindexContainer = container;
  1408. }
  1409. this.tabindexContainer = tabindexContainer;
  1410. var curTabindex = tabindexContainer.getAttribute('tabindex');
  1411. if (shouldHaveTabindex && !curTabindex) {
  1412. tabindexContainer.setAttribute('tabindex', '0');
  1413. }
  1414. else if (!shouldHaveTabindex) {
  1415. chart.container.removeAttribute('tabindex');
  1416. }
  1417. },
  1418. /**
  1419. * @private
  1420. */
  1421. makeElementAnExitAnchor: function (el) {
  1422. var chartTabindex = this.tabindexContainer.getAttribute('tabindex') || 0;
  1423. el.setAttribute('class', 'highcharts-exit-anchor');
  1424. el.setAttribute('tabindex', chartTabindex);
  1425. el.setAttribute('aria-hidden', false);
  1426. // Handle focus
  1427. this.addExitAnchorEventsToEl(el);
  1428. },
  1429. /**
  1430. * Add new exit anchor to the chart.
  1431. *
  1432. * @private
  1433. */
  1434. createExitAnchor: function () {
  1435. var chart = this.chart,
  1436. exitAnchor = this.exitAnchor = doc.createElement('div');
  1437. chart.renderTo.appendChild(exitAnchor);
  1438. this.makeElementAnExitAnchor(exitAnchor);
  1439. },
  1440. /**
  1441. * @private
  1442. */
  1443. removeExitAnchor: function () {
  1444. if (this.exitAnchor && this.exitAnchor.parentNode) {
  1445. this.exitAnchor.parentNode
  1446. .removeChild(this.exitAnchor);
  1447. delete this.exitAnchor;
  1448. }
  1449. },
  1450. /**
  1451. * @private
  1452. */
  1453. addExitAnchorEventsToEl: function (element) {
  1454. var chart = this.chart,
  1455. keyboardNavigation = this;
  1456. this.eventProvider.addEvent(element, 'focus', function (ev) {
  1457. var e = ev || win.event,
  1458. curModule,
  1459. focusComesFromChart = (e.relatedTarget &&
  1460. chart.container.contains(e.relatedTarget)),
  1461. comingInBackwards = !(focusComesFromChart || keyboardNavigation.exiting);
  1462. if (comingInBackwards) {
  1463. keyboardNavigation.tabindexContainer.focus();
  1464. e.preventDefault();
  1465. // Move to last valid keyboard nav module
  1466. // Note the we don't run it, just set the index
  1467. if (keyboardNavigation.modules &&
  1468. keyboardNavigation.modules.length) {
  1469. keyboardNavigation.currentModuleIx =
  1470. keyboardNavigation.modules.length - 1;
  1471. curModule = keyboardNavigation.modules[keyboardNavigation.currentModuleIx];
  1472. // Validate the module
  1473. if (curModule &&
  1474. curModule.validate && !curModule.validate()) {
  1475. // Invalid. Try moving backwards to find next valid.
  1476. keyboardNavigation.prev();
  1477. }
  1478. else if (curModule) {
  1479. // We have a valid module, init it
  1480. curModule.init(-1);
  1481. }
  1482. }
  1483. }
  1484. else {
  1485. // Don't skip the next focus, we only skip once.
  1486. keyboardNavigation.exiting = false;
  1487. }
  1488. });
  1489. },
  1490. /**
  1491. * Remove all traces of keyboard navigation.
  1492. * @private
  1493. */
  1494. destroy: function () {
  1495. this.removeExitAnchor();
  1496. this.eventProvider.removeAddedEvents();
  1497. this.chart.container.removeAttribute('tabindex');
  1498. }
  1499. };
  1500. return KeyboardNavigation;
  1501. });
  1502. _registerModule(_modules, 'Accessibility/Components/LegendComponent.js', [_modules['Core/Globals.js'], _modules['Core/Legend.js'], _modules['Core/Utilities.js'], _modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/KeyboardNavigationHandler.js'], _modules['Accessibility/Utils/HTMLUtilities.js']], function (H, Legend, U, AccessibilityComponent, KeyboardNavigationHandler, HTMLUtilities) {
  1503. /* *
  1504. *
  1505. * (c) 2009-2021 Øystein Moseng
  1506. *
  1507. * Accessibility component for chart legend.
  1508. *
  1509. * License: www.highcharts.com/license
  1510. *
  1511. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1512. *
  1513. * */
  1514. var addEvent = U.addEvent,
  1515. extend = U.extend,
  1516. find = U.find,
  1517. fireEvent = U.fireEvent;
  1518. var removeElement = HTMLUtilities.removeElement,
  1519. stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  1520. /* eslint-disable no-invalid-this, valid-jsdoc */
  1521. /**
  1522. * @private
  1523. */
  1524. function scrollLegendToItem(legend, itemIx) {
  1525. var itemPage = legend.allItems[itemIx].pageIx,
  1526. curPage = legend.currentPage;
  1527. if (typeof itemPage !== 'undefined' && itemPage + 1 !== curPage) {
  1528. legend.scroll(1 + itemPage - curPage);
  1529. }
  1530. }
  1531. /**
  1532. * @private
  1533. */
  1534. function shouldDoLegendA11y(chart) {
  1535. var items = chart.legend && chart.legend.allItems,
  1536. legendA11yOptions = (chart.options.legend.accessibility || {});
  1537. return !!(items && items.length &&
  1538. !(chart.colorAxis && chart.colorAxis.length) &&
  1539. legendA11yOptions.enabled !== false);
  1540. }
  1541. /**
  1542. * Highlight legend item by index.
  1543. *
  1544. * @private
  1545. * @function Highcharts.Chart#highlightLegendItem
  1546. *
  1547. * @param {number} ix
  1548. *
  1549. * @return {boolean}
  1550. */
  1551. H.Chart.prototype.highlightLegendItem = function (ix) {
  1552. var items = this.legend.allItems,
  1553. oldIx = this.highlightedLegendItemIx;
  1554. if (items[ix]) {
  1555. if (items[oldIx]) {
  1556. fireEvent(items[oldIx].legendGroup.element, 'mouseout');
  1557. }
  1558. scrollLegendToItem(this.legend, ix);
  1559. this.setFocusToElement(items[ix].legendItem, items[ix].a11yProxyElement);
  1560. fireEvent(items[ix].legendGroup.element, 'mouseover');
  1561. return true;
  1562. }
  1563. return false;
  1564. };
  1565. // Keep track of pressed state for legend items
  1566. addEvent(Legend, 'afterColorizeItem', function (e) {
  1567. var chart = this.chart,
  1568. a11yOptions = chart.options.accessibility,
  1569. legendItem = e.item;
  1570. if (a11yOptions.enabled && legendItem && legendItem.a11yProxyElement) {
  1571. legendItem.a11yProxyElement.setAttribute('aria-pressed', e.visible ? 'true' : 'false');
  1572. }
  1573. });
  1574. /**
  1575. * The LegendComponent class
  1576. *
  1577. * @private
  1578. * @class
  1579. * @name Highcharts.LegendComponent
  1580. */
  1581. var LegendComponent = function () { };
  1582. LegendComponent.prototype = new AccessibilityComponent();
  1583. extend(LegendComponent.prototype, /** @lends Highcharts.LegendComponent */ {
  1584. /**
  1585. * Init the component
  1586. * @private
  1587. */
  1588. init: function () {
  1589. var component = this;
  1590. this.proxyElementsList = [];
  1591. this.recreateProxies();
  1592. // Note: Chart could create legend dynamically, so events can not be
  1593. // tied to the component's chart's current legend.
  1594. this.addEvent(Legend, 'afterScroll', function () {
  1595. if (this.chart === component.chart) {
  1596. component.updateProxiesPositions();
  1597. component.updateLegendItemProxyVisibility();
  1598. this.chart.highlightLegendItem(component.highlightedLegendItemIx);
  1599. }
  1600. });
  1601. this.addEvent(Legend, 'afterPositionItem', function (e) {
  1602. if (this.chart === component.chart && this.chart.renderer) {
  1603. component.updateProxyPositionForItem(e.item);
  1604. }
  1605. });
  1606. },
  1607. /**
  1608. * @private
  1609. */
  1610. updateLegendItemProxyVisibility: function () {
  1611. var legend = this.chart.legend,
  1612. items = legend.allItems || [],
  1613. curPage = legend.currentPage || 1,
  1614. clipHeight = legend.clipHeight || 0;
  1615. items.forEach(function (item) {
  1616. var itemPage = item.pageIx || 0,
  1617. y = item._legendItemPos ? item._legendItemPos[1] : 0,
  1618. h = item.legendItem ? Math.round(item.legendItem.getBBox().height) : 0,
  1619. hide = y + h - legend.pages[itemPage] > clipHeight || itemPage !== curPage - 1;
  1620. if (item.a11yProxyElement) {
  1621. item.a11yProxyElement.style.visibility = hide ?
  1622. 'hidden' : 'visible';
  1623. }
  1624. });
  1625. },
  1626. /**
  1627. * The legend needs updates on every render, in order to update positioning
  1628. * of the proxy overlays.
  1629. */
  1630. onChartRender: function () {
  1631. if (shouldDoLegendA11y(this.chart)) {
  1632. this.updateProxiesPositions();
  1633. }
  1634. else {
  1635. this.removeProxies();
  1636. }
  1637. },
  1638. /**
  1639. * @private
  1640. */
  1641. onChartUpdate: function () {
  1642. this.updateLegendTitle();
  1643. },
  1644. /**
  1645. * @private
  1646. */
  1647. updateProxiesPositions: function () {
  1648. for (var _i = 0, _a = this.proxyElementsList; _i < _a.length; _i++) {
  1649. var _b = _a[_i],
  1650. element = _b.element,
  1651. posElement = _b.posElement;
  1652. this.updateProxyButtonPosition(element, posElement);
  1653. }
  1654. },
  1655. /**
  1656. * @private
  1657. */
  1658. updateProxyPositionForItem: function (item) {
  1659. var proxyRef = find(this.proxyElementsList,
  1660. function (ref) { return ref.item === item; });
  1661. if (proxyRef) {
  1662. this.updateProxyButtonPosition(proxyRef.element, proxyRef.posElement);
  1663. }
  1664. },
  1665. /**
  1666. * @private
  1667. */
  1668. recreateProxies: function () {
  1669. this.removeProxies();
  1670. if (shouldDoLegendA11y(this.chart)) {
  1671. this.addLegendProxyGroup();
  1672. this.proxyLegendItems();
  1673. this.updateLegendItemProxyVisibility();
  1674. }
  1675. },
  1676. /**
  1677. * @private
  1678. */
  1679. removeProxies: function () {
  1680. removeElement(this.legendProxyGroup);
  1681. this.proxyElementsList = [];
  1682. },
  1683. /**
  1684. * @private
  1685. */
  1686. updateLegendTitle: function () {
  1687. var _a,
  1688. _b;
  1689. var chart = this.chart;
  1690. var legendTitle = stripHTMLTags((((_b = (_a = chart.legend) === null || _a === void 0 ? void 0 : _a.options.title) === null || _b === void 0 ? void 0 : _b.text) || '').replace(/<br ?\/?>/g, ' '));
  1691. var legendLabel = chart.langFormat('accessibility.legend.legendLabel' + (legendTitle ? '' : 'NoTitle'), {
  1692. chart: chart,
  1693. legendTitle: legendTitle
  1694. });
  1695. if (this.legendProxyGroup) {
  1696. this.legendProxyGroup.setAttribute('aria-label', legendLabel);
  1697. }
  1698. },
  1699. /**
  1700. * @private
  1701. */
  1702. addLegendProxyGroup: function () {
  1703. var a11yOptions = this.chart.options.accessibility,
  1704. groupRole = a11yOptions.landmarkVerbosity === 'all' ?
  1705. 'region' : null;
  1706. this.legendProxyGroup = this.addProxyGroup({
  1707. 'aria-label': '_placeholder_',
  1708. role: groupRole
  1709. });
  1710. },
  1711. /**
  1712. * @private
  1713. */
  1714. proxyLegendItems: function () {
  1715. var component = this,
  1716. items = (this.chart.legend &&
  1717. this.chart.legend.allItems || []);
  1718. items.forEach(function (item) {
  1719. if (item.legendItem && item.legendItem.element) {
  1720. component.proxyLegendItem(item);
  1721. }
  1722. });
  1723. },
  1724. /**
  1725. * @private
  1726. * @param {Highcharts.BubbleLegend|Point|Highcharts.Series} item
  1727. */
  1728. proxyLegendItem: function (item) {
  1729. if (!item.legendItem || !item.legendGroup) {
  1730. return;
  1731. }
  1732. var itemLabel = this.chart.langFormat('accessibility.legend.legendItem', {
  1733. chart: this.chart,
  1734. itemName: stripHTMLTags(item.name)
  1735. }),
  1736. attribs = {
  1737. tabindex: -1,
  1738. 'aria-pressed': item.visible,
  1739. 'aria-label': itemLabel
  1740. },
  1741. // Considers useHTML
  1742. proxyPositioningElement = item.legendGroup.div ?
  1743. item.legendItem : item.legendGroup;
  1744. item.a11yProxyElement = this.createProxyButton(item.legendItem, this.legendProxyGroup, attribs, proxyPositioningElement);
  1745. this.proxyElementsList.push({
  1746. item: item,
  1747. element: item.a11yProxyElement,
  1748. posElement: proxyPositioningElement
  1749. });
  1750. },
  1751. /**
  1752. * Get keyboard navigation handler for this component.
  1753. * @return {Highcharts.KeyboardNavigationHandler}
  1754. */
  1755. getKeyboardNavigation: function () {
  1756. var keys = this.keyCodes,
  1757. component = this,
  1758. chart = this.chart;
  1759. return new KeyboardNavigationHandler(chart, {
  1760. keyCodeMap: [
  1761. [
  1762. [keys.left, keys.right, keys.up, keys.down],
  1763. function (keyCode) {
  1764. return component.onKbdArrowKey(this, keyCode);
  1765. }
  1766. ],
  1767. [
  1768. [keys.enter, keys.space],
  1769. function () {
  1770. return component.onKbdClick(this);
  1771. }
  1772. ]
  1773. ],
  1774. validate: function () {
  1775. return component.shouldHaveLegendNavigation();
  1776. },
  1777. init: function (direction) {
  1778. return component.onKbdNavigationInit(direction);
  1779. }
  1780. });
  1781. },
  1782. /**
  1783. * @private
  1784. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1785. * @param {number} keyCode
  1786. * @return {number}
  1787. * Response code
  1788. */
  1789. onKbdArrowKey: function (keyboardNavigationHandler, keyCode) {
  1790. var keys = this.keyCodes,
  1791. response = keyboardNavigationHandler.response,
  1792. chart = this.chart,
  1793. a11yOptions = chart.options.accessibility,
  1794. numItems = chart.legend.allItems.length,
  1795. direction = (keyCode === keys.left || keyCode === keys.up) ? -1 : 1;
  1796. var res = chart.highlightLegendItem(this.highlightedLegendItemIx + direction);
  1797. if (res) {
  1798. this.highlightedLegendItemIx += direction;
  1799. return response.success;
  1800. }
  1801. if (numItems > 1 &&
  1802. a11yOptions.keyboardNavigation.wrapAround) {
  1803. keyboardNavigationHandler.init(direction);
  1804. return response.success;
  1805. }
  1806. // No wrap, move
  1807. return response[direction > 0 ? 'next' : 'prev'];
  1808. },
  1809. /**
  1810. * @private
  1811. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  1812. * @return {number}
  1813. * Response code
  1814. */
  1815. onKbdClick: function (keyboardNavigationHandler) {
  1816. var legendItem = this.chart.legend.allItems[this.highlightedLegendItemIx];
  1817. if (legendItem && legendItem.a11yProxyElement) {
  1818. fireEvent(legendItem.a11yProxyElement, 'click');
  1819. }
  1820. return keyboardNavigationHandler.response.success;
  1821. },
  1822. /**
  1823. * @private
  1824. * @return {boolean|undefined}
  1825. */
  1826. shouldHaveLegendNavigation: function () {
  1827. var chart = this.chart,
  1828. legendOptions = chart.options.legend || {},
  1829. hasLegend = chart.legend && chart.legend.allItems,
  1830. hasColorAxis = chart.colorAxis && chart.colorAxis.length,
  1831. legendA11yOptions = (legendOptions.accessibility || {});
  1832. return !!(hasLegend &&
  1833. chart.legend.display &&
  1834. !hasColorAxis &&
  1835. legendA11yOptions.enabled &&
  1836. legendA11yOptions.keyboardNavigation &&
  1837. legendA11yOptions.keyboardNavigation.enabled);
  1838. },
  1839. /**
  1840. * @private
  1841. * @param {number} direction
  1842. */
  1843. onKbdNavigationInit: function (direction) {
  1844. var chart = this.chart,
  1845. lastIx = chart.legend.allItems.length - 1,
  1846. ixToHighlight = direction > 0 ? 0 : lastIx;
  1847. chart.highlightLegendItem(ixToHighlight);
  1848. this.highlightedLegendItemIx = ixToHighlight;
  1849. }
  1850. });
  1851. return LegendComponent;
  1852. });
  1853. _registerModule(_modules, 'Accessibility/Components/MenuComponent.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/KeyboardNavigationHandler.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Utils/HTMLUtilities.js']], function (H, U, AccessibilityComponent, KeyboardNavigationHandler, ChartUtilities, HTMLUtilities) {
  1854. /* *
  1855. *
  1856. * (c) 2009-2021 Øystein Moseng
  1857. *
  1858. * Accessibility component for exporting menu.
  1859. *
  1860. * License: www.highcharts.com/license
  1861. *
  1862. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1863. *
  1864. * */
  1865. var extend = U.extend;
  1866. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  1867. var removeElement = HTMLUtilities.removeElement,
  1868. getFakeMouseEvent = HTMLUtilities.getFakeMouseEvent;
  1869. /* eslint-disable no-invalid-this, valid-jsdoc */
  1870. /**
  1871. * Get the wrapped export button element of a chart.
  1872. *
  1873. * @private
  1874. * @param {Highcharts.Chart} chart
  1875. * @returns {Highcharts.SVGElement}
  1876. */
  1877. function getExportMenuButtonElement(chart) {
  1878. return chart.exportSVGElements && chart.exportSVGElements[0];
  1879. }
  1880. /**
  1881. * Show the export menu and focus the first item (if exists).
  1882. *
  1883. * @private
  1884. * @function Highcharts.Chart#showExportMenu
  1885. */
  1886. H.Chart.prototype.showExportMenu = function () {
  1887. var exportButton = getExportMenuButtonElement(this);
  1888. if (exportButton) {
  1889. var el = exportButton.element;
  1890. if (el.onclick) {
  1891. el.onclick(getFakeMouseEvent('click'));
  1892. }
  1893. }
  1894. };
  1895. /**
  1896. * @private
  1897. * @function Highcharts.Chart#hideExportMenu
  1898. */
  1899. H.Chart.prototype.hideExportMenu = function () {
  1900. var chart = this,
  1901. exportList = chart.exportDivElements;
  1902. if (exportList && chart.exportContextMenu) {
  1903. // Reset hover states etc.
  1904. exportList.forEach(function (el) {
  1905. if (el.className === 'highcharts-menu-item' && el.onmouseout) {
  1906. el.onmouseout(getFakeMouseEvent('mouseout'));
  1907. }
  1908. });
  1909. chart.highlightedExportItemIx = 0;
  1910. // Hide the menu div
  1911. chart.exportContextMenu.hideMenu();
  1912. // Make sure the chart has focus and can capture keyboard events
  1913. chart.container.focus();
  1914. }
  1915. };
  1916. /**
  1917. * Highlight export menu item by index.
  1918. *
  1919. * @private
  1920. * @function Highcharts.Chart#highlightExportItem
  1921. *
  1922. * @param {number} ix
  1923. *
  1924. * @return {boolean}
  1925. */
  1926. H.Chart.prototype.highlightExportItem = function (ix) {
  1927. var listItem = this.exportDivElements && this.exportDivElements[ix],
  1928. curHighlighted = this.exportDivElements &&
  1929. this.exportDivElements[this.highlightedExportItemIx],
  1930. hasSVGFocusSupport;
  1931. if (listItem &&
  1932. listItem.tagName === 'LI' &&
  1933. !(listItem.children && listItem.children.length)) {
  1934. // Test if we have focus support for SVG elements
  1935. hasSVGFocusSupport = !!(this.renderTo.getElementsByTagName('g')[0] || {}).focus;
  1936. // Only focus if we can set focus back to the elements after
  1937. // destroying the menu (#7422)
  1938. if (listItem.focus && hasSVGFocusSupport) {
  1939. listItem.focus();
  1940. }
  1941. if (curHighlighted && curHighlighted.onmouseout) {
  1942. curHighlighted.onmouseout(getFakeMouseEvent('mouseout'));
  1943. }
  1944. if (listItem.onmouseover) {
  1945. listItem.onmouseover(getFakeMouseEvent('mouseover'));
  1946. }
  1947. this.highlightedExportItemIx = ix;
  1948. return true;
  1949. }
  1950. return false;
  1951. };
  1952. /**
  1953. * Try to highlight the last valid export menu item.
  1954. *
  1955. * @private
  1956. * @function Highcharts.Chart#highlightLastExportItem
  1957. * @return {boolean}
  1958. */
  1959. H.Chart.prototype.highlightLastExportItem = function () {
  1960. var chart = this,
  1961. i;
  1962. if (chart.exportDivElements) {
  1963. i = chart.exportDivElements.length;
  1964. while (i--) {
  1965. if (chart.highlightExportItem(i)) {
  1966. return true;
  1967. }
  1968. }
  1969. }
  1970. return false;
  1971. };
  1972. /**
  1973. * @private
  1974. * @param {Highcharts.Chart} chart
  1975. */
  1976. function exportingShouldHaveA11y(chart) {
  1977. var exportingOpts = chart.options.exporting,
  1978. exportButton = getExportMenuButtonElement(chart);
  1979. return !!(exportingOpts &&
  1980. exportingOpts.enabled !== false &&
  1981. exportingOpts.accessibility &&
  1982. exportingOpts.accessibility.enabled &&
  1983. exportButton &&
  1984. exportButton.element);
  1985. }
  1986. /**
  1987. * The MenuComponent class
  1988. *
  1989. * @private
  1990. * @class
  1991. * @name Highcharts.MenuComponent
  1992. */
  1993. var MenuComponent = function () { };
  1994. MenuComponent.prototype = new AccessibilityComponent();
  1995. extend(MenuComponent.prototype, /** @lends Highcharts.MenuComponent */ {
  1996. /**
  1997. * Init the component
  1998. */
  1999. init: function () {
  2000. var chart = this.chart,
  2001. component = this;
  2002. this.addEvent(chart, 'exportMenuShown', function () {
  2003. component.onMenuShown();
  2004. });
  2005. this.addEvent(chart, 'exportMenuHidden', function () {
  2006. component.onMenuHidden();
  2007. });
  2008. },
  2009. /**
  2010. * @private
  2011. */
  2012. onMenuHidden: function () {
  2013. var menu = this.chart.exportContextMenu;
  2014. if (menu) {
  2015. menu.setAttribute('aria-hidden', 'true');
  2016. }
  2017. this.isExportMenuShown = false;
  2018. this.setExportButtonExpandedState('false');
  2019. },
  2020. /**
  2021. * @private
  2022. */
  2023. onMenuShown: function () {
  2024. var chart = this.chart,
  2025. menu = chart.exportContextMenu;
  2026. if (menu) {
  2027. this.addAccessibleContextMenuAttribs();
  2028. unhideChartElementFromAT(chart, menu);
  2029. }
  2030. this.isExportMenuShown = true;
  2031. this.setExportButtonExpandedState('true');
  2032. },
  2033. /**
  2034. * @private
  2035. * @param {string} stateStr
  2036. */
  2037. setExportButtonExpandedState: function (stateStr) {
  2038. var button = this.exportButtonProxy;
  2039. if (button) {
  2040. button.setAttribute('aria-expanded', stateStr);
  2041. }
  2042. },
  2043. /**
  2044. * Called on each render of the chart. We need to update positioning of the
  2045. * proxy overlay.
  2046. */
  2047. onChartRender: function () {
  2048. var chart = this.chart,
  2049. a11yOptions = chart.options.accessibility;
  2050. // Always start with a clean slate
  2051. removeElement(this.exportProxyGroup);
  2052. // Set screen reader properties on export menu
  2053. if (exportingShouldHaveA11y(chart)) {
  2054. // Proxy button and group
  2055. this.exportProxyGroup = this.addProxyGroup(
  2056. // Wrap in a region div if verbosity is high
  2057. a11yOptions.landmarkVerbosity === 'all' ? {
  2058. 'aria-label': chart.langFormat('accessibility.exporting.exportRegionLabel', { chart: chart }),
  2059. 'role': 'region'
  2060. } : {});
  2061. var button = getExportMenuButtonElement(this.chart);
  2062. this.exportButtonProxy = this.createProxyButton(button, this.exportProxyGroup, {
  2063. 'aria-label': chart.langFormat('accessibility.exporting.menuButtonLabel', { chart: chart }),
  2064. 'aria-expanded': 'false'
  2065. });
  2066. }
  2067. },
  2068. /**
  2069. * @private
  2070. */
  2071. addAccessibleContextMenuAttribs: function () {
  2072. var chart = this.chart,
  2073. exportList = chart.exportDivElements;
  2074. if (exportList && exportList.length) {
  2075. // Set tabindex on the menu items to allow focusing by script
  2076. // Set role to give screen readers a chance to pick up the contents
  2077. exportList.forEach(function (item) {
  2078. if (item.tagName === 'LI' &&
  2079. !(item.children && item.children.length)) {
  2080. item.setAttribute('tabindex', -1);
  2081. }
  2082. else {
  2083. item.setAttribute('aria-hidden', 'true');
  2084. }
  2085. });
  2086. // Set accessibility properties on parent div
  2087. var parentDiv = exportList[0].parentNode;
  2088. parentDiv.removeAttribute('aria-hidden');
  2089. parentDiv.setAttribute('aria-label', chart.langFormat('accessibility.exporting.chartMenuLabel', { chart: chart }));
  2090. }
  2091. },
  2092. /**
  2093. * Get keyboard navigation handler for this component.
  2094. * @return {Highcharts.KeyboardNavigationHandler}
  2095. */
  2096. getKeyboardNavigation: function () {
  2097. var keys = this.keyCodes,
  2098. chart = this.chart,
  2099. component = this;
  2100. return new KeyboardNavigationHandler(chart, {
  2101. keyCodeMap: [
  2102. // Arrow prev handler
  2103. [
  2104. [keys.left, keys.up],
  2105. function () {
  2106. return component.onKbdPrevious(this);
  2107. }
  2108. ],
  2109. // Arrow next handler
  2110. [
  2111. [keys.right, keys.down],
  2112. function () {
  2113. return component.onKbdNext(this);
  2114. }
  2115. ],
  2116. // Click handler
  2117. [
  2118. [keys.enter, keys.space],
  2119. function () {
  2120. return component.onKbdClick(this);
  2121. }
  2122. ]
  2123. ],
  2124. // Only run exporting navigation if exporting support exists and is
  2125. // enabled on chart
  2126. validate: function () {
  2127. return chart.exportChart &&
  2128. chart.options.exporting.enabled !== false &&
  2129. chart.options.exporting.accessibility.enabled !==
  2130. false;
  2131. },
  2132. // Focus export menu button
  2133. init: function () {
  2134. var exportBtn = component.exportButtonProxy,
  2135. exportGroup = chart.exportingGroup;
  2136. if (exportGroup && exportBtn) {
  2137. chart.setFocusToElement(exportGroup, exportBtn);
  2138. }
  2139. },
  2140. // Hide the menu
  2141. terminate: function () {
  2142. chart.hideExportMenu();
  2143. }
  2144. });
  2145. },
  2146. /**
  2147. * @private
  2148. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  2149. * @return {number}
  2150. * Response code
  2151. */
  2152. onKbdPrevious: function (keyboardNavigationHandler) {
  2153. var chart = this.chart,
  2154. a11yOptions = chart.options.accessibility,
  2155. response = keyboardNavigationHandler.response,
  2156. i = chart.highlightedExportItemIx || 0;
  2157. // Try to highlight prev item in list. Highlighting e.g.
  2158. // separators will fail.
  2159. while (i--) {
  2160. if (chart.highlightExportItem(i)) {
  2161. return response.success;
  2162. }
  2163. }
  2164. // We failed, so wrap around or move to prev module
  2165. if (a11yOptions.keyboardNavigation.wrapAround) {
  2166. chart.highlightLastExportItem();
  2167. return response.success;
  2168. }
  2169. return response.prev;
  2170. },
  2171. /**
  2172. * @private
  2173. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  2174. * @return {number}
  2175. * Response code
  2176. */
  2177. onKbdNext: function (keyboardNavigationHandler) {
  2178. var chart = this.chart,
  2179. a11yOptions = chart.options.accessibility,
  2180. response = keyboardNavigationHandler.response,
  2181. i = (chart.highlightedExportItemIx || 0) + 1;
  2182. // Try to highlight next item in list. Highlighting e.g.
  2183. // separators will fail.
  2184. for (; i < chart.exportDivElements.length; ++i) {
  2185. if (chart.highlightExportItem(i)) {
  2186. return response.success;
  2187. }
  2188. }
  2189. // We failed, so wrap around or move to next module
  2190. if (a11yOptions.keyboardNavigation.wrapAround) {
  2191. chart.highlightExportItem(0);
  2192. return response.success;
  2193. }
  2194. return response.next;
  2195. },
  2196. /**
  2197. * @private
  2198. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  2199. * @return {number}
  2200. * Response code
  2201. */
  2202. onKbdClick: function (keyboardNavigationHandler) {
  2203. var chart = this.chart,
  2204. curHighlightedItem = chart.exportDivElements[chart.highlightedExportItemIx],
  2205. exportButtonElement = getExportMenuButtonElement(chart).element;
  2206. if (this.isExportMenuShown) {
  2207. this.fakeClickEvent(curHighlightedItem);
  2208. }
  2209. else {
  2210. this.fakeClickEvent(exportButtonElement);
  2211. chart.highlightExportItem(0);
  2212. }
  2213. return keyboardNavigationHandler.response.success;
  2214. }
  2215. });
  2216. return MenuComponent;
  2217. });
  2218. _registerModule(_modules, 'Accessibility/Components/SeriesComponent/SeriesKeyboardNavigation.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Series/Point.js'], _modules['Core/Series/Series.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js'], _modules['Accessibility/KeyboardNavigationHandler.js'], _modules['Accessibility/Utils/EventProvider.js'], _modules['Accessibility/Utils/ChartUtilities.js']], function (Chart, Point, Series, SeriesRegistry, U, KeyboardNavigationHandler, EventProvider, ChartUtilities) {
  2219. /* *
  2220. *
  2221. * (c) 2009-2021 Øystein Moseng
  2222. *
  2223. * Handle keyboard navigation for series.
  2224. *
  2225. * License: www.highcharts.com/license
  2226. *
  2227. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2228. *
  2229. * */
  2230. var seriesTypes = SeriesRegistry.seriesTypes;
  2231. var defined = U.defined,
  2232. extend = U.extend,
  2233. fireEvent = U.fireEvent;
  2234. var getPointFromXY = ChartUtilities.getPointFromXY,
  2235. getSeriesFromName = ChartUtilities.getSeriesFromName,
  2236. scrollToPoint = ChartUtilities.scrollToPoint;
  2237. /* eslint-disable no-invalid-this, valid-jsdoc */
  2238. /*
  2239. * Set for which series types it makes sense to move to the closest point with
  2240. * up/down arrows, and which series types should just move to next series.
  2241. */
  2242. Series.prototype.keyboardMoveVertical = true;
  2243. ['column', 'pie'].forEach(function (type) {
  2244. if (seriesTypes[type]) {
  2245. seriesTypes[type].prototype.keyboardMoveVertical = false;
  2246. }
  2247. });
  2248. /**
  2249. * Get the index of a point in a series. This is needed when using e.g. data
  2250. * grouping.
  2251. *
  2252. * @private
  2253. * @function getPointIndex
  2254. *
  2255. * @param {Highcharts.AccessibilityPoint} point
  2256. * The point to find index of.
  2257. *
  2258. * @return {number|undefined}
  2259. * The index in the series.points array of the point.
  2260. */
  2261. function getPointIndex(point) {
  2262. var index = point.index,
  2263. points = point.series.points,
  2264. i = points.length;
  2265. if (points[index] !== point) {
  2266. while (i--) {
  2267. if (points[i] === point) {
  2268. return i;
  2269. }
  2270. }
  2271. }
  2272. else {
  2273. return index;
  2274. }
  2275. }
  2276. /**
  2277. * Determine if series navigation should be skipped
  2278. *
  2279. * @private
  2280. * @function isSkipSeries
  2281. *
  2282. * @param {Highcharts.Series} series
  2283. *
  2284. * @return {boolean|number|undefined}
  2285. */
  2286. function isSkipSeries(series) {
  2287. var a11yOptions = series.chart.options.accessibility,
  2288. seriesNavOptions = a11yOptions.keyboardNavigation.seriesNavigation,
  2289. seriesA11yOptions = series.options.accessibility || {},
  2290. seriesKbdNavOptions = seriesA11yOptions.keyboardNavigation;
  2291. return seriesKbdNavOptions && seriesKbdNavOptions.enabled === false ||
  2292. seriesA11yOptions.enabled === false ||
  2293. series.options.enableMouseTracking === false || // #8440
  2294. !series.visible ||
  2295. // Skip all points in a series where pointNavigationEnabledThreshold is
  2296. // reached
  2297. (seriesNavOptions.pointNavigationEnabledThreshold &&
  2298. seriesNavOptions.pointNavigationEnabledThreshold <=
  2299. series.points.length);
  2300. }
  2301. /**
  2302. * Determine if navigation for a point should be skipped
  2303. *
  2304. * @private
  2305. * @function isSkipPoint
  2306. *
  2307. * @param {Highcharts.Point} point
  2308. *
  2309. * @return {boolean|number|undefined}
  2310. */
  2311. function isSkipPoint(point) {
  2312. var _a;
  2313. var a11yOptions = point.series.chart.options.accessibility;
  2314. var pointA11yDisabled = ((_a = point.options.accessibility) === null || _a === void 0 ? void 0 : _a.enabled) === false;
  2315. return point.isNull &&
  2316. a11yOptions.keyboardNavigation.seriesNavigation.skipNullPoints ||
  2317. point.visible === false ||
  2318. point.isInside === false ||
  2319. pointA11yDisabled ||
  2320. isSkipSeries(point.series);
  2321. }
  2322. /**
  2323. * Get the point in a series that is closest (in pixel distance) to a reference
  2324. * point. Optionally supply weight factors for x and y directions.
  2325. *
  2326. * @private
  2327. * @function getClosestPoint
  2328. *
  2329. * @param {Highcharts.Point} point
  2330. * @param {Highcharts.Series} series
  2331. * @param {number} [xWeight]
  2332. * @param {number} [yWeight]
  2333. *
  2334. * @return {Highcharts.Point|undefined}
  2335. */
  2336. function getClosestPoint(point, series, xWeight, yWeight) {
  2337. var minDistance = Infinity,
  2338. dPoint,
  2339. minIx,
  2340. distance,
  2341. i = series.points.length,
  2342. hasUndefinedPosition = function (point) {
  2343. return !(defined(point.plotX) && defined(point.plotY));
  2344. };
  2345. if (hasUndefinedPosition(point)) {
  2346. return;
  2347. }
  2348. while (i--) {
  2349. dPoint = series.points[i];
  2350. if (hasUndefinedPosition(dPoint)) {
  2351. continue;
  2352. }
  2353. distance = (point.plotX - dPoint.plotX) *
  2354. (point.plotX - dPoint.plotX) *
  2355. (xWeight || 1) +
  2356. (point.plotY - dPoint.plotY) *
  2357. (point.plotY - dPoint.plotY) *
  2358. (yWeight || 1);
  2359. if (distance < minDistance) {
  2360. minDistance = distance;
  2361. minIx = i;
  2362. }
  2363. }
  2364. return defined(minIx) ? series.points[minIx] : void 0;
  2365. }
  2366. /**
  2367. * Highlights a point (show tooltip and display hover state).
  2368. *
  2369. * @private
  2370. * @function Highcharts.Point#highlight
  2371. *
  2372. * @return {Highcharts.Point}
  2373. * This highlighted point.
  2374. */
  2375. Point.prototype.highlight = function () {
  2376. var chart = this.series.chart;
  2377. if (!this.isNull) {
  2378. this.onMouseOver(); // Show the hover marker and tooltip
  2379. }
  2380. else {
  2381. if (chart.tooltip) {
  2382. chart.tooltip.hide(0);
  2383. }
  2384. // Don't call blur on the element, as it messes up the chart div's focus
  2385. }
  2386. scrollToPoint(this);
  2387. // We focus only after calling onMouseOver because the state change can
  2388. // change z-index and mess up the element.
  2389. if (this.graphic) {
  2390. chart.setFocusToElement(this.graphic);
  2391. }
  2392. chart.highlightedPoint = this;
  2393. return this;
  2394. };
  2395. /**
  2396. * Function to highlight next/previous point in chart.
  2397. *
  2398. * @private
  2399. * @function Highcharts.Chart#highlightAdjacentPoint
  2400. *
  2401. * @param {boolean} next
  2402. * Flag for the direction.
  2403. *
  2404. * @return {Highcharts.Point|boolean}
  2405. * Returns highlighted point on success, false on failure (no adjacent
  2406. * point to highlight in chosen direction).
  2407. */
  2408. Chart.prototype.highlightAdjacentPoint = function (next) {
  2409. var chart = this,
  2410. series = chart.series,
  2411. curPoint = chart.highlightedPoint,
  2412. curPointIndex = curPoint && getPointIndex(curPoint) || 0,
  2413. curPoints = (curPoint && curPoint.series.points),
  2414. lastSeries = chart.series && chart.series[chart.series.length - 1],
  2415. lastPoint = lastSeries && lastSeries.points &&
  2416. lastSeries.points[lastSeries.points.length - 1],
  2417. newSeries,
  2418. newPoint;
  2419. // If no points, return false
  2420. if (!series[0] || !series[0].points) {
  2421. return false;
  2422. }
  2423. if (!curPoint) {
  2424. // No point is highlighted yet. Try first/last point depending on move
  2425. // direction
  2426. newPoint = next ? series[0].points[0] : lastPoint;
  2427. }
  2428. else {
  2429. // We have a highlighted point.
  2430. // Grab next/prev point & series
  2431. newSeries = series[curPoint.series.index + (next ? 1 : -1)];
  2432. newPoint = curPoints[curPointIndex + (next ? 1 : -1)];
  2433. if (!newPoint && newSeries) {
  2434. // Done with this series, try next one
  2435. newPoint = newSeries.points[next ? 0 : newSeries.points.length - 1];
  2436. }
  2437. // If there is no adjacent point, we return false
  2438. if (!newPoint) {
  2439. return false;
  2440. }
  2441. }
  2442. // Recursively skip points
  2443. if (isSkipPoint(newPoint)) {
  2444. // If we skip this whole series, move to the end of the series before we
  2445. // recurse, just to optimize
  2446. newSeries = newPoint.series;
  2447. if (isSkipSeries(newSeries)) {
  2448. chart.highlightedPoint = next ?
  2449. newSeries.points[newSeries.points.length - 1] :
  2450. newSeries.points[0];
  2451. }
  2452. else {
  2453. // Otherwise, just move one point
  2454. chart.highlightedPoint = newPoint;
  2455. }
  2456. // Retry
  2457. return chart.highlightAdjacentPoint(next);
  2458. }
  2459. // There is an adjacent point, highlight it
  2460. return newPoint.highlight();
  2461. };
  2462. /**
  2463. * Highlight first valid point in a series. Returns the point if successfully
  2464. * highlighted, otherwise false. If there is a highlighted point in the series,
  2465. * use that as starting point.
  2466. *
  2467. * @private
  2468. * @function Highcharts.Series#highlightFirstValidPoint
  2469. *
  2470. * @return {boolean|Highcharts.Point}
  2471. */
  2472. Series.prototype.highlightFirstValidPoint = function () {
  2473. var curPoint = this.chart.highlightedPoint,
  2474. start = (curPoint && curPoint.series) === this ?
  2475. getPointIndex(curPoint) :
  2476. 0,
  2477. points = this.points,
  2478. len = points.length;
  2479. if (points && len) {
  2480. for (var i = start; i < len; ++i) {
  2481. if (!isSkipPoint(points[i])) {
  2482. return points[i].highlight();
  2483. }
  2484. }
  2485. for (var j = start; j >= 0; --j) {
  2486. if (!isSkipPoint(points[j])) {
  2487. return points[j].highlight();
  2488. }
  2489. }
  2490. }
  2491. return false;
  2492. };
  2493. /**
  2494. * Highlight next/previous series in chart. Returns false if no adjacent series
  2495. * in the direction, otherwise returns new highlighted point.
  2496. *
  2497. * @private
  2498. * @function Highcharts.Chart#highlightAdjacentSeries
  2499. *
  2500. * @param {boolean} down
  2501. *
  2502. * @return {Highcharts.Point|boolean}
  2503. */
  2504. Chart.prototype.highlightAdjacentSeries = function (down) {
  2505. var chart = this,
  2506. newSeries,
  2507. newPoint,
  2508. adjacentNewPoint,
  2509. curPoint = chart.highlightedPoint,
  2510. lastSeries = chart.series && chart.series[chart.series.length - 1],
  2511. lastPoint = lastSeries && lastSeries.points &&
  2512. lastSeries.points[lastSeries.points.length - 1];
  2513. // If no point is highlighted, highlight the first/last point
  2514. if (!chart.highlightedPoint) {
  2515. newSeries = down ? (chart.series && chart.series[0]) : lastSeries;
  2516. newPoint = down ?
  2517. (newSeries && newSeries.points && newSeries.points[0]) : lastPoint;
  2518. return newPoint ? newPoint.highlight() : false;
  2519. }
  2520. newSeries = chart.series[curPoint.series.index + (down ? -1 : 1)];
  2521. if (!newSeries) {
  2522. return false;
  2523. }
  2524. // We have a new series in this direction, find the right point
  2525. // Weigh xDistance as counting much higher than Y distance
  2526. newPoint = getClosestPoint(curPoint, newSeries, 4);
  2527. if (!newPoint) {
  2528. return false;
  2529. }
  2530. // New series and point exists, but we might want to skip it
  2531. if (isSkipSeries(newSeries)) {
  2532. // Skip the series
  2533. newPoint.highlight();
  2534. adjacentNewPoint = chart.highlightAdjacentSeries(down); // Try recurse
  2535. if (!adjacentNewPoint) {
  2536. // Recurse failed
  2537. curPoint.highlight();
  2538. return false;
  2539. }
  2540. // Recurse succeeded
  2541. return adjacentNewPoint;
  2542. }
  2543. // Highlight the new point or any first valid point back or forwards from it
  2544. newPoint.highlight();
  2545. return newPoint.series.highlightFirstValidPoint();
  2546. };
  2547. /**
  2548. * Highlight the closest point vertically.
  2549. *
  2550. * @private
  2551. * @function Highcharts.Chart#highlightAdjacentPointVertical
  2552. *
  2553. * @param {boolean} down
  2554. *
  2555. * @return {Highcharts.Point|boolean}
  2556. */
  2557. Chart.prototype.highlightAdjacentPointVertical = function (down) {
  2558. var curPoint = this.highlightedPoint,
  2559. minDistance = Infinity,
  2560. bestPoint;
  2561. if (!defined(curPoint.plotX) || !defined(curPoint.plotY)) {
  2562. return false;
  2563. }
  2564. this.series.forEach(function (series) {
  2565. if (isSkipSeries(series)) {
  2566. return;
  2567. }
  2568. series.points.forEach(function (point) {
  2569. if (!defined(point.plotY) || !defined(point.plotX) ||
  2570. point === curPoint) {
  2571. return;
  2572. }
  2573. var yDistance = point.plotY - curPoint.plotY,
  2574. width = Math.abs(point.plotX - curPoint.plotX),
  2575. distance = Math.abs(yDistance) * Math.abs(yDistance) +
  2576. width * width * 4; // Weigh horizontal distance highly
  2577. // Reverse distance number if axis is reversed
  2578. if (series.yAxis && series.yAxis.reversed) {
  2579. yDistance *= -1;
  2580. }
  2581. if (yDistance <= 0 && down || yDistance >= 0 && !down || // Chk dir
  2582. distance < 5 || // Points in same spot => infinite loop
  2583. isSkipPoint(point)) {
  2584. return;
  2585. }
  2586. if (distance < minDistance) {
  2587. minDistance = distance;
  2588. bestPoint = point;
  2589. }
  2590. });
  2591. });
  2592. return bestPoint ? bestPoint.highlight() : false;
  2593. };
  2594. /**
  2595. * @private
  2596. * @param {Highcharts.Chart} chart
  2597. * @return {Highcharts.Point|boolean}
  2598. */
  2599. function highlightFirstValidPointInChart(chart) {
  2600. var res = false;
  2601. delete chart.highlightedPoint;
  2602. res = chart.series.reduce(function (acc, cur) {
  2603. return acc || cur.highlightFirstValidPoint();
  2604. }, false);
  2605. return res;
  2606. }
  2607. /**
  2608. * @private
  2609. * @param {Highcharts.Chart} chart
  2610. * @return {Highcharts.Point|boolean}
  2611. */
  2612. function highlightLastValidPointInChart(chart) {
  2613. var numSeries = chart.series.length,
  2614. i = numSeries,
  2615. res = false;
  2616. while (i--) {
  2617. chart.highlightedPoint = chart.series[i].points[chart.series[i].points.length - 1];
  2618. // Highlight first valid point in the series will also
  2619. // look backwards. It always starts from currently
  2620. // highlighted point.
  2621. res = chart.series[i].highlightFirstValidPoint();
  2622. if (res) {
  2623. break;
  2624. }
  2625. }
  2626. return res;
  2627. }
  2628. /**
  2629. * @private
  2630. * @param {Highcharts.Chart} chart
  2631. */
  2632. function updateChartFocusAfterDrilling(chart) {
  2633. highlightFirstValidPointInChart(chart);
  2634. if (chart.focusElement) {
  2635. chart.focusElement.removeFocusBorder();
  2636. }
  2637. }
  2638. /**
  2639. * @private
  2640. * @class
  2641. * @name Highcharts.SeriesKeyboardNavigation
  2642. */
  2643. function SeriesKeyboardNavigation(chart, keyCodes) {
  2644. this.keyCodes = keyCodes;
  2645. this.chart = chart;
  2646. }
  2647. extend(SeriesKeyboardNavigation.prototype, /** @lends Highcharts.SeriesKeyboardNavigation */ {
  2648. /**
  2649. * Init the keyboard navigation
  2650. */
  2651. init: function () {
  2652. var keyboardNavigation = this,
  2653. chart = this.chart,
  2654. e = this.eventProvider = new EventProvider();
  2655. e.addEvent(Series, 'destroy', function () {
  2656. return keyboardNavigation.onSeriesDestroy(this);
  2657. });
  2658. e.addEvent(chart, 'afterDrilldown', function () {
  2659. updateChartFocusAfterDrilling(this);
  2660. });
  2661. e.addEvent(chart, 'drilldown', function (e) {
  2662. var point = e.point,
  2663. series = point.series;
  2664. keyboardNavigation.lastDrilledDownPoint = {
  2665. x: point.x,
  2666. y: point.y,
  2667. seriesName: series ? series.name : ''
  2668. };
  2669. });
  2670. e.addEvent(chart, 'drillupall', function () {
  2671. setTimeout(function () {
  2672. keyboardNavigation.onDrillupAll();
  2673. }, 10);
  2674. });
  2675. },
  2676. onDrillupAll: function () {
  2677. // After drillup we want to find the point that was drilled down to and
  2678. // highlight it.
  2679. var last = this.lastDrilledDownPoint,
  2680. chart = this.chart,
  2681. series = last && getSeriesFromName(chart,
  2682. last.seriesName),
  2683. point;
  2684. if (last && series && defined(last.x) && defined(last.y)) {
  2685. point = getPointFromXY(series, last.x, last.y);
  2686. }
  2687. // Container focus can be lost on drillup due to deleted elements.
  2688. if (chart.container) {
  2689. chart.container.focus();
  2690. }
  2691. if (point && point.highlight) {
  2692. point.highlight();
  2693. }
  2694. if (chart.focusElement) {
  2695. chart.focusElement.removeFocusBorder();
  2696. }
  2697. },
  2698. /**
  2699. * @return {Highcharts.KeyboardNavigationHandler}
  2700. */
  2701. getKeyboardNavigationHandler: function () {
  2702. var keyboardNavigation = this,
  2703. keys = this.keyCodes,
  2704. chart = this.chart,
  2705. inverted = chart.inverted;
  2706. return new KeyboardNavigationHandler(chart, {
  2707. keyCodeMap: [
  2708. [inverted ? [keys.up, keys.down] : [keys.left, keys.right], function (keyCode) {
  2709. return keyboardNavigation.onKbdSideways(this, keyCode);
  2710. }],
  2711. [inverted ? [keys.left, keys.right] : [keys.up, keys.down], function (keyCode) {
  2712. return keyboardNavigation.onKbdVertical(this, keyCode);
  2713. }],
  2714. [[keys.enter, keys.space], function (keyCode, event) {
  2715. var point = chart.highlightedPoint;
  2716. if (point) {
  2717. fireEvent(point.series, 'click', extend(event, {
  2718. point: point
  2719. }));
  2720. point.firePointEvent('click');
  2721. }
  2722. return this.response.success;
  2723. }]
  2724. ],
  2725. init: function (dir) {
  2726. return keyboardNavigation.onHandlerInit(this, dir);
  2727. },
  2728. terminate: function () {
  2729. return keyboardNavigation.onHandlerTerminate();
  2730. }
  2731. });
  2732. },
  2733. /**
  2734. * @private
  2735. * @param {Highcharts.KeyboardNavigationHandler} handler
  2736. * @param {number} keyCode
  2737. * @return {number}
  2738. * response
  2739. */
  2740. onKbdSideways: function (handler, keyCode) {
  2741. var keys = this.keyCodes,
  2742. isNext = keyCode === keys.right || keyCode === keys.down;
  2743. return this.attemptHighlightAdjacentPoint(handler, isNext);
  2744. },
  2745. /**
  2746. * @private
  2747. * @param {Highcharts.KeyboardNavigationHandler} handler
  2748. * @param {number} keyCode
  2749. * @return {number}
  2750. * response
  2751. */
  2752. onKbdVertical: function (handler, keyCode) {
  2753. var chart = this.chart,
  2754. keys = this.keyCodes,
  2755. isNext = keyCode === keys.down || keyCode === keys.right,
  2756. navOptions = chart.options.accessibility.keyboardNavigation
  2757. .seriesNavigation;
  2758. // Handle serialized mode, act like left/right
  2759. if (navOptions.mode && navOptions.mode === 'serialize') {
  2760. return this.attemptHighlightAdjacentPoint(handler, isNext);
  2761. }
  2762. // Normal mode, move between series
  2763. var highlightMethod = (chart.highlightedPoint &&
  2764. chart.highlightedPoint.series.keyboardMoveVertical) ?
  2765. 'highlightAdjacentPointVertical' :
  2766. 'highlightAdjacentSeries';
  2767. chart[highlightMethod](isNext);
  2768. return handler.response.success;
  2769. },
  2770. /**
  2771. * @private
  2772. * @param {Highcharts.KeyboardNavigationHandler} handler
  2773. * @param {number} initDirection
  2774. * @return {number}
  2775. * response
  2776. */
  2777. onHandlerInit: function (handler, initDirection) {
  2778. var chart = this.chart;
  2779. if (initDirection > 0) {
  2780. highlightFirstValidPointInChart(chart);
  2781. }
  2782. else {
  2783. highlightLastValidPointInChart(chart);
  2784. }
  2785. return handler.response.success;
  2786. },
  2787. /**
  2788. * @private
  2789. */
  2790. onHandlerTerminate: function () {
  2791. var _a,
  2792. _b;
  2793. var chart = this.chart;
  2794. var curPoint = chart.highlightedPoint;
  2795. (_a = chart.tooltip) === null || _a === void 0 ? void 0 : _a.hide(0);
  2796. (_b = curPoint === null || curPoint === void 0 ? void 0 : curPoint.onMouseOut) === null || _b === void 0 ? void 0 : _b.call(curPoint);
  2797. delete chart.highlightedPoint;
  2798. },
  2799. /**
  2800. * Function that attempts to highlight next/prev point. Handles wrap around.
  2801. * @private
  2802. * @param {Highcharts.KeyboardNavigationHandler} handler
  2803. * @param {boolean} directionIsNext
  2804. * @return {number}
  2805. * response
  2806. */
  2807. attemptHighlightAdjacentPoint: function (handler, directionIsNext) {
  2808. var chart = this.chart,
  2809. wrapAround = chart.options.accessibility.keyboardNavigation
  2810. .wrapAround,
  2811. highlightSuccessful = chart.highlightAdjacentPoint(directionIsNext);
  2812. if (!highlightSuccessful) {
  2813. if (wrapAround) {
  2814. return handler.init(directionIsNext ? 1 : -1);
  2815. }
  2816. return handler.response[directionIsNext ? 'next' : 'prev'];
  2817. }
  2818. return handler.response.success;
  2819. },
  2820. /**
  2821. * @private
  2822. */
  2823. onSeriesDestroy: function (series) {
  2824. var chart = this.chart,
  2825. currentHighlightedPointDestroyed = chart.highlightedPoint &&
  2826. chart.highlightedPoint.series === series;
  2827. if (currentHighlightedPointDestroyed) {
  2828. delete chart.highlightedPoint;
  2829. if (chart.focusElement) {
  2830. chart.focusElement.removeFocusBorder();
  2831. }
  2832. }
  2833. },
  2834. /**
  2835. * @private
  2836. */
  2837. destroy: function () {
  2838. this.eventProvider.removeAddedEvents();
  2839. }
  2840. });
  2841. return SeriesKeyboardNavigation;
  2842. });
  2843. _registerModule(_modules, 'Accessibility/Components/AnnotationsA11y.js', [_modules['Accessibility/Utils/HTMLUtilities.js']], function (HTMLUtilities) {
  2844. /* *
  2845. *
  2846. * (c) 2009-2021 Øystein Moseng
  2847. *
  2848. * Annotations accessibility code.
  2849. *
  2850. * License: www.highcharts.com/license
  2851. *
  2852. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2853. *
  2854. * */
  2855. var escapeStringForHTML = HTMLUtilities.escapeStringForHTML,
  2856. stripHTMLTagsFromString = HTMLUtilities.stripHTMLTagsFromString;
  2857. /**
  2858. * Get list of all annotation labels in the chart.
  2859. *
  2860. * @private
  2861. * @param {Highcharts.Chart} chart The chart to get annotation info on.
  2862. * @return {Array<object>} The labels, or empty array if none.
  2863. */
  2864. function getChartAnnotationLabels(chart) {
  2865. var annotations = chart.annotations || [];
  2866. return annotations.reduce(function (acc, cur) {
  2867. var _a;
  2868. if (((_a = cur.options) === null || _a === void 0 ? void 0 : _a.visible) !== false) {
  2869. acc = acc.concat(cur.labels);
  2870. }
  2871. return acc;
  2872. }, []);
  2873. }
  2874. /**
  2875. * Get the text of an annotation label.
  2876. *
  2877. * @private
  2878. * @param {object} label The annotation label object
  2879. * @return {string} The text in the label.
  2880. */
  2881. function getLabelText(label) {
  2882. var _a,
  2883. _b,
  2884. _c,
  2885. _d;
  2886. var a11yDesc = (_b = (_a = label.options) === null || _a === void 0 ? void 0 : _a.accessibility) === null || _b === void 0 ? void 0 : _b.description;
  2887. return a11yDesc ? a11yDesc : ((_d = (_c = label.graphic) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.textStr) || '';
  2888. }
  2889. /**
  2890. * Describe an annotation label.
  2891. *
  2892. * @private
  2893. * @param {object} label The annotation label object to describe
  2894. * @return {string} The description for the label.
  2895. */
  2896. function getAnnotationLabelDescription(label) {
  2897. var _a,
  2898. _b;
  2899. var a11yDesc = (_b = (_a = label.options) === null || _a === void 0 ? void 0 : _a.accessibility) === null || _b === void 0 ? void 0 : _b.description;
  2900. if (a11yDesc) {
  2901. return a11yDesc;
  2902. }
  2903. var chart = label.chart;
  2904. var labelText = getLabelText(label);
  2905. var points = label.points;
  2906. var getAriaLabel = function (point) { var _a,
  2907. _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')) || ''; };
  2908. var getValueDesc = function (point) {
  2909. var _a;
  2910. var valDesc = ((_a = point === null || point === void 0 ? void 0 : point.accessibility) === null || _a === void 0 ? void 0 : _a.valueDescription) || getAriaLabel(point);
  2911. var seriesName = (point === null || point === void 0 ? void 0 : point.series.name) || '';
  2912. return (seriesName ? seriesName + ', ' : '') + 'data point ' + valDesc;
  2913. };
  2914. var pointValueDescriptions = points
  2915. .filter(function (p) { return !!p.graphic; }) // Filter out mock points
  2916. .map(getValueDesc)
  2917. .filter(function (desc) { return !!desc; }); // Filter out points we can't describe
  2918. var numPoints = pointValueDescriptions.length;
  2919. var pointsSelector = numPoints > 1 ? 'MultiplePoints' : numPoints ? 'SinglePoint' : 'NoPoints';
  2920. var langFormatStr = 'accessibility.screenReaderSection.annotations.description' + pointsSelector;
  2921. var context = {
  2922. annotationText: labelText,
  2923. annotation: label,
  2924. numPoints: numPoints,
  2925. annotationPoint: pointValueDescriptions[0],
  2926. additionalAnnotationPoints: pointValueDescriptions.slice(1)
  2927. };
  2928. return chart.langFormat(langFormatStr, context);
  2929. }
  2930. /**
  2931. * Return array of HTML strings for each annotation label in the chart.
  2932. *
  2933. * @private
  2934. * @param {Highcharts.Chart} chart The chart to get annotation info on.
  2935. * @return {Array<string>} Array of strings with HTML content for each annotation label.
  2936. */
  2937. function getAnnotationListItems(chart) {
  2938. var labels = getChartAnnotationLabels(chart);
  2939. return labels.map(function (label) {
  2940. var desc = escapeStringForHTML(stripHTMLTagsFromString(getAnnotationLabelDescription(label)));
  2941. return desc ? "<li>" + desc + "</li>" : '';
  2942. });
  2943. }
  2944. /**
  2945. * Return the annotation info for a chart as string.
  2946. *
  2947. * @private
  2948. * @param {Highcharts.Chart} chart The chart to get annotation info on.
  2949. * @return {string} String with HTML content or empty string if no annotations.
  2950. */
  2951. function getAnnotationsInfoHTML(chart) {
  2952. var annotations = chart.annotations;
  2953. if (!(annotations && annotations.length)) {
  2954. return '';
  2955. }
  2956. var annotationItems = getAnnotationListItems(chart);
  2957. return "<ul style=\"list-style-type: none\">" + annotationItems.join(' ') + "</ul>";
  2958. }
  2959. /**
  2960. * Return the texts for the annotation(s) connected to a point, or empty array
  2961. * if none.
  2962. *
  2963. * @private
  2964. * @param {Highcharts.Point} point The data point to get the annotation info from.
  2965. * @return {Array<string>} Annotation texts
  2966. */
  2967. function getPointAnnotationTexts(point) {
  2968. var labels = getChartAnnotationLabels(point.series.chart);
  2969. var pointLabels = labels
  2970. .filter(function (label) { return label.points.indexOf(point) > -1; });
  2971. if (!pointLabels.length) {
  2972. return [];
  2973. }
  2974. return pointLabels.map(function (label) { return "" + getLabelText(label); });
  2975. }
  2976. var AnnotationsA11y = {
  2977. getAnnotationsInfoHTML: getAnnotationsInfoHTML,
  2978. getAnnotationLabelDescription: getAnnotationLabelDescription,
  2979. getAnnotationListItems: getAnnotationListItems,
  2980. getPointAnnotationTexts: getPointAnnotationTexts
  2981. };
  2982. return AnnotationsA11y;
  2983. });
  2984. _registerModule(_modules, 'Accessibility/Components/SeriesComponent/SeriesDescriber.js', [_modules['Accessibility/Components/AnnotationsA11y.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Tooltip.js'], _modules['Core/Utilities.js']], function (AnnotationsA11y, ChartUtilities, HTMLUtilities, Tooltip, U) {
  2985. /* *
  2986. *
  2987. * (c) 2009-2021 Øystein Moseng
  2988. *
  2989. * Place desriptions on a series and its points.
  2990. *
  2991. * License: www.highcharts.com/license
  2992. *
  2993. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2994. *
  2995. * */
  2996. var getPointAnnotationTexts = AnnotationsA11y.getPointAnnotationTexts;
  2997. var getAxisDescription = ChartUtilities.getAxisDescription,
  2998. getSeriesFirstPointElement = ChartUtilities.getSeriesFirstPointElement,
  2999. getSeriesA11yElement = ChartUtilities.getSeriesA11yElement,
  3000. unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  3001. var reverseChildNodes = HTMLUtilities.reverseChildNodes,
  3002. stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  3003. var find = U.find,
  3004. format = U.format,
  3005. isNumber = U.isNumber,
  3006. numberFormat = U.numberFormat,
  3007. pick = U.pick,
  3008. defined = U.defined;
  3009. /* eslint-disable valid-jsdoc */
  3010. /**
  3011. * @private
  3012. */
  3013. function findFirstPointWithGraphic(point) {
  3014. var sourcePointIndex = point.index;
  3015. if (!point.series || !point.series.data || !defined(sourcePointIndex)) {
  3016. return null;
  3017. }
  3018. return find(point.series.data, function (p) {
  3019. return !!(p &&
  3020. typeof p.index !== 'undefined' &&
  3021. p.index > sourcePointIndex &&
  3022. p.graphic &&
  3023. p.graphic.element);
  3024. }) || null;
  3025. }
  3026. /**
  3027. * @private
  3028. */
  3029. function shouldAddDummyPoint(point) {
  3030. // Note: Sunburst series use isNull for hidden points on drilldown.
  3031. // Ignore these.
  3032. var isSunburst = point.series && point.series.is('sunburst'),
  3033. isNull = point.isNull;
  3034. return isNull && !isSunburst;
  3035. }
  3036. /**
  3037. * @private
  3038. */
  3039. function makeDummyElement(point, pos) {
  3040. var renderer = point.series.chart.renderer,
  3041. dummy = renderer.rect(pos.x,
  3042. pos.y, 1, 1);
  3043. dummy.attr({
  3044. 'class': 'highcharts-a11y-dummy-point',
  3045. fill: 'none',
  3046. opacity: 0,
  3047. 'fill-opacity': 0,
  3048. 'stroke-opacity': 0
  3049. });
  3050. return dummy;
  3051. }
  3052. /**
  3053. * @private
  3054. * @param {Highcharts.Point} point
  3055. * @return {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement|undefined}
  3056. */
  3057. function addDummyPointElement(point) {
  3058. var series = point.series,
  3059. firstPointWithGraphic = findFirstPointWithGraphic(point),
  3060. firstGraphic = firstPointWithGraphic && firstPointWithGraphic.graphic,
  3061. parentGroup = firstGraphic ?
  3062. firstGraphic.parentGroup :
  3063. series.graph || series.group,
  3064. dummyPos = firstPointWithGraphic ? {
  3065. x: pick(point.plotX,
  3066. firstPointWithGraphic.plotX, 0),
  3067. y: pick(point.plotY,
  3068. firstPointWithGraphic.plotY, 0)
  3069. } : {
  3070. x: pick(point.plotX, 0),
  3071. y: pick(point.plotY, 0)
  3072. },
  3073. dummyElement = makeDummyElement(point,
  3074. dummyPos);
  3075. if (parentGroup && parentGroup.element) {
  3076. point.graphic = dummyElement;
  3077. point.hasDummyGraphic = true;
  3078. dummyElement.add(parentGroup);
  3079. // Move to correct pos in DOM
  3080. parentGroup.element.insertBefore(dummyElement.element, firstGraphic ? firstGraphic.element : null);
  3081. return dummyElement.element;
  3082. }
  3083. }
  3084. /**
  3085. * @private
  3086. * @param {Highcharts.Series} series
  3087. * @return {boolean}
  3088. */
  3089. function hasMorePointsThanDescriptionThreshold(series) {
  3090. var chartA11yOptions = series.chart.options.accessibility,
  3091. threshold = (chartA11yOptions.series.pointDescriptionEnabledThreshold);
  3092. return !!(threshold !== false &&
  3093. series.points &&
  3094. series.points.length >= threshold);
  3095. }
  3096. /**
  3097. * @private
  3098. * @param {Highcharts.Series} series
  3099. * @return {boolean}
  3100. */
  3101. function shouldSetScreenReaderPropsOnPoints(series) {
  3102. var seriesA11yOptions = series.options.accessibility || {};
  3103. return !hasMorePointsThanDescriptionThreshold(series) &&
  3104. !seriesA11yOptions.exposeAsGroupOnly;
  3105. }
  3106. /**
  3107. * @private
  3108. * @param {Highcharts.Series} series
  3109. * @return {boolean}
  3110. */
  3111. function shouldSetKeyboardNavPropsOnPoints(series) {
  3112. var chartA11yOptions = series.chart.options.accessibility,
  3113. seriesNavOptions = chartA11yOptions.keyboardNavigation.seriesNavigation;
  3114. return !!(series.points && (series.points.length <
  3115. seriesNavOptions.pointNavigationEnabledThreshold ||
  3116. seriesNavOptions.pointNavigationEnabledThreshold === false));
  3117. }
  3118. /**
  3119. * @private
  3120. * @param {Highcharts.Series} series
  3121. * @return {boolean}
  3122. */
  3123. function shouldDescribeSeriesElement(series) {
  3124. var chart = series.chart,
  3125. chartOptions = chart.options.chart || {},
  3126. chartHas3d = chartOptions.options3d && chartOptions.options3d.enabled,
  3127. hasMultipleSeries = chart.series.length > 1,
  3128. describeSingleSeriesOption = chart.options.accessibility.series.describeSingleSeries,
  3129. exposeAsGroupOnlyOption = (series.options.accessibility || {}).exposeAsGroupOnly,
  3130. noDescribe3D = chartHas3d && hasMultipleSeries;
  3131. return !noDescribe3D && (hasMultipleSeries || describeSingleSeriesOption ||
  3132. exposeAsGroupOnlyOption || hasMorePointsThanDescriptionThreshold(series));
  3133. }
  3134. /**
  3135. * @private
  3136. * @param {Highcharts.Point} point
  3137. * @param {number} value
  3138. * @return {string}
  3139. */
  3140. function pointNumberToString(point, value) {
  3141. var chart = point.series.chart,
  3142. a11yPointOptions = chart.options.accessibility.point || {},
  3143. tooltipOptions = point.series.tooltipOptions || {},
  3144. lang = chart.options.lang;
  3145. if (isNumber(value)) {
  3146. return numberFormat(value, a11yPointOptions.valueDecimals ||
  3147. tooltipOptions.valueDecimals ||
  3148. -1, lang.decimalPoint, lang.accessibility.thousandsSep || lang.thousandsSep);
  3149. }
  3150. return value;
  3151. }
  3152. /**
  3153. * @private
  3154. * @param {Highcharts.Series} series
  3155. * @return {string}
  3156. */
  3157. function getSeriesDescriptionText(series) {
  3158. var seriesA11yOptions = series.options.accessibility || {},
  3159. descOpt = seriesA11yOptions.description;
  3160. return descOpt && series.chart.langFormat('accessibility.series.description', {
  3161. description: descOpt,
  3162. series: series
  3163. }) || '';
  3164. }
  3165. /**
  3166. * @private
  3167. * @param {Highcharts.series} series
  3168. * @param {string} axisCollection
  3169. * @return {string}
  3170. */
  3171. function getSeriesAxisDescriptionText(series, axisCollection) {
  3172. var axis = series[axisCollection];
  3173. return series.chart.langFormat('accessibility.series.' + axisCollection + 'Description', {
  3174. name: getAxisDescription(axis),
  3175. series: series
  3176. });
  3177. }
  3178. /**
  3179. * Get accessible time description for a point on a datetime axis.
  3180. *
  3181. * @private
  3182. * @function Highcharts.Point#getTimeDescription
  3183. * @param {Highcharts.Point} point
  3184. * @return {string|undefined}
  3185. * The description as string.
  3186. */
  3187. function getPointA11yTimeDescription(point) {
  3188. var series = point.series,
  3189. chart = series.chart,
  3190. a11yOptions = chart.options.accessibility.point || {},
  3191. hasDateXAxis = series.xAxis && series.xAxis.dateTime;
  3192. if (hasDateXAxis) {
  3193. var tooltipDateFormat = Tooltip.prototype.getXDateFormat.call({
  3194. getDateFormat: Tooltip.prototype.getDateFormat,
  3195. chart: chart
  3196. },
  3197. point,
  3198. chart.options.tooltip,
  3199. series.xAxis),
  3200. dateFormat = a11yOptions.dateFormatter &&
  3201. a11yOptions.dateFormatter(point) ||
  3202. a11yOptions.dateFormat ||
  3203. tooltipDateFormat;
  3204. return chart.time.dateFormat(dateFormat, point.x, void 0);
  3205. }
  3206. }
  3207. /**
  3208. * @private
  3209. * @param {Highcharts.Point} point
  3210. * @return {string}
  3211. */
  3212. function getPointXDescription(point) {
  3213. var timeDesc = getPointA11yTimeDescription(point), xAxis = point.series.xAxis || {}, pointCategory = xAxis.categories && defined(point.category) &&
  3214. ('' + point.category).replace('<br/>', ' '), canUseId = point.id && point.id.indexOf('highcharts-') < 0, fallback = 'x, ' + point.x;
  3215. return point.name || timeDesc || pointCategory ||
  3216. (canUseId ? point.id : fallback);
  3217. }
  3218. /**
  3219. * @private
  3220. * @param {Highcharts.Point} point
  3221. * @param {string} prefix
  3222. * @param {string} suffix
  3223. * @return {string}
  3224. */
  3225. function getPointArrayMapValueDescription(point, prefix, suffix) {
  3226. var pre = prefix || '', suf = suffix || '', keyToValStr = function (key) {
  3227. var num = pointNumberToString(point, pick(point[key], point.options[key]));
  3228. return key + ': ' + pre + num + suf;
  3229. }, pointArrayMap = point.series.pointArrayMap;
  3230. return pointArrayMap.reduce(function (desc, key) {
  3231. return desc + (desc.length ? ', ' : '') + keyToValStr(key);
  3232. }, '');
  3233. }
  3234. /**
  3235. * @private
  3236. * @param {Highcharts.Point} point
  3237. * @return {string}
  3238. */
  3239. function getPointValue(point) {
  3240. var series = point.series,
  3241. a11yPointOpts = series.chart.options.accessibility.point || {},
  3242. tooltipOptions = series.tooltipOptions || {},
  3243. valuePrefix = a11yPointOpts.valuePrefix ||
  3244. tooltipOptions.valuePrefix || '',
  3245. valueSuffix = a11yPointOpts.valueSuffix ||
  3246. tooltipOptions.valueSuffix || '',
  3247. fallbackKey = (typeof point.value !==
  3248. 'undefined' ?
  3249. 'value' : 'y'),
  3250. fallbackDesc = pointNumberToString(point,
  3251. point[fallbackKey]);
  3252. if (point.isNull) {
  3253. return series.chart.langFormat('accessibility.series.nullPointValue', {
  3254. point: point
  3255. });
  3256. }
  3257. if (series.pointArrayMap) {
  3258. return getPointArrayMapValueDescription(point, valuePrefix, valueSuffix);
  3259. }
  3260. return valuePrefix + fallbackDesc + valueSuffix;
  3261. }
  3262. /**
  3263. * Return the description for the annotation(s) connected to a point, or empty
  3264. * string if none.
  3265. *
  3266. * @private
  3267. * @param {Highcharts.Point} point The data point to get the annotation info from.
  3268. * @return {string} Annotation description
  3269. */
  3270. function getPointAnnotationDescription(point) {
  3271. var chart = point.series.chart;
  3272. var langKey = 'accessibility.series.pointAnnotationsDescription';
  3273. var annotations = getPointAnnotationTexts(point);
  3274. var context = { point: point,
  3275. annotations: annotations };
  3276. return annotations.length ? chart.langFormat(langKey, context) : '';
  3277. }
  3278. /**
  3279. * Return string with information about point.
  3280. * @private
  3281. * @return {string}
  3282. */
  3283. function getPointValueDescription(point) {
  3284. var series = point.series, chart = series.chart, pointValueDescriptionFormat = chart.options.accessibility
  3285. .point.valueDescriptionFormat, showXDescription = pick(series.xAxis &&
  3286. series.xAxis.options.accessibility &&
  3287. series.xAxis.options.accessibility.enabled, !chart.angular), xDesc = showXDescription ? getPointXDescription(point) : '', context = {
  3288. point: point,
  3289. index: defined(point.index) ? (point.index + 1) : '',
  3290. xDescription: xDesc,
  3291. value: getPointValue(point),
  3292. separator: showXDescription ? ', ' : ''
  3293. };
  3294. return format(pointValueDescriptionFormat, context, chart);
  3295. }
  3296. /**
  3297. * Return string with information about point.
  3298. * @private
  3299. * @return {string}
  3300. */
  3301. function defaultPointDescriptionFormatter(point) {
  3302. var series = point.series, chart = series.chart, valText = getPointValueDescription(point), description = point.options && point.options.accessibility &&
  3303. point.options.accessibility.description, userDescText = description ? ' ' + description : '', seriesNameText = chart.series.length > 1 && series.name ?
  3304. ' ' + series.name + '.' : '', annotationsDesc = getPointAnnotationDescription(point), pointAnnotationsText = annotationsDesc ? ' ' + annotationsDesc : '';
  3305. point.accessibility = point.accessibility || {};
  3306. point.accessibility.valueDescription = valText;
  3307. return valText + userDescText + seriesNameText + pointAnnotationsText;
  3308. }
  3309. /**
  3310. * Set a11y props on a point element
  3311. * @private
  3312. * @param {Highcharts.Point} point
  3313. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} pointElement
  3314. */
  3315. function setPointScreenReaderAttribs(point, pointElement) {
  3316. var series = point.series,
  3317. a11yPointOptions = series.chart.options.accessibility.point || {},
  3318. seriesA11yOptions = series.options.accessibility || {},
  3319. label = stripHTMLTags(seriesA11yOptions.pointDescriptionFormatter &&
  3320. seriesA11yOptions.pointDescriptionFormatter(point) ||
  3321. a11yPointOptions.descriptionFormatter &&
  3322. a11yPointOptions.descriptionFormatter(point) ||
  3323. defaultPointDescriptionFormatter(point));
  3324. pointElement.setAttribute('role', 'img');
  3325. pointElement.setAttribute('aria-label', label);
  3326. }
  3327. /**
  3328. * Add accessible info to individual point elements of a series
  3329. * @private
  3330. * @param {Highcharts.Series} series
  3331. */
  3332. function describePointsInSeries(series) {
  3333. var setScreenReaderProps = shouldSetScreenReaderPropsOnPoints(series),
  3334. setKeyboardProps = shouldSetKeyboardNavPropsOnPoints(series);
  3335. if (setScreenReaderProps || setKeyboardProps) {
  3336. series.points.forEach(function (point) {
  3337. var _a,
  3338. _b;
  3339. var pointEl = point.graphic && point.graphic.element ||
  3340. shouldAddDummyPoint(point) && addDummyPointElement(point);
  3341. var pointA11yDisabled = ((_b = (_a = point.options) === null || _a === void 0 ? void 0 : _a.accessibility) === null || _b === void 0 ? void 0 : _b.enabled) === false;
  3342. if (pointEl) {
  3343. // We always set tabindex, as long as we are setting props.
  3344. // When setting tabindex, also remove default outline to
  3345. // avoid ugly border on click.
  3346. pointEl.setAttribute('tabindex', '-1');
  3347. pointEl.style.outline = '0';
  3348. if (setScreenReaderProps && !pointA11yDisabled) {
  3349. setPointScreenReaderAttribs(point, pointEl);
  3350. }
  3351. else {
  3352. pointEl.setAttribute('aria-hidden', true);
  3353. }
  3354. }
  3355. });
  3356. }
  3357. }
  3358. /**
  3359. * Return string with information about series.
  3360. * @private
  3361. * @return {string}
  3362. */
  3363. function defaultSeriesDescriptionFormatter(series) {
  3364. var chart = series.chart,
  3365. chartTypes = chart.types || [],
  3366. description = getSeriesDescriptionText(series),
  3367. shouldDescribeAxis = function (coll) {
  3368. return chart[coll] && chart[coll].length > 1 && series[coll];
  3369. }, xAxisInfo = getSeriesAxisDescriptionText(series, 'xAxis'), yAxisInfo = getSeriesAxisDescriptionText(series, 'yAxis'), summaryContext = {
  3370. name: series.name || '',
  3371. ix: series.index + 1,
  3372. numSeries: chart.series && chart.series.length,
  3373. numPoints: series.points && series.points.length,
  3374. series: series
  3375. }, combinationSuffix = chartTypes.length > 1 ? 'Combination' : '', summary = chart.langFormat('accessibility.series.summary.' + series.type + combinationSuffix, summaryContext) || chart.langFormat('accessibility.series.summary.default' + combinationSuffix, summaryContext);
  3376. return summary + (description ? ' ' + description : '') + (shouldDescribeAxis('yAxis') ? ' ' + yAxisInfo : '') + (shouldDescribeAxis('xAxis') ? ' ' + xAxisInfo : '');
  3377. }
  3378. /**
  3379. * Set a11y props on a series element
  3380. * @private
  3381. * @param {Highcharts.Series} series
  3382. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} seriesElement
  3383. */
  3384. function describeSeriesElement(series, seriesElement) {
  3385. var seriesA11yOptions = series.options.accessibility || {},
  3386. a11yOptions = series.chart.options.accessibility,
  3387. landmarkVerbosity = a11yOptions.landmarkVerbosity;
  3388. // Handle role attribute
  3389. if (seriesA11yOptions.exposeAsGroupOnly) {
  3390. seriesElement.setAttribute('role', 'img');
  3391. }
  3392. else if (landmarkVerbosity === 'all') {
  3393. seriesElement.setAttribute('role', 'region');
  3394. } /* else do not add role */
  3395. seriesElement.setAttribute('tabindex', '-1');
  3396. seriesElement.style.outline = '0'; // Don't show browser outline on click, despite tabindex
  3397. seriesElement.setAttribute('aria-label', stripHTMLTags(a11yOptions.series.descriptionFormatter &&
  3398. a11yOptions.series.descriptionFormatter(series) ||
  3399. defaultSeriesDescriptionFormatter(series)));
  3400. }
  3401. /**
  3402. * Put accessible info on series and points of a series.
  3403. * @param {Highcharts.Series} series The series to add info on.
  3404. */
  3405. function describeSeries(series) {
  3406. var chart = series.chart,
  3407. firstPointEl = getSeriesFirstPointElement(series),
  3408. seriesEl = getSeriesA11yElement(series),
  3409. is3d = chart.is3d && chart.is3d();
  3410. if (seriesEl) {
  3411. // For some series types the order of elements do not match the
  3412. // order of points in series. In that case we have to reverse them
  3413. // in order for AT to read them out in an understandable order.
  3414. // Due to z-index issues we can not do this for 3D charts.
  3415. if (seriesEl.lastChild === firstPointEl && !is3d) {
  3416. reverseChildNodes(seriesEl);
  3417. }
  3418. describePointsInSeries(series);
  3419. unhideChartElementFromAT(chart, seriesEl);
  3420. if (shouldDescribeSeriesElement(series)) {
  3421. describeSeriesElement(series, seriesEl);
  3422. }
  3423. else {
  3424. seriesEl.setAttribute('aria-label', '');
  3425. }
  3426. }
  3427. }
  3428. var SeriesDescriber = {
  3429. describeSeries: describeSeries,
  3430. defaultPointDescriptionFormatter: defaultPointDescriptionFormatter,
  3431. defaultSeriesDescriptionFormatter: defaultSeriesDescriptionFormatter,
  3432. getPointA11yTimeDescription: getPointA11yTimeDescription,
  3433. getPointXDescription: getPointXDescription,
  3434. getPointValue: getPointValue,
  3435. getPointValueDescription: getPointValueDescription
  3436. };
  3437. return SeriesDescriber;
  3438. });
  3439. _registerModule(_modules, 'Accessibility/Utils/Announcer.js', [_modules['Core/Globals.js'], _modules['Core/Renderer/HTML/AST.js'], _modules['Accessibility/Utils/DOMElementProvider.js'], _modules['Accessibility/Utils/HTMLUtilities.js']], function (H, AST, DOMElementProvider, HTMLUtilities) {
  3440. /* *
  3441. *
  3442. * (c) 2009-2021 Øystein Moseng
  3443. *
  3444. * Create announcer to speak messages to screen readers and other AT.
  3445. *
  3446. * License: www.highcharts.com/license
  3447. *
  3448. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3449. *
  3450. * */
  3451. var doc = H.doc;
  3452. var setElAttrs = HTMLUtilities.setElAttrs,
  3453. visuallyHideElement = HTMLUtilities.visuallyHideElement;
  3454. var Announcer = /** @class */ (function () {
  3455. function Announcer(chart, type) {
  3456. this.chart = chart;
  3457. this.domElementProvider = new DOMElementProvider();
  3458. this.announceRegion = this.addAnnounceRegion(type);
  3459. }
  3460. Announcer.prototype.destroy = function () {
  3461. this.domElementProvider.destroyCreatedElements();
  3462. };
  3463. Announcer.prototype.announce = function (message) {
  3464. var _this = this;
  3465. AST.setElementHTML(this.announceRegion, message);
  3466. // Delete contents after a little while to avoid user finding the live
  3467. // region in the DOM.
  3468. if (this.clearAnnouncementRegionTimer) {
  3469. clearTimeout(this.clearAnnouncementRegionTimer);
  3470. }
  3471. this.clearAnnouncementRegionTimer = setTimeout(function () {
  3472. _this.announceRegion.innerHTML = '';
  3473. delete _this.clearAnnouncementRegionTimer;
  3474. }, 1000);
  3475. };
  3476. Announcer.prototype.addAnnounceRegion = function (type) {
  3477. var chartContainer = this.chart.announcerContainer || this.createAnnouncerContainer();
  3478. var div = this.domElementProvider.createElement('div');
  3479. setElAttrs(div, {
  3480. 'aria-hidden': false,
  3481. 'aria-live': type
  3482. });
  3483. visuallyHideElement(div);
  3484. chartContainer.appendChild(div);
  3485. return div;
  3486. };
  3487. Announcer.prototype.createAnnouncerContainer = function () {
  3488. var chart = this.chart;
  3489. var container = doc.createElement('div');
  3490. setElAttrs(container, {
  3491. 'aria-hidden': false,
  3492. style: 'position:relative',
  3493. 'class': 'highcharts-announcer-container'
  3494. });
  3495. chart.renderTo.insertBefore(container, chart.renderTo.firstChild);
  3496. chart.announcerContainer = container;
  3497. return container;
  3498. };
  3499. return Announcer;
  3500. }());
  3501. H.Announcer = Announcer;
  3502. return Announcer;
  3503. });
  3504. _registerModule(_modules, 'Accessibility/Components/SeriesComponent/NewDataAnnouncer.js', [_modules['Core/Globals.js'], _modules['Core/Series/Series.js'], _modules['Core/Utilities.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Components/SeriesComponent/SeriesDescriber.js'], _modules['Accessibility/Utils/Announcer.js'], _modules['Accessibility/Utils/EventProvider.js']], function (H, Series, U, ChartUtilities, SeriesDescriber, Announcer, EventProvider) {
  3505. /* *
  3506. *
  3507. * (c) 2009-2021 Øystein Moseng
  3508. *
  3509. * Handle announcing new data for a chart.
  3510. *
  3511. * License: www.highcharts.com/license
  3512. *
  3513. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3514. *
  3515. * */
  3516. var extend = U.extend,
  3517. defined = U.defined;
  3518. var getChartTitle = ChartUtilities.getChartTitle;
  3519. var defaultPointDescriptionFormatter = SeriesDescriber
  3520. .defaultPointDescriptionFormatter,
  3521. defaultSeriesDescriptionFormatter = SeriesDescriber
  3522. .defaultSeriesDescriptionFormatter;
  3523. /* eslint-disable no-invalid-this, valid-jsdoc */
  3524. /**
  3525. * @private
  3526. */
  3527. function chartHasAnnounceEnabled(chart) {
  3528. return !!chart.options.accessibility.announceNewData.enabled;
  3529. }
  3530. /**
  3531. * @private
  3532. */
  3533. function findPointInDataArray(point) {
  3534. var candidates = point.series.data.filter(function (candidate) {
  3535. return point.x === candidate.x && point.y === candidate.y;
  3536. });
  3537. return candidates.length === 1 ? candidates[0] : point;
  3538. }
  3539. /**
  3540. * Get array of unique series from two arrays
  3541. * @private
  3542. */
  3543. function getUniqueSeries(arrayA, arrayB) {
  3544. var uniqueSeries = (arrayA || []).concat(arrayB || [])
  3545. .reduce(function (acc,
  3546. cur) {
  3547. acc[cur.name + cur.index] = cur;
  3548. return acc;
  3549. }, {});
  3550. return Object.keys(uniqueSeries).map(function (ix) {
  3551. return uniqueSeries[ix];
  3552. });
  3553. }
  3554. /**
  3555. * @private
  3556. * @class
  3557. */
  3558. var NewDataAnnouncer = function (chart) {
  3559. this.chart = chart;
  3560. };
  3561. extend(NewDataAnnouncer.prototype, {
  3562. /**
  3563. * Initialize the new data announcer.
  3564. * @private
  3565. */
  3566. init: function () {
  3567. var chart = this.chart;
  3568. var announceOptions = chart.options.accessibility.announceNewData;
  3569. var announceType = announceOptions.interruptUser ? 'assertive' : 'polite';
  3570. this.lastAnnouncementTime = 0;
  3571. this.dirty = {
  3572. allSeries: {}
  3573. };
  3574. this.eventProvider = new EventProvider();
  3575. this.announcer = new Announcer(chart, announceType);
  3576. this.addEventListeners();
  3577. },
  3578. /**
  3579. * Remove traces of announcer.
  3580. * @private
  3581. */
  3582. destroy: function () {
  3583. this.eventProvider.removeAddedEvents();
  3584. this.announcer.destroy();
  3585. },
  3586. /**
  3587. * Add event listeners for the announcer
  3588. * @private
  3589. */
  3590. addEventListeners: function () {
  3591. var announcer = this,
  3592. chart = this.chart,
  3593. e = this.eventProvider;
  3594. e.addEvent(chart, 'afterDrilldown', function () {
  3595. announcer.lastAnnouncementTime = 0;
  3596. });
  3597. e.addEvent(Series, 'updatedData', function () {
  3598. announcer.onSeriesUpdatedData(this);
  3599. });
  3600. e.addEvent(chart, 'afterAddSeries', function (e) {
  3601. announcer.onSeriesAdded(e.series);
  3602. });
  3603. e.addEvent(Series, 'addPoint', function (e) {
  3604. announcer.onPointAdded(e.point);
  3605. });
  3606. e.addEvent(chart, 'redraw', function () {
  3607. announcer.announceDirtyData();
  3608. });
  3609. },
  3610. /**
  3611. * On new data in the series, make sure we add it to the dirty list.
  3612. * @private
  3613. * @param {Highcharts.Series} series
  3614. */
  3615. onSeriesUpdatedData: function (series) {
  3616. var chart = this.chart;
  3617. if (series.chart === chart && chartHasAnnounceEnabled(chart)) {
  3618. this.dirty.hasDirty = true;
  3619. this.dirty.allSeries[series.name + series.index] = series;
  3620. }
  3621. },
  3622. /**
  3623. * On new data series added, update dirty list.
  3624. * @private
  3625. * @param {Highcharts.Series} series
  3626. */
  3627. onSeriesAdded: function (series) {
  3628. if (chartHasAnnounceEnabled(this.chart)) {
  3629. this.dirty.hasDirty = true;
  3630. this.dirty.allSeries[series.name + series.index] = series;
  3631. // Add it to newSeries storage unless we already have one
  3632. this.dirty.newSeries = defined(this.dirty.newSeries) ?
  3633. void 0 : series;
  3634. }
  3635. },
  3636. /**
  3637. * On new point added, update dirty list.
  3638. * @private
  3639. * @param {Highcharts.Point} point
  3640. */
  3641. onPointAdded: function (point) {
  3642. var chart = point.series.chart;
  3643. if (this.chart === chart && chartHasAnnounceEnabled(chart)) {
  3644. // Add it to newPoint storage unless we already have one
  3645. this.dirty.newPoint = defined(this.dirty.newPoint) ?
  3646. void 0 : point;
  3647. }
  3648. },
  3649. /**
  3650. * Gather what we know and announce the data to user.
  3651. * @private
  3652. */
  3653. announceDirtyData: function () {
  3654. var chart = this.chart,
  3655. announcer = this;
  3656. if (chart.options.accessibility.announceNewData &&
  3657. this.dirty.hasDirty) {
  3658. var newPoint = this.dirty.newPoint;
  3659. // If we have a single new point, see if we can find it in the
  3660. // data array. Otherwise we can only pass through options to
  3661. // the description builder, and it is a bit sparse in info.
  3662. if (newPoint) {
  3663. newPoint = findPointInDataArray(newPoint);
  3664. }
  3665. this.queueAnnouncement(Object.keys(this.dirty.allSeries).map(function (ix) {
  3666. return announcer.dirty.allSeries[ix];
  3667. }), this.dirty.newSeries, newPoint);
  3668. // Reset
  3669. this.dirty = {
  3670. allSeries: {}
  3671. };
  3672. }
  3673. },
  3674. /**
  3675. * Announce to user that there is new data.
  3676. * @private
  3677. * @param {Array<Highcharts.Series>} dirtySeries
  3678. * Array of series with new data.
  3679. * @param {Highcharts.Series} [newSeries]
  3680. * If a single new series was added, a reference to this series.
  3681. * @param {Highcharts.Point} [newPoint]
  3682. * If a single point was added, a reference to this point.
  3683. */
  3684. queueAnnouncement: function (dirtySeries, newSeries, newPoint) {
  3685. var _this = this;
  3686. var chart = this.chart;
  3687. var annOptions = chart.options.accessibility.announceNewData;
  3688. if (annOptions.enabled) {
  3689. var now = +new Date();
  3690. var dTime = now - this.lastAnnouncementTime;
  3691. var time = Math.max(0,
  3692. annOptions.minAnnounceInterval - dTime);
  3693. // Add series from previously queued announcement.
  3694. var allSeries = getUniqueSeries(this.queuedAnnouncement && this.queuedAnnouncement.series,
  3695. dirtySeries);
  3696. // Build message and announce
  3697. var message = this.buildAnnouncementMessage(allSeries,
  3698. newSeries,
  3699. newPoint);
  3700. if (message) {
  3701. // Is there already one queued?
  3702. if (this.queuedAnnouncement) {
  3703. clearTimeout(this.queuedAnnouncementTimer);
  3704. }
  3705. // Build the announcement
  3706. this.queuedAnnouncement = {
  3707. time: now,
  3708. message: message,
  3709. series: allSeries
  3710. };
  3711. // Queue the announcement
  3712. this.queuedAnnouncementTimer = setTimeout(function () {
  3713. if (_this && _this.announcer) {
  3714. _this.lastAnnouncementTime = +new Date();
  3715. _this.announcer.announce(_this.queuedAnnouncement.message);
  3716. delete _this.queuedAnnouncement;
  3717. delete _this.queuedAnnouncementTimer;
  3718. }
  3719. }, time);
  3720. }
  3721. }
  3722. },
  3723. /**
  3724. * Get announcement message for new data.
  3725. * @private
  3726. * @param {Array<Highcharts.Series>} dirtySeries
  3727. * Array of series with new data.
  3728. * @param {Highcharts.Series} [newSeries]
  3729. * If a single new series was added, a reference to this series.
  3730. * @param {Highcharts.Point} [newPoint]
  3731. * If a single point was added, a reference to this point.
  3732. *
  3733. * @return {string|null}
  3734. * The announcement message to give to user.
  3735. */
  3736. buildAnnouncementMessage: function (dirtySeries, newSeries, newPoint) {
  3737. var chart = this.chart,
  3738. annOptions = chart.options.accessibility.announceNewData;
  3739. // User supplied formatter?
  3740. if (annOptions.announcementFormatter) {
  3741. var formatterRes = annOptions.announcementFormatter(dirtySeries,
  3742. newSeries,
  3743. newPoint);
  3744. if (formatterRes !== false) {
  3745. return formatterRes.length ? formatterRes : null;
  3746. }
  3747. }
  3748. // Default formatter - use lang options
  3749. var multiple = H.charts && H.charts.length > 1 ? 'Multiple' : 'Single', langKey = newSeries ? 'newSeriesAnnounce' + multiple :
  3750. newPoint ? 'newPointAnnounce' + multiple : 'newDataAnnounce', chartTitle = getChartTitle(chart);
  3751. return chart.langFormat('accessibility.announceNewData.' + langKey, {
  3752. chartTitle: chartTitle,
  3753. seriesDesc: newSeries ?
  3754. defaultSeriesDescriptionFormatter(newSeries) :
  3755. null,
  3756. pointDesc: newPoint ?
  3757. defaultPointDescriptionFormatter(newPoint) :
  3758. null,
  3759. point: newPoint,
  3760. series: newSeries
  3761. });
  3762. }
  3763. });
  3764. return NewDataAnnouncer;
  3765. });
  3766. _registerModule(_modules, 'Accessibility/Components/SeriesComponent/ForcedMarkers.js', [_modules['Core/Series/Series.js'], _modules['Core/Utilities.js']], function (Series, U) {
  3767. /* *
  3768. *
  3769. * (c) 2009-2021 Øystein Moseng
  3770. *
  3771. * Handle forcing series markers.
  3772. *
  3773. * License: www.highcharts.com/license
  3774. *
  3775. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3776. *
  3777. * */
  3778. var addEvent = U.addEvent,
  3779. merge = U.merge;
  3780. /* eslint-disable no-invalid-this, valid-jsdoc */
  3781. /**
  3782. * @private
  3783. */
  3784. function isWithinDescriptionThreshold(series) {
  3785. var a11yOptions = series.chart.options.accessibility;
  3786. return series.points.length <
  3787. a11yOptions.series.pointDescriptionEnabledThreshold ||
  3788. a11yOptions.series.pointDescriptionEnabledThreshold === false;
  3789. }
  3790. /**
  3791. * @private
  3792. */
  3793. function shouldForceMarkers(series) {
  3794. var chart = series.chart,
  3795. chartA11yEnabled = chart.options.accessibility.enabled,
  3796. seriesA11yEnabled = (series.options.accessibility &&
  3797. series.options.accessibility.enabled) !== false;
  3798. return chartA11yEnabled && seriesA11yEnabled && isWithinDescriptionThreshold(series);
  3799. }
  3800. /**
  3801. * @private
  3802. */
  3803. function hasIndividualPointMarkerOptions(series) {
  3804. return !!(series._hasPointMarkers && series.points && series.points.length);
  3805. }
  3806. /**
  3807. * @private
  3808. */
  3809. function unforceSeriesMarkerOptions(series) {
  3810. var resetMarkerOptions = series.resetA11yMarkerOptions;
  3811. if (resetMarkerOptions) {
  3812. merge(true, series.options, {
  3813. marker: {
  3814. enabled: resetMarkerOptions.enabled,
  3815. states: {
  3816. normal: {
  3817. opacity: resetMarkerOptions.states &&
  3818. resetMarkerOptions.states.normal &&
  3819. resetMarkerOptions.states.normal.opacity
  3820. }
  3821. }
  3822. }
  3823. });
  3824. }
  3825. }
  3826. /**
  3827. * @private
  3828. */
  3829. function forceZeroOpacityMarkerOptions(options) {
  3830. merge(true, options, {
  3831. marker: {
  3832. enabled: true,
  3833. states: {
  3834. normal: {
  3835. opacity: 0
  3836. }
  3837. }
  3838. }
  3839. });
  3840. }
  3841. /**
  3842. * @private
  3843. */
  3844. function getPointMarkerOpacity(pointOptions) {
  3845. return pointOptions.marker.states &&
  3846. pointOptions.marker.states.normal &&
  3847. pointOptions.marker.states.normal.opacity || 1;
  3848. }
  3849. /**
  3850. * @private
  3851. */
  3852. function unforcePointMarkerOptions(pointOptions) {
  3853. merge(true, pointOptions.marker, {
  3854. states: {
  3855. normal: {
  3856. opacity: getPointMarkerOpacity(pointOptions)
  3857. }
  3858. }
  3859. });
  3860. }
  3861. /**
  3862. * @private
  3863. */
  3864. function handleForcePointMarkers(series) {
  3865. var i = series.points.length;
  3866. while (i--) {
  3867. var point = series.points[i];
  3868. var pointOptions = point.options;
  3869. delete point.hasForcedA11yMarker;
  3870. if (pointOptions.marker) {
  3871. if (pointOptions.marker.enabled) {
  3872. unforcePointMarkerOptions(pointOptions);
  3873. point.hasForcedA11yMarker = false;
  3874. }
  3875. else {
  3876. forceZeroOpacityMarkerOptions(pointOptions);
  3877. point.hasForcedA11yMarker = true;
  3878. }
  3879. }
  3880. }
  3881. }
  3882. /**
  3883. * @private
  3884. */
  3885. function addForceMarkersEvents() {
  3886. /**
  3887. * Keep track of forcing markers.
  3888. * @private
  3889. */
  3890. addEvent(Series, 'render', function () {
  3891. var series = this,
  3892. options = series.options;
  3893. if (shouldForceMarkers(series)) {
  3894. if (options.marker && options.marker.enabled === false) {
  3895. series.a11yMarkersForced = true;
  3896. forceZeroOpacityMarkerOptions(series.options);
  3897. }
  3898. if (hasIndividualPointMarkerOptions(series)) {
  3899. handleForcePointMarkers(series);
  3900. }
  3901. }
  3902. else if (series.a11yMarkersForced) {
  3903. delete series.a11yMarkersForced;
  3904. unforceSeriesMarkerOptions(series);
  3905. }
  3906. });
  3907. /**
  3908. * Keep track of options to reset markers to if no longer forced.
  3909. * @private
  3910. */
  3911. addEvent(Series, 'afterSetOptions', function (e) {
  3912. this.resetA11yMarkerOptions = merge(e.options.marker || {}, this.userOptions.marker || {});
  3913. });
  3914. /**
  3915. * Process marker graphics after render
  3916. * @private
  3917. */
  3918. addEvent(Series, 'afterRender', function () {
  3919. var series = this;
  3920. // For styled mode the rendered graphic does not reflect the style
  3921. // options, and we need to add/remove classes to achieve the same.
  3922. if (series.chart.styledMode) {
  3923. if (series.markerGroup) {
  3924. series.markerGroup[series.a11yMarkersForced ? 'addClass' : 'removeClass']('highcharts-a11y-markers-hidden');
  3925. }
  3926. // Do we need to handle individual points?
  3927. if (hasIndividualPointMarkerOptions(series)) {
  3928. series.points.forEach(function (point) {
  3929. if (point.graphic) {
  3930. point.graphic[point.hasForcedA11yMarker ? 'addClass' : 'removeClass']('highcharts-a11y-marker-hidden');
  3931. point.graphic[point.hasForcedA11yMarker === false ? 'addClass' : 'removeClass']('highcharts-a11y-marker-visible');
  3932. }
  3933. });
  3934. }
  3935. }
  3936. });
  3937. }
  3938. return addForceMarkersEvents;
  3939. });
  3940. _registerModule(_modules, 'Accessibility/Components/SeriesComponent/SeriesComponent.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/Components/SeriesComponent/SeriesKeyboardNavigation.js'], _modules['Accessibility/Components/SeriesComponent/NewDataAnnouncer.js'], _modules['Accessibility/Components/SeriesComponent/ForcedMarkers.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Components/SeriesComponent/SeriesDescriber.js'], _modules['Core/Tooltip.js']], function (H, U, AccessibilityComponent, SeriesKeyboardNavigation, NewDataAnnouncer, addForceMarkersEvents, ChartUtilities, SeriesDescriber, Tooltip) {
  3941. /* *
  3942. *
  3943. * (c) 2009-2021 Øystein Moseng
  3944. *
  3945. * Accessibility component for series and points.
  3946. *
  3947. * License: www.highcharts.com/license
  3948. *
  3949. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3950. *
  3951. * */
  3952. var extend = U.extend;
  3953. var hideSeriesFromAT = ChartUtilities.hideSeriesFromAT;
  3954. var describeSeries = SeriesDescriber.describeSeries;
  3955. // Expose functionality to users
  3956. H.SeriesAccessibilityDescriber = SeriesDescriber;
  3957. // Handle forcing markers
  3958. addForceMarkersEvents();
  3959. /* eslint-disable no-invalid-this, valid-jsdoc */
  3960. /**
  3961. * The SeriesComponent class
  3962. *
  3963. * @private
  3964. * @class
  3965. * @name Highcharts.SeriesComponent
  3966. */
  3967. var SeriesComponent = function () { };
  3968. SeriesComponent.prototype = new AccessibilityComponent();
  3969. extend(SeriesComponent.prototype, /** @lends Highcharts.SeriesComponent */ {
  3970. /**
  3971. * Init the component.
  3972. */
  3973. init: function () {
  3974. this.newDataAnnouncer = new NewDataAnnouncer(this.chart);
  3975. this.newDataAnnouncer.init();
  3976. this.keyboardNavigation = new SeriesKeyboardNavigation(this.chart, this.keyCodes);
  3977. this.keyboardNavigation.init();
  3978. this.hideTooltipFromATWhenShown();
  3979. this.hideSeriesLabelsFromATWhenShown();
  3980. },
  3981. /**
  3982. * @private
  3983. */
  3984. hideTooltipFromATWhenShown: function () {
  3985. var component = this;
  3986. this.addEvent(Tooltip, 'refresh', function () {
  3987. if (this.chart === component.chart &&
  3988. this.label &&
  3989. this.label.element) {
  3990. this.label.element.setAttribute('aria-hidden', true);
  3991. }
  3992. });
  3993. },
  3994. /**
  3995. * @private
  3996. */
  3997. hideSeriesLabelsFromATWhenShown: function () {
  3998. this.addEvent(this.chart, 'afterDrawSeriesLabels', function () {
  3999. this.series.forEach(function (series) {
  4000. if (series.labelBySeries) {
  4001. series.labelBySeries.attr('aria-hidden', true);
  4002. }
  4003. });
  4004. });
  4005. },
  4006. /**
  4007. * Called on chart render. It is necessary to do this for render in case
  4008. * markers change on zoom/pixel density.
  4009. */
  4010. onChartRender: function () {
  4011. var chart = this.chart;
  4012. chart.series.forEach(function (series) {
  4013. var shouldDescribeSeries = (series.options.accessibility &&
  4014. series.options.accessibility.enabled) !== false &&
  4015. series.visible;
  4016. if (shouldDescribeSeries) {
  4017. describeSeries(series);
  4018. }
  4019. else {
  4020. hideSeriesFromAT(series);
  4021. }
  4022. });
  4023. },
  4024. /**
  4025. * Get keyboard navigation handler for this component.
  4026. * @return {Highcharts.KeyboardNavigationHandler}
  4027. */
  4028. getKeyboardNavigation: function () {
  4029. return this.keyboardNavigation.getKeyboardNavigationHandler();
  4030. },
  4031. /**
  4032. * Remove traces
  4033. */
  4034. destroy: function () {
  4035. this.newDataAnnouncer.destroy();
  4036. this.keyboardNavigation.destroy();
  4037. }
  4038. });
  4039. return SeriesComponent;
  4040. });
  4041. _registerModule(_modules, 'Accessibility/Components/ZoomComponent.js', [_modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Accessibility/KeyboardNavigationHandler.js'], _modules['Core/Utilities.js']], function (AccessibilityComponent, ChartUtilities, H, HTMLUtilities, KeyboardNavigationHandler, U) {
  4042. /* *
  4043. *
  4044. * (c) 2009-2021 Øystein Moseng
  4045. *
  4046. * Accessibility component for chart zoom.
  4047. *
  4048. * License: www.highcharts.com/license
  4049. *
  4050. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4051. *
  4052. * */
  4053. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  4054. var noop = H.noop;
  4055. var removeElement = HTMLUtilities.removeElement,
  4056. setElAttrs = HTMLUtilities.setElAttrs;
  4057. var extend = U.extend,
  4058. pick = U.pick;
  4059. /* eslint-disable no-invalid-this, valid-jsdoc */
  4060. /**
  4061. * @private
  4062. */
  4063. function chartHasMapZoom(chart) {
  4064. return !!(chart.mapZoom &&
  4065. chart.mapNavButtons &&
  4066. chart.mapNavButtons.length);
  4067. }
  4068. /**
  4069. * Pan along axis in a direction (1 or -1), optionally with a defined
  4070. * granularity (number of steps it takes to walk across current view)
  4071. *
  4072. * @private
  4073. * @function Highcharts.Axis#panStep
  4074. *
  4075. * @param {number} direction
  4076. * @param {number} [granularity]
  4077. */
  4078. H.Axis.prototype.panStep = function (direction, granularity) {
  4079. var gran = granularity || 3,
  4080. extremes = this.getExtremes(),
  4081. step = (extremes.max - extremes.min) / gran * direction,
  4082. newMax = extremes.max + step,
  4083. newMin = extremes.min + step,
  4084. size = newMax - newMin;
  4085. if (direction < 0 && newMin < extremes.dataMin) {
  4086. newMin = extremes.dataMin;
  4087. newMax = newMin + size;
  4088. }
  4089. else if (direction > 0 && newMax > extremes.dataMax) {
  4090. newMax = extremes.dataMax;
  4091. newMin = newMax - size;
  4092. }
  4093. this.setExtremes(newMin, newMax);
  4094. };
  4095. /**
  4096. * The ZoomComponent class
  4097. *
  4098. * @private
  4099. * @class
  4100. * @name Highcharts.ZoomComponent
  4101. */
  4102. var ZoomComponent = noop;
  4103. ZoomComponent.prototype = new AccessibilityComponent();
  4104. extend(ZoomComponent.prototype, /** @lends Highcharts.ZoomComponent */ {
  4105. /**
  4106. * Initialize the component
  4107. */
  4108. init: function () {
  4109. var component = this,
  4110. chart = this.chart;
  4111. [
  4112. 'afterShowResetZoom', 'afterDrilldown', 'drillupall'
  4113. ].forEach(function (eventType) {
  4114. component.addEvent(chart, eventType, function () {
  4115. component.updateProxyOverlays();
  4116. });
  4117. });
  4118. },
  4119. /**
  4120. * Called when chart is updated
  4121. */
  4122. onChartUpdate: function () {
  4123. var chart = this.chart,
  4124. component = this;
  4125. // Make map zoom buttons accessible
  4126. if (chart.mapNavButtons) {
  4127. chart.mapNavButtons.forEach(function (button, i) {
  4128. unhideChartElementFromAT(chart, button.element);
  4129. component.setMapNavButtonAttrs(button.element, 'accessibility.zoom.mapZoom' + (i ? 'Out' : 'In'));
  4130. });
  4131. }
  4132. },
  4133. /**
  4134. * @private
  4135. * @param {Highcharts.HTMLDOMElement|Highcharts.SVGDOMElement} button
  4136. * @param {string} labelFormatKey
  4137. */
  4138. setMapNavButtonAttrs: function (button, labelFormatKey) {
  4139. var chart = this.chart,
  4140. label = chart.langFormat(labelFormatKey, { chart: chart });
  4141. setElAttrs(button, {
  4142. tabindex: -1,
  4143. role: 'button',
  4144. 'aria-label': label
  4145. });
  4146. },
  4147. /**
  4148. * Update the proxy overlays on every new render to ensure positions are
  4149. * correct.
  4150. */
  4151. onChartRender: function () {
  4152. this.updateProxyOverlays();
  4153. },
  4154. /**
  4155. * Update proxy overlays, recreating the buttons.
  4156. */
  4157. updateProxyOverlays: function () {
  4158. var chart = this.chart;
  4159. // Always start with a clean slate
  4160. removeElement(this.drillUpProxyGroup);
  4161. removeElement(this.resetZoomProxyGroup);
  4162. if (chart.resetZoomButton) {
  4163. this.recreateProxyButtonAndGroup(chart.resetZoomButton, 'resetZoomProxyButton', 'resetZoomProxyGroup', chart.langFormat('accessibility.zoom.resetZoomButton', { chart: chart }));
  4164. }
  4165. if (chart.drillUpButton) {
  4166. this.recreateProxyButtonAndGroup(chart.drillUpButton, 'drillUpProxyButton', 'drillUpProxyGroup', chart.langFormat('accessibility.drillUpButton', {
  4167. chart: chart,
  4168. buttonText: chart.getDrilldownBackText()
  4169. }));
  4170. }
  4171. },
  4172. /**
  4173. * @private
  4174. * @param {Highcharts.SVGElement} buttonEl
  4175. * @param {string} buttonProp
  4176. * @param {string} groupProp
  4177. * @param {string} label
  4178. */
  4179. recreateProxyButtonAndGroup: function (buttonEl, buttonProp, groupProp, label) {
  4180. removeElement(this[groupProp]);
  4181. this[groupProp] = this.addProxyGroup();
  4182. this[buttonProp] = this.createProxyButton(buttonEl, this[groupProp], { 'aria-label': label, tabindex: -1 });
  4183. },
  4184. /**
  4185. * Get keyboard navigation handler for map zoom.
  4186. * @private
  4187. * @return {Highcharts.KeyboardNavigationHandler} The module object
  4188. */
  4189. getMapZoomNavigation: function () {
  4190. var keys = this.keyCodes,
  4191. chart = this.chart,
  4192. component = this;
  4193. return new KeyboardNavigationHandler(chart, {
  4194. keyCodeMap: [
  4195. [
  4196. [keys.up, keys.down, keys.left, keys.right],
  4197. function (keyCode) {
  4198. return component.onMapKbdArrow(this, keyCode);
  4199. }
  4200. ],
  4201. [
  4202. [keys.tab],
  4203. function (_keyCode, e) {
  4204. return component.onMapKbdTab(this, e);
  4205. }
  4206. ],
  4207. [
  4208. [keys.space, keys.enter],
  4209. function () {
  4210. return component.onMapKbdClick(this);
  4211. }
  4212. ]
  4213. ],
  4214. validate: function () {
  4215. return chartHasMapZoom(chart);
  4216. },
  4217. init: function (direction) {
  4218. return component.onMapNavInit(direction);
  4219. }
  4220. });
  4221. },
  4222. /**
  4223. * @private
  4224. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  4225. * @param {number} keyCode
  4226. * @return {number} Response code
  4227. */
  4228. onMapKbdArrow: function (keyboardNavigationHandler, keyCode) {
  4229. var keys = this.keyCodes,
  4230. panAxis = (keyCode === keys.up || keyCode === keys.down) ?
  4231. 'yAxis' : 'xAxis',
  4232. stepDirection = (keyCode === keys.left || keyCode === keys.up) ?
  4233. -1 : 1;
  4234. this.chart[panAxis][0].panStep(stepDirection);
  4235. return keyboardNavigationHandler.response.success;
  4236. },
  4237. /**
  4238. * @private
  4239. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  4240. * @param {global.KeyboardEvent} event
  4241. * @return {number} Response code
  4242. */
  4243. onMapKbdTab: function (keyboardNavigationHandler, event) {
  4244. var button,
  4245. chart = this.chart,
  4246. response = keyboardNavigationHandler.response,
  4247. isBackwards = event.shiftKey,
  4248. isMoveOutOfRange = isBackwards && !this.focusedMapNavButtonIx ||
  4249. !isBackwards && this.focusedMapNavButtonIx;
  4250. // Deselect old
  4251. chart.mapNavButtons[this.focusedMapNavButtonIx].setState(0);
  4252. if (isMoveOutOfRange) {
  4253. chart.mapZoom(); // Reset zoom
  4254. return response[isBackwards ? 'prev' : 'next'];
  4255. }
  4256. // Select other button
  4257. this.focusedMapNavButtonIx += isBackwards ? -1 : 1;
  4258. button = chart.mapNavButtons[this.focusedMapNavButtonIx];
  4259. chart.setFocusToElement(button.box, button.element);
  4260. button.setState(2);
  4261. return response.success;
  4262. },
  4263. /**
  4264. * @private
  4265. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  4266. * @return {number} Response code
  4267. */
  4268. onMapKbdClick: function (keyboardNavigationHandler) {
  4269. this.fakeClickEvent(this.chart.mapNavButtons[this.focusedMapNavButtonIx]
  4270. .element);
  4271. return keyboardNavigationHandler.response.success;
  4272. },
  4273. /**
  4274. * @private
  4275. * @param {number} direction
  4276. */
  4277. onMapNavInit: function (direction) {
  4278. var chart = this.chart,
  4279. zoomIn = chart.mapNavButtons[0],
  4280. zoomOut = chart.mapNavButtons[1],
  4281. initialButton = direction > 0 ? zoomIn : zoomOut;
  4282. chart.setFocusToElement(initialButton.box, initialButton.element);
  4283. initialButton.setState(2);
  4284. this.focusedMapNavButtonIx = direction > 0 ? 0 : 1;
  4285. },
  4286. /**
  4287. * Get keyboard navigation handler for a simple chart button. Provide the
  4288. * button reference for the chart, and a function to call on click.
  4289. *
  4290. * @private
  4291. * @param {string} buttonProp The property on chart referencing the button.
  4292. * @return {Highcharts.KeyboardNavigationHandler} The module object
  4293. */
  4294. simpleButtonNavigation: function (buttonProp, proxyProp, onClick) {
  4295. var keys = this.keyCodes,
  4296. component = this,
  4297. chart = this.chart;
  4298. return new KeyboardNavigationHandler(chart, {
  4299. keyCodeMap: [
  4300. [
  4301. [keys.tab, keys.up, keys.down, keys.left, keys.right],
  4302. function (keyCode, e) {
  4303. var isBackwards = keyCode === keys.tab && e.shiftKey ||
  4304. keyCode === keys.left || keyCode === keys.up;
  4305. // Arrow/tab => just move
  4306. return this.response[isBackwards ? 'prev' : 'next'];
  4307. }
  4308. ],
  4309. [
  4310. [keys.space, keys.enter],
  4311. function () {
  4312. var res = onClick(this,
  4313. chart);
  4314. return pick(res, this.response.success);
  4315. }
  4316. ]
  4317. ],
  4318. validate: function () {
  4319. var hasButton = (chart[buttonProp] &&
  4320. chart[buttonProp].box &&
  4321. component[proxyProp]);
  4322. return hasButton;
  4323. },
  4324. init: function () {
  4325. chart.setFocusToElement(chart[buttonProp].box, component[proxyProp]);
  4326. }
  4327. });
  4328. },
  4329. /**
  4330. * Get keyboard navigation handlers for this component.
  4331. * @return {Array<Highcharts.KeyboardNavigationHandler>}
  4332. * List of module objects
  4333. */
  4334. getKeyboardNavigation: function () {
  4335. return [
  4336. this.simpleButtonNavigation('resetZoomButton', 'resetZoomProxyButton', function (_handler, chart) {
  4337. chart.zoomOut();
  4338. }),
  4339. this.simpleButtonNavigation('drillUpButton', 'drillUpProxyButton', function (handler, chart) {
  4340. chart.drillUp();
  4341. return handler.response.prev;
  4342. }),
  4343. this.getMapZoomNavigation()
  4344. ];
  4345. }
  4346. });
  4347. return ZoomComponent;
  4348. });
  4349. _registerModule(_modules, 'Extensions/RangeSelector.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Color/Palette.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Utilities.js']], function (Axis, Chart, H, O, palette, SVGElement, U) {
  4350. /* *
  4351. *
  4352. * (c) 2010-2021 Torstein Honsi
  4353. *
  4354. * License: www.highcharts.com/license
  4355. *
  4356. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4357. *
  4358. * */
  4359. var defaultOptions = O.defaultOptions;
  4360. var addEvent = U.addEvent,
  4361. createElement = U.createElement,
  4362. css = U.css,
  4363. defined = U.defined,
  4364. destroyObjectProperties = U.destroyObjectProperties,
  4365. discardElement = U.discardElement,
  4366. extend = U.extend,
  4367. find = U.find,
  4368. fireEvent = U.fireEvent,
  4369. isNumber = U.isNumber,
  4370. merge = U.merge,
  4371. objectEach = U.objectEach,
  4372. pad = U.pad,
  4373. pick = U.pick,
  4374. pInt = U.pInt,
  4375. splat = U.splat;
  4376. /**
  4377. * Define the time span for the button
  4378. *
  4379. * @typedef {"all"|"day"|"hour"|"millisecond"|"minute"|"month"|"second"|"week"|"year"|"ytd"} Highcharts.RangeSelectorButtonTypeValue
  4380. */
  4381. /**
  4382. * Callback function to react on button clicks.
  4383. *
  4384. * @callback Highcharts.RangeSelectorClickCallbackFunction
  4385. *
  4386. * @param {global.Event} e
  4387. * Event arguments.
  4388. *
  4389. * @param {boolean|undefined}
  4390. * Return false to cancel the default button event.
  4391. */
  4392. /**
  4393. * Callback function to parse values entered in the input boxes and return a
  4394. * valid JavaScript time as milliseconds since 1970.
  4395. *
  4396. * @callback Highcharts.RangeSelectorParseCallbackFunction
  4397. *
  4398. * @param {string} value
  4399. * Input value to parse.
  4400. *
  4401. * @return {number}
  4402. * Parsed JavaScript time value.
  4403. */
  4404. /* ************************************************************************** *
  4405. * Start Range Selector code *
  4406. * ************************************************************************** */
  4407. extend(defaultOptions, {
  4408. /**
  4409. * The range selector is a tool for selecting ranges to display within
  4410. * the chart. It provides buttons to select preconfigured ranges in
  4411. * the chart, like 1 day, 1 week, 1 month etc. It also provides input
  4412. * boxes where min and max dates can be manually input.
  4413. *
  4414. * @product highstock gantt
  4415. * @optionparent rangeSelector
  4416. */
  4417. rangeSelector: {
  4418. /**
  4419. * Whether to enable all buttons from the start. By default buttons are
  4420. * only enabled if the corresponding time range exists on the X axis,
  4421. * but enabling all buttons allows for dynamically loading different
  4422. * time ranges.
  4423. *
  4424. * @sample {highstock} stock/rangeselector/allbuttonsenabled-true/
  4425. * All buttons enabled
  4426. *
  4427. * @since 2.0.3
  4428. */
  4429. allButtonsEnabled: false,
  4430. /**
  4431. * An array of configuration objects for the buttons.
  4432. *
  4433. * Defaults to:
  4434. * ```js
  4435. * buttons: [{
  4436. * type: 'month',
  4437. * count: 1,
  4438. * text: '1m',
  4439. * title: 'View 1 month'
  4440. * }, {
  4441. * type: 'month',
  4442. * count: 3,
  4443. * text: '3m',
  4444. * title: 'View 3 months'
  4445. * }, {
  4446. * type: 'month',
  4447. * count: 6,
  4448. * text: '6m',
  4449. * title: 'View 6 months'
  4450. * }, {
  4451. * type: 'ytd',
  4452. * text: 'YTD',
  4453. * title: 'View year to date'
  4454. * }, {
  4455. * type: 'year',
  4456. * count: 1,
  4457. * text: '1y',
  4458. * title: 'View 1 year'
  4459. * }, {
  4460. * type: 'all',
  4461. * text: 'All',
  4462. * title: 'View all'
  4463. * }]
  4464. * ```
  4465. *
  4466. * @sample {highstock} stock/rangeselector/datagrouping/
  4467. * Data grouping by buttons
  4468. *
  4469. * @type {Array<*>}
  4470. */
  4471. buttons: void 0,
  4472. /**
  4473. * How many units of the defined type the button should span. If `type`
  4474. * is "month" and `count` is 3, the button spans three months.
  4475. *
  4476. * @type {number}
  4477. * @default 1
  4478. * @apioption rangeSelector.buttons.count
  4479. */
  4480. /**
  4481. * Fires when clicking on the rangeSelector button. One parameter,
  4482. * event, is passed to the function, containing common event
  4483. * information.
  4484. *
  4485. * ```js
  4486. * click: function(e) {
  4487. * console.log(this);
  4488. * }
  4489. * ```
  4490. *
  4491. * Return false to stop default button's click action.
  4492. *
  4493. * @sample {highstock} stock/rangeselector/button-click/
  4494. * Click event on the button
  4495. *
  4496. * @type {Highcharts.RangeSelectorClickCallbackFunction}
  4497. * @apioption rangeSelector.buttons.events.click
  4498. */
  4499. /**
  4500. * Additional range (in milliseconds) added to the end of the calculated
  4501. * time span.
  4502. *
  4503. * @sample {highstock} stock/rangeselector/min-max-offsets/
  4504. * Button offsets
  4505. *
  4506. * @type {number}
  4507. * @default 0
  4508. * @since 6.0.0
  4509. * @apioption rangeSelector.buttons.offsetMax
  4510. */
  4511. /**
  4512. * Additional range (in milliseconds) added to the start of the
  4513. * calculated time span.
  4514. *
  4515. * @sample {highstock} stock/rangeselector/min-max-offsets/
  4516. * Button offsets
  4517. *
  4518. * @type {number}
  4519. * @default 0
  4520. * @since 6.0.0
  4521. * @apioption rangeSelector.buttons.offsetMin
  4522. */
  4523. /**
  4524. * When buttons apply dataGrouping on a series, by default zooming
  4525. * in/out will deselect buttons and unset dataGrouping. Enable this
  4526. * option to keep buttons selected when extremes change.
  4527. *
  4528. * @sample {highstock} stock/rangeselector/preserve-datagrouping/
  4529. * Different preserveDataGrouping settings
  4530. *
  4531. * @type {boolean}
  4532. * @default false
  4533. * @since 6.1.2
  4534. * @apioption rangeSelector.buttons.preserveDataGrouping
  4535. */
  4536. /**
  4537. * A custom data grouping object for each button.
  4538. *
  4539. * @see [series.dataGrouping](#plotOptions.series.dataGrouping)
  4540. *
  4541. * @sample {highstock} stock/rangeselector/datagrouping/
  4542. * Data grouping by range selector buttons
  4543. *
  4544. * @type {*}
  4545. * @extends plotOptions.series.dataGrouping
  4546. * @apioption rangeSelector.buttons.dataGrouping
  4547. */
  4548. /**
  4549. * The text for the button itself.
  4550. *
  4551. * @type {string}
  4552. * @apioption rangeSelector.buttons.text
  4553. */
  4554. /**
  4555. * Explanation for the button, shown as a tooltip on hover, and used by
  4556. * assistive technology.
  4557. *
  4558. * @type {string}
  4559. * @apioption rangeSelector.buttons.title
  4560. */
  4561. /**
  4562. * Defined the time span for the button. Can be one of `millisecond`,
  4563. * `second`, `minute`, `hour`, `day`, `week`, `month`, `year`, `ytd`,
  4564. * and `all`.
  4565. *
  4566. * @type {Highcharts.RangeSelectorButtonTypeValue}
  4567. * @apioption rangeSelector.buttons.type
  4568. */
  4569. /**
  4570. * The space in pixels between the buttons in the range selector.
  4571. */
  4572. buttonSpacing: 5,
  4573. /**
  4574. * Whether to collapse the range selector buttons into a dropdown when
  4575. * there is not enough room to show everything in a single row, instead
  4576. * of dividing the range selector into multiple rows.
  4577. * Can be one of the following:
  4578. * - `always`: Always collapse
  4579. * - `responsive`: Only collapse when there is not enough room
  4580. * - `never`: Never collapse
  4581. *
  4582. * @sample {highstock} stock/rangeselector/dropdown/
  4583. * Dropdown option
  4584. *
  4585. * @validvalue ["always", "responsive", "never"]
  4586. * @since 9.0.0
  4587. */
  4588. dropdown: 'responsive',
  4589. /**
  4590. * Enable or disable the range selector. Default to `true` for stock
  4591. * charts, using the `stockChart` factory.
  4592. *
  4593. * @sample {highstock} stock/rangeselector/enabled/
  4594. * Disable the range selector
  4595. *
  4596. * @type {boolean|undefined}
  4597. * @default {highstock} true
  4598. */
  4599. enabled: void 0,
  4600. /**
  4601. * The vertical alignment of the rangeselector box. Allowed properties
  4602. * are `top`, `middle`, `bottom`.
  4603. *
  4604. * @sample {highstock} stock/rangeselector/vertical-align-middle/
  4605. * Middle
  4606. * @sample {highstock} stock/rangeselector/vertical-align-bottom/
  4607. * Bottom
  4608. *
  4609. * @type {Highcharts.VerticalAlignValue}
  4610. * @since 6.0.0
  4611. */
  4612. verticalAlign: 'top',
  4613. /**
  4614. * A collection of attributes for the buttons. The object takes SVG
  4615. * attributes like `fill`, `stroke`, `stroke-width`, as well as `style`,
  4616. * a collection of CSS properties for the text.
  4617. *
  4618. * The object can also be extended with states, so you can set
  4619. * presentational options for `hover`, `select` or `disabled` button
  4620. * states.
  4621. *
  4622. * CSS styles for the text label.
  4623. *
  4624. * In styled mode, the buttons are styled by the
  4625. * `.highcharts-range-selector-buttons .highcharts-button` rule with its
  4626. * different states.
  4627. *
  4628. * @sample {highstock} stock/rangeselector/styling/
  4629. * Styling the buttons and inputs
  4630. *
  4631. * @type {Highcharts.SVGAttributes}
  4632. */
  4633. buttonTheme: {
  4634. /** @ignore */
  4635. width: 28,
  4636. /** @ignore */
  4637. height: 18,
  4638. /** @ignore */
  4639. padding: 2,
  4640. /** @ignore */
  4641. zIndex: 7 // #484, #852
  4642. },
  4643. /**
  4644. * When the rangeselector is floating, the plot area does not reserve
  4645. * space for it. This opens for positioning anywhere on the chart.
  4646. *
  4647. * @sample {highstock} stock/rangeselector/floating/
  4648. * Placing the range selector between the plot area and the
  4649. * navigator
  4650. *
  4651. * @since 6.0.0
  4652. */
  4653. floating: false,
  4654. /**
  4655. * The x offset of the range selector relative to its horizontal
  4656. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  4657. *
  4658. * @since 6.0.0
  4659. */
  4660. x: 0,
  4661. /**
  4662. * The y offset of the range selector relative to its horizontal
  4663. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  4664. *
  4665. * @since 6.0.0
  4666. */
  4667. y: 0,
  4668. /**
  4669. * Deprecated. The height of the range selector. Currently it is
  4670. * calculated dynamically.
  4671. *
  4672. * @deprecated
  4673. * @type {number|undefined}
  4674. * @since 2.1.9
  4675. */
  4676. height: void 0,
  4677. /**
  4678. * The border color of the date input boxes.
  4679. *
  4680. * @sample {highstock} stock/rangeselector/styling/
  4681. * Styling the buttons and inputs
  4682. *
  4683. * @type {Highcharts.ColorString}
  4684. * @since 1.3.7
  4685. */
  4686. inputBoxBorderColor: 'none',
  4687. /**
  4688. * The pixel height of the date input boxes.
  4689. *
  4690. * @sample {highstock} stock/rangeselector/styling/
  4691. * Styling the buttons and inputs
  4692. *
  4693. * @since 1.3.7
  4694. */
  4695. inputBoxHeight: 17,
  4696. /**
  4697. * The pixel width of the date input boxes. When `undefined`, the width
  4698. * is fitted to the rendered content.
  4699. *
  4700. * @sample {highstock} stock/rangeselector/styling/
  4701. * Styling the buttons and inputs
  4702. *
  4703. * @type {number|undefined}
  4704. * @since 1.3.7
  4705. */
  4706. inputBoxWidth: void 0,
  4707. /**
  4708. * The date format in the input boxes when not selected for editing.
  4709. * Defaults to `%b %e, %Y`.
  4710. *
  4711. * This is used to determine which type of input to show,
  4712. * `datetime-local`, `date` or `time` and falling back to `text` when
  4713. * the browser does not support the input type or the format contains
  4714. * milliseconds.
  4715. *
  4716. * @sample {highstock} stock/rangeselector/input-type/
  4717. * Input types
  4718. * @sample {highstock} stock/rangeselector/input-format/
  4719. * Milliseconds in the range selector
  4720. *
  4721. */
  4722. inputDateFormat: '%b %e, %Y',
  4723. /**
  4724. * A custom callback function to parse values entered in the input boxes
  4725. * and return a valid JavaScript time as milliseconds since 1970.
  4726. * The first argument passed is a value to parse,
  4727. * second is a boolean indicating use of the UTC time.
  4728. *
  4729. * This will only get called for inputs of type `text`. Since v8.2.3,
  4730. * the input type is dynamically determined based on the granularity
  4731. * of the `inputDateFormat` and the browser support.
  4732. *
  4733. * @sample {highstock} stock/rangeselector/input-format/
  4734. * Milliseconds in the range selector
  4735. *
  4736. * @type {Highcharts.RangeSelectorParseCallbackFunction}
  4737. * @since 1.3.3
  4738. */
  4739. inputDateParser: void 0,
  4740. /**
  4741. * The date format in the input boxes when they are selected for
  4742. * editing. This must be a format that is recognized by JavaScript
  4743. * Date.parse.
  4744. *
  4745. * This will only be used for inputs of type `text`. Since v8.2.3,
  4746. * the input type is dynamically determined based on the granularity
  4747. * of the `inputDateFormat` and the browser support.
  4748. *
  4749. * @sample {highstock} stock/rangeselector/input-format/
  4750. * Milliseconds in the range selector
  4751. *
  4752. */
  4753. inputEditDateFormat: '%Y-%m-%d',
  4754. /**
  4755. * Enable or disable the date input boxes.
  4756. */
  4757. inputEnabled: true,
  4758. /**
  4759. * Positioning for the input boxes. Allowed properties are `align`,
  4760. * `x` and `y`.
  4761. *
  4762. * @since 1.2.4
  4763. */
  4764. inputPosition: {
  4765. /**
  4766. * The alignment of the input box. Allowed properties are `left`,
  4767. * `center`, `right`.
  4768. *
  4769. * @sample {highstock} stock/rangeselector/input-button-position/
  4770. * Alignment
  4771. *
  4772. * @type {Highcharts.AlignValue}
  4773. * @since 6.0.0
  4774. */
  4775. align: 'right',
  4776. /**
  4777. * X offset of the input row.
  4778. */
  4779. x: 0,
  4780. /**
  4781. * Y offset of the input row.
  4782. */
  4783. y: 0
  4784. },
  4785. /**
  4786. * The space in pixels between the labels and the date input boxes in
  4787. * the range selector.
  4788. *
  4789. * @since 9.0.0
  4790. */
  4791. inputSpacing: 5,
  4792. /**
  4793. * The index of the button to appear pre-selected.
  4794. *
  4795. * @type {number}
  4796. */
  4797. selected: void 0,
  4798. /**
  4799. * Positioning for the button row.
  4800. *
  4801. * @since 1.2.4
  4802. */
  4803. buttonPosition: {
  4804. /**
  4805. * The alignment of the input box. Allowed properties are `left`,
  4806. * `center`, `right`.
  4807. *
  4808. * @sample {highstock} stock/rangeselector/input-button-position/
  4809. * Alignment
  4810. *
  4811. * @type {Highcharts.AlignValue}
  4812. * @since 6.0.0
  4813. */
  4814. align: 'left',
  4815. /**
  4816. * X offset of the button row.
  4817. */
  4818. x: 0,
  4819. /**
  4820. * Y offset of the button row.
  4821. */
  4822. y: 0
  4823. },
  4824. /**
  4825. * CSS for the HTML inputs in the range selector.
  4826. *
  4827. * In styled mode, the inputs are styled by the
  4828. * `.highcharts-range-input text` rule in SVG mode, and
  4829. * `input.highcharts-range-selector` when active.
  4830. *
  4831. * @sample {highstock} stock/rangeselector/styling/
  4832. * Styling the buttons and inputs
  4833. *
  4834. * @type {Highcharts.CSSObject}
  4835. * @apioption rangeSelector.inputStyle
  4836. */
  4837. inputStyle: {
  4838. /** @ignore */
  4839. color: palette.highlightColor80,
  4840. /** @ignore */
  4841. cursor: 'pointer'
  4842. },
  4843. /**
  4844. * CSS styles for the labels - the Zoom, From and To texts.
  4845. *
  4846. * In styled mode, the labels are styled by the
  4847. * `.highcharts-range-label` class.
  4848. *
  4849. * @sample {highstock} stock/rangeselector/styling/
  4850. * Styling the buttons and inputs
  4851. *
  4852. * @type {Highcharts.CSSObject}
  4853. */
  4854. labelStyle: {
  4855. /** @ignore */
  4856. color: palette.neutralColor60
  4857. }
  4858. }
  4859. });
  4860. extend(defaultOptions.lang,
  4861. /**
  4862. * Language object. The language object is global and it can't be set
  4863. * on each chart initialization. Instead, use `Highcharts.setOptions` to
  4864. * set it before any chart is initialized.
  4865. *
  4866. * ```js
  4867. * Highcharts.setOptions({
  4868. * lang: {
  4869. * months: [
  4870. * 'Janvier', 'Février', 'Mars', 'Avril',
  4871. * 'Mai', 'Juin', 'Juillet', 'Août',
  4872. * 'Septembre', 'Octobre', 'Novembre', 'Décembre'
  4873. * ],
  4874. * weekdays: [
  4875. * 'Dimanche', 'Lundi', 'Mardi', 'Mercredi',
  4876. * 'Jeudi', 'Vendredi', 'Samedi'
  4877. * ]
  4878. * }
  4879. * });
  4880. * ```
  4881. *
  4882. * @optionparent lang
  4883. */
  4884. {
  4885. /**
  4886. * The text for the label for the range selector buttons.
  4887. *
  4888. * @product highstock gantt
  4889. */
  4890. rangeSelectorZoom: 'Zoom',
  4891. /**
  4892. * The text for the label for the "from" input box in the range
  4893. * selector. Since v9.0, this string is empty as the label is not
  4894. * rendered by default.
  4895. *
  4896. * @product highstock gantt
  4897. */
  4898. rangeSelectorFrom: '',
  4899. /**
  4900. * The text for the label for the "to" input box in the range selector.
  4901. *
  4902. * @product highstock gantt
  4903. */
  4904. rangeSelectorTo: '→'
  4905. });
  4906. /* eslint-disable no-invalid-this, valid-jsdoc */
  4907. /**
  4908. * The range selector.
  4909. *
  4910. * @private
  4911. * @class
  4912. * @name Highcharts.RangeSelector
  4913. * @param {Highcharts.Chart} chart
  4914. */
  4915. var RangeSelector = /** @class */ (function () {
  4916. function RangeSelector(chart) {
  4917. /* *
  4918. *
  4919. * Properties
  4920. *
  4921. * */
  4922. this.buttons = void 0;
  4923. this.buttonOptions = RangeSelector.prototype.defaultButtons;
  4924. this.initialButtonGroupWidth = 0;
  4925. this.options = void 0;
  4926. this.chart = chart;
  4927. // Run RangeSelector
  4928. this.init(chart);
  4929. }
  4930. /**
  4931. * The method to run when one of the buttons in the range selectors is
  4932. * clicked
  4933. *
  4934. * @private
  4935. * @function Highcharts.RangeSelector#clickButton
  4936. * @param {number} i
  4937. * The index of the button
  4938. * @param {boolean} [redraw]
  4939. * @return {void}
  4940. */
  4941. RangeSelector.prototype.clickButton = function (i, redraw) {
  4942. var rangeSelector = this,
  4943. chart = rangeSelector.chart,
  4944. rangeOptions = rangeSelector.buttonOptions[i],
  4945. baseAxis = chart.xAxis[0],
  4946. unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || baseAxis || {},
  4947. dataMin = unionExtremes.dataMin,
  4948. dataMax = unionExtremes.dataMax,
  4949. newMin,
  4950. newMax = baseAxis && Math.round(Math.min(baseAxis.max,
  4951. pick(dataMax,
  4952. baseAxis.max))), // #1568
  4953. type = rangeOptions.type,
  4954. baseXAxisOptions,
  4955. range = rangeOptions._range,
  4956. rangeMin,
  4957. minSetting,
  4958. rangeSetting,
  4959. ctx,
  4960. ytdExtremes,
  4961. dataGrouping = rangeOptions.dataGrouping;
  4962. // chart has no data, base series is removed
  4963. if (dataMin === null || dataMax === null) {
  4964. return;
  4965. }
  4966. // Set the fixed range before range is altered
  4967. chart.fixedRange = range;
  4968. // Apply dataGrouping associated to button
  4969. if (dataGrouping) {
  4970. this.forcedDataGrouping = true;
  4971. Axis.prototype.setDataGrouping.call(baseAxis || { chart: this.chart }, dataGrouping, false);
  4972. this.frozenStates = rangeOptions.preserveDataGrouping;
  4973. }
  4974. // Apply range
  4975. if (type === 'month' || type === 'year') {
  4976. if (!baseAxis) {
  4977. // This is set to the user options and picked up later when the
  4978. // axis is instantiated so that we know the min and max.
  4979. range = rangeOptions;
  4980. }
  4981. else {
  4982. ctx = {
  4983. range: rangeOptions,
  4984. max: newMax,
  4985. chart: chart,
  4986. dataMin: dataMin,
  4987. dataMax: dataMax
  4988. };
  4989. newMin = baseAxis.minFromRange.call(ctx);
  4990. if (isNumber(ctx.newMax)) {
  4991. newMax = ctx.newMax;
  4992. }
  4993. }
  4994. // Fixed times like minutes, hours, days
  4995. }
  4996. else if (range) {
  4997. newMin = Math.max(newMax - range, dataMin);
  4998. newMax = Math.min(newMin + range, dataMax);
  4999. }
  5000. else if (type === 'ytd') {
  5001. // On user clicks on the buttons, or a delayed action running from
  5002. // the beforeRender event (below), the baseAxis is defined.
  5003. if (baseAxis) {
  5004. // When "ytd" is the pre-selected button for the initial view,
  5005. // its calculation is delayed and rerun in the beforeRender
  5006. // event (below). When the series are initialized, but before
  5007. // the chart is rendered, we have access to the xData array
  5008. // (#942).
  5009. if (typeof dataMax === 'undefined') {
  5010. dataMin = Number.MAX_VALUE;
  5011. dataMax = Number.MIN_VALUE;
  5012. chart.series.forEach(function (series) {
  5013. // reassign it to the last item
  5014. var xData = series.xData;
  5015. dataMin = Math.min(xData[0], dataMin);
  5016. dataMax = Math.max(xData[xData.length - 1], dataMax);
  5017. });
  5018. redraw = false;
  5019. }
  5020. ytdExtremes = rangeSelector.getYTDExtremes(dataMax, dataMin, chart.time.useUTC);
  5021. newMin = rangeMin = ytdExtremes.min;
  5022. newMax = ytdExtremes.max;
  5023. // "ytd" is pre-selected. We don't yet have access to processed
  5024. // point and extremes data (things like pointStart and pointInterval
  5025. // are missing), so we delay the process (#942)
  5026. }
  5027. else {
  5028. rangeSelector.deferredYTDClick = i;
  5029. return;
  5030. }
  5031. }
  5032. else if (type === 'all' && baseAxis) {
  5033. newMin = dataMin;
  5034. newMax = dataMax;
  5035. }
  5036. if (defined(newMin)) {
  5037. newMin += rangeOptions._offsetMin;
  5038. }
  5039. if (defined(newMax)) {
  5040. newMax += rangeOptions._offsetMax;
  5041. }
  5042. rangeSelector.setSelected(i);
  5043. if (this.dropdown) {
  5044. this.dropdown.selectedIndex = i + 1;
  5045. }
  5046. // Update the chart
  5047. if (!baseAxis) {
  5048. // Axis not yet instanciated. Temporarily set min and range
  5049. // options and remove them on chart load (#4317).
  5050. baseXAxisOptions = splat(chart.options.xAxis)[0];
  5051. rangeSetting = baseXAxisOptions.range;
  5052. baseXAxisOptions.range = range;
  5053. minSetting = baseXAxisOptions.min;
  5054. baseXAxisOptions.min = rangeMin;
  5055. addEvent(chart, 'load', function resetMinAndRange() {
  5056. baseXAxisOptions.range = rangeSetting;
  5057. baseXAxisOptions.min = minSetting;
  5058. });
  5059. }
  5060. else {
  5061. // Existing axis object. Set extremes after render time.
  5062. baseAxis.setExtremes(newMin, newMax, pick(redraw, true), void 0, // auto animation
  5063. {
  5064. trigger: 'rangeSelectorButton',
  5065. rangeSelectorButton: rangeOptions
  5066. });
  5067. }
  5068. fireEvent(this, 'afterBtnClick');
  5069. };
  5070. /**
  5071. * Set the selected option. This method only sets the internal flag, it
  5072. * doesn't update the buttons or the actual zoomed range.
  5073. *
  5074. * @private
  5075. * @function Highcharts.RangeSelector#setSelected
  5076. * @param {number} [selected]
  5077. * @return {void}
  5078. */
  5079. RangeSelector.prototype.setSelected = function (selected) {
  5080. this.selected = this.options.selected = selected;
  5081. };
  5082. /**
  5083. * Initialize the range selector
  5084. *
  5085. * @private
  5086. * @function Highcharts.RangeSelector#init
  5087. * @param {Highcharts.Chart} chart
  5088. * @return {void}
  5089. */
  5090. RangeSelector.prototype.init = function (chart) {
  5091. var rangeSelector = this,
  5092. options = chart.options.rangeSelector,
  5093. buttonOptions = options.buttons || rangeSelector.defaultButtons.slice(),
  5094. selectedOption = options.selected,
  5095. blurInputs = function () {
  5096. var minInput = rangeSelector.minInput,
  5097. maxInput = rangeSelector.maxInput;
  5098. // #3274 in some case blur is not defined
  5099. if (minInput && minInput.blur) {
  5100. fireEvent(minInput, 'blur');
  5101. }
  5102. if (maxInput && maxInput.blur) {
  5103. fireEvent(maxInput, 'blur');
  5104. }
  5105. };
  5106. rangeSelector.chart = chart;
  5107. rangeSelector.options = options;
  5108. rangeSelector.buttons = [];
  5109. rangeSelector.buttonOptions = buttonOptions;
  5110. this.eventsToUnbind = [];
  5111. this.eventsToUnbind.push(addEvent(chart.container, 'mousedown', blurInputs));
  5112. this.eventsToUnbind.push(addEvent(chart, 'resize', blurInputs));
  5113. // Extend the buttonOptions with actual range
  5114. buttonOptions.forEach(rangeSelector.computeButtonRange);
  5115. // zoomed range based on a pre-selected button index
  5116. if (typeof selectedOption !== 'undefined' &&
  5117. buttonOptions[selectedOption]) {
  5118. this.clickButton(selectedOption, false);
  5119. }
  5120. this.eventsToUnbind.push(addEvent(chart, 'load', function () {
  5121. // If a data grouping is applied to the current button, release it
  5122. // when extremes change
  5123. if (chart.xAxis && chart.xAxis[0]) {
  5124. addEvent(chart.xAxis[0], 'setExtremes', function (e) {
  5125. if (this.max - this.min !==
  5126. chart.fixedRange &&
  5127. e.trigger !== 'rangeSelectorButton' &&
  5128. e.trigger !== 'updatedData' &&
  5129. rangeSelector.forcedDataGrouping &&
  5130. !rangeSelector.frozenStates) {
  5131. this.setDataGrouping(false, false);
  5132. }
  5133. });
  5134. }
  5135. }));
  5136. };
  5137. /**
  5138. * Dynamically update the range selector buttons after a new range has been
  5139. * set
  5140. *
  5141. * @private
  5142. * @function Highcharts.RangeSelector#updateButtonStates
  5143. * @return {void}
  5144. */
  5145. RangeSelector.prototype.updateButtonStates = function () {
  5146. var rangeSelector = this,
  5147. chart = this.chart,
  5148. dropdown = this.dropdown,
  5149. baseAxis = chart.xAxis[0],
  5150. actualRange = Math.round(baseAxis.max - baseAxis.min),
  5151. hasNoData = !baseAxis.hasVisibleSeries,
  5152. day = 24 * 36e5, // A single day in milliseconds
  5153. unionExtremes = (chart.scroller &&
  5154. chart.scroller.getUnionExtremes()) || baseAxis,
  5155. dataMin = unionExtremes.dataMin,
  5156. dataMax = unionExtremes.dataMax,
  5157. ytdExtremes = rangeSelector.getYTDExtremes(dataMax,
  5158. dataMin,
  5159. chart.time.useUTC),
  5160. ytdMin = ytdExtremes.min,
  5161. ytdMax = ytdExtremes.max,
  5162. selected = rangeSelector.selected,
  5163. selectedExists = isNumber(selected),
  5164. allButtonsEnabled = rangeSelector.options.allButtonsEnabled,
  5165. buttons = rangeSelector.buttons;
  5166. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  5167. var range = rangeOptions._range,
  5168. type = rangeOptions.type,
  5169. count = rangeOptions.count || 1,
  5170. button = buttons[i],
  5171. state = 0,
  5172. disable,
  5173. select,
  5174. offsetRange = rangeOptions._offsetMax -
  5175. rangeOptions._offsetMin,
  5176. isSelected = i === selected,
  5177. // Disable buttons where the range exceeds what is allowed in
  5178. // the current view
  5179. isTooGreatRange = range >
  5180. dataMax - dataMin,
  5181. // Disable buttons where the range is smaller than the minimum
  5182. // range
  5183. isTooSmallRange = range < baseAxis.minRange,
  5184. // Do not select the YTD button if not explicitly told so
  5185. isYTDButNotSelected = false,
  5186. // Disable the All button if we're already showing all
  5187. isAllButAlreadyShowingAll = false,
  5188. isSameRange = range === actualRange;
  5189. // Months and years have a variable range so we check the extremes
  5190. if ((type === 'month' || type === 'year') &&
  5191. (actualRange + 36e5 >=
  5192. { month: 28, year: 365 }[type] * day * count - offsetRange) &&
  5193. (actualRange - 36e5 <=
  5194. { month: 31, year: 366 }[type] * day * count + offsetRange)) {
  5195. isSameRange = true;
  5196. }
  5197. else if (type === 'ytd') {
  5198. isSameRange = (ytdMax - ytdMin + offsetRange) === actualRange;
  5199. isYTDButNotSelected = !isSelected;
  5200. }
  5201. else if (type === 'all') {
  5202. isSameRange = (baseAxis.max - baseAxis.min >=
  5203. dataMax - dataMin);
  5204. isAllButAlreadyShowingAll = (!isSelected &&
  5205. selectedExists &&
  5206. isSameRange);
  5207. }
  5208. // The new zoom area happens to match the range for a button - mark
  5209. // it selected. This happens when scrolling across an ordinal gap.
  5210. // It can be seen in the intraday demos when selecting 1h and scroll
  5211. // across the night gap.
  5212. disable = (!allButtonsEnabled &&
  5213. (isTooGreatRange ||
  5214. isTooSmallRange ||
  5215. isAllButAlreadyShowingAll ||
  5216. hasNoData));
  5217. select = ((isSelected && isSameRange) ||
  5218. (isSameRange && !selectedExists && !isYTDButNotSelected) ||
  5219. (isSelected && rangeSelector.frozenStates));
  5220. if (disable) {
  5221. state = 3;
  5222. }
  5223. else if (select) {
  5224. selectedExists = true; // Only one button can be selected
  5225. state = 2;
  5226. }
  5227. // If state has changed, update the button
  5228. if (button.state !== state) {
  5229. button.setState(state);
  5230. if (dropdown) {
  5231. dropdown.options[i + 1].disabled = disable;
  5232. if (state === 2) {
  5233. dropdown.selectedIndex = i + 1;
  5234. }
  5235. }
  5236. // Reset (#9209)
  5237. if (state === 0 && selected === i) {
  5238. rangeSelector.setSelected();
  5239. }
  5240. }
  5241. });
  5242. };
  5243. /**
  5244. * Compute and cache the range for an individual button
  5245. *
  5246. * @private
  5247. * @function Highcharts.RangeSelector#computeButtonRange
  5248. * @param {Highcharts.RangeSelectorButtonsOptions} rangeOptions
  5249. * @return {void}
  5250. */
  5251. RangeSelector.prototype.computeButtonRange = function (rangeOptions) {
  5252. var type = rangeOptions.type,
  5253. count = rangeOptions.count || 1,
  5254. // these time intervals have a fixed number of milliseconds, as
  5255. // opposed to month, ytd and year
  5256. fixedTimes = {
  5257. millisecond: 1,
  5258. second: 1000,
  5259. minute: 60 * 1000,
  5260. hour: 3600 * 1000,
  5261. day: 24 * 3600 * 1000,
  5262. week: 7 * 24 * 3600 * 1000
  5263. };
  5264. // Store the range on the button object
  5265. if (fixedTimes[type]) {
  5266. rangeOptions._range = fixedTimes[type] * count;
  5267. }
  5268. else if (type === 'month' || type === 'year') {
  5269. rangeOptions._range = {
  5270. month: 30,
  5271. year: 365
  5272. }[type] * 24 * 36e5 * count;
  5273. }
  5274. rangeOptions._offsetMin = pick(rangeOptions.offsetMin, 0);
  5275. rangeOptions._offsetMax = pick(rangeOptions.offsetMax, 0);
  5276. rangeOptions._range +=
  5277. rangeOptions._offsetMax - rangeOptions._offsetMin;
  5278. };
  5279. /**
  5280. * Get the unix timestamp of a HTML input for the dates
  5281. *
  5282. * @private
  5283. * @function Highcharts.RangeSelector#getInputValue
  5284. * @param {string} name
  5285. * @return {number}
  5286. */
  5287. RangeSelector.prototype.getInputValue = function (name) {
  5288. var input = name === 'min' ? this.minInput : this.maxInput;
  5289. var options = this.chart.options.rangeSelector;
  5290. var time = this.chart.time;
  5291. if (input) {
  5292. return ((input.type === 'text' && options.inputDateParser) ||
  5293. this.defaultInputDateParser)(input.value, time.useUTC, time);
  5294. }
  5295. return 0;
  5296. };
  5297. /**
  5298. * Set the internal and displayed value of a HTML input for the dates
  5299. *
  5300. * @private
  5301. * @function Highcharts.RangeSelector#setInputValue
  5302. * @param {string} name
  5303. * @param {number} [inputTime]
  5304. * @return {void}
  5305. */
  5306. RangeSelector.prototype.setInputValue = function (name, inputTime) {
  5307. var options = this.options, time = this.chart.time, input = name === 'min' ? this.minInput : this.maxInput, dateBox = name === 'min' ? this.minDateBox : this.maxDateBox;
  5308. if (input) {
  5309. var hcTimeAttr = input.getAttribute('data-hc-time');
  5310. var updatedTime = defined(hcTimeAttr) ? Number(hcTimeAttr) : void 0;
  5311. if (defined(inputTime)) {
  5312. var previousTime = updatedTime;
  5313. if (defined(previousTime)) {
  5314. input.setAttribute('data-hc-time-previous', previousTime);
  5315. }
  5316. input.setAttribute('data-hc-time', inputTime);
  5317. updatedTime = inputTime;
  5318. }
  5319. input.value = time.dateFormat(this.inputTypeFormats[input.type] || options.inputEditDateFormat, updatedTime);
  5320. if (dateBox) {
  5321. dateBox.attr({
  5322. text: time.dateFormat(options.inputDateFormat, updatedTime)
  5323. });
  5324. }
  5325. }
  5326. };
  5327. /**
  5328. * Set the min and max value of a HTML input for the dates
  5329. *
  5330. * @private
  5331. * @function Highcharts.RangeSelector#setInputExtremes
  5332. * @param {string} name
  5333. * @param {number} min
  5334. * @param {number} max
  5335. * @return {void}
  5336. */
  5337. RangeSelector.prototype.setInputExtremes = function (name, min, max) {
  5338. var input = name === 'min' ? this.minInput : this.maxInput;
  5339. if (input) {
  5340. var format = this.inputTypeFormats[input.type];
  5341. var time = this.chart.time;
  5342. if (format) {
  5343. var newMin = time.dateFormat(format,
  5344. min);
  5345. if (input.min !== newMin) {
  5346. input.min = newMin;
  5347. }
  5348. var newMax = time.dateFormat(format,
  5349. max);
  5350. if (input.max !== newMax) {
  5351. input.max = newMax;
  5352. }
  5353. }
  5354. }
  5355. };
  5356. /**
  5357. * @private
  5358. * @function Highcharts.RangeSelector#showInput
  5359. * @param {string} name
  5360. * @return {void}
  5361. */
  5362. RangeSelector.prototype.showInput = function (name) {
  5363. var dateBox = name === 'min' ? this.minDateBox : this.maxDateBox;
  5364. var input = name === 'min' ? this.minInput : this.maxInput;
  5365. if (input && dateBox && this.inputGroup) {
  5366. var isTextInput = input.type === 'text';
  5367. var _a = this.inputGroup,
  5368. translateX = _a.translateX,
  5369. translateY = _a.translateY;
  5370. css(input, {
  5371. width: isTextInput ? ((dateBox.width - 2) + 'px') : 'auto',
  5372. height: isTextInput ? ((dateBox.height - 2) + 'px') : 'auto',
  5373. border: '2px solid silver'
  5374. });
  5375. if (isTextInput) {
  5376. css(input, {
  5377. left: (translateX + dateBox.x) + 'px',
  5378. top: translateY + 'px'
  5379. });
  5380. // Inputs of types date, time or datetime-local should be centered
  5381. // on top of the dateBox
  5382. }
  5383. else {
  5384. css(input, {
  5385. left: Math.min(Math.round(dateBox.x +
  5386. translateX -
  5387. (input.offsetWidth - dateBox.width) / 2), this.chart.chartWidth - input.offsetWidth) + 'px',
  5388. top: (translateY - (input.offsetHeight - dateBox.height) / 2) + 'px'
  5389. });
  5390. }
  5391. }
  5392. };
  5393. /**
  5394. * @private
  5395. * @function Highcharts.RangeSelector#hideInput
  5396. * @param {string} name
  5397. * @return {void}
  5398. */
  5399. RangeSelector.prototype.hideInput = function (name) {
  5400. var input = name === 'min' ? this.minInput : this.maxInput;
  5401. if (input) {
  5402. css(input, {
  5403. top: '-9999em',
  5404. border: 0,
  5405. width: '1px',
  5406. height: '1px'
  5407. });
  5408. }
  5409. };
  5410. /**
  5411. * @private
  5412. * @function Highcharts.RangeSelector#defaultInputDateParser
  5413. */
  5414. RangeSelector.prototype.defaultInputDateParser = function (inputDate, useUTC, time) {
  5415. var hasTimezone = function (str) {
  5416. return str.length > 6 &&
  5417. (str.lastIndexOf('-') === str.length - 6 ||
  5418. str.lastIndexOf('+') === str.length - 6);
  5419. };
  5420. var input = inputDate.split('/').join('-').split(' ').join('T');
  5421. if (input.indexOf('T') === -1) {
  5422. input += 'T00:00';
  5423. }
  5424. if (useUTC) {
  5425. input += 'Z';
  5426. }
  5427. else if (H.isSafari && !hasTimezone(input)) {
  5428. var offset = new Date(input).getTimezoneOffset() / 60;
  5429. input += offset <= 0 ? "+" + pad(-offset) + ":00" : "-" + pad(offset) + ":00";
  5430. }
  5431. var date = Date.parse(input);
  5432. // If the value isn't parsed directly to a value by the
  5433. // browser's Date.parse method, like YYYY-MM-DD in IE8, try
  5434. // parsing it a different way
  5435. if (!isNumber(date)) {
  5436. var parts = inputDate.split('-');
  5437. date = Date.UTC(pInt(parts[0]), pInt(parts[1]) - 1, pInt(parts[2]));
  5438. }
  5439. if (time && useUTC) {
  5440. date += time.getTimezoneOffset(date);
  5441. }
  5442. return date;
  5443. };
  5444. /**
  5445. * Draw either the 'from' or the 'to' HTML input box of the range selector
  5446. *
  5447. * @private
  5448. * @function Highcharts.RangeSelector#drawInput
  5449. * @param {string} name
  5450. * @return {RangeSelectorInputElements}
  5451. */
  5452. RangeSelector.prototype.drawInput = function (name) {
  5453. var _a = this,
  5454. chart = _a.chart,
  5455. div = _a.div,
  5456. inputGroup = _a.inputGroup;
  5457. var rangeSelector = this,
  5458. chartStyle = chart.renderer.style || {},
  5459. renderer = chart.renderer,
  5460. options = chart.options.rangeSelector,
  5461. lang = defaultOptions.lang,
  5462. isMin = name === 'min';
  5463. /**
  5464. * @private
  5465. */
  5466. function updateExtremes() {
  5467. var value = rangeSelector.getInputValue(name),
  5468. chartAxis = chart.xAxis[0],
  5469. dataAxis = chart.scroller && chart.scroller.xAxis ?
  5470. chart.scroller.xAxis :
  5471. chartAxis,
  5472. dataMin = dataAxis.dataMin,
  5473. dataMax = dataAxis.dataMax;
  5474. var maxInput = rangeSelector.maxInput,
  5475. minInput = rangeSelector.minInput;
  5476. if (value !== Number(input.getAttribute('data-hc-time-previous')) &&
  5477. isNumber(value)) {
  5478. input.setAttribute('data-hc-time-previous', value);
  5479. // Validate the extremes. If it goes beyound the data min or
  5480. // max, use the actual data extreme (#2438).
  5481. if (isMin && maxInput && isNumber(dataMin)) {
  5482. if (value > Number(maxInput.getAttribute('data-hc-time'))) {
  5483. value = void 0;
  5484. }
  5485. else if (value < dataMin) {
  5486. value = dataMin;
  5487. }
  5488. }
  5489. else if (minInput && isNumber(dataMax)) {
  5490. if (value < Number(minInput.getAttribute('data-hc-time'))) {
  5491. value = void 0;
  5492. }
  5493. else if (value > dataMax) {
  5494. value = dataMax;
  5495. }
  5496. }
  5497. // Set the extremes
  5498. if (typeof value !== 'undefined') { // @todo typof undefined
  5499. chartAxis.setExtremes(isMin ? value : chartAxis.min, isMin ? chartAxis.max : value, void 0, void 0, { trigger: 'rangeSelectorInput' });
  5500. }
  5501. }
  5502. }
  5503. // Create the text label
  5504. var text = lang[isMin ? 'rangeSelectorFrom' : 'rangeSelectorTo'];
  5505. var label = renderer
  5506. .label(text, 0)
  5507. .addClass('highcharts-range-label')
  5508. .attr({
  5509. padding: text ? 2 : 0
  5510. })
  5511. .add(inputGroup);
  5512. // Create an SVG label that shows updated date ranges and and records
  5513. // click events that bring in the HTML input.
  5514. var dateBox = renderer
  5515. .label('', 0)
  5516. .addClass('highcharts-range-input')
  5517. .attr({
  5518. padding: 2,
  5519. width: options.inputBoxWidth,
  5520. height: options.inputBoxHeight,
  5521. 'text-align': 'center'
  5522. })
  5523. .on('click',
  5524. function () {
  5525. // If it is already focused, the onfocus event doesn't fire
  5526. // (#3713)
  5527. rangeSelector.showInput(name);
  5528. rangeSelector[name + 'Input'].focus();
  5529. });
  5530. if (!chart.styledMode) {
  5531. dateBox.attr({
  5532. stroke: options.inputBoxBorderColor,
  5533. 'stroke-width': 1
  5534. });
  5535. }
  5536. dateBox.add(inputGroup);
  5537. // Create the HTML input element. This is rendered as 1x1 pixel then set
  5538. // to the right size when focused.
  5539. var input = createElement('input', {
  5540. name: name,
  5541. className: 'highcharts-range-selector'
  5542. },
  5543. void 0,
  5544. div);
  5545. // #14788: Setting input.type to an unsupported type throws in IE, so
  5546. // we need to use setAttribute instead
  5547. input.setAttribute('type', preferredInputType(options.inputDateFormat || '%b %e, %Y'));
  5548. if (!chart.styledMode) {
  5549. // Styles
  5550. label.css(merge(chartStyle, options.labelStyle));
  5551. dateBox.css(merge({
  5552. color: palette.neutralColor80
  5553. }, chartStyle, options.inputStyle));
  5554. css(input, extend({
  5555. position: 'absolute',
  5556. border: 0,
  5557. boxShadow: '0 0 15px rgba(0,0,0,0.3)',
  5558. width: '1px',
  5559. height: '1px',
  5560. padding: 0,
  5561. textAlign: 'center',
  5562. fontSize: chartStyle.fontSize,
  5563. fontFamily: chartStyle.fontFamily,
  5564. top: '-9999em' // #4798
  5565. }, options.inputStyle));
  5566. }
  5567. // Blow up the input box
  5568. input.onfocus = function () {
  5569. rangeSelector.showInput(name);
  5570. };
  5571. // Hide away the input box
  5572. input.onblur = function () {
  5573. // update extermes only when inputs are active
  5574. if (input === H.doc.activeElement) { // Only when focused
  5575. // Update also when no `change` event is triggered, like when
  5576. // clicking inside the SVG (#4710)
  5577. updateExtremes();
  5578. }
  5579. // #10404 - move hide and blur outside focus
  5580. rangeSelector.hideInput(name);
  5581. rangeSelector.setInputValue(name);
  5582. input.blur(); // #4606
  5583. };
  5584. var keyDown = false;
  5585. // handle changes in the input boxes
  5586. input.onchange = function () {
  5587. updateExtremes();
  5588. // Blur input when clicking date input calendar
  5589. if (!keyDown) {
  5590. rangeSelector.hideInput(name);
  5591. input.blur();
  5592. }
  5593. };
  5594. input.onkeypress = function (event) {
  5595. // IE does not fire onchange on enter
  5596. if (event.keyCode === 13) {
  5597. updateExtremes();
  5598. }
  5599. };
  5600. input.onkeydown = function () {
  5601. keyDown = true;
  5602. };
  5603. input.onkeyup = function () {
  5604. keyDown = false;
  5605. };
  5606. return { dateBox: dateBox, input: input, label: label };
  5607. };
  5608. /**
  5609. * Get the position of the range selector buttons and inputs. This can be
  5610. * overridden from outside for custom positioning.
  5611. *
  5612. * @private
  5613. * @function Highcharts.RangeSelector#getPosition
  5614. *
  5615. * @return {Highcharts.Dictionary<number>}
  5616. */
  5617. RangeSelector.prototype.getPosition = function () {
  5618. var chart = this.chart,
  5619. options = chart.options.rangeSelector,
  5620. top = options.verticalAlign === 'top' ?
  5621. chart.plotTop - chart.axisOffset[0] :
  5622. 0; // set offset only for varticalAlign top
  5623. return {
  5624. buttonTop: top + options.buttonPosition.y,
  5625. inputTop: top + options.inputPosition.y - 10
  5626. };
  5627. };
  5628. /**
  5629. * Get the extremes of YTD. Will choose dataMax if its value is lower than
  5630. * the current timestamp. Will choose dataMin if its value is higher than
  5631. * the timestamp for the start of current year.
  5632. *
  5633. * @private
  5634. * @function Highcharts.RangeSelector#getYTDExtremes
  5635. *
  5636. * @param {number} dataMax
  5637. *
  5638. * @param {number} dataMin
  5639. *
  5640. * @return {*}
  5641. * Returns min and max for the YTD
  5642. */
  5643. RangeSelector.prototype.getYTDExtremes = function (dataMax, dataMin, useUTC) {
  5644. var time = this.chart.time,
  5645. min,
  5646. now = new time.Date(dataMax),
  5647. year = time.get('FullYear',
  5648. now),
  5649. startOfYear = useUTC ?
  5650. time.Date.UTC(year, 0, 1) : // eslint-disable-line new-cap
  5651. +new time.Date(year, 0, 1);
  5652. min = Math.max(dataMin, startOfYear);
  5653. var ts = now.getTime();
  5654. return {
  5655. max: Math.min(dataMax || ts, ts),
  5656. min: min
  5657. };
  5658. };
  5659. /**
  5660. * Render the range selector including the buttons and the inputs. The first
  5661. * time render is called, the elements are created and positioned. On
  5662. * subsequent calls, they are moved and updated.
  5663. *
  5664. * @private
  5665. * @function Highcharts.RangeSelector#render
  5666. * @param {number} [min]
  5667. * X axis minimum
  5668. * @param {number} [max]
  5669. * X axis maximum
  5670. * @return {void}
  5671. */
  5672. RangeSelector.prototype.render = function (min, max) {
  5673. var chart = this.chart,
  5674. renderer = chart.renderer,
  5675. container = chart.container,
  5676. chartOptions = chart.options,
  5677. options = chartOptions.rangeSelector,
  5678. // Place inputs above the container
  5679. inputsZIndex = pick(chartOptions.chart.style &&
  5680. chartOptions.chart.style.zIndex, 0) + 1,
  5681. inputEnabled = options.inputEnabled,
  5682. rendered = this.rendered;
  5683. if (options.enabled === false) {
  5684. return;
  5685. }
  5686. // create the elements
  5687. if (!rendered) {
  5688. this.group = renderer.g('range-selector-group')
  5689. .attr({
  5690. zIndex: 7
  5691. })
  5692. .add();
  5693. this.div = createElement('div', void 0, {
  5694. position: 'relative',
  5695. height: 0,
  5696. zIndex: inputsZIndex
  5697. });
  5698. if (this.buttonOptions.length) {
  5699. this.renderButtons();
  5700. }
  5701. // First create a wrapper outside the container in order to make
  5702. // the inputs work and make export correct
  5703. if (container.parentNode) {
  5704. container.parentNode.insertBefore(this.div, container);
  5705. }
  5706. if (inputEnabled) {
  5707. // Create the group to keep the inputs
  5708. this.inputGroup = renderer.g('input-group').add(this.group);
  5709. var minElems = this.drawInput('min');
  5710. this.minDateBox = minElems.dateBox;
  5711. this.minLabel = minElems.label;
  5712. this.minInput = minElems.input;
  5713. var maxElems = this.drawInput('max');
  5714. this.maxDateBox = maxElems.dateBox;
  5715. this.maxLabel = maxElems.label;
  5716. this.maxInput = maxElems.input;
  5717. }
  5718. }
  5719. if (inputEnabled) {
  5720. // Set or reset the input values
  5721. this.setInputValue('min', min);
  5722. this.setInputValue('max', max);
  5723. var unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || chart.xAxis[0] || {};
  5724. if (defined(unionExtremes.dataMin) && defined(unionExtremes.dataMax)) {
  5725. var minRange = chart.xAxis[0].minRange || 0;
  5726. this.setInputExtremes('min', unionExtremes.dataMin, Math.min(unionExtremes.dataMax, this.getInputValue('max')) - minRange);
  5727. this.setInputExtremes('max', Math.max(unionExtremes.dataMin, this.getInputValue('min')) + minRange, unionExtremes.dataMax);
  5728. }
  5729. // Reflow
  5730. if (this.inputGroup) {
  5731. var x_1 = 0;
  5732. [
  5733. this.minLabel,
  5734. this.minDateBox,
  5735. this.maxLabel,
  5736. this.maxDateBox
  5737. ].forEach(function (label) {
  5738. if (label && label.width) {
  5739. label.attr({ x: x_1 });
  5740. x_1 += label.width + options.inputSpacing;
  5741. }
  5742. });
  5743. }
  5744. }
  5745. this.alignElements();
  5746. this.rendered = true;
  5747. };
  5748. /**
  5749. * Render the range buttons. This only runs the first time, later the
  5750. * positioning is laid out in alignElements.
  5751. *
  5752. * @private
  5753. * @function Highcharts.RangeSelector#renderButtons
  5754. * @return {void}
  5755. */
  5756. RangeSelector.prototype.renderButtons = function () {
  5757. var _this = this;
  5758. var _a = this,
  5759. buttons = _a.buttons,
  5760. chart = _a.chart,
  5761. options = _a.options;
  5762. var lang = defaultOptions.lang;
  5763. var renderer = chart.renderer;
  5764. var buttonTheme = merge(options.buttonTheme);
  5765. var states = buttonTheme && buttonTheme.states;
  5766. // Prevent the button from resetting the width when the button state
  5767. // changes since we need more control over the width when collapsing
  5768. // the buttons
  5769. var width = buttonTheme.width || 28;
  5770. delete buttonTheme.width;
  5771. this.buttonGroup = renderer.g('range-selector-buttons').add(this.group);
  5772. var dropdown = this.dropdown = createElement('select',
  5773. void 0, {
  5774. position: 'absolute',
  5775. width: '1px',
  5776. height: '1px',
  5777. padding: 0,
  5778. border: 0,
  5779. top: '-9999em',
  5780. cursor: 'pointer',
  5781. opacity: 0.0001
  5782. },
  5783. this.div);
  5784. // Prevent page zoom on iPhone
  5785. addEvent(dropdown, 'touchstart', function () {
  5786. dropdown.style.fontSize = '16px';
  5787. });
  5788. // Forward events from select to button
  5789. [
  5790. [H.isMS ? 'mouseover' : 'mouseenter'],
  5791. [H.isMS ? 'mouseout' : 'mouseleave'],
  5792. ['change', 'click']
  5793. ].forEach(function (_a) {
  5794. var from = _a[0],
  5795. to = _a[1];
  5796. addEvent(dropdown, from, function () {
  5797. var button = buttons[_this.currentButtonIndex()];
  5798. if (button) {
  5799. fireEvent(button.element, to || from);
  5800. }
  5801. });
  5802. });
  5803. this.zoomText = renderer
  5804. .text(lang.rangeSelectorZoom, 0, 15)
  5805. .add(this.buttonGroup);
  5806. if (!this.chart.styledMode) {
  5807. this.zoomText.css(options.labelStyle);
  5808. buttonTheme['stroke-width'] = pick(buttonTheme['stroke-width'], 0);
  5809. }
  5810. createElement('option', {
  5811. textContent: this.zoomText.textStr,
  5812. disabled: true
  5813. }, void 0, dropdown);
  5814. this.buttonOptions.forEach(function (rangeOptions, i) {
  5815. createElement('option', {
  5816. textContent: rangeOptions.title || rangeOptions.text
  5817. }, void 0, dropdown);
  5818. buttons[i] = renderer
  5819. .button(rangeOptions.text, 0, 0, function (e) {
  5820. // extract events from button object and call
  5821. var buttonEvents = (rangeOptions.events &&
  5822. rangeOptions.events.click),
  5823. callDefaultEvent;
  5824. if (buttonEvents) {
  5825. callDefaultEvent =
  5826. buttonEvents.call(rangeOptions, e);
  5827. }
  5828. if (callDefaultEvent !== false) {
  5829. _this.clickButton(i);
  5830. }
  5831. _this.isActive = true;
  5832. }, buttonTheme, states && states.hover, states && states.select, states && states.disabled)
  5833. .attr({
  5834. 'text-align': 'center',
  5835. width: width
  5836. })
  5837. .add(_this.buttonGroup);
  5838. if (rangeOptions.title) {
  5839. buttons[i].attr('title', rangeOptions.title);
  5840. }
  5841. });
  5842. };
  5843. /**
  5844. * Align the elements horizontally and vertically.
  5845. *
  5846. * @private
  5847. * @function Highcharts.RangeSelector#alignElements
  5848. * @return {void}
  5849. */
  5850. RangeSelector.prototype.alignElements = function () {
  5851. var _this = this;
  5852. var _a = this,
  5853. buttonGroup = _a.buttonGroup,
  5854. buttons = _a.buttons,
  5855. chart = _a.chart,
  5856. group = _a.group,
  5857. inputGroup = _a.inputGroup,
  5858. options = _a.options,
  5859. zoomText = _a.zoomText;
  5860. var chartOptions = chart.options;
  5861. var navButtonOptions = (chartOptions.exporting &&
  5862. chartOptions.exporting.enabled !== false &&
  5863. chartOptions.navigation &&
  5864. chartOptions.navigation.buttonOptions);
  5865. var buttonPosition = options.buttonPosition,
  5866. inputPosition = options.inputPosition,
  5867. verticalAlign = options.verticalAlign;
  5868. // Get the X offset required to avoid overlapping with the exporting
  5869. // button. This is is used both by the buttonGroup and the inputGroup.
  5870. var getXOffsetForExportButton = function (group,
  5871. position) {
  5872. if (navButtonOptions &&
  5873. _this.titleCollision(chart) &&
  5874. verticalAlign === 'top' &&
  5875. position.align === 'right' && ((position.y -
  5876. group.getBBox().height - 12) <
  5877. ((navButtonOptions.y || 0) +
  5878. (navButtonOptions.height || 0) +
  5879. chart.spacing[0]))) {
  5880. return -40;
  5881. }
  5882. return 0;
  5883. };
  5884. var plotLeft = chart.plotLeft;
  5885. if (group && buttonPosition && inputPosition) {
  5886. var translateX = buttonPosition.x - chart.spacing[3];
  5887. if (buttonGroup) {
  5888. this.positionButtons();
  5889. if (!this.initialButtonGroupWidth) {
  5890. var width_1 = 0;
  5891. if (zoomText) {
  5892. width_1 += zoomText.getBBox().width + 5;
  5893. }
  5894. buttons.forEach(function (button, i) {
  5895. width_1 += button.width;
  5896. if (i !== buttons.length - 1) {
  5897. width_1 += options.buttonSpacing;
  5898. }
  5899. });
  5900. this.initialButtonGroupWidth = width_1;
  5901. }
  5902. plotLeft -= chart.spacing[3];
  5903. this.updateButtonStates();
  5904. // Detect collision between button group and exporting
  5905. var xOffsetForExportButton_1 = getXOffsetForExportButton(buttonGroup,
  5906. buttonPosition);
  5907. this.alignButtonGroup(xOffsetForExportButton_1);
  5908. // Skip animation
  5909. group.placed = buttonGroup.placed = chart.hasLoaded;
  5910. }
  5911. var xOffsetForExportButton = 0;
  5912. if (inputGroup) {
  5913. // Detect collision between the input group and exporting button
  5914. xOffsetForExportButton = getXOffsetForExportButton(inputGroup, inputPosition);
  5915. if (inputPosition.align === 'left') {
  5916. translateX = plotLeft;
  5917. }
  5918. else if (inputPosition.align === 'right') {
  5919. translateX = -Math.max(chart.axisOffset[1], -xOffsetForExportButton);
  5920. }
  5921. // Update the alignment to the updated spacing box
  5922. inputGroup.align({
  5923. y: inputPosition.y,
  5924. width: inputGroup.getBBox().width,
  5925. align: inputPosition.align,
  5926. // fix wrong getBBox() value on right align
  5927. x: inputPosition.x + translateX - 2
  5928. }, true, chart.spacingBox);
  5929. // Skip animation
  5930. inputGroup.placed = chart.hasLoaded;
  5931. }
  5932. this.handleCollision(xOffsetForExportButton);
  5933. // Vertical align
  5934. group.align({
  5935. verticalAlign: verticalAlign
  5936. }, true, chart.spacingBox);
  5937. var alignTranslateY = group.alignAttr.translateY;
  5938. // Set position
  5939. var groupHeight = group.getBBox().height + 20; // # 20 padding
  5940. var translateY = 0;
  5941. // Calculate bottom position
  5942. if (verticalAlign === 'bottom') {
  5943. var legendOptions = chart.legend && chart.legend.options;
  5944. var legendHeight = (legendOptions &&
  5945. legendOptions.verticalAlign === 'bottom' &&
  5946. legendOptions.enabled &&
  5947. !legendOptions.floating ?
  5948. (chart.legend.legendHeight +
  5949. pick(legendOptions.margin, 10)) :
  5950. 0);
  5951. groupHeight = groupHeight + legendHeight - 20;
  5952. translateY = (alignTranslateY -
  5953. groupHeight -
  5954. (options.floating ? 0 : options.y) -
  5955. (chart.titleOffset ? chart.titleOffset[2] : 0) -
  5956. 10 // 10 spacing
  5957. );
  5958. }
  5959. if (verticalAlign === 'top') {
  5960. if (options.floating) {
  5961. translateY = 0;
  5962. }
  5963. if (chart.titleOffset && chart.titleOffset[0]) {
  5964. translateY = chart.titleOffset[0];
  5965. }
  5966. translateY += ((chart.margin[0] - chart.spacing[0]) || 0);
  5967. }
  5968. else if (verticalAlign === 'middle') {
  5969. if (inputPosition.y === buttonPosition.y) {
  5970. translateY = alignTranslateY;
  5971. }
  5972. else if (inputPosition.y || buttonPosition.y) {
  5973. if (inputPosition.y < 0 ||
  5974. buttonPosition.y < 0) {
  5975. translateY -= Math.min(inputPosition.y, buttonPosition.y);
  5976. }
  5977. else {
  5978. translateY = alignTranslateY - groupHeight;
  5979. }
  5980. }
  5981. }
  5982. group.translate(options.x, options.y + Math.floor(translateY));
  5983. // Translate HTML inputs
  5984. var _b = this,
  5985. minInput = _b.minInput,
  5986. maxInput = _b.maxInput,
  5987. dropdown = _b.dropdown;
  5988. if (options.inputEnabled && minInput && maxInput) {
  5989. minInput.style.marginTop = group.translateY + 'px';
  5990. maxInput.style.marginTop = group.translateY + 'px';
  5991. }
  5992. if (dropdown) {
  5993. dropdown.style.marginTop = group.translateY + 'px';
  5994. }
  5995. }
  5996. };
  5997. /**
  5998. * Align the button group horizontally and vertically.
  5999. *
  6000. * @private
  6001. * @function Highcharts.RangeSelector#alignButtonGroup
  6002. * @param {number} xOffsetForExportButton
  6003. * @param {number} [width]
  6004. * @return {void}
  6005. */
  6006. RangeSelector.prototype.alignButtonGroup = function (xOffsetForExportButton, width) {
  6007. var _a = this,
  6008. chart = _a.chart,
  6009. options = _a.options,
  6010. buttonGroup = _a.buttonGroup,
  6011. buttons = _a.buttons;
  6012. var buttonPosition = options.buttonPosition;
  6013. var plotLeft = chart.plotLeft - chart.spacing[3];
  6014. var translateX = buttonPosition.x - chart.spacing[3];
  6015. if (buttonPosition.align === 'right') {
  6016. translateX += xOffsetForExportButton - plotLeft; // #13014
  6017. }
  6018. else if (buttonPosition.align === 'center') {
  6019. translateX -= plotLeft / 2;
  6020. }
  6021. if (buttonGroup) {
  6022. // Align button group
  6023. buttonGroup.align({
  6024. y: buttonPosition.y,
  6025. width: pick(width, this.initialButtonGroupWidth),
  6026. align: buttonPosition.align,
  6027. x: translateX
  6028. }, true, chart.spacingBox);
  6029. }
  6030. };
  6031. /**
  6032. * @private
  6033. * @function Highcharts.RangeSelector#positionButtons
  6034. * @return {void}
  6035. */
  6036. RangeSelector.prototype.positionButtons = function () {
  6037. var _a = this,
  6038. buttons = _a.buttons,
  6039. chart = _a.chart,
  6040. options = _a.options,
  6041. zoomText = _a.zoomText;
  6042. var verb = chart.hasLoaded ? 'animate' : 'attr';
  6043. var buttonPosition = options.buttonPosition;
  6044. var plotLeft = chart.plotLeft;
  6045. var buttonLeft = plotLeft;
  6046. if (zoomText && zoomText.visibility !== 'hidden') {
  6047. // #8769, allow dynamically updating margins
  6048. zoomText[verb]({
  6049. x: pick(plotLeft + buttonPosition.x, plotLeft)
  6050. });
  6051. // Button start position
  6052. buttonLeft += buttonPosition.x +
  6053. zoomText.getBBox().width + 5;
  6054. }
  6055. this.buttonOptions.forEach(function (rangeOptions, i) {
  6056. if (buttons[i].visibility !== 'hidden') {
  6057. buttons[i][verb]({ x: buttonLeft });
  6058. // increase button position for the next button
  6059. buttonLeft += buttons[i].width + options.buttonSpacing;
  6060. }
  6061. else {
  6062. buttons[i][verb]({ x: plotLeft });
  6063. }
  6064. });
  6065. };
  6066. /**
  6067. * Handle collision between the button group and the input group
  6068. *
  6069. * @private
  6070. * @function Highcharts.RangeSelector#handleCollision
  6071. *
  6072. * @param {number} xOffsetForExportButton
  6073. * The X offset of the group required to make room for the
  6074. * exporting button
  6075. * @return {void}
  6076. */
  6077. RangeSelector.prototype.handleCollision = function (xOffsetForExportButton) {
  6078. var _this = this;
  6079. var _a = this,
  6080. chart = _a.chart,
  6081. buttonGroup = _a.buttonGroup,
  6082. inputGroup = _a.inputGroup;
  6083. var _b = this.options,
  6084. buttonPosition = _b.buttonPosition,
  6085. dropdown = _b.dropdown,
  6086. inputPosition = _b.inputPosition;
  6087. var maxButtonWidth = function () {
  6088. var buttonWidth = 0;
  6089. _this.buttons.forEach(function (button) {
  6090. var bBox = button.getBBox();
  6091. if (bBox.width > buttonWidth) {
  6092. buttonWidth = bBox.width;
  6093. }
  6094. });
  6095. return buttonWidth;
  6096. };
  6097. var groupsOverlap = function (buttonGroupWidth) {
  6098. if (inputGroup && buttonGroup) {
  6099. var inputGroupX = (inputGroup.alignAttr.translateX +
  6100. inputGroup.alignOptions.x -
  6101. xOffsetForExportButton +
  6102. // getBBox for detecing left margin
  6103. inputGroup.getBBox().x +
  6104. // 2px padding to not overlap input and label
  6105. 2);
  6106. var inputGroupWidth = inputGroup.alignOptions.width;
  6107. var buttonGroupX = buttonGroup.alignAttr.translateX +
  6108. buttonGroup.getBBox().x;
  6109. return (buttonGroupX + buttonGroupWidth > inputGroupX) &&
  6110. (inputGroupX + inputGroupWidth > buttonGroupX) &&
  6111. (buttonPosition.y <
  6112. (inputPosition.y +
  6113. inputGroup.getBBox().height));
  6114. }
  6115. return false;
  6116. };
  6117. var moveInputsDown = function () {
  6118. if (inputGroup && buttonGroup) {
  6119. inputGroup.attr({
  6120. translateX: inputGroup.alignAttr.translateX + (chart.axisOffset[1] >= -xOffsetForExportButton ?
  6121. 0 :
  6122. -xOffsetForExportButton),
  6123. translateY: inputGroup.alignAttr.translateY +
  6124. buttonGroup.getBBox().height + 10
  6125. });
  6126. }
  6127. };
  6128. if (buttonGroup) {
  6129. if (dropdown === 'always') {
  6130. this.collapseButtons(xOffsetForExportButton);
  6131. if (groupsOverlap(maxButtonWidth())) {
  6132. // Move the inputs down if there is still a collision
  6133. // after collapsing the buttons
  6134. moveInputsDown();
  6135. }
  6136. return;
  6137. }
  6138. if (dropdown === 'never') {
  6139. this.expandButtons();
  6140. }
  6141. }
  6142. // Detect collision
  6143. if (inputGroup && buttonGroup) {
  6144. if ((inputPosition.align === buttonPosition.align) ||
  6145. // 20 is minimal spacing between elements
  6146. groupsOverlap(this.initialButtonGroupWidth + 20)) {
  6147. if (dropdown === 'responsive') {
  6148. this.collapseButtons(xOffsetForExportButton);
  6149. if (groupsOverlap(maxButtonWidth())) {
  6150. moveInputsDown();
  6151. }
  6152. }
  6153. else {
  6154. moveInputsDown();
  6155. }
  6156. }
  6157. else if (dropdown === 'responsive') {
  6158. this.expandButtons();
  6159. }
  6160. }
  6161. else if (buttonGroup && dropdown === 'responsive') {
  6162. if (this.initialButtonGroupWidth > chart.plotWidth) {
  6163. this.collapseButtons(xOffsetForExportButton);
  6164. }
  6165. else {
  6166. this.expandButtons();
  6167. }
  6168. }
  6169. };
  6170. /**
  6171. * Collapse the buttons and put the select element on top.
  6172. *
  6173. * @private
  6174. * @function Highcharts.RangeSelector#collapseButtons
  6175. * @param {number} xOffsetForExportButton
  6176. * @return {void}
  6177. */
  6178. RangeSelector.prototype.collapseButtons = function (xOffsetForExportButton) {
  6179. var _a;
  6180. var _b = this,
  6181. buttons = _b.buttons,
  6182. buttonOptions = _b.buttonOptions,
  6183. dropdown = _b.dropdown,
  6184. options = _b.options,
  6185. zoomText = _b.zoomText;
  6186. var getAttribs = function (text) { return ({
  6187. text: text ? text + " \u25BE" : '▾',
  6188. width: 'auto',
  6189. paddingLeft: 8,
  6190. paddingRight: 8
  6191. }); };
  6192. if (zoomText) {
  6193. zoomText.hide();
  6194. }
  6195. var hasActiveButton = false;
  6196. buttonOptions.forEach(function (rangeOptions, i) {
  6197. var button = buttons[i];
  6198. if (button.state !== 2) {
  6199. button.hide();
  6200. }
  6201. else {
  6202. button.show();
  6203. button.attr(getAttribs(rangeOptions.text));
  6204. hasActiveButton = true;
  6205. }
  6206. });
  6207. if (!hasActiveButton) {
  6208. if (dropdown) {
  6209. dropdown.selectedIndex = 0;
  6210. }
  6211. buttons[0].show();
  6212. buttons[0].attr(getAttribs((_a = this.zoomText) === null || _a === void 0 ? void 0 : _a.textStr));
  6213. }
  6214. var align = options.buttonPosition.align;
  6215. this.positionButtons();
  6216. if (align === 'right' || align === 'center') {
  6217. this.alignButtonGroup(xOffsetForExportButton, buttons[this.currentButtonIndex()].getBBox().width);
  6218. }
  6219. this.showDropdown();
  6220. };
  6221. /**
  6222. * Show all the buttons and hide the select element.
  6223. *
  6224. * @private
  6225. * @function Highcharts.RangeSelector#expandButtons
  6226. * @return {void}
  6227. */
  6228. RangeSelector.prototype.expandButtons = function () {
  6229. var _a = this,
  6230. buttons = _a.buttons,
  6231. buttonOptions = _a.buttonOptions,
  6232. options = _a.options,
  6233. zoomText = _a.zoomText;
  6234. this.hideDropdown();
  6235. if (zoomText) {
  6236. zoomText.show();
  6237. }
  6238. buttonOptions.forEach(function (rangeOptions, i) {
  6239. var button = buttons[i];
  6240. button.show();
  6241. button.attr({
  6242. text: rangeOptions.text,
  6243. width: options.buttonTheme.width || 28,
  6244. paddingLeft: 'unset',
  6245. paddingRight: 'unset'
  6246. });
  6247. if (button.state < 2) {
  6248. button.setState(0);
  6249. }
  6250. });
  6251. this.positionButtons();
  6252. };
  6253. /**
  6254. * Get the index of the visible button when the buttons are collapsed.
  6255. *
  6256. * @private
  6257. * @function Highcharts.RangeSelector#currentButtonIndex
  6258. * @return {number}
  6259. */
  6260. RangeSelector.prototype.currentButtonIndex = function () {
  6261. var dropdown = this.dropdown;
  6262. if (dropdown && dropdown.selectedIndex > 0) {
  6263. return dropdown.selectedIndex - 1;
  6264. }
  6265. return 0;
  6266. };
  6267. /**
  6268. * Position the select element on top of the button.
  6269. *
  6270. * @private
  6271. * @function Highcharts.RangeSelector#showDropdown
  6272. * @return {void}
  6273. */
  6274. RangeSelector.prototype.showDropdown = function () {
  6275. var _a = this,
  6276. buttonGroup = _a.buttonGroup,
  6277. buttons = _a.buttons,
  6278. chart = _a.chart,
  6279. dropdown = _a.dropdown;
  6280. if (buttonGroup && dropdown) {
  6281. var translateX = buttonGroup.translateX,
  6282. translateY = buttonGroup.translateY;
  6283. var bBox = buttons[this.currentButtonIndex()].getBBox();
  6284. css(dropdown, {
  6285. left: (chart.plotLeft + translateX) + 'px',
  6286. top: (translateY + 0.5) + 'px',
  6287. width: bBox.width + 'px',
  6288. height: bBox.height + 'px'
  6289. });
  6290. this.hasVisibleDropdown = true;
  6291. }
  6292. };
  6293. /**
  6294. * @private
  6295. * @function Highcharts.RangeSelector#hideDropdown
  6296. * @return {void}
  6297. */
  6298. RangeSelector.prototype.hideDropdown = function () {
  6299. var dropdown = this.dropdown;
  6300. if (dropdown) {
  6301. css(dropdown, {
  6302. top: '-9999em',
  6303. width: '1px',
  6304. height: '1px'
  6305. });
  6306. this.hasVisibleDropdown = false;
  6307. }
  6308. };
  6309. /**
  6310. * Extracts height of range selector
  6311. *
  6312. * @private
  6313. * @function Highcharts.RangeSelector#getHeight
  6314. * @return {number}
  6315. * Returns rangeSelector height
  6316. */
  6317. RangeSelector.prototype.getHeight = function () {
  6318. var rangeSelector = this,
  6319. options = rangeSelector.options,
  6320. rangeSelectorGroup = rangeSelector.group,
  6321. inputPosition = options.inputPosition,
  6322. buttonPosition = options.buttonPosition,
  6323. yPosition = options.y,
  6324. buttonPositionY = buttonPosition.y,
  6325. inputPositionY = inputPosition.y,
  6326. rangeSelectorHeight = 0,
  6327. minPosition;
  6328. if (options.height) {
  6329. return options.height;
  6330. }
  6331. // Align the elements before we read the height in case we're switching
  6332. // between wrapped and non-wrapped layout
  6333. this.alignElements();
  6334. rangeSelectorHeight = rangeSelectorGroup ?
  6335. // 13px to keep back compatibility
  6336. (rangeSelectorGroup.getBBox(true).height) + 13 +
  6337. yPosition :
  6338. 0;
  6339. minPosition = Math.min(inputPositionY, buttonPositionY);
  6340. if ((inputPositionY < 0 && buttonPositionY < 0) ||
  6341. (inputPositionY > 0 && buttonPositionY > 0)) {
  6342. rangeSelectorHeight += Math.abs(minPosition);
  6343. }
  6344. return rangeSelectorHeight;
  6345. };
  6346. /**
  6347. * Detect collision with title or subtitle
  6348. *
  6349. * @private
  6350. * @function Highcharts.RangeSelector#titleCollision
  6351. *
  6352. * @param {Highcharts.Chart} chart
  6353. *
  6354. * @return {boolean}
  6355. * Returns collision status
  6356. */
  6357. RangeSelector.prototype.titleCollision = function (chart) {
  6358. return !(chart.options.title.text ||
  6359. chart.options.subtitle.text);
  6360. };
  6361. /**
  6362. * Update the range selector with new options
  6363. *
  6364. * @private
  6365. * @function Highcharts.RangeSelector#update
  6366. * @param {Highcharts.RangeSelectorOptions} options
  6367. * @return {void}
  6368. */
  6369. RangeSelector.prototype.update = function (options) {
  6370. var chart = this.chart;
  6371. merge(true, chart.options.rangeSelector, options);
  6372. this.destroy();
  6373. this.init(chart);
  6374. this.render();
  6375. };
  6376. /**
  6377. * Destroys allocated elements.
  6378. *
  6379. * @private
  6380. * @function Highcharts.RangeSelector#destroy
  6381. */
  6382. RangeSelector.prototype.destroy = function () {
  6383. var rSelector = this,
  6384. minInput = rSelector.minInput,
  6385. maxInput = rSelector.maxInput;
  6386. if (rSelector.eventsToUnbind) {
  6387. rSelector.eventsToUnbind.forEach(function (unbind) { return unbind(); });
  6388. rSelector.eventsToUnbind = void 0;
  6389. }
  6390. // Destroy elements in collections
  6391. destroyObjectProperties(rSelector.buttons);
  6392. // Clear input element events
  6393. if (minInput) {
  6394. minInput.onfocus = minInput.onblur = minInput.onchange = null;
  6395. }
  6396. if (maxInput) {
  6397. maxInput.onfocus = maxInput.onblur = maxInput.onchange = null;
  6398. }
  6399. // Destroy HTML and SVG elements
  6400. objectEach(rSelector, function (val, key) {
  6401. if (val && key !== 'chart') {
  6402. if (val instanceof SVGElement) {
  6403. // SVGElement
  6404. val.destroy();
  6405. }
  6406. else if (val instanceof window.HTMLElement) {
  6407. // HTML element
  6408. discardElement(val);
  6409. }
  6410. }
  6411. if (val !== RangeSelector.prototype[key]) {
  6412. rSelector[key] = null;
  6413. }
  6414. }, this);
  6415. };
  6416. return RangeSelector;
  6417. }());
  6418. /**
  6419. * The default buttons for pre-selecting time frames
  6420. */
  6421. RangeSelector.prototype.defaultButtons = [{
  6422. type: 'month',
  6423. count: 1,
  6424. text: '1m',
  6425. title: 'View 1 month'
  6426. }, {
  6427. type: 'month',
  6428. count: 3,
  6429. text: '3m',
  6430. title: 'View 3 months'
  6431. }, {
  6432. type: 'month',
  6433. count: 6,
  6434. text: '6m',
  6435. title: 'View 6 months'
  6436. }, {
  6437. type: 'ytd',
  6438. text: 'YTD',
  6439. title: 'View year to date'
  6440. }, {
  6441. type: 'year',
  6442. count: 1,
  6443. text: '1y',
  6444. title: 'View 1 year'
  6445. }, {
  6446. type: 'all',
  6447. text: 'All',
  6448. title: 'View all'
  6449. }];
  6450. /**
  6451. * The date formats to use when setting min, max and value on date inputs
  6452. */
  6453. RangeSelector.prototype.inputTypeFormats = {
  6454. 'datetime-local': '%Y-%m-%dT%H:%M:%S',
  6455. 'date': '%Y-%m-%d',
  6456. 'time': '%H:%M:%S'
  6457. };
  6458. /**
  6459. * Get the preferred input type based on a date format string.
  6460. *
  6461. * @private
  6462. * @function preferredInputType
  6463. * @param {string} format
  6464. * @return {string}
  6465. */
  6466. function preferredInputType(format) {
  6467. var ms = format.indexOf('%L') !== -1;
  6468. if (ms) {
  6469. return 'text';
  6470. }
  6471. var date = ['a', 'A', 'd', 'e', 'w', 'b', 'B', 'm', 'o', 'y', 'Y'].some(function (char) {
  6472. return format.indexOf('%' + char) !== -1;
  6473. });
  6474. var time = ['H', 'k', 'I', 'l', 'M', 'S'].some(function (char) {
  6475. return format.indexOf('%' + char) !== -1;
  6476. });
  6477. if (date && time) {
  6478. return 'datetime-local';
  6479. }
  6480. if (date) {
  6481. return 'date';
  6482. }
  6483. if (time) {
  6484. return 'time';
  6485. }
  6486. return 'text';
  6487. }
  6488. /**
  6489. * Get the axis min value based on the range option and the current max. For
  6490. * stock charts this is extended via the {@link RangeSelector} so that if the
  6491. * selected range is a multiple of months or years, it is compensated for
  6492. * various month lengths.
  6493. *
  6494. * @private
  6495. * @function Highcharts.Axis#minFromRange
  6496. * @return {number|undefined}
  6497. * The new minimum value.
  6498. */
  6499. Axis.prototype.minFromRange = function () {
  6500. var rangeOptions = this.range,
  6501. type = rangeOptions.type,
  6502. min,
  6503. max = this.max,
  6504. dataMin,
  6505. range,
  6506. time = this.chart.time,
  6507. // Get the true range from a start date
  6508. getTrueRange = function (base,
  6509. count) {
  6510. var timeName = type === 'year' ? 'FullYear' : 'Month';
  6511. var date = new time.Date(base);
  6512. var basePeriod = time.get(timeName,
  6513. date);
  6514. time.set(timeName, date, basePeriod + count);
  6515. if (basePeriod === time.get(timeName, date)) {
  6516. time.set('Date', date, 0); // #6537
  6517. }
  6518. return date.getTime() - base;
  6519. };
  6520. if (isNumber(rangeOptions)) {
  6521. min = max - rangeOptions;
  6522. range = rangeOptions;
  6523. }
  6524. else {
  6525. min = max + getTrueRange(max, -rangeOptions.count);
  6526. // Let the fixedRange reflect initial settings (#5930)
  6527. if (this.chart) {
  6528. this.chart.fixedRange = max - min;
  6529. }
  6530. }
  6531. dataMin = pick(this.dataMin, Number.MIN_VALUE);
  6532. if (!isNumber(min)) {
  6533. min = dataMin;
  6534. }
  6535. if (min <= dataMin) {
  6536. min = dataMin;
  6537. if (typeof range === 'undefined') { // #4501
  6538. range = getTrueRange(min, rangeOptions.count);
  6539. }
  6540. this.newMax = Math.min(min + range, this.dataMax);
  6541. }
  6542. if (!isNumber(max)) {
  6543. min = void 0;
  6544. }
  6545. return min;
  6546. };
  6547. if (!H.RangeSelector) {
  6548. var chartDestroyEvents_1 = [];
  6549. var initRangeSelector_1 = function (chart) {
  6550. var extremes,
  6551. rangeSelector = chart.rangeSelector,
  6552. legend,
  6553. alignTo,
  6554. verticalAlign;
  6555. /**
  6556. * @private
  6557. */
  6558. function render() {
  6559. if (rangeSelector) {
  6560. extremes = chart.xAxis[0].getExtremes();
  6561. legend = chart.legend;
  6562. verticalAlign = rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.options.verticalAlign;
  6563. if (isNumber(extremes.min)) {
  6564. rangeSelector.render(extremes.min, extremes.max);
  6565. }
  6566. // Re-align the legend so that it's below the rangeselector
  6567. if (legend.display &&
  6568. verticalAlign === 'top' &&
  6569. verticalAlign === legend.options.verticalAlign) {
  6570. // Create a new alignment box for the legend.
  6571. alignTo = merge(chart.spacingBox);
  6572. if (legend.options.layout === 'vertical') {
  6573. alignTo.y = chart.plotTop;
  6574. }
  6575. else {
  6576. alignTo.y += rangeSelector.getHeight();
  6577. }
  6578. legend.group.placed = false; // Don't animate the alignment.
  6579. legend.align(alignTo);
  6580. }
  6581. }
  6582. }
  6583. if (rangeSelector) {
  6584. var events = find(chartDestroyEvents_1,
  6585. function (e) { return e[0] === chart; });
  6586. if (!events) {
  6587. chartDestroyEvents_1.push([chart, [
  6588. // redraw the scroller on setExtremes
  6589. addEvent(chart.xAxis[0], 'afterSetExtremes', function (e) {
  6590. if (rangeSelector) {
  6591. rangeSelector.render(e.min, e.max);
  6592. }
  6593. }),
  6594. // redraw the scroller chart resize
  6595. addEvent(chart, 'redraw', render)
  6596. ]]);
  6597. }
  6598. // do it now
  6599. render();
  6600. }
  6601. };
  6602. // Initialize rangeselector for stock charts
  6603. addEvent(Chart, 'afterGetContainer', function () {
  6604. var _a;
  6605. if ((_a = this.options.rangeSelector) === null || _a === void 0 ? void 0 : _a.enabled) {
  6606. this.rangeSelector = new RangeSelector(this);
  6607. }
  6608. });
  6609. addEvent(Chart, 'beforeRender', function () {
  6610. var chart = this,
  6611. axes = chart.axes,
  6612. rangeSelector = chart.rangeSelector,
  6613. verticalAlign;
  6614. if (rangeSelector) {
  6615. if (isNumber(rangeSelector.deferredYTDClick)) {
  6616. rangeSelector.clickButton(rangeSelector.deferredYTDClick);
  6617. delete rangeSelector.deferredYTDClick;
  6618. }
  6619. axes.forEach(function (axis) {
  6620. axis.updateNames();
  6621. axis.setScale();
  6622. });
  6623. chart.getAxisMargins();
  6624. rangeSelector.render();
  6625. verticalAlign = rangeSelector.options.verticalAlign;
  6626. if (!rangeSelector.options.floating) {
  6627. if (verticalAlign === 'bottom') {
  6628. this.extraBottomMargin = true;
  6629. }
  6630. else if (verticalAlign !== 'middle') {
  6631. this.extraTopMargin = true;
  6632. }
  6633. }
  6634. }
  6635. });
  6636. addEvent(Chart, 'update', function (e) {
  6637. var chart = this,
  6638. options = e.options,
  6639. optionsRangeSelector = options.rangeSelector,
  6640. rangeSelector = chart.rangeSelector,
  6641. verticalAlign,
  6642. extraBottomMarginWas = this.extraBottomMargin,
  6643. extraTopMarginWas = this.extraTopMargin;
  6644. if (optionsRangeSelector &&
  6645. optionsRangeSelector.enabled &&
  6646. !defined(rangeSelector) &&
  6647. this.options.rangeSelector) {
  6648. this.options.rangeSelector.enabled = true;
  6649. this.rangeSelector = rangeSelector = new RangeSelector(this);
  6650. }
  6651. this.extraBottomMargin = false;
  6652. this.extraTopMargin = false;
  6653. if (rangeSelector) {
  6654. initRangeSelector_1(this);
  6655. verticalAlign = (optionsRangeSelector &&
  6656. optionsRangeSelector.verticalAlign) || (rangeSelector.options && rangeSelector.options.verticalAlign);
  6657. if (!rangeSelector.options.floating) {
  6658. if (verticalAlign === 'bottom') {
  6659. this.extraBottomMargin = true;
  6660. }
  6661. else if (verticalAlign !== 'middle') {
  6662. this.extraTopMargin = true;
  6663. }
  6664. }
  6665. if (this.extraBottomMargin !== extraBottomMarginWas ||
  6666. this.extraTopMargin !== extraTopMarginWas) {
  6667. this.isDirtyBox = true;
  6668. }
  6669. }
  6670. });
  6671. addEvent(Chart, 'render', function () {
  6672. var chart = this,
  6673. rangeSelector = chart.rangeSelector,
  6674. verticalAlign;
  6675. if (rangeSelector && !rangeSelector.options.floating) {
  6676. rangeSelector.render();
  6677. verticalAlign = rangeSelector.options.verticalAlign;
  6678. if (verticalAlign === 'bottom') {
  6679. this.extraBottomMargin = true;
  6680. }
  6681. else if (verticalAlign !== 'middle') {
  6682. this.extraTopMargin = true;
  6683. }
  6684. }
  6685. });
  6686. addEvent(Chart, 'getMargins', function () {
  6687. var rangeSelector = this.rangeSelector,
  6688. rangeSelectorHeight;
  6689. if (rangeSelector) {
  6690. rangeSelectorHeight = rangeSelector.getHeight();
  6691. if (this.extraTopMargin) {
  6692. this.plotTop += rangeSelectorHeight;
  6693. }
  6694. if (this.extraBottomMargin) {
  6695. this.marginBottom += rangeSelectorHeight;
  6696. }
  6697. }
  6698. });
  6699. Chart.prototype.callbacks.push(initRangeSelector_1);
  6700. // Remove resize/afterSetExtremes at chart destroy
  6701. addEvent(Chart, 'destroy', function destroyEvents() {
  6702. for (var i = 0; i < chartDestroyEvents_1.length; i++) {
  6703. var events = chartDestroyEvents_1[i];
  6704. if (events[0] === this) {
  6705. events[1].forEach(function (unbind) { return unbind(); });
  6706. chartDestroyEvents_1.splice(i, 1);
  6707. return;
  6708. }
  6709. }
  6710. });
  6711. H.RangeSelector = RangeSelector;
  6712. }
  6713. return H.RangeSelector;
  6714. });
  6715. _registerModule(_modules, 'Accessibility/Components/RangeSelectorComponent.js', [_modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Utils/Announcer.js'], _modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Accessibility/KeyboardNavigationHandler.js'], _modules['Core/Utilities.js'], _modules['Extensions/RangeSelector.js']], function (AccessibilityComponent, ChartUtilities, Announcer, H, HTMLUtilities, KeyboardNavigationHandler, U, RangeSelector) {
  6716. /* *
  6717. *
  6718. * (c) 2009-2021 Øystein Moseng
  6719. *
  6720. * Accessibility component for the range selector.
  6721. *
  6722. * License: www.highcharts.com/license
  6723. *
  6724. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6725. *
  6726. * */
  6727. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT,
  6728. getAxisRangeDescription = ChartUtilities.getAxisRangeDescription;
  6729. var setElAttrs = HTMLUtilities.setElAttrs;
  6730. var addEvent = U.addEvent,
  6731. extend = U.extend;
  6732. /* eslint-disable no-invalid-this, valid-jsdoc */
  6733. /**
  6734. * @private
  6735. */
  6736. function shouldRunInputNavigation(chart) {
  6737. return Boolean(chart.rangeSelector &&
  6738. chart.rangeSelector.inputGroup &&
  6739. chart.rangeSelector.inputGroup.element
  6740. .getAttribute('visibility') !== 'hidden' &&
  6741. chart.options.rangeSelector.inputEnabled !== false &&
  6742. chart.rangeSelector.minInput &&
  6743. chart.rangeSelector.maxInput);
  6744. }
  6745. /**
  6746. * Highlight range selector button by index.
  6747. *
  6748. * @private
  6749. * @function Highcharts.Chart#highlightRangeSelectorButton
  6750. *
  6751. * @param {number} ix
  6752. *
  6753. * @return {boolean}
  6754. */
  6755. H.Chart.prototype.highlightRangeSelectorButton = function (ix) {
  6756. var _a,
  6757. _b;
  6758. var buttons = ((_a = this.rangeSelector) === null || _a === void 0 ? void 0 : _a.buttons) || [];
  6759. var curHighlightedIx = this.highlightedRangeSelectorItemIx;
  6760. var curSelectedIx = (_b = this.rangeSelector) === null || _b === void 0 ? void 0 : _b.selected;
  6761. // Deselect old
  6762. if (typeof curHighlightedIx !== 'undefined' &&
  6763. buttons[curHighlightedIx] &&
  6764. curHighlightedIx !== curSelectedIx) {
  6765. buttons[curHighlightedIx].setState(this.oldRangeSelectorItemState || 0);
  6766. }
  6767. // Select new
  6768. this.highlightedRangeSelectorItemIx = ix;
  6769. if (buttons[ix]) {
  6770. this.setFocusToElement(buttons[ix].box, buttons[ix].element);
  6771. if (ix !== curSelectedIx) {
  6772. this.oldRangeSelectorItemState = buttons[ix].state;
  6773. buttons[ix].setState(1);
  6774. }
  6775. return true;
  6776. }
  6777. return false;
  6778. };
  6779. // Range selector does not have destroy-setup for class instance events - so
  6780. // we set it on the class and call the component from here.
  6781. addEvent(RangeSelector, 'afterBtnClick', function () {
  6782. var _a;
  6783. var component = (_a = this.chart.accessibility) === null || _a === void 0 ? void 0 : _a.components.rangeSelector;
  6784. return component === null || component === void 0 ? void 0 : component.onAfterBtnClick();
  6785. });
  6786. /**
  6787. * The RangeSelectorComponent class
  6788. *
  6789. * @private
  6790. * @class
  6791. * @name Highcharts.RangeSelectorComponent
  6792. */
  6793. var RangeSelectorComponent = function () { };
  6794. RangeSelectorComponent.prototype = new AccessibilityComponent();
  6795. extend(RangeSelectorComponent.prototype, /** @lends Highcharts.RangeSelectorComponent */ {
  6796. /**
  6797. * Init the component
  6798. * @private
  6799. */
  6800. init: function () {
  6801. var chart = this.chart;
  6802. this.announcer = new Announcer(chart, 'polite');
  6803. },
  6804. /**
  6805. * Called on first render/updates to the chart, including options changes.
  6806. */
  6807. onChartUpdate: function () {
  6808. var _a;
  6809. var chart = this.chart,
  6810. component = this,
  6811. rangeSelector = chart.rangeSelector;
  6812. if (!rangeSelector) {
  6813. return;
  6814. }
  6815. this.updateSelectorVisibility();
  6816. this.setDropdownAttrs();
  6817. if ((_a = rangeSelector.buttons) === null || _a === void 0 ? void 0 : _a.length) {
  6818. rangeSelector.buttons.forEach(function (button) {
  6819. component.setRangeButtonAttrs(button);
  6820. });
  6821. }
  6822. // Make sure input boxes are accessible and focusable
  6823. if (rangeSelector.maxInput && rangeSelector.minInput) {
  6824. ['minInput', 'maxInput'].forEach(function (key, i) {
  6825. var input = rangeSelector[key];
  6826. if (input) {
  6827. unhideChartElementFromAT(chart, input);
  6828. component.setRangeInputAttrs(input, 'accessibility.rangeSelector.' + (i ? 'max' : 'min') +
  6829. 'InputLabel');
  6830. }
  6831. });
  6832. }
  6833. },
  6834. /**
  6835. * Hide buttons from AT when showing dropdown, and vice versa.
  6836. * @private
  6837. */
  6838. updateSelectorVisibility: function () {
  6839. var chart = this.chart;
  6840. var rangeSelector = chart.rangeSelector;
  6841. var dropdown = rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.dropdown;
  6842. var buttons = (rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.buttons) || [];
  6843. var hideFromAT = function (el) { return el.setAttribute('aria-hidden',
  6844. true); };
  6845. if ((rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.hasVisibleDropdown) && dropdown) {
  6846. unhideChartElementFromAT(chart, dropdown);
  6847. buttons.forEach(function (btn) { return hideFromAT(btn.element); });
  6848. }
  6849. else {
  6850. if (dropdown) {
  6851. hideFromAT(dropdown);
  6852. }
  6853. buttons.forEach(function (btn) { return unhideChartElementFromAT(chart, btn.element); });
  6854. }
  6855. },
  6856. /**
  6857. * Set accessibility related attributes on dropdown element.
  6858. * @private
  6859. */
  6860. setDropdownAttrs: function () {
  6861. var _a;
  6862. var chart = this.chart;
  6863. var dropdown = (_a = chart.rangeSelector) === null || _a === void 0 ? void 0 : _a.dropdown;
  6864. if (dropdown) {
  6865. var label = chart.langFormat('accessibility.rangeSelector.dropdownLabel', { rangeTitle: chart.options.lang.rangeSelectorZoom });
  6866. dropdown.setAttribute('aria-label', label);
  6867. dropdown.setAttribute('tabindex', -1);
  6868. }
  6869. },
  6870. /**
  6871. * @private
  6872. * @param {Highcharts.SVGElement} button
  6873. */
  6874. setRangeButtonAttrs: function (button) {
  6875. setElAttrs(button.element, {
  6876. tabindex: -1,
  6877. role: 'button'
  6878. });
  6879. },
  6880. /**
  6881. * @private
  6882. */
  6883. setRangeInputAttrs: function (input, langKey) {
  6884. var chart = this.chart;
  6885. setElAttrs(input, {
  6886. tabindex: -1,
  6887. 'aria-label': chart.langFormat(langKey, { chart: chart })
  6888. });
  6889. },
  6890. /**
  6891. * @private
  6892. * @param {Highcharts.KeyboardNavigationHandler} keyboardNavigationHandler
  6893. * @param {number} keyCode
  6894. * @return {number} Response code
  6895. */
  6896. onButtonNavKbdArrowKey: function (keyboardNavigationHandler, keyCode) {
  6897. var response = keyboardNavigationHandler.response,
  6898. keys = this.keyCodes,
  6899. chart = this.chart,
  6900. wrapAround = chart.options.accessibility
  6901. .keyboardNavigation.wrapAround,
  6902. direction = (keyCode === keys.left || keyCode === keys.up) ? -1 : 1,
  6903. didHighlight = chart.highlightRangeSelectorButton(chart.highlightedRangeSelectorItemIx + direction);
  6904. if (!didHighlight) {
  6905. if (wrapAround) {
  6906. keyboardNavigationHandler.init(direction);
  6907. return response.success;
  6908. }
  6909. return response[direction > 0 ? 'next' : 'prev'];
  6910. }
  6911. return response.success;
  6912. },
  6913. /**
  6914. * @private
  6915. */
  6916. onButtonNavKbdClick: function (keyboardNavigationHandler) {
  6917. var response = keyboardNavigationHandler.response,
  6918. chart = this.chart,
  6919. wasDisabled = chart.oldRangeSelectorItemState === 3;
  6920. if (!wasDisabled) {
  6921. this.fakeClickEvent(chart.rangeSelector.buttons[chart.highlightedRangeSelectorItemIx].element);
  6922. }
  6923. return response.success;
  6924. },
  6925. /**
  6926. * Called whenever a range selector button has been clicked, either by
  6927. * mouse, touch, or kbd/voice/other.
  6928. * @private
  6929. */
  6930. onAfterBtnClick: function () {
  6931. var chart = this.chart;
  6932. var axisRangeDescription = getAxisRangeDescription(chart.xAxis[0]);
  6933. var announcement = chart.langFormat('accessibility.rangeSelector.clickButtonAnnouncement', { chart: chart,
  6934. axisRangeDescription: axisRangeDescription });
  6935. if (announcement) {
  6936. this.announcer.announce(announcement);
  6937. }
  6938. },
  6939. /**
  6940. * @private
  6941. */
  6942. onInputKbdMove: function (direction) {
  6943. var _a,
  6944. _b;
  6945. var chart = this.chart;
  6946. var rangeSel = chart.rangeSelector;
  6947. var newIx = chart.highlightedInputRangeIx = (chart.highlightedInputRangeIx || 0) + direction;
  6948. var newIxOutOfRange = newIx > 1 || newIx < 0;
  6949. if (newIxOutOfRange) {
  6950. (_a = chart.accessibility) === null || _a === void 0 ? void 0 : _a.keyboardNavigation.tabindexContainer.focus();
  6951. (_b = chart.accessibility) === null || _b === void 0 ? void 0 : _b.keyboardNavigation[direction < 0 ? 'prev' : 'next']();
  6952. }
  6953. else if (rangeSel) {
  6954. var svgEl = rangeSel[newIx ? 'maxDateBox' : 'minDateBox'];
  6955. var inputEl = rangeSel[newIx ? 'maxInput' : 'minInput'];
  6956. if (svgEl && inputEl) {
  6957. chart.setFocusToElement(svgEl, inputEl);
  6958. }
  6959. }
  6960. },
  6961. /**
  6962. * @private
  6963. * @param {number} direction
  6964. */
  6965. onInputNavInit: function (direction) {
  6966. var _this = this;
  6967. var component = this;
  6968. var chart = this.chart;
  6969. var buttonIxToHighlight = direction > 0 ? 0 : 1;
  6970. var rangeSel = chart.rangeSelector;
  6971. var svgEl = rangeSel === null || rangeSel === void 0 ? void 0 : rangeSel[buttonIxToHighlight ? 'maxDateBox' : 'minDateBox'];
  6972. var minInput = rangeSel === null || rangeSel === void 0 ? void 0 : rangeSel.minInput;
  6973. var maxInput = rangeSel === null || rangeSel === void 0 ? void 0 : rangeSel.maxInput;
  6974. var inputEl = buttonIxToHighlight ? maxInput : minInput;
  6975. chart.highlightedInputRangeIx = buttonIxToHighlight;
  6976. if (svgEl && minInput && maxInput) {
  6977. chart.setFocusToElement(svgEl, inputEl);
  6978. // Tab-press with the input focused does not propagate to chart
  6979. // automatically, so we manually catch and handle it when relevant.
  6980. if (this.removeInputKeydownHandler) {
  6981. this.removeInputKeydownHandler();
  6982. }
  6983. var keydownHandler = function (e) {
  6984. var isTab = (e.which || e.keyCode) === _this.keyCodes.tab;
  6985. if (isTab) {
  6986. e.preventDefault();
  6987. e.stopPropagation();
  6988. component.onInputKbdMove(e.shiftKey ? -1 : 1);
  6989. }
  6990. };
  6991. var minRemover_1 = addEvent(minInput, 'keydown',
  6992. keydownHandler);
  6993. var maxRemover_1 = addEvent(maxInput, 'keydown',
  6994. keydownHandler);
  6995. this.removeInputKeydownHandler = function () {
  6996. minRemover_1();
  6997. maxRemover_1();
  6998. };
  6999. }
  7000. },
  7001. /**
  7002. * @private
  7003. */
  7004. onInputNavTerminate: function () {
  7005. var rangeSel = (this.chart.rangeSelector || {});
  7006. if (rangeSel.maxInput) {
  7007. rangeSel.hideInput('max');
  7008. }
  7009. if (rangeSel.minInput) {
  7010. rangeSel.hideInput('min');
  7011. }
  7012. if (this.removeInputKeydownHandler) {
  7013. this.removeInputKeydownHandler();
  7014. delete this.removeInputKeydownHandler;
  7015. }
  7016. },
  7017. /**
  7018. * @private
  7019. */
  7020. initDropdownNav: function () {
  7021. var _this = this;
  7022. var chart = this.chart;
  7023. var rangeSelector = chart.rangeSelector;
  7024. var dropdown = rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.dropdown;
  7025. if (rangeSelector && dropdown) {
  7026. chart.setFocusToElement(rangeSelector.buttonGroup, dropdown);
  7027. if (this.removeDropdownKeydownHandler) {
  7028. this.removeDropdownKeydownHandler();
  7029. }
  7030. // Tab-press with dropdown focused does not propagate to chart
  7031. // automatically, so we manually catch and handle it when relevant.
  7032. this.removeDropdownKeydownHandler = addEvent(dropdown, 'keydown', function (e) {
  7033. var _a,
  7034. _b;
  7035. var isTab = (e.which || e.keyCode) === _this.keyCodes.tab;
  7036. if (isTab) {
  7037. e.preventDefault();
  7038. e.stopPropagation();
  7039. (_a = chart.accessibility) === null || _a === void 0 ? void 0 : _a.keyboardNavigation.tabindexContainer.focus();
  7040. (_b = chart.accessibility) === null || _b === void 0 ? void 0 : _b.keyboardNavigation[e.shiftKey ? 'prev' : 'next']();
  7041. }
  7042. });
  7043. }
  7044. },
  7045. /**
  7046. * Get navigation for the range selector buttons.
  7047. * @private
  7048. * @return {Highcharts.KeyboardNavigationHandler} The module object.
  7049. */
  7050. getRangeSelectorButtonNavigation: function () {
  7051. var chart = this.chart;
  7052. var keys = this.keyCodes;
  7053. var component = this;
  7054. return new KeyboardNavigationHandler(chart, {
  7055. keyCodeMap: [
  7056. [
  7057. [keys.left, keys.right, keys.up, keys.down],
  7058. function (keyCode) {
  7059. return component.onButtonNavKbdArrowKey(this, keyCode);
  7060. }
  7061. ],
  7062. [
  7063. [keys.enter, keys.space],
  7064. function () {
  7065. return component.onButtonNavKbdClick(this);
  7066. }
  7067. ]
  7068. ],
  7069. validate: function () {
  7070. var _a,
  7071. _b;
  7072. return !!((_b = (_a = chart.rangeSelector) === null || _a === void 0 ? void 0 : _a.buttons) === null || _b === void 0 ? void 0 : _b.length);
  7073. },
  7074. init: function (direction) {
  7075. var rangeSelector = chart.rangeSelector;
  7076. if (rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.hasVisibleDropdown) {
  7077. component.initDropdownNav();
  7078. }
  7079. else if (rangeSelector) {
  7080. var lastButtonIx = rangeSelector.buttons.length - 1;
  7081. chart.highlightRangeSelectorButton(direction > 0 ? 0 : lastButtonIx);
  7082. }
  7083. },
  7084. terminate: function () {
  7085. if (component.removeDropdownKeydownHandler) {
  7086. component.removeDropdownKeydownHandler();
  7087. delete component.removeDropdownKeydownHandler;
  7088. }
  7089. }
  7090. });
  7091. },
  7092. /**
  7093. * Get navigation for the range selector input boxes.
  7094. * @private
  7095. * @return {Highcharts.KeyboardNavigationHandler}
  7096. * The module object.
  7097. */
  7098. getRangeSelectorInputNavigation: function () {
  7099. var chart = this.chart;
  7100. var component = this;
  7101. return new KeyboardNavigationHandler(chart, {
  7102. keyCodeMap: [],
  7103. validate: function () {
  7104. return shouldRunInputNavigation(chart);
  7105. },
  7106. init: function (direction) {
  7107. component.onInputNavInit(direction);
  7108. },
  7109. terminate: function () {
  7110. component.onInputNavTerminate();
  7111. }
  7112. });
  7113. },
  7114. /**
  7115. * Get keyboard navigation handlers for this component.
  7116. * @return {Array<Highcharts.KeyboardNavigationHandler>}
  7117. * List of module objects.
  7118. */
  7119. getKeyboardNavigation: function () {
  7120. return [
  7121. this.getRangeSelectorButtonNavigation(),
  7122. this.getRangeSelectorInputNavigation()
  7123. ];
  7124. },
  7125. /**
  7126. * Remove component traces
  7127. */
  7128. destroy: function () {
  7129. var _a;
  7130. if (this.removeDropdownKeydownHandler) {
  7131. this.removeDropdownKeydownHandler();
  7132. }
  7133. if (this.removeInputKeydownHandler) {
  7134. this.removeInputKeydownHandler();
  7135. }
  7136. (_a = this.announcer) === null || _a === void 0 ? void 0 : _a.destroy();
  7137. }
  7138. });
  7139. return RangeSelectorComponent;
  7140. });
  7141. _registerModule(_modules, 'Accessibility/Components/InfoRegionsComponent.js', [_modules['Core/Globals.js'], _modules['Core/Renderer/HTML/AST.js'], _modules['Core/Utilities.js'], _modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/Utils/Announcer.js'], _modules['Accessibility/Components/AnnotationsA11y.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Accessibility/Utils/HTMLUtilities.js']], function (H, AST, U, AccessibilityComponent, Announcer, AnnotationsA11y, ChartUtilities, HTMLUtilities) {
  7142. /* *
  7143. *
  7144. * (c) 2009-2021 Øystein Moseng
  7145. *
  7146. * Accessibility component for chart info region and table.
  7147. *
  7148. * License: www.highcharts.com/license
  7149. *
  7150. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7151. *
  7152. * */
  7153. var doc = H.doc;
  7154. var extend = U.extend,
  7155. format = U.format,
  7156. pick = U.pick;
  7157. var getAnnotationsInfoHTML = AnnotationsA11y.getAnnotationsInfoHTML;
  7158. var getAxisDescription = ChartUtilities.getAxisDescription,
  7159. getAxisRangeDescription = ChartUtilities.getAxisRangeDescription,
  7160. getChartTitle = ChartUtilities.getChartTitle,
  7161. unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT;
  7162. var addClass = HTMLUtilities.addClass,
  7163. escapeStringForHTML = HTMLUtilities.escapeStringForHTML,
  7164. getElement = HTMLUtilities.getElement,
  7165. getHeadingTagNameForElement = HTMLUtilities.getHeadingTagNameForElement,
  7166. setElAttrs = HTMLUtilities.setElAttrs,
  7167. stripHTMLTagsFromString = HTMLUtilities.stripHTMLTagsFromString,
  7168. visuallyHideElement = HTMLUtilities.visuallyHideElement;
  7169. /* eslint-disable no-invalid-this, valid-jsdoc */
  7170. /**
  7171. * @private
  7172. */
  7173. function stripEmptyHTMLTags(str) {
  7174. return str.replace(/<(\w+)[^>]*?>\s*<\/\1>/g, '');
  7175. }
  7176. /**
  7177. * @private
  7178. */
  7179. function getTypeDescForMapChart(chart, formatContext) {
  7180. return formatContext.mapTitle ?
  7181. chart.langFormat('accessibility.chartTypes.mapTypeDescription', formatContext) :
  7182. chart.langFormat('accessibility.chartTypes.unknownMap', formatContext);
  7183. }
  7184. /**
  7185. * @private
  7186. */
  7187. function getTypeDescForCombinationChart(chart, formatContext) {
  7188. return chart.langFormat('accessibility.chartTypes.combinationChart', formatContext);
  7189. }
  7190. /**
  7191. * @private
  7192. */
  7193. function getTypeDescForEmptyChart(chart, formatContext) {
  7194. return chart.langFormat('accessibility.chartTypes.emptyChart', formatContext);
  7195. }
  7196. /**
  7197. * @private
  7198. */
  7199. function buildTypeDescriptionFromSeries(chart, types, context) {
  7200. var firstType = types[0], typeExplaination = chart.langFormat('accessibility.seriesTypeDescriptions.' + firstType, context), multi = chart.series && chart.series.length < 2 ? 'Single' : 'Multiple';
  7201. return (chart.langFormat('accessibility.chartTypes.' + firstType + multi, context) ||
  7202. chart.langFormat('accessibility.chartTypes.default' + multi, context)) + (typeExplaination ? ' ' + typeExplaination : '');
  7203. }
  7204. /**
  7205. * @private
  7206. */
  7207. function getTableSummary(chart) {
  7208. return chart.langFormat('accessibility.table.tableSummary', { chart: chart });
  7209. }
  7210. /**
  7211. * Return simplified explaination of chart type. Some types will not be familiar
  7212. * to most users, but in those cases we try to add an explaination of the type.
  7213. *
  7214. * @private
  7215. * @function Highcharts.Chart#getTypeDescription
  7216. * @param {Array<string>} types The series types in this chart.
  7217. * @return {string} The text description of the chart type.
  7218. */
  7219. H.Chart.prototype.getTypeDescription = function (types) {
  7220. var firstType = types[0],
  7221. firstSeries = this.series && this.series[0] || {},
  7222. formatContext = {
  7223. numSeries: this.series.length,
  7224. numPoints: firstSeries.points && firstSeries.points.length,
  7225. chart: this,
  7226. mapTitle: firstSeries.mapTitle
  7227. };
  7228. if (!firstType) {
  7229. return getTypeDescForEmptyChart(this, formatContext);
  7230. }
  7231. if (firstType === 'map') {
  7232. return getTypeDescForMapChart(this, formatContext);
  7233. }
  7234. if (this.types.length > 1) {
  7235. return getTypeDescForCombinationChart(this, formatContext);
  7236. }
  7237. return buildTypeDescriptionFromSeries(this, types, formatContext);
  7238. };
  7239. /**
  7240. * The InfoRegionsComponent class
  7241. *
  7242. * @private
  7243. * @class
  7244. * @name Highcharts.InfoRegionsComponent
  7245. */
  7246. var InfoRegionsComponent = function () { };
  7247. InfoRegionsComponent.prototype = new AccessibilityComponent();
  7248. extend(InfoRegionsComponent.prototype, /** @lends Highcharts.InfoRegionsComponent */ {
  7249. /**
  7250. * Init the component
  7251. * @private
  7252. */
  7253. init: function () {
  7254. var chart = this.chart;
  7255. var component = this;
  7256. this.initRegionsDefinitions();
  7257. this.addEvent(chart, 'aftergetTableAST', function (e) {
  7258. component.onDataTableCreated(e);
  7259. });
  7260. this.addEvent(chart, 'afterViewData', function (tableDiv) {
  7261. component.dataTableDiv = tableDiv;
  7262. // Use small delay to give browsers & AT time to register new table
  7263. setTimeout(function () {
  7264. component.focusDataTable();
  7265. }, 300);
  7266. });
  7267. this.announcer = new Announcer(chart, 'assertive');
  7268. },
  7269. /**
  7270. * @private
  7271. */
  7272. initRegionsDefinitions: function () {
  7273. var component = this;
  7274. this.screenReaderSections = {
  7275. before: {
  7276. element: null,
  7277. buildContent: function (chart) {
  7278. var formatter = chart.options.accessibility
  7279. .screenReaderSection.beforeChartFormatter;
  7280. return formatter ? formatter(chart) :
  7281. component.defaultBeforeChartFormatter(chart);
  7282. },
  7283. insertIntoDOM: function (el, chart) {
  7284. chart.renderTo.insertBefore(el, chart.renderTo.firstChild);
  7285. },
  7286. afterInserted: function () {
  7287. if (typeof component.sonifyButtonId !== 'undefined') {
  7288. component.initSonifyButton(component.sonifyButtonId);
  7289. }
  7290. if (typeof component.dataTableButtonId !== 'undefined') {
  7291. component.initDataTableButton(component.dataTableButtonId);
  7292. }
  7293. }
  7294. },
  7295. after: {
  7296. element: null,
  7297. buildContent: function (chart) {
  7298. var formatter = chart.options.accessibility.screenReaderSection
  7299. .afterChartFormatter;
  7300. return formatter ? formatter(chart) :
  7301. component.defaultAfterChartFormatter();
  7302. },
  7303. insertIntoDOM: function (el, chart) {
  7304. chart.renderTo.insertBefore(el, chart.container.nextSibling);
  7305. }
  7306. }
  7307. };
  7308. },
  7309. /**
  7310. * Called on chart render. Have to update the sections on render, in order
  7311. * to get a11y info from series.
  7312. */
  7313. onChartRender: function () {
  7314. var component = this;
  7315. this.linkedDescriptionElement = this.getLinkedDescriptionElement();
  7316. this.setLinkedDescriptionAttrs();
  7317. Object.keys(this.screenReaderSections).forEach(function (regionKey) {
  7318. component.updateScreenReaderSection(regionKey);
  7319. });
  7320. },
  7321. /**
  7322. * @private
  7323. */
  7324. getLinkedDescriptionElement: function () {
  7325. var chartOptions = this.chart.options,
  7326. linkedDescOption = chartOptions.accessibility.linkedDescription;
  7327. if (!linkedDescOption) {
  7328. return;
  7329. }
  7330. if (typeof linkedDescOption !== 'string') {
  7331. return linkedDescOption;
  7332. }
  7333. var query = format(linkedDescOption,
  7334. this.chart),
  7335. queryMatch = doc.querySelectorAll(query);
  7336. if (queryMatch.length === 1) {
  7337. return queryMatch[0];
  7338. }
  7339. },
  7340. /**
  7341. * @private
  7342. */
  7343. setLinkedDescriptionAttrs: function () {
  7344. var el = this.linkedDescriptionElement;
  7345. if (el) {
  7346. el.setAttribute('aria-hidden', 'true');
  7347. addClass(el, 'highcharts-linked-description');
  7348. }
  7349. },
  7350. /**
  7351. * @private
  7352. * @param {string} regionKey The name/key of the region to update
  7353. */
  7354. updateScreenReaderSection: function (regionKey) {
  7355. 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'));
  7356. this.setScreenReaderSectionAttribs(sectionDiv, regionKey);
  7357. AST.setElementHTML(hiddenDiv, content);
  7358. sectionDiv.appendChild(hiddenDiv);
  7359. region.insertIntoDOM(sectionDiv, chart);
  7360. visuallyHideElement(hiddenDiv);
  7361. unhideChartElementFromAT(chart, hiddenDiv);
  7362. if (region.afterInserted) {
  7363. region.afterInserted();
  7364. }
  7365. },
  7366. /**
  7367. * @private
  7368. * @param {Highcharts.HTMLDOMElement} sectionDiv The section element
  7369. * @param {string} regionKey Name/key of the region we are setting attrs for
  7370. */
  7371. setScreenReaderSectionAttribs: function (sectionDiv, regionKey) {
  7372. var labelLangKey = ('accessibility.screenReaderSection.' + regionKey + 'RegionLabel'), chart = this.chart, labelText = chart.langFormat(labelLangKey, { chart: chart }), sectionId = 'highcharts-screen-reader-region-' + regionKey + '-' +
  7373. chart.index;
  7374. setElAttrs(sectionDiv, {
  7375. id: sectionId,
  7376. 'aria-label': labelText
  7377. });
  7378. // Sections are wrapped to be positioned relatively to chart in case
  7379. // elements inside are tabbed to.
  7380. sectionDiv.style.position = 'relative';
  7381. if (chart.options.accessibility.landmarkVerbosity === 'all' &&
  7382. labelText) {
  7383. sectionDiv.setAttribute('role', 'region');
  7384. }
  7385. },
  7386. /**
  7387. * @private
  7388. * @return {string}
  7389. */
  7390. defaultBeforeChartFormatter: function () {
  7391. var _a;
  7392. var chart = this.chart,
  7393. format = chart.options.accessibility
  7394. .screenReaderSection.beforeChartFormat,
  7395. axesDesc = this.getAxesDescription(),
  7396. shouldHaveSonifyBtn = chart.sonify && ((_a = chart.options.sonification) === null || _a === void 0 ? void 0 : _a.enabled),
  7397. sonifyButtonId = 'highcharts-a11y-sonify-data-btn-' +
  7398. chart.index,
  7399. dataTableButtonId = 'hc-linkto-highcharts-data-table-' +
  7400. chart.index,
  7401. annotationsList = getAnnotationsInfoHTML(chart),
  7402. annotationsTitleStr = chart.langFormat('accessibility.screenReaderSection.annotations.heading', { chart: chart }),
  7403. context = {
  7404. headingTagName: getHeadingTagNameForElement(chart.renderTo),
  7405. chartTitle: getChartTitle(chart),
  7406. typeDescription: this.getTypeDescriptionText(),
  7407. chartSubtitle: this.getSubtitleText(),
  7408. chartLongdesc: this.getLongdescText(),
  7409. xAxisDescription: axesDesc.xAxis,
  7410. yAxisDescription: axesDesc.yAxis,
  7411. playAsSoundButton: shouldHaveSonifyBtn ?
  7412. this.getSonifyButtonText(sonifyButtonId) : '',
  7413. viewTableButton: chart.getCSV ?
  7414. this.getDataTableButtonText(dataTableButtonId) : '',
  7415. annotationsTitle: annotationsList ? annotationsTitleStr : '',
  7416. annotationsList: annotationsList
  7417. },
  7418. formattedString = H.i18nFormat(format,
  7419. context,
  7420. chart);
  7421. this.dataTableButtonId = dataTableButtonId;
  7422. this.sonifyButtonId = sonifyButtonId;
  7423. return stripEmptyHTMLTags(formattedString);
  7424. },
  7425. /**
  7426. * @private
  7427. * @return {string}
  7428. */
  7429. defaultAfterChartFormatter: function () {
  7430. var chart = this.chart,
  7431. format = chart.options.accessibility
  7432. .screenReaderSection.afterChartFormat,
  7433. context = {
  7434. endOfChartMarker: this.getEndOfChartMarkerText()
  7435. },
  7436. formattedString = H.i18nFormat(format,
  7437. context,
  7438. chart);
  7439. return stripEmptyHTMLTags(formattedString);
  7440. },
  7441. /**
  7442. * @private
  7443. * @return {string}
  7444. */
  7445. getLinkedDescription: function () {
  7446. var el = this.linkedDescriptionElement,
  7447. content = el && el.innerHTML || '';
  7448. return stripHTMLTagsFromString(content);
  7449. },
  7450. /**
  7451. * @private
  7452. * @return {string}
  7453. */
  7454. getLongdescText: function () {
  7455. var chartOptions = this.chart.options,
  7456. captionOptions = chartOptions.caption,
  7457. captionText = captionOptions && captionOptions.text,
  7458. linkedDescription = this.getLinkedDescription();
  7459. return (chartOptions.accessibility.description ||
  7460. linkedDescription ||
  7461. captionText ||
  7462. '');
  7463. },
  7464. /**
  7465. * @private
  7466. * @return {string}
  7467. */
  7468. getTypeDescriptionText: function () {
  7469. var chart = this.chart;
  7470. return chart.types ?
  7471. chart.options.accessibility.typeDescription ||
  7472. chart.getTypeDescription(chart.types) : '';
  7473. },
  7474. /**
  7475. * @private
  7476. * @param {string} buttonId
  7477. * @return {string}
  7478. */
  7479. getDataTableButtonText: function (buttonId) {
  7480. var chart = this.chart,
  7481. buttonText = chart.langFormat('accessibility.table.viewAsDataTableButtonText', { chart: chart,
  7482. chartTitle: getChartTitle(chart) });
  7483. return '<button id="' + buttonId + '">' + buttonText + '</button>';
  7484. },
  7485. /**
  7486. * @private
  7487. * @param {string} buttonId
  7488. * @return {string}
  7489. */
  7490. getSonifyButtonText: function (buttonId) {
  7491. var _a;
  7492. var chart = this.chart;
  7493. if (((_a = chart.options.sonification) === null || _a === void 0 ? void 0 : _a.enabled) === false) {
  7494. return '';
  7495. }
  7496. var buttonText = chart.langFormat('accessibility.sonification.playAsSoundButtonText', { chart: chart,
  7497. chartTitle: getChartTitle(chart) });
  7498. return '<button id="' + buttonId + '">' + buttonText + '</button>';
  7499. },
  7500. /**
  7501. * @private
  7502. * @return {string}
  7503. */
  7504. getSubtitleText: function () {
  7505. var subtitle = (this.chart.options.subtitle);
  7506. return stripHTMLTagsFromString(subtitle && subtitle.text || '');
  7507. },
  7508. /**
  7509. * @private
  7510. * @return {string}
  7511. */
  7512. getEndOfChartMarkerText: function () {
  7513. var chart = this.chart, markerText = chart.langFormat('accessibility.screenReaderSection.endOfChartMarker', { chart: chart }), id = 'highcharts-end-of-chart-marker-' + chart.index;
  7514. return '<div id="' + id + '">' + markerText + '</div>';
  7515. },
  7516. /**
  7517. * @private
  7518. * @param {Highcharts.Dictionary<string>} e
  7519. */
  7520. onDataTableCreated: function (e) {
  7521. var chart = this.chart;
  7522. if (chart.options.accessibility.enabled) {
  7523. if (this.viewDataTableButton) {
  7524. this.viewDataTableButton.setAttribute('aria-expanded', 'true');
  7525. }
  7526. var attributes = e.tree.attributes || {};
  7527. attributes.tabindex = -1;
  7528. attributes.summary = getTableSummary(chart);
  7529. e.tree.attributes = attributes;
  7530. }
  7531. },
  7532. /**
  7533. * @private
  7534. */
  7535. focusDataTable: function () {
  7536. var tableDiv = this.dataTableDiv,
  7537. table = tableDiv && tableDiv.getElementsByTagName('table')[0];
  7538. if (table && table.focus) {
  7539. table.focus();
  7540. }
  7541. },
  7542. /**
  7543. * @private
  7544. * @param {string} sonifyButtonId
  7545. */
  7546. initSonifyButton: function (sonifyButtonId) {
  7547. var _this = this;
  7548. var el = this.sonifyButton = getElement(sonifyButtonId);
  7549. var chart = this.chart;
  7550. var defaultHandler = function (e) {
  7551. el === null || el === void 0 ? void 0 : el.setAttribute('aria-hidden', 'true');
  7552. el === null || el === void 0 ? void 0 : el.setAttribute('aria-label', '');
  7553. e.preventDefault();
  7554. e.stopPropagation();
  7555. var announceMsg = chart.langFormat('accessibility.sonification.playAsSoundClickAnnouncement', { chart: chart });
  7556. _this.announcer.announce(announceMsg);
  7557. setTimeout(function () {
  7558. el === null || el === void 0 ? void 0 : el.removeAttribute('aria-hidden');
  7559. el === null || el === void 0 ? void 0 : el.removeAttribute('aria-label');
  7560. if (chart.sonify) {
  7561. chart.sonify();
  7562. }
  7563. }, 1000); // Delay to let screen reader speak the button press
  7564. };
  7565. if (el && chart) {
  7566. setElAttrs(el, {
  7567. tabindex: '-1'
  7568. });
  7569. el.onclick = function (e) {
  7570. var _a;
  7571. var onPlayAsSoundClick = (_a = chart.options.accessibility) === null || _a === void 0 ? void 0 : _a.screenReaderSection.onPlayAsSoundClick;
  7572. (onPlayAsSoundClick || defaultHandler).call(this, e, chart);
  7573. };
  7574. }
  7575. },
  7576. /**
  7577. * Set attribs and handlers for default viewAsDataTable button if exists.
  7578. * @private
  7579. * @param {string} tableButtonId
  7580. */
  7581. initDataTableButton: function (tableButtonId) {
  7582. var el = this.viewDataTableButton = getElement(tableButtonId), chart = this.chart, tableId = tableButtonId.replace('hc-linkto-', '');
  7583. if (el) {
  7584. setElAttrs(el, {
  7585. tabindex: '-1',
  7586. 'aria-expanded': !!getElement(tableId)
  7587. });
  7588. el.onclick = chart.options.accessibility
  7589. .screenReaderSection.onViewDataTableClick ||
  7590. function () {
  7591. chart.viewData();
  7592. };
  7593. }
  7594. },
  7595. /**
  7596. * Return object with text description of each of the chart's axes.
  7597. * @private
  7598. * @return {Highcharts.Dictionary<string>}
  7599. */
  7600. getAxesDescription: function () {
  7601. var chart = this.chart,
  7602. shouldDescribeColl = function (collectionKey,
  7603. defaultCondition) {
  7604. var axes = chart[collectionKey];
  7605. return axes.length > 1 || axes[0] &&
  7606. pick(axes[0].options.accessibility &&
  7607. axes[0].options.accessibility.enabled, defaultCondition);
  7608. }, hasNoMap = !!chart.types && chart.types.indexOf('map') < 0, hasCartesian = !!chart.hasCartesianSeries, showXAxes = shouldDescribeColl('xAxis', !chart.angular && hasCartesian && hasNoMap), showYAxes = shouldDescribeColl('yAxis', hasCartesian && hasNoMap), desc = {};
  7609. if (showXAxes) {
  7610. desc.xAxis = this.getAxisDescriptionText('xAxis');
  7611. }
  7612. if (showYAxes) {
  7613. desc.yAxis = this.getAxisDescriptionText('yAxis');
  7614. }
  7615. return desc;
  7616. },
  7617. /**
  7618. * @private
  7619. * @param {string} collectionKey
  7620. * @return {string}
  7621. */
  7622. getAxisDescriptionText: function (collectionKey) {
  7623. var chart = this.chart;
  7624. var axes = chart[collectionKey];
  7625. return chart.langFormat('accessibility.axis.' + collectionKey + 'Description' + (axes.length > 1 ? 'Plural' : 'Singular'), {
  7626. chart: chart,
  7627. names: axes.map(function (axis) {
  7628. return getAxisDescription(axis);
  7629. }),
  7630. ranges: axes.map(function (axis) {
  7631. return getAxisRangeDescription(axis);
  7632. }),
  7633. numAxes: axes.length
  7634. });
  7635. },
  7636. /**
  7637. * Remove component traces
  7638. */
  7639. destroy: function () {
  7640. var _a;
  7641. (_a = this.announcer) === null || _a === void 0 ? void 0 : _a.destroy();
  7642. }
  7643. });
  7644. return InfoRegionsComponent;
  7645. });
  7646. _registerModule(_modules, 'Accessibility/Components/ContainerComponent.js', [_modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/Utils/ChartUtilities.js'], _modules['Core/Globals.js'], _modules['Accessibility/Utils/HTMLUtilities.js'], _modules['Core/Utilities.js']], function (AccessibilityComponent, ChartUtilities, H, HTMLUtilities, U) {
  7647. /* *
  7648. *
  7649. * (c) 2009-2021 Øystein Moseng
  7650. *
  7651. * Accessibility component for chart container.
  7652. *
  7653. * License: www.highcharts.com/license
  7654. *
  7655. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7656. *
  7657. * */
  7658. var unhideChartElementFromAT = ChartUtilities.unhideChartElementFromAT,
  7659. getChartTitle = ChartUtilities.getChartTitle;
  7660. var doc = H.doc;
  7661. var stripHTMLTags = HTMLUtilities.stripHTMLTagsFromString;
  7662. var extend = U.extend;
  7663. /* eslint-disable valid-jsdoc */
  7664. /**
  7665. * The ContainerComponent class
  7666. *
  7667. * @private
  7668. * @class
  7669. * @name Highcharts.ContainerComponent
  7670. */
  7671. var ContainerComponent = function () { };
  7672. ContainerComponent.prototype = new AccessibilityComponent();
  7673. extend(ContainerComponent.prototype, /** @lends Highcharts.ContainerComponent */ {
  7674. /**
  7675. * Called on first render/updates to the chart, including options changes.
  7676. */
  7677. onChartUpdate: function () {
  7678. this.handleSVGTitleElement();
  7679. this.setSVGContainerLabel();
  7680. this.setGraphicContainerAttrs();
  7681. this.setRenderToAttrs();
  7682. this.makeCreditsAccessible();
  7683. },
  7684. /**
  7685. * @private
  7686. */
  7687. handleSVGTitleElement: function () {
  7688. var chart = this.chart, titleId = 'highcharts-title-' + chart.index, titleContents = stripHTMLTags(chart.langFormat('accessibility.svgContainerTitle', {
  7689. chartTitle: getChartTitle(chart)
  7690. }));
  7691. if (titleContents.length) {
  7692. var titleElement = this.svgTitleElement =
  7693. this.svgTitleElement || doc.createElementNS('http://www.w3.org/2000/svg', 'title');
  7694. titleElement.textContent = titleContents;
  7695. titleElement.id = titleId;
  7696. chart.renderTo.insertBefore(titleElement, chart.renderTo.firstChild);
  7697. }
  7698. },
  7699. /**
  7700. * @private
  7701. */
  7702. setSVGContainerLabel: function () {
  7703. var chart = this.chart,
  7704. svgContainerLabel = chart.langFormat('accessibility.svgContainerLabel', {
  7705. chartTitle: getChartTitle(chart)
  7706. });
  7707. if (chart.renderer.box && svgContainerLabel.length) {
  7708. chart.renderer.box.setAttribute('aria-label', svgContainerLabel);
  7709. }
  7710. },
  7711. /**
  7712. * @private
  7713. */
  7714. setGraphicContainerAttrs: function () {
  7715. var chart = this.chart,
  7716. label = chart.langFormat('accessibility.graphicContainerLabel', {
  7717. chartTitle: getChartTitle(chart)
  7718. });
  7719. if (label.length) {
  7720. chart.container.setAttribute('aria-label', label);
  7721. }
  7722. },
  7723. /**
  7724. * @private
  7725. */
  7726. setRenderToAttrs: function () {
  7727. var chart = this.chart;
  7728. if (chart.options.accessibility.landmarkVerbosity !== 'disabled') {
  7729. chart.renderTo.setAttribute('role', 'region');
  7730. }
  7731. else {
  7732. chart.renderTo.removeAttribute('role');
  7733. }
  7734. chart.renderTo.setAttribute('aria-label', chart.langFormat('accessibility.chartContainerLabel', {
  7735. title: getChartTitle(chart),
  7736. chart: chart
  7737. }));
  7738. },
  7739. /**
  7740. * @private
  7741. */
  7742. makeCreditsAccessible: function () {
  7743. var chart = this.chart,
  7744. credits = chart.credits;
  7745. if (credits) {
  7746. if (credits.textStr) {
  7747. credits.element.setAttribute('aria-label', chart.langFormat('accessibility.credits', { creditsStr: stripHTMLTags(credits.textStr) }));
  7748. }
  7749. unhideChartElementFromAT(chart, credits.element);
  7750. }
  7751. },
  7752. /**
  7753. * Accessibility disabled/chart destroyed.
  7754. */
  7755. destroy: function () {
  7756. this.chart.renderTo.setAttribute('aria-hidden', true);
  7757. }
  7758. });
  7759. return ContainerComponent;
  7760. });
  7761. _registerModule(_modules, 'Accessibility/HighContrastMode.js', [_modules['Core/Globals.js']], function (H) {
  7762. /* *
  7763. *
  7764. * (c) 2009-2021 Øystein Moseng
  7765. *
  7766. * Handling for Windows High Contrast Mode.
  7767. *
  7768. * License: www.highcharts.com/license
  7769. *
  7770. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7771. *
  7772. * */
  7773. var doc = H.doc,
  7774. isMS = H.isMS,
  7775. win = H.win;
  7776. var whcm = {
  7777. /**
  7778. * Detect WHCM in the browser.
  7779. *
  7780. * @function Highcharts#isHighContrastModeActive
  7781. * @private
  7782. * @return {boolean} Returns true if the browser is in High Contrast mode.
  7783. */
  7784. isHighContrastModeActive: function () {
  7785. // Use media query on Edge, but not on IE
  7786. var isEdge = /(Edg)/.test(win.navigator.userAgent);
  7787. if (win.matchMedia && isEdge) {
  7788. return win.matchMedia('(-ms-high-contrast: active)').matches;
  7789. }
  7790. // Test BG image for IE
  7791. if (isMS && win.getComputedStyle) {
  7792. var testDiv = doc.createElement('div');
  7793. var imageSrc = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
  7794. testDiv.style.backgroundImage = "url(" + imageSrc + ")"; // #13071
  7795. doc.body.appendChild(testDiv);
  7796. var bi = (testDiv.currentStyle ||
  7797. win.getComputedStyle(testDiv)).backgroundImage;
  7798. doc.body.removeChild(testDiv);
  7799. return bi === 'none';
  7800. }
  7801. // Not used for other browsers
  7802. return false;
  7803. },
  7804. /**
  7805. * Force high contrast theme for the chart. The default theme is defined in
  7806. * a separate file.
  7807. *
  7808. * @function Highcharts#setHighContrastTheme
  7809. * @private
  7810. * @param {Highcharts.AccessibilityChart} chart The chart to set the theme of.
  7811. * @return {void}
  7812. */
  7813. setHighContrastTheme: function (chart) {
  7814. // We might want to add additional functionality here in the future for
  7815. // storing the old state so that we can reset the theme if HC mode is
  7816. // disabled. For now, the user will have to reload the page.
  7817. chart.highContrastModeActive = true;
  7818. // Apply theme to chart
  7819. var theme = (chart.options.accessibility.highContrastTheme);
  7820. chart.update(theme, false);
  7821. // Force series colors (plotOptions is not enough)
  7822. chart.series.forEach(function (s) {
  7823. var plotOpts = theme.plotOptions[s.type] || {};
  7824. s.update({
  7825. color: plotOpts.color || 'windowText',
  7826. colors: [plotOpts.color || 'windowText'],
  7827. borderColor: plotOpts.borderColor || 'window'
  7828. });
  7829. // Force point colors if existing
  7830. s.points.forEach(function (p) {
  7831. if (p.options && p.options.color) {
  7832. p.update({
  7833. color: plotOpts.color || 'windowText',
  7834. borderColor: plotOpts.borderColor || 'window'
  7835. }, false);
  7836. }
  7837. });
  7838. });
  7839. // The redraw for each series and after is required for 3D pie
  7840. // (workaround)
  7841. chart.redraw();
  7842. }
  7843. };
  7844. return whcm;
  7845. });
  7846. _registerModule(_modules, 'Accessibility/HighContrastTheme.js', [], function () {
  7847. /* *
  7848. *
  7849. * (c) 2009-2021 Øystein Moseng
  7850. *
  7851. * Default theme for Windows High Contrast Mode.
  7852. *
  7853. * License: www.highcharts.com/license
  7854. *
  7855. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7856. *
  7857. * */
  7858. var theme = {
  7859. chart: {
  7860. backgroundColor: 'window'
  7861. },
  7862. title: {
  7863. style: {
  7864. color: 'windowText'
  7865. }
  7866. },
  7867. subtitle: {
  7868. style: {
  7869. color: 'windowText'
  7870. }
  7871. },
  7872. colorAxis: {
  7873. minColor: 'windowText',
  7874. maxColor: 'windowText',
  7875. stops: []
  7876. },
  7877. colors: ['windowText'],
  7878. xAxis: {
  7879. gridLineColor: 'windowText',
  7880. labels: {
  7881. style: {
  7882. color: 'windowText'
  7883. }
  7884. },
  7885. lineColor: 'windowText',
  7886. minorGridLineColor: 'windowText',
  7887. tickColor: 'windowText',
  7888. title: {
  7889. style: {
  7890. color: 'windowText'
  7891. }
  7892. }
  7893. },
  7894. yAxis: {
  7895. gridLineColor: 'windowText',
  7896. labels: {
  7897. style: {
  7898. color: 'windowText'
  7899. }
  7900. },
  7901. lineColor: 'windowText',
  7902. minorGridLineColor: 'windowText',
  7903. tickColor: 'windowText',
  7904. title: {
  7905. style: {
  7906. color: 'windowText'
  7907. }
  7908. }
  7909. },
  7910. tooltip: {
  7911. backgroundColor: 'window',
  7912. borderColor: 'windowText',
  7913. style: {
  7914. color: 'windowText'
  7915. }
  7916. },
  7917. plotOptions: {
  7918. series: {
  7919. lineColor: 'windowText',
  7920. fillColor: 'window',
  7921. borderColor: 'windowText',
  7922. edgeColor: 'windowText',
  7923. borderWidth: 1,
  7924. dataLabels: {
  7925. connectorColor: 'windowText',
  7926. color: 'windowText',
  7927. style: {
  7928. color: 'windowText',
  7929. textOutline: 'none'
  7930. }
  7931. },
  7932. marker: {
  7933. lineColor: 'windowText',
  7934. fillColor: 'windowText'
  7935. }
  7936. },
  7937. pie: {
  7938. color: 'window',
  7939. colors: ['window'],
  7940. borderColor: 'windowText',
  7941. borderWidth: 1
  7942. },
  7943. boxplot: {
  7944. fillColor: 'window'
  7945. },
  7946. candlestick: {
  7947. lineColor: 'windowText',
  7948. fillColor: 'window'
  7949. },
  7950. errorbar: {
  7951. fillColor: 'window'
  7952. }
  7953. },
  7954. legend: {
  7955. backgroundColor: 'window',
  7956. itemStyle: {
  7957. color: 'windowText'
  7958. },
  7959. itemHoverStyle: {
  7960. color: 'windowText'
  7961. },
  7962. itemHiddenStyle: {
  7963. color: '#555'
  7964. },
  7965. title: {
  7966. style: {
  7967. color: 'windowText'
  7968. }
  7969. }
  7970. },
  7971. credits: {
  7972. style: {
  7973. color: 'windowText'
  7974. }
  7975. },
  7976. labels: {
  7977. style: {
  7978. color: 'windowText'
  7979. }
  7980. },
  7981. drilldown: {
  7982. activeAxisLabelStyle: {
  7983. color: 'windowText'
  7984. },
  7985. activeDataLabelStyle: {
  7986. color: 'windowText'
  7987. }
  7988. },
  7989. navigation: {
  7990. buttonOptions: {
  7991. symbolStroke: 'windowText',
  7992. theme: {
  7993. fill: 'window'
  7994. }
  7995. }
  7996. },
  7997. rangeSelector: {
  7998. buttonTheme: {
  7999. fill: 'window',
  8000. stroke: 'windowText',
  8001. style: {
  8002. color: 'windowText'
  8003. },
  8004. states: {
  8005. hover: {
  8006. fill: 'window',
  8007. stroke: 'windowText',
  8008. style: {
  8009. color: 'windowText'
  8010. }
  8011. },
  8012. select: {
  8013. fill: '#444',
  8014. stroke: 'windowText',
  8015. style: {
  8016. color: 'windowText'
  8017. }
  8018. }
  8019. }
  8020. },
  8021. inputBoxBorderColor: 'windowText',
  8022. inputStyle: {
  8023. backgroundColor: 'window',
  8024. color: 'windowText'
  8025. },
  8026. labelStyle: {
  8027. color: 'windowText'
  8028. }
  8029. },
  8030. navigator: {
  8031. handles: {
  8032. backgroundColor: 'window',
  8033. borderColor: 'windowText'
  8034. },
  8035. outlineColor: 'windowText',
  8036. maskFill: 'transparent',
  8037. series: {
  8038. color: 'windowText',
  8039. lineColor: 'windowText'
  8040. },
  8041. xAxis: {
  8042. gridLineColor: 'windowText'
  8043. }
  8044. },
  8045. scrollbar: {
  8046. barBackgroundColor: '#444',
  8047. barBorderColor: 'windowText',
  8048. buttonArrowColor: 'windowText',
  8049. buttonBackgroundColor: 'window',
  8050. buttonBorderColor: 'windowText',
  8051. rifleColor: 'windowText',
  8052. trackBackgroundColor: 'window',
  8053. trackBorderColor: 'windowText'
  8054. }
  8055. };
  8056. return theme;
  8057. });
  8058. _registerModule(_modules, 'Accessibility/Options/Options.js', [_modules['Core/Color/Palette.js']], function (palette) {
  8059. /* *
  8060. *
  8061. * (c) 2009-2021 Øystein Moseng
  8062. *
  8063. * Default options for accessibility.
  8064. *
  8065. * License: www.highcharts.com/license
  8066. *
  8067. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8068. *
  8069. * */
  8070. /**
  8071. * Formatter callback for the accessibility announcement.
  8072. *
  8073. * @callback Highcharts.AccessibilityAnnouncementFormatter
  8074. *
  8075. * @param {Array<Highcharts.Series>} updatedSeries
  8076. * Array of all series that received updates. If an announcement is already
  8077. * queued, the series that received updates for that announcement are also
  8078. * included in this array.
  8079. *
  8080. * @param {Highcharts.Series} [addedSeries]
  8081. * This is provided if {@link Highcharts.Chart#addSeries} was called, and there
  8082. * is a new series. In that case, this argument is a reference to the new
  8083. * series.
  8084. *
  8085. * @param {Highcharts.Point} [addedPoint]
  8086. * This is provided if {@link Highcharts.Series#addPoint} was called, and there
  8087. * is a new point. In that case, this argument is a reference to the new point.
  8088. *
  8089. * @return {false|string}
  8090. * The function should return a string with the text to announce to the user.
  8091. * Return empty string to not announce anything. Return `false` to use the
  8092. * default announcement format.
  8093. */
  8094. /**
  8095. * @interface Highcharts.PointAccessibilityOptionsObject
  8096. */ /**
  8097. * Provide a description of the data point, announced to screen readers.
  8098. * @name Highcharts.PointAccessibilityOptionsObject#description
  8099. * @type {string|undefined}
  8100. * @requires modules/accessibility
  8101. * @since 7.1.0
  8102. */ /**
  8103. * Enable or disable exposing the point to assistive technology
  8104. * @name Highcharts.PointAccessibilityOptionsObject#enabled
  8105. * @type {boolean|undefined}
  8106. * @requires modules/accessibility
  8107. * @since 9.0.1
  8108. */
  8109. /* *
  8110. * @interface Highcharts.PointOptionsObject in parts/Point.ts
  8111. */ /**
  8112. * @name Highcharts.PointOptionsObject#accessibility
  8113. * @type {Highcharts.PointAccessibilityOptionsObject|undefined}
  8114. * @requires modules/accessibility
  8115. * @since 7.1.0
  8116. */
  8117. /**
  8118. * @callback Highcharts.ScreenReaderClickCallbackFunction
  8119. *
  8120. * @param {global.MouseEvent} evt
  8121. * Mouse click event
  8122. *
  8123. * @return {void}
  8124. */
  8125. /**
  8126. * Creates a formatted string for the screen reader module.
  8127. *
  8128. * @callback Highcharts.ScreenReaderFormatterCallbackFunction<T>
  8129. *
  8130. * @param {T} context
  8131. * Context to format
  8132. *
  8133. * @return {string}
  8134. * Formatted string for the screen reader module.
  8135. */
  8136. var options = {
  8137. /**
  8138. * Options for configuring accessibility for the chart. Requires the
  8139. * [accessibility module](https://code.highcharts.com/modules/accessibility.js)
  8140. * to be loaded. For a description of the module and information
  8141. * on its features, see
  8142. * [Highcharts Accessibility](https://www.highcharts.com/docs/accessibility/accessibility-module).
  8143. *
  8144. * @since 5.0.0
  8145. * @requires modules/accessibility
  8146. * @optionparent accessibility
  8147. */
  8148. accessibility: {
  8149. /**
  8150. * Enable accessibility functionality for the chart.
  8151. *
  8152. * @since 5.0.0
  8153. */
  8154. enabled: true,
  8155. /**
  8156. * Accessibility options for the screen reader information sections
  8157. * added before and after the chart.
  8158. *
  8159. * @since 8.0.0
  8160. */
  8161. screenReaderSection: {
  8162. /**
  8163. * Function to run upon clicking the "View as Data Table" link in
  8164. * the screen reader region.
  8165. *
  8166. * By default Highcharts will insert and set focus to a data table
  8167. * representation of the chart.
  8168. *
  8169. * @type {Highcharts.ScreenReaderClickCallbackFunction}
  8170. * @since 8.0.0
  8171. * @apioption accessibility.screenReaderSection.onViewDataTableClick
  8172. */
  8173. /**
  8174. * Function to run upon clicking the "Play as sound" button in
  8175. * the screen reader region.
  8176. *
  8177. * By default Highcharts will call the `chart.sonify` function.
  8178. *
  8179. * @type {Highcharts.ScreenReaderClickCallbackFunction}
  8180. * @since 8.0.1
  8181. * @apioption accessibility.screenReaderSection.onPlayAsSoundClick
  8182. */
  8183. /**
  8184. * A formatter function to create the HTML contents of the hidden
  8185. * screen reader information region before the chart. Receives one
  8186. * argument, `chart`, referring to the chart object. Should return a
  8187. * string with the HTML content of the region. By default this
  8188. * returns an automatic description of the chart based on
  8189. * [beforeChartFormat](#accessibility.screenReaderSection.beforeChartFormat).
  8190. *
  8191. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Chart>}
  8192. * @since 8.0.0
  8193. * @apioption accessibility.screenReaderSection.beforeChartFormatter
  8194. */
  8195. /**
  8196. * Format for the screen reader information region before the chart.
  8197. * Supported HTML tags are `<h1-6>`, `<p>`, `<div>`, `<a>`, `<ul>`,
  8198. * `<ol>`, `<li>`, and `<button>`. Attributes are not supported,
  8199. * except for id on `<div>`, `<a>`, and `<button>`. Id is required
  8200. * on `<a>` and `<button>` in the format `<tag id="abcd">`. Numbers,
  8201. * lower- and uppercase letters, "-" and "#" are valid characters in
  8202. * IDs.
  8203. *
  8204. * The headingTagName is an auto-detected heading (h1-h6) that
  8205. * corresponds to the heading level below the previous heading in
  8206. * the DOM.
  8207. *
  8208. * @since 8.0.0
  8209. */
  8210. beforeChartFormat: '<{headingTagName}>{chartTitle}</{headingTagName}>' +
  8211. '<div>{typeDescription}</div>' +
  8212. '<div>{chartSubtitle}</div>' +
  8213. '<div>{chartLongdesc}</div>' +
  8214. '<div>{playAsSoundButton}</div>' +
  8215. '<div>{viewTableButton}</div>' +
  8216. '<div>{xAxisDescription}</div>' +
  8217. '<div>{yAxisDescription}</div>' +
  8218. '<div>{annotationsTitle}{annotationsList}</div>',
  8219. /**
  8220. * A formatter function to create the HTML contents of the hidden
  8221. * screen reader information region after the chart. Analogous to
  8222. * [beforeChartFormatter](#accessibility.screenReaderSection.beforeChartFormatter).
  8223. *
  8224. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Chart>}
  8225. * @since 8.0.0
  8226. * @apioption accessibility.screenReaderSection.afterChartFormatter
  8227. */
  8228. /**
  8229. * Format for the screen reader information region after the chart.
  8230. * Analogous to [beforeChartFormat](#accessibility.screenReaderSection.beforeChartFormat).
  8231. *
  8232. * @since 8.0.0
  8233. */
  8234. afterChartFormat: '{endOfChartMarker}',
  8235. /**
  8236. * Date format to use to describe range of datetime axes.
  8237. *
  8238. * For an overview of the replacement codes, see
  8239. * [dateFormat](/class-reference/Highcharts#dateFormat).
  8240. *
  8241. * @see [point.dateFormat](#accessibility.point.dateFormat)
  8242. *
  8243. * @since 8.0.0
  8244. */
  8245. axisRangeDateFormat: '%Y-%m-%d %H:%M:%S'
  8246. },
  8247. /**
  8248. * Accessibility options global to all data series. Individual series
  8249. * can also have specific [accessibility options](#plotOptions.series.accessibility)
  8250. * set.
  8251. *
  8252. * @since 8.0.0
  8253. */
  8254. series: {
  8255. /**
  8256. * Formatter function to use instead of the default for series
  8257. * descriptions. Receives one argument, `series`, referring to the
  8258. * series to describe. Should return a string with the description
  8259. * of the series for a screen reader user. If `false` is returned,
  8260. * the default formatter will be used for that series.
  8261. *
  8262. * @see [series.description](#plotOptions.series.description)
  8263. *
  8264. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Series>}
  8265. * @since 8.0.0
  8266. * @apioption accessibility.series.descriptionFormatter
  8267. */
  8268. /**
  8269. * Whether or not to add series descriptions to charts with a single
  8270. * series.
  8271. *
  8272. * @since 8.0.0
  8273. */
  8274. describeSingleSeries: false,
  8275. /**
  8276. * When a series contains more points than this, we no longer expose
  8277. * information about individual points to screen readers.
  8278. *
  8279. * Set to `false` to disable.
  8280. *
  8281. * @type {boolean|number}
  8282. * @since 8.0.0
  8283. */
  8284. pointDescriptionEnabledThreshold: 200
  8285. },
  8286. /**
  8287. * Options for descriptions of individual data points.
  8288. *
  8289. * @since 8.0.0
  8290. */
  8291. point: {
  8292. /**
  8293. * Date format to use for points on datetime axes when describing
  8294. * them to screen reader users.
  8295. *
  8296. * Defaults to the same format as in tooltip.
  8297. *
  8298. * For an overview of the replacement codes, see
  8299. * [dateFormat](/class-reference/Highcharts#dateFormat).
  8300. *
  8301. * @see [dateFormatter](#accessibility.point.dateFormatter)
  8302. *
  8303. * @type {string}
  8304. * @since 8.0.0
  8305. * @apioption accessibility.point.dateFormat
  8306. */
  8307. /**
  8308. * Formatter function to determine the date/time format used with
  8309. * points on datetime axes when describing them to screen reader
  8310. * users. Receives one argument, `point`, referring to the point
  8311. * to describe. Should return a date format string compatible with
  8312. * [dateFormat](/class-reference/Highcharts#dateFormat).
  8313. *
  8314. * @see [dateFormat](#accessibility.point.dateFormat)
  8315. *
  8316. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Point>}
  8317. * @since 8.0.0
  8318. * @apioption accessibility.point.dateFormatter
  8319. */
  8320. /**
  8321. * Prefix to add to the values in the point descriptions. Uses
  8322. * [tooltip.valuePrefix](#tooltip.valuePrefix) if not defined.
  8323. *
  8324. * @type {string}
  8325. * @since 8.0.0
  8326. * @apioption accessibility.point.valuePrefix
  8327. */
  8328. /**
  8329. * Suffix to add to the values in the point descriptions. Uses
  8330. * [tooltip.valueSuffix](#tooltip.valueSuffix) if not defined.
  8331. *
  8332. * @type {string}
  8333. * @since 8.0.0
  8334. * @apioption accessibility.point.valueSuffix
  8335. */
  8336. /**
  8337. * Decimals to use for the values in the point descriptions. Uses
  8338. * [tooltip.valueDecimals](#tooltip.valueDecimals) if not defined.
  8339. *
  8340. * @type {number}
  8341. * @since 8.0.0
  8342. * @apioption accessibility.point.valueDecimals
  8343. */
  8344. /**
  8345. * Formatter function to use instead of the default for point
  8346. * descriptions.
  8347. *
  8348. * Receives one argument, `point`, referring to the point to
  8349. * describe. Should return a string with the description of the
  8350. * point for a screen reader user. If `false` is returned, the
  8351. * default formatter will be used for that point.
  8352. *
  8353. * Note: Prefer using [accessibility.point.valueDescriptionFormat](#accessibility.point.valueDescriptionFormat)
  8354. * instead if possible, as default functionality such as describing
  8355. * annotations will be preserved.
  8356. *
  8357. * @see [accessibility.point.valueDescriptionFormat](#accessibility.point.valueDescriptionFormat)
  8358. * @see [point.accessibility.description](#series.line.data.accessibility.description)
  8359. *
  8360. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Point>}
  8361. * @since 8.0.0
  8362. * @apioption accessibility.point.descriptionFormatter
  8363. */
  8364. /**
  8365. * Format to use for describing the values of data points
  8366. * to assistive technology - including screen readers.
  8367. * The point context is available as `{point}`.
  8368. *
  8369. * Additionally, the series name, annotation info, and
  8370. * description added in `point.accessibility.description`
  8371. * is added by default if relevant. To override this, use the
  8372. * [accessibility.point.descriptionFormatter](#accessibility.point.descriptionFormatter)
  8373. * option.
  8374. *
  8375. * @see [point.accessibility.description](#series.line.data.accessibility.description)
  8376. * @see [accessibility.point.descriptionFormatter](#accessibility.point.descriptionFormatter)
  8377. *
  8378. * @type {string}
  8379. * @since 8.0.1
  8380. */
  8381. valueDescriptionFormat: '{index}. {xDescription}{separator}{value}.'
  8382. },
  8383. /**
  8384. * Amount of landmarks/regions to create for screen reader users. More
  8385. * landmarks can make navigation with screen readers easier, but can
  8386. * be distracting if there are lots of charts on the page. Three modes
  8387. * are available:
  8388. * - `all`: Adds regions for all series, legend, menu, information
  8389. * region.
  8390. * - `one`: Adds a single landmark per chart.
  8391. * - `disabled`: No landmarks are added.
  8392. *
  8393. * @since 7.1.0
  8394. * @validvalue ["all", "one", "disabled"]
  8395. */
  8396. landmarkVerbosity: 'all',
  8397. /**
  8398. * Link the chart to an HTML element describing the contents of the
  8399. * chart.
  8400. *
  8401. * It is always recommended to describe charts using visible text, to
  8402. * improve SEO as well as accessibility for users with disabilities.
  8403. * This option lets an HTML element with a description be linked to the
  8404. * chart, so that screen reader users can connect the two.
  8405. *
  8406. * By setting this option to a string, Highcharts runs the string as an
  8407. * HTML selector query on the entire document. If there is only a single
  8408. * match, this element is linked to the chart. The content of the linked
  8409. * element will be included in the chart description for screen reader
  8410. * users.
  8411. *
  8412. * By default, the chart looks for an adjacent sibling element with the
  8413. * `highcharts-description` class.
  8414. *
  8415. * The feature can be disabled by setting the option to an empty string,
  8416. * or overridden by providing the
  8417. * [accessibility.description](#accessibility.description) option.
  8418. * Alternatively, the HTML element to link can be passed in directly as
  8419. * an HTML node.
  8420. *
  8421. * If you need the description to be part of the exported image,
  8422. * consider using the [caption](#caption) feature.
  8423. *
  8424. * If you need the description to be hidden visually, use the
  8425. * [accessibility.description](#accessibility.description) option.
  8426. *
  8427. * @see [caption](#caption)
  8428. * @see [description](#accessibility.description)
  8429. * @see [typeDescription](#accessibility.typeDescription)
  8430. *
  8431. * @sample highcharts/accessibility/accessible-line
  8432. * Accessible line chart
  8433. *
  8434. * @type {string|Highcharts.HTMLDOMElement}
  8435. * @since 8.0.0
  8436. */
  8437. linkedDescription: '*[data-highcharts-chart="{index}"] + .highcharts-description',
  8438. /**
  8439. * A hook for adding custom components to the accessibility module.
  8440. * Should be an object mapping component names to instances of classes
  8441. * inheriting from the Highcharts.AccessibilityComponent base class.
  8442. * Remember to add the component to the
  8443. * [keyboardNavigation.order](#accessibility.keyboardNavigation.order)
  8444. * for the keyboard navigation to be usable.
  8445. *
  8446. * @sample highcharts/accessibility/custom-component
  8447. * Custom accessibility component
  8448. *
  8449. * @type {*}
  8450. * @since 7.1.0
  8451. * @apioption accessibility.customComponents
  8452. */
  8453. /**
  8454. * Theme to apply to the chart when Windows High Contrast Mode is
  8455. * detected. By default, a high contrast theme matching the high
  8456. * contrast system system colors is used.
  8457. *
  8458. * @type {*}
  8459. * @since 7.1.3
  8460. * @apioption accessibility.highContrastTheme
  8461. */
  8462. /**
  8463. * A text description of the chart.
  8464. *
  8465. * **Note: Prefer using [linkedDescription](#accessibility.linkedDescription)
  8466. * or [caption](#caption.text) instead.**
  8467. *
  8468. * If the Accessibility module is loaded, this option is included by
  8469. * default as a long description of the chart in the hidden screen
  8470. * reader information region.
  8471. *
  8472. * Note: Since Highcharts now supports captions and linked descriptions,
  8473. * it is preferred to define the description using those methods, as a
  8474. * visible caption/description benefits all users. If the
  8475. * `accessibility.description` option is defined, the linked description
  8476. * is ignored, and the caption is hidden from screen reader users.
  8477. *
  8478. * @see [linkedDescription](#accessibility.linkedDescription)
  8479. * @see [caption](#caption)
  8480. * @see [typeDescription](#accessibility.typeDescription)
  8481. *
  8482. * @type {string}
  8483. * @since 5.0.0
  8484. * @apioption accessibility.description
  8485. */
  8486. /**
  8487. * A text description of the chart type.
  8488. *
  8489. * If the Accessibility module is loaded, this will be included in the
  8490. * description of the chart in the screen reader information region.
  8491. *
  8492. * Highcharts will by default attempt to guess the chart type, but for
  8493. * more complex charts it is recommended to specify this property for
  8494. * clarity.
  8495. *
  8496. * @type {string}
  8497. * @since 5.0.0
  8498. * @apioption accessibility.typeDescription
  8499. */
  8500. /**
  8501. * Options for keyboard navigation.
  8502. *
  8503. * @declare Highcharts.KeyboardNavigationOptionsObject
  8504. * @since 5.0.0
  8505. */
  8506. keyboardNavigation: {
  8507. /**
  8508. * Enable keyboard navigation for the chart.
  8509. *
  8510. * @since 5.0.0
  8511. */
  8512. enabled: true,
  8513. /**
  8514. * Options for the focus border drawn around elements while
  8515. * navigating through them.
  8516. *
  8517. * @sample highcharts/accessibility/custom-focus
  8518. * Custom focus ring
  8519. *
  8520. * @declare Highcharts.KeyboardNavigationFocusBorderOptionsObject
  8521. * @since 6.0.3
  8522. */
  8523. focusBorder: {
  8524. /**
  8525. * Enable/disable focus border for chart.
  8526. *
  8527. * @since 6.0.3
  8528. */
  8529. enabled: true,
  8530. /**
  8531. * Hide the browser's default focus indicator.
  8532. *
  8533. * @since 6.0.4
  8534. */
  8535. hideBrowserFocusOutline: true,
  8536. /**
  8537. * Style options for the focus border drawn around elements
  8538. * while navigating through them. Note that some browsers in
  8539. * addition draw their own borders for focused elements. These
  8540. * automatic borders can not be styled by Highcharts.
  8541. *
  8542. * In styled mode, the border is given the
  8543. * `.highcharts-focus-border` class.
  8544. *
  8545. * @type {Highcharts.CSSObject}
  8546. * @since 6.0.3
  8547. */
  8548. style: {
  8549. /** @internal */
  8550. color: palette.highlightColor80,
  8551. /** @internal */
  8552. lineWidth: 2,
  8553. /** @internal */
  8554. borderRadius: 3
  8555. },
  8556. /**
  8557. * Focus border margin around the elements.
  8558. *
  8559. * @since 6.0.3
  8560. */
  8561. margin: 2
  8562. },
  8563. /**
  8564. * Order of tab navigation in the chart. Determines which elements
  8565. * are tabbed to first. Available elements are: `series`, `zoom`,
  8566. * `rangeSelector`, `chartMenu`, `legend`. In addition, any custom
  8567. * components can be added here.
  8568. *
  8569. * @type {Array<string>}
  8570. * @since 7.1.0
  8571. */
  8572. order: ['series', 'zoom', 'rangeSelector', 'legend', 'chartMenu'],
  8573. /**
  8574. * Whether or not to wrap around when reaching the end of arrow-key
  8575. * navigation for an element in the chart.
  8576. * @since 7.1.0
  8577. */
  8578. wrapAround: true,
  8579. /**
  8580. * Options for the keyboard navigation of data points and series.
  8581. *
  8582. * @declare Highcharts.KeyboardNavigationSeriesNavigationOptionsObject
  8583. * @since 8.0.0
  8584. */
  8585. seriesNavigation: {
  8586. /**
  8587. * Set the keyboard navigation mode for the chart. Can be
  8588. * "normal" or "serialize". In normal mode, left/right arrow
  8589. * keys move between points in a series, while up/down arrow
  8590. * keys move between series. Up/down navigation acts
  8591. * intelligently to figure out which series makes sense to move
  8592. * to from any given point.
  8593. *
  8594. * In "serialize" mode, points are instead navigated as a single
  8595. * list. Left/right behaves as in "normal" mode. Up/down arrow
  8596. * keys will behave like left/right. This can be useful for
  8597. * unifying navigation behavior with/without screen readers
  8598. * enabled.
  8599. *
  8600. * @type {string}
  8601. * @default normal
  8602. * @since 8.0.0
  8603. * @validvalue ["normal", "serialize"]
  8604. * @apioption accessibility.keyboardNavigation.seriesNavigation.mode
  8605. */
  8606. /**
  8607. * Skip null points when navigating through points with the
  8608. * keyboard.
  8609. *
  8610. * @since 8.0.0
  8611. */
  8612. skipNullPoints: true,
  8613. /**
  8614. * When a series contains more points than this, we no longer
  8615. * allow keyboard navigation for it.
  8616. *
  8617. * Set to `false` to disable.
  8618. *
  8619. * @type {boolean|number}
  8620. * @since 8.0.0
  8621. */
  8622. pointNavigationEnabledThreshold: false
  8623. }
  8624. },
  8625. /**
  8626. * Options for announcing new data to screen reader users. Useful
  8627. * for dynamic data applications and drilldown.
  8628. *
  8629. * Keep in mind that frequent announcements will not be useful to
  8630. * users, as they won't have time to explore the new data. For these
  8631. * applications, consider making snapshots of the data accessible, and
  8632. * do the announcements in batches.
  8633. *
  8634. * @declare Highcharts.AccessibilityAnnounceNewDataOptionsObject
  8635. * @since 7.1.0
  8636. */
  8637. announceNewData: {
  8638. /**
  8639. * Optional formatter callback for the announcement. Receives
  8640. * up to three arguments. The first argument is always an array
  8641. * of all series that received updates. If an announcement is
  8642. * already queued, the series that received updates for that
  8643. * announcement are also included in this array. The second
  8644. * argument is provided if `chart.addSeries` was called, and
  8645. * there is a new series. In that case, this argument is a
  8646. * reference to the new series. The third argument, similarly,
  8647. * is provided if `series.addPoint` was called, and there is a
  8648. * new point. In that case, this argument is a reference to the
  8649. * new point.
  8650. *
  8651. * The function should return a string with the text to announce
  8652. * to the user. Return empty string to not announce anything.
  8653. * Return `false` to use the default announcement format.
  8654. *
  8655. * @sample highcharts/accessibility/custom-dynamic
  8656. * High priority live alerts
  8657. *
  8658. * @type {Highcharts.AccessibilityAnnouncementFormatter}
  8659. * @apioption accessibility.announceNewData.announcementFormatter
  8660. */
  8661. /**
  8662. * Enable announcing new data to screen reader users
  8663. * @sample highcharts/accessibility/accessible-dynamic
  8664. * Dynamic data accessible
  8665. */
  8666. enabled: false,
  8667. /**
  8668. * Minimum interval between announcements in milliseconds. If
  8669. * new data arrives before this amount of time has passed, it is
  8670. * queued for announcement. If another new data event happens
  8671. * while an announcement is queued, the queued announcement is
  8672. * dropped, and the latest announcement is queued instead. Set
  8673. * to 0 to allow all announcements, but be warned that frequent
  8674. * announcements are disturbing to users.
  8675. */
  8676. minAnnounceInterval: 5000,
  8677. /**
  8678. * Choose whether or not the announcements should interrupt the
  8679. * screen reader. If not enabled, the user will be notified once
  8680. * idle. It is recommended not to enable this setting unless
  8681. * there is a specific reason to do so.
  8682. */
  8683. interruptUser: false
  8684. }
  8685. },
  8686. /**
  8687. * Accessibility options for a data point.
  8688. *
  8689. * @declare Highcharts.PointAccessibilityOptionsObject
  8690. * @since 7.1.0
  8691. * @apioption series.line.data.accessibility
  8692. */
  8693. /**
  8694. * Provide a description of the data point, announced to screen readers.
  8695. *
  8696. * @type {string}
  8697. * @since 7.1.0
  8698. * @apioption series.line.data.accessibility.description
  8699. */
  8700. /**
  8701. * Set to false to disable accessibility functionality for a specific point.
  8702. * The point will not be included in keyboard navigation, and will not be
  8703. * exposed to assistive technology.
  8704. *
  8705. * @type {boolean}
  8706. * @since 9.0.1
  8707. * @apioption series.line.data.accessibility.enabled
  8708. */
  8709. /**
  8710. * Accessibility options for a series.
  8711. *
  8712. * @declare Highcharts.SeriesAccessibilityOptionsObject
  8713. * @since 7.1.0
  8714. * @requires modules/accessibility
  8715. * @apioption plotOptions.series.accessibility
  8716. */
  8717. /**
  8718. * Enable/disable accessibility functionality for a specific series.
  8719. *
  8720. * @type {boolean}
  8721. * @since 7.1.0
  8722. * @apioption plotOptions.series.accessibility.enabled
  8723. */
  8724. /**
  8725. * Provide a description of the series, announced to screen readers.
  8726. *
  8727. * @type {string}
  8728. * @since 7.1.0
  8729. * @apioption plotOptions.series.accessibility.description
  8730. */
  8731. /**
  8732. * Formatter function to use instead of the default for point
  8733. * descriptions. Same as `accessibility.point.descriptionFormatter`, but for
  8734. * a single series.
  8735. *
  8736. * @see [accessibility.point.descriptionFormatter](#accessibility.point.descriptionFormatter)
  8737. *
  8738. * @type {Highcharts.ScreenReaderFormatterCallbackFunction<Highcharts.Point>}
  8739. * @since 7.1.0
  8740. * @apioption plotOptions.series.accessibility.pointDescriptionFormatter
  8741. */
  8742. /**
  8743. * Expose only the series element to screen readers, not its points.
  8744. *
  8745. * @type {boolean}
  8746. * @since 7.1.0
  8747. * @apioption plotOptions.series.accessibility.exposeAsGroupOnly
  8748. */
  8749. /**
  8750. * Keyboard navigation for a series
  8751. *
  8752. * @declare Highcharts.SeriesAccessibilityKeyboardNavigationOptionsObject
  8753. * @since 7.1.0
  8754. * @apioption plotOptions.series.accessibility.keyboardNavigation
  8755. */
  8756. /**
  8757. * Enable/disable keyboard navigation support for a specific series.
  8758. *
  8759. * @type {boolean}
  8760. * @since 7.1.0
  8761. * @apioption plotOptions.series.accessibility.keyboardNavigation.enabled
  8762. */
  8763. /**
  8764. * Accessibility options for an annotation label.
  8765. *
  8766. * @declare Highcharts.AnnotationLabelAccessibilityOptionsObject
  8767. * @since 8.0.1
  8768. * @requires modules/accessibility
  8769. * @apioption annotations.labelOptions.accessibility
  8770. */
  8771. /**
  8772. * Description of an annotation label for screen readers and other assistive
  8773. * technology.
  8774. *
  8775. * @type {string}
  8776. * @since 8.0.1
  8777. * @apioption annotations.labelOptions.accessibility.description
  8778. */
  8779. /**
  8780. * Accessibility options for an axis. Requires the accessibility module.
  8781. *
  8782. * @declare Highcharts.AxisAccessibilityOptionsObject
  8783. * @since 7.1.0
  8784. * @requires modules/accessibility
  8785. * @apioption xAxis.accessibility
  8786. */
  8787. /**
  8788. * Enable axis accessibility features, including axis information in the
  8789. * screen reader information region. If this is disabled on the xAxis, the
  8790. * x values are not exposed to screen readers for the individual data points
  8791. * by default.
  8792. *
  8793. * @type {boolean}
  8794. * @since 7.1.0
  8795. * @apioption xAxis.accessibility.enabled
  8796. */
  8797. /**
  8798. * Description for an axis to expose to screen reader users.
  8799. *
  8800. * @type {string}
  8801. * @since 7.1.0
  8802. * @apioption xAxis.accessibility.description
  8803. */
  8804. /**
  8805. * Range description for an axis. Overrides the default range description.
  8806. * Set to empty to disable range description for this axis.
  8807. *
  8808. * @type {string}
  8809. * @since 7.1.0
  8810. * @apioption xAxis.accessibility.rangeDescription
  8811. */
  8812. /**
  8813. * @optionparent legend
  8814. */
  8815. legend: {
  8816. /**
  8817. * Accessibility options for the legend. Requires the Accessibility
  8818. * module.
  8819. *
  8820. * @since 7.1.0
  8821. * @requires modules/accessibility
  8822. */
  8823. accessibility: {
  8824. /**
  8825. * Enable accessibility support for the legend.
  8826. *
  8827. * @since 7.1.0
  8828. */
  8829. enabled: true,
  8830. /**
  8831. * Options for keyboard navigation for the legend.
  8832. *
  8833. * @since 7.1.0
  8834. * @requires modules/accessibility
  8835. */
  8836. keyboardNavigation: {
  8837. /**
  8838. * Enable keyboard navigation for the legend.
  8839. *
  8840. * @see [accessibility.keyboardNavigation](#accessibility.keyboardNavigation.enabled)
  8841. *
  8842. * @since 7.1.0
  8843. */
  8844. enabled: true
  8845. }
  8846. }
  8847. },
  8848. /**
  8849. * @optionparent exporting
  8850. */
  8851. exporting: {
  8852. /**
  8853. * Accessibility options for the exporting menu. Requires the
  8854. * Accessibility module.
  8855. *
  8856. * @since 7.1.0
  8857. * @requires modules/accessibility
  8858. */
  8859. accessibility: {
  8860. /**
  8861. * Enable accessibility support for the export menu.
  8862. *
  8863. * @since 7.1.0
  8864. */
  8865. enabled: true
  8866. }
  8867. }
  8868. };
  8869. return options;
  8870. });
  8871. _registerModule(_modules, 'Accessibility/Options/LangOptions.js', [], function () {
  8872. /* *
  8873. *
  8874. * (c) 2009-2021 Øystein Moseng
  8875. *
  8876. * Default lang/i18n options for accessibility.
  8877. *
  8878. * License: www.highcharts.com/license
  8879. *
  8880. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8881. *
  8882. * */
  8883. var langOptions = {
  8884. /**
  8885. * Configure the accessibility strings in the chart. Requires the
  8886. * [accessibility module](https://code.highcharts.com/modules/accessibility.js)
  8887. * to be loaded. For a description of the module and information on its
  8888. * features, see
  8889. * [Highcharts Accessibility](https://www.highcharts.com/docs/chart-concepts/accessibility).
  8890. *
  8891. * For more dynamic control over the accessibility functionality, see
  8892. * [accessibility.pointDescriptionFormatter](#accessibility.pointDescriptionFormatter),
  8893. * [accessibility.seriesDescriptionFormatter](#accessibility.seriesDescriptionFormatter),
  8894. * and
  8895. * [accessibility.screenReaderSectionFormatter](#accessibility.screenReaderSectionFormatter).
  8896. *
  8897. * @since 6.0.6
  8898. * @optionparent lang.accessibility
  8899. */
  8900. accessibility: {
  8901. defaultChartTitle: 'Chart',
  8902. chartContainerLabel: '{title}. Highcharts interactive chart.',
  8903. svgContainerLabel: 'Interactive chart',
  8904. drillUpButton: '{buttonText}',
  8905. credits: 'Chart credits: {creditsStr}',
  8906. /**
  8907. * Thousands separator to use when formatting numbers for screen
  8908. * readers. Note that many screen readers will not handle space as a
  8909. * thousands separator, and will consider "11 700" as two numbers.
  8910. *
  8911. * Set to `null` to use the separator defined in
  8912. * [lang.thousandsSep](lang.thousandsSep).
  8913. *
  8914. * @since 7.1.0
  8915. */
  8916. thousandsSep: ',',
  8917. /**
  8918. * Title element text for the chart SVG element. Leave this
  8919. * empty to disable adding the title element. Browsers will display
  8920. * this content when hovering over elements in the chart. Assistive
  8921. * technology may use this element to label the chart.
  8922. *
  8923. * @since 6.0.8
  8924. */
  8925. svgContainerTitle: '',
  8926. /**
  8927. * Set a label on the container wrapping the SVG.
  8928. *
  8929. * @see [chartContainerLabel](#lang.accessibility.chartContainerLabel)
  8930. *
  8931. * @since 8.0.0
  8932. */
  8933. graphicContainerLabel: '',
  8934. /**
  8935. * Language options for the screen reader information sections added
  8936. * before and after the charts.
  8937. *
  8938. * @since 8.0.0
  8939. */
  8940. screenReaderSection: {
  8941. beforeRegionLabel: 'Chart screen reader information.',
  8942. afterRegionLabel: '',
  8943. /**
  8944. * Language options for annotation descriptions.
  8945. *
  8946. * @since 8.0.1
  8947. */
  8948. annotations: {
  8949. heading: 'Chart annotations summary',
  8950. descriptionSinglePoint: '{annotationText}. Related to {annotationPoint}',
  8951. descriptionMultiplePoints: '{annotationText}. Related to {annotationPoint}' +
  8952. '{ Also related to, #each(additionalAnnotationPoints)}',
  8953. descriptionNoPoints: '{annotationText}'
  8954. },
  8955. /**
  8956. * Label for the end of the chart. Announced by screen readers.
  8957. *
  8958. * @since 8.0.0
  8959. */
  8960. endOfChartMarker: 'End of interactive chart.'
  8961. },
  8962. /**
  8963. * Language options for sonification.
  8964. *
  8965. * @since 8.0.1
  8966. */
  8967. sonification: {
  8968. playAsSoundButtonText: 'Play as sound, {chartTitle}',
  8969. playAsSoundClickAnnouncement: 'Play'
  8970. },
  8971. /**
  8972. * Language options for accessibility of the legend.
  8973. *
  8974. * @since 8.0.0
  8975. */
  8976. legend: {
  8977. legendLabelNoTitle: 'Toggle series visibility',
  8978. legendLabel: 'Chart legend: {legendTitle}',
  8979. legendItem: 'Show {itemName}'
  8980. },
  8981. /**
  8982. * Chart and map zoom accessibility language options.
  8983. *
  8984. * @since 8.0.0
  8985. */
  8986. zoom: {
  8987. mapZoomIn: 'Zoom chart',
  8988. mapZoomOut: 'Zoom out chart',
  8989. resetZoomButton: 'Reset zoom'
  8990. },
  8991. /**
  8992. * Range selector language options for accessibility.
  8993. *
  8994. * @since 8.0.0
  8995. */
  8996. rangeSelector: {
  8997. dropdownLabel: '{rangeTitle}',
  8998. minInputLabel: 'Select start date.',
  8999. maxInputLabel: 'Select end date.',
  9000. clickButtonAnnouncement: 'Viewing {axisRangeDescription}'
  9001. },
  9002. /**
  9003. * Accessibility language options for the data table.
  9004. *
  9005. * @since 8.0.0
  9006. */
  9007. table: {
  9008. viewAsDataTableButtonText: 'View as data table, {chartTitle}',
  9009. tableSummary: 'Table representation of chart.'
  9010. },
  9011. /**
  9012. * Default announcement for new data in charts. If addPoint or
  9013. * addSeries is used, and only one series/point is added, the
  9014. * `newPointAnnounce` and `newSeriesAnnounce` strings are used.
  9015. * The `...Single` versions will be used if there is only one chart
  9016. * on the page, and the `...Multiple` versions will be used if there
  9017. * are multiple charts on the page. For all other new data events,
  9018. * the `newDataAnnounce` string will be used.
  9019. *
  9020. * @since 7.1.0
  9021. */
  9022. announceNewData: {
  9023. newDataAnnounce: 'Updated data for chart {chartTitle}',
  9024. newSeriesAnnounceSingle: 'New data series: {seriesDesc}',
  9025. newPointAnnounceSingle: 'New data point: {pointDesc}',
  9026. newSeriesAnnounceMultiple: 'New data series in chart {chartTitle}: {seriesDesc}',
  9027. newPointAnnounceMultiple: 'New data point in chart {chartTitle}: {pointDesc}'
  9028. },
  9029. /**
  9030. * Descriptions of lesser known series types. The relevant
  9031. * description is added to the screen reader information region
  9032. * when these series types are used.
  9033. *
  9034. * @since 6.0.6
  9035. */
  9036. seriesTypeDescriptions: {
  9037. boxplot: 'Box plot charts are typically used to display ' +
  9038. 'groups of statistical data. Each data point in the ' +
  9039. 'chart can have up to 5 values: minimum, lower quartile, ' +
  9040. 'median, upper quartile, and maximum.',
  9041. arearange: 'Arearange charts are line charts displaying a ' +
  9042. 'range between a lower and higher value for each point.',
  9043. areasplinerange: 'These charts are line charts displaying a ' +
  9044. 'range between a lower and higher value for each point.',
  9045. bubble: 'Bubble charts are scatter charts where each data ' +
  9046. 'point also has a size value.',
  9047. columnrange: 'Columnrange charts are column charts ' +
  9048. 'displaying a range between a lower and higher value for ' +
  9049. 'each point.',
  9050. errorbar: 'Errorbar series are used to display the ' +
  9051. 'variability of the data.',
  9052. funnel: 'Funnel charts are used to display reduction of data ' +
  9053. 'in stages.',
  9054. pyramid: 'Pyramid charts consist of a single pyramid with ' +
  9055. 'item heights corresponding to each point value.',
  9056. waterfall: 'A waterfall chart is a column chart where each ' +
  9057. 'column contributes towards a total end value.'
  9058. },
  9059. /**
  9060. * Chart type description strings. This is added to the chart
  9061. * information region.
  9062. *
  9063. * If there is only a single series type used in the chart, we use
  9064. * the format string for the series type, or default if missing.
  9065. * There is one format string for cases where there is only a single
  9066. * series in the chart, and one for multiple series of the same
  9067. * type.
  9068. *
  9069. * @since 6.0.6
  9070. */
  9071. chartTypes: {
  9072. /* eslint-disable max-len */
  9073. emptyChart: 'Empty chart',
  9074. mapTypeDescription: 'Map of {mapTitle} with {numSeries} data series.',
  9075. unknownMap: 'Map of unspecified region with {numSeries} data series.',
  9076. combinationChart: 'Combination chart with {numSeries} data series.',
  9077. defaultSingle: 'Chart with {numPoints} data {#plural(numPoints, points, point)}.',
  9078. defaultMultiple: 'Chart with {numSeries} data series.',
  9079. splineSingle: 'Line chart with {numPoints} data {#plural(numPoints, points, point)}.',
  9080. splineMultiple: 'Line chart with {numSeries} lines.',
  9081. lineSingle: 'Line chart with {numPoints} data {#plural(numPoints, points, point)}.',
  9082. lineMultiple: 'Line chart with {numSeries} lines.',
  9083. columnSingle: 'Bar chart with {numPoints} {#plural(numPoints, bars, bar)}.',
  9084. columnMultiple: 'Bar chart with {numSeries} data series.',
  9085. barSingle: 'Bar chart with {numPoints} {#plural(numPoints, bars, bar)}.',
  9086. barMultiple: 'Bar chart with {numSeries} data series.',
  9087. pieSingle: 'Pie chart with {numPoints} {#plural(numPoints, slices, slice)}.',
  9088. pieMultiple: 'Pie chart with {numSeries} pies.',
  9089. scatterSingle: 'Scatter chart with {numPoints} {#plural(numPoints, points, point)}.',
  9090. scatterMultiple: 'Scatter chart with {numSeries} data series.',
  9091. boxplotSingle: 'Boxplot with {numPoints} {#plural(numPoints, boxes, box)}.',
  9092. boxplotMultiple: 'Boxplot with {numSeries} data series.',
  9093. bubbleSingle: 'Bubble chart with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  9094. bubbleMultiple: 'Bubble chart with {numSeries} data series.'
  9095. },
  9096. /**
  9097. * Axis description format strings.
  9098. *
  9099. * @since 6.0.6
  9100. */
  9101. axis: {
  9102. /* eslint-disable max-len */
  9103. xAxisDescriptionSingular: 'The chart has 1 X axis displaying {names[0]}. {ranges[0]}',
  9104. xAxisDescriptionPlural: 'The chart has {numAxes} X axes displaying {#each(names, -1) }and {names[-1]}.',
  9105. yAxisDescriptionSingular: 'The chart has 1 Y axis displaying {names[0]}. {ranges[0]}',
  9106. yAxisDescriptionPlural: 'The chart has {numAxes} Y axes displaying {#each(names, -1) }and {names[-1]}.',
  9107. timeRangeDays: 'Range: {range} days.',
  9108. timeRangeHours: 'Range: {range} hours.',
  9109. timeRangeMinutes: 'Range: {range} minutes.',
  9110. timeRangeSeconds: 'Range: {range} seconds.',
  9111. rangeFromTo: 'Range: {rangeFrom} to {rangeTo}.',
  9112. rangeCategories: 'Range: {numCategories} categories.'
  9113. },
  9114. /**
  9115. * Exporting menu format strings for accessibility module.
  9116. *
  9117. * @since 6.0.6
  9118. */
  9119. exporting: {
  9120. chartMenuLabel: 'Chart menu',
  9121. menuButtonLabel: 'View chart menu',
  9122. exportRegionLabel: 'Chart menu'
  9123. },
  9124. /**
  9125. * Lang configuration for different series types. For more dynamic
  9126. * control over the series element descriptions, see
  9127. * [accessibility.seriesDescriptionFormatter](#accessibility.seriesDescriptionFormatter).
  9128. *
  9129. * @since 6.0.6
  9130. */
  9131. series: {
  9132. /**
  9133. * Lang configuration for the series main summary. Each series
  9134. * type has two modes:
  9135. *
  9136. * 1. This series type is the only series type used in the
  9137. * chart
  9138. *
  9139. * 2. This is a combination chart with multiple series types
  9140. *
  9141. * If a definition does not exist for the specific series type
  9142. * and mode, the 'default' lang definitions are used.
  9143. *
  9144. * @since 6.0.6
  9145. */
  9146. summary: {
  9147. /* eslint-disable max-len */
  9148. 'default': '{name}, series {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  9149. defaultCombination: '{name}, series {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  9150. line: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  9151. lineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
  9152. spline: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  9153. splineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
  9154. column: '{name}, bar series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bars, bar)}.',
  9155. columnCombination: '{name}, series {ix} of {numSeries}. Bar series with {numPoints} {#plural(numPoints, bars, bar)}.',
  9156. bar: '{name}, bar series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bars, bar)}.',
  9157. barCombination: '{name}, series {ix} of {numSeries}. Bar series with {numPoints} {#plural(numPoints, bars, bar)}.',
  9158. pie: '{name}, pie {ix} of {numSeries} with {numPoints} {#plural(numPoints, slices, slice)}.',
  9159. pieCombination: '{name}, series {ix} of {numSeries}. Pie with {numPoints} {#plural(numPoints, slices, slice)}.',
  9160. scatter: '{name}, scatter plot {ix} of {numSeries} with {numPoints} {#plural(numPoints, points, point)}.',
  9161. scatterCombination: '{name}, series {ix} of {numSeries}, scatter plot with {numPoints} {#plural(numPoints, points, point)}.',
  9162. boxplot: '{name}, boxplot {ix} of {numSeries} with {numPoints} {#plural(numPoints, boxes, box)}.',
  9163. boxplotCombination: '{name}, series {ix} of {numSeries}. Boxplot with {numPoints} {#plural(numPoints, boxes, box)}.',
  9164. bubble: '{name}, bubble series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  9165. bubbleCombination: '{name}, series {ix} of {numSeries}. Bubble series with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  9166. map: '{name}, map {ix} of {numSeries} with {numPoints} {#plural(numPoints, areas, area)}.',
  9167. mapCombination: '{name}, series {ix} of {numSeries}. Map with {numPoints} {#plural(numPoints, areas, area)}.',
  9168. mapline: '{name}, line {ix} of {numSeries} with {numPoints} data {#plural(numPoints, points, point)}.',
  9169. maplineCombination: '{name}, series {ix} of {numSeries}. Line with {numPoints} data {#plural(numPoints, points, point)}.',
  9170. mapbubble: '{name}, bubble series {ix} of {numSeries} with {numPoints} {#plural(numPoints, bubbles, bubble)}.',
  9171. mapbubbleCombination: '{name}, series {ix} of {numSeries}. Bubble series with {numPoints} {#plural(numPoints, bubbles, bubble)}.'
  9172. },
  9173. /**
  9174. * User supplied description text. This is added in the point
  9175. * comment description by default if present.
  9176. *
  9177. * @since 6.0.6
  9178. */
  9179. description: '{description}',
  9180. /**
  9181. * xAxis description for series if there are multiple xAxes in
  9182. * the chart.
  9183. *
  9184. * @since 6.0.6
  9185. */
  9186. xAxisDescription: 'X axis, {name}',
  9187. /**
  9188. * yAxis description for series if there are multiple yAxes in
  9189. * the chart.
  9190. *
  9191. * @since 6.0.6
  9192. */
  9193. yAxisDescription: 'Y axis, {name}',
  9194. /**
  9195. * Description for the value of null points.
  9196. *
  9197. * @since 8.0.0
  9198. */
  9199. nullPointValue: 'No value',
  9200. /**
  9201. * Description for annotations on a point, as it is made available
  9202. * to assistive technology.
  9203. *
  9204. * @since 8.0.1
  9205. */
  9206. pointAnnotationsDescription: '{Annotation: #each(annotations). }'
  9207. }
  9208. }
  9209. };
  9210. return langOptions;
  9211. });
  9212. _registerModule(_modules, 'Accessibility/Options/DeprecatedOptions.js', [_modules['Core/Utilities.js']], function (U) {
  9213. /* *
  9214. *
  9215. * (c) 2009-2021 Øystein Moseng
  9216. *
  9217. * Default options for accessibility.
  9218. *
  9219. * License: www.highcharts.com/license
  9220. *
  9221. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  9222. *
  9223. * */
  9224. /* eslint-disable max-len */
  9225. /*
  9226. * List of deprecated options:
  9227. *
  9228. * chart.description -> accessibility.description
  9229. * chart.typeDescription -> accessibility.typeDescription
  9230. * series.description -> series.accessibility.description
  9231. * series.exposeElementToA11y -> series.accessibility.exposeAsGroupOnly
  9232. * series.pointDescriptionFormatter ->
  9233. * series.accessibility.pointDescriptionFormatter
  9234. * series.skipKeyboardNavigation ->
  9235. * series.accessibility.keyboardNavigation.enabled
  9236. * point.description -> point.accessibility.description !!!! WARNING: No longer deprecated and handled, removed for HC8.
  9237. * axis.description -> axis.accessibility.description
  9238. *
  9239. * accessibility.pointDateFormat -> accessibility.point.dateFormat
  9240. * accessibility.addTableShortcut -> Handled by screenReaderSection.beforeChartFormat
  9241. * accessibility.pointDateFormatter -> accessibility.point.dateFormatter
  9242. * accessibility.pointDescriptionFormatter -> accessibility.point.descriptionFormatter
  9243. * accessibility.pointDescriptionThreshold -> accessibility.series.pointDescriptionEnabledThreshold
  9244. * accessibility.pointNavigationThreshold -> accessibility.keyboardNavigation.seriesNavigation.pointNavigationEnabledThreshold
  9245. * accessibility.pointValueDecimals -> accessibility.point.valueDecimals
  9246. * accessibility.pointValuePrefix -> accessibility.point.valuePrefix
  9247. * accessibility.pointValueSuffix -> accessibility.point.valueSuffix
  9248. * accessibility.screenReaderSectionFormatter -> accessibility.screenReaderSection.beforeChartFormatter
  9249. * accessibility.describeSingleSeries -> accessibility.series.describeSingleSeries
  9250. * accessibility.seriesDescriptionFormatter -> accessibility.series.descriptionFormatter
  9251. * accessibility.onTableAnchorClick -> accessibility.screenReaderSection.onViewDataTableClick
  9252. * accessibility.axisRangeDateFormat -> accessibility.screenReaderSection.axisRangeDateFormat
  9253. * accessibility.keyboardNavigation.skipNullPoints -> accessibility.keyboardNavigation.seriesNavigation.skipNullPoints
  9254. * accessibility.keyboardNavigation.mode -> accessibility.keyboardNavigation.seriesNavigation.mode
  9255. *
  9256. * lang.accessibility.chartHeading -> no longer used, remove
  9257. * lang.accessibility.legendItem -> lang.accessibility.legend.legendItem
  9258. * lang.accessibility.legendLabel -> lang.accessibility.legend.legendLabel
  9259. * lang.accessibility.mapZoomIn -> lang.accessibility.zoom.mapZoomIn
  9260. * lang.accessibility.mapZoomOut -> lang.accessibility.zoom.mapZoomOut
  9261. * lang.accessibility.resetZoomButton -> lang.accessibility.zoom.resetZoomButton
  9262. * lang.accessibility.screenReaderRegionLabel -> lang.accessibility.screenReaderSection.beforeRegionLabel
  9263. * lang.accessibility.rangeSelectorButton -> lang.accessibility.rangeSelector.buttonText
  9264. * lang.accessibility.rangeSelectorMaxInput -> lang.accessibility.rangeSelector.maxInputLabel
  9265. * lang.accessibility.rangeSelectorMinInput -> lang.accessibility.rangeSelector.minInputLabel
  9266. * lang.accessibility.svgContainerEnd -> lang.accessibility.screenReaderSection.endOfChartMarker
  9267. * lang.accessibility.viewAsDataTable -> lang.accessibility.table.viewAsDataTableButtonText
  9268. * lang.accessibility.tableSummary -> lang.accessibility.table.tableSummary
  9269. *
  9270. */
  9271. /* eslint-enable max-len */
  9272. var error = U.error,
  9273. pick = U.pick;
  9274. /* eslint-disable valid-jsdoc */
  9275. /**
  9276. * Set a new option on a root prop, where the option is defined as an array of
  9277. * suboptions.
  9278. * @private
  9279. * @param root
  9280. * @param {Array<string>} optionAsArray
  9281. * @param {*} val
  9282. * @return {void}
  9283. */
  9284. function traverseSetOption(root, optionAsArray, val) {
  9285. var opt = root,
  9286. prop,
  9287. i = 0;
  9288. for (; i < optionAsArray.length - 1; ++i) {
  9289. prop = optionAsArray[i];
  9290. opt = opt[prop] = pick(opt[prop], {});
  9291. }
  9292. opt[optionAsArray[optionAsArray.length - 1]] = val;
  9293. }
  9294. /**
  9295. * If we have a clear root option node for old and new options and a mapping
  9296. * between, we can use this generic function for the copy and warn logic.
  9297. */
  9298. function deprecateFromOptionsMap(chart, rootOldAsArray, rootNewAsArray, mapToNewOptions) {
  9299. /**
  9300. * @private
  9301. */
  9302. function getChildProp(root, propAsArray) {
  9303. return propAsArray.reduce(function (acc, cur) {
  9304. return acc[cur];
  9305. }, root);
  9306. }
  9307. var rootOld = getChildProp(chart.options,
  9308. rootOldAsArray),
  9309. rootNew = getChildProp(chart.options,
  9310. rootNewAsArray);
  9311. Object.keys(mapToNewOptions).forEach(function (oldOptionKey) {
  9312. var _a;
  9313. var val = rootOld[oldOptionKey];
  9314. if (typeof val !== 'undefined') {
  9315. traverseSetOption(rootNew, mapToNewOptions[oldOptionKey], val);
  9316. error(32, false, chart, (_a = {},
  9317. _a[rootOldAsArray.join('.') + "." + oldOptionKey] = rootNewAsArray.join('.') + "." + mapToNewOptions[oldOptionKey].join('.'),
  9318. _a));
  9319. }
  9320. });
  9321. }
  9322. /**
  9323. * @private
  9324. */
  9325. function copyDeprecatedChartOptions(chart) {
  9326. var chartOptions = chart.options.chart || {},
  9327. a11yOptions = chart.options.accessibility || {};
  9328. ['description', 'typeDescription'].forEach(function (prop) {
  9329. var _a;
  9330. if (chartOptions[prop]) {
  9331. a11yOptions[prop] = chartOptions[prop];
  9332. error(32, false, chart, (_a = {}, _a["chart." + prop] = "use accessibility." + prop, _a));
  9333. }
  9334. });
  9335. }
  9336. /**
  9337. * @private
  9338. */
  9339. function copyDeprecatedAxisOptions(chart) {
  9340. chart.axes.forEach(function (axis) {
  9341. var opts = axis.options;
  9342. if (opts && opts.description) {
  9343. opts.accessibility = opts.accessibility || {};
  9344. opts.accessibility.description = opts.description;
  9345. error(32, false, chart, { 'axis.description': 'use axis.accessibility.description' });
  9346. }
  9347. });
  9348. }
  9349. /**
  9350. * @private
  9351. */
  9352. function copyDeprecatedSeriesOptions(chart) {
  9353. // Map of deprecated series options. New options are defined as
  9354. // arrays of paths under series.options.
  9355. var oldToNewSeriesOptions = {
  9356. description: ['accessibility', 'description'],
  9357. exposeElementToA11y: ['accessibility', 'exposeAsGroupOnly'],
  9358. pointDescriptionFormatter: [
  9359. 'accessibility', 'pointDescriptionFormatter'
  9360. ],
  9361. skipKeyboardNavigation: [
  9362. 'accessibility', 'keyboardNavigation', 'enabled'
  9363. ]
  9364. };
  9365. chart.series.forEach(function (series) {
  9366. // Handle series wide options
  9367. Object.keys(oldToNewSeriesOptions).forEach(function (oldOption) {
  9368. var _a;
  9369. var optionVal = series.options[oldOption];
  9370. if (typeof optionVal !== 'undefined') {
  9371. // Set the new option
  9372. traverseSetOption(series.options, oldToNewSeriesOptions[oldOption],
  9373. // Note that skipKeyboardNavigation has inverted option
  9374. // value, since we set enabled rather than disabled
  9375. oldOption === 'skipKeyboardNavigation' ?
  9376. !optionVal : optionVal);
  9377. error(32, false, chart, (_a = {}, _a["series." + oldOption] = "series." + oldToNewSeriesOptions[oldOption].join('.'), _a));
  9378. }
  9379. });
  9380. });
  9381. }
  9382. /**
  9383. * @private
  9384. */
  9385. function copyDeprecatedTopLevelAccessibilityOptions(chart) {
  9386. deprecateFromOptionsMap(chart, ['accessibility'], ['accessibility'], {
  9387. pointDateFormat: ['point', 'dateFormat'],
  9388. pointDateFormatter: ['point', 'dateFormatter'],
  9389. pointDescriptionFormatter: ['point', 'descriptionFormatter'],
  9390. pointDescriptionThreshold: ['series',
  9391. 'pointDescriptionEnabledThreshold'],
  9392. pointNavigationThreshold: ['keyboardNavigation', 'seriesNavigation',
  9393. 'pointNavigationEnabledThreshold'],
  9394. pointValueDecimals: ['point', 'valueDecimals'],
  9395. pointValuePrefix: ['point', 'valuePrefix'],
  9396. pointValueSuffix: ['point', 'valueSuffix'],
  9397. screenReaderSectionFormatter: ['screenReaderSection',
  9398. 'beforeChartFormatter'],
  9399. describeSingleSeries: ['series', 'describeSingleSeries'],
  9400. seriesDescriptionFormatter: ['series', 'descriptionFormatter'],
  9401. onTableAnchorClick: ['screenReaderSection', 'onViewDataTableClick'],
  9402. axisRangeDateFormat: ['screenReaderSection', 'axisRangeDateFormat']
  9403. });
  9404. }
  9405. /**
  9406. * @private
  9407. */
  9408. function copyDeprecatedKeyboardNavigationOptions(chart) {
  9409. deprecateFromOptionsMap(chart, ['accessibility', 'keyboardNavigation'], ['accessibility', 'keyboardNavigation', 'seriesNavigation'], {
  9410. skipNullPoints: ['skipNullPoints'],
  9411. mode: ['mode']
  9412. });
  9413. }
  9414. /**
  9415. * @private
  9416. */
  9417. function copyDeprecatedLangOptions(chart) {
  9418. deprecateFromOptionsMap(chart, ['lang', 'accessibility'], ['lang', 'accessibility'], {
  9419. legendItem: ['legend', 'legendItem'],
  9420. legendLabel: ['legend', 'legendLabel'],
  9421. mapZoomIn: ['zoom', 'mapZoomIn'],
  9422. mapZoomOut: ['zoom', 'mapZoomOut'],
  9423. resetZoomButton: ['zoom', 'resetZoomButton'],
  9424. screenReaderRegionLabel: ['screenReaderSection',
  9425. 'beforeRegionLabel'],
  9426. rangeSelectorButton: ['rangeSelector', 'buttonText'],
  9427. rangeSelectorMaxInput: ['rangeSelector', 'maxInputLabel'],
  9428. rangeSelectorMinInput: ['rangeSelector', 'minInputLabel'],
  9429. svgContainerEnd: ['screenReaderSection', 'endOfChartMarker'],
  9430. viewAsDataTable: ['table', 'viewAsDataTableButtonText'],
  9431. tableSummary: ['table', 'tableSummary']
  9432. });
  9433. }
  9434. /**
  9435. * Copy options that are deprecated over to new options. Logs warnings to
  9436. * console if deprecated options are used.
  9437. *
  9438. * @private
  9439. */
  9440. function copyDeprecatedOptions(chart) {
  9441. copyDeprecatedChartOptions(chart);
  9442. copyDeprecatedAxisOptions(chart);
  9443. if (chart.series) {
  9444. copyDeprecatedSeriesOptions(chart);
  9445. }
  9446. copyDeprecatedTopLevelAccessibilityOptions(chart);
  9447. copyDeprecatedKeyboardNavigationOptions(chart);
  9448. copyDeprecatedLangOptions(chart);
  9449. }
  9450. return copyDeprecatedOptions;
  9451. });
  9452. _registerModule(_modules, 'Accessibility/A11yI18n.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  9453. /* *
  9454. *
  9455. * Accessibility module - internationalization support
  9456. *
  9457. * (c) 2010-2021 Highsoft AS
  9458. * Author: Øystein Moseng
  9459. *
  9460. * License: www.highcharts.com/license
  9461. *
  9462. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  9463. *
  9464. * */
  9465. var format = U.format,
  9466. pick = U.pick;
  9467. /* eslint-disable valid-jsdoc */
  9468. /**
  9469. * String trim that works for IE6-8 as well.
  9470. *
  9471. * @private
  9472. * @function stringTrim
  9473. *
  9474. * @param {string} str
  9475. * The input string
  9476. *
  9477. * @return {string}
  9478. * The trimmed string
  9479. */
  9480. function stringTrim(str) {
  9481. return str.trim && str.trim() || str.replace(/^\s+|\s+$/g, '');
  9482. }
  9483. /**
  9484. * i18n utility function. Format a single array or plural statement in a format
  9485. * string. If the statement is not an array or plural statement, returns the
  9486. * statement within brackets. Invalid array statements return an empty string.
  9487. *
  9488. * @private
  9489. * @function formatExtendedStatement
  9490. *
  9491. * @param {string} statement
  9492. *
  9493. * @param {Highcharts.Dictionary<*>} ctx
  9494. * Context to apply to the format string.
  9495. *
  9496. * @return {string}
  9497. */
  9498. function formatExtendedStatement(statement, ctx) {
  9499. var eachStart = statement.indexOf('#each('), pluralStart = statement.indexOf('#plural('), indexStart = statement.indexOf('['), indexEnd = statement.indexOf(']'), arr, result;
  9500. // Dealing with an each-function?
  9501. if (eachStart > -1) {
  9502. 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;
  9503. result = '';
  9504. arr = ctx[eachArguments[0]];
  9505. if (arr) {
  9506. lenArg = isNaN(lenArg) ? arr.length : lenArg;
  9507. len = lenArg < 0 ?
  9508. arr.length + lenArg :
  9509. Math.min(lenArg, arr.length); // Overshoot
  9510. // Run through the array for the specified length
  9511. for (var i = 0; i < len; ++i) {
  9512. result += preEach + arr[i] + postEach;
  9513. }
  9514. }
  9515. return result.length ? result : '';
  9516. }
  9517. // Dealing with a plural-function?
  9518. if (pluralStart > -1) {
  9519. var pluralEnd = statement.slice(pluralStart).indexOf(')') + pluralStart, pluralStatement = statement.substring(pluralStart + 8, pluralEnd), pluralArguments = pluralStatement.split(','), num = Number(ctx[pluralArguments[0]]);
  9520. switch (num) {
  9521. case 0:
  9522. result = pick(pluralArguments[4], pluralArguments[1]);
  9523. break;
  9524. case 1:
  9525. result = pick(pluralArguments[2], pluralArguments[1]);
  9526. break;
  9527. case 2:
  9528. result = pick(pluralArguments[3], pluralArguments[1]);
  9529. break;
  9530. default:
  9531. result = pluralArguments[1];
  9532. }
  9533. return result ? stringTrim(result) : '';
  9534. }
  9535. // Array index
  9536. if (indexStart > -1) {
  9537. var arrayName = statement.substring(0,
  9538. indexStart),
  9539. ix = Number(statement.substring(indexStart + 1,
  9540. indexEnd)),
  9541. val;
  9542. arr = ctx[arrayName];
  9543. if (!isNaN(ix) && arr) {
  9544. if (ix < 0) {
  9545. val = arr[arr.length + ix];
  9546. // Handle negative overshoot
  9547. if (typeof val === 'undefined') {
  9548. val = arr[0];
  9549. }
  9550. }
  9551. else {
  9552. val = arr[ix];
  9553. // Handle positive overshoot
  9554. if (typeof val === 'undefined') {
  9555. val = arr[arr.length - 1];
  9556. }
  9557. }
  9558. }
  9559. return typeof val !== 'undefined' ? val : '';
  9560. }
  9561. // Standard substitution, delegate to format or similar
  9562. return '{' + statement + '}';
  9563. }
  9564. /**
  9565. * i18n formatting function. Extends Highcharts.format() functionality by also
  9566. * handling arrays and plural conditionals. Arrays can be indexed as follows:
  9567. *
  9568. * - Format: 'This is the first index: {myArray[0]}. The last: {myArray[-1]}.'
  9569. *
  9570. * - Context: { myArray: [0, 1, 2, 3, 4, 5] }
  9571. *
  9572. * - Result: 'This is the first index: 0. The last: 5.'
  9573. *
  9574. *
  9575. * They can also be iterated using the #each() function. This will repeat the
  9576. * contents of the bracket expression for each element. Example:
  9577. *
  9578. * - Format: 'List contains: {#each(myArray)cm }'
  9579. *
  9580. * - Context: { myArray: [0, 1, 2] }
  9581. *
  9582. * - Result: 'List contains: 0cm 1cm 2cm '
  9583. *
  9584. *
  9585. * The #each() function optionally takes a length parameter. If positive, this
  9586. * parameter specifies the max number of elements to iterate through. If
  9587. * negative, the function will subtract the number from the length of the array.
  9588. * Use this to stop iterating before the array ends. Example:
  9589. *
  9590. * - Format: 'List contains: {#each(myArray, -1) }and {myArray[-1]}.'
  9591. *
  9592. * - Context: { myArray: [0, 1, 2, 3] }
  9593. *
  9594. * - Result: 'List contains: 0, 1, 2, and 3.'
  9595. *
  9596. *
  9597. * Use the #plural() function to pick a string depending on whether or not a
  9598. * context object is 1. Arguments are #plural(obj, plural, singular). Example:
  9599. *
  9600. * - Format: 'Has {numPoints} {#plural(numPoints, points, point}.'
  9601. *
  9602. * - Context: { numPoints: 5 }
  9603. *
  9604. * - Result: 'Has 5 points.'
  9605. *
  9606. *
  9607. * Optionally there are additional parameters for dual and none: #plural(obj,
  9608. * plural, singular, dual, none). Example:
  9609. *
  9610. * - Format: 'Has {#plural(numPoints, many points, one point, two points,
  9611. * none}.'
  9612. *
  9613. * - Context: { numPoints: 2 }
  9614. *
  9615. * - Result: 'Has two points.'
  9616. *
  9617. *
  9618. * The dual or none parameters will take precedence if they are supplied.
  9619. *
  9620. * @requires modules/accessibility
  9621. *
  9622. * @function Highcharts.i18nFormat
  9623. *
  9624. * @param {string} formatString
  9625. * The string to format.
  9626. *
  9627. * @param {Highcharts.Dictionary<*>} context
  9628. * Context to apply to the format string.
  9629. *
  9630. * @param {Highcharts.Chart} chart
  9631. * A `Chart` instance with a time object and numberFormatter, passed on
  9632. * to format().
  9633. *
  9634. * @return {string}
  9635. * The formatted string.
  9636. */
  9637. H.i18nFormat = function (formatString, context, chart) {
  9638. var getFirstBracketStatement = function (sourceStr, offset) {
  9639. var str = sourceStr.slice(offset || 0), startBracket = str.indexOf('{'), endBracket = str.indexOf('}');
  9640. if (startBracket > -1 && endBracket > startBracket) {
  9641. return {
  9642. statement: str.substring(startBracket + 1, endBracket),
  9643. begin: offset + startBracket + 1,
  9644. end: offset + endBracket
  9645. };
  9646. }
  9647. }, tokens = [], bracketRes, constRes, cursor = 0;
  9648. // Tokenize format string into bracket statements and constants
  9649. do {
  9650. bracketRes = getFirstBracketStatement(formatString, cursor);
  9651. constRes = formatString.substring(cursor, bracketRes && bracketRes.begin - 1);
  9652. // If we have constant content before this bracket statement, add it
  9653. if (constRes.length) {
  9654. tokens.push({
  9655. value: constRes,
  9656. type: 'constant'
  9657. });
  9658. }
  9659. // Add the bracket statement
  9660. if (bracketRes) {
  9661. tokens.push({
  9662. value: bracketRes.statement,
  9663. type: 'statement'
  9664. });
  9665. }
  9666. cursor = bracketRes ? bracketRes.end + 1 : cursor + 1;
  9667. } while (bracketRes);
  9668. // Perform the formatting. The formatArrayStatement function returns the
  9669. // statement in brackets if it is not an array statement, which means it
  9670. // gets picked up by format below.
  9671. tokens.forEach(function (token) {
  9672. if (token.type === 'statement') {
  9673. token.value = formatExtendedStatement(token.value, context);
  9674. }
  9675. });
  9676. // Join string back together and pass to format to pick up non-array
  9677. // statements.
  9678. return format(tokens.reduce(function (acc, cur) {
  9679. return acc + cur.value;
  9680. }, ''), context, chart);
  9681. };
  9682. /**
  9683. * Apply context to a format string from lang options of the chart.
  9684. *
  9685. * @requires modules/accessibility
  9686. *
  9687. * @function Highcharts.Chart#langFormat
  9688. *
  9689. * @param {string} langKey
  9690. * Key (using dot notation) into lang option structure.
  9691. *
  9692. * @param {Highcharts.Dictionary<*>} context
  9693. * Context to apply to the format string.
  9694. *
  9695. * @return {string}
  9696. * The formatted string.
  9697. */
  9698. H.Chart.prototype.langFormat = function (langKey, context) {
  9699. var keys = langKey.split('.'),
  9700. formatString = this.options.lang,
  9701. i = 0;
  9702. for (; i < keys.length; ++i) {
  9703. formatString = formatString && formatString[keys[i]];
  9704. }
  9705. return typeof formatString === 'string' ?
  9706. H.i18nFormat(formatString, context, this) : '';
  9707. };
  9708. });
  9709. _registerModule(_modules, 'Accessibility/FocusBorder.js', [_modules['Core/Globals.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Renderer/SVG/SVGLabel.js'], _modules['Core/Utilities.js']], function (H, SVGElement, SVGLabel, U) {
  9710. /* *
  9711. *
  9712. * (c) 2009-2021 Øystein Moseng
  9713. *
  9714. * Extend SVG and Chart classes with focus border capabilities.
  9715. *
  9716. * License: www.highcharts.com/license
  9717. *
  9718. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  9719. *
  9720. * */
  9721. var addEvent = U.addEvent,
  9722. extend = U.extend,
  9723. pick = U.pick;
  9724. /* eslint-disable no-invalid-this, valid-jsdoc */
  9725. // Attributes that trigger a focus border update
  9726. var svgElementBorderUpdateTriggers = [
  9727. 'x', 'y', 'transform', 'width', 'height', 'r', 'd', 'stroke-width'
  9728. ];
  9729. /**
  9730. * Add hook to destroy focus border if SVG element is destroyed, unless
  9731. * hook already exists.
  9732. * @private
  9733. * @param el Element to add destroy hook to
  9734. */
  9735. function addDestroyFocusBorderHook(el) {
  9736. if (el.focusBorderDestroyHook) {
  9737. return;
  9738. }
  9739. var origDestroy = el.destroy;
  9740. el.destroy = function () {
  9741. var _a,
  9742. _b;
  9743. (_b = (_a = el.focusBorder) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);
  9744. return origDestroy.apply(el, arguments);
  9745. };
  9746. el.focusBorderDestroyHook = origDestroy;
  9747. }
  9748. /**
  9749. * Remove hook from SVG element added by addDestroyFocusBorderHook, if
  9750. * existing.
  9751. * @private
  9752. * @param el Element to remove destroy hook from
  9753. */
  9754. function removeDestroyFocusBorderHook(el) {
  9755. if (!el.focusBorderDestroyHook) {
  9756. return;
  9757. }
  9758. el.destroy = el.focusBorderDestroyHook;
  9759. delete el.focusBorderDestroyHook;
  9760. }
  9761. /**
  9762. * Add hooks to update the focus border of an element when the element
  9763. * size/position is updated, unless already added.
  9764. * @private
  9765. * @param el Element to add update hooks to
  9766. * @param updateParams Parameters to pass through to addFocusBorder when updating.
  9767. */
  9768. function addUpdateFocusBorderHooks(el) {
  9769. var updateParams = [];
  9770. for (var _i = 1; _i < arguments.length; _i++) {
  9771. updateParams[_i - 1] = arguments[_i];
  9772. }
  9773. if (el.focusBorderUpdateHooks) {
  9774. return;
  9775. }
  9776. el.focusBorderUpdateHooks = {};
  9777. svgElementBorderUpdateTriggers.forEach(function (trigger) {
  9778. var setterKey = trigger + 'Setter';
  9779. var origSetter = el[setterKey] || el._defaultSetter;
  9780. el.focusBorderUpdateHooks[setterKey] = origSetter;
  9781. el[setterKey] = function () {
  9782. var ret = origSetter.apply(el,
  9783. arguments);
  9784. el.addFocusBorder.apply(el, updateParams);
  9785. return ret;
  9786. };
  9787. });
  9788. }
  9789. /**
  9790. * Remove hooks from SVG element added by addUpdateFocusBorderHooks, if
  9791. * existing.
  9792. * @private
  9793. * @param el Element to remove update hooks from
  9794. */
  9795. function removeUpdateFocusBorderHooks(el) {
  9796. if (!el.focusBorderUpdateHooks) {
  9797. return;
  9798. }
  9799. Object.keys(el.focusBorderUpdateHooks).forEach(function (setterKey) {
  9800. var origSetter = el.focusBorderUpdateHooks[setterKey];
  9801. if (origSetter === el._defaultSetter) {
  9802. delete el[setterKey];
  9803. }
  9804. else {
  9805. el[setterKey] = origSetter;
  9806. }
  9807. });
  9808. delete el.focusBorderUpdateHooks;
  9809. }
  9810. /*
  9811. * Add focus border functionality to SVGElements. Draws a new rect on top of
  9812. * element around its bounding box. This is used by multiple components.
  9813. */
  9814. extend(SVGElement.prototype, {
  9815. /**
  9816. * @private
  9817. * @function Highcharts.SVGElement#addFocusBorder
  9818. *
  9819. * @param {number} margin
  9820. *
  9821. * @param {Highcharts.CSSObject} style
  9822. */
  9823. addFocusBorder: function (margin, style) {
  9824. // Allow updating by just adding new border
  9825. if (this.focusBorder) {
  9826. this.removeFocusBorder();
  9827. }
  9828. // Add the border rect
  9829. var bb = this.getBBox(),
  9830. pad = pick(margin, 3);
  9831. bb.x += this.translateX ? this.translateX : 0;
  9832. bb.y += this.translateY ? this.translateY : 0;
  9833. var borderPosX = bb.x - pad,
  9834. borderPosY = bb.y - pad,
  9835. borderWidth = bb.width + 2 * pad,
  9836. borderHeight = bb.height + 2 * pad;
  9837. // For text elements, apply x and y offset, #11397.
  9838. /**
  9839. * @private
  9840. * @function
  9841. *
  9842. * @param {Highcharts.SVGElement} text
  9843. *
  9844. * @return {TextAnchorCorrectionObject}
  9845. */
  9846. function getTextAnchorCorrection(text) {
  9847. var posXCorrection = 0,
  9848. posYCorrection = 0;
  9849. if (text.attr('text-anchor') === 'middle') {
  9850. posXCorrection = H.isFirefox && text.rotation ? 0.25 : 0.5;
  9851. posYCorrection = H.isFirefox && !text.rotation ? 0.75 : 0.5;
  9852. }
  9853. else if (!text.rotation) {
  9854. posYCorrection = 0.75;
  9855. }
  9856. else {
  9857. posXCorrection = 0.25;
  9858. }
  9859. return {
  9860. x: posXCorrection,
  9861. y: posYCorrection
  9862. };
  9863. }
  9864. var isLabel = this instanceof SVGLabel;
  9865. if (this.element.nodeName === 'text' || isLabel) {
  9866. var isRotated = !!this.rotation;
  9867. var correction = !isLabel ? getTextAnchorCorrection(this) :
  9868. {
  9869. x: isRotated ? 1 : 0,
  9870. y: 0
  9871. };
  9872. var attrX = +this.attr('x');
  9873. var attrY = +this.attr('y');
  9874. if (!isNaN(attrX)) {
  9875. borderPosX = attrX - (bb.width * correction.x) - pad;
  9876. }
  9877. if (!isNaN(attrY)) {
  9878. borderPosY = attrY - (bb.height * correction.y) - pad;
  9879. }
  9880. if (isLabel && isRotated) {
  9881. var temp = borderWidth;
  9882. borderWidth = borderHeight;
  9883. borderHeight = temp;
  9884. if (!isNaN(attrX)) {
  9885. borderPosX = attrX - (bb.height * correction.x) - pad;
  9886. }
  9887. if (!isNaN(attrY)) {
  9888. borderPosY = attrY - (bb.width * correction.y) - pad;
  9889. }
  9890. }
  9891. }
  9892. this.focusBorder = this.renderer.rect(borderPosX, borderPosY, borderWidth, borderHeight, parseInt((style && style.borderRadius || 0).toString(), 10))
  9893. .addClass('highcharts-focus-border')
  9894. .attr({
  9895. zIndex: 99
  9896. })
  9897. .add(this.parentGroup);
  9898. if (!this.renderer.styledMode) {
  9899. this.focusBorder.attr({
  9900. stroke: style && style.stroke,
  9901. 'stroke-width': style && style.strokeWidth
  9902. });
  9903. }
  9904. addUpdateFocusBorderHooks(this, margin, style);
  9905. addDestroyFocusBorderHook(this);
  9906. },
  9907. /**
  9908. * @private
  9909. * @function Highcharts.SVGElement#removeFocusBorder
  9910. */
  9911. removeFocusBorder: function () {
  9912. removeUpdateFocusBorderHooks(this);
  9913. removeDestroyFocusBorderHook(this);
  9914. if (this.focusBorder) {
  9915. this.focusBorder.destroy();
  9916. delete this.focusBorder;
  9917. }
  9918. }
  9919. });
  9920. /**
  9921. * Redraws the focus border on the currently focused element.
  9922. *
  9923. * @private
  9924. * @function Highcharts.Chart#renderFocusBorder
  9925. */
  9926. H.Chart.prototype.renderFocusBorder = function () {
  9927. var focusElement = this.focusElement,
  9928. focusBorderOptions = this.options.accessibility.keyboardNavigation.focusBorder;
  9929. if (focusElement) {
  9930. focusElement.removeFocusBorder();
  9931. if (focusBorderOptions.enabled) {
  9932. focusElement.addFocusBorder(focusBorderOptions.margin, {
  9933. stroke: focusBorderOptions.style.color,
  9934. strokeWidth: focusBorderOptions.style.lineWidth,
  9935. borderRadius: focusBorderOptions.style.borderRadius
  9936. });
  9937. }
  9938. }
  9939. };
  9940. /**
  9941. * Set chart's focus to an SVGElement. Calls focus() on it, and draws the focus
  9942. * border. This is used by multiple components.
  9943. *
  9944. * @private
  9945. * @function Highcharts.Chart#setFocusToElement
  9946. *
  9947. * @param {Highcharts.SVGElement} svgElement
  9948. * Element to draw the border around.
  9949. *
  9950. * @param {SVGDOMElement|HTMLDOMElement} [focusElement]
  9951. * If supplied, it draws the border around svgElement and sets the focus
  9952. * to focusElement.
  9953. */
  9954. H.Chart.prototype.setFocusToElement = function (svgElement, focusElement) {
  9955. var focusBorderOptions = this.options.accessibility.keyboardNavigation.focusBorder,
  9956. browserFocusElement = focusElement || svgElement.element;
  9957. // Set browser focus if possible
  9958. if (browserFocusElement &&
  9959. browserFocusElement.focus) {
  9960. // If there is no focusin-listener, add one to work around Edge issue
  9961. // where Narrator is not reading out points despite calling focus().
  9962. if (!(browserFocusElement.hcEvents &&
  9963. browserFocusElement.hcEvents.focusin)) {
  9964. addEvent(browserFocusElement, 'focusin', function () { });
  9965. }
  9966. browserFocusElement.focus();
  9967. // Hide default focus ring
  9968. if (focusBorderOptions.hideBrowserFocusOutline) {
  9969. browserFocusElement.style.outline = 'none';
  9970. }
  9971. }
  9972. if (this.focusElement) {
  9973. this.focusElement.removeFocusBorder();
  9974. }
  9975. this.focusElement = svgElement;
  9976. this.renderFocusBorder();
  9977. };
  9978. });
  9979. _registerModule(_modules, 'Accessibility/Accessibility.js', [_modules['Accessibility/Utils/ChartUtilities.js'], _modules['Core/Globals.js'], _modules['Accessibility/KeyboardNavigationHandler.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Series/Series.js'], _modules['Core/Utilities.js'], _modules['Accessibility/AccessibilityComponent.js'], _modules['Accessibility/KeyboardNavigation.js'], _modules['Accessibility/Components/LegendComponent.js'], _modules['Accessibility/Components/MenuComponent.js'], _modules['Accessibility/Components/SeriesComponent/SeriesComponent.js'], _modules['Accessibility/Components/ZoomComponent.js'], _modules['Accessibility/Components/RangeSelectorComponent.js'], _modules['Accessibility/Components/InfoRegionsComponent.js'], _modules['Accessibility/Components/ContainerComponent.js'], _modules['Accessibility/HighContrastMode.js'], _modules['Accessibility/HighContrastTheme.js'], _modules['Accessibility/Options/Options.js'], _modules['Accessibility/Options/LangOptions.js'], _modules['Accessibility/Options/DeprecatedOptions.js'], _modules['Accessibility/Utils/HTMLUtilities.js']], function (ChartUtilities, H, KeyboardNavigationHandler, O, Point, Series, U, AccessibilityComponent, KeyboardNavigation, LegendComponent, MenuComponent, SeriesComponent, ZoomComponent, RangeSelectorComponent, InfoRegionsComponent, ContainerComponent, whcm, highContrastTheme, defaultOptionsA11Y, defaultLangOptions, copyDeprecatedOptions, HTMLUtilities) {
  9980. /* *
  9981. *
  9982. * (c) 2009-2021 Øystein Moseng
  9983. *
  9984. * Accessibility module for Highcharts
  9985. *
  9986. * License: www.highcharts.com/license
  9987. *
  9988. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  9989. *
  9990. * */
  9991. var doc = H.doc;
  9992. var defaultOptions = O.defaultOptions;
  9993. var addEvent = U.addEvent,
  9994. extend = U.extend,
  9995. fireEvent = U.fireEvent,
  9996. merge = U.merge;
  9997. // Add default options
  9998. merge(true, defaultOptions, defaultOptionsA11Y, {
  9999. accessibility: {
  10000. highContrastTheme: highContrastTheme
  10001. },
  10002. lang: defaultLangOptions
  10003. });
  10004. // Expose functionality on Highcharts namespace
  10005. H.A11yChartUtilities = ChartUtilities;
  10006. H.A11yHTMLUtilities = HTMLUtilities;
  10007. H.KeyboardNavigationHandler = KeyboardNavigationHandler;
  10008. H.AccessibilityComponent = AccessibilityComponent;
  10009. /* eslint-disable no-invalid-this, valid-jsdoc */
  10010. /**
  10011. * The Accessibility class
  10012. *
  10013. * @private
  10014. * @requires module:modules/accessibility
  10015. *
  10016. * @class
  10017. * @name Highcharts.Accessibility
  10018. *
  10019. * @param {Highcharts.Chart} chart
  10020. * Chart object
  10021. */
  10022. function Accessibility(chart) {
  10023. this.init(chart);
  10024. }
  10025. Accessibility.prototype = {
  10026. /**
  10027. * Initialize the accessibility class
  10028. * @private
  10029. * @param {Highcharts.Chart} chart
  10030. * Chart object
  10031. */
  10032. init: function (chart) {
  10033. this.chart = chart;
  10034. // Abort on old browsers
  10035. if (!doc.addEventListener || !chart.renderer.isSVG) {
  10036. chart.renderTo.setAttribute('aria-hidden', true);
  10037. return;
  10038. }
  10039. // Copy over any deprecated options that are used. We could do this on
  10040. // every update, but it is probably not needed.
  10041. copyDeprecatedOptions(chart);
  10042. this.initComponents();
  10043. this.keyboardNavigation = new KeyboardNavigation(chart, this.components);
  10044. this.update();
  10045. },
  10046. /**
  10047. * @private
  10048. */
  10049. initComponents: function () {
  10050. var chart = this.chart,
  10051. a11yOptions = chart.options.accessibility;
  10052. this.components = {
  10053. container: new ContainerComponent(),
  10054. infoRegions: new InfoRegionsComponent(),
  10055. legend: new LegendComponent(),
  10056. chartMenu: new MenuComponent(),
  10057. rangeSelector: new RangeSelectorComponent(),
  10058. series: new SeriesComponent(),
  10059. zoom: new ZoomComponent()
  10060. };
  10061. if (a11yOptions.customComponents) {
  10062. extend(this.components, a11yOptions.customComponents);
  10063. }
  10064. var components = this.components;
  10065. this.getComponentOrder().forEach(function (componentName) {
  10066. components[componentName].initBase(chart);
  10067. components[componentName].init();
  10068. });
  10069. },
  10070. /**
  10071. * Get order to update components in.
  10072. * @private
  10073. */
  10074. getComponentOrder: function () {
  10075. if (!this.components) {
  10076. return []; // For zombie accessibility object on old browsers
  10077. }
  10078. if (!this.components.series) {
  10079. return Object.keys(this.components);
  10080. }
  10081. var componentsExceptSeries = Object.keys(this.components)
  10082. .filter(function (c) { return c !== 'series'; });
  10083. // Update series first, so that other components can read accessibility
  10084. // info on points.
  10085. return ['series'].concat(componentsExceptSeries);
  10086. },
  10087. /**
  10088. * Update all components.
  10089. */
  10090. update: function () {
  10091. var components = this.components,
  10092. chart = this.chart,
  10093. a11yOptions = chart.options.accessibility;
  10094. fireEvent(chart, 'beforeA11yUpdate');
  10095. // Update the chart type list as this is used by multiple modules
  10096. chart.types = this.getChartTypes();
  10097. // Update markup
  10098. this.getComponentOrder().forEach(function (componentName) {
  10099. components[componentName].onChartUpdate();
  10100. fireEvent(chart, 'afterA11yComponentUpdate', {
  10101. name: componentName,
  10102. component: components[componentName]
  10103. });
  10104. });
  10105. // Update keyboard navigation
  10106. this.keyboardNavigation.update(a11yOptions.keyboardNavigation.order);
  10107. // Handle high contrast mode
  10108. if (!chart.highContrastModeActive && // Only do this once
  10109. whcm.isHighContrastModeActive()) {
  10110. whcm.setHighContrastTheme(chart);
  10111. }
  10112. fireEvent(chart, 'afterA11yUpdate', {
  10113. accessibility: this
  10114. });
  10115. },
  10116. /**
  10117. * Destroy all elements.
  10118. */
  10119. destroy: function () {
  10120. var chart = this.chart || {};
  10121. // Destroy components
  10122. var components = this.components;
  10123. Object.keys(components).forEach(function (componentName) {
  10124. components[componentName].destroy();
  10125. components[componentName].destroyBase();
  10126. });
  10127. // Kill keyboard nav
  10128. if (this.keyboardNavigation) {
  10129. this.keyboardNavigation.destroy();
  10130. }
  10131. // Hide container from screen readers if it exists
  10132. if (chart.renderTo) {
  10133. chart.renderTo.setAttribute('aria-hidden', true);
  10134. }
  10135. // Remove focus border if it exists
  10136. if (chart.focusElement) {
  10137. chart.focusElement.removeFocusBorder();
  10138. }
  10139. },
  10140. /**
  10141. * Return a list of the types of series we have in the chart.
  10142. * @private
  10143. */
  10144. getChartTypes: function () {
  10145. var types = {};
  10146. this.chart.series.forEach(function (series) {
  10147. types[series.type] = 1;
  10148. });
  10149. return Object.keys(types);
  10150. }
  10151. };
  10152. /**
  10153. * @private
  10154. */
  10155. H.Chart.prototype.updateA11yEnabled = function () {
  10156. var a11y = this.accessibility,
  10157. accessibilityOptions = this.options.accessibility;
  10158. if (accessibilityOptions && accessibilityOptions.enabled) {
  10159. if (a11y) {
  10160. a11y.update();
  10161. }
  10162. else {
  10163. this.accessibility = a11y = new Accessibility(this);
  10164. }
  10165. }
  10166. else if (a11y) {
  10167. // Destroy if after update we have a11y and it is disabled
  10168. if (a11y.destroy) {
  10169. a11y.destroy();
  10170. }
  10171. delete this.accessibility;
  10172. }
  10173. else {
  10174. // Just hide container
  10175. this.renderTo.setAttribute('aria-hidden', true);
  10176. }
  10177. };
  10178. // Handle updates to the module and send render updates to components
  10179. addEvent(H.Chart, 'render', function (e) {
  10180. // Update/destroy
  10181. if (this.a11yDirty && this.renderTo) {
  10182. delete this.a11yDirty;
  10183. this.updateA11yEnabled();
  10184. }
  10185. var a11y = this.accessibility;
  10186. if (a11y) {
  10187. a11y.getComponentOrder().forEach(function (componentName) {
  10188. a11y.components[componentName].onChartRender();
  10189. });
  10190. }
  10191. });
  10192. // Update with chart/series/point updates
  10193. addEvent(H.Chart, 'update', function (e) {
  10194. // Merge new options
  10195. var newOptions = e.options.accessibility;
  10196. if (newOptions) {
  10197. // Handle custom component updating specifically
  10198. if (newOptions.customComponents) {
  10199. this.options.accessibility.customComponents =
  10200. newOptions.customComponents;
  10201. delete newOptions.customComponents;
  10202. }
  10203. merge(true, this.options.accessibility, newOptions);
  10204. // Recreate from scratch
  10205. if (this.accessibility && this.accessibility.destroy) {
  10206. this.accessibility.destroy();
  10207. delete this.accessibility;
  10208. }
  10209. }
  10210. // Mark dirty for update
  10211. this.a11yDirty = true;
  10212. });
  10213. // Mark dirty for update
  10214. addEvent(Point, 'update', function () {
  10215. if (this.series.chart.accessibility) {
  10216. this.series.chart.a11yDirty = true;
  10217. }
  10218. });
  10219. ['addSeries', 'init'].forEach(function (event) {
  10220. addEvent(H.Chart, event, function () {
  10221. this.a11yDirty = true;
  10222. });
  10223. });
  10224. ['update', 'updatedData', 'remove'].forEach(function (event) {
  10225. addEvent(Series, event, function () {
  10226. if (this.chart.accessibility) {
  10227. this.chart.a11yDirty = true;
  10228. }
  10229. });
  10230. });
  10231. // Direct updates (events happen after render)
  10232. [
  10233. 'afterDrilldown', 'drillupall'
  10234. ].forEach(function (event) {
  10235. addEvent(H.Chart, event, function () {
  10236. if (this.accessibility) {
  10237. this.accessibility.update();
  10238. }
  10239. });
  10240. });
  10241. // Destroy with chart
  10242. addEvent(H.Chart, 'destroy', function () {
  10243. if (this.accessibility) {
  10244. this.accessibility.destroy();
  10245. }
  10246. });
  10247. });
  10248. _registerModule(_modules, 'masters/modules/accessibility.src.js', [], function () {
  10249. });
  10250. }));