accessibility.src.js 456 KB

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