annotations-advanced.src.js 336 KB

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