annotations-advanced.src.js 336 KB

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