stock-tools.src.js 346 KB

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