2
0

annotations-advanced.src.js 346 KB

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