annotations.src.js 251 KB

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