annotations.src.js 242 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698
  1. /**
  2. * @license Highcharts JS v8.2.0 (2020-08-20)
  3. *
  4. * Annotations module
  5. *
  6. * (c) 2009-2019 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/annotations', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Extensions/Annotations/Mixins/EventEmitterMixin.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  35. *
  36. * */
  37. var addEvent = U.addEvent,
  38. fireEvent = U.fireEvent,
  39. objectEach = U.objectEach,
  40. pick = U.pick,
  41. removeEvent = U.removeEvent;
  42. /* eslint-disable valid-jsdoc */
  43. /**
  44. * It provides methods for:
  45. * - adding and handling DOM events and a drag event,
  46. * - mapping a mouse move event to the distance between two following events.
  47. * The units of the distance are specific to a transformation,
  48. * e.g. for rotation they are radians, for scaling they are scale factors.
  49. *
  50. * @private
  51. * @mixin
  52. * @memberOf Annotation
  53. */
  54. var eventEmitterMixin = {
  55. /**
  56. * Add emitter events.
  57. */
  58. addEvents: function () {
  59. var emitter = this,
  60. addMouseDownEvent = function (element) {
  61. addEvent(element,
  62. H.isTouchDevice ? 'touchstart' : 'mousedown',
  63. function (e) {
  64. emitter.onMouseDown(e);
  65. });
  66. };
  67. addMouseDownEvent(this.graphic.element);
  68. (emitter.labels || []).forEach(function (label) {
  69. if (label.options.useHTML && label.graphic.text) {
  70. // Mousedown event bound to HTML element (#13070).
  71. addMouseDownEvent(label.graphic.text.element);
  72. }
  73. });
  74. objectEach(emitter.options.events, function (event, type) {
  75. var eventHandler = function (e) {
  76. if (type !== 'click' || !emitter.cancelClick) {
  77. event.call(emitter,
  78. emitter.chart.pointer.normalize(e),
  79. emitter.target);
  80. }
  81. };
  82. if ((emitter.nonDOMEvents || []).indexOf(type) === -1) {
  83. emitter.graphic.on(type, eventHandler);
  84. }
  85. else {
  86. addEvent(emitter, type, eventHandler);
  87. }
  88. });
  89. if (emitter.options.draggable) {
  90. addEvent(emitter, 'drag', emitter.onDrag);
  91. if (!emitter.graphic.renderer.styledMode) {
  92. var cssPointer_1 = {
  93. cursor: {
  94. x: 'ew-resize',
  95. y: 'ns-resize',
  96. xy: 'move'
  97. }[emitter.options.draggable]
  98. };
  99. emitter.graphic.css(cssPointer_1);
  100. (emitter.labels || []).forEach(function (label) {
  101. if (label.options.useHTML && label.graphic.text) {
  102. label.graphic.text.css(cssPointer_1);
  103. }
  104. });
  105. }
  106. }
  107. if (!emitter.isUpdating) {
  108. fireEvent(emitter, 'add');
  109. }
  110. },
  111. /**
  112. * Remove emitter document events.
  113. */
  114. removeDocEvents: function () {
  115. if (this.removeDrag) {
  116. this.removeDrag = this.removeDrag();
  117. }
  118. if (this.removeMouseUp) {
  119. this.removeMouseUp = this.removeMouseUp();
  120. }
  121. },
  122. /**
  123. * Mouse down handler.
  124. */
  125. onMouseDown: function (e) {
  126. var emitter = this,
  127. pointer = emitter.chart.pointer,
  128. prevChartX,
  129. prevChartY;
  130. if (e.preventDefault) {
  131. e.preventDefault();
  132. }
  133. // On right click, do nothing:
  134. if (e.button === 2) {
  135. return;
  136. }
  137. e = pointer.normalize(e);
  138. prevChartX = e.chartX;
  139. prevChartY = e.chartY;
  140. emitter.cancelClick = false;
  141. emitter.chart.hasDraggedAnnotation = true;
  142. emitter.removeDrag = addEvent(H.doc, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
  143. emitter.hasDragged = true;
  144. e = pointer.normalize(e);
  145. e.prevChartX = prevChartX;
  146. e.prevChartY = prevChartY;
  147. fireEvent(emitter, 'drag', e);
  148. prevChartX = e.chartX;
  149. prevChartY = e.chartY;
  150. });
  151. emitter.removeMouseUp = addEvent(H.doc, H.isTouchDevice ? 'touchend' : 'mouseup', function (e) {
  152. emitter.cancelClick = emitter.hasDragged;
  153. emitter.hasDragged = false;
  154. emitter.chart.hasDraggedAnnotation = false;
  155. // ControlPoints vs Annotation:
  156. fireEvent(pick(emitter.target, emitter), 'afterUpdate');
  157. emitter.onMouseUp(e);
  158. });
  159. },
  160. /**
  161. * Mouse up handler.
  162. */
  163. onMouseUp: function (_e) {
  164. var chart = this.chart,
  165. annotation = this.target || this,
  166. annotationsOptions = chart.options.annotations,
  167. index = chart.annotations.indexOf(annotation);
  168. this.removeDocEvents();
  169. annotationsOptions[index] = annotation.options;
  170. },
  171. /**
  172. * Drag and drop event. All basic annotations should share this
  173. * capability as well as the extended ones.
  174. */
  175. onDrag: function (e) {
  176. if (this.chart.isInsidePlot(e.chartX - this.chart.plotLeft, e.chartY - this.chart.plotTop)) {
  177. var translation = this.mouseMoveToTranslation(e);
  178. if (this.options.draggable === 'x') {
  179. translation.y = 0;
  180. }
  181. if (this.options.draggable === 'y') {
  182. translation.x = 0;
  183. }
  184. if (this.points.length) {
  185. this.translate(translation.x, translation.y);
  186. }
  187. else {
  188. this.shapes.forEach(function (shape) {
  189. shape.translate(translation.x, translation.y);
  190. });
  191. this.labels.forEach(function (label) {
  192. label.translate(translation.x, translation.y);
  193. });
  194. }
  195. this.redraw(false);
  196. }
  197. },
  198. /**
  199. * Map mouse move event to the radians.
  200. */
  201. mouseMoveToRadians: function (e, cx, cy) {
  202. var prevDy = e.prevChartY - cy,
  203. prevDx = e.prevChartX - cx,
  204. dy = e.chartY - cy,
  205. dx = e.chartX - cx,
  206. temp;
  207. if (this.chart.inverted) {
  208. temp = prevDx;
  209. prevDx = prevDy;
  210. prevDy = temp;
  211. temp = dx;
  212. dx = dy;
  213. dy = temp;
  214. }
  215. return Math.atan2(dy, dx) - Math.atan2(prevDy, prevDx);
  216. },
  217. /**
  218. * Map mouse move event to the distance between two following events.
  219. */
  220. mouseMoveToTranslation: function (e) {
  221. var dx = e.chartX - e.prevChartX,
  222. dy = e.chartY - e.prevChartY,
  223. temp;
  224. if (this.chart.inverted) {
  225. temp = dy;
  226. dy = dx;
  227. dx = temp;
  228. }
  229. return {
  230. x: dx,
  231. y: dy
  232. };
  233. },
  234. /**
  235. * Map mouse move to the scale factors.
  236. *
  237. * @param {Object} e event
  238. * @param {number} cx center x
  239. * @param {number} cy center y
  240. **/
  241. mouseMoveToScale: function (e, cx, cy) {
  242. var prevDx = e.prevChartX - cx,
  243. prevDy = e.prevChartY - cy,
  244. dx = e.chartX - cx,
  245. dy = e.chartY - cy,
  246. sx = (dx || 1) / (prevDx || 1),
  247. sy = (dy || 1) / (prevDy || 1),
  248. temp;
  249. if (this.chart.inverted) {
  250. temp = sy;
  251. sy = sx;
  252. sx = temp;
  253. }
  254. return {
  255. x: sx,
  256. y: sy
  257. };
  258. },
  259. /**
  260. * Destroy the event emitter.
  261. */
  262. destroy: function () {
  263. this.removeDocEvents();
  264. removeEvent(this);
  265. this.hcEvents = null;
  266. }
  267. };
  268. return eventEmitterMixin;
  269. });
  270. _registerModule(_modules, 'Extensions/Annotations/ControlPoint.js', [_modules['Core/Utilities.js'], _modules['Extensions/Annotations/Mixins/EventEmitterMixin.js']], function (U, eventEmitterMixin) {
  271. /* *
  272. *
  273. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  274. *
  275. * */
  276. /**
  277. * Callback to modify annotation's possitioner controls.
  278. *
  279. * @callback Highcharts.AnnotationControlPointPositionerFunction
  280. * @param {Highcharts.AnnotationControlPoint} this
  281. * @param {Highcharts.AnnotationControllable} target
  282. * @return {Highcharts.PositionObject}
  283. */
  284. var extend = U.extend,
  285. merge = U.merge,
  286. pick = U.pick;
  287. /* eslint-disable no-invalid-this, valid-jsdoc */
  288. /**
  289. * A control point class which is a connection between controllable
  290. * transform methods and a user actions.
  291. *
  292. * @requires modules/annotations
  293. *
  294. * @class
  295. * @name Highcharts.AnnotationControlPoint
  296. *
  297. * @hideconstructor
  298. *
  299. * @param {Highcharts.Chart} chart
  300. * A chart instance.
  301. *
  302. * @param {Highcharts.AnnotationControllable} target
  303. * A controllable instance which is a target for a control point.
  304. *
  305. * @param {Highcharts.AnnotationControlPointOptionsObject} options
  306. * An options object.
  307. *
  308. * @param {number} [index]
  309. * Point index.
  310. */
  311. var ControlPoint = /** @class */ (function () {
  312. function ControlPoint(chart, target, options, index) {
  313. /**
  314. *
  315. * Properties
  316. *
  317. */
  318. this.addEvents = eventEmitterMixin.addEvents;
  319. this.graphic = void 0;
  320. this.mouseMoveToRadians = eventEmitterMixin.mouseMoveToRadians;
  321. this.mouseMoveToScale = eventEmitterMixin.mouseMoveToScale;
  322. this.mouseMoveToTranslation = eventEmitterMixin.mouseMoveToTranslation;
  323. this.onDrag = eventEmitterMixin.onDrag;
  324. this.onMouseDown = eventEmitterMixin.onMouseDown;
  325. this.onMouseUp = eventEmitterMixin.onMouseUp;
  326. this.removeDocEvents = eventEmitterMixin.removeDocEvents;
  327. /**
  328. *
  329. * Functions
  330. *
  331. */
  332. /**
  333. * List of events for `anntation.options.events` that should not be
  334. * added to `annotation.graphic` but to the `annotation`.
  335. * @private
  336. * @name Highcharts.AnnotationControlPoint#nonDOMEvents
  337. * @type {Array<string>}
  338. */
  339. this.nonDOMEvents = ['drag'];
  340. this.chart = chart;
  341. this.target = target;
  342. this.options = options;
  343. this.index = pick(options.index, index);
  344. }
  345. /**
  346. * Set the visibility of the control point.
  347. *
  348. * @function Highcharts.AnnotationControlPoint#setVisibility
  349. *
  350. * @param {boolean} visible
  351. * Visibility of the control point.
  352. *
  353. * @return {void}
  354. */
  355. ControlPoint.prototype.setVisibility = function (visible) {
  356. this.graphic.attr('visibility', visible ? 'visible' : 'hidden');
  357. this.options.visible = visible;
  358. };
  359. /**
  360. * Render the control point.
  361. * @private
  362. */
  363. ControlPoint.prototype.render = function () {
  364. var chart = this.chart,
  365. options = this.options;
  366. this.graphic = chart.renderer
  367. .symbol(options.symbol, 0, 0, options.width, options.height)
  368. .add(chart.controlPointsGroup)
  369. .css(options.style);
  370. this.setVisibility(options.visible);
  371. // npm test -- --tests "highcharts/annotations-advanced/*"
  372. this.addEvents();
  373. };
  374. /**
  375. * Redraw the control point.
  376. * @private
  377. * @param {boolean} [animation]
  378. */
  379. ControlPoint.prototype.redraw = function (animation) {
  380. this.graphic[animation ? 'animate' : 'attr'](this.options.positioner.call(this, this.target));
  381. };
  382. /**
  383. * Destroy the control point.
  384. * @private
  385. */
  386. ControlPoint.prototype.destroy = function () {
  387. eventEmitterMixin.destroy.call(this);
  388. if (this.graphic) {
  389. this.graphic = this.graphic.destroy();
  390. }
  391. this.chart = null;
  392. this.target = null;
  393. this.options = null;
  394. };
  395. /**
  396. * Update the control point.
  397. *
  398. * @function Highcharts.AnnotationControlPoint#update
  399. *
  400. * @param {Partial<Highcharts.AnnotationControlPointOptionsObject>} userOptions
  401. * New options for the control point.
  402. *
  403. * @return {void}
  404. */
  405. ControlPoint.prototype.update = function (userOptions) {
  406. var chart = this.chart,
  407. target = this.target,
  408. index = this.index,
  409. options = merge(true,
  410. this.options,
  411. userOptions);
  412. this.destroy();
  413. this.constructor(chart, target, options, index);
  414. this.render(chart.controlPointsGroup);
  415. this.redraw();
  416. };
  417. return ControlPoint;
  418. }());
  419. return ControlPoint;
  420. });
  421. _registerModule(_modules, 'Extensions/Annotations/MockPoint.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  422. /* *
  423. *
  424. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  425. *
  426. * */
  427. /**
  428. * @private
  429. * @interface Highcharts.AnnotationMockLabelOptionsObject
  430. */ /**
  431. * Point instance of the point.
  432. * @name Highcharts.AnnotationMockLabelOptionsObject#point
  433. * @type {Highcharts.AnnotationMockPoint}
  434. */ /**
  435. * X value translated to x axis scale.
  436. * @name Highcharts.AnnotationMockLabelOptionsObject#x
  437. * @type {number|null}
  438. */ /**
  439. * Y value translated to y axis scale.
  440. * @name Highcharts.AnnotationMockLabelOptionsObject#y
  441. * @type {number|null}
  442. */
  443. /**
  444. * A mock series instance imitating a real series from a real point.
  445. * @private
  446. * @interface Highcharts.AnnotationMockSeries
  447. */ /**
  448. * Whether a series is visible.
  449. * @name Highcharts.AnnotationMockSeries#visible
  450. * @type {boolean}
  451. */ /**
  452. * A chart instance.
  453. * @name Highcharts.AnnotationMockSeries#chart
  454. * @type {Highcharts.Chart}
  455. */ /**
  456. * @name Highcharts.AnnotationMockSeries#getPlotBox
  457. * @type {Function}
  458. */
  459. /**
  460. * Indicates if this is a mock point for an annotation.
  461. * @name Highcharts.Point#mock
  462. * @type {boolean|undefined}
  463. */
  464. var defined = U.defined,
  465. extend = U.extend,
  466. fireEvent = U.fireEvent;
  467. /* eslint-disable no-invalid-this, valid-jsdoc */
  468. /**
  469. * A trimmed point object which imitates {@link Highchart.Point} class. It is
  470. * created when there is a need of pointing to some chart's position using axis
  471. * values or pixel values
  472. *
  473. * @requires modules/annotations
  474. *
  475. * @private
  476. * @class
  477. * @name Highcharts.AnnotationMockPoint
  478. *
  479. * @hideconstructor
  480. *
  481. * @param {Highcharts.Chart} chart
  482. * The chart instance.
  483. *
  484. * @param {Highcharts.AnnotationControllable|null} target
  485. * The related controllable.
  486. *
  487. * @param {Highcharts.AnnotationMockPointOptionsObject|Function} options
  488. * The options object.
  489. */
  490. var MockPoint = /** @class */ (function () {
  491. function MockPoint(chart, target, options) {
  492. this.isInside = void 0;
  493. this.plotX = void 0;
  494. this.plotY = void 0;
  495. this.x = void 0;
  496. this.y = void 0;
  497. /* *
  498. *
  499. * Functions
  500. *
  501. * */
  502. /**
  503. * A flag indicating that a point is not the real one.
  504. *
  505. * @type {boolean}
  506. * @default true
  507. */
  508. this.mock = true;
  509. /**
  510. * A mock series instance imitating a real series from a real point.
  511. *
  512. * @name Annotation.AnnotationMockPoint#series
  513. * @type {Highcharts.AnnotationMockSeries}
  514. */
  515. this.series = {
  516. visible: true,
  517. chart: chart,
  518. getPlotBox: H.Series.prototype.getPlotBox
  519. };
  520. /**
  521. * @name Annotation.AnnotationMockPoint#target
  522. * @type {Highcharts.AnnotationControllable|null}
  523. */
  524. this.target = target || null;
  525. /**
  526. * Options for the mock point.
  527. *
  528. * @name Annotation.AnnotationMockPoint#options
  529. * @type {Highcharts.AnnotationsMockPointOptionsObject}
  530. */
  531. this.options = options;
  532. /**
  533. * If an xAxis is set it represents the point's value in terms of the
  534. * xAxis.
  535. *
  536. * @name Annotation.AnnotationMockPoint#x
  537. * @type {number|undefined}
  538. */
  539. /**
  540. * If an yAxis is set it represents the point's value in terms of the
  541. * yAxis.
  542. *
  543. * @name Annotation.AnnotationMockPoint#y
  544. * @type {number|undefined}
  545. */
  546. /**
  547. * It represents the point's pixel x coordinate relative to its plot
  548. * box.
  549. *
  550. * @name Annotation.AnnotationMockPoint#plotX
  551. * @type {number|undefined}
  552. */
  553. /**
  554. * It represents the point's pixel y position relative to its plot box.
  555. *
  556. * @name Annotation.AnnotationMockPoint#plotY
  557. * @type {number|undefined}
  558. */
  559. /**
  560. * Whether the point is inside the plot box.
  561. *
  562. * @name Annotation.AnnotationMockPoint#isInside
  563. * @type {boolean|undefined}
  564. */
  565. this.applyOptions(this.getOptions());
  566. }
  567. /**
  568. * Create a mock point from a real Highcharts point.
  569. *
  570. * @private
  571. * @static
  572. *
  573. * @param {Highcharts.Point} point
  574. *
  575. * @return {Highcharts.AnnotationMockPoint}
  576. * A mock point instance.
  577. */
  578. MockPoint.fromPoint = function (point) {
  579. return new MockPoint(point.series.chart, null, {
  580. x: point.x,
  581. y: point.y,
  582. xAxis: point.series.xAxis,
  583. yAxis: point.series.yAxis
  584. });
  585. };
  586. /**
  587. * Get the pixel position from the point like object.
  588. *
  589. * @private
  590. * @static
  591. *
  592. * @param {Highcharts.AnnotationPointType} point
  593. *
  594. * @param {boolean} [paneCoordinates]
  595. * whether the pixel position should be relative
  596. *
  597. * @return {Highcharts.PositionObject} pixel position
  598. */
  599. MockPoint.pointToPixels = function (point, paneCoordinates) {
  600. var series = point.series,
  601. chart = series.chart,
  602. x = point.plotX,
  603. y = point.plotY,
  604. plotBox;
  605. if (chart.inverted) {
  606. if (point.mock) {
  607. x = point.plotY;
  608. y = point.plotX;
  609. }
  610. else {
  611. x = chart.plotWidth - point.plotY;
  612. y = chart.plotHeight - point.plotX;
  613. }
  614. }
  615. if (series && !paneCoordinates) {
  616. plotBox = series.getPlotBox();
  617. x += plotBox.translateX;
  618. y += plotBox.translateY;
  619. }
  620. return {
  621. x: x,
  622. y: y
  623. };
  624. };
  625. /**
  626. * Get fresh mock point options from the point like object.
  627. *
  628. * @private
  629. * @static
  630. *
  631. * @param {Highcharts.AnnotationPointType} point
  632. *
  633. * @return {Highcharts.AnnotationMockPointOptionsObject}
  634. * A mock point's options.
  635. */
  636. MockPoint.pointToOptions = function (point) {
  637. return {
  638. x: point.x,
  639. y: point.y,
  640. xAxis: point.series.xAxis,
  641. yAxis: point.series.yAxis
  642. };
  643. };
  644. /**
  645. * Check if the point has dynamic options.
  646. * @private
  647. * @return {boolean}
  648. * A positive flag if the point has dynamic options.
  649. */
  650. MockPoint.prototype.hasDynamicOptions = function () {
  651. return typeof this.options === 'function';
  652. };
  653. /**
  654. * Get the point's options.
  655. * @private
  656. * @return {Highcharts.AnnotationMockPointOptionsObject}
  657. * The mock point's options.
  658. */
  659. MockPoint.prototype.getOptions = function () {
  660. return this.hasDynamicOptions() ?
  661. this.options(this.target) :
  662. this.options;
  663. };
  664. /**
  665. * Apply options for the point.
  666. * @private
  667. * @param {Highcharts.AnnotationMockPointOptionsObject} options
  668. */
  669. MockPoint.prototype.applyOptions = function (options) {
  670. this.command = options.command;
  671. this.setAxis(options, 'x');
  672. this.setAxis(options, 'y');
  673. this.refresh();
  674. };
  675. /**
  676. * Set x or y axis.
  677. * @private
  678. * @param {Highcharts.AnnotationMockPointOptionsObject} options
  679. * @param {string} xOrY
  680. * 'x' or 'y' string literal
  681. */
  682. MockPoint.prototype.setAxis = function (options, xOrY) {
  683. var axisName = (xOrY + 'Axis'),
  684. axisOptions = options[axisName],
  685. chart = this.series.chart;
  686. this.series[axisName] =
  687. axisOptions instanceof H.Axis ?
  688. axisOptions :
  689. defined(axisOptions) ?
  690. (chart[axisName][axisOptions] ||
  691. chart.get(axisOptions)) :
  692. null;
  693. };
  694. /**
  695. * Transform the mock point to an anchor (relative position on the chart).
  696. * @private
  697. * @return {Array<number>}
  698. * A quadruple of numbers which denotes x, y, width and height of the box
  699. **/
  700. MockPoint.prototype.toAnchor = function () {
  701. var anchor = [this.plotX,
  702. this.plotY, 0, 0];
  703. if (this.series.chart.inverted) {
  704. anchor[0] = this.plotY;
  705. anchor[1] = this.plotX;
  706. }
  707. return anchor;
  708. };
  709. /**
  710. * Returns a label config object - the same as
  711. * Highcharts.Point.prototype.getLabelConfig
  712. * @private
  713. * @return {Highcharts.AnnotationMockLabelOptionsObject} the point's label config
  714. */
  715. MockPoint.prototype.getLabelConfig = function () {
  716. return {
  717. x: this.x,
  718. y: this.y,
  719. point: this
  720. };
  721. };
  722. /**
  723. * Check if the point is inside its pane.
  724. * @private
  725. * @return {boolean} A flag indicating whether the point is inside the pane.
  726. */
  727. MockPoint.prototype.isInsidePlot = function () {
  728. var plotX = this.plotX,
  729. plotY = this.plotY,
  730. xAxis = this.series.xAxis,
  731. yAxis = this.series.yAxis,
  732. e = {
  733. x: plotX,
  734. y: plotY,
  735. isInsidePlot: true
  736. };
  737. if (xAxis) {
  738. e.isInsidePlot = defined(plotX) && plotX >= 0 && plotX <= xAxis.len;
  739. }
  740. if (yAxis) {
  741. e.isInsidePlot =
  742. e.isInsidePlot &&
  743. defined(plotY) &&
  744. plotY >= 0 && plotY <= yAxis.len;
  745. }
  746. fireEvent(this.series.chart, 'afterIsInsidePlot', e);
  747. return e.isInsidePlot;
  748. };
  749. /**
  750. * Refresh point values and coordinates based on its options.
  751. * @private
  752. */
  753. MockPoint.prototype.refresh = function () {
  754. var series = this.series,
  755. xAxis = series.xAxis,
  756. yAxis = series.yAxis,
  757. options = this.getOptions();
  758. if (xAxis) {
  759. this.x = options.x;
  760. this.plotX = xAxis.toPixels(options.x, true);
  761. }
  762. else {
  763. this.x = null;
  764. this.plotX = options.x;
  765. }
  766. if (yAxis) {
  767. this.y = options.y;
  768. this.plotY = yAxis.toPixels(options.y, true);
  769. }
  770. else {
  771. this.y = null;
  772. this.plotY = options.y;
  773. }
  774. this.isInside = this.isInsidePlot();
  775. };
  776. /**
  777. * Translate the point.
  778. *
  779. * @private
  780. *
  781. * @param {number|undefined} cx
  782. * Origin x transformation.
  783. *
  784. * @param {number|undefined} cy
  785. * Origin y transformation.
  786. *
  787. * @param {number} dx
  788. * Translation for x coordinate.
  789. *
  790. * @param {number} dy
  791. * Translation for y coordinate.
  792. **/
  793. MockPoint.prototype.translate = function (_cx, _cy, dx, dy) {
  794. if (!this.hasDynamicOptions()) {
  795. this.plotX += dx;
  796. this.plotY += dy;
  797. this.refreshOptions();
  798. }
  799. };
  800. /**
  801. * Scale the point.
  802. *
  803. * @private
  804. *
  805. * @param {number} cx
  806. * Origin x transformation.
  807. *
  808. * @param {number} cy
  809. * Origin y transformation.
  810. *
  811. * @param {number} sx
  812. * Scale factor x.
  813. *
  814. * @param {number} sy
  815. * Scale factor y.
  816. */
  817. MockPoint.prototype.scale = function (cx, cy, sx, sy) {
  818. if (!this.hasDynamicOptions()) {
  819. var x = this.plotX * sx,
  820. y = this.plotY * sy,
  821. tx = (1 - sx) * cx,
  822. ty = (1 - sy) * cy;
  823. this.plotX = tx + x;
  824. this.plotY = ty + y;
  825. this.refreshOptions();
  826. }
  827. };
  828. /**
  829. * Rotate the point.
  830. * @private
  831. * @param {number} cx origin x rotation
  832. * @param {number} cy origin y rotation
  833. * @param {number} radians
  834. */
  835. MockPoint.prototype.rotate = function (cx, cy, radians) {
  836. if (!this.hasDynamicOptions()) {
  837. var cos = Math.cos(radians),
  838. sin = Math.sin(radians),
  839. x = this.plotX,
  840. y = this.plotY,
  841. tx,
  842. ty;
  843. x -= cx;
  844. y -= cy;
  845. tx = x * cos - y * sin;
  846. ty = x * sin + y * cos;
  847. this.plotX = tx + cx;
  848. this.plotY = ty + cy;
  849. this.refreshOptions();
  850. }
  851. };
  852. /**
  853. * Refresh point options based on its plot coordinates.
  854. * @private
  855. */
  856. MockPoint.prototype.refreshOptions = function () {
  857. var series = this.series,
  858. xAxis = series.xAxis,
  859. yAxis = series.yAxis;
  860. this.x = this.options.x = xAxis ?
  861. this.options.x = xAxis.toValue(this.plotX, true) :
  862. this.plotX;
  863. this.y = this.options.y = yAxis ?
  864. yAxis.toValue(this.plotY, true) :
  865. this.plotY;
  866. };
  867. return MockPoint;
  868. }());
  869. return MockPoint;
  870. });
  871. _registerModule(_modules, 'Extensions/Annotations/Mixins/ControllableMixin.js', [_modules['Extensions/Annotations/ControlPoint.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Tooltip.js'], _modules['Core/Utilities.js']], function (ControlPoint, MockPoint, Tooltip, U) {
  872. /* *
  873. *
  874. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  875. *
  876. * */
  877. var isObject = U.isObject,
  878. isString = U.isString,
  879. merge = U.merge,
  880. splat = U.splat;
  881. /**
  882. * An object which denots a controllable's anchor positions - relative and
  883. * absolute.
  884. *
  885. * @private
  886. * @interface Highcharts.AnnotationAnchorObject
  887. */ /**
  888. * Relative to the plot area position
  889. * @name Highcharts.AnnotationAnchorObject#relativePosition
  890. * @type {Highcharts.BBoxObject}
  891. */ /**
  892. * Absolute position
  893. * @name Highcharts.AnnotationAnchorObject#absolutePosition
  894. * @type {Highcharts.BBoxObject}
  895. */
  896. /**
  897. * @interface Highcharts.AnnotationControllable
  898. */ /**
  899. * @name Highcharts.AnnotationControllable#annotation
  900. * @type {Highcharts.Annotation}
  901. */ /**
  902. * @name Highcharts.AnnotationControllable#chart
  903. * @type {Highcharts.Chart}
  904. */ /**
  905. * @name Highcharts.AnnotationControllable#collection
  906. * @type {string}
  907. */ /**
  908. * @private
  909. * @name Highcharts.AnnotationControllable#controlPoints
  910. * @type {Array<Highcharts.AnnotationControlPoint>}
  911. */ /**
  912. * @name Highcharts.AnnotationControllable#points
  913. * @type {Array<Highcharts.Point>}
  914. */
  915. /* eslint-disable no-invalid-this, valid-jsdoc */
  916. /**
  917. * It provides methods for handling points, control points
  918. * and points transformations.
  919. *
  920. * @private
  921. * @mixin
  922. * @name Highcharts.AnnotationControllableMixin
  923. */
  924. var controllableMixin = {
  925. /**
  926. * Init the controllable
  927. */
  928. init: function (annotation,
  929. options,
  930. index) {
  931. this.annotation = annotation;
  932. this.chart = annotation.chart;
  933. this.options = options;
  934. this.points = [];
  935. this.controlPoints = [];
  936. this.index = index;
  937. this.linkPoints();
  938. this.addControlPoints();
  939. },
  940. /**
  941. * Redirect attr usage on the controllable graphic element.
  942. */
  943. attr: function () {
  944. this.graphic.attr.apply(this.graphic, arguments);
  945. },
  946. /**
  947. * Get the controllable's points options.
  948. *
  949. * @return {Array<Highcharts.PointOptionsObject>}
  950. * An array of points' options.
  951. */
  952. getPointsOptions: function () {
  953. var options = this.options;
  954. return (options.points || (options.point && splat(options.point)));
  955. },
  956. /**
  957. * Utility function for mapping item's options
  958. * to element's attribute
  959. *
  960. * @param {Highcharts.AnnotationsLabelsOptions|Highcharts.AnnotationsShapesOptions} options
  961. *
  962. * @return {Highcharts.SVGAttributes}
  963. * Mapped options.
  964. */
  965. attrsFromOptions: function (options) {
  966. var map = this.constructor.attrsMap,
  967. attrs = {},
  968. key,
  969. mappedKey,
  970. styledMode = this.chart.styledMode;
  971. for (key in options) { // eslint-disable-line guard-for-in
  972. mappedKey = map[key];
  973. if (mappedKey &&
  974. (!styledMode ||
  975. ['fill', 'stroke', 'stroke-width']
  976. .indexOf(mappedKey) === -1)) {
  977. attrs[mappedKey] = options[key];
  978. }
  979. }
  980. return attrs;
  981. },
  982. /**
  983. * Returns object which denotes anchor position - relative and absolute.
  984. *
  985. * @param {Highcharts.AnnotationPointType} point
  986. * A point like object.
  987. *
  988. * @return {Highcharts.AnnotationAnchorObject} a controllable anchor
  989. */
  990. anchor: function (point) {
  991. var plotBox = point.series.getPlotBox(),
  992. box = point.mock ?
  993. point.toAnchor() :
  994. Tooltip.prototype.getAnchor.call({
  995. chart: point.series.chart
  996. },
  997. point),
  998. anchor = {
  999. x: box[0] + (this.options.x || 0),
  1000. y: box[1] + (this.options.y || 0),
  1001. height: box[2] || 0,
  1002. width: box[3] || 0
  1003. };
  1004. return {
  1005. relativePosition: anchor,
  1006. absolutePosition: merge(anchor, {
  1007. x: anchor.x + plotBox.translateX,
  1008. y: anchor.y + plotBox.translateY
  1009. })
  1010. };
  1011. },
  1012. /**
  1013. * Map point's options to a point-like object.
  1014. *
  1015. * @param {string|Function|Highcharts.AnnotationMockPointOptionsObject|Highcharts.AnnotationPointType} pointOptions
  1016. * Point's options.
  1017. *
  1018. * @param {Highcharts.AnnotationPointType} point
  1019. * A point-like instance.
  1020. *
  1021. * @return {Highcharts.AnnotationPointType|null}
  1022. * if the point is found/set returns this point, otherwise null
  1023. */
  1024. point: function (pointOptions, point) {
  1025. if (pointOptions && pointOptions.series) {
  1026. return pointOptions;
  1027. }
  1028. if (!point || point.series === null) {
  1029. if (isObject(pointOptions)) {
  1030. point = new MockPoint(this.chart, this, pointOptions);
  1031. }
  1032. else if (isString(pointOptions)) {
  1033. point = this.chart.get(pointOptions) || null;
  1034. }
  1035. else if (typeof pointOptions === 'function') {
  1036. var pointConfig = pointOptions.call(point,
  1037. this);
  1038. point = pointConfig.series ?
  1039. pointConfig :
  1040. new MockPoint(this.chart, this, pointOptions);
  1041. }
  1042. }
  1043. return point;
  1044. },
  1045. /**
  1046. * Find point-like objects based on points options.
  1047. *
  1048. * @return {Array<Annotation.PointLike>} an array of point-like objects
  1049. */
  1050. linkPoints: function () {
  1051. var pointsOptions = this.getPointsOptions(),
  1052. points = this.points,
  1053. len = (pointsOptions && pointsOptions.length) || 0,
  1054. i,
  1055. point;
  1056. for (i = 0; i < len; i++) {
  1057. point = this.point(pointsOptions[i], points[i]);
  1058. if (!point) {
  1059. points.length = 0;
  1060. return;
  1061. }
  1062. if (point.mock) {
  1063. point.refresh();
  1064. }
  1065. points[i] = point;
  1066. }
  1067. return points;
  1068. },
  1069. /**
  1070. * Add control points to a controllable.
  1071. */
  1072. addControlPoints: function () {
  1073. var controlPointsOptions = this.options.controlPoints;
  1074. (controlPointsOptions || []).forEach(function (controlPointOptions, i) {
  1075. var options = merge(this.options.controlPointOptions,
  1076. controlPointOptions);
  1077. if (!options.index) {
  1078. options.index = i;
  1079. }
  1080. controlPointsOptions[i] = options;
  1081. this.controlPoints.push(new ControlPoint(this.chart, this, options));
  1082. }, this);
  1083. },
  1084. /**
  1085. * Check if a controllable should be rendered/redrawn.
  1086. *
  1087. * @return {boolean}
  1088. * Whether a controllable should be drawn.
  1089. */
  1090. shouldBeDrawn: function () {
  1091. return Boolean(this.points.length);
  1092. },
  1093. /**
  1094. * Render a controllable.
  1095. */
  1096. render: function (_parentGroup) {
  1097. this.controlPoints.forEach(function (controlPoint) {
  1098. controlPoint.render();
  1099. });
  1100. },
  1101. /**
  1102. * Redraw a controllable.
  1103. *
  1104. * @param {boolean} [animation]
  1105. */
  1106. redraw: function (animation) {
  1107. this.controlPoints.forEach(function (controlPoint) {
  1108. controlPoint.redraw(animation);
  1109. });
  1110. },
  1111. /**
  1112. * Transform a controllable with a specific transformation.
  1113. *
  1114. * @param {string} transformation a transformation name
  1115. * @param {number|null} cx origin x transformation
  1116. * @param {number|null} cy origin y transformation
  1117. * @param {number} p1 param for the transformation
  1118. * @param {number} [p2] param for the transformation
  1119. */
  1120. transform: function (transformation, cx, cy, p1, p2) {
  1121. if (this.chart.inverted) {
  1122. var temp = cx;
  1123. cx = cy;
  1124. cy = temp;
  1125. }
  1126. this.points.forEach(function (point, i) {
  1127. this.transformPoint(transformation, cx, cy, p1, p2, i);
  1128. }, this);
  1129. },
  1130. /**
  1131. * Transform a point with a specific transformation
  1132. * If a transformed point is a real point it is replaced with
  1133. * the mock point.
  1134. *
  1135. * @param {string} transformation a transformation name
  1136. * @param {number|null} cx origin x transformation
  1137. * @param {number|null} cy origin y transformation
  1138. * @param {number} p1 param for the transformation
  1139. * @param {number|undefined} p2 param for the transformation
  1140. * @param {number} i index of the point
  1141. */
  1142. transformPoint: function (transformation, cx, cy, p1, p2, i) {
  1143. var point = this.points[i];
  1144. if (!point.mock) {
  1145. point = this.points[i] = MockPoint.fromPoint(point);
  1146. }
  1147. point[transformation](cx, cy, p1, p2);
  1148. },
  1149. /**
  1150. * Translate a controllable.
  1151. *
  1152. * @param {number} dx translation for x coordinate
  1153. * @param {number} dy translation for y coordinate
  1154. **/
  1155. translate: function (dx, dy) {
  1156. this.transform('translate', null, null, dx, dy);
  1157. },
  1158. /**
  1159. * Translate a specific point within a controllable.
  1160. *
  1161. * @param {number} dx translation for x coordinate
  1162. * @param {number} dy translation for y coordinate
  1163. * @param {number} i index of the point
  1164. **/
  1165. translatePoint: function (dx, dy, i) {
  1166. this.transformPoint('translate', null, null, dx, dy, i);
  1167. },
  1168. /**
  1169. * Translate shape within controllable item.
  1170. * Replaces `controllable.translate` method.
  1171. *
  1172. * @param {number} dx translation for x coordinate
  1173. * @param {number} dy translation for y coordinate
  1174. */
  1175. translateShape: function (dx, dy) {
  1176. var chart = this.annotation.chart,
  1177. // Annotation.options
  1178. shapeOptions = this.annotation.userOptions,
  1179. // Chart.options.annotations
  1180. annotationIndex = chart.annotations.indexOf(this.annotation),
  1181. chartOptions = chart.options.annotations[annotationIndex];
  1182. this.translatePoint(dx, dy, 0);
  1183. // Options stored in:
  1184. // - chart (for exporting)
  1185. // - current config (for redraws)
  1186. chartOptions[this.collection][this.index].point = this.options.point;
  1187. shapeOptions[this.collection][this.index].point = this.options.point;
  1188. },
  1189. /**
  1190. * Rotate a controllable.
  1191. *
  1192. * @param {number} cx origin x rotation
  1193. * @param {number} cy origin y rotation
  1194. * @param {number} radians
  1195. **/
  1196. rotate: function (cx, cy, radians) {
  1197. this.transform('rotate', cx, cy, radians);
  1198. },
  1199. /**
  1200. * Scale a controllable.
  1201. *
  1202. * @param {number} cx origin x rotation
  1203. * @param {number} cy origin y rotation
  1204. * @param {number} sx scale factor x
  1205. * @param {number} sy scale factor y
  1206. */
  1207. scale: function (cx, cy, sx, sy) {
  1208. this.transform('scale', cx, cy, sx, sy);
  1209. },
  1210. /**
  1211. * Set control points' visibility.
  1212. *
  1213. * @param {boolean} visible
  1214. */
  1215. setControlPointsVisibility: function (visible) {
  1216. this.controlPoints.forEach(function (controlPoint) {
  1217. controlPoint.setVisibility(visible);
  1218. });
  1219. },
  1220. /**
  1221. * Destroy a controllable.
  1222. */
  1223. destroy: function () {
  1224. if (this.graphic) {
  1225. this.graphic = this.graphic.destroy();
  1226. }
  1227. if (this.tracker) {
  1228. this.tracker = this.tracker.destroy();
  1229. }
  1230. this.controlPoints.forEach(function (controlPoint) {
  1231. controlPoint.destroy();
  1232. });
  1233. this.chart = null;
  1234. this.points = null;
  1235. this.controlPoints = null;
  1236. this.options = null;
  1237. if (this.annotation) {
  1238. this.annotation = null;
  1239. }
  1240. },
  1241. /**
  1242. * Update a controllable.
  1243. *
  1244. * @param {Object} newOptions
  1245. */
  1246. update: function (newOptions) {
  1247. var annotation = this.annotation,
  1248. options = merge(true,
  1249. this.options,
  1250. newOptions),
  1251. parentGroup = this.graphic.parentGroup;
  1252. this.destroy();
  1253. this.constructor(annotation, options);
  1254. this.render(parentGroup);
  1255. this.redraw();
  1256. }
  1257. };
  1258. return controllableMixin;
  1259. });
  1260. _registerModule(_modules, 'Extensions/Annotations/Mixins/MarkerMixin.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Utilities.js']], function (Chart, SVGRenderer, U) {
  1261. /* *
  1262. *
  1263. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1264. *
  1265. * */
  1266. var addEvent = U.addEvent,
  1267. defined = U.defined,
  1268. merge = U.merge,
  1269. objectEach = U.objectEach,
  1270. uniqueKey = U.uniqueKey;
  1271. /**
  1272. * Options for configuring markers for annotations.
  1273. *
  1274. * An example of the arrow marker:
  1275. * <pre>
  1276. * {
  1277. * arrow: {
  1278. * id: 'arrow',
  1279. * tagName: 'marker',
  1280. * refY: 5,
  1281. * refX: 5,
  1282. * markerWidth: 10,
  1283. * markerHeight: 10,
  1284. * children: [{
  1285. * tagName: 'path',
  1286. * attrs: {
  1287. * d: 'M 0 0 L 10 5 L 0 10 Z',
  1288. * strokeWidth: 0
  1289. * }
  1290. * }]
  1291. * }
  1292. * }
  1293. * </pre>
  1294. *
  1295. * @sample highcharts/annotations/custom-markers/
  1296. * Define a custom marker for annotations
  1297. *
  1298. * @sample highcharts/css/annotations-markers/
  1299. * Define markers in a styled mode
  1300. *
  1301. * @type {Highcharts.Dictionary<Highcharts.SVGDefinitionObject>}
  1302. * @since 6.0.0
  1303. * @optionparent defs
  1304. */
  1305. var defaultMarkers = {
  1306. /**
  1307. * @type {Highcharts.SVGDefinitionObject}
  1308. */
  1309. arrow: {
  1310. tagName: 'marker',
  1311. render: false,
  1312. id: 'arrow',
  1313. refY: 5,
  1314. refX: 9,
  1315. markerWidth: 10,
  1316. markerHeight: 10,
  1317. /**
  1318. * @type {Array<Highcharts.DefsOptions>}
  1319. */
  1320. children: [{
  1321. tagName: 'path',
  1322. d: 'M 0 0 L 10 5 L 0 10 Z',
  1323. strokeWidth: 0
  1324. }]
  1325. },
  1326. /**
  1327. * @type {Highcharts.SVGDefinitionObject}
  1328. */
  1329. 'reverse-arrow': {
  1330. tagName: 'marker',
  1331. render: false,
  1332. id: 'reverse-arrow',
  1333. refY: 5,
  1334. refX: 1,
  1335. markerWidth: 10,
  1336. markerHeight: 10,
  1337. children: [{
  1338. tagName: 'path',
  1339. // reverse triangle (used as an arrow)
  1340. d: 'M 0 5 L 10 0 L 10 10 Z',
  1341. strokeWidth: 0
  1342. }]
  1343. }
  1344. };
  1345. SVGRenderer.prototype.addMarker = function (id, markerOptions) {
  1346. var options = { id: id };
  1347. var attrs = {
  1348. stroke: markerOptions.color || 'none',
  1349. fill: markerOptions.color || 'rgba(0, 0, 0, 0.75)'
  1350. };
  1351. options.children = markerOptions.children.map(function (child) {
  1352. return merge(attrs, child);
  1353. });
  1354. var marker = this.definition(merge(true, {
  1355. markerWidth: 20,
  1356. markerHeight: 20,
  1357. refX: 0,
  1358. refY: 0,
  1359. orient: 'auto'
  1360. },
  1361. markerOptions,
  1362. options));
  1363. marker.id = id;
  1364. return marker;
  1365. };
  1366. /* eslint-disable no-invalid-this, valid-jsdoc */
  1367. /**
  1368. * @private
  1369. */
  1370. function createMarkerSetter(markerType) {
  1371. return function (value) {
  1372. this.attr(markerType, 'url(#' + value + ')');
  1373. };
  1374. }
  1375. /**
  1376. * @private
  1377. * @mixin
  1378. * @name Highcharts.AnnotaitonMarkerMixin
  1379. */
  1380. var markerMixin = {
  1381. markerEndSetter: createMarkerSetter('marker-end'),
  1382. markerStartSetter: createMarkerSetter('marker-start'),
  1383. /**
  1384. * Set markers.
  1385. * @private
  1386. * @param {Highcharts.AnnotationControllablePath} item
  1387. */
  1388. setItemMarkers: function (item) {
  1389. var itemOptions = item.options,
  1390. chart = item.chart,
  1391. defs = chart.options.defs,
  1392. fill = itemOptions.fill,
  1393. color = defined(fill) && fill !== 'none' ?
  1394. fill :
  1395. itemOptions.stroke,
  1396. setMarker = function (markerType) {
  1397. var markerId = itemOptions[markerType],
  1398. def,
  1399. predefinedMarker,
  1400. key,
  1401. marker;
  1402. if (markerId) {
  1403. for (key in defs) { // eslint-disable-line guard-for-in
  1404. def = defs[key];
  1405. if (markerId === def.id &&
  1406. def.tagName === 'marker') {
  1407. predefinedMarker = def;
  1408. break;
  1409. }
  1410. }
  1411. if (predefinedMarker) {
  1412. marker = item[markerType] = chart.renderer
  1413. .addMarker((itemOptions.id || uniqueKey()) + '-' +
  1414. predefinedMarker.id, merge(predefinedMarker, { color: color }));
  1415. item.attr(markerType, marker.attr('id'));
  1416. }
  1417. }
  1418. };
  1419. ['markerStart', 'markerEnd'].forEach(setMarker);
  1420. }
  1421. };
  1422. addEvent(Chart, 'afterGetContainer', function () {
  1423. this.options.defs = merge(defaultMarkers, this.options.defs || {});
  1424. objectEach(this.options.defs, function (def) {
  1425. if (def.tagName === 'marker' && def.render !== false) {
  1426. this.renderer.addMarker(def.id, def);
  1427. }
  1428. }, this);
  1429. });
  1430. return markerMixin;
  1431. });
  1432. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllablePath.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/Mixins/MarkerMixin.js'], _modules['Core/Utilities.js']], function (ControllableMixin, H, MarkerMixin, U) {
  1433. /* *
  1434. *
  1435. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1436. *
  1437. * */
  1438. var extend = U.extend;
  1439. // See TRACKER_FILL in highcharts.src.js
  1440. var TRACKER_FILL = 'rgba(192,192,192,' + (H.svg ? 0.0001 : 0.002) + ')';
  1441. /* eslint-disable no-invalid-this, valid-jsdoc */
  1442. /**
  1443. * A controllable path class.
  1444. *
  1445. * @requires modules/annotations
  1446. *
  1447. * @private
  1448. * @class
  1449. * @name Highcharts.AnnotationControllablePath
  1450. *
  1451. * @param {Highcharts.Annotation}
  1452. * Related annotation.
  1453. *
  1454. * @param {Highcharts.AnnotationsShapeOptions} options
  1455. * A path's options object.
  1456. *
  1457. * @param {number} index
  1458. * Index of the path.
  1459. */
  1460. var ControllablePath = /** @class */ (function () {
  1461. /* *
  1462. *
  1463. * Constructors
  1464. *
  1465. * */
  1466. function ControllablePath(annotation, options, index) {
  1467. /* *
  1468. *
  1469. * Properties
  1470. *
  1471. * */
  1472. this.addControlPoints = ControllableMixin.addControlPoints;
  1473. this.anchor = ControllableMixin.anchor;
  1474. this.attr = ControllableMixin.attr;
  1475. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1476. this.destroy = ControllableMixin.destroy;
  1477. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1478. this.init = ControllableMixin.init;
  1479. this.linkPoints = ControllableMixin.linkPoints;
  1480. this.point = ControllableMixin.point;
  1481. this.rotate = ControllableMixin.rotate;
  1482. this.scale = ControllableMixin.scale;
  1483. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1484. this.setMarkers = MarkerMixin.setItemMarkers;
  1485. this.transform = ControllableMixin.transform;
  1486. this.transformPoint = ControllableMixin.transformPoint;
  1487. this.translate = ControllableMixin.translate;
  1488. this.translatePoint = ControllableMixin.translatePoint;
  1489. this.translateShape = ControllableMixin.translateShape;
  1490. this.update = ControllableMixin.update;
  1491. /**
  1492. * @type 'path'
  1493. */
  1494. this.type = 'path';
  1495. this.init(annotation, options, index);
  1496. this.collection = 'shapes';
  1497. }
  1498. /* *
  1499. *
  1500. * Functions
  1501. *
  1502. * */
  1503. /**
  1504. * Map the controllable path to 'd' path attribute.
  1505. *
  1506. * @return {Highcharts.SVGPathArray|null}
  1507. * A path's d attribute.
  1508. */
  1509. ControllablePath.prototype.toD = function () {
  1510. var dOption = this.options.d;
  1511. if (dOption) {
  1512. return typeof dOption === 'function' ?
  1513. dOption.call(this) :
  1514. dOption;
  1515. }
  1516. var points = this.points,
  1517. len = points.length,
  1518. showPath = len,
  1519. point = points[0],
  1520. position = showPath && this.anchor(point).absolutePosition,
  1521. pointIndex = 0,
  1522. command,
  1523. d = [];
  1524. if (position) {
  1525. d.push(['M', position.x, position.y]);
  1526. while (++pointIndex < len && showPath) {
  1527. point = points[pointIndex];
  1528. command = point.command || 'L';
  1529. position = this.anchor(point).absolutePosition;
  1530. if (command === 'M') {
  1531. d.push([command, position.x, position.y]);
  1532. }
  1533. else if (command === 'L') {
  1534. d.push([command, position.x, position.y]);
  1535. }
  1536. else if (command === 'Z') {
  1537. d.push([command]);
  1538. }
  1539. showPath = point.series.visible;
  1540. }
  1541. }
  1542. return showPath ?
  1543. this.chart.renderer.crispLine(d, this.graphic.strokeWidth()) :
  1544. null;
  1545. };
  1546. ControllablePath.prototype.shouldBeDrawn = function () {
  1547. return (ControllableMixin.shouldBeDrawn.call(this) || Boolean(this.options.d));
  1548. };
  1549. ControllablePath.prototype.render = function (parent) {
  1550. var options = this.options,
  1551. attrs = this.attrsFromOptions(options);
  1552. this.graphic = this.annotation.chart.renderer
  1553. .path([['M', 0, 0]])
  1554. .attr(attrs)
  1555. .add(parent);
  1556. if (options.className) {
  1557. this.graphic.addClass(options.className);
  1558. }
  1559. this.tracker = this.annotation.chart.renderer
  1560. .path([['M', 0, 0]])
  1561. .addClass('highcharts-tracker-line')
  1562. .attr({
  1563. zIndex: 2
  1564. })
  1565. .add(parent);
  1566. if (!this.annotation.chart.styledMode) {
  1567. this.tracker.attr({
  1568. 'stroke-linejoin': 'round',
  1569. stroke: TRACKER_FILL,
  1570. fill: TRACKER_FILL,
  1571. 'stroke-width': this.graphic.strokeWidth() +
  1572. options.snap * 2
  1573. });
  1574. }
  1575. ControllableMixin.render.call(this);
  1576. extend(this.graphic, {
  1577. markerStartSetter: MarkerMixin.markerStartSetter,
  1578. markerEndSetter: MarkerMixin.markerEndSetter
  1579. });
  1580. this.setMarkers(this);
  1581. };
  1582. ControllablePath.prototype.redraw = function (animation) {
  1583. var d = this.toD(),
  1584. action = animation ? 'animate' : 'attr';
  1585. if (d) {
  1586. this.graphic[action]({ d: d });
  1587. this.tracker[action]({ d: d });
  1588. }
  1589. else {
  1590. this.graphic.attr({ d: 'M 0 ' + -9e9 });
  1591. this.tracker.attr({ d: 'M 0 ' + -9e9 });
  1592. }
  1593. this.graphic.placed = this.tracker.placed = Boolean(d);
  1594. ControllableMixin.redraw.call(this, animation);
  1595. };
  1596. /* *
  1597. *
  1598. * Static Properties
  1599. *
  1600. * */
  1601. /**
  1602. * A map object which allows to map options attributes to element attributes
  1603. *
  1604. * @name Highcharts.AnnotationControllablePath.attrsMap
  1605. * @type {Highcharts.Dictionary<string>}
  1606. */
  1607. ControllablePath.attrsMap = {
  1608. dashStyle: 'dashstyle',
  1609. strokeWidth: 'stroke-width',
  1610. stroke: 'stroke',
  1611. fill: 'fill',
  1612. zIndex: 'zIndex'
  1613. };
  1614. return ControllablePath;
  1615. }());
  1616. return ControllablePath;
  1617. });
  1618. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableRect.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Core/Utilities.js']], function (ControllableMixin, ControllablePath, U) {
  1619. /* *
  1620. *
  1621. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1622. *
  1623. * */
  1624. var merge = U.merge;
  1625. /**
  1626. * @typedef {Annotation.ControllablePath.AttrsMap}
  1627. * Annotation.ControllableRect.AttrsMap
  1628. * @property {string} width=width
  1629. * @property {string} height=height
  1630. */
  1631. /* eslint-disable no-invalid-this, valid-jsdoc */
  1632. /**
  1633. * A controllable rect class.
  1634. *
  1635. * @requires modules/annotations
  1636. *
  1637. * @private
  1638. * @class
  1639. * @name Highcharts.AnnotationControllableRect
  1640. *
  1641. * @param {Highcharts.Annotation} annotation
  1642. * An annotation instance.
  1643. *
  1644. * @param {Highcharts.AnnotationsShapeOptions} options
  1645. * A rect's options.
  1646. *
  1647. * @param {number} index
  1648. * Index of the rectangle
  1649. */
  1650. var ControllableRect = /** @class */ (function () {
  1651. /* *
  1652. *
  1653. * Constructors
  1654. *
  1655. * */
  1656. function ControllableRect(annotation, options, index) {
  1657. /* *
  1658. *
  1659. * Properties
  1660. *
  1661. * */
  1662. this.addControlPoints = ControllableMixin.addControlPoints;
  1663. this.anchor = ControllableMixin.anchor;
  1664. this.attr = ControllableMixin.attr;
  1665. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1666. this.destroy = ControllableMixin.destroy;
  1667. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1668. this.init = ControllableMixin.init;
  1669. this.linkPoints = ControllableMixin.linkPoints;
  1670. this.point = ControllableMixin.point;
  1671. this.rotate = ControllableMixin.rotate;
  1672. this.scale = ControllableMixin.scale;
  1673. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1674. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1675. this.transform = ControllableMixin.transform;
  1676. this.transformPoint = ControllableMixin.transformPoint;
  1677. this.translatePoint = ControllableMixin.translatePoint;
  1678. this.translateShape = ControllableMixin.translateShape;
  1679. this.update = ControllableMixin.update;
  1680. /**
  1681. * @type 'rect'
  1682. */
  1683. this.type = 'rect';
  1684. this.translate = ControllableMixin.translateShape;
  1685. this.init(annotation, options, index);
  1686. this.collection = 'shapes';
  1687. }
  1688. /* *
  1689. *
  1690. * Functions
  1691. *
  1692. * */
  1693. ControllableRect.prototype.render = function (parent) {
  1694. var attrs = this.attrsFromOptions(this.options);
  1695. this.graphic = this.annotation.chart.renderer
  1696. .rect(0, -9e9, 0, 0)
  1697. .attr(attrs)
  1698. .add(parent);
  1699. ControllableMixin.render.call(this);
  1700. };
  1701. ControllableRect.prototype.redraw = function (animation) {
  1702. var position = this.anchor(this.points[0]).absolutePosition;
  1703. if (position) {
  1704. this.graphic[animation ? 'animate' : 'attr']({
  1705. x: position.x,
  1706. y: position.y,
  1707. width: this.options.width,
  1708. height: this.options.height
  1709. });
  1710. }
  1711. else {
  1712. this.attr({
  1713. x: 0,
  1714. y: -9e9
  1715. });
  1716. }
  1717. this.graphic.placed = Boolean(position);
  1718. ControllableMixin.redraw.call(this, animation);
  1719. };
  1720. /* *
  1721. *
  1722. * Static Properties
  1723. *
  1724. * */
  1725. /**
  1726. * A map object which allows to map options attributes to element attributes
  1727. *
  1728. * @type {Annotation.ControllableRect.AttrsMap}
  1729. */
  1730. ControllableRect.attrsMap = merge(ControllablePath.attrsMap, {
  1731. width: 'width',
  1732. height: 'height'
  1733. });
  1734. return ControllableRect;
  1735. }());
  1736. return ControllableRect;
  1737. });
  1738. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableCircle.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Core/Utilities.js']], function (ControllableMixin, ControllablePath, U) {
  1739. /* *
  1740. *
  1741. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1742. *
  1743. * */
  1744. var merge = U.merge;
  1745. /* eslint-disable no-invalid-this, valid-jsdoc */
  1746. /**
  1747. * A controllable circle class.
  1748. *
  1749. * @requires modules/annotations
  1750. *
  1751. * @private
  1752. * @class
  1753. * @name Highcharts.AnnotationControllableCircle
  1754. *
  1755. * @param {Highcharts.Annotation} annotation an annotation instance
  1756. * @param {Highcharts.AnnotationsShapeOptions} options a shape's options
  1757. * @param {number} index of the circle
  1758. */
  1759. var ControllableCircle = /** @class */ (function () {
  1760. /* *
  1761. *
  1762. * Constructors
  1763. *
  1764. * */
  1765. function ControllableCircle(annotation, options, index) {
  1766. /* *
  1767. *
  1768. * Properties
  1769. *
  1770. * */
  1771. this.addControlPoints = ControllableMixin.addControlPoints;
  1772. this.anchor = ControllableMixin.anchor;
  1773. this.attr = ControllableMixin.attr;
  1774. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1775. this.destroy = ControllableMixin.destroy;
  1776. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1777. this.init = ControllableMixin.init;
  1778. this.linkPoints = ControllableMixin.linkPoints;
  1779. this.point = ControllableMixin.point;
  1780. this.rotate = ControllableMixin.rotate;
  1781. this.scale = ControllableMixin.scale;
  1782. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1783. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1784. this.transform = ControllableMixin.transform;
  1785. this.transformPoint = ControllableMixin.transformPoint;
  1786. this.translatePoint = ControllableMixin.translatePoint;
  1787. this.translateShape = ControllableMixin.translateShape;
  1788. this.update = ControllableMixin.update;
  1789. /**
  1790. * @type 'circle'
  1791. */
  1792. this.type = 'circle';
  1793. this.translate = ControllableMixin.translateShape;
  1794. this.init(annotation, options, index);
  1795. this.collection = 'shapes';
  1796. }
  1797. /* *
  1798. *
  1799. * Functions
  1800. *
  1801. * */
  1802. ControllableCircle.prototype.render = function (parent) {
  1803. var attrs = this.attrsFromOptions(this.options);
  1804. this.graphic = this.annotation.chart.renderer
  1805. .circle(0, -9e9, 0)
  1806. .attr(attrs)
  1807. .add(parent);
  1808. ControllableMixin.render.call(this);
  1809. };
  1810. ControllableCircle.prototype.redraw = function (animation) {
  1811. var position = this.anchor(this.points[0]).absolutePosition;
  1812. if (position) {
  1813. this.graphic[animation ? 'animate' : 'attr']({
  1814. x: position.x,
  1815. y: position.y,
  1816. r: this.options.r
  1817. });
  1818. }
  1819. else {
  1820. this.graphic.attr({
  1821. x: 0,
  1822. y: -9e9
  1823. });
  1824. }
  1825. this.graphic.placed = Boolean(position);
  1826. ControllableMixin.redraw.call(this, animation);
  1827. };
  1828. /**
  1829. * Set the radius.
  1830. *
  1831. * @param {number} r a radius to be set
  1832. */
  1833. ControllableCircle.prototype.setRadius = function (r) {
  1834. this.options.r = r;
  1835. };
  1836. /* *
  1837. *
  1838. * Static Properties
  1839. *
  1840. * */
  1841. /**
  1842. * A map object which allows to map options attributes to element
  1843. * attributes.
  1844. *
  1845. * @name Highcharts.AnnotationControllableCircle.attrsMap
  1846. * @type {Highcharts.Dictionary<string>}
  1847. */
  1848. ControllableCircle.attrsMap = merge(ControllablePath.attrsMap, { r: 'r' });
  1849. return ControllableCircle;
  1850. }());
  1851. return ControllableCircle;
  1852. });
  1853. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableLabel.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Tooltip.js'], _modules['Core/Utilities.js']], function (ControllableMixin, MockPoint, SVGRenderer, Tooltip, U) {
  1854. /* *
  1855. *
  1856. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1857. *
  1858. * */
  1859. var extend = U.extend,
  1860. format = U.format,
  1861. isNumber = U.isNumber,
  1862. pick = U.pick;
  1863. /* eslint-disable no-invalid-this, valid-jsdoc */
  1864. /**
  1865. * A controllable label class.
  1866. *
  1867. * @requires modules/annotations
  1868. *
  1869. * @private
  1870. * @class
  1871. * @name Highcharts.AnnotationControllableLabel
  1872. *
  1873. * @param {Highcharts.Annotation} annotation
  1874. * An annotation instance.
  1875. * @param {Highcharts.AnnotationsLabelOptions} options
  1876. * A label's options.
  1877. * @param {number} index
  1878. * Index of the label.
  1879. */
  1880. var ControllableLabel = /** @class */ (function () {
  1881. /* *
  1882. *
  1883. * Constructors
  1884. *
  1885. * */
  1886. function ControllableLabel(annotation, options, index) {
  1887. /* *
  1888. *
  1889. * Properties
  1890. *
  1891. * */
  1892. this.addControlPoints = ControllableMixin.addControlPoints;
  1893. this.attr = ControllableMixin.attr;
  1894. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1895. this.destroy = ControllableMixin.destroy;
  1896. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1897. this.init = ControllableMixin.init;
  1898. this.linkPoints = ControllableMixin.linkPoints;
  1899. this.point = ControllableMixin.point;
  1900. this.rotate = ControllableMixin.rotate;
  1901. this.scale = ControllableMixin.scale;
  1902. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1903. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1904. this.transform = ControllableMixin.transform;
  1905. this.transformPoint = ControllableMixin.transformPoint;
  1906. this.translateShape = ControllableMixin.translateShape;
  1907. this.update = ControllableMixin.update;
  1908. this.init(annotation, options, index);
  1909. this.collection = 'labels';
  1910. }
  1911. /* *
  1912. *
  1913. * Static Functions
  1914. *
  1915. * */
  1916. /**
  1917. * Returns new aligned position based alignment options and box to align to.
  1918. * It is almost a one-to-one copy from SVGElement.prototype.align
  1919. * except it does not use and mutate an element
  1920. *
  1921. * @param {Highcharts.AnnotationAlignObject} alignOptions
  1922. *
  1923. * @param {Highcharts.BBoxObject} box
  1924. *
  1925. * @return {Highcharts.PositionObject}
  1926. * Aligned position.
  1927. */
  1928. ControllableLabel.alignedPosition = function (alignOptions, box) {
  1929. var align = alignOptions.align,
  1930. vAlign = alignOptions.verticalAlign,
  1931. x = (box.x || 0) + (alignOptions.x || 0),
  1932. y = (box.y || 0) + (alignOptions.y || 0),
  1933. alignFactor,
  1934. vAlignFactor;
  1935. if (align === 'right') {
  1936. alignFactor = 1;
  1937. }
  1938. else if (align === 'center') {
  1939. alignFactor = 2;
  1940. }
  1941. if (alignFactor) {
  1942. x += (box.width - (alignOptions.width || 0)) / alignFactor;
  1943. }
  1944. if (vAlign === 'bottom') {
  1945. vAlignFactor = 1;
  1946. }
  1947. else if (vAlign === 'middle') {
  1948. vAlignFactor = 2;
  1949. }
  1950. if (vAlignFactor) {
  1951. y += (box.height - (alignOptions.height || 0)) / vAlignFactor;
  1952. }
  1953. return {
  1954. x: Math.round(x),
  1955. y: Math.round(y)
  1956. };
  1957. };
  1958. /**
  1959. * Returns new alignment options for a label if the label is outside the
  1960. * plot area. It is almost a one-to-one copy from
  1961. * Series.prototype.justifyDataLabel except it does not mutate the label and
  1962. * it works with absolute instead of relative position.
  1963. */
  1964. ControllableLabel.justifiedOptions = function (chart, label, alignOptions, alignAttr) {
  1965. var align = alignOptions.align,
  1966. verticalAlign = alignOptions.verticalAlign,
  1967. padding = label.box ? 0 : (label.padding || 0),
  1968. bBox = label.getBBox(),
  1969. off,
  1970. //
  1971. options = {
  1972. align: align,
  1973. verticalAlign: verticalAlign,
  1974. x: alignOptions.x,
  1975. y: alignOptions.y,
  1976. width: label.width,
  1977. height: label.height
  1978. },
  1979. //
  1980. x = alignAttr.x - chart.plotLeft,
  1981. y = alignAttr.y - chart.plotTop;
  1982. // Off left
  1983. off = x + padding;
  1984. if (off < 0) {
  1985. if (align === 'right') {
  1986. options.align = 'left';
  1987. }
  1988. else {
  1989. options.x = -off;
  1990. }
  1991. }
  1992. // Off right
  1993. off = x + bBox.width - padding;
  1994. if (off > chart.plotWidth) {
  1995. if (align === 'left') {
  1996. options.align = 'right';
  1997. }
  1998. else {
  1999. options.x = chart.plotWidth - off;
  2000. }
  2001. }
  2002. // Off top
  2003. off = y + padding;
  2004. if (off < 0) {
  2005. if (verticalAlign === 'bottom') {
  2006. options.verticalAlign = 'top';
  2007. }
  2008. else {
  2009. options.y = -off;
  2010. }
  2011. }
  2012. // Off bottom
  2013. off = y + bBox.height - padding;
  2014. if (off > chart.plotHeight) {
  2015. if (verticalAlign === 'top') {
  2016. options.verticalAlign = 'bottom';
  2017. }
  2018. else {
  2019. options.y = chart.plotHeight - off;
  2020. }
  2021. }
  2022. return options;
  2023. };
  2024. /* *
  2025. *
  2026. * Functions
  2027. *
  2028. * */
  2029. /**
  2030. * Translate the point of the label by deltaX and deltaY translations.
  2031. * The point is the label's anchor.
  2032. *
  2033. * @param {number} dx translation for x coordinate
  2034. * @param {number} dy translation for y coordinate
  2035. */
  2036. ControllableLabel.prototype.translatePoint = function (dx, dy) {
  2037. ControllableMixin.translatePoint.call(this, dx, dy, 0);
  2038. };
  2039. /**
  2040. * Translate x and y position relative to the label's anchor.
  2041. *
  2042. * @param {number} dx translation for x coordinate
  2043. * @param {number} dy translation for y coordinate
  2044. */
  2045. ControllableLabel.prototype.translate = function (dx, dy) {
  2046. var chart = this.annotation.chart,
  2047. // Annotation.options
  2048. labelOptions = this.annotation.userOptions,
  2049. // Chart.options.annotations
  2050. annotationIndex = chart.annotations.indexOf(this.annotation),
  2051. chartAnnotations = chart.options.annotations,
  2052. chartOptions = chartAnnotations[annotationIndex],
  2053. temp;
  2054. if (chart.inverted) {
  2055. temp = dx;
  2056. dx = dy;
  2057. dy = temp;
  2058. }
  2059. // Local options:
  2060. this.options.x += dx;
  2061. this.options.y += dy;
  2062. // Options stored in chart:
  2063. chartOptions[this.collection][this.index].x = this.options.x;
  2064. chartOptions[this.collection][this.index].y = this.options.y;
  2065. labelOptions[this.collection][this.index].x = this.options.x;
  2066. labelOptions[this.collection][this.index].y = this.options.y;
  2067. };
  2068. ControllableLabel.prototype.render = function (parent) {
  2069. var options = this.options,
  2070. attrs = this.attrsFromOptions(options),
  2071. style = options.style;
  2072. this.graphic = this.annotation.chart.renderer
  2073. .label('', 0, -9999, // #10055
  2074. options.shape, null, null, options.useHTML, null, 'annotation-label')
  2075. .attr(attrs)
  2076. .add(parent);
  2077. if (!this.annotation.chart.styledMode) {
  2078. if (style.color === 'contrast') {
  2079. style.color = this.annotation.chart.renderer.getContrast(ControllableLabel.shapesWithoutBackground.indexOf(options.shape) > -1 ? '#FFFFFF' : options.backgroundColor);
  2080. }
  2081. this.graphic
  2082. .css(options.style)
  2083. .shadow(options.shadow);
  2084. }
  2085. if (options.className) {
  2086. this.graphic.addClass(options.className);
  2087. }
  2088. this.graphic.labelrank = options.labelrank;
  2089. ControllableMixin.render.call(this);
  2090. };
  2091. ControllableLabel.prototype.redraw = function (animation) {
  2092. var options = this.options,
  2093. text = this.text || options.format || options.text,
  2094. label = this.graphic,
  2095. point = this.points[0],
  2096. anchor,
  2097. attrs;
  2098. label.attr({
  2099. text: text ?
  2100. format(text, point.getLabelConfig(), this.annotation.chart) :
  2101. options.formatter.call(point, this)
  2102. });
  2103. anchor = this.anchor(point);
  2104. attrs = this.position(anchor);
  2105. if (attrs) {
  2106. label.alignAttr = attrs;
  2107. attrs.anchorX = anchor.absolutePosition.x;
  2108. attrs.anchorY = anchor.absolutePosition.y;
  2109. label[animation ? 'animate' : 'attr'](attrs);
  2110. }
  2111. else {
  2112. label.attr({
  2113. x: 0,
  2114. y: -9999 // #10055
  2115. });
  2116. }
  2117. label.placed = !!attrs;
  2118. ControllableMixin.redraw.call(this, animation);
  2119. };
  2120. /**
  2121. * All basic shapes don't support alignTo() method except label.
  2122. * For a controllable label, we need to subtract translation from
  2123. * options.
  2124. */
  2125. ControllableLabel.prototype.anchor = function (_point) {
  2126. var anchor = ControllableMixin.anchor.apply(this,
  2127. arguments),
  2128. x = this.options.x || 0,
  2129. y = this.options.y || 0;
  2130. anchor.absolutePosition.x -= x;
  2131. anchor.absolutePosition.y -= y;
  2132. anchor.relativePosition.x -= x;
  2133. anchor.relativePosition.y -= y;
  2134. return anchor;
  2135. };
  2136. /**
  2137. * Returns the label position relative to its anchor.
  2138. *
  2139. * @param {Highcharts.AnnotationAnchorObject} anchor
  2140. *
  2141. * @return {Highcharts.PositionObject|null}
  2142. */
  2143. ControllableLabel.prototype.position = function (anchor) {
  2144. var item = this.graphic,
  2145. chart = this.annotation.chart,
  2146. point = this.points[0],
  2147. itemOptions = this.options,
  2148. anchorAbsolutePosition = anchor.absolutePosition,
  2149. anchorRelativePosition = anchor.relativePosition,
  2150. itemPosition,
  2151. alignTo,
  2152. itemPosRelativeX,
  2153. itemPosRelativeY,
  2154. showItem = point.series.visible &&
  2155. MockPoint.prototype.isInsidePlot.call(point);
  2156. if (showItem) {
  2157. if (itemOptions.distance) {
  2158. itemPosition = Tooltip.prototype.getPosition.call({
  2159. chart: chart,
  2160. distance: pick(itemOptions.distance, 16)
  2161. }, item.width, item.height, {
  2162. plotX: anchorRelativePosition.x,
  2163. plotY: anchorRelativePosition.y,
  2164. negative: point.negative,
  2165. ttBelow: point.ttBelow,
  2166. h: (anchorRelativePosition.height || anchorRelativePosition.width)
  2167. });
  2168. }
  2169. else if (itemOptions.positioner) {
  2170. itemPosition = itemOptions.positioner.call(this);
  2171. }
  2172. else {
  2173. alignTo = {
  2174. x: anchorAbsolutePosition.x,
  2175. y: anchorAbsolutePosition.y,
  2176. width: 0,
  2177. height: 0
  2178. };
  2179. itemPosition = ControllableLabel.alignedPosition(extend(itemOptions, {
  2180. width: item.width,
  2181. height: item.height
  2182. }), alignTo);
  2183. if (this.options.overflow === 'justify') {
  2184. itemPosition = ControllableLabel.alignedPosition(ControllableLabel.justifiedOptions(chart, item, itemOptions, itemPosition), alignTo);
  2185. }
  2186. }
  2187. if (itemOptions.crop) {
  2188. itemPosRelativeX = itemPosition.x - chart.plotLeft;
  2189. itemPosRelativeY = itemPosition.y - chart.plotTop;
  2190. showItem =
  2191. chart.isInsidePlot(itemPosRelativeX, itemPosRelativeY) &&
  2192. chart.isInsidePlot(itemPosRelativeX + item.width, itemPosRelativeY + item.height);
  2193. }
  2194. }
  2195. return showItem ? itemPosition : null;
  2196. };
  2197. /* *
  2198. *
  2199. * Static Properties
  2200. *
  2201. * */
  2202. /**
  2203. * A map object which allows to map options attributes to element attributes
  2204. *
  2205. * @type {Highcharts.Dictionary<string>}
  2206. */
  2207. ControllableLabel.attrsMap = {
  2208. backgroundColor: 'fill',
  2209. borderColor: 'stroke',
  2210. borderWidth: 'stroke-width',
  2211. zIndex: 'zIndex',
  2212. borderRadius: 'r',
  2213. padding: 'padding'
  2214. };
  2215. /**
  2216. * Shapes which do not have background - the object is used for proper
  2217. * setting of the contrast color.
  2218. *
  2219. * @type {Array<string>}
  2220. */
  2221. ControllableLabel.shapesWithoutBackground = ['connector'];
  2222. return ControllableLabel;
  2223. }());
  2224. /* ********************************************************************** */
  2225. /**
  2226. * General symbol definition for labels with connector
  2227. * @private
  2228. */
  2229. SVGRenderer.prototype.symbols.connector = function (x, y, w, h, options) {
  2230. var anchorX = options && options.anchorX,
  2231. anchorY = options && options.anchorY,
  2232. path,
  2233. yOffset,
  2234. lateral = w / 2;
  2235. if (isNumber(anchorX) && isNumber(anchorY)) {
  2236. path = [['M', anchorX, anchorY]];
  2237. // Prefer 45 deg connectors
  2238. yOffset = y - anchorY;
  2239. if (yOffset < 0) {
  2240. yOffset = -h - yOffset;
  2241. }
  2242. if (yOffset < w) {
  2243. lateral = anchorX < x + (w / 2) ? yOffset : w - yOffset;
  2244. }
  2245. // Anchor below label
  2246. if (anchorY > y + h) {
  2247. path.push(['L', x + lateral, y + h]);
  2248. // Anchor above label
  2249. }
  2250. else if (anchorY < y) {
  2251. path.push(['L', x + lateral, y]);
  2252. // Anchor left of label
  2253. }
  2254. else if (anchorX < x) {
  2255. path.push(['L', x, y + h / 2]);
  2256. // Anchor right of label
  2257. }
  2258. else if (anchorX > x + w) {
  2259. path.push(['L', x + w, y + h / 2]);
  2260. }
  2261. }
  2262. return path || [];
  2263. };
  2264. return ControllableLabel;
  2265. });
  2266. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableImage.js', [_modules['Extensions/Annotations/Controllables/ControllableLabel.js'], _modules['Extensions/Annotations/Mixins/ControllableMixin.js']], function (ControllableLabel, ControllableMixin) {
  2267. /* *
  2268. *
  2269. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2270. *
  2271. * */
  2272. /* eslint-disable no-invalid-this, valid-jsdoc */
  2273. /**
  2274. * A controllable image class.
  2275. *
  2276. * @requires modules/annotations
  2277. *
  2278. * @private
  2279. * @class
  2280. * @name Highcharts.AnnotationControllableImage
  2281. *
  2282. * @param {Highcharts.Annotation} annotation
  2283. * An annotation instance.
  2284. *
  2285. * @param {Highcharts.AnnotationsShapeOptions} options
  2286. * A controllable's options.
  2287. *
  2288. * @param {number} index
  2289. * Index of the image.
  2290. */
  2291. var ControllableImage = /** @class */ (function () {
  2292. /* *
  2293. *
  2294. * Constructors
  2295. *
  2296. * */
  2297. function ControllableImage(annotation, options, index) {
  2298. /* *
  2299. *
  2300. * Properties
  2301. *
  2302. * */
  2303. this.addControlPoints = ControllableMixin.addControlPoints;
  2304. this.anchor = ControllableMixin.anchor;
  2305. this.attr = ControllableMixin.attr;
  2306. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  2307. this.destroy = ControllableMixin.destroy;
  2308. this.getPointsOptions = ControllableMixin.getPointsOptions;
  2309. this.init = ControllableMixin.init;
  2310. this.linkPoints = ControllableMixin.linkPoints;
  2311. this.point = ControllableMixin.point;
  2312. this.rotate = ControllableMixin.rotate;
  2313. this.scale = ControllableMixin.scale;
  2314. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  2315. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  2316. this.transform = ControllableMixin.transform;
  2317. this.transformPoint = ControllableMixin.transformPoint;
  2318. this.translatePoint = ControllableMixin.translatePoint;
  2319. this.translateShape = ControllableMixin.translateShape;
  2320. this.update = ControllableMixin.update;
  2321. /**
  2322. * @type 'image'
  2323. */
  2324. this.type = 'image';
  2325. this.translate = ControllableMixin.translateShape;
  2326. this.init(annotation, options, index);
  2327. this.collection = 'shapes';
  2328. }
  2329. ControllableImage.prototype.render = function (parent) {
  2330. var attrs = this.attrsFromOptions(this.options),
  2331. options = this.options;
  2332. this.graphic = this.annotation.chart.renderer
  2333. .image(options.src, 0, -9e9, options.width, options.height)
  2334. .attr(attrs)
  2335. .add(parent);
  2336. this.graphic.width = options.width;
  2337. this.graphic.height = options.height;
  2338. ControllableMixin.render.call(this);
  2339. };
  2340. ControllableImage.prototype.redraw = function (animation) {
  2341. var anchor = this.anchor(this.points[0]),
  2342. position = ControllableLabel.prototype.position.call(this,
  2343. anchor);
  2344. if (position) {
  2345. this.graphic[animation ? 'animate' : 'attr']({
  2346. x: position.x,
  2347. y: position.y
  2348. });
  2349. }
  2350. else {
  2351. this.graphic.attr({
  2352. x: 0,
  2353. y: -9e9
  2354. });
  2355. }
  2356. this.graphic.placed = Boolean(position);
  2357. ControllableMixin.redraw.call(this, animation);
  2358. };
  2359. /* *
  2360. *
  2361. * Static Properties
  2362. *
  2363. * */
  2364. /**
  2365. * A map object which allows to map options attributes to element attributes
  2366. *
  2367. * @name Highcharts.AnnotationControllableImage.attrsMap
  2368. * @type {Highcharts.Dictionary<string>}
  2369. */
  2370. ControllableImage.attrsMap = {
  2371. width: 'width',
  2372. height: 'height',
  2373. zIndex: 'zIndex'
  2374. };
  2375. return ControllableImage;
  2376. }());
  2377. return ControllableImage;
  2378. });
  2379. _registerModule(_modules, 'Extensions/Annotations/Annotations.js', [_modules['Core/Chart/Chart.js'], _modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllableRect.js'], _modules['Extensions/Annotations/Controllables/ControllableCircle.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Extensions/Annotations/Controllables/ControllableImage.js'], _modules['Extensions/Annotations/Controllables/ControllableLabel.js'], _modules['Extensions/Annotations/ControlPoint.js'], _modules['Extensions/Annotations/Mixins/EventEmitterMixin.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Pointer.js'], _modules['Core/Utilities.js']], function (Chart, ControllableMixin, ControllableRect, ControllableCircle, ControllablePath, ControllableImage, ControllableLabel, ControlPoint, EventEmitterMixin, H, MockPoint, Pointer, U) {
  2380. /* *
  2381. *
  2382. * (c) 2009-2017 Highsoft, Black Label
  2383. *
  2384. * License: www.highcharts.com/license
  2385. *
  2386. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2387. *
  2388. * */
  2389. var chartProto = Chart.prototype;
  2390. var addEvent = U.addEvent,
  2391. defined = U.defined,
  2392. destroyObjectProperties = U.destroyObjectProperties,
  2393. erase = U.erase,
  2394. extend = U.extend,
  2395. find = U.find,
  2396. fireEvent = U.fireEvent,
  2397. getDeferredAnimation = U.getDeferredAnimation,
  2398. merge = U.merge,
  2399. pick = U.pick,
  2400. splat = U.splat,
  2401. wrap = U.wrap;
  2402. /* *********************************************************************
  2403. *
  2404. * ANNOTATION
  2405. *
  2406. ******************************************************************** */
  2407. /**
  2408. * Possible directions for draggable annotations. An empty string (`''`)
  2409. * makes the annotation undraggable.
  2410. *
  2411. * @typedef {''|'x'|'xy'|'y'} Highcharts.AnnotationDraggableValue
  2412. */
  2413. /**
  2414. * @private
  2415. * @typedef {
  2416. * Highcharts.AnnotationControllableCircle|
  2417. * Highcharts.AnnotationControllableImage|
  2418. * Highcharts.AnnotationControllablePath|
  2419. * Highcharts.AnnotationControllableRect
  2420. * }
  2421. * Highcharts.AnnotationShapeType
  2422. * @requires modules/annotations
  2423. */
  2424. /**
  2425. * @private
  2426. * @typedef {
  2427. * Highcharts.AnnotationControllableLabel
  2428. * }
  2429. * Highcharts.AnnotationLabelType
  2430. * @requires modules/annotations
  2431. */
  2432. /**
  2433. * A point-like object, a mock point or a point used in series.
  2434. * @private
  2435. * @typedef {Highcharts.AnnotationMockPoint|Highcharts.Point} Highcharts.AnnotationPointType
  2436. * @requires modules/annotations
  2437. */
  2438. /* eslint-disable no-invalid-this, valid-jsdoc */
  2439. /**
  2440. * An annotation class which serves as a container for items like labels or
  2441. * shapes. Created items are positioned on the chart either by linking them to
  2442. * existing points or created mock points
  2443. *
  2444. * @class
  2445. * @name Highcharts.Annotation
  2446. *
  2447. * @param {Highcharts.Chart} chart a chart instance
  2448. * @param {Highcharts.AnnotationsOptions} userOptions the options object
  2449. */
  2450. var Annotation = /** @class */ (function () {
  2451. /* *
  2452. *
  2453. * Constructors
  2454. *
  2455. * */
  2456. function Annotation(chart, userOptions) {
  2457. /* *
  2458. *
  2459. * Properties
  2460. *
  2461. * */
  2462. this.annotation = void 0;
  2463. this.coll = 'annotations';
  2464. this.collection = void 0;
  2465. this.animationConfig = void 0;
  2466. this.graphic = void 0;
  2467. this.group = void 0;
  2468. this.labelCollector = void 0;
  2469. this.labelsGroup = void 0;
  2470. this.shapesGroup = void 0;
  2471. var labelsAndShapes;
  2472. /**
  2473. * The chart that the annotation belongs to.
  2474. *
  2475. * @type {Highcharts.Chart}
  2476. */
  2477. this.chart = chart;
  2478. /**
  2479. * The array of points which defines the annotation.
  2480. *
  2481. * @type {Array<Highcharts.Point>}
  2482. */
  2483. this.points = [];
  2484. /**
  2485. * The array of control points.
  2486. *
  2487. * @private
  2488. * @name Highcharts.Annotation#controlPoints
  2489. * @type {Array<Annotation.ControlPoint>}
  2490. */
  2491. this.controlPoints = [];
  2492. this.coll = 'annotations';
  2493. /**
  2494. * The array of labels which belong to the annotation.
  2495. *
  2496. * @private
  2497. * @name Highcharts.Annotation#labels
  2498. * @type {Array<Highcharts.AnnotationLabelType>}
  2499. */
  2500. this.labels = [];
  2501. /**
  2502. * The array of shapes which belong to the annotation.
  2503. *
  2504. * @private
  2505. * @name Highcharts.Annotation#shapes
  2506. * @type {Array<Highcharts.AnnotationShapeType>}
  2507. */
  2508. this.shapes = [];
  2509. /**
  2510. * The options for the annotations.
  2511. *
  2512. * @name Highcharts.Annotation#options
  2513. * @type {Highcharts.AnnotationsOptions}
  2514. */
  2515. this.options = merge(this.defaultOptions, userOptions);
  2516. /**
  2517. * The user options for the annotations.
  2518. *
  2519. * @name Highcharts.Annotation#userOptions
  2520. * @type {Highcharts.AnnotationsOptions}
  2521. */
  2522. this.userOptions = userOptions;
  2523. // Handle labels and shapes - those are arrays
  2524. // Merging does not work with arrays (stores reference)
  2525. labelsAndShapes = this.getLabelsAndShapesOptions(this.options, userOptions);
  2526. this.options.labels = labelsAndShapes.labels;
  2527. this.options.shapes = labelsAndShapes.shapes;
  2528. /**
  2529. * The callback that reports to the overlapping-labels module which
  2530. * labels it should account for.
  2531. * @private
  2532. * @name Highcharts.Annotation#labelCollector
  2533. * @type {Function}
  2534. */
  2535. /**
  2536. * The group svg element.
  2537. *
  2538. * @name Highcharts.Annotation#group
  2539. * @type {Highcharts.SVGElement}
  2540. */
  2541. /**
  2542. * The group svg element of the annotation's shapes.
  2543. *
  2544. * @name Highcharts.Annotation#shapesGroup
  2545. * @type {Highcharts.SVGElement}
  2546. */
  2547. /**
  2548. * The group svg element of the annotation's labels.
  2549. *
  2550. * @name Highcharts.Annotation#labelsGroup
  2551. * @type {Highcharts.SVGElement}
  2552. */
  2553. this.init(chart, this.options);
  2554. }
  2555. /**
  2556. * Initialize the annotation.
  2557. * @private
  2558. */
  2559. Annotation.prototype.init = function () {
  2560. var chart = this.chart,
  2561. animOptions = this.options.animation;
  2562. this.linkPoints();
  2563. this.addControlPoints();
  2564. this.addShapes();
  2565. this.addLabels();
  2566. this.setLabelCollector();
  2567. this.animationConfig = getDeferredAnimation(chart, animOptions);
  2568. };
  2569. Annotation.prototype.getLabelsAndShapesOptions = function (baseOptions, newOptions) {
  2570. var mergedOptions = {};
  2571. ['labels', 'shapes'].forEach(function (name) {
  2572. if (baseOptions[name]) {
  2573. mergedOptions[name] = splat(newOptions[name]).map(function (basicOptions, i) {
  2574. return merge(baseOptions[name][i], basicOptions);
  2575. });
  2576. }
  2577. });
  2578. return mergedOptions;
  2579. };
  2580. Annotation.prototype.addShapes = function () {
  2581. (this.options.shapes || []).forEach(function (shapeOptions, i) {
  2582. var shape = this.initShape(shapeOptions,
  2583. i);
  2584. merge(true, this.options.shapes[i], shape.options);
  2585. }, this);
  2586. };
  2587. Annotation.prototype.addLabels = function () {
  2588. (this.options.labels || []).forEach(function (labelsOptions, i) {
  2589. var labels = this.initLabel(labelsOptions,
  2590. i);
  2591. merge(true, this.options.labels[i], labels.options);
  2592. }, this);
  2593. };
  2594. Annotation.prototype.addClipPaths = function () {
  2595. this.setClipAxes();
  2596. if (this.clipXAxis && this.clipYAxis) {
  2597. this.clipRect = this.chart.renderer.clipRect(this.getClipBox());
  2598. }
  2599. };
  2600. Annotation.prototype.setClipAxes = function () {
  2601. var xAxes = this.chart.xAxis,
  2602. yAxes = this.chart.yAxis,
  2603. linkedAxes = (this.options.labels || [])
  2604. .concat(this.options.shapes || [])
  2605. .reduce(function (axes,
  2606. labelOrShape) {
  2607. return [
  2608. xAxes[labelOrShape &&
  2609. labelOrShape.point &&
  2610. labelOrShape.point.xAxis] || axes[0],
  2611. yAxes[labelOrShape &&
  2612. labelOrShape.point &&
  2613. labelOrShape.point.yAxis] || axes[1]
  2614. ];
  2615. }, []);
  2616. this.clipXAxis = linkedAxes[0];
  2617. this.clipYAxis = linkedAxes[1];
  2618. };
  2619. Annotation.prototype.getClipBox = function () {
  2620. if (this.clipXAxis && this.clipYAxis) {
  2621. return {
  2622. x: this.clipXAxis.left,
  2623. y: this.clipYAxis.top,
  2624. width: this.clipXAxis.width,
  2625. height: this.clipYAxis.height
  2626. };
  2627. }
  2628. };
  2629. Annotation.prototype.setLabelCollector = function () {
  2630. var annotation = this;
  2631. annotation.labelCollector = function () {
  2632. return annotation.labels.reduce(function (labels, label) {
  2633. if (!label.options.allowOverlap) {
  2634. labels.push(label.graphic);
  2635. }
  2636. return labels;
  2637. }, []);
  2638. };
  2639. annotation.chart.labelCollectors.push(annotation.labelCollector);
  2640. };
  2641. /**
  2642. * Set an annotation options.
  2643. * @private
  2644. * @param {Highcharts.AnnotationsOptions} - user options for an annotation
  2645. */
  2646. Annotation.prototype.setOptions = function (userOptions) {
  2647. this.options = merge(this.defaultOptions, userOptions);
  2648. };
  2649. Annotation.prototype.redraw = function (animation) {
  2650. this.linkPoints();
  2651. if (!this.graphic) {
  2652. this.render();
  2653. }
  2654. if (this.clipRect) {
  2655. this.clipRect.animate(this.getClipBox());
  2656. }
  2657. this.redrawItems(this.shapes, animation);
  2658. this.redrawItems(this.labels, animation);
  2659. ControllableMixin.redraw.call(this, animation);
  2660. };
  2661. /**
  2662. * @private
  2663. * @param {Array<Highcharts.AnnotationControllable>} items
  2664. * @param {boolean} [animation]
  2665. */
  2666. Annotation.prototype.redrawItems = function (items, animation) {
  2667. var i = items.length;
  2668. // needs a backward loop
  2669. // labels/shapes array might be modified
  2670. // due to destruction of the item
  2671. while (i--) {
  2672. this.redrawItem(items[i], animation);
  2673. }
  2674. };
  2675. /**
  2676. * @private
  2677. * @param {Array<Highcharts.AnnotationControllable>} items
  2678. */
  2679. Annotation.prototype.renderItems = function (items) {
  2680. var i = items.length;
  2681. while (i--) {
  2682. this.renderItem(items[i]);
  2683. }
  2684. };
  2685. Annotation.prototype.render = function () {
  2686. var renderer = this.chart.renderer;
  2687. this.graphic = renderer
  2688. .g('annotation')
  2689. .attr({
  2690. opacity: 0,
  2691. zIndex: this.options.zIndex,
  2692. visibility: this.options.visible ?
  2693. 'visible' :
  2694. 'hidden'
  2695. })
  2696. .add();
  2697. this.shapesGroup = renderer
  2698. .g('annotation-shapes')
  2699. .add(this.graphic)
  2700. .clip(this.chart.plotBoxClip);
  2701. this.labelsGroup = renderer
  2702. .g('annotation-labels')
  2703. .attr({
  2704. // hideOverlappingLabels requires translation
  2705. translateX: 0,
  2706. translateY: 0
  2707. })
  2708. .add(this.graphic);
  2709. this.addClipPaths();
  2710. if (this.clipRect) {
  2711. this.graphic.clip(this.clipRect);
  2712. }
  2713. // Render shapes and labels before adding events (#13070).
  2714. this.renderItems(this.shapes);
  2715. this.renderItems(this.labels);
  2716. this.addEvents();
  2717. ControllableMixin.render.call(this);
  2718. };
  2719. /**
  2720. * Set the annotation's visibility.
  2721. * @private
  2722. * @param {boolean} [visible]
  2723. * Whether to show or hide an annotation. If the param is omitted, the
  2724. * annotation's visibility is toggled.
  2725. */
  2726. Annotation.prototype.setVisibility = function (visible) {
  2727. var options = this.options,
  2728. visibility = pick(visible, !options.visible);
  2729. this.graphic.attr('visibility', visibility ? 'visible' : 'hidden');
  2730. if (!visibility) {
  2731. this.setControlPointsVisibility(false);
  2732. }
  2733. options.visible = visibility;
  2734. };
  2735. Annotation.prototype.setControlPointsVisibility = function (visible) {
  2736. var setItemControlPointsVisibility = function (item) {
  2737. item.setControlPointsVisibility(visible);
  2738. };
  2739. ControllableMixin.setControlPointsVisibility.call(this, visible);
  2740. this.shapes.forEach(setItemControlPointsVisibility);
  2741. this.labels.forEach(setItemControlPointsVisibility);
  2742. };
  2743. /**
  2744. * Destroy the annotation. This function does not touch the chart
  2745. * that the annotation belongs to (all annotations are kept in
  2746. * the chart.annotations array) - it is recommended to use
  2747. * {@link Highcharts.Chart#removeAnnotation} instead.
  2748. * @private
  2749. */
  2750. Annotation.prototype.destroy = function () {
  2751. var chart = this.chart,
  2752. destroyItem = function (item) {
  2753. item.destroy();
  2754. };
  2755. this.labels.forEach(destroyItem);
  2756. this.shapes.forEach(destroyItem);
  2757. this.clipXAxis = null;
  2758. this.clipYAxis = null;
  2759. erase(chart.labelCollectors, this.labelCollector);
  2760. EventEmitterMixin.destroy.call(this);
  2761. ControllableMixin.destroy.call(this);
  2762. destroyObjectProperties(this, chart);
  2763. };
  2764. /**
  2765. * See {@link Highcharts.Chart#removeAnnotation}.
  2766. * @private
  2767. */
  2768. Annotation.prototype.remove = function () {
  2769. // Let chart.update() remove annoations on demand
  2770. return this.chart.removeAnnotation(this);
  2771. };
  2772. /**
  2773. * Updates an annotation.
  2774. *
  2775. * @function Highcharts.Annotation#update
  2776. *
  2777. * @param {Partial<Highcharts.AnnotationsOptions>} userOptions
  2778. * New user options for the annotation.
  2779. *
  2780. * @return {void}
  2781. */
  2782. Annotation.prototype.update = function (userOptions, redraw) {
  2783. var chart = this.chart,
  2784. labelsAndShapes = this.getLabelsAndShapesOptions(this.userOptions,
  2785. userOptions),
  2786. userOptionsIndex = chart.annotations.indexOf(this),
  2787. options = merge(true,
  2788. this.userOptions,
  2789. userOptions);
  2790. options.labels = labelsAndShapes.labels;
  2791. options.shapes = labelsAndShapes.shapes;
  2792. this.destroy();
  2793. this.constructor(chart, options);
  2794. // Update options in chart options, used in exporting (#9767):
  2795. chart.options.annotations[userOptionsIndex] = options;
  2796. this.isUpdating = true;
  2797. if (pick(redraw, true)) {
  2798. chart.redraw();
  2799. }
  2800. fireEvent(this, 'afterUpdate');
  2801. this.isUpdating = false;
  2802. };
  2803. /* *************************************************************
  2804. * ITEM SECTION
  2805. * Contains methods for handling a single item in an annotation
  2806. **************************************************************** */
  2807. /**
  2808. * Initialisation of a single shape
  2809. * @private
  2810. * @param {Object} shapeOptions - a confg object for a single shape
  2811. */
  2812. Annotation.prototype.initShape = function (shapeOptions, index) {
  2813. var options = merge(this.options.shapeOptions, {
  2814. controlPointOptions: this.options.controlPointOptions
  2815. },
  2816. shapeOptions),
  2817. shape = new Annotation.shapesMap[options.type](this,
  2818. options,
  2819. index);
  2820. shape.itemType = 'shape';
  2821. this.shapes.push(shape);
  2822. return shape;
  2823. };
  2824. /**
  2825. * Initialisation of a single label
  2826. * @private
  2827. */
  2828. Annotation.prototype.initLabel = function (labelOptions, index) {
  2829. var options = merge(this.options.labelOptions, {
  2830. controlPointOptions: this.options.controlPointOptions
  2831. },
  2832. labelOptions),
  2833. label = new ControllableLabel(this,
  2834. options,
  2835. index);
  2836. label.itemType = 'label';
  2837. this.labels.push(label);
  2838. return label;
  2839. };
  2840. /**
  2841. * Redraw a single item.
  2842. * @private
  2843. * @param {Annotation.Label|Annotation.Shape} item
  2844. * @param {boolean} [animation]
  2845. */
  2846. Annotation.prototype.redrawItem = function (item, animation) {
  2847. item.linkPoints();
  2848. if (!item.shouldBeDrawn()) {
  2849. this.destroyItem(item);
  2850. }
  2851. else {
  2852. if (!item.graphic) {
  2853. this.renderItem(item);
  2854. }
  2855. item.redraw(pick(animation, true) && item.graphic.placed);
  2856. if (item.points.length) {
  2857. this.adjustVisibility(item);
  2858. }
  2859. }
  2860. };
  2861. /**
  2862. * Hide or show annotaiton attached to points.
  2863. * @private
  2864. * @param {Annotation.Label|Annotation.Shape} item
  2865. */
  2866. Annotation.prototype.adjustVisibility = function (item) {
  2867. var hasVisiblePoints = false,
  2868. label = item.graphic;
  2869. item.points.forEach(function (point) {
  2870. if (point.series.visible !== false &&
  2871. point.visible !== false) {
  2872. hasVisiblePoints = true;
  2873. }
  2874. });
  2875. if (!hasVisiblePoints) {
  2876. label.hide();
  2877. }
  2878. else if (label.visibility === 'hidden') {
  2879. label.show();
  2880. }
  2881. };
  2882. /**
  2883. * Destroy a single item.
  2884. * @private
  2885. * @param {Annotation.Label|Annotation.Shape} item
  2886. */
  2887. Annotation.prototype.destroyItem = function (item) {
  2888. // erase from shapes or labels array
  2889. erase(this[item.itemType + 's'], item);
  2890. item.destroy();
  2891. };
  2892. /**
  2893. * @private
  2894. */
  2895. Annotation.prototype.renderItem = function (item) {
  2896. item.render(item.itemType === 'label' ?
  2897. this.labelsGroup :
  2898. this.shapesGroup);
  2899. };
  2900. /**
  2901. * @private
  2902. */
  2903. Annotation.ControlPoint = ControlPoint;
  2904. /**
  2905. * @private
  2906. */
  2907. Annotation.MockPoint = MockPoint;
  2908. /**
  2909. * An object uses for mapping between a shape type and a constructor.
  2910. * To add a new shape type extend this object with type name as a key
  2911. * and a constructor as its value.
  2912. */
  2913. Annotation.shapesMap = {
  2914. 'rect': ControllableRect,
  2915. 'circle': ControllableCircle,
  2916. 'path': ControllablePath,
  2917. 'image': ControllableImage
  2918. };
  2919. /**
  2920. * @private
  2921. */
  2922. Annotation.types = {};
  2923. return Annotation;
  2924. }());
  2925. merge(true, Annotation.prototype, ControllableMixin, EventEmitterMixin,
  2926. // restore original Annotation implementation after mixin overwrite
  2927. merge(Annotation.prototype,
  2928. /** @lends Highcharts.Annotation# */
  2929. {
  2930. /**
  2931. * List of events for `annotation.options.events` that should not be
  2932. * added to `annotation.graphic` but to the `annotation`.
  2933. *
  2934. * @private
  2935. * @type {Array<string>}
  2936. */
  2937. nonDOMEvents: ['add', 'afterUpdate', 'drag', 'remove'],
  2938. /**
  2939. * A basic type of an annotation. It allows to add custom labels
  2940. * or shapes. The items can be tied to points, axis coordinates
  2941. * or chart pixel coordinates.
  2942. *
  2943. * @sample highcharts/annotations/basic/
  2944. * Basic annotations
  2945. * @sample highcharts/demo/annotations/
  2946. * Advanced annotations
  2947. * @sample highcharts/css/annotations
  2948. * Styled mode
  2949. * @sample highcharts/annotations-advanced/controllable
  2950. * Controllable items
  2951. * @sample {highstock} stock/annotations/fibonacci-retracements
  2952. * Custom annotation, Fibonacci retracement
  2953. *
  2954. * @type {Array<*>}
  2955. * @since 6.0.0
  2956. * @requires modules/annotations
  2957. * @optionparent annotations
  2958. *
  2959. * @private
  2960. */
  2961. defaultOptions: {
  2962. /**
  2963. * Sets an ID for an annotation. Can be user later when
  2964. * removing an annotation in [Chart#removeAnnotation(id)](
  2965. * /class-reference/Highcharts.Chart#removeAnnotation) method.
  2966. *
  2967. * @type {number|string}
  2968. * @apioption annotations.id
  2969. */
  2970. /**
  2971. * Whether the annotation is visible.
  2972. *
  2973. * @sample highcharts/annotations/visible/
  2974. * Set annotation visibility
  2975. */
  2976. visible: true,
  2977. /**
  2978. * Enable or disable the initial animation when a series is
  2979. * displayed for the `annotation`. The animation can also be set
  2980. * as a configuration object. Please note that this option only
  2981. * applies to the initial animation.
  2982. * For other animations, see [chart.animation](#chart.animation)
  2983. * and the animation parameter under the API methods.
  2984. * The following properties are supported:
  2985. *
  2986. * - `defer`: The animation delay time in milliseconds.
  2987. *
  2988. * @sample {highcharts} highcharts/annotations/defer/
  2989. * Animation defer settings
  2990. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  2991. * @since 8.2.0
  2992. * @apioption annotations.animation
  2993. */
  2994. animation: {},
  2995. /**
  2996. * The animation delay time in milliseconds.
  2997. * Set to `0` renders annotation immediately.
  2998. * As `undefined` inherits defer time from the [series.animation.defer](#plotOptions.series.animation.defer).
  2999. *
  3000. * @type {number}
  3001. * @since 8.2.0
  3002. * @apioption annotations.animation.defer
  3003. */
  3004. /**
  3005. * Allow an annotation to be draggable by a user. Possible
  3006. * values are `'x'`, `'xy'`, `'y'` and `''` (disabled).
  3007. *
  3008. * @sample highcharts/annotations/draggable/
  3009. * Annotations draggable: 'xy'
  3010. *
  3011. * @type {Highcharts.AnnotationDraggableValue}
  3012. */
  3013. draggable: 'xy',
  3014. /**
  3015. * Options for annotation's labels. Each label inherits options
  3016. * from the labelOptions object. An option from the labelOptions
  3017. * can be overwritten by config for a specific label.
  3018. *
  3019. * @requires modules/annotations
  3020. */
  3021. labelOptions: {
  3022. /**
  3023. * The alignment of the annotation's label. If right,
  3024. * the right side of the label should be touching the point.
  3025. *
  3026. * @sample highcharts/annotations/label-position/
  3027. * Set labels position
  3028. *
  3029. * @type {Highcharts.AlignValue}
  3030. */
  3031. align: 'center',
  3032. /**
  3033. * Whether to allow the annotation's labels to overlap.
  3034. * To make the labels less sensitive for overlapping,
  3035. * the can be set to 0.
  3036. *
  3037. * @sample highcharts/annotations/tooltip-like/
  3038. * Hide overlapping labels
  3039. */
  3040. allowOverlap: false,
  3041. /**
  3042. * The background color or gradient for the annotation's
  3043. * label.
  3044. *
  3045. * @sample highcharts/annotations/label-presentation/
  3046. * Set labels graphic options
  3047. *
  3048. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3049. */
  3050. backgroundColor: 'rgba(0, 0, 0, 0.75)',
  3051. /**
  3052. * The border color for the annotation's label.
  3053. *
  3054. * @sample highcharts/annotations/label-presentation/
  3055. * Set labels graphic options
  3056. *
  3057. * @type {Highcharts.ColorString}
  3058. */
  3059. borderColor: 'black',
  3060. /**
  3061. * The border radius in pixels for the annotaiton's label.
  3062. *
  3063. * @sample highcharts/annotations/label-presentation/
  3064. * Set labels graphic options
  3065. */
  3066. borderRadius: 3,
  3067. /**
  3068. * The border width in pixels for the annotation's label
  3069. *
  3070. * @sample highcharts/annotations/label-presentation/
  3071. * Set labels graphic options
  3072. */
  3073. borderWidth: 1,
  3074. /**
  3075. * A class name for styling by CSS.
  3076. *
  3077. * @sample highcharts/css/annotations
  3078. * Styled mode annotations
  3079. *
  3080. * @since 6.0.5
  3081. */
  3082. className: '',
  3083. /**
  3084. * Whether to hide the annotation's label
  3085. * that is outside the plot area.
  3086. *
  3087. * @sample highcharts/annotations/label-crop-overflow/
  3088. * Crop or justify labels
  3089. */
  3090. crop: false,
  3091. /**
  3092. * The label's pixel distance from the point.
  3093. *
  3094. * @sample highcharts/annotations/label-position/
  3095. * Set labels position
  3096. *
  3097. * @type {number}
  3098. * @apioption annotations.labelOptions.distance
  3099. */
  3100. /**
  3101. * A
  3102. * [format](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  3103. * string for the data label.
  3104. *
  3105. * @see [plotOptions.series.dataLabels.format](plotOptions.series.dataLabels.format.html)
  3106. *
  3107. * @sample highcharts/annotations/label-text/
  3108. * Set labels text
  3109. *
  3110. * @type {string}
  3111. * @apioption annotations.labelOptions.format
  3112. */
  3113. /**
  3114. * Alias for the format option.
  3115. *
  3116. * @see [format](annotations.labelOptions.format.html)
  3117. *
  3118. * @sample highcharts/annotations/label-text/
  3119. * Set labels text
  3120. *
  3121. * @type {string}
  3122. * @apioption annotations.labelOptions.text
  3123. */
  3124. /**
  3125. * Callback JavaScript function to format the annotation's
  3126. * label. Note that if a `format` or `text` are defined,
  3127. * the format or text take precedence and the formatter is
  3128. * ignored. `This` refers to a point object.
  3129. *
  3130. * @sample highcharts/annotations/label-text/
  3131. * Set labels text
  3132. *
  3133. * @type {Highcharts.FormatterCallbackFunction<Highcharts.Point>}
  3134. * @default function () { return defined(this.y) ? this.y : 'Annotation label'; }
  3135. */
  3136. formatter: function () {
  3137. return defined(this.y) ? this.y : 'Annotation label';
  3138. },
  3139. /**
  3140. * Whether the annotation is visible in the exported data
  3141. * table.
  3142. *
  3143. * @sample highcharts/annotations/include-in-data-export/
  3144. * Do not include in the data export
  3145. *
  3146. * @since 8.2.0
  3147. * @requires modules/export-data
  3148. */
  3149. includeInDataExport: true,
  3150. /**
  3151. * How to handle the annotation's label that flow outside
  3152. * the plot area. The justify option aligns the label inside
  3153. * the plot area.
  3154. *
  3155. * @sample highcharts/annotations/label-crop-overflow/
  3156. * Crop or justify labels
  3157. *
  3158. * @validvalue ["allow", "justify"]
  3159. */
  3160. overflow: 'justify',
  3161. /**
  3162. * When either the borderWidth or the backgroundColor is
  3163. * set, this is the padding within the box.
  3164. *
  3165. * @sample highcharts/annotations/label-presentation/
  3166. * Set labels graphic options
  3167. */
  3168. padding: 5,
  3169. /**
  3170. * The shadow of the box. The shadow can be an object
  3171. * configuration containing `color`, `offsetX`, `offsetY`,
  3172. * `opacity` and `width`.
  3173. *
  3174. * @sample highcharts/annotations/label-presentation/
  3175. * Set labels graphic options
  3176. *
  3177. * @type {boolean|Highcharts.ShadowOptionsObject}
  3178. */
  3179. shadow: false,
  3180. /**
  3181. * The name of a symbol to use for the border around the
  3182. * label. Symbols are predefined functions on the Renderer
  3183. * object.
  3184. *
  3185. * @sample highcharts/annotations/shapes/
  3186. * Available shapes for labels
  3187. */
  3188. shape: 'callout',
  3189. /**
  3190. * Styles for the annotation's label.
  3191. *
  3192. * @see [plotOptions.series.dataLabels.style](plotOptions.series.dataLabels.style.html)
  3193. *
  3194. * @sample highcharts/annotations/label-presentation/
  3195. * Set labels graphic options
  3196. *
  3197. * @type {Highcharts.CSSObject}
  3198. */
  3199. style: {
  3200. /** @ignore */
  3201. fontSize: '11px',
  3202. /** @ignore */
  3203. fontWeight: 'normal',
  3204. /** @ignore */
  3205. color: 'contrast'
  3206. },
  3207. /**
  3208. * Whether to [use HTML](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting#html)
  3209. * to render the annotation's label.
  3210. */
  3211. useHTML: false,
  3212. /**
  3213. * The vertical alignment of the annotation's label.
  3214. *
  3215. * @sample highcharts/annotations/label-position/
  3216. * Set labels position
  3217. *
  3218. * @type {Highcharts.VerticalAlignValue}
  3219. */
  3220. verticalAlign: 'bottom',
  3221. /**
  3222. * The x position offset of the label relative to the point.
  3223. * Note that if a `distance` is defined, the distance takes
  3224. * precedence over `x` and `y` options.
  3225. *
  3226. * @sample highcharts/annotations/label-position/
  3227. * Set labels position
  3228. */
  3229. x: 0,
  3230. /**
  3231. * The y position offset of the label relative to the point.
  3232. * Note that if a `distance` is defined, the distance takes
  3233. * precedence over `x` and `y` options.
  3234. *
  3235. * @sample highcharts/annotations/label-position/
  3236. * Set labels position
  3237. */
  3238. y: -16
  3239. },
  3240. /**
  3241. * An array of labels for the annotation. For options that apply
  3242. * to multiple labels, they can be added to the
  3243. * [labelOptions](annotations.labelOptions.html).
  3244. *
  3245. * @type {Array<*>}
  3246. * @extends annotations.labelOptions
  3247. * @apioption annotations.labels
  3248. */
  3249. /**
  3250. * This option defines the point to which the label will be
  3251. * connected. It can be either the point which exists in the
  3252. * series - it is referenced by the point's id - or a new point
  3253. * with defined x, y properties and optionally axes.
  3254. *
  3255. * @sample highcharts/annotations/mock-point/
  3256. * Attach annotation to a mock point
  3257. *
  3258. * @declare Highcharts.AnnotationMockPointOptionsObject
  3259. * @type {string|*}
  3260. * @requires modules/annotations
  3261. * @apioption annotations.labels.point
  3262. */
  3263. /**
  3264. * The x position of the point. Units can be either in axis
  3265. * or chart pixel coordinates.
  3266. *
  3267. * @type {number}
  3268. * @apioption annotations.labels.point.x
  3269. */
  3270. /**
  3271. * The y position of the point. Units can be either in axis
  3272. * or chart pixel coordinates.
  3273. *
  3274. * @type {number}
  3275. * @apioption annotations.labels.point.y
  3276. */
  3277. /**
  3278. * This number defines which xAxis the point is connected to.
  3279. * It refers to either the axis id or the index of the axis in
  3280. * the xAxis array. If the option is not configured or the axis
  3281. * is not found the point's x coordinate refers to the chart
  3282. * pixels.
  3283. *
  3284. * @type {number|string|null}
  3285. * @apioption annotations.labels.point.xAxis
  3286. */
  3287. /**
  3288. * This number defines which yAxis the point is connected to.
  3289. * It refers to either the axis id or the index of the axis in
  3290. * the yAxis array. If the option is not configured or the axis
  3291. * is not found the point's y coordinate refers to the chart
  3292. * pixels.
  3293. *
  3294. * @type {number|string|null}
  3295. * @apioption annotations.labels.point.yAxis
  3296. */
  3297. /**
  3298. * An array of shapes for the annotation. For options that apply
  3299. * to multiple shapes, then can be added to the
  3300. * [shapeOptions](annotations.shapeOptions.html).
  3301. *
  3302. * @type {Array<*>}
  3303. * @extends annotations.shapeOptions
  3304. * @apioption annotations.shapes
  3305. */
  3306. /**
  3307. * This option defines the point to which the shape will be
  3308. * connected. It can be either the point which exists in the
  3309. * series - it is referenced by the point's id - or a new point
  3310. * with defined x, y properties and optionally axes.
  3311. *
  3312. * @declare Highcharts.AnnotationMockPointOptionsObject
  3313. * @type {string|Highcharts.AnnotationMockPointOptionsObject}
  3314. * @extends annotations.labels.point
  3315. * @apioption annotations.shapes.point
  3316. */
  3317. /**
  3318. * An array of points for the shape. This option is available
  3319. * for shapes which can use multiple points such as path. A
  3320. * point can be either a point object or a point's id.
  3321. *
  3322. * @see [annotations.shapes.point](annotations.shapes.point.html)
  3323. *
  3324. * @declare Highcharts.AnnotationMockPointOptionsObject
  3325. * @type {Array<string|*>}
  3326. * @extends annotations.labels.point
  3327. * @apioption annotations.shapes.points
  3328. */
  3329. /**
  3330. * The URL for an image to use as the annotation shape. Note,
  3331. * type has to be set to `'image'`.
  3332. *
  3333. * @see [annotations.shapes.type](annotations.shapes.type)
  3334. * @sample highcharts/annotations/shape-src/
  3335. * Define a marker image url for annotations
  3336. *
  3337. * @type {string}
  3338. * @apioption annotations.shapes.src
  3339. */
  3340. /**
  3341. * Id of the marker which will be drawn at the final vertex of
  3342. * the path. Custom markers can be defined in defs property.
  3343. *
  3344. * @see [defs.markers](defs.markers.html)
  3345. *
  3346. * @sample highcharts/annotations/custom-markers/
  3347. * Define a custom marker for annotations
  3348. *
  3349. * @type {string}
  3350. * @apioption annotations.shapes.markerEnd
  3351. */
  3352. /**
  3353. * Id of the marker which will be drawn at the first vertex of
  3354. * the path. Custom markers can be defined in defs property.
  3355. *
  3356. * @see [defs.markers](defs.markers.html)
  3357. *
  3358. * @sample {highcharts} highcharts/annotations/custom-markers/
  3359. * Define a custom marker for annotations
  3360. *
  3361. * @type {string}
  3362. * @apioption annotations.shapes.markerStart
  3363. */
  3364. /**
  3365. * Options for annotation's shapes. Each shape inherits options
  3366. * from the shapeOptions object. An option from the shapeOptions
  3367. * can be overwritten by config for a specific shape.
  3368. *
  3369. * @requires modules/annotations
  3370. */
  3371. shapeOptions: {
  3372. /**
  3373. * The width of the shape.
  3374. *
  3375. * @sample highcharts/annotations/shape/
  3376. * Basic shape annotation
  3377. *
  3378. * @type {number}
  3379. * @apioption annotations.shapeOptions.width
  3380. **/
  3381. /**
  3382. * The height of the shape.
  3383. *
  3384. * @sample highcharts/annotations/shape/
  3385. * Basic shape annotation
  3386. *
  3387. * @type {number}
  3388. * @apioption annotations.shapeOptions.height
  3389. */
  3390. /**
  3391. * The type of the shape, e.g. circle or rectangle.
  3392. *
  3393. * @sample highcharts/annotations/shape/
  3394. * Basic shape annotation
  3395. *
  3396. * @type {string}
  3397. * @default 'rect'
  3398. * @apioption annotations.shapeOptions.type
  3399. */
  3400. /**
  3401. * The URL for an image to use as the annotation shape.
  3402. * Note, type has to be set to `'image'`.
  3403. *
  3404. * @see [annotations.shapeOptions.type](annotations.shapeOptions.type)
  3405. * @sample highcharts/annotations/shape-src/
  3406. * Define a marker image url for annotations
  3407. *
  3408. * @type {string}
  3409. * @apioption annotations.shapeOptions.src
  3410. */
  3411. /**
  3412. * Name of the dash style to use for the shape's stroke.
  3413. *
  3414. * @sample {highcharts} highcharts/plotoptions/series-dashstyle-all/
  3415. * Possible values demonstrated
  3416. *
  3417. * @type {Highcharts.DashStyleValue}
  3418. * @apioption annotations.shapeOptions.dashStyle
  3419. */
  3420. /**
  3421. * The color of the shape's stroke.
  3422. *
  3423. * @sample highcharts/annotations/shape/
  3424. * Basic shape annotation
  3425. *
  3426. * @type {Highcharts.ColorString}
  3427. */
  3428. stroke: 'rgba(0, 0, 0, 0.75)',
  3429. /**
  3430. * The pixel stroke width of the shape.
  3431. *
  3432. * @sample highcharts/annotations/shape/
  3433. * Basic shape annotation
  3434. */
  3435. strokeWidth: 1,
  3436. /**
  3437. * The color of the shape's fill.
  3438. *
  3439. * @sample highcharts/annotations/shape/
  3440. * Basic shape annotation
  3441. *
  3442. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3443. */
  3444. fill: 'rgba(0, 0, 0, 0.75)',
  3445. /**
  3446. * The radius of the shape.
  3447. *
  3448. * @sample highcharts/annotations/shape/
  3449. * Basic shape annotation
  3450. */
  3451. r: 0,
  3452. /**
  3453. * Defines additional snapping area around an annotation
  3454. * making this annotation to focus. Defined in pixels.
  3455. */
  3456. snap: 2
  3457. },
  3458. /**
  3459. * Options for annotation's control points. Each control point
  3460. * inherits options from controlPointOptions object.
  3461. * Options from the controlPointOptions can be overwritten
  3462. * by options in a specific control point.
  3463. *
  3464. * @declare Highcharts.AnnotationControlPointOptionsObject
  3465. * @requires modules/annotations
  3466. * @apioption annotations.controlPointOptions
  3467. */
  3468. controlPointOptions: {
  3469. /**
  3470. * @type {Highcharts.AnnotationControlPointPositionerFunction}
  3471. * @apioption annotations.controlPointOptions.positioner
  3472. */
  3473. symbol: 'circle',
  3474. width: 10,
  3475. height: 10,
  3476. style: {
  3477. stroke: 'black',
  3478. 'stroke-width': 2,
  3479. fill: 'white'
  3480. },
  3481. visible: false,
  3482. events: {}
  3483. },
  3484. /**
  3485. * Event callback when annotation is added to the chart.
  3486. *
  3487. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3488. * @since 7.1.0
  3489. * @apioption annotations.events.add
  3490. */
  3491. /**
  3492. * Event callback when annotation is updated (e.g. drag and
  3493. * droppped or resized by control points).
  3494. *
  3495. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3496. * @since 7.1.0
  3497. * @apioption annotations.events.afterUpdate
  3498. */
  3499. /**
  3500. * Event callback when annotation is removed from the chart.
  3501. *
  3502. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3503. * @since 7.1.0
  3504. * @apioption annotations.events.remove
  3505. */
  3506. /**
  3507. * Events available in annotations.
  3508. *
  3509. * @requires modules/annotations
  3510. */
  3511. events: {},
  3512. /**
  3513. * The Z index of the annotation.
  3514. */
  3515. zIndex: 6
  3516. }
  3517. }));
  3518. H.extendAnnotation = function (Constructor, BaseConstructor, prototype, defaultOptions) {
  3519. BaseConstructor = BaseConstructor || Annotation;
  3520. merge(true, Constructor.prototype, BaseConstructor.prototype, prototype);
  3521. Constructor.prototype.defaultOptions = merge(Constructor.prototype.defaultOptions, defaultOptions || {});
  3522. };
  3523. /* *********************************************************************
  3524. *
  3525. * EXTENDING CHART PROTOTYPE
  3526. *
  3527. ******************************************************************** */
  3528. extend(chartProto, /** @lends Highcharts.Chart# */ {
  3529. initAnnotation: function (userOptions) {
  3530. var Constructor = Annotation.types[userOptions.type] || Annotation,
  3531. annotation = new Constructor(this,
  3532. userOptions);
  3533. this.annotations.push(annotation);
  3534. return annotation;
  3535. },
  3536. /**
  3537. * Add an annotation to the chart after render time.
  3538. *
  3539. * @param {Highcharts.AnnotationsOptions} options
  3540. * The annotation options for the new, detailed annotation.
  3541. * @param {boolean} [redraw]
  3542. *
  3543. * @return {Highcharts.Annotation} - The newly generated annotation.
  3544. */
  3545. addAnnotation: function (userOptions, redraw) {
  3546. var annotation = this.initAnnotation(userOptions);
  3547. this.options.annotations.push(annotation.options);
  3548. if (pick(redraw, true)) {
  3549. annotation.redraw();
  3550. annotation.graphic.attr({
  3551. opacity: 1
  3552. });
  3553. }
  3554. return annotation;
  3555. },
  3556. /**
  3557. * Remove an annotation from the chart.
  3558. *
  3559. * @param {number|string|Highcharts.Annotation} idOrAnnotation
  3560. * The annotation's id or direct annotation object.
  3561. */
  3562. removeAnnotation: function (idOrAnnotation) {
  3563. var annotations = this.annotations,
  3564. annotation = idOrAnnotation.coll === 'annotations' ?
  3565. idOrAnnotation :
  3566. find(annotations,
  3567. function (annotation) {
  3568. return annotation.options.id === idOrAnnotation;
  3569. });
  3570. if (annotation) {
  3571. fireEvent(annotation, 'remove');
  3572. erase(this.options.annotations, annotation.options);
  3573. erase(annotations, annotation);
  3574. annotation.destroy();
  3575. }
  3576. },
  3577. drawAnnotations: function () {
  3578. this.plotBoxClip.attr(this.plotBox);
  3579. this.annotations.forEach(function (annotation) {
  3580. annotation.redraw();
  3581. annotation.graphic.animate({
  3582. opacity: 1
  3583. }, annotation.animationConfig);
  3584. });
  3585. }
  3586. });
  3587. // Let chart.update() update annotations
  3588. chartProto.collectionsWithUpdate.push('annotations');
  3589. // Let chart.update() create annoations on demand
  3590. chartProto.collectionsWithInit.annotations = [chartProto.addAnnotation];
  3591. chartProto.callbacks.push(function (chart) {
  3592. chart.annotations = [];
  3593. if (!chart.options.annotations) {
  3594. chart.options.annotations = [];
  3595. }
  3596. chart.plotBoxClip = this.renderer.clipRect(this.plotBox);
  3597. chart.controlPointsGroup = chart.renderer
  3598. .g('control-points')
  3599. .attr({ zIndex: 99 })
  3600. .clip(chart.plotBoxClip)
  3601. .add();
  3602. chart.options.annotations.forEach(function (annotationOptions, i) {
  3603. var annotation = chart.initAnnotation(annotationOptions);
  3604. chart.options.annotations[i] = annotation.options;
  3605. });
  3606. chart.drawAnnotations();
  3607. addEvent(chart, 'redraw', chart.drawAnnotations);
  3608. addEvent(chart, 'destroy', function () {
  3609. chart.plotBoxClip.destroy();
  3610. chart.controlPointsGroup.destroy();
  3611. });
  3612. addEvent(chart, 'exportData', function (event) {
  3613. var _a,
  3614. _b,
  3615. _c,
  3616. _d,
  3617. _e,
  3618. _f,
  3619. _g,
  3620. _h;
  3621. var annotations = chart.annotations,
  3622. csvColumnHeaderFormatter = ((this.options.exporting &&
  3623. this.options.exporting.csv) ||
  3624. {}).columnHeaderFormatter,
  3625. // If second row doesn't have xValues
  3626. // then it is a title row thus multiple level header is in use.
  3627. multiLevelHeaders = !event.dataRows[1].xValues,
  3628. annotationHeader = (_b = (_a = chart.options.lang) === null || _a === void 0 ? void 0 : _a.exportData) === null || _b === void 0 ? void 0 : _b.annotationHeader,
  3629. columnHeaderFormatter = function (index) {
  3630. var s;
  3631. if (csvColumnHeaderFormatter) {
  3632. s = csvColumnHeaderFormatter(index);
  3633. if (s !== false) {
  3634. return s;
  3635. }
  3636. }
  3637. s = annotationHeader + ' ' + index;
  3638. if (multiLevelHeaders) {
  3639. return {
  3640. columnTitle: s,
  3641. topLevelColumnTitle: s
  3642. };
  3643. }
  3644. return s;
  3645. }, startRowLength = event.dataRows[0].length, annotationSeparator = (_e = (_d = (_c = chart.options.exporting) === null || _c === void 0 ? void 0 : _c.csv) === null || _d === void 0 ? void 0 : _d.annotations) === null || _e === void 0 ? void 0 : _e.itemDelimiter, joinAnnotations = (_h = (_g = (_f = chart.options.exporting) === null || _f === void 0 ? void 0 : _f.csv) === null || _g === void 0 ? void 0 : _g.annotations) === null || _h === void 0 ? void 0 : _h.join;
  3646. annotations.forEach(function (annotation) {
  3647. if (annotation.options.labelOptions.includeInDataExport) {
  3648. annotation.labels.forEach(function (label) {
  3649. if (label.options.text) {
  3650. var annotationText_1 = label.options.text;
  3651. label.points.forEach(function (points) {
  3652. var annotationX = points.x,
  3653. xAxisIndex = points.series.xAxis ?
  3654. points.series.xAxis.options.index :
  3655. -1;
  3656. var wasAdded = false;
  3657. // Annotation not connected to any xAxis -
  3658. // add new row.
  3659. if (xAxisIndex === -1) {
  3660. var n = event.dataRows[0].length,
  3661. newRow = new Array(n);
  3662. for (var i = 0; i < n; ++i) {
  3663. newRow[i] = '';
  3664. }
  3665. newRow.push(annotationText_1);
  3666. newRow.xValues = [];
  3667. newRow.xValues[xAxisIndex] = annotationX;
  3668. event.dataRows.push(newRow);
  3669. wasAdded = true;
  3670. }
  3671. // Annotation placed on a exported data point
  3672. // - add new column
  3673. if (!wasAdded) {
  3674. event.dataRows.forEach(function (row, rowIndex) {
  3675. if (!wasAdded &&
  3676. row.xValues &&
  3677. xAxisIndex !== void 0 &&
  3678. annotationX === row.xValues[xAxisIndex]) {
  3679. if (joinAnnotations &&
  3680. row.length > startRowLength) {
  3681. row[row.length - 1] +=
  3682. annotationSeparator + annotationText_1;
  3683. }
  3684. else {
  3685. row.push(annotationText_1);
  3686. }
  3687. wasAdded = true;
  3688. }
  3689. });
  3690. }
  3691. // Annotation not placed on any exported data point,
  3692. // but connected to the xAxis - add new row
  3693. if (!wasAdded) {
  3694. var n = event.dataRows[0].length,
  3695. newRow = new Array(n);
  3696. for (var i = 0; i < n; ++i) {
  3697. newRow[i] = '';
  3698. }
  3699. newRow[0] = annotationX;
  3700. newRow.push(annotationText_1);
  3701. newRow.xValues = [];
  3702. if (xAxisIndex !== void 0) {
  3703. newRow.xValues[xAxisIndex] = annotationX;
  3704. }
  3705. event.dataRows.push(newRow);
  3706. }
  3707. });
  3708. }
  3709. });
  3710. }
  3711. });
  3712. var maxRowLen = 0;
  3713. event.dataRows.forEach(function (row) {
  3714. maxRowLen = Math.max(maxRowLen, row.length);
  3715. });
  3716. var newRows = maxRowLen - event.dataRows[0].length;
  3717. for (var i = 0; i < newRows; i++) {
  3718. var header = columnHeaderFormatter(i + 1);
  3719. if (multiLevelHeaders) {
  3720. event.dataRows[0].push(header.topLevelColumnTitle);
  3721. event.dataRows[1].push(header.columnTitle);
  3722. }
  3723. else {
  3724. event.dataRows[0].push(header);
  3725. }
  3726. }
  3727. });
  3728. });
  3729. wrap(Pointer.prototype, 'onContainerMouseDown', function (proceed) {
  3730. if (!this.chart.hasDraggedAnnotation) {
  3731. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3732. }
  3733. });
  3734. H.Annotation = Annotation;
  3735. return Annotation;
  3736. });
  3737. _registerModule(_modules, 'Mixins/Navigation.js', [], function () {
  3738. /**
  3739. *
  3740. * (c) 2010-2018 Paweł Fus
  3741. *
  3742. * License: www.highcharts.com/license
  3743. *
  3744. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3745. *
  3746. * */
  3747. var chartNavigation = {
  3748. /**
  3749. * Initializes `chart.navigation` object which delegates `update()` methods
  3750. * to all other common classes (used in exporting and navigationBindings).
  3751. *
  3752. * @private
  3753. * @param {Highcharts.Chart} chart
  3754. * The chart instance.
  3755. * @return {void}
  3756. */
  3757. initUpdate: function (chart) {
  3758. if (!chart.navigation) {
  3759. chart.navigation = {
  3760. updates: [],
  3761. update: function (options,
  3762. redraw) {
  3763. this.updates.forEach(function (updateConfig) {
  3764. updateConfig.update.call(updateConfig.context,
  3765. options,
  3766. redraw);
  3767. });
  3768. }
  3769. };
  3770. }
  3771. },
  3772. /**
  3773. * Registers an `update()` method in the `chart.navigation` object.
  3774. *
  3775. * @private
  3776. * @param {Highcharts.ChartNavigationUpdateFunction} update
  3777. * The `update()` method that will be called in `chart.update()`.
  3778. * @param {Highcharts.Chart} chart
  3779. * The chart instance. `update()` will use that as a context
  3780. * (`this`).
  3781. * @return {void}
  3782. */
  3783. addUpdate: function (update, chart) {
  3784. if (!chart.navigation) {
  3785. this.initUpdate(chart);
  3786. }
  3787. chart.navigation.updates.push({
  3788. update: update,
  3789. context: chart
  3790. });
  3791. }
  3792. };
  3793. return chartNavigation;
  3794. });
  3795. _registerModule(_modules, 'Extensions/Annotations/NavigationBindings.js', [_modules['Extensions/Annotations/Annotations.js'], _modules['Mixins/Navigation.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Annotation, chartNavigationMixin, H, U) {
  3796. /* *
  3797. *
  3798. * (c) 2009-2017 Highsoft, Black Label
  3799. *
  3800. * License: www.highcharts.com/license
  3801. *
  3802. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3803. *
  3804. * */
  3805. var addEvent = U.addEvent,
  3806. attr = U.attr,
  3807. extend = U.extend,
  3808. format = U.format,
  3809. fireEvent = U.fireEvent,
  3810. isArray = U.isArray,
  3811. isFunction = U.isFunction,
  3812. isNumber = U.isNumber,
  3813. isObject = U.isObject,
  3814. merge = U.merge,
  3815. objectEach = U.objectEach,
  3816. pick = U.pick,
  3817. setOptions = U.setOptions;
  3818. /**
  3819. * A config object for navigation bindings in annotations.
  3820. *
  3821. * @interface Highcharts.NavigationBindingsOptionsObject
  3822. */ /**
  3823. * ClassName of the element for a binding.
  3824. * @name Highcharts.NavigationBindingsOptionsObject#className
  3825. * @type {string|undefined}
  3826. */ /**
  3827. * Last event to be fired after last step event.
  3828. * @name Highcharts.NavigationBindingsOptionsObject#end
  3829. * @type {Function|undefined}
  3830. */ /**
  3831. * Initial event, fired on a button click.
  3832. * @name Highcharts.NavigationBindingsOptionsObject#init
  3833. * @type {Function|undefined}
  3834. */ /**
  3835. * Event fired on first click on a chart.
  3836. * @name Highcharts.NavigationBindingsOptionsObject#start
  3837. * @type {Function|undefined}
  3838. */ /**
  3839. * Last event to be fired after last step event. Array of step events to be
  3840. * called sequentially after each user click.
  3841. * @name Highcharts.NavigationBindingsOptionsObject#steps
  3842. * @type {Array<Function>|undefined}
  3843. */
  3844. var doc = H.doc,
  3845. win = H.win,
  3846. PREFIX = 'highcharts-';
  3847. /* eslint-disable no-invalid-this, valid-jsdoc */
  3848. /**
  3849. * IE 9-11 polyfill for Element.closest():
  3850. * @private
  3851. */
  3852. function closestPolyfill(el, s) {
  3853. var ElementProto = win.Element.prototype,
  3854. elementMatches = ElementProto.matches ||
  3855. ElementProto.msMatchesSelector ||
  3856. ElementProto.webkitMatchesSelector,
  3857. ret = null;
  3858. if (ElementProto.closest) {
  3859. ret = ElementProto.closest.call(el, s);
  3860. }
  3861. else {
  3862. do {
  3863. if (elementMatches.call(el, s)) {
  3864. return el;
  3865. }
  3866. el = el.parentElement || el.parentNode;
  3867. } while (el !== null && el.nodeType === 1);
  3868. }
  3869. return ret;
  3870. }
  3871. /**
  3872. * @private
  3873. * @interface bindingsUtils
  3874. */
  3875. var bindingsUtils = {
  3876. /**
  3877. * Update size of background (rect) in some annotations: Measure,
  3878. Simple
  3879. * Rect.
  3880. *
  3881. * @private
  3882. * @function Highcharts.NavigationBindingsUtilsObject.updateRectSize
  3883. *
  3884. * @param {Highcharts.PointerEventObject} event
  3885. * Normalized browser event
  3886. *
  3887. * @param {Highcharts.Annotation} annotation
  3888. * Annotation to be updated
  3889. */
  3890. updateRectSize: function (event,
  3891. annotation) {
  3892. var chart = annotation.chart,
  3893. options = annotation.options.typeOptions,
  3894. coords = chart.pointer.getCoordinates(event),
  3895. width = coords.xAxis[0].value - options.point.x,
  3896. height = options.point.y - coords.yAxis[0].value;
  3897. annotation.update({
  3898. typeOptions: {
  3899. background: {
  3900. width: chart.inverted ? height : width,
  3901. height: chart.inverted ? width : height
  3902. }
  3903. }
  3904. });
  3905. },
  3906. /**
  3907. * Get field type according to value
  3908. *
  3909. * @private
  3910. * @function Highcharts.NavigationBindingsUtilsObject.getFieldType
  3911. *
  3912. * @param {'boolean'|'number'|'string'} value
  3913. * Atomic type (one of: string, number, boolean)
  3914. *
  3915. * @return {'checkbox'|'number'|'text'}
  3916. * Field type (one of: text, number, checkbox)
  3917. */
  3918. getFieldType: function (value) {
  3919. return {
  3920. 'string': 'text',
  3921. 'number': 'number',
  3922. 'boolean': 'checkbox'
  3923. }[typeof value];
  3924. }
  3925. };
  3926. /**
  3927. * @private
  3928. */
  3929. var NavigationBindings = /** @class */ (function () {
  3930. /* *
  3931. *
  3932. * Constructors
  3933. *
  3934. * */
  3935. function NavigationBindings(chart, options) {
  3936. this.boundClassNames = void 0;
  3937. this.selectedButton = void 0;
  3938. this.chart = chart;
  3939. this.options = options;
  3940. this.eventsToUnbind = [];
  3941. this.container = doc.getElementsByClassName(this.options.bindingsClassName || '');
  3942. }
  3943. // Private properties added by bindings:
  3944. // Active (selected) annotation that is editted through popup/forms
  3945. // activeAnnotation: Annotation
  3946. // Holder for current step, used on mouse move to update bound object
  3947. // mouseMoveEvent: function () {}
  3948. // Next event in `step` array to be called on chart's click
  3949. // nextEvent: function () {}
  3950. // Index in the `step` array of the current event
  3951. // stepIndex: 0
  3952. // Flag to determine if current binding has steps
  3953. // steps: true|false
  3954. // Bindings holder for all events
  3955. // selectedButton: {}
  3956. // Holder for user options, returned from `start` event, and passed on to
  3957. // `step`'s' and `end`.
  3958. // currentUserDetails: {}
  3959. /* *
  3960. *
  3961. * Functions
  3962. *
  3963. * */
  3964. /**
  3965. * Initi all events conencted to NavigationBindings.
  3966. *
  3967. * @private
  3968. * @function Highcharts.NavigationBindings#initEvents
  3969. */
  3970. NavigationBindings.prototype.initEvents = function () {
  3971. var navigation = this,
  3972. chart = navigation.chart,
  3973. bindingsContainer = navigation.container,
  3974. options = navigation.options;
  3975. // Shorthand object for getting events for buttons:
  3976. navigation.boundClassNames = {};
  3977. objectEach((options.bindings || {}), function (value) {
  3978. navigation.boundClassNames[value.className] = value;
  3979. });
  3980. // Handle multiple containers with the same class names:
  3981. [].forEach.call(bindingsContainer, function (subContainer) {
  3982. navigation.eventsToUnbind.push(addEvent(subContainer, 'click', function (event) {
  3983. var bindings = navigation.getButtonEvents(subContainer,
  3984. event);
  3985. if (bindings) {
  3986. navigation.bindingsButtonClick(bindings.button, bindings.events, event);
  3987. }
  3988. }));
  3989. });
  3990. objectEach(options.events || {}, function (callback, eventName) {
  3991. if (isFunction(callback)) {
  3992. navigation.eventsToUnbind.push(addEvent(navigation, eventName, callback));
  3993. }
  3994. });
  3995. navigation.eventsToUnbind.push(addEvent(chart.container, 'click', function (e) {
  3996. if (!chart.cancelClick &&
  3997. chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  3998. navigation.bindingsChartClick(this, e);
  3999. }
  4000. }));
  4001. navigation.eventsToUnbind.push(addEvent(chart.container, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
  4002. navigation.bindingsContainerMouseMove(this, e);
  4003. }));
  4004. };
  4005. /**
  4006. * Common chart.update() delegation, shared between bindings and exporting.
  4007. *
  4008. * @private
  4009. * @function Highcharts.NavigationBindings#initUpdate
  4010. */
  4011. NavigationBindings.prototype.initUpdate = function () {
  4012. var navigation = this;
  4013. chartNavigationMixin.addUpdate(function (options) {
  4014. navigation.update(options);
  4015. }, this.chart);
  4016. };
  4017. /**
  4018. * Hook for click on a button, method selcts/unselects buttons,
  4019. * then calls `bindings.init` callback.
  4020. *
  4021. * @private
  4022. * @function Highcharts.NavigationBindings#bindingsButtonClick
  4023. *
  4024. * @param {Highcharts.HTMLDOMElement} [button]
  4025. * Clicked button
  4026. *
  4027. * @param {object} events
  4028. * Events passed down from bindings (`init`, `start`, `step`, `end`)
  4029. *
  4030. * @param {Highcharts.PointerEventObject} clickEvent
  4031. * Browser's click event
  4032. */
  4033. NavigationBindings.prototype.bindingsButtonClick = function (button, events, clickEvent) {
  4034. var navigation = this,
  4035. chart = navigation.chart;
  4036. if (navigation.selectedButtonElement) {
  4037. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4038. if (navigation.nextEvent) {
  4039. // Remove in-progress annotations adders:
  4040. if (navigation.currentUserDetails &&
  4041. navigation.currentUserDetails.coll === 'annotations') {
  4042. chart.removeAnnotation(navigation.currentUserDetails);
  4043. }
  4044. navigation.mouseMoveEvent = navigation.nextEvent = false;
  4045. }
  4046. }
  4047. navigation.selectedButton = events;
  4048. navigation.selectedButtonElement = button;
  4049. fireEvent(navigation, 'selectButton', { button: button });
  4050. // Call "init" event, for example to open modal window
  4051. if (events.init) {
  4052. events.init.call(navigation, button, clickEvent);
  4053. }
  4054. if (events.start || events.steps) {
  4055. chart.renderer.boxWrapper.addClass(PREFIX + 'draw-mode');
  4056. }
  4057. };
  4058. /**
  4059. * Hook for click on a chart, first click on a chart calls `start` event,
  4060. * then on all subsequent clicks iterate over `steps` array.
  4061. * When finished, calls `end` event.
  4062. *
  4063. * @private
  4064. * @function Highcharts.NavigationBindings#bindingsChartClick
  4065. *
  4066. * @param {Highcharts.Chart} chart
  4067. * Chart that click was performed on.
  4068. *
  4069. * @param {Highcharts.PointerEventObject} clickEvent
  4070. * Browser's click event.
  4071. */
  4072. NavigationBindings.prototype.bindingsChartClick = function (chart, clickEvent) {
  4073. var navigation = this,
  4074. chart = navigation.chart,
  4075. selectedButton = navigation.selectedButton,
  4076. svgContainer = chart.renderer.boxWrapper;
  4077. // Click outside popups, should close them and deselect the annotation
  4078. if (navigation.activeAnnotation &&
  4079. !clickEvent.activeAnnotation &&
  4080. // Element could be removed in the child action, e.g. button
  4081. clickEvent.target.parentNode &&
  4082. // TO DO: Polyfill for IE11?
  4083. !closestPolyfill(clickEvent.target, '.' + PREFIX + 'popup')) {
  4084. fireEvent(navigation, 'closePopup');
  4085. navigation.deselectAnnotation();
  4086. }
  4087. if (!selectedButton || !selectedButton.start) {
  4088. return;
  4089. }
  4090. if (!navigation.nextEvent) {
  4091. // Call init method:
  4092. navigation.currentUserDetails = selectedButton.start.call(navigation, clickEvent);
  4093. // If steps exists (e.g. Annotations), bind them:
  4094. if (selectedButton.steps) {
  4095. navigation.stepIndex = 0;
  4096. navigation.steps = true;
  4097. navigation.mouseMoveEvent = navigation.nextEvent =
  4098. selectedButton.steps[navigation.stepIndex];
  4099. }
  4100. else {
  4101. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4102. svgContainer.removeClass(PREFIX + 'draw-mode');
  4103. navigation.steps = false;
  4104. navigation.selectedButton = null;
  4105. // First click is also the last one:
  4106. if (selectedButton.end) {
  4107. selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
  4108. }
  4109. }
  4110. }
  4111. else {
  4112. navigation.nextEvent(clickEvent, navigation.currentUserDetails);
  4113. if (navigation.steps) {
  4114. navigation.stepIndex++;
  4115. if (selectedButton.steps[navigation.stepIndex]) {
  4116. // If we have more steps, bind them one by one:
  4117. navigation.mouseMoveEvent = navigation.nextEvent =
  4118. selectedButton.steps[navigation.stepIndex];
  4119. }
  4120. else {
  4121. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4122. svgContainer.removeClass(PREFIX + 'draw-mode');
  4123. // That was the last step, call end():
  4124. if (selectedButton.end) {
  4125. selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
  4126. }
  4127. navigation.nextEvent = false;
  4128. navigation.mouseMoveEvent = false;
  4129. navigation.selectedButton = null;
  4130. }
  4131. }
  4132. }
  4133. };
  4134. /**
  4135. * Hook for mouse move on a chart's container. It calls current step.
  4136. *
  4137. * @private
  4138. * @function Highcharts.NavigationBindings#bindingsContainerMouseMove
  4139. *
  4140. * @param {Highcharts.HTMLDOMElement} container
  4141. * Chart's container.
  4142. *
  4143. * @param {global.Event} moveEvent
  4144. * Browser's move event.
  4145. */
  4146. NavigationBindings.prototype.bindingsContainerMouseMove = function (_container, moveEvent) {
  4147. if (this.mouseMoveEvent) {
  4148. this.mouseMoveEvent(moveEvent, this.currentUserDetails);
  4149. }
  4150. };
  4151. /**
  4152. * Translate fields (e.g. `params.period` or `marker.styles.color`) to
  4153. * Highcharts options object (e.g. `{ params: { period } }`).
  4154. *
  4155. * @private
  4156. * @function Highcharts.NavigationBindings#fieldsToOptions<T>
  4157. *
  4158. * @param {Highcharts.Dictionary<string>} fields
  4159. * Fields from popup form.
  4160. *
  4161. * @param {T} config
  4162. * Default config to be modified.
  4163. *
  4164. * @return {T}
  4165. * Modified config
  4166. */
  4167. NavigationBindings.prototype.fieldsToOptions = function (fields, config) {
  4168. objectEach(fields, function (value, field) {
  4169. var parsedValue = parseFloat(value),
  4170. path = field.split('.'),
  4171. parent = config,
  4172. pathLength = path.length - 1;
  4173. // If it's a number (not "format" options), parse it:
  4174. if (isNumber(parsedValue) &&
  4175. !value.match(/px/g) &&
  4176. !field.match(/format/g)) {
  4177. value = parsedValue;
  4178. }
  4179. // Remove empty strings or values like 0
  4180. if (value !== '' && value !== 'undefined') {
  4181. path.forEach(function (name, index) {
  4182. var nextName = pick(path[index + 1], '');
  4183. if (pathLength === index) {
  4184. // Last index, put value:
  4185. parent[name] = value;
  4186. }
  4187. else if (!parent[name]) {
  4188. // Create middle property:
  4189. parent[name] = nextName.match(/\d/g) ? [] : {};
  4190. parent = parent[name];
  4191. }
  4192. else {
  4193. // Jump into next property
  4194. parent = parent[name];
  4195. }
  4196. });
  4197. }
  4198. });
  4199. return config;
  4200. };
  4201. /**
  4202. * Shorthand method to deselect an annotation.
  4203. *
  4204. * @function Highcharts.NavigationBindings#deselectAnnotation
  4205. */
  4206. NavigationBindings.prototype.deselectAnnotation = function () {
  4207. if (this.activeAnnotation) {
  4208. this.activeAnnotation.setControlPointsVisibility(false);
  4209. this.activeAnnotation = false;
  4210. }
  4211. };
  4212. /**
  4213. * Generates API config for popup in the same format as options for
  4214. * Annotation object.
  4215. *
  4216. * @function Highcharts.NavigationBindings#annotationToFields
  4217. *
  4218. * @param {Highcharts.Annotation} annotation
  4219. * Annotations object
  4220. *
  4221. * @return {Highcharts.Dictionary<string>}
  4222. * Annotation options to be displayed in popup box
  4223. */
  4224. NavigationBindings.prototype.annotationToFields = function (annotation) {
  4225. var options = annotation.options,
  4226. editables = NavigationBindings.annotationsEditable,
  4227. nestedEditables = editables.nestedOptions,
  4228. getFieldType = this.utils.getFieldType,
  4229. type = pick(options.type,
  4230. options.shapes && options.shapes[0] &&
  4231. options.shapes[0].type,
  4232. options.labels && options.labels[0] &&
  4233. options.labels[0].itemType, 'label'),
  4234. nonEditables = NavigationBindings.annotationsNonEditable[options.langKey] || [],
  4235. visualOptions = {
  4236. langKey: options.langKey,
  4237. type: type
  4238. };
  4239. /**
  4240. * Nested options traversing. Method goes down to the options and copies
  4241. * allowed options (with values) to new object, which is last parameter:
  4242. * "parent".
  4243. *
  4244. * @private
  4245. *
  4246. * @param {*} option
  4247. * Atomic type or object/array
  4248. *
  4249. * @param {string} key
  4250. * Option name, for example "visible" or "x", "y"
  4251. *
  4252. * @param {object} parentEditables
  4253. * Editables from NavigationBindings.annotationsEditable
  4254. *
  4255. * @param {object} parent
  4256. * Where new options will be assigned
  4257. */
  4258. function traverse(option, key, parentEditables, parent) {
  4259. var nextParent;
  4260. if (parentEditables &&
  4261. option &&
  4262. nonEditables.indexOf(key) === -1 &&
  4263. ((parentEditables.indexOf &&
  4264. parentEditables.indexOf(key)) >= 0 ||
  4265. parentEditables[key] || // nested array
  4266. parentEditables === true // simple array
  4267. )) {
  4268. // Roots:
  4269. if (isArray(option)) {
  4270. parent[key] = [];
  4271. option.forEach(function (arrayOption, i) {
  4272. if (!isObject(arrayOption)) {
  4273. // Simple arrays, e.g. [String, Number, Boolean]
  4274. traverse(arrayOption, 0, nestedEditables[key], parent[key]);
  4275. }
  4276. else {
  4277. // Advanced arrays, e.g. [Object, Object]
  4278. parent[key][i] = {};
  4279. objectEach(arrayOption, function (nestedOption, nestedKey) {
  4280. traverse(nestedOption, nestedKey, nestedEditables[key], parent[key][i]);
  4281. });
  4282. }
  4283. });
  4284. }
  4285. else if (isObject(option)) {
  4286. nextParent = {};
  4287. if (isArray(parent)) {
  4288. parent.push(nextParent);
  4289. nextParent[key] = {};
  4290. nextParent = nextParent[key];
  4291. }
  4292. else {
  4293. parent[key] = nextParent;
  4294. }
  4295. objectEach(option, function (nestedOption, nestedKey) {
  4296. traverse(nestedOption, nestedKey, key === 0 ? parentEditables : nestedEditables[key], nextParent);
  4297. });
  4298. }
  4299. else {
  4300. // Leaf:
  4301. if (key === 'format') {
  4302. parent[key] = [
  4303. format(option, annotation.labels[0].points[0]).toString(),
  4304. 'text'
  4305. ];
  4306. }
  4307. else if (isArray(parent)) {
  4308. parent.push([option, getFieldType(option)]);
  4309. }
  4310. else {
  4311. parent[key] = [option, getFieldType(option)];
  4312. }
  4313. }
  4314. }
  4315. }
  4316. objectEach(options, function (option, key) {
  4317. if (key === 'typeOptions') {
  4318. visualOptions[key] = {};
  4319. objectEach(options[key], function (typeOption, typeKey) {
  4320. traverse(typeOption, typeKey, nestedEditables, visualOptions[key], true);
  4321. });
  4322. }
  4323. else {
  4324. traverse(option, key, editables[type], visualOptions);
  4325. }
  4326. });
  4327. return visualOptions;
  4328. };
  4329. /**
  4330. * Get all class names for all parents in the element. Iterates until finds
  4331. * main container.
  4332. *
  4333. * @function Highcharts.NavigationBindings#getClickedClassNames
  4334. *
  4335. * @param {Highcharts.HTMLDOMElement}
  4336. * Container that event is bound to.
  4337. *
  4338. * @param {global.Event} event
  4339. * Browser's event.
  4340. *
  4341. * @return {Array<Array<string, Highcharts.HTMLDOMElement>>}
  4342. * Array of class names with corresponding elements
  4343. */
  4344. NavigationBindings.prototype.getClickedClassNames = function (container, event) {
  4345. var element = event.target,
  4346. classNames = [],
  4347. elemClassName;
  4348. while (element) {
  4349. elemClassName = attr(element, 'class');
  4350. if (elemClassName) {
  4351. classNames = classNames.concat(elemClassName
  4352. .split(' ')
  4353. .map(function (name) {
  4354. return [
  4355. name,
  4356. element
  4357. ];
  4358. }));
  4359. }
  4360. element = element.parentNode;
  4361. if (element === container) {
  4362. return classNames;
  4363. }
  4364. }
  4365. return classNames;
  4366. };
  4367. /**
  4368. * Get events bound to a button. It's a custom event delegation to find all
  4369. * events connected to the element.
  4370. *
  4371. * @private
  4372. * @function Highcharts.NavigationBindings#getButtonEvents
  4373. *
  4374. * @param {Highcharts.HTMLDOMElement} container
  4375. * Container that event is bound to.
  4376. *
  4377. * @param {global.Event} event
  4378. * Browser's event.
  4379. *
  4380. * @return {object}
  4381. * Object with events (init, start, steps, and end)
  4382. */
  4383. NavigationBindings.prototype.getButtonEvents = function (container, event) {
  4384. var navigation = this,
  4385. classNames = this.getClickedClassNames(container,
  4386. event),
  4387. bindings;
  4388. classNames.forEach(function (className) {
  4389. if (navigation.boundClassNames[className[0]] && !bindings) {
  4390. bindings = {
  4391. events: navigation.boundClassNames[className[0]],
  4392. button: className[1]
  4393. };
  4394. }
  4395. });
  4396. return bindings;
  4397. };
  4398. /**
  4399. * Bindings are just events, so the whole update process is simply
  4400. * removing old events and adding new ones.
  4401. *
  4402. * @private
  4403. * @function Highcharts.NavigationBindings#update
  4404. */
  4405. NavigationBindings.prototype.update = function (options) {
  4406. this.options = merge(true, this.options, options);
  4407. this.removeEvents();
  4408. this.initEvents();
  4409. };
  4410. /**
  4411. * Remove all events created in the navigation.
  4412. *
  4413. * @private
  4414. * @function Highcharts.NavigationBindings#removeEvents
  4415. */
  4416. NavigationBindings.prototype.removeEvents = function () {
  4417. this.eventsToUnbind.forEach(function (unbinder) {
  4418. unbinder();
  4419. });
  4420. };
  4421. NavigationBindings.prototype.destroy = function () {
  4422. this.removeEvents();
  4423. };
  4424. /* *
  4425. *
  4426. * Static Properties
  4427. *
  4428. * */
  4429. // Define which options from annotations should show up in edit box:
  4430. NavigationBindings.annotationsEditable = {
  4431. // `typeOptions` are always available
  4432. // Nested and shared options:
  4433. nestedOptions: {
  4434. labelOptions: ['style', 'format', 'backgroundColor'],
  4435. labels: ['style'],
  4436. label: ['style'],
  4437. style: ['fontSize', 'color'],
  4438. background: ['fill', 'strokeWidth', 'stroke'],
  4439. innerBackground: ['fill', 'strokeWidth', 'stroke'],
  4440. outerBackground: ['fill', 'strokeWidth', 'stroke'],
  4441. shapeOptions: ['fill', 'strokeWidth', 'stroke'],
  4442. shapes: ['fill', 'strokeWidth', 'stroke'],
  4443. line: ['strokeWidth', 'stroke'],
  4444. backgroundColors: [true],
  4445. connector: ['fill', 'strokeWidth', 'stroke'],
  4446. crosshairX: ['strokeWidth', 'stroke'],
  4447. crosshairY: ['strokeWidth', 'stroke']
  4448. },
  4449. // Simple shapes:
  4450. circle: ['shapes'],
  4451. verticalLine: [],
  4452. label: ['labelOptions'],
  4453. // Measure
  4454. measure: ['background', 'crosshairY', 'crosshairX'],
  4455. // Others:
  4456. fibonacci: [],
  4457. tunnel: ['background', 'line', 'height'],
  4458. pitchfork: ['innerBackground', 'outerBackground'],
  4459. rect: ['shapes'],
  4460. // Crooked lines, elliots, arrows etc:
  4461. crookedLine: [],
  4462. basicAnnotation: ['shapes', 'labelOptions']
  4463. };
  4464. // Define non editable fields per annotation, for example Rectangle inherits
  4465. // options from Measure, but crosshairs are not available
  4466. NavigationBindings.annotationsNonEditable = {
  4467. rectangle: ['crosshairX', 'crosshairY', 'label']
  4468. };
  4469. return NavigationBindings;
  4470. }());
  4471. /**
  4472. * General utils for bindings
  4473. *
  4474. * @private
  4475. * @name Highcharts.NavigationBindings.utils
  4476. * @type {bindingsUtils}
  4477. */
  4478. NavigationBindings.prototype.utils = bindingsUtils;
  4479. H.Chart.prototype.initNavigationBindings = function () {
  4480. var chart = this,
  4481. options = chart.options;
  4482. if (options && options.navigation && options.navigation.bindings) {
  4483. chart.navigationBindings = new NavigationBindings(chart, options.navigation);
  4484. chart.navigationBindings.initEvents();
  4485. chart.navigationBindings.initUpdate();
  4486. }
  4487. };
  4488. addEvent(H.Chart, 'load', function () {
  4489. this.initNavigationBindings();
  4490. });
  4491. addEvent(H.Chart, 'destroy', function () {
  4492. if (this.navigationBindings) {
  4493. this.navigationBindings.destroy();
  4494. }
  4495. });
  4496. addEvent(NavigationBindings, 'deselectButton', function () {
  4497. this.selectedButtonElement = null;
  4498. });
  4499. addEvent(Annotation, 'remove', function () {
  4500. if (this.chart.navigationBindings) {
  4501. this.chart.navigationBindings.deselectAnnotation();
  4502. }
  4503. });
  4504. /**
  4505. * Show edit-annotation form:
  4506. * @private
  4507. */
  4508. function selectableAnnotation(annotationType) {
  4509. var originalClick = annotationType.prototype.defaultOptions.events &&
  4510. annotationType.prototype.defaultOptions.events.click;
  4511. /**
  4512. * @private
  4513. */
  4514. function selectAndshowPopup(event) {
  4515. var annotation = this,
  4516. navigation = annotation.chart.navigationBindings,
  4517. prevAnnotation = navigation.activeAnnotation;
  4518. if (originalClick) {
  4519. originalClick.call(annotation, event);
  4520. }
  4521. if (prevAnnotation !== annotation) {
  4522. // Select current:
  4523. navigation.deselectAnnotation();
  4524. navigation.activeAnnotation = annotation;
  4525. annotation.setControlPointsVisibility(true);
  4526. fireEvent(navigation, 'showPopup', {
  4527. annotation: annotation,
  4528. formType: 'annotation-toolbar',
  4529. options: navigation.annotationToFields(annotation),
  4530. onSubmit: function (data) {
  4531. var config = {},
  4532. typeOptions;
  4533. if (data.actionType === 'remove') {
  4534. navigation.activeAnnotation = false;
  4535. navigation.chart.removeAnnotation(annotation);
  4536. }
  4537. else {
  4538. navigation.fieldsToOptions(data.fields, config);
  4539. navigation.deselectAnnotation();
  4540. typeOptions = config.typeOptions;
  4541. if (annotation.options.type === 'measure') {
  4542. // Manually disable crooshars according to
  4543. // stroke width of the shape:
  4544. typeOptions.crosshairY.enabled =
  4545. typeOptions.crosshairY.strokeWidth !== 0;
  4546. typeOptions.crosshairX.enabled =
  4547. typeOptions.crosshairX.strokeWidth !== 0;
  4548. }
  4549. annotation.update(config);
  4550. }
  4551. }
  4552. });
  4553. }
  4554. else {
  4555. // Deselect current:
  4556. navigation.deselectAnnotation();
  4557. fireEvent(navigation, 'closePopup');
  4558. }
  4559. // Let bubble event to chart.click:
  4560. event.activeAnnotation = true;
  4561. }
  4562. merge(true, annotationType.prototype.defaultOptions.events, {
  4563. click: selectAndshowPopup
  4564. });
  4565. }
  4566. if (H.Annotation) {
  4567. // Basic shapes:
  4568. selectableAnnotation(Annotation);
  4569. // Advanced annotations:
  4570. objectEach(Annotation.types, function (annotationType) {
  4571. selectableAnnotation(annotationType);
  4572. });
  4573. }
  4574. setOptions({
  4575. /**
  4576. * @optionparent lang
  4577. *
  4578. * @private
  4579. */
  4580. lang: {
  4581. /**
  4582. * Configure the Popup strings in the chart. Requires the
  4583. * `annotations.js` or `annotations-advanced.src.js` module to be
  4584. * loaded.
  4585. *
  4586. * @since 7.0.0
  4587. * @product highcharts highstock
  4588. */
  4589. navigation: {
  4590. /**
  4591. * Translations for all field names used in popup.
  4592. *
  4593. * @product highcharts highstock
  4594. */
  4595. popup: {
  4596. simpleShapes: 'Simple shapes',
  4597. lines: 'Lines',
  4598. circle: 'Circle',
  4599. rectangle: 'Rectangle',
  4600. label: 'Label',
  4601. shapeOptions: 'Shape options',
  4602. typeOptions: 'Details',
  4603. fill: 'Fill',
  4604. format: 'Text',
  4605. strokeWidth: 'Line width',
  4606. stroke: 'Line color',
  4607. title: 'Title',
  4608. name: 'Name',
  4609. labelOptions: 'Label options',
  4610. labels: 'Labels',
  4611. backgroundColor: 'Background color',
  4612. backgroundColors: 'Background colors',
  4613. borderColor: 'Border color',
  4614. borderRadius: 'Border radius',
  4615. borderWidth: 'Border width',
  4616. style: 'Style',
  4617. padding: 'Padding',
  4618. fontSize: 'Font size',
  4619. color: 'Color',
  4620. height: 'Height',
  4621. shapes: 'Shape options'
  4622. }
  4623. }
  4624. },
  4625. /**
  4626. * @optionparent navigation
  4627. * @product highcharts highstock
  4628. *
  4629. * @private
  4630. */
  4631. navigation: {
  4632. /**
  4633. * A CSS class name where all bindings will be attached to. Multiple
  4634. * charts on the same page should have separate class names to prevent
  4635. * duplicating events.
  4636. *
  4637. * Default value of versions < 7.0.4 `highcharts-bindings-wrapper`
  4638. *
  4639. * @since 7.0.0
  4640. * @type {string}
  4641. */
  4642. bindingsClassName: 'highcharts-bindings-container',
  4643. /**
  4644. * Bindings definitions for custom HTML buttons. Each binding implements
  4645. * simple event-driven interface:
  4646. *
  4647. * - `className`: classname used to bind event to
  4648. *
  4649. * - `init`: initial event, fired on button click
  4650. *
  4651. * - `start`: fired on first click on a chart
  4652. *
  4653. * - `steps`: array of sequential events fired one after another on each
  4654. * of users clicks
  4655. *
  4656. * - `end`: last event to be called after last step event
  4657. *
  4658. * @type {Highcharts.Dictionary<Highcharts.NavigationBindingsOptionsObject>|*}
  4659. * @sample stock/stocktools/stocktools-thresholds
  4660. * Custom bindings in Highstock
  4661. * @since 7.0.0
  4662. * @product highcharts highstock
  4663. */
  4664. bindings: {
  4665. /**
  4666. * A circle annotation bindings. Includes `start` and one event in
  4667. * `steps` array.
  4668. *
  4669. * @type {Highcharts.NavigationBindingsOptionsObject}
  4670. * @default {"className": "highcharts-circle-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4671. */
  4672. circleAnnotation: {
  4673. /** @ignore-option */
  4674. className: 'highcharts-circle-annotation',
  4675. /** @ignore-option */
  4676. start: function (e) {
  4677. var coords = this.chart.pointer.getCoordinates(e),
  4678. navigation = this.chart.options.navigation;
  4679. return this.chart.addAnnotation(merge({
  4680. langKey: 'circle',
  4681. type: 'basicAnnotation',
  4682. shapes: [{
  4683. type: 'circle',
  4684. point: {
  4685. xAxis: 0,
  4686. yAxis: 0,
  4687. x: coords.xAxis[0].value,
  4688. y: coords.yAxis[0].value
  4689. },
  4690. r: 5
  4691. }]
  4692. }, navigation
  4693. .annotationsOptions, navigation
  4694. .bindings
  4695. .circleAnnotation
  4696. .annotationsOptions));
  4697. },
  4698. /** @ignore-option */
  4699. steps: [
  4700. function (e, annotation) {
  4701. var point = annotation.options.shapes[0].point,
  4702. x = this.chart.xAxis[0].toPixels(point.x),
  4703. y = this.chart.yAxis[0].toPixels(point.y),
  4704. inverted = this.chart.inverted,
  4705. distance = Math.max(Math.sqrt(Math.pow(inverted ? y - e.chartX : x - e.chartX, 2) +
  4706. Math.pow(inverted ? x - e.chartY : y - e.chartY, 2)), 5);
  4707. annotation.update({
  4708. shapes: [{
  4709. r: distance
  4710. }]
  4711. });
  4712. }
  4713. ]
  4714. },
  4715. /**
  4716. * A rectangle annotation bindings. Includes `start` and one event
  4717. * in `steps` array.
  4718. *
  4719. * @type {Highcharts.NavigationBindingsOptionsObject}
  4720. * @default {"className": "highcharts-rectangle-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4721. */
  4722. rectangleAnnotation: {
  4723. /** @ignore-option */
  4724. className: 'highcharts-rectangle-annotation',
  4725. /** @ignore-option */
  4726. start: function (e) {
  4727. var coords = this.chart.pointer.getCoordinates(e),
  4728. navigation = this.chart.options.navigation,
  4729. x = coords.xAxis[0].value,
  4730. y = coords.yAxis[0].value;
  4731. return this.chart.addAnnotation(merge({
  4732. langKey: 'rectangle',
  4733. type: 'basicAnnotation',
  4734. shapes: [{
  4735. type: 'path',
  4736. points: [{
  4737. xAxis: 0,
  4738. yAxis: 0,
  4739. x: x,
  4740. y: y
  4741. }, {
  4742. xAxis: 0,
  4743. yAxis: 0,
  4744. x: x,
  4745. y: y
  4746. }, {
  4747. xAxis: 0,
  4748. yAxis: 0,
  4749. x: x,
  4750. y: y
  4751. }, {
  4752. xAxis: 0,
  4753. yAxis: 0,
  4754. x: x,
  4755. y: y
  4756. }]
  4757. }]
  4758. }, navigation
  4759. .annotationsOptions, navigation
  4760. .bindings
  4761. .rectangleAnnotation
  4762. .annotationsOptions));
  4763. },
  4764. /** @ignore-option */
  4765. steps: [
  4766. function (e, annotation) {
  4767. var points = annotation.options.shapes[0].points,
  4768. coords = this.chart.pointer.getCoordinates(e),
  4769. x = coords.xAxis[0].value,
  4770. y = coords.yAxis[0].value;
  4771. // Top right point
  4772. points[1].x = x;
  4773. // Bottom right point (cursor position)
  4774. points[2].x = x;
  4775. points[2].y = y;
  4776. // Bottom left
  4777. points[3].y = y;
  4778. annotation.update({
  4779. shapes: [{
  4780. points: points
  4781. }]
  4782. });
  4783. }
  4784. ]
  4785. },
  4786. /**
  4787. * A label annotation bindings. Includes `start` event only.
  4788. *
  4789. * @type {Highcharts.NavigationBindingsOptionsObject}
  4790. * @default {"className": "highcharts-label-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4791. */
  4792. labelAnnotation: {
  4793. /** @ignore-option */
  4794. className: 'highcharts-label-annotation',
  4795. /** @ignore-option */
  4796. start: function (e) {
  4797. var coords = this.chart.pointer.getCoordinates(e),
  4798. navigation = this.chart.options.navigation;
  4799. return this.chart.addAnnotation(merge({
  4800. langKey: 'label',
  4801. type: 'basicAnnotation',
  4802. labelOptions: {
  4803. format: '{y:.2f}'
  4804. },
  4805. labels: [{
  4806. point: {
  4807. xAxis: 0,
  4808. yAxis: 0,
  4809. x: coords.xAxis[0].value,
  4810. y: coords.yAxis[0].value
  4811. },
  4812. overflow: 'none',
  4813. crop: true
  4814. }]
  4815. }, navigation
  4816. .annotationsOptions, navigation
  4817. .bindings
  4818. .labelAnnotation
  4819. .annotationsOptions));
  4820. }
  4821. }
  4822. },
  4823. /**
  4824. * Path where Highcharts will look for icons. Change this to use icons
  4825. * from a different server.
  4826. *
  4827. * @type {string}
  4828. * @default https://code.highcharts.com/8.2.0/gfx/stock-icons/
  4829. * @since 7.1.3
  4830. * @apioption navigation.iconsURL
  4831. */
  4832. /**
  4833. * A `showPopup` event. Fired when selecting for example an annotation.
  4834. *
  4835. * @type {Function}
  4836. * @apioption navigation.events.showPopup
  4837. */
  4838. /**
  4839. * A `closePopup` event. Fired when Popup should be hidden, for example
  4840. * when clicking on an annotation again.
  4841. *
  4842. * @type {Function}
  4843. * @apioption navigation.events.closePopup
  4844. */
  4845. /**
  4846. * Event fired on a button click.
  4847. *
  4848. * @type {Function}
  4849. * @sample highcharts/annotations/gui/
  4850. * Change icon in a dropddown on event
  4851. * @sample highcharts/annotations/gui-buttons/
  4852. * Change button class on event
  4853. * @apioption navigation.events.selectButton
  4854. */
  4855. /**
  4856. * Event fired when button state should change, for example after
  4857. * adding an annotation.
  4858. *
  4859. * @type {Function}
  4860. * @sample highcharts/annotations/gui/
  4861. * Change icon in a dropddown on event
  4862. * @sample highcharts/annotations/gui-buttons/
  4863. * Change button class on event
  4864. * @apioption navigation.events.deselectButton
  4865. */
  4866. /**
  4867. * Events to communicate between Stock Tools and custom GUI.
  4868. *
  4869. * @since 7.0.0
  4870. * @product highcharts highstock
  4871. * @optionparent navigation.events
  4872. */
  4873. events: {},
  4874. /**
  4875. * Additional options to be merged into all annotations.
  4876. *
  4877. * @sample stock/stocktools/navigation-annotation-options
  4878. * Set red color of all line annotations
  4879. *
  4880. * @type {Highcharts.AnnotationsOptions}
  4881. * @extends annotations
  4882. * @exclude crookedLine, elliottWave, fibonacci, infinityLine,
  4883. * measure, pitchfork, tunnel, verticalLine, basicAnnotation
  4884. * @apioption navigation.annotationsOptions
  4885. */
  4886. annotationsOptions: {
  4887. animation: {
  4888. defer: 0
  4889. }
  4890. }
  4891. }
  4892. });
  4893. return NavigationBindings;
  4894. });
  4895. _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) {
  4896. /* *
  4897. *
  4898. * Popup generator for Stock tools
  4899. *
  4900. * (c) 2009-2017 Sebastian Bochan
  4901. *
  4902. * License: www.highcharts.com/license
  4903. *
  4904. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4905. *
  4906. * */
  4907. var addEvent = U.addEvent,
  4908. createElement = U.createElement,
  4909. defined = U.defined,
  4910. getOptions = U.getOptions,
  4911. isArray = U.isArray,
  4912. isObject = U.isObject,
  4913. isString = U.isString,
  4914. objectEach = U.objectEach,
  4915. pick = U.pick,
  4916. wrap = U.wrap;
  4917. 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';
  4918. /* eslint-disable no-invalid-this, valid-jsdoc */
  4919. // onContainerMouseDown blocks internal popup events, due to e.preventDefault.
  4920. // Related issue #4606
  4921. wrap(Pointer.prototype, 'onContainerMouseDown', function (proceed, e) {
  4922. var popupClass = e.target && e.target.className;
  4923. // elements is not in popup
  4924. if (!(isString(popupClass) &&
  4925. popupClass.indexOf(PREFIX + 'popup-field') >= 0)) {
  4926. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  4927. }
  4928. });
  4929. H.Popup = function (parentDiv, iconsURL) {
  4930. this.init(parentDiv, iconsURL);
  4931. };
  4932. H.Popup.prototype = {
  4933. /**
  4934. * Initialize the popup. Create base div and add close button.
  4935. * @private
  4936. * @param {Highcharts.HTMLDOMElement} parentDiv
  4937. * Container where popup should be placed
  4938. * @param {string} iconsURL
  4939. * Icon URL
  4940. */
  4941. init: function (parentDiv, iconsURL) {
  4942. // create popup div
  4943. this.container = createElement(DIV, {
  4944. className: PREFIX + 'popup'
  4945. }, null, parentDiv);
  4946. this.lang = this.getLangpack();
  4947. this.iconsURL = iconsURL;
  4948. // add close button
  4949. this.addCloseBtn();
  4950. },
  4951. /**
  4952. * Create HTML element and attach click event (close popup).
  4953. * @private
  4954. */
  4955. addCloseBtn: function () {
  4956. var _self = this,
  4957. closeBtn;
  4958. // create close popup btn
  4959. closeBtn = createElement(DIV, {
  4960. className: PREFIX + 'popup-close'
  4961. }, null, this.container);
  4962. closeBtn.style['background-image'] = 'url(' +
  4963. this.iconsURL + 'close.svg)';
  4964. ['click', 'touchstart'].forEach(function (eventName) {
  4965. addEvent(closeBtn, eventName, function () {
  4966. _self.closePopup();
  4967. });
  4968. });
  4969. },
  4970. /**
  4971. * Create two columns (divs) in HTML.
  4972. * @private
  4973. * @param {Highcharts.HTMLDOMElement} container
  4974. * Container of columns
  4975. * @return {Highcharts.Dictionary<Highcharts.HTMLDOMElement>}
  4976. * Reference to two HTML columns (lhsCol, rhsCol)
  4977. */
  4978. addColsContainer: function (container) {
  4979. var rhsCol,
  4980. lhsCol;
  4981. // left column
  4982. lhsCol = createElement(DIV, {
  4983. className: PREFIX + 'popup-lhs-col'
  4984. }, null, container);
  4985. // right column
  4986. rhsCol = createElement(DIV, {
  4987. className: PREFIX + 'popup-rhs-col'
  4988. }, null, container);
  4989. // wrapper content
  4990. createElement(DIV, {
  4991. className: PREFIX + 'popup-rhs-col-wrapper'
  4992. }, null, rhsCol);
  4993. return {
  4994. lhsCol: lhsCol,
  4995. rhsCol: rhsCol
  4996. };
  4997. },
  4998. /**
  4999. * Create input with label.
  5000. * @private
  5001. * @param {string} option
  5002. * Chain of fields i.e params.styles.fontSize
  5003. * @param {string} type
  5004. * Indicator type
  5005. * @param {Highhcharts.HTMLDOMElement}
  5006. * Container where elements should be added
  5007. * @param {string} value
  5008. * Default value of input i.e period value is 14, extracted from
  5009. * defaultOptions (ADD mode) or series options (EDIT mode)
  5010. */
  5011. addInput: function (option, type, parentDiv, value) {
  5012. var optionParamList = option.split('.'), optionName = optionParamList[optionParamList.length - 1], lang = this.lang, inputName = PREFIX + type + '-' + optionName;
  5013. if (!inputName.match(indexFilter)) {
  5014. // add label
  5015. createElement(LABEL, {
  5016. innerHTML: lang[optionName] || optionName,
  5017. htmlFor: inputName
  5018. }, null, parentDiv);
  5019. }
  5020. // add input
  5021. createElement(INPUT, {
  5022. name: inputName,
  5023. value: value[0],
  5024. type: value[1],
  5025. className: PREFIX + 'popup-field'
  5026. }, null, parentDiv).setAttribute(PREFIX + 'data-name', option);
  5027. },
  5028. /**
  5029. * Create button.
  5030. * @private
  5031. * @param {Highcharts.HTMLDOMElement} parentDiv
  5032. * Container where elements should be added
  5033. * @param {string} label
  5034. * Text placed as button label
  5035. * @param {string} type
  5036. * add | edit | remove
  5037. * @param {Function} callback
  5038. * On click callback
  5039. * @param {Highcharts.HTMLDOMElement} fieldsDiv
  5040. * Container where inputs are generated
  5041. * @return {Highcharts.HTMLDOMElement}
  5042. * HTML button
  5043. */
  5044. addButton: function (parentDiv, label, type, callback, fieldsDiv) {
  5045. var _self = this,
  5046. closePopup = this.closePopup,
  5047. getFields = this.getFields,
  5048. button;
  5049. button = createElement(BUTTON, {
  5050. innerHTML: label
  5051. }, null, parentDiv);
  5052. ['click', 'touchstart'].forEach(function (eventName) {
  5053. addEvent(button, eventName, function () {
  5054. closePopup.call(_self);
  5055. return callback(getFields(fieldsDiv, type));
  5056. });
  5057. });
  5058. return button;
  5059. },
  5060. /**
  5061. * Get values from all inputs and create JSON.
  5062. * @private
  5063. * @param {Highcharts.HTMLDOMElement} - container where inputs are created
  5064. * @param {string} - add | edit | remove
  5065. * @return {Highcharts.PopupFieldsObject} - fields
  5066. */
  5067. getFields: function (parentDiv, type) {
  5068. 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;
  5069. fieldsOutput = {
  5070. actionType: type,
  5071. linkedTo: linkedTo && linkedTo.getAttribute('value'),
  5072. fields: {}
  5073. };
  5074. [].forEach.call(inputList, function (input) {
  5075. param = input.getAttribute(PREFIX + 'data-name');
  5076. seriesId = input.getAttribute(PREFIX + 'data-series-id');
  5077. // params
  5078. if (seriesId) {
  5079. fieldsOutput.seriesId = input.value;
  5080. }
  5081. else if (param) {
  5082. fieldsOutput.fields[param] = input.value;
  5083. }
  5084. else {
  5085. // type like sma / ema
  5086. fieldsOutput.type = input.value;
  5087. }
  5088. });
  5089. if (volumeTo) {
  5090. fieldsOutput.fields['params.volumeSeriesID'] = volumeTo.getAttribute('value');
  5091. }
  5092. return fieldsOutput;
  5093. },
  5094. /**
  5095. * Reset content of the current popup and show.
  5096. * @private
  5097. */
  5098. showPopup: function () {
  5099. var popupDiv = this.container,
  5100. toolbarClass = PREFIX + 'annotation-toolbar',
  5101. popupCloseBtn = popupDiv
  5102. .querySelectorAll('.' + PREFIX + 'popup-close')[0];
  5103. // reset content
  5104. popupDiv.innerHTML = '';
  5105. // reset toolbar styles if exists
  5106. if (popupDiv.className.indexOf(toolbarClass) >= 0) {
  5107. popupDiv.classList.remove(toolbarClass);
  5108. // reset toolbar inline styles
  5109. popupDiv.removeAttribute('style');
  5110. }
  5111. // add close button
  5112. popupDiv.appendChild(popupCloseBtn);
  5113. popupDiv.style.display = 'block';
  5114. },
  5115. /**
  5116. * Hide popup.
  5117. * @private
  5118. */
  5119. closePopup: function () {
  5120. this.popup.container.style.display = 'none';
  5121. },
  5122. /**
  5123. * Create content and show popup.
  5124. * @private
  5125. * @param {string} - type of popup i.e indicators
  5126. * @param {Highcharts.Chart} - chart
  5127. * @param {Highcharts.AnnotationsOptions} - options
  5128. * @param {Function} - on click callback
  5129. */
  5130. showForm: function (type, chart, options, callback) {
  5131. this.popup = chart.navigationBindings.popup;
  5132. // show blank popup
  5133. this.showPopup();
  5134. // indicator form
  5135. if (type === 'indicators') {
  5136. this.indicators.addForm.call(this, chart, options, callback);
  5137. }
  5138. // annotation small toolbar
  5139. if (type === 'annotation-toolbar') {
  5140. this.annotations.addToolbar.call(this, chart, options, callback);
  5141. }
  5142. // annotation edit form
  5143. if (type === 'annotation-edit') {
  5144. this.annotations.addForm.call(this, chart, options, callback);
  5145. }
  5146. // flags form - add / edit
  5147. if (type === 'flag') {
  5148. this.annotations.addForm.call(this, chart, options, callback, true);
  5149. }
  5150. },
  5151. /**
  5152. * Return lang definitions for popup.
  5153. * @private
  5154. * @return {Highcharts.Dictionary<string>} - elements translations.
  5155. */
  5156. getLangpack: function () {
  5157. return getOptions().lang.navigation.popup;
  5158. },
  5159. annotations: {
  5160. /**
  5161. * Create annotation simple form. It contains two buttons
  5162. * (edit / remove) and text label.
  5163. * @private
  5164. * @param {Highcharts.Chart} - chart
  5165. * @param {Highcharts.AnnotationsOptions} - options
  5166. * @param {Function} - on click callback
  5167. */
  5168. addToolbar: function (chart, options, callback) {
  5169. var _self = this,
  5170. lang = this.lang,
  5171. popupDiv = this.popup.container,
  5172. showForm = this.showForm,
  5173. toolbarClass = PREFIX + 'annotation-toolbar',
  5174. button;
  5175. // set small size
  5176. if (popupDiv.className.indexOf(toolbarClass) === -1) {
  5177. popupDiv.className += ' ' + toolbarClass;
  5178. }
  5179. // set position
  5180. popupDiv.style.top = chart.plotTop + 10 + 'px';
  5181. // create label
  5182. createElement(SPAN, {
  5183. innerHTML: pick(
  5184. // Advanced annotations:
  5185. lang[options.langKey] || options.langKey,
  5186. // Basic shapes:
  5187. options.shapes && options.shapes[0].type)
  5188. }, null, popupDiv);
  5189. // add buttons
  5190. button = this.addButton(popupDiv, lang.removeButton || 'remove', 'remove', callback, popupDiv);
  5191. button.className += ' ' + PREFIX + 'annotation-remove-button';
  5192. button.style['background-image'] = 'url(' +
  5193. this.iconsURL + 'destroy.svg)';
  5194. button = this.addButton(popupDiv, lang.editButton || 'edit', 'edit', function () {
  5195. showForm.call(_self, 'annotation-edit', chart, options, callback);
  5196. }, popupDiv);
  5197. button.className += ' ' + PREFIX + 'annotation-edit-button';
  5198. button.style['background-image'] = 'url(' +
  5199. this.iconsURL + 'edit.svg)';
  5200. },
  5201. /**
  5202. * Create annotation simple form.
  5203. * It contains fields with param names.
  5204. * @private
  5205. * @param {Highcharts.Chart} chart
  5206. * Chart
  5207. * @param {Object} options
  5208. * Options
  5209. * @param {Function} callback
  5210. * On click callback
  5211. * @param {boolean} [isInit]
  5212. * If it is a form declared for init annotation
  5213. */
  5214. addForm: function (chart, options, callback, isInit) {
  5215. var popupDiv = this.popup.container,
  5216. lang = this.lang,
  5217. bottomRow,
  5218. lhsCol;
  5219. // create title of annotations
  5220. lhsCol = createElement('h2', {
  5221. innerHTML: lang[options.langKey] || options.langKey,
  5222. className: PREFIX + 'popup-main-title'
  5223. }, null, popupDiv);
  5224. // left column
  5225. lhsCol = createElement(DIV, {
  5226. className: PREFIX + 'popup-lhs-col ' + PREFIX + 'popup-lhs-full'
  5227. }, null, popupDiv);
  5228. bottomRow = createElement(DIV, {
  5229. className: PREFIX + 'popup-bottom-row'
  5230. }, null, popupDiv);
  5231. this.annotations.addFormFields.call(this, lhsCol, chart, '', options, [], true);
  5232. this.addButton(bottomRow, isInit ?
  5233. (lang.addButton || 'add') :
  5234. (lang.saveButton || 'save'), isInit ? 'add' : 'save', callback, popupDiv);
  5235. },
  5236. /**
  5237. * Create annotation's form fields.
  5238. * @private
  5239. * @param {Highcharts.HTMLDOMElement} parentDiv
  5240. * Div where inputs are placed
  5241. * @param {Highcharts.Chart} chart
  5242. * Chart
  5243. * @param {string} parentNode
  5244. * Name of parent to create chain of names
  5245. * @param {Highcharts.AnnotationsOptions} options
  5246. * Options
  5247. * @param {Array<unknown>} storage
  5248. * Array where all items are stored
  5249. * @param {boolean} [isRoot]
  5250. * Recursive flag for root
  5251. */
  5252. addFormFields: function (parentDiv, chart, parentNode, options, storage, isRoot) {
  5253. var _self = this,
  5254. addFormFields = this.annotations.addFormFields,
  5255. addInput = this.addInput,
  5256. lang = this.lang,
  5257. parentFullName,
  5258. titleName;
  5259. objectEach(options, function (value, option) {
  5260. // create name like params.styles.fontSize
  5261. parentFullName = parentNode !== '' ?
  5262. parentNode + '.' + option : option;
  5263. if (isObject(value)) {
  5264. if (
  5265. // value is object of options
  5266. !isArray(value) ||
  5267. // array of objects with params. i.e labels in Fibonacci
  5268. (isArray(value) && isObject(value[0]))) {
  5269. titleName = lang[option] || option;
  5270. if (!titleName.match(indexFilter)) {
  5271. storage.push([
  5272. true,
  5273. titleName,
  5274. parentDiv
  5275. ]);
  5276. }
  5277. addFormFields.call(_self, parentDiv, chart, parentFullName, value, storage, false);
  5278. }
  5279. else {
  5280. storage.push([
  5281. _self,
  5282. parentFullName,
  5283. 'annotation',
  5284. parentDiv,
  5285. value
  5286. ]);
  5287. }
  5288. }
  5289. });
  5290. if (isRoot) {
  5291. storage = storage.sort(function (a) {
  5292. return a[1].match(/format/g) ? -1 : 1;
  5293. });
  5294. storage.forEach(function (genInput) {
  5295. if (genInput[0] === true) {
  5296. createElement(SPAN, {
  5297. className: PREFIX + 'annotation-title',
  5298. innerHTML: genInput[1]
  5299. }, null, genInput[2]);
  5300. }
  5301. else {
  5302. addInput.apply(genInput[0], genInput.splice(1));
  5303. }
  5304. });
  5305. }
  5306. }
  5307. },
  5308. indicators: {
  5309. /**
  5310. * Create indicator's form. It contains two tabs (ADD and EDIT) with
  5311. * content.
  5312. * @private
  5313. */
  5314. addForm: function (chart, _options, callback) {
  5315. var tabsContainers,
  5316. indicators = this.indicators,
  5317. lang = this.lang,
  5318. buttonParentDiv;
  5319. // add tabs
  5320. this.tabs.init.call(this, chart);
  5321. // get all tabs content divs
  5322. tabsContainers = this.popup.container
  5323. .querySelectorAll('.' + PREFIX + 'tab-item-content');
  5324. // ADD tab
  5325. this.addColsContainer(tabsContainers[0]);
  5326. indicators.addIndicatorList.call(this, chart, tabsContainers[0], 'add');
  5327. buttonParentDiv = tabsContainers[0]
  5328. .querySelectorAll('.' + PREFIX + 'popup-rhs-col')[0];
  5329. this.addButton(buttonParentDiv, lang.addButton || 'add', 'add', callback, buttonParentDiv);
  5330. // EDIT tab
  5331. this.addColsContainer(tabsContainers[1]);
  5332. indicators.addIndicatorList.call(this, chart, tabsContainers[1], 'edit');
  5333. buttonParentDiv = tabsContainers[1]
  5334. .querySelectorAll('.' + PREFIX + 'popup-rhs-col')[0];
  5335. this.addButton(buttonParentDiv, lang.saveButton || 'save', 'edit', callback, buttonParentDiv);
  5336. this.addButton(buttonParentDiv, lang.removeButton || 'remove', 'remove', callback, buttonParentDiv);
  5337. },
  5338. /**
  5339. * Create HTML list of all indicators (ADD mode) or added indicators
  5340. * (EDIT mode).
  5341. * @private
  5342. */
  5343. addIndicatorList: function (chart, parentDiv, listType) {
  5344. var _self = this, lhsCol = parentDiv.querySelectorAll('.' + PREFIX + 'popup-lhs-col')[0], rhsCol = parentDiv.querySelectorAll('.' + PREFIX + 'popup-rhs-col')[0], isEdit = listType === 'edit', series = (isEdit ?
  5345. chart.series : // EDIT mode
  5346. chart.options.plotOptions // ADD mode
  5347. ), addFormFields = this.indicators.addFormFields, rhsColWrapper, indicatorList, item;
  5348. // create wrapper for list
  5349. indicatorList = createElement(UL, {
  5350. className: PREFIX + 'indicator-list'
  5351. }, null, lhsCol);
  5352. rhsColWrapper = rhsCol
  5353. .querySelectorAll('.' + PREFIX + 'popup-rhs-col-wrapper')[0];
  5354. objectEach(series, function (serie, value) {
  5355. var seriesOptions = serie.options;
  5356. if (serie.params ||
  5357. seriesOptions && seriesOptions.params) {
  5358. var indicatorNameType = _self.indicators.getNameType(serie,
  5359. value),
  5360. indicatorType = indicatorNameType.type;
  5361. item = createElement(LI, {
  5362. className: PREFIX + 'indicator-list',
  5363. innerHTML: indicatorNameType.name
  5364. }, null, indicatorList);
  5365. ['click', 'touchstart'].forEach(function (eventName) {
  5366. addEvent(item, eventName, function () {
  5367. addFormFields.call(_self, chart, isEdit ? serie : series[indicatorType], indicatorNameType.type, rhsColWrapper);
  5368. // add hidden input with series.id
  5369. if (isEdit && serie.options) {
  5370. createElement(INPUT, {
  5371. type: 'hidden',
  5372. name: PREFIX + 'id-' + indicatorType,
  5373. value: serie.options.id
  5374. }, null, rhsColWrapper)
  5375. .setAttribute(PREFIX + 'data-series-id', serie.options.id);
  5376. }
  5377. });
  5378. });
  5379. }
  5380. });
  5381. // select first item from the list
  5382. if (indicatorList.childNodes.length > 0) {
  5383. indicatorList.childNodes[0].click();
  5384. }
  5385. },
  5386. /**
  5387. * Extract full name and type of requested indicator.
  5388. * @private
  5389. * @param {Highcharts.Series} series
  5390. * Series which name is needed. (EDIT mode - defaultOptions.series, ADD
  5391. * mode - indicator series).
  5392. * @param {string} - indicator type like: sma, ema, etc.
  5393. * @return {Object} - series name and type like: sma, ema, etc.
  5394. */
  5395. getNameType: function (series, type) {
  5396. var options = series.options,
  5397. seriesTypes = H.seriesTypes,
  5398. // add mode
  5399. seriesName = seriesTypes[type] &&
  5400. seriesTypes[type].prototype.nameBase || type.toUpperCase(),
  5401. seriesType = type;
  5402. // edit
  5403. if (options && options.type) {
  5404. seriesType = series.options.type;
  5405. seriesName = series.name;
  5406. }
  5407. return {
  5408. name: seriesName,
  5409. type: seriesType
  5410. };
  5411. },
  5412. /**
  5413. * List all series with unique ID. Its mandatory for indicators to set
  5414. * correct linking.
  5415. * @private
  5416. * @param {string} type
  5417. * Indicator type like: sma, ema, etc.
  5418. * @param {string} optionName
  5419. * Type of select i.e series or volume.
  5420. * @param {Highcharts.Chart} chart
  5421. * Chart
  5422. * @param {Highcharts.HTMLDOMElement} parentDiv
  5423. * Element where created HTML list is added
  5424. * @param {string} selectedOption
  5425. * optional param for default value in dropdown
  5426. */
  5427. listAllSeries: function (type, optionName, chart, parentDiv, selectedOption) {
  5428. var selectName = PREFIX + optionName + '-type-' + type,
  5429. lang = this.lang,
  5430. selectBox,
  5431. seriesOptions;
  5432. createElement(LABEL, {
  5433. innerHTML: lang[optionName] || optionName,
  5434. htmlFor: selectName
  5435. }, null, parentDiv);
  5436. // select type
  5437. selectBox = createElement(SELECT, {
  5438. name: selectName,
  5439. className: PREFIX + 'popup-field'
  5440. }, null, parentDiv);
  5441. selectBox.setAttribute('id', PREFIX + 'select-' + optionName);
  5442. // list all series which have id - mandatory for creating indicator
  5443. chart.series.forEach(function (serie) {
  5444. seriesOptions = serie.options;
  5445. if (!seriesOptions.params &&
  5446. seriesOptions.id &&
  5447. seriesOptions.id !== PREFIX + 'navigator-series') {
  5448. createElement(OPTION, {
  5449. innerHTML: seriesOptions.name || seriesOptions.id,
  5450. value: seriesOptions.id
  5451. }, null, selectBox);
  5452. }
  5453. });
  5454. if (defined(selectedOption)) {
  5455. selectBox.value = selectedOption;
  5456. }
  5457. },
  5458. /**
  5459. * Create typical inputs for chosen indicator. Fields are extracted from
  5460. * defaultOptions (ADD mode) or current indicator (ADD mode). Two extra
  5461. * fields are added:
  5462. * - hidden input - contains indicator type (required for callback)
  5463. * - select - list of series which can be linked with indicator
  5464. * @private
  5465. * @param {Highcharts.Chart} chart
  5466. * Chart
  5467. * @param {Highcharts.Series} series
  5468. * Indicator
  5469. * @param {string} seriesType
  5470. * Indicator type like: sma, ema, etc.
  5471. * @param {Highcharts.HTMLDOMElement} rhsColWrapper
  5472. * Element where created HTML list is added
  5473. */
  5474. addFormFields: function (chart, series, seriesType, rhsColWrapper) {
  5475. var fields = series.params || series.options.params,
  5476. getNameType = this.indicators.getNameType;
  5477. // reset current content
  5478. rhsColWrapper.innerHTML = '';
  5479. // create title (indicator name in the right column)
  5480. createElement(H3, {
  5481. className: PREFIX + 'indicator-title',
  5482. innerHTML: getNameType(series, seriesType).name
  5483. }, null, rhsColWrapper);
  5484. // input type
  5485. createElement(INPUT, {
  5486. type: 'hidden',
  5487. name: PREFIX + 'type-' + seriesType,
  5488. value: seriesType
  5489. }, null, rhsColWrapper);
  5490. // list all series with id
  5491. this.indicators.listAllSeries.call(this, seriesType, 'series', chart, rhsColWrapper, series.linkedParent && fields.volumeSeriesID);
  5492. if (fields.volumeSeriesID) {
  5493. this.indicators.listAllSeries.call(this, seriesType, 'volume', chart, rhsColWrapper, series.linkedParent && series.linkedParent.options.id);
  5494. }
  5495. // add param fields
  5496. this.indicators.addParamInputs.call(this, chart, 'params', fields, seriesType, rhsColWrapper);
  5497. },
  5498. /**
  5499. * Recurent function which lists all fields, from params object and
  5500. * create them as inputs. Each input has unique `data-name` attribute,
  5501. * which keeps chain of fields i.e params.styles.fontSize.
  5502. * @private
  5503. * @param {Highcharts.Chart} chart
  5504. * Chart
  5505. * @param {string} parentNode
  5506. * Name of parent to create chain of names
  5507. * @param {Highcharts.PopupFieldsDictionary<string>} fields
  5508. * Params which are based for input create
  5509. * @param {string} type
  5510. * Indicator type like: sma, ema, etc.
  5511. * @param {Highcharts.HTMLDOMElement} parentDiv
  5512. * Element where created HTML list is added
  5513. */
  5514. addParamInputs: function (chart, parentNode, fields, type, parentDiv) {
  5515. var _self = this,
  5516. addParamInputs = this.indicators.addParamInputs,
  5517. addInput = this.addInput,
  5518. parentFullName;
  5519. objectEach(fields, function (value, fieldName) {
  5520. // create name like params.styles.fontSize
  5521. parentFullName = parentNode + '.' + fieldName;
  5522. if (isObject(value)) {
  5523. addParamInputs.call(_self, chart, parentFullName, value, type, parentDiv);
  5524. }
  5525. else if (
  5526. // skip volume field which is created by addFormFields
  5527. parentFullName !== 'params.volumeSeriesID') {
  5528. addInput.call(_self, parentFullName, type, parentDiv, [value, 'text'] // all inputs are text type
  5529. );
  5530. }
  5531. });
  5532. },
  5533. /**
  5534. * Get amount of indicators added to chart.
  5535. * @private
  5536. * @return {number} - Amount of indicators
  5537. */
  5538. getAmount: function () {
  5539. var series = this.series,
  5540. counter = 0;
  5541. series.forEach(function (serie) {
  5542. var seriesOptions = serie.options;
  5543. if (serie.params ||
  5544. seriesOptions && seriesOptions.params) {
  5545. counter++;
  5546. }
  5547. });
  5548. return counter;
  5549. }
  5550. },
  5551. tabs: {
  5552. /**
  5553. * Init tabs. Create tab menu items, tabs containers
  5554. * @private
  5555. * @param {Highcharts.Chart} chart
  5556. * Reference to current chart
  5557. */
  5558. init: function (chart) {
  5559. var tabs = this.tabs,
  5560. indicatorsCount = this.indicators.getAmount.call(chart),
  5561. firstTab; // run by default
  5562. // create menu items
  5563. firstTab = tabs.addMenuItem.call(this, 'add');
  5564. tabs.addMenuItem.call(this, 'edit', indicatorsCount);
  5565. // create tabs containers
  5566. tabs.addContentItem.call(this, 'add');
  5567. tabs.addContentItem.call(this, 'edit');
  5568. tabs.switchTabs.call(this, indicatorsCount);
  5569. // activate first tab
  5570. tabs.selectTab.call(this, firstTab, 0);
  5571. },
  5572. /**
  5573. * Create tab menu item
  5574. * @private
  5575. * @param {string} tabName
  5576. * `add` or `edit`
  5577. * @param {number} [disableTab]
  5578. * Disable tab when 0
  5579. * @return {Highcharts.HTMLDOMElement}
  5580. * Created HTML tab-menu element
  5581. */
  5582. addMenuItem: function (tabName, disableTab) {
  5583. var popupDiv = this.popup.container,
  5584. className = PREFIX + 'tab-item',
  5585. lang = this.lang,
  5586. menuItem;
  5587. if (disableTab === 0) {
  5588. className += ' ' + PREFIX + 'tab-disabled';
  5589. }
  5590. // tab 1
  5591. menuItem = createElement(SPAN, {
  5592. innerHTML: lang[tabName + 'Button'] || tabName,
  5593. className: className
  5594. }, null, popupDiv);
  5595. menuItem.setAttribute(PREFIX + 'data-tab-type', tabName);
  5596. return menuItem;
  5597. },
  5598. /**
  5599. * Create tab content
  5600. * @private
  5601. * @return {HTMLDOMElement} - created HTML tab-content element
  5602. */
  5603. addContentItem: function () {
  5604. var popupDiv = this.popup.container;
  5605. return createElement(DIV, {
  5606. className: PREFIX + 'tab-item-content'
  5607. }, null, popupDiv);
  5608. },
  5609. /**
  5610. * Add click event to each tab
  5611. * @private
  5612. * @param {number} disableTab
  5613. * Disable tab when 0
  5614. */
  5615. switchTabs: function (disableTab) {
  5616. var _self = this,
  5617. popupDiv = this.popup.container,
  5618. tabs = popupDiv.querySelectorAll('.' + PREFIX + 'tab-item'),
  5619. dataParam;
  5620. tabs.forEach(function (tab, i) {
  5621. dataParam = tab.getAttribute(PREFIX + 'data-tab-type');
  5622. if (dataParam === 'edit' && disableTab === 0) {
  5623. return;
  5624. }
  5625. ['click', 'touchstart'].forEach(function (eventName) {
  5626. addEvent(tab, eventName, function () {
  5627. // reset class on other elements
  5628. _self.tabs.deselectAll.call(_self);
  5629. _self.tabs.selectTab.call(_self, this, i);
  5630. });
  5631. });
  5632. });
  5633. },
  5634. /**
  5635. * Set tab as visible
  5636. * @private
  5637. * @param {globals.Element} - current tab
  5638. * @param {number} - Index of tab in menu
  5639. */
  5640. selectTab: function (tab, index) {
  5641. var allTabs = this.popup.container
  5642. .querySelectorAll('.' + PREFIX + 'tab-item-content');
  5643. tab.className += ' ' + PREFIX + 'tab-item-active';
  5644. allTabs[index].className += ' ' + PREFIX + 'tab-item-show';
  5645. },
  5646. /**
  5647. * Set all tabs as invisible.
  5648. * @private
  5649. */
  5650. deselectAll: function () {
  5651. var popupDiv = this.popup.container,
  5652. tabs = popupDiv
  5653. .querySelectorAll('.' + PREFIX + 'tab-item'),
  5654. tabsContent = popupDiv
  5655. .querySelectorAll('.' + PREFIX + 'tab-item-content'),
  5656. i;
  5657. for (i = 0; i < tabs.length; i++) {
  5658. tabs[i].classList.remove(PREFIX + 'tab-item-active');
  5659. tabsContent[i].classList.remove(PREFIX + 'tab-item-show');
  5660. }
  5661. }
  5662. }
  5663. };
  5664. addEvent(NavigationBindings, 'showPopup', function (config) {
  5665. if (!this.popup) {
  5666. // Add popup to main container
  5667. this.popup = new H.Popup(this.chart.container, (this.chart.options.navigation.iconsURL ||
  5668. (this.chart.options.stockTools &&
  5669. this.chart.options.stockTools.gui.iconsURL) ||
  5670. 'https://code.highcharts.com/8.2.0/gfx/stock-icons/'));
  5671. }
  5672. this.popup.showForm(config.formType, this.chart, config.options, config.onSubmit);
  5673. });
  5674. addEvent(NavigationBindings, 'closePopup', function () {
  5675. if (this.popup) {
  5676. this.popup.closePopup();
  5677. }
  5678. });
  5679. });
  5680. _registerModule(_modules, 'masters/modules/annotations.src.js', [], function () {
  5681. });
  5682. }));