annotations-advanced.src.js 349 KB

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