annotations.src.js 242 KB

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