stock-tools.src.js 347 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125
  1. /**
  2. * @license Highstock JS v8.2.2 (2020-10-22)
  3. *
  4. * Advanced Highstock tools
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Torstein Honsi
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/stock-tools', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'Extensions/Annotations/Mixins/EventEmitterMixin.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  33. /* *
  34. *
  35. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  36. *
  37. * */
  38. var addEvent = U.addEvent,
  39. fireEvent = U.fireEvent,
  40. objectEach = U.objectEach,
  41. pick = U.pick,
  42. removeEvent = U.removeEvent;
  43. /* eslint-disable valid-jsdoc */
  44. /**
  45. * It provides methods for:
  46. * - adding and handling DOM events and a drag event,
  47. * - mapping a mouse move event to the distance between two following events.
  48. * The units of the distance are specific to a transformation,
  49. * e.g. for rotation they are radians, for scaling they are scale factors.
  50. *
  51. * @private
  52. * @mixin
  53. * @memberOf Annotation
  54. */
  55. var eventEmitterMixin = {
  56. /**
  57. * Add emitter events.
  58. */
  59. addEvents: function () {
  60. var emitter = this,
  61. addMouseDownEvent = function (element) {
  62. addEvent(element,
  63. H.isTouchDevice ? 'touchstart' : 'mousedown',
  64. function (e) {
  65. emitter.onMouseDown(e);
  66. });
  67. };
  68. addMouseDownEvent(this.graphic.element);
  69. (emitter.labels || []).forEach(function (label) {
  70. if (label.options.useHTML && label.graphic.text) {
  71. // Mousedown event bound to HTML element (#13070).
  72. addMouseDownEvent(label.graphic.text.element);
  73. }
  74. });
  75. objectEach(emitter.options.events, function (event, type) {
  76. var eventHandler = function (e) {
  77. if (type !== 'click' || !emitter.cancelClick) {
  78. event.call(emitter,
  79. emitter.chart.pointer.normalize(e),
  80. emitter.target);
  81. }
  82. };
  83. if ((emitter.nonDOMEvents || []).indexOf(type) === -1) {
  84. emitter.graphic.on(type, eventHandler);
  85. }
  86. else {
  87. addEvent(emitter, type, eventHandler);
  88. }
  89. });
  90. if (emitter.options.draggable) {
  91. addEvent(emitter, 'drag', emitter.onDrag);
  92. if (!emitter.graphic.renderer.styledMode) {
  93. var cssPointer_1 = {
  94. cursor: {
  95. x: 'ew-resize',
  96. y: 'ns-resize',
  97. xy: 'move'
  98. }[emitter.options.draggable]
  99. };
  100. emitter.graphic.css(cssPointer_1);
  101. (emitter.labels || []).forEach(function (label) {
  102. if (label.options.useHTML && label.graphic.text) {
  103. label.graphic.text.css(cssPointer_1);
  104. }
  105. });
  106. }
  107. }
  108. if (!emitter.isUpdating) {
  109. fireEvent(emitter, 'add');
  110. }
  111. },
  112. /**
  113. * Remove emitter document events.
  114. */
  115. removeDocEvents: function () {
  116. if (this.removeDrag) {
  117. this.removeDrag = this.removeDrag();
  118. }
  119. if (this.removeMouseUp) {
  120. this.removeMouseUp = this.removeMouseUp();
  121. }
  122. },
  123. /**
  124. * Mouse down handler.
  125. */
  126. onMouseDown: function (e) {
  127. var emitter = this,
  128. pointer = emitter.chart.pointer,
  129. prevChartX,
  130. prevChartY;
  131. if (e.preventDefault) {
  132. e.preventDefault();
  133. }
  134. // On right click, do nothing:
  135. if (e.button === 2) {
  136. return;
  137. }
  138. e = pointer.normalize(e);
  139. prevChartX = e.chartX;
  140. prevChartY = e.chartY;
  141. emitter.cancelClick = false;
  142. emitter.chart.hasDraggedAnnotation = true;
  143. emitter.removeDrag = addEvent(H.doc, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
  144. emitter.hasDragged = true;
  145. e = pointer.normalize(e);
  146. e.prevChartX = prevChartX;
  147. e.prevChartY = prevChartY;
  148. fireEvent(emitter, 'drag', e);
  149. prevChartX = e.chartX;
  150. prevChartY = e.chartY;
  151. });
  152. emitter.removeMouseUp = addEvent(H.doc, H.isTouchDevice ? 'touchend' : 'mouseup', function (e) {
  153. emitter.cancelClick = emitter.hasDragged;
  154. emitter.hasDragged = false;
  155. emitter.chart.hasDraggedAnnotation = false;
  156. // ControlPoints vs Annotation:
  157. fireEvent(pick(emitter.target, emitter), 'afterUpdate');
  158. emitter.onMouseUp(e);
  159. });
  160. },
  161. /**
  162. * Mouse up handler.
  163. */
  164. onMouseUp: function (_e) {
  165. var chart = this.chart,
  166. annotation = this.target || this,
  167. annotationsOptions = chart.options.annotations,
  168. index = chart.annotations.indexOf(annotation);
  169. this.removeDocEvents();
  170. annotationsOptions[index] = annotation.options;
  171. },
  172. /**
  173. * Drag and drop event. All basic annotations should share this
  174. * capability as well as the extended ones.
  175. */
  176. onDrag: function (e) {
  177. if (this.chart.isInsidePlot(e.chartX - this.chart.plotLeft, e.chartY - this.chart.plotTop)) {
  178. var translation = this.mouseMoveToTranslation(e);
  179. if (this.options.draggable === 'x') {
  180. translation.y = 0;
  181. }
  182. if (this.options.draggable === 'y') {
  183. translation.x = 0;
  184. }
  185. if (this.points.length) {
  186. this.translate(translation.x, translation.y);
  187. }
  188. else {
  189. this.shapes.forEach(function (shape) {
  190. shape.translate(translation.x, translation.y);
  191. });
  192. this.labels.forEach(function (label) {
  193. label.translate(translation.x, translation.y);
  194. });
  195. }
  196. this.redraw(false);
  197. }
  198. },
  199. /**
  200. * Map mouse move event to the radians.
  201. */
  202. mouseMoveToRadians: function (e, cx, cy) {
  203. var prevDy = e.prevChartY - cy,
  204. prevDx = e.prevChartX - cx,
  205. dy = e.chartY - cy,
  206. dx = e.chartX - cx,
  207. temp;
  208. if (this.chart.inverted) {
  209. temp = prevDx;
  210. prevDx = prevDy;
  211. prevDy = temp;
  212. temp = dx;
  213. dx = dy;
  214. dy = temp;
  215. }
  216. return Math.atan2(dy, dx) - Math.atan2(prevDy, prevDx);
  217. },
  218. /**
  219. * Map mouse move event to the distance between two following events.
  220. */
  221. mouseMoveToTranslation: function (e) {
  222. var dx = e.chartX - e.prevChartX,
  223. dy = e.chartY - e.prevChartY,
  224. temp;
  225. if (this.chart.inverted) {
  226. temp = dy;
  227. dy = dx;
  228. dx = temp;
  229. }
  230. return {
  231. x: dx,
  232. y: dy
  233. };
  234. },
  235. /**
  236. * Map mouse move to the scale factors.
  237. *
  238. * @param {Object} e event
  239. * @param {number} cx center x
  240. * @param {number} cy center y
  241. **/
  242. mouseMoveToScale: function (e, cx, cy) {
  243. var prevDx = e.prevChartX - cx,
  244. prevDy = e.prevChartY - cy,
  245. dx = e.chartX - cx,
  246. dy = e.chartY - cy,
  247. sx = (dx || 1) / (prevDx || 1),
  248. sy = (dy || 1) / (prevDy || 1),
  249. temp;
  250. if (this.chart.inverted) {
  251. temp = sy;
  252. sy = sx;
  253. sx = temp;
  254. }
  255. return {
  256. x: sx,
  257. y: sy
  258. };
  259. },
  260. /**
  261. * Destroy the event emitter.
  262. */
  263. destroy: function () {
  264. this.removeDocEvents();
  265. removeEvent(this);
  266. this.hcEvents = null;
  267. }
  268. };
  269. return eventEmitterMixin;
  270. });
  271. _registerModule(_modules, 'Extensions/Annotations/ControlPoint.js', [_modules['Core/Utilities.js'], _modules['Extensions/Annotations/Mixins/EventEmitterMixin.js']], function (U, eventEmitterMixin) {
  272. /* *
  273. *
  274. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  275. *
  276. * */
  277. /**
  278. * Callback to modify annotation's possitioner controls.
  279. *
  280. * @callback Highcharts.AnnotationControlPointPositionerFunction
  281. * @param {Highcharts.AnnotationControlPoint} this
  282. * @param {Highcharts.AnnotationControllable} target
  283. * @return {Highcharts.PositionObject}
  284. */
  285. var extend = U.extend,
  286. merge = U.merge,
  287. pick = U.pick;
  288. /* eslint-disable no-invalid-this, valid-jsdoc */
  289. /**
  290. * A control point class which is a connection between controllable
  291. * transform methods and a user actions.
  292. *
  293. * @requires modules/annotations
  294. *
  295. * @class
  296. * @name Highcharts.AnnotationControlPoint
  297. *
  298. * @hideconstructor
  299. *
  300. * @param {Highcharts.Chart} chart
  301. * A chart instance.
  302. *
  303. * @param {Highcharts.AnnotationControllable} target
  304. * A controllable instance which is a target for a control point.
  305. *
  306. * @param {Highcharts.AnnotationControlPointOptionsObject} options
  307. * An options object.
  308. *
  309. * @param {number} [index]
  310. * Point index.
  311. */
  312. var ControlPoint = /** @class */ (function () {
  313. function ControlPoint(chart, target, options, index) {
  314. /**
  315. *
  316. * Properties
  317. *
  318. */
  319. this.addEvents = eventEmitterMixin.addEvents;
  320. this.graphic = void 0;
  321. this.mouseMoveToRadians = eventEmitterMixin.mouseMoveToRadians;
  322. this.mouseMoveToScale = eventEmitterMixin.mouseMoveToScale;
  323. this.mouseMoveToTranslation = eventEmitterMixin.mouseMoveToTranslation;
  324. this.onDrag = eventEmitterMixin.onDrag;
  325. this.onMouseDown = eventEmitterMixin.onMouseDown;
  326. this.onMouseUp = eventEmitterMixin.onMouseUp;
  327. this.removeDocEvents = eventEmitterMixin.removeDocEvents;
  328. /**
  329. *
  330. * Functions
  331. *
  332. */
  333. /**
  334. * List of events for `anntation.options.events` that should not be
  335. * added to `annotation.graphic` but to the `annotation`.
  336. * @private
  337. * @name Highcharts.AnnotationControlPoint#nonDOMEvents
  338. * @type {Array<string>}
  339. */
  340. this.nonDOMEvents = ['drag'];
  341. this.chart = chart;
  342. this.target = target;
  343. this.options = options;
  344. this.index = pick(options.index, index);
  345. }
  346. /**
  347. * Set the visibility of the control point.
  348. *
  349. * @function Highcharts.AnnotationControlPoint#setVisibility
  350. *
  351. * @param {boolean} visible
  352. * Visibility of the control point.
  353. *
  354. * @return {void}
  355. */
  356. ControlPoint.prototype.setVisibility = function (visible) {
  357. this.graphic.attr('visibility', visible ? 'visible' : 'hidden');
  358. this.options.visible = visible;
  359. };
  360. /**
  361. * Render the control point.
  362. * @private
  363. */
  364. ControlPoint.prototype.render = function () {
  365. var chart = this.chart,
  366. options = this.options;
  367. this.graphic = chart.renderer
  368. .symbol(options.symbol, 0, 0, options.width, options.height)
  369. .add(chart.controlPointsGroup)
  370. .css(options.style);
  371. this.setVisibility(options.visible);
  372. // npm test -- --tests "highcharts/annotations-advanced/*"
  373. this.addEvents();
  374. };
  375. /**
  376. * Redraw the control point.
  377. * @private
  378. * @param {boolean} [animation]
  379. */
  380. ControlPoint.prototype.redraw = function (animation) {
  381. this.graphic[animation ? 'animate' : 'attr'](this.options.positioner.call(this, this.target));
  382. };
  383. /**
  384. * Destroy the control point.
  385. * @private
  386. */
  387. ControlPoint.prototype.destroy = function () {
  388. eventEmitterMixin.destroy.call(this);
  389. if (this.graphic) {
  390. this.graphic = this.graphic.destroy();
  391. }
  392. this.chart = null;
  393. this.target = null;
  394. this.options = null;
  395. };
  396. /**
  397. * Update the control point.
  398. *
  399. * @function Highcharts.AnnotationControlPoint#update
  400. *
  401. * @param {Partial<Highcharts.AnnotationControlPointOptionsObject>} userOptions
  402. * New options for the control point.
  403. *
  404. * @return {void}
  405. */
  406. ControlPoint.prototype.update = function (userOptions) {
  407. var chart = this.chart,
  408. target = this.target,
  409. index = this.index,
  410. options = merge(true,
  411. this.options,
  412. userOptions);
  413. this.destroy();
  414. this.constructor(chart, target, options, index);
  415. this.render(chart.controlPointsGroup);
  416. this.redraw();
  417. };
  418. return ControlPoint;
  419. }());
  420. return ControlPoint;
  421. });
  422. _registerModule(_modules, 'Extensions/Annotations/MockPoint.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/Axis.js']], function (H, U, Axis) {
  423. /* *
  424. *
  425. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  426. *
  427. * */
  428. /**
  429. * @private
  430. * @interface Highcharts.AnnotationMockLabelOptionsObject
  431. */ /**
  432. * Point instance of the point.
  433. * @name Highcharts.AnnotationMockLabelOptionsObject#point
  434. * @type {Highcharts.AnnotationMockPoint}
  435. */ /**
  436. * X value translated to x axis scale.
  437. * @name Highcharts.AnnotationMockLabelOptionsObject#x
  438. * @type {number|null}
  439. */ /**
  440. * Y value translated to y axis scale.
  441. * @name Highcharts.AnnotationMockLabelOptionsObject#y
  442. * @type {number|null}
  443. */
  444. /**
  445. * A mock series instance imitating a real series from a real point.
  446. * @private
  447. * @interface Highcharts.AnnotationMockSeries
  448. */ /**
  449. * Whether a series is visible.
  450. * @name Highcharts.AnnotationMockSeries#visible
  451. * @type {boolean}
  452. */ /**
  453. * A chart instance.
  454. * @name Highcharts.AnnotationMockSeries#chart
  455. * @type {Highcharts.Chart}
  456. */ /**
  457. * @name Highcharts.AnnotationMockSeries#getPlotBox
  458. * @type {Function}
  459. */
  460. /**
  461. * Indicates if this is a mock point for an annotation.
  462. * @name Highcharts.Point#mock
  463. * @type {boolean|undefined}
  464. */
  465. var defined = U.defined,
  466. extend = U.extend,
  467. fireEvent = U.fireEvent;
  468. /* eslint-disable no-invalid-this, valid-jsdoc */
  469. /**
  470. * A trimmed point object which imitates {@link Highchart.Point} class. It is
  471. * created when there is a need of pointing to some chart's position using axis
  472. * values or pixel values
  473. *
  474. * @requires modules/annotations
  475. *
  476. * @private
  477. * @class
  478. * @name Highcharts.AnnotationMockPoint
  479. *
  480. * @hideconstructor
  481. *
  482. * @param {Highcharts.Chart} chart
  483. * The chart instance.
  484. *
  485. * @param {Highcharts.AnnotationControllable|null} target
  486. * The related controllable.
  487. *
  488. * @param {Highcharts.AnnotationMockPointOptionsObject|Function} options
  489. * The options object.
  490. */
  491. var MockPoint = /** @class */ (function () {
  492. function MockPoint(chart, target, options) {
  493. this.isInside = void 0;
  494. this.plotX = void 0;
  495. this.plotY = void 0;
  496. this.x = void 0;
  497. this.y = void 0;
  498. /* *
  499. *
  500. * Functions
  501. *
  502. * */
  503. /**
  504. * A flag indicating that a point is not the real one.
  505. *
  506. * @type {boolean}
  507. * @default true
  508. */
  509. this.mock = true;
  510. /**
  511. * A mock series instance imitating a real series from a real point.
  512. *
  513. * @name Annotation.AnnotationMockPoint#series
  514. * @type {Highcharts.AnnotationMockSeries}
  515. */
  516. this.series = {
  517. visible: true,
  518. chart: chart,
  519. getPlotBox: H.Series.prototype.getPlotBox
  520. };
  521. /**
  522. * @name Annotation.AnnotationMockPoint#target
  523. * @type {Highcharts.AnnotationControllable|null}
  524. */
  525. this.target = target || null;
  526. /**
  527. * Options for the mock point.
  528. *
  529. * @name Annotation.AnnotationMockPoint#options
  530. * @type {Highcharts.AnnotationsMockPointOptionsObject}
  531. */
  532. this.options = options;
  533. /**
  534. * If an xAxis is set it represents the point's value in terms of the
  535. * xAxis.
  536. *
  537. * @name Annotation.AnnotationMockPoint#x
  538. * @type {number|undefined}
  539. */
  540. /**
  541. * If an yAxis is set it represents the point's value in terms of the
  542. * yAxis.
  543. *
  544. * @name Annotation.AnnotationMockPoint#y
  545. * @type {number|undefined}
  546. */
  547. /**
  548. * It represents the point's pixel x coordinate relative to its plot
  549. * box.
  550. *
  551. * @name Annotation.AnnotationMockPoint#plotX
  552. * @type {number|undefined}
  553. */
  554. /**
  555. * It represents the point's pixel y position relative to its plot box.
  556. *
  557. * @name Annotation.AnnotationMockPoint#plotY
  558. * @type {number|undefined}
  559. */
  560. /**
  561. * Whether the point is inside the plot box.
  562. *
  563. * @name Annotation.AnnotationMockPoint#isInside
  564. * @type {boolean|undefined}
  565. */
  566. this.applyOptions(this.getOptions());
  567. }
  568. /**
  569. * Create a mock point from a real Highcharts point.
  570. *
  571. * @private
  572. * @static
  573. *
  574. * @param {Highcharts.Point} point
  575. *
  576. * @return {Highcharts.AnnotationMockPoint}
  577. * A mock point instance.
  578. */
  579. MockPoint.fromPoint = function (point) {
  580. return new MockPoint(point.series.chart, null, {
  581. x: point.x,
  582. y: point.y,
  583. xAxis: point.series.xAxis,
  584. yAxis: point.series.yAxis
  585. });
  586. };
  587. /**
  588. * Get the pixel position from the point like object.
  589. *
  590. * @private
  591. * @static
  592. *
  593. * @param {Highcharts.AnnotationPointType} point
  594. *
  595. * @param {boolean} [paneCoordinates]
  596. * whether the pixel position should be relative
  597. *
  598. * @return {Highcharts.PositionObject} pixel position
  599. */
  600. MockPoint.pointToPixels = function (point, paneCoordinates) {
  601. var series = point.series,
  602. chart = series.chart,
  603. x = point.plotX,
  604. y = point.plotY,
  605. plotBox;
  606. if (chart.inverted) {
  607. if (point.mock) {
  608. x = point.plotY;
  609. y = point.plotX;
  610. }
  611. else {
  612. x = chart.plotWidth - point.plotY;
  613. y = chart.plotHeight - point.plotX;
  614. }
  615. }
  616. if (series && !paneCoordinates) {
  617. plotBox = series.getPlotBox();
  618. x += plotBox.translateX;
  619. y += plotBox.translateY;
  620. }
  621. return {
  622. x: x,
  623. y: y
  624. };
  625. };
  626. /**
  627. * Get fresh mock point options from the point like object.
  628. *
  629. * @private
  630. * @static
  631. *
  632. * @param {Highcharts.AnnotationPointType} point
  633. *
  634. * @return {Highcharts.AnnotationMockPointOptionsObject}
  635. * A mock point's options.
  636. */
  637. MockPoint.pointToOptions = function (point) {
  638. return {
  639. x: point.x,
  640. y: point.y,
  641. xAxis: point.series.xAxis,
  642. yAxis: point.series.yAxis
  643. };
  644. };
  645. /**
  646. * Check if the point has dynamic options.
  647. * @private
  648. * @return {boolean}
  649. * A positive flag if the point has dynamic options.
  650. */
  651. MockPoint.prototype.hasDynamicOptions = function () {
  652. return typeof this.options === 'function';
  653. };
  654. /**
  655. * Get the point's options.
  656. * @private
  657. * @return {Highcharts.AnnotationMockPointOptionsObject}
  658. * The mock point's options.
  659. */
  660. MockPoint.prototype.getOptions = function () {
  661. return this.hasDynamicOptions() ?
  662. this.options(this.target) :
  663. this.options;
  664. };
  665. /**
  666. * Apply options for the point.
  667. * @private
  668. * @param {Highcharts.AnnotationMockPointOptionsObject} options
  669. */
  670. MockPoint.prototype.applyOptions = function (options) {
  671. this.command = options.command;
  672. this.setAxis(options, 'x');
  673. this.setAxis(options, 'y');
  674. this.refresh();
  675. };
  676. /**
  677. * Set x or y axis.
  678. * @private
  679. * @param {Highcharts.AnnotationMockPointOptionsObject} options
  680. * @param {string} xOrY
  681. * 'x' or 'y' string literal
  682. */
  683. MockPoint.prototype.setAxis = function (options, xOrY) {
  684. var axisName = (xOrY + 'Axis'),
  685. axisOptions = options[axisName],
  686. chart = this.series.chart;
  687. this.series[axisName] =
  688. axisOptions instanceof Axis ?
  689. axisOptions :
  690. defined(axisOptions) ?
  691. (chart[axisName][axisOptions] ||
  692. chart.get(axisOptions)) :
  693. null;
  694. };
  695. /**
  696. * Transform the mock point to an anchor (relative position on the chart).
  697. * @private
  698. * @return {Array<number>}
  699. * A quadruple of numbers which denotes x, y, width and height of the box
  700. **/
  701. MockPoint.prototype.toAnchor = function () {
  702. var anchor = [this.plotX,
  703. this.plotY, 0, 0];
  704. if (this.series.chart.inverted) {
  705. anchor[0] = this.plotY;
  706. anchor[1] = this.plotX;
  707. }
  708. return anchor;
  709. };
  710. /**
  711. * Returns a label config object - the same as
  712. * Highcharts.Point.prototype.getLabelConfig
  713. * @private
  714. * @return {Highcharts.AnnotationMockLabelOptionsObject} the point's label config
  715. */
  716. MockPoint.prototype.getLabelConfig = function () {
  717. return {
  718. x: this.x,
  719. y: this.y,
  720. point: this
  721. };
  722. };
  723. /**
  724. * Check if the point is inside its pane.
  725. * @private
  726. * @return {boolean} A flag indicating whether the point is inside the pane.
  727. */
  728. MockPoint.prototype.isInsidePlot = function () {
  729. var plotX = this.plotX,
  730. plotY = this.plotY,
  731. xAxis = this.series.xAxis,
  732. yAxis = this.series.yAxis,
  733. e = {
  734. x: plotX,
  735. y: plotY,
  736. isInsidePlot: true
  737. };
  738. if (xAxis) {
  739. e.isInsidePlot = defined(plotX) && plotX >= 0 && plotX <= xAxis.len;
  740. }
  741. if (yAxis) {
  742. e.isInsidePlot =
  743. e.isInsidePlot &&
  744. defined(plotY) &&
  745. plotY >= 0 && plotY <= yAxis.len;
  746. }
  747. fireEvent(this.series.chart, 'afterIsInsidePlot', e);
  748. return e.isInsidePlot;
  749. };
  750. /**
  751. * Refresh point values and coordinates based on its options.
  752. * @private
  753. */
  754. MockPoint.prototype.refresh = function () {
  755. var series = this.series,
  756. xAxis = series.xAxis,
  757. yAxis = series.yAxis,
  758. options = this.getOptions();
  759. if (xAxis) {
  760. this.x = options.x;
  761. this.plotX = xAxis.toPixels(options.x, true);
  762. }
  763. else {
  764. this.x = null;
  765. this.plotX = options.x;
  766. }
  767. if (yAxis) {
  768. this.y = options.y;
  769. this.plotY = yAxis.toPixels(options.y, true);
  770. }
  771. else {
  772. this.y = null;
  773. this.plotY = options.y;
  774. }
  775. this.isInside = this.isInsidePlot();
  776. };
  777. /**
  778. * Translate the point.
  779. *
  780. * @private
  781. *
  782. * @param {number|undefined} cx
  783. * Origin x transformation.
  784. *
  785. * @param {number|undefined} cy
  786. * Origin y transformation.
  787. *
  788. * @param {number} dx
  789. * Translation for x coordinate.
  790. *
  791. * @param {number} dy
  792. * Translation for y coordinate.
  793. **/
  794. MockPoint.prototype.translate = function (_cx, _cy, dx, dy) {
  795. if (!this.hasDynamicOptions()) {
  796. this.plotX += dx;
  797. this.plotY += dy;
  798. this.refreshOptions();
  799. }
  800. };
  801. /**
  802. * Scale the point.
  803. *
  804. * @private
  805. *
  806. * @param {number} cx
  807. * Origin x transformation.
  808. *
  809. * @param {number} cy
  810. * Origin y transformation.
  811. *
  812. * @param {number} sx
  813. * Scale factor x.
  814. *
  815. * @param {number} sy
  816. * Scale factor y.
  817. */
  818. MockPoint.prototype.scale = function (cx, cy, sx, sy) {
  819. if (!this.hasDynamicOptions()) {
  820. var x = this.plotX * sx,
  821. y = this.plotY * sy,
  822. tx = (1 - sx) * cx,
  823. ty = (1 - sy) * cy;
  824. this.plotX = tx + x;
  825. this.plotY = ty + y;
  826. this.refreshOptions();
  827. }
  828. };
  829. /**
  830. * Rotate the point.
  831. * @private
  832. * @param {number} cx origin x rotation
  833. * @param {number} cy origin y rotation
  834. * @param {number} radians
  835. */
  836. MockPoint.prototype.rotate = function (cx, cy, radians) {
  837. if (!this.hasDynamicOptions()) {
  838. var cos = Math.cos(radians),
  839. sin = Math.sin(radians),
  840. x = this.plotX,
  841. y = this.plotY,
  842. tx,
  843. ty;
  844. x -= cx;
  845. y -= cy;
  846. tx = x * cos - y * sin;
  847. ty = x * sin + y * cos;
  848. this.plotX = tx + cx;
  849. this.plotY = ty + cy;
  850. this.refreshOptions();
  851. }
  852. };
  853. /**
  854. * Refresh point options based on its plot coordinates.
  855. * @private
  856. */
  857. MockPoint.prototype.refreshOptions = function () {
  858. var series = this.series,
  859. xAxis = series.xAxis,
  860. yAxis = series.yAxis;
  861. this.x = this.options.x = xAxis ?
  862. this.options.x = xAxis.toValue(this.plotX, true) :
  863. this.plotX;
  864. this.y = this.options.y = yAxis ?
  865. yAxis.toValue(this.plotY, true) :
  866. this.plotY;
  867. };
  868. return MockPoint;
  869. }());
  870. return MockPoint;
  871. });
  872. _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) {
  873. /* *
  874. *
  875. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  876. *
  877. * */
  878. var isObject = U.isObject,
  879. isString = U.isString,
  880. merge = U.merge,
  881. splat = U.splat;
  882. /**
  883. * An object which denots a controllable's anchor positions - relative and
  884. * absolute.
  885. *
  886. * @private
  887. * @interface Highcharts.AnnotationAnchorObject
  888. */ /**
  889. * Relative to the plot area position
  890. * @name Highcharts.AnnotationAnchorObject#relativePosition
  891. * @type {Highcharts.BBoxObject}
  892. */ /**
  893. * Absolute position
  894. * @name Highcharts.AnnotationAnchorObject#absolutePosition
  895. * @type {Highcharts.BBoxObject}
  896. */
  897. /**
  898. * @interface Highcharts.AnnotationControllable
  899. */ /**
  900. * @name Highcharts.AnnotationControllable#annotation
  901. * @type {Highcharts.Annotation}
  902. */ /**
  903. * @name Highcharts.AnnotationControllable#chart
  904. * @type {Highcharts.Chart}
  905. */ /**
  906. * @name Highcharts.AnnotationControllable#collection
  907. * @type {string}
  908. */ /**
  909. * @private
  910. * @name Highcharts.AnnotationControllable#controlPoints
  911. * @type {Array<Highcharts.AnnotationControlPoint>}
  912. */ /**
  913. * @name Highcharts.AnnotationControllable#points
  914. * @type {Array<Highcharts.Point>}
  915. */
  916. /* eslint-disable no-invalid-this, valid-jsdoc */
  917. /**
  918. * It provides methods for handling points, control points
  919. * and points transformations.
  920. *
  921. * @private
  922. * @mixin
  923. * @name Highcharts.AnnotationControllableMixin
  924. */
  925. var controllableMixin = {
  926. /**
  927. * Init the controllable
  928. */
  929. init: function (annotation,
  930. options,
  931. index) {
  932. this.annotation = annotation;
  933. this.chart = annotation.chart;
  934. this.options = options;
  935. this.points = [];
  936. this.controlPoints = [];
  937. this.index = index;
  938. this.linkPoints();
  939. this.addControlPoints();
  940. },
  941. /**
  942. * Redirect attr usage on the controllable graphic element.
  943. */
  944. attr: function () {
  945. this.graphic.attr.apply(this.graphic, arguments);
  946. },
  947. /**
  948. * Get the controllable's points options.
  949. *
  950. * @return {Array<Highcharts.PointOptionsObject>}
  951. * An array of points' options.
  952. */
  953. getPointsOptions: function () {
  954. var options = this.options;
  955. return (options.points || (options.point && splat(options.point)));
  956. },
  957. /**
  958. * Utility function for mapping item's options
  959. * to element's attribute
  960. *
  961. * @param {Highcharts.AnnotationsLabelsOptions|Highcharts.AnnotationsShapesOptions} options
  962. *
  963. * @return {Highcharts.SVGAttributes}
  964. * Mapped options.
  965. */
  966. attrsFromOptions: function (options) {
  967. var map = this.constructor.attrsMap,
  968. attrs = {},
  969. key,
  970. mappedKey,
  971. styledMode = this.chart.styledMode;
  972. for (key in options) { // eslint-disable-line guard-for-in
  973. mappedKey = map[key];
  974. if (mappedKey &&
  975. (!styledMode ||
  976. ['fill', 'stroke', 'stroke-width']
  977. .indexOf(mappedKey) === -1)) {
  978. attrs[mappedKey] = options[key];
  979. }
  980. }
  981. return attrs;
  982. },
  983. /**
  984. * Returns object which denotes anchor position - relative and absolute.
  985. *
  986. * @param {Highcharts.AnnotationPointType} point
  987. * A point like object.
  988. *
  989. * @return {Highcharts.AnnotationAnchorObject} a controllable anchor
  990. */
  991. anchor: function (point) {
  992. var plotBox = point.series.getPlotBox(),
  993. chart = point.series.chart,
  994. box = point.mock ?
  995. point.toAnchor() :
  996. Tooltip.prototype.getAnchor.call({
  997. chart: point.series.chart
  998. },
  999. point),
  1000. anchor = {
  1001. x: box[0] + (this.options.x || 0),
  1002. y: box[1] + (this.options.y || 0),
  1003. height: box[2] || 0,
  1004. width: box[3] || 0
  1005. };
  1006. return {
  1007. relativePosition: anchor,
  1008. absolutePosition: merge(anchor, {
  1009. x: anchor.x + (point.mock ? plotBox.translateX : chart.plotLeft),
  1010. y: anchor.y + (point.mock ? plotBox.translateY : chart.plotTop)
  1011. })
  1012. };
  1013. },
  1014. /**
  1015. * Map point's options to a point-like object.
  1016. *
  1017. * @param {string|Function|Highcharts.AnnotationMockPointOptionsObject|Highcharts.AnnotationPointType} pointOptions
  1018. * Point's options.
  1019. *
  1020. * @param {Highcharts.AnnotationPointType} point
  1021. * A point-like instance.
  1022. *
  1023. * @return {Highcharts.AnnotationPointType|null}
  1024. * if the point is found/set returns this point, otherwise null
  1025. */
  1026. point: function (pointOptions, point) {
  1027. if (pointOptions && pointOptions.series) {
  1028. return pointOptions;
  1029. }
  1030. if (!point || point.series === null) {
  1031. if (isObject(pointOptions)) {
  1032. point = new MockPoint(this.chart, this, pointOptions);
  1033. }
  1034. else if (isString(pointOptions)) {
  1035. point = this.chart.get(pointOptions) || null;
  1036. }
  1037. else if (typeof pointOptions === 'function') {
  1038. var pointConfig = pointOptions.call(point,
  1039. this);
  1040. point = pointConfig.series ?
  1041. pointConfig :
  1042. new MockPoint(this.chart, this, pointOptions);
  1043. }
  1044. }
  1045. return point;
  1046. },
  1047. /**
  1048. * Find point-like objects based on points options.
  1049. *
  1050. * @return {Array<Annotation.PointLike>} an array of point-like objects
  1051. */
  1052. linkPoints: function () {
  1053. var pointsOptions = this.getPointsOptions(),
  1054. points = this.points,
  1055. len = (pointsOptions && pointsOptions.length) || 0,
  1056. i,
  1057. point;
  1058. for (i = 0; i < len; i++) {
  1059. point = this.point(pointsOptions[i], points[i]);
  1060. if (!point) {
  1061. points.length = 0;
  1062. return;
  1063. }
  1064. if (point.mock) {
  1065. point.refresh();
  1066. }
  1067. points[i] = point;
  1068. }
  1069. return points;
  1070. },
  1071. /**
  1072. * Add control points to a controllable.
  1073. */
  1074. addControlPoints: function () {
  1075. var controlPointsOptions = this.options.controlPoints;
  1076. (controlPointsOptions || []).forEach(function (controlPointOptions, i) {
  1077. var options = merge(this.options.controlPointOptions,
  1078. controlPointOptions);
  1079. if (!options.index) {
  1080. options.index = i;
  1081. }
  1082. controlPointsOptions[i] = options;
  1083. this.controlPoints.push(new ControlPoint(this.chart, this, options));
  1084. }, this);
  1085. },
  1086. /**
  1087. * Check if a controllable should be rendered/redrawn.
  1088. *
  1089. * @return {boolean}
  1090. * Whether a controllable should be drawn.
  1091. */
  1092. shouldBeDrawn: function () {
  1093. return Boolean(this.points.length);
  1094. },
  1095. /**
  1096. * Render a controllable.
  1097. */
  1098. render: function (_parentGroup) {
  1099. this.controlPoints.forEach(function (controlPoint) {
  1100. controlPoint.render();
  1101. });
  1102. },
  1103. /**
  1104. * Redraw a controllable.
  1105. *
  1106. * @param {boolean} [animation]
  1107. */
  1108. redraw: function (animation) {
  1109. this.controlPoints.forEach(function (controlPoint) {
  1110. controlPoint.redraw(animation);
  1111. });
  1112. },
  1113. /**
  1114. * Transform a controllable with a specific transformation.
  1115. *
  1116. * @param {string} transformation a transformation name
  1117. * @param {number|null} cx origin x transformation
  1118. * @param {number|null} cy origin y transformation
  1119. * @param {number} p1 param for the transformation
  1120. * @param {number} [p2] param for the transformation
  1121. */
  1122. transform: function (transformation, cx, cy, p1, p2) {
  1123. if (this.chart.inverted) {
  1124. var temp = cx;
  1125. cx = cy;
  1126. cy = temp;
  1127. }
  1128. this.points.forEach(function (point, i) {
  1129. this.transformPoint(transformation, cx, cy, p1, p2, i);
  1130. }, this);
  1131. },
  1132. /**
  1133. * Transform a point with a specific transformation
  1134. * If a transformed point is a real point it is replaced with
  1135. * the mock point.
  1136. *
  1137. * @param {string} transformation a transformation name
  1138. * @param {number|null} cx origin x transformation
  1139. * @param {number|null} cy origin y transformation
  1140. * @param {number} p1 param for the transformation
  1141. * @param {number|undefined} p2 param for the transformation
  1142. * @param {number} i index of the point
  1143. */
  1144. transformPoint: function (transformation, cx, cy, p1, p2, i) {
  1145. var point = this.points[i];
  1146. if (!point.mock) {
  1147. point = this.points[i] = MockPoint.fromPoint(point);
  1148. }
  1149. point[transformation](cx, cy, p1, p2);
  1150. },
  1151. /**
  1152. * Translate a controllable.
  1153. *
  1154. * @param {number} dx translation for x coordinate
  1155. * @param {number} dy translation for y coordinate
  1156. **/
  1157. translate: function (dx, dy) {
  1158. this.transform('translate', null, null, dx, dy);
  1159. },
  1160. /**
  1161. * Translate a specific point within a controllable.
  1162. *
  1163. * @param {number} dx translation for x coordinate
  1164. * @param {number} dy translation for y coordinate
  1165. * @param {number} i index of the point
  1166. **/
  1167. translatePoint: function (dx, dy, i) {
  1168. this.transformPoint('translate', null, null, dx, dy, i);
  1169. },
  1170. /**
  1171. * Translate shape within controllable item.
  1172. * Replaces `controllable.translate` method.
  1173. *
  1174. * @param {number} dx translation for x coordinate
  1175. * @param {number} dy translation for y coordinate
  1176. */
  1177. translateShape: function (dx, dy) {
  1178. var chart = this.annotation.chart,
  1179. // Annotation.options
  1180. shapeOptions = this.annotation.userOptions,
  1181. // Chart.options.annotations
  1182. annotationIndex = chart.annotations.indexOf(this.annotation),
  1183. chartOptions = chart.options.annotations[annotationIndex];
  1184. this.translatePoint(dx, dy, 0);
  1185. // Options stored in:
  1186. // - chart (for exporting)
  1187. // - current config (for redraws)
  1188. chartOptions[this.collection][this.index].point = this.options.point;
  1189. shapeOptions[this.collection][this.index].point = this.options.point;
  1190. },
  1191. /**
  1192. * Rotate a controllable.
  1193. *
  1194. * @param {number} cx origin x rotation
  1195. * @param {number} cy origin y rotation
  1196. * @param {number} radians
  1197. **/
  1198. rotate: function (cx, cy, radians) {
  1199. this.transform('rotate', cx, cy, radians);
  1200. },
  1201. /**
  1202. * Scale a controllable.
  1203. *
  1204. * @param {number} cx origin x rotation
  1205. * @param {number} cy origin y rotation
  1206. * @param {number} sx scale factor x
  1207. * @param {number} sy scale factor y
  1208. */
  1209. scale: function (cx, cy, sx, sy) {
  1210. this.transform('scale', cx, cy, sx, sy);
  1211. },
  1212. /**
  1213. * Set control points' visibility.
  1214. *
  1215. * @param {boolean} visible
  1216. */
  1217. setControlPointsVisibility: function (visible) {
  1218. this.controlPoints.forEach(function (controlPoint) {
  1219. controlPoint.setVisibility(visible);
  1220. });
  1221. },
  1222. /**
  1223. * Destroy a controllable.
  1224. */
  1225. destroy: function () {
  1226. if (this.graphic) {
  1227. this.graphic = this.graphic.destroy();
  1228. }
  1229. if (this.tracker) {
  1230. this.tracker = this.tracker.destroy();
  1231. }
  1232. this.controlPoints.forEach(function (controlPoint) {
  1233. controlPoint.destroy();
  1234. });
  1235. this.chart = null;
  1236. this.points = null;
  1237. this.controlPoints = null;
  1238. this.options = null;
  1239. if (this.annotation) {
  1240. this.annotation = null;
  1241. }
  1242. },
  1243. /**
  1244. * Update a controllable.
  1245. *
  1246. * @param {Object} newOptions
  1247. */
  1248. update: function (newOptions) {
  1249. var annotation = this.annotation,
  1250. options = merge(true,
  1251. this.options,
  1252. newOptions),
  1253. parentGroup = this.graphic.parentGroup;
  1254. this.destroy();
  1255. this.constructor(annotation, options);
  1256. this.render(parentGroup);
  1257. this.redraw();
  1258. }
  1259. };
  1260. return controllableMixin;
  1261. });
  1262. _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) {
  1263. /* *
  1264. *
  1265. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1266. *
  1267. * */
  1268. var addEvent = U.addEvent,
  1269. defined = U.defined,
  1270. merge = U.merge,
  1271. objectEach = U.objectEach,
  1272. uniqueKey = U.uniqueKey;
  1273. /**
  1274. * Options for configuring markers for annotations.
  1275. *
  1276. * An example of the arrow marker:
  1277. * <pre>
  1278. * {
  1279. * arrow: {
  1280. * id: 'arrow',
  1281. * tagName: 'marker',
  1282. * refY: 5,
  1283. * refX: 5,
  1284. * markerWidth: 10,
  1285. * markerHeight: 10,
  1286. * children: [{
  1287. * tagName: 'path',
  1288. * attrs: {
  1289. * d: 'M 0 0 L 10 5 L 0 10 Z',
  1290. * strokeWidth: 0
  1291. * }
  1292. * }]
  1293. * }
  1294. * }
  1295. * </pre>
  1296. *
  1297. * @sample highcharts/annotations/custom-markers/
  1298. * Define a custom marker for annotations
  1299. *
  1300. * @sample highcharts/css/annotations-markers/
  1301. * Define markers in a styled mode
  1302. *
  1303. * @type {Highcharts.Dictionary<Highcharts.SVGDefinitionObject>}
  1304. * @since 6.0.0
  1305. * @optionparent defs
  1306. */
  1307. var defaultMarkers = {
  1308. /**
  1309. * @type {Highcharts.SVGDefinitionObject}
  1310. */
  1311. arrow: {
  1312. tagName: 'marker',
  1313. render: false,
  1314. id: 'arrow',
  1315. refY: 5,
  1316. refX: 9,
  1317. markerWidth: 10,
  1318. markerHeight: 10,
  1319. /**
  1320. * @type {Array<Highcharts.DefsOptions>}
  1321. */
  1322. children: [{
  1323. tagName: 'path',
  1324. d: 'M 0 0 L 10 5 L 0 10 Z',
  1325. strokeWidth: 0
  1326. }]
  1327. },
  1328. /**
  1329. * @type {Highcharts.SVGDefinitionObject}
  1330. */
  1331. 'reverse-arrow': {
  1332. tagName: 'marker',
  1333. render: false,
  1334. id: 'reverse-arrow',
  1335. refY: 5,
  1336. refX: 1,
  1337. markerWidth: 10,
  1338. markerHeight: 10,
  1339. children: [{
  1340. tagName: 'path',
  1341. // reverse triangle (used as an arrow)
  1342. d: 'M 0 5 L 10 0 L 10 10 Z',
  1343. strokeWidth: 0
  1344. }]
  1345. }
  1346. };
  1347. SVGRenderer.prototype.addMarker = function (id, markerOptions) {
  1348. var options = { id: id };
  1349. var attrs = {
  1350. stroke: markerOptions.color || 'none',
  1351. fill: markerOptions.color || 'rgba(0, 0, 0, 0.75)'
  1352. };
  1353. options.children = markerOptions.children.map(function (child) {
  1354. return merge(attrs, child);
  1355. });
  1356. var marker = this.definition(merge(true, {
  1357. markerWidth: 20,
  1358. markerHeight: 20,
  1359. refX: 0,
  1360. refY: 0,
  1361. orient: 'auto'
  1362. },
  1363. markerOptions,
  1364. options));
  1365. marker.id = id;
  1366. return marker;
  1367. };
  1368. /* eslint-disable no-invalid-this, valid-jsdoc */
  1369. /**
  1370. * @private
  1371. */
  1372. function createMarkerSetter(markerType) {
  1373. return function (value) {
  1374. this.attr(markerType, 'url(#' + value + ')');
  1375. };
  1376. }
  1377. /**
  1378. * @private
  1379. * @mixin
  1380. * @name Highcharts.AnnotaitonMarkerMixin
  1381. */
  1382. var markerMixin = {
  1383. markerEndSetter: createMarkerSetter('marker-end'),
  1384. markerStartSetter: createMarkerSetter('marker-start'),
  1385. /**
  1386. * Set markers.
  1387. * @private
  1388. * @param {Highcharts.AnnotationControllablePath} item
  1389. */
  1390. setItemMarkers: function (item) {
  1391. var itemOptions = item.options,
  1392. chart = item.chart,
  1393. defs = chart.options.defs,
  1394. fill = itemOptions.fill,
  1395. color = defined(fill) && fill !== 'none' ?
  1396. fill :
  1397. itemOptions.stroke,
  1398. setMarker = function (markerType) {
  1399. var markerId = itemOptions[markerType],
  1400. def,
  1401. predefinedMarker,
  1402. key,
  1403. marker;
  1404. if (markerId) {
  1405. for (key in defs) { // eslint-disable-line guard-for-in
  1406. def = defs[key];
  1407. if (markerId === def.id &&
  1408. def.tagName === 'marker') {
  1409. predefinedMarker = def;
  1410. break;
  1411. }
  1412. }
  1413. if (predefinedMarker) {
  1414. marker = item[markerType] = chart.renderer
  1415. .addMarker((itemOptions.id || uniqueKey()) + '-' +
  1416. predefinedMarker.id, merge(predefinedMarker, { color: color }));
  1417. item.attr(markerType, marker.attr('id'));
  1418. }
  1419. }
  1420. };
  1421. ['markerStart', 'markerEnd'].forEach(setMarker);
  1422. }
  1423. };
  1424. addEvent(Chart, 'afterGetContainer', function () {
  1425. this.options.defs = merge(defaultMarkers, this.options.defs || {});
  1426. objectEach(this.options.defs, function (def) {
  1427. if (def.tagName === 'marker' && def.render !== false) {
  1428. this.renderer.addMarker(def.id, def);
  1429. }
  1430. }, this);
  1431. });
  1432. return markerMixin;
  1433. });
  1434. _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) {
  1435. /* *
  1436. *
  1437. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1438. *
  1439. * */
  1440. var extend = U.extend;
  1441. // See TRACKER_FILL in highcharts.src.js
  1442. var TRACKER_FILL = 'rgba(192,192,192,' + (H.svg ? 0.0001 : 0.002) + ')';
  1443. /* eslint-disable no-invalid-this, valid-jsdoc */
  1444. /**
  1445. * A controllable path class.
  1446. *
  1447. * @requires modules/annotations
  1448. *
  1449. * @private
  1450. * @class
  1451. * @name Highcharts.AnnotationControllablePath
  1452. *
  1453. * @param {Highcharts.Annotation}
  1454. * Related annotation.
  1455. *
  1456. * @param {Highcharts.AnnotationsShapeOptions} options
  1457. * A path's options object.
  1458. *
  1459. * @param {number} index
  1460. * Index of the path.
  1461. */
  1462. var ControllablePath = /** @class */ (function () {
  1463. /* *
  1464. *
  1465. * Constructors
  1466. *
  1467. * */
  1468. function ControllablePath(annotation, options, index) {
  1469. /* *
  1470. *
  1471. * Properties
  1472. *
  1473. * */
  1474. this.addControlPoints = ControllableMixin.addControlPoints;
  1475. this.anchor = ControllableMixin.anchor;
  1476. this.attr = ControllableMixin.attr;
  1477. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1478. this.destroy = ControllableMixin.destroy;
  1479. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1480. this.init = ControllableMixin.init;
  1481. this.linkPoints = ControllableMixin.linkPoints;
  1482. this.point = ControllableMixin.point;
  1483. this.rotate = ControllableMixin.rotate;
  1484. this.scale = ControllableMixin.scale;
  1485. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1486. this.setMarkers = MarkerMixin.setItemMarkers;
  1487. this.transform = ControllableMixin.transform;
  1488. this.transformPoint = ControllableMixin.transformPoint;
  1489. this.translate = ControllableMixin.translate;
  1490. this.translatePoint = ControllableMixin.translatePoint;
  1491. this.translateShape = ControllableMixin.translateShape;
  1492. this.update = ControllableMixin.update;
  1493. /**
  1494. * @type 'path'
  1495. */
  1496. this.type = 'path';
  1497. this.init(annotation, options, index);
  1498. this.collection = 'shapes';
  1499. }
  1500. /* *
  1501. *
  1502. * Functions
  1503. *
  1504. * */
  1505. /**
  1506. * Map the controllable path to 'd' path attribute.
  1507. *
  1508. * @return {Highcharts.SVGPathArray|null}
  1509. * A path's d attribute.
  1510. */
  1511. ControllablePath.prototype.toD = function () {
  1512. var dOption = this.options.d;
  1513. if (dOption) {
  1514. return typeof dOption === 'function' ?
  1515. dOption.call(this) :
  1516. dOption;
  1517. }
  1518. var points = this.points,
  1519. len = points.length,
  1520. showPath = len,
  1521. point = points[0],
  1522. position = showPath && this.anchor(point).absolutePosition,
  1523. pointIndex = 0,
  1524. command,
  1525. d = [];
  1526. if (position) {
  1527. d.push(['M', position.x, position.y]);
  1528. while (++pointIndex < len && showPath) {
  1529. point = points[pointIndex];
  1530. command = point.command || 'L';
  1531. position = this.anchor(point).absolutePosition;
  1532. if (command === 'M') {
  1533. d.push([command, position.x, position.y]);
  1534. }
  1535. else if (command === 'L') {
  1536. d.push([command, position.x, position.y]);
  1537. }
  1538. else if (command === 'Z') {
  1539. d.push([command]);
  1540. }
  1541. showPath = point.series.visible;
  1542. }
  1543. }
  1544. return showPath ?
  1545. this.chart.renderer.crispLine(d, this.graphic.strokeWidth()) :
  1546. null;
  1547. };
  1548. ControllablePath.prototype.shouldBeDrawn = function () {
  1549. return (ControllableMixin.shouldBeDrawn.call(this) || Boolean(this.options.d));
  1550. };
  1551. ControllablePath.prototype.render = function (parent) {
  1552. var options = this.options,
  1553. attrs = this.attrsFromOptions(options);
  1554. this.graphic = this.annotation.chart.renderer
  1555. .path([['M', 0, 0]])
  1556. .attr(attrs)
  1557. .add(parent);
  1558. if (options.className) {
  1559. this.graphic.addClass(options.className);
  1560. }
  1561. this.tracker = this.annotation.chart.renderer
  1562. .path([['M', 0, 0]])
  1563. .addClass('highcharts-tracker-line')
  1564. .attr({
  1565. zIndex: 2
  1566. })
  1567. .add(parent);
  1568. if (!this.annotation.chart.styledMode) {
  1569. this.tracker.attr({
  1570. 'stroke-linejoin': 'round',
  1571. stroke: TRACKER_FILL,
  1572. fill: TRACKER_FILL,
  1573. 'stroke-width': this.graphic.strokeWidth() +
  1574. options.snap * 2
  1575. });
  1576. }
  1577. ControllableMixin.render.call(this);
  1578. extend(this.graphic, {
  1579. markerStartSetter: MarkerMixin.markerStartSetter,
  1580. markerEndSetter: MarkerMixin.markerEndSetter
  1581. });
  1582. this.setMarkers(this);
  1583. };
  1584. ControllablePath.prototype.redraw = function (animation) {
  1585. var d = this.toD(),
  1586. action = animation ? 'animate' : 'attr';
  1587. if (d) {
  1588. this.graphic[action]({ d: d });
  1589. this.tracker[action]({ d: d });
  1590. }
  1591. else {
  1592. this.graphic.attr({ d: 'M 0 ' + -9e9 });
  1593. this.tracker.attr({ d: 'M 0 ' + -9e9 });
  1594. }
  1595. this.graphic.placed = this.tracker.placed = Boolean(d);
  1596. ControllableMixin.redraw.call(this, animation);
  1597. };
  1598. /* *
  1599. *
  1600. * Static Properties
  1601. *
  1602. * */
  1603. /**
  1604. * A map object which allows to map options attributes to element attributes
  1605. *
  1606. * @name Highcharts.AnnotationControllablePath.attrsMap
  1607. * @type {Highcharts.Dictionary<string>}
  1608. */
  1609. ControllablePath.attrsMap = {
  1610. dashStyle: 'dashstyle',
  1611. strokeWidth: 'stroke-width',
  1612. stroke: 'stroke',
  1613. fill: 'fill',
  1614. zIndex: 'zIndex'
  1615. };
  1616. return ControllablePath;
  1617. }());
  1618. return ControllablePath;
  1619. });
  1620. _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) {
  1621. /* *
  1622. *
  1623. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1624. *
  1625. * */
  1626. var merge = U.merge;
  1627. /**
  1628. * @typedef {Annotation.ControllablePath.AttrsMap}
  1629. * Annotation.ControllableRect.AttrsMap
  1630. * @property {string} width=width
  1631. * @property {string} height=height
  1632. */
  1633. /* eslint-disable no-invalid-this, valid-jsdoc */
  1634. /**
  1635. * A controllable rect class.
  1636. *
  1637. * @requires modules/annotations
  1638. *
  1639. * @private
  1640. * @class
  1641. * @name Highcharts.AnnotationControllableRect
  1642. *
  1643. * @param {Highcharts.Annotation} annotation
  1644. * An annotation instance.
  1645. *
  1646. * @param {Highcharts.AnnotationsShapeOptions} options
  1647. * A rect's options.
  1648. *
  1649. * @param {number} index
  1650. * Index of the rectangle
  1651. */
  1652. var ControllableRect = /** @class */ (function () {
  1653. /* *
  1654. *
  1655. * Constructors
  1656. *
  1657. * */
  1658. function ControllableRect(annotation, options, index) {
  1659. /* *
  1660. *
  1661. * Properties
  1662. *
  1663. * */
  1664. this.addControlPoints = ControllableMixin.addControlPoints;
  1665. this.anchor = ControllableMixin.anchor;
  1666. this.attr = ControllableMixin.attr;
  1667. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1668. this.destroy = ControllableMixin.destroy;
  1669. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1670. this.init = ControllableMixin.init;
  1671. this.linkPoints = ControllableMixin.linkPoints;
  1672. this.point = ControllableMixin.point;
  1673. this.rotate = ControllableMixin.rotate;
  1674. this.scale = ControllableMixin.scale;
  1675. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1676. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1677. this.transform = ControllableMixin.transform;
  1678. this.transformPoint = ControllableMixin.transformPoint;
  1679. this.translatePoint = ControllableMixin.translatePoint;
  1680. this.translateShape = ControllableMixin.translateShape;
  1681. this.update = ControllableMixin.update;
  1682. /**
  1683. * @type 'rect'
  1684. */
  1685. this.type = 'rect';
  1686. this.translate = ControllableMixin.translateShape;
  1687. this.init(annotation, options, index);
  1688. this.collection = 'shapes';
  1689. }
  1690. /* *
  1691. *
  1692. * Functions
  1693. *
  1694. * */
  1695. ControllableRect.prototype.render = function (parent) {
  1696. var attrs = this.attrsFromOptions(this.options);
  1697. this.graphic = this.annotation.chart.renderer
  1698. .rect(0, -9e9, 0, 0)
  1699. .attr(attrs)
  1700. .add(parent);
  1701. ControllableMixin.render.call(this);
  1702. };
  1703. ControllableRect.prototype.redraw = function (animation) {
  1704. var position = this.anchor(this.points[0]).absolutePosition;
  1705. if (position) {
  1706. this.graphic[animation ? 'animate' : 'attr']({
  1707. x: position.x,
  1708. y: position.y,
  1709. width: this.options.width,
  1710. height: this.options.height
  1711. });
  1712. }
  1713. else {
  1714. this.attr({
  1715. x: 0,
  1716. y: -9e9
  1717. });
  1718. }
  1719. this.graphic.placed = Boolean(position);
  1720. ControllableMixin.redraw.call(this, animation);
  1721. };
  1722. /* *
  1723. *
  1724. * Static Properties
  1725. *
  1726. * */
  1727. /**
  1728. * A map object which allows to map options attributes to element attributes
  1729. *
  1730. * @type {Annotation.ControllableRect.AttrsMap}
  1731. */
  1732. ControllableRect.attrsMap = merge(ControllablePath.attrsMap, {
  1733. width: 'width',
  1734. height: 'height'
  1735. });
  1736. return ControllableRect;
  1737. }());
  1738. return ControllableRect;
  1739. });
  1740. _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) {
  1741. /* *
  1742. *
  1743. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1744. *
  1745. * */
  1746. var merge = U.merge;
  1747. /* eslint-disable no-invalid-this, valid-jsdoc */
  1748. /**
  1749. * A controllable circle class.
  1750. *
  1751. * @requires modules/annotations
  1752. *
  1753. * @private
  1754. * @class
  1755. * @name Highcharts.AnnotationControllableCircle
  1756. *
  1757. * @param {Highcharts.Annotation} annotation an annotation instance
  1758. * @param {Highcharts.AnnotationsShapeOptions} options a shape's options
  1759. * @param {number} index of the circle
  1760. */
  1761. var ControllableCircle = /** @class */ (function () {
  1762. /* *
  1763. *
  1764. * Constructors
  1765. *
  1766. * */
  1767. function ControllableCircle(annotation, options, index) {
  1768. /* *
  1769. *
  1770. * Properties
  1771. *
  1772. * */
  1773. this.addControlPoints = ControllableMixin.addControlPoints;
  1774. this.anchor = ControllableMixin.anchor;
  1775. this.attr = ControllableMixin.attr;
  1776. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1777. this.destroy = ControllableMixin.destroy;
  1778. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1779. this.init = ControllableMixin.init;
  1780. this.linkPoints = ControllableMixin.linkPoints;
  1781. this.point = ControllableMixin.point;
  1782. this.rotate = ControllableMixin.rotate;
  1783. this.scale = ControllableMixin.scale;
  1784. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1785. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1786. this.transform = ControllableMixin.transform;
  1787. this.transformPoint = ControllableMixin.transformPoint;
  1788. this.translatePoint = ControllableMixin.translatePoint;
  1789. this.translateShape = ControllableMixin.translateShape;
  1790. this.update = ControllableMixin.update;
  1791. /**
  1792. * @type 'circle'
  1793. */
  1794. this.type = 'circle';
  1795. this.translate = ControllableMixin.translateShape;
  1796. this.init(annotation, options, index);
  1797. this.collection = 'shapes';
  1798. }
  1799. /* *
  1800. *
  1801. * Functions
  1802. *
  1803. * */
  1804. ControllableCircle.prototype.render = function (parent) {
  1805. var attrs = this.attrsFromOptions(this.options);
  1806. this.graphic = this.annotation.chart.renderer
  1807. .circle(0, -9e9, 0)
  1808. .attr(attrs)
  1809. .add(parent);
  1810. ControllableMixin.render.call(this);
  1811. };
  1812. ControllableCircle.prototype.redraw = function (animation) {
  1813. var position = this.anchor(this.points[0]).absolutePosition;
  1814. if (position) {
  1815. this.graphic[animation ? 'animate' : 'attr']({
  1816. x: position.x,
  1817. y: position.y,
  1818. r: this.options.r
  1819. });
  1820. }
  1821. else {
  1822. this.graphic.attr({
  1823. x: 0,
  1824. y: -9e9
  1825. });
  1826. }
  1827. this.graphic.placed = Boolean(position);
  1828. ControllableMixin.redraw.call(this, animation);
  1829. };
  1830. /**
  1831. * Set the radius.
  1832. *
  1833. * @param {number} r a radius to be set
  1834. */
  1835. ControllableCircle.prototype.setRadius = function (r) {
  1836. this.options.r = r;
  1837. };
  1838. /* *
  1839. *
  1840. * Static Properties
  1841. *
  1842. * */
  1843. /**
  1844. * A map object which allows to map options attributes to element
  1845. * attributes.
  1846. *
  1847. * @name Highcharts.AnnotationControllableCircle.attrsMap
  1848. * @type {Highcharts.Dictionary<string>}
  1849. */
  1850. ControllableCircle.attrsMap = merge(ControllablePath.attrsMap, { r: 'r' });
  1851. return ControllableCircle;
  1852. }());
  1853. return ControllableCircle;
  1854. });
  1855. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableLabel.js', [_modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Renderer/SVG/SVGRenderer.js'], _modules['Core/Tooltip.js'], _modules['Core/Utilities.js']], function (ControllableMixin, MockPoint, SVGRenderer, Tooltip, U) {
  1856. /* *
  1857. *
  1858. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1859. *
  1860. * */
  1861. var extend = U.extend,
  1862. format = U.format,
  1863. isNumber = U.isNumber,
  1864. pick = U.pick;
  1865. /* eslint-disable no-invalid-this, valid-jsdoc */
  1866. /**
  1867. * A controllable label class.
  1868. *
  1869. * @requires modules/annotations
  1870. *
  1871. * @private
  1872. * @class
  1873. * @name Highcharts.AnnotationControllableLabel
  1874. *
  1875. * @param {Highcharts.Annotation} annotation
  1876. * An annotation instance.
  1877. * @param {Highcharts.AnnotationsLabelOptions} options
  1878. * A label's options.
  1879. * @param {number} index
  1880. * Index of the label.
  1881. */
  1882. var ControllableLabel = /** @class */ (function () {
  1883. /* *
  1884. *
  1885. * Constructors
  1886. *
  1887. * */
  1888. function ControllableLabel(annotation, options, index) {
  1889. /* *
  1890. *
  1891. * Properties
  1892. *
  1893. * */
  1894. this.addControlPoints = ControllableMixin.addControlPoints;
  1895. this.attr = ControllableMixin.attr;
  1896. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  1897. this.destroy = ControllableMixin.destroy;
  1898. this.getPointsOptions = ControllableMixin.getPointsOptions;
  1899. this.init = ControllableMixin.init;
  1900. this.linkPoints = ControllableMixin.linkPoints;
  1901. this.point = ControllableMixin.point;
  1902. this.rotate = ControllableMixin.rotate;
  1903. this.scale = ControllableMixin.scale;
  1904. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  1905. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  1906. this.transform = ControllableMixin.transform;
  1907. this.transformPoint = ControllableMixin.transformPoint;
  1908. this.translateShape = ControllableMixin.translateShape;
  1909. this.update = ControllableMixin.update;
  1910. this.init(annotation, options, index);
  1911. this.collection = 'labels';
  1912. }
  1913. /* *
  1914. *
  1915. * Static Functions
  1916. *
  1917. * */
  1918. /**
  1919. * Returns new aligned position based alignment options and box to align to.
  1920. * It is almost a one-to-one copy from SVGElement.prototype.align
  1921. * except it does not use and mutate an element
  1922. *
  1923. * @param {Highcharts.AnnotationAlignObject} alignOptions
  1924. *
  1925. * @param {Highcharts.BBoxObject} box
  1926. *
  1927. * @return {Highcharts.PositionObject}
  1928. * Aligned position.
  1929. */
  1930. ControllableLabel.alignedPosition = function (alignOptions, box) {
  1931. var align = alignOptions.align,
  1932. vAlign = alignOptions.verticalAlign,
  1933. x = (box.x || 0) + (alignOptions.x || 0),
  1934. y = (box.y || 0) + (alignOptions.y || 0),
  1935. alignFactor,
  1936. vAlignFactor;
  1937. if (align === 'right') {
  1938. alignFactor = 1;
  1939. }
  1940. else if (align === 'center') {
  1941. alignFactor = 2;
  1942. }
  1943. if (alignFactor) {
  1944. x += (box.width - (alignOptions.width || 0)) / alignFactor;
  1945. }
  1946. if (vAlign === 'bottom') {
  1947. vAlignFactor = 1;
  1948. }
  1949. else if (vAlign === 'middle') {
  1950. vAlignFactor = 2;
  1951. }
  1952. if (vAlignFactor) {
  1953. y += (box.height - (alignOptions.height || 0)) / vAlignFactor;
  1954. }
  1955. return {
  1956. x: Math.round(x),
  1957. y: Math.round(y)
  1958. };
  1959. };
  1960. /**
  1961. * Returns new alignment options for a label if the label is outside the
  1962. * plot area. It is almost a one-to-one copy from
  1963. * Series.prototype.justifyDataLabel except it does not mutate the label and
  1964. * it works with absolute instead of relative position.
  1965. */
  1966. ControllableLabel.justifiedOptions = function (chart, label, alignOptions, alignAttr) {
  1967. var align = alignOptions.align,
  1968. verticalAlign = alignOptions.verticalAlign,
  1969. padding = label.box ? 0 : (label.padding || 0),
  1970. bBox = label.getBBox(),
  1971. off,
  1972. //
  1973. options = {
  1974. align: align,
  1975. verticalAlign: verticalAlign,
  1976. x: alignOptions.x,
  1977. y: alignOptions.y,
  1978. width: label.width,
  1979. height: label.height
  1980. },
  1981. //
  1982. x = alignAttr.x - chart.plotLeft,
  1983. y = alignAttr.y - chart.plotTop;
  1984. // Off left
  1985. off = x + padding;
  1986. if (off < 0) {
  1987. if (align === 'right') {
  1988. options.align = 'left';
  1989. }
  1990. else {
  1991. options.x = -off;
  1992. }
  1993. }
  1994. // Off right
  1995. off = x + bBox.width - padding;
  1996. if (off > chart.plotWidth) {
  1997. if (align === 'left') {
  1998. options.align = 'right';
  1999. }
  2000. else {
  2001. options.x = chart.plotWidth - off;
  2002. }
  2003. }
  2004. // Off top
  2005. off = y + padding;
  2006. if (off < 0) {
  2007. if (verticalAlign === 'bottom') {
  2008. options.verticalAlign = 'top';
  2009. }
  2010. else {
  2011. options.y = -off;
  2012. }
  2013. }
  2014. // Off bottom
  2015. off = y + bBox.height - padding;
  2016. if (off > chart.plotHeight) {
  2017. if (verticalAlign === 'top') {
  2018. options.verticalAlign = 'bottom';
  2019. }
  2020. else {
  2021. options.y = chart.plotHeight - off;
  2022. }
  2023. }
  2024. return options;
  2025. };
  2026. /* *
  2027. *
  2028. * Functions
  2029. *
  2030. * */
  2031. /**
  2032. * Translate the point of the label by deltaX and deltaY translations.
  2033. * The point is the label's anchor.
  2034. *
  2035. * @param {number} dx translation for x coordinate
  2036. * @param {number} dy translation for y coordinate
  2037. */
  2038. ControllableLabel.prototype.translatePoint = function (dx, dy) {
  2039. ControllableMixin.translatePoint.call(this, dx, dy, 0);
  2040. };
  2041. /**
  2042. * Translate x and y position relative to the label's anchor.
  2043. *
  2044. * @param {number} dx translation for x coordinate
  2045. * @param {number} dy translation for y coordinate
  2046. */
  2047. ControllableLabel.prototype.translate = function (dx, dy) {
  2048. var chart = this.annotation.chart,
  2049. // Annotation.options
  2050. labelOptions = this.annotation.userOptions,
  2051. // Chart.options.annotations
  2052. annotationIndex = chart.annotations.indexOf(this.annotation),
  2053. chartAnnotations = chart.options.annotations,
  2054. chartOptions = chartAnnotations[annotationIndex],
  2055. temp;
  2056. if (chart.inverted) {
  2057. temp = dx;
  2058. dx = dy;
  2059. dy = temp;
  2060. }
  2061. // Local options:
  2062. this.options.x += dx;
  2063. this.options.y += dy;
  2064. // Options stored in chart:
  2065. chartOptions[this.collection][this.index].x = this.options.x;
  2066. chartOptions[this.collection][this.index].y = this.options.y;
  2067. labelOptions[this.collection][this.index].x = this.options.x;
  2068. labelOptions[this.collection][this.index].y = this.options.y;
  2069. };
  2070. ControllableLabel.prototype.render = function (parent) {
  2071. var options = this.options,
  2072. attrs = this.attrsFromOptions(options),
  2073. style = options.style;
  2074. this.graphic = this.annotation.chart.renderer
  2075. .label('', 0, -9999, // #10055
  2076. options.shape, null, null, options.useHTML, null, 'annotation-label')
  2077. .attr(attrs)
  2078. .add(parent);
  2079. if (!this.annotation.chart.styledMode) {
  2080. if (style.color === 'contrast') {
  2081. style.color = this.annotation.chart.renderer.getContrast(ControllableLabel.shapesWithoutBackground.indexOf(options.shape) > -1 ? '#FFFFFF' : options.backgroundColor);
  2082. }
  2083. this.graphic
  2084. .css(options.style)
  2085. .shadow(options.shadow);
  2086. }
  2087. if (options.className) {
  2088. this.graphic.addClass(options.className);
  2089. }
  2090. this.graphic.labelrank = options.labelrank;
  2091. ControllableMixin.render.call(this);
  2092. };
  2093. ControllableLabel.prototype.redraw = function (animation) {
  2094. var options = this.options,
  2095. text = this.text || options.format || options.text,
  2096. label = this.graphic,
  2097. point = this.points[0],
  2098. anchor,
  2099. attrs;
  2100. label.attr({
  2101. text: text ?
  2102. format(text, point.getLabelConfig(), this.annotation.chart) :
  2103. options.formatter.call(point, this)
  2104. });
  2105. anchor = this.anchor(point);
  2106. attrs = this.position(anchor);
  2107. if (attrs) {
  2108. label.alignAttr = attrs;
  2109. attrs.anchorX = anchor.absolutePosition.x;
  2110. attrs.anchorY = anchor.absolutePosition.y;
  2111. label[animation ? 'animate' : 'attr'](attrs);
  2112. }
  2113. else {
  2114. label.attr({
  2115. x: 0,
  2116. y: -9999 // #10055
  2117. });
  2118. }
  2119. label.placed = !!attrs;
  2120. ControllableMixin.redraw.call(this, animation);
  2121. };
  2122. /**
  2123. * All basic shapes don't support alignTo() method except label.
  2124. * For a controllable label, we need to subtract translation from
  2125. * options.
  2126. */
  2127. ControllableLabel.prototype.anchor = function (_point) {
  2128. var anchor = ControllableMixin.anchor.apply(this,
  2129. arguments),
  2130. x = this.options.x || 0,
  2131. y = this.options.y || 0;
  2132. anchor.absolutePosition.x -= x;
  2133. anchor.absolutePosition.y -= y;
  2134. anchor.relativePosition.x -= x;
  2135. anchor.relativePosition.y -= y;
  2136. return anchor;
  2137. };
  2138. /**
  2139. * Returns the label position relative to its anchor.
  2140. *
  2141. * @param {Highcharts.AnnotationAnchorObject} anchor
  2142. *
  2143. * @return {Highcharts.PositionObject|null}
  2144. */
  2145. ControllableLabel.prototype.position = function (anchor) {
  2146. var item = this.graphic,
  2147. chart = this.annotation.chart,
  2148. point = this.points[0],
  2149. itemOptions = this.options,
  2150. anchorAbsolutePosition = anchor.absolutePosition,
  2151. anchorRelativePosition = anchor.relativePosition,
  2152. itemPosition,
  2153. alignTo,
  2154. itemPosRelativeX,
  2155. itemPosRelativeY,
  2156. showItem = point.series.visible &&
  2157. MockPoint.prototype.isInsidePlot.call(point);
  2158. if (showItem) {
  2159. if (itemOptions.distance) {
  2160. itemPosition = Tooltip.prototype.getPosition.call({
  2161. chart: chart,
  2162. distance: pick(itemOptions.distance, 16)
  2163. }, item.width, item.height, {
  2164. plotX: anchorRelativePosition.x,
  2165. plotY: anchorRelativePosition.y,
  2166. negative: point.negative,
  2167. ttBelow: point.ttBelow,
  2168. h: (anchorRelativePosition.height || anchorRelativePosition.width)
  2169. });
  2170. }
  2171. else if (itemOptions.positioner) {
  2172. itemPosition = itemOptions.positioner.call(this);
  2173. }
  2174. else {
  2175. alignTo = {
  2176. x: anchorAbsolutePosition.x,
  2177. y: anchorAbsolutePosition.y,
  2178. width: 0,
  2179. height: 0
  2180. };
  2181. itemPosition = ControllableLabel.alignedPosition(extend(itemOptions, {
  2182. width: item.width,
  2183. height: item.height
  2184. }), alignTo);
  2185. if (this.options.overflow === 'justify') {
  2186. itemPosition = ControllableLabel.alignedPosition(ControllableLabel.justifiedOptions(chart, item, itemOptions, itemPosition), alignTo);
  2187. }
  2188. }
  2189. if (itemOptions.crop) {
  2190. itemPosRelativeX = itemPosition.x - chart.plotLeft;
  2191. itemPosRelativeY = itemPosition.y - chart.plotTop;
  2192. showItem =
  2193. chart.isInsidePlot(itemPosRelativeX, itemPosRelativeY) &&
  2194. chart.isInsidePlot(itemPosRelativeX + item.width, itemPosRelativeY + item.height);
  2195. }
  2196. }
  2197. return showItem ? itemPosition : null;
  2198. };
  2199. /* *
  2200. *
  2201. * Static Properties
  2202. *
  2203. * */
  2204. /**
  2205. * A map object which allows to map options attributes to element attributes
  2206. *
  2207. * @type {Highcharts.Dictionary<string>}
  2208. */
  2209. ControllableLabel.attrsMap = {
  2210. backgroundColor: 'fill',
  2211. borderColor: 'stroke',
  2212. borderWidth: 'stroke-width',
  2213. zIndex: 'zIndex',
  2214. borderRadius: 'r',
  2215. padding: 'padding'
  2216. };
  2217. /**
  2218. * Shapes which do not have background - the object is used for proper
  2219. * setting of the contrast color.
  2220. *
  2221. * @type {Array<string>}
  2222. */
  2223. ControllableLabel.shapesWithoutBackground = ['connector'];
  2224. return ControllableLabel;
  2225. }());
  2226. /* ********************************************************************** */
  2227. /**
  2228. * General symbol definition for labels with connector
  2229. * @private
  2230. */
  2231. SVGRenderer.prototype.symbols.connector = function (x, y, w, h, options) {
  2232. var anchorX = options && options.anchorX,
  2233. anchorY = options && options.anchorY,
  2234. path,
  2235. yOffset,
  2236. lateral = w / 2;
  2237. if (isNumber(anchorX) && isNumber(anchorY)) {
  2238. path = [['M', anchorX, anchorY]];
  2239. // Prefer 45 deg connectors
  2240. yOffset = y - anchorY;
  2241. if (yOffset < 0) {
  2242. yOffset = -h - yOffset;
  2243. }
  2244. if (yOffset < w) {
  2245. lateral = anchorX < x + (w / 2) ? yOffset : w - yOffset;
  2246. }
  2247. // Anchor below label
  2248. if (anchorY > y + h) {
  2249. path.push(['L', x + lateral, y + h]);
  2250. // Anchor above label
  2251. }
  2252. else if (anchorY < y) {
  2253. path.push(['L', x + lateral, y]);
  2254. // Anchor left of label
  2255. }
  2256. else if (anchorX < x) {
  2257. path.push(['L', x, y + h / 2]);
  2258. // Anchor right of label
  2259. }
  2260. else if (anchorX > x + w) {
  2261. path.push(['L', x + w, y + h / 2]);
  2262. }
  2263. }
  2264. return path || [];
  2265. };
  2266. return ControllableLabel;
  2267. });
  2268. _registerModule(_modules, 'Extensions/Annotations/Controllables/ControllableImage.js', [_modules['Extensions/Annotations/Controllables/ControllableLabel.js'], _modules['Extensions/Annotations/Mixins/ControllableMixin.js']], function (ControllableLabel, ControllableMixin) {
  2269. /* *
  2270. *
  2271. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2272. *
  2273. * */
  2274. /* eslint-disable no-invalid-this, valid-jsdoc */
  2275. /**
  2276. * A controllable image class.
  2277. *
  2278. * @requires modules/annotations
  2279. *
  2280. * @private
  2281. * @class
  2282. * @name Highcharts.AnnotationControllableImage
  2283. *
  2284. * @param {Highcharts.Annotation} annotation
  2285. * An annotation instance.
  2286. *
  2287. * @param {Highcharts.AnnotationsShapeOptions} options
  2288. * A controllable's options.
  2289. *
  2290. * @param {number} index
  2291. * Index of the image.
  2292. */
  2293. var ControllableImage = /** @class */ (function () {
  2294. /* *
  2295. *
  2296. * Constructors
  2297. *
  2298. * */
  2299. function ControllableImage(annotation, options, index) {
  2300. /* *
  2301. *
  2302. * Properties
  2303. *
  2304. * */
  2305. this.addControlPoints = ControllableMixin.addControlPoints;
  2306. this.anchor = ControllableMixin.anchor;
  2307. this.attr = ControllableMixin.attr;
  2308. this.attrsFromOptions = ControllableMixin.attrsFromOptions;
  2309. this.destroy = ControllableMixin.destroy;
  2310. this.getPointsOptions = ControllableMixin.getPointsOptions;
  2311. this.init = ControllableMixin.init;
  2312. this.linkPoints = ControllableMixin.linkPoints;
  2313. this.point = ControllableMixin.point;
  2314. this.rotate = ControllableMixin.rotate;
  2315. this.scale = ControllableMixin.scale;
  2316. this.setControlPointsVisibility = ControllableMixin.setControlPointsVisibility;
  2317. this.shouldBeDrawn = ControllableMixin.shouldBeDrawn;
  2318. this.transform = ControllableMixin.transform;
  2319. this.transformPoint = ControllableMixin.transformPoint;
  2320. this.translatePoint = ControllableMixin.translatePoint;
  2321. this.translateShape = ControllableMixin.translateShape;
  2322. this.update = ControllableMixin.update;
  2323. /**
  2324. * @type 'image'
  2325. */
  2326. this.type = 'image';
  2327. this.translate = ControllableMixin.translateShape;
  2328. this.init(annotation, options, index);
  2329. this.collection = 'shapes';
  2330. }
  2331. ControllableImage.prototype.render = function (parent) {
  2332. var attrs = this.attrsFromOptions(this.options),
  2333. options = this.options;
  2334. this.graphic = this.annotation.chart.renderer
  2335. .image(options.src, 0, -9e9, options.width, options.height)
  2336. .attr(attrs)
  2337. .add(parent);
  2338. this.graphic.width = options.width;
  2339. this.graphic.height = options.height;
  2340. ControllableMixin.render.call(this);
  2341. };
  2342. ControllableImage.prototype.redraw = function (animation) {
  2343. var anchor = this.anchor(this.points[0]),
  2344. position = ControllableLabel.prototype.position.call(this,
  2345. anchor);
  2346. if (position) {
  2347. this.graphic[animation ? 'animate' : 'attr']({
  2348. x: position.x,
  2349. y: position.y
  2350. });
  2351. }
  2352. else {
  2353. this.graphic.attr({
  2354. x: 0,
  2355. y: -9e9
  2356. });
  2357. }
  2358. this.graphic.placed = Boolean(position);
  2359. ControllableMixin.redraw.call(this, animation);
  2360. };
  2361. /* *
  2362. *
  2363. * Static Properties
  2364. *
  2365. * */
  2366. /**
  2367. * A map object which allows to map options attributes to element attributes
  2368. *
  2369. * @name Highcharts.AnnotationControllableImage.attrsMap
  2370. * @type {Highcharts.Dictionary<string>}
  2371. */
  2372. ControllableImage.attrsMap = {
  2373. width: 'width',
  2374. height: 'height',
  2375. zIndex: 'zIndex'
  2376. };
  2377. return ControllableImage;
  2378. }());
  2379. return ControllableImage;
  2380. });
  2381. _registerModule(_modules, 'Extensions/Annotations/Annotations.js', [_modules['Core/Animation/AnimationUtilities.js'], _modules['Core/Chart/Chart.js'], _modules['Extensions/Annotations/Mixins/ControllableMixin.js'], _modules['Extensions/Annotations/Controllables/ControllableRect.js'], _modules['Extensions/Annotations/Controllables/ControllableCircle.js'], _modules['Extensions/Annotations/Controllables/ControllablePath.js'], _modules['Extensions/Annotations/Controllables/ControllableImage.js'], _modules['Extensions/Annotations/Controllables/ControllableLabel.js'], _modules['Extensions/Annotations/ControlPoint.js'], _modules['Extensions/Annotations/Mixins/EventEmitterMixin.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/MockPoint.js'], _modules['Core/Pointer.js'], _modules['Core/Utilities.js']], function (A, Chart, ControllableMixin, ControllableRect, ControllableCircle, ControllablePath, ControllableImage, ControllableLabel, ControlPoint, EventEmitterMixin, H, MockPoint, Pointer, U) {
  2382. /* *
  2383. *
  2384. * (c) 2009-2017 Highsoft, Black Label
  2385. *
  2386. * License: www.highcharts.com/license
  2387. *
  2388. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2389. *
  2390. * */
  2391. var getDeferredAnimation = A.getDeferredAnimation;
  2392. var chartProto = Chart.prototype;
  2393. var addEvent = U.addEvent,
  2394. defined = U.defined,
  2395. destroyObjectProperties = U.destroyObjectProperties,
  2396. erase = U.erase,
  2397. extend = U.extend,
  2398. find = U.find,
  2399. fireEvent = U.fireEvent,
  2400. merge = U.merge,
  2401. pick = U.pick,
  2402. splat = U.splat,
  2403. wrap = U.wrap;
  2404. /* *********************************************************************
  2405. *
  2406. * ANNOTATION
  2407. *
  2408. ******************************************************************** */
  2409. /**
  2410. * Possible directions for draggable annotations. An empty string (`''`)
  2411. * makes the annotation undraggable.
  2412. *
  2413. * @typedef {''|'x'|'xy'|'y'} Highcharts.AnnotationDraggableValue
  2414. */
  2415. /**
  2416. * @private
  2417. * @typedef {
  2418. * Highcharts.AnnotationControllableCircle|
  2419. * Highcharts.AnnotationControllableImage|
  2420. * Highcharts.AnnotationControllablePath|
  2421. * Highcharts.AnnotationControllableRect
  2422. * }
  2423. * Highcharts.AnnotationShapeType
  2424. * @requires modules/annotations
  2425. */
  2426. /**
  2427. * @private
  2428. * @typedef {
  2429. * Highcharts.AnnotationControllableLabel
  2430. * }
  2431. * Highcharts.AnnotationLabelType
  2432. * @requires modules/annotations
  2433. */
  2434. /**
  2435. * A point-like object, a mock point or a point used in series.
  2436. * @private
  2437. * @typedef {Highcharts.AnnotationMockPoint|Highcharts.Point} Highcharts.AnnotationPointType
  2438. * @requires modules/annotations
  2439. */
  2440. /* eslint-disable no-invalid-this, valid-jsdoc */
  2441. /**
  2442. * An annotation class which serves as a container for items like labels or
  2443. * shapes. Created items are positioned on the chart either by linking them to
  2444. * existing points or created mock points
  2445. *
  2446. * @class
  2447. * @name Highcharts.Annotation
  2448. *
  2449. * @param {Highcharts.Chart} chart a chart instance
  2450. * @param {Highcharts.AnnotationsOptions} userOptions the options object
  2451. */
  2452. var Annotation = /** @class */ (function () {
  2453. /* *
  2454. *
  2455. * Constructors
  2456. *
  2457. * */
  2458. function Annotation(chart, userOptions) {
  2459. /* *
  2460. *
  2461. * Properties
  2462. *
  2463. * */
  2464. this.annotation = void 0;
  2465. this.coll = 'annotations';
  2466. this.collection = void 0;
  2467. this.animationConfig = void 0;
  2468. this.graphic = void 0;
  2469. this.group = void 0;
  2470. this.labelCollector = void 0;
  2471. this.labelsGroup = void 0;
  2472. this.shapesGroup = void 0;
  2473. var labelsAndShapes;
  2474. /**
  2475. * The chart that the annotation belongs to.
  2476. *
  2477. * @type {Highcharts.Chart}
  2478. */
  2479. this.chart = chart;
  2480. /**
  2481. * The array of points which defines the annotation.
  2482. *
  2483. * @type {Array<Highcharts.Point>}
  2484. */
  2485. this.points = [];
  2486. /**
  2487. * The array of control points.
  2488. *
  2489. * @private
  2490. * @name Highcharts.Annotation#controlPoints
  2491. * @type {Array<Annotation.ControlPoint>}
  2492. */
  2493. this.controlPoints = [];
  2494. this.coll = 'annotations';
  2495. /**
  2496. * The array of labels which belong to the annotation.
  2497. *
  2498. * @private
  2499. * @name Highcharts.Annotation#labels
  2500. * @type {Array<Highcharts.AnnotationLabelType>}
  2501. */
  2502. this.labels = [];
  2503. /**
  2504. * The array of shapes which belong to the annotation.
  2505. *
  2506. * @private
  2507. * @name Highcharts.Annotation#shapes
  2508. * @type {Array<Highcharts.AnnotationShapeType>}
  2509. */
  2510. this.shapes = [];
  2511. /**
  2512. * The options for the annotations.
  2513. *
  2514. * @name Highcharts.Annotation#options
  2515. * @type {Highcharts.AnnotationsOptions}
  2516. */
  2517. this.options = merge(this.defaultOptions, userOptions);
  2518. /**
  2519. * The user options for the annotations.
  2520. *
  2521. * @name Highcharts.Annotation#userOptions
  2522. * @type {Highcharts.AnnotationsOptions}
  2523. */
  2524. this.userOptions = userOptions;
  2525. // Handle labels and shapes - those are arrays
  2526. // Merging does not work with arrays (stores reference)
  2527. labelsAndShapes = this.getLabelsAndShapesOptions(this.options, userOptions);
  2528. this.options.labels = labelsAndShapes.labels;
  2529. this.options.shapes = labelsAndShapes.shapes;
  2530. /**
  2531. * The callback that reports to the overlapping-labels module which
  2532. * labels it should account for.
  2533. * @private
  2534. * @name Highcharts.Annotation#labelCollector
  2535. * @type {Function}
  2536. */
  2537. /**
  2538. * The group svg element.
  2539. *
  2540. * @name Highcharts.Annotation#group
  2541. * @type {Highcharts.SVGElement}
  2542. */
  2543. /**
  2544. * The group svg element of the annotation's shapes.
  2545. *
  2546. * @name Highcharts.Annotation#shapesGroup
  2547. * @type {Highcharts.SVGElement}
  2548. */
  2549. /**
  2550. * The group svg element of the annotation's labels.
  2551. *
  2552. * @name Highcharts.Annotation#labelsGroup
  2553. * @type {Highcharts.SVGElement}
  2554. */
  2555. this.init(chart, this.options);
  2556. }
  2557. /**
  2558. * Initialize the annotation.
  2559. * @private
  2560. */
  2561. Annotation.prototype.init = function () {
  2562. var chart = this.chart,
  2563. animOptions = this.options.animation;
  2564. this.linkPoints();
  2565. this.addControlPoints();
  2566. this.addShapes();
  2567. this.addLabels();
  2568. this.setLabelCollector();
  2569. this.animationConfig = getDeferredAnimation(chart, animOptions);
  2570. };
  2571. Annotation.prototype.getLabelsAndShapesOptions = function (baseOptions, newOptions) {
  2572. var mergedOptions = {};
  2573. ['labels', 'shapes'].forEach(function (name) {
  2574. if (baseOptions[name]) {
  2575. mergedOptions[name] = splat(newOptions[name]).map(function (basicOptions, i) {
  2576. return merge(baseOptions[name][i], basicOptions);
  2577. });
  2578. }
  2579. });
  2580. return mergedOptions;
  2581. };
  2582. Annotation.prototype.addShapes = function () {
  2583. (this.options.shapes || []).forEach(function (shapeOptions, i) {
  2584. var shape = this.initShape(shapeOptions,
  2585. i);
  2586. merge(true, this.options.shapes[i], shape.options);
  2587. }, this);
  2588. };
  2589. Annotation.prototype.addLabels = function () {
  2590. (this.options.labels || []).forEach(function (labelsOptions, i) {
  2591. var labels = this.initLabel(labelsOptions,
  2592. i);
  2593. merge(true, this.options.labels[i], labels.options);
  2594. }, this);
  2595. };
  2596. Annotation.prototype.addClipPaths = function () {
  2597. this.setClipAxes();
  2598. if (this.clipXAxis && this.clipYAxis) {
  2599. this.clipRect = this.chart.renderer.clipRect(this.getClipBox());
  2600. }
  2601. };
  2602. Annotation.prototype.setClipAxes = function () {
  2603. var xAxes = this.chart.xAxis,
  2604. yAxes = this.chart.yAxis,
  2605. linkedAxes = (this.options.labels || [])
  2606. .concat(this.options.shapes || [])
  2607. .reduce(function (axes,
  2608. labelOrShape) {
  2609. return [
  2610. xAxes[labelOrShape &&
  2611. labelOrShape.point &&
  2612. labelOrShape.point.xAxis] || axes[0],
  2613. yAxes[labelOrShape &&
  2614. labelOrShape.point &&
  2615. labelOrShape.point.yAxis] || axes[1]
  2616. ];
  2617. }, []);
  2618. this.clipXAxis = linkedAxes[0];
  2619. this.clipYAxis = linkedAxes[1];
  2620. };
  2621. Annotation.prototype.getClipBox = function () {
  2622. if (this.clipXAxis && this.clipYAxis) {
  2623. return {
  2624. x: this.clipXAxis.left,
  2625. y: this.clipYAxis.top,
  2626. width: this.clipXAxis.width,
  2627. height: this.clipYAxis.height
  2628. };
  2629. }
  2630. };
  2631. Annotation.prototype.setLabelCollector = function () {
  2632. var annotation = this;
  2633. annotation.labelCollector = function () {
  2634. return annotation.labels.reduce(function (labels, label) {
  2635. if (!label.options.allowOverlap) {
  2636. labels.push(label.graphic);
  2637. }
  2638. return labels;
  2639. }, []);
  2640. };
  2641. annotation.chart.labelCollectors.push(annotation.labelCollector);
  2642. };
  2643. /**
  2644. * Set an annotation options.
  2645. * @private
  2646. * @param {Highcharts.AnnotationsOptions} - user options for an annotation
  2647. */
  2648. Annotation.prototype.setOptions = function (userOptions) {
  2649. this.options = merge(this.defaultOptions, userOptions);
  2650. };
  2651. Annotation.prototype.redraw = function (animation) {
  2652. this.linkPoints();
  2653. if (!this.graphic) {
  2654. this.render();
  2655. }
  2656. if (this.clipRect) {
  2657. this.clipRect.animate(this.getClipBox());
  2658. }
  2659. this.redrawItems(this.shapes, animation);
  2660. this.redrawItems(this.labels, animation);
  2661. ControllableMixin.redraw.call(this, animation);
  2662. };
  2663. /**
  2664. * @private
  2665. * @param {Array<Highcharts.AnnotationControllable>} items
  2666. * @param {boolean} [animation]
  2667. */
  2668. Annotation.prototype.redrawItems = function (items, animation) {
  2669. var i = items.length;
  2670. // needs a backward loop
  2671. // labels/shapes array might be modified
  2672. // due to destruction of the item
  2673. while (i--) {
  2674. this.redrawItem(items[i], animation);
  2675. }
  2676. };
  2677. /**
  2678. * @private
  2679. * @param {Array<Highcharts.AnnotationControllable>} items
  2680. */
  2681. Annotation.prototype.renderItems = function (items) {
  2682. var i = items.length;
  2683. while (i--) {
  2684. this.renderItem(items[i]);
  2685. }
  2686. };
  2687. Annotation.prototype.render = function () {
  2688. var renderer = this.chart.renderer;
  2689. this.graphic = renderer
  2690. .g('annotation')
  2691. .attr({
  2692. opacity: 0,
  2693. zIndex: this.options.zIndex,
  2694. visibility: this.options.visible ?
  2695. 'visible' :
  2696. 'hidden'
  2697. })
  2698. .add();
  2699. this.shapesGroup = renderer
  2700. .g('annotation-shapes')
  2701. .add(this.graphic)
  2702. .clip(this.chart.plotBoxClip);
  2703. this.labelsGroup = renderer
  2704. .g('annotation-labels')
  2705. .attr({
  2706. // hideOverlappingLabels requires translation
  2707. translateX: 0,
  2708. translateY: 0
  2709. })
  2710. .add(this.graphic);
  2711. this.addClipPaths();
  2712. if (this.clipRect) {
  2713. this.graphic.clip(this.clipRect);
  2714. }
  2715. // Render shapes and labels before adding events (#13070).
  2716. this.renderItems(this.shapes);
  2717. this.renderItems(this.labels);
  2718. this.addEvents();
  2719. ControllableMixin.render.call(this);
  2720. };
  2721. /**
  2722. * Set the annotation's visibility.
  2723. * @private
  2724. * @param {boolean} [visible]
  2725. * Whether to show or hide an annotation. If the param is omitted, the
  2726. * annotation's visibility is toggled.
  2727. */
  2728. Annotation.prototype.setVisibility = function (visible) {
  2729. var options = this.options,
  2730. visibility = pick(visible, !options.visible);
  2731. this.graphic.attr('visibility', visibility ? 'visible' : 'hidden');
  2732. if (!visibility) {
  2733. this.setControlPointsVisibility(false);
  2734. }
  2735. options.visible = visibility;
  2736. };
  2737. Annotation.prototype.setControlPointsVisibility = function (visible) {
  2738. var setItemControlPointsVisibility = function (item) {
  2739. item.setControlPointsVisibility(visible);
  2740. };
  2741. ControllableMixin.setControlPointsVisibility.call(this, visible);
  2742. this.shapes.forEach(setItemControlPointsVisibility);
  2743. this.labels.forEach(setItemControlPointsVisibility);
  2744. };
  2745. /**
  2746. * Destroy the annotation. This function does not touch the chart
  2747. * that the annotation belongs to (all annotations are kept in
  2748. * the chart.annotations array) - it is recommended to use
  2749. * {@link Highcharts.Chart#removeAnnotation} instead.
  2750. * @private
  2751. */
  2752. Annotation.prototype.destroy = function () {
  2753. var chart = this.chart,
  2754. destroyItem = function (item) {
  2755. item.destroy();
  2756. };
  2757. this.labels.forEach(destroyItem);
  2758. this.shapes.forEach(destroyItem);
  2759. this.clipXAxis = null;
  2760. this.clipYAxis = null;
  2761. erase(chart.labelCollectors, this.labelCollector);
  2762. EventEmitterMixin.destroy.call(this);
  2763. ControllableMixin.destroy.call(this);
  2764. destroyObjectProperties(this, chart);
  2765. };
  2766. /**
  2767. * See {@link Highcharts.Chart#removeAnnotation}.
  2768. * @private
  2769. */
  2770. Annotation.prototype.remove = function () {
  2771. // Let chart.update() remove annoations on demand
  2772. return this.chart.removeAnnotation(this);
  2773. };
  2774. /**
  2775. * Updates an annotation.
  2776. *
  2777. * @function Highcharts.Annotation#update
  2778. *
  2779. * @param {Partial<Highcharts.AnnotationsOptions>} userOptions
  2780. * New user options for the annotation.
  2781. *
  2782. * @return {void}
  2783. */
  2784. Annotation.prototype.update = function (userOptions, redraw) {
  2785. var chart = this.chart,
  2786. labelsAndShapes = this.getLabelsAndShapesOptions(this.userOptions,
  2787. userOptions),
  2788. userOptionsIndex = chart.annotations.indexOf(this),
  2789. options = merge(true,
  2790. this.userOptions,
  2791. userOptions);
  2792. options.labels = labelsAndShapes.labels;
  2793. options.shapes = labelsAndShapes.shapes;
  2794. this.destroy();
  2795. this.constructor(chart, options);
  2796. // Update options in chart options, used in exporting (#9767):
  2797. chart.options.annotations[userOptionsIndex] = options;
  2798. this.isUpdating = true;
  2799. if (pick(redraw, true)) {
  2800. chart.redraw();
  2801. }
  2802. fireEvent(this, 'afterUpdate');
  2803. this.isUpdating = false;
  2804. };
  2805. /* *************************************************************
  2806. * ITEM SECTION
  2807. * Contains methods for handling a single item in an annotation
  2808. **************************************************************** */
  2809. /**
  2810. * Initialisation of a single shape
  2811. * @private
  2812. * @param {Object} shapeOptions - a confg object for a single shape
  2813. */
  2814. Annotation.prototype.initShape = function (shapeOptions, index) {
  2815. var options = merge(this.options.shapeOptions, {
  2816. controlPointOptions: this.options.controlPointOptions
  2817. },
  2818. shapeOptions),
  2819. shape = new Annotation.shapesMap[options.type](this,
  2820. options,
  2821. index);
  2822. shape.itemType = 'shape';
  2823. this.shapes.push(shape);
  2824. return shape;
  2825. };
  2826. /**
  2827. * Initialisation of a single label
  2828. * @private
  2829. */
  2830. Annotation.prototype.initLabel = function (labelOptions, index) {
  2831. var options = merge(this.options.labelOptions, {
  2832. controlPointOptions: this.options.controlPointOptions
  2833. },
  2834. labelOptions),
  2835. label = new ControllableLabel(this,
  2836. options,
  2837. index);
  2838. label.itemType = 'label';
  2839. this.labels.push(label);
  2840. return label;
  2841. };
  2842. /**
  2843. * Redraw a single item.
  2844. * @private
  2845. * @param {Annotation.Label|Annotation.Shape} item
  2846. * @param {boolean} [animation]
  2847. */
  2848. Annotation.prototype.redrawItem = function (item, animation) {
  2849. item.linkPoints();
  2850. if (!item.shouldBeDrawn()) {
  2851. this.destroyItem(item);
  2852. }
  2853. else {
  2854. if (!item.graphic) {
  2855. this.renderItem(item);
  2856. }
  2857. item.redraw(pick(animation, true) && item.graphic.placed);
  2858. if (item.points.length) {
  2859. this.adjustVisibility(item);
  2860. }
  2861. }
  2862. };
  2863. /**
  2864. * Hide or show annotaiton attached to points.
  2865. * @private
  2866. * @param {Annotation.Label|Annotation.Shape} item
  2867. */
  2868. Annotation.prototype.adjustVisibility = function (item) {
  2869. var hasVisiblePoints = false,
  2870. label = item.graphic;
  2871. item.points.forEach(function (point) {
  2872. if (point.series.visible !== false &&
  2873. point.visible !== false) {
  2874. hasVisiblePoints = true;
  2875. }
  2876. });
  2877. if (!hasVisiblePoints) {
  2878. label.hide();
  2879. }
  2880. else if (label.visibility === 'hidden') {
  2881. label.show();
  2882. }
  2883. };
  2884. /**
  2885. * Destroy a single item.
  2886. * @private
  2887. * @param {Annotation.Label|Annotation.Shape} item
  2888. */
  2889. Annotation.prototype.destroyItem = function (item) {
  2890. // erase from shapes or labels array
  2891. erase(this[item.itemType + 's'], item);
  2892. item.destroy();
  2893. };
  2894. /**
  2895. * @private
  2896. */
  2897. Annotation.prototype.renderItem = function (item) {
  2898. item.render(item.itemType === 'label' ?
  2899. this.labelsGroup :
  2900. this.shapesGroup);
  2901. };
  2902. /**
  2903. * @private
  2904. */
  2905. Annotation.ControlPoint = ControlPoint;
  2906. /**
  2907. * @private
  2908. */
  2909. Annotation.MockPoint = MockPoint;
  2910. /**
  2911. * An object uses for mapping between a shape type and a constructor.
  2912. * To add a new shape type extend this object with type name as a key
  2913. * and a constructor as its value.
  2914. */
  2915. Annotation.shapesMap = {
  2916. 'rect': ControllableRect,
  2917. 'circle': ControllableCircle,
  2918. 'path': ControllablePath,
  2919. 'image': ControllableImage
  2920. };
  2921. /**
  2922. * @private
  2923. */
  2924. Annotation.types = {};
  2925. return Annotation;
  2926. }());
  2927. merge(true, Annotation.prototype, ControllableMixin, EventEmitterMixin,
  2928. // restore original Annotation implementation after mixin overwrite
  2929. merge(Annotation.prototype,
  2930. /** @lends Highcharts.Annotation# */
  2931. {
  2932. /**
  2933. * List of events for `annotation.options.events` that should not be
  2934. * added to `annotation.graphic` but to the `annotation`.
  2935. *
  2936. * @private
  2937. * @type {Array<string>}
  2938. */
  2939. nonDOMEvents: ['add', 'afterUpdate', 'drag', 'remove'],
  2940. /**
  2941. * A basic type of an annotation. It allows to add custom labels
  2942. * or shapes. The items can be tied to points, axis coordinates
  2943. * or chart pixel coordinates.
  2944. *
  2945. * @sample highcharts/annotations/basic/
  2946. * Basic annotations
  2947. * @sample highcharts/demo/annotations/
  2948. * Advanced annotations
  2949. * @sample highcharts/css/annotations
  2950. * Styled mode
  2951. * @sample highcharts/annotations-advanced/controllable
  2952. * Controllable items
  2953. * @sample {highstock} stock/annotations/fibonacci-retracements
  2954. * Custom annotation, Fibonacci retracement
  2955. *
  2956. * @type {Array<*>}
  2957. * @since 6.0.0
  2958. * @requires modules/annotations
  2959. * @optionparent annotations
  2960. *
  2961. * @private
  2962. */
  2963. defaultOptions: {
  2964. /**
  2965. * Sets an ID for an annotation. Can be user later when
  2966. * removing an annotation in [Chart#removeAnnotation(id)](
  2967. * /class-reference/Highcharts.Chart#removeAnnotation) method.
  2968. *
  2969. * @type {number|string}
  2970. * @apioption annotations.id
  2971. */
  2972. /**
  2973. * Whether the annotation is visible.
  2974. *
  2975. * @sample highcharts/annotations/visible/
  2976. * Set annotation visibility
  2977. */
  2978. visible: true,
  2979. /**
  2980. * Enable or disable the initial animation when a series is
  2981. * displayed for the `annotation`. The animation can also be set
  2982. * as a configuration object. Please note that this option only
  2983. * applies to the initial animation.
  2984. * For other animations, see [chart.animation](#chart.animation)
  2985. * and the animation parameter under the API methods.
  2986. * The following properties are supported:
  2987. *
  2988. * - `defer`: The animation delay time in milliseconds.
  2989. *
  2990. * @sample {highcharts} highcharts/annotations/defer/
  2991. * Animation defer settings
  2992. * @type {boolean|Partial<Highcharts.AnimationOptionsObject>}
  2993. * @since 8.2.0
  2994. * @apioption annotations.animation
  2995. */
  2996. animation: {},
  2997. /**
  2998. * The animation delay time in milliseconds.
  2999. * Set to `0` renders annotation immediately.
  3000. * As `undefined` inherits defer time from the [series.animation.defer](#plotOptions.series.animation.defer).
  3001. *
  3002. * @type {number}
  3003. * @since 8.2.0
  3004. * @apioption annotations.animation.defer
  3005. */
  3006. /**
  3007. * Allow an annotation to be draggable by a user. Possible
  3008. * values are `'x'`, `'xy'`, `'y'` and `''` (disabled).
  3009. *
  3010. * @sample highcharts/annotations/draggable/
  3011. * Annotations draggable: 'xy'
  3012. *
  3013. * @type {Highcharts.AnnotationDraggableValue}
  3014. */
  3015. draggable: 'xy',
  3016. /**
  3017. * Options for annotation's labels. Each label inherits options
  3018. * from the labelOptions object. An option from the labelOptions
  3019. * can be overwritten by config for a specific label.
  3020. *
  3021. * @requires modules/annotations
  3022. */
  3023. labelOptions: {
  3024. /**
  3025. * The alignment of the annotation's label. If right,
  3026. * the right side of the label should be touching the point.
  3027. *
  3028. * @sample highcharts/annotations/label-position/
  3029. * Set labels position
  3030. *
  3031. * @type {Highcharts.AlignValue}
  3032. */
  3033. align: 'center',
  3034. /**
  3035. * Whether to allow the annotation's labels to overlap.
  3036. * To make the labels less sensitive for overlapping,
  3037. * the can be set to 0.
  3038. *
  3039. * @sample highcharts/annotations/tooltip-like/
  3040. * Hide overlapping labels
  3041. */
  3042. allowOverlap: false,
  3043. /**
  3044. * The background color or gradient for the annotation's
  3045. * label.
  3046. *
  3047. * @sample highcharts/annotations/label-presentation/
  3048. * Set labels graphic options
  3049. *
  3050. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3051. */
  3052. backgroundColor: 'rgba(0, 0, 0, 0.75)',
  3053. /**
  3054. * The border color for the annotation's label.
  3055. *
  3056. * @sample highcharts/annotations/label-presentation/
  3057. * Set labels graphic options
  3058. *
  3059. * @type {Highcharts.ColorString}
  3060. */
  3061. borderColor: 'black',
  3062. /**
  3063. * The border radius in pixels for the annotaiton's label.
  3064. *
  3065. * @sample highcharts/annotations/label-presentation/
  3066. * Set labels graphic options
  3067. */
  3068. borderRadius: 3,
  3069. /**
  3070. * The border width in pixels for the annotation's label
  3071. *
  3072. * @sample highcharts/annotations/label-presentation/
  3073. * Set labels graphic options
  3074. */
  3075. borderWidth: 1,
  3076. /**
  3077. * A class name for styling by CSS.
  3078. *
  3079. * @sample highcharts/css/annotations
  3080. * Styled mode annotations
  3081. *
  3082. * @since 6.0.5
  3083. */
  3084. className: '',
  3085. /**
  3086. * Whether to hide the annotation's label
  3087. * that is outside the plot area.
  3088. *
  3089. * @sample highcharts/annotations/label-crop-overflow/
  3090. * Crop or justify labels
  3091. */
  3092. crop: false,
  3093. /**
  3094. * The label's pixel distance from the point.
  3095. *
  3096. * @sample highcharts/annotations/label-position/
  3097. * Set labels position
  3098. *
  3099. * @type {number}
  3100. * @apioption annotations.labelOptions.distance
  3101. */
  3102. /**
  3103. * A
  3104. * [format](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting)
  3105. * string for the data label.
  3106. *
  3107. * @see [plotOptions.series.dataLabels.format](plotOptions.series.dataLabels.format.html)
  3108. *
  3109. * @sample highcharts/annotations/label-text/
  3110. * Set labels text
  3111. *
  3112. * @type {string}
  3113. * @apioption annotations.labelOptions.format
  3114. */
  3115. /**
  3116. * Alias for the format option.
  3117. *
  3118. * @see [format](annotations.labelOptions.format.html)
  3119. *
  3120. * @sample highcharts/annotations/label-text/
  3121. * Set labels text
  3122. *
  3123. * @type {string}
  3124. * @apioption annotations.labelOptions.text
  3125. */
  3126. /**
  3127. * Callback JavaScript function to format the annotation's
  3128. * label. Note that if a `format` or `text` are defined,
  3129. * the format or text take precedence and the formatter is
  3130. * ignored. `This` refers to a point object.
  3131. *
  3132. * @sample highcharts/annotations/label-text/
  3133. * Set labels text
  3134. *
  3135. * @type {Highcharts.FormatterCallbackFunction<Highcharts.Point>}
  3136. * @default function () { return defined(this.y) ? this.y : 'Annotation label'; }
  3137. */
  3138. formatter: function () {
  3139. return defined(this.y) ? this.y : 'Annotation label';
  3140. },
  3141. /**
  3142. * Whether the annotation is visible in the exported data
  3143. * table.
  3144. *
  3145. * @sample highcharts/annotations/include-in-data-export/
  3146. * Do not include in the data export
  3147. *
  3148. * @since 8.2.0
  3149. * @requires modules/export-data
  3150. */
  3151. includeInDataExport: true,
  3152. /**
  3153. * How to handle the annotation's label that flow outside
  3154. * the plot area. The justify option aligns the label inside
  3155. * the plot area.
  3156. *
  3157. * @sample highcharts/annotations/label-crop-overflow/
  3158. * Crop or justify labels
  3159. *
  3160. * @validvalue ["allow", "justify"]
  3161. */
  3162. overflow: 'justify',
  3163. /**
  3164. * When either the borderWidth or the backgroundColor is
  3165. * set, this is the padding within the box.
  3166. *
  3167. * @sample highcharts/annotations/label-presentation/
  3168. * Set labels graphic options
  3169. */
  3170. padding: 5,
  3171. /**
  3172. * The shadow of the box. The shadow can be an object
  3173. * configuration containing `color`, `offsetX`, `offsetY`,
  3174. * `opacity` and `width`.
  3175. *
  3176. * @sample highcharts/annotations/label-presentation/
  3177. * Set labels graphic options
  3178. *
  3179. * @type {boolean|Highcharts.ShadowOptionsObject}
  3180. */
  3181. shadow: false,
  3182. /**
  3183. * The name of a symbol to use for the border around the
  3184. * label. Symbols are predefined functions on the Renderer
  3185. * object.
  3186. *
  3187. * @sample highcharts/annotations/shapes/
  3188. * Available shapes for labels
  3189. */
  3190. shape: 'callout',
  3191. /**
  3192. * Styles for the annotation's label.
  3193. *
  3194. * @see [plotOptions.series.dataLabels.style](plotOptions.series.dataLabels.style.html)
  3195. *
  3196. * @sample highcharts/annotations/label-presentation/
  3197. * Set labels graphic options
  3198. *
  3199. * @type {Highcharts.CSSObject}
  3200. */
  3201. style: {
  3202. /** @ignore */
  3203. fontSize: '11px',
  3204. /** @ignore */
  3205. fontWeight: 'normal',
  3206. /** @ignore */
  3207. color: 'contrast'
  3208. },
  3209. /**
  3210. * Whether to [use HTML](https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting#html)
  3211. * to render the annotation's label.
  3212. */
  3213. useHTML: false,
  3214. /**
  3215. * The vertical alignment of the annotation's label.
  3216. *
  3217. * @sample highcharts/annotations/label-position/
  3218. * Set labels position
  3219. *
  3220. * @type {Highcharts.VerticalAlignValue}
  3221. */
  3222. verticalAlign: 'bottom',
  3223. /**
  3224. * The x position offset of the label relative to the point.
  3225. * Note that if a `distance` is defined, the distance takes
  3226. * precedence over `x` and `y` options.
  3227. *
  3228. * @sample highcharts/annotations/label-position/
  3229. * Set labels position
  3230. */
  3231. x: 0,
  3232. /**
  3233. * The y position offset of the label relative to the point.
  3234. * Note that if a `distance` is defined, the distance takes
  3235. * precedence over `x` and `y` options.
  3236. *
  3237. * @sample highcharts/annotations/label-position/
  3238. * Set labels position
  3239. */
  3240. y: -16
  3241. },
  3242. /**
  3243. * An array of labels for the annotation. For options that apply
  3244. * to multiple labels, they can be added to the
  3245. * [labelOptions](annotations.labelOptions.html).
  3246. *
  3247. * @type {Array<*>}
  3248. * @extends annotations.labelOptions
  3249. * @apioption annotations.labels
  3250. */
  3251. /**
  3252. * This option defines the point to which the label will be
  3253. * connected. It can be either the point which exists in the
  3254. * series - it is referenced by the point's id - or a new point
  3255. * with defined x, y properties and optionally axes.
  3256. *
  3257. * @sample highcharts/annotations/mock-point/
  3258. * Attach annotation to a mock point
  3259. *
  3260. * @declare Highcharts.AnnotationMockPointOptionsObject
  3261. * @type {string|*}
  3262. * @requires modules/annotations
  3263. * @apioption annotations.labels.point
  3264. */
  3265. /**
  3266. * The x position of the point. Units can be either in axis
  3267. * or chart pixel coordinates.
  3268. *
  3269. * @type {number}
  3270. * @apioption annotations.labels.point.x
  3271. */
  3272. /**
  3273. * The y position of the point. Units can be either in axis
  3274. * or chart pixel coordinates.
  3275. *
  3276. * @type {number}
  3277. * @apioption annotations.labels.point.y
  3278. */
  3279. /**
  3280. * This number defines which xAxis the point is connected to.
  3281. * It refers to either the axis id or the index of the axis in
  3282. * the xAxis array. If the option is not configured or the axis
  3283. * is not found the point's x coordinate refers to the chart
  3284. * pixels.
  3285. *
  3286. * @type {number|string|null}
  3287. * @apioption annotations.labels.point.xAxis
  3288. */
  3289. /**
  3290. * This number defines which yAxis the point is connected to.
  3291. * It refers to either the axis id or the index of the axis in
  3292. * the yAxis array. If the option is not configured or the axis
  3293. * is not found the point's y coordinate refers to the chart
  3294. * pixels.
  3295. *
  3296. * @type {number|string|null}
  3297. * @apioption annotations.labels.point.yAxis
  3298. */
  3299. /**
  3300. * An array of shapes for the annotation. For options that apply
  3301. * to multiple shapes, then can be added to the
  3302. * [shapeOptions](annotations.shapeOptions.html).
  3303. *
  3304. * @type {Array<*>}
  3305. * @extends annotations.shapeOptions
  3306. * @apioption annotations.shapes
  3307. */
  3308. /**
  3309. * This option defines the point to which the shape will be
  3310. * connected. It can be either the point which exists in the
  3311. * series - it is referenced by the point's id - or a new point
  3312. * with defined x, y properties and optionally axes.
  3313. *
  3314. * @declare Highcharts.AnnotationMockPointOptionsObject
  3315. * @type {string|Highcharts.AnnotationMockPointOptionsObject}
  3316. * @extends annotations.labels.point
  3317. * @apioption annotations.shapes.point
  3318. */
  3319. /**
  3320. * An array of points for the shape. This option is available
  3321. * for shapes which can use multiple points such as path. A
  3322. * point can be either a point object or a point's id.
  3323. *
  3324. * @see [annotations.shapes.point](annotations.shapes.point.html)
  3325. *
  3326. * @declare Highcharts.AnnotationMockPointOptionsObject
  3327. * @type {Array<string|*>}
  3328. * @extends annotations.labels.point
  3329. * @apioption annotations.shapes.points
  3330. */
  3331. /**
  3332. * The URL for an image to use as the annotation shape. Note,
  3333. * type has to be set to `'image'`.
  3334. *
  3335. * @see [annotations.shapes.type](annotations.shapes.type)
  3336. * @sample highcharts/annotations/shape-src/
  3337. * Define a marker image url for annotations
  3338. *
  3339. * @type {string}
  3340. * @apioption annotations.shapes.src
  3341. */
  3342. /**
  3343. * Id of the marker which will be drawn at the final vertex of
  3344. * the path. Custom markers can be defined in defs property.
  3345. *
  3346. * @see [defs.markers](defs.markers.html)
  3347. *
  3348. * @sample highcharts/annotations/custom-markers/
  3349. * Define a custom marker for annotations
  3350. *
  3351. * @type {string}
  3352. * @apioption annotations.shapes.markerEnd
  3353. */
  3354. /**
  3355. * Id of the marker which will be drawn at the first vertex of
  3356. * the path. Custom markers can be defined in defs property.
  3357. *
  3358. * @see [defs.markers](defs.markers.html)
  3359. *
  3360. * @sample {highcharts} highcharts/annotations/custom-markers/
  3361. * Define a custom marker for annotations
  3362. *
  3363. * @type {string}
  3364. * @apioption annotations.shapes.markerStart
  3365. */
  3366. /**
  3367. * Options for annotation's shapes. Each shape inherits options
  3368. * from the shapeOptions object. An option from the shapeOptions
  3369. * can be overwritten by config for a specific shape.
  3370. *
  3371. * @requires modules/annotations
  3372. */
  3373. shapeOptions: {
  3374. /**
  3375. * The width of the shape.
  3376. *
  3377. * @sample highcharts/annotations/shape/
  3378. * Basic shape annotation
  3379. *
  3380. * @type {number}
  3381. * @apioption annotations.shapeOptions.width
  3382. **/
  3383. /**
  3384. * The height of the shape.
  3385. *
  3386. * @sample highcharts/annotations/shape/
  3387. * Basic shape annotation
  3388. *
  3389. * @type {number}
  3390. * @apioption annotations.shapeOptions.height
  3391. */
  3392. /**
  3393. * The type of the shape, e.g. circle or rectangle.
  3394. *
  3395. * @sample highcharts/annotations/shape/
  3396. * Basic shape annotation
  3397. *
  3398. * @type {string}
  3399. * @default rect
  3400. * @apioption annotations.shapeOptions.type
  3401. */
  3402. /**
  3403. * The URL for an image to use as the annotation shape.
  3404. * Note, type has to be set to `'image'`.
  3405. *
  3406. * @see [annotations.shapeOptions.type](annotations.shapeOptions.type)
  3407. * @sample highcharts/annotations/shape-src/
  3408. * Define a marker image url for annotations
  3409. *
  3410. * @type {string}
  3411. * @apioption annotations.shapeOptions.src
  3412. */
  3413. /**
  3414. * Name of the dash style to use for the shape's stroke.
  3415. *
  3416. * @sample {highcharts} highcharts/plotoptions/series-dashstyle-all/
  3417. * Possible values demonstrated
  3418. *
  3419. * @type {Highcharts.DashStyleValue}
  3420. * @apioption annotations.shapeOptions.dashStyle
  3421. */
  3422. /**
  3423. * The color of the shape's stroke.
  3424. *
  3425. * @sample highcharts/annotations/shape/
  3426. * Basic shape annotation
  3427. *
  3428. * @type {Highcharts.ColorString}
  3429. */
  3430. stroke: 'rgba(0, 0, 0, 0.75)',
  3431. /**
  3432. * The pixel stroke width of the shape.
  3433. *
  3434. * @sample highcharts/annotations/shape/
  3435. * Basic shape annotation
  3436. */
  3437. strokeWidth: 1,
  3438. /**
  3439. * The color of the shape's fill.
  3440. *
  3441. * @sample highcharts/annotations/shape/
  3442. * Basic shape annotation
  3443. *
  3444. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3445. */
  3446. fill: 'rgba(0, 0, 0, 0.75)',
  3447. /**
  3448. * The radius of the shape.
  3449. *
  3450. * @sample highcharts/annotations/shape/
  3451. * Basic shape annotation
  3452. */
  3453. r: 0,
  3454. /**
  3455. * Defines additional snapping area around an annotation
  3456. * making this annotation to focus. Defined in pixels.
  3457. */
  3458. snap: 2
  3459. },
  3460. /**
  3461. * Options for annotation's control points. Each control point
  3462. * inherits options from controlPointOptions object.
  3463. * Options from the controlPointOptions can be overwritten
  3464. * by options in a specific control point.
  3465. *
  3466. * @declare Highcharts.AnnotationControlPointOptionsObject
  3467. * @requires modules/annotations
  3468. * @apioption annotations.controlPointOptions
  3469. */
  3470. controlPointOptions: {
  3471. /**
  3472. * @type {Highcharts.AnnotationControlPointPositionerFunction}
  3473. * @apioption annotations.controlPointOptions.positioner
  3474. */
  3475. symbol: 'circle',
  3476. width: 10,
  3477. height: 10,
  3478. style: {
  3479. stroke: 'black',
  3480. 'stroke-width': 2,
  3481. fill: 'white'
  3482. },
  3483. visible: false,
  3484. events: {}
  3485. },
  3486. /**
  3487. * Event callback when annotation is added to the chart.
  3488. *
  3489. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3490. * @since 7.1.0
  3491. * @apioption annotations.events.add
  3492. */
  3493. /**
  3494. * Event callback when annotation is updated (e.g. drag and
  3495. * droppped or resized by control points).
  3496. *
  3497. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3498. * @since 7.1.0
  3499. * @apioption annotations.events.afterUpdate
  3500. */
  3501. /**
  3502. * Event callback when annotation is removed from the chart.
  3503. *
  3504. * @type {Highcharts.EventCallbackFunction<Highcharts.Annotation>}
  3505. * @since 7.1.0
  3506. * @apioption annotations.events.remove
  3507. */
  3508. /**
  3509. * Events available in annotations.
  3510. *
  3511. * @requires modules/annotations
  3512. */
  3513. events: {},
  3514. /**
  3515. * The Z index of the annotation.
  3516. */
  3517. zIndex: 6
  3518. }
  3519. }));
  3520. H.extendAnnotation = function (Constructor, BaseConstructor, prototype, defaultOptions) {
  3521. BaseConstructor = BaseConstructor || Annotation;
  3522. merge(true, Constructor.prototype, BaseConstructor.prototype, prototype);
  3523. Constructor.prototype.defaultOptions = merge(Constructor.prototype.defaultOptions, defaultOptions || {});
  3524. };
  3525. /* *********************************************************************
  3526. *
  3527. * EXTENDING CHART PROTOTYPE
  3528. *
  3529. ******************************************************************** */
  3530. extend(chartProto, /** @lends Highcharts.Chart# */ {
  3531. initAnnotation: function (userOptions) {
  3532. var Constructor = Annotation.types[userOptions.type] || Annotation,
  3533. annotation = new Constructor(this,
  3534. userOptions);
  3535. this.annotations.push(annotation);
  3536. return annotation;
  3537. },
  3538. /**
  3539. * Add an annotation to the chart after render time.
  3540. *
  3541. * @param {Highcharts.AnnotationsOptions} options
  3542. * The annotation options for the new, detailed annotation.
  3543. * @param {boolean} [redraw]
  3544. *
  3545. * @return {Highcharts.Annotation} - The newly generated annotation.
  3546. */
  3547. addAnnotation: function (userOptions, redraw) {
  3548. var annotation = this.initAnnotation(userOptions);
  3549. this.options.annotations.push(annotation.options);
  3550. if (pick(redraw, true)) {
  3551. annotation.redraw();
  3552. annotation.graphic.attr({
  3553. opacity: 1
  3554. });
  3555. }
  3556. return annotation;
  3557. },
  3558. /**
  3559. * Remove an annotation from the chart.
  3560. *
  3561. * @param {number|string|Highcharts.Annotation} idOrAnnotation
  3562. * The annotation's id or direct annotation object.
  3563. */
  3564. removeAnnotation: function (idOrAnnotation) {
  3565. var annotations = this.annotations,
  3566. annotation = idOrAnnotation.coll === 'annotations' ?
  3567. idOrAnnotation :
  3568. find(annotations,
  3569. function (annotation) {
  3570. return annotation.options.id === idOrAnnotation;
  3571. });
  3572. if (annotation) {
  3573. fireEvent(annotation, 'remove');
  3574. erase(this.options.annotations, annotation.options);
  3575. erase(annotations, annotation);
  3576. annotation.destroy();
  3577. }
  3578. },
  3579. drawAnnotations: function () {
  3580. this.plotBoxClip.attr(this.plotBox);
  3581. this.annotations.forEach(function (annotation) {
  3582. annotation.redraw();
  3583. annotation.graphic.animate({
  3584. opacity: 1
  3585. }, annotation.animationConfig);
  3586. });
  3587. }
  3588. });
  3589. // Let chart.update() update annotations
  3590. chartProto.collectionsWithUpdate.push('annotations');
  3591. // Let chart.update() create annoations on demand
  3592. chartProto.collectionsWithInit.annotations = [chartProto.addAnnotation];
  3593. chartProto.callbacks.push(function (chart) {
  3594. chart.annotations = [];
  3595. if (!chart.options.annotations) {
  3596. chart.options.annotations = [];
  3597. }
  3598. chart.plotBoxClip = this.renderer.clipRect(this.plotBox);
  3599. chart.controlPointsGroup = chart.renderer
  3600. .g('control-points')
  3601. .attr({ zIndex: 99 })
  3602. .clip(chart.plotBoxClip)
  3603. .add();
  3604. chart.options.annotations.forEach(function (annotationOptions, i) {
  3605. var annotation = chart.initAnnotation(annotationOptions);
  3606. chart.options.annotations[i] = annotation.options;
  3607. });
  3608. chart.drawAnnotations();
  3609. addEvent(chart, 'redraw', chart.drawAnnotations);
  3610. addEvent(chart, 'destroy', function () {
  3611. chart.plotBoxClip.destroy();
  3612. chart.controlPointsGroup.destroy();
  3613. });
  3614. addEvent(chart, 'exportData', function (event) {
  3615. var _a,
  3616. _b,
  3617. _c,
  3618. _d,
  3619. _e,
  3620. _f,
  3621. _g,
  3622. _h;
  3623. var annotations = chart.annotations,
  3624. csvColumnHeaderFormatter = ((this.options.exporting &&
  3625. this.options.exporting.csv) ||
  3626. {}).columnHeaderFormatter,
  3627. // If second row doesn't have xValues
  3628. // then it is a title row thus multiple level header is in use.
  3629. multiLevelHeaders = !event.dataRows[1].xValues,
  3630. annotationHeader = (_b = (_a = chart.options.lang) === null || _a === void 0 ? void 0 : _a.exportData) === null || _b === void 0 ? void 0 : _b.annotationHeader,
  3631. columnHeaderFormatter = function (index) {
  3632. var s;
  3633. if (csvColumnHeaderFormatter) {
  3634. s = csvColumnHeaderFormatter(index);
  3635. if (s !== false) {
  3636. return s;
  3637. }
  3638. }
  3639. s = annotationHeader + ' ' + index;
  3640. if (multiLevelHeaders) {
  3641. return {
  3642. columnTitle: s,
  3643. topLevelColumnTitle: s
  3644. };
  3645. }
  3646. return s;
  3647. }, startRowLength = event.dataRows[0].length, annotationSeparator = (_e = (_d = (_c = chart.options.exporting) === null || _c === void 0 ? void 0 : _c.csv) === null || _d === void 0 ? void 0 : _d.annotations) === null || _e === void 0 ? void 0 : _e.itemDelimiter, joinAnnotations = (_h = (_g = (_f = chart.options.exporting) === null || _f === void 0 ? void 0 : _f.csv) === null || _g === void 0 ? void 0 : _g.annotations) === null || _h === void 0 ? void 0 : _h.join;
  3648. annotations.forEach(function (annotation) {
  3649. if (annotation.options.labelOptions.includeInDataExport) {
  3650. annotation.labels.forEach(function (label) {
  3651. if (label.options.text) {
  3652. var annotationText_1 = label.options.text;
  3653. label.points.forEach(function (points) {
  3654. var annotationX = points.x,
  3655. xAxisIndex = points.series.xAxis ?
  3656. points.series.xAxis.options.index :
  3657. -1;
  3658. var wasAdded = false;
  3659. // Annotation not connected to any xAxis -
  3660. // add new row.
  3661. if (xAxisIndex === -1) {
  3662. var n = event.dataRows[0].length,
  3663. newRow = new Array(n);
  3664. for (var i = 0; i < n; ++i) {
  3665. newRow[i] = '';
  3666. }
  3667. newRow.push(annotationText_1);
  3668. newRow.xValues = [];
  3669. newRow.xValues[xAxisIndex] = annotationX;
  3670. event.dataRows.push(newRow);
  3671. wasAdded = true;
  3672. }
  3673. // Annotation placed on a exported data point
  3674. // - add new column
  3675. if (!wasAdded) {
  3676. event.dataRows.forEach(function (row, rowIndex) {
  3677. if (!wasAdded &&
  3678. row.xValues &&
  3679. xAxisIndex !== void 0 &&
  3680. annotationX === row.xValues[xAxisIndex]) {
  3681. if (joinAnnotations &&
  3682. row.length > startRowLength) {
  3683. row[row.length - 1] +=
  3684. annotationSeparator + annotationText_1;
  3685. }
  3686. else {
  3687. row.push(annotationText_1);
  3688. }
  3689. wasAdded = true;
  3690. }
  3691. });
  3692. }
  3693. // Annotation not placed on any exported data point,
  3694. // but connected to the xAxis - add new row
  3695. if (!wasAdded) {
  3696. var n = event.dataRows[0].length,
  3697. newRow = new Array(n);
  3698. for (var i = 0; i < n; ++i) {
  3699. newRow[i] = '';
  3700. }
  3701. newRow[0] = annotationX;
  3702. newRow.push(annotationText_1);
  3703. newRow.xValues = [];
  3704. if (xAxisIndex !== void 0) {
  3705. newRow.xValues[xAxisIndex] = annotationX;
  3706. }
  3707. event.dataRows.push(newRow);
  3708. }
  3709. });
  3710. }
  3711. });
  3712. }
  3713. });
  3714. var maxRowLen = 0;
  3715. event.dataRows.forEach(function (row) {
  3716. maxRowLen = Math.max(maxRowLen, row.length);
  3717. });
  3718. var newRows = maxRowLen - event.dataRows[0].length;
  3719. for (var i = 0; i < newRows; i++) {
  3720. var header = columnHeaderFormatter(i + 1);
  3721. if (multiLevelHeaders) {
  3722. event.dataRows[0].push(header.topLevelColumnTitle);
  3723. event.dataRows[1].push(header.columnTitle);
  3724. }
  3725. else {
  3726. event.dataRows[0].push(header);
  3727. }
  3728. }
  3729. });
  3730. });
  3731. wrap(Pointer.prototype, 'onContainerMouseDown', function (proceed) {
  3732. if (!this.chart.hasDraggedAnnotation) {
  3733. proceed.apply(this, Array.prototype.slice.call(arguments, 1));
  3734. }
  3735. });
  3736. H.Annotation = Annotation;
  3737. return Annotation;
  3738. });
  3739. _registerModule(_modules, 'Mixins/Navigation.js', [], function () {
  3740. /**
  3741. *
  3742. * (c) 2010-2018 Paweł Fus
  3743. *
  3744. * License: www.highcharts.com/license
  3745. *
  3746. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3747. *
  3748. * */
  3749. var chartNavigation = {
  3750. /**
  3751. * Initializes `chart.navigation` object which delegates `update()` methods
  3752. * to all other common classes (used in exporting and navigationBindings).
  3753. *
  3754. * @private
  3755. * @param {Highcharts.Chart} chart
  3756. * The chart instance.
  3757. * @return {void}
  3758. */
  3759. initUpdate: function (chart) {
  3760. if (!chart.navigation) {
  3761. chart.navigation = {
  3762. updates: [],
  3763. update: function (options,
  3764. redraw) {
  3765. this.updates.forEach(function (updateConfig) {
  3766. updateConfig.update.call(updateConfig.context,
  3767. options,
  3768. redraw);
  3769. });
  3770. }
  3771. };
  3772. }
  3773. },
  3774. /**
  3775. * Registers an `update()` method in the `chart.navigation` object.
  3776. *
  3777. * @private
  3778. * @param {Highcharts.ChartNavigationUpdateFunction} update
  3779. * The `update()` method that will be called in `chart.update()`.
  3780. * @param {Highcharts.Chart} chart
  3781. * The chart instance. `update()` will use that as a context
  3782. * (`this`).
  3783. * @return {void}
  3784. */
  3785. addUpdate: function (update, chart) {
  3786. if (!chart.navigation) {
  3787. this.initUpdate(chart);
  3788. }
  3789. chart.navigation.updates.push({
  3790. update: update,
  3791. context: chart
  3792. });
  3793. }
  3794. };
  3795. return chartNavigation;
  3796. });
  3797. _registerModule(_modules, 'Extensions/Annotations/NavigationBindings.js', [_modules['Extensions/Annotations/Annotations.js'], _modules['Core/Chart/Chart.js'], _modules['Mixins/Navigation.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Annotation, Chart, chartNavigationMixin, H, U) {
  3798. /* *
  3799. *
  3800. * (c) 2009-2017 Highsoft, Black Label
  3801. *
  3802. * License: www.highcharts.com/license
  3803. *
  3804. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3805. *
  3806. * */
  3807. var addEvent = U.addEvent,
  3808. attr = U.attr,
  3809. extend = U.extend,
  3810. format = U.format,
  3811. fireEvent = U.fireEvent,
  3812. isArray = U.isArray,
  3813. isFunction = U.isFunction,
  3814. isNumber = U.isNumber,
  3815. isObject = U.isObject,
  3816. merge = U.merge,
  3817. objectEach = U.objectEach,
  3818. pick = U.pick,
  3819. setOptions = U.setOptions;
  3820. /**
  3821. * A config object for navigation bindings in annotations.
  3822. *
  3823. * @interface Highcharts.NavigationBindingsOptionsObject
  3824. */ /**
  3825. * ClassName of the element for a binding.
  3826. * @name Highcharts.NavigationBindingsOptionsObject#className
  3827. * @type {string|undefined}
  3828. */ /**
  3829. * Last event to be fired after last step event.
  3830. * @name Highcharts.NavigationBindingsOptionsObject#end
  3831. * @type {Function|undefined}
  3832. */ /**
  3833. * Initial event, fired on a button click.
  3834. * @name Highcharts.NavigationBindingsOptionsObject#init
  3835. * @type {Function|undefined}
  3836. */ /**
  3837. * Event fired on first click on a chart.
  3838. * @name Highcharts.NavigationBindingsOptionsObject#start
  3839. * @type {Function|undefined}
  3840. */ /**
  3841. * Last event to be fired after last step event. Array of step events to be
  3842. * called sequentially after each user click.
  3843. * @name Highcharts.NavigationBindingsOptionsObject#steps
  3844. * @type {Array<Function>|undefined}
  3845. */
  3846. var doc = H.doc,
  3847. win = H.win,
  3848. PREFIX = 'highcharts-';
  3849. /* eslint-disable no-invalid-this, valid-jsdoc */
  3850. /**
  3851. * IE 9-11 polyfill for Element.closest():
  3852. * @private
  3853. */
  3854. function closestPolyfill(el, s) {
  3855. var ElementProto = win.Element.prototype,
  3856. elementMatches = ElementProto.matches ||
  3857. ElementProto.msMatchesSelector ||
  3858. ElementProto.webkitMatchesSelector,
  3859. ret = null;
  3860. if (ElementProto.closest) {
  3861. ret = ElementProto.closest.call(el, s);
  3862. }
  3863. else {
  3864. do {
  3865. if (elementMatches.call(el, s)) {
  3866. return el;
  3867. }
  3868. el = el.parentElement || el.parentNode;
  3869. } while (el !== null && el.nodeType === 1);
  3870. }
  3871. return ret;
  3872. }
  3873. /**
  3874. * @private
  3875. * @interface bindingsUtils
  3876. */
  3877. var bindingsUtils = {
  3878. /**
  3879. * Update size of background (rect) in some annotations: Measure,
  3880. Simple
  3881. * Rect.
  3882. *
  3883. * @private
  3884. * @function Highcharts.NavigationBindingsUtilsObject.updateRectSize
  3885. *
  3886. * @param {Highcharts.PointerEventObject} event
  3887. * Normalized browser event
  3888. *
  3889. * @param {Highcharts.Annotation} annotation
  3890. * Annotation to be updated
  3891. */
  3892. updateRectSize: function (event,
  3893. annotation) {
  3894. var chart = annotation.chart,
  3895. options = annotation.options.typeOptions,
  3896. coords = chart.pointer.getCoordinates(event),
  3897. width = coords.xAxis[0].value - options.point.x,
  3898. height = options.point.y - coords.yAxis[0].value;
  3899. annotation.update({
  3900. typeOptions: {
  3901. background: {
  3902. width: chart.inverted ? height : width,
  3903. height: chart.inverted ? width : height
  3904. }
  3905. }
  3906. });
  3907. },
  3908. /**
  3909. * Get field type according to value
  3910. *
  3911. * @private
  3912. * @function Highcharts.NavigationBindingsUtilsObject.getFieldType
  3913. *
  3914. * @param {'boolean'|'number'|'string'} value
  3915. * Atomic type (one of: string, number, boolean)
  3916. *
  3917. * @return {'checkbox'|'number'|'text'}
  3918. * Field type (one of: text, number, checkbox)
  3919. */
  3920. getFieldType: function (value) {
  3921. return {
  3922. 'string': 'text',
  3923. 'number': 'number',
  3924. 'boolean': 'checkbox'
  3925. }[typeof value];
  3926. }
  3927. };
  3928. /**
  3929. * @private
  3930. */
  3931. var NavigationBindings = /** @class */ (function () {
  3932. /* *
  3933. *
  3934. * Constructors
  3935. *
  3936. * */
  3937. function NavigationBindings(chart, options) {
  3938. this.boundClassNames = void 0;
  3939. this.selectedButton = void 0;
  3940. this.chart = chart;
  3941. this.options = options;
  3942. this.eventsToUnbind = [];
  3943. this.container = doc.getElementsByClassName(this.options.bindingsClassName || '');
  3944. }
  3945. // Private properties added by bindings:
  3946. // Active (selected) annotation that is editted through popup/forms
  3947. // activeAnnotation: Annotation
  3948. // Holder for current step, used on mouse move to update bound object
  3949. // mouseMoveEvent: function () {}
  3950. // Next event in `step` array to be called on chart's click
  3951. // nextEvent: function () {}
  3952. // Index in the `step` array of the current event
  3953. // stepIndex: 0
  3954. // Flag to determine if current binding has steps
  3955. // steps: true|false
  3956. // Bindings holder for all events
  3957. // selectedButton: {}
  3958. // Holder for user options, returned from `start` event, and passed on to
  3959. // `step`'s' and `end`.
  3960. // currentUserDetails: {}
  3961. /* *
  3962. *
  3963. * Functions
  3964. *
  3965. * */
  3966. /**
  3967. * Initi all events conencted to NavigationBindings.
  3968. *
  3969. * @private
  3970. * @function Highcharts.NavigationBindings#initEvents
  3971. */
  3972. NavigationBindings.prototype.initEvents = function () {
  3973. var navigation = this,
  3974. chart = navigation.chart,
  3975. bindingsContainer = navigation.container,
  3976. options = navigation.options;
  3977. // Shorthand object for getting events for buttons:
  3978. navigation.boundClassNames = {};
  3979. objectEach((options.bindings || {}), function (value) {
  3980. navigation.boundClassNames[value.className] = value;
  3981. });
  3982. // Handle multiple containers with the same class names:
  3983. [].forEach.call(bindingsContainer, function (subContainer) {
  3984. navigation.eventsToUnbind.push(addEvent(subContainer, 'click', function (event) {
  3985. var bindings = navigation.getButtonEvents(subContainer,
  3986. event);
  3987. if (bindings) {
  3988. navigation.bindingsButtonClick(bindings.button, bindings.events, event);
  3989. }
  3990. }));
  3991. });
  3992. objectEach(options.events || {}, function (callback, eventName) {
  3993. if (isFunction(callback)) {
  3994. navigation.eventsToUnbind.push(addEvent(navigation, eventName, callback));
  3995. }
  3996. });
  3997. navigation.eventsToUnbind.push(addEvent(chart.container, 'click', function (e) {
  3998. if (!chart.cancelClick &&
  3999. chart.isInsidePlot(e.chartX - chart.plotLeft, e.chartY - chart.plotTop)) {
  4000. navigation.bindingsChartClick(this, e);
  4001. }
  4002. }));
  4003. navigation.eventsToUnbind.push(addEvent(chart.container, H.isTouchDevice ? 'touchmove' : 'mousemove', function (e) {
  4004. navigation.bindingsContainerMouseMove(this, e);
  4005. }));
  4006. };
  4007. /**
  4008. * Common chart.update() delegation, shared between bindings and exporting.
  4009. *
  4010. * @private
  4011. * @function Highcharts.NavigationBindings#initUpdate
  4012. */
  4013. NavigationBindings.prototype.initUpdate = function () {
  4014. var navigation = this;
  4015. chartNavigationMixin.addUpdate(function (options) {
  4016. navigation.update(options);
  4017. }, this.chart);
  4018. };
  4019. /**
  4020. * Hook for click on a button, method selcts/unselects buttons,
  4021. * then calls `bindings.init` callback.
  4022. *
  4023. * @private
  4024. * @function Highcharts.NavigationBindings#bindingsButtonClick
  4025. *
  4026. * @param {Highcharts.HTMLDOMElement} [button]
  4027. * Clicked button
  4028. *
  4029. * @param {object} events
  4030. * Events passed down from bindings (`init`, `start`, `step`, `end`)
  4031. *
  4032. * @param {Highcharts.PointerEventObject} clickEvent
  4033. * Browser's click event
  4034. */
  4035. NavigationBindings.prototype.bindingsButtonClick = function (button, events, clickEvent) {
  4036. var navigation = this,
  4037. chart = navigation.chart;
  4038. if (navigation.selectedButtonElement) {
  4039. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4040. if (navigation.nextEvent) {
  4041. // Remove in-progress annotations adders:
  4042. if (navigation.currentUserDetails &&
  4043. navigation.currentUserDetails.coll === 'annotations') {
  4044. chart.removeAnnotation(navigation.currentUserDetails);
  4045. }
  4046. navigation.mouseMoveEvent = navigation.nextEvent = false;
  4047. }
  4048. }
  4049. navigation.selectedButton = events;
  4050. navigation.selectedButtonElement = button;
  4051. fireEvent(navigation, 'selectButton', { button: button });
  4052. // Call "init" event, for example to open modal window
  4053. if (events.init) {
  4054. events.init.call(navigation, button, clickEvent);
  4055. }
  4056. if (events.start || events.steps) {
  4057. chart.renderer.boxWrapper.addClass(PREFIX + 'draw-mode');
  4058. }
  4059. };
  4060. /**
  4061. * Hook for click on a chart, first click on a chart calls `start` event,
  4062. * then on all subsequent clicks iterate over `steps` array.
  4063. * When finished, calls `end` event.
  4064. *
  4065. * @private
  4066. * @function Highcharts.NavigationBindings#bindingsChartClick
  4067. *
  4068. * @param {Highcharts.Chart} chart
  4069. * Chart that click was performed on.
  4070. *
  4071. * @param {Highcharts.PointerEventObject} clickEvent
  4072. * Browser's click event.
  4073. */
  4074. NavigationBindings.prototype.bindingsChartClick = function (chart, clickEvent) {
  4075. var navigation = this,
  4076. chart = navigation.chart,
  4077. selectedButton = navigation.selectedButton,
  4078. svgContainer = chart.renderer.boxWrapper;
  4079. // Click outside popups, should close them and deselect the annotation
  4080. if (navigation.activeAnnotation &&
  4081. !clickEvent.activeAnnotation &&
  4082. // Element could be removed in the child action, e.g. button
  4083. clickEvent.target.parentNode &&
  4084. // TO DO: Polyfill for IE11?
  4085. !closestPolyfill(clickEvent.target, '.' + PREFIX + 'popup')) {
  4086. fireEvent(navigation, 'closePopup');
  4087. navigation.deselectAnnotation();
  4088. }
  4089. if (!selectedButton || !selectedButton.start) {
  4090. return;
  4091. }
  4092. if (!navigation.nextEvent) {
  4093. // Call init method:
  4094. navigation.currentUserDetails = selectedButton.start.call(navigation, clickEvent);
  4095. // If steps exists (e.g. Annotations), bind them:
  4096. if (selectedButton.steps) {
  4097. navigation.stepIndex = 0;
  4098. navigation.steps = true;
  4099. navigation.mouseMoveEvent = navigation.nextEvent =
  4100. selectedButton.steps[navigation.stepIndex];
  4101. }
  4102. else {
  4103. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4104. svgContainer.removeClass(PREFIX + 'draw-mode');
  4105. navigation.steps = false;
  4106. navigation.selectedButton = null;
  4107. // First click is also the last one:
  4108. if (selectedButton.end) {
  4109. selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
  4110. }
  4111. }
  4112. }
  4113. else {
  4114. navigation.nextEvent(clickEvent, navigation.currentUserDetails);
  4115. if (navigation.steps) {
  4116. navigation.stepIndex++;
  4117. if (selectedButton.steps[navigation.stepIndex]) {
  4118. // If we have more steps, bind them one by one:
  4119. navigation.mouseMoveEvent = navigation.nextEvent =
  4120. selectedButton.steps[navigation.stepIndex];
  4121. }
  4122. else {
  4123. fireEvent(navigation, 'deselectButton', { button: navigation.selectedButtonElement });
  4124. svgContainer.removeClass(PREFIX + 'draw-mode');
  4125. // That was the last step, call end():
  4126. if (selectedButton.end) {
  4127. selectedButton.end.call(navigation, clickEvent, navigation.currentUserDetails);
  4128. }
  4129. navigation.nextEvent = false;
  4130. navigation.mouseMoveEvent = false;
  4131. navigation.selectedButton = null;
  4132. }
  4133. }
  4134. }
  4135. };
  4136. /**
  4137. * Hook for mouse move on a chart's container. It calls current step.
  4138. *
  4139. * @private
  4140. * @function Highcharts.NavigationBindings#bindingsContainerMouseMove
  4141. *
  4142. * @param {Highcharts.HTMLDOMElement} container
  4143. * Chart's container.
  4144. *
  4145. * @param {global.Event} moveEvent
  4146. * Browser's move event.
  4147. */
  4148. NavigationBindings.prototype.bindingsContainerMouseMove = function (_container, moveEvent) {
  4149. if (this.mouseMoveEvent) {
  4150. this.mouseMoveEvent(moveEvent, this.currentUserDetails);
  4151. }
  4152. };
  4153. /**
  4154. * Translate fields (e.g. `params.period` or `marker.styles.color`) to
  4155. * Highcharts options object (e.g. `{ params: { period } }`).
  4156. *
  4157. * @private
  4158. * @function Highcharts.NavigationBindings#fieldsToOptions<T>
  4159. *
  4160. * @param {Highcharts.Dictionary<string>} fields
  4161. * Fields from popup form.
  4162. *
  4163. * @param {T} config
  4164. * Default config to be modified.
  4165. *
  4166. * @return {T}
  4167. * Modified config
  4168. */
  4169. NavigationBindings.prototype.fieldsToOptions = function (fields, config) {
  4170. objectEach(fields, function (value, field) {
  4171. var parsedValue = parseFloat(value),
  4172. path = field.split('.'),
  4173. parent = config,
  4174. pathLength = path.length - 1;
  4175. // If it's a number (not "format" options), parse it:
  4176. if (isNumber(parsedValue) &&
  4177. !value.match(/px/g) &&
  4178. !field.match(/format/g)) {
  4179. value = parsedValue;
  4180. }
  4181. // Remove empty strings or values like 0
  4182. if (value !== '' && value !== 'undefined') {
  4183. path.forEach(function (name, index) {
  4184. var nextName = pick(path[index + 1], '');
  4185. if (pathLength === index) {
  4186. // Last index, put value:
  4187. parent[name] = value;
  4188. }
  4189. else if (!parent[name]) {
  4190. // Create middle property:
  4191. parent[name] = nextName.match(/\d/g) ? [] : {};
  4192. parent = parent[name];
  4193. }
  4194. else {
  4195. // Jump into next property
  4196. parent = parent[name];
  4197. }
  4198. });
  4199. }
  4200. });
  4201. return config;
  4202. };
  4203. /**
  4204. * Shorthand method to deselect an annotation.
  4205. *
  4206. * @function Highcharts.NavigationBindings#deselectAnnotation
  4207. */
  4208. NavigationBindings.prototype.deselectAnnotation = function () {
  4209. if (this.activeAnnotation) {
  4210. this.activeAnnotation.setControlPointsVisibility(false);
  4211. this.activeAnnotation = false;
  4212. }
  4213. };
  4214. /**
  4215. * Generates API config for popup in the same format as options for
  4216. * Annotation object.
  4217. *
  4218. * @function Highcharts.NavigationBindings#annotationToFields
  4219. *
  4220. * @param {Highcharts.Annotation} annotation
  4221. * Annotations object
  4222. *
  4223. * @return {Highcharts.Dictionary<string>}
  4224. * Annotation options to be displayed in popup box
  4225. */
  4226. NavigationBindings.prototype.annotationToFields = function (annotation) {
  4227. var options = annotation.options,
  4228. editables = NavigationBindings.annotationsEditable,
  4229. nestedEditables = editables.nestedOptions,
  4230. getFieldType = this.utils.getFieldType,
  4231. type = pick(options.type,
  4232. options.shapes && options.shapes[0] &&
  4233. options.shapes[0].type,
  4234. options.labels && options.labels[0] &&
  4235. options.labels[0].itemType, 'label'),
  4236. nonEditables = NavigationBindings.annotationsNonEditable[options.langKey] || [],
  4237. visualOptions = {
  4238. langKey: options.langKey,
  4239. type: type
  4240. };
  4241. /**
  4242. * Nested options traversing. Method goes down to the options and copies
  4243. * allowed options (with values) to new object, which is last parameter:
  4244. * "parent".
  4245. *
  4246. * @private
  4247. *
  4248. * @param {*} option
  4249. * Atomic type or object/array
  4250. *
  4251. * @param {string} key
  4252. * Option name, for example "visible" or "x", "y"
  4253. *
  4254. * @param {object} parentEditables
  4255. * Editables from NavigationBindings.annotationsEditable
  4256. *
  4257. * @param {object} parent
  4258. * Where new options will be assigned
  4259. */
  4260. function traverse(option, key, parentEditables, parent) {
  4261. var nextParent;
  4262. if (parentEditables &&
  4263. option &&
  4264. nonEditables.indexOf(key) === -1 &&
  4265. ((parentEditables.indexOf &&
  4266. parentEditables.indexOf(key)) >= 0 ||
  4267. parentEditables[key] || // nested array
  4268. parentEditables === true // simple array
  4269. )) {
  4270. // Roots:
  4271. if (isArray(option)) {
  4272. parent[key] = [];
  4273. option.forEach(function (arrayOption, i) {
  4274. if (!isObject(arrayOption)) {
  4275. // Simple arrays, e.g. [String, Number, Boolean]
  4276. traverse(arrayOption, 0, nestedEditables[key], parent[key]);
  4277. }
  4278. else {
  4279. // Advanced arrays, e.g. [Object, Object]
  4280. parent[key][i] = {};
  4281. objectEach(arrayOption, function (nestedOption, nestedKey) {
  4282. traverse(nestedOption, nestedKey, nestedEditables[key], parent[key][i]);
  4283. });
  4284. }
  4285. });
  4286. }
  4287. else if (isObject(option)) {
  4288. nextParent = {};
  4289. if (isArray(parent)) {
  4290. parent.push(nextParent);
  4291. nextParent[key] = {};
  4292. nextParent = nextParent[key];
  4293. }
  4294. else {
  4295. parent[key] = nextParent;
  4296. }
  4297. objectEach(option, function (nestedOption, nestedKey) {
  4298. traverse(nestedOption, nestedKey, key === 0 ? parentEditables : nestedEditables[key], nextParent);
  4299. });
  4300. }
  4301. else {
  4302. // Leaf:
  4303. if (key === 'format') {
  4304. parent[key] = [
  4305. format(option, annotation.labels[0].points[0]).toString(),
  4306. 'text'
  4307. ];
  4308. }
  4309. else if (isArray(parent)) {
  4310. parent.push([option, getFieldType(option)]);
  4311. }
  4312. else {
  4313. parent[key] = [option, getFieldType(option)];
  4314. }
  4315. }
  4316. }
  4317. }
  4318. objectEach(options, function (option, key) {
  4319. if (key === 'typeOptions') {
  4320. visualOptions[key] = {};
  4321. objectEach(options[key], function (typeOption, typeKey) {
  4322. traverse(typeOption, typeKey, nestedEditables, visualOptions[key], true);
  4323. });
  4324. }
  4325. else {
  4326. traverse(option, key, editables[type], visualOptions);
  4327. }
  4328. });
  4329. return visualOptions;
  4330. };
  4331. /**
  4332. * Get all class names for all parents in the element. Iterates until finds
  4333. * main container.
  4334. *
  4335. * @function Highcharts.NavigationBindings#getClickedClassNames
  4336. *
  4337. * @param {Highcharts.HTMLDOMElement}
  4338. * Container that event is bound to.
  4339. *
  4340. * @param {global.Event} event
  4341. * Browser's event.
  4342. *
  4343. * @return {Array<Array<string, Highcharts.HTMLDOMElement>>}
  4344. * Array of class names with corresponding elements
  4345. */
  4346. NavigationBindings.prototype.getClickedClassNames = function (container, event) {
  4347. var element = event.target,
  4348. classNames = [],
  4349. elemClassName;
  4350. while (element) {
  4351. elemClassName = attr(element, 'class');
  4352. if (elemClassName) {
  4353. classNames = classNames.concat(elemClassName
  4354. .split(' ')
  4355. .map(function (name) {
  4356. return [
  4357. name,
  4358. element
  4359. ];
  4360. }));
  4361. }
  4362. element = element.parentNode;
  4363. if (element === container) {
  4364. return classNames;
  4365. }
  4366. }
  4367. return classNames;
  4368. };
  4369. /**
  4370. * Get events bound to a button. It's a custom event delegation to find all
  4371. * events connected to the element.
  4372. *
  4373. * @private
  4374. * @function Highcharts.NavigationBindings#getButtonEvents
  4375. *
  4376. * @param {Highcharts.HTMLDOMElement} container
  4377. * Container that event is bound to.
  4378. *
  4379. * @param {global.Event} event
  4380. * Browser's event.
  4381. *
  4382. * @return {object}
  4383. * Object with events (init, start, steps, and end)
  4384. */
  4385. NavigationBindings.prototype.getButtonEvents = function (container, event) {
  4386. var navigation = this,
  4387. classNames = this.getClickedClassNames(container,
  4388. event),
  4389. bindings;
  4390. classNames.forEach(function (className) {
  4391. if (navigation.boundClassNames[className[0]] && !bindings) {
  4392. bindings = {
  4393. events: navigation.boundClassNames[className[0]],
  4394. button: className[1]
  4395. };
  4396. }
  4397. });
  4398. return bindings;
  4399. };
  4400. /**
  4401. * Bindings are just events, so the whole update process is simply
  4402. * removing old events and adding new ones.
  4403. *
  4404. * @private
  4405. * @function Highcharts.NavigationBindings#update
  4406. */
  4407. NavigationBindings.prototype.update = function (options) {
  4408. this.options = merge(true, this.options, options);
  4409. this.removeEvents();
  4410. this.initEvents();
  4411. };
  4412. /**
  4413. * Remove all events created in the navigation.
  4414. *
  4415. * @private
  4416. * @function Highcharts.NavigationBindings#removeEvents
  4417. */
  4418. NavigationBindings.prototype.removeEvents = function () {
  4419. this.eventsToUnbind.forEach(function (unbinder) {
  4420. unbinder();
  4421. });
  4422. };
  4423. NavigationBindings.prototype.destroy = function () {
  4424. this.removeEvents();
  4425. };
  4426. /* *
  4427. *
  4428. * Static Properties
  4429. *
  4430. * */
  4431. // Define which options from annotations should show up in edit box:
  4432. NavigationBindings.annotationsEditable = {
  4433. // `typeOptions` are always available
  4434. // Nested and shared options:
  4435. nestedOptions: {
  4436. labelOptions: ['style', 'format', 'backgroundColor'],
  4437. labels: ['style'],
  4438. label: ['style'],
  4439. style: ['fontSize', 'color'],
  4440. background: ['fill', 'strokeWidth', 'stroke'],
  4441. innerBackground: ['fill', 'strokeWidth', 'stroke'],
  4442. outerBackground: ['fill', 'strokeWidth', 'stroke'],
  4443. shapeOptions: ['fill', 'strokeWidth', 'stroke'],
  4444. shapes: ['fill', 'strokeWidth', 'stroke'],
  4445. line: ['strokeWidth', 'stroke'],
  4446. backgroundColors: [true],
  4447. connector: ['fill', 'strokeWidth', 'stroke'],
  4448. crosshairX: ['strokeWidth', 'stroke'],
  4449. crosshairY: ['strokeWidth', 'stroke']
  4450. },
  4451. // Simple shapes:
  4452. circle: ['shapes'],
  4453. verticalLine: [],
  4454. label: ['labelOptions'],
  4455. // Measure
  4456. measure: ['background', 'crosshairY', 'crosshairX'],
  4457. // Others:
  4458. fibonacci: [],
  4459. tunnel: ['background', 'line', 'height'],
  4460. pitchfork: ['innerBackground', 'outerBackground'],
  4461. rect: ['shapes'],
  4462. // Crooked lines, elliots, arrows etc:
  4463. crookedLine: [],
  4464. basicAnnotation: ['shapes', 'labelOptions']
  4465. };
  4466. // Define non editable fields per annotation, for example Rectangle inherits
  4467. // options from Measure, but crosshairs are not available
  4468. NavigationBindings.annotationsNonEditable = {
  4469. rectangle: ['crosshairX', 'crosshairY', 'label']
  4470. };
  4471. return NavigationBindings;
  4472. }());
  4473. /**
  4474. * General utils for bindings
  4475. *
  4476. * @private
  4477. * @name Highcharts.NavigationBindings.utils
  4478. * @type {bindingsUtils}
  4479. */
  4480. NavigationBindings.prototype.utils = bindingsUtils;
  4481. Chart.prototype.initNavigationBindings = function () {
  4482. var chart = this,
  4483. options = chart.options;
  4484. if (options && options.navigation && options.navigation.bindings) {
  4485. chart.navigationBindings = new NavigationBindings(chart, options.navigation);
  4486. chart.navigationBindings.initEvents();
  4487. chart.navigationBindings.initUpdate();
  4488. }
  4489. };
  4490. addEvent(Chart, 'load', function () {
  4491. this.initNavigationBindings();
  4492. });
  4493. addEvent(Chart, 'destroy', function () {
  4494. if (this.navigationBindings) {
  4495. this.navigationBindings.destroy();
  4496. }
  4497. });
  4498. addEvent(NavigationBindings, 'deselectButton', function () {
  4499. this.selectedButtonElement = null;
  4500. });
  4501. addEvent(Annotation, 'remove', function () {
  4502. if (this.chart.navigationBindings) {
  4503. this.chart.navigationBindings.deselectAnnotation();
  4504. }
  4505. });
  4506. /**
  4507. * Show edit-annotation form:
  4508. * @private
  4509. */
  4510. function selectableAnnotation(annotationType) {
  4511. var originalClick = annotationType.prototype.defaultOptions.events &&
  4512. annotationType.prototype.defaultOptions.events.click;
  4513. /**
  4514. * @private
  4515. */
  4516. function selectAndshowPopup(event) {
  4517. var annotation = this,
  4518. navigation = annotation.chart.navigationBindings,
  4519. prevAnnotation = navigation.activeAnnotation;
  4520. if (originalClick) {
  4521. originalClick.call(annotation, event);
  4522. }
  4523. if (prevAnnotation !== annotation) {
  4524. // Select current:
  4525. navigation.deselectAnnotation();
  4526. navigation.activeAnnotation = annotation;
  4527. annotation.setControlPointsVisibility(true);
  4528. fireEvent(navigation, 'showPopup', {
  4529. annotation: annotation,
  4530. formType: 'annotation-toolbar',
  4531. options: navigation.annotationToFields(annotation),
  4532. onSubmit: function (data) {
  4533. var config = {},
  4534. typeOptions;
  4535. if (data.actionType === 'remove') {
  4536. navigation.activeAnnotation = false;
  4537. navigation.chart.removeAnnotation(annotation);
  4538. }
  4539. else {
  4540. navigation.fieldsToOptions(data.fields, config);
  4541. navigation.deselectAnnotation();
  4542. typeOptions = config.typeOptions;
  4543. if (annotation.options.type === 'measure') {
  4544. // Manually disable crooshars according to
  4545. // stroke width of the shape:
  4546. typeOptions.crosshairY.enabled =
  4547. typeOptions.crosshairY.strokeWidth !== 0;
  4548. typeOptions.crosshairX.enabled =
  4549. typeOptions.crosshairX.strokeWidth !== 0;
  4550. }
  4551. annotation.update(config);
  4552. }
  4553. }
  4554. });
  4555. }
  4556. else {
  4557. // Deselect current:
  4558. navigation.deselectAnnotation();
  4559. fireEvent(navigation, 'closePopup');
  4560. }
  4561. // Let bubble event to chart.click:
  4562. event.activeAnnotation = true;
  4563. }
  4564. merge(true, annotationType.prototype.defaultOptions.events, {
  4565. click: selectAndshowPopup
  4566. });
  4567. }
  4568. if (H.Annotation) {
  4569. // Basic shapes:
  4570. selectableAnnotation(Annotation);
  4571. // Advanced annotations:
  4572. objectEach(Annotation.types, function (annotationType) {
  4573. selectableAnnotation(annotationType);
  4574. });
  4575. }
  4576. setOptions({
  4577. /**
  4578. * @optionparent lang
  4579. *
  4580. * @private
  4581. */
  4582. lang: {
  4583. /**
  4584. * Configure the Popup strings in the chart. Requires the
  4585. * `annotations.js` or `annotations-advanced.src.js` module to be
  4586. * loaded.
  4587. *
  4588. * @since 7.0.0
  4589. * @product highcharts highstock
  4590. */
  4591. navigation: {
  4592. /**
  4593. * Translations for all field names used in popup.
  4594. *
  4595. * @product highcharts highstock
  4596. */
  4597. popup: {
  4598. simpleShapes: 'Simple shapes',
  4599. lines: 'Lines',
  4600. circle: 'Circle',
  4601. rectangle: 'Rectangle',
  4602. label: 'Label',
  4603. shapeOptions: 'Shape options',
  4604. typeOptions: 'Details',
  4605. fill: 'Fill',
  4606. format: 'Text',
  4607. strokeWidth: 'Line width',
  4608. stroke: 'Line color',
  4609. title: 'Title',
  4610. name: 'Name',
  4611. labelOptions: 'Label options',
  4612. labels: 'Labels',
  4613. backgroundColor: 'Background color',
  4614. backgroundColors: 'Background colors',
  4615. borderColor: 'Border color',
  4616. borderRadius: 'Border radius',
  4617. borderWidth: 'Border width',
  4618. style: 'Style',
  4619. padding: 'Padding',
  4620. fontSize: 'Font size',
  4621. color: 'Color',
  4622. height: 'Height',
  4623. shapes: 'Shape options'
  4624. }
  4625. }
  4626. },
  4627. /**
  4628. * @optionparent navigation
  4629. * @product highcharts highstock
  4630. *
  4631. * @private
  4632. */
  4633. navigation: {
  4634. /**
  4635. * A CSS class name where all bindings will be attached to. Multiple
  4636. * charts on the same page should have separate class names to prevent
  4637. * duplicating events.
  4638. *
  4639. * Default value of versions < 7.0.4 `highcharts-bindings-wrapper`
  4640. *
  4641. * @since 7.0.0
  4642. * @type {string}
  4643. */
  4644. bindingsClassName: 'highcharts-bindings-container',
  4645. /**
  4646. * Bindings definitions for custom HTML buttons. Each binding implements
  4647. * simple event-driven interface:
  4648. *
  4649. * - `className`: classname used to bind event to
  4650. *
  4651. * - `init`: initial event, fired on button click
  4652. *
  4653. * - `start`: fired on first click on a chart
  4654. *
  4655. * - `steps`: array of sequential events fired one after another on each
  4656. * of users clicks
  4657. *
  4658. * - `end`: last event to be called after last step event
  4659. *
  4660. * @type {Highcharts.Dictionary<Highcharts.NavigationBindingsOptionsObject>|*}
  4661. * @sample stock/stocktools/stocktools-thresholds
  4662. * Custom bindings in Highstock
  4663. * @since 7.0.0
  4664. * @product highcharts highstock
  4665. */
  4666. bindings: {
  4667. /**
  4668. * A circle annotation bindings. Includes `start` and one event in
  4669. * `steps` array.
  4670. *
  4671. * @type {Highcharts.NavigationBindingsOptionsObject}
  4672. * @default {"className": "highcharts-circle-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4673. */
  4674. circleAnnotation: {
  4675. /** @ignore-option */
  4676. className: 'highcharts-circle-annotation',
  4677. /** @ignore-option */
  4678. start: function (e) {
  4679. var coords = this.chart.pointer.getCoordinates(e),
  4680. navigation = this.chart.options.navigation;
  4681. return this.chart.addAnnotation(merge({
  4682. langKey: 'circle',
  4683. type: 'basicAnnotation',
  4684. shapes: [{
  4685. type: 'circle',
  4686. point: {
  4687. xAxis: 0,
  4688. yAxis: 0,
  4689. x: coords.xAxis[0].value,
  4690. y: coords.yAxis[0].value
  4691. },
  4692. r: 5
  4693. }]
  4694. }, navigation
  4695. .annotationsOptions, navigation
  4696. .bindings
  4697. .circleAnnotation
  4698. .annotationsOptions));
  4699. },
  4700. /** @ignore-option */
  4701. steps: [
  4702. function (e, annotation) {
  4703. var point = annotation.options.shapes[0].point,
  4704. x = this.chart.xAxis[0].toPixels(point.x),
  4705. y = this.chart.yAxis[0].toPixels(point.y),
  4706. inverted = this.chart.inverted,
  4707. distance = Math.max(Math.sqrt(Math.pow(inverted ? y - e.chartX : x - e.chartX, 2) +
  4708. Math.pow(inverted ? x - e.chartY : y - e.chartY, 2)), 5);
  4709. annotation.update({
  4710. shapes: [{
  4711. r: distance
  4712. }]
  4713. });
  4714. }
  4715. ]
  4716. },
  4717. /**
  4718. * A rectangle annotation bindings. Includes `start` and one event
  4719. * in `steps` array.
  4720. *
  4721. * @type {Highcharts.NavigationBindingsOptionsObject}
  4722. * @default {"className": "highcharts-rectangle-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4723. */
  4724. rectangleAnnotation: {
  4725. /** @ignore-option */
  4726. className: 'highcharts-rectangle-annotation',
  4727. /** @ignore-option */
  4728. start: function (e) {
  4729. var coords = this.chart.pointer.getCoordinates(e),
  4730. navigation = this.chart.options.navigation,
  4731. x = coords.xAxis[0].value,
  4732. y = coords.yAxis[0].value;
  4733. return this.chart.addAnnotation(merge({
  4734. langKey: 'rectangle',
  4735. type: 'basicAnnotation',
  4736. shapes: [{
  4737. type: 'path',
  4738. points: [{
  4739. xAxis: 0,
  4740. yAxis: 0,
  4741. x: x,
  4742. y: y
  4743. }, {
  4744. xAxis: 0,
  4745. yAxis: 0,
  4746. x: x,
  4747. y: y
  4748. }, {
  4749. xAxis: 0,
  4750. yAxis: 0,
  4751. x: x,
  4752. y: y
  4753. }, {
  4754. xAxis: 0,
  4755. yAxis: 0,
  4756. x: x,
  4757. y: y
  4758. }]
  4759. }]
  4760. }, navigation
  4761. .annotationsOptions, navigation
  4762. .bindings
  4763. .rectangleAnnotation
  4764. .annotationsOptions));
  4765. },
  4766. /** @ignore-option */
  4767. steps: [
  4768. function (e, annotation) {
  4769. var points = annotation.options.shapes[0].points,
  4770. coords = this.chart.pointer.getCoordinates(e),
  4771. x = coords.xAxis[0].value,
  4772. y = coords.yAxis[0].value;
  4773. // Top right point
  4774. points[1].x = x;
  4775. // Bottom right point (cursor position)
  4776. points[2].x = x;
  4777. points[2].y = y;
  4778. // Bottom left
  4779. points[3].y = y;
  4780. annotation.update({
  4781. shapes: [{
  4782. points: points
  4783. }]
  4784. });
  4785. }
  4786. ]
  4787. },
  4788. /**
  4789. * A label annotation bindings. Includes `start` event only.
  4790. *
  4791. * @type {Highcharts.NavigationBindingsOptionsObject}
  4792. * @default {"className": "highcharts-label-annotation", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  4793. */
  4794. labelAnnotation: {
  4795. /** @ignore-option */
  4796. className: 'highcharts-label-annotation',
  4797. /** @ignore-option */
  4798. start: function (e) {
  4799. var coords = this.chart.pointer.getCoordinates(e),
  4800. navigation = this.chart.options.navigation;
  4801. return this.chart.addAnnotation(merge({
  4802. langKey: 'label',
  4803. type: 'basicAnnotation',
  4804. labelOptions: {
  4805. format: '{y:.2f}'
  4806. },
  4807. labels: [{
  4808. point: {
  4809. xAxis: 0,
  4810. yAxis: 0,
  4811. x: coords.xAxis[0].value,
  4812. y: coords.yAxis[0].value
  4813. },
  4814. overflow: 'none',
  4815. crop: true
  4816. }]
  4817. }, navigation
  4818. .annotationsOptions, navigation
  4819. .bindings
  4820. .labelAnnotation
  4821. .annotationsOptions));
  4822. }
  4823. }
  4824. },
  4825. /**
  4826. * Path where Highcharts will look for icons. Change this to use icons
  4827. * from a different server.
  4828. *
  4829. * @type {string}
  4830. * @default https://code.highcharts.com/8.2.2/gfx/stock-icons/
  4831. * @since 7.1.3
  4832. * @apioption navigation.iconsURL
  4833. */
  4834. /**
  4835. * A `showPopup` event. Fired when selecting for example an annotation.
  4836. *
  4837. * @type {Function}
  4838. * @apioption navigation.events.showPopup
  4839. */
  4840. /**
  4841. * A `closePopup` event. Fired when Popup should be hidden, for example
  4842. * when clicking on an annotation again.
  4843. *
  4844. * @type {Function}
  4845. * @apioption navigation.events.closePopup
  4846. */
  4847. /**
  4848. * Event fired on a button click.
  4849. *
  4850. * @type {Function}
  4851. * @sample highcharts/annotations/gui/
  4852. * Change icon in a dropddown on event
  4853. * @sample highcharts/annotations/gui-buttons/
  4854. * Change button class on event
  4855. * @apioption navigation.events.selectButton
  4856. */
  4857. /**
  4858. * Event fired when button state should change, for example after
  4859. * adding an annotation.
  4860. *
  4861. * @type {Function}
  4862. * @sample highcharts/annotations/gui/
  4863. * Change icon in a dropddown on event
  4864. * @sample highcharts/annotations/gui-buttons/
  4865. * Change button class on event
  4866. * @apioption navigation.events.deselectButton
  4867. */
  4868. /**
  4869. * Events to communicate between Stock Tools and custom GUI.
  4870. *
  4871. * @since 7.0.0
  4872. * @product highcharts highstock
  4873. * @optionparent navigation.events
  4874. */
  4875. events: {},
  4876. /**
  4877. * Additional options to be merged into all annotations.
  4878. *
  4879. * @sample stock/stocktools/navigation-annotation-options
  4880. * Set red color of all line annotations
  4881. *
  4882. * @type {Highcharts.AnnotationsOptions}
  4883. * @extends annotations
  4884. * @exclude crookedLine, elliottWave, fibonacci, infinityLine,
  4885. * measure, pitchfork, tunnel, verticalLine, basicAnnotation
  4886. * @apioption navigation.annotationsOptions
  4887. */
  4888. annotationsOptions: {
  4889. animation: {
  4890. defer: 0
  4891. }
  4892. }
  4893. }
  4894. });
  4895. return NavigationBindings;
  4896. });
  4897. _registerModule(_modules, 'Stock/StockToolsBindings.js', [_modules['Core/Globals.js'], _modules['Extensions/Annotations/NavigationBindings.js'], _modules['Core/Utilities.js']], function (H, NavigationBindings, U) {
  4898. /**
  4899. *
  4900. * Events generator for Stock tools
  4901. *
  4902. * (c) 2009-2020 Paweł Fus
  4903. *
  4904. * License: www.highcharts.com/license
  4905. *
  4906. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4907. *
  4908. * */
  4909. var correctFloat = U.correctFloat,
  4910. defined = U.defined,
  4911. extend = U.extend,
  4912. fireEvent = U.fireEvent,
  4913. getOptions = U.getOptions,
  4914. isNumber = U.isNumber,
  4915. merge = U.merge,
  4916. pick = U.pick,
  4917. setOptions = U.setOptions,
  4918. uniqueKey = U.uniqueKey;
  4919. var bindingsUtils = NavigationBindings.prototype.utils,
  4920. PREFIX = 'highcharts-';
  4921. /* eslint-disable no-invalid-this, valid-jsdoc */
  4922. /**
  4923. * Generates function which will add a flag series using modal in GUI.
  4924. * Method fires an event "showPopup" with config:
  4925. * `{type, options, callback}`.
  4926. *
  4927. * Example: NavigationBindings.utils.addFlagFromForm('url(...)') - will
  4928. * generate function that shows modal in GUI.
  4929. *
  4930. * @private
  4931. * @function bindingsUtils.addFlagFromForm
  4932. *
  4933. * @param {Highcharts.FlagsShapeValue} type
  4934. * Type of flag series, e.g. "squarepin"
  4935. *
  4936. * @return {Function}
  4937. * Callback to be used in `start` callback
  4938. */
  4939. bindingsUtils.addFlagFromForm = function (type) {
  4940. return function (e) {
  4941. var navigation = this,
  4942. chart = navigation.chart,
  4943. toolbar = chart.stockTools,
  4944. getFieldType = bindingsUtils.getFieldType,
  4945. point = bindingsUtils.attractToPoint(e,
  4946. chart),
  4947. pointConfig = {
  4948. x: point.x,
  4949. y: point.y
  4950. },
  4951. seriesOptions = {
  4952. type: 'flags',
  4953. onSeries: point.series.id,
  4954. shape: type,
  4955. data: [pointConfig],
  4956. point: {
  4957. events: {
  4958. click: function () {
  4959. var point = this,
  4960. options = point.options;
  4961. fireEvent(navigation, 'showPopup', {
  4962. point: point,
  4963. formType: 'annotation-toolbar',
  4964. options: {
  4965. langKey: 'flags',
  4966. type: 'flags',
  4967. title: [
  4968. options.title,
  4969. getFieldType(options.title)
  4970. ],
  4971. name: [
  4972. options.name,
  4973. getFieldType(options.name)
  4974. ]
  4975. },
  4976. onSubmit: function (updated) {
  4977. if (updated.actionType === 'remove') {
  4978. point.remove();
  4979. }
  4980. else {
  4981. point.update(navigation.fieldsToOptions(updated.fields, {}));
  4982. }
  4983. }
  4984. });
  4985. }
  4986. }
  4987. }
  4988. };
  4989. if (!toolbar || !toolbar.guiEnabled) {
  4990. chart.addSeries(seriesOptions);
  4991. }
  4992. fireEvent(navigation, 'showPopup', {
  4993. formType: 'flag',
  4994. // Enabled options:
  4995. options: {
  4996. langKey: 'flags',
  4997. type: 'flags',
  4998. title: ['A', getFieldType('A')],
  4999. name: ['Flag A', getFieldType('Flag A')]
  5000. },
  5001. // Callback on submit:
  5002. onSubmit: function (data) {
  5003. navigation.fieldsToOptions(data.fields, seriesOptions.data[0]);
  5004. chart.addSeries(seriesOptions);
  5005. }
  5006. });
  5007. };
  5008. };
  5009. bindingsUtils.manageIndicators = function (data) {
  5010. var _a;
  5011. var navigation = this,
  5012. chart = navigation.chart,
  5013. seriesConfig = {
  5014. linkedTo: data.linkedTo,
  5015. type: data.type
  5016. },
  5017. indicatorsWithVolume = [
  5018. 'ad',
  5019. 'cmf',
  5020. 'mfi',
  5021. 'vbp',
  5022. 'vwap'
  5023. ],
  5024. indicatorsWithAxes = [
  5025. 'ad',
  5026. 'atr',
  5027. 'cci',
  5028. 'cmf',
  5029. 'macd',
  5030. 'mfi',
  5031. 'roc',
  5032. 'rsi',
  5033. 'ao',
  5034. 'aroon',
  5035. 'aroonoscillator',
  5036. 'trix',
  5037. 'apo',
  5038. 'dpo',
  5039. 'ppo',
  5040. 'natr',
  5041. 'williamsr',
  5042. 'stochastic',
  5043. 'slowstochastic',
  5044. 'linearRegression',
  5045. 'linearRegressionSlope',
  5046. 'linearRegressionIntercept',
  5047. 'linearRegressionAngle'
  5048. ],
  5049. yAxis,
  5050. parentSeries,
  5051. defaultOptions,
  5052. series;
  5053. if (data.actionType === 'edit') {
  5054. navigation.fieldsToOptions(data.fields, seriesConfig);
  5055. series = chart.get(data.seriesId);
  5056. if (series) {
  5057. series.update(seriesConfig, false);
  5058. }
  5059. }
  5060. else if (data.actionType === 'remove') {
  5061. series = chart.get(data.seriesId);
  5062. if (series) {
  5063. yAxis = series.yAxis;
  5064. if (series.linkedSeries) {
  5065. series.linkedSeries.forEach(function (linkedSeries) {
  5066. linkedSeries.remove(false);
  5067. });
  5068. }
  5069. series.remove(false);
  5070. if (indicatorsWithAxes.indexOf(series.type) >= 0) {
  5071. yAxis.remove(false);
  5072. navigation.resizeYAxes();
  5073. }
  5074. }
  5075. }
  5076. else {
  5077. seriesConfig.id = uniqueKey();
  5078. navigation.fieldsToOptions(data.fields, seriesConfig);
  5079. parentSeries = chart.get(seriesConfig.linkedTo);
  5080. defaultOptions = getOptions().plotOptions;
  5081. // Make sure that indicator uses the SUM approx if SUM approx is used
  5082. // by parent series (#13950).
  5083. if (typeof parentSeries !== 'undefined' &&
  5084. parentSeries instanceof Highcharts.Series &&
  5085. parentSeries.getDGApproximation() === 'sum' &&
  5086. // If indicator has defined approx type, use it (e.g. "ranges")
  5087. !defined(defaultOptions && defaultOptions[seriesConfig.type] && ((_a = defaultOptions.dataGrouping) === null || _a === void 0 ? void 0 : _a.approximation))) {
  5088. seriesConfig.dataGrouping = {
  5089. approximation: 'sum'
  5090. };
  5091. }
  5092. if (indicatorsWithAxes.indexOf(data.type) >= 0) {
  5093. yAxis = chart.addAxis({
  5094. id: uniqueKey(),
  5095. offset: 0,
  5096. opposite: true,
  5097. title: {
  5098. text: ''
  5099. },
  5100. tickPixelInterval: 40,
  5101. showLastLabel: false,
  5102. labels: {
  5103. align: 'left',
  5104. y: -2
  5105. }
  5106. }, false, false);
  5107. seriesConfig.yAxis = yAxis.options.id;
  5108. navigation.resizeYAxes();
  5109. }
  5110. else {
  5111. seriesConfig.yAxis = chart.get(data.linkedTo).options.yAxis;
  5112. }
  5113. if (indicatorsWithVolume.indexOf(data.type) >= 0) {
  5114. seriesConfig.params.volumeSeriesID = chart.series.filter(function (series) {
  5115. return series.options.type === 'column';
  5116. })[0].options.id;
  5117. }
  5118. chart.addSeries(seriesConfig, false);
  5119. }
  5120. fireEvent(navigation, 'deselectButton', {
  5121. button: navigation.selectedButtonElement
  5122. });
  5123. chart.redraw();
  5124. };
  5125. /**
  5126. * Update height for an annotation. Height is calculated as a difference
  5127. * between last point in `typeOptions` and current position. It's a value,
  5128. * not pixels height.
  5129. *
  5130. * @private
  5131. * @function bindingsUtils.updateHeight
  5132. *
  5133. * @param {Highcharts.PointerEventObject} e
  5134. * normalized browser event
  5135. *
  5136. * @param {Highcharts.Annotation} annotation
  5137. * Annotation to be updated
  5138. *
  5139. * @return {void}
  5140. */
  5141. bindingsUtils.updateHeight = function (e, annotation) {
  5142. annotation.update({
  5143. typeOptions: {
  5144. height: this.chart.pointer.getCoordinates(e).yAxis[0].value -
  5145. annotation.options.typeOptions.points[1].y
  5146. }
  5147. });
  5148. };
  5149. // @todo
  5150. // Consider using getHoverData(), but always kdTree (columns?)
  5151. bindingsUtils.attractToPoint = function (e, chart) {
  5152. var coords = chart.pointer.getCoordinates(e),
  5153. x = coords.xAxis[0].value,
  5154. y = coords.yAxis[0].value,
  5155. distX = Number.MAX_VALUE,
  5156. closestPoint;
  5157. chart.series.forEach(function (series) {
  5158. series.points.forEach(function (point) {
  5159. if (point && distX > Math.abs(point.x - x)) {
  5160. distX = Math.abs(point.x - x);
  5161. closestPoint = point;
  5162. }
  5163. });
  5164. });
  5165. return {
  5166. x: closestPoint.x,
  5167. y: closestPoint.y,
  5168. below: y < closestPoint.y,
  5169. series: closestPoint.series,
  5170. xAxis: closestPoint.series.xAxis.index || 0,
  5171. yAxis: closestPoint.series.yAxis.index || 0
  5172. };
  5173. };
  5174. /**
  5175. * Shorthand to check if given yAxis comes from navigator.
  5176. *
  5177. * @private
  5178. * @function bindingsUtils.isNotNavigatorYAxis
  5179. *
  5180. * @param {Highcharts.Axis} axis
  5181. * Axis to check.
  5182. *
  5183. * @return {boolean}
  5184. * True, if axis comes from navigator.
  5185. */
  5186. bindingsUtils.isNotNavigatorYAxis = function (axis) {
  5187. return axis.userOptions.className !== PREFIX + 'navigator-yaxis';
  5188. };
  5189. /**
  5190. * Update each point after specified index, most of the annotations use
  5191. * this. For example crooked line: logic behind updating each point is the
  5192. * same, only index changes when adding an annotation.
  5193. *
  5194. * Example: NavigationBindings.utils.updateNthPoint(1) - will generate
  5195. * function that updates all consecutive points except point with index=0.
  5196. *
  5197. * @private
  5198. * @function bindingsUtils.updateNthPoint
  5199. *
  5200. * @param {number} startIndex
  5201. * Index from each point should udpated
  5202. *
  5203. * @return {Function}
  5204. * Callback to be used in steps array
  5205. */
  5206. bindingsUtils.updateNthPoint = function (startIndex) {
  5207. return function (e, annotation) {
  5208. var options = annotation.options.typeOptions,
  5209. coords = this.chart.pointer.getCoordinates(e),
  5210. x = coords.xAxis[0].value,
  5211. y = coords.yAxis[0].value;
  5212. options.points.forEach(function (point, index) {
  5213. if (index >= startIndex) {
  5214. point.x = x;
  5215. point.y = y;
  5216. }
  5217. });
  5218. annotation.update({
  5219. typeOptions: {
  5220. points: options.points
  5221. }
  5222. });
  5223. };
  5224. };
  5225. // Extends NavigationBindigs to support indicators and resizers:
  5226. extend(NavigationBindings.prototype, {
  5227. /* eslint-disable valid-jsdoc */
  5228. /**
  5229. * Get current positions for all yAxes. If new axis does not have position,
  5230. * returned is default height and last available top place.
  5231. *
  5232. * @private
  5233. * @function Highcharts.NavigationBindings#getYAxisPositions
  5234. *
  5235. * @param {Array<Highcharts.Axis>} yAxes
  5236. * Array of yAxes available in the chart.
  5237. *
  5238. * @param {number} plotHeight
  5239. * Available height in the chart.
  5240. *
  5241. * @param {number} defaultHeight
  5242. * Default height in percents.
  5243. *
  5244. * @return {Array}
  5245. * An array of calculated positions in percentages.
  5246. * Format: `{top: Number, height: Number}`
  5247. */
  5248. getYAxisPositions: function (yAxes, plotHeight, defaultHeight) {
  5249. var positions,
  5250. allAxesHeight = 0;
  5251. /** @private */
  5252. function isPercentage(prop) {
  5253. return defined(prop) && !isNumber(prop) && prop.match('%');
  5254. }
  5255. positions = yAxes.map(function (yAxis) {
  5256. var height = isPercentage(yAxis.options.height) ?
  5257. parseFloat(yAxis.options.height) / 100 :
  5258. yAxis.height / plotHeight,
  5259. top = isPercentage(yAxis.options.top) ?
  5260. parseFloat(yAxis.options.top) / 100 :
  5261. correctFloat(yAxis.top - yAxis.chart.plotTop) / plotHeight;
  5262. // New yAxis does not contain "height" info yet
  5263. if (!isNumber(height)) {
  5264. height = defaultHeight / 100;
  5265. }
  5266. allAxesHeight = correctFloat(allAxesHeight + height);
  5267. return {
  5268. height: height * 100,
  5269. top: top * 100
  5270. };
  5271. });
  5272. positions.allAxesHeight = allAxesHeight;
  5273. return positions;
  5274. },
  5275. /**
  5276. * Get current resize options for each yAxis. Note that each resize is
  5277. * linked to the next axis, except the last one which shouldn't affect
  5278. * axes in the navigator. Because indicator can be removed with it's yAxis
  5279. * in the middle of yAxis array, we need to bind closest yAxes back.
  5280. *
  5281. * @private
  5282. * @function Highcharts.NavigationBindings#getYAxisResizers
  5283. *
  5284. * @param {Array<Highcharts.Axis>} yAxes
  5285. * Array of yAxes available in the chart
  5286. *
  5287. * @return {Array<object>}
  5288. * An array of resizer options.
  5289. * Format: `{enabled: Boolean, controlledAxis: { next: [String]}}`
  5290. */
  5291. getYAxisResizers: function (yAxes) {
  5292. var resizers = [];
  5293. yAxes.forEach(function (_yAxis, index) {
  5294. var nextYAxis = yAxes[index + 1];
  5295. // We have next axis, bind them:
  5296. if (nextYAxis) {
  5297. resizers[index] = {
  5298. enabled: true,
  5299. controlledAxis: {
  5300. next: [
  5301. pick(nextYAxis.options.id, nextYAxis.options.index)
  5302. ]
  5303. }
  5304. };
  5305. }
  5306. else {
  5307. // Remove binding:
  5308. resizers[index] = {
  5309. enabled: false
  5310. };
  5311. }
  5312. });
  5313. return resizers;
  5314. },
  5315. /**
  5316. * Resize all yAxes (except navigator) to fit the plotting height. Method
  5317. * checks if new axis is added, then shrinks other main axis up to 5 panes.
  5318. * If added is more thatn 5 panes, it rescales all other axes to fit new
  5319. * yAxis.
  5320. *
  5321. * If axis is removed, and we have more than 5 panes, rescales all other
  5322. * axes. If chart has less than 5 panes, first pane receives all extra
  5323. * space.
  5324. *
  5325. * @private
  5326. * @function Highcharts.NavigationBindings#resizeYAxes
  5327. * @param {number} [defaultHeight]
  5328. * Default height for yAxis
  5329. */
  5330. resizeYAxes: function (defaultHeight) {
  5331. defaultHeight = defaultHeight || 20; // in %, but as a number
  5332. var chart = this.chart,
  5333. // Only non-navigator axes
  5334. yAxes = chart.yAxis.filter(bindingsUtils.isNotNavigatorYAxis),
  5335. plotHeight = chart.plotHeight,
  5336. allAxesLength = yAxes.length,
  5337. // Gather current heights (in %)
  5338. positions = this.getYAxisPositions(yAxes,
  5339. plotHeight,
  5340. defaultHeight),
  5341. resizers = this.getYAxisResizers(yAxes),
  5342. allAxesHeight = positions.allAxesHeight,
  5343. changedSpace = defaultHeight;
  5344. // More than 100%
  5345. if (allAxesHeight > 1) {
  5346. // Simple case, add new panes up to 5
  5347. if (allAxesLength < 6) {
  5348. // Added axis, decrease first pane's height:
  5349. positions[0].height = correctFloat(positions[0].height - changedSpace);
  5350. // And update all other "top" positions:
  5351. positions = this.recalculateYAxisPositions(positions, changedSpace);
  5352. }
  5353. else {
  5354. // We have more panes, rescale all others to gain some space,
  5355. // This is new height for upcoming yAxis:
  5356. defaultHeight = 100 / allAxesLength;
  5357. // This is how much we need to take from each other yAxis:
  5358. changedSpace = defaultHeight / (allAxesLength - 1);
  5359. // Now update all positions:
  5360. positions = this.recalculateYAxisPositions(positions, changedSpace, true, -1);
  5361. }
  5362. // Set last position manually:
  5363. positions[allAxesLength - 1] = {
  5364. top: correctFloat(100 - defaultHeight),
  5365. height: defaultHeight
  5366. };
  5367. }
  5368. else {
  5369. // Less than 100%
  5370. changedSpace = correctFloat(1 - allAxesHeight) * 100;
  5371. // Simple case, return first pane it's space:
  5372. if (allAxesLength < 5) {
  5373. positions[0].height = correctFloat(positions[0].height + changedSpace);
  5374. positions = this.recalculateYAxisPositions(positions, changedSpace);
  5375. }
  5376. else {
  5377. // There were more panes, return to each pane a bit of space:
  5378. changedSpace /= allAxesLength;
  5379. // Removed axis, add extra space to the first pane:
  5380. // And update all other positions:
  5381. positions = this.recalculateYAxisPositions(positions, changedSpace, true, 1);
  5382. }
  5383. }
  5384. positions.forEach(function (position, index) {
  5385. // if (index === 0) debugger;
  5386. yAxes[index].update({
  5387. height: position.height + '%',
  5388. top: position.top + '%',
  5389. resize: resizers[index]
  5390. }, false);
  5391. });
  5392. },
  5393. /**
  5394. * Utility to modify calculated positions according to the remaining/needed
  5395. * space. Later, these positions are used in `yAxis.update({ top, height })`
  5396. *
  5397. * @private
  5398. * @function Highcharts.NavigationBindings#recalculateYAxisPositions
  5399. * @param {Array<Highcharts.Dictionary<number>>} positions
  5400. * Default positions of all yAxes.
  5401. * @param {number} changedSpace
  5402. * How much space should be added or removed.
  5403. * @param {boolean} modifyHeight
  5404. * Update only `top` or both `top` and `height`.
  5405. * @param {number} adder
  5406. * `-1` or `1`, to determine whether we should add or remove space.
  5407. *
  5408. * @return {Array<object>}
  5409. * Modified positions,
  5410. */
  5411. recalculateYAxisPositions: function (positions, changedSpace, modifyHeight, adder) {
  5412. positions.forEach(function (position, index) {
  5413. var prevPosition = positions[index - 1];
  5414. position.top = !prevPosition ? 0 :
  5415. correctFloat(prevPosition.height + prevPosition.top);
  5416. if (modifyHeight) {
  5417. position.height = correctFloat(position.height + adder * changedSpace);
  5418. }
  5419. });
  5420. return positions;
  5421. }
  5422. /* eslint-enable valid-jsdoc */
  5423. });
  5424. /**
  5425. * @type {Highcharts.Dictionary<Highcharts.NavigationBindingsOptionsObject>}
  5426. * @since 7.0.0
  5427. * @optionparent navigation.bindings
  5428. */
  5429. var stockToolsBindings = {
  5430. // Line type annotations:
  5431. /**
  5432. * A segment annotation bindings. Includes `start` and one event in `steps`
  5433. * array.
  5434. *
  5435. * @type {Highcharts.NavigationBindingsOptionsObject}
  5436. * @product highstock
  5437. * @default {"className": "highcharts-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5438. */
  5439. segment: {
  5440. /** @ignore-option */
  5441. className: 'highcharts-segment',
  5442. // eslint-disable-next-line valid-jsdoc
  5443. /** @ignore-option */
  5444. start: function (e) {
  5445. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  5446. langKey: 'segment',
  5447. type: 'crookedLine',
  5448. typeOptions: {
  5449. points: [{
  5450. x: coords.xAxis[0].value,
  5451. y: coords.yAxis[0].value
  5452. }, {
  5453. x: coords.xAxis[0].value,
  5454. y: coords.yAxis[0].value
  5455. }]
  5456. }
  5457. }, navigation.annotationsOptions, navigation.bindings.segment.annotationsOptions);
  5458. return this.chart.addAnnotation(options);
  5459. },
  5460. /** @ignore-option */
  5461. steps: [
  5462. bindingsUtils.updateNthPoint(1)
  5463. ]
  5464. },
  5465. /**
  5466. * A segment with an arrow annotation bindings. Includes `start` and one
  5467. * event in `steps` array.
  5468. *
  5469. * @type {Highcharts.NavigationBindingsOptionsObject}
  5470. * @product highstock
  5471. * @default {"className": "highcharts-arrow-segment", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5472. */
  5473. arrowSegment: {
  5474. /** @ignore-option */
  5475. className: 'highcharts-arrow-segment',
  5476. // eslint-disable-next-line valid-jsdoc
  5477. /** @ignore-option */
  5478. start: function (e) {
  5479. var coords = this.chart.pointer.getCoordinates(e),
  5480. navigation = this.chart.options.navigation,
  5481. options = merge({
  5482. langKey: 'arrowSegment',
  5483. type: 'crookedLine',
  5484. typeOptions: {
  5485. line: {
  5486. markerEnd: 'arrow'
  5487. },
  5488. points: [{
  5489. x: coords.xAxis[0].value,
  5490. y: coords.yAxis[0].value
  5491. }, {
  5492. x: coords.xAxis[0].value,
  5493. y: coords.yAxis[0].value
  5494. }]
  5495. }
  5496. },
  5497. navigation.annotationsOptions,
  5498. navigation.bindings.arrowSegment.annotationsOptions);
  5499. return this.chart.addAnnotation(options);
  5500. },
  5501. /** @ignore-option */
  5502. steps: [
  5503. bindingsUtils.updateNthPoint(1)
  5504. ]
  5505. },
  5506. /**
  5507. * A ray annotation bindings. Includes `start` and one event in `steps`
  5508. * array.
  5509. *
  5510. * @type {Highcharts.NavigationBindingsOptionsObject}
  5511. * @product highstock
  5512. * @default {"className": "highcharts-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5513. */
  5514. ray: {
  5515. /** @ignore-option */
  5516. className: 'highcharts-ray',
  5517. // eslint-disable-next-line valid-jsdoc
  5518. /** @ignore-option */
  5519. start: function (e) {
  5520. var coords = this.chart.pointer.getCoordinates(e),
  5521. navigation = this.chart.options.navigation,
  5522. options = merge({
  5523. langKey: 'ray',
  5524. type: 'crookedLine',
  5525. typeOptions: {
  5526. type: 'ray',
  5527. points: [{
  5528. x: coords.xAxis[0].value,
  5529. y: coords.yAxis[0].value
  5530. }, {
  5531. x: coords.xAxis[0].value,
  5532. y: coords.yAxis[0].value
  5533. }]
  5534. }
  5535. },
  5536. navigation.annotationsOptions,
  5537. navigation.bindings.ray.annotationsOptions);
  5538. return this.chart.addAnnotation(options);
  5539. },
  5540. /** @ignore-option */
  5541. steps: [
  5542. bindingsUtils.updateNthPoint(1)
  5543. ]
  5544. },
  5545. /**
  5546. * A ray with an arrow annotation bindings. Includes `start` and one event
  5547. * in `steps` array.
  5548. *
  5549. * @type {Highcharts.NavigationBindingsOptionsObject}
  5550. * @product highstock
  5551. * @default {"className": "highcharts-arrow-ray", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5552. */
  5553. arrowRay: {
  5554. /** @ignore-option */
  5555. className: 'highcharts-arrow-ray',
  5556. // eslint-disable-next-line valid-jsdoc
  5557. /** @ignore-option */
  5558. start: function (e) {
  5559. var coords = this.chart.pointer.getCoordinates(e),
  5560. navigation = this.chart.options.navigation,
  5561. options = merge({
  5562. langKey: 'arrowRay',
  5563. type: 'infinityLine',
  5564. typeOptions: {
  5565. type: 'ray',
  5566. line: {
  5567. markerEnd: 'arrow'
  5568. },
  5569. points: [{
  5570. x: coords.xAxis[0].value,
  5571. y: coords.yAxis[0].value
  5572. }, {
  5573. x: coords.xAxis[0].value,
  5574. y: coords.yAxis[0].value
  5575. }]
  5576. }
  5577. },
  5578. navigation.annotationsOptions,
  5579. navigation.bindings.arrowRay.annotationsOptions);
  5580. return this.chart.addAnnotation(options);
  5581. },
  5582. /** @ignore-option */
  5583. steps: [
  5584. bindingsUtils.updateNthPoint(1)
  5585. ]
  5586. },
  5587. /**
  5588. * A line annotation. Includes `start` and one event in `steps` array.
  5589. *
  5590. * @type {Highcharts.NavigationBindingsOptionsObject}
  5591. * @product highstock
  5592. * @default {"className": "highcharts-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5593. */
  5594. infinityLine: {
  5595. /** @ignore-option */
  5596. className: 'highcharts-infinity-line',
  5597. // eslint-disable-next-line valid-jsdoc
  5598. /** @ignore-option */
  5599. start: function (e) {
  5600. var coords = this.chart.pointer.getCoordinates(e),
  5601. navigation = this.chart.options.navigation,
  5602. options = merge({
  5603. langKey: 'infinityLine',
  5604. type: 'infinityLine',
  5605. typeOptions: {
  5606. type: 'line',
  5607. points: [{
  5608. x: coords.xAxis[0].value,
  5609. y: coords.yAxis[0].value
  5610. }, {
  5611. x: coords.xAxis[0].value,
  5612. y: coords.yAxis[0].value
  5613. }]
  5614. }
  5615. },
  5616. navigation.annotationsOptions,
  5617. navigation.bindings.infinityLine.annotationsOptions);
  5618. return this.chart.addAnnotation(options);
  5619. },
  5620. /** @ignore-option */
  5621. steps: [
  5622. bindingsUtils.updateNthPoint(1)
  5623. ]
  5624. },
  5625. /**
  5626. * A line with arrow annotation. Includes `start` and one event in `steps`
  5627. * array.
  5628. *
  5629. * @type {Highcharts.NavigationBindingsOptionsObject}
  5630. * @product highstock
  5631. * @default {"className": "highcharts-arrow-infinity-line", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5632. */
  5633. arrowInfinityLine: {
  5634. /** @ignore-option */
  5635. className: 'highcharts-arrow-infinity-line',
  5636. // eslint-disable-next-line valid-jsdoc
  5637. /** @ignore-option */
  5638. start: function (e) {
  5639. var coords = this.chart.pointer.getCoordinates(e),
  5640. navigation = this.chart.options.navigation,
  5641. options = merge({
  5642. langKey: 'arrowInfinityLine',
  5643. type: 'infinityLine',
  5644. typeOptions: {
  5645. type: 'line',
  5646. line: {
  5647. markerEnd: 'arrow'
  5648. },
  5649. points: [{
  5650. x: coords.xAxis[0].value,
  5651. y: coords.yAxis[0].value
  5652. }, {
  5653. x: coords.xAxis[0].value,
  5654. y: coords.yAxis[0].value
  5655. }]
  5656. }
  5657. },
  5658. navigation.annotationsOptions,
  5659. navigation.bindings.arrowInfinityLine.annotationsOptions);
  5660. return this.chart.addAnnotation(options);
  5661. },
  5662. /** @ignore-option */
  5663. steps: [
  5664. bindingsUtils.updateNthPoint(1)
  5665. ]
  5666. },
  5667. /**
  5668. * A horizontal line annotation. Includes `start` event.
  5669. *
  5670. * @type {Highcharts.NavigationBindingsOptionsObject}
  5671. * @product highstock
  5672. * @default {"className": "highcharts-horizontal-line", "start": function() {}, "annotationsOptions": {}}
  5673. */
  5674. horizontalLine: {
  5675. /** @ignore-option */
  5676. className: 'highcharts-horizontal-line',
  5677. // eslint-disable-next-line valid-jsdoc
  5678. /** @ignore-option */
  5679. start: function (e) {
  5680. var coords = this.chart.pointer.getCoordinates(e),
  5681. navigation = this.chart.options.navigation,
  5682. options = merge({
  5683. langKey: 'horizontalLine',
  5684. type: 'infinityLine',
  5685. draggable: 'y',
  5686. typeOptions: {
  5687. type: 'horizontalLine',
  5688. points: [{
  5689. x: coords.xAxis[0].value,
  5690. y: coords.yAxis[0].value
  5691. }]
  5692. }
  5693. },
  5694. navigation.annotationsOptions,
  5695. navigation.bindings.horizontalLine.annotationsOptions);
  5696. this.chart.addAnnotation(options);
  5697. }
  5698. },
  5699. /**
  5700. * A vertical line annotation. Includes `start` event.
  5701. *
  5702. * @type {Highcharts.NavigationBindingsOptionsObject}
  5703. * @product highstock
  5704. * @default {"className": "highcharts-vertical-line", "start": function() {}, "annotationsOptions": {}}
  5705. */
  5706. verticalLine: {
  5707. /** @ignore-option */
  5708. className: 'highcharts-vertical-line',
  5709. // eslint-disable-next-line valid-jsdoc
  5710. /** @ignore-option */
  5711. start: function (e) {
  5712. var coords = this.chart.pointer.getCoordinates(e),
  5713. navigation = this.chart.options.navigation,
  5714. options = merge({
  5715. langKey: 'verticalLine',
  5716. type: 'infinityLine',
  5717. draggable: 'x',
  5718. typeOptions: {
  5719. type: 'verticalLine',
  5720. points: [{
  5721. x: coords.xAxis[0].value,
  5722. y: coords.yAxis[0].value
  5723. }]
  5724. }
  5725. },
  5726. navigation.annotationsOptions,
  5727. navigation.bindings.verticalLine.annotationsOptions);
  5728. this.chart.addAnnotation(options);
  5729. }
  5730. },
  5731. /**
  5732. * Crooked line (three points) annotation bindings. Includes `start` and two
  5733. * events in `steps` (for second and third points in crooked line) array.
  5734. *
  5735. * @type {Highcharts.NavigationBindingsOptionsObject}
  5736. * @product highstock
  5737. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  5738. */
  5739. // Crooked Line type annotations:
  5740. crooked3: {
  5741. /** @ignore-option */
  5742. className: 'highcharts-crooked3',
  5743. // eslint-disable-next-line valid-jsdoc
  5744. /** @ignore-option */
  5745. start: function (e) {
  5746. var coords = this.chart.pointer.getCoordinates(e),
  5747. navigation = this.chart.options.navigation,
  5748. options = merge({
  5749. langKey: 'crooked3',
  5750. type: 'crookedLine',
  5751. typeOptions: {
  5752. points: [{
  5753. x: coords.xAxis[0].value,
  5754. y: coords.yAxis[0].value
  5755. }, {
  5756. x: coords.xAxis[0].value,
  5757. y: coords.yAxis[0].value
  5758. }, {
  5759. x: coords.xAxis[0].value,
  5760. y: coords.yAxis[0].value
  5761. }]
  5762. }
  5763. },
  5764. navigation.annotationsOptions,
  5765. navigation.bindings.crooked3.annotationsOptions);
  5766. return this.chart.addAnnotation(options);
  5767. },
  5768. /** @ignore-option */
  5769. steps: [
  5770. bindingsUtils.updateNthPoint(1),
  5771. bindingsUtils.updateNthPoint(2)
  5772. ]
  5773. },
  5774. /**
  5775. * Crooked line (five points) annotation bindings. Includes `start` and four
  5776. * events in `steps` (for all consequent points in crooked line) array.
  5777. *
  5778. * @type {Highcharts.NavigationBindingsOptionsObject}
  5779. * @product highstock
  5780. * @default {"className": "highcharts-crooked3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  5781. */
  5782. crooked5: {
  5783. /** @ignore-option */
  5784. className: 'highcharts-crooked5',
  5785. // eslint-disable-next-line valid-jsdoc
  5786. /** @ignore-option */
  5787. start: function (e) {
  5788. var coords = this.chart.pointer.getCoordinates(e),
  5789. navigation = this.chart.options.navigation,
  5790. options = merge({
  5791. langKey: 'crookedLine',
  5792. type: 'crookedLine',
  5793. typeOptions: {
  5794. points: [{
  5795. x: coords.xAxis[0].value,
  5796. y: coords.yAxis[0].value
  5797. }, {
  5798. x: coords.xAxis[0].value,
  5799. y: coords.yAxis[0].value
  5800. }, {
  5801. x: coords.xAxis[0].value,
  5802. y: coords.yAxis[0].value
  5803. }, {
  5804. x: coords.xAxis[0].value,
  5805. y: coords.yAxis[0].value
  5806. }, {
  5807. x: coords.xAxis[0].value,
  5808. y: coords.yAxis[0].value
  5809. }]
  5810. }
  5811. },
  5812. navigation.annotationsOptions,
  5813. navigation.bindings.crooked5.annotationsOptions);
  5814. return this.chart.addAnnotation(options);
  5815. },
  5816. /** @ignore-option */
  5817. steps: [
  5818. bindingsUtils.updateNthPoint(1),
  5819. bindingsUtils.updateNthPoint(2),
  5820. bindingsUtils.updateNthPoint(3),
  5821. bindingsUtils.updateNthPoint(4)
  5822. ]
  5823. },
  5824. /**
  5825. * Elliott wave (three points) annotation bindings. Includes `start` and two
  5826. * events in `steps` (for second and third points) array.
  5827. *
  5828. * @type {Highcharts.NavigationBindingsOptionsObject}
  5829. * @product highstock
  5830. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  5831. */
  5832. elliott3: {
  5833. /** @ignore-option */
  5834. className: 'highcharts-elliott3',
  5835. // eslint-disable-next-line valid-jsdoc
  5836. /** @ignore-option */
  5837. start: function (e) {
  5838. var coords = this.chart.pointer.getCoordinates(e),
  5839. navigation = this.chart.options.navigation,
  5840. options = merge({
  5841. langKey: 'elliott3',
  5842. type: 'elliottWave',
  5843. typeOptions: {
  5844. points: [{
  5845. x: coords.xAxis[0].value,
  5846. y: coords.yAxis[0].value
  5847. }, {
  5848. x: coords.xAxis[0].value,
  5849. y: coords.yAxis[0].value
  5850. }, {
  5851. x: coords.xAxis[0].value,
  5852. y: coords.yAxis[0].value
  5853. }, {
  5854. x: coords.xAxis[0].value,
  5855. y: coords.yAxis[0].value
  5856. }]
  5857. },
  5858. labelOptions: {
  5859. style: {
  5860. color: '#666666'
  5861. }
  5862. }
  5863. },
  5864. navigation.annotationsOptions,
  5865. navigation.bindings.elliott3.annotationsOptions);
  5866. return this.chart.addAnnotation(options);
  5867. },
  5868. /** @ignore-option */
  5869. steps: [
  5870. bindingsUtils.updateNthPoint(1),
  5871. bindingsUtils.updateNthPoint(2),
  5872. bindingsUtils.updateNthPoint(3)
  5873. ]
  5874. },
  5875. /**
  5876. * Elliott wave (five points) annotation bindings. Includes `start` and four
  5877. * event in `steps` (for all consequent points in Elliott wave) array.
  5878. *
  5879. * @type {Highcharts.NavigationBindingsOptionsObject}
  5880. * @product highstock
  5881. * @default {"className": "highcharts-elliott3", "start": function() {}, "steps": [function() {}, function() {}, function() {}, function() {}], "annotationsOptions": {}}
  5882. */
  5883. elliott5: {
  5884. /** @ignore-option */
  5885. className: 'highcharts-elliott5',
  5886. // eslint-disable-next-line valid-jsdoc
  5887. /** @ignore-option */
  5888. start: function (e) {
  5889. var coords = this.chart.pointer.getCoordinates(e),
  5890. navigation = this.chart.options.navigation,
  5891. options = merge({
  5892. langKey: 'elliott5',
  5893. type: 'elliottWave',
  5894. typeOptions: {
  5895. points: [{
  5896. x: coords.xAxis[0].value,
  5897. y: coords.yAxis[0].value
  5898. }, {
  5899. x: coords.xAxis[0].value,
  5900. y: coords.yAxis[0].value
  5901. }, {
  5902. x: coords.xAxis[0].value,
  5903. y: coords.yAxis[0].value
  5904. }, {
  5905. x: coords.xAxis[0].value,
  5906. y: coords.yAxis[0].value
  5907. }, {
  5908. x: coords.xAxis[0].value,
  5909. y: coords.yAxis[0].value
  5910. }, {
  5911. x: coords.xAxis[0].value,
  5912. y: coords.yAxis[0].value
  5913. }]
  5914. },
  5915. labelOptions: {
  5916. style: {
  5917. color: '#666666'
  5918. }
  5919. }
  5920. },
  5921. navigation.annotationsOptions,
  5922. navigation.bindings.elliott5.annotationsOptions);
  5923. return this.chart.addAnnotation(options);
  5924. },
  5925. /** @ignore-option */
  5926. steps: [
  5927. bindingsUtils.updateNthPoint(1),
  5928. bindingsUtils.updateNthPoint(2),
  5929. bindingsUtils.updateNthPoint(3),
  5930. bindingsUtils.updateNthPoint(4),
  5931. bindingsUtils.updateNthPoint(5)
  5932. ]
  5933. },
  5934. /**
  5935. * A measure (x-dimension) annotation bindings. Includes `start` and one
  5936. * event in `steps` array.
  5937. *
  5938. * @type {Highcharts.NavigationBindingsOptionsObject}
  5939. * @product highstock
  5940. * @default {"className": "highcharts-measure-x", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5941. */
  5942. measureX: {
  5943. /** @ignore-option */
  5944. className: 'highcharts-measure-x',
  5945. // eslint-disable-next-line valid-jsdoc
  5946. /** @ignore-option */
  5947. start: function (e) {
  5948. var coords = this.chart.pointer.getCoordinates(e),
  5949. navigation = this.chart.options.navigation,
  5950. options = merge({
  5951. langKey: 'measure',
  5952. type: 'measure',
  5953. typeOptions: {
  5954. selectType: 'x',
  5955. point: {
  5956. x: coords.xAxis[0].value,
  5957. y: coords.yAxis[0].value,
  5958. xAxis: 0,
  5959. yAxis: 0
  5960. },
  5961. crosshairX: {
  5962. strokeWidth: 1,
  5963. stroke: '#000000'
  5964. },
  5965. crosshairY: {
  5966. enabled: false,
  5967. strokeWidth: 0,
  5968. stroke: '#000000'
  5969. },
  5970. background: {
  5971. width: 0,
  5972. height: 0,
  5973. strokeWidth: 0,
  5974. stroke: '#ffffff'
  5975. }
  5976. },
  5977. labelOptions: {
  5978. style: {
  5979. color: '#666666'
  5980. }
  5981. }
  5982. },
  5983. navigation.annotationsOptions,
  5984. navigation.bindings.measureX.annotationsOptions);
  5985. return this.chart.addAnnotation(options);
  5986. },
  5987. /** @ignore-option */
  5988. steps: [
  5989. bindingsUtils.updateRectSize
  5990. ]
  5991. },
  5992. /**
  5993. * A measure (y-dimension) annotation bindings. Includes `start` and one
  5994. * event in `steps` array.
  5995. *
  5996. * @type {Highcharts.NavigationBindingsOptionsObject}
  5997. * @product highstock
  5998. * @default {"className": "highcharts-measure-y", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  5999. */
  6000. measureY: {
  6001. /** @ignore-option */
  6002. className: 'highcharts-measure-y',
  6003. // eslint-disable-next-line valid-jsdoc
  6004. /** @ignore-option */
  6005. start: function (e) {
  6006. var coords = this.chart.pointer.getCoordinates(e),
  6007. navigation = this.chart.options.navigation,
  6008. options = merge({
  6009. langKey: 'measure',
  6010. type: 'measure',
  6011. typeOptions: {
  6012. selectType: 'y',
  6013. point: {
  6014. x: coords.xAxis[0].value,
  6015. y: coords.yAxis[0].value,
  6016. xAxis: 0,
  6017. yAxis: 0
  6018. },
  6019. crosshairX: {
  6020. enabled: false,
  6021. strokeWidth: 0,
  6022. stroke: '#000000'
  6023. },
  6024. crosshairY: {
  6025. strokeWidth: 1,
  6026. stroke: '#000000'
  6027. },
  6028. background: {
  6029. width: 0,
  6030. height: 0,
  6031. strokeWidth: 0,
  6032. stroke: '#ffffff'
  6033. }
  6034. },
  6035. labelOptions: {
  6036. style: {
  6037. color: '#666666'
  6038. }
  6039. }
  6040. },
  6041. navigation.annotationsOptions,
  6042. navigation.bindings.measureY.annotationsOptions);
  6043. return this.chart.addAnnotation(options);
  6044. },
  6045. /** @ignore-option */
  6046. steps: [
  6047. bindingsUtils.updateRectSize
  6048. ]
  6049. },
  6050. /**
  6051. * A measure (xy-dimension) annotation bindings. Includes `start` and one
  6052. * event in `steps` array.
  6053. *
  6054. * @type {Highcharts.NavigationBindingsOptionsObject}
  6055. * @product highstock
  6056. * @default {"className": "highcharts-measure-xy", "start": function() {}, "steps": [function() {}], "annotationsOptions": {}}
  6057. */
  6058. measureXY: {
  6059. /** @ignore-option */
  6060. className: 'highcharts-measure-xy',
  6061. // eslint-disable-next-line valid-jsdoc
  6062. /** @ignore-option */
  6063. start: function (e) {
  6064. var coords = this.chart.pointer.getCoordinates(e),
  6065. navigation = this.chart.options.navigation,
  6066. options = merge({
  6067. langKey: 'measure',
  6068. type: 'measure',
  6069. typeOptions: {
  6070. selectType: 'xy',
  6071. point: {
  6072. x: coords.xAxis[0].value,
  6073. y: coords.yAxis[0].value,
  6074. xAxis: 0,
  6075. yAxis: 0
  6076. },
  6077. background: {
  6078. width: 0,
  6079. height: 0,
  6080. strokeWidth: 10
  6081. },
  6082. crosshairX: {
  6083. strokeWidth: 1,
  6084. stroke: '#000000'
  6085. },
  6086. crosshairY: {
  6087. strokeWidth: 1,
  6088. stroke: '#000000'
  6089. }
  6090. },
  6091. labelOptions: {
  6092. style: {
  6093. color: '#666666'
  6094. }
  6095. }
  6096. },
  6097. navigation.annotationsOptions,
  6098. navigation.bindings.measureXY.annotationsOptions);
  6099. return this.chart.addAnnotation(options);
  6100. },
  6101. /** @ignore-option */
  6102. steps: [
  6103. bindingsUtils.updateRectSize
  6104. ]
  6105. },
  6106. // Advanced type annotations:
  6107. /**
  6108. * A fibonacci annotation bindings. Includes `start` and two events in
  6109. * `steps` array (updates second point, then height).
  6110. *
  6111. * @type {Highcharts.NavigationBindingsOptionsObject}
  6112. * @product highstock
  6113. * @default {"className": "highcharts-fibonacci", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6114. */
  6115. fibonacci: {
  6116. /** @ignore-option */
  6117. className: 'highcharts-fibonacci',
  6118. // eslint-disable-next-line valid-jsdoc
  6119. /** @ignore-option */
  6120. start: function (e) {
  6121. var coords = this.chart.pointer.getCoordinates(e),
  6122. navigation = this.chart.options.navigation,
  6123. options = merge({
  6124. langKey: 'fibonacci',
  6125. type: 'fibonacci',
  6126. typeOptions: {
  6127. points: [{
  6128. x: coords.xAxis[0].value,
  6129. y: coords.yAxis[0].value
  6130. }, {
  6131. x: coords.xAxis[0].value,
  6132. y: coords.yAxis[0].value
  6133. }]
  6134. },
  6135. labelOptions: {
  6136. style: {
  6137. color: '#666666'
  6138. }
  6139. }
  6140. },
  6141. navigation.annotationsOptions,
  6142. navigation.bindings.fibonacci.annotationsOptions);
  6143. return this.chart.addAnnotation(options);
  6144. },
  6145. /** @ignore-option */
  6146. steps: [
  6147. bindingsUtils.updateNthPoint(1),
  6148. bindingsUtils.updateHeight
  6149. ]
  6150. },
  6151. /**
  6152. * A parallel channel (tunnel) annotation bindings. Includes `start` and
  6153. * two events in `steps` array (updates second point, then height).
  6154. *
  6155. * @type {Highcharts.NavigationBindingsOptionsObject}
  6156. * @product highstock
  6157. * @default {"className": "highcharts-parallel-channel", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6158. */
  6159. parallelChannel: {
  6160. /** @ignore-option */
  6161. className: 'highcharts-parallel-channel',
  6162. // eslint-disable-next-line valid-jsdoc
  6163. /** @ignore-option */
  6164. start: function (e) {
  6165. var coords = this.chart.pointer.getCoordinates(e),
  6166. navigation = this.chart.options.navigation,
  6167. options = merge({
  6168. langKey: 'parallelChannel',
  6169. type: 'tunnel',
  6170. typeOptions: {
  6171. points: [{
  6172. x: coords.xAxis[0].value,
  6173. y: coords.yAxis[0].value
  6174. }, {
  6175. x: coords.xAxis[0].value,
  6176. y: coords.yAxis[0].value
  6177. }]
  6178. }
  6179. },
  6180. navigation.annotationsOptions,
  6181. navigation.bindings.parallelChannel.annotationsOptions);
  6182. return this.chart.addAnnotation(options);
  6183. },
  6184. /** @ignore-option */
  6185. steps: [
  6186. bindingsUtils.updateNthPoint(1),
  6187. bindingsUtils.updateHeight
  6188. ]
  6189. },
  6190. /**
  6191. * An Andrew's pitchfork annotation bindings. Includes `start` and two
  6192. * events in `steps` array (sets second and third control points).
  6193. *
  6194. * @type {Highcharts.NavigationBindingsOptionsObject}
  6195. * @product highstock
  6196. * @default {"className": "highcharts-pitchfork", "start": function() {}, "steps": [function() {}, function() {}], "annotationsOptions": {}}
  6197. */
  6198. pitchfork: {
  6199. /** @ignore-option */
  6200. className: 'highcharts-pitchfork',
  6201. // eslint-disable-next-line valid-jsdoc
  6202. /** @ignore-option */
  6203. start: function (e) {
  6204. var coords = this.chart.pointer.getCoordinates(e), navigation = this.chart.options.navigation, options = merge({
  6205. langKey: 'pitchfork',
  6206. type: 'pitchfork',
  6207. typeOptions: {
  6208. points: [{
  6209. x: coords.xAxis[0].value,
  6210. y: coords.yAxis[0].value,
  6211. controlPoint: {
  6212. style: {
  6213. fill: 'red'
  6214. }
  6215. }
  6216. }, {
  6217. x: coords.xAxis[0].value,
  6218. y: coords.yAxis[0].value
  6219. }, {
  6220. x: coords.xAxis[0].value,
  6221. y: coords.yAxis[0].value
  6222. }],
  6223. innerBackground: {
  6224. fill: 'rgba(100, 170, 255, 0.8)'
  6225. }
  6226. },
  6227. shapeOptions: {
  6228. strokeWidth: 2
  6229. }
  6230. }, navigation.annotationsOptions, navigation.bindings.pitchfork.annotationsOptions);
  6231. return this.chart.addAnnotation(options);
  6232. },
  6233. /** @ignore-option */
  6234. steps: [
  6235. bindingsUtils.updateNthPoint(1),
  6236. bindingsUtils.updateNthPoint(2)
  6237. ]
  6238. },
  6239. // Labels with arrow and auto increments
  6240. /**
  6241. * A vertical counter annotation bindings. Includes `start` event. On click,
  6242. * finds the closest point and marks it with a numeric annotation -
  6243. * incrementing counter on each add.
  6244. *
  6245. * @type {Highcharts.NavigationBindingsOptionsObject}
  6246. * @product highstock
  6247. * @default {"className": "highcharts-vertical-counter", "start": function() {}, "annotationsOptions": {}}
  6248. */
  6249. verticalCounter: {
  6250. /** @ignore-option */
  6251. className: 'highcharts-vertical-counter',
  6252. // eslint-disable-next-line valid-jsdoc
  6253. /** @ignore-option */
  6254. start: function (e) {
  6255. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, verticalCounter = !defined(this.verticalCounter) ? 0 :
  6256. this.verticalCounter, options = merge({
  6257. langKey: 'verticalCounter',
  6258. type: 'verticalLine',
  6259. typeOptions: {
  6260. point: {
  6261. x: closestPoint.x,
  6262. y: closestPoint.y,
  6263. xAxis: closestPoint.xAxis,
  6264. yAxis: closestPoint.yAxis
  6265. },
  6266. label: {
  6267. offset: closestPoint.below ? 40 : -40,
  6268. text: verticalCounter.toString()
  6269. }
  6270. },
  6271. labelOptions: {
  6272. style: {
  6273. color: '#666666',
  6274. fontSize: '11px'
  6275. }
  6276. },
  6277. shapeOptions: {
  6278. stroke: 'rgba(0, 0, 0, 0.75)',
  6279. strokeWidth: 1
  6280. }
  6281. }, navigation.annotationsOptions, navigation.bindings.verticalCounter.annotationsOptions), annotation;
  6282. annotation = this.chart.addAnnotation(options);
  6283. verticalCounter++;
  6284. annotation.options.events.click.call(annotation, {});
  6285. }
  6286. },
  6287. /**
  6288. * A vertical arrow annotation bindings. Includes `start` event. On click,
  6289. * finds the closest point and marks it with an arrow and a label with
  6290. * value.
  6291. *
  6292. * @type {Highcharts.NavigationBindingsOptionsObject}
  6293. * @product highstock
  6294. * @default {"className": "highcharts-vertical-label", "start": function() {}, "annotationsOptions": {}}
  6295. */
  6296. verticalLabel: {
  6297. /** @ignore-option */
  6298. className: 'highcharts-vertical-label',
  6299. // eslint-disable-next-line valid-jsdoc
  6300. /** @ignore-option */
  6301. start: function (e) {
  6302. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, options = merge({
  6303. langKey: 'verticalLabel',
  6304. type: 'verticalLine',
  6305. typeOptions: {
  6306. point: {
  6307. x: closestPoint.x,
  6308. y: closestPoint.y,
  6309. xAxis: closestPoint.xAxis,
  6310. yAxis: closestPoint.yAxis
  6311. },
  6312. label: {
  6313. offset: closestPoint.below ? 40 : -40
  6314. }
  6315. },
  6316. labelOptions: {
  6317. style: {
  6318. color: '#666666',
  6319. fontSize: '11px'
  6320. }
  6321. },
  6322. shapeOptions: {
  6323. stroke: 'rgba(0, 0, 0, 0.75)',
  6324. strokeWidth: 1
  6325. }
  6326. }, navigation.annotationsOptions, navigation.bindings.verticalLabel.annotationsOptions), annotation;
  6327. annotation = this.chart.addAnnotation(options);
  6328. annotation.options.events.click.call(annotation, {});
  6329. }
  6330. },
  6331. /**
  6332. * A vertical arrow annotation bindings. Includes `start` event. On click,
  6333. * finds the closest point and marks it with an arrow. Green arrow when
  6334. * pointing from above, red when pointing from below the point.
  6335. *
  6336. * @type {Highcharts.NavigationBindingsOptionsObject}
  6337. * @product highstock
  6338. * @default {"className": "highcharts-vertical-arrow", "start": function() {}, "annotationsOptions": {}}
  6339. */
  6340. verticalArrow: {
  6341. /** @ignore-option */
  6342. className: 'highcharts-vertical-arrow',
  6343. // eslint-disable-next-line valid-jsdoc
  6344. /** @ignore-option */
  6345. start: function (e) {
  6346. var closestPoint = bindingsUtils.attractToPoint(e, this.chart), navigation = this.chart.options.navigation, options = merge({
  6347. langKey: 'verticalArrow',
  6348. type: 'verticalLine',
  6349. typeOptions: {
  6350. point: {
  6351. x: closestPoint.x,
  6352. y: closestPoint.y,
  6353. xAxis: closestPoint.xAxis,
  6354. yAxis: closestPoint.yAxis
  6355. },
  6356. label: {
  6357. offset: closestPoint.below ? 40 : -40,
  6358. format: ' '
  6359. },
  6360. connector: {
  6361. fill: 'none',
  6362. stroke: closestPoint.below ? 'red' : 'green'
  6363. }
  6364. },
  6365. shapeOptions: {
  6366. stroke: 'rgba(0, 0, 0, 0.75)',
  6367. strokeWidth: 1
  6368. }
  6369. }, navigation.annotationsOptions, navigation.bindings.verticalArrow.annotationsOptions), annotation;
  6370. annotation = this.chart.addAnnotation(options);
  6371. annotation.options.events.click.call(annotation, {});
  6372. }
  6373. },
  6374. // Flag types:
  6375. /**
  6376. * A flag series bindings. Includes `start` event. On click, finds the
  6377. * closest point and marks it with a flag with `'circlepin'` shape.
  6378. *
  6379. * @type {Highcharts.NavigationBindingsOptionsObject}
  6380. * @product highstock
  6381. * @default {"className": "highcharts-flag-circlepin", "start": function() {}}
  6382. */
  6383. flagCirclepin: {
  6384. /** @ignore-option */
  6385. className: 'highcharts-flag-circlepin',
  6386. /** @ignore-option */
  6387. start: bindingsUtils.addFlagFromForm('circlepin')
  6388. },
  6389. /**
  6390. * A flag series bindings. Includes `start` event. On click, finds the
  6391. * closest point and marks it with a flag with `'diamondpin'` shape.
  6392. *
  6393. * @type {Highcharts.NavigationBindingsOptionsObject}
  6394. * @product highstock
  6395. * @default {"className": "highcharts-flag-diamondpin", "start": function() {}}
  6396. */
  6397. flagDiamondpin: {
  6398. /** @ignore-option */
  6399. className: 'highcharts-flag-diamondpin',
  6400. /** @ignore-option */
  6401. start: bindingsUtils.addFlagFromForm('flag')
  6402. },
  6403. /**
  6404. * A flag series bindings. Includes `start` event.
  6405. * On click, finds the closest point and marks it with a flag with
  6406. * `'squarepin'` shape.
  6407. *
  6408. * @type {Highcharts.NavigationBindingsOptionsObject}
  6409. * @product highstock
  6410. * @default {"className": "highcharts-flag-squarepin", "start": function() {}}
  6411. */
  6412. flagSquarepin: {
  6413. /** @ignore-option */
  6414. className: 'highcharts-flag-squarepin',
  6415. /** @ignore-option */
  6416. start: bindingsUtils.addFlagFromForm('squarepin')
  6417. },
  6418. /**
  6419. * A flag series bindings. Includes `start` event.
  6420. * On click, finds the closest point and marks it with a flag without pin
  6421. * shape.
  6422. *
  6423. * @type {Highcharts.NavigationBindingsOptionsObject}
  6424. * @product highstock
  6425. * @default {"className": "highcharts-flag-simplepin", "start": function() {}}
  6426. */
  6427. flagSimplepin: {
  6428. /** @ignore-option */
  6429. className: 'highcharts-flag-simplepin',
  6430. /** @ignore-option */
  6431. start: bindingsUtils.addFlagFromForm('nopin')
  6432. },
  6433. // Other tools:
  6434. /**
  6435. * Enables zooming in xAxis on a chart. Includes `start` event which
  6436. * changes [chart.zoomType](#chart.zoomType).
  6437. *
  6438. * @type {Highcharts.NavigationBindingsOptionsObject}
  6439. * @product highstock
  6440. * @default {"className": "highcharts-zoom-x", "init": function() {}}
  6441. */
  6442. zoomX: {
  6443. /** @ignore-option */
  6444. className: 'highcharts-zoom-x',
  6445. // eslint-disable-next-line valid-jsdoc
  6446. /** @ignore-option */
  6447. init: function (button) {
  6448. this.chart.update({
  6449. chart: {
  6450. zoomType: 'x'
  6451. }
  6452. });
  6453. fireEvent(this, 'deselectButton', { button: button });
  6454. }
  6455. },
  6456. /**
  6457. * Enables zooming in yAxis on a chart. Includes `start` event which
  6458. * changes [chart.zoomType](#chart.zoomType).
  6459. *
  6460. * @type {Highcharts.NavigationBindingsOptionsObject}
  6461. * @product highstock
  6462. * @default {"className": "highcharts-zoom-y", "init": function() {}}
  6463. */
  6464. zoomY: {
  6465. /** @ignore-option */
  6466. className: 'highcharts-zoom-y',
  6467. // eslint-disable-next-line valid-jsdoc
  6468. /** @ignore-option */
  6469. init: function (button) {
  6470. this.chart.update({
  6471. chart: {
  6472. zoomType: 'y'
  6473. }
  6474. });
  6475. fireEvent(this, 'deselectButton', { button: button });
  6476. }
  6477. },
  6478. /**
  6479. * Enables zooming in xAxis and yAxis on a chart. Includes `start` event
  6480. * which changes [chart.zoomType](#chart.zoomType).
  6481. *
  6482. * @type {Highcharts.NavigationBindingsOptionsObject}
  6483. * @product highstock
  6484. * @default {"className": "highcharts-zoom-xy", "init": function() {}}
  6485. */
  6486. zoomXY: {
  6487. /** @ignore-option */
  6488. className: 'highcharts-zoom-xy',
  6489. // eslint-disable-next-line valid-jsdoc
  6490. /** @ignore-option */
  6491. init: function (button) {
  6492. this.chart.update({
  6493. chart: {
  6494. zoomType: 'xy'
  6495. }
  6496. });
  6497. fireEvent(this, 'deselectButton', { button: button });
  6498. }
  6499. },
  6500. /**
  6501. * Changes main series to `'line'` type.
  6502. *
  6503. * @type {Highcharts.NavigationBindingsOptionsObject}
  6504. * @product highstock
  6505. * @default {"className": "highcharts-series-type-line", "init": function() {}}
  6506. */
  6507. seriesTypeLine: {
  6508. /** @ignore-option */
  6509. className: 'highcharts-series-type-line',
  6510. // eslint-disable-next-line valid-jsdoc
  6511. /** @ignore-option */
  6512. init: function (button) {
  6513. this.chart.series[0].update({
  6514. type: 'line',
  6515. useOhlcData: true
  6516. });
  6517. fireEvent(this, 'deselectButton', { button: button });
  6518. }
  6519. },
  6520. /**
  6521. * Changes main series to `'ohlc'` type.
  6522. *
  6523. * @type {Highcharts.NavigationBindingsOptionsObject}
  6524. * @product highstock
  6525. * @default {"className": "highcharts-series-type-ohlc", "init": function() {}}
  6526. */
  6527. seriesTypeOhlc: {
  6528. /** @ignore-option */
  6529. className: 'highcharts-series-type-ohlc',
  6530. // eslint-disable-next-line valid-jsdoc
  6531. /** @ignore-option */
  6532. init: function (button) {
  6533. this.chart.series[0].update({
  6534. type: 'ohlc'
  6535. });
  6536. fireEvent(this, 'deselectButton', { button: button });
  6537. }
  6538. },
  6539. /**
  6540. * Changes main series to `'candlestick'` type.
  6541. *
  6542. * @type {Highcharts.NavigationBindingsOptionsObject}
  6543. * @product highstock
  6544. * @default {"className": "highcharts-series-type-candlestick", "init": function() {}}
  6545. */
  6546. seriesTypeCandlestick: {
  6547. /** @ignore-option */
  6548. className: 'highcharts-series-type-candlestick',
  6549. // eslint-disable-next-line valid-jsdoc
  6550. /** @ignore-option */
  6551. init: function (button) {
  6552. this.chart.series[0].update({
  6553. type: 'candlestick'
  6554. });
  6555. fireEvent(this, 'deselectButton', { button: button });
  6556. }
  6557. },
  6558. /**
  6559. * Displays chart in fullscreen.
  6560. *
  6561. * **Note**: Fullscreen is not supported on iPhone due to iOS limitations.
  6562. *
  6563. * @type {Highcharts.NavigationBindingsOptionsObject}
  6564. * @product highstock
  6565. * @default {"className": "highcharts-full-screen", "init": function() {}}
  6566. */
  6567. fullScreen: {
  6568. /** @ignore-option */
  6569. className: 'highcharts-full-screen',
  6570. // eslint-disable-next-line valid-jsdoc
  6571. /** @ignore-option */
  6572. init: function (button) {
  6573. this.chart.fullscreen.toggle();
  6574. fireEvent(this, 'deselectButton', { button: button });
  6575. }
  6576. },
  6577. /**
  6578. * Hides/shows two price indicators:
  6579. * - last price in the dataset
  6580. * - last price in the selected range
  6581. *
  6582. * @type {Highcharts.NavigationBindingsOptionsObject}
  6583. * @product highstock
  6584. * @default {"className": "highcharts-current-price-indicator", "init": function() {}}
  6585. */
  6586. currentPriceIndicator: {
  6587. /** @ignore-option */
  6588. className: 'highcharts-current-price-indicator',
  6589. // eslint-disable-next-line valid-jsdoc
  6590. /** @ignore-option */
  6591. init: function (button) {
  6592. var chart = this.chart,
  6593. series = chart.series[0],
  6594. options = series.options,
  6595. lastVisiblePrice = (options.lastVisiblePrice &&
  6596. options.lastVisiblePrice.enabled),
  6597. lastPrice = options.lastPrice && options.lastPrice.enabled,
  6598. gui = chart.stockTools,
  6599. iconsURL = gui.getIconsURL();
  6600. if (gui && gui.guiEnabled) {
  6601. if (lastPrice) {
  6602. button.firstChild.style['background-image'] =
  6603. 'url("' + iconsURL +
  6604. 'current-price-show.svg")';
  6605. }
  6606. else {
  6607. button.firstChild.style['background-image'] =
  6608. 'url("' + iconsURL +
  6609. 'current-price-hide.svg")';
  6610. }
  6611. }
  6612. series.update({
  6613. // line
  6614. lastPrice: {
  6615. enabled: !lastPrice,
  6616. color: 'red'
  6617. },
  6618. // label
  6619. lastVisiblePrice: {
  6620. enabled: !lastVisiblePrice,
  6621. label: {
  6622. enabled: true
  6623. }
  6624. }
  6625. });
  6626. fireEvent(this, 'deselectButton', { button: button });
  6627. }
  6628. },
  6629. /**
  6630. * Indicators bindings. Includes `init` event to show a popup.
  6631. *
  6632. * Note: In order to show base series from the chart in the popup's
  6633. * dropdown each series requires
  6634. * [series.id](https://api.highcharts.com/highstock/series.line.id) to be
  6635. * defined.
  6636. *
  6637. * @type {Highcharts.NavigationBindingsOptionsObject}
  6638. * @product highstock
  6639. * @default {"className": "highcharts-indicators", "init": function() {}}
  6640. */
  6641. indicators: {
  6642. /** @ignore-option */
  6643. className: 'highcharts-indicators',
  6644. // eslint-disable-next-line valid-jsdoc
  6645. /** @ignore-option */
  6646. init: function () {
  6647. var navigation = this;
  6648. fireEvent(navigation, 'showPopup', {
  6649. formType: 'indicators',
  6650. options: {},
  6651. // Callback on submit:
  6652. onSubmit: function (data) {
  6653. navigation.utils.manageIndicators.call(navigation, data);
  6654. }
  6655. });
  6656. }
  6657. },
  6658. /**
  6659. * Hides/shows all annotations on a chart.
  6660. *
  6661. * @type {Highcharts.NavigationBindingsOptionsObject}
  6662. * @product highstock
  6663. * @default {"className": "highcharts-toggle-annotations", "init": function() {}}
  6664. */
  6665. toggleAnnotations: {
  6666. /** @ignore-option */
  6667. className: 'highcharts-toggle-annotations',
  6668. // eslint-disable-next-line valid-jsdoc
  6669. /** @ignore-option */
  6670. init: function (button) {
  6671. var chart = this.chart,
  6672. gui = chart.stockTools,
  6673. iconsURL = gui.getIconsURL();
  6674. this.toggledAnnotations = !this.toggledAnnotations;
  6675. (chart.annotations || []).forEach(function (annotation) {
  6676. annotation.setVisibility(!this.toggledAnnotations);
  6677. }, this);
  6678. if (gui && gui.guiEnabled) {
  6679. if (this.toggledAnnotations) {
  6680. button.firstChild.style['background-image'] =
  6681. 'url("' + iconsURL +
  6682. 'annotations-hidden.svg")';
  6683. }
  6684. else {
  6685. button.firstChild.style['background-image'] =
  6686. 'url("' + iconsURL +
  6687. 'annotations-visible.svg")';
  6688. }
  6689. }
  6690. fireEvent(this, 'deselectButton', { button: button });
  6691. }
  6692. },
  6693. /**
  6694. * Save a chart in localStorage under `highcharts-chart` key.
  6695. * Stored items:
  6696. * - annotations
  6697. * - indicators (with yAxes)
  6698. * - flags
  6699. *
  6700. * @type {Highcharts.NavigationBindingsOptionsObject}
  6701. * @product highstock
  6702. * @default {"className": "highcharts-save-chart", "init": function() {}}
  6703. */
  6704. saveChart: {
  6705. /** @ignore-option */
  6706. className: 'highcharts-save-chart',
  6707. // eslint-disable-next-line valid-jsdoc
  6708. /** @ignore-option */
  6709. init: function (button) {
  6710. var navigation = this,
  6711. chart = navigation.chart,
  6712. annotations = [],
  6713. indicators = [],
  6714. flags = [],
  6715. yAxes = [];
  6716. chart.annotations.forEach(function (annotation, index) {
  6717. annotations[index] = annotation.userOptions;
  6718. });
  6719. chart.series.forEach(function (series) {
  6720. if (series.is('sma')) {
  6721. indicators.push(series.userOptions);
  6722. }
  6723. else if (series.type === 'flags') {
  6724. flags.push(series.userOptions);
  6725. }
  6726. });
  6727. chart.yAxis.forEach(function (yAxis) {
  6728. if (bindingsUtils.isNotNavigatorYAxis(yAxis)) {
  6729. yAxes.push(yAxis.options);
  6730. }
  6731. });
  6732. H.win.localStorage.setItem(PREFIX + 'chart', JSON.stringify({
  6733. annotations: annotations,
  6734. indicators: indicators,
  6735. flags: flags,
  6736. yAxes: yAxes
  6737. }));
  6738. fireEvent(this, 'deselectButton', { button: button });
  6739. }
  6740. }
  6741. };
  6742. setOptions({
  6743. navigation: {
  6744. bindings: stockToolsBindings
  6745. }
  6746. });
  6747. NavigationBindings.prototype.utils = merge(bindingsUtils, NavigationBindings.prototype.utils);
  6748. });
  6749. _registerModule(_modules, 'Stock/StockToolsGui.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Extensions/Annotations/NavigationBindings.js'], _modules['Core/Utilities.js']], function (Chart, H, NavigationBindings, U) {
  6750. /* *
  6751. *
  6752. * GUI generator for Stock tools
  6753. *
  6754. * (c) 2009-2017 Sebastian Bochan
  6755. *
  6756. * License: www.highcharts.com/license
  6757. *
  6758. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6759. *
  6760. * */
  6761. var addEvent = U.addEvent,
  6762. createElement = U.createElement,
  6763. css = U.css,
  6764. extend = U.extend,
  6765. fireEvent = U.fireEvent,
  6766. getStyle = U.getStyle,
  6767. isArray = U.isArray,
  6768. merge = U.merge,
  6769. pick = U.pick,
  6770. setOptions = U.setOptions;
  6771. var DIV = 'div', SPAN = 'span', UL = 'ul', LI = 'li', PREFIX = 'highcharts-', activeClass = PREFIX + 'active';
  6772. setOptions({
  6773. /**
  6774. * @optionparent lang
  6775. */
  6776. lang: {
  6777. /**
  6778. * Configure the stockTools GUI titles(hints) in the chart. Requires
  6779. * the `stock-tools.js` module to be loaded.
  6780. *
  6781. * @product highstock
  6782. * @since 7.0.0
  6783. */
  6784. stockTools: {
  6785. gui: {
  6786. // Main buttons:
  6787. simpleShapes: 'Simple shapes',
  6788. lines: 'Lines',
  6789. crookedLines: 'Crooked lines',
  6790. measure: 'Measure',
  6791. advanced: 'Advanced',
  6792. toggleAnnotations: 'Toggle annotations',
  6793. verticalLabels: 'Vertical labels',
  6794. flags: 'Flags',
  6795. zoomChange: 'Zoom change',
  6796. typeChange: 'Type change',
  6797. saveChart: 'Save chart',
  6798. indicators: 'Indicators',
  6799. currentPriceIndicator: 'Current Price Indicators',
  6800. // Other features:
  6801. zoomX: 'Zoom X',
  6802. zoomY: 'Zoom Y',
  6803. zoomXY: 'Zooom XY',
  6804. fullScreen: 'Fullscreen',
  6805. typeOHLC: 'OHLC',
  6806. typeLine: 'Line',
  6807. typeCandlestick: 'Candlestick',
  6808. // Basic shapes:
  6809. circle: 'Circle',
  6810. label: 'Label',
  6811. rectangle: 'Rectangle',
  6812. // Flags:
  6813. flagCirclepin: 'Flag circle',
  6814. flagDiamondpin: 'Flag diamond',
  6815. flagSquarepin: 'Flag square',
  6816. flagSimplepin: 'Flag simple',
  6817. // Measures:
  6818. measureXY: 'Measure XY',
  6819. measureX: 'Measure X',
  6820. measureY: 'Measure Y',
  6821. // Segment, ray and line:
  6822. segment: 'Segment',
  6823. arrowSegment: 'Arrow segment',
  6824. ray: 'Ray',
  6825. arrowRay: 'Arrow ray',
  6826. line: 'Line',
  6827. arrowLine: 'Arrow line',
  6828. horizontalLine: 'Horizontal line',
  6829. verticalLine: 'Vertical line',
  6830. infinityLine: 'Infinity line',
  6831. // Crooked lines:
  6832. crooked3: 'Crooked 3 line',
  6833. crooked5: 'Crooked 5 line',
  6834. elliott3: 'Elliott 3 line',
  6835. elliott5: 'Elliott 5 line',
  6836. // Counters:
  6837. verticalCounter: 'Vertical counter',
  6838. verticalLabel: 'Vertical label',
  6839. verticalArrow: 'Vertical arrow',
  6840. // Advanced:
  6841. fibonacci: 'Fibonacci',
  6842. pitchfork: 'Pitchfork',
  6843. parallelChannel: 'Parallel channel'
  6844. }
  6845. },
  6846. navigation: {
  6847. popup: {
  6848. // Annotations:
  6849. circle: 'Circle',
  6850. rectangle: 'Rectangle',
  6851. label: 'Label',
  6852. segment: 'Segment',
  6853. arrowSegment: 'Arrow segment',
  6854. ray: 'Ray',
  6855. arrowRay: 'Arrow ray',
  6856. line: 'Line',
  6857. arrowLine: 'Arrow line',
  6858. horizontalLine: 'Horizontal line',
  6859. verticalLine: 'Vertical line',
  6860. crooked3: 'Crooked 3 line',
  6861. crooked5: 'Crooked 5 line',
  6862. elliott3: 'Elliott 3 line',
  6863. elliott5: 'Elliott 5 line',
  6864. verticalCounter: 'Vertical counter',
  6865. verticalLabel: 'Vertical label',
  6866. verticalArrow: 'Vertical arrow',
  6867. fibonacci: 'Fibonacci',
  6868. pitchfork: 'Pitchfork',
  6869. parallelChannel: 'Parallel channel',
  6870. infinityLine: 'Infinity line',
  6871. measure: 'Measure',
  6872. measureXY: 'Measure XY',
  6873. measureX: 'Measure X',
  6874. measureY: 'Measure Y',
  6875. // Flags:
  6876. flags: 'Flags',
  6877. // GUI elements:
  6878. addButton: 'add',
  6879. saveButton: 'save',
  6880. editButton: 'edit',
  6881. removeButton: 'remove',
  6882. series: 'Series',
  6883. volume: 'Volume',
  6884. connector: 'Connector',
  6885. // Field names:
  6886. innerBackground: 'Inner background',
  6887. outerBackground: 'Outer background',
  6888. crosshairX: 'Crosshair X',
  6889. crosshairY: 'Crosshair Y',
  6890. tunnel: 'Tunnel',
  6891. background: 'Background'
  6892. }
  6893. }
  6894. },
  6895. /**
  6896. * Configure the stockTools gui strings in the chart. Requires the
  6897. * [stockTools module]() to be loaded. For a description of the module
  6898. * and information on its features, see [Highcharts StockTools]().
  6899. *
  6900. * @product highstock
  6901. *
  6902. * @sample stock/demo/stock-tools-gui Stock Tools GUI
  6903. *
  6904. * @sample stock/demo/stock-tools-custom-gui Stock Tools customized GUI
  6905. *
  6906. * @since 7.0.0
  6907. * @optionparent stockTools
  6908. */
  6909. stockTools: {
  6910. /**
  6911. * Definitions of buttons in Stock Tools GUI.
  6912. */
  6913. gui: {
  6914. /**
  6915. * Path where Highcharts will look for icons. Change this to use
  6916. * icons from a different server.
  6917. *
  6918. * Since 7.1.3 use [iconsURL](#navigation.iconsURL) for popup and
  6919. * stock tools.
  6920. *
  6921. * @deprecated
  6922. * @apioption stockTools.gui.iconsURL
  6923. *
  6924. */
  6925. /**
  6926. * Enable or disable the stockTools gui.
  6927. */
  6928. enabled: true,
  6929. /**
  6930. * A CSS class name to apply to the stocktools' div,
  6931. * allowing unique CSS styling for each chart.
  6932. */
  6933. className: 'highcharts-bindings-wrapper',
  6934. /**
  6935. * A CSS class name to apply to the container of buttons,
  6936. * allowing unique CSS styling for each chart.
  6937. */
  6938. toolbarClassName: 'stocktools-toolbar',
  6939. /**
  6940. * A collection of strings pointing to config options for the
  6941. * toolbar items. Each name refers to a unique key from the
  6942. * definitions object.
  6943. *
  6944. * @type {Array<string>}
  6945. * @default [
  6946. * 'indicators',
  6947. * 'separator',
  6948. * 'simpleShapes',
  6949. * 'lines',
  6950. * 'crookedLines',
  6951. * 'measure',
  6952. * 'advanced',
  6953. * 'toggleAnnotations',
  6954. * 'separator',
  6955. * 'verticalLabels',
  6956. * 'flags',
  6957. * 'separator',
  6958. * 'zoomChange',
  6959. * 'fullScreen',
  6960. * 'typeChange',
  6961. * 'separator',
  6962. * 'currentPriceIndicator',
  6963. * 'saveChart'
  6964. * ]
  6965. */
  6966. buttons: [
  6967. 'indicators',
  6968. 'separator',
  6969. 'simpleShapes',
  6970. 'lines',
  6971. 'crookedLines',
  6972. 'measure',
  6973. 'advanced',
  6974. 'toggleAnnotations',
  6975. 'separator',
  6976. 'verticalLabels',
  6977. 'flags',
  6978. 'separator',
  6979. 'zoomChange',
  6980. 'fullScreen',
  6981. 'typeChange',
  6982. 'separator',
  6983. 'currentPriceIndicator',
  6984. 'saveChart'
  6985. ],
  6986. /**
  6987. * An options object of the buttons definitions. Each name refers to
  6988. * unique key from buttons array.
  6989. */
  6990. definitions: {
  6991. separator: {
  6992. /**
  6993. * A predefined background symbol for the button.
  6994. */
  6995. symbol: 'separator.svg'
  6996. },
  6997. simpleShapes: {
  6998. /**
  6999. * A collection of strings pointing to config options for
  7000. * the items.
  7001. *
  7002. * @type {array}
  7003. * @default [
  7004. * 'label',
  7005. * 'circle',
  7006. * 'rectangle'
  7007. * ]
  7008. *
  7009. */
  7010. items: [
  7011. 'label',
  7012. 'circle',
  7013. 'rectangle'
  7014. ],
  7015. circle: {
  7016. /**
  7017. * A predefined background symbol for the button.
  7018. *
  7019. * @type {string}
  7020. *
  7021. */
  7022. symbol: 'circle.svg'
  7023. },
  7024. rectangle: {
  7025. /**
  7026. * A predefined background symbol for the button.
  7027. *
  7028. * @type {string}
  7029. *
  7030. */
  7031. symbol: 'rectangle.svg'
  7032. },
  7033. label: {
  7034. /**
  7035. * A predefined background symbol for the button.
  7036. *
  7037. * @type {string}
  7038. *
  7039. */
  7040. symbol: 'label.svg'
  7041. }
  7042. },
  7043. flags: {
  7044. /**
  7045. * A collection of strings pointing to config options for
  7046. * the items.
  7047. *
  7048. * @type {array}
  7049. * @default [
  7050. * 'flagCirclepin',
  7051. * 'flagDiamondpin',
  7052. * 'flagSquarepin',
  7053. * 'flagSimplepin'
  7054. * ]
  7055. *
  7056. */
  7057. items: [
  7058. 'flagCirclepin',
  7059. 'flagDiamondpin',
  7060. 'flagSquarepin',
  7061. 'flagSimplepin'
  7062. ],
  7063. flagSimplepin: {
  7064. /**
  7065. * A predefined background symbol for the button.
  7066. *
  7067. * @type {string}
  7068. *
  7069. */
  7070. symbol: 'flag-basic.svg'
  7071. },
  7072. flagDiamondpin: {
  7073. /**
  7074. * A predefined background symbol for the button.
  7075. *
  7076. * @type {string}
  7077. *
  7078. */
  7079. symbol: 'flag-diamond.svg'
  7080. },
  7081. flagSquarepin: {
  7082. /**
  7083. * A predefined background symbol for the button.
  7084. *
  7085. * @type {string}
  7086. */
  7087. symbol: 'flag-trapeze.svg'
  7088. },
  7089. flagCirclepin: {
  7090. /**
  7091. * A predefined background symbol for the button.
  7092. *
  7093. * @type {string}
  7094. */
  7095. symbol: 'flag-elipse.svg'
  7096. }
  7097. },
  7098. lines: {
  7099. /**
  7100. * A collection of strings pointing to config options for
  7101. * the items.
  7102. *
  7103. * @type {array}
  7104. * @default [
  7105. * 'segment',
  7106. * 'arrowSegment',
  7107. * 'ray',
  7108. * 'arrowRay',
  7109. * 'line',
  7110. * 'arrowLine',
  7111. * 'horizontalLine',
  7112. * 'verticalLine'
  7113. * ]
  7114. */
  7115. items: [
  7116. 'segment',
  7117. 'arrowSegment',
  7118. 'ray',
  7119. 'arrowRay',
  7120. 'line',
  7121. 'arrowLine',
  7122. 'horizontalLine',
  7123. 'verticalLine'
  7124. ],
  7125. segment: {
  7126. /**
  7127. * A predefined background symbol for the button.
  7128. *
  7129. * @type {string}
  7130. */
  7131. symbol: 'segment.svg'
  7132. },
  7133. arrowSegment: {
  7134. /**
  7135. * A predefined background symbol for the button.
  7136. *
  7137. * @type {string}
  7138. */
  7139. symbol: 'arrow-segment.svg'
  7140. },
  7141. ray: {
  7142. /**
  7143. * A predefined background symbol for the button.
  7144. *
  7145. * @type {string}
  7146. */
  7147. symbol: 'ray.svg'
  7148. },
  7149. arrowRay: {
  7150. /**
  7151. * A predefined background symbol for the button.
  7152. *
  7153. * @type {string}
  7154. */
  7155. symbol: 'arrow-ray.svg'
  7156. },
  7157. line: {
  7158. /**
  7159. * A predefined background symbol for the button.
  7160. *
  7161. * @type {string}
  7162. */
  7163. symbol: 'line.svg'
  7164. },
  7165. arrowLine: {
  7166. /**
  7167. * A predefined background symbol for the button.
  7168. *
  7169. * @type {string}
  7170. */
  7171. symbol: 'arrow-line.svg'
  7172. },
  7173. verticalLine: {
  7174. /**
  7175. * A predefined background symbol for the button.
  7176. *
  7177. * @type {string}
  7178. */
  7179. symbol: 'vertical-line.svg'
  7180. },
  7181. horizontalLine: {
  7182. /**
  7183. * A predefined background symbol for the button.
  7184. *
  7185. * @type {string}
  7186. */
  7187. symbol: 'horizontal-line.svg'
  7188. }
  7189. },
  7190. crookedLines: {
  7191. /**
  7192. * A collection of strings pointing to config options for
  7193. * the items.
  7194. *
  7195. * @type {array}
  7196. * @default [
  7197. * 'elliott3',
  7198. * 'elliott5',
  7199. * 'crooked3',
  7200. * 'crooked5'
  7201. * ]
  7202. *
  7203. */
  7204. items: [
  7205. 'elliott3',
  7206. 'elliott5',
  7207. 'crooked3',
  7208. 'crooked5'
  7209. ],
  7210. crooked3: {
  7211. /**
  7212. * A predefined background symbol for the button.
  7213. *
  7214. * @type {string}
  7215. */
  7216. symbol: 'crooked-3.svg'
  7217. },
  7218. crooked5: {
  7219. /**
  7220. * A predefined background symbol for the button.
  7221. *
  7222. * @type {string}
  7223. */
  7224. symbol: 'crooked-5.svg'
  7225. },
  7226. elliott3: {
  7227. /**
  7228. * A predefined background symbol for the button.
  7229. *
  7230. * @type {string}
  7231. */
  7232. symbol: 'elliott-3.svg'
  7233. },
  7234. elliott5: {
  7235. /**
  7236. * A predefined background symbol for the button.
  7237. *
  7238. * @type {string}
  7239. */
  7240. symbol: 'elliott-5.svg'
  7241. }
  7242. },
  7243. verticalLabels: {
  7244. /**
  7245. * A collection of strings pointing to config options for
  7246. * the items.
  7247. *
  7248. * @type {array}
  7249. * @default [
  7250. * 'verticalCounter',
  7251. * 'verticalLabel',
  7252. * 'verticalArrow'
  7253. * ]
  7254. */
  7255. items: [
  7256. 'verticalCounter',
  7257. 'verticalLabel',
  7258. 'verticalArrow'
  7259. ],
  7260. verticalCounter: {
  7261. /**
  7262. * A predefined background symbol for the button.
  7263. *
  7264. * @type {string}
  7265. */
  7266. symbol: 'vertical-counter.svg'
  7267. },
  7268. verticalLabel: {
  7269. /**
  7270. * A predefined background symbol for the button.
  7271. *
  7272. * @type {string}
  7273. */
  7274. symbol: 'vertical-label.svg'
  7275. },
  7276. verticalArrow: {
  7277. /**
  7278. * A predefined background symbol for the button.
  7279. *
  7280. * @type {string}
  7281. */
  7282. symbol: 'vertical-arrow.svg'
  7283. }
  7284. },
  7285. advanced: {
  7286. /**
  7287. * A collection of strings pointing to config options for
  7288. * the items.
  7289. *
  7290. * @type {array}
  7291. * @default [
  7292. * 'fibonacci',
  7293. * 'pitchfork',
  7294. * 'parallelChannel'
  7295. * ]
  7296. */
  7297. items: [
  7298. 'fibonacci',
  7299. 'pitchfork',
  7300. 'parallelChannel'
  7301. ],
  7302. pitchfork: {
  7303. /**
  7304. * A predefined background symbol for the button.
  7305. *
  7306. * @type {string}
  7307. */
  7308. symbol: 'pitchfork.svg'
  7309. },
  7310. fibonacci: {
  7311. /**
  7312. * A predefined background symbol for the button.
  7313. *
  7314. * @type {string}
  7315. */
  7316. symbol: 'fibonacci.svg'
  7317. },
  7318. parallelChannel: {
  7319. /**
  7320. * A predefined background symbol for the button.
  7321. *
  7322. * @type {string}
  7323. */
  7324. symbol: 'parallel-channel.svg'
  7325. }
  7326. },
  7327. measure: {
  7328. /**
  7329. * A collection of strings pointing to config options for
  7330. * the items.
  7331. *
  7332. * @type {array}
  7333. * @default [
  7334. * 'measureXY',
  7335. * 'measureX',
  7336. * 'measureY'
  7337. * ]
  7338. */
  7339. items: [
  7340. 'measureXY',
  7341. 'measureX',
  7342. 'measureY'
  7343. ],
  7344. measureX: {
  7345. /**
  7346. * A predefined background symbol for the button.
  7347. *
  7348. * @type {string}
  7349. */
  7350. symbol: 'measure-x.svg'
  7351. },
  7352. measureY: {
  7353. /**
  7354. * A predefined background symbol for the button.
  7355. *
  7356. * @type {string}
  7357. */
  7358. symbol: 'measure-y.svg'
  7359. },
  7360. measureXY: {
  7361. /**
  7362. * A predefined background symbol for the button.
  7363. *
  7364. * @type {string}
  7365. */
  7366. symbol: 'measure-xy.svg'
  7367. }
  7368. },
  7369. toggleAnnotations: {
  7370. /**
  7371. * A predefined background symbol for the button.
  7372. *
  7373. * @type {string}
  7374. */
  7375. symbol: 'annotations-visible.svg'
  7376. },
  7377. currentPriceIndicator: {
  7378. /**
  7379. * A predefined background symbol for the button.
  7380. *
  7381. * @type {string}
  7382. */
  7383. symbol: 'current-price-show.svg'
  7384. },
  7385. indicators: {
  7386. /**
  7387. * A predefined background symbol for the button.
  7388. *
  7389. * @type {string}
  7390. */
  7391. symbol: 'indicators.svg'
  7392. },
  7393. zoomChange: {
  7394. /**
  7395. * A collection of strings pointing to config options for
  7396. * the items.
  7397. *
  7398. * @type {array}
  7399. * @default [
  7400. * 'zoomX',
  7401. * 'zoomY',
  7402. * 'zoomXY'
  7403. * ]
  7404. */
  7405. items: [
  7406. 'zoomX',
  7407. 'zoomY',
  7408. 'zoomXY'
  7409. ],
  7410. zoomX: {
  7411. /**
  7412. * A predefined background symbol for the button.
  7413. *
  7414. * @type {string}
  7415. */
  7416. symbol: 'zoom-x.svg'
  7417. },
  7418. zoomY: {
  7419. /**
  7420. * A predefined background symbol for the button.
  7421. *
  7422. * @type {string}
  7423. */
  7424. symbol: 'zoom-y.svg'
  7425. },
  7426. zoomXY: {
  7427. /**
  7428. * A predefined background symbol for the button.
  7429. *
  7430. * @type {string}
  7431. */
  7432. symbol: 'zoom-xy.svg'
  7433. }
  7434. },
  7435. typeChange: {
  7436. /**
  7437. * A collection of strings pointing to config options for
  7438. * the items.
  7439. *
  7440. * @type {array}
  7441. * @default [
  7442. * 'typeOHLC',
  7443. * 'typeLine',
  7444. * 'typeCandlestick'
  7445. * ]
  7446. */
  7447. items: [
  7448. 'typeOHLC',
  7449. 'typeLine',
  7450. 'typeCandlestick'
  7451. ],
  7452. typeOHLC: {
  7453. /**
  7454. * A predefined background symbol for the button.
  7455. *
  7456. * @type {string}
  7457. */
  7458. symbol: 'series-ohlc.svg'
  7459. },
  7460. typeLine: {
  7461. /**
  7462. * A predefined background symbol for the button.
  7463. *
  7464. * @type {string}
  7465. */
  7466. symbol: 'series-line.svg'
  7467. },
  7468. typeCandlestick: {
  7469. /**
  7470. * A predefined background symbol for the button.
  7471. *
  7472. * @type {string}
  7473. */
  7474. symbol: 'series-candlestick.svg'
  7475. }
  7476. },
  7477. fullScreen: {
  7478. /**
  7479. * A predefined background symbol for the button.
  7480. *
  7481. * @type {string}
  7482. */
  7483. symbol: 'fullscreen.svg'
  7484. },
  7485. saveChart: {
  7486. /**
  7487. * A predefined background symbol for the button.
  7488. *
  7489. * @type {string}
  7490. */
  7491. symbol: 'save-chart.svg'
  7492. }
  7493. }
  7494. }
  7495. }
  7496. });
  7497. /* eslint-disable no-invalid-this, valid-jsdoc */
  7498. // Run HTML generator
  7499. addEvent(Chart, 'afterGetContainer', function () {
  7500. this.setStockTools();
  7501. });
  7502. addEvent(Chart, 'getMargins', function () {
  7503. var listWrapper = this.stockTools && this.stockTools.listWrapper,
  7504. offsetWidth = listWrapper && ((listWrapper.startWidth +
  7505. getStyle(listWrapper, 'padding-left') +
  7506. getStyle(listWrapper, 'padding-right')) || listWrapper.offsetWidth);
  7507. if (offsetWidth && offsetWidth < this.plotWidth) {
  7508. this.plotLeft += offsetWidth;
  7509. }
  7510. });
  7511. addEvent(Chart, 'destroy', function () {
  7512. if (this.stockTools) {
  7513. this.stockTools.destroy();
  7514. }
  7515. });
  7516. addEvent(Chart, 'redraw', function () {
  7517. if (this.stockTools && this.stockTools.guiEnabled) {
  7518. this.stockTools.redraw();
  7519. }
  7520. });
  7521. /**
  7522. * Toolbar Class
  7523. * @private
  7524. * @constructor
  7525. * @param {Object} - options of toolbar
  7526. * @param {Chart} - Reference to chart
  7527. */
  7528. var Toolbar = /** @class */ (function () {
  7529. function Toolbar(options, langOptions, chart) {
  7530. this.arrowDown = void 0;
  7531. this.arrowUp = void 0;
  7532. this.arrowWrapper = void 0;
  7533. this.listWrapper = void 0;
  7534. this.showhideBtn = void 0;
  7535. this.submenu = void 0;
  7536. this.toolbar = void 0;
  7537. this.wrapper = void 0;
  7538. this.chart = chart;
  7539. this.options = options;
  7540. this.lang = langOptions;
  7541. // set url for icons.
  7542. this.iconsURL = this.getIconsURL();
  7543. this.guiEnabled = options.enabled;
  7544. this.visible = pick(options.visible, true);
  7545. this.placed = pick(options.placed, false);
  7546. // General events collection which should be removed upon
  7547. // destroy/update:
  7548. this.eventsToUnbind = [];
  7549. if (this.guiEnabled) {
  7550. this.createHTML();
  7551. this.init();
  7552. this.showHideNavigatorion();
  7553. }
  7554. fireEvent(this, 'afterInit');
  7555. }
  7556. /**
  7557. * Initialize the toolbar. Create buttons and submenu for each option
  7558. * defined in `stockTools.gui`.
  7559. * @private
  7560. */
  7561. Toolbar.prototype.init = function () {
  7562. var _self = this,
  7563. lang = this.lang,
  7564. guiOptions = this.options,
  7565. toolbar = this.toolbar,
  7566. addSubmenu = _self.addSubmenu,
  7567. buttons = guiOptions.buttons,
  7568. defs = guiOptions.definitions,
  7569. allButtons = toolbar.childNodes,
  7570. button;
  7571. // create buttons
  7572. buttons.forEach(function (btnName) {
  7573. button = _self.addButton(toolbar, defs, btnName, lang);
  7574. _self.eventsToUnbind.push(addEvent(button.buttonWrapper, 'click', function () {
  7575. _self.eraseActiveButtons(allButtons, button.buttonWrapper);
  7576. }));
  7577. if (isArray(defs[btnName].items)) {
  7578. // create submenu buttons
  7579. addSubmenu.call(_self, button, defs[btnName]);
  7580. }
  7581. });
  7582. };
  7583. /**
  7584. * Create submenu (list of buttons) for the option. In example main button
  7585. * is Line, in submenu will be buttons with types of lines.
  7586. * @private
  7587. * @param {Highcharts.Dictionary<Highcharts.HTMLDOMElement>}
  7588. * button which has submenu
  7589. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions}
  7590. * list of all buttons
  7591. */
  7592. Toolbar.prototype.addSubmenu = function (parentBtn, button) {
  7593. var _self = this,
  7594. submenuArrow = parentBtn.submenuArrow,
  7595. buttonWrapper = parentBtn.buttonWrapper,
  7596. buttonWidth = getStyle(buttonWrapper, 'width'),
  7597. wrapper = this.wrapper,
  7598. menuWrapper = this.listWrapper,
  7599. allButtons = this.toolbar.childNodes,
  7600. topMargin = 0,
  7601. submenuWrapper;
  7602. // create submenu container
  7603. this.submenu = submenuWrapper = createElement(UL, {
  7604. className: PREFIX + 'submenu-wrapper'
  7605. }, null, buttonWrapper);
  7606. // create submenu buttons and select the first one
  7607. this.addSubmenuItems(buttonWrapper, button);
  7608. // show / hide submenu
  7609. _self.eventsToUnbind.push(addEvent(submenuArrow, 'click', function (e) {
  7610. e.stopPropagation();
  7611. // Erase active class on all other buttons
  7612. _self.eraseActiveButtons(allButtons, buttonWrapper);
  7613. // hide menu
  7614. if (buttonWrapper.className.indexOf(PREFIX + 'current') >= 0) {
  7615. menuWrapper.style.width =
  7616. menuWrapper.startWidth + 'px';
  7617. buttonWrapper.classList.remove(PREFIX + 'current');
  7618. submenuWrapper.style.display = 'none';
  7619. }
  7620. else {
  7621. // show menu
  7622. // to calculate height of element
  7623. submenuWrapper.style.display = 'block';
  7624. topMargin = submenuWrapper.offsetHeight -
  7625. buttonWrapper.offsetHeight - 3;
  7626. // calculate position of submenu in the box
  7627. // if submenu is inside, reset top margin
  7628. if (
  7629. // cut on the bottom
  7630. !(submenuWrapper.offsetHeight +
  7631. buttonWrapper.offsetTop >
  7632. wrapper.offsetHeight &&
  7633. // cut on the top
  7634. buttonWrapper.offsetTop > topMargin)) {
  7635. topMargin = 0;
  7636. }
  7637. // apply calculated styles
  7638. css(submenuWrapper, {
  7639. top: -topMargin + 'px',
  7640. left: buttonWidth + 3 + 'px'
  7641. });
  7642. buttonWrapper.className += ' ' + PREFIX + 'current';
  7643. menuWrapper.startWidth = wrapper.offsetWidth;
  7644. menuWrapper.style.width = menuWrapper.startWidth +
  7645. getStyle(menuWrapper, 'padding-left') +
  7646. submenuWrapper.offsetWidth + 3 + 'px';
  7647. }
  7648. }));
  7649. };
  7650. /**
  7651. * Create buttons in submenu
  7652. * @private
  7653. * @param {Highcharts.HTMLDOMElement}
  7654. * button where submenu is placed
  7655. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions}
  7656. * list of all buttons options
  7657. *
  7658. */
  7659. Toolbar.prototype.addSubmenuItems = function (buttonWrapper, button) {
  7660. var _self = this,
  7661. submenuWrapper = this.submenu,
  7662. lang = this.lang,
  7663. menuWrapper = this.listWrapper,
  7664. items = button.items,
  7665. firstSubmenuItem,
  7666. submenuBtn;
  7667. // add items to submenu
  7668. items.forEach(function (btnName) {
  7669. // add buttons to submenu
  7670. submenuBtn = _self.addButton(submenuWrapper, button, btnName, lang);
  7671. _self.eventsToUnbind.push(addEvent(submenuBtn.mainButton, 'click', function () {
  7672. _self.switchSymbol(this, buttonWrapper, true);
  7673. menuWrapper.style.width =
  7674. menuWrapper.startWidth + 'px';
  7675. submenuWrapper.style.display = 'none';
  7676. }));
  7677. });
  7678. // select first submenu item
  7679. firstSubmenuItem = submenuWrapper
  7680. .querySelectorAll('li > .' + PREFIX + 'menu-item-btn')[0];
  7681. // replace current symbol, in main button, with submenu's button style
  7682. _self.switchSymbol(firstSubmenuItem, false);
  7683. };
  7684. /*
  7685. * Erase active class on all other buttons.
  7686. *
  7687. * @param {Array} - Array of HTML buttons
  7688. * @param {HTMLDOMElement} - Current HTML button
  7689. *
  7690. */
  7691. Toolbar.prototype.eraseActiveButtons = function (buttons, currentButton, submenuItems) {
  7692. [].forEach.call(buttons, function (btn) {
  7693. if (btn !== currentButton) {
  7694. btn.classList.remove(PREFIX + 'current');
  7695. btn.classList.remove(PREFIX + 'active');
  7696. submenuItems =
  7697. btn.querySelectorAll('.' + PREFIX + 'submenu-wrapper');
  7698. // hide submenu
  7699. if (submenuItems.length > 0) {
  7700. submenuItems[0].style.display = 'none';
  7701. }
  7702. }
  7703. });
  7704. };
  7705. /**
  7706. * Create single button. Consist of HTML elements `li`, `span`, and (if
  7707. * exists) submenu container.
  7708. * @private
  7709. * @param {Highcharts.HTMLDOMElement} target
  7710. * HTML reference, where button should be added
  7711. * @param {Highcharts.StockToolsGuiDefinitionsButtonsOptions|Highcharts.StockToolsGuiDefinitionsOptions} options
  7712. * All options, by btnName refer to particular button
  7713. * @param {string} btnName
  7714. * of functionality mapped for specific class
  7715. * @param {Highcharts.Dictionary<string>} lang
  7716. * All titles, by btnName refer to particular button
  7717. * @return {Object} - references to all created HTML elements
  7718. */
  7719. Toolbar.prototype.addButton = function (target, options, btnName, lang) {
  7720. if (lang === void 0) { lang = {}; }
  7721. var btnOptions = options[btnName],
  7722. items = btnOptions.items,
  7723. classMapping = Toolbar.prototype.classMapping,
  7724. userClassName = btnOptions.className || '',
  7725. mainButton,
  7726. submenuArrow,
  7727. buttonWrapper;
  7728. // main button wrapper
  7729. buttonWrapper = createElement(LI, {
  7730. className: pick(classMapping[btnName], '') + ' ' + userClassName,
  7731. title: lang[btnName] || btnName
  7732. }, null, target);
  7733. // single button
  7734. mainButton = createElement(SPAN, {
  7735. className: PREFIX + 'menu-item-btn'
  7736. }, null, buttonWrapper);
  7737. // submenu
  7738. if (items && items.length) {
  7739. // arrow is a hook to show / hide submenu
  7740. submenuArrow = createElement(SPAN, {
  7741. className: PREFIX + 'submenu-item-arrow ' +
  7742. PREFIX + 'arrow-right'
  7743. }, null, buttonWrapper);
  7744. submenuArrow.style['background-image'] = 'url(' +
  7745. this.iconsURL + 'arrow-bottom.svg)';
  7746. }
  7747. else {
  7748. mainButton.style['background-image'] = 'url(' +
  7749. this.iconsURL + btnOptions.symbol + ')';
  7750. }
  7751. return {
  7752. buttonWrapper: buttonWrapper,
  7753. mainButton: mainButton,
  7754. submenuArrow: submenuArrow
  7755. };
  7756. };
  7757. /*
  7758. * Create navigation's HTML elements: container and arrows.
  7759. *
  7760. */
  7761. Toolbar.prototype.addNavigation = function () {
  7762. var stockToolbar = this,
  7763. wrapper = stockToolbar.wrapper;
  7764. // arrow wrapper
  7765. stockToolbar.arrowWrapper = createElement(DIV, {
  7766. className: PREFIX + 'arrow-wrapper'
  7767. });
  7768. stockToolbar.arrowUp = createElement(DIV, {
  7769. className: PREFIX + 'arrow-up'
  7770. }, null, stockToolbar.arrowWrapper);
  7771. stockToolbar.arrowUp.style['background-image'] =
  7772. 'url(' + this.iconsURL + 'arrow-right.svg)';
  7773. stockToolbar.arrowDown = createElement(DIV, {
  7774. className: PREFIX + 'arrow-down'
  7775. }, null, stockToolbar.arrowWrapper);
  7776. stockToolbar.arrowDown.style['background-image'] =
  7777. 'url(' + this.iconsURL + 'arrow-right.svg)';
  7778. wrapper.insertBefore(stockToolbar.arrowWrapper, wrapper.childNodes[0]);
  7779. // attach scroll events
  7780. stockToolbar.scrollButtons();
  7781. };
  7782. /*
  7783. * Add events to navigation (two arrows) which allows user to scroll
  7784. * top/down GUI buttons, if container's height is not enough.
  7785. *
  7786. */
  7787. Toolbar.prototype.scrollButtons = function () {
  7788. var targetY = 0,
  7789. _self = this,
  7790. wrapper = _self.wrapper,
  7791. toolbar = _self.toolbar,
  7792. step = 0.1 * wrapper.offsetHeight; // 0.1 = 10%
  7793. _self.eventsToUnbind.push(addEvent(_self.arrowUp, 'click',
  7794. function () {
  7795. if (targetY > 0) {
  7796. targetY -= step;
  7797. toolbar.style['margin-top'] = -targetY + 'px';
  7798. }
  7799. }));
  7800. _self.eventsToUnbind.push(addEvent(_self.arrowDown, 'click', function () {
  7801. if (wrapper.offsetHeight + targetY <=
  7802. toolbar.offsetHeight + step) {
  7803. targetY += step;
  7804. toolbar.style['margin-top'] = -targetY + 'px';
  7805. }
  7806. }));
  7807. };
  7808. /*
  7809. * Create stockTools HTML main elements.
  7810. *
  7811. */
  7812. Toolbar.prototype.createHTML = function () {
  7813. var stockToolbar = this,
  7814. chart = stockToolbar.chart,
  7815. guiOptions = stockToolbar.options,
  7816. container = chart.container,
  7817. navigation = chart.options.navigation,
  7818. bindingsClassName = navigation && navigation.bindingsClassName,
  7819. listWrapper,
  7820. toolbar,
  7821. wrapper;
  7822. // create main container
  7823. stockToolbar.wrapper = wrapper = createElement(DIV, {
  7824. className: PREFIX + 'stocktools-wrapper ' +
  7825. guiOptions.className + ' ' + bindingsClassName
  7826. });
  7827. container.parentNode.insertBefore(wrapper, container);
  7828. // toolbar
  7829. stockToolbar.toolbar = toolbar = createElement(UL, {
  7830. className: PREFIX + 'stocktools-toolbar ' +
  7831. guiOptions.toolbarClassName
  7832. });
  7833. // add container for list of buttons
  7834. stockToolbar.listWrapper = listWrapper = createElement(DIV, {
  7835. className: PREFIX + 'menu-wrapper'
  7836. });
  7837. wrapper.insertBefore(listWrapper, wrapper.childNodes[0]);
  7838. listWrapper.insertBefore(toolbar, listWrapper.childNodes[0]);
  7839. stockToolbar.showHideToolbar();
  7840. // add navigation which allows user to scroll down / top GUI buttons
  7841. stockToolbar.addNavigation();
  7842. };
  7843. /**
  7844. * Function called in redraw verifies if the navigation should be visible.
  7845. * @private
  7846. */
  7847. Toolbar.prototype.showHideNavigatorion = function () {
  7848. // arrows
  7849. // 50px space for arrows
  7850. if (this.visible &&
  7851. this.toolbar.offsetHeight > (this.wrapper.offsetHeight - 50)) {
  7852. this.arrowWrapper.style.display = 'block';
  7853. }
  7854. else {
  7855. // reset margin if whole toolbar is visible
  7856. this.toolbar.style.marginTop = '0px';
  7857. // hide arrows
  7858. this.arrowWrapper.style.display = 'none';
  7859. }
  7860. };
  7861. /**
  7862. * Create button which shows or hides GUI toolbar.
  7863. * @private
  7864. */
  7865. Toolbar.prototype.showHideToolbar = function () {
  7866. var stockToolbar = this,
  7867. chart = this.chart,
  7868. wrapper = stockToolbar.wrapper,
  7869. toolbar = this.listWrapper,
  7870. submenu = this.submenu,
  7871. visible = this.visible,
  7872. showhideBtn;
  7873. // Show hide toolbar
  7874. this.showhideBtn = showhideBtn = createElement(DIV, {
  7875. className: PREFIX + 'toggle-toolbar ' + PREFIX + 'arrow-left'
  7876. }, null, wrapper);
  7877. showhideBtn.style['background-image'] =
  7878. 'url(' + this.iconsURL + 'arrow-right.svg)';
  7879. if (!visible) {
  7880. // hide
  7881. if (submenu) {
  7882. submenu.style.display = 'none';
  7883. }
  7884. showhideBtn.style.left = '0px';
  7885. stockToolbar.visible = visible = false;
  7886. toolbar.classList.add(PREFIX + 'hide');
  7887. showhideBtn.classList.toggle(PREFIX + 'arrow-right');
  7888. wrapper.style.height = showhideBtn.offsetHeight + 'px';
  7889. }
  7890. else {
  7891. wrapper.style.height = '100%';
  7892. showhideBtn.style.top = getStyle(toolbar, 'padding-top') + 'px';
  7893. showhideBtn.style.left = (wrapper.offsetWidth +
  7894. getStyle(toolbar, 'padding-left')) + 'px';
  7895. }
  7896. // Toggle menu
  7897. stockToolbar.eventsToUnbind.push(addEvent(showhideBtn, 'click', function () {
  7898. chart.update({
  7899. stockTools: {
  7900. gui: {
  7901. visible: !visible,
  7902. placed: true
  7903. }
  7904. }
  7905. });
  7906. }));
  7907. };
  7908. /*
  7909. * In main GUI button, replace icon and class with submenu button's
  7910. * class / symbol.
  7911. *
  7912. * @param {HTMLDOMElement} - submenu button
  7913. * @param {Boolean} - true or false
  7914. *
  7915. */
  7916. Toolbar.prototype.switchSymbol = function (button, redraw) {
  7917. var buttonWrapper = button.parentNode,
  7918. buttonWrapperClass = buttonWrapper.classList.value,
  7919. // main button in first level og GUI
  7920. mainNavButton = buttonWrapper.parentNode.parentNode;
  7921. // set class
  7922. mainNavButton.className = '';
  7923. if (buttonWrapperClass) {
  7924. mainNavButton.classList.add(buttonWrapperClass.trim());
  7925. }
  7926. // set icon
  7927. mainNavButton
  7928. .querySelectorAll('.' + PREFIX + 'menu-item-btn')[0]
  7929. .style['background-image'] =
  7930. button.style['background-image'];
  7931. // set active class
  7932. if (redraw) {
  7933. this.selectButton(mainNavButton);
  7934. }
  7935. };
  7936. /*
  7937. * Set select state (active class) on button.
  7938. *
  7939. * @param {HTMLDOMElement} - button
  7940. *
  7941. */
  7942. Toolbar.prototype.selectButton = function (button) {
  7943. if (button.className.indexOf(activeClass) >= 0) {
  7944. button.classList.remove(activeClass);
  7945. }
  7946. else {
  7947. button.classList.add(activeClass);
  7948. }
  7949. };
  7950. /*
  7951. * Remove active class from all buttons except defined.
  7952. *
  7953. * @param {HTMLDOMElement} - button which should not be deactivated
  7954. *
  7955. */
  7956. Toolbar.prototype.unselectAllButtons = function (button) {
  7957. var activeButtons = button.parentNode
  7958. .querySelectorAll('.' + activeClass);
  7959. [].forEach.call(activeButtons, function (activeBtn) {
  7960. if (activeBtn !== button) {
  7961. activeBtn.classList.remove(activeClass);
  7962. }
  7963. });
  7964. };
  7965. /*
  7966. * Update GUI with given options.
  7967. *
  7968. * @param {Object} - general options for Stock Tools
  7969. */
  7970. Toolbar.prototype.update = function (options) {
  7971. merge(true, this.chart.options.stockTools, options);
  7972. this.destroy();
  7973. this.chart.setStockTools(options);
  7974. // If Stock Tools are updated, then bindings should be updated too:
  7975. if (this.chart.navigationBindings) {
  7976. this.chart.navigationBindings.update();
  7977. }
  7978. };
  7979. /**
  7980. * Destroy all HTML GUI elements.
  7981. * @private
  7982. */
  7983. Toolbar.prototype.destroy = function () {
  7984. var stockToolsDiv = this.wrapper,
  7985. parent = stockToolsDiv && stockToolsDiv.parentNode;
  7986. this.eventsToUnbind.forEach(function (unbinder) {
  7987. unbinder();
  7988. });
  7989. // Remove the empty element
  7990. if (parent) {
  7991. parent.removeChild(stockToolsDiv);
  7992. }
  7993. // redraw
  7994. this.chart.isDirtyBox = true;
  7995. this.chart.redraw();
  7996. };
  7997. /**
  7998. * Redraw, GUI requires to verify if the navigation should be visible.
  7999. * @private
  8000. */
  8001. Toolbar.prototype.redraw = function () {
  8002. this.showHideNavigatorion();
  8003. };
  8004. Toolbar.prototype.getIconsURL = function () {
  8005. return this.chart.options.navigation.iconsURL ||
  8006. this.options.iconsURL ||
  8007. 'https://code.highcharts.com/8.2.2/gfx/stock-icons/';
  8008. };
  8009. return Toolbar;
  8010. }());
  8011. /**
  8012. * Mapping JSON fields to CSS classes.
  8013. * @private
  8014. */
  8015. Toolbar.prototype.classMapping = {
  8016. circle: PREFIX + 'circle-annotation',
  8017. rectangle: PREFIX + 'rectangle-annotation',
  8018. label: PREFIX + 'label-annotation',
  8019. segment: PREFIX + 'segment',
  8020. arrowSegment: PREFIX + 'arrow-segment',
  8021. ray: PREFIX + 'ray',
  8022. arrowRay: PREFIX + 'arrow-ray',
  8023. line: PREFIX + 'infinity-line',
  8024. arrowLine: PREFIX + 'arrow-infinity-line',
  8025. verticalLine: PREFIX + 'vertical-line',
  8026. horizontalLine: PREFIX + 'horizontal-line',
  8027. crooked3: PREFIX + 'crooked3',
  8028. crooked5: PREFIX + 'crooked5',
  8029. elliott3: PREFIX + 'elliott3',
  8030. elliott5: PREFIX + 'elliott5',
  8031. pitchfork: PREFIX + 'pitchfork',
  8032. fibonacci: PREFIX + 'fibonacci',
  8033. parallelChannel: PREFIX + 'parallel-channel',
  8034. measureX: PREFIX + 'measure-x',
  8035. measureY: PREFIX + 'measure-y',
  8036. measureXY: PREFIX + 'measure-xy',
  8037. verticalCounter: PREFIX + 'vertical-counter',
  8038. verticalLabel: PREFIX + 'vertical-label',
  8039. verticalArrow: PREFIX + 'vertical-arrow',
  8040. currentPriceIndicator: PREFIX + 'current-price-indicator',
  8041. indicators: PREFIX + 'indicators',
  8042. flagCirclepin: PREFIX + 'flag-circlepin',
  8043. flagDiamondpin: PREFIX + 'flag-diamondpin',
  8044. flagSquarepin: PREFIX + 'flag-squarepin',
  8045. flagSimplepin: PREFIX + 'flag-simplepin',
  8046. zoomX: PREFIX + 'zoom-x',
  8047. zoomY: PREFIX + 'zoom-y',
  8048. zoomXY: PREFIX + 'zoom-xy',
  8049. typeLine: PREFIX + 'series-type-line',
  8050. typeOHLC: PREFIX + 'series-type-ohlc',
  8051. typeCandlestick: PREFIX + 'series-type-candlestick',
  8052. fullScreen: PREFIX + 'full-screen',
  8053. toggleAnnotations: PREFIX + 'toggle-annotations',
  8054. saveChart: PREFIX + 'save-chart',
  8055. separator: PREFIX + 'separator'
  8056. };
  8057. extend(Chart.prototype, {
  8058. /**
  8059. * Verify if Toolbar should be added.
  8060. * @private
  8061. * @param {Highcharts.StockToolsOptions} - chart options
  8062. */
  8063. setStockTools: function (options) {
  8064. var chartOptions = this.options,
  8065. lang = chartOptions.lang,
  8066. guiOptions = merge(chartOptions.stockTools && chartOptions.stockTools.gui,
  8067. options && options.gui),
  8068. langOptions = lang.stockTools && lang.stockTools.gui;
  8069. this.stockTools = new Toolbar(guiOptions, langOptions, this);
  8070. if (this.stockTools.guiEnabled) {
  8071. this.isDirtyBox = true;
  8072. }
  8073. }
  8074. });
  8075. // Comunication with bindings:
  8076. addEvent(NavigationBindings, 'selectButton', function (event) {
  8077. var button = event.button,
  8078. className = PREFIX + 'submenu-wrapper',
  8079. gui = this.chart.stockTools;
  8080. if (gui && gui.guiEnabled) {
  8081. // Unslect other active buttons
  8082. gui.unselectAllButtons(event.button);
  8083. // If clicked on a submenu, select state for it's parent
  8084. if (button.parentNode.className.indexOf(className) >= 0) {
  8085. button = button.parentNode.parentNode;
  8086. }
  8087. // Set active class on the current button
  8088. gui.selectButton(button);
  8089. }
  8090. });
  8091. addEvent(NavigationBindings, 'deselectButton', function (event) {
  8092. var button = event.button,
  8093. className = PREFIX + 'submenu-wrapper',
  8094. gui = this.chart.stockTools;
  8095. if (gui && gui.guiEnabled) {
  8096. // If deselecting a button from a submenu, select state for it's parent
  8097. if (button.parentNode.className.indexOf(className) >= 0) {
  8098. button = button.parentNode.parentNode;
  8099. }
  8100. gui.selectButton(button);
  8101. }
  8102. });
  8103. H.Toolbar = Toolbar;
  8104. return H.Toolbar;
  8105. });
  8106. _registerModule(_modules, 'masters/modules/stock-tools.src.js', [], function () {
  8107. });
  8108. }));