annotations.src.js 244 KB

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