stock-tools.src.js 367 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Advanced Highcharts Stock tools
  5. *
  6. * (c) 2010-2021 Highsoft AS
  7. * Author: Torstein Honsi
  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/stock-tools', ['highcharts', 'highcharts/modules/stock'], 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, 'Extensions/Annotations/Mixins/EventEmitterMixin.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  33. /* *
  34. *
  35. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  36. *
  37. * */
  38. var addEvent = U.addEvent,
  39. fireEvent = U.fireEvent,
  40. objectEach = U.objectEach,
  41. pick = U.pick,
  42. removeEvent = U.removeEvent;
  43. /* eslint-disable valid-jsdoc */
  44. /**
  45. * It provides methods for:
  46. * - adding and handling DOM events and a drag event,
  47. * - mapping a mouse move event to the distance between two following events.
  48. * The units of the distance are specific to a transformation,
  49. * e.g. for rotation they are radians, for scaling they are scale factors.
  50. *
  51. * @private
  52. * @mixin
  53. * @memberOf Annotation
  54. */
  55. var eventEmitterMixin = {
  56. /**
  57. * Add emitter events.
  58. */
  59. addEvents: function () {
  60. var emitter = this,
  61. addMouseDownEvent = function (element) {
  62. addEvent(element,
  63. H.isTouchDevice ? 'touchstart' : 'mousedown',
  64. function (e) {
  65. emitter.onMouseDown(e);
  66. }, { passive: false });
  67. };
  68. addMouseDownEvent(this.graphic.element);
  69. (emitter.labels || []).forEach(function (label) {
  70. if (label.options.useHTML && label.graphic.text) {
  71. // Mousedown event bound to HTML element (#13070).
  72. addMouseDownEvent(label.graphic.text.element);
  73. }
  74. });
  75. objectEach(emitter.options.events, function (event, type) {
  76. var eventHandler = function (e) {
  77. if (type !== 'click' || !emitter.cancelClick) {
  78. event.call(emitter,
  79. emitter.chart.pointer.normalize(e),
  80. emitter.target);
  81. }
  82. };
  83. if ((emitter.nonDOMEvents || []).indexOf(type) === -1) {
  84. emitter.graphic.on(type, eventHandler);
  85. }
  86. else {
  87. addEvent(emitter, type, eventHandler, { passive: false });
  88. }
  89. });
  90. if (emitter.options.draggable) {
  91. addEvent(emitter, 'drag', emitter.onDrag);
  92. if (!emitter.graphic.renderer.styledMode) {
  93. var cssPointer_1 = {
  94. cursor: {
  95. x: 'ew-resize',
  96. y: 'ns-resize',
  97. xy: 'move'
  98. }[emitter.options.draggable]
  99. };
  100. emitter.graphic.css(cssPointer_1);
  101. (emitter.labels || []).forEach(function (label) {
  102. if (label.options.useHTML && label.graphic.text) {
  103. label.graphic.text.css(cssPointer_1);
  104. }
  105. });
  106. }
  107. }
  108. if (!emitter.isUpdating) {
  109. fireEvent(emitter, 'add');
  110. }
  111. },
  112. /**
  113. * Remove emitter document events.
  114. */
  115. removeDocEvents: function () {
  116. if (this.removeDrag) {
  117. this.removeDrag = this.removeDrag();
  118. }
  119. if (this.removeMouseUp) {
  120. this.removeMouseUp = this.removeMouseUp();
  121. }
  122. },
  123. /**
  124. * Mouse down handler.
  125. */
  126. onMouseDown: function (e) {
  127. var emitter = this,
  128. pointer = emitter.chart.pointer,
  129. prevChartX,
  130. prevChartY;
  131. if (e.preventDefault) {
  132. e.preventDefault();
  133. }
  134. // On right click, do nothing:
  135. if (e.button === 2) {
  136. return;
  137. }
  138. e = pointer.normalize(e);
  139. prevChartX = e.chartX;
  140. prevChartY = e.chartY;
  141. emitter.cancelClick = false;
  142. emitter.chart.hasDraggedAnnotation = true;
  143. emitter.removeDrag = addEvent(H.doc, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
  144. emitter.hasDragged = true;
  145. e = pointer.normalize(e);
  146. e.prevChartX = prevChartX;
  147. e.prevChartY = prevChartY;
  148. fireEvent(emitter, 'drag', e);
  149. prevChartX = e.chartX;
  150. prevChartY = e.chartY;
  151. }, H.isTouchDevice ? { passive: false } : void 0);
  152. emitter.removeMouseUp = addEvent(H.doc, H.isTouchDevice ? 'touchend' : 'mouseup', function (e) {
  153. emitter.cancelClick = emitter.hasDragged;
  154. emitter.hasDragged = false;
  155. emitter.chart.hasDraggedAnnotation = false;
  156. // ControlPoints vs Annotation:
  157. fireEvent(pick(emitter.target, emitter), 'afterUpdate');
  158. emitter.onMouseUp(e);
  159. }, H.isTouchDevice ? { passive: false } : void 0);
  160. },
  161. /**
  162. * Mouse up handler.
  163. */
  164. onMouseUp: function (_e) {
  165. var chart = this.chart,
  166. annotation = this.target || this,
  167. annotationsOptions = chart.options.annotations,
  168. index = chart.annotations.indexOf(annotation);
  169. this.removeDocEvents();
  170. annotationsOptions[index] = annotation.options;
  171. },
  172. /**
  173. * Drag and drop event. All basic annotations should share this
  174. * capability as well as the extended ones.
  175. */
  176. onDrag: function (e) {
  177. if (this.chart.isInsidePlot(e.chartX - this.chart.plotLeft, e.chartY - this.chart.plotTop, {
  178. visiblePlotOnly: true
  179. })) {
  180. var translation_1 = this.mouseMoveToTranslation(e);
  181. if (this.options.draggable === 'x') {
  182. translation_1.y = 0;
  183. }
  184. if (this.options.draggable === 'y') {
  185. translation_1.x = 0;
  186. }
  187. if (this.points.length) {
  188. this.translate(translation_1.x, translation_1.y);
  189. }
  190. else {
  191. this.shapes.forEach(function (shape) {
  192. shape.translate(translation_1.x, translation_1.y);
  193. });
  194. this.labels.forEach(function (label) {
  195. label.translate(translation_1.x, translation_1.y);
  196. });
  197. }
  198. this.redraw(false);
  199. }
  200. },
  201. /**
  202. * Map mouse move event to the radians.
  203. */
  204. mouseMoveToRadians: function (e, cx, cy) {
  205. var prevDy = e.prevChartY - cy,
  206. prevDx = e.prevChartX - cx,
  207. dy = e.chartY - cy,
  208. dx = e.chartX - cx,
  209. temp;
  210. if (this.chart.inverted) {
  211. temp = prevDx;
  212. prevDx = prevDy;
  213. prevDy = temp;
  214. temp = dx;
  215. dx = dy;
  216. dy = temp;
  217. }
  218. return Math.atan2(dy, dx) - Math.atan2(prevDy, prevDx);
  219. },
  220. /**
  221. * Map mouse move event to the distance between two following events.
  222. */
  223. mouseMoveToTranslation: function (e) {
  224. var dx = e.chartX - e.prevChartX,
  225. dy = e.chartY - e.prevChartY,
  226. temp;
  227. if (this.chart.inverted) {
  228. temp = dy;
  229. dy = dx;
  230. dx = temp;
  231. }
  232. return {
  233. x: dx,
  234. y: dy
  235. };
  236. },
  237. /**
  238. * Map mouse move to the scale factors.
  239. *
  240. * @param {Object} e event
  241. * @param {number} cx center x
  242. * @param {number} cy center y
  243. **/
  244. mouseMoveToScale: function (e, cx, cy) {
  245. var prevDx = e.prevChartX - cx,
  246. prevDy = e.prevChartY - cy,
  247. dx = e.chartX - cx,
  248. dy = e.chartY - cy,
  249. sx = (dx || 1) / (prevDx || 1),
  250. sy = (dy || 1) / (prevDy || 1),
  251. temp;
  252. if (this.chart.inverted) {
  253. temp = sy;
  254. sy = sx;
  255. sx = temp;
  256. }
  257. return {
  258. x: sx,
  259. y: sy
  260. };
  261. },
  262. /**
  263. * Destroy the event emitter.
  264. */
  265. destroy: function () {
  266. this.removeDocEvents();
  267. removeEvent(this);
  268. this.hcEvents = null;
  269. }
  270. };
  271. return eventEmitterMixin;
  272. });
  273. _registerModule(_modules, 'Extensions/Annotations/ControlPoint.js', [_modules['Core/Utilities.js'], _modules['Extensions/Annotations/Mixins/EventEmitterMixin.js']], function (U, eventEmitterMixin) {
  274. /* *
  275. *
  276. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  277. *
  278. * */
  279. /**
  280. * Callback to modify annotation's possitioner controls.
  281. *
  282. * @callback Highcharts.AnnotationControlPointPositionerFunction
  283. * @param {Highcharts.AnnotationControlPoint} this
  284. * @param {Highcharts.AnnotationControllable} target
  285. * @return {Highcharts.PositionObject}
  286. */
  287. var extend = U.extend,
  288. merge = U.merge,
  289. pick = U.pick;
  290. /* eslint-disable no-invalid-this, valid-jsdoc */
  291. /**
  292. * A control point class which is a connection between controllable
  293. * transform methods and a user actions.
  294. *
  295. * @requires modules/annotations
  296. *
  297. * @class
  298. * @name Highcharts.AnnotationControlPoint
  299. *
  300. * @hideconstructor
  301. *
  302. * @param {Highcharts.Chart} chart
  303. * A chart instance.
  304. *
  305. * @param {Highcharts.AnnotationControllable} target
  306. * A controllable instance which is a target for a control point.
  307. *
  308. * @param {Highcharts.AnnotationControlPointOptionsObject} options
  309. * An options object.
  310. *
  311. * @param {number} [index]
  312. * Point index.
  313. */
  314. var ControlPoint = /** @class */ (function () {
  315. function ControlPoint(chart, target, options, index) {
  316. /**
  317. *
  318. * Properties
  319. *
  320. */
  321. this.addEvents = eventEmitterMixin.addEvents;
  322. this.graphic = void 0;
  323. this.mouseMoveToRadians = eventEmitterMixin.mouseMoveToRadians;
  324. this.mouseMoveToScale = eventEmitterMixin.mouseMoveToScale;
  325. this.mouseMoveToTranslation = eventEmitterMixin.mouseMoveToTranslation;
  326. this.onDrag = eventEmitterMixin.onDrag;
  327. this.onMouseDown = eventEmitterMixin.onMouseDown;
  328. this.onMouseUp = eventEmitterMixin.onMouseUp;
  329. this.removeDocEvents = eventEmitterMixin.removeDocEvents;
  330. /**
  331. *
  332. * Functions
  333. *
  334. */
  335. /**
  336. * List of events for `anntation.options.events` that should not be
  337. * added to `annotation.graphic` but to the `annotation`.
  338. * @private
  339. * @name Highcharts.AnnotationControlPoint#nonDOMEvents
  340. * @type {Array<string>}
  341. */
  342. this.nonDOMEvents = ['drag'];
  343. this.chart = chart;
  344. this.target = target;
  345. this.options = options;
  346. this.index = pick(options.index, index);
  347. }
  348. /**
  349. * Set the visibility of the control point.
  350. *
  351. * @function Highcharts.AnnotationControlPoint#setVisibility
  352. *
  353. * @param {boolean} visible
  354. * Visibility of the control point.
  355. *
  356. * @return {void}
  357. */
  358. ControlPoint.prototype.setVisibility = function (visible) {
  359. this.graphic.attr('visibility', visible ? 'visible' : 'hidden');
  360. this.options.visible = visible;
  361. };
  362. /**
  363. * Render the control point.
  364. * @private
  365. */
  366. ControlPoint.prototype.render = function () {
  367. var chart = this.chart,
  368. options = this.options;
  369. this.graphic = chart.renderer
  370. .symbol(options.symbol, 0, 0, options.width, options.height)
  371. .add(chart.controlPointsGroup)
  372. .css(options.style);
  373. this.setVisibility(options.visible);
  374. // npm test -- --tests "highcharts/annotations-advanced/*"
  375. this.addEvents();
  376. };
  377. /**
  378. * Redraw the control point.
  379. * @private
  380. * @param {boolean} [animation]
  381. */
  382. ControlPoint.prototype.redraw = function (animation) {
  383. this.graphic[animation ? 'animate' : 'attr'](this.options.positioner.call(this, this.target));
  384. };
  385. /**
  386. * Destroy the control point.
  387. * @private
  388. */
  389. ControlPoint.prototype.destroy = function () {
  390. eventEmitterMixin.destroy.call(this);
  391. if (this.graphic) {
  392. this.graphic = this.graphic.destroy();
  393. }
  394. this.chart = null;
  395. this.target = null;
  396. this.options = null;
  397. };
  398. /**
  399. * Update the control point.
  400. *
  401. * @function Highcharts.AnnotationControlPoint#update
  402. *
  403. * @param {Partial<Highcharts.AnnotationControlPointOptionsObject>} userOptions
  404. * New options for the control point.
  405. *
  406. * @return {void}
  407. */
  408. ControlPoint.prototype.update = function (userOptions) {
  409. var chart = this.chart,
  410. target = this.target,
  411. index = this.index,
  412. options = merge(true,
  413. this.options,
  414. userOptions);
  415. this.destroy();
  416. this.constructor(chart, target, options, index);
  417. this.render(chart.controlPointsGroup);
  418. this.redraw();
  419. };
  420. return ControlPoint;
  421. }());
  422. return ControlPoint;
  423. });
  424. _registerModule(_modules, 'Extensions/Annotations/MockPoint.js', [_modules['Core/Series/Series.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/Axis.js']], function (Series, U, Axis) {
  425. /* *
  426. *
  427. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  428. *
  429. * */
  430. /**
  431. * @private
  432. * @interface Highcharts.AnnotationMockLabelOptionsObject
  433. */ /**
  434. * Point instance of the point.
  435. * @name Highcharts.AnnotationMockLabelOptionsObject#point
  436. * @type {Highcharts.AnnotationMockPoint}
  437. */ /**
  438. * X value translated to x axis scale.
  439. * @name Highcharts.AnnotationMockLabelOptionsObject#x
  440. * @type {number|null}
  441. */ /**
  442. * Y value translated to y axis scale.
  443. * @name Highcharts.AnnotationMockLabelOptionsObject#y
  444. * @type {number|null}
  445. */
  446. /**
  447. * A mock series instance imitating a real series from a real point.
  448. * @private
  449. * @interface Highcharts.AnnotationMockSeries
  450. */ /**
  451. * Whether a series is visible.
  452. * @name Highcharts.AnnotationMockSeries#visible
  453. * @type {boolean}
  454. */ /**
  455. * A chart instance.
  456. * @name Highcharts.AnnotationMockSeries#chart
  457. * @type {Highcharts.Chart}
  458. */ /**
  459. * @name Highcharts.AnnotationMockSeries#getPlotBox
  460. * @type {Function}
  461. */
  462. /**
  463. * Indicates if this is a mock point for an annotation.
  464. * @name Highcharts.Point#mock
  465. * @type {boolean|undefined}
  466. */
  467. var defined = U.defined,
  468. extend = U.extend,
  469. fireEvent = U.fireEvent;
  470. /* eslint-disable no-invalid-this, valid-jsdoc */
  471. /**
  472. * A trimmed point object which imitates {@link Highchart.Point} class. It is
  473. * created when there is a need of pointing to some chart's position using axis
  474. * values or pixel values
  475. *
  476. * @requires modules/annotations
  477. *
  478. * @private
  479. * @class
  480. * @name Highcharts.AnnotationMockPoint
  481. *
  482. * @hideconstructor
  483. *
  484. * @param {Highcharts.Chart} chart
  485. * The chart instance.
  486. *
  487. * @param {Highcharts.AnnotationControllable|null} target
  488. * The related controllable.
  489. *
  490. * @param {Highcharts.AnnotationMockPointOptionsObject|Function} options
  491. * The options object.
  492. */
  493. var MockPoint = /** @class */ (function () {
  494. function MockPoint(chart, target, options) {
  495. this.isInside = void 0;
  496. this.negative = void 0;
  497. this.plotX = void 0;
  498. this.plotY = void 0;
  499. this.ttBelow = void 0;
  500. this.x = void 0;
  501. this.y = void 0;
  502. /* *
  503. *
  504. * Functions
  505. *
  506. * */
  507. /**
  508. * A flag indicating that a point is not the real one.
  509. *
  510. * @type {boolean}
  511. * @default true
  512. */
  513. this.mock = true;
  514. /**
  515. * A mock series instance imitating a real series from a real point.
  516. *
  517. * @name Annotation.AnnotationMockPoint#series
  518. * @type {Highcharts.AnnotationMockSeries}
  519. */
  520. this.series = {
  521. visible: true,
  522. chart: chart,
  523. getPlotBox: Series.prototype.getPlotBox
  524. };
  525. /**
  526. * @name Annotation.AnnotationMockPoint#target
  527. * @type {Highcharts.AnnotationControllable|null}
  528. */
  529. this.target = target || null;
  530. /**
  531. * Options for the mock point.
  532. *
  533. * @name Annotation.AnnotationMockPoint#options
  534. * @type {Highcharts.AnnotationsMockPointOptionsObject}
  535. */
  536. this.options = options;
  537. /**
  538. * If an xAxis is set it represents the point's value in terms of the
  539. * xAxis.
  540. *
  541. * @name Annotation.AnnotationMockPoint#x
  542. * @type {number|undefined}
  543. */
  544. /**
  545. * If an yAxis is set it represents the point's value in terms of the
  546. * yAxis.
  547. *
  548. * @name Annotation.AnnotationMockPoint#y
  549. * @type {number|undefined}
  550. */
  551. /**
  552. * It represents the point's pixel x coordinate relative to its plot
  553. * box.
  554. *
  555. * @name Annotation.AnnotationMockPoint#plotX
  556. * @type {number|undefined}
  557. */
  558. /**
  559. * It represents the point's pixel y position relative to its plot box.
  560. *
  561. * @name Annotation.AnnotationMockPoint#plotY
  562. * @type {number|undefined}
  563. */
  564. /**
  565. * Whether the point is inside the plot box.
  566. *
  567. * @name Annotation.AnnotationMockPoint#isInside
  568. * @type {boolean|undefined}
  569. */
  570. this.applyOptions(this.getOptions());
  571. }
  572. /**
  573. * Create a mock point from a real Highcharts point.
  574. *
  575. * @private
  576. * @static
  577. *
  578. * @param {Highcharts.Point} point
  579. *
  580. * @return {Highcharts.AnnotationMockPoint}
  581. * A mock point instance.
  582. */
  583. MockPoint.fromPoint = function (point) {
  584. return new MockPoint(point.series.chart, null, {
  585. x: point.x,
  586. y: point.y,
  587. xAxis: point.series.xAxis,
  588. yAxis: point.series.yAxis
  589. });
  590. };
  591. /**
  592. * Get the pixel position from the point like object.
  593. *
  594. * @private
  595. * @static
  596. *
  597. * @param {Highcharts.AnnotationPointType} point
  598. *
  599. * @param {boolean} [paneCoordinates]
  600. * whether the pixel position should be relative
  601. *
  602. * @return {Highcharts.PositionObject} pixel position
  603. */
  604. MockPoint.pointToPixels = function (point, paneCoordinates) {
  605. var series = point.series,
  606. chart = series.chart,
  607. x = point.plotX,
  608. y = point.plotY,
  609. plotBox;
  610. if (chart.inverted) {
  611. if (point.mock) {
  612. x = point.plotY;
  613. y = point.plotX;
  614. }
  615. else {
  616. x = chart.plotWidth - point.plotY;
  617. y = chart.plotHeight - point.plotX;
  618. }
  619. }
  620. if (series && !paneCoordinates) {
  621. plotBox = series.getPlotBox();
  622. x += plotBox.translateX;
  623. y += plotBox.translateY;
  624. }
  625. return {
  626. x: x,
  627. y: y
  628. };
  629. };
  630. /**
  631. * Get fresh mock point options from the point like object.
  632. *
  633. * @private
  634. * @static
  635. *
  636. * @param {Highcharts.AnnotationPointType} point
  637. *
  638. * @return {Highcharts.AnnotationMockPointOptionsObject}
  639. * A mock point's options.
  640. */
  641. MockPoint.pointToOptions = function (point) {
  642. return {
  643. x: point.x,
  644. y: point.y,
  645. xAxis: point.series.xAxis,
  646. yAxis: point.series.yAxis
  647. };
  648. };
  649. /**
  650. * Check if the point has dynamic options.
  651. * @private
  652. * @return {boolean}
  653. * A positive flag if the point has dynamic options.
  654. */
  655. MockPoint.prototype.hasDynamicOptions = function () {
  656. return typeof this.options === 'function';
  657. };
  658. /**
  659. * Get the point's options.
  660. * @private
  661. * @return {Highcharts.AnnotationMockPointOptionsObject}
  662. * The mock point's options.
  663. */
  664. MockPoint.prototype.getOptions = function () {
  665. return this.hasDynamicOptions() ?
  666. this.options(this.target) :
  667. this.options;
  668. };
  669. /**
  670. * Apply options for the point.
  671. * @private
  672. * @param {Highcharts.AnnotationMockPointOptionsObject} options
  673. */
  674. MockPoint.prototype.applyOptions = function (options) {
  675. this.command = options.command;
  676. this.setAxis(options, 'x');
  677. this.setAxis(options, 'y');
  678. this.refresh();
  679. };
  680. /**
  681. * Set x or y axis.
  682. * @private
  683. * @param {Highcharts.AnnotationMockPointOptionsObject} options
  684. * @param {string} xOrY
  685. * 'x' or 'y' string literal
  686. */
  687. MockPoint.prototype.setAxis = function (options, xOrY) {
  688. var axisName = (xOrY + 'Axis'),
  689. axisOptions = options[axisName],
  690. chart = this.series.chart;
  691. this.series[axisName] =
  692. axisOptions instanceof Axis ?
  693. axisOptions :
  694. defined(axisOptions) ?
  695. (chart[axisName][axisOptions] ||
  696. chart.get(axisOptions)) :
  697. null;
  698. };
  699. /**
  700. * Transform the mock point to an anchor (relative position on the chart).
  701. * @private
  702. * @return {Array<number>}
  703. * A quadruple of numbers which denotes x, y, width and height of the box
  704. **/
  705. MockPoint.prototype.toAnchor = function () {
  706. var anchor = [this.plotX,
  707. this.plotY, 0, 0];
  708. if (this.series.chart.inverted) {
  709. anchor[0] = this.plotY;
  710. anchor[1] = this.plotX;
  711. }
  712. return anchor;
  713. };
  714. /**
  715. * Returns a label config object - the same as
  716. * Highcharts.Point.prototype.getLabelConfig
  717. * @private
  718. * @return {Highcharts.AnnotationMockLabelOptionsObject} the point's label config
  719. */
  720. MockPoint.prototype.getLabelConfig = function () {
  721. return {
  722. x: this.x,
  723. y: this.y,
  724. point: this
  725. };
  726. };
  727. /**
  728. * Check if the point is inside its pane.
  729. * @private
  730. * @return {boolean} A flag indicating whether the point is inside the pane.
  731. */
  732. MockPoint.prototype.isInsidePlot = function () {
  733. var plotX = this.plotX,
  734. plotY = this.plotY,
  735. xAxis = this.series.xAxis,
  736. yAxis = this.series.yAxis,
  737. e = {
  738. x: plotX,
  739. y: plotY,
  740. isInsidePlot: true
  741. };
  742. if (xAxis) {
  743. e.isInsidePlot = defined(plotX) && plotX >= 0 && plotX <= xAxis.len;
  744. }
  745. if (yAxis) {
  746. e.isInsidePlot =
  747. e.isInsidePlot &&
  748. defined(plotY) &&
  749. plotY >= 0 && plotY <= yAxis.len;
  750. }
  751. fireEvent(this.series.chart, 'afterIsInsidePlot', e);
  752. return e.isInsidePlot;
  753. };
  754. /**
  755. * Refresh point values and coordinates based on its options.
  756. * @private
  757. */
  758. MockPoint.prototype.refresh = function () {
  759. var series = this.series,
  760. xAxis = series.xAxis,
  761. yAxis = series.yAxis,
  762. options = this.getOptions();
  763. if (xAxis) {
  764. this.x = options.x;
  765. this.plotX = xAxis.toPixels(options.x, true);
  766. }
  767. else {
  768. this.x = null;
  769. this.plotX = options.x;
  770. }
  771. if (yAxis) {
  772. this.y = options.y;
  773. this.plotY = yAxis.toPixels(options.y, true);
  774. }
  775. else {
  776. this.y = null;
  777. this.plotY = options.y;
  778. }
  779. this.isInside = this.isInsidePlot();
  780. };
  781. /**
  782. * Translate the point.
  783. *
  784. * @private
  785. *
  786. * @param {number|undefined} cx
  787. * Origin x transformation.
  788. *
  789. * @param {number|undefined} cy
  790. * Origin y transformation.
  791. *
  792. * @param {number} dx
  793. * Translation for x coordinate.
  794. *
  795. * @param {number} dy
  796. * Translation for y coordinate.
  797. **/
  798. MockPoint.prototype.translate = function (_cx, _cy, dx, dy) {
  799. if (!this.hasDynamicOptions()) {
  800. this.plotX += dx;
  801. this.plotY += dy;
  802. this.refreshOptions();
  803. }
  804. };
  805. /**
  806. * Scale the point.
  807. *
  808. * @private
  809. *
  810. * @param {number} cx
  811. * Origin x transformation.
  812. *
  813. * @param {number} cy
  814. * Origin y transformation.
  815. *
  816. * @param {number} sx
  817. * Scale factor x.
  818. *
  819. * @param {number} sy
  820. * Scale factor y.
  821. */
  822. MockPoint.prototype.scale = function (cx, cy, sx, sy) {
  823. if (!this.hasDynamicOptions()) {
  824. var x = this.plotX * sx,
  825. y = this.plotY * sy,
  826. tx = (1 - sx) * cx,
  827. ty = (1 - sy) * cy;
  828. this.plotX = tx + x;
  829. this.plotY = ty + y;
  830. this.refreshOptions();
  831. }
  832. };
  833. /**
  834. * Rotate the point.
  835. * @private
  836. * @param {number} cx origin x rotation
  837. * @param {number} cy origin y rotation
  838. * @param {number} radians
  839. */
  840. MockPoint.prototype.rotate = function (cx, cy, radians) {
  841. if (!this.hasDynamicOptions()) {
  842. var cos = Math.cos(radians),
  843. sin = Math.sin(radians),
  844. x = this.plotX,
  845. y = this.plotY,
  846. tx = void 0,
  847. ty = void 0;
  848. x -= cx;
  849. y -= cy;
  850. tx = x * cos - y * sin;
  851. ty = x * sin + y * cos;
  852. this.plotX = tx + cx;
  853. this.plotY = ty + cy;
  854. this.refreshOptions();
  855. }
  856. };
  857. /**
  858. * Refresh point options based on its plot coordinates.
  859. * @private
  860. */
  861. MockPoint.prototype.refreshOptions = function () {
  862. var series = this.series,
  863. xAxis = series.xAxis,
  864. yAxis = series.yAxis;
  865. this.x = this.options.x = xAxis ?
  866. this.options.x = xAxis.toValue(this.plotX, true) :
  867. this.plotX;
  868. this.y = this.options.y = yAxis ?
  869. yAxis.toValue(this.plotY, true) :
  870. this.plotY;
  871. };
  872. return MockPoint;
  873. }());
  874. return MockPoint;
  875. });
  876. _registerModule(_modules, 'Extensions/Annotations/Mixins/ControllableMixin.js', [_modules['Extensions/Annotations/ControlPoint.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Tooltip.js'], _modules['Core/Utilities.js']], function (ControlPoint, MockPoint, Tooltip, U) {
  877. /* *
  878. *
  879. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  880. *
  881. * */
  882. var isObject = U.isObject,
  883. isString = U.isString,
  884. merge = U.merge,
  885. splat = U.splat;
  886. /**
  887. * An object which denots a controllable's anchor positions - relative and
  888. * absolute.
  889. *
  890. * @private
  891. * @interface Highcharts.AnnotationAnchorObject
  892. */ /**
  893. * Relative to the plot area position
  894. * @name Highcharts.AnnotationAnchorObject#relativePosition
  895. * @type {Highcharts.BBoxObject}
  896. */ /**
  897. * Absolute position
  898. * @name Highcharts.AnnotationAnchorObject#absolutePosition
  899. * @type {Highcharts.BBoxObject}
  900. */
  901. /**
  902. * @interface Highcharts.AnnotationControllable
  903. */ /**
  904. * @name Highcharts.AnnotationControllable#annotation
  905. * @type {Highcharts.Annotation}
  906. */ /**
  907. * @name Highcharts.AnnotationControllable#chart
  908. * @type {Highcharts.Chart}
  909. */ /**
  910. * @name Highcharts.AnnotationControllable#collection
  911. * @type {string}
  912. */ /**
  913. * @private
  914. * @name Highcharts.AnnotationControllable#controlPoints
  915. * @type {Array<Highcharts.AnnotationControlPoint>}
  916. */ /**
  917. * @name Highcharts.AnnotationControllable#points
  918. * @type {Array<Highcharts.Point>}
  919. */
  920. /* eslint-disable no-invalid-this, valid-jsdoc */
  921. /**
  922. * It provides methods for handling points, control points
  923. * and points transformations.
  924. *
  925. * @private
  926. * @mixin
  927. * @name Highcharts.AnnotationControllableMixin
  928. */
  929. var controllableMixin = {
  930. /**
  931. * Init the controllable
  932. */
  933. init: function (annotation,
  934. options,
  935. index) {
  936. this.annotation = annotation;
  937. this.chart = annotation.chart;
  938. this.options = options;
  939. this.points = [];
  940. this.controlPoints = [];
  941. this.index = index;
  942. this.linkPoints();
  943. this.addControlPoints();
  944. },
  945. /**
  946. * Redirect attr usage on the controllable graphic element.
  947. */
  948. attr: function () {
  949. this.graphic.attr.apply(this.graphic, arguments);
  950. },
  951. /**
  952. * Get the controllable's points options.
  953. *
  954. * @return {Array<Highcharts.PointOptionsObject>}
  955. * An array of points' options.
  956. */
  957. getPointsOptions: function () {
  958. var options = this.options;
  959. return (options.points || (options.point && splat(options.point)));
  960. },
  961. /**
  962. * Utility function for mapping item's options
  963. * to element's attribute
  964. *
  965. * @param {Highcharts.AnnotationsLabelsOptions|Highcharts.AnnotationsShapesOptions} options
  966. *
  967. * @return {Highcharts.SVGAttributes}
  968. * Mapped options.
  969. */
  970. attrsFromOptions: function (options) {
  971. var map = this.constructor.attrsMap,
  972. attrs = {},
  973. key,
  974. mappedKey,
  975. styledMode = this.chart.styledMode;
  976. for (key in options) { // eslint-disable-line guard-for-in
  977. mappedKey = map[key];
  978. if (mappedKey &&
  979. (!styledMode ||
  980. ['fill', 'stroke', 'stroke-width']
  981. .indexOf(mappedKey) === -1)) {
  982. attrs[mappedKey] = options[key];
  983. }
  984. }
  985. return attrs;
  986. },
  987. /**
  988. * Returns object which denotes anchor position - relative and absolute.
  989. *
  990. * @param {Highcharts.AnnotationPointType} point
  991. * A point like object.
  992. *
  993. * @return {Highcharts.AnnotationAnchorObject} a controllable anchor
  994. */
  995. anchor: function (point) {
  996. var plotBox = point.series.getPlotBox(),
  997. chart = point.series.chart,
  998. box = point.mock ?
  999. point.toAnchor() :
  1000. Tooltip.prototype.getAnchor.call({
  1001. chart: point.series.chart
  1002. },
  1003. point),
  1004. anchor = {
  1005. x: box[0] + (this.options.x || 0),
  1006. y: box[1] + (this.options.y || 0),
  1007. height: box[2] || 0,
  1008. width: box[3] || 0
  1009. };
  1010. return {
  1011. relativePosition: anchor,
  1012. absolutePosition: merge(anchor, {
  1013. x: anchor.x + (point.mock ? plotBox.translateX : chart.plotLeft),
  1014. y: anchor.y + (point.mock ? plotBox.translateY : chart.plotTop)
  1015. })
  1016. };
  1017. },
  1018. /**
  1019. * Map point's options to a point-like object.
  1020. *
  1021. * @param {string|Function|Highcharts.AnnotationMockPointOptionsObject|Highcharts.AnnotationPointType} pointOptions
  1022. * Point's options.
  1023. *
  1024. * @param {Highcharts.AnnotationPointType} point
  1025. * A point-like instance.
  1026. *
  1027. * @return {Highcharts.AnnotationPointType|null}
  1028. * if the point is found/set returns this point, otherwise null
  1029. */
  1030. point: function (pointOptions, point) {
  1031. if (pointOptions && pointOptions.series) {
  1032. return pointOptions;
  1033. }
  1034. if (!point || point.series === null) {
  1035. if (isObject(pointOptions)) {
  1036. point = new MockPoint(this.chart, this, pointOptions);
  1037. }
  1038. else if (isString(pointOptions)) {
  1039. point = this.chart.get(pointOptions) || null;
  1040. }
  1041. else if (typeof pointOptions === 'function') {
  1042. var pointConfig = pointOptions.call(point,
  1043. this);
  1044. point = pointConfig.series ?
  1045. pointConfig :
  1046. new MockPoint(this.chart, this, pointOptions);
  1047. }
  1048. }
  1049. return point;
  1050. },
  1051. /**
  1052. * Find point-like objects based on points options.
  1053. *
  1054. * @return {Array<Annotation.PointLike>} an array of point-like objects
  1055. */
  1056. linkPoints: function () {
  1057. var pointsOptions = this.getPointsOptions(),
  1058. points = this.points,
  1059. len = (pointsOptions && pointsOptions.length) || 0,
  1060. i,
  1061. point;
  1062. for (i = 0; i < len; i++) {
  1063. point = this.point(pointsOptions[i], points[i]);
  1064. if (!point) {
  1065. points.length = 0;
  1066. return;
  1067. }
  1068. if (point.mock) {
  1069. point.refresh();
  1070. }
  1071. points[i] = point;
  1072. }
  1073. return points;
  1074. },
  1075. /**
  1076. * Add control points to a controllable.
  1077. */
  1078. addControlPoints: function () {
  1079. var controlPointsOptions = this.options.controlPoints;
  1080. (controlPointsOptions || []).forEach(function (controlPointOptions, i) {
  1081. var options = merge(this.options.controlPointOptions,
  1082. controlPointOptions);
  1083. if (!options.index) {
  1084. options.index = i;
  1085. }
  1086. controlPointsOptions[i] = options;
  1087. this.controlPoints.push(new ControlPoint(this.chart, this, options));
  1088. }, this);
  1089. },
  1090. /**
  1091. * Check if a controllable should be rendered/redrawn.
  1092. *
  1093. * @return {boolean}
  1094. * Whether a controllable should be drawn.
  1095. */
  1096. shouldBeDrawn: function () {
  1097. return Boolean(this.points.length);
  1098. },
  1099. /**
  1100. * Render a controllable.
  1101. */
  1102. render: function (_parentGroup) {
  1103. this.controlPoints.forEach(function (controlPoint) {
  1104. controlPoint.render();
  1105. });
  1106. },
  1107. /**
  1108. * Redraw a controllable.
  1109. *
  1110. * @param {boolean} [animation]
  1111. */
  1112. redraw: function (animation) {
  1113. this.controlPoints.forEach(function (controlPoint) {
  1114. controlPoint.redraw(animation);
  1115. });
  1116. },
  1117. /**
  1118. * Transform a controllable with a specific transformation.
  1119. *
  1120. * @param {string} transformation a transformation name
  1121. * @param {number|null} cx origin x transformation
  1122. * @param {number|null} cy origin y transformation
  1123. * @param {number} p1 param for the transformation
  1124. * @param {number} [p2] param for the transformation
  1125. */
  1126. transform: function (transformation, cx, cy, p1, p2) {
  1127. if (this.chart.inverted) {
  1128. var temp = cx;
  1129. cx = cy;
  1130. cy = temp;
  1131. }
  1132. this.points.forEach(function (point, i) {
  1133. this.transformPoint(transformation, cx, cy, p1, p2, i);
  1134. }, this);
  1135. },
  1136. /**
  1137. * Transform a point with a specific transformation
  1138. * If a transformed point is a real point it is replaced with
  1139. * the mock point.
  1140. *
  1141. * @param {string} transformation a transformation name
  1142. * @param {number|null} cx origin x transformation
  1143. * @param {number|null} cy origin y transformation
  1144. * @param {number} p1 param for the transformation
  1145. * @param {number|undefined} p2 param for the transformation
  1146. * @param {number} i index of the point
  1147. */
  1148. transformPoint: function (transformation, cx, cy, p1, p2, i) {
  1149. var point = this.points[i];
  1150. if (!point.mock) {
  1151. point = this.points[i] = MockPoint.fromPoint(point);
  1152. }
  1153. point[transformation](cx, cy, p1, p2);
  1154. },
  1155. /**
  1156. * Translate a controllable.
  1157. *
  1158. * @param {number} dx translation for x coordinate
  1159. * @param {number} dy translation for y coordinate
  1160. **/
  1161. translate: function (dx, dy) {
  1162. this.transform('translate', null, null, dx, dy);
  1163. },
  1164. /**
  1165. * Translate a specific point within a controllable.
  1166. *
  1167. * @param {number} dx translation for x coordinate
  1168. * @param {number} dy translation for y coordinate
  1169. * @param {number} i index of the point
  1170. **/
  1171. translatePoint: function (dx, dy, i) {
  1172. this.transformPoint('translate', null, null, dx, dy, i);
  1173. },
  1174. /**
  1175. * Translate shape within controllable item.
  1176. * Replaces `controllable.translate` method.
  1177. *
  1178. * @param {number} dx translation for x coordinate
  1179. * @param {number} dy translation for y coordinate
  1180. */
  1181. translateShape: function (dx, dy) {
  1182. var chart = this.annotation.chart,
  1183. // Annotation.options
  1184. shapeOptions = this.annotation.userOptions,
  1185. // Chart.options.annotations
  1186. annotationIndex = chart.annotations.indexOf(this.annotation),
  1187. chartOptions = chart.options.annotations[annotationIndex];
  1188. this.translatePoint(dx, dy, 0);
  1189. // Options stored in:
  1190. // - chart (for exporting)
  1191. // - current config (for redraws)
  1192. chartOptions[this.collection][this.index].point = this.options.point;
  1193. shapeOptions[this.collection][this.index].point = this.options.point;
  1194. },
  1195. /**
  1196. * Rotate a controllable.
  1197. *
  1198. * @param {number} cx origin x rotation
  1199. * @param {number} cy origin y rotation
  1200. * @param {number} radians
  1201. **/
  1202. rotate: function (cx, cy, radians) {
  1203. this.transform('rotate', cx, cy, radians);
  1204. },
  1205. /**
  1206. * Scale a controllable.
  1207. *
  1208. * @param {number} cx origin x rotation
  1209. * @param {number} cy origin y rotation
  1210. * @param {number} sx scale factor x
  1211. * @param {number} sy scale factor y
  1212. */
  1213. scale: function (cx, cy, sx, sy) {
  1214. this.transform('scale', cx, cy, sx, sy);
  1215. },
  1216. /**
  1217. * Set control points' visibility.
  1218. *
  1219. * @param {boolean} visible
  1220. */
  1221. setControlPointsVisibility: function (visible) {
  1222. this.controlPoints.forEach(function (controlPoint) {
  1223. controlPoint.setVisibility(visible);
  1224. });
  1225. },
  1226. /**
  1227. * Destroy a controllable.
  1228. */
  1229. destroy: function () {
  1230. if (this.graphic) {
  1231. this.graphic = this.graphic.destroy();
  1232. }
  1233. if (this.tracker) {
  1234. this.tracker = this.tracker.destroy();
  1235. }
  1236. this.controlPoints.forEach(function (controlPoint) {
  1237. controlPoint.destroy();
  1238. });
  1239. this.chart = null;
  1240. this.points = null;
  1241. this.controlPoints = null;
  1242. this.options = null;
  1243. if (this.annotation) {
  1244. this.annotation = null;
  1245. }
  1246. },
  1247. /**
  1248. * Update a controllable.
  1249. *
  1250. * @param {Object} newOptions
  1251. */
  1252. update: function (newOptions) {
  1253. var annotation = this.annotation,
  1254. options = merge(true,
  1255. this.options,
  1256. newOptions),
  1257. parentGroup = this.graphic.parentGroup;
  1258. this.destroy();
  1259. this.constructor(annotation, options, this.index);
  1260. this.render(parentGroup);
  1261. this.redraw();
  1262. }
  1263. };
  1264. return controllableMixin;
  1265. });
  1266. _registerModule(_modules, 'Extensions/Annotations/Mixins/MarkerMixin.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js']], function (Chart, SVGRenderer, U) {
  1267. /* *
  1268. *
  1269. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1270. *
  1271. * */
  1272. var addEvent = U.addEvent,
  1273. defined = U.defined,
  1274. merge = U.merge,
  1275. uniqueKey = U.uniqueKey;
  1276. /**
  1277. * Options for configuring markers for annotations.
  1278. *
  1279. * An example of the arrow marker:
  1280. * <pre>
  1281. * {
  1282. * arrow: {
  1283. * id: 'arrow',
  1284. * tagName: 'marker',
  1285. * refY: 5,
  1286. * refX: 5,
  1287. * markerWidth: 10,
  1288. * markerHeight: 10,
  1289. * children: [{
  1290. * tagName: 'path',
  1291. * attrs: {
  1292. * d: 'M 0 0 L 10 5 L 0 10 Z',
  1293. * 'stroke-width': 0
  1294. * }
  1295. * }]
  1296. * }
  1297. * }
  1298. * </pre>
  1299. *
  1300. * @sample highcharts/annotations/custom-markers/
  1301. * Define a custom marker for annotations
  1302. *
  1303. * @sample highcharts/css/annotations-markers/
  1304. * Define markers in a styled mode
  1305. *
  1306. * @type {Highcharts.Dictionary<Highcharts.ASTNode>}
  1307. * @since 6.0.0
  1308. * @optionparent defs
  1309. */
  1310. var defaultMarkers = {
  1311. /**
  1312. * @type {Highcharts.ASTNode}
  1313. */
  1314. arrow: {
  1315. tagName: 'marker',
  1316. attributes: {
  1317. id: 'arrow',
  1318. refY: 5,
  1319. refX: 9,
  1320. markerWidth: 10,
  1321. markerHeight: 10
  1322. },
  1323. /**
  1324. * @type {Array<Highcharts.DefsOptions>}
  1325. */
  1326. children: [{
  1327. tagName: 'path',
  1328. attributes: {
  1329. d: 'M 0 0 L 10 5 L 0 10 Z',
  1330. 'stroke-width': 0
  1331. }
  1332. }]
  1333. },
  1334. /**
  1335. * @type {Highcharts.ASTNode}
  1336. */
  1337. 'reverse-arrow': {
  1338. tagName: 'marker',
  1339. attributes: {
  1340. id: 'reverse-arrow',
  1341. refY: 5,
  1342. refX: 1,
  1343. markerWidth: 10,
  1344. markerHeight: 10
  1345. },
  1346. children: [{
  1347. tagName: 'path',
  1348. attributes: {
  1349. // reverse triangle (used as an arrow)
  1350. d: 'M 0 5 L 10 0 L 10 10 Z',
  1351. 'stroke-width': 0
  1352. }
  1353. }]
  1354. }
  1355. };
  1356. SVGRenderer.prototype.addMarker = function (id, markerOptions) {
  1357. var options = { attributes: { id: id } };
  1358. var attrs = {
  1359. stroke: markerOptions.color || 'none',
  1360. fill: markerOptions.color || 'rgba(0, 0, 0, 0.75)'
  1361. };
  1362. options.children = (markerOptions.children &&
  1363. markerOptions.children.map(function (child) {
  1364. return merge(attrs, child);
  1365. }));
  1366. var ast = merge(true, {
  1367. attributes: {
  1368. markerWidth: 20,
  1369. markerHeight: 20,
  1370. refX: 0,
  1371. refY: 0,
  1372. orient: 'auto'
  1373. }
  1374. },
  1375. markerOptions,
  1376. options);
  1377. var marker = this.definition(ast);
  1378. marker.id = id;
  1379. return marker;
  1380. };
  1381. /* eslint-disable no-invalid-this, valid-jsdoc */
  1382. /**
  1383. * @private
  1384. */
  1385. function createMarkerSetter(markerType) {
  1386. return function (value) {
  1387. this.attr(markerType, 'url(#' + value + ')');
  1388. };
  1389. }
  1390. /**
  1391. * @private
  1392. * @mixin
  1393. * @name Highcharts.AnnotaitonMarkerMixin
  1394. */
  1395. var markerMixin = {
  1396. markerEndSetter: createMarkerSetter('marker-end'),
  1397. markerStartSetter: createMarkerSetter('marker-start'),
  1398. /**
  1399. * Set markers.
  1400. * @private
  1401. * @param {Highcharts.AnnotationControllablePath} item
  1402. */
  1403. setItemMarkers: function (item) {
  1404. var itemOptions = item.options,
  1405. chart = item.chart,
  1406. defs = chart.options.defs,
  1407. fill = itemOptions.fill,
  1408. color = defined(fill) && fill !== 'none' ?
  1409. fill :
  1410. itemOptions.stroke,
  1411. setMarker = function (markerType) {
  1412. var markerId = itemOptions[markerType],
  1413. def,
  1414. predefinedMarker,
  1415. key,
  1416. marker;
  1417. if (markerId) {
  1418. for (key in defs) { // eslint-disable-line guard-for-in
  1419. def = defs[key];
  1420. if ((markerId === (def.attributes && def.attributes.id) ||
  1421. // Legacy, for
  1422. // unit-tests/annotations/annotations-shapes
  1423. markerId === def.id) &&
  1424. def.tagName === 'marker') {
  1425. predefinedMarker = def;
  1426. break;
  1427. }
  1428. }
  1429. if (predefinedMarker) {
  1430. marker = item[markerType] = chart.renderer
  1431. .addMarker((itemOptions.id || uniqueKey()) + '-' +
  1432. markerId, merge(predefinedMarker, { color: color }));
  1433. item.attr(markerType, marker.getAttribute('id'));
  1434. }
  1435. }
  1436. };
  1437. ['markerStart', 'markerEnd'].forEach(setMarker);
  1438. }
  1439. };
  1440. addEvent(Chart, 'afterGetContainer', function () {
  1441. this.options.defs = merge(defaultMarkers, this.options.defs || {});
  1442. // objectEach(this.options.defs, function (def): void {
  1443. // const attributes = def.attributes;
  1444. // if (
  1445. // def.tagName === 'marker' &&
  1446. // attributes &&
  1447. // attributes.id &&
  1448. // attributes.display !== 'none'
  1449. // ) {
  1450. // this.renderer.addMarker(attributes.id, def);
  1451. // }
  1452. // }, this);
  1453. });
  1454. return markerMixin;
  1455. });
  1456. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllablePath.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/Mixins/MarkerMixin.js'], _modules['Core/Utilities.js']], function (ControllableMixin, H, MarkerMixin, U) {
  1457. /* *
  1458. *
  1459. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1460. *
  1461. * */
  1462. var extend = U.extend;
  1463. // See TRACKER_FILL in highcharts.src.js
  1464. var TRACKER_FILL = 'rgba(192,192,192,' + (H.svg ? 0.0001 : 0.002) + ')';
  1465. /* eslint-disable no-invalid-this, valid-jsdoc */
  1466. /**
  1467. * A controllable path class.
  1468. *
  1469. * @requires modules/annotations
  1470. *
  1471. * @private
  1472. * @class
  1473. * @name Highcharts.AnnotationControllablePath
  1474. *
  1475. * @param {Highcharts.Annotation}
  1476. * Related annotation.
  1477. *
  1478. * @param {Highcharts.AnnotationsShapeOptions} options
  1479. * A path's options object.
  1480. *
  1481. * @param {number} index
  1482. * Index of the path.
  1483. */
  1484. var ControllablePath = /** @class */ (function () {
  1485. /* *
  1486. *
  1487. * Constructors
  1488. *
  1489. * */
  1490. function ControllablePath(annotation, options, index) {
  1491. /* *
  1492. *
  1493. * Properties
  1494. *
  1495. * */
  1496. this.addControlPoints = ControllableMixin.addControlPoints;
  1497. this.anchor = ControllableMixin.anchor;
  1498. this.attr = ControllableMixin.attr;
  1499. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1500. this.destroy = ControllableMixin.destroy;
  1501. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1502. this.init = ControllableMixin.init;
  1503. this.linkPoints = ControllableMixin.linkPoints;
  1504. this.point = ControllableMixin.point;
  1505. this.rotate = ControllableMixin.rotate;
  1506. this.scale = ControllableMixin.scale;
  1507. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1508. this.setMarkers = MarkerMixin.setItemMarkers;
  1509. this.transform = ControllableMixin.transform;
  1510. this.transformPoint = ControllableMixin.transformPoint;
  1511. this.translate = ControllableMixin.translate;
  1512. this.translatePoint = ControllableMixin.translatePoint;
  1513. this.translateShape = ControllableMixin.translateShape;
  1514. this.update = ControllableMixin.update;
  1515. /**
  1516. * @type 'path'
  1517. */
  1518. this.type = 'path';
  1519. this.init(annotation, options, index);
  1520. this.collection = 'shapes';
  1521. }
  1522. /* *
  1523. *
  1524. * Functions
  1525. *
  1526. * */
  1527. /**
  1528. * Map the controllable path to 'd' path attribute.
  1529. *
  1530. * @return {Highcharts.SVGPathArray|null}
  1531. * A path's d attribute.
  1532. */
  1533. ControllablePath.prototype.toD = function () {
  1534. var dOption = this.options.d;
  1535. if (dOption) {
  1536. return typeof dOption === 'function' ?
  1537. dOption.call(this) :
  1538. dOption;
  1539. }
  1540. var points = this.points,
  1541. len = points.length,
  1542. showPath = len,
  1543. point = points[0],
  1544. position = showPath && this.anchor(point).absolutePosition,
  1545. pointIndex = 0,
  1546. command,
  1547. d = [];
  1548. if (position) {
  1549. d.push(['M', position.x, position.y]);
  1550. while (++pointIndex < len && showPath) {
  1551. point = points[pointIndex];
  1552. command = point.command || 'L';
  1553. position = this.anchor(point).absolutePosition;
  1554. if (command === 'M') {
  1555. d.push([command, position.x, position.y]);
  1556. }
  1557. else if (command === 'L') {
  1558. d.push([command, position.x, position.y]);
  1559. }
  1560. else if (command === 'Z') {
  1561. d.push([command]);
  1562. }
  1563. showPath = point.series.visible;
  1564. }
  1565. }
  1566. return showPath ?
  1567. this.chart.renderer.crispLine(d, this.graphic.strokeWidth()) :
  1568. null;
  1569. };
  1570. ControllablePath.prototype.shouldBeDrawn = function () {
  1571. return (ControllableMixin.shouldBeDrawn.call(this) || Boolean(this.options.d));
  1572. };
  1573. ControllablePath.prototype.render = function (parent) {
  1574. var options = this.options,
  1575. attrs = this.attrsFromOptions(options);
  1576. this.graphic = this.annotation.chart.renderer
  1577. .path([['M', 0, 0]])
  1578. .attr(attrs)
  1579. .add(parent);
  1580. if (options.className) {
  1581. this.graphic.addClass(options.className);
  1582. }
  1583. this.tracker = this.annotation.chart.renderer
  1584. .path([['M', 0, 0]])
  1585. .addClass('highcharts-tracker-line')
  1586. .attr({
  1587. zIndex: 2
  1588. })
  1589. .add(parent);
  1590. if (!this.annotation.chart.styledMode) {
  1591. this.tracker.attr({
  1592. 'stroke-linejoin': 'round',
  1593. stroke: TRACKER_FILL,
  1594. fill: TRACKER_FILL,
  1595. 'stroke-width': this.graphic.strokeWidth() +
  1596. options.snap * 2
  1597. });
  1598. }
  1599. ControllableMixin.render.call(this);
  1600. extend(this.graphic, {
  1601. markerStartSetter: MarkerMixin.markerStartSetter,
  1602. markerEndSetter: MarkerMixin.markerEndSetter
  1603. });
  1604. this.setMarkers(this);
  1605. };
  1606. ControllablePath.prototype.redraw = function (animation) {
  1607. var d = this.toD(),
  1608. action = animation ? 'animate' : 'attr';
  1609. if (d) {
  1610. this.graphic[action]({ d: d });
  1611. this.tracker[action]({ d: d });
  1612. }
  1613. else {
  1614. this.graphic.attr({ d: 'M 0 ' + -9e9 });
  1615. this.tracker.attr({ d: 'M 0 ' + -9e9 });
  1616. }
  1617. this.graphic.placed = this.tracker.placed = Boolean(d);
  1618. ControllableMixin.redraw.call(this, animation);
  1619. };
  1620. /* *
  1621. *
  1622. * Static Properties
  1623. *
  1624. * */
  1625. /**
  1626. * A map object which allows to map options attributes to element attributes
  1627. *
  1628. * @name Highcharts.AnnotationControllablePath.attrsMap
  1629. * @type {Highcharts.Dictionary<string>}
  1630. */
  1631. ControllablePath.attrsMap = {
  1632. dashStyle: 'dashstyle',
  1633. strokeWidth: 'stroke-width',
  1634. stroke: 'stroke',
  1635. fill: 'fill',
  1636. zIndex: 'zIndex'
  1637. };
  1638. return ControllablePath;
  1639. }());
  1640. return ControllablePath;
  1641. });
  1642. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableRect.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Core/Utilities.js']], function (ControllableMixin, ControllablePath, U) {
  1643. /* *
  1644. *
  1645. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1646. *
  1647. * */
  1648. var merge = U.merge;
  1649. /**
  1650. * @typedef {Annotation.ControllablePath.AttrsMap}
  1651. * Annotation.ControllableRect.AttrsMap
  1652. * @property {string} width=width
  1653. * @property {string} height=height
  1654. */
  1655. /* eslint-disable no-invalid-this, valid-jsdoc */
  1656. /**
  1657. * A controllable rect class.
  1658. *
  1659. * @requires modules/annotations
  1660. *
  1661. * @private
  1662. * @class
  1663. * @name Highcharts.AnnotationControllableRect
  1664. *
  1665. * @param {Highcharts.Annotation} annotation
  1666. * An annotation instance.
  1667. *
  1668. * @param {Highcharts.AnnotationsShapeOptions} options
  1669. * A rect's options.
  1670. *
  1671. * @param {number} index
  1672. * Index of the rectangle
  1673. */
  1674. var ControllableRect = /** @class */ (function () {
  1675. /* *
  1676. *
  1677. * Constructors
  1678. *
  1679. * */
  1680. function ControllableRect(annotation, options, index) {
  1681. /* *
  1682. *
  1683. * Properties
  1684. *
  1685. * */
  1686. this.addControlPoints = ControllableMixin.addControlPoints;
  1687. this.anchor = ControllableMixin.anchor;
  1688. this.attr = ControllableMixin.attr;
  1689. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1690. this.destroy = ControllableMixin.destroy;
  1691. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1692. this.init = ControllableMixin.init;
  1693. this.linkPoints = ControllableMixin.linkPoints;
  1694. this.point = ControllableMixin.point;
  1695. this.rotate = ControllableMixin.rotate;
  1696. this.scale = ControllableMixin.scale;
  1697. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1698. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1699. this.transform = ControllableMixin.transform;
  1700. this.transformPoint = ControllableMixin.transformPoint;
  1701. this.translatePoint = ControllableMixin.translatePoint;
  1702. this.translateShape = ControllableMixin.translateShape;
  1703. this.update = ControllableMixin.update;
  1704. /**
  1705. * @type 'rect'
  1706. */
  1707. this.type = 'rect';
  1708. this.translate = ControllableMixin.translateShape;
  1709. this.init(annotation, options, index);
  1710. this.collection = 'shapes';
  1711. }
  1712. /* *
  1713. *
  1714. * Functions
  1715. *
  1716. * */
  1717. ControllableRect.prototype.render = function (parent) {
  1718. var attrs = this.attrsFromOptions(this.options);
  1719. this.graphic = this.annotation.chart.renderer
  1720. .rect(0, -9e9, 0, 0)
  1721. .attr(attrs)
  1722. .add(parent);
  1723. ControllableMixin.render.call(this);
  1724. };
  1725. ControllableRect.prototype.redraw = function (animation) {
  1726. var position = this.anchor(this.points[0]).absolutePosition;
  1727. if (position) {
  1728. this.graphic[animation ? 'animate' : 'attr']({
  1729. x: position.x,
  1730. y: position.y,
  1731. width: this.options.width,
  1732. height: this.options.height
  1733. });
  1734. }
  1735. else {
  1736. this.attr({
  1737. x: 0,
  1738. y: -9e9
  1739. });
  1740. }
  1741. this.graphic.placed = Boolean(position);
  1742. ControllableMixin.redraw.call(this, animation);
  1743. };
  1744. /* *
  1745. *
  1746. * Static Properties
  1747. *
  1748. * */
  1749. /**
  1750. * A map object which allows to map options attributes to element attributes
  1751. *
  1752. * @type {Annotation.ControllableRect.AttrsMap}
  1753. */
  1754. ControllableRect.attrsMap = merge(ControllablePath.attrsMap, {
  1755. width: 'width',
  1756. height: 'height'
  1757. });
  1758. return ControllableRect;
  1759. }());
  1760. return ControllableRect;
  1761. });
  1762. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableCircle.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Core/Utilities.js']], function (ControllableMixin, ControllablePath, U) {
  1763. /* *
  1764. *
  1765. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1766. *
  1767. * */
  1768. var merge = U.merge;
  1769. /* eslint-disable no-invalid-this, valid-jsdoc */
  1770. /**
  1771. * A controllable circle class.
  1772. *
  1773. * @requires modules/annotations
  1774. *
  1775. * @private
  1776. * @class
  1777. * @name Highcharts.AnnotationControllableCircle
  1778. *
  1779. * @param {Highcharts.Annotation} annotation an annotation instance
  1780. * @param {Highcharts.AnnotationsShapeOptions} options a shape's options
  1781. * @param {number} index of the circle
  1782. */
  1783. var ControllableCircle = /** @class */ (function () {
  1784. /* *
  1785. *
  1786. * Constructors
  1787. *
  1788. * */
  1789. function ControllableCircle(annotation, options, index) {
  1790. /* *
  1791. *
  1792. * Properties
  1793. *
  1794. * */
  1795. this.addControlPoints = ControllableMixin.addControlPoints;
  1796. this.anchor = ControllableMixin.anchor;
  1797. this.attr = ControllableMixin.attr;
  1798. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1799. this.destroy = ControllableMixin.destroy;
  1800. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1801. this.init = ControllableMixin.init;
  1802. this.linkPoints = ControllableMixin.linkPoints;
  1803. this.point = ControllableMixin.point;
  1804. this.rotate = ControllableMixin.rotate;
  1805. this.scale = ControllableMixin.scale;
  1806. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1807. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1808. this.transform = ControllableMixin.transform;
  1809. this.transformPoint = ControllableMixin.transformPoint;
  1810. this.translatePoint = ControllableMixin.translatePoint;
  1811. this.translateShape = ControllableMixin.translateShape;
  1812. this.update = ControllableMixin.update;
  1813. /**
  1814. * @type 'circle'
  1815. */
  1816. this.type = 'circle';
  1817. this.translate = ControllableMixin.translateShape;
  1818. this.init(annotation, options, index);
  1819. this.collection = 'shapes';
  1820. }
  1821. /* *
  1822. *
  1823. * Functions
  1824. *
  1825. * */
  1826. ControllableCircle.prototype.render = function (parent) {
  1827. var attrs = this.attrsFromOptions(this.options);
  1828. this.graphic = this.annotation.chart.renderer
  1829. .circle(0, -9e9, 0)
  1830. .attr(attrs)
  1831. .add(parent);
  1832. ControllableMixin.render.call(this);
  1833. };
  1834. ControllableCircle.prototype.redraw = function (animation) {
  1835. var position = this.anchor(this.points[0]).absolutePosition;
  1836. if (position) {
  1837. this.graphic[animation ? 'animate' : 'attr']({
  1838. x: position.x,
  1839. y: position.y,
  1840. r: this.options.r
  1841. });
  1842. }
  1843. else {
  1844. this.graphic.attr({
  1845. x: 0,
  1846. y: -9e9
  1847. });
  1848. }
  1849. this.graphic.placed = Boolean(position);
  1850. ControllableMixin.redraw.call(this, animation);
  1851. };
  1852. /**
  1853. * Set the radius.
  1854. *
  1855. * @param {number} r a radius to be set
  1856. */
  1857. ControllableCircle.prototype.setRadius = function (r) {
  1858. this.options.r = r;
  1859. };
  1860. /* *
  1861. *
  1862. * Static Properties
  1863. *
  1864. * */
  1865. /**
  1866. * A map object which allows to map options attributes to element
  1867. * attributes.
  1868. *
  1869. * @name Highcharts.AnnotationControllableCircle.attrsMap
  1870. * @type {Highcharts.Dictionary<string>}
  1871. */
  1872. ControllableCircle.attrsMap = merge(ControllablePath.attrsMap, { r: 'r' });
  1873. return ControllableCircle;
  1874. }());
  1875. return ControllableCircle;
  1876. });
  1877. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableLabel.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Core/FormatUtilities.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Tooltip.js'], _modules['Core/Utilities.js']], function (ControllableMixin, F, MockPoint, SVGRenderer, Tooltip, U) {
  1878. /* *
  1879. *
  1880. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1881. *
  1882. * */
  1883. /* *
  1884. *
  1885. * Imports
  1886. *
  1887. * */
  1888. var format = F.format;
  1889. var symbols = SVGRenderer.prototype.symbols;
  1890. var extend = U.extend,
  1891. isNumber = U.isNumber,
  1892. pick = U.pick;
  1893. /* eslint-disable no-invalid-this, valid-jsdoc */
  1894. /**
  1895. * A controllable label class.
  1896. *
  1897. * @requires modules/annotations
  1898. *
  1899. * @private
  1900. * @class
  1901. * @name Highcharts.AnnotationControllableLabel
  1902. *
  1903. * @param {Highcharts.Annotation} annotation
  1904. * An annotation instance.
  1905. * @param {Highcharts.AnnotationsLabelOptions} options
  1906. * A label's options.
  1907. * @param {number} index
  1908. * Index of the label.
  1909. */
  1910. var ControllableLabel = /** @class */ (function () {
  1911. /* *
  1912. *
  1913. * Constructors
  1914. *
  1915. * */
  1916. function ControllableLabel(annotation, options, index) {
  1917. /* *
  1918. *
  1919. * Properties
  1920. *
  1921. * */
  1922. this.addControlPoints = ControllableMixin.addControlPoints;
  1923. this.attr = ControllableMixin.attr;
  1924. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1925. this.destroy = ControllableMixin.destroy;
  1926. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1927. this.init = ControllableMixin.init;
  1928. this.linkPoints = ControllableMixin.linkPoints;
  1929. this.point = ControllableMixin.point;
  1930. this.rotate = ControllableMixin.rotate;
  1931. this.scale = ControllableMixin.scale;
  1932. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1933. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1934. this.transform = ControllableMixin.transform;
  1935. this.transformPoint = ControllableMixin.transformPoint;
  1936. this.translateShape = ControllableMixin.translateShape;
  1937. this.update = ControllableMixin.update;
  1938. this.init(annotation, options, index);
  1939. this.collection = 'labels';
  1940. }
  1941. /* *
  1942. *
  1943. * Static Functions
  1944. *
  1945. * */
  1946. /**
  1947. * Returns new aligned position based alignment options and box to align to.
  1948. * It is almost a one-to-one copy from SVGElement.prototype.align
  1949. * except it does not use and mutate an element
  1950. *
  1951. * @param {Highcharts.AnnotationAlignObject} alignOptions
  1952. *
  1953. * @param {Highcharts.BBoxObject} box
  1954. *
  1955. * @return {Highcharts.PositionObject}
  1956. * Aligned position.
  1957. */
  1958. ControllableLabel.alignedPosition = function (alignOptions, box) {
  1959. var align = alignOptions.align,
  1960. vAlign = alignOptions.verticalAlign;
  1961. var x = (box.x || 0) + (alignOptions.x || 0),
  1962. y = (box.y || 0) + (alignOptions.y || 0),
  1963. alignFactor,
  1964. vAlignFactor;
  1965. if (align === 'right') {
  1966. alignFactor = 1;
  1967. }
  1968. else if (align === 'center') {
  1969. alignFactor = 2;
  1970. }
  1971. if (alignFactor) {
  1972. x += (box.width - (alignOptions.width || 0)) / alignFactor;
  1973. }
  1974. if (vAlign === 'bottom') {
  1975. vAlignFactor = 1;
  1976. }
  1977. else if (vAlign === 'middle') {
  1978. vAlignFactor = 2;
  1979. }
  1980. if (vAlignFactor) {
  1981. y += (box.height - (alignOptions.height || 0)) / vAlignFactor;
  1982. }
  1983. return {
  1984. x: Math.round(x),
  1985. y: Math.round(y)
  1986. };
  1987. };
  1988. /**
  1989. * Returns new alignment options for a label if the label is outside the
  1990. * plot area. It is almost a one-to-one copy from
  1991. * Series.prototype.justifyDataLabel except it does not mutate the label and
  1992. * it works with absolute instead of relative position.
  1993. */
  1994. ControllableLabel.justifiedOptions = function (chart, label, alignOptions, alignAttr) {
  1995. var align = alignOptions.align,
  1996. verticalAlign = alignOptions.verticalAlign,
  1997. padding = label.box ? 0 : (label.padding || 0),
  1998. bBox = label.getBBox(),
  1999. //
  2000. options = {
  2001. align: align,
  2002. verticalAlign: verticalAlign,
  2003. x: alignOptions.x,
  2004. y: alignOptions.y,
  2005. width: label.width,
  2006. height: label.height
  2007. },
  2008. //
  2009. x = (alignAttr.x || 0) - chart.plotLeft,
  2010. y = (alignAttr.y || 0) - chart.plotTop;
  2011. var off;
  2012. // Off left
  2013. off = x + padding;
  2014. if (off < 0) {
  2015. if (align === 'right') {
  2016. options.align = 'left';
  2017. }
  2018. else {
  2019. options.x = (options.x || 0) - off;
  2020. }
  2021. }
  2022. // Off right
  2023. off = x + bBox.width - padding;
  2024. if (off > chart.plotWidth) {
  2025. if (align === 'left') {
  2026. options.align = 'right';
  2027. }
  2028. else {
  2029. options.x = (options.x || 0) + chart.plotWidth - off;
  2030. }
  2031. }
  2032. // Off top
  2033. off = y + padding;
  2034. if (off < 0) {
  2035. if (verticalAlign === 'bottom') {
  2036. options.verticalAlign = 'top';
  2037. }
  2038. else {
  2039. options.y = (options.y || 0) - off;
  2040. }
  2041. }
  2042. // Off bottom
  2043. off = y + bBox.height - padding;
  2044. if (off > chart.plotHeight) {
  2045. if (verticalAlign === 'top') {
  2046. options.verticalAlign = 'bottom';
  2047. }
  2048. else {
  2049. options.y = (options.y || 0) + chart.plotHeight - off;
  2050. }
  2051. }
  2052. return options;
  2053. };
  2054. /* *
  2055. *
  2056. * Functions
  2057. *
  2058. * */
  2059. /**
  2060. * Translate the point of the label by deltaX and deltaY translations.
  2061. * The point is the label's anchor.
  2062. *
  2063. * @param {number} dx translation for x coordinate
  2064. * @param {number} dy translation for y coordinate
  2065. */
  2066. ControllableLabel.prototype.translatePoint = function (dx, dy) {
  2067. ControllableMixin.translatePoint.call(this, dx, dy, 0);
  2068. };
  2069. /**
  2070. * Translate x and y position relative to the label's anchor.
  2071. *
  2072. * @param {number} dx translation for x coordinate
  2073. * @param {number} dy translation for y coordinate
  2074. */
  2075. ControllableLabel.prototype.translate = function (dx, dy) {
  2076. var chart = this.annotation.chart,
  2077. // Annotation.options
  2078. labelOptions = this.annotation.userOptions,
  2079. // Chart.options.annotations
  2080. annotationIndex = chart.annotations.indexOf(this.annotation),
  2081. chartAnnotations = chart.options.annotations,
  2082. chartOptions = chartAnnotations[annotationIndex];
  2083. if (chart.inverted) {
  2084. var temp = dx;
  2085. dx = dy;
  2086. dy = temp;
  2087. }
  2088. // Local options:
  2089. this.options.x += dx;
  2090. this.options.y += dy;
  2091. // Options stored in chart:
  2092. chartOptions[this.collection][this.index].x = this.options.x;
  2093. chartOptions[this.collection][this.index].y = this.options.y;
  2094. labelOptions[this.collection][this.index].x = this.options.x;
  2095. labelOptions[this.collection][this.index].y = this.options.y;
  2096. };
  2097. ControllableLabel.prototype.render = function (parent) {
  2098. var options = this.options,
  2099. attrs = this.attrsFromOptions(options),
  2100. style = options.style;
  2101. this.graphic = this.annotation.chart.renderer
  2102. .label('', 0, -9999, // #10055
  2103. options.shape, null, null, options.useHTML, null, 'annotation-label')
  2104. .attr(attrs)
  2105. .add(parent);
  2106. if (!this.annotation.chart.styledMode) {
  2107. if (style.color === 'contrast') {
  2108. style.color = this.annotation.chart.renderer.getContrast(ControllableLabel.shapesWithoutBackground.indexOf(options.shape) > -1 ? '#FFFFFF' : options.backgroundColor);
  2109. }
  2110. this.graphic
  2111. .css(options.style)
  2112. .shadow(options.shadow);
  2113. }
  2114. if (options.className) {
  2115. this.graphic.addClass(options.className);
  2116. }
  2117. this.graphic.labelrank = options.labelrank;
  2118. ControllableMixin.render.call(this);
  2119. };
  2120. ControllableLabel.prototype.redraw = function (animation) {
  2121. var options = this.options,
  2122. text = this.text || options.format || options.text,
  2123. label = this.graphic,
  2124. point = this.points[0];
  2125. label.attr({
  2126. text: text ?
  2127. format(text, point.getLabelConfig(), this.annotation.chart) :
  2128. options.formatter.call(point, this)
  2129. });
  2130. var anchor = this.anchor(point);
  2131. var attrs = this.position(anchor);
  2132. if (attrs) {
  2133. label.alignAttr = attrs;
  2134. attrs.anchorX = anchor.absolutePosition.x;
  2135. attrs.anchorY = anchor.absolutePosition.y;
  2136. label[animation ? 'animate' : 'attr'](attrs);
  2137. }
  2138. else {
  2139. label.attr({
  2140. x: 0,
  2141. y: -9999 // #10055
  2142. });
  2143. }
  2144. label.placed = !!attrs;
  2145. ControllableMixin.redraw.call(this, animation);
  2146. };
  2147. /**
  2148. * All basic shapes don't support alignTo() method except label.
  2149. * For a controllable label, we need to subtract translation from
  2150. * options.
  2151. */
  2152. ControllableLabel.prototype.anchor = function (_point) {
  2153. var anchor = ControllableMixin.anchor.apply(this,
  2154. arguments),
  2155. x = this.options.x || 0,
  2156. y = this.options.y || 0;
  2157. anchor.absolutePosition.x -= x;
  2158. anchor.absolutePosition.y -= y;
  2159. anchor.relativePosition.x -= x;
  2160. anchor.relativePosition.y -= y;
  2161. return anchor;
  2162. };
  2163. /**
  2164. * Returns the label position relative to its anchor.
  2165. *
  2166. * @param {Highcharts.AnnotationAnchorObject} anchor
  2167. *
  2168. * @return {Highcharts.PositionObject|null}
  2169. */
  2170. ControllableLabel.prototype.position = function (anchor) {
  2171. var item = this.graphic,
  2172. chart = this.annotation.chart,
  2173. point = this.points[0],
  2174. itemOptions = this.options,
  2175. anchorAbsolutePosition = anchor.absolutePosition,
  2176. anchorRelativePosition = anchor.relativePosition;
  2177. var itemPosition,
  2178. alignTo,
  2179. itemPosRelativeX,
  2180. itemPosRelativeY,
  2181. showItem = point.series.visible &&
  2182. MockPoint.prototype.isInsidePlot.call(point);
  2183. var _a = item.width,
  2184. width = _a === void 0 ? 0 : _a,
  2185. _b = item.height,
  2186. height = _b === void 0 ? 0 : _b;
  2187. if (showItem) {
  2188. if (itemOptions.distance) {
  2189. itemPosition = Tooltip.prototype.getPosition.call({
  2190. chart: chart,
  2191. distance: pick(itemOptions.distance, 16)
  2192. }, width, height, {
  2193. plotX: anchorRelativePosition.x,
  2194. plotY: anchorRelativePosition.y,
  2195. negative: point.negative,
  2196. ttBelow: point.ttBelow,
  2197. h: (anchorRelativePosition.height || anchorRelativePosition.width)
  2198. });
  2199. }
  2200. else if (itemOptions.positioner) {
  2201. itemPosition = itemOptions.positioner.call(this);
  2202. }
  2203. else {
  2204. alignTo = {
  2205. x: anchorAbsolutePosition.x,
  2206. y: anchorAbsolutePosition.y,
  2207. width: 0,
  2208. height: 0
  2209. };
  2210. itemPosition = ControllableLabel.alignedPosition(extend(itemOptions, {
  2211. width: width,
  2212. height: height
  2213. }), alignTo);
  2214. if (this.options.overflow === 'justify') {
  2215. itemPosition = ControllableLabel.alignedPosition(ControllableLabel.justifiedOptions(chart, item, itemOptions, itemPosition), alignTo);
  2216. }
  2217. }
  2218. if (itemOptions.crop) {
  2219. itemPosRelativeX = itemPosition.x - chart.plotLeft;
  2220. itemPosRelativeY = itemPosition.y - chart.plotTop;
  2221. showItem =
  2222. chart.isInsidePlot(itemPosRelativeX, itemPosRelativeY) &&
  2223. chart.isInsidePlot(itemPosRelativeX + width, itemPosRelativeY + height);
  2224. }
  2225. }
  2226. return showItem ? itemPosition : null;
  2227. };
  2228. /* *
  2229. *
  2230. * Static Properties
  2231. *
  2232. * */
  2233. /**
  2234. * A map object which allows to map options attributes to element attributes
  2235. *
  2236. * @type {Highcharts.Dictionary<string>}
  2237. */
  2238. ControllableLabel.attrsMap = {
  2239. backgroundColor: 'fill',
  2240. borderColor: 'stroke',
  2241. borderWidth: 'stroke-width',
  2242. zIndex: 'zIndex',
  2243. borderRadius: 'r',
  2244. padding: 'padding'
  2245. };
  2246. /**
  2247. * Shapes which do not have background - the object is used for proper
  2248. * setting of the contrast color.
  2249. *
  2250. * @type {Array<string>}
  2251. */
  2252. ControllableLabel.shapesWithoutBackground = ['connector'];
  2253. return ControllableLabel;
  2254. }());
  2255. /**
  2256. * General symbol definition for labels with connector
  2257. * @private
  2258. */
  2259. symbols.connector = function (x, y, w, h, options) {
  2260. var anchorX = options && options.anchorX,
  2261. anchorY = options && options.anchorY;
  2262. var path,
  2263. yOffset,
  2264. lateral = w / 2;
  2265. if (isNumber(anchorX) && isNumber(anchorY)) {
  2266. path = [['M', anchorX, anchorY]];
  2267. // Prefer 45 deg connectors
  2268. yOffset = y - anchorY;
  2269. if (yOffset < 0) {
  2270. yOffset = -h - yOffset;
  2271. }
  2272. if (yOffset < w) {
  2273. lateral = anchorX < x + (w / 2) ? yOffset : w - yOffset;
  2274. }
  2275. // Anchor below label
  2276. if (anchorY > y + h) {
  2277. path.push(['L', x + lateral, y + h]);
  2278. // Anchor above label
  2279. }
  2280. else if (anchorY < y) {
  2281. path.push(['L', x + lateral, y]);
  2282. // Anchor left of label
  2283. }
  2284. else if (anchorX < x) {
  2285. path.push(['L', x, y + h / 2]);
  2286. // Anchor right of label
  2287. }
  2288. else if (anchorX > x + w) {
  2289. path.push(['L', x + w, y + h / 2]);
  2290. }
  2291. }
  2292. return path || [];
  2293. };
  2294. return ControllableLabel;
  2295. });
  2296. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableImage.js', [_modules['Extensions/Annotations/Controllables/ControllableLabel.js'], _modules['Extensions/Annotations/Mixins/ControllableMixin.js']], function (ControllableLabel, ControllableMixin) {
  2297. /* *
  2298. *
  2299. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2300. *
  2301. * */
  2302. /* eslint-disable no-invalid-this, valid-jsdoc */
  2303. /**
  2304. * A controllable image class.
  2305. *
  2306. * @requires modules/annotations
  2307. *
  2308. * @private
  2309. * @class
  2310. * @name Highcharts.AnnotationControllableImage
  2311. *
  2312. * @param {Highcharts.Annotation} annotation
  2313. * An annotation instance.
  2314. *
  2315. * @param {Highcharts.AnnotationsShapeOptions} options
  2316. * A controllable's options.
  2317. *
  2318. * @param {number} index
  2319. * Index of the image.
  2320. */
  2321. var ControllableImage = /** @class */ (function () {
  2322. /* *
  2323. *
  2324. * Constructors
  2325. *
  2326. * */
  2327. function ControllableImage(annotation, options, index) {
  2328. /* *
  2329. *
  2330. * Properties
  2331. *
  2332. * */
  2333. this.addControlPoints = ControllableMixin.addControlPoints;
  2334. this.anchor = ControllableMixin.anchor;
  2335. this.attr = ControllableMixin.attr;
  2336. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  2337. this.destroy = ControllableMixin.destroy;
  2338. this.getPointsOptions = ControllableMixin.getPointsOptions;
  2339. this.init = ControllableMixin.init;
  2340. this.linkPoints = ControllableMixin.linkPoints;
  2341. this.point = ControllableMixin.point;
  2342. this.rotate = ControllableMixin.rotate;
  2343. this.scale = ControllableMixin.scale;
  2344. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  2345. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  2346. this.transform = ControllableMixin.transform;
  2347. this.transformPoint = ControllableMixin.transformPoint;
  2348. this.translatePoint = ControllableMixin.translatePoint;
  2349. this.translateShape = ControllableMixin.translateShape;
  2350. this.update = ControllableMixin.update;
  2351. /**
  2352. * @type 'image'
  2353. */
  2354. this.type = 'image';
  2355. this.translate = ControllableMixin.translateShape;
  2356. this.init(annotation, options, index);
  2357. this.collection = 'shapes';
  2358. }
  2359. ControllableImage.prototype.render = function (parent) {
  2360. var attrs = this.attrsFromOptions(this.options),
  2361. options = this.options;
  2362. this.graphic = this.annotation.chart.renderer
  2363. .image(options.src, 0, -9e9, options.width, options.height)
  2364. .attr(attrs)
  2365. .add(parent);
  2366. this.graphic.width = options.width;
  2367. this.graphic.height = options.height;
  2368. ControllableMixin.render.call(this);
  2369. };
  2370. ControllableImage.prototype.redraw = function (animation) {
  2371. var anchor = this.anchor(this.points[0]),
  2372. position = ControllableLabel.prototype.position.call(this,
  2373. anchor);
  2374. if (position) {
  2375. this.graphic[animation ? 'animate' : 'attr']({
  2376. x: position.x,
  2377. y: position.y
  2378. });
  2379. }
  2380. else {
  2381. this.graphic.attr({
  2382. x: 0,
  2383. y: -9e9
  2384. });
  2385. }
  2386. this.graphic.placed = Boolean(position);
  2387. ControllableMixin.redraw.call(this, animation);
  2388. };
  2389. /* *
  2390. *
  2391. * Static Properties
  2392. *
  2393. * */
  2394. /**
  2395. * A map object which allows to map options attributes to element attributes
  2396. *
  2397. * @name Highcharts.AnnotationControllableImage.attrsMap
  2398. * @type {Highcharts.Dictionary<string>}
  2399. */
  2400. ControllableImage.attrsMap = {
  2401. width: 'width',
  2402. height: 'height',
  2403. zIndex: 'zIndex'
  2404. };
  2405. return ControllableImage;
  2406. }());
  2407. return ControllableImage;
  2408. });
  2409. _registerModule(_modules, 'Extensions/Annotations/Annotations.js', [_modules['Core/Animation/AnimationUtilities.js'], _modules['Core/Chart/Chart.js'], _modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllableRect.js'], _modules['Extensions/Annotations/Controllables/ControllableCircle.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Extensions/Annotations/Controllables/ControllableImage.js'], _modules['Extensions/Annotations/Controllables/ControllableLabel.js'], _modules['Extensions/Annotations/ControlPoint.js'], _modules['Extensions/Annotations/Mixins/EventEmitterMixin.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Pointer.js'], _modules['Core/Utilities.js'], _modules['Core/Color/Palette.js']], function (A, Chart, ControllableMixin, ControllableRect, ControllableCircle, ControllablePath, ControllableImage, ControllableLabel, ControlPoint, EventEmitterMixin, H, MockPoint, Pointer, U, palette) {
  2410. /* *
  2411. *
  2412. * (c) 2009-2021 Highsoft, Black Label
  2413. *
  2414. * License: www.highcharts.com/license
  2415. *
  2416. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2417. *
  2418. * */
  2419. var getDeferredAnimation = A.getDeferredAnimation;
  2420. var chartProto = Chart.prototype;
  2421. var addEvent = U.addEvent,
  2422. defined = U.defined,
  2423. destroyObjectProperties = U.destroyObjectProperties,
  2424. erase = U.erase,
  2425. extend = U.extend,
  2426. find = U.find,
  2427. fireEvent = U.fireEvent,
  2428. merge = U.merge,
  2429. pick = U.pick,
  2430. splat = U.splat,
  2431. wrap = U.wrap;
  2432. /* *********************************************************************
  2433. *
  2434. * ANNOTATION
  2435. *
  2436. ******************************************************************** */
  2437. /**
  2438. * Possible directions for draggable annotations. An empty string (`''`)
  2439. * makes the annotation undraggable.
  2440. *
  2441. * @typedef {''|'x'|'xy'|'y'} Highcharts.AnnotationDraggableValue
  2442. */
  2443. /**
  2444. * @private
  2445. * @typedef {
  2446. * Highcharts.AnnotationControllableCircle|
  2447. * Highcharts.AnnotationControllableImage|
  2448. * Highcharts.AnnotationControllablePath|
  2449. * Highcharts.AnnotationControllableRect
  2450. * }
  2451. * Highcharts.AnnotationShapeType
  2452. * @requires modules/annotations
  2453. */
  2454. /**
  2455. * @private
  2456. * @typedef {
  2457. * Highcharts.AnnotationControllableLabel
  2458. * }
  2459. * Highcharts.AnnotationLabelType
  2460. * @requires modules/annotations
  2461. */
  2462. /**
  2463. * A point-like object, a mock point or a point used in series.
  2464. * @private
  2465. * @typedef {Highcharts.AnnotationMockPoint|Highcharts.Point} Highcharts.AnnotationPointType
  2466. * @requires modules/annotations
  2467. */
  2468. /* eslint-disable no-invalid-this, valid-jsdoc */
  2469. /**
  2470. * An annotation class which serves as a container for items like labels or
  2471. * shapes. Created items are positioned on the chart either by linking them to
  2472. * existing points or created mock points
  2473. *
  2474. * @class
  2475. * @name Highcharts.Annotation
  2476. *
  2477. * @param {Highcharts.Chart} chart a chart instance
  2478. * @param {Highcharts.AnnotationsOptions} userOptions the options object
  2479. */
  2480. var Annotation = /** @class */ (function () {
  2481. /* *
  2482. *
  2483. * Constructors
  2484. *
  2485. * */
  2486. function Annotation(chart, userOptions) {
  2487. /* *
  2488. *
  2489. * Properties
  2490. *
  2491. * */
  2492. this.annotation = void 0;
  2493. this.coll = 'annotations';
  2494. this.collection = void 0;
  2495. this.animationConfig = void 0;
  2496. this.graphic = void 0;
  2497. this.group = void 0;
  2498. this.labelCollector = void 0;
  2499. this.labelsGroup = void 0;
  2500. this.shapesGroup = void 0;
  2501. var labelsAndShapes;
  2502. /**
  2503. * The chart that the annotation belongs to.
  2504. *
  2505. * @type {Highcharts.Chart}
  2506. */
  2507. this.chart = chart;
  2508. /**
  2509. * The array of points which defines the annotation.
  2510. *
  2511. * @type {Array<Highcharts.Point>}
  2512. */
  2513. this.points = [];
  2514. /**
  2515. * The array of control points.
  2516. *
  2517. * @private
  2518. * @name Highcharts.Annotation#controlPoints
  2519. * @type {Array<Annotation.ControlPoint>}
  2520. */
  2521. this.controlPoints = [];
  2522. this.coll = 'annotations';
  2523. /**
  2524. * The array of labels which belong to the annotation.
  2525. *
  2526. * @private
  2527. * @name Highcharts.Annotation#labels
  2528. * @type {Array<Highcharts.AnnotationLabelType>}
  2529. */
  2530. this.labels = [];
  2531. /**
  2532. * The array of shapes which belong to the annotation.
  2533. *
  2534. * @private
  2535. * @name Highcharts.Annotation#shapes
  2536. * @type {Array<Highcharts.AnnotationShapeType>}
  2537. */
  2538. this.shapes = [];
  2539. /**
  2540. * The options for the annotations.
  2541. *
  2542. * @name Highcharts.Annotation#options
  2543. * @type {Highcharts.AnnotationsOptions}
  2544. */
  2545. this.options = merge(this.defaultOptions, userOptions);
  2546. /**
  2547. * The user options for the annotations.
  2548. *
  2549. * @name Highcharts.Annotation#userOptions
  2550. * @type {Highcharts.AnnotationsOptions}
  2551. */
  2552. this.userOptions = userOptions;
  2553. // Handle labels and shapes - those are arrays
  2554. // Merging does not work with arrays (stores reference)
  2555. labelsAndShapes = this.getLabelsAndShapesOptions(this.options, userOptions);
  2556. this.options.labels = labelsAndShapes.labels;
  2557. this.options.shapes = labelsAndShapes.shapes;
  2558. /**
  2559. * The callback that reports to the overlapping-labels module which
  2560. * labels it should account for.
  2561. * @private
  2562. * @name Highcharts.Annotation#labelCollector
  2563. * @type {Function}
  2564. */
  2565. /**
  2566. * The group svg element.
  2567. *
  2568. * @name Highcharts.Annotation#group
  2569. * @type {Highcharts.SVGElement}
  2570. */
  2571. /**
  2572. * The group svg element of the annotation's shapes.
  2573. *
  2574. * @name Highcharts.Annotation#shapesGroup
  2575. * @type {Highcharts.SVGElement}
  2576. */
  2577. /**
  2578. * The group svg element of the annotation's labels.
  2579. *
  2580. * @name Highcharts.Annotation#labelsGroup
  2581. * @type {Highcharts.SVGElement}
  2582. */
  2583. this.init(chart, this.options);
  2584. }
  2585. /**
  2586. * Initialize the annotation.
  2587. * @private
  2588. */
  2589. Annotation.prototype.init = function () {
  2590. var chart = this.chart,
  2591. animOptions = this.options.animation;
  2592. this.linkPoints();
  2593. this.addControlPoints();
  2594. this.addShapes();
  2595. this.addLabels();
  2596. this.setLabelCollector();
  2597. this.animationConfig = getDeferredAnimation(chart, animOptions);
  2598. };
  2599. Annotation.prototype.getLabelsAndShapesOptions = function (baseOptions, newOptions) {
  2600. var mergedOptions = {};
  2601. ['labels', 'shapes'].forEach(function (name) {
  2602. if (baseOptions[name]) {
  2603. mergedOptions[name] = splat(newOptions[name]).map(function (basicOptions, i) {
  2604. return merge(baseOptions[name][i], basicOptions);
  2605. });
  2606. }
  2607. });
  2608. return mergedOptions;
  2609. };
  2610. Annotation.prototype.addShapes = function () {
  2611. (this.options.shapes || []).forEach(function (shapeOptions, i) {
  2612. var shape = this.initShape(shapeOptions,
  2613. i);
  2614. merge(true, this.options.shapes[i], shape.options);
  2615. }, this);
  2616. };
  2617. Annotation.prototype.addLabels = function () {
  2618. (this.options.labels || []).forEach(function (labelsOptions, i) {
  2619. var labels = this.initLabel(labelsOptions,
  2620. i);
  2621. merge(true, this.options.labels[i], labels.options);
  2622. }, this);
  2623. };
  2624. Annotation.prototype.addClipPaths = function () {
  2625. this.setClipAxes();
  2626. if (this.clipXAxis && this.clipYAxis) {
  2627. this.clipRect = this.chart.renderer.clipRect(this.getClipBox());
  2628. }
  2629. };
  2630. Annotation.prototype.setClipAxes = function () {
  2631. var xAxes = this.chart.xAxis,
  2632. yAxes = this.chart.yAxis,
  2633. linkedAxes = (this.options.labels || [])
  2634. .concat(this.options.shapes || [])
  2635. .reduce(function (axes,
  2636. labelOrShape) {
  2637. return [
  2638. xAxes[labelOrShape &&
  2639. labelOrShape.point &&
  2640. labelOrShape.point.xAxis] || axes[0],
  2641. yAxes[labelOrShape &&
  2642. labelOrShape.point &&
  2643. labelOrShape.point.yAxis] || axes[1]
  2644. ];
  2645. }, []);
  2646. this.clipXAxis = linkedAxes[0];
  2647. this.clipYAxis = linkedAxes[1];
  2648. };
  2649. Annotation.prototype.getClipBox = function () {
  2650. if (this.clipXAxis && this.clipYAxis) {
  2651. return {
  2652. x: this.clipXAxis.left,
  2653. y: this.clipYAxis.top,
  2654. width: this.clipXAxis.width,
  2655. height: this.clipYAxis.height
  2656. };
  2657. }
  2658. };
  2659. Annotation.prototype.setLabelCollector = function () {
  2660. var annotation = this;
  2661. annotation.labelCollector = function () {
  2662. return annotation.labels.reduce(function (labels, label) {
  2663. if (!label.options.allowOverlap) {
  2664. labels.push(label.graphic);
  2665. }
  2666. return labels;
  2667. }, []);
  2668. };
  2669. annotation.chart.labelCollectors.push(annotation.labelCollector);
  2670. };
  2671. /**
  2672. * Set an annotation options.
  2673. * @private
  2674. * @param {Highcharts.AnnotationsOptions} - user options for an annotation
  2675. */
  2676. Annotation.prototype.setOptions = function (userOptions) {
  2677. this.options = merge(this.defaultOptions, userOptions);
  2678. };
  2679. Annotation.prototype.redraw = function (animation) {
  2680. this.linkPoints();
  2681. if (!this.graphic) {
  2682. this.render();
  2683. }
  2684. if (this.clipRect) {
  2685. this.clipRect.animate(this.getClipBox());
  2686. }
  2687. this.redrawItems(this.shapes, animation);
  2688. this.redrawItems(this.labels, animation);
  2689. ControllableMixin.redraw.call(this, animation);
  2690. };
  2691. /**
  2692. * @private
  2693. * @param {Array<Highcharts.AnnotationControllable>} items
  2694. * @param {boolean} [animation]
  2695. */
  2696. Annotation.prototype.redrawItems = function (items, animation) {
  2697. var i = items.length;
  2698. // needs a backward loop
  2699. // labels/shapes array might be modified
  2700. // due to destruction of the item
  2701. while (i--) {
  2702. this.redrawItem(items[i], animation);
  2703. }
  2704. };
  2705. /**
  2706. * @private
  2707. * @param {Array<Highcharts.AnnotationControllable>} items
  2708. */
  2709. Annotation.prototype.renderItems = function (items) {
  2710. var i = items.length;
  2711. while (i--) {
  2712. this.renderItem(items[i]);
  2713. }
  2714. };
  2715. Annotation.prototype.render = function () {
  2716. var renderer = this.chart.renderer;
  2717. this.graphic = renderer
  2718. .g('annotation')
  2719. .attr({
  2720. opacity: 0,
  2721. zIndex: this.options.zIndex,
  2722. visibility: this.options.visible ?
  2723. 'visible' :
  2724. 'hidden'
  2725. })
  2726. .add();
  2727. this.shapesGroup = renderer
  2728. .g('annotation-shapes')
  2729. .add(this.graphic)
  2730. .clip(this.chart.plotBoxClip);
  2731. this.labelsGroup = renderer
  2732. .g('annotation-labels')
  2733. .attr({
  2734. // hideOverlappingLabels requires translation
  2735. translateX: 0,
  2736. translateY: 0
  2737. })
  2738. .add(this.graphic);
  2739. this.addClipPaths();
  2740. if (this.clipRect) {
  2741. this.graphic.clip(this.clipRect);
  2742. }
  2743. // Render shapes and labels before adding events (#13070).
  2744. this.renderItems(this.shapes);
  2745. this.renderItems(this.labels);
  2746. this.addEvents();
  2747. ControllableMixin.render.call(this);
  2748. };
  2749. /**
  2750. * Set the annotation's visibility.
  2751. * @private
  2752. * @param {boolean} [visible]
  2753. * Whether to show or hide an annotation. If the param is omitted, the
  2754. * annotation's visibility is toggled.
  2755. */
  2756. Annotation.prototype.setVisibility = function (visible) {
  2757. var options = this.options,
  2758. visibility = pick(visible, !options.visible);
  2759. this.graphic.attr('visibility', visibility ? 'visible' : 'hidden');
  2760. if (!visibility) {
  2761. this.setControlPointsVisibility(false);
  2762. }
  2763. options.visible = visibility;
  2764. };
  2765. Annotation.prototype.setControlPointsVisibility = function (visible) {
  2766. var setItemControlPointsVisibility = function (item) {
  2767. item.setControlPointsVisibility(visible);
  2768. };
  2769. ControllableMixin.setControlPointsVisibility.call(this, visible);
  2770. this.shapes.forEach(setItemControlPointsVisibility);
  2771. this.labels.forEach(setItemControlPointsVisibility);
  2772. };
  2773. /**
  2774. * Destroy the annotation. This function does not touch the chart
  2775. * that the annotation belongs to (all annotations are kept in
  2776. * the chart.annotations array) - it is recommended to use
  2777. * {@link Highcharts.Chart#removeAnnotation} instead.
  2778. * @private
  2779. */
  2780. Annotation.prototype.destroy = function () {
  2781. var chart = this.chart,
  2782. destroyItem = function (item) {
  2783. item.destroy();
  2784. };
  2785. this.labels.forEach(destroyItem);
  2786. this.shapes.forEach(destroyItem);
  2787. this.clipXAxis = null;
  2788. this.clipYAxis = null;
  2789. erase(chart.labelCollectors, this.labelCollector);
  2790. EventEmitterMixin.destroy.call(this);
  2791. ControllableMixin.destroy.call(this);
  2792. destroyObjectProperties(this, chart);
  2793. };
  2794. /**
  2795. * See {@link Highcharts.Chart#removeAnnotation}.
  2796. * @private
  2797. */
  2798. Annotation.prototype.remove = function () {
  2799. // Let chart.update() remove annoations on demand
  2800. return this.chart.removeAnnotation(this);
  2801. };
  2802. /**
  2803. * Updates an annotation.
  2804. *
  2805. * @function Highcharts.Annotation#update
  2806. *
  2807. * @param {Partial<Highcharts.AnnotationsOptions>} userOptions
  2808. * New user options for the annotation.
  2809. *
  2810. * @return {void}
  2811. */
  2812. Annotation.prototype.update = function (userOptions, redraw) {
  2813. var chart = this.chart,
  2814. labelsAndShapes = this.getLabelsAndShapesOptions(this.userOptions,
  2815. userOptions),
  2816. userOptionsIndex = chart.annotations.indexOf(this),
  2817. options = merge(true,
  2818. this.userOptions,
  2819. userOptions);
  2820. options.labels = labelsAndShapes.labels;
  2821. options.shapes = labelsAndShapes.shapes;
  2822. this.destroy();
  2823. this.constructor(chart, options);
  2824. // Update options in chart options, used in exporting (#9767):
  2825. chart.options.annotations[userOptionsIndex] = options;
  2826. this.isUpdating = true;
  2827. if (pick(redraw, true)) {
  2828. chart.redraw();
  2829. }
  2830. fireEvent(this, 'afterUpdate');
  2831. this.isUpdating = false;
  2832. };
  2833. /* *************************************************************
  2834. * ITEM SECTION
  2835. * Contains methods for handling a single item in an annotation
  2836. **************************************************************** */
  2837. /**
  2838. * Initialisation of a single shape
  2839. * @private
  2840. * @param {Object} shapeOptions - a confg object for a single shape
  2841. */
  2842. Annotation.prototype.initShape = function (shapeOptions, index) {
  2843. var options = merge(this.options.shapeOptions, {
  2844. controlPointOptions: this.options.controlPointOptions
  2845. },
  2846. shapeOptions),
  2847. shape = new Annotation.shapesMap[options.type](this,
  2848. options,
  2849. index);
  2850. shape.itemType = 'shape';
  2851. this.shapes.push(shape);
  2852. return shape;
  2853. };
  2854. /**
  2855. * Initialisation of a single label
  2856. * @private
  2857. */
  2858. Annotation.prototype.initLabel = function (labelOptions, index) {
  2859. var options = merge(this.options.labelOptions, {
  2860. controlPointOptions: this.options.controlPointOptions
  2861. },
  2862. labelOptions),
  2863. label = new ControllableLabel(this,
  2864. options,
  2865. index);
  2866. label.itemType = 'label';
  2867. this.labels.push(label);
  2868. return label;
  2869. };
  2870. /**
  2871. * Redraw a single item.
  2872. * @private
  2873. * @param {Annotation.Label|Annotation.Shape} item
  2874. * @param {boolean} [animation]
  2875. */
  2876. Annotation.prototype.redrawItem = function (item, animation) {
  2877. item.linkPoints();
  2878. if (!item.shouldBeDrawn()) {
  2879. this.destroyItem(item);
  2880. }
  2881. else {
  2882. if (!item.graphic) {
  2883. this.renderItem(item);
  2884. }
  2885. item.redraw(pick(animation, true) && item.graphic.placed);
  2886. if (item.points.length) {
  2887. this.adjustVisibility(item);
  2888. }
  2889. }
  2890. };
  2891. /**
  2892. * Hide or show annotaiton attached to points.
  2893. * @private
  2894. * @param {Annotation.Label|Annotation.Shape} item
  2895. */
  2896. Annotation.prototype.adjustVisibility = function (item) {
  2897. var hasVisiblePoints = false,
  2898. label = item.graphic;
  2899. item.points.forEach(function (point) {
  2900. if (point.series.visible !== false &&
  2901. point.visible !== false) {
  2902. hasVisiblePoints = true;
  2903. }
  2904. });
  2905. if (!hasVisiblePoints) {
  2906. label.hide();
  2907. }
  2908. else if (label.visibility === 'hidden') {
  2909. label.show();
  2910. }
  2911. };
  2912. /**
  2913. * Destroy a single item.
  2914. * @private
  2915. * @param {Annotation.Label|Annotation.Shape} item
  2916. */
  2917. Annotation.prototype.destroyItem = function (item) {
  2918. // erase from shapes or labels array
  2919. erase(this[item.itemType + 's'], item);
  2920. item.destroy();
  2921. };
  2922. /**
  2923. * @private
  2924. */
  2925. Annotation.prototype.renderItem = function (item) {
  2926. item.render(item.itemType === 'label' ?
  2927. this.labelsGroup :
  2928. this.shapesGroup);
  2929. };
  2930. /**
  2931. * @private
  2932. */
  2933. Annotation.ControlPoint = ControlPoint;
  2934. /**
  2935. * @private
  2936. */
  2937. Annotation.MockPoint = MockPoint;
  2938. /**
  2939. * An object uses for mapping between a shape type and a constructor.
  2940. * To add a new shape type extend this object with type name as a key
  2941. * and a constructor as its value.
  2942. */
  2943. Annotation.shapesMap = {
  2944. 'rect': ControllableRect,
  2945. 'circle': ControllableCircle,
  2946. 'path': ControllablePath,
  2947. 'image': ControllableImage
  2948. };
  2949. /**
  2950. * @private
  2951. */
  2952. Annotation.types = {};
  2953. return Annotation;
  2954. }());
  2955. merge(true, Annotation.prototype, ControllableMixin, EventEmitterMixin,
  2956. // restore original Annotation implementation after mixin overwrite
  2957. merge(Annotation.prototype,
  2958. /** @lends Highcharts.Annotation# */
  2959. {
  2960. /**
  2961. * List of events for `annotation.options.events` that should not be
  2962. * added to `annotation.graphic` but to the `annotation`.
  2963. *
  2964. * @private
  2965. * @type {Array<string>}
  2966. */
  2967. nonDOMEvents: ['add', 'afterUpdate', 'drag', 'remove'],
  2968. /**
  2969. * A basic type of an annotation. It allows to add custom labels
  2970. * or shapes. The items can be tied to points, axis coordinates
  2971. * or chart pixel coordinates.
  2972. *
  2973. * @sample highcharts/annotations/basic/
  2974. * Basic annotations
  2975. * @sample highcharts/demo/annotations/
  2976. * Advanced annotations
  2977. * @sample highcharts/css/annotations
  2978. * Styled mode
  2979. * @sample highcharts/annotations-advanced/controllable
  2980. * Controllable items
  2981. * @sample {highstock} stock/annotations/fibonacci-retracements
  2982. * Custom annotation, Fibonacci retracement
  2983. *
  2984. * @type {Array<*>}
  2985. * @since 6.0.0
  2986. * @requires modules/annotations
  2987. * @optionparent annotations
  2988. *
  2989. * @private
  2990. */
  2991. defaultOptions: {
  2992. /**
  2993. * Sets an ID for an annotation. Can be user later when
  2994. * removing an annotation in [Chart#removeAnnotation(id)](
  2995. * /class-reference/Highcharts.Chart#removeAnnotation) method.
  2996. *
  2997. * @type {number|string}
  2998. * @apioption annotations.id
  2999. */
  3000. /**
  3001. * Whether the annotation is visible.
  3002. *
  3003. * @sample highcharts/annotations/visible/
  3004. * Set annotation visibility
  3005. */
  3006. visible: true,
  3007. /**
  3008. * Enable or disable the initial animation when a series is
  3009. * displayed for the `annotation`. The animation can also be set
  3010. * as a configuration object. Please note that this option only
  3011. * applies to the initial animation.
  3012. * For other animations, see [chart.animation](#chart.animation)
  3013. * and the animation parameter under the API methods.
  3014. * The following properties are supported:
  3015. *
  3016. * - `defer`: The animation delay time in milliseconds.
  3017. *
  3018. * @sample {highcharts} highcharts/annotations/defer/
  3019. * Animation defer settings
  3020. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  3021. * @since 8.2.0
  3022. * @apioption annotations.animation
  3023. */
  3024. animation: {},
  3025. /**
  3026. * The animation delay time in milliseconds.
  3027. * Set to `0` renders annotation immediately.
  3028. * As `undefined` inherits defer time from the [series.animation.defer](#plotOptions.series.animation.defer).
  3029. *
  3030. * @type {number}
  3031. * @since 8.2.0
  3032. * @apioption annotations.animation.defer
  3033. */
  3034. /**
  3035. * Allow an annotation to be draggable by a user. Possible
  3036. * values are `'x'`, `'xy'`, `'y'` and `''` (disabled).
  3037. *
  3038. * @sample highcharts/annotations/draggable/
  3039. * Annotations draggable: 'xy'
  3040. *
  3041. * @type {Highcharts.AnnotationDraggableValue}
  3042. */
  3043. draggable: 'xy',
  3044. /**
  3045. * Options for annotation's labels. Each label inherits options
  3046. * from the labelOptions object. An option from the labelOptions
  3047. * can be overwritten by config for a specific label.
  3048. *
  3049. * @requires modules/annotations
  3050. */
  3051. labelOptions: {
  3052. /**
  3053. * The alignment of the annotation's label. If right,
  3054. * the right side of the label should be touching the point.
  3055. *
  3056. * @sample highcharts/annotations/label-position/
  3057. * Set labels position
  3058. *
  3059. * @type {Highcharts.AlignValue}
  3060. */
  3061. align: 'center',
  3062. /**
  3063. * Whether to allow the annotation's labels to overlap.
  3064. * To make the labels less sensitive for overlapping,
  3065. * the can be set to 0.
  3066. *
  3067. * @sample highcharts/annotations/tooltip-like/
  3068. * Hide overlapping labels
  3069. */
  3070. allowOverlap: false,
  3071. /**
  3072. * The background color or gradient for the annotation's
  3073. * label.
  3074. *
  3075. * @sample highcharts/annotations/label-presentation/
  3076. * Set labels graphic options
  3077. *
  3078. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3079. */
  3080. backgroundColor: 'rgba(0, 0, 0, 0.75)',
  3081. /**
  3082. * The border color for the annotation's label.
  3083. *
  3084. * @sample highcharts/annotations/label-presentation/
  3085. * Set labels graphic options
  3086. *
  3087. * @type {Highcharts.ColorString}
  3088. */
  3089. borderColor: palette.neutralColor100,
  3090. /**
  3091. * The border radius in pixels for the annotaiton's label.
  3092. *
  3093. * @sample highcharts/annotations/label-presentation/
  3094. * Set labels graphic options
  3095. */
  3096. borderRadius: 3,
  3097. /**
  3098. * The border width in pixels for the annotation's label
  3099. *
  3100. * @sample highcharts/annotations/label-presentation/
  3101. * Set labels graphic options
  3102. */
  3103. borderWidth: 1,
  3104. /**
  3105. * A class name for styling by CSS.
  3106. *
  3107. * @sample highcharts/css/annotations
  3108. * Styled mode annotations
  3109. *
  3110. * @since 6.0.5
  3111. */
  3112. className: 'highcharts-no-tooltip',
  3113. /**
  3114. * Whether to hide the annotation's label
  3115. * that is outside the plot area.
  3116. *
  3117. * @sample highcharts/annotations/label-crop-overflow/
  3118. * Crop or justify labels
  3119. */
  3120. crop: false,
  3121. /**
  3122. * The label's pixel distance from the point.
  3123. *
  3124. * @sample highcharts/annotations/label-position/
  3125. * Set labels position
  3126. *
  3127. * @type {number}
  3128. * @apioption annotations.labelOptions.distance
  3129. */
  3130. /**
  3131. * A
  3132. * [format](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  3133. * string for the data label.
  3134. *
  3135. * @see [plotOptions.series.dataLabels.format](plotOptions.series.dataLabels.format.html)
  3136. *
  3137. * @sample highcharts/annotations/label-text/
  3138. * Set labels text
  3139. *
  3140. * @type {string}
  3141. * @apioption annotations.labelOptions.format
  3142. */
  3143. /**
  3144. * Alias for the format option.
  3145. *
  3146. * @see [format](annotations.labelOptions.format.html)
  3147. *
  3148. * @sample highcharts/annotations/label-text/
  3149. * Set labels text
  3150. *
  3151. * @type {string}
  3152. * @apioption annotations.labelOptions.text
  3153. */
  3154. /**
  3155. * Callback JavaScript function to format the annotation's
  3156. * label. Note that if a `format` or `text` are defined,
  3157. * the format or text take precedence and the formatter is
  3158. * ignored. `This` refers to a point object.
  3159. *
  3160. * @sample highcharts/annotations/label-text/
  3161. * Set labels text
  3162. *
  3163. * @type {Highcharts.FormatterCallbackFunction<Highcharts.Point>}
  3164. * @default function () { return defined(this.y) ? this.y : 'Annotation label'; }
  3165. */
  3166. formatter: function () {
  3167. return defined(this.y) ? this.y : 'Annotation label';
  3168. },
  3169. /**
  3170. * Whether the annotation is visible in the exported data
  3171. * table.
  3172. *
  3173. * @sample highcharts/annotations/include-in-data-export/
  3174. * Do not include in the data export
  3175. *
  3176. * @since 8.2.0
  3177. * @requires modules/export-data
  3178. */
  3179. includeInDataExport: true,
  3180. /**
  3181. * How to handle the annotation's label that flow outside
  3182. * the plot area. The justify option aligns the label inside
  3183. * the plot area.
  3184. *
  3185. * @sample highcharts/annotations/label-crop-overflow/
  3186. * Crop or justify labels
  3187. *
  3188. * @validvalue ["allow", "justify"]
  3189. */
  3190. overflow: 'justify',
  3191. /**
  3192. * When either the borderWidth or the backgroundColor is
  3193. * set, this is the padding within the box.
  3194. *
  3195. * @sample highcharts/annotations/label-presentation/
  3196. * Set labels graphic options
  3197. */
  3198. padding: 5,
  3199. /**
  3200. * The shadow of the box. The shadow can be an object
  3201. * configuration containing `color`, `offsetX`, `offsetY`,
  3202. * `opacity` and `width`.
  3203. *
  3204. * @sample highcharts/annotations/label-presentation/
  3205. * Set labels graphic options
  3206. *
  3207. * @type {boolean|Highcharts.ShadowOptionsObject}
  3208. */
  3209. shadow: false,
  3210. /**
  3211. * The name of a symbol to use for the border around the
  3212. * label. Symbols are predefined functions on the Renderer
  3213. * object.
  3214. *
  3215. * @sample highcharts/annotations/shapes/
  3216. * Available shapes for labels
  3217. */
  3218. shape: 'callout',
  3219. /**
  3220. * Styles for the annotation's label.
  3221. *
  3222. * @see [plotOptions.series.dataLabels.style](plotOptions.series.dataLabels.style.html)
  3223. *
  3224. * @sample highcharts/annotations/label-presentation/
  3225. * Set labels graphic options
  3226. *
  3227. * @type {Highcharts.CSSObject}
  3228. */
  3229. style: {
  3230. /** @ignore */
  3231. fontSize: '11px',
  3232. /** @ignore */
  3233. fontWeight: 'normal',
  3234. /** @ignore */
  3235. color: 'contrast'
  3236. },
  3237. /**
  3238. * Whether to [use HTML](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting#html)
  3239. * to render the annotation's label.
  3240. */
  3241. useHTML: false,
  3242. /**
  3243. * The vertical alignment of the annotation's label.
  3244. *
  3245. * @sample highcharts/annotations/label-position/
  3246. * Set labels position
  3247. *
  3248. * @type {Highcharts.VerticalAlignValue}
  3249. */
  3250. verticalAlign: 'bottom',
  3251. /**
  3252. * The x position offset of the label relative to the point.
  3253. * Note that if a `distance` is defined, the distance takes
  3254. * precedence over `x` and `y` options.
  3255. *
  3256. * @sample highcharts/annotations/label-position/
  3257. * Set labels position
  3258. */
  3259. x: 0,
  3260. /**
  3261. * The y position offset of the label relative to the point.
  3262. * Note that if a `distance` is defined, the distance takes
  3263. * precedence over `x` and `y` options.
  3264. *
  3265. * @sample highcharts/annotations/label-position/
  3266. * Set labels position
  3267. */
  3268. y: -16
  3269. },
  3270. /**
  3271. * An array of labels for the annotation. For options that apply
  3272. * to multiple labels, they can be added to the
  3273. * [labelOptions](annotations.labelOptions.html).
  3274. *
  3275. * @type {Array<*>}
  3276. * @extends annotations.labelOptions
  3277. * @apioption annotations.labels
  3278. */
  3279. /**
  3280. * This option defines the point to which the label will be
  3281. * connected. It can be either the point which exists in the
  3282. * series - it is referenced by the point's id - or a new point
  3283. * with defined x, y properties and optionally axes.
  3284. *
  3285. * @sample highcharts/annotations/mock-point/
  3286. * Attach annotation to a mock point
  3287. *
  3288. * @declare Highcharts.AnnotationMockPointOptionsObject
  3289. * @type {string|*}
  3290. * @requires modules/annotations
  3291. * @apioption annotations.labels.point
  3292. */
  3293. /**
  3294. * The x position of the point. Units can be either in axis
  3295. * or chart pixel coordinates.
  3296. *
  3297. * @type {number}
  3298. * @apioption annotations.labels.point.x
  3299. */
  3300. /**
  3301. * The y position of the point. Units can be either in axis
  3302. * or chart pixel coordinates.
  3303. *
  3304. * @type {number}
  3305. * @apioption annotations.labels.point.y
  3306. */
  3307. /**
  3308. * This number defines which xAxis the point is connected to.
  3309. * It refers to either the axis id or the index of the axis in
  3310. * the xAxis array. If the option is not configured or the axis
  3311. * is not found the point's x coordinate refers to the chart
  3312. * pixels.
  3313. *
  3314. * @type {number|string|null}
  3315. * @apioption annotations.labels.point.xAxis
  3316. */
  3317. /**
  3318. * This number defines which yAxis the point is connected to.
  3319. * It refers to either the axis id or the index of the axis in
  3320. * the yAxis array. If the option is not configured or the axis
  3321. * is not found the point's y coordinate refers to the chart
  3322. * pixels.
  3323. *
  3324. * @type {number|string|null}
  3325. * @apioption annotations.labels.point.yAxis
  3326. */
  3327. /**
  3328. * An array of shapes for the annotation. For options that apply
  3329. * to multiple shapes, then can be added to the
  3330. * [shapeOptions](annotations.shapeOptions.html).
  3331. *
  3332. * @type {Array<*>}
  3333. * @extends annotations.shapeOptions
  3334. * @apioption annotations.shapes
  3335. */
  3336. /**
  3337. * This option defines the point to which the shape will be
  3338. * connected. It can be either the point which exists in the
  3339. * series - it is referenced by the point's id - or a new point
  3340. * with defined x, y properties and optionally axes.
  3341. *
  3342. * @declare Highcharts.AnnotationMockPointOptionsObject
  3343. * @type {string|Highcharts.AnnotationMockPointOptionsObject}
  3344. * @extends annotations.labels.point
  3345. * @apioption annotations.shapes.point
  3346. */
  3347. /**
  3348. * An array of points for the shape. This option is available
  3349. * for shapes which can use multiple points such as path. A
  3350. * point can be either a point object or a point's id.
  3351. *
  3352. * @see [annotations.shapes.point](annotations.shapes.point.html)
  3353. *
  3354. * @declare Highcharts.AnnotationMockPointOptionsObject
  3355. * @type {Array<string|*>}
  3356. * @extends annotations.labels.point
  3357. * @apioption annotations.shapes.points
  3358. */
  3359. /**
  3360. * The URL for an image to use as the annotation shape. Note,
  3361. * type has to be set to `'image'`.
  3362. *
  3363. * @see [annotations.shapes.type](annotations.shapes.type)
  3364. * @sample highcharts/annotations/shape-src/
  3365. * Define a marker image url for annotations
  3366. *
  3367. * @type {string}
  3368. * @apioption annotations.shapes.src
  3369. */
  3370. /**
  3371. * Id of the marker which will be drawn at the final vertex of
  3372. * the path. Custom markers can be defined in defs property.
  3373. *
  3374. * @see [defs.markers](defs.markers.html)
  3375. *
  3376. * @sample highcharts/annotations/custom-markers/
  3377. * Define a custom marker for annotations
  3378. *
  3379. * @type {string}
  3380. * @apioption annotations.shapes.markerEnd
  3381. */
  3382. /**
  3383. * Id of the marker which will be drawn at the first vertex of
  3384. * the path. Custom markers can be defined in defs property.
  3385. *
  3386. * @see [defs.markers](defs.markers.html)
  3387. *
  3388. * @sample {highcharts} highcharts/annotations/custom-markers/
  3389. * Define a custom marker for annotations
  3390. *
  3391. * @type {string}
  3392. * @apioption annotations.shapes.markerStart
  3393. */
  3394. /**
  3395. * Options for annotation's shapes. Each shape inherits options
  3396. * from the shapeOptions object. An option from the shapeOptions
  3397. * can be overwritten by config for a specific shape.
  3398. *
  3399. * @requires modules/annotations
  3400. */
  3401. shapeOptions: {
  3402. /**
  3403. * The width of the shape.
  3404. *
  3405. * @sample highcharts/annotations/shape/
  3406. * Basic shape annotation
  3407. *
  3408. * @type {number}
  3409. * @apioption annotations.shapeOptions.width
  3410. **/
  3411. /**
  3412. * The height of the shape.
  3413. *
  3414. * @sample highcharts/annotations/shape/
  3415. * Basic shape annotation
  3416. *
  3417. * @type {number}
  3418. * @apioption annotations.shapeOptions.height
  3419. */
  3420. /**
  3421. * The type of the shape, e.g. circle or rectangle.
  3422. *
  3423. * @sample highcharts/annotations/shape/
  3424. * Basic shape annotation
  3425. *
  3426. * @type {string}
  3427. * @default rect
  3428. * @apioption annotations.shapeOptions.type
  3429. */
  3430. /**
  3431. * The URL for an image to use as the annotation shape.
  3432. * Note, type has to be set to `'image'`.
  3433. *
  3434. * @see [annotations.shapeOptions.type](annotations.shapeOptions.type)
  3435. * @sample highcharts/annotations/shape-src/
  3436. * Define a marker image url for annotations
  3437. *
  3438. * @type {string}
  3439. * @apioption annotations.shapeOptions.src
  3440. */
  3441. /**
  3442. * Name of the dash style to use for the shape's stroke.
  3443. *
  3444. * @sample {highcharts} highcharts/plotoptions/series-dashstyle-all/
  3445. * Possible values demonstrated
  3446. *
  3447. * @type {Highcharts.DashStyleValue}
  3448. * @apioption annotations.shapeOptions.dashStyle
  3449. */
  3450. /**
  3451. * The color of the shape's stroke.
  3452. *
  3453. * @sample highcharts/annotations/shape/
  3454. * Basic shape annotation
  3455. *
  3456. * @type {Highcharts.ColorString}
  3457. */
  3458. stroke: 'rgba(0, 0, 0, 0.75)',
  3459. /**
  3460. * The pixel stroke width of the shape.
  3461. *
  3462. * @sample highcharts/annotations/shape/
  3463. * Basic shape annotation
  3464. */
  3465. strokeWidth: 1,
  3466. /**
  3467. * The color of the shape's fill.
  3468. *
  3469. * @sample highcharts/annotations/shape/
  3470. * Basic shape annotation
  3471. *
  3472. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3473. */
  3474. fill: 'rgba(0, 0, 0, 0.75)',
  3475. /**
  3476. * The radius of the shape.
  3477. *
  3478. * @sample highcharts/annotations/shape/
  3479. * Basic shape annotation
  3480. */
  3481. r: 0,
  3482. /**
  3483. * Defines additional snapping area around an annotation
  3484. * making this annotation to focus. Defined in pixels.
  3485. */
  3486. snap: 2
  3487. },
  3488. /**
  3489. * Options for annotation's control points. Each control point
  3490. * inherits options from controlPointOptions object.
  3491. * Options from the controlPointOptions can be overwritten
  3492. * by options in a specific control point.
  3493. *
  3494. * @declare Highcharts.AnnotationControlPointOptionsObject
  3495. * @requires modules/annotations
  3496. * @apioption annotations.controlPointOptions
  3497. */
  3498. controlPointOptions: {
  3499. /**
  3500. * @type {Highcharts.AnnotationControlPointPositionerFunction}
  3501. * @apioption annotations.controlPointOptions.positioner
  3502. */
  3503. symbol: 'circle',
  3504. width: 10,
  3505. height: 10,
  3506. style: {
  3507. stroke: palette.neutralColor100,
  3508. 'stroke-width': 2,
  3509. fill: palette.backgroundColor
  3510. },
  3511. visible: false,
  3512. events: {}
  3513. },
  3514. /**
  3515. * Event callback when annotation is added to the chart.
  3516. *
  3517. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3518. * @since 7.1.0
  3519. * @apioption annotations.events.add
  3520. */
  3521. /**
  3522. * Event callback when annotation is updated (e.g. drag and
  3523. * droppped or resized by control points).
  3524. *
  3525. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3526. * @since 7.1.0
  3527. * @apioption annotations.events.afterUpdate
  3528. */
  3529. /**
  3530. * Event callback when annotation is removed from the chart.
  3531. *
  3532. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3533. * @since 7.1.0
  3534. * @apioption annotations.events.remove
  3535. */
  3536. /**
  3537. * Events available in annotations.
  3538. *
  3539. * @requires modules/annotations
  3540. */
  3541. events: {},
  3542. /**
  3543. * The Z index of the annotation.
  3544. */
  3545. zIndex: 6
  3546. }
  3547. }));
  3548. H.extendAnnotation = function (Constructor, BaseConstructor, prototype, defaultOptions) {
  3549. BaseConstructor = BaseConstructor || Annotation;
  3550. extend(Constructor.prototype, merge(BaseConstructor.prototype, prototype));
  3551. Constructor.prototype.defaultOptions = merge(Constructor.prototype.defaultOptions, defaultOptions || {});
  3552. };
  3553. /* *********************************************************************
  3554. *
  3555. * EXTENDING CHART PROTOTYPE
  3556. *
  3557. ******************************************************************** */
  3558. extend(chartProto, /** @lends Highcharts.Chart# */ {
  3559. initAnnotation: function (userOptions) {
  3560. var Constructor = Annotation.types[userOptions.type] || Annotation,
  3561. annotation = new Constructor(this,
  3562. userOptions);
  3563. this.annotations.push(annotation);
  3564. return annotation;
  3565. },
  3566. /**
  3567. * Add an annotation to the chart after render time.
  3568. *
  3569. * @param {Highcharts.AnnotationsOptions} options
  3570. * The annotation options for the new, detailed annotation.
  3571. * @param {boolean} [redraw]
  3572. *
  3573. * @return {Highcharts.Annotation} - The newly generated annotation.
  3574. */
  3575. addAnnotation: function (userOptions, redraw) {
  3576. var annotation = this.initAnnotation(userOptions);
  3577. this.options.annotations.push(annotation.options);
  3578. if (pick(redraw, true)) {
  3579. annotation.redraw();
  3580. annotation.graphic.attr({
  3581. opacity: 1
  3582. });
  3583. }
  3584. return annotation;
  3585. },
  3586. /**
  3587. * Remove an annotation from the chart.
  3588. *
  3589. * @param {number|string|Highcharts.Annotation} idOrAnnotation
  3590. * The annotation's id or direct annotation object.
  3591. */
  3592. removeAnnotation: function (idOrAnnotation) {
  3593. var annotations = this.annotations,
  3594. annotation = idOrAnnotation.coll === 'annotations' ?
  3595. idOrAnnotation :
  3596. find(annotations,
  3597. function (annotation) {
  3598. return annotation.options.id === idOrAnnotation;
  3599. });
  3600. if (annotation) {
  3601. fireEvent(annotation, 'remove');
  3602. erase(this.options.annotations, annotation.options);
  3603. erase(annotations, annotation);
  3604. annotation.destroy();
  3605. }
  3606. },
  3607. drawAnnotations: function () {
  3608. this.plotBoxClip.attr(this.plotBox);
  3609. this.annotations.forEach(function (annotation) {
  3610. annotation.redraw();
  3611. annotation.graphic.animate({
  3612. opacity: 1
  3613. }, annotation.animationConfig);
  3614. });
  3615. }
  3616. });
  3617. // Let chart.update() update annotations
  3618. chartProto.collectionsWithUpdate.push('annotations');
  3619. // Let chart.update() create annoations on demand
  3620. chartProto.collectionsWithInit.annotations = [chartProto.addAnnotation];
  3621. // Create lookups initially
  3622. addEvent(Chart, 'afterInit', function () {
  3623. this.annotations = [];
  3624. if (!this.options.annotations) {
  3625. this.options.annotations = [];
  3626. }
  3627. });
  3628. chartProto.callbacks.push(function (chart) {
  3629. chart.plotBoxClip = this.renderer.clipRect(this.plotBox);
  3630. chart.controlPointsGroup = chart.renderer
  3631. .g('control-points')
  3632. .attr({ zIndex: 99 })
  3633. .clip(chart.plotBoxClip)
  3634. .add();
  3635. chart.options.annotations.forEach(function (annotationOptions, i) {
  3636. if (
  3637. // Verify that it has not been previously added in a responsive rule
  3638. !chart.annotations.some(function (annotation) {
  3639. return annotation.options === annotationOptions;
  3640. })) {
  3641. var annotation = chart.initAnnotation(annotationOptions);
  3642. chart.options.annotations[i] = annotation.options;
  3643. }
  3644. });
  3645. chart.drawAnnotations();
  3646. addEvent(chart, 'redraw', chart.drawAnnotations);
  3647. addEvent(chart, 'destroy', function () {
  3648. chart.plotBoxClip.destroy();
  3649. chart.controlPointsGroup.destroy();
  3650. });
  3651. addEvent(chart, 'exportData', function (event) {
  3652. var annotations = chart.annotations,
  3653. csvColumnHeaderFormatter = ((this.options.exporting &&
  3654. this.options.exporting.csv) ||
  3655. {}).columnHeaderFormatter,
  3656. // If second row doesn't have xValues
  3657. // then it is a title row thus multiple level header is in use.
  3658. multiLevelHeaders = !event.dataRows[1].xValues,
  3659. annotationHeader = (chart.options.lang &&
  3660. chart.options.lang.exportData &&
  3661. chart.options.lang.exportData.annotationHeader),
  3662. columnHeaderFormatter = function (index) {
  3663. var s;
  3664. if (csvColumnHeaderFormatter) {
  3665. s = csvColumnHeaderFormatter(index);
  3666. if (s !== false) {
  3667. return s;
  3668. }
  3669. }
  3670. s = annotationHeader + ' ' + index;
  3671. if (multiLevelHeaders) {
  3672. return {
  3673. columnTitle: s,
  3674. topLevelColumnTitle: s
  3675. };
  3676. }
  3677. return s;
  3678. }, startRowLength = event.dataRows[0].length, annotationSeparator = (chart.options.exporting &&
  3679. chart.options.exporting.csv &&
  3680. chart.options.exporting.csv.annotations &&
  3681. chart.options.exporting.csv.annotations.itemDelimiter), joinAnnotations = (chart.options.exporting &&
  3682. chart.options.exporting.csv &&
  3683. chart.options.exporting.csv.annotations &&
  3684. chart.options.exporting.csv.annotations.join);
  3685. annotations.forEach(function (annotation) {
  3686. if (annotation.options.labelOptions.includeInDataExport) {
  3687. annotation.labels.forEach(function (label) {
  3688. if (label.options.text) {
  3689. var annotationText_1 = label.options.text;
  3690. label.points.forEach(function (points) {
  3691. var annotationX = points.x,
  3692. xAxisIndex = points.series.xAxis ?
  3693. points.series.xAxis.options.index :
  3694. -1;
  3695. var wasAdded = false;
  3696. // Annotation not connected to any xAxis -
  3697. // add new row.
  3698. if (xAxisIndex === -1) {
  3699. var n = event.dataRows[0].length,
  3700. newRow = new Array(n);
  3701. for (var i = 0; i < n; ++i) {
  3702. newRow[i] = '';
  3703. }
  3704. newRow.push(annotationText_1);
  3705. newRow.xValues = [];
  3706. newRow.xValues[xAxisIndex] = annotationX;
  3707. event.dataRows.push(newRow);
  3708. wasAdded = true;
  3709. }
  3710. // Annotation placed on a exported data point
  3711. // - add new column
  3712. if (!wasAdded) {
  3713. event.dataRows.forEach(function (row, rowIndex) {
  3714. if (!wasAdded &&
  3715. row.xValues &&
  3716. xAxisIndex !== void 0 &&
  3717. annotationX === row.xValues[xAxisIndex]) {
  3718. if (joinAnnotations &&
  3719. row.length > startRowLength) {
  3720. row[row.length - 1] +=
  3721. annotationSeparator + annotationText_1;
  3722. }
  3723. else {
  3724. row.push(annotationText_1);
  3725. }
  3726. wasAdded = true;
  3727. }
  3728. });
  3729. }
  3730. // Annotation not placed on any exported data point,
  3731. // but connected to the xAxis - add new row
  3732. if (!wasAdded) {
  3733. var n = event.dataRows[0].length,
  3734. newRow = new Array(n);
  3735. for (var i = 0; i < n; ++i) {
  3736. newRow[i] = '';
  3737. }
  3738. newRow[0] = annotationX;
  3739. newRow.push(annotationText_1);
  3740. newRow.xValues = [];
  3741. if (xAxisIndex !== void 0) {
  3742. newRow.xValues[xAxisIndex] = annotationX;
  3743. }
  3744. event.dataRows.push(newRow);
  3745. }
  3746. });
  3747. }
  3748. });
  3749. }
  3750. });
  3751. var maxRowLen = 0;
  3752. event.dataRows.forEach(function (row) {
  3753. maxRowLen = Math.max(maxRowLen, row.length);
  3754. });
  3755. var newRows = maxRowLen - event.dataRows[0].length;
  3756. for (var i = 0; i < newRows; i++) {
  3757. var header = columnHeaderFormatter(i + 1);
  3758. if (multiLevelHeaders) {
  3759. event.dataRows[0].push(header.topLevelColumnTitle);
  3760. event.dataRows[1].push(header.columnTitle);
  3761. }
  3762. else {
  3763. event.dataRows[0].push(header);
  3764. }
  3765. }
  3766. });
  3767. });
  3768. wrap(Pointer.prototype, 'onContainerMouseDown', function (proceed) {
  3769. if (!this.chart.hasDraggedAnnotation) {
  3770. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3771. }
  3772. });
  3773. H.Annotation = Annotation;
  3774. return Annotation;
  3775. });
  3776. _registerModule(_modules, 'Mixins/Navigation.js', [], function () {
  3777. /**
  3778. *
  3779. * (c) 2010-2021 Paweł Fus
  3780. *
  3781. * License: www.highcharts.com/license
  3782. *
  3783. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3784. *
  3785. * */
  3786. var chartNavigation = {
  3787. /**
  3788. * Initializes `chart.navigation` object which delegates `update()` methods
  3789. * to all other common classes (used in exporting and navigationBindings).
  3790. *
  3791. * @private
  3792. * @param {Highcharts.Chart} chart
  3793. * The chart instance.
  3794. * @return {void}
  3795. */
  3796. initUpdate: function (chart) {
  3797. if (!chart.navigation) {
  3798. chart.navigation = {
  3799. updates: [],
  3800. update: function (options,
  3801. redraw) {
  3802. this.updates.forEach(function (updateConfig) {
  3803. updateConfig.update.call(updateConfig.context,
  3804. options,
  3805. redraw);
  3806. });
  3807. }
  3808. };
  3809. }
  3810. },
  3811. /**
  3812. * Registers an `update()` method in the `chart.navigation` object.
  3813. *
  3814. * @private
  3815. * @param {Highcharts.ChartNavigationUpdateFunction} update
  3816. * The `update()` method that will be called in `chart.update()`.
  3817. * @param {Highcharts.Chart} chart
  3818. * The chart instance. `update()` will use that as a context
  3819. * (`this`).
  3820. * @return {void}
  3821. */
  3822. addUpdate: function (update, chart) {
  3823. if (!chart.navigation) {
  3824. this.initUpdate(chart);
  3825. }
  3826. chart.navigation.updates.push({
  3827. update: update,
  3828. context: chart
  3829. });
  3830. }
  3831. };
  3832. return chartNavigation;
  3833. });
  3834. _registerModule(_modules, 'Extensions/Annotations/NavigationBindings.js', [_modules['Extensions/Annotations/Annotations.js'], _modules['Core/Chart/Chart.js'], _modules['Mixins/Navigation.js'], _modules['Core/FormatUtilities.js'], _modules['Core/Globals.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Utilities.js']], function (Annotation, Chart, chartNavigationMixin, F, H, D, U) {
  3835. /* *
  3836. *
  3837. * (c) 2009-2021 Highsoft, Black Label
  3838. *
  3839. * License: www.highcharts.com/license
  3840. *
  3841. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3842. *
  3843. * */
  3844. var format = F.format;
  3845. var setOptions = D.setOptions;
  3846. var addEvent = U.addEvent,
  3847. attr = U.attr,
  3848. fireEvent = U.fireEvent,
  3849. isArray = U.isArray,
  3850. isFunction = U.isFunction,
  3851. isNumber = U.isNumber,
  3852. isObject = U.isObject,
  3853. merge = U.merge,
  3854. objectEach = U.objectEach,
  3855. pick = U.pick;
  3856. /**
  3857. * A config object for navigation bindings in annotations.
  3858. *
  3859. * @interface Highcharts.NavigationBindingsOptionsObject
  3860. */ /**
  3861. * ClassName of the element for a binding.
  3862. * @name Highcharts.NavigationBindingsOptionsObject#className
  3863. * @type {string|undefined}
  3864. */ /**
  3865. * Last event to be fired after last step event.
  3866. * @name Highcharts.NavigationBindingsOptionsObject#end
  3867. * @type {Function|undefined}
  3868. */ /**
  3869. * Initial event, fired on a button click.
  3870. * @name Highcharts.NavigationBindingsOptionsObject#init
  3871. * @type {Function|undefined}
  3872. */ /**
  3873. * Event fired on first click on a chart.
  3874. * @name Highcharts.NavigationBindingsOptionsObject#start
  3875. * @type {Function|undefined}
  3876. */ /**
  3877. * Last event to be fired after last step event. Array of step events to be
  3878. * called sequentially after each user click.
  3879. * @name Highcharts.NavigationBindingsOptionsObject#steps
  3880. * @type {Array<Function>|undefined}
  3881. */
  3882. var doc = H.doc,
  3883. win = H.win,
  3884. PREFIX = 'highcharts-';
  3885. /* eslint-disable no-invalid-this, valid-jsdoc */
  3886. /**
  3887. * IE 9-11 polyfill for Element.closest():
  3888. * @private
  3889. */
  3890. function closestPolyfill(el, s) {
  3891. var ElementProto = win.Element.prototype,
  3892. elementMatches = ElementProto.matches ||
  3893. ElementProto.msMatchesSelector ||
  3894. ElementProto.webkitMatchesSelector,
  3895. ret = null;
  3896. if (ElementProto.closest) {
  3897. ret = ElementProto.closest.call(el, s);
  3898. }
  3899. else {
  3900. do {
  3901. if (elementMatches.call(el, s)) {
  3902. return el;
  3903. }
  3904. el = el.parentElement || el.parentNode;
  3905. } while (el !== null && el.nodeType === 1);
  3906. }
  3907. return ret;
  3908. }
  3909. /**
  3910. * @private
  3911. * @interface bindingsUtils
  3912. */
  3913. var bindingsUtils = {
  3914. /**
  3915. * Get field type according to value
  3916. *
  3917. * @private
  3918. * @function Highcharts.NavigationBindingsUtilsObject.getFieldType
  3919. *
  3920. * @param {'boolean'|'number'|'string'} value
  3921. * Atomic type (one of: string,
  3922. number,
  3923. boolean)
  3924. *
  3925. * @return {'checkbox'|'number'|'text'}
  3926. * Field type (one of: text,
  3927. number,
  3928. checkbox)
  3929. */
  3930. getFieldType: function (value) {
  3931. return {
  3932. 'string': 'text',
  3933. 'number': 'number',
  3934. 'boolean': 'checkbox'
  3935. }[typeof value];
  3936. },
  3937. /**
  3938. * Update size of background (rect) in some annotations: Measure, Simple
  3939. * Rect.
  3940. *
  3941. * @private
  3942. * @function Highcharts.NavigationBindingsUtilsObject.updateRectSize
  3943. *
  3944. * @param {Highcharts.PointerEventObject} event
  3945. * Normalized browser event
  3946. *
  3947. * @param {Highcharts.Annotation} annotation
  3948. * Annotation to be updated
  3949. */
  3950. updateRectSize: function (event, annotation) {
  3951. var chart = annotation.chart,
  3952. options = annotation.options.typeOptions,
  3953. coords = chart.pointer.getCoordinates(event),
  3954. coordsX = chart.navigationBindings.utils.getAssignedAxis(coords.xAxis),
  3955. coordsY = chart.navigationBindings.utils.getAssignedAxis(coords.yAxis),
  3956. width,
  3957. height;
  3958. if (coordsX && coordsY) {
  3959. width = coordsX.value - options.point.x;
  3960. height = options.point.y - coordsY.value;
  3961. annotation.update({
  3962. typeOptions: {
  3963. background: {
  3964. width: chart.inverted ? height : width,
  3965. height: chart.inverted ? width : height
  3966. }
  3967. }
  3968. });
  3969. }
  3970. },
  3971. /**
  3972. * Returns the first xAxis or yAxis that was clicked with its value.
  3973. *
  3974. * @private
  3975. * @function Highcharts.NavigationBindingsUtilsObject#getAssignedAxis
  3976. *
  3977. * @param {Array<Highcharts.PointerAxisCoordinateObject>} coords
  3978. * All the chart's x or y axes with a current pointer's axis value.
  3979. *
  3980. * @return {Highcharts.PointerAxisCoordinateObject}
  3981. * Object with a first found axis and its value that pointer
  3982. * is currently pointing.
  3983. */
  3984. getAssignedAxis: function (coords) {
  3985. return coords.filter(function (coord) {
  3986. var axisMin = coord.axis.min,
  3987. axisMax = coord.axis.max,
  3988. // Correct axis edges when axis has series
  3989. // with pointRange (like column)
  3990. minPointOffset = pick(coord.axis.minPointOffset, 0);
  3991. return isNumber(axisMin) && isNumber(axisMax) &&
  3992. coord.value >= (axisMin - minPointOffset) &&
  3993. coord.value <= (axisMax + minPointOffset) &&
  3994. // don't count navigator axis
  3995. !coord.axis.options.isInternal;
  3996. })[0]; // If the axes overlap, return the first axis that was found.
  3997. }
  3998. };
  3999. /**
  4000. * @private
  4001. */
  4002. var NavigationBindings = /** @class */ (function () {
  4003. /* *
  4004. *
  4005. * Constructors
  4006. *
  4007. * */
  4008. function NavigationBindings(chart, options) {
  4009. this.boundClassNames = void 0;
  4010. this.selectedButton = void 0;
  4011. this.chart = chart;
  4012. this.options = options;
  4013. this.eventsToUnbind = [];
  4014. this.container = doc.getElementsByClassName(this.options.bindingsClassName || '');
  4015. }
  4016. // Private properties added by bindings:
  4017. // Active (selected) annotation that is editted through popup/forms
  4018. // activeAnnotation: Annotation
  4019. // Holder for current step, used on mouse move to update bound object
  4020. // mouseMoveEvent: function () {}
  4021. // Next event in `step` array to be called on chart's click
  4022. // nextEvent: function () {}
  4023. // Index in the `step` array of the current event
  4024. // stepIndex: 0
  4025. // Flag to determine if current binding has steps
  4026. // steps: true|false
  4027. // Bindings holder for all events
  4028. // selectedButton: {}
  4029. // Holder for user options, returned from `start` event, and passed on to
  4030. // `step`'s' and `end`.
  4031. // currentUserDetails: {}
  4032. /* *
  4033. *
  4034. * Functions
  4035. *
  4036. * */
  4037. /**
  4038. * Initi all events conencted to NavigationBindings.
  4039. *
  4040. * @private
  4041. * @function Highcharts.NavigationBindings#initEvents
  4042. */
  4043. NavigationBindings.prototype.initEvents = function () {
  4044. var navigation = this,
  4045. chart = navigation.chart,
  4046. bindingsContainer = navigation.container,
  4047. options = navigation.options;
  4048. // Shorthand object for getting events for buttons:
  4049. navigation.boundClassNames = {};
  4050. objectEach((options.bindings || {}), function (value) {
  4051. navigation.boundClassNames[value.className] = value;
  4052. });
  4053. // Handle multiple containers with the same class names:
  4054. [].forEach.call(bindingsContainer, function (subContainer) {
  4055. navigation.eventsToUnbind.push(addEvent(subContainer, 'click', function (event) {
  4056. var bindings = navigation.getButtonEvents(subContainer,
  4057. event);
  4058. if (bindings && bindings.button.className.indexOf('highcharts-disabled-btn') === -1) {
  4059. navigation.bindingsButtonClick(bindings.button, bindings.events, event);
  4060. }
  4061. }));
  4062. });
  4063. objectEach(options.events || {}, function (callback, eventName) {
  4064. if (isFunction(callback)) {
  4065. navigation.eventsToUnbind.push(addEvent(navigation, eventName, callback, { passive: false }));
  4066. }
  4067. });
  4068. navigation.eventsToUnbind.push(addEvent(chart.container, 'click', function (e) {
  4069. if (!chart.cancelClick &&
  4070. chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop, {
  4071. visiblePlotOnly: true
  4072. })) {
  4073. navigation.bindingsChartClick(this, e);
  4074. }
  4075. }));
  4076. navigation.eventsToUnbind.push(addEvent(chart.container, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
  4077. navigation.bindingsContainerMouseMove(this, e);
  4078. }, H.isTouchDevice ? { passive: false } : void 0));
  4079. };
  4080. /**
  4081. * Common chart.update() delegation, shared between bindings and exporting.
  4082. *
  4083. * @private
  4084. * @function Highcharts.NavigationBindings#initUpdate
  4085. */
  4086. NavigationBindings.prototype.initUpdate = function () {
  4087. var navigation = this;
  4088. chartNavigationMixin.addUpdate(function (options) {
  4089. navigation.update(options);
  4090. }, this.chart);
  4091. };
  4092. /**
  4093. * Hook for click on a button, method selcts/unselects buttons,
  4094. * then calls `bindings.init` callback.
  4095. *
  4096. * @private
  4097. * @function Highcharts.NavigationBindings#bindingsButtonClick
  4098. *
  4099. * @param {Highcharts.HTMLDOMElement} [button]
  4100. * Clicked button
  4101. *
  4102. * @param {object} events
  4103. * Events passed down from bindings (`init`, `start`, `step`, `end`)
  4104. *
  4105. * @param {Highcharts.PointerEventObject} clickEvent
  4106. * Browser's click event
  4107. */
  4108. NavigationBindings.prototype.bindingsButtonClick = function (button, events, clickEvent) {
  4109. var navigation = this,
  4110. chart = navigation.chart;
  4111. if (navigation.selectedButtonElement) {
  4112. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4113. if (navigation.nextEvent) {
  4114. // Remove in-progress annotations adders:
  4115. if (navigation.currentUserDetails &&
  4116. navigation.currentUserDetails.coll === 'annotations') {
  4117. chart.removeAnnotation(navigation.currentUserDetails);
  4118. }
  4119. navigation.mouseMoveEvent = navigation.nextEvent = false;
  4120. }
  4121. }
  4122. navigation.selectedButton = events;
  4123. navigation.selectedButtonElement = button;
  4124. fireEvent(navigation, 'selectButton', { button: button });
  4125. // Call "init" event, for example to open modal window
  4126. if (events.init) {
  4127. events.init.call(navigation, button, clickEvent);
  4128. }
  4129. if (events.start || events.steps) {
  4130. chart.renderer.boxWrapper.addClass(PREFIX + 'draw-mode');
  4131. }
  4132. };
  4133. /**
  4134. * Hook for click on a chart, first click on a chart calls `start` event,
  4135. * then on all subsequent clicks iterate over `steps` array.
  4136. * When finished, calls `end` event.
  4137. *
  4138. * @private
  4139. * @function Highcharts.NavigationBindings#bindingsChartClick
  4140. *
  4141. * @param {Highcharts.Chart} chart
  4142. * Chart that click was performed on.
  4143. *
  4144. * @param {Highcharts.PointerEventObject} clickEvent
  4145. * Browser's click event.
  4146. */
  4147. NavigationBindings.prototype.bindingsChartClick = function (chart, clickEvent) {
  4148. chart = this.chart;
  4149. var navigation = this,
  4150. selectedButton = navigation.selectedButton,
  4151. svgContainer = chart.renderer.boxWrapper;
  4152. // Click outside popups, should close them and deselect the annotation
  4153. if (navigation.activeAnnotation &&
  4154. !clickEvent.activeAnnotation &&
  4155. // Element could be removed in the child action, e.g. button
  4156. clickEvent.target.parentNode &&
  4157. // TO DO: Polyfill for IE11?
  4158. !closestPolyfill(clickEvent.target, '.' + PREFIX + 'popup')) {
  4159. fireEvent(navigation, 'closePopup');
  4160. }
  4161. if (!selectedButton || !selectedButton.start) {
  4162. return;
  4163. }
  4164. if (!navigation.nextEvent) {
  4165. // Call init method:
  4166. navigation.currentUserDetails = selectedButton.start.call(navigation, clickEvent);
  4167. // If steps exists (e.g. Annotations), bind them:
  4168. if (navigation.currentUserDetails && selectedButton.steps) {
  4169. navigation.stepIndex = 0;
  4170. navigation.steps = true;
  4171. navigation.mouseMoveEvent = navigation.nextEvent =
  4172. selectedButton.steps[navigation.stepIndex];
  4173. }
  4174. else {
  4175. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4176. svgContainer.removeClass(PREFIX + 'draw-mode');
  4177. navigation.steps = false;
  4178. navigation.selectedButton = null;
  4179. // First click is also the last one:
  4180. if (selectedButton.end) {
  4181. selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
  4182. }
  4183. }
  4184. }
  4185. else {
  4186. navigation.nextEvent(clickEvent, navigation.currentUserDetails);
  4187. if (navigation.steps) {
  4188. navigation.stepIndex++;
  4189. if (selectedButton.steps[navigation.stepIndex]) {
  4190. // If we have more steps, bind them one by one:
  4191. navigation.mouseMoveEvent = navigation.nextEvent =
  4192. selectedButton.steps[navigation.stepIndex];
  4193. }
  4194. else {
  4195. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4196. svgContainer.removeClass(PREFIX + 'draw-mode');
  4197. // That was the last step, call end():
  4198. if (selectedButton.end) {
  4199. selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
  4200. }
  4201. navigation.nextEvent = false;
  4202. navigation.mouseMoveEvent = false;
  4203. navigation.selectedButton = null;
  4204. }
  4205. }
  4206. }
  4207. };
  4208. /**
  4209. * Hook for mouse move on a chart's container. It calls current step.
  4210. *
  4211. * @private
  4212. * @function Highcharts.NavigationBindings#bindingsContainerMouseMove
  4213. *
  4214. * @param {Highcharts.HTMLDOMElement} container
  4215. * Chart's container.
  4216. *
  4217. * @param {global.Event} moveEvent
  4218. * Browser's move event.
  4219. */
  4220. NavigationBindings.prototype.bindingsContainerMouseMove = function (_container, moveEvent) {
  4221. if (this.mouseMoveEvent) {
  4222. this.mouseMoveEvent(moveEvent, this.currentUserDetails);
  4223. }
  4224. };
  4225. /**
  4226. * Translate fields (e.g. `params.period` or `marker.styles.color`) to
  4227. * Highcharts options object (e.g. `{ params: { period } }`).
  4228. *
  4229. * @private
  4230. * @function Highcharts.NavigationBindings#fieldsToOptions<T>
  4231. *
  4232. * @param {Highcharts.Dictionary<string>} fields
  4233. * Fields from popup form.
  4234. *
  4235. * @param {T} config
  4236. * Default config to be modified.
  4237. *
  4238. * @return {T}
  4239. * Modified config
  4240. */
  4241. NavigationBindings.prototype.fieldsToOptions = function (fields, config) {
  4242. objectEach(fields, function (value, field) {
  4243. var parsedValue = parseFloat(value),
  4244. path = field.split('.'),
  4245. parent = config,
  4246. pathLength = path.length - 1;
  4247. // If it's a number (not "format" options), parse it:
  4248. if (isNumber(parsedValue) &&
  4249. !value.match(/px/g) &&
  4250. !field.match(/format/g)) {
  4251. value = parsedValue;
  4252. }
  4253. // Remove empty strings or values like 0
  4254. if (value !== '' && value !== 'undefined') {
  4255. path.forEach(function (name, index) {
  4256. var nextName = pick(path[index + 1], '');
  4257. if (pathLength === index) {
  4258. // Last index, put value:
  4259. parent[name] = value;
  4260. }
  4261. else if (!parent[name]) {
  4262. // Create middle property:
  4263. parent[name] = nextName.match(/\d/g) ? [] : {};
  4264. parent = parent[name];
  4265. }
  4266. else {
  4267. // Jump into next property
  4268. parent = parent[name];
  4269. }
  4270. });
  4271. }
  4272. });
  4273. return config;
  4274. };
  4275. /**
  4276. * Shorthand method to deselect an annotation.
  4277. *
  4278. * @function Highcharts.NavigationBindings#deselectAnnotation
  4279. */
  4280. NavigationBindings.prototype.deselectAnnotation = function () {
  4281. if (this.activeAnnotation) {
  4282. this.activeAnnotation.setControlPointsVisibility(false);
  4283. this.activeAnnotation = false;
  4284. }
  4285. };
  4286. /**
  4287. * Generates API config for popup in the same format as options for
  4288. * Annotation object.
  4289. *
  4290. * @function Highcharts.NavigationBindings#annotationToFields
  4291. *
  4292. * @param {Highcharts.Annotation} annotation
  4293. * Annotations object
  4294. *
  4295. * @return {Highcharts.Dictionary<string>}
  4296. * Annotation options to be displayed in popup box
  4297. */
  4298. NavigationBindings.prototype.annotationToFields = function (annotation) {
  4299. var options = annotation.options,
  4300. editables = NavigationBindings.annotationsEditable,
  4301. nestedEditables = editables.nestedOptions,
  4302. getFieldType = this.utils.getFieldType,
  4303. type = pick(options.type,
  4304. options.shapes && options.shapes[0] &&
  4305. options.shapes[0].type,
  4306. options.labels && options.labels[0] &&
  4307. options.labels[0].itemType, 'label'),
  4308. nonEditables = NavigationBindings.annotationsNonEditable[options.langKey] || [],
  4309. visualOptions = {
  4310. langKey: options.langKey,
  4311. type: type
  4312. };
  4313. /**
  4314. * Nested options traversing. Method goes down to the options and copies
  4315. * allowed options (with values) to new object, which is last parameter:
  4316. * "parent".
  4317. *
  4318. * @private
  4319. *
  4320. * @param {*} option
  4321. * Atomic type or object/array
  4322. *
  4323. * @param {string} key
  4324. * Option name, for example "visible" or "x", "y"
  4325. *
  4326. * @param {object} parentEditables
  4327. * Editables from NavigationBindings.annotationsEditable
  4328. *
  4329. * @param {object} parent
  4330. * Where new options will be assigned
  4331. */
  4332. function traverse(option, key, parentEditables, parent) {
  4333. var nextParent;
  4334. if (parentEditables &&
  4335. option &&
  4336. nonEditables.indexOf(key) === -1 &&
  4337. ((parentEditables.indexOf &&
  4338. parentEditables.indexOf(key)) >= 0 ||
  4339. parentEditables[key] || // nested array
  4340. parentEditables === true // simple array
  4341. )) {
  4342. // Roots:
  4343. if (isArray(option)) {
  4344. parent[key] = [];
  4345. option.forEach(function (arrayOption, i) {
  4346. if (!isObject(arrayOption)) {
  4347. // Simple arrays, e.g. [String, Number, Boolean]
  4348. traverse(arrayOption, 0, nestedEditables[key], parent[key]);
  4349. }
  4350. else {
  4351. // Advanced arrays, e.g. [Object, Object]
  4352. parent[key][i] = {};
  4353. objectEach(arrayOption, function (nestedOption, nestedKey) {
  4354. traverse(nestedOption, nestedKey, nestedEditables[key], parent[key][i]);
  4355. });
  4356. }
  4357. });
  4358. }
  4359. else if (isObject(option)) {
  4360. nextParent = {};
  4361. if (isArray(parent)) {
  4362. parent.push(nextParent);
  4363. nextParent[key] = {};
  4364. nextParent = nextParent[key];
  4365. }
  4366. else {
  4367. parent[key] = nextParent;
  4368. }
  4369. objectEach(option, function (nestedOption, nestedKey) {
  4370. traverse(nestedOption, nestedKey, key === 0 ? parentEditables : nestedEditables[key], nextParent);
  4371. });
  4372. }
  4373. else {
  4374. // Leaf:
  4375. if (key === 'format') {
  4376. parent[key] = [
  4377. format(option, annotation.labels[0].points[0]).toString(),
  4378. 'text'
  4379. ];
  4380. }
  4381. else if (isArray(parent)) {
  4382. parent.push([option, getFieldType(option)]);
  4383. }
  4384. else {
  4385. parent[key] = [option, getFieldType(option)];
  4386. }
  4387. }
  4388. }
  4389. }
  4390. objectEach(options, function (option, key) {
  4391. if (key === 'typeOptions') {
  4392. visualOptions[key] = {};
  4393. objectEach(options[key], function (typeOption, typeKey) {
  4394. traverse(typeOption, typeKey, nestedEditables, visualOptions[key], true);
  4395. });
  4396. }
  4397. else {
  4398. traverse(option, key, editables[type], visualOptions);
  4399. }
  4400. });
  4401. return visualOptions;
  4402. };
  4403. /**
  4404. * Get all class names for all parents in the element. Iterates until finds
  4405. * main container.
  4406. *
  4407. * @function Highcharts.NavigationBindings#getClickedClassNames
  4408. *
  4409. * @param {Highcharts.HTMLDOMElement}
  4410. * Container that event is bound to.
  4411. *
  4412. * @param {global.Event} event
  4413. * Browser's event.
  4414. *
  4415. * @return {Array<Array<string, Highcharts.HTMLDOMElement>>}
  4416. * Array of class names with corresponding elements
  4417. */
  4418. NavigationBindings.prototype.getClickedClassNames = function (container, event) {
  4419. var element = event.target,
  4420. classNames = [],
  4421. elemClassName;
  4422. while (element) {
  4423. elemClassName = attr(element, 'class');
  4424. if (elemClassName) {
  4425. classNames = classNames.concat(elemClassName
  4426. .split(' ')
  4427. .map(function (name) {
  4428. return [
  4429. name,
  4430. element
  4431. ];
  4432. }));
  4433. }
  4434. element = element.parentNode;
  4435. if (element === container) {
  4436. return classNames;
  4437. }
  4438. }
  4439. return classNames;
  4440. };
  4441. /**
  4442. * Get events bound to a button. It's a custom event delegation to find all
  4443. * events connected to the element.
  4444. *
  4445. * @private
  4446. * @function Highcharts.NavigationBindings#getButtonEvents
  4447. *
  4448. * @param {Highcharts.HTMLDOMElement} container
  4449. * Container that event is bound to.
  4450. *
  4451. * @param {global.Event} event
  4452. * Browser's event.
  4453. *
  4454. * @return {object}
  4455. * Object with events (init, start, steps, and end)
  4456. */
  4457. NavigationBindings.prototype.getButtonEvents = function (container, event) {
  4458. var navigation = this,
  4459. classNames = this.getClickedClassNames(container,
  4460. event),
  4461. bindings;
  4462. classNames.forEach(function (className) {
  4463. if (navigation.boundClassNames[className[0]] && !bindings) {
  4464. bindings = {
  4465. events: navigation.boundClassNames[className[0]],
  4466. button: className[1]
  4467. };
  4468. }
  4469. });
  4470. return bindings;
  4471. };
  4472. /**
  4473. * Bindings are just events, so the whole update process is simply
  4474. * removing old events and adding new ones.
  4475. *
  4476. * @private
  4477. * @function Highcharts.NavigationBindings#update
  4478. */
  4479. NavigationBindings.prototype.update = function (options) {
  4480. this.options = merge(true, this.options, options);
  4481. this.removeEvents();
  4482. this.initEvents();
  4483. };
  4484. /**
  4485. * Remove all events created in the navigation.
  4486. *
  4487. * @private
  4488. * @function Highcharts.NavigationBindings#removeEvents
  4489. */
  4490. NavigationBindings.prototype.removeEvents = function () {
  4491. this.eventsToUnbind.forEach(function (unbinder) {
  4492. unbinder();
  4493. });
  4494. };
  4495. NavigationBindings.prototype.destroy = function () {
  4496. this.removeEvents();
  4497. };
  4498. /* *
  4499. *
  4500. * Static Properties
  4501. *
  4502. * */
  4503. // Define which options from annotations should show up in edit box:
  4504. NavigationBindings.annotationsEditable = {
  4505. // `typeOptions` are always available
  4506. // Nested and shared options:
  4507. nestedOptions: {
  4508. labelOptions: ['style', 'format', 'backgroundColor'],
  4509. labels: ['style'],
  4510. label: ['style'],
  4511. style: ['fontSize', 'color'],
  4512. background: ['fill', 'strokeWidth', 'stroke'],
  4513. innerBackground: ['fill', 'strokeWidth', 'stroke'],
  4514. outerBackground: ['fill', 'strokeWidth', 'stroke'],
  4515. shapeOptions: ['fill', 'strokeWidth', 'stroke'],
  4516. shapes: ['fill', 'strokeWidth', 'stroke'],
  4517. line: ['strokeWidth', 'stroke'],
  4518. backgroundColors: [true],
  4519. connector: ['fill', 'strokeWidth', 'stroke'],
  4520. crosshairX: ['strokeWidth', 'stroke'],
  4521. crosshairY: ['strokeWidth', 'stroke']
  4522. },
  4523. // Simple shapes:
  4524. circle: ['shapes'],
  4525. verticalLine: [],
  4526. label: ['labelOptions'],
  4527. // Measure
  4528. measure: ['background', 'crosshairY', 'crosshairX'],
  4529. // Others:
  4530. fibonacci: [],
  4531. tunnel: ['background', 'line', 'height'],
  4532. pitchfork: ['innerBackground', 'outerBackground'],
  4533. rect: ['shapes'],
  4534. // Crooked lines, elliots, arrows etc:
  4535. crookedLine: [],
  4536. basicAnnotation: ['shapes', 'labelOptions']
  4537. };
  4538. // Define non editable fields per annotation, for example Rectangle inherits
  4539. // options from Measure, but crosshairs are not available
  4540. NavigationBindings.annotationsNonEditable = {
  4541. rectangle: ['crosshairX', 'crosshairY', 'label']
  4542. };
  4543. return NavigationBindings;
  4544. }());
  4545. /**
  4546. * General utils for bindings
  4547. *
  4548. * @private
  4549. * @name Highcharts.NavigationBindings.utils
  4550. * @type {bindingsUtils}
  4551. */
  4552. NavigationBindings.prototype.utils = bindingsUtils;
  4553. Chart.prototype.initNavigationBindings = function () {
  4554. var chart = this,
  4555. options = chart.options;
  4556. if (options && options.navigation && options.navigation.bindings) {
  4557. chart.navigationBindings = new NavigationBindings(chart, options.navigation);
  4558. chart.navigationBindings.initEvents();
  4559. chart.navigationBindings.initUpdate();
  4560. }
  4561. };
  4562. addEvent(Chart, 'load', function () {
  4563. this.initNavigationBindings();
  4564. });
  4565. addEvent(Chart, 'destroy', function () {
  4566. if (this.navigationBindings) {
  4567. this.navigationBindings.destroy();
  4568. }
  4569. });
  4570. addEvent(NavigationBindings, 'deselectButton', function () {
  4571. this.selectedButtonElement = null;
  4572. });
  4573. addEvent(Annotation, 'remove', function () {
  4574. if (this.chart.navigationBindings) {
  4575. this.chart.navigationBindings.deselectAnnotation();
  4576. }
  4577. });
  4578. /**
  4579. * Show edit-annotation form:
  4580. * @private
  4581. */
  4582. function selectableAnnotation(annotationType) {
  4583. var originalClick = annotationType.prototype.defaultOptions.events &&
  4584. annotationType.prototype.defaultOptions.events.click;
  4585. /**
  4586. * @private
  4587. */
  4588. function selectAndShowPopup(eventArguments) {
  4589. var annotation = this,
  4590. navigation = annotation.chart.navigationBindings,
  4591. prevAnnotation = navigation.activeAnnotation;
  4592. if (originalClick) {
  4593. originalClick.call(annotation, eventArguments);
  4594. }
  4595. if (prevAnnotation !== annotation) {
  4596. // Select current:
  4597. navigation.deselectAnnotation();
  4598. navigation.activeAnnotation = annotation;
  4599. annotation.setControlPointsVisibility(true);
  4600. fireEvent(navigation, 'showPopup', {
  4601. annotation: annotation,
  4602. formType: 'annotation-toolbar',
  4603. options: navigation.annotationToFields(annotation),
  4604. onSubmit: function (data) {
  4605. var config = {},
  4606. typeOptions;
  4607. if (data.actionType === 'remove') {
  4608. navigation.activeAnnotation = false;
  4609. navigation.chart.removeAnnotation(annotation);
  4610. }
  4611. else {
  4612. navigation.fieldsToOptions(data.fields, config);
  4613. navigation.deselectAnnotation();
  4614. typeOptions = config.typeOptions;
  4615. if (annotation.options.type === 'measure') {
  4616. // Manually disable crooshars according to
  4617. // stroke width of the shape:
  4618. typeOptions.crosshairY.enabled =
  4619. typeOptions.crosshairY.strokeWidth !== 0;
  4620. typeOptions.crosshairX.enabled =
  4621. typeOptions.crosshairX.strokeWidth !== 0;
  4622. }
  4623. annotation.update(config);
  4624. }
  4625. }
  4626. });
  4627. }
  4628. else {
  4629. // Deselect current:
  4630. fireEvent(navigation, 'closePopup');
  4631. }
  4632. // Let bubble event to chart.click:
  4633. eventArguments.activeAnnotation = true;
  4634. }
  4635. merge(true, annotationType.prototype.defaultOptions.events, {
  4636. click: selectAndShowPopup
  4637. });
  4638. }
  4639. if (H.Annotation) {
  4640. // Basic shapes:
  4641. selectableAnnotation(Annotation);
  4642. // Advanced annotations:
  4643. objectEach(Annotation.types, function (annotationType) {
  4644. selectableAnnotation(annotationType);
  4645. });
  4646. }
  4647. setOptions({
  4648. /**
  4649. * @optionparent lang
  4650. *
  4651. * @private
  4652. */
  4653. lang: {
  4654. /**
  4655. * Configure the Popup strings in the chart. Requires the
  4656. * `annotations.js` or `annotations-advanced.src.js` module to be
  4657. * loaded.
  4658. *
  4659. * @since 7.0.0
  4660. * @product highcharts highstock
  4661. */
  4662. navigation: {
  4663. /**
  4664. * Translations for all field names used in popup.
  4665. *
  4666. * @product highcharts highstock
  4667. */
  4668. popup: {
  4669. simpleShapes: 'Simple shapes',
  4670. lines: 'Lines',
  4671. circle: 'Circle',
  4672. rectangle: 'Rectangle',
  4673. label: 'Label',
  4674. shapeOptions: 'Shape options',
  4675. typeOptions: 'Details',
  4676. fill: 'Fill',
  4677. format: 'Text',
  4678. strokeWidth: 'Line width',
  4679. stroke: 'Line color',
  4680. title: 'Title',
  4681. name: 'Name',
  4682. labelOptions: 'Label options',
  4683. labels: 'Labels',
  4684. backgroundColor: 'Background color',
  4685. backgroundColors: 'Background colors',
  4686. borderColor: 'Border color',
  4687. borderRadius: 'Border radius',
  4688. borderWidth: 'Border width',
  4689. style: 'Style',
  4690. padding: 'Padding',
  4691. fontSize: 'Font size',
  4692. color: 'Color',
  4693. height: 'Height',
  4694. shapes: 'Shape options'
  4695. }
  4696. }
  4697. },
  4698. /**
  4699. * @optionparent navigation
  4700. * @product highcharts highstock
  4701. *
  4702. * @private
  4703. */
  4704. navigation: {
  4705. /**
  4706. * A CSS class name where all bindings will be attached to. Multiple
  4707. * charts on the same page should have separate class names to prevent
  4708. * duplicating events.
  4709. *
  4710. * Default value of versions < 7.0.4 `highcharts-bindings-wrapper`
  4711. *
  4712. * @since 7.0.0
  4713. * @type {string}
  4714. */
  4715. bindingsClassName: 'highcharts-bindings-container',
  4716. /**
  4717. * Bindings definitions for custom HTML buttons. Each binding implements
  4718. * simple event-driven interface:
  4719. *
  4720. * - `className`: classname used to bind event to
  4721. *
  4722. * - `init`: initial event, fired on button click
  4723. *
  4724. * - `start`: fired on first click on a chart
  4725. *
  4726. * - `steps`: array of sequential events fired one after another on each
  4727. * of users clicks
  4728. *
  4729. * - `end`: last event to be called after last step event
  4730. *
  4731. * @type {Highcharts.Dictionary<Highcharts.NavigationBindingsOptionsObject>|*}
  4732. * @sample stock/stocktools/stocktools-thresholds
  4733. * Custom bindings in Highcharts Stock
  4734. * @since 7.0.0
  4735. * @product highcharts highstock
  4736. */
  4737. bindings: {
  4738. /**
  4739. * A circle annotation bindings. Includes `start` and one event in
  4740. * `steps` array.
  4741. *
  4742. * @type {Highcharts.NavigationBindingsOptionsObject}
  4743. * @default {"className": "highcharts-circle-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4744. */
  4745. circleAnnotation: {
  4746. /** @ignore-option */
  4747. className: 'highcharts-circle-annotation',
  4748. /** @ignore-option */
  4749. start: function (e) {
  4750. var coords = this.chart.pointer.getCoordinates(e),
  4751. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  4752. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  4753. navigation = this.chart.options.navigation;
  4754. // Exit if clicked out of axes area
  4755. if (!coordsX || !coordsY) {
  4756. return;
  4757. }
  4758. return this.chart.addAnnotation(merge({
  4759. langKey: 'circle',
  4760. type: 'basicAnnotation',
  4761. shapes: [{
  4762. type: 'circle',
  4763. point: {
  4764. x: coordsX.value,
  4765. y: coordsY.value,
  4766. xAxis: coordsX.axis.options.index,
  4767. yAxis: coordsY.axis.options.index
  4768. },
  4769. r: 5
  4770. }]
  4771. }, navigation
  4772. .annotationsOptions, navigation
  4773. .bindings
  4774. .circleAnnotation
  4775. .annotationsOptions));
  4776. },
  4777. /** @ignore-option */
  4778. steps: [
  4779. function (e, annotation) {
  4780. var mockPointOpts = annotation.options.shapes[0]
  4781. .point,
  4782. inverted = this.chart.inverted,
  4783. x,
  4784. y,
  4785. distance;
  4786. if (isNumber(mockPointOpts.xAxis) &&
  4787. isNumber(mockPointOpts.yAxis)) {
  4788. x = this.chart.xAxis[mockPointOpts.xAxis]
  4789. .toPixels(mockPointOpts.x);
  4790. y = this.chart.yAxis[mockPointOpts.yAxis]
  4791. .toPixels(mockPointOpts.y);
  4792. distance = Math.max(Math.sqrt(Math.pow(inverted ? y - e.chartX : x - e.chartX, 2) +
  4793. Math.pow(inverted ? x - e.chartY : y - e.chartY, 2)), 5);
  4794. }
  4795. annotation.update({
  4796. shapes: [{
  4797. r: distance
  4798. }]
  4799. });
  4800. }
  4801. ]
  4802. },
  4803. /**
  4804. * A rectangle annotation bindings. Includes `start` and one event
  4805. * in `steps` array.
  4806. *
  4807. * @type {Highcharts.NavigationBindingsOptionsObject}
  4808. * @default {"className": "highcharts-rectangle-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4809. */
  4810. rectangleAnnotation: {
  4811. /** @ignore-option */
  4812. className: 'highcharts-rectangle-annotation',
  4813. /** @ignore-option */
  4814. start: function (e) {
  4815. var coords = this.chart.pointer.getCoordinates(e),
  4816. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  4817. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  4818. // Exit if clicked out of axes area
  4819. if (!coordsX || !coordsY) {
  4820. return;
  4821. }
  4822. var x = coordsX.value,
  4823. y = coordsY.value,
  4824. xAxis = coordsX.axis.options.index,
  4825. yAxis = coordsY.axis.options.index,
  4826. navigation = this.chart.options.navigation;
  4827. return this.chart.addAnnotation(merge({
  4828. langKey: 'rectangle',
  4829. type: 'basicAnnotation',
  4830. shapes: [{
  4831. type: 'path',
  4832. points: [
  4833. { xAxis: xAxis, yAxis: yAxis, x: x, y: y },
  4834. { xAxis: xAxis, yAxis: yAxis, x: x, y: y },
  4835. { xAxis: xAxis, yAxis: yAxis, x: x, y: y },
  4836. { xAxis: xAxis, yAxis: yAxis, x: x, y: y }
  4837. ]
  4838. }]
  4839. }, navigation
  4840. .annotationsOptions, navigation
  4841. .bindings
  4842. .rectangleAnnotation
  4843. .annotationsOptions));
  4844. },
  4845. /** @ignore-option */
  4846. steps: [
  4847. function (e, annotation) {
  4848. var points = annotation.options.shapes[0].points,
  4849. coords = this.chart.pointer.getCoordinates(e),
  4850. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  4851. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  4852. x,
  4853. y;
  4854. if (coordsX && coordsY) {
  4855. x = coordsX.value;
  4856. y = coordsY.value;
  4857. // Top right point
  4858. points[1].x = x;
  4859. // Bottom right point (cursor position)
  4860. points[2].x = x;
  4861. points[2].y = y;
  4862. // Bottom left
  4863. points[3].y = y;
  4864. annotation.update({
  4865. shapes: [{
  4866. points: points
  4867. }]
  4868. });
  4869. }
  4870. }
  4871. ]
  4872. },
  4873. /**
  4874. * A label annotation bindings. Includes `start` event only.
  4875. *
  4876. * @type {Highcharts.NavigationBindingsOptionsObject}
  4877. * @default {"className": "highcharts-label-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4878. */
  4879. labelAnnotation: {
  4880. /** @ignore-option */
  4881. className: 'highcharts-label-annotation',
  4882. /** @ignore-option */
  4883. start: function (e) {
  4884. var coords = this.chart.pointer.getCoordinates(e),
  4885. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  4886. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  4887. navigation = this.chart.options.navigation;
  4888. // Exit if clicked out of axes area
  4889. if (!coordsX || !coordsY) {
  4890. return;
  4891. }
  4892. return this.chart.addAnnotation(merge({
  4893. langKey: 'label',
  4894. type: 'basicAnnotation',
  4895. labelOptions: {
  4896. format: '{y:.2f}'
  4897. },
  4898. labels: [{
  4899. point: {
  4900. xAxis: coordsX.axis.options.index,
  4901. yAxis: coordsY.axis.options.index,
  4902. x: coordsX.value,
  4903. y: coordsY.value
  4904. },
  4905. overflow: 'none',
  4906. crop: true
  4907. }]
  4908. }, navigation
  4909. .annotationsOptions, navigation
  4910. .bindings
  4911. .labelAnnotation
  4912. .annotationsOptions));
  4913. }
  4914. }
  4915. },
  4916. /**
  4917. * Path where Highcharts will look for icons. Change this to use icons
  4918. * from a different server.
  4919. *
  4920. * @type {string}
  4921. * @default https://code.highcharts.com/9.1.1/gfx/stock-icons/
  4922. * @since 7.1.3
  4923. * @apioption navigation.iconsURL
  4924. */
  4925. /**
  4926. * A `showPopup` event. Fired when selecting for example an annotation.
  4927. *
  4928. * @type {Function}
  4929. * @apioption navigation.events.showPopup
  4930. */
  4931. /**
  4932. * A `closePopup` event. Fired when Popup should be hidden, for example
  4933. * when clicking on an annotation again.
  4934. *
  4935. * @type {Function}
  4936. * @apioption navigation.events.closePopup
  4937. */
  4938. /**
  4939. * Event fired on a button click.
  4940. *
  4941. * @type {Function}
  4942. * @sample highcharts/annotations/gui/
  4943. * Change icon in a dropddown on event
  4944. * @sample highcharts/annotations/gui-buttons/
  4945. * Change button class on event
  4946. * @apioption navigation.events.selectButton
  4947. */
  4948. /**
  4949. * Event fired when button state should change, for example after
  4950. * adding an annotation.
  4951. *
  4952. * @type {Function}
  4953. * @sample highcharts/annotations/gui/
  4954. * Change icon in a dropddown on event
  4955. * @sample highcharts/annotations/gui-buttons/
  4956. * Change button class on event
  4957. * @apioption navigation.events.deselectButton
  4958. */
  4959. /**
  4960. * Events to communicate between Stock Tools and custom GUI.
  4961. *
  4962. * @since 7.0.0
  4963. * @product highcharts highstock
  4964. * @optionparent navigation.events
  4965. */
  4966. events: {},
  4967. /**
  4968. * Additional options to be merged into all annotations.
  4969. *
  4970. * @sample stock/stocktools/navigation-annotation-options
  4971. * Set red color of all line annotations
  4972. *
  4973. * @type {Highcharts.AnnotationsOptions}
  4974. * @extends annotations
  4975. * @exclude crookedLine, elliottWave, fibonacci, infinityLine,
  4976. * measure, pitchfork, tunnel, verticalLine, basicAnnotation
  4977. * @apioption navigation.annotationsOptions
  4978. */
  4979. annotationsOptions: {
  4980. animation: {
  4981. defer: 0
  4982. }
  4983. }
  4984. }
  4985. });
  4986. addEvent(Chart, 'render', function () {
  4987. var chart = this,
  4988. navigationBindings = chart.navigationBindings,
  4989. disabledClassName = 'highcharts-disabled-btn';
  4990. if (chart && navigationBindings) {
  4991. // Check if the buttons should be enabled/disabled based on
  4992. // visible series.
  4993. var buttonsEnabled_1 = false;
  4994. chart.series.forEach(function (series) {
  4995. if (!series.options.isInternal && series.visible) {
  4996. buttonsEnabled_1 = true;
  4997. }
  4998. });
  4999. objectEach(navigationBindings.boundClassNames, function (value, key) {
  5000. if (chart.navigationBindings &&
  5001. chart.navigationBindings.container &&
  5002. chart.navigationBindings.container[0]) {
  5003. // Get the HTML element coresponding to the
  5004. // className taken from StockToolsBindings.
  5005. var buttonNode = chart.navigationBindings.container[0].querySelectorAll('.' + key);
  5006. if (buttonNode) {
  5007. if (value.noDataState === 'normal') {
  5008. buttonNode.forEach(function (button) {
  5009. // If button has noDataState: 'normal',
  5010. // and has disabledClassName,
  5011. // remove this className.
  5012. if (button.className.indexOf(disabledClassName) !== -1) {
  5013. button.classList.remove(disabledClassName);
  5014. }
  5015. });
  5016. }
  5017. else if (!buttonsEnabled_1) {
  5018. buttonNode.forEach(function (button) {
  5019. if (button.className.indexOf(disabledClassName) === -1) {
  5020. button.className += ' ' + disabledClassName;
  5021. }
  5022. });
  5023. }
  5024. else {
  5025. buttonNode.forEach(function (button) {
  5026. // Enable all buttons by deleting the className.
  5027. if (button.className.indexOf(disabledClassName) !== -1) {
  5028. button.classList.remove(disabledClassName);
  5029. }
  5030. });
  5031. }
  5032. }
  5033. }
  5034. });
  5035. }
  5036. });
  5037. addEvent(NavigationBindings, 'closePopup', function () {
  5038. this.deselectAnnotation();
  5039. });
  5040. return NavigationBindings;
  5041. });
  5042. _registerModule(_modules, 'Stock/StockToolsBindings.js', [_modules['Core/Globals.js'], _modules['Extensions/Annotations/NavigationBindings.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Series/Series.js'], _modules['Core/Utilities.js'], _modules['Core/Color/Palette.js']], function (H, NavigationBindings, D, Series, U, palette) {
  5043. /**
  5044. *
  5045. * Events generator for Stock tools
  5046. *
  5047. * (c) 2009-2021 Paweł Fus
  5048. *
  5049. * License: www.highcharts.com/license
  5050. *
  5051. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5052. *
  5053. * */
  5054. var getOptions = D.getOptions,
  5055. setOptions = D.setOptions;
  5056. var correctFloat = U.correctFloat,
  5057. defined = U.defined,
  5058. extend = U.extend,
  5059. fireEvent = U.fireEvent,
  5060. isNumber = U.isNumber,
  5061. merge = U.merge,
  5062. pick = U.pick,
  5063. uniqueKey = U.uniqueKey;
  5064. var bindingsUtils = NavigationBindings.prototype.utils,
  5065. PREFIX = 'highcharts-';
  5066. /* eslint-disable no-invalid-this, valid-jsdoc */
  5067. /**
  5068. * Generates function which will add a flag series using modal in GUI.
  5069. * Method fires an event "showPopup" with config:
  5070. * `{type, options, callback}`.
  5071. *
  5072. * Example: NavigationBindings.utils.addFlagFromForm('url(...)') - will
  5073. * generate function that shows modal in GUI.
  5074. *
  5075. * @private
  5076. * @function bindingsUtils.addFlagFromForm
  5077. *
  5078. * @param {Highcharts.FlagsShapeValue} type
  5079. * Type of flag series, e.g. "squarepin"
  5080. *
  5081. * @return {Function}
  5082. * Callback to be used in `start` callback
  5083. */
  5084. bindingsUtils.addFlagFromForm = function (type) {
  5085. return function (e) {
  5086. var navigation = this,
  5087. chart = navigation.chart,
  5088. toolbar = chart.stockTools,
  5089. getFieldType = bindingsUtils.getFieldType,
  5090. point = bindingsUtils.attractToPoint(e,
  5091. chart),
  5092. pointConfig,
  5093. seriesOptions;
  5094. if (!point) {
  5095. return;
  5096. }
  5097. pointConfig = {
  5098. x: point.x,
  5099. y: point.y
  5100. };
  5101. seriesOptions = {
  5102. type: 'flags',
  5103. onSeries: point.series.id,
  5104. shape: type,
  5105. data: [pointConfig],
  5106. xAxis: point.xAxis,
  5107. yAxis: point.yAxis,
  5108. point: {
  5109. events: {
  5110. click: function () {
  5111. var point = this,
  5112. options = point.options;
  5113. fireEvent(navigation, 'showPopup', {
  5114. point: point,
  5115. formType: 'annotation-toolbar',
  5116. options: {
  5117. langKey: 'flags',
  5118. type: 'flags',
  5119. title: [
  5120. options.title,
  5121. getFieldType(options.title)
  5122. ],
  5123. name: [
  5124. options.name,
  5125. getFieldType(options.name)
  5126. ]
  5127. },
  5128. onSubmit: function (updated) {
  5129. if (updated.actionType === 'remove') {
  5130. point.remove();
  5131. }
  5132. else {
  5133. point.update(navigation.fieldsToOptions(updated.fields, {}));
  5134. }
  5135. }
  5136. });
  5137. }
  5138. }
  5139. }
  5140. };
  5141. if (!toolbar || !toolbar.guiEnabled) {
  5142. chart.addSeries(seriesOptions);
  5143. }
  5144. fireEvent(navigation, 'showPopup', {
  5145. formType: 'flag',
  5146. // Enabled options:
  5147. options: {
  5148. langKey: 'flags',
  5149. type: 'flags',
  5150. title: ['A', getFieldType('A')],
  5151. name: ['Flag A', getFieldType('Flag A')]
  5152. },
  5153. // Callback on submit:
  5154. onSubmit: function (data) {
  5155. navigation.fieldsToOptions(data.fields, seriesOptions.data[0]);
  5156. chart.addSeries(seriesOptions);
  5157. }
  5158. });
  5159. };
  5160. };
  5161. bindingsUtils.manageIndicators = function (data) {
  5162. var navigation = this,
  5163. chart = navigation.chart,
  5164. seriesConfig = {
  5165. linkedTo: data.linkedTo,
  5166. type: data.type
  5167. },
  5168. indicatorsWithVolume = [
  5169. 'ad',
  5170. 'cmf',
  5171. 'klinger',
  5172. 'mfi',
  5173. 'obv',
  5174. 'vbp',
  5175. 'vwap'
  5176. ],
  5177. indicatorsWithAxes = [
  5178. 'ad',
  5179. 'atr',
  5180. 'cci',
  5181. 'cmf',
  5182. 'disparityindex',
  5183. 'cmo',
  5184. 'dmi',
  5185. 'macd',
  5186. 'mfi',
  5187. 'roc',
  5188. 'rsi',
  5189. 'ao',
  5190. 'aroon',
  5191. 'aroonoscillator',
  5192. 'trix',
  5193. 'apo',
  5194. 'dpo',
  5195. 'ppo',
  5196. 'natr',
  5197. 'obv',
  5198. 'williamsr',
  5199. 'stochastic',
  5200. 'slowstochastic',
  5201. 'linearRegression',
  5202. 'linearRegressionSlope',
  5203. 'linearRegressionIntercept',
  5204. 'linearRegressionAngle',
  5205. 'klinger'
  5206. ],
  5207. yAxis,
  5208. parentSeries,
  5209. defaultOptions,
  5210. series;
  5211. if (data.actionType === 'edit') {
  5212. navigation.fieldsToOptions(data.fields, seriesConfig);
  5213. series = chart.get(data.seriesId);
  5214. if (series) {
  5215. series.update(seriesConfig, false);
  5216. }
  5217. }
  5218. else if (data.actionType === 'remove') {
  5219. series = chart.get(data.seriesId);
  5220. if (series) {
  5221. yAxis = series.yAxis;
  5222. if (series.linkedSeries) {
  5223. series.linkedSeries.forEach(function (linkedSeries) {
  5224. linkedSeries.remove(false);
  5225. });
  5226. }
  5227. series.remove(false);
  5228. if (indicatorsWithAxes.indexOf(series.type) >= 0) {
  5229. var removedYAxisHeight = yAxis.options.height;
  5230. yAxis.remove(false);
  5231. navigation.resizeYAxes(removedYAxisHeight);
  5232. }
  5233. }
  5234. }
  5235. else {
  5236. seriesConfig.id = uniqueKey();
  5237. navigation.fieldsToOptions(data.fields, seriesConfig);
  5238. parentSeries = chart.get(seriesConfig.linkedTo);
  5239. defaultOptions = getOptions().plotOptions;
  5240. // Make sure that indicator uses the SUM approx if SUM approx is used
  5241. // by parent series (#13950).
  5242. if (typeof parentSeries !== 'undefined' &&
  5243. parentSeries instanceof Series &&
  5244. parentSeries.getDGApproximation() === 'sum' &&
  5245. // If indicator has defined approx type, use it (e.g. "ranges")
  5246. !defined(defaultOptions && defaultOptions[seriesConfig.type] &&
  5247. defaultOptions.dataGrouping &&
  5248. defaultOptions.dataGrouping.approximation)) {
  5249. seriesConfig.dataGrouping = {
  5250. approximation: 'sum'
  5251. };
  5252. }
  5253. if (indicatorsWithAxes.indexOf(data.type) >= 0) {
  5254. yAxis = chart.addAxis({
  5255. id: uniqueKey(),
  5256. offset: 0,
  5257. opposite: true,
  5258. title: {
  5259. text: ''
  5260. },
  5261. tickPixelInterval: 40,
  5262. showLastLabel: false,
  5263. labels: {
  5264. align: 'left',
  5265. y: -2
  5266. }
  5267. }, false, false);
  5268. seriesConfig.yAxis = yAxis.options.id;
  5269. navigation.resizeYAxes();
  5270. }
  5271. else {
  5272. seriesConfig.yAxis = chart.get(data.linkedTo).options.yAxis;
  5273. }
  5274. if (indicatorsWithVolume.indexOf(data.type) >= 0) {
  5275. seriesConfig.params.volumeSeriesID = chart.series.filter(function (series) {
  5276. return series.options.type === 'column';
  5277. })[0].options.id;
  5278. }
  5279. chart.addSeries(seriesConfig, false);
  5280. }
  5281. fireEvent(navigation, 'deselectButton', {
  5282. button: navigation.selectedButtonElement
  5283. });
  5284. chart.redraw();
  5285. };
  5286. /**
  5287. * Update height for an annotation. Height is calculated as a difference
  5288. * between last point in `typeOptions` and current position. It's a value,
  5289. * not pixels height.
  5290. *
  5291. * @private
  5292. * @function bindingsUtils.updateHeight
  5293. *
  5294. * @param {Highcharts.PointerEventObject} e
  5295. * normalized browser event
  5296. *
  5297. * @param {Highcharts.Annotation} annotation
  5298. * Annotation to be updated
  5299. *
  5300. * @return {void}
  5301. */
  5302. bindingsUtils.updateHeight = function (e, annotation) {
  5303. var coordsY = this.utils.getAssignedAxis(this.chart.pointer.getCoordinates(e).yAxis);
  5304. if (coordsY) {
  5305. annotation.update({
  5306. typeOptions: {
  5307. height: coordsY.value -
  5308. annotation.options.typeOptions.points[1].y
  5309. }
  5310. });
  5311. }
  5312. };
  5313. // @todo
  5314. // Consider using getHoverData(), but always kdTree (columns?)
  5315. bindingsUtils.attractToPoint = function (e, chart) {
  5316. var coords = chart.pointer.getCoordinates(e),
  5317. coordsX,
  5318. coordsY,
  5319. distX = Number.MAX_VALUE,
  5320. closestPoint,
  5321. x,
  5322. y;
  5323. if (chart.navigationBindings) {
  5324. coordsX = chart.navigationBindings.utils.getAssignedAxis(coords.xAxis);
  5325. coordsY = chart.navigationBindings.utils.getAssignedAxis(coords.yAxis);
  5326. }
  5327. // Exit if clicked out of axes area.
  5328. if (!coordsX || !coordsY) {
  5329. return;
  5330. }
  5331. x = coordsX.value;
  5332. y = coordsY.value;
  5333. // Search by 'x' but only in yAxis' series.
  5334. coordsY.axis.series.forEach(function (series) {
  5335. if (series.points) {
  5336. series.points.forEach(function (point) {
  5337. if (point && distX > Math.abs(point.x - x)) {
  5338. distX = Math.abs(point.x - x);
  5339. closestPoint = point;
  5340. }
  5341. });
  5342. }
  5343. });
  5344. if (closestPoint && closestPoint.x && closestPoint.y) {
  5345. return {
  5346. x: closestPoint.x,
  5347. y: closestPoint.y,
  5348. below: y < closestPoint.y,
  5349. series: closestPoint.series,
  5350. xAxis: closestPoint.series.xAxis.options.index || 0,
  5351. yAxis: closestPoint.series.yAxis.options.index || 0
  5352. };
  5353. }
  5354. };
  5355. /**
  5356. * Shorthand to check if given yAxis comes from navigator.
  5357. *
  5358. * @private
  5359. * @function bindingsUtils.isNotNavigatorYAxis
  5360. *
  5361. * @param {Highcharts.Axis} axis
  5362. * Axis to check.
  5363. *
  5364. * @return {boolean}
  5365. * True, if axis comes from navigator.
  5366. */
  5367. bindingsUtils.isNotNavigatorYAxis = function (axis) {
  5368. return axis.userOptions.className !== PREFIX + 'navigator-yaxis';
  5369. };
  5370. /**
  5371. * Check if any of the price indicators are enabled.
  5372. * @private
  5373. * @function bindingsUtils.isLastPriceEnabled
  5374. *
  5375. * @param {array} series
  5376. * Array of series.
  5377. *
  5378. * @return {boolean}
  5379. * Tells which indicator is enabled.
  5380. */
  5381. bindingsUtils.isPriceIndicatorEnabled = function (series) {
  5382. return series.some(function (s) { return s.lastVisiblePrice || s.lastPrice; });
  5383. };
  5384. /**
  5385. * Update each point after specified index, most of the annotations use
  5386. * this. For example crooked line: logic behind updating each point is the
  5387. * same, only index changes when adding an annotation.
  5388. *
  5389. * Example: NavigationBindings.utils.updateNthPoint(1) - will generate
  5390. * function that updates all consecutive points except point with index=0.
  5391. *
  5392. * @private
  5393. * @function bindingsUtils.updateNthPoint
  5394. *
  5395. * @param {number} startIndex
  5396. * Index from each point should udpated
  5397. *
  5398. * @return {Function}
  5399. * Callback to be used in steps array
  5400. */
  5401. bindingsUtils.updateNthPoint = function (startIndex) {
  5402. return function (e, annotation) {
  5403. var options = annotation.options.typeOptions,
  5404. coords = this.chart.pointer.getCoordinates(e),
  5405. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5406. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  5407. if (coordsX && coordsY) {
  5408. options.points.forEach(function (point, index) {
  5409. if (index >= startIndex) {
  5410. point.x = coordsX.value;
  5411. point.y = coordsY.value;
  5412. }
  5413. });
  5414. annotation.update({
  5415. typeOptions: {
  5416. points: options.points
  5417. }
  5418. });
  5419. }
  5420. };
  5421. };
  5422. // Extends NavigationBindigs to support indicators and resizers:
  5423. extend(NavigationBindings.prototype, {
  5424. /* eslint-disable valid-jsdoc */
  5425. /**
  5426. * Get current positions for all yAxes. If new axis does not have position,
  5427. * returned is default height and last available top place.
  5428. *
  5429. * @private
  5430. * @function Highcharts.NavigationBindings#getYAxisPositions
  5431. *
  5432. * @param {Array<Highcharts.Axis>} yAxes
  5433. * Array of yAxes available in the chart.
  5434. *
  5435. * @param {number} plotHeight
  5436. * Available height in the chart.
  5437. *
  5438. * @param {number} defaultHeight
  5439. * Default height in percents.
  5440. *
  5441. * @param {string} removedYAxisHeight
  5442. * Height of the removed yAxis in percents.
  5443. *
  5444. * @return {Highcharts.YAxisPositions}
  5445. * An object containing an array of calculated positions
  5446. * in percentages. Format: `{top: Number, height: Number}`
  5447. * and maximum value of top + height of axes.
  5448. */
  5449. getYAxisPositions: function (yAxes, plotHeight, defaultHeight, removedYAxisHeight) {
  5450. var positions,
  5451. allAxesHeight = 0,
  5452. previousAxisHeight,
  5453. removedHeight;
  5454. /** @private */
  5455. function isPercentage(prop) {
  5456. return defined(prop) && !isNumber(prop) && prop.match('%');
  5457. }
  5458. if (removedYAxisHeight) {
  5459. removedHeight = correctFloat((parseFloat(removedYAxisHeight) / 100));
  5460. }
  5461. positions = yAxes.map(function (yAxis, index) {
  5462. var height = correctFloat(isPercentage(yAxis.options.height) ?
  5463. parseFloat(yAxis.options.height) / 100 :
  5464. yAxis.height / plotHeight),
  5465. top = correctFloat(isPercentage(yAxis.options.top) ?
  5466. parseFloat(yAxis.options.top) / 100 :
  5467. (yAxis.top - yAxis.chart.plotTop) / plotHeight);
  5468. // New axis' height is NaN so we can check if
  5469. // the axis is newly created this way
  5470. if (!removedHeight) {
  5471. if (!isNumber(height)) {
  5472. // Check if the previous axis is the
  5473. // indicator axis (every indicator inherits from sma)
  5474. height = yAxes[index - 1].series.every(function (s) { return s.is('sma'); }) ?
  5475. previousAxisHeight : defaultHeight / 100;
  5476. }
  5477. if (!isNumber(top)) {
  5478. top = allAxesHeight;
  5479. }
  5480. previousAxisHeight = height;
  5481. allAxesHeight = correctFloat(Math.max(allAxesHeight, (top || 0) + (height || 0)));
  5482. }
  5483. else {
  5484. if (top <= allAxesHeight) {
  5485. allAxesHeight = correctFloat(Math.max(allAxesHeight, (top || 0) + (height || 0)));
  5486. }
  5487. else {
  5488. top = correctFloat(top - removedHeight);
  5489. allAxesHeight = correctFloat(allAxesHeight + height);
  5490. }
  5491. }
  5492. return {
  5493. height: height * 100,
  5494. top: top * 100
  5495. };
  5496. });
  5497. return { positions: positions, allAxesHeight: allAxesHeight };
  5498. },
  5499. /**
  5500. * Get current resize options for each yAxis. Note that each resize is
  5501. * linked to the next axis, except the last one which shouldn't affect
  5502. * axes in the navigator. Because indicator can be removed with it's yAxis
  5503. * in the middle of yAxis array, we need to bind closest yAxes back.
  5504. *
  5505. * @private
  5506. * @function Highcharts.NavigationBindings#getYAxisResizers
  5507. *
  5508. * @param {Array<Highcharts.Axis>} yAxes
  5509. * Array of yAxes available in the chart
  5510. *
  5511. * @return {Array<object>}
  5512. * An array of resizer options.
  5513. * Format: `{enabled: Boolean, controlledAxis: { next: [String]}}`
  5514. */
  5515. getYAxisResizers: function (yAxes) {
  5516. var resizers = [];
  5517. yAxes.forEach(function (_yAxis, index) {
  5518. var nextYAxis = yAxes[index + 1];
  5519. // We have next axis, bind them:
  5520. if (nextYAxis) {
  5521. resizers[index] = {
  5522. enabled: true,
  5523. controlledAxis: {
  5524. next: [
  5525. pick(nextYAxis.options.id, nextYAxis.options.index)
  5526. ]
  5527. }
  5528. };
  5529. }
  5530. else {
  5531. // Remove binding:
  5532. resizers[index] = {
  5533. enabled: false
  5534. };
  5535. }
  5536. });
  5537. return resizers;
  5538. },
  5539. /**
  5540. * Resize all yAxes (except navigator) to fit the plotting height. Method
  5541. * checks if new axis is added, if the new axis will fit under previous
  5542. * axes it is placed there. If not, current plot area is scaled
  5543. * to make room for new axis.
  5544. *
  5545. * If axis is removed, the current plot area streaches to fit into 100%
  5546. * of the plot area.
  5547. *
  5548. * @private
  5549. * @function Highcharts.NavigationBindings#resizeYAxes
  5550. * @param {string} [removedYAxisHeight]
  5551. *
  5552. *
  5553. */
  5554. resizeYAxes: function (removedYAxisHeight) {
  5555. // The height of the new axis before rescalling. In %, but as a number.
  5556. var defaultHeight = 20;
  5557. var chart = this.chart,
  5558. // Only non-navigator axes
  5559. yAxes = chart.yAxis.filter(bindingsUtils.isNotNavigatorYAxis),
  5560. plotHeight = chart.plotHeight,
  5561. // Gather current heights (in %)
  5562. _a = this.getYAxisPositions(yAxes,
  5563. plotHeight,
  5564. defaultHeight,
  5565. removedYAxisHeight),
  5566. positions = _a.positions,
  5567. allAxesHeight = _a.allAxesHeight,
  5568. resizers = this.getYAxisResizers(yAxes);
  5569. // check if the axis is being either added or removed and
  5570. // if the new indicator axis will fit under existing axes.
  5571. // if so, there is no need to scale them.
  5572. if (!removedYAxisHeight &&
  5573. allAxesHeight <= correctFloat(0.8 + defaultHeight / 100)) {
  5574. positions[positions.length - 1] = {
  5575. height: defaultHeight,
  5576. top: correctFloat(allAxesHeight * 100 - defaultHeight)
  5577. };
  5578. }
  5579. else {
  5580. positions.forEach(function (position) {
  5581. position.height = (position.height / (allAxesHeight * 100)) * 100;
  5582. position.top = (position.top / (allAxesHeight * 100)) * 100;
  5583. });
  5584. }
  5585. positions.forEach(function (position, index) {
  5586. yAxes[index].update({
  5587. height: position.height + '%',
  5588. top: position.top + '%',
  5589. resize: resizers[index],
  5590. offset: 0
  5591. }, false);
  5592. });
  5593. },
  5594. /**
  5595. * Utility to modify calculated positions according to the remaining/needed
  5596. * space. Later, these positions are used in `yAxis.update({ top, height })`
  5597. *
  5598. * @private
  5599. * @function Highcharts.NavigationBindings#recalculateYAxisPositions
  5600. * @param {Array<Highcharts.Dictionary<number>>} positions
  5601. * Default positions of all yAxes.
  5602. * @param {number} changedSpace
  5603. * How much space should be added or removed.
  5604. * @param {boolean} modifyHeight
  5605. * Update only `top` or both `top` and `height`.
  5606. * @param {number} adder
  5607. * `-1` or `1`, to determine whether we should add or remove space.
  5608. *
  5609. * @return {Array<object>}
  5610. * Modified positions,
  5611. */
  5612. recalculateYAxisPositions: function (positions, changedSpace, modifyHeight, adder) {
  5613. positions.forEach(function (position, index) {
  5614. var prevPosition = positions[index - 1];
  5615. position.top = !prevPosition ? 0 :
  5616. correctFloat(prevPosition.height + prevPosition.top);
  5617. if (modifyHeight) {
  5618. position.height = correctFloat(position.height + adder * changedSpace);
  5619. }
  5620. });
  5621. return positions;
  5622. }
  5623. /* eslint-enable valid-jsdoc */
  5624. });
  5625. /**
  5626. * @type {Highcharts.Dictionary<Highcharts.NavigationBindingsOptionsObject>}
  5627. * @since 7.0.0
  5628. * @optionparent navigation.bindings
  5629. */
  5630. var stockToolsBindings = {
  5631. // Line type annotations:
  5632. /**
  5633. * A segment annotation bindings. Includes `start` and one event in `steps`
  5634. * array.
  5635. *
  5636. * @type {Highcharts.NavigationBindingsOptionsObject}
  5637. * @product highstock
  5638. * @default {"className": "highcharts-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5639. */
  5640. segment: {
  5641. /** @ignore-option */
  5642. className: 'highcharts-segment',
  5643. // eslint-disable-next-line valid-jsdoc
  5644. /** @ignore-option */
  5645. start: function (e) {
  5646. var coords = this.chart.pointer.getCoordinates(e), coordsX = this.utils.getAssignedAxis(coords.xAxis), coordsY = this.utils.getAssignedAxis(coords.yAxis), navigation = this.chart.options.navigation, options;
  5647. // Exit if clicked out of axes area
  5648. if (!coordsX || !coordsY) {
  5649. return;
  5650. }
  5651. options = merge({
  5652. langKey: 'segment',
  5653. type: 'crookedLine',
  5654. typeOptions: {
  5655. xAxis: coordsX.axis.options.index,
  5656. yAxis: coordsY.axis.options.index,
  5657. points: [{
  5658. x: coordsX.value,
  5659. y: coordsY.value
  5660. }, {
  5661. x: coordsX.value,
  5662. y: coordsY.value
  5663. }]
  5664. }
  5665. }, navigation.annotationsOptions, navigation.bindings.segment.annotationsOptions);
  5666. return this.chart.addAnnotation(options);
  5667. },
  5668. /** @ignore-option */
  5669. steps: [
  5670. bindingsUtils.updateNthPoint(1)
  5671. ]
  5672. },
  5673. /**
  5674. * A segment with an arrow annotation bindings. Includes `start` and one
  5675. * event in `steps` array.
  5676. *
  5677. * @type {Highcharts.NavigationBindingsOptionsObject}
  5678. * @product highstock
  5679. * @default {"className": "highcharts-arrow-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5680. */
  5681. arrowSegment: {
  5682. /** @ignore-option */
  5683. className: 'highcharts-arrow-segment',
  5684. // eslint-disable-next-line valid-jsdoc
  5685. /** @ignore-option */
  5686. start: function (e) {
  5687. var coords = this.chart.pointer.getCoordinates(e),
  5688. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5689. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5690. navigation = this.chart.options.navigation,
  5691. options;
  5692. // Exit if clicked out of axes area
  5693. if (!coordsX || !coordsY) {
  5694. return;
  5695. }
  5696. options = merge({
  5697. langKey: 'arrowSegment',
  5698. type: 'crookedLine',
  5699. typeOptions: {
  5700. line: {
  5701. markerEnd: 'arrow'
  5702. },
  5703. xAxis: coordsX.axis.options.index,
  5704. yAxis: coordsY.axis.options.index,
  5705. points: [{
  5706. x: coordsX.value,
  5707. y: coordsY.value
  5708. }, {
  5709. x: coordsX.value,
  5710. y: coordsY.value
  5711. }]
  5712. }
  5713. }, navigation.annotationsOptions, navigation.bindings.arrowSegment.annotationsOptions);
  5714. return this.chart.addAnnotation(options);
  5715. },
  5716. /** @ignore-option */
  5717. steps: [
  5718. bindingsUtils.updateNthPoint(1)
  5719. ]
  5720. },
  5721. /**
  5722. * A ray annotation bindings. Includes `start` and one event in `steps`
  5723. * array.
  5724. *
  5725. * @type {Highcharts.NavigationBindingsOptionsObject}
  5726. * @product highstock
  5727. * @default {"className": "highcharts-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5728. */
  5729. ray: {
  5730. /** @ignore-option */
  5731. className: 'highcharts-ray',
  5732. // eslint-disable-next-line valid-jsdoc
  5733. /** @ignore-option */
  5734. start: function (e) {
  5735. var coords = this.chart.pointer.getCoordinates(e),
  5736. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5737. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5738. navigation = this.chart.options.navigation,
  5739. options;
  5740. // Exit if clicked out of axes area
  5741. if (!coordsX || !coordsY) {
  5742. return;
  5743. }
  5744. options = merge({
  5745. langKey: 'ray',
  5746. type: 'infinityLine',
  5747. typeOptions: {
  5748. type: 'ray',
  5749. xAxis: coordsX.axis.options.index,
  5750. yAxis: coordsY.axis.options.index,
  5751. points: [{
  5752. x: coordsX.value,
  5753. y: coordsY.value
  5754. }, {
  5755. x: coordsX.value,
  5756. y: coordsY.value
  5757. }]
  5758. }
  5759. }, navigation.annotationsOptions, navigation.bindings.ray.annotationsOptions);
  5760. return this.chart.addAnnotation(options);
  5761. },
  5762. /** @ignore-option */
  5763. steps: [
  5764. bindingsUtils.updateNthPoint(1)
  5765. ]
  5766. },
  5767. /**
  5768. * A ray with an arrow annotation bindings. Includes `start` and one event
  5769. * in `steps` array.
  5770. *
  5771. * @type {Highcharts.NavigationBindingsOptionsObject}
  5772. * @product highstock
  5773. * @default {"className": "highcharts-arrow-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5774. */
  5775. arrowRay: {
  5776. /** @ignore-option */
  5777. className: 'highcharts-arrow-ray',
  5778. // eslint-disable-next-line valid-jsdoc
  5779. /** @ignore-option */
  5780. start: function (e) {
  5781. var coords = this.chart.pointer.getCoordinates(e),
  5782. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5783. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5784. navigation = this.chart.options.navigation,
  5785. options;
  5786. // Exit if clicked out of axes area
  5787. if (!coordsX || !coordsY) {
  5788. return;
  5789. }
  5790. options = merge({
  5791. langKey: 'arrowRay',
  5792. type: 'infinityLine',
  5793. typeOptions: {
  5794. type: 'ray',
  5795. line: {
  5796. markerEnd: 'arrow'
  5797. },
  5798. xAxis: coordsX.axis.options.index,
  5799. yAxis: coordsY.axis.options.index,
  5800. points: [{
  5801. x: coordsX.value,
  5802. y: coordsY.value
  5803. }, {
  5804. x: coordsX.value,
  5805. y: coordsY.value
  5806. }]
  5807. }
  5808. }, navigation.annotationsOptions, navigation.bindings.arrowRay.annotationsOptions);
  5809. return this.chart.addAnnotation(options);
  5810. },
  5811. /** @ignore-option */
  5812. steps: [
  5813. bindingsUtils.updateNthPoint(1)
  5814. ]
  5815. },
  5816. /**
  5817. * A line annotation. Includes `start` and one event in `steps` array.
  5818. *
  5819. * @type {Highcharts.NavigationBindingsOptionsObject}
  5820. * @product highstock
  5821. * @default {"className": "highcharts-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5822. */
  5823. infinityLine: {
  5824. /** @ignore-option */
  5825. className: 'highcharts-infinity-line',
  5826. // eslint-disable-next-line valid-jsdoc
  5827. /** @ignore-option */
  5828. start: function (e) {
  5829. var coords = this.chart.pointer.getCoordinates(e),
  5830. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5831. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5832. navigation = this.chart.options.navigation,
  5833. options;
  5834. // Exit if clicked out of axes area
  5835. if (!coordsX || !coordsY) {
  5836. return;
  5837. }
  5838. options = merge({
  5839. langKey: 'infinityLine',
  5840. type: 'infinityLine',
  5841. typeOptions: {
  5842. type: 'line',
  5843. xAxis: coordsX.axis.options.index,
  5844. yAxis: coordsY.axis.options.index,
  5845. points: [{
  5846. x: coordsX.value,
  5847. y: coordsY.value
  5848. }, {
  5849. x: coordsX.value,
  5850. y: coordsY.value
  5851. }]
  5852. }
  5853. }, navigation.annotationsOptions, navigation.bindings.infinityLine.annotationsOptions);
  5854. return this.chart.addAnnotation(options);
  5855. },
  5856. /** @ignore-option */
  5857. steps: [
  5858. bindingsUtils.updateNthPoint(1)
  5859. ]
  5860. },
  5861. /**
  5862. * A line with arrow annotation. Includes `start` and one event in `steps`
  5863. * array.
  5864. *
  5865. * @type {Highcharts.NavigationBindingsOptionsObject}
  5866. * @product highstock
  5867. * @default {"className": "highcharts-arrow-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5868. */
  5869. arrowInfinityLine: {
  5870. /** @ignore-option */
  5871. className: 'highcharts-arrow-infinity-line',
  5872. // eslint-disable-next-line valid-jsdoc
  5873. /** @ignore-option */
  5874. start: function (e) {
  5875. var coords = this.chart.pointer.getCoordinates(e),
  5876. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5877. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5878. navigation = this.chart.options.navigation,
  5879. options;
  5880. // Exit if clicked out of axes area
  5881. if (!coordsX || !coordsY) {
  5882. return;
  5883. }
  5884. options = merge({
  5885. langKey: 'arrowInfinityLine',
  5886. type: 'infinityLine',
  5887. typeOptions: {
  5888. type: 'line',
  5889. line: {
  5890. markerEnd: 'arrow'
  5891. },
  5892. xAxis: coordsX.axis.options.index,
  5893. yAxis: coordsY.axis.options.index,
  5894. points: [{
  5895. x: coordsX.value,
  5896. y: coordsY.value
  5897. }, {
  5898. x: coordsX.value,
  5899. y: coordsY.value
  5900. }]
  5901. }
  5902. }, navigation.annotationsOptions, navigation.bindings.arrowInfinityLine.annotationsOptions);
  5903. return this.chart.addAnnotation(options);
  5904. },
  5905. /** @ignore-option */
  5906. steps: [
  5907. bindingsUtils.updateNthPoint(1)
  5908. ]
  5909. },
  5910. /**
  5911. * A horizontal line annotation. Includes `start` event.
  5912. *
  5913. * @type {Highcharts.NavigationBindingsOptionsObject}
  5914. * @product highstock
  5915. * @default {"className": "highcharts-horizontal-line", "start": function() {}, "annotationsOptions": {}}
  5916. */
  5917. horizontalLine: {
  5918. /** @ignore-option */
  5919. className: 'highcharts-horizontal-line',
  5920. // eslint-disable-next-line valid-jsdoc
  5921. /** @ignore-option */
  5922. start: function (e) {
  5923. var coords = this.chart.pointer.getCoordinates(e),
  5924. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5925. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5926. navigation = this.chart.options.navigation,
  5927. options;
  5928. // Exit if clicked out of axes area
  5929. if (!coordsX || !coordsY) {
  5930. return;
  5931. }
  5932. options = merge({
  5933. langKey: 'horizontalLine',
  5934. type: 'infinityLine',
  5935. draggable: 'y',
  5936. typeOptions: {
  5937. type: 'horizontalLine',
  5938. xAxis: coordsX.axis.options.index,
  5939. yAxis: coordsY.axis.options.index,
  5940. points: [{
  5941. x: coordsX.value,
  5942. y: coordsY.value
  5943. }]
  5944. }
  5945. }, navigation.annotationsOptions, navigation.bindings.horizontalLine.annotationsOptions);
  5946. this.chart.addAnnotation(options);
  5947. }
  5948. },
  5949. /**
  5950. * A vertical line annotation. Includes `start` event.
  5951. *
  5952. * @type {Highcharts.NavigationBindingsOptionsObject}
  5953. * @product highstock
  5954. * @default {"className": "highcharts-vertical-line", "start": function() {}, "annotationsOptions": {}}
  5955. */
  5956. verticalLine: {
  5957. /** @ignore-option */
  5958. className: 'highcharts-vertical-line',
  5959. // eslint-disable-next-line valid-jsdoc
  5960. /** @ignore-option */
  5961. start: function (e) {
  5962. var coords = this.chart.pointer.getCoordinates(e),
  5963. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  5964. coordsY = this.utils.getAssignedAxis(coords.yAxis),
  5965. navigation = this.chart.options.navigation,
  5966. options;
  5967. // Exit if clicked out of axes area
  5968. if (!coordsX || !coordsY) {
  5969. return;
  5970. }
  5971. options = merge({
  5972. langKey: 'verticalLine',
  5973. type: 'infinityLine',
  5974. draggable: 'x',
  5975. typeOptions: {
  5976. type: 'verticalLine',
  5977. xAxis: coordsX.axis.options.index,
  5978. yAxis: coordsY.axis.options.index,
  5979. points: [{
  5980. x: coordsX.value,
  5981. y: coordsY.value
  5982. }]
  5983. }
  5984. }, navigation.annotationsOptions, navigation.bindings.verticalLine.annotationsOptions);
  5985. this.chart.addAnnotation(options);
  5986. }
  5987. },
  5988. /**
  5989. * Crooked line (three points) annotation bindings. Includes `start` and two
  5990. * events in `steps` (for second and third points in crooked line) array.
  5991. *
  5992. * @type {Highcharts.NavigationBindingsOptionsObject}
  5993. * @product highstock
  5994. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  5995. */
  5996. // Crooked Line type annotations:
  5997. crooked3: {
  5998. /** @ignore-option */
  5999. className: 'highcharts-crooked3',
  6000. // eslint-disable-next-line valid-jsdoc
  6001. /** @ignore-option */
  6002. start: function (e) {
  6003. var coords = this.chart.pointer.getCoordinates(e),
  6004. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6005. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6006. // Exit if clicked out of axes area
  6007. if (!coordsX || !coordsY) {
  6008. return;
  6009. }
  6010. var x = coordsX.value,
  6011. y = coordsY.value,
  6012. navigation = this.chart.options.navigation,
  6013. options = merge({
  6014. langKey: 'crooked3',
  6015. type: 'crookedLine',
  6016. typeOptions: {
  6017. xAxis: coordsX.axis.options.index,
  6018. yAxis: coordsY.axis.options.index,
  6019. points: [
  6020. { x: x,
  6021. y: y },
  6022. { x: x,
  6023. y: y },
  6024. { x: x,
  6025. y: y }
  6026. ]
  6027. }
  6028. },
  6029. navigation.annotationsOptions,
  6030. navigation.bindings.crooked3.annotationsOptions);
  6031. return this.chart.addAnnotation(options);
  6032. },
  6033. /** @ignore-option */
  6034. steps: [
  6035. bindingsUtils.updateNthPoint(1),
  6036. bindingsUtils.updateNthPoint(2)
  6037. ]
  6038. },
  6039. /**
  6040. * Crooked line (five points) annotation bindings. Includes `start` and four
  6041. * events in `steps` (for all consequent points in crooked line) array.
  6042. *
  6043. * @type {Highcharts.NavigationBindingsOptionsObject}
  6044. * @product highstock
  6045. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  6046. */
  6047. crooked5: {
  6048. /** @ignore-option */
  6049. className: 'highcharts-crooked5',
  6050. // eslint-disable-next-line valid-jsdoc
  6051. /** @ignore-option */
  6052. start: function (e) {
  6053. var coords = this.chart.pointer.getCoordinates(e),
  6054. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6055. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6056. // Exit if clicked out of axes area
  6057. if (!coordsX || !coordsY) {
  6058. return;
  6059. }
  6060. var x = coordsX.value,
  6061. y = coordsY.value,
  6062. navigation = this.chart.options.navigation,
  6063. options = merge({
  6064. langKey: 'crookedLine',
  6065. type: 'crookedLine',
  6066. typeOptions: {
  6067. xAxis: coordsX.axis.options.index,
  6068. yAxis: coordsY.axis.options.index,
  6069. points: [
  6070. { x: x,
  6071. y: y },
  6072. { x: x,
  6073. y: y },
  6074. { x: x,
  6075. y: y },
  6076. { x: x,
  6077. y: y },
  6078. { x: x,
  6079. y: y }
  6080. ]
  6081. }
  6082. },
  6083. navigation.annotationsOptions,
  6084. navigation.bindings.crooked5.annotationsOptions);
  6085. return this.chart.addAnnotation(options);
  6086. },
  6087. /** @ignore-option */
  6088. steps: [
  6089. bindingsUtils.updateNthPoint(1),
  6090. bindingsUtils.updateNthPoint(2),
  6091. bindingsUtils.updateNthPoint(3),
  6092. bindingsUtils.updateNthPoint(4)
  6093. ]
  6094. },
  6095. /**
  6096. * Elliott wave (three points) annotation bindings. Includes `start` and two
  6097. * events in `steps` (for second and third points) array.
  6098. *
  6099. * @type {Highcharts.NavigationBindingsOptionsObject}
  6100. * @product highstock
  6101. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6102. */
  6103. elliott3: {
  6104. /** @ignore-option */
  6105. className: 'highcharts-elliott3',
  6106. // eslint-disable-next-line valid-jsdoc
  6107. /** @ignore-option */
  6108. start: function (e) {
  6109. var coords = this.chart.pointer.getCoordinates(e),
  6110. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6111. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6112. // Exit if clicked out of axes area
  6113. if (!coordsX || !coordsY) {
  6114. return;
  6115. }
  6116. var x = coordsX.value,
  6117. y = coordsY.value,
  6118. navigation = this.chart.options.navigation,
  6119. options = merge({
  6120. langKey: 'elliott3',
  6121. type: 'elliottWave',
  6122. typeOptions: {
  6123. xAxis: coordsX.axis.options.index,
  6124. yAxis: coordsY.axis.options.index,
  6125. points: [
  6126. { x: x,
  6127. y: y },
  6128. { x: x,
  6129. y: y },
  6130. { x: x,
  6131. y: y },
  6132. { x: x,
  6133. y: y }
  6134. ]
  6135. },
  6136. labelOptions: {
  6137. style: {
  6138. color: palette.neutralColor60
  6139. }
  6140. }
  6141. },
  6142. navigation.annotationsOptions,
  6143. navigation.bindings.elliott3.annotationsOptions);
  6144. return this.chart.addAnnotation(options);
  6145. },
  6146. /** @ignore-option */
  6147. steps: [
  6148. bindingsUtils.updateNthPoint(1),
  6149. bindingsUtils.updateNthPoint(2),
  6150. bindingsUtils.updateNthPoint(3)
  6151. ]
  6152. },
  6153. /**
  6154. * Elliott wave (five points) annotation bindings. Includes `start` and four
  6155. * event in `steps` (for all consequent points in Elliott wave) array.
  6156. *
  6157. * @type {Highcharts.NavigationBindingsOptionsObject}
  6158. * @product highstock
  6159. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  6160. */
  6161. elliott5: {
  6162. /** @ignore-option */
  6163. className: 'highcharts-elliott5',
  6164. // eslint-disable-next-line valid-jsdoc
  6165. /** @ignore-option */
  6166. start: function (e) {
  6167. var coords = this.chart.pointer.getCoordinates(e),
  6168. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6169. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6170. // Exit if clicked out of axes area
  6171. if (!coordsX || !coordsY) {
  6172. return;
  6173. }
  6174. var x = coordsX.value,
  6175. y = coordsY.value,
  6176. navigation = this.chart.options.navigation,
  6177. options = merge({
  6178. langKey: 'elliott5',
  6179. type: 'elliottWave',
  6180. typeOptions: {
  6181. xAxis: coordsX.axis.options.index,
  6182. yAxis: coordsY.axis.options.index,
  6183. points: [
  6184. { x: x,
  6185. y: y },
  6186. { x: x,
  6187. y: y },
  6188. { x: x,
  6189. y: y },
  6190. { x: x,
  6191. y: y },
  6192. { x: x,
  6193. y: y },
  6194. { x: x,
  6195. y: y }
  6196. ]
  6197. },
  6198. labelOptions: {
  6199. style: {
  6200. color: palette.neutralColor60
  6201. }
  6202. }
  6203. },
  6204. navigation.annotationsOptions,
  6205. navigation.bindings.elliott5.annotationsOptions);
  6206. return this.chart.addAnnotation(options);
  6207. },
  6208. /** @ignore-option */
  6209. steps: [
  6210. bindingsUtils.updateNthPoint(1),
  6211. bindingsUtils.updateNthPoint(2),
  6212. bindingsUtils.updateNthPoint(3),
  6213. bindingsUtils.updateNthPoint(4),
  6214. bindingsUtils.updateNthPoint(5)
  6215. ]
  6216. },
  6217. /**
  6218. * A measure (x-dimension) annotation bindings. Includes `start` and one
  6219. * event in `steps` array.
  6220. *
  6221. * @type {Highcharts.NavigationBindingsOptionsObject}
  6222. * @product highstock
  6223. * @default {"className": "highcharts-measure-x", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  6224. */
  6225. measureX: {
  6226. /** @ignore-option */
  6227. className: 'highcharts-measure-x',
  6228. // eslint-disable-next-line valid-jsdoc
  6229. /** @ignore-option */
  6230. start: function (e) {
  6231. var coords = this.chart.pointer.getCoordinates(e),
  6232. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6233. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6234. // Exit if clicked out of axes area
  6235. if (!coordsX || !coordsY) {
  6236. return;
  6237. }
  6238. var x = coordsX.value,
  6239. y = coordsY.value,
  6240. navigation = this.chart.options.navigation,
  6241. options = merge({
  6242. langKey: 'measure',
  6243. type: 'measure',
  6244. typeOptions: {
  6245. selectType: 'x',
  6246. xAxis: coordsX.axis.options.index,
  6247. yAxis: coordsY.axis.options.index,
  6248. point: { x: x,
  6249. y: y },
  6250. crosshairX: {
  6251. strokeWidth: 1,
  6252. stroke: palette.neutralColor100
  6253. },
  6254. crosshairY: {
  6255. enabled: false,
  6256. strokeWidth: 0,
  6257. stroke: palette.neutralColor100
  6258. },
  6259. background: {
  6260. width: 0,
  6261. height: 0,
  6262. strokeWidth: 0,
  6263. stroke: palette.backgroundColor
  6264. }
  6265. },
  6266. labelOptions: {
  6267. style: {
  6268. color: palette.neutralColor60
  6269. }
  6270. }
  6271. },
  6272. navigation.annotationsOptions,
  6273. navigation.bindings.measureX.annotationsOptions);
  6274. return this.chart.addAnnotation(options);
  6275. },
  6276. /** @ignore-option */
  6277. steps: [
  6278. bindingsUtils.updateRectSize
  6279. ]
  6280. },
  6281. /**
  6282. * A measure (y-dimension) annotation bindings. Includes `start` and one
  6283. * event in `steps` array.
  6284. *
  6285. * @type {Highcharts.NavigationBindingsOptionsObject}
  6286. * @product highstock
  6287. * @default {"className": "highcharts-measure-y", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  6288. */
  6289. measureY: {
  6290. /** @ignore-option */
  6291. className: 'highcharts-measure-y',
  6292. // eslint-disable-next-line valid-jsdoc
  6293. /** @ignore-option */
  6294. start: function (e) {
  6295. var coords = this.chart.pointer.getCoordinates(e),
  6296. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6297. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6298. // Exit if clicked out of axes area
  6299. if (!coordsX || !coordsY) {
  6300. return;
  6301. }
  6302. var x = coordsX.value,
  6303. y = coordsY.value,
  6304. navigation = this.chart.options.navigation,
  6305. options = merge({
  6306. langKey: 'measure',
  6307. type: 'measure',
  6308. typeOptions: {
  6309. selectType: 'y',
  6310. xAxis: coordsX.axis.options.index,
  6311. yAxis: coordsY.axis.options.index,
  6312. point: { x: x,
  6313. y: y },
  6314. crosshairX: {
  6315. enabled: false,
  6316. strokeWidth: 0,
  6317. stroke: palette.neutralColor100
  6318. },
  6319. crosshairY: {
  6320. strokeWidth: 1,
  6321. stroke: palette.neutralColor100
  6322. },
  6323. background: {
  6324. width: 0,
  6325. height: 0,
  6326. strokeWidth: 0,
  6327. stroke: palette.backgroundColor
  6328. }
  6329. },
  6330. labelOptions: {
  6331. style: {
  6332. color: palette.neutralColor60
  6333. }
  6334. }
  6335. },
  6336. navigation.annotationsOptions,
  6337. navigation.bindings.measureY.annotationsOptions);
  6338. return this.chart.addAnnotation(options);
  6339. },
  6340. /** @ignore-option */
  6341. steps: [
  6342. bindingsUtils.updateRectSize
  6343. ]
  6344. },
  6345. /**
  6346. * A measure (xy-dimension) annotation bindings. Includes `start` and one
  6347. * event in `steps` array.
  6348. *
  6349. * @type {Highcharts.NavigationBindingsOptionsObject}
  6350. * @product highstock
  6351. * @default {"className": "highcharts-measure-xy", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  6352. */
  6353. measureXY: {
  6354. /** @ignore-option */
  6355. className: 'highcharts-measure-xy',
  6356. // eslint-disable-next-line valid-jsdoc
  6357. /** @ignore-option */
  6358. start: function (e) {
  6359. var coords = this.chart.pointer.getCoordinates(e),
  6360. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6361. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6362. // Exit if clicked out of axes area
  6363. if (!coordsX || !coordsY) {
  6364. return;
  6365. }
  6366. var x = coordsX.value,
  6367. y = coordsY.value,
  6368. navigation = this.chart.options.navigation,
  6369. options = merge({
  6370. langKey: 'measure',
  6371. type: 'measure',
  6372. typeOptions: {
  6373. selectType: 'xy',
  6374. xAxis: coordsX.axis.options.index,
  6375. yAxis: coordsY.axis.options.index,
  6376. point: { x: x,
  6377. y: y },
  6378. background: {
  6379. width: 0,
  6380. height: 0,
  6381. strokeWidth: 10
  6382. },
  6383. crosshairX: {
  6384. strokeWidth: 1,
  6385. stroke: palette.neutralColor100
  6386. },
  6387. crosshairY: {
  6388. strokeWidth: 1,
  6389. stroke: palette.neutralColor100
  6390. }
  6391. },
  6392. labelOptions: {
  6393. style: {
  6394. color: palette.neutralColor60
  6395. }
  6396. }
  6397. },
  6398. navigation.annotationsOptions,
  6399. navigation.bindings.measureXY.annotationsOptions);
  6400. return this.chart.addAnnotation(options);
  6401. },
  6402. /** @ignore-option */
  6403. steps: [
  6404. bindingsUtils.updateRectSize
  6405. ]
  6406. },
  6407. // Advanced type annotations:
  6408. /**
  6409. * A fibonacci annotation bindings. Includes `start` and two events in
  6410. * `steps` array (updates second point, then height).
  6411. *
  6412. * @type {Highcharts.NavigationBindingsOptionsObject}
  6413. * @product highstock
  6414. * @default {"className": "highcharts-fibonacci", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6415. */
  6416. fibonacci: {
  6417. /** @ignore-option */
  6418. className: 'highcharts-fibonacci',
  6419. // eslint-disable-next-line valid-jsdoc
  6420. /** @ignore-option */
  6421. start: function (e) {
  6422. var coords = this.chart.pointer.getCoordinates(e),
  6423. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6424. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6425. // Exit if clicked out of axes area
  6426. if (!coordsX || !coordsY) {
  6427. return;
  6428. }
  6429. var x = coordsX.value,
  6430. y = coordsY.value,
  6431. navigation = this.chart.options.navigation,
  6432. options = merge({
  6433. langKey: 'fibonacci',
  6434. type: 'fibonacci',
  6435. typeOptions: {
  6436. xAxis: coordsX.axis.options.index,
  6437. yAxis: coordsY.axis.options.index,
  6438. points: [
  6439. { x: x,
  6440. y: y },
  6441. { x: x,
  6442. y: y }
  6443. ]
  6444. },
  6445. labelOptions: {
  6446. style: {
  6447. color: palette.neutralColor60
  6448. }
  6449. }
  6450. },
  6451. navigation.annotationsOptions,
  6452. navigation.bindings.fibonacci.annotationsOptions);
  6453. return this.chart.addAnnotation(options);
  6454. },
  6455. /** @ignore-option */
  6456. steps: [
  6457. bindingsUtils.updateNthPoint(1),
  6458. bindingsUtils.updateHeight
  6459. ]
  6460. },
  6461. /**
  6462. * A parallel channel (tunnel) annotation bindings. Includes `start` and
  6463. * two events in `steps` array (updates second point, then height).
  6464. *
  6465. * @type {Highcharts.NavigationBindingsOptionsObject}
  6466. * @product highstock
  6467. * @default {"className": "highcharts-parallel-channel", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6468. */
  6469. parallelChannel: {
  6470. /** @ignore-option */
  6471. className: 'highcharts-parallel-channel',
  6472. // eslint-disable-next-line valid-jsdoc
  6473. /** @ignore-option */
  6474. start: function (e) {
  6475. var coords = this.chart.pointer.getCoordinates(e),
  6476. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6477. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6478. // Exit if clicked out of axes area
  6479. if (!coordsX || !coordsY) {
  6480. return;
  6481. }
  6482. var x = coordsX.value,
  6483. y = coordsY.value,
  6484. navigation = this.chart.options.navigation,
  6485. options = merge({
  6486. langKey: 'parallelChannel',
  6487. type: 'tunnel',
  6488. typeOptions: {
  6489. xAxis: coordsX.axis.options.index,
  6490. yAxis: coordsY.axis.options.index,
  6491. points: [
  6492. { x: x,
  6493. y: y },
  6494. { x: x,
  6495. y: y }
  6496. ]
  6497. }
  6498. },
  6499. navigation.annotationsOptions,
  6500. navigation.bindings.parallelChannel.annotationsOptions);
  6501. return this.chart.addAnnotation(options);
  6502. },
  6503. /** @ignore-option */
  6504. steps: [
  6505. bindingsUtils.updateNthPoint(1),
  6506. bindingsUtils.updateHeight
  6507. ]
  6508. },
  6509. /**
  6510. * An Andrew's pitchfork annotation bindings. Includes `start` and two
  6511. * events in `steps` array (sets second and third control points).
  6512. *
  6513. * @type {Highcharts.NavigationBindingsOptionsObject}
  6514. * @product highstock
  6515. * @default {"className": "highcharts-pitchfork", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6516. */
  6517. pitchfork: {
  6518. /** @ignore-option */
  6519. className: 'highcharts-pitchfork',
  6520. // eslint-disable-next-line valid-jsdoc
  6521. /** @ignore-option */
  6522. start: function (e) {
  6523. var coords = this.chart.pointer.getCoordinates(e),
  6524. coordsX = this.utils.getAssignedAxis(coords.xAxis),
  6525. coordsY = this.utils.getAssignedAxis(coords.yAxis);
  6526. // Exit if clicked out of axes area
  6527. if (!coordsX || !coordsY) {
  6528. return;
  6529. }
  6530. var x = coordsX.value, y = coordsY.value, navigation = this.chart.options.navigation, options = merge({
  6531. langKey: 'pitchfork',
  6532. type: 'pitchfork',
  6533. typeOptions: {
  6534. xAxis: coordsX.axis.options.index,
  6535. yAxis: coordsY.axis.options.index,
  6536. points: [{
  6537. x: coordsX.value,
  6538. y: coordsY.value,
  6539. controlPoint: {
  6540. style: {
  6541. fill: palette.negativeColor
  6542. }
  6543. }
  6544. }, { x: x, y: y },
  6545. { x: x, y: y }],
  6546. innerBackground: {
  6547. fill: 'rgba(100, 170, 255, 0.8)'
  6548. }
  6549. },
  6550. shapeOptions: {
  6551. strokeWidth: 2
  6552. }
  6553. }, navigation.annotationsOptions, navigation.bindings.pitchfork.annotationsOptions);
  6554. return this.chart.addAnnotation(options);
  6555. },
  6556. /** @ignore-option */
  6557. steps: [
  6558. bindingsUtils.updateNthPoint(1),
  6559. bindingsUtils.updateNthPoint(2)
  6560. ]
  6561. },
  6562. // Labels with arrow and auto increments
  6563. /**
  6564. * A vertical counter annotation bindings. Includes `start` event. On click,
  6565. * finds the closest point and marks it with a numeric annotation -
  6566. * incrementing counter on each add.
  6567. *
  6568. * @type {Highcharts.NavigationBindingsOptionsObject}
  6569. * @product highstock
  6570. * @default {"className": "highcharts-vertical-counter", "start": function() {}, "annotationsOptions": {}}
  6571. */
  6572. verticalCounter: {
  6573. /** @ignore-option */
  6574. className: 'highcharts-vertical-counter',
  6575. // eslint-disable-next-line valid-jsdoc
  6576. /** @ignore-option */
  6577. start: function (e) {
  6578. var closestPoint = bindingsUtils.attractToPoint(e,
  6579. this.chart),
  6580. navigation = this.chart.options.navigation,
  6581. options,
  6582. annotation;
  6583. // Exit if clicked out of axes area
  6584. if (!closestPoint) {
  6585. return;
  6586. }
  6587. this.verticalCounter = this.verticalCounter || 0;
  6588. options = merge({
  6589. langKey: 'verticalCounter',
  6590. type: 'verticalLine',
  6591. typeOptions: {
  6592. point: {
  6593. x: closestPoint.x,
  6594. y: closestPoint.y,
  6595. xAxis: closestPoint.xAxis,
  6596. yAxis: closestPoint.yAxis
  6597. },
  6598. label: {
  6599. offset: closestPoint.below ? 40 : -40,
  6600. text: this.verticalCounter.toString()
  6601. }
  6602. },
  6603. labelOptions: {
  6604. style: {
  6605. color: palette.neutralColor60,
  6606. fontSize: '11px'
  6607. }
  6608. },
  6609. shapeOptions: {
  6610. stroke: 'rgba(0, 0, 0, 0.75)',
  6611. strokeWidth: 1
  6612. }
  6613. }, navigation.annotationsOptions, navigation.bindings.verticalCounter.annotationsOptions);
  6614. annotation = this.chart.addAnnotation(options);
  6615. this.verticalCounter++;
  6616. annotation.options.events.click.call(annotation, {});
  6617. }
  6618. },
  6619. /**
  6620. * A vertical arrow annotation bindings. Includes `start` event. On click,
  6621. * finds the closest point and marks it with an arrow and a label with
  6622. * value.
  6623. *
  6624. * @type {Highcharts.NavigationBindingsOptionsObject}
  6625. * @product highstock
  6626. * @default {"className": "highcharts-vertical-label", "start": function() {}, "annotationsOptions": {}}
  6627. */
  6628. verticalLabel: {
  6629. /** @ignore-option */
  6630. className: 'highcharts-vertical-label',
  6631. // eslint-disable-next-line valid-jsdoc
  6632. /** @ignore-option */
  6633. start: function (e) {
  6634. var closestPoint = bindingsUtils.attractToPoint(e,
  6635. this.chart),
  6636. navigation = this.chart.options.navigation,
  6637. options,
  6638. annotation;
  6639. // Exit if clicked out of axes area
  6640. if (!closestPoint) {
  6641. return;
  6642. }
  6643. options = merge({
  6644. langKey: 'verticalLabel',
  6645. type: 'verticalLine',
  6646. typeOptions: {
  6647. point: {
  6648. x: closestPoint.x,
  6649. y: closestPoint.y,
  6650. xAxis: closestPoint.xAxis,
  6651. yAxis: closestPoint.yAxis
  6652. },
  6653. label: {
  6654. offset: closestPoint.below ? 40 : -40
  6655. }
  6656. },
  6657. labelOptions: {
  6658. style: {
  6659. color: palette.neutralColor60,
  6660. fontSize: '11px'
  6661. }
  6662. },
  6663. shapeOptions: {
  6664. stroke: 'rgba(0, 0, 0, 0.75)',
  6665. strokeWidth: 1
  6666. }
  6667. }, navigation.annotationsOptions, navigation.bindings.verticalLabel.annotationsOptions);
  6668. annotation = this.chart.addAnnotation(options);
  6669. annotation.options.events.click.call(annotation, {});
  6670. }
  6671. },
  6672. /**
  6673. * A vertical arrow annotation bindings. Includes `start` event. On click,
  6674. * finds the closest point and marks it with an arrow.
  6675. * `${palette.positiveColor}` is the color of the arrow when
  6676. * pointing from above and `${palette.negativeColor}`
  6677. * when pointing from below the point.
  6678. *
  6679. * @type {Highcharts.NavigationBindingsOptionsObject}
  6680. * @product highstock
  6681. * @default {"className": "highcharts-vertical-arrow", "start": function() {}, "annotationsOptions": {}}
  6682. */
  6683. verticalArrow: {
  6684. /** @ignore-option */
  6685. className: 'highcharts-vertical-arrow',
  6686. // eslint-disable-next-line valid-jsdoc
  6687. /** @ignore-option */
  6688. start: function (e) {
  6689. var closestPoint = bindingsUtils.attractToPoint(e,
  6690. this.chart),
  6691. navigation = this.chart.options.navigation,
  6692. options,
  6693. annotation;
  6694. // Exit if clicked out of axes area
  6695. if (!closestPoint) {
  6696. return;
  6697. }
  6698. options = merge({
  6699. langKey: 'verticalArrow',
  6700. type: 'verticalLine',
  6701. typeOptions: {
  6702. point: {
  6703. x: closestPoint.x,
  6704. y: closestPoint.y,
  6705. xAxis: closestPoint.xAxis,
  6706. yAxis: closestPoint.yAxis
  6707. },
  6708. label: {
  6709. offset: closestPoint.below ? 40 : -40,
  6710. format: ' '
  6711. },
  6712. connector: {
  6713. fill: 'none',
  6714. stroke: closestPoint.below ?
  6715. palette.negativeColor : palette.positiveColor
  6716. }
  6717. },
  6718. shapeOptions: {
  6719. stroke: 'rgba(0, 0, 0, 0.75)',
  6720. strokeWidth: 1
  6721. }
  6722. }, navigation.annotationsOptions, navigation.bindings.verticalArrow.annotationsOptions);
  6723. annotation = this.chart.addAnnotation(options);
  6724. annotation.options.events.click.call(annotation, {});
  6725. }
  6726. },
  6727. // Flag types:
  6728. /**
  6729. * A flag series bindings. Includes `start` event. On click, finds the
  6730. * closest point and marks it with a flag with `'circlepin'` shape.
  6731. *
  6732. * @type {Highcharts.NavigationBindingsOptionsObject}
  6733. * @product highstock
  6734. * @default {"className": "highcharts-flag-circlepin", "start": function() {}}
  6735. */
  6736. flagCirclepin: {
  6737. /** @ignore-option */
  6738. className: 'highcharts-flag-circlepin',
  6739. /** @ignore-option */
  6740. start: bindingsUtils.addFlagFromForm('circlepin')
  6741. },
  6742. /**
  6743. * A flag series bindings. Includes `start` event. On click, finds the
  6744. * closest point and marks it with a flag with `'diamondpin'` shape.
  6745. *
  6746. * @type {Highcharts.NavigationBindingsOptionsObject}
  6747. * @product highstock
  6748. * @default {"className": "highcharts-flag-diamondpin", "start": function() {}}
  6749. */
  6750. flagDiamondpin: {
  6751. /** @ignore-option */
  6752. className: 'highcharts-flag-diamondpin',
  6753. /** @ignore-option */
  6754. start: bindingsUtils.addFlagFromForm('flag')
  6755. },
  6756. /**
  6757. * A flag series bindings. Includes `start` event.
  6758. * On click, finds the closest point and marks it with a flag with
  6759. * `'squarepin'` shape.
  6760. *
  6761. * @type {Highcharts.NavigationBindingsOptionsObject}
  6762. * @product highstock
  6763. * @default {"className": "highcharts-flag-squarepin", "start": function() {}}
  6764. */
  6765. flagSquarepin: {
  6766. /** @ignore-option */
  6767. className: 'highcharts-flag-squarepin',
  6768. /** @ignore-option */
  6769. start: bindingsUtils.addFlagFromForm('squarepin')
  6770. },
  6771. /**
  6772. * A flag series bindings. Includes `start` event.
  6773. * On click, finds the closest point and marks it with a flag without pin
  6774. * shape.
  6775. *
  6776. * @type {Highcharts.NavigationBindingsOptionsObject}
  6777. * @product highstock
  6778. * @default {"className": "highcharts-flag-simplepin", "start": function() {}}
  6779. */
  6780. flagSimplepin: {
  6781. /** @ignore-option */
  6782. className: 'highcharts-flag-simplepin',
  6783. /** @ignore-option */
  6784. start: bindingsUtils.addFlagFromForm('nopin')
  6785. },
  6786. // Other tools:
  6787. /**
  6788. * Enables zooming in xAxis on a chart. Includes `start` event which
  6789. * changes [chart.zoomType](#chart.zoomType).
  6790. *
  6791. * @type {Highcharts.NavigationBindingsOptionsObject}
  6792. * @product highstock
  6793. * @default {"className": "highcharts-zoom-x", "init": function() {}}
  6794. */
  6795. zoomX: {
  6796. /** @ignore-option */
  6797. className: 'highcharts-zoom-x',
  6798. // eslint-disable-next-line valid-jsdoc
  6799. /** @ignore-option */
  6800. init: function (button) {
  6801. this.chart.update({
  6802. chart: {
  6803. zoomType: 'x'
  6804. }
  6805. });
  6806. fireEvent(this, 'deselectButton', { button: button });
  6807. }
  6808. },
  6809. /**
  6810. * Enables zooming in yAxis on a chart. Includes `start` event which
  6811. * changes [chart.zoomType](#chart.zoomType).
  6812. *
  6813. * @type {Highcharts.NavigationBindingsOptionsObject}
  6814. * @product highstock
  6815. * @default {"className": "highcharts-zoom-y", "init": function() {}}
  6816. */
  6817. zoomY: {
  6818. /** @ignore-option */
  6819. className: 'highcharts-zoom-y',
  6820. // eslint-disable-next-line valid-jsdoc
  6821. /** @ignore-option */
  6822. init: function (button) {
  6823. this.chart.update({
  6824. chart: {
  6825. zoomType: 'y'
  6826. }
  6827. });
  6828. fireEvent(this, 'deselectButton', { button: button });
  6829. }
  6830. },
  6831. /**
  6832. * Enables zooming in xAxis and yAxis on a chart. Includes `start` event
  6833. * which changes [chart.zoomType](#chart.zoomType).
  6834. *
  6835. * @type {Highcharts.NavigationBindingsOptionsObject}
  6836. * @product highstock
  6837. * @default {"className": "highcharts-zoom-xy", "init": function() {}}
  6838. */
  6839. zoomXY: {
  6840. /** @ignore-option */
  6841. className: 'highcharts-zoom-xy',
  6842. // eslint-disable-next-line valid-jsdoc
  6843. /** @ignore-option */
  6844. init: function (button) {
  6845. this.chart.update({
  6846. chart: {
  6847. zoomType: 'xy'
  6848. }
  6849. });
  6850. fireEvent(this, 'deselectButton', { button: button });
  6851. }
  6852. },
  6853. /**
  6854. * Changes main series to `'line'` type.
  6855. *
  6856. * @type {Highcharts.NavigationBindingsOptionsObject}
  6857. * @product highstock
  6858. * @default {"className": "highcharts-series-type-line", "init": function() {}}
  6859. */
  6860. seriesTypeLine: {
  6861. /** @ignore-option */
  6862. className: 'highcharts-series-type-line',
  6863. // eslint-disable-next-line valid-jsdoc
  6864. /** @ignore-option */
  6865. init: function (button) {
  6866. this.chart.series[0].update({
  6867. type: 'line',
  6868. useOhlcData: true
  6869. });
  6870. fireEvent(this, 'deselectButton', { button: button });
  6871. }
  6872. },
  6873. /**
  6874. * Changes main series to `'ohlc'` type.
  6875. *
  6876. * @type {Highcharts.NavigationBindingsOptionsObject}
  6877. * @product highstock
  6878. * @default {"className": "highcharts-series-type-ohlc", "init": function() {}}
  6879. */
  6880. seriesTypeOhlc: {
  6881. /** @ignore-option */
  6882. className: 'highcharts-series-type-ohlc',
  6883. // eslint-disable-next-line valid-jsdoc
  6884. /** @ignore-option */
  6885. init: function (button) {
  6886. this.chart.series[0].update({
  6887. type: 'ohlc'
  6888. });
  6889. fireEvent(this, 'deselectButton', { button: button });
  6890. }
  6891. },
  6892. /**
  6893. * Changes main series to `'candlestick'` type.
  6894. *
  6895. * @type {Highcharts.NavigationBindingsOptionsObject}
  6896. * @product highstock
  6897. * @default {"className": "highcharts-series-type-candlestick", "init": function() {}}
  6898. */
  6899. seriesTypeCandlestick: {
  6900. /** @ignore-option */
  6901. className: 'highcharts-series-type-candlestick',
  6902. // eslint-disable-next-line valid-jsdoc
  6903. /** @ignore-option */
  6904. init: function (button) {
  6905. this.chart.series[0].update({
  6906. type: 'candlestick'
  6907. });
  6908. fireEvent(this, 'deselectButton', { button: button });
  6909. }
  6910. },
  6911. /**
  6912. * Displays chart in fullscreen.
  6913. *
  6914. * **Note**: Fullscreen is not supported on iPhone due to iOS limitations.
  6915. *
  6916. * @type {Highcharts.NavigationBindingsOptionsObject}
  6917. * @product highstock
  6918. * @default {"className": "noDataState": "normal", "highcharts-full-screen", "init": function() {}}
  6919. */
  6920. fullScreen: {
  6921. /** @ignore-option */
  6922. className: 'highcharts-full-screen',
  6923. noDataState: 'normal',
  6924. // eslint-disable-next-line valid-jsdoc
  6925. /** @ignore-option */
  6926. init: function (button) {
  6927. this.chart.fullscreen.toggle();
  6928. fireEvent(this, 'deselectButton', { button: button });
  6929. }
  6930. },
  6931. /**
  6932. * Hides/shows two price indicators:
  6933. * - last price in the dataset
  6934. * - last price in the selected range
  6935. *
  6936. * @type {Highcharts.NavigationBindingsOptionsObject}
  6937. * @product highstock
  6938. * @default {"className": "highcharts-current-price-indicator", "init": function() {}}
  6939. */
  6940. currentPriceIndicator: {
  6941. /** @ignore-option */
  6942. className: 'highcharts-current-price-indicator',
  6943. // eslint-disable-next-line valid-jsdoc
  6944. /** @ignore-option */
  6945. init: function (button) {
  6946. var chart = this.chart,
  6947. series = chart.series,
  6948. gui = chart.stockTools,
  6949. priceIndicatorEnabled = bindingsUtils.isPriceIndicatorEnabled(chart.series);
  6950. if (gui && gui.guiEnabled) {
  6951. series.forEach(function (series) {
  6952. series.update({
  6953. lastPrice: { enabled: !priceIndicatorEnabled },
  6954. lastVisiblePrice: { enabled: !priceIndicatorEnabled, label: { enabled: true } }
  6955. }, false);
  6956. });
  6957. chart.redraw();
  6958. }
  6959. fireEvent(this, 'deselectButton', { button: button });
  6960. }
  6961. },
  6962. /**
  6963. * Indicators bindings. Includes `init` event to show a popup.
  6964. *
  6965. * Note: In order to show base series from the chart in the popup's
  6966. * dropdown each series requires
  6967. * [series.id](https://api.highcharts.com/highstock/series.line.id) to be
  6968. * defined.
  6969. *
  6970. * @type {Highcharts.NavigationBindingsOptionsObject}
  6971. * @product highstock
  6972. * @default {"className": "highcharts-indicators", "init": function() {}}
  6973. */
  6974. indicators: {
  6975. /** @ignore-option */
  6976. className: 'highcharts-indicators',
  6977. // eslint-disable-next-line valid-jsdoc
  6978. /** @ignore-option */
  6979. init: function () {
  6980. var navigation = this;
  6981. fireEvent(navigation, 'showPopup', {
  6982. formType: 'indicators',
  6983. options: {},
  6984. // Callback on submit:
  6985. onSubmit: function (data) {
  6986. navigation.utils.manageIndicators.call(navigation, data);
  6987. }
  6988. });
  6989. }
  6990. },
  6991. /**
  6992. * Hides/shows all annotations on a chart.
  6993. *
  6994. * @type {Highcharts.NavigationBindingsOptionsObject}
  6995. * @product highstock
  6996. * @default {"className": "highcharts-toggle-annotations", "init": function() {}}
  6997. */
  6998. toggleAnnotations: {
  6999. /** @ignore-option */
  7000. className: 'highcharts-toggle-annotations',
  7001. // eslint-disable-next-line valid-jsdoc
  7002. /** @ignore-option */
  7003. init: function (button) {
  7004. var chart = this.chart,
  7005. gui = chart.stockTools,
  7006. iconsURL = gui.getIconsURL();
  7007. this.toggledAnnotations = !this.toggledAnnotations;
  7008. (chart.annotations || []).forEach(function (annotation) {
  7009. annotation.setVisibility(!this.toggledAnnotations);
  7010. }, this);
  7011. if (gui && gui.guiEnabled) {
  7012. if (this.toggledAnnotations) {
  7013. button.firstChild.style['background-image'] =
  7014. 'url("' + iconsURL +
  7015. 'annotations-hidden.svg")';
  7016. }
  7017. else {
  7018. button.firstChild.style['background-image'] =
  7019. 'url("' + iconsURL +
  7020. 'annotations-visible.svg")';
  7021. }
  7022. }
  7023. fireEvent(this, 'deselectButton', { button: button });
  7024. }
  7025. },
  7026. /**
  7027. * Save a chart in localStorage under `highcharts-chart` key.
  7028. * Stored items:
  7029. * - annotations
  7030. * - indicators (with yAxes)
  7031. * - flags
  7032. *
  7033. * @type {Highcharts.NavigationBindingsOptionsObject}
  7034. * @product highstock
  7035. * @default {"className": "highcharts-save-chart", "noDataState": "normal", "init": function() {}}
  7036. */
  7037. saveChart: {
  7038. /** @ignore-option */
  7039. className: 'highcharts-save-chart',
  7040. noDataState: 'normal',
  7041. // eslint-disable-next-line valid-jsdoc
  7042. /** @ignore-option */
  7043. init: function (button) {
  7044. var navigation = this,
  7045. chart = navigation.chart,
  7046. annotations = [],
  7047. indicators = [],
  7048. flags = [],
  7049. yAxes = [];
  7050. chart.annotations.forEach(function (annotation, index) {
  7051. annotations[index] = annotation.userOptions;
  7052. });
  7053. chart.series.forEach(function (series) {
  7054. if (series.is('sma')) {
  7055. indicators.push(series.userOptions);
  7056. }
  7057. else if (series.type === 'flags') {
  7058. flags.push(series.userOptions);
  7059. }
  7060. });
  7061. chart.yAxis.forEach(function (yAxis) {
  7062. if (bindingsUtils.isNotNavigatorYAxis(yAxis)) {
  7063. yAxes.push(yAxis.options);
  7064. }
  7065. });
  7066. H.win.localStorage.setItem(PREFIX + 'chart', JSON.stringify({
  7067. annotations: annotations,
  7068. indicators: indicators,
  7069. flags: flags,
  7070. yAxes: yAxes
  7071. }));
  7072. fireEvent(this, 'deselectButton', { button: button });
  7073. }
  7074. }
  7075. };
  7076. setOptions({
  7077. navigation: {
  7078. bindings: stockToolsBindings
  7079. }
  7080. });
  7081. NavigationBindings.prototype.utils = merge(bindingsUtils, NavigationBindings.prototype.utils);
  7082. });
  7083. _registerModule(_modules, 'Stock/StockToolsGui.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/NavigationBindings.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Utilities.js']], function (Chart, H, NavigationBindings, D, U) {
  7084. /* *
  7085. *
  7086. * GUI generator for Stock tools
  7087. *
  7088. * (c) 2009-2021 Sebastian Bochan
  7089. *
  7090. * License: www.highcharts.com/license
  7091. *
  7092. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7093. *
  7094. * */
  7095. var setOptions = D.setOptions;
  7096. var addEvent = U.addEvent,
  7097. createElement = U.createElement,
  7098. css = U.css,
  7099. extend = U.extend,
  7100. fireEvent = U.fireEvent,
  7101. getStyle = U.getStyle,
  7102. isArray = U.isArray,
  7103. merge = U.merge,
  7104. pick = U.pick;
  7105. var DIV = 'div', SPAN = 'span', UL = 'ul', LI = 'li', PREFIX = 'highcharts-', activeClass = PREFIX + 'active';
  7106. setOptions({
  7107. /**
  7108. * @optionparent lang
  7109. */
  7110. lang: {
  7111. /**
  7112. * Configure the stockTools GUI titles(hints) in the chart. Requires
  7113. * the `stock-tools.js` module to be loaded.
  7114. *
  7115. * @product highstock
  7116. * @since 7.0.0
  7117. */
  7118. stockTools: {
  7119. gui: {
  7120. // Main buttons:
  7121. simpleShapes: 'Simple shapes',
  7122. lines: 'Lines',
  7123. crookedLines: 'Crooked lines',
  7124. measure: 'Measure',
  7125. advanced: 'Advanced',
  7126. toggleAnnotations: 'Toggle annotations',
  7127. verticalLabels: 'Vertical labels',
  7128. flags: 'Flags',
  7129. zoomChange: 'Zoom change',
  7130. typeChange: 'Type change',
  7131. saveChart: 'Save chart',
  7132. indicators: 'Indicators',
  7133. currentPriceIndicator: 'Current Price Indicators',
  7134. // Other features:
  7135. zoomX: 'Zoom X',
  7136. zoomY: 'Zoom Y',
  7137. zoomXY: 'Zooom XY',
  7138. fullScreen: 'Fullscreen',
  7139. typeOHLC: 'OHLC',
  7140. typeLine: 'Line',
  7141. typeCandlestick: 'Candlestick',
  7142. // Basic shapes:
  7143. circle: 'Circle',
  7144. label: 'Label',
  7145. rectangle: 'Rectangle',
  7146. // Flags:
  7147. flagCirclepin: 'Flag circle',
  7148. flagDiamondpin: 'Flag diamond',
  7149. flagSquarepin: 'Flag square',
  7150. flagSimplepin: 'Flag simple',
  7151. // Measures:
  7152. measureXY: 'Measure XY',
  7153. measureX: 'Measure X',
  7154. measureY: 'Measure Y',
  7155. // Segment, ray and line:
  7156. segment: 'Segment',
  7157. arrowSegment: 'Arrow segment',
  7158. ray: 'Ray',
  7159. arrowRay: 'Arrow ray',
  7160. line: 'Line',
  7161. arrowLine: 'Arrow line',
  7162. horizontalLine: 'Horizontal line',
  7163. verticalLine: 'Vertical line',
  7164. infinityLine: 'Infinity line',
  7165. // Crooked lines:
  7166. crooked3: 'Crooked 3 line',
  7167. crooked5: 'Crooked 5 line',
  7168. elliott3: 'Elliott 3 line',
  7169. elliott5: 'Elliott 5 line',
  7170. // Counters:
  7171. verticalCounter: 'Vertical counter',
  7172. verticalLabel: 'Vertical label',
  7173. verticalArrow: 'Vertical arrow',
  7174. // Advanced:
  7175. fibonacci: 'Fibonacci',
  7176. pitchfork: 'Pitchfork',
  7177. parallelChannel: 'Parallel channel'
  7178. }
  7179. },
  7180. navigation: {
  7181. popup: {
  7182. // Annotations:
  7183. circle: 'Circle',
  7184. rectangle: 'Rectangle',
  7185. label: 'Label',
  7186. segment: 'Segment',
  7187. arrowSegment: 'Arrow segment',
  7188. ray: 'Ray',
  7189. arrowRay: 'Arrow ray',
  7190. line: 'Line',
  7191. arrowLine: 'Arrow line',
  7192. horizontalLine: 'Horizontal line',
  7193. verticalLine: 'Vertical line',
  7194. crooked3: 'Crooked 3 line',
  7195. crooked5: 'Crooked 5 line',
  7196. elliott3: 'Elliott 3 line',
  7197. elliott5: 'Elliott 5 line',
  7198. verticalCounter: 'Vertical counter',
  7199. verticalLabel: 'Vertical label',
  7200. verticalArrow: 'Vertical arrow',
  7201. fibonacci: 'Fibonacci',
  7202. pitchfork: 'Pitchfork',
  7203. parallelChannel: 'Parallel channel',
  7204. infinityLine: 'Infinity line',
  7205. measure: 'Measure',
  7206. measureXY: 'Measure XY',
  7207. measureX: 'Measure X',
  7208. measureY: 'Measure Y',
  7209. // Flags:
  7210. flags: 'Flags',
  7211. // GUI elements:
  7212. addButton: 'add',
  7213. saveButton: 'save',
  7214. editButton: 'edit',
  7215. removeButton: 'remove',
  7216. series: 'Series',
  7217. volume: 'Volume',
  7218. connector: 'Connector',
  7219. // Field names:
  7220. innerBackground: 'Inner background',
  7221. outerBackground: 'Outer background',
  7222. crosshairX: 'Crosshair X',
  7223. crosshairY: 'Crosshair Y',
  7224. tunnel: 'Tunnel',
  7225. background: 'Background',
  7226. // Indicators' params (#15170):
  7227. index: 'Index',
  7228. period: 'Period',
  7229. standardDeviation: 'Standard deviation',
  7230. periodTenkan: 'Tenkan period',
  7231. periodSenkouSpanB: 'Senkou Span B period',
  7232. periodATR: 'ATR period',
  7233. multiplierATR: 'ATR multiplier',
  7234. shortPeriod: 'Short period',
  7235. longPeriod: 'Long period',
  7236. signalPeriod: 'Signal period',
  7237. decimals: 'Decimals',
  7238. algorithm: 'Algorithm',
  7239. topBand: 'Top band',
  7240. bottomBand: 'Bottom band',
  7241. initialAccelerationFactor: 'Initial acceleration factor',
  7242. maxAccelerationFactor: 'Max acceleration factor',
  7243. increment: 'Increment',
  7244. multiplier: 'Multiplier',
  7245. ranges: 'Ranges',
  7246. highIndex: 'High index',
  7247. lowIndex: 'Low index',
  7248. deviation: 'Deviation',
  7249. xAxisUnit: 'x-axis unit',
  7250. factor: 'Factor',
  7251. fastAvgPeriod: 'Fast average period',
  7252. slowAvgPeriod: 'Slow average period',
  7253. average: 'Average'
  7254. }
  7255. }
  7256. },
  7257. /**
  7258. * Configure the stockTools gui strings in the chart. Requires the
  7259. * [stockTools module]() to be loaded. For a description of the module
  7260. * and information on its features, see [Highcharts StockTools]().
  7261. *
  7262. * @product highstock
  7263. *
  7264. * @sample stock/demo/stock-tools-gui Stock Tools GUI
  7265. *
  7266. * @sample stock/demo/stock-tools-custom-gui Stock Tools customized GUI
  7267. *
  7268. * @since 7.0.0
  7269. * @optionparent stockTools
  7270. */
  7271. stockTools: {
  7272. /**
  7273. * Definitions of buttons in Stock Tools GUI.
  7274. */
  7275. gui: {
  7276. /**
  7277. * Path where Highcharts will look for icons. Change this to use
  7278. * icons from a different server.
  7279. *
  7280. * Since 7.1.3 use [iconsURL](#navigation.iconsURL) for popup and
  7281. * stock tools.
  7282. *
  7283. * @deprecated
  7284. * @apioption stockTools.gui.iconsURL
  7285. *
  7286. */
  7287. /**
  7288. * Enable or disable the stockTools gui.
  7289. */
  7290. enabled: true,
  7291. /**
  7292. * A CSS class name to apply to the stocktools' div,
  7293. * allowing unique CSS styling for each chart.
  7294. */
  7295. className: 'highcharts-bindings-wrapper',
  7296. /**
  7297. * A CSS class name to apply to the container of buttons,
  7298. * allowing unique CSS styling for each chart.
  7299. */
  7300. toolbarClassName: 'stocktools-toolbar',
  7301. /**
  7302. * A collection of strings pointing to config options for the
  7303. * toolbar items. Each name refers to a unique key from the
  7304. * definitions object.
  7305. *
  7306. * @type {Array<string>}
  7307. * @default [
  7308. * 'indicators',
  7309. * 'separator',
  7310. * 'simpleShapes',
  7311. * 'lines',
  7312. * 'crookedLines',
  7313. * 'measure',
  7314. * 'advanced',
  7315. * 'toggleAnnotations',
  7316. * 'separator',
  7317. * 'verticalLabels',
  7318. * 'flags',
  7319. * 'separator',
  7320. * 'zoomChange',
  7321. * 'fullScreen',
  7322. * 'typeChange',
  7323. * 'separator',
  7324. * 'currentPriceIndicator',
  7325. * 'saveChart'
  7326. * ]
  7327. */
  7328. buttons: [
  7329. 'indicators',
  7330. 'separator',
  7331. 'simpleShapes',
  7332. 'lines',
  7333. 'crookedLines',
  7334. 'measure',
  7335. 'advanced',
  7336. 'toggleAnnotations',
  7337. 'separator',
  7338. 'verticalLabels',
  7339. 'flags',
  7340. 'separator',
  7341. 'zoomChange',
  7342. 'fullScreen',
  7343. 'typeChange',
  7344. 'separator',
  7345. 'currentPriceIndicator',
  7346. 'saveChart'
  7347. ],
  7348. /**
  7349. * An options object of the buttons definitions. Each name refers to
  7350. * unique key from buttons array.
  7351. */
  7352. definitions: {
  7353. separator: {
  7354. /**
  7355. * A predefined background symbol for the button.
  7356. */
  7357. symbol: 'separator.svg'
  7358. },
  7359. simpleShapes: {
  7360. /**
  7361. * A collection of strings pointing to config options for
  7362. * the items.
  7363. *
  7364. * @type {array}
  7365. * @default [
  7366. * 'label',
  7367. * 'circle',
  7368. * 'rectangle'
  7369. * ]
  7370. *
  7371. */
  7372. items: [
  7373. 'label',
  7374. 'circle',
  7375. 'rectangle'
  7376. ],
  7377. circle: {
  7378. /**
  7379. * A predefined background symbol for the button.
  7380. *
  7381. * @type {string}
  7382. *
  7383. */
  7384. symbol: 'circle.svg'
  7385. },
  7386. rectangle: {
  7387. /**
  7388. * A predefined background symbol for the button.
  7389. *
  7390. * @type {string}
  7391. *
  7392. */
  7393. symbol: 'rectangle.svg'
  7394. },
  7395. label: {
  7396. /**
  7397. * A predefined background symbol for the button.
  7398. *
  7399. * @type {string}
  7400. *
  7401. */
  7402. symbol: 'label.svg'
  7403. }
  7404. },
  7405. flags: {
  7406. /**
  7407. * A collection of strings pointing to config options for
  7408. * the items.
  7409. *
  7410. * @type {array}
  7411. * @default [
  7412. * 'flagCirclepin',
  7413. * 'flagDiamondpin',
  7414. * 'flagSquarepin',
  7415. * 'flagSimplepin'
  7416. * ]
  7417. *
  7418. */
  7419. items: [
  7420. 'flagCirclepin',
  7421. 'flagDiamondpin',
  7422. 'flagSquarepin',
  7423. 'flagSimplepin'
  7424. ],
  7425. flagSimplepin: {
  7426. /**
  7427. * A predefined background symbol for the button.
  7428. *
  7429. * @type {string}
  7430. *
  7431. */
  7432. symbol: 'flag-basic.svg'
  7433. },
  7434. flagDiamondpin: {
  7435. /**
  7436. * A predefined background symbol for the button.
  7437. *
  7438. * @type {string}
  7439. *
  7440. */
  7441. symbol: 'flag-diamond.svg'
  7442. },
  7443. flagSquarepin: {
  7444. /**
  7445. * A predefined background symbol for the button.
  7446. *
  7447. * @type {string}
  7448. */
  7449. symbol: 'flag-trapeze.svg'
  7450. },
  7451. flagCirclepin: {
  7452. /**
  7453. * A predefined background symbol for the button.
  7454. *
  7455. * @type {string}
  7456. */
  7457. symbol: 'flag-elipse.svg'
  7458. }
  7459. },
  7460. lines: {
  7461. /**
  7462. * A collection of strings pointing to config options for
  7463. * the items.
  7464. *
  7465. * @type {array}
  7466. * @default [
  7467. * 'segment',
  7468. * 'arrowSegment',
  7469. * 'ray',
  7470. * 'arrowRay',
  7471. * 'line',
  7472. * 'arrowLine',
  7473. * 'horizontalLine',
  7474. * 'verticalLine'
  7475. * ]
  7476. */
  7477. items: [
  7478. 'segment',
  7479. 'arrowSegment',
  7480. 'ray',
  7481. 'arrowRay',
  7482. 'line',
  7483. 'arrowLine',
  7484. 'horizontalLine',
  7485. 'verticalLine'
  7486. ],
  7487. segment: {
  7488. /**
  7489. * A predefined background symbol for the button.
  7490. *
  7491. * @type {string}
  7492. */
  7493. symbol: 'segment.svg'
  7494. },
  7495. arrowSegment: {
  7496. /**
  7497. * A predefined background symbol for the button.
  7498. *
  7499. * @type {string}
  7500. */
  7501. symbol: 'arrow-segment.svg'
  7502. },
  7503. ray: {
  7504. /**
  7505. * A predefined background symbol for the button.
  7506. *
  7507. * @type {string}
  7508. */
  7509. symbol: 'ray.svg'
  7510. },
  7511. arrowRay: {
  7512. /**
  7513. * A predefined background symbol for the button.
  7514. *
  7515. * @type {string}
  7516. */
  7517. symbol: 'arrow-ray.svg'
  7518. },
  7519. line: {
  7520. /**
  7521. * A predefined background symbol for the button.
  7522. *
  7523. * @type {string}
  7524. */
  7525. symbol: 'line.svg'
  7526. },
  7527. arrowLine: {
  7528. /**
  7529. * A predefined background symbol for the button.
  7530. *
  7531. * @type {string}
  7532. */
  7533. symbol: 'arrow-line.svg'
  7534. },
  7535. verticalLine: {
  7536. /**
  7537. * A predefined background symbol for the button.
  7538. *
  7539. * @type {string}
  7540. */
  7541. symbol: 'vertical-line.svg'
  7542. },
  7543. horizontalLine: {
  7544. /**
  7545. * A predefined background symbol for the button.
  7546. *
  7547. * @type {string}
  7548. */
  7549. symbol: 'horizontal-line.svg'
  7550. }
  7551. },
  7552. crookedLines: {
  7553. /**
  7554. * A collection of strings pointing to config options for
  7555. * the items.
  7556. *
  7557. * @type {array}
  7558. * @default [
  7559. * 'elliott3',
  7560. * 'elliott5',
  7561. * 'crooked3',
  7562. * 'crooked5'
  7563. * ]
  7564. *
  7565. */
  7566. items: [
  7567. 'elliott3',
  7568. 'elliott5',
  7569. 'crooked3',
  7570. 'crooked5'
  7571. ],
  7572. crooked3: {
  7573. /**
  7574. * A predefined background symbol for the button.
  7575. *
  7576. * @type {string}
  7577. */
  7578. symbol: 'crooked-3.svg'
  7579. },
  7580. crooked5: {
  7581. /**
  7582. * A predefined background symbol for the button.
  7583. *
  7584. * @type {string}
  7585. */
  7586. symbol: 'crooked-5.svg'
  7587. },
  7588. elliott3: {
  7589. /**
  7590. * A predefined background symbol for the button.
  7591. *
  7592. * @type {string}
  7593. */
  7594. symbol: 'elliott-3.svg'
  7595. },
  7596. elliott5: {
  7597. /**
  7598. * A predefined background symbol for the button.
  7599. *
  7600. * @type {string}
  7601. */
  7602. symbol: 'elliott-5.svg'
  7603. }
  7604. },
  7605. verticalLabels: {
  7606. /**
  7607. * A collection of strings pointing to config options for
  7608. * the items.
  7609. *
  7610. * @type {array}
  7611. * @default [
  7612. * 'verticalCounter',
  7613. * 'verticalLabel',
  7614. * 'verticalArrow'
  7615. * ]
  7616. */
  7617. items: [
  7618. 'verticalCounter',
  7619. 'verticalLabel',
  7620. 'verticalArrow'
  7621. ],
  7622. verticalCounter: {
  7623. /**
  7624. * A predefined background symbol for the button.
  7625. *
  7626. * @type {string}
  7627. */
  7628. symbol: 'vertical-counter.svg'
  7629. },
  7630. verticalLabel: {
  7631. /**
  7632. * A predefined background symbol for the button.
  7633. *
  7634. * @type {string}
  7635. */
  7636. symbol: 'vertical-label.svg'
  7637. },
  7638. verticalArrow: {
  7639. /**
  7640. * A predefined background symbol for the button.
  7641. *
  7642. * @type {string}
  7643. */
  7644. symbol: 'vertical-arrow.svg'
  7645. }
  7646. },
  7647. advanced: {
  7648. /**
  7649. * A collection of strings pointing to config options for
  7650. * the items.
  7651. *
  7652. * @type {array}
  7653. * @default [
  7654. * 'fibonacci',
  7655. * 'pitchfork',
  7656. * 'parallelChannel'
  7657. * ]
  7658. */
  7659. items: [
  7660. 'fibonacci',
  7661. 'pitchfork',
  7662. 'parallelChannel'
  7663. ],
  7664. pitchfork: {
  7665. /**
  7666. * A predefined background symbol for the button.
  7667. *
  7668. * @type {string}
  7669. */
  7670. symbol: 'pitchfork.svg'
  7671. },
  7672. fibonacci: {
  7673. /**
  7674. * A predefined background symbol for the button.
  7675. *
  7676. * @type {string}
  7677. */
  7678. symbol: 'fibonacci.svg'
  7679. },
  7680. parallelChannel: {
  7681. /**
  7682. * A predefined background symbol for the button.
  7683. *
  7684. * @type {string}
  7685. */
  7686. symbol: 'parallel-channel.svg'
  7687. }
  7688. },
  7689. measure: {
  7690. /**
  7691. * A collection of strings pointing to config options for
  7692. * the items.
  7693. *
  7694. * @type {array}
  7695. * @default [
  7696. * 'measureXY',
  7697. * 'measureX',
  7698. * 'measureY'
  7699. * ]
  7700. */
  7701. items: [
  7702. 'measureXY',
  7703. 'measureX',
  7704. 'measureY'
  7705. ],
  7706. measureX: {
  7707. /**
  7708. * A predefined background symbol for the button.
  7709. *
  7710. * @type {string}
  7711. */
  7712. symbol: 'measure-x.svg'
  7713. },
  7714. measureY: {
  7715. /**
  7716. * A predefined background symbol for the button.
  7717. *
  7718. * @type {string}
  7719. */
  7720. symbol: 'measure-y.svg'
  7721. },
  7722. measureXY: {
  7723. /**
  7724. * A predefined background symbol for the button.
  7725. *
  7726. * @type {string}
  7727. */
  7728. symbol: 'measure-xy.svg'
  7729. }
  7730. },
  7731. toggleAnnotations: {
  7732. /**
  7733. * A predefined background symbol for the button.
  7734. *
  7735. * @type {string}
  7736. */
  7737. symbol: 'annotations-visible.svg'
  7738. },
  7739. currentPriceIndicator: {
  7740. /**
  7741. * A predefined background symbol for the button.
  7742. *
  7743. * @type {string}
  7744. */
  7745. symbol: 'current-price-show.svg'
  7746. },
  7747. indicators: {
  7748. /**
  7749. * A predefined background symbol for the button.
  7750. *
  7751. * @type {string}
  7752. */
  7753. symbol: 'indicators.svg'
  7754. },
  7755. zoomChange: {
  7756. /**
  7757. * A collection of strings pointing to config options for
  7758. * the items.
  7759. *
  7760. * @type {array}
  7761. * @default [
  7762. * 'zoomX',
  7763. * 'zoomY',
  7764. * 'zoomXY'
  7765. * ]
  7766. */
  7767. items: [
  7768. 'zoomX',
  7769. 'zoomY',
  7770. 'zoomXY'
  7771. ],
  7772. zoomX: {
  7773. /**
  7774. * A predefined background symbol for the button.
  7775. *
  7776. * @type {string}
  7777. */
  7778. symbol: 'zoom-x.svg'
  7779. },
  7780. zoomY: {
  7781. /**
  7782. * A predefined background symbol for the button.
  7783. *
  7784. * @type {string}
  7785. */
  7786. symbol: 'zoom-y.svg'
  7787. },
  7788. zoomXY: {
  7789. /**
  7790. * A predefined background symbol for the button.
  7791. *
  7792. * @type {string}
  7793. */
  7794. symbol: 'zoom-xy.svg'
  7795. }
  7796. },
  7797. typeChange: {
  7798. /**
  7799. * A collection of strings pointing to config options for
  7800. * the items.
  7801. *
  7802. * @type {array}
  7803. * @default [
  7804. * 'typeOHLC',
  7805. * 'typeLine',
  7806. * 'typeCandlestick'
  7807. * ]
  7808. */
  7809. items: [
  7810. 'typeOHLC',
  7811. 'typeLine',
  7812. 'typeCandlestick'
  7813. ],
  7814. typeOHLC: {
  7815. /**
  7816. * A predefined background symbol for the button.
  7817. *
  7818. * @type {string}
  7819. */
  7820. symbol: 'series-ohlc.svg'
  7821. },
  7822. typeLine: {
  7823. /**
  7824. * A predefined background symbol for the button.
  7825. *
  7826. * @type {string}
  7827. */
  7828. symbol: 'series-line.svg'
  7829. },
  7830. typeCandlestick: {
  7831. /**
  7832. * A predefined background symbol for the button.
  7833. *
  7834. * @type {string}
  7835. */
  7836. symbol: 'series-candlestick.svg'
  7837. }
  7838. },
  7839. fullScreen: {
  7840. /**
  7841. * A predefined background symbol for the button.
  7842. *
  7843. * @type {string}
  7844. */
  7845. symbol: 'fullscreen.svg'
  7846. },
  7847. saveChart: {
  7848. /**
  7849. * A predefined background symbol for the button.
  7850. *
  7851. * @type {string}
  7852. */
  7853. symbol: 'save-chart.svg'
  7854. }
  7855. }
  7856. }
  7857. }
  7858. });
  7859. /* eslint-disable no-invalid-this, valid-jsdoc */
  7860. // Run HTML generator
  7861. addEvent(Chart, 'afterGetContainer', function () {
  7862. this.setStockTools();
  7863. });
  7864. addEvent(Chart, 'getMargins', function () {
  7865. var listWrapper = this.stockTools && this.stockTools.listWrapper,
  7866. offsetWidth = listWrapper && ((listWrapper.startWidth +
  7867. getStyle(listWrapper, 'padding-left') +
  7868. getStyle(listWrapper, 'padding-right')) || listWrapper.offsetWidth);
  7869. if (offsetWidth && offsetWidth < this.plotWidth) {
  7870. this.plotLeft += offsetWidth;
  7871. this.spacing[3] += offsetWidth;
  7872. }
  7873. }, {
  7874. order: 0
  7875. });
  7876. ['beforeRender', 'beforeRedraw'].forEach(function (event) {
  7877. addEvent(Chart, event, function () {
  7878. if (this.stockTools) {
  7879. var optionsChart = this.options.chart;
  7880. var listWrapper = this.stockTools.listWrapper,
  7881. offsetWidth = listWrapper && ((listWrapper.startWidth +
  7882. getStyle(listWrapper, 'padding-left') +
  7883. getStyle(listWrapper, 'padding-right')) || listWrapper.offsetWidth);
  7884. var dirty = false;
  7885. if (offsetWidth && offsetWidth < this.plotWidth) {
  7886. var nextX = pick(optionsChart.spacingLeft,
  7887. optionsChart.spacing && optionsChart.spacing[3], 0) + offsetWidth;
  7888. var diff = nextX - this.spacingBox.x;
  7889. this.spacingBox.x = nextX;
  7890. this.spacingBox.width -= diff;
  7891. dirty = true;
  7892. }
  7893. else if (offsetWidth === 0) {
  7894. dirty = true;
  7895. }
  7896. if (offsetWidth !== this.stockTools.prevOffsetWidth) {
  7897. this.stockTools.prevOffsetWidth = offsetWidth;
  7898. if (dirty) {
  7899. this.isDirtyLegend = true;
  7900. }
  7901. }
  7902. }
  7903. });
  7904. });
  7905. addEvent(Chart, 'destroy', function () {
  7906. if (this.stockTools) {
  7907. this.stockTools.destroy();
  7908. }
  7909. });
  7910. addEvent(Chart, 'redraw', function () {
  7911. if (this.stockTools && this.stockTools.guiEnabled) {
  7912. this.stockTools.redraw();
  7913. }
  7914. });
  7915. /**
  7916. * Toolbar Class
  7917. * @private
  7918. * @constructor
  7919. * @param {Object} - options of toolbar
  7920. * @param {Chart} - Reference to chart
  7921. */
  7922. var Toolbar = /** @class */ (function () {
  7923. function Toolbar(options, langOptions, chart) {
  7924. this.arrowDown = void 0;
  7925. this.arrowUp = void 0;
  7926. this.arrowWrapper = void 0;
  7927. this.listWrapper = void 0;
  7928. this.showhideBtn = void 0;
  7929. this.submenu = void 0;
  7930. this.toolbar = void 0;
  7931. this.wrapper = void 0;
  7932. this.chart = chart;
  7933. this.options = options;
  7934. this.lang = langOptions;
  7935. // set url for icons.
  7936. this.iconsURL = this.getIconsURL();
  7937. this.guiEnabled = options.enabled;
  7938. this.visible = pick(options.visible, true);
  7939. this.placed = pick(options.placed, false);
  7940. // General events collection which should be removed upon
  7941. // destroy/update:
  7942. this.eventsToUnbind = [];
  7943. if (this.guiEnabled) {
  7944. this.createHTML();
  7945. this.init();
  7946. this.showHideNavigatorion();
  7947. }
  7948. fireEvent(this, 'afterInit');
  7949. }
  7950. /**
  7951. * Initialize the toolbar. Create buttons and submenu for each option
  7952. * defined in `stockTools.gui`.
  7953. * @private
  7954. */
  7955. Toolbar.prototype.init = function () {
  7956. var _self = this,
  7957. lang = this.lang,
  7958. guiOptions = this.options,
  7959. toolbar = this.toolbar,
  7960. addSubmenu = _self.addSubmenu,
  7961. buttons = guiOptions.buttons,
  7962. defs = guiOptions.definitions,
  7963. allButtons = toolbar.childNodes,
  7964. button;
  7965. // create buttons
  7966. buttons.forEach(function (btnName) {
  7967. button = _self.addButton(toolbar, defs, btnName, lang);
  7968. _self.eventsToUnbind.push(addEvent(button.buttonWrapper, 'click', function () {
  7969. _self.eraseActiveButtons(allButtons, button.buttonWrapper);
  7970. }));
  7971. if (isArray(defs[btnName].items)) {
  7972. // create submenu buttons
  7973. addSubmenu.call(_self, button, defs[btnName]);
  7974. }
  7975. });
  7976. };
  7977. /**
  7978. * Create submenu (list of buttons) for the option. In example main button
  7979. * is Line, in submenu will be buttons with types of lines.
  7980. * @private
  7981. * @param {Highcharts.Dictionary<Highcharts.HTMLDOMElement>}
  7982. * button which has submenu
  7983. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions}
  7984. * list of all buttons
  7985. */
  7986. Toolbar.prototype.addSubmenu = function (parentBtn, button) {
  7987. var _self = this,
  7988. submenuArrow = parentBtn.submenuArrow,
  7989. buttonWrapper = parentBtn.buttonWrapper,
  7990. buttonWidth = getStyle(buttonWrapper, 'width'),
  7991. wrapper = this.wrapper,
  7992. menuWrapper = this.listWrapper,
  7993. allButtons = this.toolbar.childNodes,
  7994. topMargin = 0,
  7995. submenuWrapper;
  7996. // create submenu container
  7997. this.submenu = submenuWrapper = createElement(UL, {
  7998. className: PREFIX + 'submenu-wrapper'
  7999. }, void 0, buttonWrapper);
  8000. // create submenu buttons and select the first one
  8001. this.addSubmenuItems(buttonWrapper, button);
  8002. // show / hide submenu
  8003. _self.eventsToUnbind.push(addEvent(submenuArrow, 'click', function (e) {
  8004. e.stopPropagation();
  8005. // Erase active class on all other buttons
  8006. _self.eraseActiveButtons(allButtons, buttonWrapper);
  8007. // hide menu
  8008. if (buttonWrapper.className.indexOf(PREFIX + 'current') >= 0) {
  8009. menuWrapper.style.width =
  8010. menuWrapper.startWidth + 'px';
  8011. buttonWrapper.classList.remove(PREFIX + 'current');
  8012. submenuWrapper.style.display = 'none';
  8013. }
  8014. else {
  8015. // show menu
  8016. // to calculate height of element
  8017. submenuWrapper.style.display = 'block';
  8018. topMargin = submenuWrapper.offsetHeight -
  8019. buttonWrapper.offsetHeight - 3;
  8020. // calculate position of submenu in the box
  8021. // if submenu is inside, reset top margin
  8022. if (
  8023. // cut on the bottom
  8024. !(submenuWrapper.offsetHeight +
  8025. buttonWrapper.offsetTop >
  8026. wrapper.offsetHeight &&
  8027. // cut on the top
  8028. buttonWrapper.offsetTop > topMargin)) {
  8029. topMargin = 0;
  8030. }
  8031. // apply calculated styles
  8032. css(submenuWrapper, {
  8033. top: -topMargin + 'px',
  8034. left: buttonWidth + 3 + 'px'
  8035. });
  8036. buttonWrapper.className += ' ' + PREFIX + 'current';
  8037. menuWrapper.startWidth = wrapper.offsetWidth;
  8038. menuWrapper.style.width = menuWrapper.startWidth +
  8039. getStyle(menuWrapper, 'padding-left') +
  8040. submenuWrapper.offsetWidth + 3 + 'px';
  8041. }
  8042. }));
  8043. };
  8044. /**
  8045. * Create buttons in submenu
  8046. * @private
  8047. * @param {Highcharts.HTMLDOMElement}
  8048. * button where submenu is placed
  8049. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions}
  8050. * list of all buttons options
  8051. *
  8052. */
  8053. Toolbar.prototype.addSubmenuItems = function (buttonWrapper, button) {
  8054. var _self = this,
  8055. submenuWrapper = this.submenu,
  8056. lang = this.lang,
  8057. menuWrapper = this.listWrapper,
  8058. items = button.items,
  8059. firstSubmenuItem,
  8060. submenuBtn;
  8061. // add items to submenu
  8062. items.forEach(function (btnName) {
  8063. // add buttons to submenu
  8064. submenuBtn = _self.addButton(submenuWrapper, button, btnName, lang);
  8065. _self.eventsToUnbind.push(addEvent(submenuBtn.mainButton, 'click', function () {
  8066. _self.switchSymbol(this, buttonWrapper, true);
  8067. menuWrapper.style.width =
  8068. menuWrapper.startWidth + 'px';
  8069. submenuWrapper.style.display = 'none';
  8070. }));
  8071. });
  8072. // select first submenu item
  8073. firstSubmenuItem = submenuWrapper
  8074. .querySelectorAll('li > .' + PREFIX + 'menu-item-btn')[0];
  8075. // replace current symbol, in main button, with submenu's button style
  8076. _self.switchSymbol(firstSubmenuItem, false);
  8077. };
  8078. /*
  8079. * Erase active class on all other buttons.
  8080. *
  8081. * @param {Array} - Array of HTML buttons
  8082. * @param {HTMLDOMElement} - Current HTML button
  8083. *
  8084. */
  8085. Toolbar.prototype.eraseActiveButtons = function (buttons, currentButton, submenuItems) {
  8086. [].forEach.call(buttons, function (btn) {
  8087. if (btn !== currentButton) {
  8088. btn.classList.remove(PREFIX + 'current');
  8089. btn.classList.remove(PREFIX + 'active');
  8090. submenuItems =
  8091. btn.querySelectorAll('.' + PREFIX + 'submenu-wrapper');
  8092. // hide submenu
  8093. if (submenuItems.length > 0) {
  8094. submenuItems[0].style.display = 'none';
  8095. }
  8096. }
  8097. });
  8098. };
  8099. /**
  8100. * Create single button. Consist of HTML elements `li`, `span`, and (if
  8101. * exists) submenu container.
  8102. * @private
  8103. * @param {Highcharts.HTMLDOMElement} target
  8104. * HTML reference, where button should be added
  8105. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions|Highcharts.StockToolsGuiDefinitionsOptions} options
  8106. * All options, by btnName refer to particular button
  8107. * @param {string} btnName
  8108. * of functionality mapped for specific class
  8109. * @param {Highcharts.Dictionary<string>} lang
  8110. * All titles, by btnName refer to particular button
  8111. * @return {Object} - references to all created HTML elements
  8112. */
  8113. Toolbar.prototype.addButton = function (target, options, btnName, lang) {
  8114. if (lang === void 0) { lang = {}; }
  8115. var btnOptions = options[btnName],
  8116. items = btnOptions.items,
  8117. classMapping = Toolbar.prototype.classMapping,
  8118. userClassName = btnOptions.className || '',
  8119. mainButton,
  8120. submenuArrow,
  8121. buttonWrapper;
  8122. // main button wrapper
  8123. buttonWrapper = createElement(LI, {
  8124. className: pick(classMapping[btnName], '') + ' ' + userClassName,
  8125. title: lang[btnName] || btnName
  8126. }, void 0, target);
  8127. // single button
  8128. mainButton = createElement(SPAN, {
  8129. className: PREFIX + 'menu-item-btn'
  8130. }, void 0, buttonWrapper);
  8131. // submenu
  8132. if (items && items.length) {
  8133. // arrow is a hook to show / hide submenu
  8134. submenuArrow = createElement(SPAN, {
  8135. className: PREFIX + 'submenu-item-arrow ' +
  8136. PREFIX + 'arrow-right'
  8137. }, void 0, buttonWrapper);
  8138. submenuArrow.style.backgroundImage = 'url(' +
  8139. this.iconsURL + 'arrow-bottom.svg)';
  8140. }
  8141. else {
  8142. mainButton.style.backgroundImage = 'url(' +
  8143. this.iconsURL + btnOptions.symbol + ')';
  8144. }
  8145. return {
  8146. buttonWrapper: buttonWrapper,
  8147. mainButton: mainButton,
  8148. submenuArrow: submenuArrow
  8149. };
  8150. };
  8151. /*
  8152. * Create navigation's HTML elements: container and arrows.
  8153. *
  8154. */
  8155. Toolbar.prototype.addNavigation = function () {
  8156. var stockToolbar = this,
  8157. wrapper = stockToolbar.wrapper;
  8158. // arrow wrapper
  8159. stockToolbar.arrowWrapper = createElement(DIV, {
  8160. className: PREFIX + 'arrow-wrapper'
  8161. });
  8162. stockToolbar.arrowUp = createElement(DIV, {
  8163. className: PREFIX + 'arrow-up'
  8164. }, void 0, stockToolbar.arrowWrapper);
  8165. stockToolbar.arrowUp.style.backgroundImage =
  8166. 'url(' + this.iconsURL + 'arrow-right.svg)';
  8167. stockToolbar.arrowDown = createElement(DIV, {
  8168. className: PREFIX + 'arrow-down'
  8169. }, void 0, stockToolbar.arrowWrapper);
  8170. stockToolbar.arrowDown.style.backgroundImage =
  8171. 'url(' + this.iconsURL + 'arrow-right.svg)';
  8172. wrapper.insertBefore(stockToolbar.arrowWrapper, wrapper.childNodes[0]);
  8173. // attach scroll events
  8174. stockToolbar.scrollButtons();
  8175. };
  8176. /*
  8177. * Add events to navigation (two arrows) which allows user to scroll
  8178. * top/down GUI buttons, if container's height is not enough.
  8179. *
  8180. */
  8181. Toolbar.prototype.scrollButtons = function () {
  8182. var targetY = 0,
  8183. _self = this,
  8184. wrapper = _self.wrapper,
  8185. toolbar = _self.toolbar,
  8186. step = 0.1 * wrapper.offsetHeight; // 0.1 = 10%
  8187. _self.eventsToUnbind.push(addEvent(_self.arrowUp, 'click',
  8188. function () {
  8189. if (targetY > 0) {
  8190. targetY -= step;
  8191. toolbar.style.marginTop = -targetY + 'px';
  8192. }
  8193. }));
  8194. _self.eventsToUnbind.push(addEvent(_self.arrowDown, 'click', function () {
  8195. if (wrapper.offsetHeight + targetY <=
  8196. toolbar.offsetHeight + step) {
  8197. targetY += step;
  8198. toolbar.style.marginTop = -targetY + 'px';
  8199. }
  8200. }));
  8201. };
  8202. /*
  8203. * Create stockTools HTML main elements.
  8204. *
  8205. */
  8206. Toolbar.prototype.createHTML = function () {
  8207. var stockToolbar = this,
  8208. chart = stockToolbar.chart,
  8209. guiOptions = stockToolbar.options,
  8210. container = chart.container,
  8211. navigation = chart.options.navigation,
  8212. bindingsClassName = navigation && navigation.bindingsClassName,
  8213. listWrapper,
  8214. toolbar;
  8215. // create main container
  8216. var wrapper = stockToolbar.wrapper = createElement(DIV, {
  8217. className: PREFIX + 'stocktools-wrapper ' +
  8218. guiOptions.className + ' ' + bindingsClassName
  8219. });
  8220. container.appendChild(wrapper);
  8221. // Mimic event behaviour of being outside chart.container
  8222. [
  8223. 'mousemove',
  8224. 'click',
  8225. 'touchstart'
  8226. ].forEach(function (eventType) {
  8227. addEvent(wrapper, eventType, function (e) {
  8228. return e.stopPropagation();
  8229. });
  8230. });
  8231. addEvent(wrapper, 'mouseover', function (e) {
  8232. return chart.pointer.onContainerMouseLeave(e);
  8233. });
  8234. // toolbar
  8235. stockToolbar.toolbar = toolbar = createElement(UL, {
  8236. className: PREFIX + 'stocktools-toolbar ' +
  8237. guiOptions.toolbarClassName
  8238. });
  8239. // add container for list of buttons
  8240. stockToolbar.listWrapper = listWrapper = createElement(DIV, {
  8241. className: PREFIX + 'menu-wrapper'
  8242. });
  8243. wrapper.insertBefore(listWrapper, wrapper.childNodes[0]);
  8244. listWrapper.insertBefore(toolbar, listWrapper.childNodes[0]);
  8245. stockToolbar.showHideToolbar();
  8246. // add navigation which allows user to scroll down / top GUI buttons
  8247. stockToolbar.addNavigation();
  8248. };
  8249. /**
  8250. * Function called in redraw verifies if the navigation should be visible.
  8251. * @private
  8252. */
  8253. Toolbar.prototype.showHideNavigatorion = function () {
  8254. // arrows
  8255. // 50px space for arrows
  8256. if (this.visible &&
  8257. this.toolbar.offsetHeight > (this.wrapper.offsetHeight - 50)) {
  8258. this.arrowWrapper.style.display = 'block';
  8259. }
  8260. else {
  8261. // reset margin if whole toolbar is visible
  8262. this.toolbar.style.marginTop = '0px';
  8263. // hide arrows
  8264. this.arrowWrapper.style.display = 'none';
  8265. }
  8266. };
  8267. /**
  8268. * Create button which shows or hides GUI toolbar.
  8269. * @private
  8270. */
  8271. Toolbar.prototype.showHideToolbar = function () {
  8272. var stockToolbar = this,
  8273. chart = this.chart,
  8274. wrapper = stockToolbar.wrapper,
  8275. toolbar = this.listWrapper,
  8276. submenu = this.submenu,
  8277. visible = this.visible,
  8278. showhideBtn;
  8279. // Show hide toolbar
  8280. this.showhideBtn = showhideBtn = createElement(DIV, {
  8281. className: PREFIX + 'toggle-toolbar ' + PREFIX + 'arrow-left'
  8282. }, void 0, wrapper);
  8283. showhideBtn.style.backgroundImage =
  8284. 'url(' + this.iconsURL + 'arrow-right.svg)';
  8285. if (!visible) {
  8286. // hide
  8287. if (submenu) {
  8288. submenu.style.display = 'none';
  8289. }
  8290. showhideBtn.style.left = '0px';
  8291. stockToolbar.visible = visible = false;
  8292. toolbar.classList.add(PREFIX + 'hide');
  8293. showhideBtn.classList.toggle(PREFIX + 'arrow-right');
  8294. wrapper.style.height = showhideBtn.offsetHeight + 'px';
  8295. }
  8296. else {
  8297. wrapper.style.height = '100%';
  8298. showhideBtn.style.top = getStyle(toolbar, 'padding-top') + 'px';
  8299. showhideBtn.style.left = (wrapper.offsetWidth +
  8300. getStyle(toolbar, 'padding-left')) + 'px';
  8301. }
  8302. // Toggle menu
  8303. stockToolbar.eventsToUnbind.push(addEvent(showhideBtn, 'click', function () {
  8304. chart.update({
  8305. stockTools: {
  8306. gui: {
  8307. visible: !visible,
  8308. placed: true
  8309. }
  8310. }
  8311. });
  8312. }));
  8313. };
  8314. /*
  8315. * In main GUI button, replace icon and class with submenu button's
  8316. * class / symbol.
  8317. *
  8318. * @param {HTMLDOMElement} - submenu button
  8319. * @param {Boolean} - true or false
  8320. *
  8321. */
  8322. Toolbar.prototype.switchSymbol = function (button, redraw) {
  8323. var buttonWrapper = button.parentNode,
  8324. buttonWrapperClass = buttonWrapper.classList.value,
  8325. // main button in first level og GUI
  8326. mainNavButton = buttonWrapper.parentNode.parentNode;
  8327. // if the button is disabled, don't do anything
  8328. if (buttonWrapperClass.indexOf('highcharts-disabled-btn') > -1) {
  8329. return;
  8330. }
  8331. // set class
  8332. mainNavButton.className = '';
  8333. if (buttonWrapperClass) {
  8334. mainNavButton.classList.add(buttonWrapperClass.trim());
  8335. }
  8336. // set icon
  8337. mainNavButton
  8338. .querySelectorAll('.' + PREFIX + 'menu-item-btn')[0]
  8339. .style.backgroundImage =
  8340. button.style.backgroundImage;
  8341. // set active class
  8342. if (redraw) {
  8343. this.selectButton(mainNavButton);
  8344. }
  8345. };
  8346. /*
  8347. * Set select state (active class) on button.
  8348. *
  8349. * @param {HTMLDOMElement} - button
  8350. *
  8351. */
  8352. Toolbar.prototype.selectButton = function (button) {
  8353. if (button.className.indexOf(activeClass) >= 0) {
  8354. button.classList.remove(activeClass);
  8355. }
  8356. else {
  8357. button.classList.add(activeClass);
  8358. }
  8359. };
  8360. /*
  8361. * Remove active class from all buttons except defined.
  8362. *
  8363. * @param {HTMLDOMElement} - button which should not be deactivated
  8364. *
  8365. */
  8366. Toolbar.prototype.unselectAllButtons = function (button) {
  8367. var activeButtons = button.parentNode
  8368. .querySelectorAll('.' + activeClass);
  8369. [].forEach.call(activeButtons, function (activeBtn) {
  8370. if (activeBtn !== button) {
  8371. activeBtn.classList.remove(activeClass);
  8372. }
  8373. });
  8374. };
  8375. /*
  8376. * Update GUI with given options.
  8377. *
  8378. * @param {Object} - general options for Stock Tools
  8379. */
  8380. Toolbar.prototype.update = function (options, redraw) {
  8381. merge(true, this.chart.options.stockTools, options);
  8382. this.destroy();
  8383. this.chart.setStockTools(options);
  8384. // If Stock Tools are updated, then bindings should be updated too:
  8385. if (this.chart.navigationBindings) {
  8386. this.chart.navigationBindings.update();
  8387. }
  8388. this.chart.isDirtyBox = true;
  8389. if (pick(redraw, true)) {
  8390. this.chart.redraw();
  8391. }
  8392. };
  8393. /**
  8394. * Destroy all HTML GUI elements.
  8395. * @private
  8396. */
  8397. Toolbar.prototype.destroy = function () {
  8398. var stockToolsDiv = this.wrapper,
  8399. parent = stockToolsDiv && stockToolsDiv.parentNode;
  8400. this.eventsToUnbind.forEach(function (unbinder) {
  8401. unbinder();
  8402. });
  8403. // Remove the empty element
  8404. if (parent) {
  8405. parent.removeChild(stockToolsDiv);
  8406. }
  8407. };
  8408. /**
  8409. * Redraw, GUI requires to verify if the navigation should be visible.
  8410. * @private
  8411. */
  8412. Toolbar.prototype.redraw = function () {
  8413. this.showHideNavigatorion();
  8414. };
  8415. Toolbar.prototype.getIconsURL = function () {
  8416. return this.chart.options.navigation.iconsURL ||
  8417. this.options.iconsURL ||
  8418. 'https://code.highcharts.com/9.1.1/gfx/stock-icons/';
  8419. };
  8420. return Toolbar;
  8421. }());
  8422. /**
  8423. * Mapping JSON fields to CSS classes.
  8424. * @private
  8425. */
  8426. Toolbar.prototype.classMapping = {
  8427. circle: PREFIX + 'circle-annotation',
  8428. rectangle: PREFIX + 'rectangle-annotation',
  8429. label: PREFIX + 'label-annotation',
  8430. segment: PREFIX + 'segment',
  8431. arrowSegment: PREFIX + 'arrow-segment',
  8432. ray: PREFIX + 'ray',
  8433. arrowRay: PREFIX + 'arrow-ray',
  8434. line: PREFIX + 'infinity-line',
  8435. arrowLine: PREFIX + 'arrow-infinity-line',
  8436. verticalLine: PREFIX + 'vertical-line',
  8437. horizontalLine: PREFIX + 'horizontal-line',
  8438. crooked3: PREFIX + 'crooked3',
  8439. crooked5: PREFIX + 'crooked5',
  8440. elliott3: PREFIX + 'elliott3',
  8441. elliott5: PREFIX + 'elliott5',
  8442. pitchfork: PREFIX + 'pitchfork',
  8443. fibonacci: PREFIX + 'fibonacci',
  8444. parallelChannel: PREFIX + 'parallel-channel',
  8445. measureX: PREFIX + 'measure-x',
  8446. measureY: PREFIX + 'measure-y',
  8447. measureXY: PREFIX + 'measure-xy',
  8448. verticalCounter: PREFIX + 'vertical-counter',
  8449. verticalLabel: PREFIX + 'vertical-label',
  8450. verticalArrow: PREFIX + 'vertical-arrow',
  8451. currentPriceIndicator: PREFIX + 'current-price-indicator',
  8452. indicators: PREFIX + 'indicators',
  8453. flagCirclepin: PREFIX + 'flag-circlepin',
  8454. flagDiamondpin: PREFIX + 'flag-diamondpin',
  8455. flagSquarepin: PREFIX + 'flag-squarepin',
  8456. flagSimplepin: PREFIX + 'flag-simplepin',
  8457. zoomX: PREFIX + 'zoom-x',
  8458. zoomY: PREFIX + 'zoom-y',
  8459. zoomXY: PREFIX + 'zoom-xy',
  8460. typeLine: PREFIX + 'series-type-line',
  8461. typeOHLC: PREFIX + 'series-type-ohlc',
  8462. typeCandlestick: PREFIX + 'series-type-candlestick',
  8463. fullScreen: PREFIX + 'full-screen',
  8464. toggleAnnotations: PREFIX + 'toggle-annotations',
  8465. saveChart: PREFIX + 'save-chart',
  8466. separator: PREFIX + 'separator'
  8467. };
  8468. extend(Chart.prototype, {
  8469. /**
  8470. * Verify if Toolbar should be added.
  8471. * @private
  8472. * @param {Highcharts.StockToolsOptions} - chart options
  8473. */
  8474. setStockTools: function (options) {
  8475. var chartOptions = this.options,
  8476. lang = chartOptions.lang,
  8477. guiOptions = merge(chartOptions.stockTools && chartOptions.stockTools.gui,
  8478. options && options.gui),
  8479. langOptions = lang && lang.stockTools && lang.stockTools.gui;
  8480. this.stockTools = new Toolbar(guiOptions, langOptions, this);
  8481. if (this.stockTools.guiEnabled) {
  8482. this.isDirtyBox = true;
  8483. }
  8484. }
  8485. });
  8486. // Comunication with bindings:
  8487. addEvent(NavigationBindings, 'selectButton', function (event) {
  8488. var button = event.button,
  8489. className = PREFIX + 'submenu-wrapper',
  8490. gui = this.chart.stockTools;
  8491. if (gui && gui.guiEnabled) {
  8492. // Unslect other active buttons
  8493. gui.unselectAllButtons(event.button);
  8494. // If clicked on a submenu, select state for it's parent
  8495. if (button.parentNode.className.indexOf(className) >= 0) {
  8496. button = button.parentNode.parentNode;
  8497. }
  8498. // Set active class on the current button
  8499. gui.selectButton(button);
  8500. }
  8501. });
  8502. addEvent(NavigationBindings, 'deselectButton', function (event) {
  8503. var button = event.button,
  8504. className = PREFIX + 'submenu-wrapper',
  8505. gui = this.chart.stockTools;
  8506. if (gui && gui.guiEnabled) {
  8507. // If deselecting a button from a submenu, select state for it's parent
  8508. if (button.parentNode.className.indexOf(className) >= 0) {
  8509. button = button.parentNode.parentNode;
  8510. }
  8511. gui.selectButton(button);
  8512. }
  8513. });
  8514. // Check if the correct price indicator button is displayed, #15029.
  8515. addEvent(Chart, 'render', function () {
  8516. var chart = this,
  8517. stockTools = chart.stockTools,
  8518. button = stockTools &&
  8519. stockTools.toolbar &&
  8520. stockTools.toolbar.querySelector('.highcharts-current-price-indicator');
  8521. // Change the initial button background.
  8522. if (stockTools && chart.navigationBindings && chart.options.series && button) {
  8523. if (chart.navigationBindings.constructor.prototype.utils.isPriceIndicatorEnabled(chart.series)) {
  8524. button.firstChild.style['background-image'] =
  8525. 'url("' + stockTools.getIconsURL() + 'current-price-hide.svg")';
  8526. }
  8527. else {
  8528. button.firstChild.style['background-image'] =
  8529. 'url("' + stockTools.getIconsURL() + 'current-price-show.svg")';
  8530. }
  8531. }
  8532. });
  8533. H.Toolbar = Toolbar;
  8534. return H.Toolbar;
  8535. });
  8536. _registerModule(_modules, 'masters/modules/stock-tools.src.js', [], function () {
  8537. });
  8538. }));