accessibility.src.js 453 KB

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