annotations.src.js 252 KB

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