stock-tools.src.js 367 KB

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