stock-tools.src.js 350 KB

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