gantt.src.js 532 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314
  1. /**
  2. * @license Highcharts Gantt JS v8.2.2 (2020-10-22)
  3. *
  4. * Gantt series
  5. *
  6. * (c) 2016-2019 Lars A. V. Cabrera
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/gantt', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Gantt/Tree.js', [_modules['Core/Utilities.js']], function (U) {
  32. /* *
  33. *
  34. * (c) 2016-2020 Highsoft AS
  35. *
  36. * Authors: Jon Arild Nygard
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. /* eslint no-console: 0 */
  44. var extend = U.extend,
  45. isNumber = U.isNumber,
  46. pick = U.pick;
  47. /**
  48. * Creates an object map from parent id to childrens index.
  49. *
  50. * @private
  51. * @function Highcharts.Tree#getListOfParents
  52. *
  53. * @param {Array<*>} data
  54. * List of points set in options. `Array.parent` is parent id of point.
  55. *
  56. * @param {Array<string>} ids
  57. * List of all point ids.
  58. *
  59. * @return {Highcharts.Dictionary<Array<*>>}
  60. * Map from parent id to children index in data
  61. */
  62. var getListOfParents = function (data,
  63. ids) {
  64. var listOfParents = data.reduce(function (prev,
  65. curr) {
  66. var parent = pick(curr.parent, '');
  67. if (typeof prev[parent] === 'undefined') {
  68. prev[parent] = [];
  69. }
  70. prev[parent].push(curr);
  71. return prev;
  72. }, {}), parents = Object.keys(listOfParents);
  73. // If parent does not exist, hoist parent to root of tree.
  74. parents.forEach(function (parent, list) {
  75. var children = listOfParents[parent];
  76. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  77. children.forEach(function (child) {
  78. list[''].push(child);
  79. });
  80. delete list[parent];
  81. }
  82. });
  83. return listOfParents;
  84. };
  85. var getNode = function (id,
  86. parent,
  87. level,
  88. data,
  89. mapOfIdToChildren,
  90. options) {
  91. var descendants = 0,
  92. height = 0,
  93. after = options && options.after,
  94. before = options && options.before,
  95. node = {
  96. data: data,
  97. depth: level - 1,
  98. id: id,
  99. level: level,
  100. parent: parent
  101. },
  102. start,
  103. end,
  104. children;
  105. // Allow custom logic before the children has been created.
  106. if (typeof before === 'function') {
  107. before(node, options);
  108. }
  109. // Call getNode recursively on the children. Calulate the height of the
  110. // node, and the number of descendants.
  111. children = ((mapOfIdToChildren[id] || [])).map(function (child) {
  112. var node = getNode(child.id,
  113. id, (level + 1),
  114. child,
  115. mapOfIdToChildren,
  116. options),
  117. childStart = child.start,
  118. childEnd = (child.milestone === true ?
  119. childStart :
  120. child.end);
  121. // Start should be the lowest child.start.
  122. start = ((!isNumber(start) || childStart < start) ?
  123. childStart :
  124. start);
  125. // End should be the largest child.end.
  126. // If child is milestone, then use start as end.
  127. end = ((!isNumber(end) || childEnd > end) ?
  128. childEnd :
  129. end);
  130. descendants = descendants + 1 + node.descendants;
  131. height = Math.max(node.height + 1, height);
  132. return node;
  133. });
  134. // Calculate start and end for point if it is not already explicitly set.
  135. if (data) {
  136. data.start = pick(data.start, start);
  137. data.end = pick(data.end, end);
  138. }
  139. extend(node, {
  140. children: children,
  141. descendants: descendants,
  142. height: height
  143. });
  144. // Allow custom logic after the children has been created.
  145. if (typeof after === 'function') {
  146. after(node, options);
  147. }
  148. return node;
  149. };
  150. var getTree = function (data,
  151. options) {
  152. var ids = data.map(function (d) {
  153. return d.id;
  154. }), mapOfIdToChildren = getListOfParents(data, ids);
  155. return getNode('', null, 1, null, mapOfIdToChildren, options);
  156. };
  157. var Tree = {
  158. getListOfParents: getListOfParents,
  159. getNode: getNode,
  160. getTree: getTree
  161. };
  162. return Tree;
  163. });
  164. _registerModule(_modules, 'Core/Axis/TreeGridTick.js', [_modules['Core/Utilities.js']], function (U) {
  165. /* *
  166. *
  167. * (c) 2016 Highsoft AS
  168. * Authors: Jon Arild Nygard
  169. *
  170. * License: www.highcharts.com/license
  171. *
  172. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  173. *
  174. * */
  175. var addEvent = U.addEvent,
  176. defined = U.defined,
  177. isObject = U.isObject,
  178. isNumber = U.isNumber,
  179. pick = U.pick,
  180. wrap = U.wrap;
  181. /**
  182. * @private
  183. */
  184. var TreeGridTick;
  185. (function (TreeGridTick) {
  186. /* *
  187. *
  188. * Interfaces
  189. *
  190. * */
  191. /* *
  192. *
  193. * Variables
  194. *
  195. * */
  196. var applied = false;
  197. /* *
  198. *
  199. * Functions
  200. *
  201. * */
  202. /**
  203. * @private
  204. */
  205. function compose(TickClass) {
  206. if (!applied) {
  207. addEvent(TickClass, 'init', onInit);
  208. wrap(TickClass.prototype, 'getLabelPosition', wrapGetLabelPosition);
  209. wrap(TickClass.prototype, 'renderLabel', wrapRenderLabel);
  210. // backwards compatibility
  211. TickClass.prototype.collapse = function (redraw) {
  212. this.treeGrid.collapse(redraw);
  213. };
  214. TickClass.prototype.expand = function (redraw) {
  215. this.treeGrid.expand(redraw);
  216. };
  217. TickClass.prototype.toggleCollapse = function (redraw) {
  218. this.treeGrid.toggleCollapse(redraw);
  219. };
  220. applied = true;
  221. }
  222. }
  223. TreeGridTick.compose = compose;
  224. /**
  225. * @private
  226. */
  227. function onInit() {
  228. var tick = this;
  229. if (!tick.treeGrid) {
  230. tick.treeGrid = new Additions(tick);
  231. }
  232. }
  233. /**
  234. * @private
  235. */
  236. function onTickHover(label) {
  237. label.addClass('highcharts-treegrid-node-active');
  238. if (!label.renderer.styledMode) {
  239. label.css({
  240. textDecoration: 'underline'
  241. });
  242. }
  243. }
  244. /**
  245. * @private
  246. */
  247. function onTickHoverExit(label, options) {
  248. var css = defined(options.style) ? options.style : {};
  249. label.removeClass('highcharts-treegrid-node-active');
  250. if (!label.renderer.styledMode) {
  251. label.css({ textDecoration: css.textDecoration });
  252. }
  253. }
  254. /**
  255. * @private
  256. */
  257. function renderLabelIcon(tick, params) {
  258. var treeGrid = tick.treeGrid,
  259. isNew = !treeGrid.labelIcon,
  260. renderer = params.renderer,
  261. labelBox = params.xy,
  262. options = params.options,
  263. width = options.width,
  264. height = options.height,
  265. iconCenter = {
  266. x: labelBox.x - (width / 2) - options.padding,
  267. y: labelBox.y - (height / 2)
  268. },
  269. rotation = params.collapsed ? 90 : 180,
  270. shouldRender = params.show && isNumber(iconCenter.y);
  271. var icon = treeGrid.labelIcon;
  272. if (!icon) {
  273. treeGrid.labelIcon = icon = renderer
  274. .path(renderer.symbols[options.type](options.x, options.y, width, height))
  275. .addClass('highcharts-label-icon')
  276. .add(params.group);
  277. }
  278. // Set the new position, and show or hide
  279. if (!shouldRender) {
  280. icon.attr({ y: -9999 }); // #1338
  281. }
  282. // Presentational attributes
  283. if (!renderer.styledMode) {
  284. icon
  285. .attr({
  286. 'stroke-width': 1,
  287. 'fill': pick(params.color, '#666666')
  288. })
  289. .css({
  290. cursor: 'pointer',
  291. stroke: options.lineColor,
  292. strokeWidth: options.lineWidth
  293. });
  294. }
  295. // Update the icon positions
  296. icon[isNew ? 'attr' : 'animate']({
  297. translateX: iconCenter.x,
  298. translateY: iconCenter.y,
  299. rotation: rotation
  300. });
  301. }
  302. /**
  303. * @private
  304. */
  305. function wrapGetLabelPosition(proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  306. var tick = this,
  307. lbOptions = pick(tick.options && tick.options.labels,
  308. labelOptions),
  309. pos = tick.pos,
  310. axis = tick.axis,
  311. options = axis.options,
  312. isTreeGrid = options.type === 'treegrid',
  313. result = proceed.apply(tick,
  314. [x,
  315. y,
  316. label,
  317. horiz,
  318. lbOptions,
  319. tickmarkOffset,
  320. index,
  321. step]);
  322. var symbolOptions,
  323. indentation,
  324. mapOfPosToGridNode,
  325. node,
  326. level;
  327. if (isTreeGrid) {
  328. symbolOptions = (lbOptions && isObject(lbOptions.symbol, true) ?
  329. lbOptions.symbol :
  330. {});
  331. indentation = (lbOptions && isNumber(lbOptions.indentation) ?
  332. lbOptions.indentation :
  333. 0);
  334. mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode;
  335. node = mapOfPosToGridNode && mapOfPosToGridNode[pos];
  336. level = (node && node.depth) || 1;
  337. result.x += (
  338. // Add space for symbols
  339. ((symbolOptions.width) + (symbolOptions.padding * 2)) +
  340. // Apply indentation
  341. ((level - 1) * indentation));
  342. }
  343. return result;
  344. }
  345. /**
  346. * @private
  347. */
  348. function wrapRenderLabel(proceed) {
  349. var tick = this, pos = tick.pos, axis = tick.axis, label = tick.label, mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode, options = axis.options, labelOptions = pick(tick.options && tick.options.labels, options && options.labels), symbolOptions = (labelOptions && isObject(labelOptions.symbol, true) ?
  350. labelOptions.symbol :
  351. {}), node = mapOfPosToGridNode && mapOfPosToGridNode[pos], level = node && node.depth, isTreeGrid = options.type === 'treegrid', shouldRender = axis.tickPositions.indexOf(pos) > -1, prefixClassName = 'highcharts-treegrid-node-', styledMode = axis.chart.styledMode;
  352. var collapsed,
  353. addClassName,
  354. removeClassName;
  355. if (isTreeGrid && node) {
  356. // Add class name for hierarchical styling.
  357. if (label &&
  358. label.element) {
  359. label.addClass(prefixClassName + 'level-' + level);
  360. }
  361. }
  362. proceed.apply(tick, Array.prototype.slice.call(arguments, 1));
  363. if (isTreeGrid &&
  364. label &&
  365. label.element &&
  366. node &&
  367. node.descendants &&
  368. node.descendants > 0) {
  369. collapsed = axis.treeGrid.isCollapsed(node);
  370. renderLabelIcon(tick, {
  371. color: !styledMode && label.styles && label.styles.color || '',
  372. collapsed: collapsed,
  373. group: label.parentGroup,
  374. options: symbolOptions,
  375. renderer: label.renderer,
  376. show: shouldRender,
  377. xy: label.xy
  378. });
  379. // Add class name for the node.
  380. addClassName = prefixClassName +
  381. (collapsed ? 'collapsed' : 'expanded');
  382. removeClassName = prefixClassName +
  383. (collapsed ? 'expanded' : 'collapsed');
  384. label
  385. .addClass(addClassName)
  386. .removeClass(removeClassName);
  387. if (!styledMode) {
  388. label.css({
  389. cursor: 'pointer'
  390. });
  391. }
  392. // Add events to both label text and icon
  393. [label, tick.treeGrid.labelIcon].forEach(function (object) {
  394. if (object && !object.attachedTreeGridEvents) {
  395. // On hover
  396. addEvent(object.element, 'mouseover', function () {
  397. onTickHover(label);
  398. });
  399. // On hover out
  400. addEvent(object.element, 'mouseout', function () {
  401. onTickHoverExit(label, labelOptions);
  402. });
  403. addEvent(object.element, 'click', function () {
  404. tick.treeGrid.toggleCollapse();
  405. });
  406. object.attachedTreeGridEvents = true;
  407. }
  408. });
  409. }
  410. }
  411. /* *
  412. *
  413. * Classes
  414. *
  415. * */
  416. /**
  417. * @private
  418. * @class
  419. */
  420. var Additions = /** @class */ (function () {
  421. /* *
  422. *
  423. * Constructors
  424. *
  425. * */
  426. /**
  427. * @private
  428. */
  429. function Additions(tick) {
  430. this.tick = tick;
  431. }
  432. /* *
  433. *
  434. * Functions
  435. *
  436. * */
  437. /**
  438. * Collapse the grid cell. Used when axis is of type treegrid.
  439. *
  440. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  441. *
  442. * @private
  443. * @function Highcharts.Tick#collapse
  444. *
  445. * @param {boolean} [redraw=true]
  446. * Whether to redraw the chart or wait for an explicit call to
  447. * {@link Highcharts.Chart#redraw}
  448. */
  449. Additions.prototype.collapse = function (redraw) {
  450. var tick = this.tick,
  451. axis = tick.axis,
  452. brokenAxis = axis.brokenAxis;
  453. if (brokenAxis &&
  454. axis.treeGrid.mapOfPosToGridNode) {
  455. var pos = tick.pos,
  456. node = axis.treeGrid.mapOfPosToGridNode[pos],
  457. breaks = axis.treeGrid.collapse(node);
  458. brokenAxis.setBreaks(breaks, pick(redraw, true));
  459. }
  460. };
  461. /**
  462. * Expand the grid cell. Used when axis is of type treegrid.
  463. *
  464. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  465. *
  466. * @private
  467. * @function Highcharts.Tick#expand
  468. *
  469. * @param {boolean} [redraw=true]
  470. * Whether to redraw the chart or wait for an explicit call to
  471. * {@link Highcharts.Chart#redraw}
  472. */
  473. Additions.prototype.expand = function (redraw) {
  474. var tick = this.tick,
  475. axis = tick.axis,
  476. brokenAxis = axis.brokenAxis;
  477. if (brokenAxis &&
  478. axis.treeGrid.mapOfPosToGridNode) {
  479. var pos = tick.pos,
  480. node = axis.treeGrid.mapOfPosToGridNode[pos],
  481. breaks = axis.treeGrid.expand(node);
  482. brokenAxis.setBreaks(breaks, pick(redraw, true));
  483. }
  484. };
  485. /**
  486. * Toggle the collapse/expand state of the grid cell. Used when axis is
  487. * of type treegrid.
  488. *
  489. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  490. *
  491. * @private
  492. * @function Highcharts.Tick#toggleCollapse
  493. *
  494. * @param {boolean} [redraw=true]
  495. * Whether to redraw the chart or wait for an explicit call to
  496. * {@link Highcharts.Chart#redraw}
  497. */
  498. Additions.prototype.toggleCollapse = function (redraw) {
  499. var tick = this.tick,
  500. axis = tick.axis,
  501. brokenAxis = axis.brokenAxis;
  502. if (brokenAxis &&
  503. axis.treeGrid.mapOfPosToGridNode) {
  504. var pos = tick.pos,
  505. node = axis.treeGrid.mapOfPosToGridNode[pos],
  506. breaks = axis.treeGrid.toggleCollapse(node);
  507. brokenAxis.setBreaks(breaks, pick(redraw, true));
  508. }
  509. };
  510. return Additions;
  511. }());
  512. TreeGridTick.Additions = Additions;
  513. })(TreeGridTick || (TreeGridTick = {}));
  514. return TreeGridTick;
  515. });
  516. _registerModule(_modules, 'Mixins/TreeSeries.js', [_modules['Core/Color/Color.js'], _modules['Core/Utilities.js']], function (Color, U) {
  517. /* *
  518. *
  519. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  520. *
  521. * */
  522. var extend = U.extend,
  523. isArray = U.isArray,
  524. isNumber = U.isNumber,
  525. isObject = U.isObject,
  526. merge = U.merge,
  527. pick = U.pick;
  528. var isBoolean = function (x) {
  529. return typeof x === 'boolean';
  530. }, isFn = function (x) {
  531. return typeof x === 'function';
  532. };
  533. /* eslint-disable valid-jsdoc */
  534. /**
  535. * @todo Combine buildTree and buildNode with setTreeValues
  536. * @todo Remove logic from Treemap and make it utilize this mixin.
  537. * @private
  538. */
  539. var setTreeValues = function setTreeValues(tree,
  540. options) {
  541. var before = options.before,
  542. idRoot = options.idRoot,
  543. mapIdToNode = options.mapIdToNode,
  544. nodeRoot = mapIdToNode[idRoot],
  545. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  546. options.levelIsConstant :
  547. true),
  548. points = options.points,
  549. point = points[tree.i],
  550. optionsPoint = point && point.options || {},
  551. childrenTotal = 0,
  552. children = [],
  553. value;
  554. extend(tree, {
  555. levelDynamic: tree.level - (levelIsConstant ? 0 : nodeRoot.level),
  556. name: pick(point && point.name, ''),
  557. visible: (idRoot === tree.id ||
  558. (isBoolean(options.visible) ? options.visible : false))
  559. });
  560. if (isFn(before)) {
  561. tree = before(tree, options);
  562. }
  563. // First give the children some values
  564. tree.children.forEach(function (child, i) {
  565. var newOptions = extend({},
  566. options);
  567. extend(newOptions, {
  568. index: i,
  569. siblings: tree.children.length,
  570. visible: tree.visible
  571. });
  572. child = setTreeValues(child, newOptions);
  573. children.push(child);
  574. if (child.visible) {
  575. childrenTotal += child.val;
  576. }
  577. });
  578. tree.visible = childrenTotal > 0 || tree.visible;
  579. // Set the values
  580. value = pick(optionsPoint.value, childrenTotal);
  581. extend(tree, {
  582. children: children,
  583. childrenTotal: childrenTotal,
  584. isLeaf: tree.visible && !childrenTotal,
  585. val: value
  586. });
  587. return tree;
  588. };
  589. /**
  590. * @private
  591. */
  592. var getColor = function getColor(node,
  593. options) {
  594. var index = options.index,
  595. mapOptionsToLevel = options.mapOptionsToLevel,
  596. parentColor = options.parentColor,
  597. parentColorIndex = options.parentColorIndex,
  598. series = options.series,
  599. colors = options.colors,
  600. siblings = options.siblings,
  601. points = series.points,
  602. getColorByPoint,
  603. chartOptionsChart = series.chart.options.chart,
  604. point,
  605. level,
  606. colorByPoint,
  607. colorIndexByPoint,
  608. color,
  609. colorIndex;
  610. /**
  611. * @private
  612. */
  613. function variation(color) {
  614. var colorVariation = level && level.colorVariation;
  615. if (colorVariation) {
  616. if (colorVariation.key === 'brightness') {
  617. return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
  618. }
  619. }
  620. return color;
  621. }
  622. if (node) {
  623. point = points[node.i];
  624. level = mapOptionsToLevel[node.level] || {};
  625. getColorByPoint = point && level.colorByPoint;
  626. if (getColorByPoint) {
  627. colorIndexByPoint = point.index % (colors ?
  628. colors.length :
  629. chartOptionsChart.colorCount);
  630. colorByPoint = colors && colors[colorIndexByPoint];
  631. }
  632. // Select either point color, level color or inherited color.
  633. if (!series.chart.styledMode) {
  634. color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
  635. }
  636. colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
  637. }
  638. return {
  639. color: color,
  640. colorIndex: colorIndex
  641. };
  642. };
  643. /**
  644. * Creates a map from level number to its given options.
  645. *
  646. * @private
  647. * @function getLevelOptions
  648. * @param {object} params
  649. * Object containing parameters.
  650. * - `defaults` Object containing default options. The default options
  651. * are merged with the userOptions to get the final options for a
  652. * specific level.
  653. * - `from` The lowest level number.
  654. * - `levels` User options from series.levels.
  655. * - `to` The highest level number.
  656. * @return {Highcharts.Dictionary<object>|null}
  657. * Returns a map from level number to its given options.
  658. */
  659. var getLevelOptions = function getLevelOptions(params) {
  660. var result = null,
  661. defaults,
  662. converted,
  663. i,
  664. from,
  665. to,
  666. levels;
  667. if (isObject(params)) {
  668. result = {};
  669. from = isNumber(params.from) ? params.from : 1;
  670. levels = params.levels;
  671. converted = {};
  672. defaults = isObject(params.defaults) ? params.defaults : {};
  673. if (isArray(levels)) {
  674. converted = levels.reduce(function (obj, item) {
  675. var level,
  676. levelIsConstant,
  677. options;
  678. if (isObject(item) && isNumber(item.level)) {
  679. options = merge({}, item);
  680. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  681. options.levelIsConstant :
  682. defaults.levelIsConstant);
  683. // Delete redundant properties.
  684. delete options.levelIsConstant;
  685. delete options.level;
  686. // Calculate which level these options apply to.
  687. level = item.level + (levelIsConstant ? 0 : from - 1);
  688. if (isObject(obj[level])) {
  689. extend(obj[level], options);
  690. }
  691. else {
  692. obj[level] = options;
  693. }
  694. }
  695. return obj;
  696. }, {});
  697. }
  698. to = isNumber(params.to) ? params.to : 1;
  699. for (i = 0; i <= to; i++) {
  700. result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
  701. }
  702. }
  703. return result;
  704. };
  705. /**
  706. * Update the rootId property on the series. Also makes sure that it is
  707. * accessible to exporting.
  708. *
  709. * @private
  710. * @function updateRootId
  711. *
  712. * @param {object} series
  713. * The series to operate on.
  714. *
  715. * @return {string}
  716. * Returns the resulting rootId after update.
  717. */
  718. var updateRootId = function (series) {
  719. var rootId,
  720. options;
  721. if (isObject(series)) {
  722. // Get the series options.
  723. options = isObject(series.options) ? series.options : {};
  724. // Calculate the rootId.
  725. rootId = pick(series.rootNode, options.rootId, '');
  726. // Set rootId on series.userOptions to pick it up in exporting.
  727. if (isObject(series.userOptions)) {
  728. series.userOptions.rootId = rootId;
  729. }
  730. // Set rootId on series to pick it up on next update.
  731. series.rootNode = rootId;
  732. }
  733. return rootId;
  734. };
  735. var result = {
  736. getColor: getColor,
  737. getLevelOptions: getLevelOptions,
  738. setTreeValues: setTreeValues,
  739. updateRootId: updateRootId
  740. };
  741. return result;
  742. });
  743. _registerModule(_modules, 'Core/Axis/GridAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Utilities.js']], function (Axis, H, O, Tick, U) {
  744. /* *
  745. *
  746. * (c) 2016 Highsoft AS
  747. * Authors: Lars A. V. Cabrera
  748. *
  749. * License: www.highcharts.com/license
  750. *
  751. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  752. *
  753. * */
  754. var dateFormat = O.dateFormat;
  755. var addEvent = U.addEvent,
  756. defined = U.defined,
  757. erase = U.erase,
  758. find = U.find,
  759. isArray = U.isArray,
  760. isNumber = U.isNumber,
  761. merge = U.merge,
  762. pick = U.pick,
  763. timeUnits = U.timeUnits,
  764. wrap = U.wrap;
  765. var argsToArray = function (args) {
  766. return Array.prototype.slice.call(args, 1);
  767. }, isObject = function (x) {
  768. // Always use strict mode
  769. return U.isObject(x, true);
  770. }, Chart = H.Chart;
  771. var applyGridOptions = function applyGridOptions(axis) {
  772. var options = axis.options;
  773. // Center-align by default
  774. if (!options.labels) {
  775. options.labels = {};
  776. }
  777. options.labels.align = pick(options.labels.align, 'center');
  778. // @todo: Check against tickLabelPlacement between/on etc
  779. /* Prevents adding the last tick label if the axis is not a category
  780. axis.
  781. Since numeric labels are normally placed at starts and ends of a
  782. range of value, and this module makes the label point at the value,
  783. an "extra" label would appear. */
  784. if (!axis.categories) {
  785. options.showLastLabel = false;
  786. }
  787. // Prevents rotation of labels when squished, as rotating them would not
  788. // help.
  789. axis.labelRotation = 0;
  790. options.labels.rotation = 0;
  791. };
  792. /**
  793. * @productdesc {gantt}
  794. * For grid axes (like in Gantt charts),
  795. * it is possible to declare as a list to provide different
  796. * formats depending on available space.
  797. *
  798. * Defaults to:
  799. * ```js
  800. * {
  801. * hour: { list: ['%H:%M', '%H'] },
  802. * day: { list: ['%A, %e. %B', '%a, %e. %b', '%E'] },
  803. * week: { list: ['Week %W', 'W%W'] },
  804. * month: { list: ['%B', '%b', '%o'] }
  805. * }
  806. * ```
  807. *
  808. * @sample {gantt} gantt/grid-axis/date-time-label-formats
  809. * Gantt chart with custom axis date format.
  810. *
  811. * @apioption xAxis.dateTimeLabelFormats
  812. */
  813. /**
  814. * Set grid options for the axis labels. Requires Highcharts Gantt.
  815. *
  816. * @since 6.2.0
  817. * @product gantt
  818. * @apioption xAxis.grid
  819. */
  820. /**
  821. * Enable grid on the axis labels. Defaults to true for Gantt charts.
  822. *
  823. * @type {boolean}
  824. * @default true
  825. * @since 6.2.0
  826. * @product gantt
  827. * @apioption xAxis.grid.enabled
  828. */
  829. /**
  830. * Set specific options for each column (or row for horizontal axes) in the
  831. * grid. Each extra column/row is its own axis, and the axis options can be set
  832. * here.
  833. *
  834. * @sample gantt/demo/left-axis-table
  835. * Left axis as a table
  836. *
  837. * @type {Array<Highcharts.XAxisOptions>}
  838. * @apioption xAxis.grid.columns
  839. */
  840. /**
  841. * Set border color for the label grid lines.
  842. *
  843. * @type {Highcharts.ColorString}
  844. * @apioption xAxis.grid.borderColor
  845. */
  846. /**
  847. * Set border width of the label grid lines.
  848. *
  849. * @type {number}
  850. * @default 1
  851. * @apioption xAxis.grid.borderWidth
  852. */
  853. /**
  854. * Set cell height for grid axis labels. By default this is calculated from font
  855. * size. This option only applies to horizontal axes.
  856. *
  857. * @sample gantt/grid-axis/cellheight
  858. * Gant chart with custom cell height
  859. * @type {number}
  860. * @apioption xAxis.grid.cellHeight
  861. */
  862. ''; // detach doclets above
  863. /**
  864. * Get the largest label width and height.
  865. *
  866. * @private
  867. * @function Highcharts.Axis#getMaxLabelDimensions
  868. *
  869. * @param {Highcharts.Dictionary<Highcharts.Tick>} ticks
  870. * All the ticks on one axis.
  871. *
  872. * @param {Array<number|string>} tickPositions
  873. * All the tick positions on one axis.
  874. *
  875. * @return {Highcharts.SizeObject}
  876. * Object containing the properties height and width.
  877. *
  878. * @todo Move this to the generic axis implementation, as it is used there.
  879. */
  880. Axis.prototype.getMaxLabelDimensions = function (ticks, tickPositions) {
  881. var dimensions = {
  882. width: 0,
  883. height: 0
  884. };
  885. tickPositions.forEach(function (pos) {
  886. var tick = ticks[pos],
  887. labelHeight = 0,
  888. labelWidth = 0,
  889. label;
  890. if (isObject(tick)) {
  891. label = isObject(tick.label) ? tick.label : {};
  892. // Find width and height of label
  893. labelHeight = label.getBBox ? label.getBBox().height : 0;
  894. if (label.textStr && !isNumber(label.textPxLength)) {
  895. label.textPxLength = label.getBBox().width;
  896. }
  897. labelWidth = isNumber(label.textPxLength) ?
  898. // Math.round ensures crisp lines
  899. Math.round(label.textPxLength) :
  900. 0;
  901. if (label.textStr) {
  902. // Set the tickWidth same as the label width after ellipsis
  903. // applied #10281
  904. labelWidth = Math.round(label.getBBox().width);
  905. }
  906. // Update the result if width and/or height are larger
  907. dimensions.height = Math.max(labelHeight, dimensions.height);
  908. dimensions.width = Math.max(labelWidth, dimensions.width);
  909. }
  910. });
  911. return dimensions;
  912. };
  913. // Adds week date format
  914. H.dateFormats.W = function (timestamp) {
  915. var d = new this.Date(timestamp);
  916. var firstDay = (this.get('Day',
  917. d) + 6) % 7;
  918. var thursday = new this.Date(d.valueOf());
  919. this.set('Date', thursday, this.get('Date', d) - firstDay + 3);
  920. var firstThursday = new this.Date(this.get('FullYear',
  921. thursday), 0, 1);
  922. if (this.get('Day', firstThursday) !== 4) {
  923. this.set('Month', d, 0);
  924. this.set('Date', d, 1 + (11 - this.get('Day', firstThursday)) % 7);
  925. }
  926. return (1 +
  927. Math.floor((thursday.valueOf() - firstThursday.valueOf()) / 604800000)).toString();
  928. };
  929. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  930. H.dateFormats.E = function (timestamp) {
  931. return this.dateFormat('%a', timestamp, true).charAt(0);
  932. };
  933. /* eslint-disable no-invalid-this */
  934. addEvent(Chart, 'afterSetChartSize', function () {
  935. this.axes.forEach(function (axis) {
  936. (axis.grid && axis.grid.columns || []).forEach(function (column) {
  937. column.setAxisSize();
  938. column.setAxisTranslation();
  939. });
  940. });
  941. });
  942. // Center tick labels in cells.
  943. addEvent(Tick, 'afterGetLabelPosition', function (e) {
  944. var tick = this,
  945. label = tick.label,
  946. axis = tick.axis,
  947. reversed = axis.reversed,
  948. chart = axis.chart,
  949. options = axis.options,
  950. gridOptions = options.grid || {},
  951. labelOpts = axis.options.labels,
  952. align = labelOpts.align,
  953. // verticalAlign is currently not supported for axis.labels.
  954. verticalAlign = 'middle', // labelOpts.verticalAlign,
  955. side = GridAxis.Side[axis.side],
  956. tickmarkOffset = e.tickmarkOffset,
  957. tickPositions = axis.tickPositions,
  958. tickPos = tick.pos - tickmarkOffset,
  959. nextTickPos = (isNumber(tickPositions[e.index + 1]) ?
  960. tickPositions[e.index + 1] - tickmarkOffset :
  961. axis.max + tickmarkOffset),
  962. tickSize = axis.tickSize('tick'),
  963. tickWidth = tickSize ? tickSize[0] : 0,
  964. crispCorr = tickSize ? tickSize[1] / 2 : 0,
  965. labelHeight,
  966. lblMetrics,
  967. lines,
  968. bottom,
  969. top,
  970. left,
  971. right;
  972. // Only center tick labels in grid axes
  973. if (gridOptions.enabled === true) {
  974. // Calculate top and bottom positions of the cell.
  975. if (side === 'top') {
  976. bottom = axis.top + axis.offset;
  977. top = bottom - tickWidth;
  978. }
  979. else if (side === 'bottom') {
  980. top = chart.chartHeight - axis.bottom + axis.offset;
  981. bottom = top + tickWidth;
  982. }
  983. else {
  984. bottom = axis.top + axis.len - axis.translate(reversed ? nextTickPos : tickPos);
  985. top = axis.top + axis.len - axis.translate(reversed ? tickPos : nextTickPos);
  986. }
  987. // Calculate left and right positions of the cell.
  988. if (side === 'right') {
  989. left = chart.chartWidth - axis.right + axis.offset;
  990. right = left + tickWidth;
  991. }
  992. else if (side === 'left') {
  993. right = axis.left + axis.offset;
  994. left = right - tickWidth;
  995. }
  996. else {
  997. left = Math.round(axis.left + axis.translate(reversed ? nextTickPos : tickPos)) - crispCorr;
  998. right = Math.round(axis.left + axis.translate(reversed ? tickPos : nextTickPos)) - crispCorr;
  999. }
  1000. tick.slotWidth = right - left;
  1001. // Calculate the positioning of the label based on
  1002. // alignment.
  1003. e.pos.x = (align === 'left' ?
  1004. left :
  1005. align === 'right' ?
  1006. right :
  1007. left + ((right - left) / 2) // default to center
  1008. );
  1009. e.pos.y = (verticalAlign === 'top' ?
  1010. top :
  1011. verticalAlign === 'bottom' ?
  1012. bottom :
  1013. top + ((bottom - top) / 2) // default to middle
  1014. );
  1015. lblMetrics = chart.renderer.fontMetrics(labelOpts.style.fontSize, label.element);
  1016. labelHeight = label.getBBox().height;
  1017. // Adjustment to y position to align the label correctly.
  1018. // Would be better to have a setter or similar for this.
  1019. if (!labelOpts.useHTML) {
  1020. lines = Math.round(labelHeight / lblMetrics.h);
  1021. e.pos.y += (
  1022. // Center the label
  1023. // TODO: why does this actually center the label?
  1024. ((lblMetrics.b - (lblMetrics.h - lblMetrics.f)) / 2) +
  1025. // Adjust for height of additional lines.
  1026. -(((lines - 1) * lblMetrics.h) / 2));
  1027. }
  1028. else {
  1029. e.pos.y += (
  1030. // Readjust yCorr in htmlUpdateTransform
  1031. lblMetrics.b +
  1032. // Adjust for height of html label
  1033. -(labelHeight / 2));
  1034. }
  1035. e.pos.x += (axis.horiz && labelOpts.x || 0);
  1036. }
  1037. });
  1038. /* eslint-enable no-invalid-this */
  1039. /**
  1040. * Additions for grid axes.
  1041. * @private
  1042. * @class
  1043. */
  1044. var GridAxisAdditions = /** @class */ (function () {
  1045. /* *
  1046. *
  1047. * Constructors
  1048. *
  1049. * */
  1050. function GridAxisAdditions(axis) {
  1051. this.axis = axis;
  1052. }
  1053. /* *
  1054. *
  1055. * Functions
  1056. *
  1057. * */
  1058. /**
  1059. * Checks if an axis is the outer axis in its dimension. Since
  1060. * axes are placed outwards in order, the axis with the highest
  1061. * index is the outermost axis.
  1062. *
  1063. * Example: If there are multiple x-axes at the top of the chart,
  1064. * this function returns true if the axis supplied is the last
  1065. * of the x-axes.
  1066. *
  1067. * @private
  1068. *
  1069. * @return {boolean}
  1070. * True if the axis is the outermost axis in its dimension; false if
  1071. * not.
  1072. */
  1073. GridAxisAdditions.prototype.isOuterAxis = function () {
  1074. var axis = this.axis;
  1075. var chart = axis.chart;
  1076. var columnIndex = axis.grid.columnIndex;
  1077. var columns = (axis.linkedParent && axis.linkedParent.grid.columns ||
  1078. axis.grid.columns);
  1079. var parentAxis = columnIndex ? axis.linkedParent : axis;
  1080. var thisIndex = -1,
  1081. lastIndex = 0;
  1082. chart[axis.coll].forEach(function (otherAxis, index) {
  1083. if (otherAxis.side === axis.side && !otherAxis.options.isInternal) {
  1084. lastIndex = index;
  1085. if (otherAxis === parentAxis) {
  1086. // Get the index of the axis in question
  1087. thisIndex = index;
  1088. }
  1089. }
  1090. });
  1091. return (lastIndex === thisIndex &&
  1092. (isNumber(columnIndex) ? columns.length === columnIndex : true));
  1093. };
  1094. /**
  1095. * Add extra border based on the provided path.
  1096. * *
  1097. * @private
  1098. *
  1099. * @param {SVGPath} path
  1100. * The path of the border.
  1101. *
  1102. * @return {Highcharts.SVGElement}
  1103. */
  1104. GridAxisAdditions.prototype.renderBorder = function (path) {
  1105. var axis = this.axis,
  1106. renderer = axis.chart.renderer,
  1107. options = axis.options,
  1108. extraBorderLine = renderer.path(path)
  1109. .addClass('highcharts-axis-line')
  1110. .add(axis.axisBorder);
  1111. if (!renderer.styledMode) {
  1112. extraBorderLine.attr({
  1113. stroke: options.lineColor,
  1114. 'stroke-width': options.lineWidth,
  1115. zIndex: 7
  1116. });
  1117. }
  1118. return extraBorderLine;
  1119. };
  1120. return GridAxisAdditions;
  1121. }());
  1122. /**
  1123. * Axis with grid support.
  1124. * @private
  1125. * @class
  1126. */
  1127. var GridAxis = /** @class */ (function () {
  1128. function GridAxis() {
  1129. }
  1130. /* *
  1131. *
  1132. * Static Functions
  1133. *
  1134. * */
  1135. /* eslint-disable valid-jsdoc */
  1136. /**
  1137. * Extends axis class with grid support.
  1138. * @private
  1139. */
  1140. GridAxis.compose = function (AxisClass) {
  1141. Axis.keepProps.push('grid');
  1142. wrap(AxisClass.prototype, 'unsquish', GridAxis.wrapUnsquish);
  1143. // Add event handlers
  1144. addEvent(AxisClass, 'init', GridAxis.onInit);
  1145. addEvent(AxisClass, 'afterGetOffset', GridAxis.onAfterGetOffset);
  1146. addEvent(AxisClass, 'afterGetTitlePosition', GridAxis.onAfterGetTitlePosition);
  1147. addEvent(AxisClass, 'afterInit', GridAxis.onAfterInit);
  1148. addEvent(AxisClass, 'afterRender', GridAxis.onAfterRender);
  1149. addEvent(AxisClass, 'afterSetAxisTranslation', GridAxis.onAfterSetAxisTranslation);
  1150. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions);
  1151. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions2);
  1152. addEvent(AxisClass, 'afterSetScale', GridAxis.onAfterSetScale);
  1153. addEvent(AxisClass, 'afterTickSize', GridAxis.onAfterTickSize);
  1154. addEvent(AxisClass, 'trimTicks', GridAxis.onTrimTicks);
  1155. addEvent(AxisClass, 'destroy', GridAxis.onDestroy);
  1156. };
  1157. /**
  1158. * Handle columns and getOffset.
  1159. * @private
  1160. */
  1161. GridAxis.onAfterGetOffset = function () {
  1162. var grid = this.grid;
  1163. (grid && grid.columns || []).forEach(function (column) {
  1164. column.getOffset();
  1165. });
  1166. };
  1167. /**
  1168. * @private
  1169. */
  1170. GridAxis.onAfterGetTitlePosition = function (e) {
  1171. var axis = this;
  1172. var options = axis.options;
  1173. var gridOptions = options.grid || {};
  1174. if (gridOptions.enabled === true) {
  1175. // compute anchor points for each of the title align options
  1176. var title = axis.axisTitle,
  1177. axisHeight = axis.height,
  1178. horiz = axis.horiz,
  1179. axisLeft = axis.left,
  1180. offset = axis.offset,
  1181. opposite = axis.opposite,
  1182. _a = axis.options.title,
  1183. axisTitleOptions = _a === void 0 ? {} : _a,
  1184. axisTop = axis.top,
  1185. axisWidth = axis.width;
  1186. var tickSize = axis.tickSize();
  1187. var titleWidth = title && title.getBBox().width;
  1188. var xOption = axisTitleOptions.x || 0;
  1189. var yOption = axisTitleOptions.y || 0;
  1190. var titleMargin = pick(axisTitleOptions.margin,
  1191. horiz ? 5 : 10);
  1192. var titleFontSize = axis.chart.renderer.fontMetrics(axisTitleOptions.style &&
  1193. axisTitleOptions.style.fontSize,
  1194. title).f;
  1195. var crispCorr = tickSize ? tickSize[0] / 2 : 0;
  1196. // TODO account for alignment
  1197. // the position in the perpendicular direction of the axis
  1198. var offAxis = ((horiz ? axisTop + axisHeight : axisLeft) +
  1199. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  1200. (opposite ? -1 : 1) * // so does opposite axes
  1201. crispCorr +
  1202. (axis.side === GridAxis.Side.bottom ? titleFontSize : 0));
  1203. e.titlePosition.x = horiz ?
  1204. axisLeft - titleWidth / 2 - titleMargin + xOption :
  1205. offAxis + (opposite ? axisWidth : 0) + offset + xOption;
  1206. e.titlePosition.y = horiz ?
  1207. (offAxis -
  1208. (opposite ? axisHeight : 0) +
  1209. (opposite ? titleFontSize : -titleFontSize) / 2 +
  1210. offset +
  1211. yOption) :
  1212. axisTop - titleMargin + yOption;
  1213. }
  1214. };
  1215. /**
  1216. * @private
  1217. */
  1218. GridAxis.onAfterInit = function () {
  1219. var axis = this;
  1220. var chart = axis.chart,
  1221. _a = axis.options.grid,
  1222. gridOptions = _a === void 0 ? {} : _a,
  1223. userOptions = axis.userOptions;
  1224. if (gridOptions.enabled) {
  1225. applyGridOptions(axis);
  1226. /* eslint-disable no-invalid-this */
  1227. // TODO: wrap the axis instead
  1228. wrap(axis, 'labelFormatter', function (proceed) {
  1229. var _a = this,
  1230. axis = _a.axis,
  1231. value = _a.value;
  1232. var tickPos = axis.tickPositions;
  1233. var series = (axis.isLinked ?
  1234. axis.linkedParent :
  1235. axis).series[0];
  1236. var isFirst = value === tickPos[0];
  1237. var isLast = value === tickPos[tickPos.length - 1];
  1238. var point = series && find(series.options.data,
  1239. function (p) {
  1240. return p[axis.isXAxis ? 'x' : 'y'] === value;
  1241. });
  1242. var pointCopy;
  1243. if (point && series.is('gantt')) {
  1244. // For the Gantt set point aliases to the pointCopy
  1245. // to do not change the original point
  1246. pointCopy = merge(point);
  1247. H.seriesTypes.gantt.prototype.setGanttPointAliases(pointCopy);
  1248. }
  1249. // Make additional properties available for the
  1250. // formatter
  1251. this.isFirst = isFirst;
  1252. this.isLast = isLast;
  1253. this.point = pointCopy;
  1254. // Call original labelFormatter
  1255. return proceed.call(this);
  1256. });
  1257. /* eslint-enable no-invalid-this */
  1258. }
  1259. if (gridOptions.columns) {
  1260. var columns = axis.grid.columns = [],
  1261. columnIndex = axis.grid.columnIndex = 0;
  1262. // Handle columns, each column is a grid axis
  1263. while (++columnIndex < gridOptions.columns.length) {
  1264. var columnOptions = merge(userOptions,
  1265. gridOptions.columns[gridOptions.columns.length - columnIndex - 1], {
  1266. linkedTo: 0,
  1267. // Force to behave like category axis
  1268. type: 'category',
  1269. // Disable by default the scrollbar on the grid axis
  1270. scrollbar: {
  1271. enabled: false
  1272. }
  1273. });
  1274. delete columnOptions.grid.columns; // Prevent recursion
  1275. var column = new Axis(axis.chart,
  1276. columnOptions);
  1277. column.grid.isColumn = true;
  1278. column.grid.columnIndex = columnIndex;
  1279. // Remove column axis from chart axes array, and place it
  1280. // in the columns array.
  1281. erase(chart.axes, column);
  1282. erase(chart[axis.coll], column);
  1283. columns.push(column);
  1284. }
  1285. }
  1286. };
  1287. /**
  1288. * Draw an extra line on the far side of the outermost axis,
  1289. * creating floor/roof/wall of a grid. And some padding.
  1290. * ```
  1291. * Make this:
  1292. * (axis.min) __________________________ (axis.max)
  1293. * | | | | |
  1294. * Into this:
  1295. * (axis.min) __________________________ (axis.max)
  1296. * ___|____|____|____|____|__
  1297. * ```
  1298. * @private
  1299. */
  1300. GridAxis.onAfterRender = function () {
  1301. var _a;
  1302. var axis = this,
  1303. grid = axis.grid,
  1304. options = axis.options,
  1305. gridOptions = options.grid || {};
  1306. if (gridOptions.enabled === true) {
  1307. // @todo acutual label padding (top, bottom, left, right)
  1308. axis.maxLabelDimensions = axis.getMaxLabelDimensions(axis.ticks, axis.tickPositions);
  1309. // Remove right wall before rendering if updating
  1310. if (axis.rightWall) {
  1311. axis.rightWall.destroy();
  1312. }
  1313. /*
  1314. Draw an extra axis line on outer axes
  1315. >
  1316. Make this: |______|______|______|___
  1317. > _________________________
  1318. Into this: |______|______|______|__|
  1319. */
  1320. if (axis.grid && axis.grid.isOuterAxis() && axis.axisLine) {
  1321. var lineWidth = options.lineWidth;
  1322. if (lineWidth) {
  1323. var linePath = axis.getLinePath(lineWidth),
  1324. startPoint = linePath[0],
  1325. endPoint = linePath[1],
  1326. // Negate distance if top or left axis
  1327. // Subtract 1px to draw the line at the end of the tick
  1328. tickLength = (axis.tickSize('tick') || [1])[0],
  1329. distance = (tickLength - 1) * ((axis.side === GridAxis.Side.top ||
  1330. axis.side === GridAxis.Side.left) ? -1 : 1);
  1331. // If axis is horizontal, reposition line path vertically
  1332. if (startPoint[0] === 'M' && endPoint[0] === 'L') {
  1333. if (axis.horiz) {
  1334. startPoint[2] += distance;
  1335. endPoint[2] += distance;
  1336. }
  1337. else {
  1338. startPoint[1] += distance;
  1339. endPoint[1] += distance;
  1340. }
  1341. }
  1342. // If it doesn't exist, add an upper and lower border
  1343. // for the vertical grid axis.
  1344. if (!axis.horiz && axis.chart.marginRight) {
  1345. var upperBorderStartPoint = startPoint, upperBorderEndPoint = ['L', axis.left, startPoint[2]], upperBorderPath = [upperBorderStartPoint, upperBorderEndPoint], lowerBorderEndPoint = ['L', axis.chart.chartWidth - axis.chart.marginRight, axis.toPixels(axis.max + axis.tickmarkOffset)], lowerBorderStartPoint = ['M', endPoint[1], axis.toPixels(axis.max + axis.tickmarkOffset)], lowerBorderPath = [lowerBorderStartPoint, lowerBorderEndPoint];
  1346. if (!axis.grid.upperBorder && axis.min % 1 !== 0) {
  1347. axis.grid.upperBorder = axis.grid.renderBorder(upperBorderPath);
  1348. }
  1349. if (axis.grid.upperBorder) {
  1350. axis.grid.upperBorder.animate({
  1351. d: upperBorderPath
  1352. });
  1353. }
  1354. if (!axis.grid.lowerBorder && axis.max % 1 !== 0) {
  1355. axis.grid.lowerBorder = axis.grid.renderBorder(lowerBorderPath);
  1356. }
  1357. if (axis.grid.lowerBorder) {
  1358. axis.grid.lowerBorder.animate({
  1359. d: lowerBorderPath
  1360. });
  1361. }
  1362. }
  1363. // Render an extra line parallel to the existing axes,
  1364. // to close the grid.
  1365. if (!axis.grid.axisLineExtra) {
  1366. axis.grid.axisLineExtra = axis.grid.renderBorder(linePath);
  1367. }
  1368. else {
  1369. axis.grid.axisLineExtra.animate({
  1370. d: linePath
  1371. });
  1372. }
  1373. // show or hide the line depending on
  1374. // options.showEmpty
  1375. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  1376. }
  1377. }
  1378. (grid && grid.columns || []).forEach(function (column) {
  1379. column.render();
  1380. });
  1381. // Manipulate the tick mark visibility
  1382. // based on the axis.max- allows smooth scrolling.
  1383. if (!axis.horiz && axis.chart.hasRendered && (axis.scrollbar || ((_a = axis.linkedParent) === null || _a === void 0 ? void 0 : _a.scrollbar))) {
  1384. var max = axis.max,
  1385. min = axis.min,
  1386. tickmarkOffset = axis.tickmarkOffset,
  1387. lastTick = axis.tickPositions[axis.tickPositions.length - 1],
  1388. firstTick = axis.tickPositions[0];
  1389. // Hide/show firts tick label.
  1390. if (min - firstTick > tickmarkOffset) {
  1391. axis.ticks[firstTick].label.hide();
  1392. }
  1393. else {
  1394. axis.ticks[firstTick].label.show();
  1395. }
  1396. // Hide/show last tick mark/label.
  1397. if (lastTick - max > tickmarkOffset) {
  1398. axis.ticks[lastTick].label.hide();
  1399. }
  1400. else {
  1401. axis.ticks[lastTick].label.show();
  1402. }
  1403. if (lastTick - max < tickmarkOffset && lastTick - max > 0 && axis.ticks[lastTick].isLast) {
  1404. axis.ticks[lastTick].mark.hide();
  1405. }
  1406. else {
  1407. axis.ticks[lastTick - 1].mark.show();
  1408. }
  1409. }
  1410. }
  1411. };
  1412. /**
  1413. * @private
  1414. */
  1415. GridAxis.onAfterSetAxisTranslation = function () {
  1416. var _a;
  1417. var axis = this;
  1418. var tickInfo = axis.tickPositions && axis.tickPositions.info;
  1419. var options = axis.options;
  1420. var gridOptions = options.grid || {};
  1421. var userLabels = axis.userOptions.labels || {};
  1422. if (axis.horiz) {
  1423. if (gridOptions.enabled === true) {
  1424. axis.series.forEach(function (series) {
  1425. series.options.pointRange = 0;
  1426. });
  1427. }
  1428. // Lower level time ticks, like hours or minutes, represent
  1429. // points in time and not ranges. These should be aligned
  1430. // left in the grid cell by default. The same applies to
  1431. // years of higher order.
  1432. if (tickInfo &&
  1433. options.dateTimeLabelFormats &&
  1434. options.labels &&
  1435. !defined(userLabels.align) &&
  1436. (options.dateTimeLabelFormats[tickInfo.unitName].range === false ||
  1437. tickInfo.count > 1 // years
  1438. )) {
  1439. options.labels.align = 'left';
  1440. if (!defined(userLabels.x)) {
  1441. options.labels.x = 3;
  1442. }
  1443. }
  1444. }
  1445. else {
  1446. // Don't trim ticks which not in min/max range but
  1447. // they are still in the min/max plus tickInterval.
  1448. if (this.options.type !== 'treegrid' && ((_a = axis.grid) === null || _a === void 0 ? void 0 : _a.columns)) {
  1449. this.minPointOffset = this.tickInterval;
  1450. }
  1451. }
  1452. };
  1453. /**
  1454. * Creates a left and right wall on horizontal axes:
  1455. * - Places leftmost tick at the start of the axis, to create a left
  1456. * wall
  1457. * - Ensures that the rightmost tick is at the end of the axis, to
  1458. * create a right wall.
  1459. * @private
  1460. */
  1461. GridAxis.onAfterSetOptions = function (e) {
  1462. var options = this.options,
  1463. userOptions = e.userOptions,
  1464. gridAxisOptions,
  1465. gridOptions = ((options && isObject(options.grid)) ? options.grid : {});
  1466. if (gridOptions.enabled === true) {
  1467. // Merge the user options into default grid axis options so
  1468. // that when a user option is set, it takes presedence.
  1469. gridAxisOptions = merge(true, {
  1470. className: ('highcharts-grid-axis ' + (userOptions.className || '')),
  1471. dateTimeLabelFormats: {
  1472. hour: {
  1473. list: ['%H:%M', '%H']
  1474. },
  1475. day: {
  1476. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  1477. },
  1478. week: {
  1479. list: ['Week %W', 'W%W']
  1480. },
  1481. month: {
  1482. list: ['%B', '%b', '%o']
  1483. }
  1484. },
  1485. grid: {
  1486. borderWidth: 1
  1487. },
  1488. labels: {
  1489. padding: 2,
  1490. style: {
  1491. fontSize: '13px'
  1492. }
  1493. },
  1494. margin: 0,
  1495. title: {
  1496. text: null,
  1497. reserveSpace: false,
  1498. rotation: 0
  1499. },
  1500. // In a grid axis, only allow one unit of certain types,
  1501. // for example we shouln't have one grid cell spanning
  1502. // two days.
  1503. units: [[
  1504. 'millisecond',
  1505. [1, 10, 100]
  1506. ], [
  1507. 'second',
  1508. [1, 10]
  1509. ], [
  1510. 'minute',
  1511. [1, 5, 15]
  1512. ], [
  1513. 'hour',
  1514. [1, 6]
  1515. ], [
  1516. 'day',
  1517. [1]
  1518. ], [
  1519. 'week',
  1520. [1]
  1521. ], [
  1522. 'month',
  1523. [1]
  1524. ], [
  1525. 'year',
  1526. null
  1527. ]]
  1528. }, userOptions);
  1529. // X-axis specific options
  1530. if (this.coll === 'xAxis') {
  1531. // For linked axes, tickPixelInterval is used only if
  1532. // the tickPositioner below doesn't run or returns
  1533. // undefined (like multiple years)
  1534. if (defined(userOptions.linkedTo) &&
  1535. !defined(userOptions.tickPixelInterval)) {
  1536. gridAxisOptions.tickPixelInterval = 350;
  1537. }
  1538. // For the secondary grid axis, use the primary axis'
  1539. // tick intervals and return ticks one level higher.
  1540. if (
  1541. // Check for tick pixel interval in options
  1542. !defined(userOptions.tickPixelInterval) &&
  1543. // Only for linked axes
  1544. defined(userOptions.linkedTo) &&
  1545. !defined(userOptions.tickPositioner) &&
  1546. !defined(userOptions.tickInterval)) {
  1547. gridAxisOptions.tickPositioner = function (min, max) {
  1548. var parentInfo = (this.linkedParent &&
  1549. this.linkedParent.tickPositions &&
  1550. this.linkedParent.tickPositions.info);
  1551. if (parentInfo) {
  1552. var unitIdx,
  1553. count,
  1554. unitName,
  1555. i,
  1556. units = gridAxisOptions.units,
  1557. unitRange;
  1558. for (i = 0; i < units.length; i++) {
  1559. if (units[i][0] ===
  1560. parentInfo.unitName) {
  1561. unitIdx = i;
  1562. break;
  1563. }
  1564. }
  1565. // Get the first allowed count on the next
  1566. // unit.
  1567. if (units[unitIdx + 1]) {
  1568. unitName = units[unitIdx + 1][0];
  1569. count =
  1570. (units[unitIdx + 1][1] || [1])[0];
  1571. // In case the base X axis shows years, make
  1572. // the secondary axis show ten times the
  1573. // years (#11427)
  1574. }
  1575. else if (parentInfo.unitName === 'year') {
  1576. unitName = 'year';
  1577. count = parentInfo.count * 10;
  1578. }
  1579. unitRange = timeUnits[unitName];
  1580. this.tickInterval = unitRange * count;
  1581. return this.getTimeTicks({
  1582. unitRange: unitRange,
  1583. count: count,
  1584. unitName: unitName
  1585. }, min, max, this.options.startOfWeek);
  1586. }
  1587. };
  1588. }
  1589. }
  1590. // Now merge the combined options into the axis options
  1591. merge(true, this.options, gridAxisOptions);
  1592. if (this.horiz) {
  1593. /* _________________________
  1594. Make this: ___|_____|_____|_____|__|
  1595. ^ ^
  1596. _________________________
  1597. Into this: |_____|_____|_____|_____|
  1598. ^ ^ */
  1599. options.minPadding = pick(userOptions.minPadding, 0);
  1600. options.maxPadding = pick(userOptions.maxPadding, 0);
  1601. }
  1602. // If borderWidth is set, then use its value for tick and
  1603. // line width.
  1604. if (isNumber(options.grid.borderWidth)) {
  1605. options.tickWidth = options.lineWidth = gridOptions.borderWidth;
  1606. }
  1607. }
  1608. };
  1609. /**
  1610. * @private
  1611. */
  1612. GridAxis.onAfterSetOptions2 = function (e) {
  1613. var axis = this;
  1614. var userOptions = e.userOptions;
  1615. var gridOptions = userOptions && userOptions.grid || {};
  1616. var columns = gridOptions.columns;
  1617. // Add column options to the parent axis. Children has their column
  1618. // options set on init in onGridAxisAfterInit.
  1619. if (gridOptions.enabled && columns) {
  1620. merge(true, axis.options, columns[columns.length - 1]);
  1621. }
  1622. };
  1623. /**
  1624. * Handle columns and setScale.
  1625. * @private
  1626. */
  1627. GridAxis.onAfterSetScale = function () {
  1628. var axis = this;
  1629. (axis.grid.columns || []).forEach(function (column) {
  1630. column.setScale();
  1631. });
  1632. };
  1633. /**
  1634. * Draw vertical axis ticks extra long to create cell floors and roofs.
  1635. * Overrides the tickLength for vertical axes.
  1636. * @private
  1637. */
  1638. GridAxis.onAfterTickSize = function (e) {
  1639. var defaultLeftAxisOptions = Axis.defaultLeftAxisOptions;
  1640. var _a = this,
  1641. horiz = _a.horiz,
  1642. maxLabelDimensions = _a.maxLabelDimensions,
  1643. _b = _a.options.grid,
  1644. gridOptions = _b === void 0 ? {} : _b;
  1645. if (gridOptions.enabled && maxLabelDimensions) {
  1646. var labelPadding = (Math.abs(defaultLeftAxisOptions.labels.x) * 2);
  1647. var distance = horiz ?
  1648. gridOptions.cellHeight || labelPadding + maxLabelDimensions.height :
  1649. labelPadding + maxLabelDimensions.width;
  1650. if (isArray(e.tickSize)) {
  1651. e.tickSize[0] = distance;
  1652. }
  1653. else {
  1654. e.tickSize = [distance, 0];
  1655. }
  1656. }
  1657. };
  1658. /**
  1659. * @private
  1660. */
  1661. GridAxis.onDestroy = function (e) {
  1662. var grid = this.grid;
  1663. (grid.columns || []).forEach(function (column) {
  1664. column.destroy(e.keepEvents);
  1665. });
  1666. grid.columns = void 0;
  1667. };
  1668. /**
  1669. * Wraps axis init to draw cell walls on vertical axes.
  1670. * @private
  1671. */
  1672. GridAxis.onInit = function (e) {
  1673. var axis = this;
  1674. var userOptions = e.userOptions || {};
  1675. var gridOptions = userOptions.grid || {};
  1676. if (gridOptions.enabled && defined(gridOptions.borderColor)) {
  1677. userOptions.tickColor = userOptions.lineColor = gridOptions.borderColor;
  1678. }
  1679. if (!axis.grid) {
  1680. axis.grid = new GridAxisAdditions(axis);
  1681. }
  1682. };
  1683. /**
  1684. * Makes tick labels which are usually ignored in a linked axis
  1685. * displayed if they are within range of linkedParent.min.
  1686. * ```
  1687. * _____________________________
  1688. * | | | | |
  1689. * Make this: | | 2 | 3 | 4 |
  1690. * |___|_______|_______|_______|
  1691. * ^
  1692. * _____________________________
  1693. * | | | | |
  1694. * Into this: | 1 | 2 | 3 | 4 |
  1695. * |___|_______|_______|_______|
  1696. * ^
  1697. * ```
  1698. * @private
  1699. * @todo Does this function do what the drawing says? Seems to affect
  1700. * ticks and not the labels directly?
  1701. */
  1702. GridAxis.onTrimTicks = function () {
  1703. var axis = this;
  1704. var options = axis.options;
  1705. var gridOptions = options.grid || {};
  1706. var categoryAxis = axis.categories;
  1707. var tickPositions = axis.tickPositions;
  1708. var firstPos = tickPositions[0];
  1709. var lastPos = tickPositions[tickPositions.length - 1];
  1710. var linkedMin = axis.linkedParent && axis.linkedParent.min;
  1711. var linkedMax = axis.linkedParent && axis.linkedParent.max;
  1712. var min = linkedMin || axis.min;
  1713. var max = linkedMax || axis.max;
  1714. var tickInterval = axis.tickInterval;
  1715. var endMoreThanMin = (firstPos < min &&
  1716. firstPos + tickInterval > min);
  1717. var startLessThanMax = (lastPos > max &&
  1718. lastPos - tickInterval < max);
  1719. if (gridOptions.enabled === true &&
  1720. !categoryAxis &&
  1721. (axis.horiz || axis.isLinked)) {
  1722. if (endMoreThanMin && !options.startOnTick) {
  1723. tickPositions[0] = min;
  1724. }
  1725. if (startLessThanMax && !options.endOnTick) {
  1726. tickPositions[tickPositions.length - 1] = max;
  1727. }
  1728. }
  1729. };
  1730. /**
  1731. * Avoid altering tickInterval when reserving space.
  1732. * @private
  1733. */
  1734. GridAxis.wrapUnsquish = function (proceed) {
  1735. var axis = this;
  1736. var _a = axis.options.grid,
  1737. gridOptions = _a === void 0 ? {} : _a;
  1738. if (gridOptions.enabled === true && axis.categories) {
  1739. return axis.tickInterval;
  1740. }
  1741. return proceed.apply(axis, argsToArray(arguments));
  1742. };
  1743. return GridAxis;
  1744. }());
  1745. (function (GridAxis) {
  1746. /**
  1747. * Enum for which side the axis is on. Maps to axis.side.
  1748. * @private
  1749. */
  1750. var Side;
  1751. (function (Side) {
  1752. Side[Side["top"] = 0] = "top";
  1753. Side[Side["right"] = 1] = "right";
  1754. Side[Side["bottom"] = 2] = "bottom";
  1755. Side[Side["left"] = 3] = "left";
  1756. })(Side = GridAxis.Side || (GridAxis.Side = {}));
  1757. })(GridAxis || (GridAxis = {}));
  1758. GridAxis.compose(Axis);
  1759. return GridAxis;
  1760. });
  1761. _registerModule(_modules, 'Core/Axis/BrokenAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Series/LineSeries.js'], _modules['Extensions/Stacking.js'], _modules['Core/Utilities.js']], function (Axis, LineSeries, StackItem, U) {
  1762. /* *
  1763. *
  1764. * (c) 2009-2020 Torstein Honsi
  1765. *
  1766. * License: www.highcharts.com/license
  1767. *
  1768. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1769. *
  1770. * */
  1771. var addEvent = U.addEvent,
  1772. find = U.find,
  1773. fireEvent = U.fireEvent,
  1774. isArray = U.isArray,
  1775. isNumber = U.isNumber,
  1776. pick = U.pick;
  1777. /* eslint-disable valid-jsdoc */
  1778. /**
  1779. * Provides support for broken axes.
  1780. * @private
  1781. * @class
  1782. */
  1783. var BrokenAxisAdditions = /** @class */ (function () {
  1784. /* *
  1785. *
  1786. * Constructors
  1787. *
  1788. * */
  1789. function BrokenAxisAdditions(axis) {
  1790. this.hasBreaks = false;
  1791. this.axis = axis;
  1792. }
  1793. /* *
  1794. *
  1795. * Static Functions
  1796. *
  1797. * */
  1798. /**
  1799. * @private
  1800. */
  1801. BrokenAxisAdditions.isInBreak = function (brk, val) {
  1802. var ret,
  1803. repeat = brk.repeat || Infinity,
  1804. from = brk.from,
  1805. length = brk.to - brk.from,
  1806. test = (val >= from ?
  1807. (val - from) % repeat :
  1808. repeat - ((from - val) % repeat));
  1809. if (!brk.inclusive) {
  1810. ret = test < length && test !== 0;
  1811. }
  1812. else {
  1813. ret = test <= length;
  1814. }
  1815. return ret;
  1816. };
  1817. /**
  1818. * @private
  1819. */
  1820. BrokenAxisAdditions.lin2Val = function (val) {
  1821. var axis = this;
  1822. var brokenAxis = axis.brokenAxis;
  1823. var breakArray = brokenAxis && brokenAxis.breakArray;
  1824. if (!breakArray) {
  1825. return val;
  1826. }
  1827. var nval = val,
  1828. brk,
  1829. i;
  1830. for (i = 0; i < breakArray.length; i++) {
  1831. brk = breakArray[i];
  1832. if (brk.from >= nval) {
  1833. break;
  1834. }
  1835. else if (brk.to < nval) {
  1836. nval += brk.len;
  1837. }
  1838. else if (BrokenAxisAdditions.isInBreak(brk, nval)) {
  1839. nval += brk.len;
  1840. }
  1841. }
  1842. return nval;
  1843. };
  1844. /**
  1845. * @private
  1846. */
  1847. BrokenAxisAdditions.val2Lin = function (val) {
  1848. var axis = this;
  1849. var brokenAxis = axis.brokenAxis;
  1850. var breakArray = brokenAxis && brokenAxis.breakArray;
  1851. if (!breakArray) {
  1852. return val;
  1853. }
  1854. var nval = val,
  1855. brk,
  1856. i;
  1857. for (i = 0; i < breakArray.length; i++) {
  1858. brk = breakArray[i];
  1859. if (brk.to <= val) {
  1860. nval -= brk.len;
  1861. }
  1862. else if (brk.from >= val) {
  1863. break;
  1864. }
  1865. else if (BrokenAxisAdditions.isInBreak(brk, val)) {
  1866. nval -= (val - brk.from);
  1867. break;
  1868. }
  1869. }
  1870. return nval;
  1871. };
  1872. /* *
  1873. *
  1874. * Functions
  1875. *
  1876. * */
  1877. /**
  1878. * Returns the first break found where the x is larger then break.from and
  1879. * smaller then break.to.
  1880. *
  1881. * @param {number} x
  1882. * The number which should be within a break.
  1883. *
  1884. * @param {Array<Highcharts.XAxisBreaksOptions>} breaks
  1885. * The array of breaks to search within.
  1886. *
  1887. * @return {Highcharts.XAxisBreaksOptions|undefined}
  1888. * Returns the first break found that matches, returns false if no break is
  1889. * found.
  1890. */
  1891. BrokenAxisAdditions.prototype.findBreakAt = function (x, breaks) {
  1892. return find(breaks, function (b) {
  1893. return b.from < x && x < b.to;
  1894. });
  1895. };
  1896. /**
  1897. * @private
  1898. */
  1899. BrokenAxisAdditions.prototype.isInAnyBreak = function (val, testKeep) {
  1900. var brokenAxis = this;
  1901. var axis = brokenAxis.axis;
  1902. var breaks = axis.options.breaks,
  1903. i = breaks && breaks.length,
  1904. inbrk,
  1905. keep,
  1906. ret;
  1907. if (i) {
  1908. while (i--) {
  1909. if (BrokenAxisAdditions.isInBreak(breaks[i], val)) {
  1910. inbrk = true;
  1911. if (!keep) {
  1912. keep = pick(breaks[i].showPoints, !axis.isXAxis);
  1913. }
  1914. }
  1915. }
  1916. if (inbrk && testKeep) {
  1917. ret = inbrk && !keep;
  1918. }
  1919. else {
  1920. ret = inbrk;
  1921. }
  1922. }
  1923. return ret;
  1924. };
  1925. /**
  1926. * Dynamically set or unset breaks in an axis. This function in lighter than
  1927. * usin Axis.update, and it also preserves animation.
  1928. *
  1929. * @private
  1930. * @function Highcharts.Axis#setBreaks
  1931. *
  1932. * @param {Array<Highcharts.XAxisBreaksOptions>} [breaks]
  1933. * The breaks to add. When `undefined` it removes existing breaks.
  1934. *
  1935. * @param {boolean} [redraw=true]
  1936. * Whether to redraw the chart immediately.
  1937. *
  1938. * @return {void}
  1939. */
  1940. BrokenAxisAdditions.prototype.setBreaks = function (breaks, redraw) {
  1941. var brokenAxis = this;
  1942. var axis = brokenAxis.axis;
  1943. var hasBreaks = (isArray(breaks) && !!breaks.length);
  1944. axis.isDirty = brokenAxis.hasBreaks !== hasBreaks;
  1945. brokenAxis.hasBreaks = hasBreaks;
  1946. axis.options.breaks = axis.userOptions.breaks = breaks;
  1947. axis.forceRedraw = true; // Force recalculation in setScale
  1948. // Recalculate series related to the axis.
  1949. axis.series.forEach(function (series) {
  1950. series.isDirty = true;
  1951. });
  1952. if (!hasBreaks && axis.val2lin === BrokenAxisAdditions.val2Lin) {
  1953. // Revert to prototype functions
  1954. delete axis.val2lin;
  1955. delete axis.lin2val;
  1956. }
  1957. if (hasBreaks) {
  1958. axis.userOptions.ordinal = false;
  1959. axis.lin2val = BrokenAxisAdditions.lin2Val;
  1960. axis.val2lin = BrokenAxisAdditions.val2Lin;
  1961. axis.setExtremes = function (newMin, newMax, redraw, animation, eventArguments) {
  1962. // If trying to set extremes inside a break, extend min to
  1963. // after, and max to before the break ( #3857 )
  1964. if (brokenAxis.hasBreaks) {
  1965. var axisBreak,
  1966. breaks = this.options.breaks;
  1967. while ((axisBreak = brokenAxis.findBreakAt(newMin, breaks))) {
  1968. newMin = axisBreak.to;
  1969. }
  1970. while ((axisBreak = brokenAxis.findBreakAt(newMax, breaks))) {
  1971. newMax = axisBreak.from;
  1972. }
  1973. // If both min and max is within the same break.
  1974. if (newMax < newMin) {
  1975. newMax = newMin;
  1976. }
  1977. }
  1978. Axis.prototype.setExtremes.call(this, newMin, newMax, redraw, animation, eventArguments);
  1979. };
  1980. axis.setAxisTranslation = function (saveOld) {
  1981. Axis.prototype.setAxisTranslation.call(this, saveOld);
  1982. brokenAxis.unitLength = null;
  1983. if (brokenAxis.hasBreaks) {
  1984. var breaks = axis.options.breaks || [],
  1985. // Temporary one:
  1986. breakArrayT = [],
  1987. breakArray = [],
  1988. length = 0,
  1989. inBrk,
  1990. repeat,
  1991. min = axis.userMin || axis.min,
  1992. max = axis.userMax || axis.max,
  1993. pointRangePadding = pick(axis.pointRangePadding, 0),
  1994. start,
  1995. i;
  1996. // Min & max check (#4247)
  1997. breaks.forEach(function (brk) {
  1998. repeat = brk.repeat || Infinity;
  1999. if (BrokenAxisAdditions.isInBreak(brk, min)) {
  2000. min +=
  2001. (brk.to % repeat) -
  2002. (min % repeat);
  2003. }
  2004. if (BrokenAxisAdditions.isInBreak(brk, max)) {
  2005. max -=
  2006. (max % repeat) -
  2007. (brk.from % repeat);
  2008. }
  2009. });
  2010. // Construct an array holding all breaks in the axis
  2011. breaks.forEach(function (brk) {
  2012. start = brk.from;
  2013. repeat = brk.repeat || Infinity;
  2014. while (start - repeat > min) {
  2015. start -= repeat;
  2016. }
  2017. while (start < min) {
  2018. start += repeat;
  2019. }
  2020. for (i = start; i < max; i += repeat) {
  2021. breakArrayT.push({
  2022. value: i,
  2023. move: 'in'
  2024. });
  2025. breakArrayT.push({
  2026. value: i + (brk.to - brk.from),
  2027. move: 'out',
  2028. size: brk.breakSize
  2029. });
  2030. }
  2031. });
  2032. breakArrayT.sort(function (a, b) {
  2033. return ((a.value === b.value) ?
  2034. ((a.move === 'in' ? 0 : 1) -
  2035. (b.move === 'in' ? 0 : 1)) :
  2036. a.value - b.value);
  2037. });
  2038. // Simplify the breaks
  2039. inBrk = 0;
  2040. start = min;
  2041. breakArrayT.forEach(function (brk) {
  2042. inBrk += (brk.move === 'in' ? 1 : -1);
  2043. if (inBrk === 1 && brk.move === 'in') {
  2044. start = brk.value;
  2045. }
  2046. if (inBrk === 0) {
  2047. breakArray.push({
  2048. from: start,
  2049. to: brk.value,
  2050. len: brk.value - start - (brk.size || 0)
  2051. });
  2052. length += brk.value - start - (brk.size || 0);
  2053. }
  2054. });
  2055. /**
  2056. * HC <= 8 backwards compatibility, used by demo samples.
  2057. * @deprecated
  2058. * @private
  2059. * @requires modules/broken-axis
  2060. */
  2061. axis.breakArray = brokenAxis.breakArray = breakArray;
  2062. // Used with staticScale, and below the actual axis length,
  2063. // when breaks are substracted.
  2064. brokenAxis.unitLength = max - min - length + pointRangePadding;
  2065. fireEvent(axis, 'afterBreaks');
  2066. if (axis.staticScale) {
  2067. axis.transA = axis.staticScale;
  2068. }
  2069. else if (brokenAxis.unitLength) {
  2070. axis.transA *=
  2071. (max - axis.min + pointRangePadding) /
  2072. brokenAxis.unitLength;
  2073. }
  2074. if (pointRangePadding) {
  2075. axis.minPixelPadding =
  2076. axis.transA * axis.minPointOffset;
  2077. }
  2078. axis.min = min;
  2079. axis.max = max;
  2080. }
  2081. };
  2082. }
  2083. if (pick(redraw, true)) {
  2084. axis.chart.redraw();
  2085. }
  2086. };
  2087. return BrokenAxisAdditions;
  2088. }());
  2089. /**
  2090. * Axis with support of broken data rows.
  2091. * @private
  2092. * @class
  2093. */
  2094. var BrokenAxis = /** @class */ (function () {
  2095. function BrokenAxis() {
  2096. }
  2097. /**
  2098. * Adds support for broken axes.
  2099. * @private
  2100. */
  2101. BrokenAxis.compose = function (AxisClass, SeriesClass) {
  2102. AxisClass.keepProps.push('brokenAxis');
  2103. var seriesProto = LineSeries.prototype;
  2104. /**
  2105. * @private
  2106. */
  2107. seriesProto.drawBreaks = function (axis, keys) {
  2108. var series = this,
  2109. points = series.points,
  2110. breaks,
  2111. threshold,
  2112. eventName,
  2113. y;
  2114. if (axis && // #5950
  2115. axis.brokenAxis &&
  2116. axis.brokenAxis.hasBreaks) {
  2117. var brokenAxis_1 = axis.brokenAxis;
  2118. keys.forEach(function (key) {
  2119. breaks = brokenAxis_1 && brokenAxis_1.breakArray || [];
  2120. threshold = axis.isXAxis ?
  2121. axis.min :
  2122. pick(series.options.threshold, axis.min);
  2123. points.forEach(function (point) {
  2124. y = pick(point['stack' + key.toUpperCase()], point[key]);
  2125. breaks.forEach(function (brk) {
  2126. if (isNumber(threshold) && isNumber(y)) {
  2127. eventName = false;
  2128. if ((threshold < brk.from && y > brk.to) ||
  2129. (threshold > brk.from && y < brk.from)) {
  2130. eventName = 'pointBreak';
  2131. }
  2132. else if ((threshold < brk.from && y > brk.from && y < brk.to) ||
  2133. (threshold > brk.from && y > brk.to && y < brk.from)) {
  2134. eventName = 'pointInBreak';
  2135. }
  2136. if (eventName) {
  2137. fireEvent(axis, eventName, { point: point, brk: brk });
  2138. }
  2139. }
  2140. });
  2141. });
  2142. });
  2143. }
  2144. };
  2145. /**
  2146. * Extend getGraphPath by identifying gaps in the data so that we can
  2147. * draw a gap in the line or area. This was moved from ordinal axis
  2148. * module to broken axis module as of #5045.
  2149. *
  2150. * @private
  2151. * @function Highcharts.Series#gappedPath
  2152. *
  2153. * @return {Highcharts.SVGPathArray}
  2154. * Gapped path
  2155. */
  2156. seriesProto.gappedPath = function () {
  2157. var currentDataGrouping = this.currentDataGrouping,
  2158. groupingSize = currentDataGrouping && currentDataGrouping.gapSize,
  2159. gapSize = this.options.gapSize,
  2160. points = this.points.slice(),
  2161. i = points.length - 1,
  2162. yAxis = this.yAxis,
  2163. stack;
  2164. /**
  2165. * Defines when to display a gap in the graph, together with the
  2166. * [gapUnit](plotOptions.series.gapUnit) option.
  2167. *
  2168. * In case when `dataGrouping` is enabled, points can be grouped
  2169. * into a larger time span. This can make the grouped points to have
  2170. * a greater distance than the absolute value of `gapSize` property,
  2171. * which will result in disappearing graph completely. To prevent
  2172. * this situation the mentioned distance between grouped points is
  2173. * used instead of previously defined `gapSize`.
  2174. *
  2175. * In practice, this option is most often used to visualize gaps in
  2176. * time series. In a stock chart, intraday data is available for
  2177. * daytime hours, while gaps will appear in nights and weekends.
  2178. *
  2179. * @see [gapUnit](plotOptions.series.gapUnit)
  2180. * @see [xAxis.breaks](#xAxis.breaks)
  2181. *
  2182. * @sample {highstock} stock/plotoptions/series-gapsize/
  2183. * Setting the gap size to 2 introduces gaps for weekends
  2184. * in daily datasets.
  2185. *
  2186. * @type {number}
  2187. * @default 0
  2188. * @product highstock
  2189. * @requires modules/broken-axis
  2190. * @apioption plotOptions.series.gapSize
  2191. */
  2192. /**
  2193. * Together with [gapSize](plotOptions.series.gapSize), this option
  2194. * defines where to draw gaps in the graph.
  2195. *
  2196. * When the `gapUnit` is `"relative"` (default), a gap size of 5
  2197. * means that if the distance between two points is greater than
  2198. * 5 times that of the two closest points, the graph will be broken.
  2199. *
  2200. * When the `gapUnit` is `"value"`, the gap is based on absolute
  2201. * axis values, which on a datetime axis is milliseconds. This also
  2202. * applies to the navigator series that inherits gap options from
  2203. * the base series.
  2204. *
  2205. * @see [gapSize](plotOptions.series.gapSize)
  2206. *
  2207. * @type {string}
  2208. * @default relative
  2209. * @since 5.0.13
  2210. * @product highstock
  2211. * @validvalue ["relative", "value"]
  2212. * @requires modules/broken-axis
  2213. * @apioption plotOptions.series.gapUnit
  2214. */
  2215. if (gapSize && i > 0) { // #5008
  2216. // Gap unit is relative
  2217. if (this.options.gapUnit !== 'value') {
  2218. gapSize *= this.basePointRange;
  2219. }
  2220. // Setting a new gapSize in case dataGrouping is enabled (#7686)
  2221. if (groupingSize &&
  2222. groupingSize > gapSize &&
  2223. // Except when DG is forced (e.g. from other series)
  2224. // and has lower granularity than actual points (#11351)
  2225. groupingSize >= this.basePointRange) {
  2226. gapSize = groupingSize;
  2227. }
  2228. // extension for ordinal breaks
  2229. var current = void 0,
  2230. next = void 0;
  2231. while (i--) {
  2232. // Reassign next if it is not visible
  2233. if (!(next && next.visible !== false)) {
  2234. next = points[i + 1];
  2235. }
  2236. current = points[i];
  2237. // Skip iteration if one of the points is not visible
  2238. if (next.visible === false || current.visible === false) {
  2239. continue;
  2240. }
  2241. if (next.x - current.x > gapSize) {
  2242. var xRange = (current.x + next.x) / 2;
  2243. points.splice(// insert after this one
  2244. i + 1, 0, {
  2245. isNull: true,
  2246. x: xRange
  2247. });
  2248. // For stacked chart generate empty stack items, #6546
  2249. if (yAxis.stacking && this.options.stacking) {
  2250. stack = yAxis.stacking.stacks[this.stackKey][xRange] =
  2251. new StackItem(yAxis, yAxis.options
  2252. .stackLabels, false, xRange, this.stack);
  2253. stack.total = 0;
  2254. }
  2255. }
  2256. // Assign current to next for the upcoming iteration
  2257. next = current;
  2258. }
  2259. }
  2260. // Call base method
  2261. return this.getGraphPath(points);
  2262. };
  2263. /* eslint-disable no-invalid-this */
  2264. addEvent(AxisClass, 'init', function () {
  2265. var axis = this;
  2266. if (!axis.brokenAxis) {
  2267. axis.brokenAxis = new BrokenAxisAdditions(axis);
  2268. }
  2269. });
  2270. addEvent(AxisClass, 'afterInit', function () {
  2271. if (typeof this.brokenAxis !== 'undefined') {
  2272. this.brokenAxis.setBreaks(this.options.breaks, false);
  2273. }
  2274. });
  2275. addEvent(AxisClass, 'afterSetTickPositions', function () {
  2276. var axis = this;
  2277. var brokenAxis = axis.brokenAxis;
  2278. if (brokenAxis &&
  2279. brokenAxis.hasBreaks) {
  2280. var tickPositions = this.tickPositions,
  2281. info = this.tickPositions.info,
  2282. newPositions = [],
  2283. i;
  2284. for (i = 0; i < tickPositions.length; i++) {
  2285. if (!brokenAxis.isInAnyBreak(tickPositions[i])) {
  2286. newPositions.push(tickPositions[i]);
  2287. }
  2288. }
  2289. this.tickPositions = newPositions;
  2290. this.tickPositions.info = info;
  2291. }
  2292. });
  2293. // Force Axis to be not-ordinal when breaks are defined
  2294. addEvent(AxisClass, 'afterSetOptions', function () {
  2295. if (this.brokenAxis && this.brokenAxis.hasBreaks) {
  2296. this.options.ordinal = false;
  2297. }
  2298. });
  2299. addEvent(SeriesClass, 'afterGeneratePoints', function () {
  2300. var _a = this,
  2301. isDirty = _a.isDirty,
  2302. connectNulls = _a.options.connectNulls,
  2303. points = _a.points,
  2304. xAxis = _a.xAxis,
  2305. yAxis = _a.yAxis;
  2306. // Set, or reset visibility of the points. Axis.setBreaks marks the
  2307. // series as isDirty
  2308. if (isDirty) {
  2309. var i = points.length;
  2310. while (i--) {
  2311. var point = points[i];
  2312. // Respect nulls inside the break (#4275)
  2313. var nullGap = point.y === null && connectNulls === false;
  2314. var isPointInBreak = (!nullGap && ((xAxis &&
  2315. xAxis.brokenAxis &&
  2316. xAxis.brokenAxis.isInAnyBreak(point.x,
  2317. true)) || (yAxis &&
  2318. yAxis.brokenAxis &&
  2319. yAxis.brokenAxis.isInAnyBreak(point.y,
  2320. true))));
  2321. // Set point.visible if in any break.
  2322. // If not in break, reset visible to original value.
  2323. point.visible = isPointInBreak ?
  2324. false :
  2325. point.options.visible !== false;
  2326. }
  2327. }
  2328. });
  2329. addEvent(SeriesClass, 'afterRender', function drawPointsWrapped() {
  2330. this.drawBreaks(this.xAxis, ['x']);
  2331. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  2332. });
  2333. };
  2334. return BrokenAxis;
  2335. }());
  2336. BrokenAxis.compose(Axis, LineSeries); // @todo remove automatism
  2337. return BrokenAxis;
  2338. });
  2339. _registerModule(_modules, 'Core/Axis/TreeGridAxis.js', [_modules['Core/Globals.js'], _modules['Core/Axis/Axis.js'], _modules['Core/Axis/Tick.js'], _modules['Gantt/Tree.js'], _modules['Core/Axis/TreeGridTick.js'], _modules['Mixins/TreeSeries.js'], _modules['Core/Utilities.js']], function (H, Axis, Tick, Tree, TreeGridTick, mixinTreeSeries, U) {
  2340. /* *
  2341. *
  2342. * (c) 2016 Highsoft AS
  2343. * Authors: Jon Arild Nygard
  2344. *
  2345. * License: www.highcharts.com/license
  2346. *
  2347. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2348. *
  2349. * */
  2350. var getLevelOptions = mixinTreeSeries.getLevelOptions;
  2351. var addEvent = U.addEvent,
  2352. find = U.find,
  2353. fireEvent = U.fireEvent,
  2354. isArray = U.isArray,
  2355. isNumber = U.isNumber,
  2356. isObject = U.isObject,
  2357. isString = U.isString,
  2358. merge = U.merge,
  2359. pick = U.pick,
  2360. wrap = U.wrap;
  2361. /**
  2362. * @private
  2363. */
  2364. var TreeGridAxis;
  2365. (function (TreeGridAxis) {
  2366. /* *
  2367. *
  2368. * Interfaces
  2369. *
  2370. * */
  2371. /* *
  2372. *
  2373. * Variables
  2374. *
  2375. * */
  2376. var applied = false;
  2377. /* *
  2378. *
  2379. * Functions
  2380. *
  2381. * */
  2382. /**
  2383. * @private
  2384. */
  2385. function compose(AxisClass) {
  2386. if (!applied) {
  2387. wrap(AxisClass.prototype, 'generateTick', wrapGenerateTick);
  2388. wrap(AxisClass.prototype, 'getMaxLabelDimensions', wrapGetMaxLabelDimensions);
  2389. wrap(AxisClass.prototype, 'init', wrapInit);
  2390. wrap(AxisClass.prototype, 'setTickInterval', wrapSetTickInterval);
  2391. TreeGridTick.compose(Tick);
  2392. applied = true;
  2393. }
  2394. }
  2395. TreeGridAxis.compose = compose;
  2396. /**
  2397. * @private
  2398. */
  2399. function getBreakFromNode(node, max) {
  2400. var from = node.collapseStart || 0,
  2401. to = node.collapseEnd || 0;
  2402. // In broken-axis, the axis.max is minimized until it is not within a
  2403. // break. Therefore, if break.to is larger than axis.max, the axis.to
  2404. // should not add the 0.5 axis.tickMarkOffset, to avoid adding a break
  2405. // larger than axis.max.
  2406. // TODO consider simplifying broken-axis and this might solve itself
  2407. if (to >= max) {
  2408. from -= 0.5;
  2409. }
  2410. return {
  2411. from: from,
  2412. to: to,
  2413. showPoints: false
  2414. };
  2415. }
  2416. /**
  2417. * Creates a tree structure of the data, and the treegrid. Calculates
  2418. * categories, and y-values of points based on the tree.
  2419. *
  2420. * @private
  2421. * @function getTreeGridFromData
  2422. *
  2423. * @param {Array<Highcharts.GanttPointOptions>} data
  2424. * All the data points to display in the axis.
  2425. *
  2426. * @param {boolean} uniqueNames
  2427. * Wether or not the data node with the same name should share grid cell. If
  2428. * true they do share cell. False by default.
  2429. *
  2430. * @param {number} numberOfSeries
  2431. *
  2432. * @return {object}
  2433. * Returns an object containing categories, mapOfIdToNode,
  2434. * mapOfPosToGridNode, and tree.
  2435. *
  2436. * @todo There should be only one point per line.
  2437. * @todo It should be optional to have one category per point, or merge
  2438. * cells
  2439. * @todo Add unit-tests.
  2440. */
  2441. function getTreeGridFromData(data, uniqueNames, numberOfSeries) {
  2442. var categories = [],
  2443. collapsedNodes = [],
  2444. mapOfIdToNode = {},
  2445. mapOfPosToGridNode = {},
  2446. posIterator = -1,
  2447. uniqueNamesEnabled = typeof uniqueNames === 'boolean' ? uniqueNames : false,
  2448. tree;
  2449. // Build the tree from the series data.
  2450. var treeParams = {
  2451. // After the children has been created.
  2452. after: function (node) {
  2453. var gridNode = mapOfPosToGridNode[node.pos],
  2454. height = 0,
  2455. descendants = 0;
  2456. gridNode.children.forEach(function (child) {
  2457. descendants += (child.descendants || 0) + 1;
  2458. height = Math.max((child.height || 0) + 1, height);
  2459. });
  2460. gridNode.descendants = descendants;
  2461. gridNode.height = height;
  2462. if (gridNode.collapsed) {
  2463. collapsedNodes.push(gridNode);
  2464. }
  2465. },
  2466. // Before the children has been created.
  2467. before: function (node) {
  2468. var data = isObject(node.data,
  2469. true) ? node.data : {},
  2470. name = isString(data.name) ? data.name : '',
  2471. parentNode = mapOfIdToNode[node.parent],
  2472. parentGridNode = (isObject(parentNode,
  2473. true) ?
  2474. mapOfPosToGridNode[parentNode.pos] :
  2475. null),
  2476. hasSameName = function (x) {
  2477. return x.name === name;
  2478. }, gridNode, pos;
  2479. // If not unique names, look for sibling node with the same name
  2480. if (uniqueNamesEnabled &&
  2481. isObject(parentGridNode, true) &&
  2482. !!(gridNode = find(parentGridNode.children, hasSameName))) {
  2483. // If there is a gridNode with the same name, reuse position
  2484. pos = gridNode.pos;
  2485. // Add data node to list of nodes in the grid node.
  2486. gridNode.nodes.push(node);
  2487. }
  2488. else {
  2489. // If it is a new grid node, increment position.
  2490. pos = posIterator++;
  2491. }
  2492. // Add new grid node to map.
  2493. if (!mapOfPosToGridNode[pos]) {
  2494. mapOfPosToGridNode[pos] = gridNode = {
  2495. depth: parentGridNode ? parentGridNode.depth + 1 : 0,
  2496. name: name,
  2497. id: data.id,
  2498. nodes: [node],
  2499. children: [],
  2500. pos: pos
  2501. };
  2502. // If not root, then add name to categories.
  2503. if (pos !== -1) {
  2504. categories.push(name);
  2505. }
  2506. // Add name to list of children.
  2507. if (isObject(parentGridNode, true)) {
  2508. parentGridNode.children.push(gridNode);
  2509. }
  2510. }
  2511. // Add data node to map
  2512. if (isString(node.id)) {
  2513. mapOfIdToNode[node.id] = node;
  2514. }
  2515. // If one of the points are collapsed, then start the grid node
  2516. // in collapsed state.
  2517. if (gridNode &&
  2518. data.collapsed === true) {
  2519. gridNode.collapsed = true;
  2520. }
  2521. // Assign pos to data node
  2522. node.pos = pos;
  2523. }
  2524. };
  2525. var updateYValuesAndTickPos = function (map,
  2526. numberOfSeries) {
  2527. var setValues = function (gridNode,
  2528. start,
  2529. result) {
  2530. var nodes = gridNode.nodes,
  2531. end = start + (start === -1 ? 0 : numberOfSeries - 1),
  2532. diff = (end - start) / 2,
  2533. padding = 0.5,
  2534. pos = start + diff;
  2535. nodes.forEach(function (node) {
  2536. var data = node.data;
  2537. if (isObject(data, true)) {
  2538. // Update point
  2539. data.y = start + (data.seriesIndex || 0);
  2540. // Remove the property once used
  2541. delete data.seriesIndex;
  2542. }
  2543. node.pos = pos;
  2544. });
  2545. result[pos] = gridNode;
  2546. gridNode.pos = pos;
  2547. gridNode.tickmarkOffset = diff + padding;
  2548. gridNode.collapseStart = end + padding;
  2549. gridNode.children.forEach(function (child) {
  2550. setValues(child, end + 1, result);
  2551. end = (child.collapseEnd || 0) - padding;
  2552. });
  2553. // Set collapseEnd to the end of the last child node.
  2554. gridNode.collapseEnd = end + padding;
  2555. return result;
  2556. };
  2557. return setValues(map['-1'], -1, {});
  2558. };
  2559. // Create tree from data
  2560. tree = Tree.getTree(data, treeParams);
  2561. // Update y values of data, and set calculate tick positions.
  2562. mapOfPosToGridNode = updateYValuesAndTickPos(mapOfPosToGridNode, numberOfSeries);
  2563. // Return the resulting data.
  2564. return {
  2565. categories: categories,
  2566. mapOfIdToNode: mapOfIdToNode,
  2567. mapOfPosToGridNode: mapOfPosToGridNode,
  2568. collapsedNodes: collapsedNodes,
  2569. tree: tree
  2570. };
  2571. }
  2572. /**
  2573. * Builds the tree of categories and calculates its positions.
  2574. * @private
  2575. * @param {object} e Event object
  2576. * @param {object} e.target The chart instance which the event was fired on.
  2577. * @param {object[]} e.target.axes The axes of the chart.
  2578. */
  2579. function onBeforeRender(e) {
  2580. var chart = e.target,
  2581. axes = chart.axes;
  2582. axes.filter(function (axis) {
  2583. return axis.options.type === 'treegrid';
  2584. }).forEach(function (axis) {
  2585. var options = axis.options || {},
  2586. labelOptions = options.labels,
  2587. uniqueNames = options.uniqueNames,
  2588. numberOfSeries = 0,
  2589. isDirty,
  2590. data,
  2591. treeGrid,
  2592. max = options.max;
  2593. // Check whether any of series is rendering for the first time,
  2594. // visibility has changed, or its data is dirty,
  2595. // and only then update. #10570, #10580
  2596. // Also check if mapOfPosToGridNode exists. #10887
  2597. isDirty = (!axis.treeGrid.mapOfPosToGridNode ||
  2598. axis.series.some(function (series) {
  2599. return !series.hasRendered ||
  2600. series.isDirtyData ||
  2601. series.isDirty;
  2602. }));
  2603. if (isDirty) {
  2604. // Concatenate data from all series assigned to this axis.
  2605. data = axis.series.reduce(function (arr, s) {
  2606. if (s.visible) {
  2607. // Push all data to array
  2608. (s.options.data || []).forEach(function (data) {
  2609. // For using keys - rebuild the data structure
  2610. if (s.options.keys && s.options.keys.length) {
  2611. data = s.pointClass.prototype.optionsToObject.call({ series: s }, data);
  2612. H.seriesTypes.gantt.prototype.setGanttPointAliases(data);
  2613. }
  2614. if (isObject(data, true)) {
  2615. // Set series index on data. Removed again
  2616. // after use.
  2617. data.seriesIndex = numberOfSeries;
  2618. arr.push(data);
  2619. }
  2620. });
  2621. // Increment series index
  2622. if (uniqueNames === true) {
  2623. numberOfSeries++;
  2624. }
  2625. }
  2626. return arr;
  2627. }, []);
  2628. // If max is higher than set data - add a
  2629. // dummy data to render categories #10779
  2630. if (max && data.length < max) {
  2631. for (var i = data.length; i <= max; i++) {
  2632. data.push({
  2633. // Use the zero-width character
  2634. // to avoid conflict with uniqueNames
  2635. name: i + '\u200B'
  2636. });
  2637. }
  2638. }
  2639. // setScale is fired after all the series is initialized,
  2640. // which is an ideal time to update the axis.categories.
  2641. treeGrid = getTreeGridFromData(data, uniqueNames || false, (uniqueNames === true) ? numberOfSeries : 1);
  2642. // Assign values to the axis.
  2643. axis.categories = treeGrid.categories;
  2644. axis.treeGrid.mapOfPosToGridNode = treeGrid.mapOfPosToGridNode;
  2645. axis.hasNames = true;
  2646. axis.treeGrid.tree = treeGrid.tree;
  2647. // Update yData now that we have calculated the y values
  2648. axis.series.forEach(function (series) {
  2649. var axisData = (series.options.data || []).map(function (d) {
  2650. if (isArray(d) && series.options.keys && series.options.keys.length) {
  2651. // Get the axisData from the data array used to
  2652. // build the treeGrid where has been modified
  2653. data.forEach(function (point) {
  2654. if (d.indexOf(point.x) >= 0 && d.indexOf(point.x2) >= 0) {
  2655. d = point;
  2656. }
  2657. });
  2658. }
  2659. return isObject(d, true) ? merge(d) : d;
  2660. });
  2661. // Avoid destroying points when series is not visible
  2662. if (series.visible) {
  2663. series.setData(axisData, false);
  2664. }
  2665. });
  2666. // Calculate the label options for each level in the tree.
  2667. axis.treeGrid.mapOptionsToLevel =
  2668. getLevelOptions({
  2669. defaults: labelOptions,
  2670. from: 1,
  2671. levels: labelOptions && labelOptions.levels,
  2672. to: axis.treeGrid.tree && axis.treeGrid.tree.height
  2673. });
  2674. // Setting initial collapsed nodes
  2675. if (e.type === 'beforeRender') {
  2676. axis.treeGrid.collapsedNodes = treeGrid.collapsedNodes;
  2677. }
  2678. }
  2679. });
  2680. }
  2681. /**
  2682. * Generates a tick for initial positioning.
  2683. *
  2684. * @private
  2685. * @function Highcharts.GridAxis#generateTick
  2686. *
  2687. * @param {Function} proceed
  2688. * The original generateTick function.
  2689. *
  2690. * @param {number} pos
  2691. * The tick position in axis values.
  2692. */
  2693. function wrapGenerateTick(proceed, pos) {
  2694. var axis = this,
  2695. mapOptionsToLevel = axis.treeGrid.mapOptionsToLevel || {},
  2696. isTreeGrid = axis.options.type === 'treegrid',
  2697. ticks = axis.ticks;
  2698. var tick = ticks[pos],
  2699. levelOptions,
  2700. options,
  2701. gridNode;
  2702. if (isTreeGrid &&
  2703. axis.treeGrid.mapOfPosToGridNode) {
  2704. gridNode = axis.treeGrid.mapOfPosToGridNode[pos];
  2705. levelOptions = mapOptionsToLevel[gridNode.depth];
  2706. if (levelOptions) {
  2707. options = {
  2708. labels: levelOptions
  2709. };
  2710. }
  2711. if (!tick) {
  2712. ticks[pos] = tick =
  2713. new Tick(axis, pos, void 0, void 0, {
  2714. category: gridNode.name,
  2715. tickmarkOffset: gridNode.tickmarkOffset,
  2716. options: options
  2717. });
  2718. }
  2719. else {
  2720. // update labels depending on tick interval
  2721. tick.parameters.category = gridNode.name;
  2722. tick.options = options;
  2723. tick.addLabel();
  2724. }
  2725. }
  2726. else {
  2727. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2728. }
  2729. }
  2730. /**
  2731. * Override to add indentation to axis.maxLabelDimensions.
  2732. *
  2733. * @private
  2734. * @function Highcharts.GridAxis#getMaxLabelDimensions
  2735. *
  2736. * @param {Function} proceed
  2737. * The original function
  2738. */
  2739. function wrapGetMaxLabelDimensions(proceed) {
  2740. var axis = this,
  2741. options = axis.options,
  2742. labelOptions = options && options.labels,
  2743. indentation = (labelOptions && isNumber(labelOptions.indentation) ?
  2744. labelOptions.indentation :
  2745. 0),
  2746. retVal = proceed.apply(axis,
  2747. Array.prototype.slice.call(arguments, 1)),
  2748. isTreeGrid = axis.options.type === 'treegrid';
  2749. var treeDepth;
  2750. if (isTreeGrid && axis.treeGrid.mapOfPosToGridNode) {
  2751. treeDepth = axis.treeGrid.mapOfPosToGridNode[-1].height || 0;
  2752. retVal.width += indentation * (treeDepth - 1);
  2753. }
  2754. return retVal;
  2755. }
  2756. /**
  2757. * @private
  2758. */
  2759. function wrapInit(proceed, chart, userOptions) {
  2760. var axis = this,
  2761. isTreeGrid = userOptions.type === 'treegrid';
  2762. if (!axis.treeGrid) {
  2763. axis.treeGrid = new Additions(axis);
  2764. }
  2765. // Set default and forced options for TreeGrid
  2766. if (isTreeGrid) {
  2767. // Add event for updating the categories of a treegrid.
  2768. // NOTE Preferably these events should be set on the axis.
  2769. addEvent(chart, 'beforeRender', onBeforeRender);
  2770. addEvent(chart, 'beforeRedraw', onBeforeRender);
  2771. // Add new collapsed nodes on addseries
  2772. addEvent(chart, 'addSeries', function (e) {
  2773. if (e.options.data) {
  2774. var treeGrid = getTreeGridFromData(e.options.data,
  2775. userOptions.uniqueNames || false, 1);
  2776. axis.treeGrid.collapsedNodes = (axis.treeGrid.collapsedNodes || []).concat(treeGrid.collapsedNodes);
  2777. }
  2778. });
  2779. // Collapse all nodes in axis.treegrid.collapsednodes
  2780. // where collapsed equals true.
  2781. addEvent(axis, 'foundExtremes', function () {
  2782. if (axis.treeGrid.collapsedNodes) {
  2783. axis.treeGrid.collapsedNodes.forEach(function (node) {
  2784. var breaks = axis.treeGrid.collapse(node);
  2785. if (axis.brokenAxis) {
  2786. axis.brokenAxis.setBreaks(breaks, false);
  2787. // remove the node from the axis collapsedNodes
  2788. if (axis.treeGrid.collapsedNodes) {
  2789. axis.treeGrid.collapsedNodes = axis.treeGrid.collapsedNodes.filter(function (n) {
  2790. return node.collapseStart !== n.collapseStart ||
  2791. node.collapseEnd !== n.collapseEnd;
  2792. });
  2793. }
  2794. }
  2795. });
  2796. }
  2797. });
  2798. // If staticScale is not defined on the yAxis
  2799. // and chart height is set, set axis.isDirty
  2800. // to ensure collapsing works (#12012)
  2801. addEvent(axis, 'afterBreaks', function () {
  2802. var _a;
  2803. if (axis.coll === 'yAxis' && !axis.staticScale && ((_a = axis.chart.options.chart) === null || _a === void 0 ? void 0 : _a.height)) {
  2804. axis.isDirty = true;
  2805. }
  2806. });
  2807. userOptions = merge({
  2808. // Default options
  2809. grid: {
  2810. enabled: true
  2811. },
  2812. // TODO: add support for align in treegrid.
  2813. labels: {
  2814. align: 'left',
  2815. /**
  2816. * Set options on specific levels in a tree grid axis. Takes
  2817. * precedence over labels options.
  2818. *
  2819. * @sample {gantt} gantt/treegrid-axis/labels-levels
  2820. * Levels on TreeGrid Labels
  2821. *
  2822. * @type {Array<*>}
  2823. * @product gantt
  2824. * @apioption yAxis.labels.levels
  2825. *
  2826. * @private
  2827. */
  2828. levels: [{
  2829. /**
  2830. * Specify the level which the options within this object
  2831. * applies to.
  2832. *
  2833. * @type {number}
  2834. * @product gantt
  2835. * @apioption yAxis.labels.levels.level
  2836. *
  2837. * @private
  2838. */
  2839. level: void 0
  2840. }, {
  2841. level: 1,
  2842. /**
  2843. * @type {Highcharts.CSSObject}
  2844. * @product gantt
  2845. * @apioption yAxis.labels.levels.style
  2846. *
  2847. * @private
  2848. */
  2849. style: {
  2850. /** @ignore-option */
  2851. fontWeight: 'bold'
  2852. }
  2853. }],
  2854. /**
  2855. * The symbol for the collapse and expand icon in a
  2856. * treegrid.
  2857. *
  2858. * @product gantt
  2859. * @optionparent yAxis.labels.symbol
  2860. *
  2861. * @private
  2862. */
  2863. symbol: {
  2864. /**
  2865. * The symbol type. Points to a definition function in
  2866. * the `Highcharts.Renderer.symbols` collection.
  2867. *
  2868. * @type {Highcharts.SymbolKeyValue}
  2869. *
  2870. * @private
  2871. */
  2872. type: 'triangle',
  2873. x: -5,
  2874. y: -5,
  2875. height: 10,
  2876. width: 10,
  2877. padding: 5
  2878. }
  2879. },
  2880. uniqueNames: false
  2881. }, userOptions, {
  2882. // Forced options
  2883. reversed: true,
  2884. // grid.columns is not supported in treegrid
  2885. grid: {
  2886. columns: void 0
  2887. }
  2888. });
  2889. }
  2890. // Now apply the original function with the original arguments,
  2891. // which are sliced off this function's arguments
  2892. proceed.apply(axis, [chart, userOptions]);
  2893. if (isTreeGrid) {
  2894. axis.hasNames = true;
  2895. axis.options.showLastLabel = true;
  2896. }
  2897. }
  2898. /**
  2899. * Set the tick positions, tickInterval, axis min and max.
  2900. *
  2901. * @private
  2902. * @function Highcharts.GridAxis#setTickInterval
  2903. *
  2904. * @param {Function} proceed
  2905. * The original setTickInterval function.
  2906. */
  2907. function wrapSetTickInterval(proceed) {
  2908. var axis = this,
  2909. options = axis.options,
  2910. isTreeGrid = options.type === 'treegrid';
  2911. if (isTreeGrid) {
  2912. axis.min = pick(axis.userMin, options.min, axis.dataMin);
  2913. axis.max = pick(axis.userMax, options.max, axis.dataMax);
  2914. fireEvent(axis, 'foundExtremes');
  2915. // setAxisTranslation modifies the min and max according to
  2916. // axis breaks.
  2917. axis.setAxisTranslation(true);
  2918. axis.tickmarkOffset = 0.5;
  2919. axis.tickInterval = 1;
  2920. axis.tickPositions = axis.treeGrid.mapOfPosToGridNode ?
  2921. axis.treeGrid.getTickPositions() :
  2922. [];
  2923. }
  2924. else {
  2925. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2926. }
  2927. }
  2928. /* *
  2929. *
  2930. * Classes
  2931. *
  2932. * */
  2933. /**
  2934. * @private
  2935. * @class
  2936. */
  2937. var Additions = /** @class */ (function () {
  2938. /* *
  2939. *
  2940. * Constructors
  2941. *
  2942. * */
  2943. /**
  2944. * @private
  2945. */
  2946. function Additions(axis) {
  2947. this.axis = axis;
  2948. }
  2949. /* *
  2950. *
  2951. * Functions
  2952. *
  2953. * */
  2954. /**
  2955. * Set the collapse status.
  2956. *
  2957. * @private
  2958. *
  2959. * @param {Highcharts.Axis} axis
  2960. * The axis to check against.
  2961. *
  2962. * @param {Highcharts.GridNode} node
  2963. * The node to collapse.
  2964. */
  2965. Additions.prototype.setCollapsedStatus = function (node) {
  2966. var axis = this.axis,
  2967. chart = axis.chart;
  2968. axis.series.forEach(function (series) {
  2969. var data = series.options.data;
  2970. if (node.id && data) {
  2971. var point = chart.get(node.id),
  2972. dataPoint = data[series.data.indexOf(point)];
  2973. if (point && dataPoint) {
  2974. point.collapsed = node.collapsed;
  2975. dataPoint.collapsed = node.collapsed;
  2976. }
  2977. }
  2978. });
  2979. };
  2980. /**
  2981. * Calculates the new axis breaks to collapse a node.
  2982. *
  2983. * @private
  2984. *
  2985. * @param {Highcharts.Axis} axis
  2986. * The axis to check against.
  2987. *
  2988. * @param {Highcharts.GridNode} node
  2989. * The node to collapse.
  2990. *
  2991. * @param {number} pos
  2992. * The tick position to collapse.
  2993. *
  2994. * @return {Array<object>}
  2995. * Returns an array of the new breaks for the axis.
  2996. */
  2997. Additions.prototype.collapse = function (node) {
  2998. var axis = this.axis,
  2999. breaks = (axis.options.breaks || []),
  3000. obj = getBreakFromNode(node,
  3001. axis.max);
  3002. breaks.push(obj);
  3003. // Change the collapsed flag #13838
  3004. node.collapsed = true;
  3005. axis.treeGrid.setCollapsedStatus(node);
  3006. return breaks;
  3007. };
  3008. /**
  3009. * Calculates the new axis breaks to expand a node.
  3010. *
  3011. * @private
  3012. *
  3013. * @param {Highcharts.Axis} axis
  3014. * The axis to check against.
  3015. *
  3016. * @param {Highcharts.GridNode} node
  3017. * The node to expand.
  3018. *
  3019. * @param {number} pos
  3020. * The tick position to expand.
  3021. *
  3022. * @return {Array<object>}
  3023. * Returns an array of the new breaks for the axis.
  3024. */
  3025. Additions.prototype.expand = function (node) {
  3026. var axis = this.axis,
  3027. breaks = (axis.options.breaks || []),
  3028. obj = getBreakFromNode(node,
  3029. axis.max);
  3030. // Change the collapsed flag #13838
  3031. node.collapsed = false;
  3032. axis.treeGrid.setCollapsedStatus(node);
  3033. // Remove the break from the axis breaks array.
  3034. return breaks.reduce(function (arr, b) {
  3035. if (b.to !== obj.to || b.from !== obj.from) {
  3036. arr.push(b);
  3037. }
  3038. return arr;
  3039. }, []);
  3040. };
  3041. /**
  3042. * Creates a list of positions for the ticks on the axis. Filters out
  3043. * positions that are outside min and max, or is inside an axis break.
  3044. *
  3045. * @private
  3046. *
  3047. * @return {Array<number>}
  3048. * List of positions.
  3049. */
  3050. Additions.prototype.getTickPositions = function () {
  3051. var axis = this.axis,
  3052. roundedMin = Math.floor(axis.min / axis.tickInterval) * axis.tickInterval,
  3053. roundedMax = Math.ceil(axis.max / axis.tickInterval) * axis.tickInterval;
  3054. return Object.keys(axis.treeGrid.mapOfPosToGridNode || {}).reduce(function (arr, key) {
  3055. var pos = +key;
  3056. if (pos >= roundedMin &&
  3057. pos <= roundedMax &&
  3058. !(axis.brokenAxis && axis.brokenAxis.isInAnyBreak(pos))) {
  3059. arr.push(pos);
  3060. }
  3061. return arr;
  3062. }, []);
  3063. };
  3064. /**
  3065. * Check if a node is collapsed.
  3066. *
  3067. * @private
  3068. *
  3069. * @param {Highcharts.Axis} axis
  3070. * The axis to check against.
  3071. *
  3072. * @param {object} node
  3073. * The node to check if is collapsed.
  3074. *
  3075. * @param {number} pos
  3076. * The tick position to collapse.
  3077. *
  3078. * @return {boolean}
  3079. * Returns true if collapsed, false if expanded.
  3080. */
  3081. Additions.prototype.isCollapsed = function (node) {
  3082. var axis = this.axis,
  3083. breaks = (axis.options.breaks || []),
  3084. obj = getBreakFromNode(node,
  3085. axis.max);
  3086. return breaks.some(function (b) {
  3087. return b.from === obj.from && b.to === obj.to;
  3088. });
  3089. };
  3090. /**
  3091. * Calculates the new axis breaks after toggling the collapse/expand
  3092. * state of a node. If it is collapsed it will be expanded, and if it is
  3093. * exapended it will be collapsed.
  3094. *
  3095. * @private
  3096. *
  3097. * @param {Highcharts.Axis} axis
  3098. * The axis to check against.
  3099. *
  3100. * @param {Highcharts.GridNode} node
  3101. * The node to toggle.
  3102. *
  3103. * @return {Array<object>}
  3104. * Returns an array of the new breaks for the axis.
  3105. */
  3106. Additions.prototype.toggleCollapse = function (node) {
  3107. return (this.isCollapsed(node) ?
  3108. this.expand(node) :
  3109. this.collapse(node));
  3110. };
  3111. return Additions;
  3112. }());
  3113. TreeGridAxis.Additions = Additions;
  3114. })(TreeGridAxis || (TreeGridAxis = {}));
  3115. // Make utility functions available for testing.
  3116. Axis.prototype.utils = {
  3117. getNode: Tree.getNode
  3118. };
  3119. TreeGridAxis.compose(Axis);
  3120. return TreeGridAxis;
  3121. });
  3122. _registerModule(_modules, 'Extensions/CurrentDateIndication.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/PlotLineOrBand.js']], function (Axis, U, PlotLineOrBand) {
  3123. /* *
  3124. *
  3125. * (c) 2016-2020 Highsoft AS
  3126. *
  3127. * Author: Lars A. V. Cabrera
  3128. *
  3129. * License: www.highcharts.com/license
  3130. *
  3131. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3132. *
  3133. * */
  3134. var addEvent = U.addEvent,
  3135. merge = U.merge,
  3136. wrap = U.wrap;
  3137. var defaultConfig = {
  3138. /**
  3139. * Show an indicator on the axis for the current date and time. Can be a
  3140. * boolean or a configuration object similar to
  3141. * [xAxis.plotLines](#xAxis.plotLines).
  3142. *
  3143. * @sample gantt/current-date-indicator/demo
  3144. * Current date indicator enabled
  3145. * @sample gantt/current-date-indicator/object-config
  3146. * Current date indicator with custom options
  3147. *
  3148. * @declare Highcharts.AxisCurrentDateIndicatorOptions
  3149. * @type {boolean|*}
  3150. * @default true
  3151. * @extends xAxis.plotLines
  3152. * @excluding value
  3153. * @product gantt
  3154. * @apioption xAxis.currentDateIndicator
  3155. */
  3156. currentDateIndicator: true,
  3157. color: '#ccd6eb',
  3158. width: 2,
  3159. /**
  3160. * @declare Highcharts.AxisCurrentDateIndicatorLabelOptions
  3161. */
  3162. label: {
  3163. /**
  3164. * Format of the label. This options is passed as the fist argument to
  3165. * [dateFormat](/class-reference/Highcharts#dateFormat) function.
  3166. *
  3167. * @type {string}
  3168. * @default %a, %b %d %Y, %H:%M
  3169. * @product gantt
  3170. * @apioption xAxis.currentDateIndicator.label.format
  3171. */
  3172. format: '%a, %b %d %Y, %H:%M',
  3173. formatter: function (value, format) {
  3174. return this.axis.chart.time.dateFormat(format, value);
  3175. },
  3176. rotation: 0,
  3177. /**
  3178. * @type {Highcharts.CSSObject}
  3179. */
  3180. style: {
  3181. /** @internal */
  3182. fontSize: '10px'
  3183. }
  3184. }
  3185. };
  3186. /* eslint-disable no-invalid-this */
  3187. addEvent(Axis, 'afterSetOptions', function () {
  3188. var options = this.options,
  3189. cdiOptions = options.currentDateIndicator;
  3190. if (cdiOptions) {
  3191. cdiOptions = typeof cdiOptions === 'object' ?
  3192. merge(defaultConfig, cdiOptions) : merge(defaultConfig);
  3193. cdiOptions.value = new Date();
  3194. if (!options.plotLines) {
  3195. options.plotLines = [];
  3196. }
  3197. options.plotLines.push(cdiOptions);
  3198. }
  3199. });
  3200. addEvent(PlotLineOrBand, 'render', function () {
  3201. // If the label already exists, update its text
  3202. if (this.label) {
  3203. this.label.attr({
  3204. text: this.getLabelText(this.options.label)
  3205. });
  3206. }
  3207. });
  3208. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  3209. var options = this.options;
  3210. if (options.currentDateIndicator && options.label &&
  3211. typeof options.label.formatter === 'function') {
  3212. options.value = new Date();
  3213. return options.label.formatter
  3214. .call(this, options.value, options.label.format);
  3215. }
  3216. return defaultMethod.call(this, defaultLabelOptions);
  3217. });
  3218. });
  3219. _registerModule(_modules, 'Extensions/StaticScale.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Utilities.js']], function (Axis, Chart, U) {
  3220. /* *
  3221. *
  3222. * (c) 2016-2020 Torstein Honsi, Lars Cabrera
  3223. *
  3224. * License: www.highcharts.com/license
  3225. *
  3226. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3227. *
  3228. * */
  3229. var addEvent = U.addEvent,
  3230. defined = U.defined,
  3231. isNumber = U.isNumber,
  3232. pick = U.pick;
  3233. /* eslint-disable no-invalid-this */
  3234. /**
  3235. * For vertical axes only. Setting the static scale ensures that each tick unit
  3236. * is translated into a fixed pixel height. For example, setting the static
  3237. * scale to 24 results in each Y axis category taking up 24 pixels, and the
  3238. * height of the chart adjusts. Adding or removing items will make the chart
  3239. * resize.
  3240. *
  3241. * @sample gantt/xrange-series/demo/
  3242. * X-range series with static scale
  3243. *
  3244. * @type {number}
  3245. * @default 50
  3246. * @since 6.2.0
  3247. * @product gantt
  3248. * @apioption yAxis.staticScale
  3249. */
  3250. addEvent(Axis, 'afterSetOptions', function () {
  3251. var chartOptions = this.chart.options && this.chart.options.chart;
  3252. if (!this.horiz &&
  3253. isNumber(this.options.staticScale) &&
  3254. (!chartOptions.height ||
  3255. (chartOptions.scrollablePlotArea &&
  3256. chartOptions.scrollablePlotArea.minHeight))) {
  3257. this.staticScale = this.options.staticScale;
  3258. }
  3259. });
  3260. Chart.prototype.adjustHeight = function () {
  3261. if (this.redrawTrigger !== 'adjustHeight') {
  3262. (this.axes || []).forEach(function (axis) {
  3263. var chart = axis.chart,
  3264. animate = !!chart.initiatedScale &&
  3265. chart.options.animation,
  3266. staticScale = axis.options.staticScale,
  3267. height,
  3268. diff;
  3269. if (axis.staticScale && defined(axis.min)) {
  3270. height = pick(axis.brokenAxis && axis.brokenAxis.unitLength, axis.max + axis.tickInterval - axis.min) * staticScale;
  3271. // Minimum height is 1 x staticScale.
  3272. height = Math.max(height, staticScale);
  3273. diff = height - chart.plotHeight;
  3274. if (Math.abs(diff) >= 1) {
  3275. chart.plotHeight = height;
  3276. chart.redrawTrigger = 'adjustHeight';
  3277. chart.setSize(void 0, chart.chartHeight + diff, animate);
  3278. }
  3279. // Make sure clip rects have the right height before initial
  3280. // animation.
  3281. axis.series.forEach(function (series) {
  3282. var clipRect = series.sharedClipKey &&
  3283. chart[series.sharedClipKey];
  3284. if (clipRect) {
  3285. clipRect.attr({
  3286. height: chart.plotHeight
  3287. });
  3288. }
  3289. });
  3290. }
  3291. });
  3292. this.initiatedScale = true;
  3293. }
  3294. this.redrawTrigger = null;
  3295. };
  3296. addEvent(Chart, 'render', Chart.prototype.adjustHeight);
  3297. });
  3298. _registerModule(_modules, 'Extensions/ArrowSymbols.js', [_modules['Core/Renderer/SVG/SVGRenderer.js']], function (SVGRenderer) {
  3299. /* *
  3300. *
  3301. * (c) 2017 Highsoft AS
  3302. * Authors: Lars A. V. Cabrera
  3303. *
  3304. * License: www.highcharts.com/license
  3305. *
  3306. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3307. *
  3308. * */
  3309. /**
  3310. * Creates an arrow symbol. Like a triangle, except not filled.
  3311. * ```
  3312. * o
  3313. * o
  3314. * o
  3315. * o
  3316. * o
  3317. * o
  3318. * o
  3319. * ```
  3320. *
  3321. * @private
  3322. * @function
  3323. *
  3324. * @param {number} x
  3325. * x position of the arrow
  3326. *
  3327. * @param {number} y
  3328. * y position of the arrow
  3329. *
  3330. * @param {number} w
  3331. * width of the arrow
  3332. *
  3333. * @param {number} h
  3334. * height of the arrow
  3335. *
  3336. * @return {Highcharts.SVGPathArray}
  3337. * Path array
  3338. */
  3339. SVGRenderer.prototype.symbols.arrow = function (x, y, w, h) {
  3340. return [
  3341. ['M', x, y + h / 2],
  3342. ['L', x + w, y],
  3343. ['L', x, y + h / 2],
  3344. ['L', x + w, y + h]
  3345. ];
  3346. };
  3347. /**
  3348. * Creates a half-width arrow symbol. Like a triangle, except not filled.
  3349. * ```
  3350. * o
  3351. * o
  3352. * o
  3353. * o
  3354. * o
  3355. * ```
  3356. *
  3357. * @private
  3358. * @function
  3359. *
  3360. * @param {number} x
  3361. * x position of the arrow
  3362. *
  3363. * @param {number} y
  3364. * y position of the arrow
  3365. *
  3366. * @param {number} w
  3367. * width of the arrow
  3368. *
  3369. * @param {number} h
  3370. * height of the arrow
  3371. *
  3372. * @return {Highcharts.SVGPathArray}
  3373. * Path array
  3374. */
  3375. SVGRenderer.prototype.symbols['arrow-half'] = function (x, y, w, h) {
  3376. return SVGRenderer.prototype.symbols.arrow(x, y, w / 2, h);
  3377. };
  3378. /**
  3379. * Creates a left-oriented triangle.
  3380. * ```
  3381. * o
  3382. * ooooooo
  3383. * ooooooooooooo
  3384. * ooooooo
  3385. * o
  3386. * ```
  3387. *
  3388. * @private
  3389. * @function
  3390. *
  3391. * @param {number} x
  3392. * x position of the triangle
  3393. *
  3394. * @param {number} y
  3395. * y position of the triangle
  3396. *
  3397. * @param {number} w
  3398. * width of the triangle
  3399. *
  3400. * @param {number} h
  3401. * height of the triangle
  3402. *
  3403. * @return {Highcharts.SVGPathArray}
  3404. * Path array
  3405. */
  3406. SVGRenderer.prototype.symbols['triangle-left'] = function (x, y, w, h) {
  3407. return [
  3408. ['M', x + w, y],
  3409. ['L', x, y + h / 2],
  3410. ['L', x + w, y + h],
  3411. ['Z']
  3412. ];
  3413. };
  3414. /**
  3415. * Alias function for triangle-left.
  3416. *
  3417. * @private
  3418. * @function
  3419. *
  3420. * @param {number} x
  3421. * x position of the arrow
  3422. *
  3423. * @param {number} y
  3424. * y position of the arrow
  3425. *
  3426. * @param {number} w
  3427. * width of the arrow
  3428. *
  3429. * @param {number} h
  3430. * height of the arrow
  3431. *
  3432. * @return {Highcharts.SVGPathArray}
  3433. * Path array
  3434. */
  3435. SVGRenderer.prototype.symbols['arrow-filled'] = SVGRenderer.prototype.symbols['triangle-left'];
  3436. /**
  3437. * Creates a half-width, left-oriented triangle.
  3438. * ```
  3439. * o
  3440. * oooo
  3441. * ooooooo
  3442. * oooo
  3443. * o
  3444. * ```
  3445. *
  3446. * @private
  3447. * @function
  3448. *
  3449. * @param {number} x
  3450. * x position of the triangle
  3451. *
  3452. * @param {number} y
  3453. * y position of the triangle
  3454. *
  3455. * @param {number} w
  3456. * width of the triangle
  3457. *
  3458. * @param {number} h
  3459. * height of the triangle
  3460. *
  3461. * @return {Highcharts.SVGPathArray}
  3462. * Path array
  3463. */
  3464. SVGRenderer.prototype.symbols['triangle-left-half'] = function (x, y, w, h) {
  3465. return SVGRenderer.prototype.symbols['triangle-left'](x, y, w / 2, h);
  3466. };
  3467. /**
  3468. * Alias function for triangle-left-half.
  3469. *
  3470. * @private
  3471. * @function
  3472. *
  3473. * @param {number} x
  3474. * x position of the arrow
  3475. *
  3476. * @param {number} y
  3477. * y position of the arrow
  3478. *
  3479. * @param {number} w
  3480. * width of the arrow
  3481. *
  3482. * @param {number} h
  3483. * height of the arrow
  3484. *
  3485. * @return {Highcharts.SVGPathArray}
  3486. * Path array
  3487. */
  3488. SVGRenderer.prototype.symbols['arrow-filled-half'] = SVGRenderer.prototype.symbols['triangle-left-half'];
  3489. });
  3490. _registerModule(_modules, 'Gantt/Connection.js', [_modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (H, O, Point, U) {
  3491. /* *
  3492. *
  3493. * (c) 2016 Highsoft AS
  3494. * Authors: Øystein Moseng, Lars A. V. Cabrera
  3495. *
  3496. * License: www.highcharts.com/license
  3497. *
  3498. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3499. *
  3500. * */
  3501. /**
  3502. * The default pathfinder algorithm to use for a chart. It is possible to define
  3503. * your own algorithms by adding them to the
  3504. * `Highcharts.Pathfinder.prototype.algorithms`
  3505. * object before the chart has been created.
  3506. *
  3507. * The default algorithms are as follows:
  3508. *
  3509. * `straight`: Draws a straight line between the connecting
  3510. * points. Does not avoid other points when drawing.
  3511. *
  3512. * `simpleConnect`: Finds a path between the points using right angles
  3513. * only. Takes only starting/ending points into
  3514. * account, and will not avoid other points.
  3515. *
  3516. * `fastAvoid`: Finds a path between the points using right angles
  3517. * only. Will attempt to avoid other points, but its
  3518. * focus is performance over accuracy. Works well with
  3519. * less dense datasets.
  3520. *
  3521. * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
  3522. */
  3523. ''; // detach doclets above
  3524. var defaultOptions = O.defaultOptions;
  3525. var addEvent = U.addEvent,
  3526. defined = U.defined,
  3527. error = U.error,
  3528. extend = U.extend,
  3529. merge = U.merge,
  3530. objectEach = U.objectEach,
  3531. pick = U.pick,
  3532. splat = U.splat;
  3533. var deg2rad = H.deg2rad,
  3534. max = Math.max,
  3535. min = Math.min;
  3536. /*
  3537. @todo:
  3538. - Document how to write your own algorithms
  3539. - Consider adding a Point.pathTo method that wraps creating a connection
  3540. and rendering it
  3541. */
  3542. // Set default Pathfinder options
  3543. extend(defaultOptions, {
  3544. /**
  3545. * The Pathfinder module allows you to define connections between any two
  3546. * points, represented as lines - optionally with markers for the start
  3547. * and/or end points. Multiple algorithms are available for calculating how
  3548. * the connecting lines are drawn.
  3549. *
  3550. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  3551. * charts, the connectors are used to draw dependencies between tasks.
  3552. *
  3553. * @see [dependency](series.gantt.data.dependency)
  3554. *
  3555. * @sample gantt/pathfinder/demo
  3556. * Pathfinder connections
  3557. *
  3558. * @declare Highcharts.ConnectorsOptions
  3559. * @product gantt
  3560. * @optionparent connectors
  3561. */
  3562. connectors: {
  3563. /**
  3564. * Enable connectors for this chart. Requires Highcharts Gantt.
  3565. *
  3566. * @type {boolean}
  3567. * @default true
  3568. * @since 6.2.0
  3569. * @apioption connectors.enabled
  3570. */
  3571. /**
  3572. * Set the default dash style for this chart's connecting lines.
  3573. *
  3574. * @type {string}
  3575. * @default solid
  3576. * @since 6.2.0
  3577. * @apioption connectors.dashStyle
  3578. */
  3579. /**
  3580. * Set the default color for this chart's Pathfinder connecting lines.
  3581. * Defaults to the color of the point being connected.
  3582. *
  3583. * @type {Highcharts.ColorString}
  3584. * @since 6.2.0
  3585. * @apioption connectors.lineColor
  3586. */
  3587. /**
  3588. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  3589. * algorithms attempt to avoid obstacles, such as other points in the
  3590. * chart. These algorithms use this margin to determine how close lines
  3591. * can be to an obstacle. The default is to compute this automatically
  3592. * from the size of the obstacles in the chart.
  3593. *
  3594. * To draw connecting lines close to existing points, set this to a low
  3595. * number. For more space around existing points, set this number
  3596. * higher.
  3597. *
  3598. * @sample gantt/pathfinder/algorithm-margin
  3599. * Small algorithmMargin
  3600. *
  3601. * @type {number}
  3602. * @since 6.2.0
  3603. * @apioption connectors.algorithmMargin
  3604. */
  3605. /**
  3606. * Set the default pathfinder algorithm to use for this chart. It is
  3607. * possible to define your own algorithms by adding them to the
  3608. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  3609. * has been created.
  3610. *
  3611. * The default algorithms are as follows:
  3612. *
  3613. * `straight`: Draws a straight line between the connecting
  3614. * points. Does not avoid other points when drawing.
  3615. *
  3616. * `simpleConnect`: Finds a path between the points using right angles
  3617. * only. Takes only starting/ending points into
  3618. * account, and will not avoid other points.
  3619. *
  3620. * `fastAvoid`: Finds a path between the points using right angles
  3621. * only. Will attempt to avoid other points, but its
  3622. * focus is performance over accuracy. Works well with
  3623. * less dense datasets.
  3624. *
  3625. * Default value: `straight` is used as default for most series types,
  3626. * while `simpleConnect` is used as default for Gantt series, to show
  3627. * dependencies between points.
  3628. *
  3629. * @sample gantt/pathfinder/demo
  3630. * Different types used
  3631. *
  3632. * @type {Highcharts.PathfinderTypeValue}
  3633. * @default undefined
  3634. * @since 6.2.0
  3635. */
  3636. type: 'straight',
  3637. /**
  3638. * Set the default pixel width for this chart's Pathfinder connecting
  3639. * lines.
  3640. *
  3641. * @since 6.2.0
  3642. */
  3643. lineWidth: 1,
  3644. /**
  3645. * Marker options for this chart's Pathfinder connectors. Note that
  3646. * this option is overridden by the `startMarker` and `endMarker`
  3647. * options.
  3648. *
  3649. * @declare Highcharts.ConnectorsMarkerOptions
  3650. * @since 6.2.0
  3651. */
  3652. marker: {
  3653. /**
  3654. * Set the radius of the connector markers. The default is
  3655. * automatically computed based on the algorithmMargin setting.
  3656. *
  3657. * Setting marker.width and marker.height will override this
  3658. * setting.
  3659. *
  3660. * @type {number}
  3661. * @since 6.2.0
  3662. * @apioption connectors.marker.radius
  3663. */
  3664. /**
  3665. * Set the width of the connector markers. If not supplied, this
  3666. * is inferred from the marker radius.
  3667. *
  3668. * @type {number}
  3669. * @since 6.2.0
  3670. * @apioption connectors.marker.width
  3671. */
  3672. /**
  3673. * Set the height of the connector markers. If not supplied, this
  3674. * is inferred from the marker radius.
  3675. *
  3676. * @type {number}
  3677. * @since 6.2.0
  3678. * @apioption connectors.marker.height
  3679. */
  3680. /**
  3681. * Set the color of the connector markers. By default this is the
  3682. * same as the connector color.
  3683. *
  3684. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3685. * @since 6.2.0
  3686. * @apioption connectors.marker.color
  3687. */
  3688. /**
  3689. * Set the line/border color of the connector markers. By default
  3690. * this is the same as the marker color.
  3691. *
  3692. * @type {Highcharts.ColorString}
  3693. * @since 6.2.0
  3694. * @apioption connectors.marker.lineColor
  3695. */
  3696. /**
  3697. * Enable markers for the connectors.
  3698. */
  3699. enabled: false,
  3700. /**
  3701. * Horizontal alignment of the markers relative to the points.
  3702. *
  3703. * @type {Highcharts.AlignValue}
  3704. */
  3705. align: 'center',
  3706. /**
  3707. * Vertical alignment of the markers relative to the points.
  3708. *
  3709. * @type {Highcharts.VerticalAlignValue}
  3710. */
  3711. verticalAlign: 'middle',
  3712. /**
  3713. * Whether or not to draw the markers inside the points.
  3714. */
  3715. inside: false,
  3716. /**
  3717. * Set the line/border width of the pathfinder markers.
  3718. */
  3719. lineWidth: 1
  3720. },
  3721. /**
  3722. * Marker options specific to the start markers for this chart's
  3723. * Pathfinder connectors. Overrides the generic marker options.
  3724. *
  3725. * @declare Highcharts.ConnectorsStartMarkerOptions
  3726. * @extends connectors.marker
  3727. * @since 6.2.0
  3728. */
  3729. startMarker: {
  3730. /**
  3731. * Set the symbol of the connector start markers.
  3732. */
  3733. symbol: 'diamond'
  3734. },
  3735. /**
  3736. * Marker options specific to the end markers for this chart's
  3737. * Pathfinder connectors. Overrides the generic marker options.
  3738. *
  3739. * @declare Highcharts.ConnectorsEndMarkerOptions
  3740. * @extends connectors.marker
  3741. * @since 6.2.0
  3742. */
  3743. endMarker: {
  3744. /**
  3745. * Set the symbol of the connector end markers.
  3746. */
  3747. symbol: 'arrow-filled'
  3748. }
  3749. }
  3750. });
  3751. /**
  3752. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  3753. * to be loaded.
  3754. *
  3755. * @declare Highcharts.SeriesConnectorsOptionsObject
  3756. * @extends connectors
  3757. * @since 6.2.0
  3758. * @excluding enabled, algorithmMargin
  3759. * @product gantt
  3760. * @apioption plotOptions.series.connectors
  3761. */
  3762. /**
  3763. * Connect to a point. This option can be either a string, referring to the ID
  3764. * of another point, or an object, or an array of either. If the option is an
  3765. * array, each element defines a connection.
  3766. *
  3767. * @sample gantt/pathfinder/demo
  3768. * Different connection types
  3769. *
  3770. * @declare Highcharts.XrangePointConnectorsOptionsObject
  3771. * @type {string|Array<string|*>|*}
  3772. * @extends plotOptions.series.connectors
  3773. * @since 6.2.0
  3774. * @excluding enabled
  3775. * @product gantt
  3776. * @requires highcharts-gantt
  3777. * @apioption series.xrange.data.connect
  3778. */
  3779. /**
  3780. * The ID of the point to connect to.
  3781. *
  3782. * @type {string}
  3783. * @since 6.2.0
  3784. * @product gantt
  3785. * @apioption series.xrange.data.connect.to
  3786. */
  3787. /**
  3788. * Get point bounding box using plotX/plotY and shapeArgs. If using
  3789. * graphic.getBBox() directly, the bbox will be affected by animation.
  3790. *
  3791. * @private
  3792. * @function
  3793. *
  3794. * @param {Highcharts.Point} point
  3795. * The point to get BB of.
  3796. *
  3797. * @return {Highcharts.Dictionary<number>|null}
  3798. * Result xMax, xMin, yMax, yMin.
  3799. */
  3800. function getPointBB(point) {
  3801. var shapeArgs = point.shapeArgs,
  3802. bb;
  3803. // Prefer using shapeArgs (columns)
  3804. if (shapeArgs) {
  3805. return {
  3806. xMin: shapeArgs.x,
  3807. xMax: shapeArgs.x + shapeArgs.width,
  3808. yMin: shapeArgs.y,
  3809. yMax: shapeArgs.y + shapeArgs.height
  3810. };
  3811. }
  3812. // Otherwise use plotX/plotY and bb
  3813. bb = point.graphic && point.graphic.getBBox();
  3814. return bb ? {
  3815. xMin: point.plotX - bb.width / 2,
  3816. xMax: point.plotX + bb.width / 2,
  3817. yMin: point.plotY - bb.height / 2,
  3818. yMax: point.plotY + bb.height / 2
  3819. } : null;
  3820. }
  3821. /**
  3822. * Calculate margin to place around obstacles for the pathfinder in pixels.
  3823. * Returns a minimum of 1 pixel margin.
  3824. *
  3825. * @private
  3826. * @function
  3827. *
  3828. * @param {Array<object>} obstacles
  3829. * Obstacles to calculate margin from.
  3830. *
  3831. * @return {number}
  3832. * The calculated margin in pixels. At least 1.
  3833. */
  3834. function calculateObstacleMargin(obstacles) {
  3835. var len = obstacles.length,
  3836. i = 0,
  3837. j,
  3838. obstacleDistance,
  3839. distances = [],
  3840. // Compute smallest distance between two rectangles
  3841. distance = function (a,
  3842. b,
  3843. bbMargin) {
  3844. // Count the distance even if we are slightly off
  3845. var margin = pick(bbMargin, 10),
  3846. yOverlap = a.yMax + margin > b.yMin - margin &&
  3847. a.yMin - margin < b.yMax + margin,
  3848. xOverlap = a.xMax + margin > b.xMin - margin &&
  3849. a.xMin - margin < b.xMax + margin,
  3850. xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
  3851. yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
  3852. // If the rectangles collide, try recomputing with smaller margin.
  3853. // If they collide anyway, discard the obstacle.
  3854. if (xOverlap && yOverlap) {
  3855. return (margin ?
  3856. distance(a, b, Math.floor(margin / 2)) :
  3857. Infinity);
  3858. }
  3859. return min(xDistance, yDistance);
  3860. };
  3861. // Go over all obstacles and compare them to the others.
  3862. for (; i < len; ++i) {
  3863. // Compare to all obstacles ahead. We will already have compared this
  3864. // obstacle to the ones before.
  3865. for (j = i + 1; j < len; ++j) {
  3866. obstacleDistance = distance(obstacles[i], obstacles[j]);
  3867. // TODO: Magic number 80
  3868. if (obstacleDistance < 80) { // Ignore large distances
  3869. distances.push(obstacleDistance);
  3870. }
  3871. }
  3872. }
  3873. // Ensure we always have at least one value, even in very spaceous charts
  3874. distances.push(80);
  3875. return max(Math.floor(distances.sort(function (a, b) {
  3876. return (a - b);
  3877. })[
  3878. // Discard first 10% of the relevant distances, and then grab
  3879. // the smallest one.
  3880. Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
  3881. ), 1 // 1 is the minimum margin
  3882. );
  3883. }
  3884. /* eslint-disable no-invalid-this, valid-jsdoc */
  3885. /**
  3886. * The Connection class. Used internally to represent a connection between two
  3887. * points.
  3888. *
  3889. * @private
  3890. * @class
  3891. * @name Highcharts.Connection
  3892. *
  3893. * @param {Highcharts.Point} from
  3894. * Connection runs from this Point.
  3895. *
  3896. * @param {Highcharts.Point} to
  3897. * Connection runs to this Point.
  3898. *
  3899. * @param {Highcharts.ConnectorsOptions} [options]
  3900. * Connection options.
  3901. */
  3902. var Connection = /** @class */ (function () {
  3903. function Connection(from, to, options) {
  3904. /* *
  3905. *
  3906. * Properties
  3907. *
  3908. * */
  3909. this.chart = void 0;
  3910. this.fromPoint = void 0;
  3911. this.graphics = void 0;
  3912. this.pathfinder = void 0;
  3913. this.toPoint = void 0;
  3914. this.init(from, to, options);
  3915. }
  3916. /**
  3917. * Initialize the Connection object. Used as constructor only.
  3918. *
  3919. * @function Highcharts.Connection#init
  3920. *
  3921. * @param {Highcharts.Point} from
  3922. * Connection runs from this Point.
  3923. *
  3924. * @param {Highcharts.Point} to
  3925. * Connection runs to this Point.
  3926. *
  3927. * @param {Highcharts.ConnectorsOptions} [options]
  3928. * Connection options.
  3929. */
  3930. Connection.prototype.init = function (from, to, options) {
  3931. this.fromPoint = from;
  3932. this.toPoint = to;
  3933. this.options = options;
  3934. this.chart = from.series.chart;
  3935. this.pathfinder = this.chart.pathfinder;
  3936. };
  3937. /**
  3938. * Add (or update) this connection's path on chart. Stores reference to the
  3939. * created element on this.graphics.path.
  3940. *
  3941. * @function Highcharts.Connection#renderPath
  3942. *
  3943. * @param {Highcharts.SVGPathArray} path
  3944. * Path to render, in array format. E.g. ['M', 0, 0, 'L', 10, 10]
  3945. *
  3946. * @param {Highcharts.SVGAttributes} [attribs]
  3947. * SVG attributes for the path.
  3948. *
  3949. * @param {Partial<Highcharts.AnimationOptionsObject>} [animation]
  3950. * Animation options for the rendering.
  3951. */
  3952. Connection.prototype.renderPath = function (path, attribs, animation) {
  3953. var connection = this,
  3954. chart = this.chart,
  3955. styledMode = chart.styledMode,
  3956. pathfinder = chart.pathfinder,
  3957. animate = !chart.options.chart.forExport && animation !== false,
  3958. pathGraphic = connection.graphics && connection.graphics.path,
  3959. anim;
  3960. // Add the SVG element of the pathfinder group if it doesn't exist
  3961. if (!pathfinder.group) {
  3962. pathfinder.group = chart.renderer.g()
  3963. .addClass('highcharts-pathfinder-group')
  3964. .attr({ zIndex: -1 })
  3965. .add(chart.seriesGroup);
  3966. }
  3967. // Shift the group to compensate for plot area.
  3968. // Note: Do this always (even when redrawing a path) to avoid issues
  3969. // when updating chart in a way that changes plot metrics.
  3970. pathfinder.group.translate(chart.plotLeft, chart.plotTop);
  3971. // Create path if does not exist
  3972. if (!(pathGraphic && pathGraphic.renderer)) {
  3973. pathGraphic = chart.renderer.path()
  3974. .add(pathfinder.group);
  3975. if (!styledMode) {
  3976. pathGraphic.attr({
  3977. opacity: 0
  3978. });
  3979. }
  3980. }
  3981. // Set path attribs and animate to the new path
  3982. pathGraphic.attr(attribs);
  3983. anim = { d: path };
  3984. if (!styledMode) {
  3985. anim.opacity = 1;
  3986. }
  3987. pathGraphic[animate ? 'animate' : 'attr'](anim, animation);
  3988. // Store reference on connection
  3989. this.graphics = this.graphics || {};
  3990. this.graphics.path = pathGraphic;
  3991. };
  3992. /**
  3993. * Calculate and add marker graphics for connection to the chart. The
  3994. * created/updated elements are stored on this.graphics.start and
  3995. * this.graphics.end.
  3996. *
  3997. * @function Highcharts.Connection#addMarker
  3998. *
  3999. * @param {string} type
  4000. * Marker type, either 'start' or 'end'.
  4001. *
  4002. * @param {Highcharts.ConnectorsMarkerOptions} options
  4003. * All options for this marker. Not calculated or merged with other
  4004. * options.
  4005. *
  4006. * @param {Highcharts.SVGPathArray} path
  4007. * Connection path in array format. This is used to calculate the
  4008. * rotation angle of the markers.
  4009. */
  4010. Connection.prototype.addMarker = function (type, options, path) {
  4011. var connection = this,
  4012. chart = connection.fromPoint.series.chart,
  4013. pathfinder = chart.pathfinder,
  4014. renderer = chart.renderer,
  4015. point = (type === 'start' ?
  4016. connection.fromPoint :
  4017. connection.toPoint),
  4018. anchor = point.getPathfinderAnchorPoint(options),
  4019. markerVector,
  4020. radians,
  4021. rotation,
  4022. box,
  4023. width,
  4024. height,
  4025. pathVector,
  4026. segment;
  4027. if (!options.enabled) {
  4028. return;
  4029. }
  4030. // Last vector before start/end of path, used to get angle
  4031. if (type === 'start') {
  4032. segment = path[1];
  4033. }
  4034. else { // 'end'
  4035. segment = path[path.length - 2];
  4036. }
  4037. if (segment && segment[0] === 'M' || segment[0] === 'L') {
  4038. pathVector = {
  4039. x: segment[1],
  4040. y: segment[2]
  4041. };
  4042. // Get angle between pathVector and anchor point and use it to
  4043. // create marker position.
  4044. radians = point.getRadiansToVector(pathVector, anchor);
  4045. markerVector = point.getMarkerVector(radians, options.radius, anchor);
  4046. // Rotation of marker is calculated from angle between pathVector
  4047. // and markerVector.
  4048. // (Note:
  4049. // Used to recalculate radians between markerVector and pathVector,
  4050. // but this should be the same as between pathVector and anchor.)
  4051. rotation = -radians / deg2rad;
  4052. if (options.width && options.height) {
  4053. width = options.width;
  4054. height = options.height;
  4055. }
  4056. else {
  4057. width = height = options.radius * 2;
  4058. }
  4059. // Add graphics object if it does not exist
  4060. connection.graphics = connection.graphics || {};
  4061. box = {
  4062. x: markerVector.x - (width / 2),
  4063. y: markerVector.y - (height / 2),
  4064. width: width,
  4065. height: height,
  4066. rotation: rotation,
  4067. rotationOriginX: markerVector.x,
  4068. rotationOriginY: markerVector.y
  4069. };
  4070. if (!connection.graphics[type]) {
  4071. // Create new marker element
  4072. connection.graphics[type] = renderer
  4073. .symbol(options.symbol)
  4074. .addClass('highcharts-point-connecting-path-' + type + '-marker')
  4075. .attr(box)
  4076. .add(pathfinder.group);
  4077. if (!renderer.styledMode) {
  4078. connection.graphics[type].attr({
  4079. fill: options.color || connection.fromPoint.color,
  4080. stroke: options.lineColor,
  4081. 'stroke-width': options.lineWidth,
  4082. opacity: 0
  4083. })
  4084. .animate({
  4085. opacity: 1
  4086. }, point.series.options.animation);
  4087. }
  4088. }
  4089. else {
  4090. connection.graphics[type].animate(box);
  4091. }
  4092. }
  4093. };
  4094. /**
  4095. * Calculate and return connection path.
  4096. * Note: Recalculates chart obstacles on demand if they aren't calculated.
  4097. *
  4098. * @function Highcharts.Connection#getPath
  4099. *
  4100. * @param {Highcharts.ConnectorsOptions} options
  4101. * Connector options. Not calculated or merged with other options.
  4102. *
  4103. * @return {object|undefined}
  4104. * Calculated SVG path data in array format.
  4105. */
  4106. Connection.prototype.getPath = function (options) {
  4107. var pathfinder = this.pathfinder,
  4108. chart = this.chart,
  4109. algorithm = pathfinder.algorithms[options.type],
  4110. chartObstacles = pathfinder.chartObstacles;
  4111. if (typeof algorithm !== 'function') {
  4112. error('"' + options.type + '" is not a Pathfinder algorithm.');
  4113. return {
  4114. path: [],
  4115. obstacles: []
  4116. };
  4117. }
  4118. // This function calculates obstacles on demand if they don't exist
  4119. if (algorithm.requiresObstacles && !chartObstacles) {
  4120. chartObstacles =
  4121. pathfinder.chartObstacles =
  4122. pathfinder.getChartObstacles(options);
  4123. // If the algorithmMargin was computed, store the result in default
  4124. // options.
  4125. chart.options.connectors.algorithmMargin =
  4126. options.algorithmMargin;
  4127. // Cache some metrics too
  4128. pathfinder.chartObstacleMetrics =
  4129. pathfinder.getObstacleMetrics(chartObstacles);
  4130. }
  4131. // Get the SVG path
  4132. return algorithm(
  4133. // From
  4134. this.fromPoint.getPathfinderAnchorPoint(options.startMarker),
  4135. // To
  4136. this.toPoint.getPathfinderAnchorPoint(options.endMarker), merge({
  4137. chartObstacles: chartObstacles,
  4138. lineObstacles: pathfinder.lineObstacles || [],
  4139. obstacleMetrics: pathfinder.chartObstacleMetrics,
  4140. hardBounds: {
  4141. xMin: 0,
  4142. xMax: chart.plotWidth,
  4143. yMin: 0,
  4144. yMax: chart.plotHeight
  4145. },
  4146. obstacleOptions: {
  4147. margin: options.algorithmMargin
  4148. },
  4149. startDirectionX: pathfinder.getAlgorithmStartDirection(options.startMarker)
  4150. }, options));
  4151. };
  4152. /**
  4153. * (re)Calculate and (re)draw the connection.
  4154. *
  4155. * @function Highcharts.Connection#render
  4156. */
  4157. Connection.prototype.render = function () {
  4158. var connection = this,
  4159. fromPoint = connection.fromPoint,
  4160. series = fromPoint.series,
  4161. chart = series.chart,
  4162. pathfinder = chart.pathfinder,
  4163. pathResult,
  4164. path,
  4165. options = merge(chart.options.connectors,
  4166. series.options.connectors,
  4167. fromPoint.options.connectors,
  4168. connection.options),
  4169. attribs = {};
  4170. // Set path attribs
  4171. if (!chart.styledMode) {
  4172. attribs.stroke = options.lineColor || fromPoint.color;
  4173. attribs['stroke-width'] = options.lineWidth;
  4174. if (options.dashStyle) {
  4175. attribs.dashstyle = options.dashStyle;
  4176. }
  4177. }
  4178. attribs['class'] = // eslint-disable-line dot-notation
  4179. 'highcharts-point-connecting-path ' +
  4180. 'highcharts-color-' + fromPoint.colorIndex;
  4181. options = merge(attribs, options);
  4182. // Set common marker options
  4183. if (!defined(options.marker.radius)) {
  4184. options.marker.radius = min(max(Math.ceil((options.algorithmMargin || 8) / 2) - 1, 1), 5);
  4185. }
  4186. // Get the path
  4187. pathResult = connection.getPath(options);
  4188. path = pathResult.path;
  4189. // Always update obstacle storage with obstacles from this path.
  4190. // We don't know if future calls will need this for their algorithm.
  4191. if (pathResult.obstacles) {
  4192. pathfinder.lineObstacles =
  4193. pathfinder.lineObstacles || [];
  4194. pathfinder.lineObstacles =
  4195. pathfinder.lineObstacles.concat(pathResult.obstacles);
  4196. }
  4197. // Add the calculated path to the pathfinder group
  4198. connection.renderPath(path, attribs, series.options.animation);
  4199. // Render the markers
  4200. connection.addMarker('start', merge(options.marker, options.startMarker), path);
  4201. connection.addMarker('end', merge(options.marker, options.endMarker), path);
  4202. };
  4203. /**
  4204. * Destroy connection by destroying the added graphics elements.
  4205. *
  4206. * @function Highcharts.Connection#destroy
  4207. */
  4208. Connection.prototype.destroy = function () {
  4209. if (this.graphics) {
  4210. objectEach(this.graphics, function (val) {
  4211. val.destroy();
  4212. });
  4213. delete this.graphics;
  4214. }
  4215. };
  4216. return Connection;
  4217. }());
  4218. // Add to Highcharts namespace
  4219. H.Connection = Connection;
  4220. // Add pathfinding capabilities to Points
  4221. extend(Point.prototype, /** @lends Point.prototype */ {
  4222. /**
  4223. * Get coordinates of anchor point for pathfinder connection.
  4224. *
  4225. * @private
  4226. * @function Highcharts.Point#getPathfinderAnchorPoint
  4227. *
  4228. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  4229. * Connection options for position on point.
  4230. *
  4231. * @return {Highcharts.PositionObject}
  4232. * An object with x/y properties for the position. Coordinates are
  4233. * in plot values, not relative to point.
  4234. */
  4235. getPathfinderAnchorPoint: function (markerOptions) {
  4236. var bb = getPointBB(this),
  4237. x,
  4238. y;
  4239. switch (markerOptions.align) { // eslint-disable-line default-case
  4240. case 'right':
  4241. x = 'xMax';
  4242. break;
  4243. case 'left':
  4244. x = 'xMin';
  4245. }
  4246. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  4247. case 'top':
  4248. y = 'yMin';
  4249. break;
  4250. case 'bottom':
  4251. y = 'yMax';
  4252. }
  4253. return {
  4254. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  4255. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  4256. };
  4257. },
  4258. /**
  4259. * Utility to get the angle from one point to another.
  4260. *
  4261. * @private
  4262. * @function Highcharts.Point#getRadiansToVector
  4263. *
  4264. * @param {Highcharts.PositionObject} v1
  4265. * The first vector, as an object with x/y properties.
  4266. *
  4267. * @param {Highcharts.PositionObject} v2
  4268. * The second vector, as an object with x/y properties.
  4269. *
  4270. * @return {number}
  4271. * The angle in degrees
  4272. */
  4273. getRadiansToVector: function (v1, v2) {
  4274. var box;
  4275. if (!defined(v2)) {
  4276. box = getPointBB(this);
  4277. if (box) {
  4278. v2 = {
  4279. x: (box.xMin + box.xMax) / 2,
  4280. y: (box.yMin + box.yMax) / 2
  4281. };
  4282. }
  4283. }
  4284. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  4285. },
  4286. /**
  4287. * Utility to get the position of the marker, based on the path angle and
  4288. * the marker's radius.
  4289. *
  4290. * @private
  4291. * @function Highcharts.Point#getMarkerVector
  4292. *
  4293. * @param {number} radians
  4294. * The angle in radians from the point center to another vector.
  4295. *
  4296. * @param {number} markerRadius
  4297. * The radius of the marker, to calculate the additional distance to
  4298. * the center of the marker.
  4299. *
  4300. * @param {object} anchor
  4301. * The anchor point of the path and marker as an object with x/y
  4302. * properties.
  4303. *
  4304. * @return {object}
  4305. * The marker vector as an object with x/y properties.
  4306. */
  4307. getMarkerVector: function (radians, markerRadius, anchor) {
  4308. var twoPI = Math.PI * 2.0,
  4309. theta = radians,
  4310. bb = getPointBB(this),
  4311. rectWidth = bb.xMax - bb.xMin,
  4312. rectHeight = bb.yMax - bb.yMin,
  4313. rAtan = Math.atan2(rectHeight,
  4314. rectWidth),
  4315. tanTheta = 1,
  4316. leftOrRightRegion = false,
  4317. rectHalfWidth = rectWidth / 2.0,
  4318. rectHalfHeight = rectHeight / 2.0,
  4319. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  4320. rectVerticalCenter = bb.yMin + rectHalfHeight,
  4321. edgePoint = {
  4322. x: rectHorizontalCenter,
  4323. y: rectVerticalCenter
  4324. },
  4325. markerPoint = {},
  4326. xFactor = 1,
  4327. yFactor = 1;
  4328. while (theta < -Math.PI) {
  4329. theta += twoPI;
  4330. }
  4331. while (theta > Math.PI) {
  4332. theta -= twoPI;
  4333. }
  4334. tanTheta = Math.tan(theta);
  4335. if ((theta > -rAtan) && (theta <= rAtan)) {
  4336. // Right side
  4337. yFactor = -1;
  4338. leftOrRightRegion = true;
  4339. }
  4340. else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  4341. // Top side
  4342. yFactor = -1;
  4343. }
  4344. else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  4345. // Left side
  4346. xFactor = -1;
  4347. leftOrRightRegion = true;
  4348. }
  4349. else {
  4350. // Bottom side
  4351. xFactor = -1;
  4352. }
  4353. // Correct the edgePoint according to the placement of the marker
  4354. if (leftOrRightRegion) {
  4355. edgePoint.x += xFactor * (rectHalfWidth);
  4356. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  4357. }
  4358. else {
  4359. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  4360. edgePoint.y += yFactor * (rectHalfHeight);
  4361. }
  4362. if (anchor.x !== rectHorizontalCenter) {
  4363. edgePoint.x = anchor.x;
  4364. }
  4365. if (anchor.y !== rectVerticalCenter) {
  4366. edgePoint.y = anchor.y;
  4367. }
  4368. markerPoint.x = edgePoint.x + (markerRadius * Math.cos(theta));
  4369. markerPoint.y = edgePoint.y - (markerRadius * Math.sin(theta));
  4370. return markerPoint;
  4371. }
  4372. });
  4373. /**
  4374. * Warn if using legacy options. Copy the options over. Note that this will
  4375. * still break if using the legacy options in chart.update, addSeries etc.
  4376. * @private
  4377. */
  4378. function warnLegacy(chart) {
  4379. if (chart.options.pathfinder ||
  4380. chart.series.reduce(function (acc, series) {
  4381. if (series.options) {
  4382. merge(true, (series.options.connectors = series.options.connectors ||
  4383. {}), series.options.pathfinder);
  4384. }
  4385. return acc || series.options && series.options.pathfinder;
  4386. }, false)) {
  4387. merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
  4388. error('WARNING: Pathfinder options have been renamed. ' +
  4389. 'Use "chart.connectors" or "series.connectors" instead.');
  4390. }
  4391. }
  4392. return Connection;
  4393. });
  4394. _registerModule(_modules, 'Gantt/PathfinderAlgorithms.js', [_modules['Core/Utilities.js']], function (U) {
  4395. /* *
  4396. *
  4397. * (c) 2016 Highsoft AS
  4398. * Author: Øystein Moseng
  4399. *
  4400. * License: www.highcharts.com/license
  4401. *
  4402. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4403. *
  4404. * */
  4405. var extend = U.extend,
  4406. pick = U.pick;
  4407. var min = Math.min,
  4408. max = Math.max,
  4409. abs = Math.abs;
  4410. /**
  4411. * Get index of last obstacle before xMin. Employs a type of binary search, and
  4412. * thus requires that obstacles are sorted by xMin value.
  4413. *
  4414. * @private
  4415. * @function findLastObstacleBefore
  4416. *
  4417. * @param {Array<object>} obstacles
  4418. * Array of obstacles to search in.
  4419. *
  4420. * @param {number} xMin
  4421. * The xMin threshold.
  4422. *
  4423. * @param {number} [startIx]
  4424. * Starting index to search from. Must be within array range.
  4425. *
  4426. * @return {number}
  4427. * The index of the last obstacle element before xMin.
  4428. */
  4429. function findLastObstacleBefore(obstacles, xMin, startIx) {
  4430. var left = startIx || 0, // left limit
  4431. right = obstacles.length - 1, // right limit
  4432. min = xMin - 0.0000001, // Make sure we include all obstacles at xMin
  4433. cursor,
  4434. cmp;
  4435. while (left <= right) {
  4436. cursor = (right + left) >> 1;
  4437. cmp = min - obstacles[cursor].xMin;
  4438. if (cmp > 0) {
  4439. left = cursor + 1;
  4440. }
  4441. else if (cmp < 0) {
  4442. right = cursor - 1;
  4443. }
  4444. else {
  4445. return cursor;
  4446. }
  4447. }
  4448. return left > 0 ? left - 1 : 0;
  4449. }
  4450. /**
  4451. * Test if a point lays within an obstacle.
  4452. *
  4453. * @private
  4454. * @function pointWithinObstacle
  4455. *
  4456. * @param {object} obstacle
  4457. * Obstacle to test.
  4458. *
  4459. * @param {Highcharts.Point} point
  4460. * Point with x/y props.
  4461. *
  4462. * @return {boolean}
  4463. * Whether point is within the obstacle or not.
  4464. */
  4465. function pointWithinObstacle(obstacle, point) {
  4466. return (point.x <= obstacle.xMax &&
  4467. point.x >= obstacle.xMin &&
  4468. point.y <= obstacle.yMax &&
  4469. point.y >= obstacle.yMin);
  4470. }
  4471. /**
  4472. * Find the index of an obstacle that wraps around a point.
  4473. * Returns -1 if not found.
  4474. *
  4475. * @private
  4476. * @function findObstacleFromPoint
  4477. *
  4478. * @param {Array<object>} obstacles
  4479. * Obstacles to test.
  4480. *
  4481. * @param {Highcharts.Point} point
  4482. * Point with x/y props.
  4483. *
  4484. * @return {number}
  4485. * Ix of the obstacle in the array, or -1 if not found.
  4486. */
  4487. function findObstacleFromPoint(obstacles, point) {
  4488. var i = findLastObstacleBefore(obstacles,
  4489. point.x + 1) + 1;
  4490. while (i--) {
  4491. if (obstacles[i].xMax >= point.x &&
  4492. // optimization using lazy evaluation
  4493. pointWithinObstacle(obstacles[i], point)) {
  4494. return i;
  4495. }
  4496. }
  4497. return -1;
  4498. }
  4499. /**
  4500. * Get SVG path array from array of line segments.
  4501. *
  4502. * @private
  4503. * @function pathFromSegments
  4504. *
  4505. * @param {Array<object>} segments
  4506. * The segments to build the path from.
  4507. *
  4508. * @return {Highcharts.SVGPathArray}
  4509. * SVG path array as accepted by the SVG Renderer.
  4510. */
  4511. function pathFromSegments(segments) {
  4512. var path = [];
  4513. if (segments.length) {
  4514. path.push(['M', segments[0].start.x, segments[0].start.y]);
  4515. for (var i = 0; i < segments.length; ++i) {
  4516. path.push(['L', segments[i].end.x, segments[i].end.y]);
  4517. }
  4518. }
  4519. return path;
  4520. }
  4521. /**
  4522. * Limits obstacle max/mins in all directions to bounds. Modifies input
  4523. * obstacle.
  4524. *
  4525. * @private
  4526. * @function limitObstacleToBounds
  4527. *
  4528. * @param {object} obstacle
  4529. * Obstacle to limit.
  4530. *
  4531. * @param {object} bounds
  4532. * Bounds to use as limit.
  4533. *
  4534. * @return {void}
  4535. */
  4536. function limitObstacleToBounds(obstacle, bounds) {
  4537. obstacle.yMin = max(obstacle.yMin, bounds.yMin);
  4538. obstacle.yMax = min(obstacle.yMax, bounds.yMax);
  4539. obstacle.xMin = max(obstacle.xMin, bounds.xMin);
  4540. obstacle.xMax = min(obstacle.xMax, bounds.xMax);
  4541. }
  4542. /**
  4543. * Get an SVG path from a starting coordinate to an ending coordinate.
  4544. * Draws a straight line.
  4545. *
  4546. * @function Highcharts.Pathfinder.algorithms.straight
  4547. *
  4548. * @param {Highcharts.PositionObject} start
  4549. * Starting coordinate, object with x/y props.
  4550. *
  4551. * @param {Highcharts.PositionObject} end
  4552. * Ending coordinate, object with x/y props.
  4553. *
  4554. * @return {object}
  4555. * An object with the SVG path in Array form as accepted by the SVG
  4556. * renderer, as well as an array of new obstacles making up this
  4557. * path.
  4558. */
  4559. function straight(start, end) {
  4560. return {
  4561. path: [
  4562. ['M', start.x, start.y],
  4563. ['L', end.x, end.y]
  4564. ],
  4565. obstacles: [{ start: start, end: end }]
  4566. };
  4567. }
  4568. /**
  4569. * Find a path from a starting coordinate to an ending coordinate, using
  4570. * right angles only, and taking only starting/ending obstacle into
  4571. * consideration.
  4572. *
  4573. * @function Highcharts.Pathfinder.algorithms.simpleConnect
  4574. *
  4575. * @param {Highcharts.PositionObject} start
  4576. * Starting coordinate, object with x/y props.
  4577. *
  4578. * @param {Highcharts.PositionObject} end
  4579. * Ending coordinate, object with x/y props.
  4580. *
  4581. * @param {object} options
  4582. * Options for the algorithm:
  4583. * - chartObstacles: Array of chart obstacles to avoid
  4584. * - startDirectionX: Optional. True if starting in the X direction.
  4585. * If not provided, the algorithm starts in the direction that is
  4586. * the furthest between start/end.
  4587. *
  4588. * @return {object}
  4589. * An object with the SVG path in Array form as accepted by the SVG
  4590. * renderer, as well as an array of new obstacles making up this
  4591. * path.
  4592. */
  4593. var simpleConnect = extend(function (start,
  4594. end,
  4595. options) {
  4596. var segments = [],
  4597. endSegment,
  4598. dir = pick(options.startDirectionX,
  4599. abs(end.x - start.x) > abs(end.y - start.y)) ? 'x' : 'y',
  4600. chartObstacles = options.chartObstacles,
  4601. startObstacleIx = findObstacleFromPoint(chartObstacles,
  4602. start),
  4603. endObstacleIx = findObstacleFromPoint(chartObstacles,
  4604. end),
  4605. startObstacle,
  4606. endObstacle,
  4607. prevWaypoint,
  4608. waypoint,
  4609. waypoint2,
  4610. useMax,
  4611. endPoint;
  4612. // eslint-disable-next-line valid-jsdoc
  4613. /**
  4614. * Return a clone of a point with a property set from a target object,
  4615. * optionally with an offset
  4616. * @private
  4617. */
  4618. function copyFromPoint(from, fromKey, to, toKey, offset) {
  4619. var point = {
  4620. x: from.x,
  4621. y: from.y
  4622. };
  4623. point[fromKey] = to[toKey || fromKey] + (offset || 0);
  4624. return point;
  4625. }
  4626. // eslint-disable-next-line valid-jsdoc
  4627. /**
  4628. * Return waypoint outside obstacle.
  4629. * @private
  4630. */
  4631. function getMeOut(obstacle, point, direction) {
  4632. var useMax = abs(point[direction] - obstacle[direction + 'Min']) >
  4633. abs(point[direction] - obstacle[direction + 'Max']);
  4634. return copyFromPoint(point, direction, obstacle, direction + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1);
  4635. }
  4636. // Pull out end point
  4637. if (endObstacleIx > -1) {
  4638. endObstacle = chartObstacles[endObstacleIx];
  4639. waypoint = getMeOut(endObstacle, end, dir);
  4640. endSegment = {
  4641. start: waypoint,
  4642. end: end
  4643. };
  4644. endPoint = waypoint;
  4645. }
  4646. else {
  4647. endPoint = end;
  4648. }
  4649. // If an obstacle envelops the start point, add a segment to get out,
  4650. // and around it.
  4651. if (startObstacleIx > -1) {
  4652. startObstacle = chartObstacles[startObstacleIx];
  4653. waypoint = getMeOut(startObstacle, start, dir);
  4654. segments.push({
  4655. start: start,
  4656. end: waypoint
  4657. });
  4658. // If we are going back again, switch direction to get around start
  4659. // obstacle.
  4660. if (
  4661. // Going towards max from start:
  4662. waypoint[dir] >= start[dir] ===
  4663. // Going towards min to end:
  4664. waypoint[dir] >= endPoint[dir]) {
  4665. dir = dir === 'y' ? 'x' : 'y';
  4666. useMax = start[dir] < end[dir];
  4667. segments.push({
  4668. start: waypoint,
  4669. end: copyFromPoint(waypoint, dir, startObstacle, dir + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1)
  4670. });
  4671. // Switch direction again
  4672. dir = dir === 'y' ? 'x' : 'y';
  4673. }
  4674. }
  4675. // We are around the start obstacle. Go towards the end in one
  4676. // direction.
  4677. prevWaypoint = segments.length ?
  4678. segments[segments.length - 1].end :
  4679. start;
  4680. waypoint = copyFromPoint(prevWaypoint, dir, endPoint);
  4681. segments.push({
  4682. start: prevWaypoint,
  4683. end: waypoint
  4684. });
  4685. // Final run to end point in the other direction
  4686. dir = dir === 'y' ? 'x' : 'y';
  4687. waypoint2 = copyFromPoint(waypoint, dir, endPoint);
  4688. segments.push({
  4689. start: waypoint,
  4690. end: waypoint2
  4691. });
  4692. // Finally add the endSegment
  4693. segments.push(endSegment);
  4694. return {
  4695. path: pathFromSegments(segments),
  4696. obstacles: segments
  4697. };
  4698. }, {
  4699. requiresObstacles: true
  4700. });
  4701. /**
  4702. * Find a path from a starting coordinate to an ending coordinate, taking
  4703. * obstacles into consideration. Might not always find the optimal path,
  4704. * but is fast, and usually good enough.
  4705. *
  4706. * @function Highcharts.Pathfinder.algorithms.fastAvoid
  4707. *
  4708. * @param {Highcharts.PositionObject} start
  4709. * Starting coordinate, object with x/y props.
  4710. *
  4711. * @param {Highcharts.PositionObject} end
  4712. * Ending coordinate, object with x/y props.
  4713. *
  4714. * @param {object} options
  4715. * Options for the algorithm.
  4716. * - chartObstacles: Array of chart obstacles to avoid
  4717. * - lineObstacles: Array of line obstacles to jump over
  4718. * - obstacleMetrics: Object with metrics of chartObstacles cached
  4719. * - hardBounds: Hard boundaries to not cross
  4720. * - obstacleOptions: Options for the obstacles, including margin
  4721. * - startDirectionX: Optional. True if starting in the X direction.
  4722. * If not provided, the algorithm starts in the
  4723. * direction that is the furthest between
  4724. * start/end.
  4725. *
  4726. * @return {object}
  4727. * An object with the SVG path in Array form as accepted by the SVG
  4728. * renderer, as well as an array of new obstacles making up this
  4729. * path.
  4730. */
  4731. var fastAvoid = extend(function (start,
  4732. end,
  4733. options) {
  4734. /*
  4735. Algorithm rules/description
  4736. - Find initial direction
  4737. - Determine soft/hard max for each direction.
  4738. - Move along initial direction until obstacle.
  4739. - Change direction.
  4740. - If hitting obstacle,
  4741. first try to change length of previous line
  4742. before changing direction again.
  4743. Soft min/max x = start/destination x +/- widest obstacle + margin
  4744. Soft min/max y = start/destination y +/- tallest obstacle + margin
  4745. @todo:
  4746. - Make retrospective,
  4747. try changing prev segment to reduce
  4748. corners
  4749. - Fix logic for breaking out of end-points - not always picking
  4750. the best direction currently
  4751. - When going around the end obstacle we should not always go the
  4752. shortest route,
  4753. rather pick the one closer to the end point
  4754. */
  4755. var dirIsX = pick(options.startDirectionX,
  4756. abs(end.x - start.x) > abs(end.y - start.y)),
  4757. dir = dirIsX ? 'x' : 'y',
  4758. segments,
  4759. useMax,
  4760. extractedEndPoint,
  4761. endSegments = [],
  4762. forceObstacleBreak = false, // Used in clearPathTo to keep track of
  4763. // when to force break through an obstacle.
  4764. // Boundaries to stay within. If beyond soft boundary, prefer to
  4765. // change direction ASAP. If at hard max, always change immediately.
  4766. metrics = options.obstacleMetrics,
  4767. softMinX = min(start.x,
  4768. end.x) - metrics.maxWidth - 10,
  4769. softMaxX = max(start.x,
  4770. end.x) + metrics.maxWidth + 10,
  4771. softMinY = min(start.y,
  4772. end.y) - metrics.maxHeight - 10,
  4773. softMaxY = max(start.y,
  4774. end.y) + metrics.maxHeight + 10,
  4775. // Obstacles
  4776. chartObstacles = options.chartObstacles,
  4777. startObstacleIx = findLastObstacleBefore(chartObstacles,
  4778. softMinX),
  4779. endObstacleIx = findLastObstacleBefore(chartObstacles,
  4780. softMaxX);
  4781. // eslint-disable-next-line valid-jsdoc
  4782. /**
  4783. * How far can you go between two points before hitting an obstacle?
  4784. * Does not work for diagonal lines (because it doesn't have to).
  4785. * @private
  4786. */
  4787. function pivotPoint(fromPoint, toPoint, directionIsX) {
  4788. var firstPoint,
  4789. lastPoint,
  4790. highestPoint,
  4791. lowestPoint,
  4792. i,
  4793. searchDirection = fromPoint.x < toPoint.x ? 1 : -1;
  4794. if (fromPoint.x < toPoint.x) {
  4795. firstPoint = fromPoint;
  4796. lastPoint = toPoint;
  4797. }
  4798. else {
  4799. firstPoint = toPoint;
  4800. lastPoint = fromPoint;
  4801. }
  4802. if (fromPoint.y < toPoint.y) {
  4803. lowestPoint = fromPoint;
  4804. highestPoint = toPoint;
  4805. }
  4806. else {
  4807. lowestPoint = toPoint;
  4808. highestPoint = fromPoint;
  4809. }
  4810. // Go through obstacle range in reverse if toPoint is before
  4811. // fromPoint in the X-dimension.
  4812. i = searchDirection < 0 ?
  4813. // Searching backwards, start at last obstacle before last point
  4814. min(findLastObstacleBefore(chartObstacles, lastPoint.x), chartObstacles.length - 1) :
  4815. // Forwards. Since we're not sorted by xMax, we have to look
  4816. // at all obstacles.
  4817. 0;
  4818. // Go through obstacles in this X range
  4819. while (chartObstacles[i] && (searchDirection > 0 && chartObstacles[i].xMin <= lastPoint.x ||
  4820. searchDirection < 0 && chartObstacles[i].xMax >= firstPoint.x)) {
  4821. // If this obstacle is between from and to points in a straight
  4822. // line, pivot at the intersection.
  4823. if (chartObstacles[i].xMin <= lastPoint.x &&
  4824. chartObstacles[i].xMax >= firstPoint.x &&
  4825. chartObstacles[i].yMin <= highestPoint.y &&
  4826. chartObstacles[i].yMax >= lowestPoint.y) {
  4827. if (directionIsX) {
  4828. return {
  4829. y: fromPoint.y,
  4830. x: fromPoint.x < toPoint.x ?
  4831. chartObstacles[i].xMin - 1 :
  4832. chartObstacles[i].xMax + 1,
  4833. obstacle: chartObstacles[i]
  4834. };
  4835. }
  4836. // else ...
  4837. return {
  4838. x: fromPoint.x,
  4839. y: fromPoint.y < toPoint.y ?
  4840. chartObstacles[i].yMin - 1 :
  4841. chartObstacles[i].yMax + 1,
  4842. obstacle: chartObstacles[i]
  4843. };
  4844. }
  4845. i += searchDirection;
  4846. }
  4847. return toPoint;
  4848. }
  4849. /**
  4850. * Decide in which direction to dodge or get out of an obstacle.
  4851. * Considers desired direction, which way is shortest, soft and hard
  4852. * bounds.
  4853. *
  4854. * (? Returns a string, either xMin, xMax, yMin or yMax.)
  4855. *
  4856. * @private
  4857. * @function
  4858. *
  4859. * @param {object} obstacle
  4860. * Obstacle to dodge/escape.
  4861. *
  4862. * @param {object} fromPoint
  4863. * Point with x/y props that's dodging/escaping.
  4864. *
  4865. * @param {object} toPoint
  4866. * Goal point.
  4867. *
  4868. * @param {boolean} dirIsX
  4869. * Dodge in X dimension.
  4870. *
  4871. * @param {object} bounds
  4872. * Hard and soft boundaries.
  4873. *
  4874. * @return {boolean}
  4875. * Use max or not.
  4876. */
  4877. function getDodgeDirection(obstacle, fromPoint, toPoint, dirIsX, bounds) {
  4878. var softBounds = bounds.soft, hardBounds = bounds.hard, dir = dirIsX ? 'x' : 'y', toPointMax = { x: fromPoint.x, y: fromPoint.y }, toPointMin = { x: fromPoint.x, y: fromPoint.y }, minPivot, maxPivot, maxOutOfSoftBounds = obstacle[dir + 'Max'] >=
  4879. softBounds[dir + 'Max'], minOutOfSoftBounds = obstacle[dir + 'Min'] <=
  4880. softBounds[dir + 'Min'], maxOutOfHardBounds = obstacle[dir + 'Max'] >=
  4881. hardBounds[dir + 'Max'], minOutOfHardBounds = obstacle[dir + 'Min'] <=
  4882. hardBounds[dir + 'Min'],
  4883. // Find out if we should prefer one direction over the other if
  4884. // we can choose freely
  4885. minDistance = abs(obstacle[dir + 'Min'] - fromPoint[dir]), maxDistance = abs(obstacle[dir + 'Max'] - fromPoint[dir]),
  4886. // If it's a small difference, pick the one leading towards dest
  4887. // point. Otherwise pick the shortest distance
  4888. useMax = abs(minDistance - maxDistance) < 10 ?
  4889. fromPoint[dir] < toPoint[dir] :
  4890. maxDistance < minDistance;
  4891. // Check if we hit any obstacles trying to go around in either
  4892. // direction.
  4893. toPointMin[dir] = obstacle[dir + 'Min'];
  4894. toPointMax[dir] = obstacle[dir + 'Max'];
  4895. minPivot = pivotPoint(fromPoint, toPointMin, dirIsX)[dir] !==
  4896. toPointMin[dir];
  4897. maxPivot = pivotPoint(fromPoint, toPointMax, dirIsX)[dir] !==
  4898. toPointMax[dir];
  4899. useMax = minPivot ?
  4900. (maxPivot ? useMax : true) :
  4901. (maxPivot ? false : useMax);
  4902. // useMax now contains our preferred choice, bounds not taken into
  4903. // account. If both or neither direction is out of bounds we want to
  4904. // use this.
  4905. // Deal with soft bounds
  4906. useMax = minOutOfSoftBounds ?
  4907. (maxOutOfSoftBounds ? useMax : true) : // Out on min
  4908. (maxOutOfSoftBounds ? false : useMax); // Not out on min
  4909. // Deal with hard bounds
  4910. useMax = minOutOfHardBounds ?
  4911. (maxOutOfHardBounds ? useMax : true) : // Out on min
  4912. (maxOutOfHardBounds ? false : useMax); // Not out on min
  4913. return useMax;
  4914. }
  4915. // eslint-disable-next-line valid-jsdoc
  4916. /**
  4917. * Find a clear path between point.
  4918. * @private
  4919. */
  4920. function clearPathTo(fromPoint, toPoint, dirIsX) {
  4921. // Don't waste time if we've hit goal
  4922. if (fromPoint.x === toPoint.x && fromPoint.y === toPoint.y) {
  4923. return [];
  4924. }
  4925. var dir = dirIsX ? 'x' : 'y',
  4926. pivot,
  4927. segments,
  4928. waypoint,
  4929. waypointUseMax,
  4930. envelopingObstacle,
  4931. secondEnvelopingObstacle,
  4932. envelopWaypoint,
  4933. obstacleMargin = options.obstacleOptions.margin,
  4934. bounds = {
  4935. soft: {
  4936. xMin: softMinX,
  4937. xMax: softMaxX,
  4938. yMin: softMinY,
  4939. yMax: softMaxY
  4940. },
  4941. hard: options.hardBounds
  4942. };
  4943. // If fromPoint is inside an obstacle we have a problem. Break out
  4944. // by just going to the outside of this obstacle. We prefer to go to
  4945. // the nearest edge in the chosen direction.
  4946. envelopingObstacle =
  4947. findObstacleFromPoint(chartObstacles, fromPoint);
  4948. if (envelopingObstacle > -1) {
  4949. envelopingObstacle = chartObstacles[envelopingObstacle];
  4950. waypointUseMax = getDodgeDirection(envelopingObstacle, fromPoint, toPoint, dirIsX, bounds);
  4951. // Cut obstacle to hard bounds to make sure we stay within
  4952. limitObstacleToBounds(envelopingObstacle, options.hardBounds);
  4953. envelopWaypoint = dirIsX ? {
  4954. y: fromPoint.y,
  4955. x: envelopingObstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  4956. (waypointUseMax ? 1 : -1)
  4957. } : {
  4958. x: fromPoint.x,
  4959. y: envelopingObstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  4960. (waypointUseMax ? 1 : -1)
  4961. };
  4962. // If we crashed into another obstacle doing this, we put the
  4963. // waypoint between them instead
  4964. secondEnvelopingObstacle = findObstacleFromPoint(chartObstacles, envelopWaypoint);
  4965. if (secondEnvelopingObstacle > -1) {
  4966. secondEnvelopingObstacle = chartObstacles[secondEnvelopingObstacle];
  4967. // Cut obstacle to hard bounds
  4968. limitObstacleToBounds(secondEnvelopingObstacle, options.hardBounds);
  4969. // Modify waypoint to lay between obstacles
  4970. envelopWaypoint[dir] = waypointUseMax ? max(envelopingObstacle[dir + 'Max'] - obstacleMargin + 1, (secondEnvelopingObstacle[dir + 'Min'] +
  4971. envelopingObstacle[dir + 'Max']) / 2) :
  4972. min((envelopingObstacle[dir + 'Min'] + obstacleMargin - 1), ((secondEnvelopingObstacle[dir + 'Max'] +
  4973. envelopingObstacle[dir + 'Min']) / 2));
  4974. // We are not going anywhere. If this happens for the first
  4975. // time, do nothing. Otherwise, try to go to the extreme of
  4976. // the obstacle pair in the current direction.
  4977. if (fromPoint.x === envelopWaypoint.x &&
  4978. fromPoint.y === envelopWaypoint.y) {
  4979. if (forceObstacleBreak) {
  4980. envelopWaypoint[dir] = waypointUseMax ?
  4981. max(envelopingObstacle[dir + 'Max'], secondEnvelopingObstacle[dir + 'Max']) + 1 :
  4982. min(envelopingObstacle[dir + 'Min'], secondEnvelopingObstacle[dir + 'Min']) - 1;
  4983. }
  4984. // Toggle on if off, and the opposite
  4985. forceObstacleBreak = !forceObstacleBreak;
  4986. }
  4987. else {
  4988. // This point is not identical to previous.
  4989. // Clear break trigger.
  4990. forceObstacleBreak = false;
  4991. }
  4992. }
  4993. segments = [{
  4994. start: fromPoint,
  4995. end: envelopWaypoint
  4996. }];
  4997. }
  4998. else { // If not enveloping, use standard pivot calculation
  4999. pivot = pivotPoint(fromPoint, {
  5000. x: dirIsX ? toPoint.x : fromPoint.x,
  5001. y: dirIsX ? fromPoint.y : toPoint.y
  5002. }, dirIsX);
  5003. segments = [{
  5004. start: fromPoint,
  5005. end: {
  5006. x: pivot.x,
  5007. y: pivot.y
  5008. }
  5009. }];
  5010. // Pivot before goal, use a waypoint to dodge obstacle
  5011. if (pivot[dirIsX ? 'x' : 'y'] !== toPoint[dirIsX ? 'x' : 'y']) {
  5012. // Find direction of waypoint
  5013. waypointUseMax = getDodgeDirection(pivot.obstacle, pivot, toPoint, !dirIsX, bounds);
  5014. // Cut waypoint to hard bounds
  5015. limitObstacleToBounds(pivot.obstacle, options.hardBounds);
  5016. waypoint = {
  5017. x: dirIsX ?
  5018. pivot.x :
  5019. pivot.obstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  5020. (waypointUseMax ? 1 : -1),
  5021. y: dirIsX ?
  5022. pivot.obstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  5023. (waypointUseMax ? 1 : -1) :
  5024. pivot.y
  5025. };
  5026. // We're changing direction here, store that to make sure we
  5027. // also change direction when adding the last segment array
  5028. // after handling waypoint.
  5029. dirIsX = !dirIsX;
  5030. segments = segments.concat(clearPathTo({
  5031. x: pivot.x,
  5032. y: pivot.y
  5033. }, waypoint, dirIsX));
  5034. }
  5035. }
  5036. // Get segments for the other direction too
  5037. // Recursion is our friend
  5038. segments = segments.concat(clearPathTo(segments[segments.length - 1].end, toPoint, !dirIsX));
  5039. return segments;
  5040. }
  5041. // eslint-disable-next-line valid-jsdoc
  5042. /**
  5043. * Extract point to outside of obstacle in whichever direction is
  5044. * closest. Returns new point outside obstacle.
  5045. * @private
  5046. */
  5047. function extractFromObstacle(obstacle, point, goalPoint) {
  5048. var dirIsX = min(obstacle.xMax - point.x,
  5049. point.x - obstacle.xMin) <
  5050. min(obstacle.yMax - point.y,
  5051. point.y - obstacle.yMin),
  5052. bounds = {
  5053. soft: options.hardBounds,
  5054. hard: options.hardBounds
  5055. },
  5056. useMax = getDodgeDirection(obstacle,
  5057. point,
  5058. goalPoint,
  5059. dirIsX,
  5060. bounds);
  5061. return dirIsX ? {
  5062. y: point.y,
  5063. x: obstacle[useMax ? 'xMax' : 'xMin'] + (useMax ? 1 : -1)
  5064. } : {
  5065. x: point.x,
  5066. y: obstacle[useMax ? 'yMax' : 'yMin'] + (useMax ? 1 : -1)
  5067. };
  5068. }
  5069. // Cut the obstacle array to soft bounds for optimization in large
  5070. // datasets.
  5071. chartObstacles =
  5072. chartObstacles.slice(startObstacleIx, endObstacleIx + 1);
  5073. // If an obstacle envelops the end point, move it out of there and add
  5074. // a little segment to where it was.
  5075. if ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  5076. extractedEndPoint = extractFromObstacle(chartObstacles[endObstacleIx], end, start);
  5077. endSegments.push({
  5078. end: end,
  5079. start: extractedEndPoint
  5080. });
  5081. end = extractedEndPoint;
  5082. }
  5083. // If it's still inside one or more obstacles, get out of there by
  5084. // force-moving towards the start point.
  5085. while ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  5086. useMax = end[dir] - start[dir] < 0;
  5087. extractedEndPoint = {
  5088. x: end.x,
  5089. y: end.y
  5090. };
  5091. extractedEndPoint[dir] = chartObstacles[endObstacleIx][useMax ? dir + 'Max' : dir + 'Min'] + (useMax ? 1 : -1);
  5092. endSegments.push({
  5093. end: end,
  5094. start: extractedEndPoint
  5095. });
  5096. end = extractedEndPoint;
  5097. }
  5098. // Find the path
  5099. segments = clearPathTo(start, end, dirIsX);
  5100. // Add the end-point segments
  5101. segments = segments.concat(endSegments.reverse());
  5102. return {
  5103. path: pathFromSegments(segments),
  5104. obstacles: segments
  5105. };
  5106. }, {
  5107. requiresObstacles: true
  5108. });
  5109. // Define the available pathfinding algorithms.
  5110. // Algorithms take up to 3 arguments: starting point, ending point, and an
  5111. // options object.
  5112. var algorithms = {
  5113. fastAvoid: fastAvoid,
  5114. straight: straight,
  5115. simpleConnect: simpleConnect
  5116. };
  5117. return algorithms;
  5118. });
  5119. _registerModule(_modules, 'Gantt/Pathfinder.js', [_modules['Gantt/Connection.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js'], _modules['Gantt/PathfinderAlgorithms.js']], function (Connection, Chart, H, O, Point, U, pathfinderAlgorithms) {
  5120. /* *
  5121. *
  5122. * (c) 2016 Highsoft AS
  5123. * Authors: Øystein Moseng, Lars A. V. Cabrera
  5124. *
  5125. * License: www.highcharts.com/license
  5126. *
  5127. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5128. *
  5129. * */
  5130. /**
  5131. * The default pathfinder algorithm to use for a chart. It is possible to define
  5132. * your own algorithms by adding them to the
  5133. * `Highcharts.Pathfinder.prototype.algorithms`
  5134. * object before the chart has been created.
  5135. *
  5136. * The default algorithms are as follows:
  5137. *
  5138. * `straight`: Draws a straight line between the connecting
  5139. * points. Does not avoid other points when drawing.
  5140. *
  5141. * `simpleConnect`: Finds a path between the points using right angles
  5142. * only. Takes only starting/ending points into
  5143. * account, and will not avoid other points.
  5144. *
  5145. * `fastAvoid`: Finds a path between the points using right angles
  5146. * only. Will attempt to avoid other points, but its
  5147. * focus is performance over accuracy. Works well with
  5148. * less dense datasets.
  5149. *
  5150. * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
  5151. */
  5152. ''; // detach doclets above
  5153. var defaultOptions = O.defaultOptions;
  5154. var addEvent = U.addEvent,
  5155. defined = U.defined,
  5156. error = U.error,
  5157. extend = U.extend,
  5158. merge = U.merge,
  5159. objectEach = U.objectEach,
  5160. pick = U.pick,
  5161. splat = U.splat;
  5162. var deg2rad = H.deg2rad,
  5163. max = Math.max,
  5164. min = Math.min;
  5165. /*
  5166. @todo:
  5167. - Document how to write your own algorithms
  5168. - Consider adding a Point.pathTo method that wraps creating a connection
  5169. and rendering it
  5170. */
  5171. // Set default Pathfinder options
  5172. extend(defaultOptions, {
  5173. /**
  5174. * The Pathfinder module allows you to define connections between any two
  5175. * points, represented as lines - optionally with markers for the start
  5176. * and/or end points. Multiple algorithms are available for calculating how
  5177. * the connecting lines are drawn.
  5178. *
  5179. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  5180. * charts, the connectors are used to draw dependencies between tasks.
  5181. *
  5182. * @see [dependency](series.gantt.data.dependency)
  5183. *
  5184. * @sample gantt/pathfinder/demo
  5185. * Pathfinder connections
  5186. *
  5187. * @declare Highcharts.ConnectorsOptions
  5188. * @product gantt
  5189. * @optionparent connectors
  5190. */
  5191. connectors: {
  5192. /**
  5193. * Enable connectors for this chart. Requires Highcharts Gantt.
  5194. *
  5195. * @type {boolean}
  5196. * @default true
  5197. * @since 6.2.0
  5198. * @apioption connectors.enabled
  5199. */
  5200. /**
  5201. * Set the default dash style for this chart's connecting lines.
  5202. *
  5203. * @type {string}
  5204. * @default solid
  5205. * @since 6.2.0
  5206. * @apioption connectors.dashStyle
  5207. */
  5208. /**
  5209. * Set the default color for this chart's Pathfinder connecting lines.
  5210. * Defaults to the color of the point being connected.
  5211. *
  5212. * @type {Highcharts.ColorString}
  5213. * @since 6.2.0
  5214. * @apioption connectors.lineColor
  5215. */
  5216. /**
  5217. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  5218. * algorithms attempt to avoid obstacles, such as other points in the
  5219. * chart. These algorithms use this margin to determine how close lines
  5220. * can be to an obstacle. The default is to compute this automatically
  5221. * from the size of the obstacles in the chart.
  5222. *
  5223. * To draw connecting lines close to existing points, set this to a low
  5224. * number. For more space around existing points, set this number
  5225. * higher.
  5226. *
  5227. * @sample gantt/pathfinder/algorithm-margin
  5228. * Small algorithmMargin
  5229. *
  5230. * @type {number}
  5231. * @since 6.2.0
  5232. * @apioption connectors.algorithmMargin
  5233. */
  5234. /**
  5235. * Set the default pathfinder algorithm to use for this chart. It is
  5236. * possible to define your own algorithms by adding them to the
  5237. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  5238. * has been created.
  5239. *
  5240. * The default algorithms are as follows:
  5241. *
  5242. * `straight`: Draws a straight line between the connecting
  5243. * points. Does not avoid other points when drawing.
  5244. *
  5245. * `simpleConnect`: Finds a path between the points using right angles
  5246. * only. Takes only starting/ending points into
  5247. * account, and will not avoid other points.
  5248. *
  5249. * `fastAvoid`: Finds a path between the points using right angles
  5250. * only. Will attempt to avoid other points, but its
  5251. * focus is performance over accuracy. Works well with
  5252. * less dense datasets.
  5253. *
  5254. * Default value: `straight` is used as default for most series types,
  5255. * while `simpleConnect` is used as default for Gantt series, to show
  5256. * dependencies between points.
  5257. *
  5258. * @sample gantt/pathfinder/demo
  5259. * Different types used
  5260. *
  5261. * @type {Highcharts.PathfinderTypeValue}
  5262. * @default undefined
  5263. * @since 6.2.0
  5264. */
  5265. type: 'straight',
  5266. /**
  5267. * Set the default pixel width for this chart's Pathfinder connecting
  5268. * lines.
  5269. *
  5270. * @since 6.2.0
  5271. */
  5272. lineWidth: 1,
  5273. /**
  5274. * Marker options for this chart's Pathfinder connectors. Note that
  5275. * this option is overridden by the `startMarker` and `endMarker`
  5276. * options.
  5277. *
  5278. * @declare Highcharts.ConnectorsMarkerOptions
  5279. * @since 6.2.0
  5280. */
  5281. marker: {
  5282. /**
  5283. * Set the radius of the connector markers. The default is
  5284. * automatically computed based on the algorithmMargin setting.
  5285. *
  5286. * Setting marker.width and marker.height will override this
  5287. * setting.
  5288. *
  5289. * @type {number}
  5290. * @since 6.2.0
  5291. * @apioption connectors.marker.radius
  5292. */
  5293. /**
  5294. * Set the width of the connector markers. If not supplied, this
  5295. * is inferred from the marker radius.
  5296. *
  5297. * @type {number}
  5298. * @since 6.2.0
  5299. * @apioption connectors.marker.width
  5300. */
  5301. /**
  5302. * Set the height of the connector markers. If not supplied, this
  5303. * is inferred from the marker radius.
  5304. *
  5305. * @type {number}
  5306. * @since 6.2.0
  5307. * @apioption connectors.marker.height
  5308. */
  5309. /**
  5310. * Set the color of the connector markers. By default this is the
  5311. * same as the connector color.
  5312. *
  5313. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5314. * @since 6.2.0
  5315. * @apioption connectors.marker.color
  5316. */
  5317. /**
  5318. * Set the line/border color of the connector markers. By default
  5319. * this is the same as the marker color.
  5320. *
  5321. * @type {Highcharts.ColorString}
  5322. * @since 6.2.0
  5323. * @apioption connectors.marker.lineColor
  5324. */
  5325. /**
  5326. * Enable markers for the connectors.
  5327. */
  5328. enabled: false,
  5329. /**
  5330. * Horizontal alignment of the markers relative to the points.
  5331. *
  5332. * @type {Highcharts.AlignValue}
  5333. */
  5334. align: 'center',
  5335. /**
  5336. * Vertical alignment of the markers relative to the points.
  5337. *
  5338. * @type {Highcharts.VerticalAlignValue}
  5339. */
  5340. verticalAlign: 'middle',
  5341. /**
  5342. * Whether or not to draw the markers inside the points.
  5343. */
  5344. inside: false,
  5345. /**
  5346. * Set the line/border width of the pathfinder markers.
  5347. */
  5348. lineWidth: 1
  5349. },
  5350. /**
  5351. * Marker options specific to the start markers for this chart's
  5352. * Pathfinder connectors. Overrides the generic marker options.
  5353. *
  5354. * @declare Highcharts.ConnectorsStartMarkerOptions
  5355. * @extends connectors.marker
  5356. * @since 6.2.0
  5357. */
  5358. startMarker: {
  5359. /**
  5360. * Set the symbol of the connector start markers.
  5361. */
  5362. symbol: 'diamond'
  5363. },
  5364. /**
  5365. * Marker options specific to the end markers for this chart's
  5366. * Pathfinder connectors. Overrides the generic marker options.
  5367. *
  5368. * @declare Highcharts.ConnectorsEndMarkerOptions
  5369. * @extends connectors.marker
  5370. * @since 6.2.0
  5371. */
  5372. endMarker: {
  5373. /**
  5374. * Set the symbol of the connector end markers.
  5375. */
  5376. symbol: 'arrow-filled'
  5377. }
  5378. }
  5379. });
  5380. /**
  5381. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  5382. * to be loaded.
  5383. *
  5384. * @declare Highcharts.SeriesConnectorsOptionsObject
  5385. * @extends connectors
  5386. * @since 6.2.0
  5387. * @excluding enabled, algorithmMargin
  5388. * @product gantt
  5389. * @apioption plotOptions.series.connectors
  5390. */
  5391. /**
  5392. * Connect to a point. This option can be either a string, referring to the ID
  5393. * of another point, or an object, or an array of either. If the option is an
  5394. * array, each element defines a connection.
  5395. *
  5396. * @sample gantt/pathfinder/demo
  5397. * Different connection types
  5398. *
  5399. * @declare Highcharts.XrangePointConnectorsOptionsObject
  5400. * @type {string|Array<string|*>|*}
  5401. * @extends plotOptions.series.connectors
  5402. * @since 6.2.0
  5403. * @excluding enabled
  5404. * @product gantt
  5405. * @requires highcharts-gantt
  5406. * @apioption series.xrange.data.connect
  5407. */
  5408. /**
  5409. * The ID of the point to connect to.
  5410. *
  5411. * @type {string}
  5412. * @since 6.2.0
  5413. * @product gantt
  5414. * @apioption series.xrange.data.connect.to
  5415. */
  5416. /**
  5417. * Get point bounding box using plotX/plotY and shapeArgs. If using
  5418. * graphic.getBBox() directly, the bbox will be affected by animation.
  5419. *
  5420. * @private
  5421. * @function
  5422. *
  5423. * @param {Highcharts.Point} point
  5424. * The point to get BB of.
  5425. *
  5426. * @return {Highcharts.Dictionary<number>|null}
  5427. * Result xMax, xMin, yMax, yMin.
  5428. */
  5429. function getPointBB(point) {
  5430. var shapeArgs = point.shapeArgs,
  5431. bb;
  5432. // Prefer using shapeArgs (columns)
  5433. if (shapeArgs) {
  5434. return {
  5435. xMin: shapeArgs.x,
  5436. xMax: shapeArgs.x + shapeArgs.width,
  5437. yMin: shapeArgs.y,
  5438. yMax: shapeArgs.y + shapeArgs.height
  5439. };
  5440. }
  5441. // Otherwise use plotX/plotY and bb
  5442. bb = point.graphic && point.graphic.getBBox();
  5443. return bb ? {
  5444. xMin: point.plotX - bb.width / 2,
  5445. xMax: point.plotX + bb.width / 2,
  5446. yMin: point.plotY - bb.height / 2,
  5447. yMax: point.plotY + bb.height / 2
  5448. } : null;
  5449. }
  5450. /**
  5451. * Calculate margin to place around obstacles for the pathfinder in pixels.
  5452. * Returns a minimum of 1 pixel margin.
  5453. *
  5454. * @private
  5455. * @function
  5456. *
  5457. * @param {Array<object>} obstacles
  5458. * Obstacles to calculate margin from.
  5459. *
  5460. * @return {number}
  5461. * The calculated margin in pixels. At least 1.
  5462. */
  5463. function calculateObstacleMargin(obstacles) {
  5464. var len = obstacles.length,
  5465. i = 0,
  5466. j,
  5467. obstacleDistance,
  5468. distances = [],
  5469. // Compute smallest distance between two rectangles
  5470. distance = function (a,
  5471. b,
  5472. bbMargin) {
  5473. // Count the distance even if we are slightly off
  5474. var margin = pick(bbMargin, 10),
  5475. yOverlap = a.yMax + margin > b.yMin - margin &&
  5476. a.yMin - margin < b.yMax + margin,
  5477. xOverlap = a.xMax + margin > b.xMin - margin &&
  5478. a.xMin - margin < b.xMax + margin,
  5479. xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
  5480. yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
  5481. // If the rectangles collide, try recomputing with smaller margin.
  5482. // If they collide anyway, discard the obstacle.
  5483. if (xOverlap && yOverlap) {
  5484. return (margin ?
  5485. distance(a, b, Math.floor(margin / 2)) :
  5486. Infinity);
  5487. }
  5488. return min(xDistance, yDistance);
  5489. };
  5490. // Go over all obstacles and compare them to the others.
  5491. for (; i < len; ++i) {
  5492. // Compare to all obstacles ahead. We will already have compared this
  5493. // obstacle to the ones before.
  5494. for (j = i + 1; j < len; ++j) {
  5495. obstacleDistance = distance(obstacles[i], obstacles[j]);
  5496. // TODO: Magic number 80
  5497. if (obstacleDistance < 80) { // Ignore large distances
  5498. distances.push(obstacleDistance);
  5499. }
  5500. }
  5501. }
  5502. // Ensure we always have at least one value, even in very spaceous charts
  5503. distances.push(80);
  5504. return max(Math.floor(distances.sort(function (a, b) {
  5505. return (a - b);
  5506. })[
  5507. // Discard first 10% of the relevant distances, and then grab
  5508. // the smallest one.
  5509. Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
  5510. ), 1 // 1 is the minimum margin
  5511. );
  5512. }
  5513. /* eslint-disable no-invalid-this, valid-jsdoc */
  5514. /**
  5515. * The Pathfinder class.
  5516. *
  5517. * @private
  5518. * @class
  5519. * @name Highcharts.Pathfinder
  5520. *
  5521. * @param {Highcharts.Chart} chart
  5522. * The chart to operate on.
  5523. */
  5524. var Pathfinder = /** @class */ (function () {
  5525. function Pathfinder(chart) {
  5526. /* *
  5527. *
  5528. * Properties
  5529. *
  5530. * */
  5531. this.chart = void 0;
  5532. this.chartObstacles = void 0;
  5533. this.chartObstacleMetrics = void 0;
  5534. this.connections = void 0;
  5535. this.group = void 0;
  5536. this.lineObstacles = void 0;
  5537. this.init(chart);
  5538. }
  5539. /**
  5540. * @name Highcharts.Pathfinder#algorithms
  5541. * @type {Highcharts.Dictionary<Function>}
  5542. */
  5543. /**
  5544. * Initialize the Pathfinder object.
  5545. *
  5546. * @function Highcharts.Pathfinder#init
  5547. *
  5548. * @param {Highcharts.Chart} chart
  5549. * The chart context.
  5550. */
  5551. Pathfinder.prototype.init = function (chart) {
  5552. // Initialize pathfinder with chart context
  5553. this.chart = chart;
  5554. // Init connection reference list
  5555. this.connections = [];
  5556. // Recalculate paths/obstacles on chart redraw
  5557. addEvent(chart, 'redraw', function () {
  5558. this.pathfinder.update();
  5559. });
  5560. };
  5561. /**
  5562. * Update Pathfinder connections from scratch.
  5563. *
  5564. * @function Highcharts.Pathfinder#update
  5565. *
  5566. * @param {boolean} [deferRender]
  5567. * Whether or not to defer rendering of connections until
  5568. * series.afterAnimate event has fired. Used on first render.
  5569. */
  5570. Pathfinder.prototype.update = function (deferRender) {
  5571. var chart = this.chart,
  5572. pathfinder = this,
  5573. oldConnections = pathfinder.connections;
  5574. // Rebuild pathfinder connections from options
  5575. pathfinder.connections = [];
  5576. chart.series.forEach(function (series) {
  5577. if (series.visible && !series.options.isInternal) {
  5578. series.points.forEach(function (point) {
  5579. var ganttPointOptions = point.options;
  5580. // For Gantt series the connect could be
  5581. // defined as a dependency
  5582. if (ganttPointOptions && ganttPointOptions.dependency) {
  5583. ganttPointOptions.connect = ganttPointOptions.dependency;
  5584. }
  5585. var to,
  5586. connects = (point.options &&
  5587. point.options.connect &&
  5588. splat(point.options.connect));
  5589. if (point.visible && point.isInside !== false && connects) {
  5590. connects.forEach(function (connect) {
  5591. to = chart.get(typeof connect === 'string' ?
  5592. connect : connect.to);
  5593. if (to instanceof Point &&
  5594. to.series.visible &&
  5595. to.visible &&
  5596. to.isInside !== false) {
  5597. // Add new connection
  5598. pathfinder.connections.push(new Connection(point, // from
  5599. to, typeof connect === 'string' ?
  5600. {} :
  5601. connect));
  5602. }
  5603. });
  5604. }
  5605. });
  5606. }
  5607. });
  5608. // Clear connections that should not be updated, and move old info over
  5609. // to new connections.
  5610. for (var j = 0, k, found, lenOld = oldConnections.length, lenNew = pathfinder.connections.length; j < lenOld; ++j) {
  5611. found = false;
  5612. for (k = 0; k < lenNew; ++k) {
  5613. if (oldConnections[j].fromPoint ===
  5614. pathfinder.connections[k].fromPoint &&
  5615. oldConnections[j].toPoint ===
  5616. pathfinder.connections[k].toPoint) {
  5617. pathfinder.connections[k].graphics =
  5618. oldConnections[j].graphics;
  5619. found = true;
  5620. break;
  5621. }
  5622. }
  5623. if (!found) {
  5624. oldConnections[j].destroy();
  5625. }
  5626. }
  5627. // Clear obstacles to force recalculation. This must be done on every
  5628. // redraw in case positions have changed. Recalculation is handled in
  5629. // Connection.getPath on demand.
  5630. delete this.chartObstacles;
  5631. delete this.lineObstacles;
  5632. // Draw the pending connections
  5633. pathfinder.renderConnections(deferRender);
  5634. };
  5635. /**
  5636. * Draw the chart's connecting paths.
  5637. *
  5638. * @function Highcharts.Pathfinder#renderConnections
  5639. *
  5640. * @param {boolean} [deferRender]
  5641. * Whether or not to defer render until series animation is finished.
  5642. * Used on first render.
  5643. */
  5644. Pathfinder.prototype.renderConnections = function (deferRender) {
  5645. if (deferRender) {
  5646. // Render after series are done animating
  5647. this.chart.series.forEach(function (series) {
  5648. var render = function () {
  5649. // Find pathfinder connections belonging to this series
  5650. // that haven't rendered, and render them now.
  5651. var pathfinder = series.chart.pathfinder,
  5652. conns = pathfinder && pathfinder.connections || [];
  5653. conns.forEach(function (connection) {
  5654. if (connection.fromPoint &&
  5655. connection.fromPoint.series === series) {
  5656. connection.render();
  5657. }
  5658. });
  5659. if (series.pathfinderRemoveRenderEvent) {
  5660. series.pathfinderRemoveRenderEvent();
  5661. delete series.pathfinderRemoveRenderEvent;
  5662. }
  5663. };
  5664. if (series.options.animation === false) {
  5665. render();
  5666. }
  5667. else {
  5668. series.pathfinderRemoveRenderEvent = addEvent(series, 'afterAnimate', render);
  5669. }
  5670. });
  5671. }
  5672. else {
  5673. // Go through connections and render them
  5674. this.connections.forEach(function (connection) {
  5675. connection.render();
  5676. });
  5677. }
  5678. };
  5679. /**
  5680. * Get obstacles for the points in the chart. Does not include connecting
  5681. * lines from Pathfinder. Applies algorithmMargin to the obstacles.
  5682. *
  5683. * @function Highcharts.Pathfinder#getChartObstacles
  5684. *
  5685. * @param {object} options
  5686. * Options for the calculation. Currenlty only
  5687. * options.algorithmMargin.
  5688. *
  5689. * @return {Array<object>}
  5690. * An array of calculated obstacles. Each obstacle is defined as an
  5691. * object with xMin, xMax, yMin and yMax properties.
  5692. */
  5693. Pathfinder.prototype.getChartObstacles = function (options) {
  5694. var obstacles = [],
  5695. series = this.chart.series,
  5696. margin = pick(options.algorithmMargin, 0),
  5697. calculatedMargin;
  5698. for (var i = 0, sLen = series.length; i < sLen; ++i) {
  5699. if (series[i].visible && !series[i].options.isInternal) {
  5700. for (var j = 0, pLen = series[i].points.length, bb, point; j < pLen; ++j) {
  5701. point = series[i].points[j];
  5702. if (point.visible) {
  5703. bb = getPointBB(point);
  5704. if (bb) {
  5705. obstacles.push({
  5706. xMin: bb.xMin - margin,
  5707. xMax: bb.xMax + margin,
  5708. yMin: bb.yMin - margin,
  5709. yMax: bb.yMax + margin
  5710. });
  5711. }
  5712. }
  5713. }
  5714. }
  5715. }
  5716. // Sort obstacles by xMin for optimization
  5717. obstacles = obstacles.sort(function (a, b) {
  5718. return a.xMin - b.xMin;
  5719. });
  5720. // Add auto-calculated margin if the option is not defined
  5721. if (!defined(options.algorithmMargin)) {
  5722. calculatedMargin =
  5723. options.algorithmMargin =
  5724. calculateObstacleMargin(obstacles);
  5725. obstacles.forEach(function (obstacle) {
  5726. obstacle.xMin -= calculatedMargin;
  5727. obstacle.xMax += calculatedMargin;
  5728. obstacle.yMin -= calculatedMargin;
  5729. obstacle.yMax += calculatedMargin;
  5730. });
  5731. }
  5732. return obstacles;
  5733. };
  5734. /**
  5735. * Utility function to get metrics for obstacles:
  5736. * - Widest obstacle width
  5737. * - Tallest obstacle height
  5738. *
  5739. * @function Highcharts.Pathfinder#getObstacleMetrics
  5740. *
  5741. * @param {Array<object>} obstacles
  5742. * An array of obstacles to inspect.
  5743. *
  5744. * @return {object}
  5745. * The calculated metrics, as an object with maxHeight and maxWidth
  5746. * properties.
  5747. */
  5748. Pathfinder.prototype.getObstacleMetrics = function (obstacles) {
  5749. var maxWidth = 0,
  5750. maxHeight = 0,
  5751. width,
  5752. height,
  5753. i = obstacles.length;
  5754. while (i--) {
  5755. width = obstacles[i].xMax - obstacles[i].xMin;
  5756. height = obstacles[i].yMax - obstacles[i].yMin;
  5757. if (maxWidth < width) {
  5758. maxWidth = width;
  5759. }
  5760. if (maxHeight < height) {
  5761. maxHeight = height;
  5762. }
  5763. }
  5764. return {
  5765. maxHeight: maxHeight,
  5766. maxWidth: maxWidth
  5767. };
  5768. };
  5769. /**
  5770. * Utility to get which direction to start the pathfinding algorithm
  5771. * (X vs Y), calculated from a set of marker options.
  5772. *
  5773. * @function Highcharts.Pathfinder#getAlgorithmStartDirection
  5774. *
  5775. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  5776. * Marker options to calculate from.
  5777. *
  5778. * @return {boolean}
  5779. * Returns true for X, false for Y, and undefined for autocalculate.
  5780. */
  5781. Pathfinder.prototype.getAlgorithmStartDirection = function (markerOptions) {
  5782. var xCenter = markerOptions.align !== 'left' &&
  5783. markerOptions.align !== 'right', yCenter = markerOptions.verticalAlign !== 'top' &&
  5784. markerOptions.verticalAlign !== 'bottom', undef;
  5785. return xCenter ?
  5786. (yCenter ? undef : false) : // x is centered
  5787. (yCenter ? true : undef); // x is off-center
  5788. };
  5789. return Pathfinder;
  5790. }());
  5791. Pathfinder.prototype.algorithms = pathfinderAlgorithms;
  5792. // Add to Highcharts namespace
  5793. H.Pathfinder = Pathfinder;
  5794. // Add pathfinding capabilities to Points
  5795. extend(Point.prototype, /** @lends Point.prototype */ {
  5796. /**
  5797. * Get coordinates of anchor point for pathfinder connection.
  5798. *
  5799. * @private
  5800. * @function Highcharts.Point#getPathfinderAnchorPoint
  5801. *
  5802. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  5803. * Connection options for position on point.
  5804. *
  5805. * @return {Highcharts.PositionObject}
  5806. * An object with x/y properties for the position. Coordinates are
  5807. * in plot values, not relative to point.
  5808. */
  5809. getPathfinderAnchorPoint: function (markerOptions) {
  5810. var bb = getPointBB(this),
  5811. x,
  5812. y;
  5813. switch (markerOptions.align) { // eslint-disable-line default-case
  5814. case 'right':
  5815. x = 'xMax';
  5816. break;
  5817. case 'left':
  5818. x = 'xMin';
  5819. }
  5820. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  5821. case 'top':
  5822. y = 'yMin';
  5823. break;
  5824. case 'bottom':
  5825. y = 'yMax';
  5826. }
  5827. return {
  5828. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  5829. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  5830. };
  5831. },
  5832. /**
  5833. * Utility to get the angle from one point to another.
  5834. *
  5835. * @private
  5836. * @function Highcharts.Point#getRadiansToVector
  5837. *
  5838. * @param {Highcharts.PositionObject} v1
  5839. * The first vector, as an object with x/y properties.
  5840. *
  5841. * @param {Highcharts.PositionObject} v2
  5842. * The second vector, as an object with x/y properties.
  5843. *
  5844. * @return {number}
  5845. * The angle in degrees
  5846. */
  5847. getRadiansToVector: function (v1, v2) {
  5848. var box;
  5849. if (!defined(v2)) {
  5850. box = getPointBB(this);
  5851. if (box) {
  5852. v2 = {
  5853. x: (box.xMin + box.xMax) / 2,
  5854. y: (box.yMin + box.yMax) / 2
  5855. };
  5856. }
  5857. }
  5858. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  5859. },
  5860. /**
  5861. * Utility to get the position of the marker, based on the path angle and
  5862. * the marker's radius.
  5863. *
  5864. * @private
  5865. * @function Highcharts.Point#getMarkerVector
  5866. *
  5867. * @param {number} radians
  5868. * The angle in radians from the point center to another vector.
  5869. *
  5870. * @param {number} markerRadius
  5871. * The radius of the marker, to calculate the additional distance to
  5872. * the center of the marker.
  5873. *
  5874. * @param {object} anchor
  5875. * The anchor point of the path and marker as an object with x/y
  5876. * properties.
  5877. *
  5878. * @return {object}
  5879. * The marker vector as an object with x/y properties.
  5880. */
  5881. getMarkerVector: function (radians, markerRadius, anchor) {
  5882. var twoPI = Math.PI * 2.0,
  5883. theta = radians,
  5884. bb = getPointBB(this),
  5885. rectWidth = bb.xMax - bb.xMin,
  5886. rectHeight = bb.yMax - bb.yMin,
  5887. rAtan = Math.atan2(rectHeight,
  5888. rectWidth),
  5889. tanTheta = 1,
  5890. leftOrRightRegion = false,
  5891. rectHalfWidth = rectWidth / 2.0,
  5892. rectHalfHeight = rectHeight / 2.0,
  5893. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  5894. rectVerticalCenter = bb.yMin + rectHalfHeight,
  5895. edgePoint = {
  5896. x: rectHorizontalCenter,
  5897. y: rectVerticalCenter
  5898. },
  5899. markerPoint = {},
  5900. xFactor = 1,
  5901. yFactor = 1;
  5902. while (theta < -Math.PI) {
  5903. theta += twoPI;
  5904. }
  5905. while (theta > Math.PI) {
  5906. theta -= twoPI;
  5907. }
  5908. tanTheta = Math.tan(theta);
  5909. if ((theta > -rAtan) && (theta <= rAtan)) {
  5910. // Right side
  5911. yFactor = -1;
  5912. leftOrRightRegion = true;
  5913. }
  5914. else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  5915. // Top side
  5916. yFactor = -1;
  5917. }
  5918. else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  5919. // Left side
  5920. xFactor = -1;
  5921. leftOrRightRegion = true;
  5922. }
  5923. else {
  5924. // Bottom side
  5925. xFactor = -1;
  5926. }
  5927. // Correct the edgePoint according to the placement of the marker
  5928. if (leftOrRightRegion) {
  5929. edgePoint.x += xFactor * (rectHalfWidth);
  5930. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  5931. }
  5932. else {
  5933. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  5934. edgePoint.y += yFactor * (rectHalfHeight);
  5935. }
  5936. if (anchor.x !== rectHorizontalCenter) {
  5937. edgePoint.x = anchor.x;
  5938. }
  5939. if (anchor.y !== rectVerticalCenter) {
  5940. edgePoint.y = anchor.y;
  5941. }
  5942. markerPoint.x = edgePoint.x + (markerRadius * Math.cos(theta));
  5943. markerPoint.y = edgePoint.y - (markerRadius * Math.sin(theta));
  5944. return markerPoint;
  5945. }
  5946. });
  5947. /**
  5948. * Warn if using legacy options. Copy the options over. Note that this will
  5949. * still break if using the legacy options in chart.update, addSeries etc.
  5950. * @private
  5951. */
  5952. function warnLegacy(chart) {
  5953. if (chart.options.pathfinder ||
  5954. chart.series.reduce(function (acc, series) {
  5955. if (series.options) {
  5956. merge(true, (series.options.connectors = series.options.connectors ||
  5957. {}), series.options.pathfinder);
  5958. }
  5959. return acc || series.options && series.options.pathfinder;
  5960. }, false)) {
  5961. merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
  5962. error('WARNING: Pathfinder options have been renamed. ' +
  5963. 'Use "chart.connectors" or "series.connectors" instead.');
  5964. }
  5965. }
  5966. // Initialize Pathfinder for charts
  5967. Chart.prototype.callbacks.push(function (chart) {
  5968. var options = chart.options;
  5969. if (options.connectors.enabled !== false) {
  5970. warnLegacy(chart);
  5971. this.pathfinder = new Pathfinder(this);
  5972. this.pathfinder.update(true); // First draw, defer render
  5973. }
  5974. });
  5975. return Pathfinder;
  5976. });
  5977. _registerModule(_modules, 'Series/XRangeSeries.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Series/Series.js'], _modules['Core/Globals.js'], _modules['Core/Color/Color.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (Axis, BaseSeries, H, Color, Point, U) {
  5978. /* *
  5979. *
  5980. * X-range series module
  5981. *
  5982. * (c) 2010-2020 Torstein Honsi, Lars A. V. Cabrera
  5983. *
  5984. * License: www.highcharts.com/license
  5985. *
  5986. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5987. *
  5988. * */
  5989. var color = Color.parse;
  5990. var addEvent = U.addEvent,
  5991. clamp = U.clamp,
  5992. correctFloat = U.correctFloat,
  5993. defined = U.defined,
  5994. find = U.find,
  5995. isNumber = U.isNumber,
  5996. isObject = U.isObject,
  5997. merge = U.merge,
  5998. pick = U.pick;
  5999. /* *
  6000. * @interface Highcharts.PointOptionsObject in parts/Point.ts
  6001. */ /**
  6002. * The ending X value of the range point.
  6003. * @name Highcharts.PointOptionsObject#x2
  6004. * @type {number|undefined}
  6005. * @requires modules/xrange
  6006. */
  6007. var Series = H.Series,
  6008. seriesTypes = BaseSeries.seriesTypes,
  6009. columnType = seriesTypes.column;
  6010. /**
  6011. * Return color of a point based on its category.
  6012. *
  6013. * @private
  6014. * @function getColorByCategory
  6015. *
  6016. * @param {object} series
  6017. * The series which the point belongs to.
  6018. *
  6019. * @param {object} point
  6020. * The point to calculate its color for.
  6021. *
  6022. * @return {object}
  6023. * Returns an object containing the properties color and colorIndex.
  6024. */
  6025. function getColorByCategory(series, point) {
  6026. var colors = series.options.colors || series.chart.options.colors,
  6027. colorCount = colors ?
  6028. colors.length :
  6029. series.chart.options.chart.colorCount,
  6030. colorIndex = point.y % colorCount,
  6031. color = colors && colors[colorIndex];
  6032. return {
  6033. colorIndex: colorIndex,
  6034. color: color
  6035. };
  6036. }
  6037. /**
  6038. * @private
  6039. * @class
  6040. * @name Highcharts.seriesTypes.xrange
  6041. *
  6042. * @augments Highcharts.Series
  6043. */
  6044. BaseSeries.seriesType('xrange', 'column'
  6045. /**
  6046. * The X-range series displays ranges on the X axis, typically time
  6047. * intervals with a start and end date.
  6048. *
  6049. * @sample {highcharts} highcharts/demo/x-range/
  6050. * X-range
  6051. * @sample {highcharts} highcharts/css/x-range/
  6052. * Styled mode X-range
  6053. * @sample {highcharts} highcharts/chart/inverted-xrange/
  6054. * Inverted X-range
  6055. *
  6056. * @extends plotOptions.column
  6057. * @since 6.0.0
  6058. * @product highcharts highstock gantt
  6059. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor,
  6060. * edgeWidth, findNearestPointBy, getExtremesFromAll,
  6061. * negativeColor, pointInterval, pointIntervalUnit,
  6062. * pointPlacement, pointRange, pointStart, softThreshold,
  6063. * stacking, threshold, data, dataSorting, boostBlending
  6064. * @requires modules/xrange
  6065. * @optionparent plotOptions.xrange
  6066. */
  6067. , {
  6068. /**
  6069. * A partial fill for each point, typically used to visualize how much
  6070. * of a task is performed. The partial fill object can be set either on
  6071. * series or point level.
  6072. *
  6073. * @sample {highcharts} highcharts/demo/x-range
  6074. * X-range with partial fill
  6075. *
  6076. * @product highcharts highstock gantt
  6077. * @apioption plotOptions.xrange.partialFill
  6078. */
  6079. /**
  6080. * The fill color to be used for partial fills. Defaults to a darker
  6081. * shade of the point color.
  6082. *
  6083. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  6084. * @product highcharts highstock gantt
  6085. * @apioption plotOptions.xrange.partialFill.fill
  6086. */
  6087. /**
  6088. * A partial fill for each point, typically used to visualize how much
  6089. * of a task is performed. See [completed](series.gantt.data.completed).
  6090. *
  6091. * @sample gantt/demo/progress-indicator
  6092. * Gantt with progress indicator
  6093. *
  6094. * @product gantt
  6095. * @apioption plotOptions.gantt.partialFill
  6096. */
  6097. /**
  6098. * In an X-range series, this option makes all points of the same Y-axis
  6099. * category the same color.
  6100. */
  6101. colorByPoint: true,
  6102. dataLabels: {
  6103. formatter: function () {
  6104. var point = this.point,
  6105. amount = point.partialFill;
  6106. if (isObject(amount)) {
  6107. amount = amount.amount;
  6108. }
  6109. if (isNumber(amount) && amount > 0) {
  6110. return correctFloat(amount * 100) + '%';
  6111. }
  6112. },
  6113. inside: true,
  6114. verticalAlign: 'middle'
  6115. },
  6116. tooltip: {
  6117. headerFormat: '<span style="font-size: 10px">{point.x} - {point.x2}</span><br/>',
  6118. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
  6119. },
  6120. borderRadius: 3,
  6121. pointRange: 0
  6122. }, {
  6123. type: 'xrange',
  6124. parallelArrays: ['x', 'x2', 'y'],
  6125. requireSorting: false,
  6126. animate: seriesTypes.line.prototype.animate,
  6127. cropShoulder: 1,
  6128. getExtremesFromAll: true,
  6129. autoIncrement: H.noop,
  6130. buildKDTree: H.noop,
  6131. /* eslint-disable valid-jsdoc */
  6132. /**
  6133. * @private
  6134. * @function Highcarts.seriesTypes.xrange#init
  6135. * @return {void}
  6136. */
  6137. init: function () {
  6138. seriesTypes.column.prototype.init.apply(this, arguments);
  6139. this.options.stacking = void 0; // #13161
  6140. },
  6141. /**
  6142. * Borrow the column series metrics, but with swapped axes. This gives
  6143. * free access to features like groupPadding, grouping, pointWidth etc.
  6144. *
  6145. * @private
  6146. * @function Highcharts.Series#getColumnMetrics
  6147. *
  6148. * @return {Highcharts.ColumnMetricsObject}
  6149. */
  6150. getColumnMetrics: function () {
  6151. var metrics,
  6152. chart = this.chart;
  6153. /**
  6154. * @private
  6155. */
  6156. function swapAxes() {
  6157. chart.series.forEach(function (s) {
  6158. var xAxis = s.xAxis;
  6159. s.xAxis = s.yAxis;
  6160. s.yAxis = xAxis;
  6161. });
  6162. }
  6163. swapAxes();
  6164. metrics = columnType.prototype.getColumnMetrics.call(this);
  6165. swapAxes();
  6166. return metrics;
  6167. },
  6168. /**
  6169. * Override cropData to show a point where x or x2 is outside visible
  6170. * range, but one of them is inside.
  6171. *
  6172. * @private
  6173. * @function Highcharts.Series#cropData
  6174. *
  6175. * @param {Array<number>} xData
  6176. *
  6177. * @param {Array<number>} yData
  6178. *
  6179. * @param {number} min
  6180. *
  6181. * @param {number} max
  6182. *
  6183. * @param {number} [cropShoulder]
  6184. *
  6185. * @return {*}
  6186. */
  6187. cropData: function (xData, yData, min, max) {
  6188. // Replace xData with x2Data to find the appropriate cropStart
  6189. var cropData = Series.prototype.cropData,
  6190. crop = cropData.call(this,
  6191. this.x2Data,
  6192. yData,
  6193. min,
  6194. max);
  6195. // Re-insert the cropped xData
  6196. crop.xData = xData.slice(crop.start, crop.end);
  6197. return crop;
  6198. },
  6199. /**
  6200. * Finds the index of an existing point that matches the given point
  6201. * options.
  6202. *
  6203. * @private
  6204. * @function Highcharts.Series#findPointIndex
  6205. * @param {object} options The options of the point.
  6206. * @returns {number|undefined} Returns index of a matching point,
  6207. * returns undefined if no match is found.
  6208. */
  6209. findPointIndex: function (options) {
  6210. var _a = this,
  6211. cropped = _a.cropped,
  6212. cropStart = _a.cropStart,
  6213. points = _a.points;
  6214. var id = options.id;
  6215. var pointIndex;
  6216. if (id) {
  6217. var point = find(points,
  6218. function (point) {
  6219. return point.id === id;
  6220. });
  6221. pointIndex = point ? point.index : void 0;
  6222. }
  6223. if (typeof pointIndex === 'undefined') {
  6224. var point = find(points,
  6225. function (point) {
  6226. return (point.x === options.x &&
  6227. point.x2 === options.x2 &&
  6228. !point.touched);
  6229. });
  6230. pointIndex = point ? point.index : void 0;
  6231. }
  6232. // Reduce pointIndex if data is cropped
  6233. if (cropped &&
  6234. isNumber(pointIndex) &&
  6235. isNumber(cropStart) &&
  6236. pointIndex >= cropStart) {
  6237. pointIndex -= cropStart;
  6238. }
  6239. return pointIndex;
  6240. },
  6241. /**
  6242. * @private
  6243. * @function Highcharts.Series#translatePoint
  6244. *
  6245. * @param {Highcharts.Point} point
  6246. */
  6247. translatePoint: function (point) {
  6248. var series = this,
  6249. xAxis = series.xAxis,
  6250. yAxis = series.yAxis,
  6251. metrics = series.columnMetrics,
  6252. options = series.options,
  6253. minPointLength = options.minPointLength || 0,
  6254. plotX = point.plotX,
  6255. posX = pick(point.x2,
  6256. point.x + (point.len || 0)),
  6257. plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
  6258. length = Math.abs(plotX2 - plotX),
  6259. widthDifference,
  6260. shapeArgs,
  6261. partialFill,
  6262. inverted = this.chart.inverted,
  6263. borderWidth = pick(options.borderWidth, 1),
  6264. crisper = borderWidth % 2 / 2,
  6265. yOffset = metrics.offset,
  6266. pointHeight = Math.round(metrics.width),
  6267. dlLeft,
  6268. dlRight,
  6269. dlWidth,
  6270. clipRectWidth,
  6271. tooltipYOffset;
  6272. if (minPointLength) {
  6273. widthDifference = minPointLength - length;
  6274. if (widthDifference < 0) {
  6275. widthDifference = 0;
  6276. }
  6277. plotX -= widthDifference / 2;
  6278. plotX2 += widthDifference / 2;
  6279. }
  6280. plotX = Math.max(plotX, -10);
  6281. plotX2 = clamp(plotX2, -10, xAxis.len + 10);
  6282. // Handle individual pointWidth
  6283. if (defined(point.options.pointWidth)) {
  6284. yOffset -= ((Math.ceil(point.options.pointWidth) - pointHeight) / 2);
  6285. pointHeight = Math.ceil(point.options.pointWidth);
  6286. }
  6287. // Apply pointPlacement to the Y axis
  6288. if (options.pointPlacement &&
  6289. isNumber(point.plotY) &&
  6290. yAxis.categories) {
  6291. point.plotY = yAxis.translate(point.y, 0, 1, 0, 1, options.pointPlacement);
  6292. }
  6293. point.shapeArgs = {
  6294. x: Math.floor(Math.min(plotX, plotX2)) + crisper,
  6295. y: Math.floor(point.plotY + yOffset) + crisper,
  6296. width: Math.round(Math.abs(plotX2 - plotX)),
  6297. height: pointHeight,
  6298. r: series.options.borderRadius
  6299. };
  6300. // Align data labels inside the shape and inside the plot area
  6301. dlLeft = point.shapeArgs.x;
  6302. dlRight = dlLeft + point.shapeArgs.width;
  6303. if (dlLeft < 0 || dlRight > xAxis.len) {
  6304. dlLeft = clamp(dlLeft, 0, xAxis.len);
  6305. dlRight = clamp(dlRight, 0, xAxis.len);
  6306. dlWidth = dlRight - dlLeft;
  6307. point.dlBox = merge(point.shapeArgs, {
  6308. x: dlLeft,
  6309. width: dlRight - dlLeft,
  6310. centerX: dlWidth ? dlWidth / 2 : null
  6311. });
  6312. }
  6313. else {
  6314. point.dlBox = null;
  6315. }
  6316. // Tooltip position
  6317. var tooltipPos = point.tooltipPos;
  6318. var xIndex = !inverted ? 0 : 1;
  6319. var yIndex = !inverted ? 1 : 0;
  6320. tooltipYOffset = series.columnMetrics ?
  6321. series.columnMetrics.offset : -metrics.width / 2;
  6322. // Limit position by the correct axis size (#9727)
  6323. tooltipPos[xIndex] = clamp(tooltipPos[xIndex] + ((!inverted ? 1 : -1) * (xAxis.reversed ? -1 : 1) *
  6324. (length / 2)), 0, xAxis.len - 1);
  6325. tooltipPos[yIndex] = clamp(tooltipPos[yIndex] + ((inverted ? -1 : 1) * tooltipYOffset), 0, yAxis.len - 1);
  6326. // Add a partShapeArgs to the point, based on the shapeArgs property
  6327. partialFill = point.partialFill;
  6328. if (partialFill) {
  6329. // Get the partial fill amount
  6330. if (isObject(partialFill)) {
  6331. partialFill = partialFill.amount;
  6332. }
  6333. // If it was not a number, assume 0
  6334. if (!isNumber(partialFill)) {
  6335. partialFill = 0;
  6336. }
  6337. shapeArgs = point.shapeArgs;
  6338. point.partShapeArgs = {
  6339. x: shapeArgs.x,
  6340. y: shapeArgs.y,
  6341. width: shapeArgs.width,
  6342. height: shapeArgs.height,
  6343. r: series.options.borderRadius
  6344. };
  6345. clipRectWidth = Math.max(Math.round(length * partialFill + point.plotX -
  6346. plotX), 0);
  6347. point.clipRectArgs = {
  6348. x: xAxis.reversed ? // #10717
  6349. shapeArgs.x + length - clipRectWidth :
  6350. shapeArgs.x,
  6351. y: shapeArgs.y,
  6352. width: clipRectWidth,
  6353. height: shapeArgs.height
  6354. };
  6355. }
  6356. },
  6357. /**
  6358. * @private
  6359. * @function Highcharts.Series#translate
  6360. */
  6361. translate: function () {
  6362. columnType.prototype.translate.apply(this, arguments);
  6363. this.points.forEach(function (point) {
  6364. this.translatePoint(point);
  6365. }, this);
  6366. },
  6367. /**
  6368. * Draws a single point in the series. Needed for partial fill.
  6369. *
  6370. * This override turns point.graphic into a group containing the
  6371. * original graphic and an overlay displaying the partial fill.
  6372. *
  6373. * @private
  6374. * @function Highcharts.Series#drawPoint
  6375. *
  6376. * @param {Highcharts.Point} point
  6377. * An instance of Point in the series.
  6378. *
  6379. * @param {"animate"|"attr"} verb
  6380. * 'animate' (animates changes) or 'attr' (sets options)
  6381. */
  6382. drawPoint: function (point, verb) {
  6383. var series = this,
  6384. seriesOpts = series.options,
  6385. renderer = series.chart.renderer,
  6386. graphic = point.graphic,
  6387. type = point.shapeType,
  6388. shapeArgs = point.shapeArgs,
  6389. partShapeArgs = point.partShapeArgs,
  6390. clipRectArgs = point.clipRectArgs,
  6391. pfOptions = point.partialFill,
  6392. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  6393. pointState = point.state,
  6394. stateOpts = (seriesOpts.states[pointState || 'normal'] ||
  6395. {}),
  6396. pointStateVerb = typeof pointState === 'undefined' ?
  6397. 'attr' : verb,
  6398. pointAttr = series.pointAttribs(point,
  6399. pointState),
  6400. animation = pick(series.chart.options.chart.animation,
  6401. stateOpts.animation),
  6402. fill;
  6403. if (!point.isNull && point.visible !== false) {
  6404. // Original graphic
  6405. if (graphic) { // update
  6406. graphic.rect[verb](shapeArgs);
  6407. }
  6408. else {
  6409. point.graphic = graphic = renderer.g('point')
  6410. .addClass(point.getClassName())
  6411. .add(point.group || series.group);
  6412. graphic.rect = renderer[type](merge(shapeArgs))
  6413. .addClass(point.getClassName())
  6414. .addClass('highcharts-partfill-original')
  6415. .add(graphic);
  6416. }
  6417. // Partial fill graphic
  6418. if (partShapeArgs) {
  6419. if (graphic.partRect) {
  6420. graphic.partRect[verb](merge(partShapeArgs));
  6421. graphic.partialClipRect[verb](merge(clipRectArgs));
  6422. }
  6423. else {
  6424. graphic.partialClipRect = renderer.clipRect(clipRectArgs.x, clipRectArgs.y, clipRectArgs.width, clipRectArgs.height);
  6425. graphic.partRect =
  6426. renderer[type](partShapeArgs)
  6427. .addClass('highcharts-partfill-overlay')
  6428. .add(graphic)
  6429. .clip(graphic.partialClipRect);
  6430. }
  6431. }
  6432. // Presentational
  6433. if (!series.chart.styledMode) {
  6434. graphic
  6435. .rect[verb](pointAttr, animation)
  6436. .shadow(seriesOpts.shadow, null, cutOff);
  6437. if (partShapeArgs) {
  6438. // Ensure pfOptions is an object
  6439. if (!isObject(pfOptions)) {
  6440. pfOptions = {};
  6441. }
  6442. if (isObject(seriesOpts.partialFill)) {
  6443. pfOptions = merge(seriesOpts.partialFill, pfOptions);
  6444. }
  6445. fill = (pfOptions.fill ||
  6446. color(pointAttr.fill).brighten(-0.3).get() ||
  6447. color(point.color || series.color)
  6448. .brighten(-0.3).get());
  6449. pointAttr.fill = fill;
  6450. graphic
  6451. .partRect[pointStateVerb](pointAttr, animation)
  6452. .shadow(seriesOpts.shadow, null, cutOff);
  6453. }
  6454. }
  6455. }
  6456. else if (graphic) {
  6457. point.graphic = graphic.destroy(); // #1269
  6458. }
  6459. },
  6460. /**
  6461. * @private
  6462. * @function Highcharts.Series#drawPoints
  6463. */
  6464. drawPoints: function () {
  6465. var series = this,
  6466. verb = series.getAnimationVerb();
  6467. // Draw the columns
  6468. series.points.forEach(function (point) {
  6469. series.drawPoint(point, verb);
  6470. });
  6471. },
  6472. /**
  6473. * Returns "animate", or "attr" if the number of points is above the
  6474. * animation limit.
  6475. *
  6476. * @private
  6477. * @function Highcharts.Series#getAnimationVerb
  6478. *
  6479. * @return {string}
  6480. */
  6481. getAnimationVerb: function () {
  6482. return (this.chart.pointCount < (this.options.animationLimit || 250) ?
  6483. 'animate' :
  6484. 'attr');
  6485. }
  6486. /*
  6487. // Override to remove stroke from points. For partial fill.
  6488. pointAttribs: function () {
  6489. var series = this,
  6490. retVal = columnType.prototype.pointAttribs
  6491. .apply(series,
  6492. arguments);
  6493. //retVal['stroke-width'] = 0;
  6494. return retVal;
  6495. }
  6496. //*/
  6497. /* eslint-enable valid-jsdoc */
  6498. }, {
  6499. /**
  6500. * The ending X value of the range point.
  6501. * @name Highcharts.Point#x2
  6502. * @type {number|undefined}
  6503. * @requires modules/xrange
  6504. */
  6505. /**
  6506. * Extend applyOptions so that `colorByPoint` for x-range means that one
  6507. * color is applied per Y axis category.
  6508. *
  6509. * @private
  6510. * @function Highcharts.Point#applyOptions
  6511. *
  6512. * @return {Highcharts.Series}
  6513. */
  6514. /* eslint-disable valid-jsdoc */
  6515. /**
  6516. * @private
  6517. */
  6518. resolveColor: function () {
  6519. var series = this.series,
  6520. colorByPoint;
  6521. if (series.options.colorByPoint && !this.options.color) {
  6522. colorByPoint = getColorByCategory(series, this);
  6523. if (!series.chart.styledMode) {
  6524. this.color = colorByPoint.color;
  6525. }
  6526. if (!this.options.colorIndex) {
  6527. this.colorIndex = colorByPoint.colorIndex;
  6528. }
  6529. }
  6530. else if (!this.color) {
  6531. this.color = series.color;
  6532. }
  6533. },
  6534. /**
  6535. * Extend init to have y default to 0.
  6536. *
  6537. * @private
  6538. * @function Highcharts.Point#init
  6539. *
  6540. * @return {Highcharts.Point}
  6541. */
  6542. init: function () {
  6543. Point.prototype.init.apply(this, arguments);
  6544. if (!this.y) {
  6545. this.y = 0;
  6546. }
  6547. return this;
  6548. },
  6549. /**
  6550. * @private
  6551. * @function Highcharts.Point#setState
  6552. */
  6553. setState: function () {
  6554. Point.prototype.setState.apply(this, arguments);
  6555. this.series.drawPoint(this, this.series.getAnimationVerb());
  6556. },
  6557. /**
  6558. * @private
  6559. * @function Highcharts.Point#getLabelConfig
  6560. *
  6561. * @return {Highcharts.PointLabelObject}
  6562. */
  6563. // Add x2 and yCategory to the available properties for tooltip formats
  6564. getLabelConfig: function () {
  6565. var point = this,
  6566. cfg = Point.prototype.getLabelConfig.call(point),
  6567. yCats = point.series.yAxis.categories;
  6568. cfg.x2 = point.x2;
  6569. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  6570. return cfg;
  6571. },
  6572. tooltipDateKeys: ['x', 'x2'],
  6573. /**
  6574. * @private
  6575. * @function Highcharts.Point#isValid
  6576. *
  6577. * @return {boolean}
  6578. */
  6579. isValid: function () {
  6580. return typeof this.x === 'number' &&
  6581. typeof this.x2 === 'number';
  6582. }
  6583. /* eslint-enable valid-jsdoc */
  6584. });
  6585. /**
  6586. * Max x2 should be considered in xAxis extremes
  6587. */
  6588. addEvent(Axis, 'afterGetSeriesExtremes', function () {
  6589. var axis = this, // eslint-disable-line no-invalid-this
  6590. axisSeries = axis.series,
  6591. dataMax,
  6592. modMax;
  6593. if (axis.isXAxis) {
  6594. dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
  6595. axisSeries.forEach(function (series) {
  6596. if (series.x2Data) {
  6597. series.x2Data
  6598. .forEach(function (val) {
  6599. if (val > dataMax) {
  6600. dataMax = val;
  6601. modMax = true;
  6602. }
  6603. });
  6604. }
  6605. });
  6606. if (modMax) {
  6607. axis.dataMax = dataMax;
  6608. }
  6609. }
  6610. });
  6611. /**
  6612. * An `xrange` series. If the [type](#series.xrange.type) option is not
  6613. * specified, it is inherited from [chart.type](#chart.type).
  6614. *
  6615. * @extends series,plotOptions.xrange
  6616. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor, edgeWidth,
  6617. * findNearestPointBy, getExtremesFromAll, negativeColor,
  6618. * pointInterval, pointIntervalUnit, pointPlacement, pointRange,
  6619. * pointStart, softThreshold, stacking, threshold, dataSorting,
  6620. * boostBlending
  6621. * @product highcharts highstock gantt
  6622. * @requires modules/xrange
  6623. * @apioption series.xrange
  6624. */
  6625. /**
  6626. * An array of data points for the series. For the `xrange` series type,
  6627. * points can be given in the following ways:
  6628. *
  6629. * 1. An array of objects with named values. The objects are point configuration
  6630. * objects as seen below.
  6631. * ```js
  6632. * data: [{
  6633. * x: Date.UTC(2017, 0, 1),
  6634. * x2: Date.UTC(2017, 0, 3),
  6635. * name: "Test",
  6636. * y: 0,
  6637. * color: "#00FF00"
  6638. * }, {
  6639. * x: Date.UTC(2017, 0, 4),
  6640. * x2: Date.UTC(2017, 0, 5),
  6641. * name: "Deploy",
  6642. * y: 1,
  6643. * color: "#FF0000"
  6644. * }]
  6645. * ```
  6646. *
  6647. * @sample {highcharts} highcharts/series/data-array-of-objects/
  6648. * Config objects
  6649. *
  6650. * @declare Highcharts.XrangePointOptionsObject
  6651. * @type {Array<*>}
  6652. * @extends series.line.data
  6653. * @product highcharts highstock gantt
  6654. * @apioption series.xrange.data
  6655. */
  6656. /**
  6657. * The starting X value of the range point.
  6658. *
  6659. * @sample {highcharts} highcharts/demo/x-range
  6660. * X-range
  6661. *
  6662. * @type {number}
  6663. * @product highcharts highstock gantt
  6664. * @apioption series.xrange.data.x
  6665. */
  6666. /**
  6667. * The ending X value of the range point.
  6668. *
  6669. * @sample {highcharts} highcharts/demo/x-range
  6670. * X-range
  6671. *
  6672. * @type {number}
  6673. * @product highcharts highstock gantt
  6674. * @apioption series.xrange.data.x2
  6675. */
  6676. /**
  6677. * The Y value of the range point.
  6678. *
  6679. * @sample {highcharts} highcharts/demo/x-range
  6680. * X-range
  6681. *
  6682. * @type {number}
  6683. * @product highcharts highstock gantt
  6684. * @apioption series.xrange.data.y
  6685. */
  6686. /**
  6687. * A partial fill for each point, typically used to visualize how much of
  6688. * a task is performed. The partial fill object can be set either on series
  6689. * or point level.
  6690. *
  6691. * @sample {highcharts} highcharts/demo/x-range
  6692. * X-range with partial fill
  6693. *
  6694. * @declare Highcharts.XrangePointPartialFillOptionsObject
  6695. * @product highcharts highstock gantt
  6696. * @apioption series.xrange.data.partialFill
  6697. */
  6698. /**
  6699. * The amount of the X-range point to be filled. Values can be 0-1 and are
  6700. * converted to percentages in the default data label formatter.
  6701. *
  6702. * @type {number}
  6703. * @product highcharts highstock gantt
  6704. * @apioption series.xrange.data.partialFill.amount
  6705. */
  6706. /**
  6707. * The fill color to be used for partial fills. Defaults to a darker shade
  6708. * of the point color.
  6709. *
  6710. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  6711. * @product highcharts highstock gantt
  6712. * @apioption series.xrange.data.partialFill.fill
  6713. */
  6714. ''; // adds doclets above to transpiled file
  6715. });
  6716. _registerModule(_modules, 'Series/GanttSeries.js', [_modules['Core/Series/Series.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Utilities.js']], function (BaseSeries, H, O, U) {
  6717. /* *
  6718. *
  6719. * (c) 2016-2020 Highsoft AS
  6720. *
  6721. * Author: Lars A. V. Cabrera
  6722. *
  6723. * License: www.highcharts.com/license
  6724. *
  6725. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6726. *
  6727. * */
  6728. var dateFormat = O.dateFormat;
  6729. var isNumber = U.isNumber,
  6730. merge = U.merge,
  6731. pick = U.pick,
  6732. splat = U.splat;
  6733. var Series = H.Series,
  6734. seriesTypes = BaseSeries.seriesTypes,
  6735. parent = seriesTypes.xrange;
  6736. /**
  6737. * @private
  6738. * @class
  6739. * @name Highcharts.seriesTypes.gantt
  6740. *
  6741. * @augments Highcharts.Series
  6742. */
  6743. BaseSeries.seriesType('gantt', 'xrange'
  6744. /**
  6745. * A `gantt` series. If the [type](#series.gantt.type) option is not specified,
  6746. * it is inherited from [chart.type](#chart.type).
  6747. *
  6748. * @extends plotOptions.xrange
  6749. * @product gantt
  6750. * @requires highcharts-gantt
  6751. * @optionparent plotOptions.gantt
  6752. */
  6753. , {
  6754. // options - default options merged with parent
  6755. grouping: false,
  6756. dataLabels: {
  6757. enabled: true
  6758. },
  6759. tooltip: {
  6760. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  6761. pointFormat: null,
  6762. pointFormatter: function () {
  6763. var point = this,
  6764. series = point.series,
  6765. tooltip = series.chart.tooltip,
  6766. xAxis = series.xAxis,
  6767. formats = series.tooltipOptions.dateTimeLabelFormats,
  6768. startOfWeek = xAxis.options.startOfWeek,
  6769. ttOptions = series.tooltipOptions,
  6770. format = ttOptions.xDateFormat,
  6771. start,
  6772. end,
  6773. milestone = point.options.milestone,
  6774. retVal = '<b>' + (point.name || point.yCategory) + '</b>';
  6775. if (ttOptions.pointFormat) {
  6776. return point.tooltipFormatter(ttOptions.pointFormat);
  6777. }
  6778. if (!format) {
  6779. format = splat(tooltip.getDateFormat(xAxis.closestPointRange, point.start, startOfWeek, formats))[0];
  6780. }
  6781. start = series.chart.time.dateFormat(format, point.start);
  6782. end = series.chart.time.dateFormat(format, point.end);
  6783. retVal += '<br/>';
  6784. if (!milestone) {
  6785. retVal += 'Start: ' + start + '<br/>';
  6786. retVal += 'End: ' + end + '<br/>';
  6787. }
  6788. else {
  6789. retVal += start + '<br/>';
  6790. }
  6791. return retVal;
  6792. }
  6793. },
  6794. connectors: {
  6795. type: 'simpleConnect',
  6796. /**
  6797. * @declare Highcharts.ConnectorsAnimationOptionsObject
  6798. */
  6799. animation: {
  6800. reversed: true // Dependencies go from child to parent
  6801. },
  6802. startMarker: {
  6803. enabled: true,
  6804. symbol: 'arrow-filled',
  6805. radius: 4,
  6806. fill: '#fa0',
  6807. align: 'left'
  6808. },
  6809. endMarker: {
  6810. enabled: false,
  6811. align: 'right'
  6812. }
  6813. }
  6814. }, {
  6815. pointArrayMap: ['start', 'end', 'y'],
  6816. // Keyboard navigation, don't use nearest vertical mode
  6817. keyboardMoveVertical: false,
  6818. /* eslint-disable valid-jsdoc */
  6819. /**
  6820. * Handle milestones, as they have no x2.
  6821. * @private
  6822. */
  6823. translatePoint: function (point) {
  6824. var series = this,
  6825. shapeArgs,
  6826. size;
  6827. parent.prototype.translatePoint.call(series, point);
  6828. if (point.options.milestone) {
  6829. shapeArgs = point.shapeArgs;
  6830. size = shapeArgs.height;
  6831. point.shapeArgs = {
  6832. x: shapeArgs.x - (size / 2),
  6833. y: shapeArgs.y,
  6834. width: size,
  6835. height: size
  6836. };
  6837. }
  6838. },
  6839. /**
  6840. * Draws a single point in the series.
  6841. *
  6842. * This override draws the point as a diamond if point.options.milestone
  6843. * is true, and uses the original drawPoint() if it is false or not set.
  6844. *
  6845. * @requires highcharts-gantt
  6846. *
  6847. * @private
  6848. * @function Highcharts.seriesTypes.gantt#drawPoint
  6849. *
  6850. * @param {Highcharts.Point} point
  6851. * An instance of Point in the series
  6852. *
  6853. * @param {"animate"|"attr"} verb
  6854. * 'animate' (animates changes) or 'attr' (sets options)
  6855. *
  6856. * @return {void}
  6857. */
  6858. drawPoint: function (point, verb) {
  6859. var series = this,
  6860. seriesOpts = series.options,
  6861. renderer = series.chart.renderer,
  6862. shapeArgs = point.shapeArgs,
  6863. plotY = point.plotY,
  6864. graphic = point.graphic,
  6865. state = point.selected && 'select',
  6866. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  6867. diamondShape;
  6868. if (point.options.milestone) {
  6869. if (isNumber(plotY) && point.y !== null && point.visible !== false) {
  6870. diamondShape = renderer.symbols.diamond(shapeArgs.x, shapeArgs.y, shapeArgs.width, shapeArgs.height);
  6871. if (graphic) {
  6872. graphic[verb]({
  6873. d: diamondShape
  6874. });
  6875. }
  6876. else {
  6877. point.graphic = graphic = renderer.path(diamondShape)
  6878. .addClass(point.getClassName(), true)
  6879. .add(point.group || series.group);
  6880. }
  6881. // Presentational
  6882. if (!series.chart.styledMode) {
  6883. point.graphic
  6884. .attr(series.pointAttribs(point, state))
  6885. .shadow(seriesOpts.shadow, null, cutOff);
  6886. }
  6887. }
  6888. else if (graphic) {
  6889. point.graphic = graphic.destroy(); // #1269
  6890. }
  6891. }
  6892. else {
  6893. parent.prototype.drawPoint.call(series, point, verb);
  6894. }
  6895. },
  6896. setData: Series.prototype.setData,
  6897. /**
  6898. * @private
  6899. */
  6900. setGanttPointAliases: function (options) {
  6901. /**
  6902. * Add a value to options if the value exists.
  6903. * @private
  6904. */
  6905. function addIfExists(prop, val) {
  6906. if (typeof val !== 'undefined') {
  6907. options[prop] = val;
  6908. }
  6909. }
  6910. addIfExists('x', pick(options.start, options.x));
  6911. addIfExists('x2', pick(options.end, options.x2));
  6912. addIfExists('partialFill', pick(options.completed, options.partialFill));
  6913. }
  6914. /* eslint-enable valid-jsdoc */
  6915. }, merge(parent.prototype.pointClass.prototype, {
  6916. // pointProps - point member overrides. We inherit from parent as well.
  6917. /* eslint-disable valid-jsdoc */
  6918. /**
  6919. * Applies the options containing the x and y data and possible some
  6920. * extra properties. This is called on point init or from point.update.
  6921. *
  6922. * @private
  6923. * @function Highcharts.Point#applyOptions
  6924. *
  6925. * @param {object} options
  6926. * The point options
  6927. *
  6928. * @param {number} x
  6929. * The x value
  6930. *
  6931. * @return {Highcharts.Point}
  6932. * The Point instance
  6933. */
  6934. applyOptions: function (options, x) {
  6935. var point = this,
  6936. ganttPoint;
  6937. ganttPoint = parent.prototype.pointClass.prototype.applyOptions
  6938. .call(point, options, x);
  6939. H.seriesTypes.gantt.prototype.setGanttPointAliases(ganttPoint);
  6940. return ganttPoint;
  6941. },
  6942. isValid: function () {
  6943. return ((typeof this.start === 'number' ||
  6944. typeof this.x === 'number') &&
  6945. (typeof this.end === 'number' ||
  6946. typeof this.x2 === 'number' ||
  6947. this.milestone));
  6948. }
  6949. /* eslint-enable valid-jsdoc */
  6950. }));
  6951. /**
  6952. * A `gantt` series.
  6953. *
  6954. * @extends series,plotOptions.gantt
  6955. * @excluding boostThreshold, connectors, dashStyle, findNearestPointBy,
  6956. * getExtremesFromAll, marker, negativeColor, pointInterval,
  6957. * pointIntervalUnit, pointPlacement, pointStart
  6958. * @product gantt
  6959. * @requires highcharts-gantt
  6960. * @apioption series.gantt
  6961. */
  6962. /**
  6963. * Data for a Gantt series.
  6964. *
  6965. * @declare Highcharts.GanttPointOptionsObject
  6966. * @type {Array<*>}
  6967. * @extends series.xrange.data
  6968. * @excluding className, color, colorIndex, connect, dataLabels, events,
  6969. * partialFill, selected, x, x2
  6970. * @product gantt
  6971. * @apioption series.gantt.data
  6972. */
  6973. /**
  6974. * Whether the grid node belonging to this point should start as collapsed. Used
  6975. * in axes of type treegrid.
  6976. *
  6977. * @sample {gantt} gantt/treegrid-axis/collapsed/
  6978. * Start as collapsed
  6979. *
  6980. * @type {boolean}
  6981. * @default false
  6982. * @product gantt
  6983. * @apioption series.gantt.data.collapsed
  6984. */
  6985. /**
  6986. * The start time of a task.
  6987. *
  6988. * @type {number}
  6989. * @product gantt
  6990. * @apioption series.gantt.data.start
  6991. */
  6992. /**
  6993. * The end time of a task.
  6994. *
  6995. * @type {number}
  6996. * @product gantt
  6997. * @apioption series.gantt.data.end
  6998. */
  6999. /**
  7000. * The Y value of a task.
  7001. *
  7002. * @type {number}
  7003. * @product gantt
  7004. * @apioption series.gantt.data.y
  7005. */
  7006. /**
  7007. * The name of a task. If a `treegrid` y-axis is used (default in Gantt charts),
  7008. * this will be picked up automatically, and used to calculate the y-value.
  7009. *
  7010. * @type {string}
  7011. * @product gantt
  7012. * @apioption series.gantt.data.name
  7013. */
  7014. /**
  7015. * Progress indicator, how much of the task completed. If it is a number, the
  7016. * `fill` will be applied automatically.
  7017. *
  7018. * @sample {gantt} gantt/demo/progress-indicator
  7019. * Progress indicator
  7020. *
  7021. * @type {number|*}
  7022. * @extends series.xrange.data.partialFill
  7023. * @product gantt
  7024. * @apioption series.gantt.data.completed
  7025. */
  7026. /**
  7027. * The amount of the progress indicator, ranging from 0 (not started) to 1
  7028. * (finished).
  7029. *
  7030. * @type {number}
  7031. * @default 0
  7032. * @apioption series.gantt.data.completed.amount
  7033. */
  7034. /**
  7035. * The fill of the progress indicator. Defaults to a darkened variety of the
  7036. * main color.
  7037. *
  7038. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7039. * @apioption series.gantt.data.completed.fill
  7040. */
  7041. /**
  7042. * The ID of the point (task) that this point depends on in Gantt charts.
  7043. * Aliases [connect](series.xrange.data.connect). Can also be an object,
  7044. * specifying further connecting [options](series.gantt.connectors) between the
  7045. * points. Multiple connections can be specified by providing an array.
  7046. *
  7047. * @sample gantt/demo/project-management
  7048. * Dependencies
  7049. * @sample gantt/pathfinder/demo
  7050. * Different connection types
  7051. *
  7052. * @type {string|Array<string|*>|*}
  7053. * @extends series.xrange.data.connect
  7054. * @since 6.2.0
  7055. * @product gantt
  7056. * @apioption series.gantt.data.dependency
  7057. */
  7058. /**
  7059. * Whether this point is a milestone. If so, only the `start` option is handled,
  7060. * while `end` is ignored.
  7061. *
  7062. * @sample gantt/gantt/milestones
  7063. * Milestones
  7064. *
  7065. * @type {boolean}
  7066. * @since 6.2.0
  7067. * @product gantt
  7068. * @apioption series.gantt.data.milestone
  7069. */
  7070. /**
  7071. * The ID of the parent point (task) of this point in Gantt charts.
  7072. *
  7073. * @sample gantt/demo/subtasks
  7074. * Gantt chart with subtasks
  7075. *
  7076. * @type {string}
  7077. * @since 6.2.0
  7078. * @product gantt
  7079. * @apioption series.gantt.data.parent
  7080. */
  7081. /**
  7082. * @excluding afterAnimate
  7083. * @apioption series.gantt.events
  7084. */
  7085. ''; // adds doclets above to the transpiled file
  7086. });
  7087. _registerModule(_modules, 'Core/Chart/GanttChart.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Chart, H, U) {
  7088. /* *
  7089. *
  7090. * (c) 2016-2020 Highsoft AS
  7091. *
  7092. * Author: Lars A. V. Cabrera
  7093. *
  7094. * License: www.highcharts.com/license
  7095. *
  7096. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7097. *
  7098. * */
  7099. var getOptions = U.getOptions,
  7100. isArray = U.isArray,
  7101. merge = U.merge,
  7102. splat = U.splat;
  7103. /**
  7104. * Factory function for Gantt charts.
  7105. *
  7106. * @example
  7107. * // Render a chart in to div#container
  7108. * var chart = Highcharts.ganttChart('container', {
  7109. * title: {
  7110. * text: 'My chart'
  7111. * },
  7112. * series: [{
  7113. * data: ...
  7114. * }]
  7115. * });
  7116. *
  7117. * @function Highcharts.ganttChart
  7118. *
  7119. * @param {string|Highcharts.HTMLDOMElement} renderTo
  7120. * The DOM element to render to, or its id.
  7121. *
  7122. * @param {Highcharts.Options} options
  7123. * The chart options structure.
  7124. *
  7125. * @param {Highcharts.ChartCallbackFunction} [callback]
  7126. * Function to run when the chart has loaded and and all external images
  7127. * are loaded. Defining a
  7128. * [chart.events.load](https://api.highcharts.com/highcharts/chart.events.load)
  7129. * handler is equivalent.
  7130. *
  7131. * @return {Highcharts.Chart}
  7132. * Returns the Chart object.
  7133. */
  7134. H.ganttChart = function (renderTo, options, callback) {
  7135. var hasRenderToArg = typeof renderTo === 'string' || renderTo.nodeName,
  7136. seriesOptions = options.series,
  7137. defaultOptions = getOptions(),
  7138. defaultLinkedTo,
  7139. userOptions = options;
  7140. options = arguments[hasRenderToArg ? 1 : 0];
  7141. // If user hasn't defined axes as array, make it into an array and add a
  7142. // second axis by default.
  7143. if (!isArray(options.xAxis)) {
  7144. options.xAxis = [options.xAxis || {}, {}];
  7145. }
  7146. // apply X axis options to both single and multi x axes
  7147. options.xAxis = options.xAxis.map(function (xAxisOptions, i) {
  7148. if (i === 1) { // Second xAxis
  7149. defaultLinkedTo = 0;
  7150. }
  7151. return merge(defaultOptions.xAxis, {
  7152. grid: {
  7153. enabled: true
  7154. },
  7155. opposite: true,
  7156. linkedTo: defaultLinkedTo
  7157. }, xAxisOptions, // user options
  7158. {
  7159. type: 'datetime'
  7160. });
  7161. });
  7162. // apply Y axis options to both single and multi y axes
  7163. options.yAxis = (splat(options.yAxis || {})).map(function (yAxisOptions) {
  7164. return merge(defaultOptions.yAxis, // #3802
  7165. {
  7166. grid: {
  7167. enabled: true
  7168. },
  7169. staticScale: 50,
  7170. reversed: true,
  7171. // Set default type treegrid, but only if 'categories' is
  7172. // undefined
  7173. type: yAxisOptions.categories ? yAxisOptions.type : 'treegrid'
  7174. }, yAxisOptions // user options
  7175. );
  7176. });
  7177. options.series = null;
  7178. options = merge(true, {
  7179. chart: {
  7180. type: 'gantt'
  7181. },
  7182. title: {
  7183. text: null
  7184. },
  7185. legend: {
  7186. enabled: false
  7187. },
  7188. navigator: {
  7189. series: { type: 'gantt' },
  7190. // Bars were clipped, #14060.
  7191. yAxis: {
  7192. type: 'category'
  7193. }
  7194. }
  7195. }, options, // user's options
  7196. // forced options
  7197. {
  7198. isGantt: true
  7199. });
  7200. options.series = userOptions.series = seriesOptions;
  7201. return hasRenderToArg ?
  7202. new Chart(renderTo, options, callback) :
  7203. new Chart(options, options); // @todo does not look correct
  7204. };
  7205. });
  7206. _registerModule(_modules, 'Core/Axis/ScrollbarAxis.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  7207. /* *
  7208. *
  7209. * (c) 2010-2020 Torstein Honsi
  7210. *
  7211. * License: www.highcharts.com/license
  7212. *
  7213. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7214. *
  7215. * */
  7216. var addEvent = U.addEvent,
  7217. defined = U.defined,
  7218. pick = U.pick;
  7219. /* eslint-disable no-invalid-this, valid-jsdoc */
  7220. /**
  7221. * Creates scrollbars if enabled.
  7222. *
  7223. * @private
  7224. */
  7225. var ScrollbarAxis = /** @class */ (function () {
  7226. function ScrollbarAxis() {
  7227. }
  7228. /**
  7229. * Attaches to axis events to create scrollbars if enabled.
  7230. *
  7231. * @private
  7232. *
  7233. * @param AxisClass
  7234. * Axis class to extend.
  7235. *
  7236. * @param ScrollbarClass
  7237. * Scrollbar class to use.
  7238. */
  7239. ScrollbarAxis.compose = function (AxisClass, ScrollbarClass) {
  7240. // Wrap axis initialization and create scrollbar if enabled:
  7241. addEvent(AxisClass, 'afterInit', function () {
  7242. var axis = this;
  7243. if (axis.options &&
  7244. axis.options.scrollbar &&
  7245. axis.options.scrollbar.enabled) {
  7246. // Predefined options:
  7247. axis.options.scrollbar.vertical = !axis.horiz;
  7248. axis.options.startOnTick = axis.options.endOnTick = false;
  7249. axis.scrollbar = new ScrollbarClass(axis.chart.renderer, axis.options.scrollbar, axis.chart);
  7250. addEvent(axis.scrollbar, 'changed', function (e) {
  7251. var axisMin = pick(axis.options && axis.options.min,
  7252. axis.min),
  7253. axisMax = pick(axis.options && axis.options.max,
  7254. axis.max),
  7255. unitedMin = defined(axis.dataMin) ?
  7256. Math.min(axisMin,
  7257. axis.min,
  7258. axis.dataMin) : axisMin,
  7259. unitedMax = defined(axis.dataMax) ?
  7260. Math.max(axisMax,
  7261. axis.max,
  7262. axis.dataMax) : axisMax,
  7263. range = unitedMax - unitedMin,
  7264. to,
  7265. from;
  7266. // #12834, scroll when show/hide series, wrong extremes
  7267. if (!defined(axisMin) || !defined(axisMax)) {
  7268. return;
  7269. }
  7270. if ((axis.horiz && !axis.reversed) ||
  7271. (!axis.horiz && axis.reversed)) {
  7272. to = unitedMin + range * this.to;
  7273. from = unitedMin + range * this.from;
  7274. }
  7275. else {
  7276. // y-values in browser are reversed, but this also
  7277. // applies for reversed horizontal axis:
  7278. to = unitedMin + range * (1 - this.from);
  7279. from = unitedMin + range * (1 - this.to);
  7280. }
  7281. if (pick(this.options.liveRedraw, H.svg && !H.isTouchDevice && !this.chart.isBoosting) ||
  7282. // Mouseup always should change extremes
  7283. e.DOMType === 'mouseup' ||
  7284. // Internal events
  7285. !defined(e.DOMType)) {
  7286. axis.setExtremes(from, to, true, e.DOMType !== 'mousemove', e);
  7287. }
  7288. else {
  7289. // When live redraw is disabled, don't change extremes
  7290. // Only change the position of the scollbar thumb
  7291. this.setRange(this.from, this.to);
  7292. }
  7293. });
  7294. }
  7295. });
  7296. // Wrap rendering axis, and update scrollbar if one is created:
  7297. addEvent(AxisClass, 'afterRender', function () {
  7298. var axis = this,
  7299. scrollMin = Math.min(pick(axis.options.min,
  7300. axis.min),
  7301. axis.min,
  7302. pick(axis.dataMin,
  7303. axis.min) // #6930
  7304. ),
  7305. scrollMax = Math.max(pick(axis.options.max,
  7306. axis.max),
  7307. axis.max,
  7308. pick(axis.dataMax,
  7309. axis.max) // #6930
  7310. ),
  7311. scrollbar = axis.scrollbar,
  7312. offset = axis.axisTitleMargin + (axis.titleOffset || 0),
  7313. scrollbarsOffsets = axis.chart.scrollbarsOffsets,
  7314. axisMargin = axis.options.margin || 0,
  7315. offsetsIndex,
  7316. from,
  7317. to;
  7318. if (scrollbar) {
  7319. if (axis.horiz) {
  7320. // Reserve space for labels/title
  7321. if (!axis.opposite) {
  7322. scrollbarsOffsets[1] += offset;
  7323. }
  7324. scrollbar.position(axis.left, axis.top + axis.height + 2 + scrollbarsOffsets[1] -
  7325. (axis.opposite ? axisMargin : 0), axis.width, axis.height);
  7326. // Next scrollbar should reserve space for margin (if set)
  7327. if (!axis.opposite) {
  7328. scrollbarsOffsets[1] += axisMargin;
  7329. }
  7330. offsetsIndex = 1;
  7331. }
  7332. else {
  7333. // Reserve space for labels/title
  7334. if (axis.opposite) {
  7335. scrollbarsOffsets[0] += offset;
  7336. }
  7337. scrollbar.position(axis.left + axis.width + 2 + scrollbarsOffsets[0] -
  7338. (axis.opposite ? 0 : axisMargin), axis.top, axis.width, axis.height);
  7339. // Next scrollbar should reserve space for margin (if set)
  7340. if (axis.opposite) {
  7341. scrollbarsOffsets[0] += axisMargin;
  7342. }
  7343. offsetsIndex = 0;
  7344. }
  7345. scrollbarsOffsets[offsetsIndex] += scrollbar.size +
  7346. scrollbar.options.margin;
  7347. if (isNaN(scrollMin) ||
  7348. isNaN(scrollMax) ||
  7349. !defined(axis.min) ||
  7350. !defined(axis.max) ||
  7351. axis.min === axis.max // #10733
  7352. ) {
  7353. // default action: when extremes are the same or there is
  7354. // not extremes on the axis, but scrollbar exists, make it
  7355. // full size
  7356. scrollbar.setRange(0, 1);
  7357. }
  7358. else {
  7359. from =
  7360. (axis.min - scrollMin) / (scrollMax - scrollMin);
  7361. to =
  7362. (axis.max - scrollMin) / (scrollMax - scrollMin);
  7363. if ((axis.horiz && !axis.reversed) ||
  7364. (!axis.horiz && axis.reversed)) {
  7365. scrollbar.setRange(from, to);
  7366. }
  7367. else {
  7368. // inverse vertical axis
  7369. scrollbar.setRange(1 - to, 1 - from);
  7370. }
  7371. }
  7372. }
  7373. });
  7374. // Make space for a scrollbar:
  7375. addEvent(AxisClass, 'afterGetOffset', function () {
  7376. var axis = this,
  7377. index = axis.horiz ? 2 : 1,
  7378. scrollbar = axis.scrollbar;
  7379. if (scrollbar) {
  7380. axis.chart.scrollbarsOffsets = [0, 0]; // reset scrollbars offsets
  7381. axis.chart.axisOffset[index] +=
  7382. scrollbar.size + scrollbar.options.margin;
  7383. }
  7384. });
  7385. };
  7386. return ScrollbarAxis;
  7387. }());
  7388. return ScrollbarAxis;
  7389. });
  7390. _registerModule(_modules, 'Core/Scrollbar.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Axis/ScrollbarAxis.js'], _modules['Core/Utilities.js'], _modules['Core/Options.js']], function (Axis, H, ScrollbarAxis, U, O) {
  7391. /* *
  7392. *
  7393. * (c) 2010-2020 Torstein Honsi
  7394. *
  7395. * License: www.highcharts.com/license
  7396. *
  7397. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7398. *
  7399. * */
  7400. var addEvent = U.addEvent,
  7401. correctFloat = U.correctFloat,
  7402. defined = U.defined,
  7403. destroyObjectProperties = U.destroyObjectProperties,
  7404. fireEvent = U.fireEvent,
  7405. merge = U.merge,
  7406. pick = U.pick,
  7407. removeEvent = U.removeEvent;
  7408. var defaultOptions = O.defaultOptions;
  7409. var hasTouch = H.hasTouch,
  7410. isTouchDevice = H.isTouchDevice;
  7411. /**
  7412. * When we have vertical scrollbar, rifles and arrow in buttons should be
  7413. * rotated. The same method is used in Navigator's handles, to rotate them.
  7414. *
  7415. * @function Highcharts.swapXY
  7416. *
  7417. * @param {Highcharts.SVGPathArray} path
  7418. * Path to be rotated.
  7419. *
  7420. * @param {boolean} [vertical]
  7421. * If vertical scrollbar, swap x-y values.
  7422. *
  7423. * @return {Highcharts.SVGPathArray}
  7424. * Rotated path.
  7425. *
  7426. * @requires modules/stock
  7427. */
  7428. var swapXY = H.swapXY = function (path,
  7429. vertical) {
  7430. if (vertical) {
  7431. path.forEach(function (seg) {
  7432. var len = seg.length;
  7433. var temp;
  7434. for (var i = 0; i < len; i += 2) {
  7435. temp = seg[i + 1];
  7436. if (typeof temp === 'number') {
  7437. seg[i + 1] = seg[i + 2];
  7438. seg[i + 2] = temp;
  7439. }
  7440. }
  7441. });
  7442. }
  7443. return path;
  7444. };
  7445. /* eslint-disable no-invalid-this, valid-jsdoc */
  7446. /**
  7447. * A reusable scrollbar, internally used in Highstock's navigator and optionally
  7448. * on individual axes.
  7449. *
  7450. * @private
  7451. * @class
  7452. * @name Highcharts.Scrollbar
  7453. * @param {Highcharts.SVGRenderer} renderer
  7454. * @param {Highcharts.ScrollbarOptions} options
  7455. * @param {Highcharts.Chart} chart
  7456. */
  7457. var Scrollbar = /** @class */ (function () {
  7458. /* *
  7459. *
  7460. * Constructors
  7461. *
  7462. * */
  7463. function Scrollbar(renderer, options, chart) {
  7464. /* *
  7465. *
  7466. * Properties
  7467. *
  7468. * */
  7469. this._events = [];
  7470. this.chartX = 0;
  7471. this.chartY = 0;
  7472. this.from = 0;
  7473. this.group = void 0;
  7474. this.scrollbar = void 0;
  7475. this.scrollbarButtons = [];
  7476. this.scrollbarGroup = void 0;
  7477. this.scrollbarLeft = 0;
  7478. this.scrollbarRifles = void 0;
  7479. this.scrollbarStrokeWidth = 1;
  7480. this.scrollbarTop = 0;
  7481. this.size = 0;
  7482. this.to = 0;
  7483. this.track = void 0;
  7484. this.trackBorderWidth = 1;
  7485. this.userOptions = {};
  7486. this.x = 0;
  7487. this.y = 0;
  7488. this.chart = chart;
  7489. this.options = options;
  7490. this.renderer = chart.renderer;
  7491. this.init(renderer, options, chart);
  7492. }
  7493. /* *
  7494. *
  7495. * Functions
  7496. *
  7497. * */
  7498. /**
  7499. * Set up the mouse and touch events for the Scrollbar
  7500. *
  7501. * @private
  7502. * @function Highcharts.Scrollbar#addEvents
  7503. * @return {void}
  7504. */
  7505. Scrollbar.prototype.addEvents = function () {
  7506. var buttonsOrder = this.options.inverted ? [1, 0] : [0, 1],
  7507. buttons = this.scrollbarButtons,
  7508. bar = this.scrollbarGroup.element,
  7509. track = this.track.element,
  7510. mouseDownHandler = this.mouseDownHandler.bind(this),
  7511. mouseMoveHandler = this.mouseMoveHandler.bind(this),
  7512. mouseUpHandler = this.mouseUpHandler.bind(this),
  7513. _events;
  7514. // Mouse events
  7515. _events = [
  7516. [buttons[buttonsOrder[0]].element, 'click', this.buttonToMinClick.bind(this)],
  7517. [buttons[buttonsOrder[1]].element, 'click', this.buttonToMaxClick.bind(this)],
  7518. [track, 'click', this.trackClick.bind(this)],
  7519. [bar, 'mousedown', mouseDownHandler],
  7520. [bar.ownerDocument, 'mousemove', mouseMoveHandler],
  7521. [bar.ownerDocument, 'mouseup', mouseUpHandler]
  7522. ];
  7523. // Touch events
  7524. if (hasTouch) {
  7525. _events.push([bar, 'touchstart', mouseDownHandler], [bar.ownerDocument, 'touchmove', mouseMoveHandler], [bar.ownerDocument, 'touchend', mouseUpHandler]);
  7526. }
  7527. // Add them all
  7528. _events.forEach(function (args) {
  7529. addEvent.apply(null, args);
  7530. });
  7531. this._events = _events;
  7532. };
  7533. Scrollbar.prototype.buttonToMaxClick = function (e) {
  7534. var scroller = this;
  7535. var range = (scroller.to - scroller.from) * pick(scroller.options.step, 0.2);
  7536. scroller.updatePosition(scroller.from + range, scroller.to + range);
  7537. fireEvent(scroller, 'changed', {
  7538. from: scroller.from,
  7539. to: scroller.to,
  7540. trigger: 'scrollbar',
  7541. DOMEvent: e
  7542. });
  7543. };
  7544. Scrollbar.prototype.buttonToMinClick = function (e) {
  7545. var scroller = this;
  7546. var range = correctFloat(scroller.to - scroller.from) *
  7547. pick(scroller.options.step, 0.2);
  7548. scroller.updatePosition(correctFloat(scroller.from - range), correctFloat(scroller.to - range));
  7549. fireEvent(scroller, 'changed', {
  7550. from: scroller.from,
  7551. to: scroller.to,
  7552. trigger: 'scrollbar',
  7553. DOMEvent: e
  7554. });
  7555. };
  7556. /**
  7557. * Get normalized (0-1) cursor position over the scrollbar
  7558. *
  7559. * @private
  7560. * @function Highcharts.Scrollbar#cursorToScrollbarPosition
  7561. *
  7562. * @param {*} normalizedEvent
  7563. * normalized event, with chartX and chartY values
  7564. *
  7565. * @return {Highcharts.Dictionary<number>}
  7566. * Local position {chartX, chartY}
  7567. */
  7568. Scrollbar.prototype.cursorToScrollbarPosition = function (normalizedEvent) {
  7569. var scroller = this,
  7570. options = scroller.options,
  7571. minWidthDifference = options.minWidth > scroller.calculatedWidth ?
  7572. options.minWidth :
  7573. 0; // minWidth distorts translation
  7574. return {
  7575. chartX: (normalizedEvent.chartX - scroller.x -
  7576. scroller.xOffset) /
  7577. (scroller.barWidth - minWidthDifference),
  7578. chartY: (normalizedEvent.chartY - scroller.y -
  7579. scroller.yOffset) /
  7580. (scroller.barWidth - minWidthDifference)
  7581. };
  7582. };
  7583. /**
  7584. * Destroys allocated elements.
  7585. *
  7586. * @private
  7587. * @function Highcharts.Scrollbar#destroy
  7588. * @return {void}
  7589. */
  7590. Scrollbar.prototype.destroy = function () {
  7591. var scroller = this.chart.scroller;
  7592. // Disconnect events added in addEvents
  7593. this.removeEvents();
  7594. // Destroy properties
  7595. [
  7596. 'track',
  7597. 'scrollbarRifles',
  7598. 'scrollbar',
  7599. 'scrollbarGroup',
  7600. 'group'
  7601. ].forEach(function (prop) {
  7602. if (this[prop] && this[prop].destroy) {
  7603. this[prop] = this[prop].destroy();
  7604. }
  7605. }, this);
  7606. // #6421, chart may have more scrollbars
  7607. if (scroller && this === scroller.scrollbar) {
  7608. scroller.scrollbar = null;
  7609. // Destroy elements in collection
  7610. destroyObjectProperties(scroller.scrollbarButtons);
  7611. }
  7612. };
  7613. /**
  7614. * Draw the scrollbar buttons with arrows
  7615. *
  7616. * @private
  7617. * @function Highcharts.Scrollbar#drawScrollbarButton
  7618. * @param {number} index
  7619. * 0 is left, 1 is right
  7620. * @return {void}
  7621. */
  7622. Scrollbar.prototype.drawScrollbarButton = function (index) {
  7623. var scroller = this,
  7624. renderer = scroller.renderer,
  7625. scrollbarButtons = scroller.scrollbarButtons,
  7626. options = scroller.options,
  7627. size = scroller.size,
  7628. group,
  7629. tempElem;
  7630. group = renderer.g().add(scroller.group);
  7631. scrollbarButtons.push(group);
  7632. // Create a rectangle for the scrollbar button
  7633. tempElem = renderer.rect()
  7634. .addClass('highcharts-scrollbar-button')
  7635. .add(group);
  7636. // Presentational attributes
  7637. if (!this.chart.styledMode) {
  7638. tempElem.attr({
  7639. stroke: options.buttonBorderColor,
  7640. 'stroke-width': options.buttonBorderWidth,
  7641. fill: options.buttonBackgroundColor
  7642. });
  7643. }
  7644. // Place the rectangle based on the rendered stroke width
  7645. tempElem.attr(tempElem.crisp({
  7646. x: -0.5,
  7647. y: -0.5,
  7648. width: size + 1,
  7649. height: size + 1,
  7650. r: options.buttonBorderRadius
  7651. }, tempElem.strokeWidth()));
  7652. // Button arrow
  7653. tempElem = renderer
  7654. .path(swapXY([[
  7655. 'M',
  7656. size / 2 + (index ? -1 : 1),
  7657. size / 2 - 3
  7658. ], [
  7659. 'L',
  7660. size / 2 + (index ? -1 : 1),
  7661. size / 2 + 3
  7662. ], [
  7663. 'L',
  7664. size / 2 + (index ? 2 : -2),
  7665. size / 2
  7666. ]], options.vertical))
  7667. .addClass('highcharts-scrollbar-arrow')
  7668. .add(scrollbarButtons[index]);
  7669. if (!this.chart.styledMode) {
  7670. tempElem.attr({
  7671. fill: options.buttonArrowColor
  7672. });
  7673. }
  7674. };
  7675. /**
  7676. * @private
  7677. * @function Highcharts.Scrollbar#init
  7678. * @param {Highcharts.SVGRenderer} renderer
  7679. * @param {Highcharts.ScrollbarOptions} options
  7680. * @param {Highcharts.Chart} chart
  7681. */
  7682. Scrollbar.prototype.init = function (renderer, options, chart) {
  7683. this.scrollbarButtons = [];
  7684. this.renderer = renderer;
  7685. this.userOptions = options;
  7686. this.options = merge(Scrollbar.defaultOptions, options);
  7687. this.chart = chart;
  7688. // backward compatibility
  7689. this.size = pick(this.options.size, this.options.height);
  7690. // Init
  7691. if (options.enabled) {
  7692. this.render();
  7693. this.addEvents();
  7694. }
  7695. };
  7696. Scrollbar.prototype.mouseDownHandler = function (e) {
  7697. var scroller = this;
  7698. var normalizedEvent = scroller.chart.pointer.normalize(e),
  7699. mousePosition = scroller.cursorToScrollbarPosition(normalizedEvent);
  7700. scroller.chartX = mousePosition.chartX;
  7701. scroller.chartY = mousePosition.chartY;
  7702. scroller.initPositions = [scroller.from, scroller.to];
  7703. scroller.grabbedCenter = true;
  7704. };
  7705. /**
  7706. * Event handler for the mouse move event.
  7707. * @private
  7708. */
  7709. Scrollbar.prototype.mouseMoveHandler = function (e) {
  7710. var scroller = this;
  7711. var normalizedEvent = scroller.chart.pointer.normalize(e),
  7712. options = scroller.options,
  7713. direction = options.vertical ? 'chartY' : 'chartX',
  7714. initPositions = scroller.initPositions || [],
  7715. scrollPosition,
  7716. chartPosition,
  7717. change;
  7718. // In iOS, a mousemove event with e.pageX === 0 is fired when
  7719. // holding the finger down in the center of the scrollbar. This
  7720. // should be ignored.
  7721. if (scroller.grabbedCenter &&
  7722. // #4696, scrollbar failed on Android
  7723. (!e.touches || e.touches[0][direction] !== 0)) {
  7724. chartPosition = scroller.cursorToScrollbarPosition(normalizedEvent)[direction];
  7725. scrollPosition = scroller[direction];
  7726. change = chartPosition - scrollPosition;
  7727. scroller.hasDragged = true;
  7728. scroller.updatePosition(initPositions[0] + change, initPositions[1] + change);
  7729. if (scroller.hasDragged) {
  7730. fireEvent(scroller, 'changed', {
  7731. from: scroller.from,
  7732. to: scroller.to,
  7733. trigger: 'scrollbar',
  7734. DOMType: e.type,
  7735. DOMEvent: e
  7736. });
  7737. }
  7738. }
  7739. };
  7740. /**
  7741. * Event handler for the mouse up event.
  7742. * @private
  7743. */
  7744. Scrollbar.prototype.mouseUpHandler = function (e) {
  7745. var scroller = this;
  7746. if (scroller.hasDragged) {
  7747. fireEvent(scroller, 'changed', {
  7748. from: scroller.from,
  7749. to: scroller.to,
  7750. trigger: 'scrollbar',
  7751. DOMType: e.type,
  7752. DOMEvent: e
  7753. });
  7754. }
  7755. scroller.grabbedCenter =
  7756. scroller.hasDragged =
  7757. scroller.chartX =
  7758. scroller.chartY = null;
  7759. };
  7760. /**
  7761. * Position the scrollbar, method called from a parent with defined
  7762. * dimensions.
  7763. *
  7764. * @private
  7765. * @function Highcharts.Scrollbar#position
  7766. * @param {number} x
  7767. * x-position on the chart
  7768. * @param {number} y
  7769. * y-position on the chart
  7770. * @param {number} width
  7771. * width of the scrollbar
  7772. * @param {number} height
  7773. * height of the scorllbar
  7774. * @return {void}
  7775. */
  7776. Scrollbar.prototype.position = function (x, y, width, height) {
  7777. var scroller = this,
  7778. options = scroller.options,
  7779. vertical = options.vertical,
  7780. xOffset = height,
  7781. yOffset = 0,
  7782. method = scroller.rendered ? 'animate' : 'attr';
  7783. scroller.x = x;
  7784. scroller.y = y + this.trackBorderWidth;
  7785. scroller.width = width; // width with buttons
  7786. scroller.height = height;
  7787. scroller.xOffset = xOffset;
  7788. scroller.yOffset = yOffset;
  7789. // If Scrollbar is a vertical type, swap options:
  7790. if (vertical) {
  7791. scroller.width = scroller.yOffset = width = yOffset = scroller.size;
  7792. scroller.xOffset = xOffset = 0;
  7793. scroller.barWidth = height - width * 2; // width without buttons
  7794. scroller.x = x = x + scroller.options.margin;
  7795. }
  7796. else {
  7797. scroller.height = scroller.xOffset = height = xOffset =
  7798. scroller.size;
  7799. scroller.barWidth = width - height * 2; // width without buttons
  7800. scroller.y = scroller.y + scroller.options.margin;
  7801. }
  7802. // Set general position for a group:
  7803. scroller.group[method]({
  7804. translateX: x,
  7805. translateY: scroller.y
  7806. });
  7807. // Resize background/track:
  7808. scroller.track[method]({
  7809. width: width,
  7810. height: height
  7811. });
  7812. // Move right/bottom button ot it's place:
  7813. scroller.scrollbarButtons[1][method]({
  7814. translateX: vertical ? 0 : width - xOffset,
  7815. translateY: vertical ? height - yOffset : 0
  7816. });
  7817. };
  7818. /**
  7819. * Removes the event handlers attached previously with addEvents.
  7820. *
  7821. * @private
  7822. * @function Highcharts.Scrollbar#removeEvents
  7823. * @return {void}
  7824. */
  7825. Scrollbar.prototype.removeEvents = function () {
  7826. this._events.forEach(function (args) {
  7827. removeEvent.apply(null, args);
  7828. });
  7829. this._events.length = 0;
  7830. };
  7831. /**
  7832. * Render scrollbar with all required items.
  7833. *
  7834. * @private
  7835. * @function Highcharts.Scrollbar#render
  7836. */
  7837. Scrollbar.prototype.render = function () {
  7838. var scroller = this,
  7839. renderer = scroller.renderer,
  7840. options = scroller.options,
  7841. size = scroller.size,
  7842. styledMode = this.chart.styledMode,
  7843. group;
  7844. // Draw the scrollbar group
  7845. scroller.group = group = renderer.g('scrollbar').attr({
  7846. zIndex: options.zIndex,
  7847. translateY: -99999
  7848. }).add();
  7849. // Draw the scrollbar track:
  7850. scroller.track = renderer.rect()
  7851. .addClass('highcharts-scrollbar-track')
  7852. .attr({
  7853. x: 0,
  7854. r: options.trackBorderRadius || 0,
  7855. height: size,
  7856. width: size
  7857. }).add(group);
  7858. if (!styledMode) {
  7859. scroller.track.attr({
  7860. fill: options.trackBackgroundColor,
  7861. stroke: options.trackBorderColor,
  7862. 'stroke-width': options.trackBorderWidth
  7863. });
  7864. }
  7865. this.trackBorderWidth = scroller.track.strokeWidth();
  7866. scroller.track.attr({
  7867. y: -this.trackBorderWidth % 2 / 2
  7868. });
  7869. // Draw the scrollbar itself
  7870. scroller.scrollbarGroup = renderer.g().add(group);
  7871. scroller.scrollbar = renderer.rect()
  7872. .addClass('highcharts-scrollbar-thumb')
  7873. .attr({
  7874. height: size,
  7875. width: size,
  7876. r: options.barBorderRadius || 0
  7877. }).add(scroller.scrollbarGroup);
  7878. scroller.scrollbarRifles = renderer
  7879. .path(swapXY([
  7880. ['M', -3, size / 4],
  7881. ['L', -3, 2 * size / 3],
  7882. ['M', 0, size / 4],
  7883. ['L', 0, 2 * size / 3],
  7884. ['M', 3, size / 4],
  7885. ['L', 3, 2 * size / 3]
  7886. ], options.vertical))
  7887. .addClass('highcharts-scrollbar-rifles')
  7888. .add(scroller.scrollbarGroup);
  7889. if (!styledMode) {
  7890. scroller.scrollbar.attr({
  7891. fill: options.barBackgroundColor,
  7892. stroke: options.barBorderColor,
  7893. 'stroke-width': options.barBorderWidth
  7894. });
  7895. scroller.scrollbarRifles.attr({
  7896. stroke: options.rifleColor,
  7897. 'stroke-width': 1
  7898. });
  7899. }
  7900. scroller.scrollbarStrokeWidth = scroller.scrollbar.strokeWidth();
  7901. scroller.scrollbarGroup.translate(-scroller.scrollbarStrokeWidth % 2 / 2, -scroller.scrollbarStrokeWidth % 2 / 2);
  7902. // Draw the buttons:
  7903. scroller.drawScrollbarButton(0);
  7904. scroller.drawScrollbarButton(1);
  7905. };
  7906. /**
  7907. * Set scrollbar size, with a given scale.
  7908. *
  7909. * @private
  7910. * @function Highcharts.Scrollbar#setRange
  7911. * @param {number} from
  7912. * scale (0-1) where bar should start
  7913. * @param {number} to
  7914. * scale (0-1) where bar should end
  7915. * @return {void}
  7916. */
  7917. Scrollbar.prototype.setRange = function (from, to) {
  7918. var scroller = this,
  7919. options = scroller.options,
  7920. vertical = options.vertical,
  7921. minWidth = options.minWidth,
  7922. fullWidth = scroller.barWidth,
  7923. fromPX,
  7924. toPX,
  7925. newPos,
  7926. newSize,
  7927. newRiflesPos,
  7928. method = (this.rendered &&
  7929. !this.hasDragged &&
  7930. !(this.chart.navigator && this.chart.navigator.hasDragged)) ? 'animate' : 'attr';
  7931. if (!defined(fullWidth)) {
  7932. return;
  7933. }
  7934. from = Math.max(from, 0);
  7935. fromPX = Math.ceil(fullWidth * from);
  7936. toPX = fullWidth * Math.min(to, 1);
  7937. scroller.calculatedWidth = newSize = correctFloat(toPX - fromPX);
  7938. // We need to recalculate position, if minWidth is used
  7939. if (newSize < minWidth) {
  7940. fromPX = (fullWidth - minWidth + newSize) * from;
  7941. newSize = minWidth;
  7942. }
  7943. newPos = Math.floor(fromPX + scroller.xOffset + scroller.yOffset);
  7944. newRiflesPos = newSize / 2 - 0.5; // -0.5 -> rifle line width / 2
  7945. // Store current position:
  7946. scroller.from = from;
  7947. scroller.to = to;
  7948. if (!vertical) {
  7949. scroller.scrollbarGroup[method]({
  7950. translateX: newPos
  7951. });
  7952. scroller.scrollbar[method]({
  7953. width: newSize
  7954. });
  7955. scroller.scrollbarRifles[method]({
  7956. translateX: newRiflesPos
  7957. });
  7958. scroller.scrollbarLeft = newPos;
  7959. scroller.scrollbarTop = 0;
  7960. }
  7961. else {
  7962. scroller.scrollbarGroup[method]({
  7963. translateY: newPos
  7964. });
  7965. scroller.scrollbar[method]({
  7966. height: newSize
  7967. });
  7968. scroller.scrollbarRifles[method]({
  7969. translateY: newRiflesPos
  7970. });
  7971. scroller.scrollbarTop = newPos;
  7972. scroller.scrollbarLeft = 0;
  7973. }
  7974. if (newSize <= 12) {
  7975. scroller.scrollbarRifles.hide();
  7976. }
  7977. else {
  7978. scroller.scrollbarRifles.show(true);
  7979. }
  7980. // Show or hide the scrollbar based on the showFull setting
  7981. if (options.showFull === false) {
  7982. if (from <= 0 && to >= 1) {
  7983. scroller.group.hide();
  7984. }
  7985. else {
  7986. scroller.group.show();
  7987. }
  7988. }
  7989. scroller.rendered = true;
  7990. };
  7991. Scrollbar.prototype.trackClick = function (e) {
  7992. var scroller = this;
  7993. var normalizedEvent = scroller.chart.pointer.normalize(e),
  7994. range = scroller.to - scroller.from,
  7995. top = scroller.y + scroller.scrollbarTop,
  7996. left = scroller.x + scroller.scrollbarLeft;
  7997. if ((scroller.options.vertical && normalizedEvent.chartY > top) ||
  7998. (!scroller.options.vertical && normalizedEvent.chartX > left)) {
  7999. // On the top or on the left side of the track:
  8000. scroller.updatePosition(scroller.from + range, scroller.to + range);
  8001. }
  8002. else {
  8003. // On the bottom or the right side of the track:
  8004. scroller.updatePosition(scroller.from - range, scroller.to - range);
  8005. }
  8006. fireEvent(scroller, 'changed', {
  8007. from: scroller.from,
  8008. to: scroller.to,
  8009. trigger: 'scrollbar',
  8010. DOMEvent: e
  8011. });
  8012. };
  8013. /**
  8014. * Update the scrollbar with new options
  8015. *
  8016. * @private
  8017. * @function Highcharts.Scrollbar#update
  8018. * @param {Highcharts.ScrollbarOptions} options
  8019. * @return {void}
  8020. */
  8021. Scrollbar.prototype.update = function (options) {
  8022. this.destroy();
  8023. this.init(this.chart.renderer, merge(true, this.options, options), this.chart);
  8024. };
  8025. /**
  8026. * Update position option in the Scrollbar, with normalized 0-1 scale
  8027. *
  8028. * @private
  8029. * @function Highcharts.Scrollbar#updatePosition
  8030. * @param {number} from
  8031. * @param {number} to
  8032. * @return {void}
  8033. */
  8034. Scrollbar.prototype.updatePosition = function (from, to) {
  8035. if (to > 1) {
  8036. from = correctFloat(1 - correctFloat(to - from));
  8037. to = 1;
  8038. }
  8039. if (from < 0) {
  8040. to = correctFloat(to - from);
  8041. from = 0;
  8042. }
  8043. this.from = from;
  8044. this.to = to;
  8045. };
  8046. /* *
  8047. *
  8048. * Static Properties
  8049. *
  8050. * */
  8051. /**
  8052. *
  8053. * The scrollbar is a means of panning over the X axis of a stock chart.
  8054. * Scrollbars can also be applied to other types of axes.
  8055. *
  8056. * Another approach to scrollable charts is the [chart.scrollablePlotArea](
  8057. * https://api.highcharts.com/highcharts/chart.scrollablePlotArea) option that
  8058. * is especially suitable for simpler cartesian charts on mobile.
  8059. *
  8060. * In styled mode, all the presentational options for the
  8061. * scrollbar are replaced by the classes `.highcharts-scrollbar-thumb`,
  8062. * `.highcharts-scrollbar-arrow`, `.highcharts-scrollbar-button`,
  8063. * `.highcharts-scrollbar-rifles` and `.highcharts-scrollbar-track`.
  8064. *
  8065. * @sample stock/yaxis/inverted-bar-scrollbar/
  8066. * A scrollbar on a simple bar chart
  8067. *
  8068. * @product highstock gantt
  8069. * @optionparent scrollbar
  8070. *
  8071. * @private
  8072. */
  8073. Scrollbar.defaultOptions = {
  8074. /**
  8075. * The height of the scrollbar. The height also applies to the width
  8076. * of the scroll arrows so that they are always squares. Defaults to
  8077. * 20 for touch devices and 14 for mouse devices.
  8078. *
  8079. * @sample stock/scrollbar/height/
  8080. * A 30px scrollbar
  8081. *
  8082. * @type {number}
  8083. * @default 20/14
  8084. */
  8085. height: isTouchDevice ? 20 : 14,
  8086. /**
  8087. * The border rounding radius of the bar.
  8088. *
  8089. * @sample stock/scrollbar/style/
  8090. * Scrollbar styling
  8091. */
  8092. barBorderRadius: 0,
  8093. /**
  8094. * The corner radius of the scrollbar buttons.
  8095. *
  8096. * @sample stock/scrollbar/style/
  8097. * Scrollbar styling
  8098. */
  8099. buttonBorderRadius: 0,
  8100. /**
  8101. * Enable or disable the scrollbar.
  8102. *
  8103. * @sample stock/scrollbar/enabled/
  8104. * Disable the scrollbar, only use navigator
  8105. *
  8106. * @type {boolean}
  8107. * @default true
  8108. * @apioption scrollbar.enabled
  8109. */
  8110. /**
  8111. * Whether to redraw the main chart as the scrollbar or the navigator
  8112. * zoomed window is moved. Defaults to `true` for modern browsers and
  8113. * `false` for legacy IE browsers as well as mobile devices.
  8114. *
  8115. * @sample stock/scrollbar/liveredraw
  8116. * Setting live redraw to false
  8117. *
  8118. * @type {boolean}
  8119. * @since 1.3
  8120. */
  8121. liveRedraw: void 0,
  8122. /**
  8123. * The margin between the scrollbar and its axis when the scrollbar is
  8124. * applied directly to an axis.
  8125. */
  8126. margin: 10,
  8127. /**
  8128. * The minimum width of the scrollbar.
  8129. *
  8130. * @since 1.2.5
  8131. */
  8132. minWidth: 6,
  8133. /**
  8134. * Whether to show or hide the scrollbar when the scrolled content is
  8135. * zoomed out to it full extent.
  8136. *
  8137. * @type {boolean}
  8138. * @default true
  8139. * @apioption scrollbar.showFull
  8140. */
  8141. step: 0.2,
  8142. /**
  8143. * The z index of the scrollbar group.
  8144. */
  8145. zIndex: 3,
  8146. /**
  8147. * The background color of the scrollbar itself.
  8148. *
  8149. * @sample stock/scrollbar/style/
  8150. * Scrollbar styling
  8151. *
  8152. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8153. */
  8154. barBackgroundColor: '#cccccc',
  8155. /**
  8156. * The width of the bar's border.
  8157. *
  8158. * @sample stock/scrollbar/style/
  8159. * Scrollbar styling
  8160. */
  8161. barBorderWidth: 1,
  8162. /**
  8163. * The color of the scrollbar's border.
  8164. *
  8165. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8166. */
  8167. barBorderColor: '#cccccc',
  8168. /**
  8169. * The color of the small arrow inside the scrollbar buttons.
  8170. *
  8171. * @sample stock/scrollbar/style/
  8172. * Scrollbar styling
  8173. *
  8174. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8175. */
  8176. buttonArrowColor: '#333333',
  8177. /**
  8178. * The color of scrollbar buttons.
  8179. *
  8180. * @sample stock/scrollbar/style/
  8181. * Scrollbar styling
  8182. *
  8183. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8184. */
  8185. buttonBackgroundColor: '#e6e6e6',
  8186. /**
  8187. * The color of the border of the scrollbar buttons.
  8188. *
  8189. * @sample stock/scrollbar/style/
  8190. * Scrollbar styling
  8191. *
  8192. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8193. */
  8194. buttonBorderColor: '#cccccc',
  8195. /**
  8196. * The border width of the scrollbar buttons.
  8197. *
  8198. * @sample stock/scrollbar/style/
  8199. * Scrollbar styling
  8200. */
  8201. buttonBorderWidth: 1,
  8202. /**
  8203. * The color of the small rifles in the middle of the scrollbar.
  8204. *
  8205. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8206. */
  8207. rifleColor: '#333333',
  8208. /**
  8209. * The color of the track background.
  8210. *
  8211. * @sample stock/scrollbar/style/
  8212. * Scrollbar styling
  8213. *
  8214. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8215. */
  8216. trackBackgroundColor: '#f2f2f2',
  8217. /**
  8218. * The color of the border of the scrollbar track.
  8219. *
  8220. * @sample stock/scrollbar/style/
  8221. * Scrollbar styling
  8222. *
  8223. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8224. */
  8225. trackBorderColor: '#f2f2f2',
  8226. /**
  8227. * The corner radius of the border of the scrollbar track.
  8228. *
  8229. * @sample stock/scrollbar/style/
  8230. * Scrollbar styling
  8231. *
  8232. * @type {number}
  8233. * @default 0
  8234. * @apioption scrollbar.trackBorderRadius
  8235. */
  8236. /**
  8237. * The width of the border of the scrollbar track.
  8238. *
  8239. * @sample stock/scrollbar/style/
  8240. * Scrollbar styling
  8241. */
  8242. trackBorderWidth: 1
  8243. };
  8244. return Scrollbar;
  8245. }());
  8246. if (!H.Scrollbar) {
  8247. defaultOptions.scrollbar = merge(true, Scrollbar.defaultOptions, defaultOptions.scrollbar);
  8248. H.Scrollbar = Scrollbar;
  8249. ScrollbarAxis.compose(Axis, Scrollbar);
  8250. }
  8251. return H.Scrollbar;
  8252. });
  8253. _registerModule(_modules, 'Extensions/RangeSelector.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Utilities.js']], function (Axis, Chart, H, O, SVGElement, U) {
  8254. /* *
  8255. *
  8256. * (c) 2010-2020 Torstein Honsi
  8257. *
  8258. * License: www.highcharts.com/license
  8259. *
  8260. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8261. *
  8262. * */
  8263. var defaultOptions = O.defaultOptions;
  8264. var addEvent = U.addEvent,
  8265. createElement = U.createElement,
  8266. css = U.css,
  8267. defined = U.defined,
  8268. destroyObjectProperties = U.destroyObjectProperties,
  8269. discardElement = U.discardElement,
  8270. extend = U.extend,
  8271. fireEvent = U.fireEvent,
  8272. isNumber = U.isNumber,
  8273. merge = U.merge,
  8274. objectEach = U.objectEach,
  8275. pick = U.pick,
  8276. pInt = U.pInt,
  8277. splat = U.splat;
  8278. /**
  8279. * Define the time span for the button
  8280. *
  8281. * @typedef {"all"|"day"|"hour"|"millisecond"|"minute"|"month"|"second"|"week"|"year"|"ytd"} Highcharts.RangeSelectorButtonTypeValue
  8282. */
  8283. /**
  8284. * Callback function to react on button clicks.
  8285. *
  8286. * @callback Highcharts.RangeSelectorClickCallbackFunction
  8287. *
  8288. * @param {global.Event} e
  8289. * Event arguments.
  8290. *
  8291. * @param {boolean|undefined}
  8292. * Return false to cancel the default button event.
  8293. */
  8294. /**
  8295. * Callback function to parse values entered in the input boxes and return a
  8296. * valid JavaScript time as milliseconds since 1970.
  8297. *
  8298. * @callback Highcharts.RangeSelectorParseCallbackFunction
  8299. *
  8300. * @param {string} value
  8301. * Input value to parse.
  8302. *
  8303. * @return {number}
  8304. * Parsed JavaScript time value.
  8305. */
  8306. /* ************************************************************************** *
  8307. * Start Range Selector code *
  8308. * ************************************************************************** */
  8309. extend(defaultOptions, {
  8310. /**
  8311. * The range selector is a tool for selecting ranges to display within
  8312. * the chart. It provides buttons to select preconfigured ranges in
  8313. * the chart, like 1 day, 1 week, 1 month etc. It also provides input
  8314. * boxes where min and max dates can be manually input.
  8315. *
  8316. * @product highstock gantt
  8317. * @optionparent rangeSelector
  8318. */
  8319. rangeSelector: {
  8320. /**
  8321. * Whether to enable all buttons from the start. By default buttons are
  8322. * only enabled if the corresponding time range exists on the X axis,
  8323. * but enabling all buttons allows for dynamically loading different
  8324. * time ranges.
  8325. *
  8326. * @sample {highstock} stock/rangeselector/allbuttonsenabled-true/
  8327. * All buttons enabled
  8328. *
  8329. * @type {boolean}
  8330. * @default false
  8331. * @since 2.0.3
  8332. * @apioption rangeSelector.allButtonsEnabled
  8333. */
  8334. /**
  8335. * An array of configuration objects for the buttons.
  8336. *
  8337. * Defaults to:
  8338. * ```js
  8339. * buttons: [{
  8340. * type: 'month',
  8341. * count: 1,
  8342. * text: '1m'
  8343. * }, {
  8344. * type: 'month',
  8345. * count: 3,
  8346. * text: '3m'
  8347. * }, {
  8348. * type: 'month',
  8349. * count: 6,
  8350. * text: '6m'
  8351. * }, {
  8352. * type: 'ytd',
  8353. * text: 'YTD'
  8354. * }, {
  8355. * type: 'year',
  8356. * count: 1,
  8357. * text: '1y'
  8358. * }, {
  8359. * type: 'all',
  8360. * text: 'All'
  8361. * }]
  8362. * ```
  8363. *
  8364. * @sample {highstock} stock/rangeselector/datagrouping/
  8365. * Data grouping by buttons
  8366. *
  8367. * @type {Array<*>}
  8368. * @apioption rangeSelector.buttons
  8369. */
  8370. /**
  8371. * How many units of the defined type the button should span. If `type`
  8372. * is "month" and `count` is 3, the button spans three months.
  8373. *
  8374. * @type {number}
  8375. * @default 1
  8376. * @apioption rangeSelector.buttons.count
  8377. */
  8378. /**
  8379. * Fires when clicking on the rangeSelector button. One parameter,
  8380. * event, is passed to the function, containing common event
  8381. * information.
  8382. *
  8383. * ```js
  8384. * click: function(e) {
  8385. * console.log(this);
  8386. * }
  8387. * ```
  8388. *
  8389. * Return false to stop default button's click action.
  8390. *
  8391. * @sample {highstock} stock/rangeselector/button-click/
  8392. * Click event on the button
  8393. *
  8394. * @type {Highcharts.RangeSelectorClickCallbackFunction}
  8395. * @apioption rangeSelector.buttons.events.click
  8396. */
  8397. /**
  8398. * Additional range (in milliseconds) added to the end of the calculated
  8399. * time span.
  8400. *
  8401. * @sample {highstock} stock/rangeselector/min-max-offsets/
  8402. * Button offsets
  8403. *
  8404. * @type {number}
  8405. * @default 0
  8406. * @since 6.0.0
  8407. * @apioption rangeSelector.buttons.offsetMax
  8408. */
  8409. /**
  8410. * Additional range (in milliseconds) added to the start of the
  8411. * calculated time span.
  8412. *
  8413. * @sample {highstock} stock/rangeselector/min-max-offsets/
  8414. * Button offsets
  8415. *
  8416. * @type {number}
  8417. * @default 0
  8418. * @since 6.0.0
  8419. * @apioption rangeSelector.buttons.offsetMin
  8420. */
  8421. /**
  8422. * When buttons apply dataGrouping on a series, by default zooming
  8423. * in/out will deselect buttons and unset dataGrouping. Enable this
  8424. * option to keep buttons selected when extremes change.
  8425. *
  8426. * @sample {highstock} stock/rangeselector/preserve-datagrouping/
  8427. * Different preserveDataGrouping settings
  8428. *
  8429. * @type {boolean}
  8430. * @default false
  8431. * @since 6.1.2
  8432. * @apioption rangeSelector.buttons.preserveDataGrouping
  8433. */
  8434. /**
  8435. * A custom data grouping object for each button.
  8436. *
  8437. * @see [series.dataGrouping](#plotOptions.series.dataGrouping)
  8438. *
  8439. * @sample {highstock} stock/rangeselector/datagrouping/
  8440. * Data grouping by range selector buttons
  8441. *
  8442. * @type {*}
  8443. * @extends plotOptions.series.dataGrouping
  8444. * @apioption rangeSelector.buttons.dataGrouping
  8445. */
  8446. /**
  8447. * The text for the button itself.
  8448. *
  8449. * @type {string}
  8450. * @apioption rangeSelector.buttons.text
  8451. */
  8452. /**
  8453. * Defined the time span for the button. Can be one of `millisecond`,
  8454. * `second`, `minute`, `hour`, `day`, `week`, `month`, `year`, `ytd`,
  8455. * and `all`.
  8456. *
  8457. * @type {Highcharts.RangeSelectorButtonTypeValue}
  8458. * @apioption rangeSelector.buttons.type
  8459. */
  8460. /**
  8461. * The space in pixels between the buttons in the range selector.
  8462. *
  8463. * @type {number}
  8464. * @default 0
  8465. * @apioption rangeSelector.buttonSpacing
  8466. */
  8467. /**
  8468. * Enable or disable the range selector.
  8469. *
  8470. * @sample {highstock} stock/rangeselector/enabled/
  8471. * Disable the range selector
  8472. *
  8473. * @type {boolean}
  8474. * @default true
  8475. * @apioption rangeSelector.enabled
  8476. */
  8477. /**
  8478. * The vertical alignment of the rangeselector box. Allowed properties
  8479. * are `top`, `middle`, `bottom`.
  8480. *
  8481. * @sample {highstock} stock/rangeselector/vertical-align-middle/
  8482. * Middle
  8483. * @sample {highstock} stock/rangeselector/vertical-align-bottom/
  8484. * Bottom
  8485. *
  8486. * @type {Highcharts.VerticalAlignValue}
  8487. * @since 6.0.0
  8488. */
  8489. verticalAlign: 'top',
  8490. /**
  8491. * A collection of attributes for the buttons. The object takes SVG
  8492. * attributes like `fill`, `stroke`, `stroke-width`, as well as `style`,
  8493. * a collection of CSS properties for the text.
  8494. *
  8495. * The object can also be extended with states, so you can set
  8496. * presentational options for `hover`, `select` or `disabled` button
  8497. * states.
  8498. *
  8499. * CSS styles for the text label.
  8500. *
  8501. * In styled mode, the buttons are styled by the
  8502. * `.highcharts-range-selector-buttons .highcharts-button` rule with its
  8503. * different states.
  8504. *
  8505. * @sample {highstock} stock/rangeselector/styling/
  8506. * Styling the buttons and inputs
  8507. *
  8508. * @type {Highcharts.SVGAttributes}
  8509. */
  8510. buttonTheme: {
  8511. /** @ignore */
  8512. width: 28,
  8513. /** @ignore */
  8514. height: 18,
  8515. /** @ignore */
  8516. padding: 2,
  8517. /** @ignore */
  8518. zIndex: 7 // #484, #852
  8519. },
  8520. /**
  8521. * When the rangeselector is floating, the plot area does not reserve
  8522. * space for it. This opens for positioning anywhere on the chart.
  8523. *
  8524. * @sample {highstock} stock/rangeselector/floating/
  8525. * Placing the range selector between the plot area and the
  8526. * navigator
  8527. *
  8528. * @since 6.0.0
  8529. */
  8530. floating: false,
  8531. /**
  8532. * The x offset of the range selector relative to its horizontal
  8533. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  8534. *
  8535. * @since 6.0.0
  8536. */
  8537. x: 0,
  8538. /**
  8539. * The y offset of the range selector relative to its horizontal
  8540. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  8541. *
  8542. * @since 6.0.0
  8543. */
  8544. y: 0,
  8545. /**
  8546. * Deprecated. The height of the range selector. Currently it is
  8547. * calculated dynamically.
  8548. *
  8549. * @deprecated
  8550. * @type {number|undefined}
  8551. * @since 2.1.9
  8552. */
  8553. height: void 0,
  8554. /**
  8555. * The border color of the date input boxes.
  8556. *
  8557. * @sample {highstock} stock/rangeselector/styling/
  8558. * Styling the buttons and inputs
  8559. *
  8560. * @type {Highcharts.ColorString}
  8561. * @default #cccccc
  8562. * @since 1.3.7
  8563. * @apioption rangeSelector.inputBoxBorderColor
  8564. */
  8565. /**
  8566. * The pixel height of the date input boxes.
  8567. *
  8568. * @sample {highstock} stock/rangeselector/styling/
  8569. * Styling the buttons and inputs
  8570. *
  8571. * @type {number}
  8572. * @default 17
  8573. * @since 1.3.7
  8574. * @apioption rangeSelector.inputBoxHeight
  8575. */
  8576. /**
  8577. * CSS for the container DIV holding the input boxes. Deprecated as
  8578. * of 1.2.5\. Use [inputPosition](#rangeSelector.inputPosition) instead.
  8579. *
  8580. * @sample {highstock} stock/rangeselector/styling/
  8581. * Styling the buttons and inputs
  8582. *
  8583. * @deprecated
  8584. * @type {Highcharts.CSSObject}
  8585. * @apioption rangeSelector.inputBoxStyle
  8586. */
  8587. /**
  8588. * The pixel width of the date input boxes.
  8589. *
  8590. * @sample {highstock} stock/rangeselector/styling/
  8591. * Styling the buttons and inputs
  8592. *
  8593. * @type {number}
  8594. * @default 90
  8595. * @since 1.3.7
  8596. * @apioption rangeSelector.inputBoxWidth
  8597. */
  8598. /**
  8599. * The date format in the input boxes when not selected for editing.
  8600. * Defaults to `%b %e, %Y`.
  8601. *
  8602. * @sample {highstock} stock/rangeselector/input-format/
  8603. * Milliseconds in the range selector
  8604. *
  8605. * @type {string}
  8606. * @default %b %e, %Y
  8607. * @apioption rangeSelector.inputDateFormat
  8608. */
  8609. /**
  8610. * A custom callback function to parse values entered in the input boxes
  8611. * and return a valid JavaScript time as milliseconds since 1970.
  8612. * The first argument passed is a value to parse,
  8613. * second is a boolean indicating use of the UTC time.
  8614. *
  8615. * @sample {highstock} stock/rangeselector/input-format/
  8616. * Milliseconds in the range selector
  8617. *
  8618. * @type {Highcharts.RangeSelectorParseCallbackFunction}
  8619. * @since 1.3.3
  8620. * @apioption rangeSelector.inputDateParser
  8621. */
  8622. /**
  8623. * The date format in the input boxes when they are selected for
  8624. * editing. This must be a format that is recognized by JavaScript
  8625. * Date.parse.
  8626. *
  8627. * @sample {highstock} stock/rangeselector/input-format/
  8628. * Milliseconds in the range selector
  8629. *
  8630. * @type {string}
  8631. * @default %Y-%m-%d
  8632. * @apioption rangeSelector.inputEditDateFormat
  8633. */
  8634. /**
  8635. * Enable or disable the date input boxes. Defaults to enabled when
  8636. * there is enough space, disabled if not (typically mobile).
  8637. *
  8638. * @sample {highstock} stock/rangeselector/input-datepicker/
  8639. * Extending the input with a jQuery UI datepicker
  8640. *
  8641. * @type {boolean}
  8642. * @default true
  8643. * @apioption rangeSelector.inputEnabled
  8644. */
  8645. /**
  8646. * Positioning for the input boxes. Allowed properties are `align`,
  8647. * `x` and `y`.
  8648. *
  8649. * @since 1.2.4
  8650. */
  8651. inputPosition: {
  8652. /**
  8653. * The alignment of the input box. Allowed properties are `left`,
  8654. * `center`, `right`.
  8655. *
  8656. * @sample {highstock} stock/rangeselector/input-button-position/
  8657. * Alignment
  8658. *
  8659. * @type {Highcharts.AlignValue}
  8660. * @since 6.0.0
  8661. */
  8662. align: 'right',
  8663. /**
  8664. * X offset of the input row.
  8665. */
  8666. x: 0,
  8667. /**
  8668. * Y offset of the input row.
  8669. */
  8670. y: 0
  8671. },
  8672. /**
  8673. * The index of the button to appear pre-selected.
  8674. *
  8675. * @type {number}
  8676. * @apioption rangeSelector.selected
  8677. */
  8678. /**
  8679. * Positioning for the button row.
  8680. *
  8681. * @since 1.2.4
  8682. */
  8683. buttonPosition: {
  8684. /**
  8685. * The alignment of the input box. Allowed properties are `left`,
  8686. * `center`, `right`.
  8687. *
  8688. * @sample {highstock} stock/rangeselector/input-button-position/
  8689. * Alignment
  8690. *
  8691. * @type {Highcharts.AlignValue}
  8692. * @since 6.0.0
  8693. */
  8694. align: 'left',
  8695. /**
  8696. * X offset of the button row.
  8697. */
  8698. x: 0,
  8699. /**
  8700. * Y offset of the button row.
  8701. */
  8702. y: 0
  8703. },
  8704. /**
  8705. * CSS for the HTML inputs in the range selector.
  8706. *
  8707. * In styled mode, the inputs are styled by the
  8708. * `.highcharts-range-input text` rule in SVG mode, and
  8709. * `input.highcharts-range-selector` when active.
  8710. *
  8711. * @sample {highstock} stock/rangeselector/styling/
  8712. * Styling the buttons and inputs
  8713. *
  8714. * @type {Highcharts.CSSObject}
  8715. * @apioption rangeSelector.inputStyle
  8716. */
  8717. /**
  8718. * CSS styles for the labels - the Zoom, From and To texts.
  8719. *
  8720. * In styled mode, the labels are styled by the
  8721. * `.highcharts-range-label` class.
  8722. *
  8723. * @sample {highstock} stock/rangeselector/styling/
  8724. * Styling the buttons and inputs
  8725. *
  8726. * @type {Highcharts.CSSObject}
  8727. */
  8728. labelStyle: {
  8729. /** @ignore */
  8730. color: '#666666'
  8731. }
  8732. }
  8733. });
  8734. defaultOptions.lang = merge(defaultOptions.lang,
  8735. /**
  8736. * Language object. The language object is global and it can't be set
  8737. * on each chart initialization. Instead, use `Highcharts.setOptions` to
  8738. * set it before any chart is initialized.
  8739. *
  8740. * ```js
  8741. * Highcharts.setOptions({
  8742. * lang: {
  8743. * months: [
  8744. * 'Janvier', 'Février', 'Mars', 'Avril',
  8745. * 'Mai', 'Juin', 'Juillet', 'Août',
  8746. * 'Septembre', 'Octobre', 'Novembre', 'Décembre'
  8747. * ],
  8748. * weekdays: [
  8749. * 'Dimanche', 'Lundi', 'Mardi', 'Mercredi',
  8750. * 'Jeudi', 'Vendredi', 'Samedi'
  8751. * ]
  8752. * }
  8753. * });
  8754. * ```
  8755. *
  8756. * @optionparent lang
  8757. */
  8758. {
  8759. /**
  8760. * The text for the label for the range selector buttons.
  8761. *
  8762. * @product highstock gantt
  8763. */
  8764. rangeSelectorZoom: 'Zoom',
  8765. /**
  8766. * The text for the label for the "from" input box in the range
  8767. * selector.
  8768. *
  8769. * @product highstock gantt
  8770. */
  8771. rangeSelectorFrom: 'From',
  8772. /**
  8773. * The text for the label for the "to" input box in the range selector.
  8774. *
  8775. * @product highstock gantt
  8776. */
  8777. rangeSelectorTo: 'To'
  8778. });
  8779. /* eslint-disable no-invalid-this, valid-jsdoc */
  8780. /**
  8781. * The range selector.
  8782. *
  8783. * @private
  8784. * @class
  8785. * @name Highcharts.RangeSelector
  8786. * @param {Highcharts.Chart} chart
  8787. */
  8788. var RangeSelector = /** @class */ (function () {
  8789. function RangeSelector(chart) {
  8790. /* *
  8791. *
  8792. * Properties
  8793. *
  8794. * */
  8795. this.buttons = void 0;
  8796. this.buttonOptions = RangeSelector.prototype.defaultButtons;
  8797. this.options = void 0;
  8798. this.chart = chart;
  8799. // Run RangeSelector
  8800. this.init(chart);
  8801. }
  8802. /**
  8803. * The method to run when one of the buttons in the range selectors is
  8804. * clicked
  8805. *
  8806. * @private
  8807. * @function Highcharts.RangeSelector#clickButton
  8808. * @param {number} i
  8809. * The index of the button
  8810. * @param {boolean} [redraw]
  8811. * @return {void}
  8812. */
  8813. RangeSelector.prototype.clickButton = function (i, redraw) {
  8814. var rangeSelector = this,
  8815. chart = rangeSelector.chart,
  8816. rangeOptions = rangeSelector.buttonOptions[i],
  8817. baseAxis = chart.xAxis[0],
  8818. unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || baseAxis || {},
  8819. dataMin = unionExtremes.dataMin,
  8820. dataMax = unionExtremes.dataMax,
  8821. newMin,
  8822. newMax = baseAxis && Math.round(Math.min(baseAxis.max,
  8823. pick(dataMax,
  8824. baseAxis.max))), // #1568
  8825. type = rangeOptions.type,
  8826. baseXAxisOptions,
  8827. range = rangeOptions._range,
  8828. rangeMin,
  8829. minSetting,
  8830. rangeSetting,
  8831. ctx,
  8832. ytdExtremes,
  8833. dataGrouping = rangeOptions.dataGrouping;
  8834. // chart has no data, base series is removed
  8835. if (dataMin === null || dataMax === null) {
  8836. return;
  8837. }
  8838. // Set the fixed range before range is altered
  8839. chart.fixedRange = range;
  8840. // Apply dataGrouping associated to button
  8841. if (dataGrouping) {
  8842. this.forcedDataGrouping = true;
  8843. Axis.prototype.setDataGrouping.call(baseAxis || { chart: this.chart }, dataGrouping, false);
  8844. this.frozenStates = rangeOptions.preserveDataGrouping;
  8845. }
  8846. // Apply range
  8847. if (type === 'month' || type === 'year') {
  8848. if (!baseAxis) {
  8849. // This is set to the user options and picked up later when the
  8850. // axis is instantiated so that we know the min and max.
  8851. range = rangeOptions;
  8852. }
  8853. else {
  8854. ctx = {
  8855. range: rangeOptions,
  8856. max: newMax,
  8857. chart: chart,
  8858. dataMin: dataMin,
  8859. dataMax: dataMax
  8860. };
  8861. newMin = baseAxis.minFromRange.call(ctx);
  8862. if (isNumber(ctx.newMax)) {
  8863. newMax = ctx.newMax;
  8864. }
  8865. }
  8866. // Fixed times like minutes, hours, days
  8867. }
  8868. else if (range) {
  8869. newMin = Math.max(newMax - range, dataMin);
  8870. newMax = Math.min(newMin + range, dataMax);
  8871. }
  8872. else if (type === 'ytd') {
  8873. // On user clicks on the buttons, or a delayed action running from
  8874. // the beforeRender event (below), the baseAxis is defined.
  8875. if (baseAxis) {
  8876. // When "ytd" is the pre-selected button for the initial view,
  8877. // its calculation is delayed and rerun in the beforeRender
  8878. // event (below). When the series are initialized, but before
  8879. // the chart is rendered, we have access to the xData array
  8880. // (#942).
  8881. if (typeof dataMax === 'undefined') {
  8882. dataMin = Number.MAX_VALUE;
  8883. dataMax = Number.MIN_VALUE;
  8884. chart.series.forEach(function (series) {
  8885. // reassign it to the last item
  8886. var xData = series.xData;
  8887. dataMin = Math.min(xData[0], dataMin);
  8888. dataMax = Math.max(xData[xData.length - 1], dataMax);
  8889. });
  8890. redraw = false;
  8891. }
  8892. ytdExtremes = rangeSelector.getYTDExtremes(dataMax, dataMin, chart.time.useUTC);
  8893. newMin = rangeMin = ytdExtremes.min;
  8894. newMax = ytdExtremes.max;
  8895. // "ytd" is pre-selected. We don't yet have access to processed
  8896. // point and extremes data (things like pointStart and pointInterval
  8897. // are missing), so we delay the process (#942)
  8898. }
  8899. else {
  8900. rangeSelector.deferredYTDClick = i;
  8901. return;
  8902. }
  8903. }
  8904. else if (type === 'all' && baseAxis) {
  8905. newMin = dataMin;
  8906. newMax = dataMax;
  8907. }
  8908. if (defined(newMin)) {
  8909. newMin += rangeOptions._offsetMin;
  8910. }
  8911. if (defined(newMax)) {
  8912. newMax += rangeOptions._offsetMax;
  8913. }
  8914. rangeSelector.setSelected(i);
  8915. // Update the chart
  8916. if (!baseAxis) {
  8917. // Axis not yet instanciated. Temporarily set min and range
  8918. // options and remove them on chart load (#4317).
  8919. baseXAxisOptions = splat(chart.options.xAxis)[0];
  8920. rangeSetting = baseXAxisOptions.range;
  8921. baseXAxisOptions.range = range;
  8922. minSetting = baseXAxisOptions.min;
  8923. baseXAxisOptions.min = rangeMin;
  8924. addEvent(chart, 'load', function resetMinAndRange() {
  8925. baseXAxisOptions.range = rangeSetting;
  8926. baseXAxisOptions.min = minSetting;
  8927. });
  8928. }
  8929. else {
  8930. // Existing axis object. Set extremes after render time.
  8931. baseAxis.setExtremes(newMin, newMax, pick(redraw, 1), null, // auto animation
  8932. {
  8933. trigger: 'rangeSelectorButton',
  8934. rangeSelectorButton: rangeOptions
  8935. });
  8936. }
  8937. };
  8938. /**
  8939. * Set the selected option. This method only sets the internal flag, it
  8940. * doesn't update the buttons or the actual zoomed range.
  8941. *
  8942. * @private
  8943. * @function Highcharts.RangeSelector#setSelected
  8944. * @param {number} [selected]
  8945. * @return {void}
  8946. */
  8947. RangeSelector.prototype.setSelected = function (selected) {
  8948. this.selected = this.options.selected = selected;
  8949. };
  8950. /**
  8951. * Initialize the range selector
  8952. *
  8953. * @private
  8954. * @function Highcharts.RangeSelector#init
  8955. * @param {Highcharts.Chart} chart
  8956. * @return {void}
  8957. */
  8958. RangeSelector.prototype.init = function (chart) {
  8959. var rangeSelector = this,
  8960. options = chart.options.rangeSelector,
  8961. buttonOptions = options.buttons || rangeSelector.defaultButtons.slice(),
  8962. selectedOption = options.selected,
  8963. blurInputs = function () {
  8964. var minInput = rangeSelector.minInput,
  8965. maxInput = rangeSelector.maxInput;
  8966. // #3274 in some case blur is not defined
  8967. if (minInput && minInput.blur) {
  8968. fireEvent(minInput, 'blur');
  8969. }
  8970. if (maxInput && maxInput.blur) {
  8971. fireEvent(maxInput, 'blur');
  8972. }
  8973. };
  8974. rangeSelector.chart = chart;
  8975. rangeSelector.options = options;
  8976. rangeSelector.buttons = [];
  8977. rangeSelector.buttonOptions = buttonOptions;
  8978. this.unMouseDown = addEvent(chart.container, 'mousedown', blurInputs);
  8979. this.unResize = addEvent(chart, 'resize', blurInputs);
  8980. // Extend the buttonOptions with actual range
  8981. buttonOptions.forEach(rangeSelector.computeButtonRange);
  8982. // zoomed range based on a pre-selected button index
  8983. if (typeof selectedOption !== 'undefined' &&
  8984. buttonOptions[selectedOption]) {
  8985. this.clickButton(selectedOption, false);
  8986. }
  8987. addEvent(chart, 'load', function () {
  8988. // If a data grouping is applied to the current button, release it
  8989. // when extremes change
  8990. if (chart.xAxis && chart.xAxis[0]) {
  8991. addEvent(chart.xAxis[0], 'setExtremes', function (e) {
  8992. if (this.max - this.min !==
  8993. chart.fixedRange &&
  8994. e.trigger !== 'rangeSelectorButton' &&
  8995. e.trigger !== 'updatedData' &&
  8996. rangeSelector.forcedDataGrouping &&
  8997. !rangeSelector.frozenStates) {
  8998. this.setDataGrouping(false, false);
  8999. }
  9000. });
  9001. }
  9002. });
  9003. };
  9004. /**
  9005. * Dynamically update the range selector buttons after a new range has been
  9006. * set
  9007. *
  9008. * @private
  9009. * @function Highcharts.RangeSelector#updateButtonStates
  9010. * @return {void}
  9011. */
  9012. RangeSelector.prototype.updateButtonStates = function () {
  9013. var rangeSelector = this,
  9014. chart = this.chart,
  9015. baseAxis = chart.xAxis[0],
  9016. actualRange = Math.round(baseAxis.max - baseAxis.min),
  9017. hasNoData = !baseAxis.hasVisibleSeries,
  9018. day = 24 * 36e5, // A single day in milliseconds
  9019. unionExtremes = (chart.scroller &&
  9020. chart.scroller.getUnionExtremes()) || baseAxis,
  9021. dataMin = unionExtremes.dataMin,
  9022. dataMax = unionExtremes.dataMax,
  9023. ytdExtremes = rangeSelector.getYTDExtremes(dataMax,
  9024. dataMin,
  9025. chart.time.useUTC),
  9026. ytdMin = ytdExtremes.min,
  9027. ytdMax = ytdExtremes.max,
  9028. selected = rangeSelector.selected,
  9029. selectedExists = isNumber(selected),
  9030. allButtonsEnabled = rangeSelector.options.allButtonsEnabled,
  9031. buttons = rangeSelector.buttons;
  9032. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  9033. var range = rangeOptions._range,
  9034. type = rangeOptions.type,
  9035. count = rangeOptions.count || 1,
  9036. button = buttons[i],
  9037. state = 0,
  9038. disable,
  9039. select,
  9040. offsetRange = rangeOptions._offsetMax -
  9041. rangeOptions._offsetMin,
  9042. isSelected = i === selected,
  9043. // Disable buttons where the range exceeds what is allowed in
  9044. // the current view
  9045. isTooGreatRange = range >
  9046. dataMax - dataMin,
  9047. // Disable buttons where the range is smaller than the minimum
  9048. // range
  9049. isTooSmallRange = range < baseAxis.minRange,
  9050. // Do not select the YTD button if not explicitly told so
  9051. isYTDButNotSelected = false,
  9052. // Disable the All button if we're already showing all
  9053. isAllButAlreadyShowingAll = false,
  9054. isSameRange = range === actualRange;
  9055. // Months and years have a variable range so we check the extremes
  9056. if ((type === 'month' || type === 'year') &&
  9057. (actualRange + 36e5 >=
  9058. { month: 28, year: 365 }[type] * day * count - offsetRange) &&
  9059. (actualRange - 36e5 <=
  9060. { month: 31, year: 366 }[type] * day * count + offsetRange)) {
  9061. isSameRange = true;
  9062. }
  9063. else if (type === 'ytd') {
  9064. isSameRange = (ytdMax - ytdMin + offsetRange) === actualRange;
  9065. isYTDButNotSelected = !isSelected;
  9066. }
  9067. else if (type === 'all') {
  9068. isSameRange = (baseAxis.max - baseAxis.min >=
  9069. dataMax - dataMin);
  9070. isAllButAlreadyShowingAll = (!isSelected &&
  9071. selectedExists &&
  9072. isSameRange);
  9073. }
  9074. // The new zoom area happens to match the range for a button - mark
  9075. // it selected. This happens when scrolling across an ordinal gap.
  9076. // It can be seen in the intraday demos when selecting 1h and scroll
  9077. // across the night gap.
  9078. disable = (!allButtonsEnabled &&
  9079. (isTooGreatRange ||
  9080. isTooSmallRange ||
  9081. isAllButAlreadyShowingAll ||
  9082. hasNoData));
  9083. select = ((isSelected && isSameRange) ||
  9084. (isSameRange && !selectedExists && !isYTDButNotSelected) ||
  9085. (isSelected && rangeSelector.frozenStates));
  9086. if (disable) {
  9087. state = 3;
  9088. }
  9089. else if (select) {
  9090. selectedExists = true; // Only one button can be selected
  9091. state = 2;
  9092. }
  9093. // If state has changed, update the button
  9094. if (button.state !== state) {
  9095. button.setState(state);
  9096. // Reset (#9209)
  9097. if (state === 0 && selected === i) {
  9098. rangeSelector.setSelected(null);
  9099. }
  9100. }
  9101. });
  9102. };
  9103. /**
  9104. * Compute and cache the range for an individual button
  9105. *
  9106. * @private
  9107. * @function Highcharts.RangeSelector#computeButtonRange
  9108. * @param {Highcharts.RangeSelectorButtonsOptions} rangeOptions
  9109. * @return {void}
  9110. */
  9111. RangeSelector.prototype.computeButtonRange = function (rangeOptions) {
  9112. var type = rangeOptions.type,
  9113. count = rangeOptions.count || 1,
  9114. // these time intervals have a fixed number of milliseconds, as
  9115. // opposed to month, ytd and year
  9116. fixedTimes = {
  9117. millisecond: 1,
  9118. second: 1000,
  9119. minute: 60 * 1000,
  9120. hour: 3600 * 1000,
  9121. day: 24 * 3600 * 1000,
  9122. week: 7 * 24 * 3600 * 1000
  9123. };
  9124. // Store the range on the button object
  9125. if (fixedTimes[type]) {
  9126. rangeOptions._range = fixedTimes[type] * count;
  9127. }
  9128. else if (type === 'month' || type === 'year') {
  9129. rangeOptions._range = {
  9130. month: 30,
  9131. year: 365
  9132. }[type] * 24 * 36e5 * count;
  9133. }
  9134. rangeOptions._offsetMin = pick(rangeOptions.offsetMin, 0);
  9135. rangeOptions._offsetMax = pick(rangeOptions.offsetMax, 0);
  9136. rangeOptions._range +=
  9137. rangeOptions._offsetMax - rangeOptions._offsetMin;
  9138. };
  9139. /**
  9140. * Set the internal and displayed value of a HTML input for the dates
  9141. *
  9142. * @private
  9143. * @function Highcharts.RangeSelector#setInputValue
  9144. * @param {string} name
  9145. * @param {number} [inputTime]
  9146. * @return {void}
  9147. */
  9148. RangeSelector.prototype.setInputValue = function (name, inputTime) {
  9149. var options = this.chart.options.rangeSelector,
  9150. time = this.chart.time,
  9151. input = this[name + 'Input'];
  9152. if (defined(inputTime)) {
  9153. input.previousValue = input.HCTime;
  9154. input.HCTime = inputTime;
  9155. }
  9156. input.value = time.dateFormat(options.inputEditDateFormat || '%Y-%m-%d', input.HCTime);
  9157. this[name + 'DateBox'].attr({
  9158. text: time.dateFormat(options.inputDateFormat || '%b %e, %Y', input.HCTime)
  9159. });
  9160. };
  9161. /**
  9162. * @private
  9163. * @function Highcharts.RangeSelector#showInput
  9164. * @param {string} name
  9165. * @return {void}
  9166. */
  9167. RangeSelector.prototype.showInput = function (name) {
  9168. var inputGroup = this.inputGroup,
  9169. dateBox = this[name + 'DateBox'];
  9170. css(this[name + 'Input'], {
  9171. left: (inputGroup.translateX + dateBox.x) + 'px',
  9172. top: inputGroup.translateY + 'px',
  9173. width: (dateBox.width - 2) + 'px',
  9174. height: (dateBox.height - 2) + 'px',
  9175. border: '2px solid silver'
  9176. });
  9177. };
  9178. /**
  9179. * @private
  9180. * @function Highcharts.RangeSelector#hideInput
  9181. * @param {string} name
  9182. * @return {void}
  9183. */
  9184. RangeSelector.prototype.hideInput = function (name) {
  9185. css(this[name + 'Input'], {
  9186. border: 0,
  9187. width: '1px',
  9188. height: '1px'
  9189. });
  9190. this.setInputValue(name);
  9191. };
  9192. /**
  9193. * @private
  9194. * @function Highcharts.RangeSelector#defaultInputDateParser
  9195. */
  9196. RangeSelector.prototype.defaultInputDateParser = function (inputDate, useUTC) {
  9197. var date = new Date();
  9198. if (H.isSafari) {
  9199. return Date.parse(inputDate.split(' ').join('T'));
  9200. }
  9201. if (useUTC) {
  9202. return Date.parse(inputDate + 'Z');
  9203. }
  9204. return Date.parse(inputDate) - date.getTimezoneOffset() * 60 * 1000;
  9205. };
  9206. /**
  9207. * Draw either the 'from' or the 'to' HTML input box of the range selector
  9208. *
  9209. * @private
  9210. * @function Highcharts.RangeSelector#drawInput
  9211. * @param {string} name
  9212. * @return {void}
  9213. */
  9214. RangeSelector.prototype.drawInput = function (name) {
  9215. var rangeSelector = this,
  9216. chart = rangeSelector.chart,
  9217. chartStyle = chart.renderer.style || {},
  9218. renderer = chart.renderer,
  9219. options = chart.options.rangeSelector,
  9220. lang = defaultOptions.lang,
  9221. div = rangeSelector.div,
  9222. isMin = name === 'min',
  9223. input,
  9224. label,
  9225. dateBox,
  9226. inputGroup = this.inputGroup,
  9227. defaultInputDateParser = this.defaultInputDateParser;
  9228. /**
  9229. * @private
  9230. */
  9231. function updateExtremes() {
  9232. var inputValue = input.value,
  9233. value,
  9234. chartAxis = chart.xAxis[0],
  9235. dataAxis = chart.scroller && chart.scroller.xAxis ?
  9236. chart.scroller.xAxis :
  9237. chartAxis,
  9238. dataMin = dataAxis.dataMin,
  9239. dataMax = dataAxis.dataMax;
  9240. value = (options.inputDateParser || defaultInputDateParser)(inputValue, chart.time.useUTC);
  9241. if (value !== input.previousValue) {
  9242. input.previousValue = value;
  9243. // If the value isn't parsed directly to a value by the
  9244. // browser's Date.parse method, like YYYY-MM-DD in IE, try
  9245. // parsing it a different way
  9246. if (!isNumber(value)) {
  9247. value = inputValue.split('-');
  9248. value = Date.UTC(pInt(value[0]), pInt(value[1]) - 1, pInt(value[2]));
  9249. }
  9250. if (isNumber(value)) {
  9251. // Correct for timezone offset (#433)
  9252. if (!chart.time.useUTC) {
  9253. value =
  9254. value + new Date().getTimezoneOffset() * 60 * 1000;
  9255. }
  9256. // Validate the extremes. If it goes beyound the data min or
  9257. // max, use the actual data extreme (#2438).
  9258. if (isMin) {
  9259. if (value > rangeSelector.maxInput.HCTime) {
  9260. value = void 0;
  9261. }
  9262. else if (value < dataMin) {
  9263. value = dataMin;
  9264. }
  9265. }
  9266. else {
  9267. if (value < rangeSelector.minInput.HCTime) {
  9268. value = void 0;
  9269. }
  9270. else if (value > dataMax) {
  9271. value = dataMax;
  9272. }
  9273. }
  9274. // Set the extremes
  9275. if (typeof value !== 'undefined') { // @todo typof undefined
  9276. chartAxis.setExtremes(isMin ? value : chartAxis.min, isMin ? chartAxis.max : value, void 0, void 0, { trigger: 'rangeSelectorInput' });
  9277. }
  9278. }
  9279. }
  9280. }
  9281. // Create the text label
  9282. this[name + 'Label'] = label = renderer
  9283. .label(lang[isMin ? 'rangeSelectorFrom' : 'rangeSelectorTo'], this.inputGroup.offset)
  9284. .addClass('highcharts-range-label')
  9285. .attr({
  9286. padding: 2
  9287. })
  9288. .add(inputGroup);
  9289. inputGroup.offset += label.width + 5;
  9290. // Create an SVG label that shows updated date ranges and and records
  9291. // click events that bring in the HTML input.
  9292. this[name + 'DateBox'] = dateBox = renderer
  9293. .label('', inputGroup.offset)
  9294. .addClass('highcharts-range-input')
  9295. .attr({
  9296. padding: 2,
  9297. width: options.inputBoxWidth || 90,
  9298. height: options.inputBoxHeight || 17,
  9299. 'text-align': 'center'
  9300. })
  9301. .on('click', function () {
  9302. // If it is already focused, the onfocus event doesn't fire
  9303. // (#3713)
  9304. rangeSelector.showInput(name);
  9305. rangeSelector[name + 'Input'].focus();
  9306. });
  9307. if (!chart.styledMode) {
  9308. dateBox.attr({
  9309. stroke: options.inputBoxBorderColor || '#cccccc',
  9310. 'stroke-width': 1
  9311. });
  9312. }
  9313. dateBox.add(inputGroup);
  9314. inputGroup.offset += dateBox.width + (isMin ? 10 : 0);
  9315. // Create the HTML input element. This is rendered as 1x1 pixel then set
  9316. // to the right size when focused.
  9317. this[name + 'Input'] = input = createElement('input', {
  9318. name: name,
  9319. className: 'highcharts-range-selector',
  9320. type: 'text'
  9321. }, {
  9322. top: chart.plotTop + 'px' // prevent jump on focus in Firefox
  9323. }, div);
  9324. if (!chart.styledMode) {
  9325. // Styles
  9326. label.css(merge(chartStyle, options.labelStyle));
  9327. dateBox.css(merge({
  9328. color: '#333333'
  9329. }, chartStyle, options.inputStyle));
  9330. css(input, extend({
  9331. position: 'absolute',
  9332. border: 0,
  9333. width: '1px',
  9334. height: '1px',
  9335. padding: 0,
  9336. textAlign: 'center',
  9337. fontSize: chartStyle.fontSize,
  9338. fontFamily: chartStyle.fontFamily,
  9339. top: '-9999em' // #4798
  9340. }, options.inputStyle));
  9341. }
  9342. // Blow up the input box
  9343. input.onfocus = function () {
  9344. rangeSelector.showInput(name);
  9345. };
  9346. // Hide away the input box
  9347. input.onblur = function () {
  9348. // update extermes only when inputs are active
  9349. if (input === H.doc.activeElement) { // Only when focused
  9350. // Update also when no `change` event is triggered, like when
  9351. // clicking inside the SVG (#4710)
  9352. updateExtremes();
  9353. }
  9354. // #10404 - move hide and blur outside focus
  9355. rangeSelector.hideInput(name);
  9356. input.blur(); // #4606
  9357. };
  9358. // handle changes in the input boxes
  9359. input.onchange = updateExtremes;
  9360. input.onkeypress = function (event) {
  9361. // IE does not fire onchange on enter
  9362. if (event.keyCode === 13) {
  9363. updateExtremes();
  9364. }
  9365. };
  9366. };
  9367. /**
  9368. * Get the position of the range selector buttons and inputs. This can be
  9369. * overridden from outside for custom positioning.
  9370. *
  9371. * @private
  9372. * @function Highcharts.RangeSelector#getPosition
  9373. *
  9374. * @return {Highcharts.Dictionary<number>}
  9375. */
  9376. RangeSelector.prototype.getPosition = function () {
  9377. var chart = this.chart,
  9378. options = chart.options.rangeSelector,
  9379. top = options.verticalAlign === 'top' ?
  9380. chart.plotTop - chart.axisOffset[0] :
  9381. 0; // set offset only for varticalAlign top
  9382. return {
  9383. buttonTop: top + options.buttonPosition.y,
  9384. inputTop: top + options.inputPosition.y - 10
  9385. };
  9386. };
  9387. /**
  9388. * Get the extremes of YTD. Will choose dataMax if its value is lower than
  9389. * the current timestamp. Will choose dataMin if its value is higher than
  9390. * the timestamp for the start of current year.
  9391. *
  9392. * @private
  9393. * @function Highcharts.RangeSelector#getYTDExtremes
  9394. *
  9395. * @param {number} dataMax
  9396. *
  9397. * @param {number} dataMin
  9398. *
  9399. * @return {*}
  9400. * Returns min and max for the YTD
  9401. */
  9402. RangeSelector.prototype.getYTDExtremes = function (dataMax, dataMin, useUTC) {
  9403. var time = this.chart.time,
  9404. min,
  9405. now = new time.Date(dataMax),
  9406. year = time.get('FullYear',
  9407. now),
  9408. startOfYear = useUTC ?
  9409. time.Date.UTC(year, 0, 1) : // eslint-disable-line new-cap
  9410. +new time.Date(year, 0, 1);
  9411. min = Math.max(dataMin || 0, startOfYear);
  9412. now = now.getTime();
  9413. return {
  9414. max: Math.min(dataMax || now, now),
  9415. min: min
  9416. };
  9417. };
  9418. /**
  9419. * Render the range selector including the buttons and the inputs. The first
  9420. * time render is called, the elements are created and positioned. On
  9421. * subsequent calls, they are moved and updated.
  9422. *
  9423. * @private
  9424. * @function Highcharts.RangeSelector#render
  9425. * @param {number} [min]
  9426. * X axis minimum
  9427. * @param {number} [max]
  9428. * X axis maximum
  9429. * @return {void}
  9430. */
  9431. RangeSelector.prototype.render = function (min, max) {
  9432. var rangeSelector = this,
  9433. chart = rangeSelector.chart,
  9434. renderer = chart.renderer,
  9435. container = chart.container,
  9436. chartOptions = chart.options,
  9437. navButtonOptions = (chartOptions.exporting &&
  9438. chartOptions.exporting.enabled !== false &&
  9439. chartOptions.navigation &&
  9440. chartOptions.navigation.buttonOptions),
  9441. lang = defaultOptions.lang,
  9442. div = rangeSelector.div,
  9443. options = chartOptions.rangeSelector,
  9444. // Place inputs above the container
  9445. inputsZIndex = pick(chartOptions.chart.style &&
  9446. chartOptions.chart.style.zIndex, 0) + 1,
  9447. floating = options.floating,
  9448. buttons = rangeSelector.buttons,
  9449. inputGroup = rangeSelector.inputGroup,
  9450. buttonTheme = options.buttonTheme,
  9451. buttonPosition = options.buttonPosition,
  9452. inputPosition = options.inputPosition,
  9453. inputEnabled = options.inputEnabled,
  9454. states = buttonTheme && buttonTheme.states,
  9455. plotLeft = chart.plotLeft,
  9456. buttonLeft,
  9457. buttonGroup = rangeSelector.buttonGroup,
  9458. group,
  9459. groupHeight,
  9460. rendered = rangeSelector.rendered,
  9461. verticalAlign = rangeSelector.options.verticalAlign,
  9462. legend = chart.legend,
  9463. legendOptions = legend && legend.options,
  9464. buttonPositionY = buttonPosition.y,
  9465. inputPositionY = inputPosition.y,
  9466. animate = chart.hasLoaded,
  9467. verb = animate ? 'animate' : 'attr',
  9468. exportingX = 0,
  9469. alignTranslateY,
  9470. legendHeight,
  9471. minPosition,
  9472. translateY = 0,
  9473. translateX;
  9474. if (options.enabled === false) {
  9475. return;
  9476. }
  9477. // create the elements
  9478. if (!rendered) {
  9479. rangeSelector.group = group = renderer.g('range-selector-group')
  9480. .attr({
  9481. zIndex: 7
  9482. })
  9483. .add();
  9484. rangeSelector.buttonGroup = buttonGroup =
  9485. renderer.g('range-selector-buttons').add(group);
  9486. rangeSelector.zoomText = renderer
  9487. .text(lang.rangeSelectorZoom, 0, 15)
  9488. .add(buttonGroup);
  9489. if (!chart.styledMode) {
  9490. rangeSelector.zoomText.css(options.labelStyle);
  9491. buttonTheme['stroke-width'] =
  9492. pick(buttonTheme['stroke-width'], 0);
  9493. }
  9494. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  9495. buttons[i] = renderer
  9496. .button(rangeOptions.text, 0, 0, function (e) {
  9497. // extract events from button object and call
  9498. var buttonEvents = (rangeOptions.events &&
  9499. rangeOptions.events.click),
  9500. callDefaultEvent;
  9501. if (buttonEvents) {
  9502. callDefaultEvent =
  9503. buttonEvents.call(rangeOptions, e);
  9504. }
  9505. if (callDefaultEvent !== false) {
  9506. rangeSelector.clickButton(i);
  9507. }
  9508. rangeSelector.isActive = true;
  9509. }, buttonTheme, states && states.hover, states && states.select, states && states.disabled)
  9510. .attr({
  9511. 'text-align': 'center'
  9512. })
  9513. .add(buttonGroup);
  9514. });
  9515. // first create a wrapper outside the container in order to make
  9516. // the inputs work and make export correct
  9517. if (inputEnabled !== false) {
  9518. rangeSelector.div = div = createElement('div', null, {
  9519. position: 'relative',
  9520. height: 0,
  9521. zIndex: inputsZIndex
  9522. });
  9523. container.parentNode.insertBefore(div, container);
  9524. // Create the group to keep the inputs
  9525. rangeSelector.inputGroup = inputGroup =
  9526. renderer.g('input-group').add(group);
  9527. inputGroup.offset = 0;
  9528. rangeSelector.drawInput('min');
  9529. rangeSelector.drawInput('max');
  9530. }
  9531. }
  9532. // #8769, allow dynamically updating margins
  9533. rangeSelector.zoomText[verb]({
  9534. x: pick(plotLeft + buttonPosition.x, plotLeft)
  9535. });
  9536. // button start position
  9537. buttonLeft = pick(plotLeft + buttonPosition.x, plotLeft) +
  9538. rangeSelector.zoomText.getBBox().width + 5;
  9539. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  9540. buttons[i][verb]({ x: buttonLeft });
  9541. // increase button position for the next button
  9542. buttonLeft += buttons[i].width + pick(options.buttonSpacing, 5);
  9543. });
  9544. plotLeft = chart.plotLeft - chart.spacing[3];
  9545. rangeSelector.updateButtonStates();
  9546. // detect collisiton with exporting
  9547. if (navButtonOptions &&
  9548. this.titleCollision(chart) &&
  9549. verticalAlign === 'top' &&
  9550. buttonPosition.align === 'right' && ((buttonPosition.y +
  9551. buttonGroup.getBBox().height - 12) <
  9552. ((navButtonOptions.y || 0) +
  9553. navButtonOptions.height))) {
  9554. exportingX = -40;
  9555. }
  9556. translateX = buttonPosition.x - chart.spacing[3];
  9557. if (buttonPosition.align === 'right') {
  9558. translateX += exportingX - plotLeft; // (#13014)
  9559. }
  9560. else if (buttonPosition.align === 'center') {
  9561. translateX -= plotLeft / 2;
  9562. }
  9563. // align button group
  9564. buttonGroup.align({
  9565. y: buttonPosition.y,
  9566. width: buttonGroup.getBBox().width,
  9567. align: buttonPosition.align,
  9568. x: translateX
  9569. }, true, chart.spacingBox);
  9570. // skip animation
  9571. rangeSelector.group.placed = animate;
  9572. rangeSelector.buttonGroup.placed = animate;
  9573. if (inputEnabled !== false) {
  9574. var inputGroupX,
  9575. inputGroupWidth,
  9576. buttonGroupX,
  9577. buttonGroupWidth;
  9578. // detect collision with exporting
  9579. if (navButtonOptions &&
  9580. this.titleCollision(chart) &&
  9581. verticalAlign === 'top' &&
  9582. inputPosition.align === 'right' && ((inputPosition.y -
  9583. inputGroup.getBBox().height - 12) <
  9584. ((navButtonOptions.y || 0) +
  9585. navButtonOptions.height +
  9586. chart.spacing[0]))) {
  9587. exportingX = -40;
  9588. }
  9589. else {
  9590. exportingX = 0;
  9591. }
  9592. if (inputPosition.align === 'left') {
  9593. translateX = plotLeft;
  9594. }
  9595. else if (inputPosition.align === 'right') {
  9596. translateX = -Math.max(chart.axisOffset[1], -exportingX);
  9597. }
  9598. // Update the alignment to the updated spacing box
  9599. inputGroup.align({
  9600. y: inputPosition.y,
  9601. width: inputGroup.getBBox().width,
  9602. align: inputPosition.align,
  9603. // fix wrong getBBox() value on right align
  9604. x: inputPosition.x + translateX - 2
  9605. }, true, chart.spacingBox);
  9606. // detect collision
  9607. inputGroupX = (inputGroup.alignAttr.translateX +
  9608. inputGroup.alignOptions.x -
  9609. exportingX +
  9610. // getBBox for detecing left margin
  9611. inputGroup.getBBox().x +
  9612. // 2px padding to not overlap input and label
  9613. 2);
  9614. inputGroupWidth = inputGroup.alignOptions.width;
  9615. buttonGroupX = buttonGroup.alignAttr.translateX +
  9616. buttonGroup.getBBox().x;
  9617. // 20 is minimal spacing between elements
  9618. buttonGroupWidth = buttonGroup.getBBox().width + 20;
  9619. if ((inputPosition.align ===
  9620. buttonPosition.align) || ((buttonGroupX + buttonGroupWidth > inputGroupX) &&
  9621. (inputGroupX + inputGroupWidth > buttonGroupX) &&
  9622. (buttonPositionY <
  9623. (inputPositionY +
  9624. inputGroup.getBBox().height)))) {
  9625. inputGroup.attr({
  9626. translateX: inputGroup.alignAttr.translateX +
  9627. (chart.axisOffset[1] >= -exportingX ? 0 : -exportingX),
  9628. translateY: inputGroup.alignAttr.translateY +
  9629. buttonGroup.getBBox().height + 10
  9630. });
  9631. }
  9632. // Set or reset the input values
  9633. rangeSelector.setInputValue('min', min);
  9634. rangeSelector.setInputValue('max', max);
  9635. // skip animation
  9636. rangeSelector.inputGroup.placed = animate;
  9637. }
  9638. // vertical align
  9639. rangeSelector.group.align({
  9640. verticalAlign: verticalAlign
  9641. }, true, chart.spacingBox);
  9642. // set position
  9643. groupHeight =
  9644. rangeSelector.group.getBBox().height + 20; // # 20 padding
  9645. alignTranslateY =
  9646. rangeSelector.group.alignAttr.translateY;
  9647. // calculate bottom position
  9648. if (verticalAlign === 'bottom') {
  9649. legendHeight = (legendOptions &&
  9650. legendOptions.verticalAlign === 'bottom' &&
  9651. legendOptions.enabled &&
  9652. !legendOptions.floating ?
  9653. legend.legendHeight + pick(legendOptions.margin, 10) :
  9654. 0);
  9655. groupHeight = groupHeight + legendHeight - 20;
  9656. translateY = (alignTranslateY -
  9657. groupHeight -
  9658. (floating ? 0 : options.y) -
  9659. (chart.titleOffset ? chart.titleOffset[2] : 0) -
  9660. 10 // 10 spacing
  9661. );
  9662. }
  9663. if (verticalAlign === 'top') {
  9664. if (floating) {
  9665. translateY = 0;
  9666. }
  9667. if (chart.titleOffset && chart.titleOffset[0]) {
  9668. translateY = chart.titleOffset[0];
  9669. }
  9670. translateY += ((chart.margin[0] - chart.spacing[0]) || 0);
  9671. }
  9672. else if (verticalAlign === 'middle') {
  9673. if (inputPositionY === buttonPositionY) {
  9674. if (inputPositionY < 0) {
  9675. translateY = alignTranslateY + minPosition;
  9676. }
  9677. else {
  9678. translateY = alignTranslateY;
  9679. }
  9680. }
  9681. else if (inputPositionY || buttonPositionY) {
  9682. if (inputPositionY < 0 ||
  9683. buttonPositionY < 0) {
  9684. translateY -= Math.min(inputPositionY, buttonPositionY);
  9685. }
  9686. else {
  9687. translateY =
  9688. alignTranslateY - groupHeight + minPosition;
  9689. }
  9690. }
  9691. }
  9692. rangeSelector.group.translate(options.x, options.y + Math.floor(translateY));
  9693. // translate HTML inputs
  9694. if (inputEnabled !== false) {
  9695. rangeSelector.minInput.style.marginTop =
  9696. rangeSelector.group.translateY + 'px';
  9697. rangeSelector.maxInput.style.marginTop =
  9698. rangeSelector.group.translateY + 'px';
  9699. }
  9700. rangeSelector.rendered = true;
  9701. };
  9702. /**
  9703. * Extracts height of range selector
  9704. *
  9705. * @private
  9706. * @function Highcharts.RangeSelector#getHeight
  9707. * @return {number}
  9708. * Returns rangeSelector height
  9709. */
  9710. RangeSelector.prototype.getHeight = function () {
  9711. var rangeSelector = this,
  9712. options = rangeSelector.options,
  9713. rangeSelectorGroup = rangeSelector.group,
  9714. inputPosition = options.inputPosition,
  9715. buttonPosition = options.buttonPosition,
  9716. yPosition = options.y,
  9717. buttonPositionY = buttonPosition.y,
  9718. inputPositionY = inputPosition.y,
  9719. rangeSelectorHeight = 0,
  9720. minPosition;
  9721. if (options.height) {
  9722. return options.height;
  9723. }
  9724. rangeSelectorHeight = rangeSelectorGroup ?
  9725. // 13px to keep back compatibility
  9726. (rangeSelectorGroup.getBBox(true).height) + 13 +
  9727. yPosition :
  9728. 0;
  9729. minPosition = Math.min(inputPositionY, buttonPositionY);
  9730. if ((inputPositionY < 0 && buttonPositionY < 0) ||
  9731. (inputPositionY > 0 && buttonPositionY > 0)) {
  9732. rangeSelectorHeight += Math.abs(minPosition);
  9733. }
  9734. return rangeSelectorHeight;
  9735. };
  9736. /**
  9737. * Detect collision with title or subtitle
  9738. *
  9739. * @private
  9740. * @function Highcharts.RangeSelector#titleCollision
  9741. *
  9742. * @param {Highcharts.Chart} chart
  9743. *
  9744. * @return {boolean}
  9745. * Returns collision status
  9746. */
  9747. RangeSelector.prototype.titleCollision = function (chart) {
  9748. return !(chart.options.title.text ||
  9749. chart.options.subtitle.text);
  9750. };
  9751. /**
  9752. * Update the range selector with new options
  9753. *
  9754. * @private
  9755. * @function Highcharts.RangeSelector#update
  9756. * @param {Highcharts.RangeSelectorOptions} options
  9757. * @return {void}
  9758. */
  9759. RangeSelector.prototype.update = function (options) {
  9760. var chart = this.chart;
  9761. merge(true, chart.options.rangeSelector, options);
  9762. this.destroy();
  9763. this.init(chart);
  9764. chart.rangeSelector.render();
  9765. };
  9766. /**
  9767. * Destroys allocated elements.
  9768. *
  9769. * @private
  9770. * @function Highcharts.RangeSelector#destroy
  9771. */
  9772. RangeSelector.prototype.destroy = function () {
  9773. var rSelector = this,
  9774. minInput = rSelector.minInput,
  9775. maxInput = rSelector.maxInput;
  9776. rSelector.unMouseDown();
  9777. rSelector.unResize();
  9778. // Destroy elements in collections
  9779. destroyObjectProperties(rSelector.buttons);
  9780. // Clear input element events
  9781. if (minInput) {
  9782. minInput.onfocus = minInput.onblur = minInput.onchange = null;
  9783. }
  9784. if (maxInput) {
  9785. maxInput.onfocus = maxInput.onblur = maxInput.onchange = null;
  9786. }
  9787. // Destroy HTML and SVG elements
  9788. objectEach(rSelector, function (val, key) {
  9789. if (val && key !== 'chart') {
  9790. if (val instanceof SVGElement) {
  9791. // SVGElement
  9792. val.destroy();
  9793. }
  9794. else if (val instanceof window.HTMLElement) {
  9795. // HTML element
  9796. discardElement(val);
  9797. }
  9798. }
  9799. if (val !== RangeSelector.prototype[key]) {
  9800. rSelector[key] = null;
  9801. }
  9802. }, this);
  9803. };
  9804. return RangeSelector;
  9805. }());
  9806. /**
  9807. * The default buttons for pre-selecting time frames
  9808. */
  9809. RangeSelector.prototype.defaultButtons = [{
  9810. type: 'month',
  9811. count: 1,
  9812. text: '1m'
  9813. }, {
  9814. type: 'month',
  9815. count: 3,
  9816. text: '3m'
  9817. }, {
  9818. type: 'month',
  9819. count: 6,
  9820. text: '6m'
  9821. }, {
  9822. type: 'ytd',
  9823. text: 'YTD'
  9824. }, {
  9825. type: 'year',
  9826. count: 1,
  9827. text: '1y'
  9828. }, {
  9829. type: 'all',
  9830. text: 'All'
  9831. }];
  9832. /**
  9833. * Get the axis min value based on the range option and the current max. For
  9834. * stock charts this is extended via the {@link RangeSelector} so that if the
  9835. * selected range is a multiple of months or years, it is compensated for
  9836. * various month lengths.
  9837. *
  9838. * @private
  9839. * @function Highcharts.Axis#minFromRange
  9840. * @return {number|undefined}
  9841. * The new minimum value.
  9842. */
  9843. Axis.prototype.minFromRange = function () {
  9844. var rangeOptions = this.range,
  9845. type = rangeOptions.type,
  9846. min,
  9847. max = this.max,
  9848. dataMin,
  9849. range,
  9850. time = this.chart.time,
  9851. // Get the true range from a start date
  9852. getTrueRange = function (base,
  9853. count) {
  9854. var timeName = type === 'year' ? 'FullYear' : 'Month';
  9855. var date = new time.Date(base);
  9856. var basePeriod = time.get(timeName,
  9857. date);
  9858. time.set(timeName, date, basePeriod + count);
  9859. if (basePeriod === time.get(timeName, date)) {
  9860. time.set('Date', date, 0); // #6537
  9861. }
  9862. return date.getTime() - base;
  9863. };
  9864. if (isNumber(rangeOptions)) {
  9865. min = max - rangeOptions;
  9866. range = rangeOptions;
  9867. }
  9868. else {
  9869. min = max + getTrueRange(max, -rangeOptions.count);
  9870. // Let the fixedRange reflect initial settings (#5930)
  9871. if (this.chart) {
  9872. this.chart.fixedRange = max - min;
  9873. }
  9874. }
  9875. dataMin = pick(this.dataMin, Number.MIN_VALUE);
  9876. if (!isNumber(min)) {
  9877. min = dataMin;
  9878. }
  9879. if (min <= dataMin) {
  9880. min = dataMin;
  9881. if (typeof range === 'undefined') { // #4501
  9882. range = getTrueRange(min, rangeOptions.count);
  9883. }
  9884. this.newMax = Math.min(min + range, this.dataMax);
  9885. }
  9886. if (!isNumber(max)) {
  9887. min = void 0;
  9888. }
  9889. return min;
  9890. };
  9891. if (!H.RangeSelector) {
  9892. // Initialize rangeselector for stock charts
  9893. addEvent(Chart, 'afterGetContainer', function () {
  9894. if (this.options.rangeSelector.enabled) {
  9895. this.rangeSelector = new RangeSelector(this);
  9896. }
  9897. });
  9898. addEvent(Chart, 'beforeRender', function () {
  9899. var chart = this,
  9900. axes = chart.axes,
  9901. rangeSelector = chart.rangeSelector,
  9902. verticalAlign;
  9903. if (rangeSelector) {
  9904. if (isNumber(rangeSelector.deferredYTDClick)) {
  9905. rangeSelector.clickButton(rangeSelector.deferredYTDClick);
  9906. delete rangeSelector.deferredYTDClick;
  9907. }
  9908. axes.forEach(function (axis) {
  9909. axis.updateNames();
  9910. axis.setScale();
  9911. });
  9912. chart.getAxisMargins();
  9913. rangeSelector.render();
  9914. verticalAlign = rangeSelector.options.verticalAlign;
  9915. if (!rangeSelector.options.floating) {
  9916. if (verticalAlign === 'bottom') {
  9917. this.extraBottomMargin = true;
  9918. }
  9919. else if (verticalAlign !== 'middle') {
  9920. this.extraTopMargin = true;
  9921. }
  9922. }
  9923. }
  9924. });
  9925. addEvent(Chart, 'update', function (e) {
  9926. var chart = this,
  9927. options = e.options,
  9928. optionsRangeSelector = options.rangeSelector,
  9929. rangeSelector = chart.rangeSelector,
  9930. verticalAlign,
  9931. extraBottomMarginWas = this.extraBottomMargin,
  9932. extraTopMarginWas = this.extraTopMargin;
  9933. if (optionsRangeSelector &&
  9934. optionsRangeSelector.enabled &&
  9935. !defined(rangeSelector)) {
  9936. this.options.rangeSelector.enabled = true;
  9937. this.rangeSelector = new RangeSelector(this);
  9938. }
  9939. this.extraBottomMargin = false;
  9940. this.extraTopMargin = false;
  9941. if (rangeSelector) {
  9942. rangeSelector.render();
  9943. verticalAlign = (optionsRangeSelector &&
  9944. optionsRangeSelector.verticalAlign) || (rangeSelector.options && rangeSelector.options.verticalAlign);
  9945. if (!rangeSelector.options.floating) {
  9946. if (verticalAlign === 'bottom') {
  9947. this.extraBottomMargin = true;
  9948. }
  9949. else if (verticalAlign !== 'middle') {
  9950. this.extraTopMargin = true;
  9951. }
  9952. }
  9953. if (this.extraBottomMargin !== extraBottomMarginWas ||
  9954. this.extraTopMargin !== extraTopMarginWas) {
  9955. this.isDirtyBox = true;
  9956. }
  9957. }
  9958. });
  9959. addEvent(Chart, 'render', function () {
  9960. var chart = this,
  9961. rangeSelector = chart.rangeSelector,
  9962. verticalAlign;
  9963. if (rangeSelector && !rangeSelector.options.floating) {
  9964. rangeSelector.render();
  9965. verticalAlign = rangeSelector.options.verticalAlign;
  9966. if (verticalAlign === 'bottom') {
  9967. this.extraBottomMargin = true;
  9968. }
  9969. else if (verticalAlign !== 'middle') {
  9970. this.extraTopMargin = true;
  9971. }
  9972. }
  9973. });
  9974. addEvent(Chart, 'getMargins', function () {
  9975. var rangeSelector = this.rangeSelector,
  9976. rangeSelectorHeight;
  9977. if (rangeSelector) {
  9978. rangeSelectorHeight = rangeSelector.getHeight();
  9979. if (this.extraTopMargin) {
  9980. this.plotTop += rangeSelectorHeight;
  9981. }
  9982. if (this.extraBottomMargin) {
  9983. this.marginBottom += rangeSelectorHeight;
  9984. }
  9985. }
  9986. });
  9987. Chart.prototype.callbacks.push(function (chart) {
  9988. var extremes,
  9989. rangeSelector = chart.rangeSelector,
  9990. unbindRender,
  9991. unbindSetExtremes,
  9992. legend,
  9993. alignTo,
  9994. verticalAlign;
  9995. /**
  9996. * @private
  9997. */
  9998. function renderRangeSelector() {
  9999. extremes = chart.xAxis[0].getExtremes();
  10000. legend = chart.legend;
  10001. verticalAlign = rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.options.verticalAlign;
  10002. if (isNumber(extremes.min)) {
  10003. rangeSelector.render(extremes.min, extremes.max);
  10004. }
  10005. // Re-align the legend so that it's below the rangeselector
  10006. if (rangeSelector && legend.display &&
  10007. verticalAlign === 'top' &&
  10008. verticalAlign === legend.options.verticalAlign) {
  10009. // Create a new alignment box for the legend.
  10010. alignTo = merge(chart.spacingBox);
  10011. if (legend.options.layout === 'vertical') {
  10012. alignTo.y = chart.plotTop;
  10013. }
  10014. else {
  10015. alignTo.y += rangeSelector.getHeight();
  10016. }
  10017. legend.group.placed = false; // Don't animate the alignment.
  10018. legend.align(alignTo);
  10019. }
  10020. }
  10021. if (rangeSelector) {
  10022. // redraw the scroller on setExtremes
  10023. unbindSetExtremes = addEvent(chart.xAxis[0], 'afterSetExtremes', function (e) {
  10024. rangeSelector.render(e.min, e.max);
  10025. });
  10026. // redraw the scroller chart resize
  10027. unbindRender = addEvent(chart, 'redraw', renderRangeSelector);
  10028. // do it now
  10029. renderRangeSelector();
  10030. }
  10031. // Remove resize/afterSetExtremes at chart destroy
  10032. addEvent(chart, 'destroy', function destroyEvents() {
  10033. if (rangeSelector) {
  10034. unbindRender();
  10035. unbindSetExtremes();
  10036. }
  10037. });
  10038. });
  10039. H.RangeSelector = RangeSelector;
  10040. }
  10041. return H.RangeSelector;
  10042. });
  10043. _registerModule(_modules, 'Core/Axis/NavigatorAxis.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  10044. /* *
  10045. *
  10046. * (c) 2010-2020 Torstein Honsi
  10047. *
  10048. * License: www.highcharts.com/license
  10049. *
  10050. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10051. *
  10052. * */
  10053. var isTouchDevice = H.isTouchDevice;
  10054. var addEvent = U.addEvent,
  10055. correctFloat = U.correctFloat,
  10056. defined = U.defined,
  10057. isNumber = U.isNumber,
  10058. pick = U.pick;
  10059. /* eslint-disable valid-jsdoc */
  10060. /**
  10061. * @private
  10062. * @class
  10063. */
  10064. var NavigatorAxisAdditions = /** @class */ (function () {
  10065. /* *
  10066. *
  10067. * Constructors
  10068. *
  10069. * */
  10070. function NavigatorAxisAdditions(axis) {
  10071. this.axis = axis;
  10072. }
  10073. /* *
  10074. *
  10075. * Functions
  10076. *
  10077. * */
  10078. /**
  10079. * @private
  10080. */
  10081. NavigatorAxisAdditions.prototype.destroy = function () {
  10082. this.axis = void 0;
  10083. };
  10084. /**
  10085. * Add logic to normalize the zoomed range in order to preserve the pressed
  10086. * state of range selector buttons
  10087. *
  10088. * @private
  10089. * @function Highcharts.Axis#toFixedRange
  10090. * @param {number} [pxMin]
  10091. * @param {number} [pxMax]
  10092. * @param {number} [fixedMin]
  10093. * @param {number} [fixedMax]
  10094. * @return {*}
  10095. */
  10096. NavigatorAxisAdditions.prototype.toFixedRange = function (pxMin, pxMax, fixedMin, fixedMax) {
  10097. var navigator = this;
  10098. var axis = navigator.axis;
  10099. var chart = axis.chart;
  10100. var fixedRange = chart && chart.fixedRange,
  10101. halfPointRange = (axis.pointRange || 0) / 2,
  10102. newMin = pick(fixedMin,
  10103. axis.translate(pxMin,
  10104. true, !axis.horiz)),
  10105. newMax = pick(fixedMax,
  10106. axis.translate(pxMax,
  10107. true, !axis.horiz)),
  10108. changeRatio = fixedRange && (newMax - newMin) / fixedRange;
  10109. // Add/remove half point range to/from the extremes (#1172)
  10110. if (!defined(fixedMin)) {
  10111. newMin = correctFloat(newMin + halfPointRange);
  10112. }
  10113. if (!defined(fixedMax)) {
  10114. newMax = correctFloat(newMax - halfPointRange);
  10115. }
  10116. // If the difference between the fixed range and the actual requested
  10117. // range is too great, the user is dragging across an ordinal gap, and
  10118. // we need to release the range selector button.
  10119. if (changeRatio > 0.7 && changeRatio < 1.3) {
  10120. if (fixedMax) {
  10121. newMin = newMax - fixedRange;
  10122. }
  10123. else {
  10124. newMax = newMin + fixedRange;
  10125. }
  10126. }
  10127. if (!isNumber(newMin) || !isNumber(newMax)) { // #1195, #7411
  10128. newMin = newMax = void 0;
  10129. }
  10130. return {
  10131. min: newMin,
  10132. max: newMax
  10133. };
  10134. };
  10135. return NavigatorAxisAdditions;
  10136. }());
  10137. /**
  10138. * @private
  10139. * @class
  10140. */
  10141. var NavigatorAxis = /** @class */ (function () {
  10142. function NavigatorAxis() {
  10143. }
  10144. /* *
  10145. *
  10146. * Static Functions
  10147. *
  10148. * */
  10149. /**
  10150. * @private
  10151. */
  10152. NavigatorAxis.compose = function (AxisClass) {
  10153. AxisClass.keepProps.push('navigatorAxis');
  10154. /* eslint-disable no-invalid-this */
  10155. addEvent(AxisClass, 'init', function () {
  10156. var axis = this;
  10157. if (!axis.navigatorAxis) {
  10158. axis.navigatorAxis = new NavigatorAxisAdditions(axis);
  10159. }
  10160. });
  10161. // For Stock charts, override selection zooming with some special
  10162. // features because X axis zooming is already allowed by the Navigator
  10163. // and Range selector.
  10164. addEvent(AxisClass, 'zoom', function (e) {
  10165. var axis = this;
  10166. var chart = axis.chart;
  10167. var chartOptions = chart.options;
  10168. var navigator = chartOptions.navigator;
  10169. var navigatorAxis = axis.navigatorAxis;
  10170. var pinchType = chartOptions.chart.pinchType;
  10171. var rangeSelector = chartOptions.rangeSelector;
  10172. var zoomType = chartOptions.chart.zoomType;
  10173. var previousZoom;
  10174. if (axis.isXAxis && ((navigator && navigator.enabled) ||
  10175. (rangeSelector && rangeSelector.enabled))) {
  10176. // For y only zooming, ignore the X axis completely
  10177. if (zoomType === 'y') {
  10178. e.zoomed = false;
  10179. // For xy zooming, record the state of the zoom before zoom
  10180. // selection, then when the reset button is pressed, revert to
  10181. // this state. This should apply only if the chart is
  10182. // initialized with a range (#6612), otherwise zoom all the way
  10183. // out.
  10184. }
  10185. else if (((!isTouchDevice && zoomType === 'xy') ||
  10186. (isTouchDevice && pinchType === 'xy')) &&
  10187. axis.options.range) {
  10188. previousZoom = navigatorAxis.previousZoom;
  10189. if (defined(e.newMin)) {
  10190. navigatorAxis.previousZoom = [axis.min, axis.max];
  10191. }
  10192. else if (previousZoom) {
  10193. e.newMin = previousZoom[0];
  10194. e.newMax = previousZoom[1];
  10195. navigatorAxis.previousZoom = void 0;
  10196. }
  10197. }
  10198. }
  10199. if (typeof e.zoomed !== 'undefined') {
  10200. e.preventDefault();
  10201. }
  10202. });
  10203. /* eslint-enable no-invalid-this */
  10204. };
  10205. /* *
  10206. *
  10207. * Static Properties
  10208. *
  10209. * */
  10210. /**
  10211. * @private
  10212. */
  10213. NavigatorAxis.AdditionsClass = NavigatorAxisAdditions;
  10214. return NavigatorAxis;
  10215. }());
  10216. return NavigatorAxis;
  10217. });
  10218. _registerModule(_modules, 'Core/Navigator.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Series/Series.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Series/LineSeries.js'], _modules['Core/Axis/NavigatorAxis.js'], _modules['Core/Options.js'], _modules['Core/Scrollbar.js'], _modules['Core/Utilities.js']], function (Axis, BaseSeries, Chart, Color, H, LineSeries, NavigatorAxis, O, Scrollbar, U) {
  10219. /* *
  10220. *
  10221. * (c) 2010-2020 Torstein Honsi
  10222. *
  10223. * License: www.highcharts.com/license
  10224. *
  10225. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10226. *
  10227. * */
  10228. var seriesTypes = BaseSeries.seriesTypes;
  10229. var color = Color.parse;
  10230. var hasTouch = H.hasTouch,
  10231. isTouchDevice = H.isTouchDevice;
  10232. var defaultOptions = O.defaultOptions;
  10233. var addEvent = U.addEvent,
  10234. clamp = U.clamp,
  10235. correctFloat = U.correctFloat,
  10236. defined = U.defined,
  10237. destroyObjectProperties = U.destroyObjectProperties,
  10238. erase = U.erase,
  10239. extend = U.extend,
  10240. find = U.find,
  10241. isArray = U.isArray,
  10242. isNumber = U.isNumber,
  10243. merge = U.merge,
  10244. pick = U.pick,
  10245. removeEvent = U.removeEvent,
  10246. splat = U.splat;
  10247. var defaultSeriesType,
  10248. // Finding the min or max of a set of variables where we don't know if they
  10249. // are defined, is a pattern that is repeated several places in Highcharts.
  10250. // Consider making this a global utility method.
  10251. numExt = function (extreme) {
  10252. var args = [];
  10253. for (var _i = 1; _i < arguments.length; _i++) {
  10254. args[_i - 1] = arguments[_i];
  10255. }
  10256. var numbers = [].filter.call(args,
  10257. isNumber);
  10258. if (numbers.length) {
  10259. return Math[extreme].apply(0, numbers);
  10260. }
  10261. };
  10262. defaultSeriesType = typeof seriesTypes.areaspline === 'undefined' ?
  10263. 'line' :
  10264. 'areaspline';
  10265. extend(defaultOptions, {
  10266. /**
  10267. * Maximum range which can be set using the navigator's handles.
  10268. * Opposite of [xAxis.minRange](#xAxis.minRange).
  10269. *
  10270. * @sample {highstock} stock/navigator/maxrange/
  10271. * Defined max and min range
  10272. *
  10273. * @type {number}
  10274. * @since 6.0.0
  10275. * @product highstock gantt
  10276. * @apioption xAxis.maxRange
  10277. */
  10278. /**
  10279. * The navigator is a small series below the main series, displaying
  10280. * a view of the entire data set. It provides tools to zoom in and
  10281. * out on parts of the data as well as panning across the dataset.
  10282. *
  10283. * @product highstock gantt
  10284. * @optionparent navigator
  10285. */
  10286. navigator: {
  10287. /**
  10288. * Whether the navigator and scrollbar should adapt to updated data
  10289. * in the base X axis. When loading data async, as in the demo below,
  10290. * this should be `false`. Otherwise new data will trigger navigator
  10291. * redraw, which will cause unwanted looping. In the demo below, the
  10292. * data in the navigator is set only once. On navigating, only the main
  10293. * chart content is updated.
  10294. *
  10295. * @sample {highstock} stock/demo/lazy-loading/
  10296. * Set to false with async data loading
  10297. *
  10298. * @type {boolean}
  10299. * @default true
  10300. * @apioption navigator.adaptToUpdatedData
  10301. */
  10302. /**
  10303. * An integer identifying the index to use for the base series, or a
  10304. * string representing the id of the series.
  10305. *
  10306. * **Note**: As of Highcharts 5.0, this is now a deprecated option.
  10307. * Prefer [series.showInNavigator](#plotOptions.series.showInNavigator).
  10308. *
  10309. * @see [series.showInNavigator](#plotOptions.series.showInNavigator)
  10310. *
  10311. * @deprecated
  10312. * @type {number|string}
  10313. * @default 0
  10314. * @apioption navigator.baseSeries
  10315. */
  10316. /**
  10317. * Enable or disable the navigator.
  10318. *
  10319. * @sample {highstock} stock/navigator/enabled/
  10320. * Disable the navigator
  10321. *
  10322. * @type {boolean}
  10323. * @default true
  10324. * @apioption navigator.enabled
  10325. */
  10326. /**
  10327. * When the chart is inverted, whether to draw the navigator on the
  10328. * opposite side.
  10329. *
  10330. * @type {boolean}
  10331. * @default false
  10332. * @since 5.0.8
  10333. * @apioption navigator.opposite
  10334. */
  10335. /**
  10336. * The height of the navigator.
  10337. *
  10338. * @sample {highstock} stock/navigator/height/
  10339. * A higher navigator
  10340. */
  10341. height: 40,
  10342. /**
  10343. * The distance from the nearest element, the X axis or X axis labels.
  10344. *
  10345. * @sample {highstock} stock/navigator/margin/
  10346. * A margin of 2 draws the navigator closer to the X axis labels
  10347. */
  10348. margin: 25,
  10349. /**
  10350. * Whether the mask should be inside the range marking the zoomed
  10351. * range, or outside. In Highstock 1.x it was always `false`.
  10352. *
  10353. * @sample {highstock} stock/navigator/maskinside-false/
  10354. * False, mask outside
  10355. *
  10356. * @since 2.0
  10357. */
  10358. maskInside: true,
  10359. /**
  10360. * Options for the handles for dragging the zoomed area.
  10361. *
  10362. * @sample {highstock} stock/navigator/handles/
  10363. * Colored handles
  10364. */
  10365. handles: {
  10366. /**
  10367. * Width for handles.
  10368. *
  10369. * @sample {highstock} stock/navigator/styled-handles/
  10370. * Styled handles
  10371. *
  10372. * @since 6.0.0
  10373. */
  10374. width: 7,
  10375. /**
  10376. * Height for handles.
  10377. *
  10378. * @sample {highstock} stock/navigator/styled-handles/
  10379. * Styled handles
  10380. *
  10381. * @since 6.0.0
  10382. */
  10383. height: 15,
  10384. /**
  10385. * Array to define shapes of handles. 0-index for left, 1-index for
  10386. * right.
  10387. *
  10388. * Additionally, the URL to a graphic can be given on this form:
  10389. * `url(graphic.png)`. Note that for the image to be applied to
  10390. * exported charts, its URL needs to be accessible by the export
  10391. * server.
  10392. *
  10393. * Custom callbacks for symbol path generation can also be added to
  10394. * `Highcharts.SVGRenderer.prototype.symbols`. The callback is then
  10395. * used by its method name, as shown in the demo.
  10396. *
  10397. * @sample {highstock} stock/navigator/styled-handles/
  10398. * Styled handles
  10399. *
  10400. * @type {Array<string>}
  10401. * @default ["navigator-handle", "navigator-handle"]
  10402. * @since 6.0.0
  10403. */
  10404. symbols: ['navigator-handle', 'navigator-handle'],
  10405. /**
  10406. * Allows to enable/disable handles.
  10407. *
  10408. * @since 6.0.0
  10409. */
  10410. enabled: true,
  10411. /**
  10412. * The width for the handle border and the stripes inside.
  10413. *
  10414. * @sample {highstock} stock/navigator/styled-handles/
  10415. * Styled handles
  10416. *
  10417. * @since 6.0.0
  10418. * @apioption navigator.handles.lineWidth
  10419. */
  10420. lineWidth: 1,
  10421. /**
  10422. * The fill for the handle.
  10423. *
  10424. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10425. */
  10426. backgroundColor: '#f2f2f2',
  10427. /**
  10428. * The stroke for the handle border and the stripes inside.
  10429. *
  10430. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10431. */
  10432. borderColor: '#999999'
  10433. },
  10434. /**
  10435. * The color of the mask covering the areas of the navigator series
  10436. * that are currently not visible in the main series. The default
  10437. * color is bluish with an opacity of 0.3 to see the series below.
  10438. *
  10439. * @see In styled mode, the mask is styled with the
  10440. * `.highcharts-navigator-mask` and
  10441. * `.highcharts-navigator-mask-inside` classes.
  10442. *
  10443. * @sample {highstock} stock/navigator/maskfill/
  10444. * Blue, semi transparent mask
  10445. *
  10446. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10447. * @default rgba(102,133,194,0.3)
  10448. */
  10449. maskFill: color('#6685c2').setOpacity(0.3).get(),
  10450. /**
  10451. * The color of the line marking the currently zoomed area in the
  10452. * navigator.
  10453. *
  10454. * @sample {highstock} stock/navigator/outline/
  10455. * 2px blue outline
  10456. *
  10457. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10458. * @default #cccccc
  10459. */
  10460. outlineColor: '#cccccc',
  10461. /**
  10462. * The width of the line marking the currently zoomed area in the
  10463. * navigator.
  10464. *
  10465. * @see In styled mode, the outline stroke width is set with the
  10466. * `.highcharts-navigator-outline` class.
  10467. *
  10468. * @sample {highstock} stock/navigator/outline/
  10469. * 2px blue outline
  10470. *
  10471. * @type {number}
  10472. */
  10473. outlineWidth: 1,
  10474. /**
  10475. * Options for the navigator series. Available options are the same
  10476. * as any series, documented at [plotOptions](#plotOptions.series)
  10477. * and [series](#series).
  10478. *
  10479. * Unless data is explicitly defined on navigator.series, the data
  10480. * is borrowed from the first series in the chart.
  10481. *
  10482. * Default series options for the navigator series are:
  10483. * ```js
  10484. * series: {
  10485. * type: 'areaspline',
  10486. * fillOpacity: 0.05,
  10487. * dataGrouping: {
  10488. * smoothed: true
  10489. * },
  10490. * lineWidth: 1,
  10491. * marker: {
  10492. * enabled: false
  10493. * }
  10494. * }
  10495. * ```
  10496. *
  10497. * @see In styled mode, the navigator series is styled with the
  10498. * `.highcharts-navigator-series` class.
  10499. *
  10500. * @sample {highstock} stock/navigator/series-data/
  10501. * Using a separate data set for the navigator
  10502. * @sample {highstock} stock/navigator/series/
  10503. * A green navigator series
  10504. *
  10505. * @type {*|Array<*>|Highcharts.SeriesOptionsType|Array<Highcharts.SeriesOptionsType>}
  10506. */
  10507. series: {
  10508. /**
  10509. * The type of the navigator series.
  10510. *
  10511. * Heads up:
  10512. * In column-type navigator, zooming is limited to at least one
  10513. * point with its `pointRange`.
  10514. *
  10515. * @sample {highstock} stock/navigator/column/
  10516. * Column type navigator
  10517. *
  10518. * @type {string}
  10519. * @default {highstock} `areaspline` if defined, otherwise `line`
  10520. * @default {gantt} gantt
  10521. */
  10522. type: defaultSeriesType,
  10523. /**
  10524. * The fill opacity of the navigator series.
  10525. */
  10526. fillOpacity: 0.05,
  10527. /**
  10528. * The pixel line width of the navigator series.
  10529. */
  10530. lineWidth: 1,
  10531. /**
  10532. * @ignore-option
  10533. */
  10534. compare: null,
  10535. /**
  10536. * Unless data is explicitly defined, the data is borrowed from the
  10537. * first series in the chart.
  10538. *
  10539. * @type {Array<number|Array<number|string|null>|object|null>}
  10540. * @product highstock
  10541. * @apioption navigator.series.data
  10542. */
  10543. /**
  10544. * Data grouping options for the navigator series.
  10545. *
  10546. * @extends plotOptions.series.dataGrouping
  10547. */
  10548. dataGrouping: {
  10549. approximation: 'average',
  10550. enabled: true,
  10551. groupPixelWidth: 2,
  10552. smoothed: true,
  10553. // Day and week differs from plotOptions.series.dataGrouping
  10554. units: [
  10555. ['millisecond', [1, 2, 5, 10, 20, 25, 50, 100, 200, 500]],
  10556. ['second', [1, 2, 5, 10, 15, 30]],
  10557. ['minute', [1, 2, 5, 10, 15, 30]],
  10558. ['hour', [1, 2, 3, 4, 6, 8, 12]],
  10559. ['day', [1, 2, 3, 4]],
  10560. ['week', [1, 2, 3]],
  10561. ['month', [1, 3, 6]],
  10562. ['year', null]
  10563. ]
  10564. },
  10565. /**
  10566. * Data label options for the navigator series. Data labels are
  10567. * disabled by default on the navigator series.
  10568. *
  10569. * @extends plotOptions.series.dataLabels
  10570. */
  10571. dataLabels: {
  10572. enabled: false,
  10573. zIndex: 2 // #1839
  10574. },
  10575. id: 'highcharts-navigator-series',
  10576. className: 'highcharts-navigator-series',
  10577. /**
  10578. * Sets the fill color of the navigator series.
  10579. *
  10580. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10581. * @apioption navigator.series.color
  10582. */
  10583. /**
  10584. * Line color for the navigator series. Allows setting the color
  10585. * while disallowing the default candlestick setting.
  10586. *
  10587. * @type {Highcharts.ColorString|null}
  10588. */
  10589. lineColor: null,
  10590. marker: {
  10591. enabled: false
  10592. },
  10593. /**
  10594. * Since Highstock v8, default value is the same as default
  10595. * `pointRange` defined for a specific type (e.g. `null` for
  10596. * column type).
  10597. *
  10598. * In Highstock version < 8, defaults to 0.
  10599. *
  10600. * @extends plotOptions.series.pointRange
  10601. * @type {number|null}
  10602. * @apioption navigator.series.pointRange
  10603. */
  10604. /**
  10605. * The threshold option. Setting it to 0 will make the default
  10606. * navigator area series draw its area from the 0 value and up.
  10607. *
  10608. * @type {number|null}
  10609. */
  10610. threshold: null
  10611. },
  10612. /**
  10613. * Options for the navigator X axis. Default series options for the
  10614. * navigator xAxis are:
  10615. * ```js
  10616. * xAxis: {
  10617. * tickWidth: 0,
  10618. * lineWidth: 0,
  10619. * gridLineWidth: 1,
  10620. * tickPixelInterval: 200,
  10621. * labels: {
  10622. * align: 'left',
  10623. * style: {
  10624. * color: '#888'
  10625. * },
  10626. * x: 3,
  10627. * y: -4
  10628. * }
  10629. * }
  10630. * ```
  10631. *
  10632. * @extends xAxis
  10633. * @excluding linkedTo, maxZoom, minRange, opposite, range, scrollbar,
  10634. * showEmpty, maxRange
  10635. */
  10636. xAxis: {
  10637. /**
  10638. * Additional range on the right side of the xAxis. Works similar to
  10639. * xAxis.maxPadding, but value is set in milliseconds.
  10640. * Can be set for both, main xAxis and navigator's xAxis.
  10641. *
  10642. * @since 6.0.0
  10643. */
  10644. overscroll: 0,
  10645. className: 'highcharts-navigator-xaxis',
  10646. tickLength: 0,
  10647. lineWidth: 0,
  10648. gridLineColor: '#e6e6e6',
  10649. gridLineWidth: 1,
  10650. tickPixelInterval: 200,
  10651. labels: {
  10652. align: 'left',
  10653. /**
  10654. * @type {Highcharts.CSSObject}
  10655. */
  10656. style: {
  10657. /** @ignore */
  10658. color: '#999999'
  10659. },
  10660. x: 3,
  10661. y: -4
  10662. },
  10663. crosshair: false
  10664. },
  10665. /**
  10666. * Options for the navigator Y axis. Default series options for the
  10667. * navigator yAxis are:
  10668. * ```js
  10669. * yAxis: {
  10670. * gridLineWidth: 0,
  10671. * startOnTick: false,
  10672. * endOnTick: false,
  10673. * minPadding: 0.1,
  10674. * maxPadding: 0.1,
  10675. * labels: {
  10676. * enabled: false
  10677. * },
  10678. * title: {
  10679. * text: null
  10680. * },
  10681. * tickWidth: 0
  10682. * }
  10683. * ```
  10684. *
  10685. * @extends yAxis
  10686. * @excluding height, linkedTo, maxZoom, minRange, ordinal, range,
  10687. * showEmpty, scrollbar, top, units, maxRange, minLength,
  10688. * maxLength, resize
  10689. */
  10690. yAxis: {
  10691. className: 'highcharts-navigator-yaxis',
  10692. gridLineWidth: 0,
  10693. startOnTick: false,
  10694. endOnTick: false,
  10695. minPadding: 0.1,
  10696. maxPadding: 0.1,
  10697. labels: {
  10698. enabled: false
  10699. },
  10700. crosshair: false,
  10701. title: {
  10702. text: null
  10703. },
  10704. tickLength: 0,
  10705. tickWidth: 0
  10706. }
  10707. }
  10708. });
  10709. /* eslint-disable no-invalid-this, valid-jsdoc */
  10710. /**
  10711. * Draw one of the handles on the side of the zoomed range in the navigator
  10712. *
  10713. * @private
  10714. * @function Highcharts.Renderer#symbols.navigator-handle
  10715. * @param {number} x
  10716. * @param {number} y
  10717. * @param {number} w
  10718. * @param {number} h
  10719. * @param {Highcharts.NavigatorHandlesOptions} options
  10720. * @return {Highcharts.SVGPathArray}
  10721. * Path to be used in a handle
  10722. */
  10723. H.Renderer.prototype.symbols['navigator-handle'] = function (x, y, w, h, options) {
  10724. var halfWidth = (options && options.width || 0) / 2,
  10725. markerPosition = Math.round(halfWidth / 3) + 0.5,
  10726. height = options && options.height || 0;
  10727. return [
  10728. ['M', -halfWidth - 1, 0.5],
  10729. ['L', halfWidth, 0.5],
  10730. ['L', halfWidth, height + 0.5],
  10731. ['L', -halfWidth - 1, height + 0.5],
  10732. ['L', -halfWidth - 1, 0.5],
  10733. ['M', -markerPosition, 4],
  10734. ['L', -markerPosition, height - 3],
  10735. ['M', markerPosition - 1, 4],
  10736. ['L', markerPosition - 1, height - 3]
  10737. ];
  10738. };
  10739. /**
  10740. * The Navigator class
  10741. *
  10742. * @private
  10743. * @class
  10744. * @name Highcharts.Navigator
  10745. *
  10746. * @param {Highcharts.Chart} chart
  10747. * Chart object
  10748. */
  10749. var Navigator = /** @class */ (function () {
  10750. function Navigator(chart) {
  10751. this.baseSeries = void 0;
  10752. this.chart = void 0;
  10753. this.handles = void 0;
  10754. this.height = void 0;
  10755. this.left = void 0;
  10756. this.navigatorEnabled = void 0;
  10757. this.navigatorGroup = void 0;
  10758. this.navigatorOptions = void 0;
  10759. this.navigatorSeries = void 0;
  10760. this.navigatorSize = void 0;
  10761. this.opposite = void 0;
  10762. this.outline = void 0;
  10763. this.outlineHeight = void 0;
  10764. this.range = void 0;
  10765. this.rendered = void 0;
  10766. this.shades = void 0;
  10767. this.size = void 0;
  10768. this.top = void 0;
  10769. this.xAxis = void 0;
  10770. this.yAxis = void 0;
  10771. this.zoomedMax = void 0;
  10772. this.zoomedMin = void 0;
  10773. this.init(chart);
  10774. }
  10775. /**
  10776. * Draw one of the handles on the side of the zoomed range in the navigator
  10777. *
  10778. * @private
  10779. * @function Highcharts.Navigator#drawHandle
  10780. *
  10781. * @param {number} x
  10782. * The x center for the handle
  10783. *
  10784. * @param {number} index
  10785. * 0 for left and 1 for right
  10786. *
  10787. * @param {boolean|undefined} inverted
  10788. * flag for chart.inverted
  10789. *
  10790. * @param {string} verb
  10791. * use 'animate' or 'attr'
  10792. */
  10793. Navigator.prototype.drawHandle = function (x, index, inverted, verb) {
  10794. var navigator = this,
  10795. height = navigator.navigatorOptions.handles.height;
  10796. // Place it
  10797. navigator.handles[index][verb](inverted ? {
  10798. translateX: Math.round(navigator.left + navigator.height / 2),
  10799. translateY: Math.round(navigator.top + parseInt(x, 10) + 0.5 - height)
  10800. } : {
  10801. translateX: Math.round(navigator.left + parseInt(x, 10)),
  10802. translateY: Math.round(navigator.top + navigator.height / 2 - height / 2 - 1)
  10803. });
  10804. };
  10805. /**
  10806. * Render outline around the zoomed range
  10807. *
  10808. * @private
  10809. * @function Highcharts.Navigator#drawOutline
  10810. *
  10811. * @param {number} zoomedMin
  10812. * in pixels position where zoomed range starts
  10813. *
  10814. * @param {number} zoomedMax
  10815. * in pixels position where zoomed range ends
  10816. *
  10817. * @param {boolean|undefined} inverted
  10818. * flag if chart is inverted
  10819. *
  10820. * @param {string} verb
  10821. * use 'animate' or 'attr'
  10822. */
  10823. Navigator.prototype.drawOutline = function (zoomedMin, zoomedMax, inverted, verb) {
  10824. var navigator = this,
  10825. maskInside = navigator.navigatorOptions.maskInside,
  10826. outlineWidth = navigator.outline.strokeWidth(),
  10827. halfOutline = outlineWidth / 2,
  10828. outlineCorrection = (outlineWidth % 2) / 2, // #5800
  10829. outlineHeight = navigator.outlineHeight,
  10830. scrollbarHeight = navigator.scrollbarHeight || 0,
  10831. navigatorSize = navigator.size,
  10832. left = navigator.left - scrollbarHeight,
  10833. navigatorTop = navigator.top,
  10834. verticalMin,
  10835. path;
  10836. if (inverted) {
  10837. left -= halfOutline;
  10838. verticalMin = navigatorTop + zoomedMax + outlineCorrection;
  10839. zoomedMax = navigatorTop + zoomedMin + outlineCorrection;
  10840. path = [
  10841. ['M', left + outlineHeight, navigatorTop - scrollbarHeight - outlineCorrection],
  10842. ['L', left + outlineHeight, verticalMin],
  10843. ['L', left, verticalMin],
  10844. ['L', left, zoomedMax],
  10845. ['L', left + outlineHeight, zoomedMax],
  10846. ['L', left + outlineHeight, navigatorTop + navigatorSize + scrollbarHeight]
  10847. ];
  10848. if (maskInside) {
  10849. path.push(['M', left + outlineHeight, verticalMin - halfOutline], // upper left of zoomed range
  10850. ['L', left + outlineHeight, zoomedMax + halfOutline] // upper right of z.r.
  10851. );
  10852. }
  10853. }
  10854. else {
  10855. zoomedMin += left + scrollbarHeight - outlineCorrection;
  10856. zoomedMax += left + scrollbarHeight - outlineCorrection;
  10857. navigatorTop += halfOutline;
  10858. path = [
  10859. ['M', left, navigatorTop],
  10860. ['L', zoomedMin, navigatorTop],
  10861. ['L', zoomedMin, navigatorTop + outlineHeight],
  10862. ['L', zoomedMax, navigatorTop + outlineHeight],
  10863. ['L', zoomedMax, navigatorTop],
  10864. ['L', left + navigatorSize + scrollbarHeight * 2, navigatorTop] // right
  10865. ];
  10866. if (maskInside) {
  10867. path.push(['M', zoomedMin - halfOutline, navigatorTop], // upper left of zoomed range
  10868. ['L', zoomedMax + halfOutline, navigatorTop] // upper right of z.r.
  10869. );
  10870. }
  10871. }
  10872. navigator.outline[verb]({
  10873. d: path
  10874. });
  10875. };
  10876. /**
  10877. * Render outline around the zoomed range
  10878. *
  10879. * @private
  10880. * @function Highcharts.Navigator#drawMasks
  10881. *
  10882. * @param {number} zoomedMin
  10883. * in pixels position where zoomed range starts
  10884. *
  10885. * @param {number} zoomedMax
  10886. * in pixels position where zoomed range ends
  10887. *
  10888. * @param {boolean|undefined} inverted
  10889. * flag if chart is inverted
  10890. *
  10891. * @param {string} verb
  10892. * use 'animate' or 'attr'
  10893. */
  10894. Navigator.prototype.drawMasks = function (zoomedMin, zoomedMax, inverted, verb) {
  10895. var navigator = this,
  10896. left = navigator.left,
  10897. top = navigator.top,
  10898. navigatorHeight = navigator.height,
  10899. height,
  10900. width,
  10901. x,
  10902. y;
  10903. // Determine rectangle position & size
  10904. // According to (non)inverted position:
  10905. if (inverted) {
  10906. x = [left, left, left];
  10907. y = [top, top + zoomedMin, top + zoomedMax];
  10908. width = [navigatorHeight, navigatorHeight, navigatorHeight];
  10909. height = [
  10910. zoomedMin,
  10911. zoomedMax - zoomedMin,
  10912. navigator.size - zoomedMax
  10913. ];
  10914. }
  10915. else {
  10916. x = [left, left + zoomedMin, left + zoomedMax];
  10917. y = [top, top, top];
  10918. width = [
  10919. zoomedMin,
  10920. zoomedMax - zoomedMin,
  10921. navigator.size - zoomedMax
  10922. ];
  10923. height = [navigatorHeight, navigatorHeight, navigatorHeight];
  10924. }
  10925. navigator.shades.forEach(function (shade, i) {
  10926. shade[verb]({
  10927. x: x[i],
  10928. y: y[i],
  10929. width: width[i],
  10930. height: height[i]
  10931. });
  10932. });
  10933. };
  10934. /**
  10935. * Generate DOM elements for a navigator:
  10936. *
  10937. * - main navigator group
  10938. *
  10939. * - all shades
  10940. *
  10941. * - outline
  10942. *
  10943. * - handles
  10944. *
  10945. * @private
  10946. * @function Highcharts.Navigator#renderElements
  10947. */
  10948. Navigator.prototype.renderElements = function () {
  10949. var navigator = this,
  10950. navigatorOptions = navigator.navigatorOptions,
  10951. maskInside = navigatorOptions.maskInside,
  10952. chart = navigator.chart,
  10953. inverted = chart.inverted,
  10954. renderer = chart.renderer,
  10955. navigatorGroup,
  10956. mouseCursor = {
  10957. cursor: inverted ? 'ns-resize' : 'ew-resize'
  10958. };
  10959. // Create the main navigator group
  10960. navigator.navigatorGroup = navigatorGroup = renderer.g('navigator')
  10961. .attr({
  10962. zIndex: 8,
  10963. visibility: 'hidden'
  10964. })
  10965. .add();
  10966. // Create masks, each mask will get events and fill:
  10967. [
  10968. !maskInside,
  10969. maskInside,
  10970. !maskInside
  10971. ].forEach(function (hasMask, index) {
  10972. navigator.shades[index] = renderer.rect()
  10973. .addClass('highcharts-navigator-mask' +
  10974. (index === 1 ? '-inside' : '-outside'))
  10975. .add(navigatorGroup);
  10976. if (!chart.styledMode) {
  10977. navigator.shades[index]
  10978. .attr({
  10979. fill: hasMask ?
  10980. navigatorOptions.maskFill :
  10981. 'rgba(0,0,0,0)'
  10982. })
  10983. .css((index === 1) && mouseCursor);
  10984. }
  10985. });
  10986. // Create the outline:
  10987. navigator.outline = renderer.path()
  10988. .addClass('highcharts-navigator-outline')
  10989. .add(navigatorGroup);
  10990. if (!chart.styledMode) {
  10991. navigator.outline.attr({
  10992. 'stroke-width': navigatorOptions.outlineWidth,
  10993. stroke: navigatorOptions.outlineColor
  10994. });
  10995. }
  10996. // Create the handlers:
  10997. if (navigatorOptions.handles.enabled) {
  10998. [0, 1].forEach(function (index) {
  10999. navigatorOptions.handles.inverted = chart.inverted;
  11000. navigator.handles[index] = renderer.symbol(navigatorOptions.handles.symbols[index], -navigatorOptions.handles.width / 2 - 1, 0, navigatorOptions.handles.width, navigatorOptions.handles.height, navigatorOptions.handles);
  11001. // zIndex = 6 for right handle, 7 for left.
  11002. // Can't be 10, because of the tooltip in inverted chart #2908
  11003. navigator.handles[index].attr({ zIndex: 7 - index })
  11004. .addClass('highcharts-navigator-handle ' +
  11005. 'highcharts-navigator-handle-' +
  11006. ['left', 'right'][index]).add(navigatorGroup);
  11007. if (!chart.styledMode) {
  11008. var handlesOptions = navigatorOptions.handles;
  11009. navigator.handles[index]
  11010. .attr({
  11011. fill: handlesOptions.backgroundColor,
  11012. stroke: handlesOptions.borderColor,
  11013. 'stroke-width': handlesOptions.lineWidth
  11014. })
  11015. .css(mouseCursor);
  11016. }
  11017. });
  11018. }
  11019. };
  11020. /**
  11021. * Update navigator
  11022. *
  11023. * @private
  11024. * @function Highcharts.Navigator#update
  11025. *
  11026. * @param {Highcharts.NavigatorOptions} options
  11027. * Options to merge in when updating navigator
  11028. */
  11029. Navigator.prototype.update = function (options) {
  11030. // Remove references to old navigator series in base series
  11031. (this.series || []).forEach(function (series) {
  11032. if (series.baseSeries) {
  11033. delete series.baseSeries.navigatorSeries;
  11034. }
  11035. });
  11036. // Destroy and rebuild navigator
  11037. this.destroy();
  11038. var chartOptions = this.chart.options;
  11039. merge(true, chartOptions.navigator, this.options, options);
  11040. this.init(this.chart);
  11041. };
  11042. /**
  11043. * Render the navigator
  11044. *
  11045. * @private
  11046. * @function Highcharts.Navigator#render
  11047. * @param {number} min
  11048. * X axis value minimum
  11049. * @param {number} max
  11050. * X axis value maximum
  11051. * @param {number} [pxMin]
  11052. * Pixel value minimum
  11053. * @param {number} [pxMax]
  11054. * Pixel value maximum
  11055. * @return {void}
  11056. */
  11057. Navigator.prototype.render = function (min, max, pxMin, pxMax) {
  11058. var navigator = this,
  11059. chart = navigator.chart,
  11060. navigatorWidth,
  11061. scrollbarLeft,
  11062. scrollbarTop,
  11063. scrollbarHeight = navigator.scrollbarHeight,
  11064. navigatorSize,
  11065. xAxis = navigator.xAxis,
  11066. pointRange = xAxis.pointRange || 0,
  11067. scrollbarXAxis = xAxis.navigatorAxis.fake ? chart.xAxis[0] : xAxis,
  11068. navigatorEnabled = navigator.navigatorEnabled,
  11069. zoomedMin,
  11070. zoomedMax,
  11071. rendered = navigator.rendered,
  11072. inverted = chart.inverted,
  11073. verb,
  11074. newMin,
  11075. newMax,
  11076. currentRange,
  11077. minRange = chart.xAxis[0].minRange,
  11078. maxRange = chart.xAxis[0].options.maxRange;
  11079. // Don't redraw while moving the handles (#4703).
  11080. if (this.hasDragged && !defined(pxMin)) {
  11081. return;
  11082. }
  11083. min = correctFloat(min - pointRange / 2);
  11084. max = correctFloat(max + pointRange / 2);
  11085. // Don't render the navigator until we have data (#486, #4202, #5172).
  11086. if (!isNumber(min) || !isNumber(max)) {
  11087. // However, if navigator was already rendered, we may need to resize
  11088. // it. For example hidden series, but visible navigator (#6022).
  11089. if (rendered) {
  11090. pxMin = 0;
  11091. pxMax = pick(xAxis.width, scrollbarXAxis.width);
  11092. }
  11093. else {
  11094. return;
  11095. }
  11096. }
  11097. navigator.left = pick(xAxis.left,
  11098. // in case of scrollbar only, without navigator
  11099. chart.plotLeft + scrollbarHeight +
  11100. (inverted ? chart.plotWidth : 0));
  11101. navigator.size = zoomedMax = navigatorSize = pick(xAxis.len, (inverted ? chart.plotHeight : chart.plotWidth) -
  11102. 2 * scrollbarHeight);
  11103. if (inverted) {
  11104. navigatorWidth = scrollbarHeight;
  11105. }
  11106. else {
  11107. navigatorWidth = navigatorSize + 2 * scrollbarHeight;
  11108. }
  11109. // Get the pixel position of the handles
  11110. pxMin = pick(pxMin, xAxis.toPixels(min, true));
  11111. pxMax = pick(pxMax, xAxis.toPixels(max, true));
  11112. // Verify (#1851, #2238)
  11113. if (!isNumber(pxMin) || Math.abs(pxMin) === Infinity) {
  11114. pxMin = 0;
  11115. pxMax = navigatorWidth;
  11116. }
  11117. // Are we below the minRange? (#2618, #6191)
  11118. newMin = xAxis.toValue(pxMin, true);
  11119. newMax = xAxis.toValue(pxMax, true);
  11120. currentRange = Math.abs(correctFloat(newMax - newMin));
  11121. if (currentRange < minRange) {
  11122. if (this.grabbedLeft) {
  11123. pxMin = xAxis.toPixels(newMax - minRange - pointRange, true);
  11124. }
  11125. else if (this.grabbedRight) {
  11126. pxMax = xAxis.toPixels(newMin + minRange + pointRange, true);
  11127. }
  11128. }
  11129. else if (defined(maxRange) &&
  11130. correctFloat(currentRange - pointRange) > maxRange) {
  11131. if (this.grabbedLeft) {
  11132. pxMin = xAxis.toPixels(newMax - maxRange - pointRange, true);
  11133. }
  11134. else if (this.grabbedRight) {
  11135. pxMax = xAxis.toPixels(newMin + maxRange + pointRange, true);
  11136. }
  11137. }
  11138. // Handles are allowed to cross, but never exceed the plot area
  11139. navigator.zoomedMax = clamp(Math.max(pxMin, pxMax), 0, zoomedMax);
  11140. navigator.zoomedMin = clamp(navigator.fixedWidth ?
  11141. navigator.zoomedMax - navigator.fixedWidth :
  11142. Math.min(pxMin, pxMax), 0, zoomedMax);
  11143. navigator.range = navigator.zoomedMax - navigator.zoomedMin;
  11144. zoomedMax = Math.round(navigator.zoomedMax);
  11145. zoomedMin = Math.round(navigator.zoomedMin);
  11146. if (navigatorEnabled) {
  11147. navigator.navigatorGroup.attr({
  11148. visibility: 'visible'
  11149. });
  11150. // Place elements
  11151. verb = rendered && !navigator.hasDragged ? 'animate' : 'attr';
  11152. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  11153. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  11154. if (navigator.navigatorOptions.handles.enabled) {
  11155. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  11156. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  11157. }
  11158. }
  11159. if (navigator.scrollbar) {
  11160. if (inverted) {
  11161. scrollbarTop = navigator.top - scrollbarHeight;
  11162. scrollbarLeft = navigator.left - scrollbarHeight +
  11163. (navigatorEnabled || !scrollbarXAxis.opposite ? 0 :
  11164. // Multiple axes has offsets:
  11165. (scrollbarXAxis.titleOffset || 0) +
  11166. // Self margin from the axis.title
  11167. scrollbarXAxis.axisTitleMargin);
  11168. scrollbarHeight = navigatorSize + 2 * scrollbarHeight;
  11169. }
  11170. else {
  11171. scrollbarTop = navigator.top + (navigatorEnabled ?
  11172. navigator.height :
  11173. -scrollbarHeight);
  11174. scrollbarLeft = navigator.left - scrollbarHeight;
  11175. }
  11176. // Reposition scrollbar
  11177. navigator.scrollbar.position(scrollbarLeft, scrollbarTop, navigatorWidth, scrollbarHeight);
  11178. // Keep scale 0-1
  11179. navigator.scrollbar.setRange(
  11180. // Use real value, not rounded because range can be very small
  11181. // (#1716)
  11182. navigator.zoomedMin / (navigatorSize || 1), navigator.zoomedMax / (navigatorSize || 1));
  11183. }
  11184. navigator.rendered = true;
  11185. };
  11186. /**
  11187. * Set up the mouse and touch events for the navigator
  11188. *
  11189. * @private
  11190. * @function Highcharts.Navigator#addMouseEvents
  11191. */
  11192. Navigator.prototype.addMouseEvents = function () {
  11193. var navigator = this,
  11194. chart = navigator.chart,
  11195. container = chart.container,
  11196. eventsToUnbind = [],
  11197. mouseMoveHandler,
  11198. mouseUpHandler;
  11199. /**
  11200. * Create mouse events' handlers.
  11201. * Make them as separate functions to enable wrapping them:
  11202. */
  11203. navigator.mouseMoveHandler = mouseMoveHandler = function (e) {
  11204. navigator.onMouseMove(e);
  11205. };
  11206. navigator.mouseUpHandler = mouseUpHandler = function (e) {
  11207. navigator.onMouseUp(e);
  11208. };
  11209. // Add shades and handles mousedown events
  11210. eventsToUnbind = navigator.getPartsEvents('mousedown');
  11211. // Add mouse move and mouseup events. These are bind to doc/container,
  11212. // because Navigator.grabbedSomething flags are stored in mousedown
  11213. // events
  11214. eventsToUnbind.push(addEvent(chart.renderTo, 'mousemove', mouseMoveHandler), addEvent(container.ownerDocument, 'mouseup', mouseUpHandler));
  11215. // Touch events
  11216. if (hasTouch) {
  11217. eventsToUnbind.push(addEvent(chart.renderTo, 'touchmove', mouseMoveHandler), addEvent(container.ownerDocument, 'touchend', mouseUpHandler));
  11218. eventsToUnbind.concat(navigator.getPartsEvents('touchstart'));
  11219. }
  11220. navigator.eventsToUnbind = eventsToUnbind;
  11221. // Data events
  11222. if (navigator.series && navigator.series[0]) {
  11223. eventsToUnbind.push(addEvent(navigator.series[0].xAxis, 'foundExtremes', function () {
  11224. chart.navigator.modifyNavigatorAxisExtremes();
  11225. }));
  11226. }
  11227. };
  11228. /**
  11229. * Generate events for handles and masks
  11230. *
  11231. * @private
  11232. * @function Highcharts.Navigator#getPartsEvents
  11233. *
  11234. * @param {string} eventName
  11235. * Event name handler, 'mousedown' or 'touchstart'
  11236. *
  11237. * @return {Array<Function>}
  11238. * An array of functions to remove navigator functions from the
  11239. * events again.
  11240. */
  11241. Navigator.prototype.getPartsEvents = function (eventName) {
  11242. var navigator = this,
  11243. events = [];
  11244. ['shades', 'handles'].forEach(function (name) {
  11245. navigator[name].forEach(function (navigatorItem, index) {
  11246. events.push(addEvent(navigatorItem.element, eventName, function (e) {
  11247. navigator[name + 'Mousedown'](e, index);
  11248. }));
  11249. });
  11250. });
  11251. return events;
  11252. };
  11253. /**
  11254. * Mousedown on a shaded mask, either:
  11255. *
  11256. * - will be stored for future drag&drop
  11257. *
  11258. * - will directly shift to a new range
  11259. *
  11260. * @private
  11261. * @function Highcharts.Navigator#shadesMousedown
  11262. *
  11263. * @param {Highcharts.PointerEventObject} e
  11264. * Mouse event
  11265. *
  11266. * @param {number} index
  11267. * Index of a mask in Navigator.shades array
  11268. */
  11269. Navigator.prototype.shadesMousedown = function (e, index) {
  11270. e = this.chart.pointer.normalize(e);
  11271. var navigator = this,
  11272. chart = navigator.chart,
  11273. xAxis = navigator.xAxis,
  11274. zoomedMin = navigator.zoomedMin,
  11275. navigatorPosition = navigator.left,
  11276. navigatorSize = navigator.size,
  11277. range = navigator.range,
  11278. chartX = e.chartX,
  11279. fixedMax,
  11280. fixedMin,
  11281. ext,
  11282. left;
  11283. // For inverted chart, swap some options:
  11284. if (chart.inverted) {
  11285. chartX = e.chartY;
  11286. navigatorPosition = navigator.top;
  11287. }
  11288. if (index === 1) {
  11289. // Store information for drag&drop
  11290. navigator.grabbedCenter = chartX;
  11291. navigator.fixedWidth = range;
  11292. navigator.dragOffset = chartX - zoomedMin;
  11293. }
  11294. else {
  11295. // Shift the range by clicking on shaded areas
  11296. left = chartX - navigatorPosition - range / 2;
  11297. if (index === 0) {
  11298. left = Math.max(0, left);
  11299. }
  11300. else if (index === 2 && left + range >= navigatorSize) {
  11301. left = navigatorSize - range;
  11302. if (navigator.reversedExtremes) {
  11303. // #7713
  11304. left -= range;
  11305. fixedMin = navigator.getUnionExtremes().dataMin;
  11306. }
  11307. else {
  11308. // #2293, #3543
  11309. fixedMax = navigator.getUnionExtremes().dataMax;
  11310. }
  11311. }
  11312. if (left !== zoomedMin) { // it has actually moved
  11313. navigator.fixedWidth = range; // #1370
  11314. ext = xAxis.navigatorAxis.toFixedRange(left, left + range, fixedMin, fixedMax);
  11315. if (defined(ext.min)) { // #7411
  11316. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true, null, // auto animation
  11317. { trigger: 'navigator' });
  11318. }
  11319. }
  11320. }
  11321. };
  11322. /**
  11323. * Mousedown on a handle mask.
  11324. * Will store necessary information for drag&drop.
  11325. *
  11326. * @private
  11327. * @function Highcharts.Navigator#handlesMousedown
  11328. * @param {Highcharts.PointerEventObject} e
  11329. * Mouse event
  11330. * @param {number} index
  11331. * Index of a handle in Navigator.handles array
  11332. * @return {void}
  11333. */
  11334. Navigator.prototype.handlesMousedown = function (e, index) {
  11335. e = this.chart.pointer.normalize(e);
  11336. var navigator = this,
  11337. chart = navigator.chart,
  11338. baseXAxis = chart.xAxis[0],
  11339. // For reversed axes, min and max are changed,
  11340. // so the other extreme should be stored
  11341. reverse = navigator.reversedExtremes;
  11342. if (index === 0) {
  11343. // Grab the left handle
  11344. navigator.grabbedLeft = true;
  11345. navigator.otherHandlePos = navigator.zoomedMax;
  11346. navigator.fixedExtreme = reverse ? baseXAxis.min : baseXAxis.max;
  11347. }
  11348. else {
  11349. // Grab the right handle
  11350. navigator.grabbedRight = true;
  11351. navigator.otherHandlePos = navigator.zoomedMin;
  11352. navigator.fixedExtreme = reverse ? baseXAxis.max : baseXAxis.min;
  11353. }
  11354. chart.fixedRange = null;
  11355. };
  11356. /**
  11357. * Mouse move event based on x/y mouse position.
  11358. *
  11359. * @private
  11360. * @function Highcharts.Navigator#onMouseMove
  11361. *
  11362. * @param {Highcharts.PointerEventObject} e
  11363. * Mouse event
  11364. */
  11365. Navigator.prototype.onMouseMove = function (e) {
  11366. var navigator = this,
  11367. chart = navigator.chart,
  11368. left = navigator.left,
  11369. navigatorSize = navigator.navigatorSize,
  11370. range = navigator.range,
  11371. dragOffset = navigator.dragOffset,
  11372. inverted = chart.inverted,
  11373. chartX;
  11374. // In iOS, a mousemove event with e.pageX === 0 is fired when holding
  11375. // the finger down in the center of the scrollbar. This should be
  11376. // ignored.
  11377. if (!e.touches || e.touches[0].pageX !== 0) { // #4696
  11378. e = chart.pointer.normalize(e);
  11379. chartX = e.chartX;
  11380. // Swap some options for inverted chart
  11381. if (inverted) {
  11382. left = navigator.top;
  11383. chartX = e.chartY;
  11384. }
  11385. // Drag left handle or top handle
  11386. if (navigator.grabbedLeft) {
  11387. navigator.hasDragged = true;
  11388. navigator.render(0, 0, chartX - left, navigator.otherHandlePos);
  11389. // Drag right handle or bottom handle
  11390. }
  11391. else if (navigator.grabbedRight) {
  11392. navigator.hasDragged = true;
  11393. navigator.render(0, 0, navigator.otherHandlePos, chartX - left);
  11394. // Drag scrollbar or open area in navigator
  11395. }
  11396. else if (navigator.grabbedCenter) {
  11397. navigator.hasDragged = true;
  11398. if (chartX < dragOffset) { // outside left
  11399. chartX = dragOffset;
  11400. // outside right
  11401. }
  11402. else if (chartX >
  11403. navigatorSize + dragOffset - range) {
  11404. chartX = navigatorSize + dragOffset - range;
  11405. }
  11406. navigator.render(0, 0, chartX - dragOffset, chartX - dragOffset + range);
  11407. }
  11408. if (navigator.hasDragged &&
  11409. navigator.scrollbar &&
  11410. pick(navigator.scrollbar.options.liveRedraw,
  11411. // By default, don't run live redraw on VML, on touch
  11412. // devices or if the chart is in boost.
  11413. H.svg && !isTouchDevice && !this.chart.isBoosting)) {
  11414. e.DOMType = e.type; // DOMType is for IE8
  11415. setTimeout(function () {
  11416. navigator.onMouseUp(e);
  11417. }, 0);
  11418. }
  11419. }
  11420. };
  11421. /**
  11422. * Mouse up event based on x/y mouse position.
  11423. *
  11424. * @private
  11425. * @function Highcharts.Navigator#onMouseUp
  11426. * @param {Highcharts.PointerEventObject} e
  11427. * Mouse event
  11428. * @return {void}
  11429. */
  11430. Navigator.prototype.onMouseUp = function (e) {
  11431. var navigator = this,
  11432. chart = navigator.chart,
  11433. xAxis = navigator.xAxis,
  11434. scrollbar = navigator.scrollbar,
  11435. DOMEvent = e.DOMEvent || e,
  11436. inverted = chart.inverted,
  11437. verb = navigator.rendered && !navigator.hasDragged ?
  11438. 'animate' : 'attr',
  11439. zoomedMax,
  11440. zoomedMin,
  11441. unionExtremes,
  11442. fixedMin,
  11443. fixedMax,
  11444. ext;
  11445. if (
  11446. // MouseUp is called for both, navigator and scrollbar (that order),
  11447. // which causes calling afterSetExtremes twice. Prevent first call
  11448. // by checking if scrollbar is going to set new extremes (#6334)
  11449. (navigator.hasDragged && (!scrollbar || !scrollbar.hasDragged)) ||
  11450. e.trigger === 'scrollbar') {
  11451. unionExtremes = navigator.getUnionExtremes();
  11452. // When dragging one handle, make sure the other one doesn't change
  11453. if (navigator.zoomedMin === navigator.otherHandlePos) {
  11454. fixedMin = navigator.fixedExtreme;
  11455. }
  11456. else if (navigator.zoomedMax === navigator.otherHandlePos) {
  11457. fixedMax = navigator.fixedExtreme;
  11458. }
  11459. // Snap to right edge (#4076)
  11460. if (navigator.zoomedMax === navigator.size) {
  11461. fixedMax = navigator.reversedExtremes ?
  11462. unionExtremes.dataMin :
  11463. unionExtremes.dataMax;
  11464. }
  11465. // Snap to left edge (#7576)
  11466. if (navigator.zoomedMin === 0) {
  11467. fixedMin = navigator.reversedExtremes ?
  11468. unionExtremes.dataMax :
  11469. unionExtremes.dataMin;
  11470. }
  11471. ext = xAxis.navigatorAxis.toFixedRange(navigator.zoomedMin, navigator.zoomedMax, fixedMin, fixedMax);
  11472. if (defined(ext.min)) {
  11473. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true,
  11474. // Run animation when clicking buttons, scrollbar track etc,
  11475. // but not when dragging handles or scrollbar
  11476. navigator.hasDragged ? false : null, {
  11477. trigger: 'navigator',
  11478. triggerOp: 'navigator-drag',
  11479. DOMEvent: DOMEvent // #1838
  11480. });
  11481. }
  11482. }
  11483. if (e.DOMType !== 'mousemove' &&
  11484. e.DOMType !== 'touchmove') {
  11485. navigator.grabbedLeft = navigator.grabbedRight =
  11486. navigator.grabbedCenter = navigator.fixedWidth =
  11487. navigator.fixedExtreme = navigator.otherHandlePos =
  11488. navigator.hasDragged = navigator.dragOffset = null;
  11489. }
  11490. // Update position of navigator shades, outline and handles (#12573)
  11491. if (navigator.navigatorEnabled &&
  11492. isNumber(navigator.zoomedMin) &&
  11493. isNumber(navigator.zoomedMax)) {
  11494. zoomedMin = Math.round(navigator.zoomedMin);
  11495. zoomedMax = Math.round(navigator.zoomedMax);
  11496. if (navigator.shades) {
  11497. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  11498. }
  11499. if (navigator.outline) {
  11500. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  11501. }
  11502. if (navigator.navigatorOptions.handles.enabled &&
  11503. Object.keys(navigator.handles).length ===
  11504. navigator.handles.length) {
  11505. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  11506. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  11507. }
  11508. }
  11509. };
  11510. /**
  11511. * Removes the event handlers attached previously with addEvents.
  11512. *
  11513. * @private
  11514. * @function Highcharts.Navigator#removeEvents
  11515. * @return {void}
  11516. */
  11517. Navigator.prototype.removeEvents = function () {
  11518. if (this.eventsToUnbind) {
  11519. this.eventsToUnbind.forEach(function (unbind) {
  11520. unbind();
  11521. });
  11522. this.eventsToUnbind = void 0;
  11523. }
  11524. this.removeBaseSeriesEvents();
  11525. };
  11526. /**
  11527. * Remove data events.
  11528. *
  11529. * @private
  11530. * @function Highcharts.Navigator#removeBaseSeriesEvents
  11531. * @return {void}
  11532. */
  11533. Navigator.prototype.removeBaseSeriesEvents = function () {
  11534. var baseSeries = this.baseSeries || [];
  11535. if (this.navigatorEnabled && baseSeries[0]) {
  11536. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  11537. baseSeries.forEach(function (series) {
  11538. removeEvent(series, 'updatedData', this.updatedDataHandler);
  11539. }, this);
  11540. }
  11541. // We only listen for extremes-events on the first baseSeries
  11542. if (baseSeries[0].xAxis) {
  11543. removeEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  11544. }
  11545. }
  11546. };
  11547. /**
  11548. * Initialize the Navigator object
  11549. *
  11550. * @private
  11551. * @function Highcharts.Navigator#init
  11552. *
  11553. * @param {Highcharts.Chart} chart
  11554. */
  11555. Navigator.prototype.init = function (chart) {
  11556. var chartOptions = chart.options,
  11557. navigatorOptions = chartOptions.navigator,
  11558. navigatorEnabled = navigatorOptions.enabled,
  11559. scrollbarOptions = chartOptions.scrollbar,
  11560. scrollbarEnabled = scrollbarOptions.enabled,
  11561. height = navigatorEnabled ? navigatorOptions.height : 0,
  11562. scrollbarHeight = scrollbarEnabled ?
  11563. scrollbarOptions.height :
  11564. 0;
  11565. this.handles = [];
  11566. this.shades = [];
  11567. this.chart = chart;
  11568. this.setBaseSeries();
  11569. this.height = height;
  11570. this.scrollbarHeight = scrollbarHeight;
  11571. this.scrollbarEnabled = scrollbarEnabled;
  11572. this.navigatorEnabled = navigatorEnabled;
  11573. this.navigatorOptions = navigatorOptions;
  11574. this.scrollbarOptions = scrollbarOptions;
  11575. this.outlineHeight = height + scrollbarHeight;
  11576. this.opposite = pick(navigatorOptions.opposite, Boolean(!navigatorEnabled && chart.inverted)); // #6262
  11577. var navigator = this,
  11578. baseSeries = navigator.baseSeries,
  11579. xAxisIndex = chart.xAxis.length,
  11580. yAxisIndex = chart.yAxis.length,
  11581. baseXaxis = baseSeries && baseSeries[0] && baseSeries[0].xAxis ||
  11582. chart.xAxis[0] || { options: {} };
  11583. chart.isDirtyBox = true;
  11584. if (navigator.navigatorEnabled) {
  11585. // an x axis is required for scrollbar also
  11586. navigator.xAxis = new Axis(chart, merge({
  11587. // inherit base xAxis' break and ordinal options
  11588. breaks: baseXaxis.options.breaks,
  11589. ordinal: baseXaxis.options.ordinal
  11590. }, navigatorOptions.xAxis, {
  11591. id: 'navigator-x-axis',
  11592. yAxis: 'navigator-y-axis',
  11593. isX: true,
  11594. type: 'datetime',
  11595. index: xAxisIndex,
  11596. isInternal: true,
  11597. offset: 0,
  11598. keepOrdinalPadding: true,
  11599. startOnTick: false,
  11600. endOnTick: false,
  11601. minPadding: 0,
  11602. maxPadding: 0,
  11603. zoomEnabled: false
  11604. }, chart.inverted ? {
  11605. offsets: [scrollbarHeight, 0, -scrollbarHeight, 0],
  11606. width: height
  11607. } : {
  11608. offsets: [0, -scrollbarHeight, 0, scrollbarHeight],
  11609. height: height
  11610. }));
  11611. navigator.yAxis = new Axis(chart, merge(navigatorOptions.yAxis, {
  11612. id: 'navigator-y-axis',
  11613. alignTicks: false,
  11614. offset: 0,
  11615. index: yAxisIndex,
  11616. isInternal: true,
  11617. reversed: pick((navigatorOptions.yAxis && navigatorOptions.yAxis.reversed), (chart.yAxis[0] && chart.yAxis[0].reversed), false),
  11618. zoomEnabled: false
  11619. }, chart.inverted ? {
  11620. width: height
  11621. } : {
  11622. height: height
  11623. }));
  11624. // If we have a base series, initialize the navigator series
  11625. if (baseSeries || navigatorOptions.series.data) {
  11626. navigator.updateNavigatorSeries(false);
  11627. // If not, set up an event to listen for added series
  11628. }
  11629. else if (chart.series.length === 0) {
  11630. navigator.unbindRedraw = addEvent(chart, 'beforeRedraw', function () {
  11631. // We've got one, now add it as base
  11632. if (chart.series.length > 0 && !navigator.series) {
  11633. navigator.setBaseSeries();
  11634. navigator.unbindRedraw(); // reset
  11635. }
  11636. });
  11637. }
  11638. navigator.reversedExtremes = (chart.inverted && !navigator.xAxis.reversed) || (!chart.inverted && navigator.xAxis.reversed);
  11639. // Render items, so we can bind events to them:
  11640. navigator.renderElements();
  11641. // Add mouse events
  11642. navigator.addMouseEvents();
  11643. // in case of scrollbar only, fake an x axis to get translation
  11644. }
  11645. else {
  11646. navigator.xAxis = {
  11647. chart: chart,
  11648. navigatorAxis: {
  11649. fake: true
  11650. },
  11651. translate: function (value, reverse) {
  11652. var axis = chart.xAxis[0], ext = axis.getExtremes(), scrollTrackWidth = axis.len - 2 * scrollbarHeight, min = numExt('min', axis.options.min, ext.dataMin), valueRange = numExt('max', axis.options.max, ext.dataMax) - min;
  11653. return reverse ?
  11654. // from pixel to value
  11655. (value * valueRange / scrollTrackWidth) + min :
  11656. // from value to pixel
  11657. scrollTrackWidth * (value - min) / valueRange;
  11658. },
  11659. toPixels: function (value) {
  11660. return this.translate(value);
  11661. },
  11662. toValue: function (value) {
  11663. return this.translate(value, true);
  11664. }
  11665. };
  11666. navigator.xAxis.navigatorAxis.axis = navigator.xAxis;
  11667. navigator.xAxis.navigatorAxis.toFixedRange = (NavigatorAxis.AdditionsClass.prototype.toFixedRange.bind(navigator.xAxis.navigatorAxis));
  11668. }
  11669. // Initialize the scrollbar
  11670. if (chart.options.scrollbar.enabled) {
  11671. chart.scrollbar = navigator.scrollbar = new Scrollbar(chart.renderer, merge(chart.options.scrollbar, {
  11672. margin: navigator.navigatorEnabled ? 0 : 10,
  11673. vertical: chart.inverted
  11674. }), chart);
  11675. addEvent(navigator.scrollbar, 'changed', function (e) {
  11676. var range = navigator.size,
  11677. to = range * this.to,
  11678. from = range * this.from;
  11679. navigator.hasDragged = navigator.scrollbar.hasDragged;
  11680. navigator.render(0, 0, from, to);
  11681. if (chart.options.scrollbar.liveRedraw ||
  11682. (e.DOMType !== 'mousemove' &&
  11683. e.DOMType !== 'touchmove')) {
  11684. setTimeout(function () {
  11685. navigator.onMouseUp(e);
  11686. });
  11687. }
  11688. });
  11689. }
  11690. // Add data events
  11691. navigator.addBaseSeriesEvents();
  11692. // Add redraw events
  11693. navigator.addChartEvents();
  11694. };
  11695. /**
  11696. * Get the union data extremes of the chart - the outer data extremes of the
  11697. * base X axis and the navigator axis.
  11698. *
  11699. * @private
  11700. * @function Highcharts.Navigator#getUnionExtremes
  11701. * @param {boolean} [returnFalseOnNoBaseSeries]
  11702. * as the param says.
  11703. * @return {Highcharts.Dictionary<(number|undefined)>|undefined}
  11704. */
  11705. Navigator.prototype.getUnionExtremes = function (returnFalseOnNoBaseSeries) {
  11706. var baseAxis = this.chart.xAxis[0],
  11707. navAxis = this.xAxis,
  11708. navAxisOptions = navAxis.options,
  11709. baseAxisOptions = baseAxis.options,
  11710. ret;
  11711. if (!returnFalseOnNoBaseSeries || baseAxis.dataMin !== null) {
  11712. ret = {
  11713. dataMin: pick(// #4053
  11714. navAxisOptions && navAxisOptions.min, numExt('min', baseAxisOptions.min, baseAxis.dataMin, navAxis.dataMin, navAxis.min)),
  11715. dataMax: pick(navAxisOptions && navAxisOptions.max, numExt('max', baseAxisOptions.max, baseAxis.dataMax, navAxis.dataMax, navAxis.max))
  11716. };
  11717. }
  11718. return ret;
  11719. };
  11720. /**
  11721. * Set the base series and update the navigator series from this. With a bit
  11722. * of modification we should be able to make this an API method to be called
  11723. * from the outside
  11724. *
  11725. * @private
  11726. * @function Highcharts.Navigator#setBaseSeries
  11727. * @param {Highcharts.SeriesOptionsType} [baseSeriesOptions]
  11728. * Additional series options for a navigator
  11729. * @param {boolean} [redraw]
  11730. * Whether to redraw after update.
  11731. * @return {void}
  11732. */
  11733. Navigator.prototype.setBaseSeries = function (baseSeriesOptions, redraw) {
  11734. var chart = this.chart,
  11735. baseSeries = this.baseSeries = [];
  11736. baseSeriesOptions = (baseSeriesOptions ||
  11737. chart.options && chart.options.navigator.baseSeries ||
  11738. (chart.series.length ?
  11739. // Find the first non-navigator series (#8430)
  11740. find(chart.series, function (s) {
  11741. return !s.options.isInternal;
  11742. }).index :
  11743. 0));
  11744. // Iterate through series and add the ones that should be shown in
  11745. // navigator.
  11746. (chart.series || []).forEach(function (series, i) {
  11747. if (
  11748. // Don't include existing nav series
  11749. !series.options.isInternal &&
  11750. (series.options.showInNavigator ||
  11751. (i === baseSeriesOptions ||
  11752. series.options.id === baseSeriesOptions) &&
  11753. series.options.showInNavigator !== false)) {
  11754. baseSeries.push(series);
  11755. }
  11756. });
  11757. // When run after render, this.xAxis already exists
  11758. if (this.xAxis && !this.xAxis.navigatorAxis.fake) {
  11759. this.updateNavigatorSeries(true, redraw);
  11760. }
  11761. };
  11762. /**
  11763. * Update series in the navigator from baseSeries, adding new if does not
  11764. * exist.
  11765. *
  11766. * @private
  11767. * @function Highcharts.Navigator.updateNavigatorSeries
  11768. * @param {boolean} addEvents
  11769. * @param {boolean} [redraw]
  11770. * @return {void}
  11771. */
  11772. Navigator.prototype.updateNavigatorSeries = function (addEvents, redraw) {
  11773. var navigator = this,
  11774. chart = navigator.chart,
  11775. baseSeries = navigator.baseSeries,
  11776. baseOptions,
  11777. mergedNavSeriesOptions,
  11778. chartNavigatorSeriesOptions = navigator.navigatorOptions.series,
  11779. baseNavigatorOptions,
  11780. navSeriesMixin = {
  11781. enableMouseTracking: false,
  11782. index: null,
  11783. linkedTo: null,
  11784. group: 'nav',
  11785. padXAxis: false,
  11786. xAxis: 'navigator-x-axis',
  11787. yAxis: 'navigator-y-axis',
  11788. showInLegend: false,
  11789. stacking: void 0,
  11790. isInternal: true,
  11791. states: {
  11792. inactive: {
  11793. opacity: 1
  11794. }
  11795. }
  11796. },
  11797. // Remove navigator series that are no longer in the baseSeries
  11798. navigatorSeries = navigator.series =
  11799. (navigator.series || []).filter(function (navSeries) {
  11800. var base = navSeries.baseSeries;
  11801. if (baseSeries.indexOf(base) < 0) { // Not in array
  11802. // If there is still a base series connected to this
  11803. // series, remove event handler and reference.
  11804. if (base) {
  11805. removeEvent(base, 'updatedData', navigator.updatedDataHandler);
  11806. delete base.navigatorSeries;
  11807. }
  11808. // Kill the nav series. It may already have been
  11809. // destroyed (#8715).
  11810. if (navSeries.chart) {
  11811. navSeries.destroy();
  11812. }
  11813. return false;
  11814. }
  11815. return true;
  11816. });
  11817. // Go through each base series and merge the options to create new
  11818. // series
  11819. if (baseSeries && baseSeries.length) {
  11820. baseSeries.forEach(function eachBaseSeries(base) {
  11821. var linkedNavSeries = base.navigatorSeries,
  11822. userNavOptions = extend(
  11823. // Grab color and visibility from base as default
  11824. {
  11825. color: base.color,
  11826. visible: base.visible
  11827. }, !isArray(chartNavigatorSeriesOptions) ?
  11828. chartNavigatorSeriesOptions :
  11829. defaultOptions.navigator.series);
  11830. // Don't update if the series exists in nav and we have disabled
  11831. // adaptToUpdatedData.
  11832. if (linkedNavSeries &&
  11833. navigator.navigatorOptions.adaptToUpdatedData === false) {
  11834. return;
  11835. }
  11836. navSeriesMixin.name = 'Navigator ' + baseSeries.length;
  11837. baseOptions = base.options || {};
  11838. baseNavigatorOptions = baseOptions.navigatorOptions || {};
  11839. mergedNavSeriesOptions = merge(baseOptions, navSeriesMixin, userNavOptions, baseNavigatorOptions);
  11840. // Once nav series type is resolved, pick correct pointRange
  11841. mergedNavSeriesOptions.pointRange = pick(
  11842. // Stricte set pointRange in options
  11843. userNavOptions.pointRange, baseNavigatorOptions.pointRange,
  11844. // Fallback to default values, e.g. `null` for column
  11845. defaultOptions.plotOptions[mergedNavSeriesOptions.type || 'line'].pointRange);
  11846. // Merge data separately. Do a slice to avoid mutating the
  11847. // navigator options from base series (#4923).
  11848. var navigatorSeriesData = baseNavigatorOptions.data || userNavOptions.data;
  11849. navigator.hasNavigatorData =
  11850. navigator.hasNavigatorData || !!navigatorSeriesData;
  11851. mergedNavSeriesOptions.data =
  11852. navigatorSeriesData ||
  11853. baseOptions.data && baseOptions.data.slice(0);
  11854. // Update or add the series
  11855. if (linkedNavSeries && linkedNavSeries.options) {
  11856. linkedNavSeries.update(mergedNavSeriesOptions, redraw);
  11857. }
  11858. else {
  11859. base.navigatorSeries = chart.initSeries(mergedNavSeriesOptions);
  11860. base.navigatorSeries.baseSeries = base; // Store ref
  11861. navigatorSeries.push(base.navigatorSeries);
  11862. }
  11863. });
  11864. }
  11865. // If user has defined data (and no base series) or explicitly defined
  11866. // navigator.series as an array, we create these series on top of any
  11867. // base series.
  11868. if (chartNavigatorSeriesOptions.data &&
  11869. !(baseSeries && baseSeries.length) ||
  11870. isArray(chartNavigatorSeriesOptions)) {
  11871. navigator.hasNavigatorData = false;
  11872. // Allow navigator.series to be an array
  11873. chartNavigatorSeriesOptions =
  11874. splat(chartNavigatorSeriesOptions);
  11875. chartNavigatorSeriesOptions.forEach(function (userSeriesOptions, i) {
  11876. navSeriesMixin.name =
  11877. 'Navigator ' + (navigatorSeries.length + 1);
  11878. mergedNavSeriesOptions = merge(defaultOptions.navigator.series, {
  11879. // Since we don't have a base series to pull color from,
  11880. // try to fake it by using color from series with same
  11881. // index. Otherwise pull from the colors array. We need
  11882. // an explicit color as otherwise updates will increment
  11883. // color counter and we'll get a new color for each
  11884. // update of the nav series.
  11885. color: chart.series[i] &&
  11886. !chart.series[i].options.isInternal &&
  11887. chart.series[i].color ||
  11888. chart.options.colors[i] ||
  11889. chart.options.colors[0]
  11890. }, navSeriesMixin, userSeriesOptions);
  11891. mergedNavSeriesOptions.data = userSeriesOptions.data;
  11892. if (mergedNavSeriesOptions.data) {
  11893. navigator.hasNavigatorData = true;
  11894. navigatorSeries.push(chart.initSeries(mergedNavSeriesOptions));
  11895. }
  11896. });
  11897. }
  11898. if (addEvents) {
  11899. this.addBaseSeriesEvents();
  11900. }
  11901. };
  11902. /**
  11903. * Add data events.
  11904. * For example when main series is updated we need to recalculate extremes
  11905. *
  11906. * @private
  11907. * @function Highcharts.Navigator#addBaseSeriesEvent
  11908. * @return {void}
  11909. */
  11910. Navigator.prototype.addBaseSeriesEvents = function () {
  11911. var navigator = this,
  11912. baseSeries = navigator.baseSeries || [];
  11913. // Bind modified extremes event to first base's xAxis only.
  11914. // In event of > 1 base-xAxes, the navigator will ignore those.
  11915. // Adding this multiple times to the same axis is no problem, as
  11916. // duplicates should be discarded by the browser.
  11917. if (baseSeries[0] && baseSeries[0].xAxis) {
  11918. addEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  11919. }
  11920. baseSeries.forEach(function (base) {
  11921. // Link base series show/hide to navigator series visibility
  11922. addEvent(base, 'show', function () {
  11923. if (this.navigatorSeries) {
  11924. this.navigatorSeries.setVisible(true, false);
  11925. }
  11926. });
  11927. addEvent(base, 'hide', function () {
  11928. if (this.navigatorSeries) {
  11929. this.navigatorSeries.setVisible(false, false);
  11930. }
  11931. });
  11932. // Respond to updated data in the base series, unless explicitily
  11933. // not adapting to data changes.
  11934. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  11935. if (base.xAxis) {
  11936. addEvent(base, 'updatedData', this.updatedDataHandler);
  11937. }
  11938. }
  11939. // Handle series removal
  11940. addEvent(base, 'remove', function () {
  11941. if (this.navigatorSeries) {
  11942. erase(navigator.series, this.navigatorSeries);
  11943. if (defined(this.navigatorSeries.options)) {
  11944. this.navigatorSeries.remove(false);
  11945. }
  11946. delete this.navigatorSeries;
  11947. }
  11948. });
  11949. }, this);
  11950. };
  11951. /**
  11952. * Get minimum from all base series connected to the navigator
  11953. * @private
  11954. * @param {number} currentSeriesMin
  11955. * Minium from the current series
  11956. * @return {number} Minimum from all series
  11957. */
  11958. Navigator.prototype.getBaseSeriesMin = function (currentSeriesMin) {
  11959. return this.baseSeries.reduce(function (min, series) {
  11960. // (#10193)
  11961. return Math.min(min, series.xData ? series.xData[0] : min);
  11962. }, currentSeriesMin);
  11963. };
  11964. /**
  11965. * Set the navigator x axis extremes to reflect the total. The navigator
  11966. * extremes should always be the extremes of the union of all series in the
  11967. * chart as well as the navigator series.
  11968. *
  11969. * @private
  11970. * @function Highcharts.Navigator#modifyNavigatorAxisExtremes
  11971. */
  11972. Navigator.prototype.modifyNavigatorAxisExtremes = function () {
  11973. var xAxis = this.xAxis,
  11974. unionExtremes;
  11975. if (typeof xAxis.getExtremes !== 'undefined') {
  11976. unionExtremes = this.getUnionExtremes(true);
  11977. if (unionExtremes &&
  11978. (unionExtremes.dataMin !== xAxis.min ||
  11979. unionExtremes.dataMax !== xAxis.max)) {
  11980. xAxis.min = unionExtremes.dataMin;
  11981. xAxis.max = unionExtremes.dataMax;
  11982. }
  11983. }
  11984. };
  11985. /**
  11986. * Hook to modify the base axis extremes with information from the Navigator
  11987. *
  11988. * @private
  11989. * @function Highcharts.Navigator#modifyBaseAxisExtremes
  11990. */
  11991. Navigator.prototype.modifyBaseAxisExtremes = function () {
  11992. var baseXAxis = this,
  11993. navigator = baseXAxis.chart.navigator,
  11994. baseExtremes = baseXAxis.getExtremes(),
  11995. baseMin = baseExtremes.min,
  11996. baseMax = baseExtremes.max,
  11997. baseDataMin = baseExtremes.dataMin,
  11998. baseDataMax = baseExtremes.dataMax,
  11999. range = baseMax - baseMin,
  12000. stickToMin = navigator.stickToMin,
  12001. stickToMax = navigator.stickToMax,
  12002. overscroll = pick(baseXAxis.options.overscroll, 0),
  12003. newMax,
  12004. newMin,
  12005. navigatorSeries = navigator.series && navigator.series[0],
  12006. hasSetExtremes = !!baseXAxis.setExtremes,
  12007. // When the extremes have been set by range selector button, don't
  12008. // stick to min or max. The range selector buttons will handle the
  12009. // extremes. (#5489)
  12010. unmutable = baseXAxis.eventArgs &&
  12011. baseXAxis.eventArgs.trigger === 'rangeSelectorButton';
  12012. if (!unmutable) {
  12013. // If the zoomed range is already at the min, move it to the right
  12014. // as new data comes in
  12015. if (stickToMin) {
  12016. newMin = baseDataMin;
  12017. newMax = newMin + range;
  12018. }
  12019. // If the zoomed range is already at the max, move it to the right
  12020. // as new data comes in
  12021. if (stickToMax) {
  12022. newMax = baseDataMax + overscroll;
  12023. // If stickToMin is true, the new min value is set above
  12024. if (!stickToMin) {
  12025. newMin = Math.max(baseDataMin, // don't go below data extremes (#13184)
  12026. newMax - range, navigator.getBaseSeriesMin(navigatorSeries && navigatorSeries.xData ?
  12027. navigatorSeries.xData[0] :
  12028. -Number.MAX_VALUE));
  12029. }
  12030. }
  12031. // Update the extremes
  12032. if (hasSetExtremes && (stickToMin || stickToMax)) {
  12033. if (isNumber(newMin)) {
  12034. baseXAxis.min = baseXAxis.userMin = newMin;
  12035. baseXAxis.max = baseXAxis.userMax = newMax;
  12036. }
  12037. }
  12038. }
  12039. // Reset
  12040. navigator.stickToMin =
  12041. navigator.stickToMax = null;
  12042. };
  12043. /**
  12044. * Handler for updated data on the base series. When data is modified, the
  12045. * navigator series must reflect it. This is called from the Chart.redraw
  12046. * function before axis and series extremes are computed.
  12047. *
  12048. * @private
  12049. * @function Highcharts.Navigator#updateDataHandler
  12050. */
  12051. Navigator.prototype.updatedDataHandler = function () {
  12052. var navigator = this.chart.navigator,
  12053. baseSeries = this,
  12054. navigatorSeries = this.navigatorSeries,
  12055. xDataMin = navigator.getBaseSeriesMin(baseSeries.xData[0]);
  12056. // If the scrollbar is scrolled all the way to the right, keep right as
  12057. // new data comes in.
  12058. navigator.stickToMax = navigator.reversedExtremes ?
  12059. Math.round(navigator.zoomedMin) === 0 :
  12060. Math.round(navigator.zoomedMax) >= Math.round(navigator.size);
  12061. // Detect whether the zoomed area should stick to the minimum or
  12062. // maximum. If the current axis minimum falls outside the new updated
  12063. // dataset, we must adjust.
  12064. navigator.stickToMin = isNumber(baseSeries.xAxis.min) &&
  12065. (baseSeries.xAxis.min <= xDataMin) &&
  12066. (!this.chart.fixedRange || !navigator.stickToMax);
  12067. // Set the navigator series data to the new data of the base series
  12068. if (navigatorSeries && !navigator.hasNavigatorData) {
  12069. navigatorSeries.options.pointStart = baseSeries.xData[0];
  12070. navigatorSeries.setData(baseSeries.options.data, false, null, false); // #5414
  12071. }
  12072. };
  12073. /**
  12074. * Add chart events, like redrawing navigator, when chart requires that.
  12075. *
  12076. * @private
  12077. * @function Highcharts.Navigator#addChartEvents
  12078. * @return {void}
  12079. */
  12080. Navigator.prototype.addChartEvents = function () {
  12081. if (!this.eventsToUnbind) {
  12082. this.eventsToUnbind = [];
  12083. }
  12084. this.eventsToUnbind.push(
  12085. // Move the scrollbar after redraw, like after data updata even if
  12086. // axes don't redraw
  12087. addEvent(this.chart, 'redraw', function () {
  12088. var navigator = this.navigator,
  12089. xAxis = navigator && (navigator.baseSeries &&
  12090. navigator.baseSeries[0] &&
  12091. navigator.baseSeries[0].xAxis ||
  12092. this.xAxis[0]); // #5709, #13114
  12093. if (xAxis) {
  12094. navigator.render(xAxis.min,
  12095. xAxis.max);
  12096. }
  12097. }),
  12098. // Make room for the navigator, can be placed around the chart:
  12099. addEvent(this.chart, 'getMargins', function () {
  12100. var chart = this,
  12101. navigator = chart.navigator,
  12102. marginName = navigator.opposite ?
  12103. 'plotTop' : 'marginBottom';
  12104. if (chart.inverted) {
  12105. marginName = navigator.opposite ?
  12106. 'marginRight' : 'plotLeft';
  12107. }
  12108. chart[marginName] =
  12109. (chart[marginName] || 0) + (navigator.navigatorEnabled || !chart.inverted ?
  12110. navigator.outlineHeight :
  12111. 0) + navigator.navigatorOptions.margin;
  12112. }));
  12113. };
  12114. /**
  12115. * Destroys allocated elements.
  12116. *
  12117. * @private
  12118. * @function Highcharts.Navigator#destroy
  12119. */
  12120. Navigator.prototype.destroy = function () {
  12121. // Disconnect events added in addEvents
  12122. this.removeEvents();
  12123. if (this.xAxis) {
  12124. erase(this.chart.xAxis, this.xAxis);
  12125. erase(this.chart.axes, this.xAxis);
  12126. }
  12127. if (this.yAxis) {
  12128. erase(this.chart.yAxis, this.yAxis);
  12129. erase(this.chart.axes, this.yAxis);
  12130. }
  12131. // Destroy series
  12132. (this.series || []).forEach(function (s) {
  12133. if (s.destroy) {
  12134. s.destroy();
  12135. }
  12136. });
  12137. // Destroy properties
  12138. [
  12139. 'series', 'xAxis', 'yAxis', 'shades', 'outline', 'scrollbarTrack',
  12140. 'scrollbarRifles', 'scrollbarGroup', 'scrollbar', 'navigatorGroup',
  12141. 'rendered'
  12142. ].forEach(function (prop) {
  12143. if (this[prop] && this[prop].destroy) {
  12144. this[prop].destroy();
  12145. }
  12146. this[prop] = null;
  12147. }, this);
  12148. // Destroy elements in collection
  12149. [this.handles].forEach(function (coll) {
  12150. destroyObjectProperties(coll);
  12151. }, this);
  12152. };
  12153. return Navigator;
  12154. }());
  12155. // End of prototype
  12156. if (!H.Navigator) {
  12157. H.Navigator = Navigator;
  12158. NavigatorAxis.compose(Axis);
  12159. // For Stock charts. For x only zooming, do not to create the zoom button
  12160. // because X axis zooming is already allowed by the Navigator and Range
  12161. // selector. (#9285)
  12162. addEvent(Chart, 'beforeShowResetZoom', function () {
  12163. var chartOptions = this.options,
  12164. navigator = chartOptions.navigator,
  12165. rangeSelector = chartOptions.rangeSelector;
  12166. if (((navigator && navigator.enabled) ||
  12167. (rangeSelector && rangeSelector.enabled)) &&
  12168. ((!isTouchDevice && chartOptions.chart.zoomType === 'x') ||
  12169. (isTouchDevice && chartOptions.chart.pinchType === 'x'))) {
  12170. return false;
  12171. }
  12172. });
  12173. // Initialize navigator for stock charts
  12174. addEvent(Chart, 'beforeRender', function () {
  12175. var options = this.options;
  12176. if (options.navigator.enabled ||
  12177. options.scrollbar.enabled) {
  12178. this.scroller = this.navigator = new Navigator(this);
  12179. }
  12180. });
  12181. // For stock charts, extend the Chart.setChartSize method so that we can set
  12182. // the final top position of the navigator once the height of the chart,
  12183. // including the legend, is determined. #367. We can't use Chart.getMargins,
  12184. // because labels offsets are not calculated yet.
  12185. addEvent(Chart, 'afterSetChartSize', function () {
  12186. var legend = this.legend,
  12187. navigator = this.navigator,
  12188. scrollbarHeight,
  12189. legendOptions,
  12190. xAxis,
  12191. yAxis;
  12192. if (navigator) {
  12193. legendOptions = legend && legend.options;
  12194. xAxis = navigator.xAxis;
  12195. yAxis = navigator.yAxis;
  12196. scrollbarHeight = navigator.scrollbarHeight;
  12197. // Compute the top position
  12198. if (this.inverted) {
  12199. navigator.left = navigator.opposite ?
  12200. this.chartWidth - scrollbarHeight -
  12201. navigator.height :
  12202. this.spacing[3] + scrollbarHeight;
  12203. navigator.top = this.plotTop + scrollbarHeight;
  12204. }
  12205. else {
  12206. navigator.left = this.plotLeft + scrollbarHeight;
  12207. navigator.top = navigator.navigatorOptions.top ||
  12208. this.chartHeight -
  12209. navigator.height -
  12210. scrollbarHeight -
  12211. this.spacing[2] -
  12212. (this.rangeSelector && this.extraBottomMargin ?
  12213. this.rangeSelector.getHeight() :
  12214. 0) -
  12215. ((legendOptions &&
  12216. legendOptions.verticalAlign === 'bottom' &&
  12217. legendOptions.layout !== 'proximate' && // #13392
  12218. legendOptions.enabled &&
  12219. !legendOptions.floating) ?
  12220. legend.legendHeight +
  12221. pick(legendOptions.margin, 10) :
  12222. 0) -
  12223. (this.titleOffset ? this.titleOffset[2] : 0);
  12224. }
  12225. if (xAxis && yAxis) { // false if navigator is disabled (#904)
  12226. if (this.inverted) {
  12227. xAxis.options.left = yAxis.options.left = navigator.left;
  12228. }
  12229. else {
  12230. xAxis.options.top = yAxis.options.top = navigator.top;
  12231. }
  12232. xAxis.setAxisSize();
  12233. yAxis.setAxisSize();
  12234. }
  12235. }
  12236. });
  12237. // Merge options, if no scrolling exists yet
  12238. addEvent(Chart, 'update', function (e) {
  12239. var navigatorOptions = (e.options.navigator || {}),
  12240. scrollbarOptions = (e.options.scrollbar || {});
  12241. if (!this.navigator && !this.scroller &&
  12242. (navigatorOptions.enabled || scrollbarOptions.enabled)) {
  12243. merge(true, this.options.navigator, navigatorOptions);
  12244. merge(true, this.options.scrollbar, scrollbarOptions);
  12245. delete e.options.navigator;
  12246. delete e.options.scrollbar;
  12247. }
  12248. });
  12249. // Initialize navigator, if no scrolling exists yet
  12250. addEvent(Chart, 'afterUpdate', function (event) {
  12251. if (!this.navigator && !this.scroller &&
  12252. (this.options.navigator.enabled ||
  12253. this.options.scrollbar.enabled)) {
  12254. this.scroller = this.navigator = new Navigator(this);
  12255. if (pick(event.redraw, true)) {
  12256. this.redraw(event.animation); // #7067
  12257. }
  12258. }
  12259. });
  12260. // Handle adding new series
  12261. addEvent(Chart, 'afterAddSeries', function () {
  12262. if (this.navigator) {
  12263. // Recompute which series should be shown in navigator, and add them
  12264. this.navigator.setBaseSeries(null, false);
  12265. }
  12266. });
  12267. // Handle updating series
  12268. addEvent(LineSeries, 'afterUpdate', function () {
  12269. if (this.chart.navigator && !this.options.isInternal) {
  12270. this.chart.navigator.setBaseSeries(null, false);
  12271. }
  12272. });
  12273. Chart.prototype.callbacks.push(function (chart) {
  12274. var extremes,
  12275. navigator = chart.navigator;
  12276. // Initialize the navigator
  12277. if (navigator && chart.xAxis[0]) {
  12278. extremes = chart.xAxis[0].getExtremes();
  12279. navigator.render(extremes.min, extremes.max);
  12280. }
  12281. });
  12282. }
  12283. H.Navigator = Navigator;
  12284. return H.Navigator;
  12285. });
  12286. _registerModule(_modules, 'masters/modules/gantt.src.js', [], function () {
  12287. });
  12288. }));