gantt.src.js 579 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442
  1. /**
  2. * @license Highcharts Gantt JS v9.1.1 (2021-06-04)
  3. *
  4. * Gantt series
  5. *
  6. * (c) 2016-2021 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, 'Series/XRange/XRangePoint.js', [_modules['Core/Series/Point.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (Point, SeriesRegistry, U) {
  32. /* *
  33. *
  34. * X-range series module
  35. *
  36. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. var __extends = (this && this.__extends) || (function () {
  44. var extendStatics = function (d,
  45. b) {
  46. extendStatics = Object.setPrototypeOf ||
  47. ({ __proto__: [] } instanceof Array && function (d,
  48. b) { d.__proto__ = b; }) ||
  49. function (d,
  50. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  51. return extendStatics(d, b);
  52. };
  53. return function (d, b) {
  54. extendStatics(d, b);
  55. function __() { this.constructor = d; }
  56. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  57. };
  58. })();
  59. var ColumnSeries = SeriesRegistry.seriesTypes.column;
  60. var extend = U.extend;
  61. /* *
  62. *
  63. * Class
  64. *
  65. * */
  66. var XRangePoint = /** @class */ (function (_super) {
  67. __extends(XRangePoint, _super);
  68. function XRangePoint() {
  69. var _this = _super !== null && _super.apply(this,
  70. arguments) || this;
  71. /* *
  72. *
  73. * Properties
  74. *
  75. * */
  76. _this.options = void 0;
  77. _this.series = void 0;
  78. return _this;
  79. /* eslint-enable valid-jsdoc */
  80. }
  81. /* *
  82. *
  83. * Static properties
  84. *
  85. * */
  86. /**
  87. * Return color of a point based on its category.
  88. *
  89. * @private
  90. * @function getColorByCategory
  91. *
  92. * @param {object} series
  93. * The series which the point belongs to.
  94. *
  95. * @param {object} point
  96. * The point to calculate its color for.
  97. *
  98. * @return {object}
  99. * Returns an object containing the properties color and colorIndex.
  100. */
  101. XRangePoint.getColorByCategory = function (series, point) {
  102. var colors = series.options.colors || series.chart.options.colors,
  103. colorCount = colors ?
  104. colors.length :
  105. series.chart.options.chart.colorCount,
  106. colorIndex = point.y % colorCount,
  107. color = colors && colors[colorIndex];
  108. return {
  109. colorIndex: colorIndex,
  110. color: color
  111. };
  112. };
  113. /* *
  114. *
  115. * Functions
  116. *
  117. * */
  118. /**
  119. * The ending X value of the range point.
  120. * @name Highcharts.Point#x2
  121. * @type {number|undefined}
  122. * @requires modules/xrange
  123. */
  124. /**
  125. * Extend applyOptions so that `colorByPoint` for x-range means that one
  126. * color is applied per Y axis category.
  127. *
  128. * @private
  129. * @function Highcharts.Point#applyOptions
  130. *
  131. * @return {Highcharts.Series}
  132. */
  133. /* eslint-disable valid-jsdoc */
  134. /**
  135. * @private
  136. */
  137. XRangePoint.prototype.resolveColor = function () {
  138. var series = this.series,
  139. colorByPoint;
  140. if (series.options.colorByPoint && !this.options.color) {
  141. colorByPoint = XRangePoint.getColorByCategory(series, this);
  142. if (!series.chart.styledMode) {
  143. this.color = colorByPoint.color;
  144. }
  145. if (!this.options.colorIndex) {
  146. this.colorIndex = colorByPoint.colorIndex;
  147. }
  148. }
  149. else if (!this.color) {
  150. this.color = series.color;
  151. }
  152. };
  153. /**
  154. * Extend init to have y default to 0.
  155. *
  156. * @private
  157. * @function Highcharts.Point#init
  158. *
  159. * @return {Highcharts.Point}
  160. */
  161. XRangePoint.prototype.init = function () {
  162. Point.prototype.init.apply(this, arguments);
  163. if (!this.y) {
  164. this.y = 0;
  165. }
  166. return this;
  167. };
  168. /**
  169. * @private
  170. * @function Highcharts.Point#setState
  171. */
  172. XRangePoint.prototype.setState = function () {
  173. Point.prototype.setState.apply(this, arguments);
  174. this.series.drawPoint(this, this.series.getAnimationVerb());
  175. };
  176. /**
  177. * @private
  178. * @function Highcharts.Point#getLabelConfig
  179. *
  180. * @return {Highcharts.PointLabelObject}
  181. */
  182. // Add x2 and yCategory to the available properties for tooltip formats
  183. XRangePoint.prototype.getLabelConfig = function () {
  184. var point = this,
  185. cfg = Point.prototype.getLabelConfig.call(point),
  186. yCats = point.series.yAxis.categories;
  187. cfg.x2 = point.x2;
  188. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  189. return cfg;
  190. };
  191. /**
  192. * @private
  193. * @function Highcharts.Point#isValid
  194. *
  195. * @return {boolean}
  196. */
  197. XRangePoint.prototype.isValid = function () {
  198. return typeof this.x === 'number' &&
  199. typeof this.x2 === 'number';
  200. };
  201. return XRangePoint;
  202. }(ColumnSeries.prototype.pointClass));
  203. extend(XRangePoint.prototype, {
  204. tooltipDateKeys: ['x', 'x2']
  205. });
  206. /* *
  207. *
  208. * Default Export
  209. *
  210. * */
  211. return XRangePoint;
  212. });
  213. _registerModule(_modules, 'Series/XRange/XRangeComposition.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Utilities.js']], function (Axis, U) {
  214. /* *
  215. *
  216. * X-range series module
  217. *
  218. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  219. *
  220. * License: www.highcharts.com/license
  221. *
  222. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  223. *
  224. * */
  225. /* *
  226. *
  227. * Imports
  228. *
  229. * */
  230. /* *
  231. *
  232. * Imports
  233. *
  234. * */
  235. var addEvent = U.addEvent,
  236. pick = U.pick;
  237. /**
  238. * Max x2 should be considered in xAxis extremes
  239. */
  240. addEvent(Axis, 'afterGetSeriesExtremes', function () {
  241. var axis = this, // eslint-disable-line no-invalid-this
  242. axisSeries = axis.series,
  243. dataMax,
  244. modMax;
  245. if (axis.isXAxis) {
  246. dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
  247. axisSeries.forEach(function (series) {
  248. if (series.x2Data) {
  249. series.x2Data
  250. .forEach(function (val) {
  251. if (val > dataMax) {
  252. dataMax = val;
  253. modMax = true;
  254. }
  255. });
  256. }
  257. });
  258. if (modMax) {
  259. axis.dataMax = dataMax;
  260. }
  261. }
  262. });
  263. });
  264. _registerModule(_modules, 'Series/XRange/XRangeSeries.js', [_modules['Core/Globals.js'], _modules['Core/Color/Color.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js'], _modules['Series/XRange/XRangePoint.js']], function (H, Color, SeriesRegistry, U, XRangePoint) {
  265. /* *
  266. *
  267. * X-range series module
  268. *
  269. * (c) 2010-2021 Torstein Honsi, Lars A. V. Cabrera
  270. *
  271. * License: www.highcharts.com/license
  272. *
  273. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  274. *
  275. * */
  276. var __extends = (this && this.__extends) || (function () {
  277. var extendStatics = function (d,
  278. b) {
  279. extendStatics = Object.setPrototypeOf ||
  280. ({ __proto__: [] } instanceof Array && function (d,
  281. b) { d.__proto__ = b; }) ||
  282. function (d,
  283. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  284. return extendStatics(d, b);
  285. };
  286. return function (d, b) {
  287. extendStatics(d, b);
  288. function __() { this.constructor = d; }
  289. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  290. };
  291. })();
  292. var color = Color.parse;
  293. var Series = SeriesRegistry.series,
  294. ColumnSeries = SeriesRegistry.seriesTypes.column;
  295. var columnProto = ColumnSeries.prototype;
  296. var clamp = U.clamp,
  297. correctFloat = U.correctFloat,
  298. defined = U.defined,
  299. extend = U.extend,
  300. find = U.find,
  301. isNumber = U.isNumber,
  302. isObject = U.isObject,
  303. merge = U.merge,
  304. pick = U.pick;
  305. /* *
  306. * @interface Highcharts.PointOptionsObject in parts/Point.ts
  307. */ /**
  308. * The ending X value of the range point.
  309. * @name Highcharts.PointOptionsObject#x2
  310. * @type {number|undefined}
  311. * @requires modules/xrange
  312. */
  313. /**
  314. * @private
  315. * @class
  316. * @name Highcharts.seriesTypes.xrange
  317. *
  318. * @augments Highcharts.Series
  319. */
  320. var XRangeSeries = /** @class */ (function (_super) {
  321. __extends(XRangeSeries, _super);
  322. function XRangeSeries() {
  323. var _this = _super !== null && _super.apply(this,
  324. arguments) || this;
  325. /* *
  326. *
  327. * Properties
  328. *
  329. * */
  330. _this.data = void 0;
  331. _this.options = void 0;
  332. _this.points = void 0;
  333. return _this;
  334. /*
  335. // Override to remove stroke from points. For partial fill.
  336. pointAttribs: function () {
  337. let series = this,
  338. retVal = columnType.prototype.pointAttribs
  339. .apply(series, arguments);
  340. //retVal['stroke-width'] = 0;
  341. return retVal;
  342. }
  343. //*/
  344. /* eslint-enable valid-jsdoc */
  345. }
  346. /* *
  347. *
  348. * Functions
  349. *
  350. * */
  351. /* eslint-disable valid-jsdoc */
  352. /**
  353. * @private
  354. * @function Highcarts.seriesTypes.xrange#init
  355. * @return {void}
  356. */
  357. XRangeSeries.prototype.init = function () {
  358. ColumnSeries.prototype.init.apply(this, arguments);
  359. this.options.stacking = void 0; // #13161
  360. };
  361. /**
  362. * Borrow the column series metrics, but with swapped axes. This gives
  363. * free access to features like groupPadding, grouping, pointWidth etc.
  364. *
  365. * @private
  366. * @function Highcharts.Series#getColumnMetrics
  367. *
  368. * @return {Highcharts.ColumnMetricsObject}
  369. */
  370. XRangeSeries.prototype.getColumnMetrics = function () {
  371. var metrics,
  372. chart = this.chart;
  373. /**
  374. * @private
  375. */
  376. function swapAxes() {
  377. chart.series.forEach(function (s) {
  378. var xAxis = s.xAxis;
  379. s.xAxis = s.yAxis;
  380. s.yAxis = xAxis;
  381. });
  382. }
  383. swapAxes();
  384. metrics = columnProto.getColumnMetrics.call(this);
  385. swapAxes();
  386. return metrics;
  387. };
  388. /**
  389. * Override cropData to show a point where x or x2 is outside visible
  390. * range, but one of them is inside.
  391. *
  392. * @private
  393. * @function Highcharts.Series#cropData
  394. *
  395. * @param {Array<number>} xData
  396. *
  397. * @param {Array<number>} yData
  398. *
  399. * @param {number} min
  400. *
  401. * @param {number} max
  402. *
  403. * @param {number} [cropShoulder]
  404. *
  405. * @return {*}
  406. */
  407. XRangeSeries.prototype.cropData = function (xData, yData, min, max) {
  408. // Replace xData with x2Data to find the appropriate cropStart
  409. var cropData = Series.prototype.cropData,
  410. crop = cropData.call(this,
  411. this.x2Data,
  412. yData,
  413. min,
  414. max);
  415. // Re-insert the cropped xData
  416. crop.xData = xData.slice(crop.start, crop.end);
  417. return crop;
  418. };
  419. /**
  420. * Finds the index of an existing point that matches the given point
  421. * options.
  422. *
  423. * @private
  424. * @function Highcharts.Series#findPointIndex
  425. * @param {object} options The options of the point.
  426. * @returns {number|undefined} Returns index of a matching point,
  427. * returns undefined if no match is found.
  428. */
  429. XRangeSeries.prototype.findPointIndex = function (options) {
  430. var _a = this,
  431. cropped = _a.cropped,
  432. cropStart = _a.cropStart,
  433. points = _a.points;
  434. var id = options.id;
  435. var pointIndex;
  436. if (id) {
  437. var point = find(points,
  438. function (point) {
  439. return point.id === id;
  440. });
  441. pointIndex = point ? point.index : void 0;
  442. }
  443. if (typeof pointIndex === 'undefined') {
  444. var point = find(points,
  445. function (point) {
  446. return (point.x === options.x &&
  447. point.x2 === options.x2 &&
  448. !point.touched);
  449. });
  450. pointIndex = point ? point.index : void 0;
  451. }
  452. // Reduce pointIndex if data is cropped
  453. if (cropped &&
  454. isNumber(pointIndex) &&
  455. isNumber(cropStart) &&
  456. pointIndex >= cropStart) {
  457. pointIndex -= cropStart;
  458. }
  459. return pointIndex;
  460. };
  461. /**
  462. * @private
  463. * @function Highcharts.Series#translatePoint
  464. *
  465. * @param {Highcharts.Point} point
  466. */
  467. XRangeSeries.prototype.translatePoint = function (point) {
  468. var series = this,
  469. xAxis = series.xAxis,
  470. yAxis = series.yAxis,
  471. metrics = series.columnMetrics,
  472. options = series.options,
  473. minPointLength = options.minPointLength || 0,
  474. oldColWidth = (point.shapeArgs && point.shapeArgs.width || 0) / 2,
  475. seriesXOffset = series.pointXOffset = metrics.offset,
  476. plotX = point.plotX,
  477. posX = pick(point.x2,
  478. point.x + (point.len || 0)),
  479. plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
  480. length = Math.abs(plotX2 - plotX),
  481. widthDifference,
  482. partialFill,
  483. inverted = this.chart.inverted,
  484. borderWidth = pick(options.borderWidth, 1),
  485. crisper = borderWidth % 2 / 2,
  486. yOffset = metrics.offset,
  487. pointHeight = Math.round(metrics.width),
  488. dlLeft,
  489. dlRight,
  490. dlWidth,
  491. clipRectWidth,
  492. tooltipYOffset;
  493. if (minPointLength) {
  494. widthDifference = minPointLength - length;
  495. if (widthDifference < 0) {
  496. widthDifference = 0;
  497. }
  498. plotX -= widthDifference / 2;
  499. plotX2 += widthDifference / 2;
  500. }
  501. plotX = Math.max(plotX, -10);
  502. plotX2 = clamp(plotX2, -10, xAxis.len + 10);
  503. // Handle individual pointWidth
  504. if (defined(point.options.pointWidth)) {
  505. yOffset -= ((Math.ceil(point.options.pointWidth) - pointHeight) / 2);
  506. pointHeight = Math.ceil(point.options.pointWidth);
  507. }
  508. // Apply pointPlacement to the Y axis
  509. if (options.pointPlacement &&
  510. isNumber(point.plotY) &&
  511. yAxis.categories) {
  512. point.plotY = yAxis.translate(point.y, 0, 1, 0, 1, options.pointPlacement);
  513. }
  514. var shapeArgs = {
  515. x: Math.floor(Math.min(plotX,
  516. plotX2)) + crisper,
  517. y: Math.floor(point.plotY + yOffset) + crisper,
  518. width: Math.round(Math.abs(plotX2 - plotX)),
  519. height: pointHeight,
  520. r: series.options.borderRadius
  521. };
  522. point.shapeArgs = shapeArgs;
  523. // Move tooltip to default position
  524. if (!inverted) {
  525. point.tooltipPos[0] -= oldColWidth +
  526. seriesXOffset -
  527. shapeArgs.width / 2;
  528. }
  529. else {
  530. point.tooltipPos[1] += seriesXOffset +
  531. oldColWidth;
  532. }
  533. // Align data labels inside the shape and inside the plot area
  534. dlLeft = shapeArgs.x;
  535. dlRight = dlLeft + shapeArgs.width;
  536. if (dlLeft < 0 || dlRight > xAxis.len) {
  537. dlLeft = clamp(dlLeft, 0, xAxis.len);
  538. dlRight = clamp(dlRight, 0, xAxis.len);
  539. dlWidth = dlRight - dlLeft;
  540. point.dlBox = merge(shapeArgs, {
  541. x: dlLeft,
  542. width: dlRight - dlLeft,
  543. centerX: dlWidth ? dlWidth / 2 : null
  544. });
  545. }
  546. else {
  547. point.dlBox = null;
  548. }
  549. // Tooltip position
  550. var tooltipPos = point.tooltipPos;
  551. var xIndex = !inverted ? 0 : 1;
  552. var yIndex = !inverted ? 1 : 0;
  553. tooltipYOffset = series.columnMetrics ?
  554. series.columnMetrics.offset : -metrics.width / 2;
  555. // Centering tooltip position (#14147)
  556. if (!inverted) {
  557. tooltipPos[xIndex] += (xAxis.reversed ? -1 : 0) * shapeArgs.width;
  558. }
  559. else {
  560. tooltipPos[xIndex] += shapeArgs.width / 2;
  561. }
  562. tooltipPos[yIndex] = clamp(tooltipPos[yIndex] + ((inverted ? -1 : 1) * tooltipYOffset), 0, yAxis.len - 1);
  563. // Add a partShapeArgs to the point, based on the shapeArgs property
  564. partialFill = point.partialFill;
  565. if (partialFill) {
  566. // Get the partial fill amount
  567. if (isObject(partialFill)) {
  568. partialFill = partialFill.amount;
  569. }
  570. // If it was not a number, assume 0
  571. if (!isNumber(partialFill)) {
  572. partialFill = 0;
  573. }
  574. point.partShapeArgs = merge(shapeArgs, {
  575. r: series.options.borderRadius
  576. });
  577. clipRectWidth = Math.max(Math.round(length * partialFill + point.plotX -
  578. plotX), 0);
  579. point.clipRectArgs = {
  580. x: xAxis.reversed ? // #10717
  581. shapeArgs.x + length - clipRectWidth :
  582. shapeArgs.x,
  583. y: shapeArgs.y,
  584. width: clipRectWidth,
  585. height: shapeArgs.height
  586. };
  587. }
  588. };
  589. /**
  590. * @private
  591. * @function Highcharts.Series#translate
  592. */
  593. XRangeSeries.prototype.translate = function () {
  594. columnProto.translate.apply(this, arguments);
  595. this.points.forEach(function (point) {
  596. this.translatePoint(point);
  597. }, this);
  598. };
  599. /**
  600. * Draws a single point in the series. Needed for partial fill.
  601. *
  602. * This override turns point.graphic into a group containing the
  603. * original graphic and an overlay displaying the partial fill.
  604. *
  605. * @private
  606. * @function Highcharts.Series#drawPoint
  607. *
  608. * @param {Highcharts.Point} point
  609. * An instance of Point in the series.
  610. *
  611. * @param {"animate"|"attr"} verb
  612. * 'animate' (animates changes) or 'attr' (sets options)
  613. */
  614. XRangeSeries.prototype.drawPoint = function (point, verb) {
  615. var series = this,
  616. seriesOpts = series.options,
  617. renderer = series.chart.renderer,
  618. graphic = point.graphic,
  619. type = point.shapeType,
  620. shapeArgs = point.shapeArgs,
  621. partShapeArgs = point.partShapeArgs,
  622. clipRectArgs = point.clipRectArgs,
  623. pfOptions = point.partialFill,
  624. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  625. pointState = point.state,
  626. stateOpts = (seriesOpts.states[pointState || 'normal'] ||
  627. {}),
  628. pointStateVerb = typeof pointState === 'undefined' ?
  629. 'attr' : verb,
  630. pointAttr = series.pointAttribs(point,
  631. pointState),
  632. animation = pick(series.chart.options.chart.animation,
  633. stateOpts.animation),
  634. fill;
  635. if (!point.isNull && point.visible !== false) {
  636. // Original graphic
  637. if (graphic) { // update
  638. graphic.rect[verb](shapeArgs);
  639. }
  640. else {
  641. point.graphic = graphic = renderer.g('point')
  642. .addClass(point.getClassName())
  643. .add(point.group || series.group);
  644. graphic.rect = renderer[type](merge(shapeArgs))
  645. .addClass(point.getClassName())
  646. .addClass('highcharts-partfill-original')
  647. .add(graphic);
  648. }
  649. // Partial fill graphic
  650. if (partShapeArgs) {
  651. if (graphic.partRect) {
  652. graphic.partRect[verb](merge(partShapeArgs));
  653. graphic.partialClipRect[verb](merge(clipRectArgs));
  654. }
  655. else {
  656. graphic.partialClipRect = renderer.clipRect(clipRectArgs.x, clipRectArgs.y, clipRectArgs.width, clipRectArgs.height);
  657. graphic.partRect =
  658. renderer[type](partShapeArgs)
  659. .addClass('highcharts-partfill-overlay')
  660. .add(graphic)
  661. .clip(graphic.partialClipRect);
  662. }
  663. }
  664. // Presentational
  665. if (!series.chart.styledMode) {
  666. graphic
  667. .rect[verb](pointAttr, animation)
  668. .shadow(seriesOpts.shadow, null, cutOff);
  669. if (partShapeArgs) {
  670. // Ensure pfOptions is an object
  671. if (!isObject(pfOptions)) {
  672. pfOptions = {};
  673. }
  674. if (isObject(seriesOpts.partialFill)) {
  675. pfOptions = merge(seriesOpts.partialFill, pfOptions);
  676. }
  677. fill = (pfOptions.fill ||
  678. color(pointAttr.fill).brighten(-0.3).get() ||
  679. color(point.color || series.color)
  680. .brighten(-0.3).get());
  681. pointAttr.fill = fill;
  682. graphic
  683. .partRect[pointStateVerb](pointAttr, animation)
  684. .shadow(seriesOpts.shadow, null, cutOff);
  685. }
  686. }
  687. }
  688. else if (graphic) {
  689. point.graphic = graphic.destroy(); // #1269
  690. }
  691. };
  692. /**
  693. * @private
  694. * @function Highcharts.Series#drawPoints
  695. */
  696. XRangeSeries.prototype.drawPoints = function () {
  697. var series = this,
  698. verb = series.getAnimationVerb();
  699. // Draw the columns
  700. series.points.forEach(function (point) {
  701. series.drawPoint(point, verb);
  702. });
  703. };
  704. /**
  705. * Returns "animate", or "attr" if the number of points is above the
  706. * animation limit.
  707. *
  708. * @private
  709. * @function Highcharts.Series#getAnimationVerb
  710. *
  711. * @return {string}
  712. */
  713. XRangeSeries.prototype.getAnimationVerb = function () {
  714. return (this.chart.pointCount < (this.options.animationLimit || 250) ?
  715. 'animate' :
  716. 'attr');
  717. };
  718. /**
  719. * @private
  720. * @function Highcharts.XRangeSeries#isPointInside
  721. */
  722. XRangeSeries.prototype.isPointInside = function (point) {
  723. var shapeArgs = point.shapeArgs,
  724. plotX = point.plotX,
  725. plotY = point.plotY;
  726. if (!shapeArgs) {
  727. return _super.prototype.isPointInside.apply(this, arguments);
  728. }
  729. var isInside = typeof plotX !== 'undefined' &&
  730. typeof plotY !== 'undefined' &&
  731. plotY >= 0 &&
  732. plotY <= this.yAxis.len &&
  733. (shapeArgs.x || 0) + (shapeArgs.width || 0) >= 0 &&
  734. plotX <= this.xAxis.len;
  735. return isInside;
  736. };
  737. /* *
  738. *
  739. * Static properties
  740. *
  741. * */
  742. /**
  743. * The X-range series displays ranges on the X axis, typically time
  744. * intervals with a start and end date.
  745. *
  746. * @sample {highcharts} highcharts/demo/x-range/
  747. * X-range
  748. * @sample {highcharts} highcharts/css/x-range/
  749. * Styled mode X-range
  750. * @sample {highcharts} highcharts/chart/inverted-xrange/
  751. * Inverted X-range
  752. *
  753. * @extends plotOptions.column
  754. * @since 6.0.0
  755. * @product highcharts highstock gantt
  756. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor,
  757. * edgeWidth, findNearestPointBy, getExtremesFromAll,
  758. * negativeColor, pointInterval, pointIntervalUnit,
  759. * pointPlacement, pointRange, pointStart, softThreshold,
  760. * stacking, threshold, data, dataSorting, boostBlending
  761. * @requires modules/xrange
  762. * @optionparent plotOptions.xrange
  763. */
  764. XRangeSeries.defaultOptions = merge(ColumnSeries.defaultOptions, {
  765. /**
  766. * A partial fill for each point, typically used to visualize how much
  767. * of a task is performed. The partial fill object can be set either on
  768. * series or point level.
  769. *
  770. * @sample {highcharts} highcharts/demo/x-range
  771. * X-range with partial fill
  772. *
  773. * @product highcharts highstock gantt
  774. * @apioption plotOptions.xrange.partialFill
  775. */
  776. /**
  777. * The fill color to be used for partial fills. Defaults to a darker
  778. * shade of the point color.
  779. *
  780. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  781. * @product highcharts highstock gantt
  782. * @apioption plotOptions.xrange.partialFill.fill
  783. */
  784. /**
  785. * A partial fill for each point, typically used to visualize how much
  786. * of a task is performed. See [completed](series.gantt.data.completed).
  787. *
  788. * @sample gantt/demo/progress-indicator
  789. * Gantt with progress indicator
  790. *
  791. * @product gantt
  792. * @apioption plotOptions.gantt.partialFill
  793. */
  794. /**
  795. * In an X-range series, this option makes all points of the same Y-axis
  796. * category the same color.
  797. */
  798. colorByPoint: true,
  799. dataLabels: {
  800. formatter: function () {
  801. var point = this.point,
  802. amount = point.partialFill;
  803. if (isObject(amount)) {
  804. amount = amount.amount;
  805. }
  806. if (isNumber(amount) && amount > 0) {
  807. return correctFloat(amount * 100) + '%';
  808. }
  809. },
  810. inside: true,
  811. verticalAlign: 'middle'
  812. },
  813. tooltip: {
  814. headerFormat: '<span style="font-size: 10px">{point.x} - {point.x2}</span><br/>',
  815. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
  816. },
  817. borderRadius: 3,
  818. pointRange: 0
  819. });
  820. return XRangeSeries;
  821. }(ColumnSeries));
  822. extend(XRangeSeries.prototype, {
  823. type: 'xrange',
  824. parallelArrays: ['x', 'x2', 'y'],
  825. requireSorting: false,
  826. animate: Series.prototype.animate,
  827. cropShoulder: 1,
  828. getExtremesFromAll: true,
  829. autoIncrement: H.noop,
  830. buildKDTree: H.noop,
  831. pointClass: XRangePoint
  832. });
  833. SeriesRegistry.registerSeriesType('xrange', XRangeSeries);
  834. /* *
  835. *
  836. * Default Export
  837. *
  838. * */
  839. /* *
  840. *
  841. * API Options
  842. *
  843. * */
  844. /**
  845. * An `xrange` series. If the [type](#series.xrange.type) option is not
  846. * specified, it is inherited from [chart.type](#chart.type).
  847. *
  848. * @extends series,plotOptions.xrange
  849. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor, edgeWidth,
  850. * findNearestPointBy, getExtremesFromAll, negativeColor,
  851. * pointInterval, pointIntervalUnit, pointPlacement, pointRange,
  852. * pointStart, softThreshold, stacking, threshold, dataSorting,
  853. * boostBlending
  854. * @product highcharts highstock gantt
  855. * @requires modules/xrange
  856. * @apioption series.xrange
  857. */
  858. /**
  859. * An array of data points for the series. For the `xrange` series type,
  860. * points can be given in the following ways:
  861. *
  862. * 1. An array of objects with named values. The objects are point configuration
  863. * objects as seen below.
  864. * ```js
  865. * data: [{
  866. * x: Date.UTC(2017, 0, 1),
  867. * x2: Date.UTC(2017, 0, 3),
  868. * name: "Test",
  869. * y: 0,
  870. * color: "#00FF00"
  871. * }, {
  872. * x: Date.UTC(2017, 0, 4),
  873. * x2: Date.UTC(2017, 0, 5),
  874. * name: "Deploy",
  875. * y: 1,
  876. * color: "#FF0000"
  877. * }]
  878. * ```
  879. *
  880. * @sample {highcharts} highcharts/series/data-array-of-objects/
  881. * Config objects
  882. *
  883. * @declare Highcharts.XrangePointOptionsObject
  884. * @type {Array<*>}
  885. * @extends series.line.data
  886. * @product highcharts highstock gantt
  887. * @apioption series.xrange.data
  888. */
  889. /**
  890. * The starting X value of the range point.
  891. *
  892. * @sample {highcharts} highcharts/demo/x-range
  893. * X-range
  894. *
  895. * @type {number}
  896. * @product highcharts highstock gantt
  897. * @apioption series.xrange.data.x
  898. */
  899. /**
  900. * The ending X value of the range point.
  901. *
  902. * @sample {highcharts} highcharts/demo/x-range
  903. * X-range
  904. *
  905. * @type {number}
  906. * @product highcharts highstock gantt
  907. * @apioption series.xrange.data.x2
  908. */
  909. /**
  910. * The Y value of the range point.
  911. *
  912. * @sample {highcharts} highcharts/demo/x-range
  913. * X-range
  914. *
  915. * @type {number}
  916. * @product highcharts highstock gantt
  917. * @apioption series.xrange.data.y
  918. */
  919. /**
  920. * A partial fill for each point, typically used to visualize how much of
  921. * a task is performed. The partial fill object can be set either on series
  922. * or point level.
  923. *
  924. * @sample {highcharts} highcharts/demo/x-range
  925. * X-range with partial fill
  926. *
  927. * @declare Highcharts.XrangePointPartialFillOptionsObject
  928. * @product highcharts highstock gantt
  929. * @apioption series.xrange.data.partialFill
  930. */
  931. /**
  932. * The amount of the X-range point to be filled. Values can be 0-1 and are
  933. * converted to percentages in the default data label formatter.
  934. *
  935. * @type {number}
  936. * @product highcharts highstock gantt
  937. * @apioption series.xrange.data.partialFill.amount
  938. */
  939. /**
  940. * The fill color to be used for partial fills. Defaults to a darker shade
  941. * of the point color.
  942. *
  943. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  944. * @product highcharts highstock gantt
  945. * @apioption series.xrange.data.partialFill.fill
  946. */
  947. ''; // adds doclets above to transpiled file
  948. return XRangeSeries;
  949. });
  950. _registerModule(_modules, 'Series/Gantt/GanttPoint.js', [_modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (SeriesRegistry, U) {
  951. /* *
  952. *
  953. * (c) 2016-2021 Highsoft AS
  954. *
  955. * Author: Lars A. V. Cabrera
  956. *
  957. * License: www.highcharts.com/license
  958. *
  959. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  960. *
  961. * */
  962. var __extends = (this && this.__extends) || (function () {
  963. var extendStatics = function (d,
  964. b) {
  965. extendStatics = Object.setPrototypeOf ||
  966. ({ __proto__: [] } instanceof Array && function (d,
  967. b) { d.__proto__ = b; }) ||
  968. function (d,
  969. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  970. return extendStatics(d, b);
  971. };
  972. return function (d, b) {
  973. extendStatics(d, b);
  974. function __() { this.constructor = d; }
  975. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  976. };
  977. })();
  978. var XRangePoint = SeriesRegistry.seriesTypes.xrange.prototype.pointClass;
  979. var pick = U.pick;
  980. /* *
  981. *
  982. * Class
  983. *
  984. * */
  985. var GanttPoint = /** @class */ (function (_super) {
  986. __extends(GanttPoint, _super);
  987. function GanttPoint() {
  988. /* *
  989. *
  990. * Static Functions
  991. *
  992. * */
  993. var _this = _super !== null && _super.apply(this,
  994. arguments) || this;
  995. _this.options = void 0;
  996. _this.series = void 0;
  997. return _this;
  998. /* eslint-enable valid-jsdoc */
  999. }
  1000. /* eslint-disable valid-jsdoc */
  1001. /**
  1002. * @private
  1003. */
  1004. GanttPoint.setGanttPointAliases = function (options) {
  1005. /**
  1006. * Add a value to options if the value exists.
  1007. * @private
  1008. */
  1009. function addIfExists(prop, val) {
  1010. if (typeof val !== 'undefined') {
  1011. options[prop] = val;
  1012. }
  1013. }
  1014. addIfExists('x', pick(options.start, options.x));
  1015. addIfExists('x2', pick(options.end, options.x2));
  1016. addIfExists('partialFill', pick(options.completed, options.partialFill));
  1017. };
  1018. /* *
  1019. *
  1020. * Functions
  1021. *
  1022. * */
  1023. /* eslint-disable valid-jsdoc */
  1024. /**
  1025. * Applies the options containing the x and y data and possible some
  1026. * extra properties. This is called on point init or from point.update.
  1027. *
  1028. * @private
  1029. * @function Highcharts.Point#applyOptions
  1030. *
  1031. * @param {object} options
  1032. * The point options
  1033. *
  1034. * @param {number} x
  1035. * The x value
  1036. *
  1037. * @return {Highcharts.Point}
  1038. * The Point instance
  1039. */
  1040. GanttPoint.prototype.applyOptions = function (options, x) {
  1041. var point = this,
  1042. ganttPoint;
  1043. ganttPoint = _super.prototype.applyOptions.call(point, options, x);
  1044. GanttPoint.setGanttPointAliases(ganttPoint);
  1045. return ganttPoint;
  1046. };
  1047. GanttPoint.prototype.isValid = function () {
  1048. return ((typeof this.start === 'number' ||
  1049. typeof this.x === 'number') &&
  1050. (typeof this.end === 'number' ||
  1051. typeof this.x2 === 'number' ||
  1052. this.milestone));
  1053. };
  1054. return GanttPoint;
  1055. }(XRangePoint));
  1056. /* *
  1057. *
  1058. * Default Export
  1059. *
  1060. * */
  1061. return GanttPoint;
  1062. });
  1063. _registerModule(_modules, 'Core/Axis/BrokenAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Series/Series.js'], _modules['Extensions/Stacking.js'], _modules['Core/Utilities.js']], function (Axis, Series, StackItem, U) {
  1064. /* *
  1065. *
  1066. * (c) 2009-2021 Torstein Honsi
  1067. *
  1068. * License: www.highcharts.com/license
  1069. *
  1070. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1071. *
  1072. * */
  1073. var addEvent = U.addEvent,
  1074. find = U.find,
  1075. fireEvent = U.fireEvent,
  1076. isArray = U.isArray,
  1077. isNumber = U.isNumber,
  1078. pick = U.pick;
  1079. /**
  1080. * Axis with support of broken data rows.
  1081. * @private
  1082. * @class
  1083. */
  1084. var BrokenAxis;
  1085. (function (BrokenAxis) {
  1086. /* *
  1087. *
  1088. * Functions
  1089. *
  1090. * */
  1091. /* eslint-disable valid-jsdoc */
  1092. /**
  1093. * Adds support for broken axes.
  1094. * @private
  1095. */
  1096. function compose(AxisClass, SeriesClass) {
  1097. if (AxisClass.keepProps.indexOf('brokenAxis') === -1) {
  1098. AxisClass.keepProps.push('brokenAxis');
  1099. var seriesProto = Series.prototype;
  1100. seriesProto.drawBreaks = seriesDrawBreaks;
  1101. seriesProto.gappedPath = seriesGappedPath;
  1102. addEvent(AxisClass, 'init', onInit);
  1103. addEvent(AxisClass, 'afterInit', onAfterInit);
  1104. addEvent(AxisClass, 'afterSetTickPositions', onAfterSetTickPositions);
  1105. addEvent(AxisClass, 'afterSetOptions', onAfterSetOptions);
  1106. addEvent(SeriesClass, 'afterGeneratePoints', onSeriesAfterGeneratePoints);
  1107. addEvent(SeriesClass, 'afterRender', onSeriesAfterRender);
  1108. }
  1109. return AxisClass;
  1110. }
  1111. BrokenAxis.compose = compose;
  1112. /**
  1113. * @private
  1114. */
  1115. function onAfterInit() {
  1116. if (typeof this.brokenAxis !== 'undefined') {
  1117. this.brokenAxis.setBreaks(this.options.breaks, false);
  1118. }
  1119. }
  1120. /**
  1121. * Force Axis to be not-ordinal when breaks are defined.
  1122. * @private
  1123. */
  1124. function onAfterSetOptions() {
  1125. var axis = this;
  1126. if (axis.brokenAxis && axis.brokenAxis.hasBreaks) {
  1127. axis.options.ordinal = false;
  1128. }
  1129. }
  1130. /**
  1131. * @private
  1132. */
  1133. function onAfterSetTickPositions() {
  1134. var axis = this,
  1135. brokenAxis = axis.brokenAxis;
  1136. if (brokenAxis &&
  1137. brokenAxis.hasBreaks) {
  1138. var tickPositions = axis.tickPositions,
  1139. info = axis.tickPositions.info,
  1140. newPositions = [];
  1141. for (var i = 0; i < tickPositions.length; i++) {
  1142. if (!brokenAxis.isInAnyBreak(tickPositions[i])) {
  1143. newPositions.push(tickPositions[i]);
  1144. }
  1145. }
  1146. axis.tickPositions = newPositions;
  1147. axis.tickPositions.info = info;
  1148. }
  1149. }
  1150. /**
  1151. * @private
  1152. */
  1153. function onInit() {
  1154. var axis = this;
  1155. if (!axis.brokenAxis) {
  1156. axis.brokenAxis = new Additions(axis);
  1157. }
  1158. }
  1159. /**
  1160. * @private
  1161. */
  1162. function onSeriesAfterGeneratePoints() {
  1163. var _a = this,
  1164. isDirty = _a.isDirty,
  1165. connectNulls = _a.options.connectNulls,
  1166. points = _a.points,
  1167. xAxis = _a.xAxis,
  1168. yAxis = _a.yAxis;
  1169. // Set, or reset visibility of the points. Axis.setBreaks marks
  1170. // the series as isDirty
  1171. if (isDirty) {
  1172. var i = points.length;
  1173. while (i--) {
  1174. var point = points[i];
  1175. // Respect nulls inside the break (#4275)
  1176. var nullGap = point.y === null && connectNulls === false;
  1177. var isPointInBreak = (!nullGap && ((xAxis &&
  1178. xAxis.brokenAxis &&
  1179. xAxis.brokenAxis.isInAnyBreak(point.x,
  1180. true)) || (yAxis &&
  1181. yAxis.brokenAxis &&
  1182. yAxis.brokenAxis.isInAnyBreak(point.y,
  1183. true))));
  1184. // Set point.visible if in any break.
  1185. // If not in break, reset visible to original value.
  1186. point.visible = isPointInBreak ?
  1187. false :
  1188. point.options.visible !== false;
  1189. }
  1190. }
  1191. }
  1192. /**
  1193. * @private
  1194. */
  1195. function onSeriesAfterRender() {
  1196. this.drawBreaks(this.xAxis, ['x']);
  1197. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  1198. }
  1199. /**
  1200. * @private
  1201. */
  1202. function seriesDrawBreaks(axis, keys) {
  1203. var series = this,
  1204. points = series.points;
  1205. var breaks,
  1206. threshold,
  1207. eventName,
  1208. y;
  1209. if (axis && // #5950
  1210. axis.brokenAxis &&
  1211. axis.brokenAxis.hasBreaks) {
  1212. var brokenAxis_1 = axis.brokenAxis;
  1213. keys.forEach(function (key) {
  1214. breaks = brokenAxis_1 && brokenAxis_1.breakArray || [];
  1215. threshold = axis.isXAxis ?
  1216. axis.min :
  1217. pick(series.options.threshold, axis.min);
  1218. points.forEach(function (point) {
  1219. y = pick(point['stack' + key.toUpperCase()], point[key]);
  1220. breaks.forEach(function (brk) {
  1221. if (isNumber(threshold) && isNumber(y)) {
  1222. eventName = false;
  1223. if ((threshold < brk.from && y > brk.to) ||
  1224. (threshold > brk.from && y < brk.from)) {
  1225. eventName = 'pointBreak';
  1226. }
  1227. else if ((threshold < brk.from && y > brk.from && y < brk.to) ||
  1228. (threshold > brk.from && y > brk.to && y < brk.from)) {
  1229. eventName = 'pointInBreak';
  1230. }
  1231. if (eventName) {
  1232. fireEvent(axis, eventName, { point: point, brk: brk });
  1233. }
  1234. }
  1235. });
  1236. });
  1237. });
  1238. }
  1239. }
  1240. /**
  1241. * Extend getGraphPath by identifying gaps in the data so that we
  1242. * can draw a gap in the line or area. This was moved from ordinal
  1243. * axis module to broken axis module as of #5045.
  1244. *
  1245. * @private
  1246. * @function Highcharts.Series#gappedPath
  1247. *
  1248. * @return {Highcharts.SVGPathArray}
  1249. * Gapped path
  1250. */
  1251. function seriesGappedPath() {
  1252. var currentDataGrouping = this.currentDataGrouping,
  1253. groupingSize = currentDataGrouping && currentDataGrouping.gapSize,
  1254. points = this.points.slice(),
  1255. yAxis = this.yAxis;
  1256. var gapSize = this.options.gapSize,
  1257. i = points.length - 1,
  1258. stack;
  1259. /**
  1260. * Defines when to display a gap in the graph, together with the
  1261. * [gapUnit](plotOptions.series.gapUnit) option.
  1262. *
  1263. * In case when `dataGrouping` is enabled, points can be grouped
  1264. * into a larger time span. This can make the grouped points to
  1265. * have a greater distance than the absolute value of `gapSize`
  1266. * property, which will result in disappearing graph completely.
  1267. * To prevent this situation the mentioned distance between
  1268. * grouped points is used instead of previously defined
  1269. * `gapSize`.
  1270. *
  1271. * In practice, this option is most often used to visualize gaps
  1272. * in time series. In a stock chart, intraday data is available
  1273. * for daytime hours, while gaps will appear in nights and
  1274. * weekends.
  1275. *
  1276. * @see [gapUnit](plotOptions.series.gapUnit)
  1277. * @see [xAxis.breaks](#xAxis.breaks)
  1278. *
  1279. * @sample {highstock} stock/plotoptions/series-gapsize/
  1280. * Setting the gap size to 2 introduces gaps for weekends in
  1281. * daily datasets.
  1282. *
  1283. * @type {number}
  1284. * @default 0
  1285. * @product highstock
  1286. * @requires modules/broken-axis
  1287. * @apioption plotOptions.series.gapSize
  1288. */
  1289. /**
  1290. * Together with [gapSize](plotOptions.series.gapSize), this
  1291. * option defines where to draw gaps in the graph.
  1292. *
  1293. * When the `gapUnit` is `"relative"` (default), a gap size of 5
  1294. * means that if the distance between two points is greater than
  1295. * 5 times that of the two closest points, the graph will be
  1296. * broken.
  1297. *
  1298. * When the `gapUnit` is `"value"`, the gap is based on absolute
  1299. * axis values, which on a datetime axis is milliseconds. This
  1300. * also applies to the navigator series that inherits gap
  1301. * options from the base series.
  1302. *
  1303. * @see [gapSize](plotOptions.series.gapSize)
  1304. *
  1305. * @type {string}
  1306. * @default relative
  1307. * @since 5.0.13
  1308. * @product highstock
  1309. * @validvalue ["relative", "value"]
  1310. * @requires modules/broken-axis
  1311. * @apioption plotOptions.series.gapUnit
  1312. */
  1313. if (gapSize && i > 0) { // #5008
  1314. // Gap unit is relative
  1315. if (this.options.gapUnit !== 'value') {
  1316. gapSize *= this.basePointRange;
  1317. }
  1318. // Setting a new gapSize in case dataGrouping is enabled
  1319. // (#7686)
  1320. if (groupingSize &&
  1321. groupingSize > gapSize &&
  1322. // Except when DG is forced (e.g. from other series)
  1323. // and has lower granularity than actual points (#11351)
  1324. groupingSize >= this.basePointRange) {
  1325. gapSize = groupingSize;
  1326. }
  1327. // extension for ordinal breaks
  1328. var current = void 0,
  1329. next = void 0;
  1330. while (i--) {
  1331. // Reassign next if it is not visible
  1332. if (!(next && next.visible !== false)) {
  1333. next = points[i + 1];
  1334. }
  1335. current = points[i];
  1336. // Skip iteration if one of the points is not visible
  1337. if (next.visible === false || current.visible === false) {
  1338. continue;
  1339. }
  1340. if (next.x - current.x > gapSize) {
  1341. var xRange = (current.x + next.x) / 2;
  1342. points.splice(// insert after this one
  1343. i + 1, 0, {
  1344. isNull: true,
  1345. x: xRange
  1346. });
  1347. // For stacked chart generate empty stack items,
  1348. // #6546
  1349. if (yAxis.stacking && this.options.stacking) {
  1350. stack = yAxis.stacking.stacks[this.stackKey][xRange] =
  1351. new StackItem(yAxis, yAxis.options
  1352. .stackLabels, false, xRange, this.stack);
  1353. stack.total = 0;
  1354. }
  1355. }
  1356. // Assign current to next for the upcoming iteration
  1357. next = current;
  1358. }
  1359. }
  1360. // Call base method
  1361. return this.getGraphPath(points);
  1362. }
  1363. /* *
  1364. *
  1365. * Class
  1366. *
  1367. * */
  1368. /**
  1369. * Provides support for broken axes.
  1370. * @private
  1371. * @class
  1372. */
  1373. var Additions = /** @class */ (function () {
  1374. /* *
  1375. *
  1376. * Constructors
  1377. *
  1378. * */
  1379. function Additions(axis) {
  1380. this.hasBreaks = false;
  1381. this.axis = axis;
  1382. }
  1383. /* *
  1384. *
  1385. * Static Functions
  1386. *
  1387. * */
  1388. /**
  1389. * @private
  1390. */
  1391. Additions.isInBreak = function (brk, val) {
  1392. var repeat = brk.repeat || Infinity,
  1393. from = brk.from,
  1394. length = brk.to - brk.from,
  1395. test = (val >= from ?
  1396. (val - from) % repeat :
  1397. repeat - ((from - val) % repeat));
  1398. var ret;
  1399. if (!brk.inclusive) {
  1400. ret = test < length && test !== 0;
  1401. }
  1402. else {
  1403. ret = test <= length;
  1404. }
  1405. return ret;
  1406. };
  1407. /**
  1408. * @private
  1409. */
  1410. Additions.lin2Val = function (val) {
  1411. var axis = this;
  1412. var brokenAxis = axis.brokenAxis;
  1413. var breakArray = brokenAxis && brokenAxis.breakArray;
  1414. if (!breakArray || !isNumber(val)) {
  1415. return val;
  1416. }
  1417. var nval = val,
  1418. brk,
  1419. i;
  1420. for (i = 0; i < breakArray.length; i++) {
  1421. brk = breakArray[i];
  1422. if (brk.from >= nval) {
  1423. break;
  1424. }
  1425. else if (brk.to < nval) {
  1426. nval += brk.len;
  1427. }
  1428. else if (Additions.isInBreak(brk, nval)) {
  1429. nval += brk.len;
  1430. }
  1431. }
  1432. return nval;
  1433. };
  1434. /**
  1435. * @private
  1436. */
  1437. Additions.val2Lin = function (val) {
  1438. var axis = this;
  1439. var brokenAxis = axis.brokenAxis;
  1440. var breakArray = brokenAxis && brokenAxis.breakArray;
  1441. if (!breakArray || !isNumber(val)) {
  1442. return val;
  1443. }
  1444. var nval = val,
  1445. brk,
  1446. i;
  1447. for (i = 0; i < breakArray.length; i++) {
  1448. brk = breakArray[i];
  1449. if (brk.to <= val) {
  1450. nval -= brk.len;
  1451. }
  1452. else if (brk.from >= val) {
  1453. break;
  1454. }
  1455. else if (Additions.isInBreak(brk, val)) {
  1456. nval -= (val - brk.from);
  1457. break;
  1458. }
  1459. }
  1460. return nval;
  1461. };
  1462. /* *
  1463. *
  1464. * Functions
  1465. *
  1466. * */
  1467. /**
  1468. * Returns the first break found where the x is larger then break.from
  1469. * and smaller then break.to.
  1470. *
  1471. * @param {number} x
  1472. * The number which should be within a break.
  1473. *
  1474. * @param {Array<Highcharts.XAxisBreaksOptions>} breaks
  1475. * The array of breaks to search within.
  1476. *
  1477. * @return {Highcharts.XAxisBreaksOptions|undefined}
  1478. * Returns the first break found that matches, returns false if no break
  1479. * is found.
  1480. */
  1481. Additions.prototype.findBreakAt = function (x, breaks) {
  1482. return find(breaks, function (b) {
  1483. return b.from < x && x < b.to;
  1484. });
  1485. };
  1486. /**
  1487. * @private
  1488. */
  1489. Additions.prototype.isInAnyBreak = function (val, testKeep) {
  1490. var brokenAxis = this,
  1491. axis = brokenAxis.axis,
  1492. breaks = axis.options.breaks || [];
  1493. var i = breaks.length,
  1494. inbrk,
  1495. keep,
  1496. ret;
  1497. if (i && isNumber(val)) {
  1498. while (i--) {
  1499. if (Additions.isInBreak(breaks[i], val)) {
  1500. inbrk = true;
  1501. if (!keep) {
  1502. keep = pick(breaks[i].showPoints, !axis.isXAxis);
  1503. }
  1504. }
  1505. }
  1506. if (inbrk && testKeep) {
  1507. ret = inbrk && !keep;
  1508. }
  1509. else {
  1510. ret = inbrk;
  1511. }
  1512. }
  1513. return ret;
  1514. };
  1515. /**
  1516. * Dynamically set or unset breaks in an axis. This function in lighter
  1517. * than usin Axis.update, and it also preserves animation.
  1518. *
  1519. * @private
  1520. * @function Highcharts.Axis#setBreaks
  1521. *
  1522. * @param {Array<Highcharts.XAxisBreaksOptions>} [breaks]
  1523. * The breaks to add. When `undefined` it removes existing breaks.
  1524. *
  1525. * @param {boolean} [redraw=true]
  1526. * Whether to redraw the chart immediately.
  1527. */
  1528. Additions.prototype.setBreaks = function (breaks, redraw) {
  1529. var brokenAxis = this;
  1530. var axis = brokenAxis.axis;
  1531. var hasBreaks = (isArray(breaks) && !!breaks.length);
  1532. axis.isDirty = brokenAxis.hasBreaks !== hasBreaks;
  1533. brokenAxis.hasBreaks = hasBreaks;
  1534. axis.options.breaks = axis.userOptions.breaks = breaks;
  1535. axis.forceRedraw = true; // Force recalculation in setScale
  1536. // Recalculate series related to the axis.
  1537. axis.series.forEach(function (series) {
  1538. series.isDirty = true;
  1539. });
  1540. if (!hasBreaks && axis.val2lin === Additions.val2Lin) {
  1541. // Revert to prototype functions
  1542. delete axis.val2lin;
  1543. delete axis.lin2val;
  1544. }
  1545. if (hasBreaks) {
  1546. axis.userOptions.ordinal = false;
  1547. axis.lin2val = Additions.lin2Val;
  1548. axis.val2lin = Additions.val2Lin;
  1549. axis.setExtremes = function (newMin, newMax, redraw, animation, eventArguments) {
  1550. // If trying to set extremes inside a break, extend min to
  1551. // after, and max to before the break ( #3857 )
  1552. if (brokenAxis.hasBreaks) {
  1553. var breaks_1 = (this.options.breaks || []);
  1554. var axisBreak = void 0;
  1555. while ((axisBreak = brokenAxis.findBreakAt(newMin, breaks_1))) {
  1556. newMin = axisBreak.to;
  1557. }
  1558. while ((axisBreak = brokenAxis.findBreakAt(newMax, breaks_1))) {
  1559. newMax = axisBreak.from;
  1560. }
  1561. // If both min and max is within the same break.
  1562. if (newMax < newMin) {
  1563. newMax = newMin;
  1564. }
  1565. }
  1566. Axis.prototype.setExtremes.call(this, newMin, newMax, redraw, animation, eventArguments);
  1567. };
  1568. axis.setAxisTranslation = function () {
  1569. Axis.prototype.setAxisTranslation.call(this);
  1570. brokenAxis.unitLength = void 0;
  1571. if (brokenAxis.hasBreaks) {
  1572. var breaks_2 = axis.options.breaks || [],
  1573. // Temporary one:
  1574. breakArrayT_1 = [],
  1575. breakArray_1 = [],
  1576. pointRangePadding = pick(axis.pointRangePadding, 0);
  1577. var length_1 = 0,
  1578. inBrk_1,
  1579. repeat_1,
  1580. min_1 = axis.userMin || axis.min,
  1581. max_1 = axis.userMax || axis.max,
  1582. start_1,
  1583. i_1;
  1584. // Min & max check (#4247)
  1585. breaks_2.forEach(function (brk) {
  1586. repeat_1 = brk.repeat || Infinity;
  1587. if (isNumber(min_1) && isNumber(max_1)) {
  1588. if (Additions.isInBreak(brk, min_1)) {
  1589. min_1 += (brk.to % repeat_1) - (min_1 % repeat_1);
  1590. }
  1591. if (Additions.isInBreak(brk, max_1)) {
  1592. max_1 -= (max_1 % repeat_1) - (brk.from % repeat_1);
  1593. }
  1594. }
  1595. });
  1596. // Construct an array holding all breaks in the axis
  1597. breaks_2.forEach(function (brk) {
  1598. start_1 = brk.from;
  1599. repeat_1 = brk.repeat || Infinity;
  1600. if (isNumber(min_1) && isNumber(max_1)) {
  1601. while (start_1 - repeat_1 > min_1) {
  1602. start_1 -= repeat_1;
  1603. }
  1604. while (start_1 < min_1) {
  1605. start_1 += repeat_1;
  1606. }
  1607. for (i_1 = start_1; i_1 < max_1; i_1 += repeat_1) {
  1608. breakArrayT_1.push({
  1609. value: i_1,
  1610. move: 'in'
  1611. });
  1612. breakArrayT_1.push({
  1613. value: i_1 + brk.to - brk.from,
  1614. move: 'out',
  1615. size: brk.breakSize
  1616. });
  1617. }
  1618. }
  1619. });
  1620. breakArrayT_1.sort(function (a, b) {
  1621. return ((a.value === b.value) ?
  1622. ((a.move === 'in' ? 0 : 1) -
  1623. (b.move === 'in' ? 0 : 1)) :
  1624. a.value - b.value);
  1625. });
  1626. // Simplify the breaks
  1627. inBrk_1 = 0;
  1628. start_1 = min_1;
  1629. breakArrayT_1.forEach(function (brk) {
  1630. inBrk_1 += (brk.move === 'in' ? 1 : -1);
  1631. if (inBrk_1 === 1 && brk.move === 'in') {
  1632. start_1 = brk.value;
  1633. }
  1634. if (inBrk_1 === 0 && isNumber(start_1)) {
  1635. breakArray_1.push({
  1636. from: start_1,
  1637. to: brk.value,
  1638. len: brk.value - start_1 - (brk.size || 0)
  1639. });
  1640. length_1 += brk.value - start_1 - (brk.size || 0);
  1641. }
  1642. });
  1643. brokenAxis.breakArray = breakArray_1;
  1644. // Used with staticScale, and below the actual axis
  1645. // length, when breaks are substracted.
  1646. if (isNumber(min_1) && isNumber(max_1) && isNumber(axis.min)) {
  1647. brokenAxis.unitLength = max_1 - min_1 - length_1 +
  1648. pointRangePadding;
  1649. fireEvent(axis, 'afterBreaks');
  1650. if (axis.staticScale) {
  1651. axis.transA = axis.staticScale;
  1652. }
  1653. else if (brokenAxis.unitLength) {
  1654. axis.transA *=
  1655. (max_1 - axis.min + pointRangePadding) /
  1656. brokenAxis.unitLength;
  1657. }
  1658. if (pointRangePadding) {
  1659. axis.minPixelPadding =
  1660. axis.transA * (axis.minPointOffset || 0);
  1661. }
  1662. axis.min = min_1;
  1663. axis.max = max_1;
  1664. }
  1665. }
  1666. };
  1667. }
  1668. if (pick(redraw, true)) {
  1669. axis.chart.redraw();
  1670. }
  1671. };
  1672. return Additions;
  1673. }());
  1674. BrokenAxis.Additions = Additions;
  1675. })(BrokenAxis || (BrokenAxis = {}));
  1676. /* *
  1677. *
  1678. * Default Export
  1679. *
  1680. * */
  1681. return BrokenAxis;
  1682. });
  1683. _registerModule(_modules, 'Core/Axis/GridAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Axis/AxisDefaults.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Axis, AxisDefaults, H, U) {
  1684. /* *
  1685. *
  1686. * (c) 2016 Highsoft AS
  1687. * Authors: Lars A. V. Cabrera
  1688. *
  1689. * License: www.highcharts.com/license
  1690. *
  1691. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1692. *
  1693. * */
  1694. var dateFormats = H.dateFormats;
  1695. var addEvent = U.addEvent,
  1696. defined = U.defined,
  1697. erase = U.erase,
  1698. find = U.find,
  1699. isArray = U.isArray,
  1700. isNumber = U.isNumber,
  1701. merge = U.merge,
  1702. pick = U.pick,
  1703. timeUnits = U.timeUnits,
  1704. wrap = U.wrap;
  1705. /* *
  1706. *
  1707. * Functions
  1708. *
  1709. * */
  1710. /* eslint-disable require-jsdoc */
  1711. function argsToArray(args) {
  1712. return Array.prototype.slice.call(args, 1);
  1713. }
  1714. function isObject(x) {
  1715. // Always use strict mode
  1716. return U.isObject(x, true);
  1717. }
  1718. function applyGridOptions(axis) {
  1719. var options = axis.options;
  1720. // Center-align by default
  1721. /*
  1722. if (!options.labels) {
  1723. options.labels = {};
  1724. }
  1725. */
  1726. options.labels.align = pick(options.labels.align, 'center');
  1727. // @todo: Check against tickLabelPlacement between/on etc
  1728. /* Prevents adding the last tick label if the axis is not a category
  1729. axis.
  1730. Since numeric labels are normally placed at starts and ends of a
  1731. range of value, and this module makes the label point at the value,
  1732. an "extra" label would appear. */
  1733. if (!axis.categories) {
  1734. options.showLastLabel = false;
  1735. }
  1736. // Prevents rotation of labels when squished, as rotating them would not
  1737. // help.
  1738. axis.labelRotation = 0;
  1739. options.labels.rotation = 0;
  1740. }
  1741. /**
  1742. * Axis with grid support.
  1743. * @private
  1744. */
  1745. var GridAxis;
  1746. (function (GridAxis) {
  1747. /* *
  1748. *
  1749. * Declarations
  1750. *
  1751. * */
  1752. /**
  1753. * Enum for which side the axis is on. Maps to axis.side.
  1754. * @private
  1755. */
  1756. var Side;
  1757. (function (Side) {
  1758. Side[Side["top"] = 0] = "top";
  1759. Side[Side["right"] = 1] = "right";
  1760. Side[Side["bottom"] = 2] = "bottom";
  1761. Side[Side["left"] = 3] = "left";
  1762. })(Side = GridAxis.Side || (GridAxis.Side = {}));
  1763. /* *
  1764. *
  1765. * Functions
  1766. *
  1767. * */
  1768. /* eslint-disable valid-jsdoc */
  1769. /**
  1770. * Extends axis class with grid support.
  1771. * @private
  1772. */
  1773. function compose(AxisClass, ChartClass, TickClass) {
  1774. if (AxisClass.keepProps.indexOf('grid') === -1) {
  1775. AxisClass.keepProps.push('grid');
  1776. AxisClass.prototype.getMaxLabelDimensions = getMaxLabelDimensions;
  1777. wrap(AxisClass.prototype, 'unsquish', wrapUnsquish);
  1778. // Add event handlers
  1779. addEvent(AxisClass, 'init', onInit);
  1780. addEvent(AxisClass, 'afterGetOffset', onAfterGetOffset);
  1781. addEvent(AxisClass, 'afterGetTitlePosition', onAfterGetTitlePosition);
  1782. addEvent(AxisClass, 'afterInit', onAfterInit);
  1783. addEvent(AxisClass, 'afterRender', onAfterRender);
  1784. addEvent(AxisClass, 'afterSetAxisTranslation', onAfterSetAxisTranslation);
  1785. addEvent(AxisClass, 'afterSetOptions', onAfterSetOptions);
  1786. addEvent(AxisClass, 'afterSetOptions', onAfterSetOptions2);
  1787. addEvent(AxisClass, 'afterSetScale', onAfterSetScale);
  1788. addEvent(AxisClass, 'afterTickSize', onAfterTickSize);
  1789. addEvent(AxisClass, 'trimTicks', onTrimTicks);
  1790. addEvent(AxisClass, 'destroy', onDestroy);
  1791. }
  1792. addEvent(ChartClass, 'afterSetChartSize', onChartAfterSetChartSize);
  1793. addEvent(TickClass, 'afterGetLabelPosition', onTickAfterGetLabelPosition);
  1794. addEvent(TickClass, 'labelFormat', onTickLabelFormat);
  1795. return AxisClass;
  1796. }
  1797. GridAxis.compose = compose;
  1798. /**
  1799. * Get the largest label width and height.
  1800. *
  1801. * @private
  1802. * @function Highcharts.Axis#getMaxLabelDimensions
  1803. *
  1804. * @param {Highcharts.Dictionary<Highcharts.Tick>} ticks
  1805. * All the ticks on one axis.
  1806. *
  1807. * @param {Array<number|string>} tickPositions
  1808. * All the tick positions on one axis.
  1809. *
  1810. * @return {Highcharts.SizeObject}
  1811. * Object containing the properties height and width.
  1812. *
  1813. * @todo Move this to the generic axis implementation, as it is used there.
  1814. */
  1815. function getMaxLabelDimensions(ticks, tickPositions) {
  1816. var dimensions = {
  1817. width: 0,
  1818. height: 0
  1819. };
  1820. tickPositions.forEach(function (pos) {
  1821. var tick = ticks[pos];
  1822. var labelHeight = 0,
  1823. labelWidth = 0,
  1824. label;
  1825. if (isObject(tick)) {
  1826. label = isObject(tick.label) ? tick.label : {};
  1827. // Find width and height of label
  1828. labelHeight = label.getBBox ? label.getBBox().height : 0;
  1829. if (label.textStr && !isNumber(label.textPxLength)) {
  1830. label.textPxLength = label.getBBox().width;
  1831. }
  1832. labelWidth = isNumber(label.textPxLength) ?
  1833. // Math.round ensures crisp lines
  1834. Math.round(label.textPxLength) :
  1835. 0;
  1836. if (label.textStr) {
  1837. // Set the tickWidth same as the label width after ellipsis
  1838. // applied #10281
  1839. labelWidth = Math.round(label.getBBox().width);
  1840. }
  1841. // Update the result if width and/or height are larger
  1842. dimensions.height = Math.max(labelHeight, dimensions.height);
  1843. dimensions.width = Math.max(labelWidth, dimensions.width);
  1844. }
  1845. });
  1846. // For tree grid, add indentation
  1847. if (this.options.type === 'treegrid' &&
  1848. this.treeGrid &&
  1849. this.treeGrid.mapOfPosToGridNode) {
  1850. var treeDepth = this.treeGrid.mapOfPosToGridNode[-1].height || 0;
  1851. dimensions.width += this.options.labels.indentation * (treeDepth - 1);
  1852. }
  1853. return dimensions;
  1854. }
  1855. /**
  1856. * Handle columns and getOffset.
  1857. * @private
  1858. */
  1859. function onAfterGetOffset() {
  1860. var grid = this.grid;
  1861. (grid && grid.columns || []).forEach(function (column) {
  1862. column.getOffset();
  1863. });
  1864. }
  1865. /**
  1866. * @private
  1867. */
  1868. function onAfterGetTitlePosition(e) {
  1869. var axis = this;
  1870. var options = axis.options;
  1871. var gridOptions = options.grid || {};
  1872. if (gridOptions.enabled === true) {
  1873. // compute anchor points for each of the title align options
  1874. var axisTitle = axis.axisTitle,
  1875. axisHeight = axis.height,
  1876. horiz = axis.horiz,
  1877. axisLeft = axis.left,
  1878. offset = axis.offset,
  1879. opposite = axis.opposite,
  1880. options_1 = axis.options,
  1881. axisTop = axis.top,
  1882. axisWidth = axis.width;
  1883. var tickSize = axis.tickSize();
  1884. var titleWidth = axisTitle && axisTitle.getBBox().width;
  1885. var xOption = options_1.title.x;
  1886. var yOption = options_1.title.y;
  1887. var titleMargin = pick(options_1.title.margin,
  1888. horiz ? 5 : 10);
  1889. var titleFontSize = axis.chart.renderer.fontMetrics(options_1.title.style.fontSize,
  1890. axisTitle).f;
  1891. var crispCorr = tickSize ? tickSize[0] / 2 : 0;
  1892. // TODO account for alignment
  1893. // the position in the perpendicular direction of the axis
  1894. var offAxis = ((horiz ? axisTop + axisHeight : axisLeft) +
  1895. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  1896. (opposite ? -1 : 1) * // so does opposite axes
  1897. crispCorr +
  1898. (axis.side === GridAxis.Side.bottom ? titleFontSize : 0));
  1899. e.titlePosition.x = horiz ?
  1900. axisLeft - (titleWidth || 0) / 2 - titleMargin + xOption :
  1901. offAxis + (opposite ? axisWidth : 0) + offset + xOption;
  1902. e.titlePosition.y = horiz ?
  1903. (offAxis -
  1904. (opposite ? axisHeight : 0) +
  1905. (opposite ? titleFontSize : -titleFontSize) / 2 +
  1906. offset +
  1907. yOption) :
  1908. axisTop - titleMargin + yOption;
  1909. }
  1910. }
  1911. /**
  1912. * @private
  1913. */
  1914. function onAfterInit() {
  1915. var axis = this;
  1916. var chart = axis.chart,
  1917. _a = axis.options.grid,
  1918. gridOptions = _a === void 0 ? {} : _a,
  1919. userOptions = axis.userOptions;
  1920. if (gridOptions.enabled) {
  1921. applyGridOptions(axis);
  1922. }
  1923. if (gridOptions.columns) {
  1924. var columns = axis.grid.columns = [];
  1925. var columnIndex = axis.grid.columnIndex = 0;
  1926. // Handle columns, each column is a grid axis
  1927. while (++columnIndex < gridOptions.columns.length) {
  1928. var columnOptions = merge(userOptions,
  1929. gridOptions.columns[gridOptions.columns.length - columnIndex - 1], {
  1930. linkedTo: 0,
  1931. // Force to behave like category axis
  1932. type: 'category',
  1933. // Disable by default the scrollbar on the grid axis
  1934. scrollbar: {
  1935. enabled: false
  1936. }
  1937. });
  1938. delete columnOptions.grid.columns; // Prevent recursion
  1939. var column = new Axis(axis.chart,
  1940. columnOptions);
  1941. column.grid.isColumn = true;
  1942. column.grid.columnIndex = columnIndex;
  1943. // Remove column axis from chart axes array, and place it
  1944. // in the columns array.
  1945. erase(chart.axes, column);
  1946. erase(chart[axis.coll], column);
  1947. columns.push(column);
  1948. }
  1949. }
  1950. }
  1951. /**
  1952. * Draw an extra line on the far side of the outermost axis,
  1953. * creating floor/roof/wall of a grid. And some padding.
  1954. * ```
  1955. * Make this:
  1956. * (axis.min) __________________________ (axis.max)
  1957. * | | | | |
  1958. * Into this:
  1959. * (axis.min) __________________________ (axis.max)
  1960. * ___|____|____|____|____|__
  1961. * ```
  1962. * @private
  1963. */
  1964. function onAfterRender() {
  1965. var axis = this,
  1966. grid = axis.grid,
  1967. options = axis.options,
  1968. gridOptions = options.grid || {};
  1969. if (gridOptions.enabled === true) {
  1970. var min = axis.min || 0,
  1971. max = axis.max || 0;
  1972. // @todo acutual label padding (top, bottom, left, right)
  1973. axis.maxLabelDimensions = axis.getMaxLabelDimensions(axis.ticks, axis.tickPositions);
  1974. // Remove right wall before rendering if updating
  1975. if (axis.rightWall) {
  1976. axis.rightWall.destroy();
  1977. }
  1978. /*
  1979. Draw an extra axis line on outer axes
  1980. >
  1981. Make this: |______|______|______|___
  1982. > _________________________
  1983. Into this: |______|______|______|__|
  1984. */
  1985. if (axis.grid && axis.grid.isOuterAxis() && axis.axisLine) {
  1986. var lineWidth = options.lineWidth;
  1987. if (lineWidth) {
  1988. var linePath = axis.getLinePath(lineWidth),
  1989. startPoint = linePath[0],
  1990. endPoint = linePath[1],
  1991. // Negate distance if top or left axis
  1992. // Subtract 1px to draw the line at the end of the tick
  1993. tickLength = (axis.tickSize('tick') || [1])[0],
  1994. distance = (tickLength - 1) * ((axis.side === GridAxis.Side.top ||
  1995. axis.side === GridAxis.Side.left) ? -1 : 1);
  1996. // If axis is horizontal, reposition line path vertically
  1997. if (startPoint[0] === 'M' && endPoint[0] === 'L') {
  1998. if (axis.horiz) {
  1999. startPoint[2] += distance;
  2000. endPoint[2] += distance;
  2001. }
  2002. else {
  2003. startPoint[1] += distance;
  2004. endPoint[1] += distance;
  2005. }
  2006. }
  2007. // If it doesn't exist, add an upper and lower border
  2008. // for the vertical grid axis.
  2009. if (!axis.horiz && axis.chart.marginRight) {
  2010. var upperBorderStartPoint = startPoint,
  2011. upperBorderEndPoint = [
  2012. 'L',
  2013. axis.left,
  2014. startPoint[2] || 0
  2015. ],
  2016. upperBorderPath = [upperBorderStartPoint,
  2017. upperBorderEndPoint],
  2018. lowerBorderEndPoint = [
  2019. 'L',
  2020. axis.chart.chartWidth - axis.chart.marginRight,
  2021. axis.toPixels(max + axis.tickmarkOffset)
  2022. ],
  2023. lowerBorderStartPoint = [
  2024. 'M',
  2025. endPoint[1] || 0,
  2026. axis.toPixels(max + axis.tickmarkOffset)
  2027. ],
  2028. lowerBorderPath = [lowerBorderStartPoint,
  2029. lowerBorderEndPoint];
  2030. if (!axis.grid.upperBorder && min % 1 !== 0) {
  2031. axis.grid.upperBorder = axis.grid.renderBorder(upperBorderPath);
  2032. }
  2033. if (axis.grid.upperBorder) {
  2034. axis.grid.upperBorder.attr({
  2035. stroke: options.lineColor,
  2036. 'stroke-width': options.lineWidth
  2037. });
  2038. axis.grid.upperBorder.animate({
  2039. d: upperBorderPath
  2040. });
  2041. }
  2042. if (!axis.grid.lowerBorder && max % 1 !== 0) {
  2043. axis.grid.lowerBorder = axis.grid.renderBorder(lowerBorderPath);
  2044. }
  2045. if (axis.grid.lowerBorder) {
  2046. axis.grid.lowerBorder.attr({
  2047. stroke: options.lineColor,
  2048. 'stroke-width': options.lineWidth
  2049. });
  2050. axis.grid.lowerBorder.animate({
  2051. d: lowerBorderPath
  2052. });
  2053. }
  2054. }
  2055. // Render an extra line parallel to the existing axes,
  2056. // to close the grid.
  2057. if (!axis.grid.axisLineExtra) {
  2058. axis.grid.axisLineExtra = axis.grid.renderBorder(linePath);
  2059. }
  2060. else {
  2061. axis.grid.axisLineExtra.attr({
  2062. stroke: options.lineColor,
  2063. 'stroke-width': options.lineWidth
  2064. });
  2065. axis.grid.axisLineExtra.animate({
  2066. d: linePath
  2067. });
  2068. }
  2069. // show or hide the line depending on
  2070. // options.showEmpty
  2071. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  2072. }
  2073. }
  2074. (grid && grid.columns || []).forEach(function (column) {
  2075. column.render();
  2076. });
  2077. // Manipulate the tick mark visibility
  2078. // based on the axis.max- allows smooth scrolling.
  2079. if (!axis.horiz &&
  2080. axis.chart.hasRendered &&
  2081. (axis.scrollbar ||
  2082. (axis.linkedParent && axis.linkedParent.scrollbar))) {
  2083. var tickmarkOffset = axis.tickmarkOffset,
  2084. lastTick = axis.tickPositions[axis.tickPositions.length - 1],
  2085. firstTick = axis.tickPositions[0];
  2086. // Hide/show firts tick label.
  2087. var label = axis.ticks[firstTick].label;
  2088. if (label) {
  2089. if (min - firstTick > tickmarkOffset) {
  2090. label.hide();
  2091. }
  2092. else {
  2093. label.show();
  2094. }
  2095. }
  2096. // Hide/show last tick mark/label.
  2097. label = axis.ticks[lastTick].label;
  2098. if (label) {
  2099. if (lastTick - max > tickmarkOffset) {
  2100. label.hide();
  2101. }
  2102. else {
  2103. label.show();
  2104. }
  2105. }
  2106. var mark = axis.ticks[lastTick].mark;
  2107. if (mark) {
  2108. if (lastTick - max < tickmarkOffset && lastTick - max > 0 && axis.ticks[lastTick].isLast) {
  2109. mark.hide();
  2110. }
  2111. else if (axis.ticks[lastTick - 1]) {
  2112. mark.show();
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. /**
  2119. * @private
  2120. */
  2121. function onAfterSetAxisTranslation() {
  2122. var axis = this;
  2123. var tickInfo = axis.tickPositions && axis.tickPositions.info;
  2124. var options = axis.options;
  2125. var gridOptions = options.grid || {};
  2126. var userLabels = axis.userOptions.labels || {};
  2127. // Fire this only for the Gantt type chart, #14868.
  2128. if (gridOptions.enabled) {
  2129. if (axis.horiz) {
  2130. axis.series.forEach(function (series) {
  2131. series.options.pointRange = 0;
  2132. });
  2133. // Lower level time ticks, like hours or minutes, represent
  2134. // points in time and not ranges. These should be aligned
  2135. // left in the grid cell by default. The same applies to
  2136. // years of higher order.
  2137. if (tickInfo &&
  2138. options.dateTimeLabelFormats &&
  2139. options.labels &&
  2140. !defined(userLabels.align) &&
  2141. (options.dateTimeLabelFormats[tickInfo.unitName].range === false ||
  2142. tickInfo.count > 1 // years
  2143. )) {
  2144. options.labels.align = 'left';
  2145. if (!defined(userLabels.x)) {
  2146. options.labels.x = 3;
  2147. }
  2148. }
  2149. }
  2150. else {
  2151. // Don't trim ticks which not in min/max range but
  2152. // they are still in the min/max plus tickInterval.
  2153. if (this.options.type !== 'treegrid' &&
  2154. axis.grid &&
  2155. axis.grid.columns) {
  2156. this.minPointOffset = this.tickInterval;
  2157. }
  2158. }
  2159. }
  2160. }
  2161. /**
  2162. * Creates a left and right wall on horizontal axes:
  2163. * - Places leftmost tick at the start of the axis, to create a left
  2164. * wall
  2165. * - Ensures that the rightmost tick is at the end of the axis, to
  2166. * create a right wall.
  2167. * @private
  2168. */
  2169. function onAfterSetOptions(e) {
  2170. var options = this.options,
  2171. userOptions = e.userOptions,
  2172. gridOptions = ((options && isObject(options.grid)) ? options.grid : {});
  2173. var gridAxisOptions;
  2174. if (gridOptions.enabled === true) {
  2175. // Merge the user options into default grid axis options so
  2176. // that when a user option is set, it takes presedence.
  2177. gridAxisOptions = merge(true, {
  2178. className: ('highcharts-grid-axis ' + (userOptions.className || '')),
  2179. dateTimeLabelFormats: {
  2180. hour: {
  2181. list: ['%H:%M', '%H']
  2182. },
  2183. day: {
  2184. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  2185. },
  2186. week: {
  2187. list: ['Week %W', 'W%W']
  2188. },
  2189. month: {
  2190. list: ['%B', '%b', '%o']
  2191. }
  2192. },
  2193. grid: {
  2194. borderWidth: 1
  2195. },
  2196. labels: {
  2197. padding: 2,
  2198. style: {
  2199. fontSize: '13px'
  2200. }
  2201. },
  2202. margin: 0,
  2203. title: {
  2204. text: null,
  2205. reserveSpace: false,
  2206. rotation: 0
  2207. },
  2208. // In a grid axis, only allow one unit of certain types,
  2209. // for example we shouln't have one grid cell spanning
  2210. // two days.
  2211. units: [[
  2212. 'millisecond',
  2213. [1, 10, 100]
  2214. ], [
  2215. 'second',
  2216. [1, 10]
  2217. ], [
  2218. 'minute',
  2219. [1, 5, 15]
  2220. ], [
  2221. 'hour',
  2222. [1, 6]
  2223. ], [
  2224. 'day',
  2225. [1]
  2226. ], [
  2227. 'week',
  2228. [1]
  2229. ], [
  2230. 'month',
  2231. [1]
  2232. ], [
  2233. 'year',
  2234. null
  2235. ]]
  2236. }, userOptions);
  2237. // X-axis specific options
  2238. if (this.coll === 'xAxis') {
  2239. // For linked axes, tickPixelInterval is used only if
  2240. // the tickPositioner below doesn't run or returns
  2241. // undefined (like multiple years)
  2242. if (defined(userOptions.linkedTo) &&
  2243. !defined(userOptions.tickPixelInterval)) {
  2244. gridAxisOptions.tickPixelInterval = 350;
  2245. }
  2246. // For the secondary grid axis, use the primary axis'
  2247. // tick intervals and return ticks one level higher.
  2248. if (
  2249. // Check for tick pixel interval in options
  2250. !defined(userOptions.tickPixelInterval) &&
  2251. // Only for linked axes
  2252. defined(userOptions.linkedTo) &&
  2253. !defined(userOptions.tickPositioner) &&
  2254. !defined(userOptions.tickInterval)) {
  2255. gridAxisOptions.tickPositioner = function (min, max) {
  2256. var parentInfo = (this.linkedParent &&
  2257. this.linkedParent.tickPositions &&
  2258. this.linkedParent.tickPositions.info);
  2259. if (parentInfo) {
  2260. var units = (gridAxisOptions.units || []);
  2261. var unitIdx = void 0,
  2262. count = void 0,
  2263. unitName = void 0;
  2264. for (var i = 0; i < units.length; i++) {
  2265. if (units[i][0] ===
  2266. parentInfo.unitName) {
  2267. unitIdx = i;
  2268. break;
  2269. }
  2270. }
  2271. // Get the first allowed count on the next
  2272. // unit.
  2273. if (units[unitIdx + 1]) {
  2274. unitName = units[unitIdx + 1][0];
  2275. count =
  2276. (units[unitIdx + 1][1] || [1])[0];
  2277. // In case the base X axis shows years, make
  2278. // the secondary axis show ten times the
  2279. // years (#11427)
  2280. }
  2281. else if (parentInfo.unitName === 'year') {
  2282. unitName = 'year';
  2283. count = parentInfo.count * 10;
  2284. }
  2285. var unitRange = timeUnits[unitName];
  2286. this.tickInterval = unitRange * count;
  2287. return this.getTimeTicks({
  2288. unitRange: unitRange,
  2289. count: count,
  2290. unitName: unitName
  2291. }, min, max, this.options.startOfWeek);
  2292. }
  2293. };
  2294. }
  2295. }
  2296. // Now merge the combined options into the axis options
  2297. merge(true, this.options, gridAxisOptions);
  2298. if (this.horiz) {
  2299. /* _________________________
  2300. Make this: ___|_____|_____|_____|__|
  2301. ^ ^
  2302. _________________________
  2303. Into this: |_____|_____|_____|_____|
  2304. ^ ^ */
  2305. options.minPadding = pick(userOptions.minPadding, 0);
  2306. options.maxPadding = pick(userOptions.maxPadding, 0);
  2307. }
  2308. // If borderWidth is set, then use its value for tick and
  2309. // line width.
  2310. if (isNumber(options.grid.borderWidth)) {
  2311. options.tickWidth = options.lineWidth =
  2312. gridOptions.borderWidth;
  2313. }
  2314. }
  2315. }
  2316. /**
  2317. * @private
  2318. */
  2319. function onAfterSetOptions2(e) {
  2320. var axis = this;
  2321. var userOptions = e.userOptions;
  2322. var gridOptions = userOptions && userOptions.grid || {};
  2323. var columns = gridOptions.columns;
  2324. // Add column options to the parent axis. Children has their column
  2325. // options set on init in onGridAxisAfterInit.
  2326. if (gridOptions.enabled && columns) {
  2327. merge(true, axis.options, columns[columns.length - 1]);
  2328. }
  2329. }
  2330. /**
  2331. * Handle columns and setScale.
  2332. * @private
  2333. */
  2334. function onAfterSetScale() {
  2335. var axis = this;
  2336. (axis.grid.columns || []).forEach(function (column) {
  2337. column.setScale();
  2338. });
  2339. }
  2340. /**
  2341. * Draw vertical axis ticks extra long to create cell floors and roofs.
  2342. * Overrides the tickLength for vertical axes.
  2343. * @private
  2344. */
  2345. function onAfterTickSize(e) {
  2346. var defaultLeftAxisOptions = AxisDefaults.defaultLeftAxisOptions;
  2347. var _a = this,
  2348. horiz = _a.horiz,
  2349. maxLabelDimensions = _a.maxLabelDimensions,
  2350. _b = _a.options.grid,
  2351. gridOptions = _b === void 0 ? {} : _b;
  2352. if (gridOptions.enabled && maxLabelDimensions) {
  2353. var labelPadding = (Math.abs(defaultLeftAxisOptions.labels.x) * 2);
  2354. var distance = horiz ?
  2355. gridOptions.cellHeight || labelPadding + maxLabelDimensions.height :
  2356. labelPadding + maxLabelDimensions.width;
  2357. if (isArray(e.tickSize)) {
  2358. e.tickSize[0] = distance;
  2359. }
  2360. else {
  2361. e.tickSize = [distance, 0];
  2362. }
  2363. }
  2364. }
  2365. /**
  2366. * @private
  2367. */
  2368. function onChartAfterSetChartSize() {
  2369. this.axes.forEach(function (axis) {
  2370. (axis.grid && axis.grid.columns || []).forEach(function (column) {
  2371. column.setAxisSize();
  2372. column.setAxisTranslation();
  2373. });
  2374. });
  2375. }
  2376. /**
  2377. * @private
  2378. */
  2379. function onDestroy(e) {
  2380. var grid = this.grid;
  2381. (grid.columns || []).forEach(function (column) {
  2382. column.destroy(e.keepEvents);
  2383. });
  2384. grid.columns = void 0;
  2385. }
  2386. /**
  2387. * Wraps axis init to draw cell walls on vertical axes.
  2388. * @private
  2389. */
  2390. function onInit(e) {
  2391. var axis = this;
  2392. var userOptions = e.userOptions || {};
  2393. var gridOptions = userOptions.grid || {};
  2394. if (gridOptions.enabled && defined(gridOptions.borderColor)) {
  2395. userOptions.tickColor = userOptions.lineColor = gridOptions.borderColor;
  2396. }
  2397. if (!axis.grid) {
  2398. axis.grid = new Additions(axis);
  2399. }
  2400. }
  2401. /**
  2402. * Center tick labels in cells.
  2403. * @private
  2404. */
  2405. function onTickAfterGetLabelPosition(e) {
  2406. var tick = this,
  2407. label = tick.label,
  2408. axis = tick.axis,
  2409. reversed = axis.reversed,
  2410. chart = axis.chart,
  2411. options = axis.options,
  2412. gridOptions = options.grid || {},
  2413. labelOpts = axis.options.labels,
  2414. align = labelOpts.align,
  2415. // verticalAlign is currently not supported for axis.labels.
  2416. verticalAlign = 'middle', // labelOpts.verticalAlign,
  2417. side = GridAxis.Side[axis.side],
  2418. tickmarkOffset = e.tickmarkOffset,
  2419. tickPositions = axis.tickPositions,
  2420. tickPos = tick.pos - tickmarkOffset,
  2421. nextTickPos = (isNumber(tickPositions[e.index + 1]) ?
  2422. tickPositions[e.index + 1] - tickmarkOffset :
  2423. (axis.max || 0) + tickmarkOffset),
  2424. tickSize = axis.tickSize('tick'),
  2425. tickWidth = tickSize ? tickSize[0] : 0,
  2426. crispCorr = tickSize ? tickSize[1] / 2 : 0;
  2427. var labelHeight,
  2428. lblMetrics,
  2429. lines,
  2430. bottom,
  2431. top,
  2432. left,
  2433. right;
  2434. // Only center tick labels in grid axes
  2435. if (gridOptions.enabled === true) {
  2436. // Calculate top and bottom positions of the cell.
  2437. if (side === 'top') {
  2438. bottom = axis.top + axis.offset;
  2439. top = bottom - tickWidth;
  2440. }
  2441. else if (side === 'bottom') {
  2442. top = chart.chartHeight - axis.bottom + axis.offset;
  2443. bottom = top + tickWidth;
  2444. }
  2445. else {
  2446. bottom = axis.top + axis.len - (axis.translate(reversed ? nextTickPos : tickPos) || 0);
  2447. top = axis.top + axis.len - (axis.translate(reversed ? tickPos : nextTickPos) || 0);
  2448. }
  2449. // Calculate left and right positions of the cell.
  2450. if (side === 'right') {
  2451. left = chart.chartWidth - axis.right + axis.offset;
  2452. right = left + tickWidth;
  2453. }
  2454. else if (side === 'left') {
  2455. right = axis.left + axis.offset;
  2456. left = right - tickWidth;
  2457. }
  2458. else {
  2459. left = Math.round(axis.left + (axis.translate(reversed ? nextTickPos : tickPos) || 0)) - crispCorr;
  2460. right = Math.min(// #15742
  2461. Math.round(axis.left + (axis.translate(reversed ? tickPos : nextTickPos) || 0)) - crispCorr, axis.left + axis.len);
  2462. }
  2463. tick.slotWidth = right - left;
  2464. // Calculate the positioning of the label based on
  2465. // alignment.
  2466. e.pos.x = (align === 'left' ?
  2467. left :
  2468. align === 'right' ?
  2469. right :
  2470. left + ((right - left) / 2) // default to center
  2471. );
  2472. e.pos.y = (verticalAlign === 'top' ?
  2473. top :
  2474. verticalAlign === 'bottom' ?
  2475. bottom :
  2476. top + ((bottom - top) / 2) // default to middle
  2477. );
  2478. lblMetrics = chart.renderer.fontMetrics(labelOpts.style.fontSize, label && label.element);
  2479. labelHeight = label ? label.getBBox().height : 0;
  2480. // Adjustment to y position to align the label correctly.
  2481. // Would be better to have a setter or similar for this.
  2482. if (!labelOpts.useHTML) {
  2483. lines = Math.round(labelHeight / lblMetrics.h);
  2484. e.pos.y += (
  2485. // Center the label
  2486. // TODO: why does this actually center the label?
  2487. ((lblMetrics.b - (lblMetrics.h - lblMetrics.f)) / 2) +
  2488. // Adjust for height of additional lines.
  2489. -(((lines - 1) * lblMetrics.h) / 2));
  2490. }
  2491. else {
  2492. e.pos.y += (
  2493. // Readjust yCorr in htmlUpdateTransform
  2494. lblMetrics.b +
  2495. // Adjust for height of html label
  2496. -(labelHeight / 2));
  2497. }
  2498. e.pos.x += (axis.horiz && labelOpts.x) || 0;
  2499. }
  2500. }
  2501. /**
  2502. * @private
  2503. */
  2504. function onTickLabelFormat(ctx) {
  2505. var axis = ctx.axis,
  2506. value = ctx.value;
  2507. if (axis.options.grid &&
  2508. axis.options.grid.enabled) {
  2509. var tickPos = axis.tickPositions;
  2510. var series = (axis.linkedParent || axis).series[0];
  2511. var isFirst = value === tickPos[0];
  2512. var isLast = value === tickPos[tickPos.length - 1];
  2513. var point = series && find(series.options.data,
  2514. function (p) {
  2515. return p[axis.isXAxis ? 'x' : 'y'] === value;
  2516. });
  2517. var pointCopy = void 0;
  2518. if (point && series.is('gantt')) {
  2519. // For the Gantt set point aliases to the pointCopy
  2520. // to do not change the original point
  2521. pointCopy = merge(point);
  2522. H.seriesTypes.gantt.prototype.pointClass
  2523. .setGanttPointAliases(pointCopy);
  2524. }
  2525. // Make additional properties available for the
  2526. // formatter
  2527. ctx.isFirst = isFirst;
  2528. ctx.isLast = isLast;
  2529. ctx.point = pointCopy;
  2530. }
  2531. }
  2532. /**
  2533. * Makes tick labels which are usually ignored in a linked axis
  2534. * displayed if they are within range of linkedParent.min.
  2535. * ```
  2536. * _____________________________
  2537. * | | | | |
  2538. * Make this: | | 2 | 3 | 4 |
  2539. * |___|_______|_______|_______|
  2540. * ^
  2541. * _____________________________
  2542. * | | | | |
  2543. * Into this: | 1 | 2 | 3 | 4 |
  2544. * |___|_______|_______|_______|
  2545. * ^
  2546. * ```
  2547. * @private
  2548. * @todo Does this function do what the drawing says? Seems to affect
  2549. * ticks and not the labels directly?
  2550. */
  2551. function onTrimTicks() {
  2552. var axis = this;
  2553. var options = axis.options;
  2554. var gridOptions = options.grid || {};
  2555. var categoryAxis = axis.categories;
  2556. var tickPositions = axis.tickPositions;
  2557. var firstPos = tickPositions[0];
  2558. var lastPos = tickPositions[tickPositions.length - 1];
  2559. var linkedMin = axis.linkedParent && axis.linkedParent.min;
  2560. var linkedMax = axis.linkedParent && axis.linkedParent.max;
  2561. var min = linkedMin || axis.min;
  2562. var max = linkedMax || axis.max;
  2563. var tickInterval = axis.tickInterval;
  2564. var endMoreThanMin = (firstPos < min &&
  2565. firstPos + tickInterval > min);
  2566. var startLessThanMax = (lastPos > max &&
  2567. lastPos - tickInterval < max);
  2568. if (gridOptions.enabled === true &&
  2569. !categoryAxis &&
  2570. (axis.horiz || axis.isLinked)) {
  2571. if (endMoreThanMin && !options.startOnTick) {
  2572. tickPositions[0] = min;
  2573. }
  2574. if (startLessThanMax && !options.endOnTick) {
  2575. tickPositions[tickPositions.length - 1] = max;
  2576. }
  2577. }
  2578. }
  2579. /**
  2580. * Avoid altering tickInterval when reserving space.
  2581. * @private
  2582. */
  2583. function wrapUnsquish(proceed) {
  2584. var axis = this;
  2585. var _a = axis.options.grid,
  2586. gridOptions = _a === void 0 ? {} : _a;
  2587. if (gridOptions.enabled === true && axis.categories) {
  2588. return axis.tickInterval;
  2589. }
  2590. return proceed.apply(axis, argsToArray(arguments));
  2591. }
  2592. /* *
  2593. *
  2594. * Class
  2595. *
  2596. * */
  2597. /**
  2598. * Additions for grid axes.
  2599. * @private
  2600. * @class
  2601. */
  2602. var Additions = /** @class */ (function () {
  2603. /* *
  2604. *
  2605. * Constructors
  2606. *
  2607. * */
  2608. function Additions(axis) {
  2609. this.axis = axis;
  2610. }
  2611. /* *
  2612. *
  2613. * Functions
  2614. *
  2615. * */
  2616. /**
  2617. * Checks if an axis is the outer axis in its dimension. Since
  2618. * axes are placed outwards in order, the axis with the highest
  2619. * index is the outermost axis.
  2620. *
  2621. * Example: If there are multiple x-axes at the top of the chart,
  2622. * this function returns true if the axis supplied is the last
  2623. * of the x-axes.
  2624. *
  2625. * @private
  2626. *
  2627. * @return {boolean}
  2628. * True if the axis is the outermost axis in its dimension; false if
  2629. * not.
  2630. */
  2631. Additions.prototype.isOuterAxis = function () {
  2632. var axis = this.axis;
  2633. var chart = axis.chart;
  2634. var columnIndex = axis.grid.columnIndex;
  2635. var columns = (axis.linkedParent && axis.linkedParent.grid.columns ||
  2636. axis.grid.columns);
  2637. var parentAxis = columnIndex ? axis.linkedParent : axis;
  2638. var thisIndex = -1,
  2639. lastIndex = 0;
  2640. chart[axis.coll].forEach(function (otherAxis, index) {
  2641. if (otherAxis.side === axis.side && !otherAxis.options.isInternal) {
  2642. lastIndex = index;
  2643. if (otherAxis === parentAxis) {
  2644. // Get the index of the axis in question
  2645. thisIndex = index;
  2646. }
  2647. }
  2648. });
  2649. return (lastIndex === thisIndex &&
  2650. (isNumber(columnIndex) ? columns.length === columnIndex : true));
  2651. };
  2652. /**
  2653. * Add extra border based on the provided path.
  2654. * *
  2655. * @private
  2656. *
  2657. * @param {SVGPath} path
  2658. * The path of the border.
  2659. *
  2660. * @return {Highcharts.SVGElement}
  2661. */
  2662. Additions.prototype.renderBorder = function (path) {
  2663. var axis = this.axis,
  2664. renderer = axis.chart.renderer,
  2665. options = axis.options,
  2666. extraBorderLine = renderer.path(path)
  2667. .addClass('highcharts-axis-line')
  2668. .add(axis.axisBorder);
  2669. if (!renderer.styledMode) {
  2670. extraBorderLine.attr({
  2671. stroke: options.lineColor,
  2672. 'stroke-width': options.lineWidth,
  2673. zIndex: 7
  2674. });
  2675. }
  2676. return extraBorderLine;
  2677. };
  2678. return Additions;
  2679. }());
  2680. GridAxis.Additions = Additions;
  2681. })(GridAxis || (GridAxis = {}));
  2682. /* *
  2683. *
  2684. * Registry
  2685. *
  2686. * */
  2687. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  2688. dateFormats.E = function (timestamp) {
  2689. return this.dateFormat('%a', timestamp, true).charAt(0);
  2690. };
  2691. // Adds week date format
  2692. dateFormats.W = function (timestamp) {
  2693. var d = new this.Date(timestamp);
  2694. var firstDay = (this.get('Day',
  2695. d) + 6) % 7;
  2696. var thursday = new this.Date(d.valueOf());
  2697. this.set('Date', thursday, this.get('Date', d) - firstDay + 3);
  2698. var firstThursday = new this.Date(this.get('FullYear',
  2699. thursday), 0, 1);
  2700. if (this.get('Day', firstThursday) !== 4) {
  2701. this.set('Month', d, 0);
  2702. this.set('Date', d, 1 + (11 - this.get('Day', firstThursday)) % 7);
  2703. }
  2704. return (1 +
  2705. Math.floor((thursday.valueOf() - firstThursday.valueOf()) / 604800000)).toString();
  2706. };
  2707. /* *
  2708. *
  2709. * Default Export
  2710. *
  2711. * */
  2712. /* *
  2713. *
  2714. * API Options
  2715. *
  2716. * */
  2717. /**
  2718. * @productdesc {gantt}
  2719. * For grid axes (like in Gantt charts),
  2720. * it is possible to declare as a list to provide different
  2721. * formats depending on available space.
  2722. *
  2723. * Defaults to:
  2724. * ```js
  2725. * {
  2726. * hour: { list: ['%H:%M', '%H'] },
  2727. * day: { list: ['%A, %e. %B', '%a, %e. %b', '%E'] },
  2728. * week: { list: ['Week %W', 'W%W'] },
  2729. * month: { list: ['%B', '%b', '%o'] }
  2730. * }
  2731. * ```
  2732. *
  2733. * @sample {gantt} gantt/grid-axis/date-time-label-formats
  2734. * Gantt chart with custom axis date format.
  2735. *
  2736. * @apioption xAxis.dateTimeLabelFormats
  2737. */
  2738. /**
  2739. * Set grid options for the axis labels. Requires Highcharts Gantt.
  2740. *
  2741. * @since 6.2.0
  2742. * @product gantt
  2743. * @apioption xAxis.grid
  2744. */
  2745. /**
  2746. * Enable grid on the axis labels. Defaults to true for Gantt charts.
  2747. *
  2748. * @type {boolean}
  2749. * @default true
  2750. * @since 6.2.0
  2751. * @product gantt
  2752. * @apioption xAxis.grid.enabled
  2753. */
  2754. /**
  2755. * Set specific options for each column (or row for horizontal axes) in the
  2756. * grid. Each extra column/row is its own axis, and the axis options can be set
  2757. * here.
  2758. *
  2759. * @sample gantt/demo/left-axis-table
  2760. * Left axis as a table
  2761. *
  2762. * @type {Array<Highcharts.XAxisOptions>}
  2763. * @apioption xAxis.grid.columns
  2764. */
  2765. /**
  2766. * Set border color for the label grid lines.
  2767. *
  2768. * @type {Highcharts.ColorString}
  2769. * @apioption xAxis.grid.borderColor
  2770. */
  2771. /**
  2772. * Set border width of the label grid lines.
  2773. *
  2774. * @type {number}
  2775. * @default 1
  2776. * @apioption xAxis.grid.borderWidth
  2777. */
  2778. /**
  2779. * Set cell height for grid axis labels. By default this is calculated from font
  2780. * size. This option only applies to horizontal axes.
  2781. *
  2782. * @sample gantt/grid-axis/cellheight
  2783. * Gant chart with custom cell height
  2784. * @type {number}
  2785. * @apioption xAxis.grid.cellHeight
  2786. */
  2787. ''; // keeps doclets above in JS file
  2788. return GridAxis;
  2789. });
  2790. _registerModule(_modules, 'Gantt/Tree.js', [_modules['Core/Utilities.js']], function (U) {
  2791. /* *
  2792. *
  2793. * (c) 2016-2021 Highsoft AS
  2794. *
  2795. * Authors: Jon Arild Nygard
  2796. *
  2797. * License: www.highcharts.com/license
  2798. *
  2799. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2800. *
  2801. * */
  2802. /* eslint no-console: 0 */
  2803. var extend = U.extend,
  2804. isNumber = U.isNumber,
  2805. pick = U.pick;
  2806. /**
  2807. * Creates an object map from parent id to childrens index.
  2808. *
  2809. * @private
  2810. * @function Highcharts.Tree#getListOfParents
  2811. *
  2812. * @param {Array<*>} data
  2813. * List of points set in options. `Array.parent` is parent id of point.
  2814. *
  2815. * @param {Array<string>} ids
  2816. * List of all point ids.
  2817. *
  2818. * @return {Highcharts.Dictionary<Array<*>>}
  2819. * Map from parent id to children index in data
  2820. */
  2821. var getListOfParents = function (data,
  2822. ids) {
  2823. var listOfParents = data.reduce(function (prev,
  2824. curr) {
  2825. var parent = pick(curr.parent, '');
  2826. if (typeof prev[parent] === 'undefined') {
  2827. prev[parent] = [];
  2828. }
  2829. prev[parent].push(curr);
  2830. return prev;
  2831. }, {}), parents = Object.keys(listOfParents);
  2832. // If parent does not exist, hoist parent to root of tree.
  2833. parents.forEach(function (parent, list) {
  2834. var children = listOfParents[parent];
  2835. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  2836. children.forEach(function (child) {
  2837. list[''].push(child);
  2838. });
  2839. delete list[parent];
  2840. }
  2841. });
  2842. return listOfParents;
  2843. };
  2844. var getNode = function (id,
  2845. parent,
  2846. level,
  2847. data,
  2848. mapOfIdToChildren,
  2849. options) {
  2850. var descendants = 0,
  2851. height = 0,
  2852. after = options && options.after,
  2853. before = options && options.before,
  2854. node = {
  2855. data: data,
  2856. depth: level - 1,
  2857. id: id,
  2858. level: level,
  2859. parent: parent
  2860. },
  2861. start,
  2862. end,
  2863. children;
  2864. // Allow custom logic before the children has been created.
  2865. if (typeof before === 'function') {
  2866. before(node, options);
  2867. }
  2868. // Call getNode recursively on the children. Calulate the height of the
  2869. // node, and the number of descendants.
  2870. children = ((mapOfIdToChildren[id] || [])).map(function (child) {
  2871. var node = getNode(child.id,
  2872. id, (level + 1),
  2873. child,
  2874. mapOfIdToChildren,
  2875. options),
  2876. childStart = child.start,
  2877. childEnd = (child.milestone === true ?
  2878. childStart :
  2879. child.end);
  2880. // Start should be the lowest child.start.
  2881. start = ((!isNumber(start) || childStart < start) ?
  2882. childStart :
  2883. start);
  2884. // End should be the largest child.end.
  2885. // If child is milestone, then use start as end.
  2886. end = ((!isNumber(end) || childEnd > end) ?
  2887. childEnd :
  2888. end);
  2889. descendants = descendants + 1 + node.descendants;
  2890. height = Math.max(node.height + 1, height);
  2891. return node;
  2892. });
  2893. // Calculate start and end for point if it is not already explicitly set.
  2894. if (data) {
  2895. data.start = pick(data.start, start);
  2896. data.end = pick(data.end, end);
  2897. }
  2898. extend(node, {
  2899. children: children,
  2900. descendants: descendants,
  2901. height: height
  2902. });
  2903. // Allow custom logic after the children has been created.
  2904. if (typeof after === 'function') {
  2905. after(node, options);
  2906. }
  2907. return node;
  2908. };
  2909. var getTree = function (data,
  2910. options) {
  2911. var ids = data.map(function (d) {
  2912. return d.id;
  2913. }), mapOfIdToChildren = getListOfParents(data, ids);
  2914. return getNode('', null, 1, null, mapOfIdToChildren, options);
  2915. };
  2916. var Tree = {
  2917. getListOfParents: getListOfParents,
  2918. getNode: getNode,
  2919. getTree: getTree
  2920. };
  2921. return Tree;
  2922. });
  2923. _registerModule(_modules, 'Core/Axis/TreeGridTick.js', [_modules['Core/Color/Palette.js'], _modules['Core/Utilities.js']], function (palette, U) {
  2924. /* *
  2925. *
  2926. * (c) 2016 Highsoft AS
  2927. * Authors: Jon Arild Nygard
  2928. *
  2929. * License: www.highcharts.com/license
  2930. *
  2931. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2932. *
  2933. * */
  2934. var addEvent = U.addEvent,
  2935. isObject = U.isObject,
  2936. isNumber = U.isNumber,
  2937. pick = U.pick,
  2938. wrap = U.wrap;
  2939. /* eslint-disable no-invalid-this, valid-jsdoc */
  2940. /**
  2941. * @private
  2942. */
  2943. var TreeGridTick;
  2944. (function (TreeGridTick) {
  2945. /* *
  2946. *
  2947. * Interfaces
  2948. *
  2949. * */
  2950. /* *
  2951. *
  2952. * Variables
  2953. *
  2954. * */
  2955. var applied = false;
  2956. /* *
  2957. *
  2958. * Functions
  2959. *
  2960. * */
  2961. /**
  2962. * @private
  2963. */
  2964. function compose(TickClass) {
  2965. if (!applied) {
  2966. addEvent(TickClass, 'init', onInit);
  2967. wrap(TickClass.prototype, 'getLabelPosition', wrapGetLabelPosition);
  2968. wrap(TickClass.prototype, 'renderLabel', wrapRenderLabel);
  2969. // backwards compatibility
  2970. TickClass.prototype.collapse = function (redraw) {
  2971. this.treeGrid.collapse(redraw);
  2972. };
  2973. TickClass.prototype.expand = function (redraw) {
  2974. this.treeGrid.expand(redraw);
  2975. };
  2976. TickClass.prototype.toggleCollapse = function (redraw) {
  2977. this.treeGrid.toggleCollapse(redraw);
  2978. };
  2979. applied = true;
  2980. }
  2981. }
  2982. TreeGridTick.compose = compose;
  2983. /**
  2984. * @private
  2985. */
  2986. function onInit() {
  2987. var tick = this;
  2988. if (!tick.treeGrid) {
  2989. tick.treeGrid = new Additions(tick);
  2990. }
  2991. }
  2992. /**
  2993. * @private
  2994. */
  2995. function onTickHover(label) {
  2996. label.addClass('highcharts-treegrid-node-active');
  2997. if (!label.renderer.styledMode) {
  2998. label.css({
  2999. textDecoration: 'underline'
  3000. });
  3001. }
  3002. }
  3003. /**
  3004. * @private
  3005. */
  3006. function onTickHoverExit(label, options) {
  3007. var css = isObject(options.style) ? options.style : {};
  3008. label.removeClass('highcharts-treegrid-node-active');
  3009. if (!label.renderer.styledMode) {
  3010. label.css({ textDecoration: css.textDecoration });
  3011. }
  3012. }
  3013. /**
  3014. * @private
  3015. */
  3016. function renderLabelIcon(tick, params) {
  3017. var treeGrid = tick.treeGrid,
  3018. isNew = !treeGrid.labelIcon,
  3019. renderer = params.renderer,
  3020. labelBox = params.xy,
  3021. options = params.options,
  3022. width = options.width || 0,
  3023. height = options.height || 0,
  3024. iconCenter = {
  3025. x: labelBox.x - (width / 2) - (options.padding || 0),
  3026. y: labelBox.y - (height / 2)
  3027. },
  3028. rotation = params.collapsed ? 90 : 180,
  3029. shouldRender = params.show && isNumber(iconCenter.y);
  3030. var icon = treeGrid.labelIcon;
  3031. if (!icon) {
  3032. treeGrid.labelIcon = icon = renderer
  3033. .path(renderer.symbols[options.type](options.x || 0, options.y || 0, width, height))
  3034. .addClass('highcharts-label-icon')
  3035. .add(params.group);
  3036. }
  3037. // Set the new position, and show or hide
  3038. icon.attr({ y: shouldRender ? 0 : -9999 }); // #14904, #1338
  3039. // Presentational attributes
  3040. if (!renderer.styledMode) {
  3041. icon
  3042. .attr({
  3043. cursor: 'pointer',
  3044. 'fill': pick(params.color, palette.neutralColor60),
  3045. 'stroke-width': 1,
  3046. stroke: options.lineColor,
  3047. strokeWidth: options.lineWidth || 0
  3048. });
  3049. }
  3050. // Update the icon positions
  3051. icon[isNew ? 'attr' : 'animate']({
  3052. translateX: iconCenter.x,
  3053. translateY: iconCenter.y,
  3054. rotation: rotation
  3055. });
  3056. }
  3057. /**
  3058. * @private
  3059. */
  3060. function wrapGetLabelPosition(proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  3061. var tick = this,
  3062. lbOptions = pick(tick.options && tick.options.labels,
  3063. labelOptions),
  3064. pos = tick.pos,
  3065. axis = tick.axis,
  3066. options = axis.options,
  3067. isTreeGrid = options.type === 'treegrid',
  3068. result = proceed.apply(tick,
  3069. [x,
  3070. y,
  3071. label,
  3072. horiz,
  3073. lbOptions,
  3074. tickmarkOffset,
  3075. index,
  3076. step]);
  3077. var symbolOptions,
  3078. indentation,
  3079. mapOfPosToGridNode,
  3080. node,
  3081. level;
  3082. if (isTreeGrid) {
  3083. symbolOptions = (lbOptions && isObject(lbOptions.symbol, true) ?
  3084. lbOptions.symbol :
  3085. {});
  3086. indentation = (lbOptions && isNumber(lbOptions.indentation) ?
  3087. lbOptions.indentation :
  3088. 0);
  3089. mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode;
  3090. node = mapOfPosToGridNode && mapOfPosToGridNode[pos];
  3091. level = (node && node.depth) || 1;
  3092. result.x += (
  3093. // Add space for symbols
  3094. ((symbolOptions.width || 0) +
  3095. ((symbolOptions.padding || 0) * 2)) +
  3096. // Apply indentation
  3097. ((level - 1) * indentation));
  3098. }
  3099. return result;
  3100. }
  3101. /**
  3102. * @private
  3103. */
  3104. function wrapRenderLabel(proceed) {
  3105. 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) ?
  3106. labelOptions.symbol :
  3107. {}), 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;
  3108. var collapsed,
  3109. addClassName,
  3110. removeClassName;
  3111. if (isTreeGrid && node) {
  3112. // Add class name for hierarchical styling.
  3113. if (label &&
  3114. label.element) {
  3115. label.addClass(prefixClassName + 'level-' + level);
  3116. }
  3117. }
  3118. proceed.apply(tick, Array.prototype.slice.call(arguments, 1));
  3119. if (isTreeGrid &&
  3120. label &&
  3121. label.element &&
  3122. node &&
  3123. node.descendants &&
  3124. node.descendants > 0) {
  3125. collapsed = axis.treeGrid.isCollapsed(node);
  3126. renderLabelIcon(tick, {
  3127. color: !styledMode && label.styles && label.styles.color || '',
  3128. collapsed: collapsed,
  3129. group: label.parentGroup,
  3130. options: symbolOptions,
  3131. renderer: label.renderer,
  3132. show: shouldRender,
  3133. xy: label.xy
  3134. });
  3135. // Add class name for the node.
  3136. addClassName = prefixClassName +
  3137. (collapsed ? 'collapsed' : 'expanded');
  3138. removeClassName = prefixClassName +
  3139. (collapsed ? 'expanded' : 'collapsed');
  3140. label
  3141. .addClass(addClassName)
  3142. .removeClass(removeClassName);
  3143. if (!styledMode) {
  3144. label.css({
  3145. cursor: 'pointer'
  3146. });
  3147. }
  3148. // Add events to both label text and icon
  3149. [label, tick.treeGrid.labelIcon].forEach(function (object) {
  3150. if (object && !object.attachedTreeGridEvents) {
  3151. // On hover
  3152. addEvent(object.element, 'mouseover', function () {
  3153. onTickHover(label);
  3154. });
  3155. // On hover out
  3156. addEvent(object.element, 'mouseout', function () {
  3157. onTickHoverExit(label, labelOptions);
  3158. });
  3159. addEvent(object.element, 'click', function () {
  3160. tick.treeGrid.toggleCollapse();
  3161. });
  3162. object.attachedTreeGridEvents = true;
  3163. }
  3164. });
  3165. }
  3166. }
  3167. /* *
  3168. *
  3169. * Classes
  3170. *
  3171. * */
  3172. /**
  3173. * @private
  3174. * @class
  3175. */
  3176. var Additions = /** @class */ (function () {
  3177. /* *
  3178. *
  3179. * Constructors
  3180. *
  3181. * */
  3182. /**
  3183. * @private
  3184. */
  3185. function Additions(tick) {
  3186. this.tick = tick;
  3187. }
  3188. /* *
  3189. *
  3190. * Functions
  3191. *
  3192. * */
  3193. /**
  3194. * Collapse the grid cell. Used when axis is of type treegrid.
  3195. *
  3196. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  3197. *
  3198. * @private
  3199. * @function Highcharts.Tick#collapse
  3200. *
  3201. * @param {boolean} [redraw=true]
  3202. * Whether to redraw the chart or wait for an explicit call to
  3203. * {@link Highcharts.Chart#redraw}
  3204. */
  3205. Additions.prototype.collapse = function (redraw) {
  3206. var tick = this.tick,
  3207. axis = tick.axis,
  3208. brokenAxis = axis.brokenAxis;
  3209. if (brokenAxis &&
  3210. axis.treeGrid.mapOfPosToGridNode) {
  3211. var pos = tick.pos,
  3212. node = axis.treeGrid.mapOfPosToGridNode[pos],
  3213. breaks = axis.treeGrid.collapse(node);
  3214. brokenAxis.setBreaks(breaks, pick(redraw, true));
  3215. }
  3216. };
  3217. /**
  3218. * Expand the grid cell. Used when axis is of type treegrid.
  3219. *
  3220. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  3221. *
  3222. * @private
  3223. * @function Highcharts.Tick#expand
  3224. *
  3225. * @param {boolean} [redraw=true]
  3226. * Whether to redraw the chart or wait for an explicit call to
  3227. * {@link Highcharts.Chart#redraw}
  3228. */
  3229. Additions.prototype.expand = function (redraw) {
  3230. var tick = this.tick,
  3231. axis = tick.axis,
  3232. brokenAxis = axis.brokenAxis;
  3233. if (brokenAxis &&
  3234. axis.treeGrid.mapOfPosToGridNode) {
  3235. var pos = tick.pos,
  3236. node = axis.treeGrid.mapOfPosToGridNode[pos],
  3237. breaks = axis.treeGrid.expand(node);
  3238. brokenAxis.setBreaks(breaks, pick(redraw, true));
  3239. }
  3240. };
  3241. /**
  3242. * Toggle the collapse/expand state of the grid cell. Used when axis is
  3243. * of type treegrid.
  3244. *
  3245. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  3246. *
  3247. * @private
  3248. * @function Highcharts.Tick#toggleCollapse
  3249. *
  3250. * @param {boolean} [redraw=true]
  3251. * Whether to redraw the chart or wait for an explicit call to
  3252. * {@link Highcharts.Chart#redraw}
  3253. */
  3254. Additions.prototype.toggleCollapse = function (redraw) {
  3255. var tick = this.tick,
  3256. axis = tick.axis,
  3257. brokenAxis = axis.brokenAxis;
  3258. if (brokenAxis &&
  3259. axis.treeGrid.mapOfPosToGridNode) {
  3260. var pos = tick.pos,
  3261. node = axis.treeGrid.mapOfPosToGridNode[pos],
  3262. breaks = axis.treeGrid.toggleCollapse(node);
  3263. brokenAxis.setBreaks(breaks, pick(redraw, true));
  3264. }
  3265. };
  3266. return Additions;
  3267. }());
  3268. TreeGridTick.Additions = Additions;
  3269. })(TreeGridTick || (TreeGridTick = {}));
  3270. return TreeGridTick;
  3271. });
  3272. _registerModule(_modules, 'Mixins/TreeSeries.js', [_modules['Core/Color/Color.js'], _modules['Core/Utilities.js']], function (Color, U) {
  3273. /* *
  3274. *
  3275. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3276. *
  3277. * */
  3278. var extend = U.extend,
  3279. isArray = U.isArray,
  3280. isNumber = U.isNumber,
  3281. isObject = U.isObject,
  3282. merge = U.merge,
  3283. pick = U.pick;
  3284. var isBoolean = function (x) {
  3285. return typeof x === 'boolean';
  3286. }, isFn = function (x) {
  3287. return typeof x === 'function';
  3288. };
  3289. /* eslint-disable valid-jsdoc */
  3290. /**
  3291. * @todo Combine buildTree and buildNode with setTreeValues
  3292. * @todo Remove logic from Treemap and make it utilize this mixin.
  3293. * @private
  3294. */
  3295. var setTreeValues = function setTreeValues(tree,
  3296. options) {
  3297. var before = options.before,
  3298. idRoot = options.idRoot,
  3299. mapIdToNode = options.mapIdToNode,
  3300. nodeRoot = mapIdToNode[idRoot],
  3301. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  3302. options.levelIsConstant :
  3303. true),
  3304. points = options.points,
  3305. point = points[tree.i],
  3306. optionsPoint = point && point.options || {},
  3307. childrenTotal = 0,
  3308. children = [],
  3309. value;
  3310. tree.levelDynamic = tree.level - (levelIsConstant ? 0 : nodeRoot.level);
  3311. tree.name = pick(point && point.name, '');
  3312. tree.visible = (idRoot === tree.id ||
  3313. (isBoolean(options.visible) ? options.visible : false));
  3314. if (isFn(before)) {
  3315. tree = before(tree, options);
  3316. }
  3317. // First give the children some values
  3318. tree.children.forEach(function (child, i) {
  3319. var newOptions = extend({},
  3320. options);
  3321. extend(newOptions, {
  3322. index: i,
  3323. siblings: tree.children.length,
  3324. visible: tree.visible
  3325. });
  3326. child = setTreeValues(child, newOptions);
  3327. children.push(child);
  3328. if (child.visible) {
  3329. childrenTotal += child.val;
  3330. }
  3331. });
  3332. tree.visible = childrenTotal > 0 || tree.visible;
  3333. // Set the values
  3334. value = pick(optionsPoint.value, childrenTotal);
  3335. tree.children = children;
  3336. tree.childrenTotal = childrenTotal;
  3337. tree.isLeaf = tree.visible && !childrenTotal;
  3338. tree.val = value;
  3339. return tree;
  3340. };
  3341. /**
  3342. * @private
  3343. */
  3344. var getColor = function getColor(node,
  3345. options) {
  3346. var index = options.index,
  3347. mapOptionsToLevel = options.mapOptionsToLevel,
  3348. parentColor = options.parentColor,
  3349. parentColorIndex = options.parentColorIndex,
  3350. series = options.series,
  3351. colors = options.colors,
  3352. siblings = options.siblings,
  3353. points = series.points,
  3354. getColorByPoint,
  3355. chartOptionsChart = series.chart.options.chart,
  3356. point,
  3357. level,
  3358. colorByPoint,
  3359. colorIndexByPoint,
  3360. color,
  3361. colorIndex;
  3362. /**
  3363. * @private
  3364. */
  3365. function variation(color) {
  3366. var colorVariation = level && level.colorVariation;
  3367. if (colorVariation) {
  3368. if (colorVariation.key === 'brightness') {
  3369. return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
  3370. }
  3371. }
  3372. return color;
  3373. }
  3374. if (node) {
  3375. point = points[node.i];
  3376. level = mapOptionsToLevel[node.level] || {};
  3377. getColorByPoint = point && level.colorByPoint;
  3378. if (getColorByPoint) {
  3379. colorIndexByPoint = point.index % (colors ?
  3380. colors.length :
  3381. chartOptionsChart.colorCount);
  3382. colorByPoint = colors && colors[colorIndexByPoint];
  3383. }
  3384. // Select either point color, level color or inherited color.
  3385. if (!series.chart.styledMode) {
  3386. color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
  3387. }
  3388. colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
  3389. }
  3390. return {
  3391. color: color,
  3392. colorIndex: colorIndex
  3393. };
  3394. };
  3395. /**
  3396. * Creates a map from level number to its given options.
  3397. *
  3398. * @private
  3399. * @function getLevelOptions
  3400. * @param {object} params
  3401. * Object containing parameters.
  3402. * - `defaults` Object containing default options. The default options
  3403. * are merged with the userOptions to get the final options for a
  3404. * specific level.
  3405. * - `from` The lowest level number.
  3406. * - `levels` User options from series.levels.
  3407. * - `to` The highest level number.
  3408. * @return {Highcharts.Dictionary<object>|null}
  3409. * Returns a map from level number to its given options.
  3410. */
  3411. var getLevelOptions = function getLevelOptions(params) {
  3412. var result = null,
  3413. defaults,
  3414. converted,
  3415. i,
  3416. from,
  3417. to,
  3418. levels;
  3419. if (isObject(params)) {
  3420. result = {};
  3421. from = isNumber(params.from) ? params.from : 1;
  3422. levels = params.levels;
  3423. converted = {};
  3424. defaults = isObject(params.defaults) ? params.defaults : {};
  3425. if (isArray(levels)) {
  3426. converted = levels.reduce(function (obj, item) {
  3427. var level,
  3428. levelIsConstant,
  3429. options;
  3430. if (isObject(item) && isNumber(item.level)) {
  3431. options = merge({}, item);
  3432. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  3433. options.levelIsConstant :
  3434. defaults.levelIsConstant);
  3435. // Delete redundant properties.
  3436. delete options.levelIsConstant;
  3437. delete options.level;
  3438. // Calculate which level these options apply to.
  3439. level = item.level + (levelIsConstant ? 0 : from - 1);
  3440. if (isObject(obj[level])) {
  3441. extend(obj[level], options);
  3442. }
  3443. else {
  3444. obj[level] = options;
  3445. }
  3446. }
  3447. return obj;
  3448. }, {});
  3449. }
  3450. to = isNumber(params.to) ? params.to : 1;
  3451. for (i = 0; i <= to; i++) {
  3452. result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
  3453. }
  3454. }
  3455. return result;
  3456. };
  3457. /**
  3458. * Update the rootId property on the series. Also makes sure that it is
  3459. * accessible to exporting.
  3460. *
  3461. * @private
  3462. * @function updateRootId
  3463. *
  3464. * @param {object} series
  3465. * The series to operate on.
  3466. *
  3467. * @return {string}
  3468. * Returns the resulting rootId after update.
  3469. */
  3470. var updateRootId = function (series) {
  3471. var rootId,
  3472. options;
  3473. if (isObject(series)) {
  3474. // Get the series options.
  3475. options = isObject(series.options) ? series.options : {};
  3476. // Calculate the rootId.
  3477. rootId = pick(series.rootNode, options.rootId, '');
  3478. // Set rootId on series.userOptions to pick it up in exporting.
  3479. if (isObject(series.userOptions)) {
  3480. series.userOptions.rootId = rootId;
  3481. }
  3482. // Set rootId on series to pick it up on next update.
  3483. series.rootNode = rootId;
  3484. }
  3485. return rootId;
  3486. };
  3487. var result = {
  3488. getColor: getColor,
  3489. getLevelOptions: getLevelOptions,
  3490. setTreeValues: setTreeValues,
  3491. updateRootId: updateRootId
  3492. };
  3493. return result;
  3494. });
  3495. _registerModule(_modules, 'Core/Axis/TreeGridAxis.js', [_modules['Core/Axis/BrokenAxis.js'], _modules['Core/Axis/GridAxis.js'], _modules['Gantt/Tree.js'], _modules['Core/Axis/TreeGridTick.js'], _modules['Mixins/TreeSeries.js'], _modules['Core/Utilities.js']], function (BrokenAxis, GridAxis, Tree, TreeGridTick, mixinTreeSeries, U) {
  3496. /* *
  3497. *
  3498. * (c) 2016 Highsoft AS
  3499. * Authors: Jon Arild Nygard
  3500. *
  3501. * License: www.highcharts.com/license
  3502. *
  3503. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3504. *
  3505. * */
  3506. var getLevelOptions = mixinTreeSeries.getLevelOptions;
  3507. var addEvent = U.addEvent,
  3508. find = U.find,
  3509. fireEvent = U.fireEvent,
  3510. isArray = U.isArray,
  3511. isObject = U.isObject,
  3512. isString = U.isString,
  3513. merge = U.merge,
  3514. pick = U.pick,
  3515. wrap = U.wrap;
  3516. /**
  3517. * @private
  3518. */
  3519. var TreeGridAxis;
  3520. (function (TreeGridAxis) {
  3521. /* *
  3522. *
  3523. * Declarations
  3524. *
  3525. * */
  3526. /* *
  3527. *
  3528. * Variables
  3529. *
  3530. * */
  3531. var TickConstructor;
  3532. /* *
  3533. *
  3534. * Functions
  3535. *
  3536. * */
  3537. /**
  3538. * @private
  3539. */
  3540. function compose(AxisClass, ChartClass, SeriesClass, TickClass) {
  3541. if (AxisClass.keepProps.indexOf('treeGrid') === -1) {
  3542. AxisClass.keepProps.push('treeGrid');
  3543. TickConstructor = TickClass;
  3544. wrap(AxisClass.prototype, 'generateTick', wrapGenerateTick);
  3545. wrap(AxisClass.prototype, 'init', wrapInit);
  3546. wrap(AxisClass.prototype, 'setTickInterval', wrapSetTickInterval);
  3547. // Make utility functions available for testing.
  3548. AxisClass.prototype.utils = {
  3549. getNode: Tree.getNode
  3550. };
  3551. GridAxis.compose(AxisClass, ChartClass, TickClass);
  3552. BrokenAxis.compose(AxisClass, SeriesClass);
  3553. TreeGridTick.compose(TickClass);
  3554. }
  3555. return AxisClass;
  3556. }
  3557. TreeGridAxis.compose = compose;
  3558. /**
  3559. * @private
  3560. */
  3561. function getBreakFromNode(node, max) {
  3562. var to = node.collapseEnd || 0;
  3563. var from = node.collapseStart || 0;
  3564. // In broken-axis, the axis.max is minimized until it is not within a
  3565. // break. Therefore, if break.to is larger than axis.max, the axis.to
  3566. // should not add the 0.5 axis.tickMarkOffset, to avoid adding a break
  3567. // larger than axis.max.
  3568. // TODO consider simplifying broken-axis and this might solve itself
  3569. if (to >= max) {
  3570. from -= 0.5;
  3571. }
  3572. return {
  3573. from: from,
  3574. to: to,
  3575. showPoints: false
  3576. };
  3577. }
  3578. /**
  3579. * Creates a tree structure of the data, and the treegrid. Calculates
  3580. * categories, and y-values of points based on the tree.
  3581. *
  3582. * @private
  3583. * @function getTreeGridFromData
  3584. *
  3585. * @param {Array<Highcharts.GanttPointOptions>} data
  3586. * All the data points to display in the axis.
  3587. *
  3588. * @param {boolean} uniqueNames
  3589. * Wether or not the data node with the same name should share grid cell. If
  3590. * true they do share cell. False by default.
  3591. *
  3592. * @param {number} numberOfSeries
  3593. *
  3594. * @return {object}
  3595. * Returns an object containing categories, mapOfIdToNode,
  3596. * mapOfPosToGridNode, and tree.
  3597. *
  3598. * @todo There should be only one point per line.
  3599. * @todo It should be optional to have one category per point, or merge
  3600. * cells
  3601. * @todo Add unit-tests.
  3602. */
  3603. function getTreeGridFromData(data, uniqueNames, numberOfSeries) {
  3604. var categories = [],
  3605. collapsedNodes = [],
  3606. mapOfIdToNode = {},
  3607. uniqueNamesEnabled = typeof uniqueNames === 'boolean' ? uniqueNames : false;
  3608. var mapOfPosToGridNode = {},
  3609. posIterator = -1;
  3610. // Build the tree from the series data.
  3611. var treeParams = {
  3612. // After the children has been created.
  3613. after: function (node) {
  3614. var gridNode = mapOfPosToGridNode[node.pos];
  3615. var height = 0,
  3616. descendants = 0;
  3617. gridNode.children.forEach(function (child) {
  3618. descendants += (child.descendants || 0) + 1;
  3619. height = Math.max((child.height || 0) + 1, height);
  3620. });
  3621. gridNode.descendants = descendants;
  3622. gridNode.height = height;
  3623. if (gridNode.collapsed) {
  3624. collapsedNodes.push(gridNode);
  3625. }
  3626. },
  3627. // Before the children has been created.
  3628. before: function (node) {
  3629. var data = isObject(node.data,
  3630. true) ? node.data : {},
  3631. name = isString(data.name) ? data.name : '',
  3632. parentNode = mapOfIdToNode[node.parent],
  3633. parentGridNode = (isObject(parentNode,
  3634. true) ?
  3635. mapOfPosToGridNode[parentNode.pos] :
  3636. null),
  3637. hasSameName = function (x) {
  3638. return x.name === name;
  3639. };
  3640. var gridNode,
  3641. pos;
  3642. // If not unique names, look for sibling node with the same name
  3643. if (uniqueNamesEnabled &&
  3644. isObject(parentGridNode, true) &&
  3645. !!(gridNode = find(parentGridNode.children, hasSameName))) {
  3646. // If there is a gridNode with the same name, reuse position
  3647. pos = gridNode.pos;
  3648. // Add data node to list of nodes in the grid node.
  3649. gridNode.nodes.push(node);
  3650. }
  3651. else {
  3652. // If it is a new grid node, increment position.
  3653. pos = posIterator++;
  3654. }
  3655. // Add new grid node to map.
  3656. if (!mapOfPosToGridNode[pos]) {
  3657. mapOfPosToGridNode[pos] = gridNode = {
  3658. depth: parentGridNode ? parentGridNode.depth + 1 : 0,
  3659. name: name,
  3660. id: data.id,
  3661. nodes: [node],
  3662. children: [],
  3663. pos: pos
  3664. };
  3665. // If not root, then add name to categories.
  3666. if (pos !== -1) {
  3667. categories.push(name);
  3668. }
  3669. // Add name to list of children.
  3670. if (isObject(parentGridNode, true)) {
  3671. parentGridNode.children.push(gridNode);
  3672. }
  3673. }
  3674. // Add data node to map
  3675. if (isString(node.id)) {
  3676. mapOfIdToNode[node.id] = node;
  3677. }
  3678. // If one of the points are collapsed, then start the grid node
  3679. // in collapsed state.
  3680. if (gridNode &&
  3681. data.collapsed === true) {
  3682. gridNode.collapsed = true;
  3683. }
  3684. // Assign pos to data node
  3685. node.pos = pos;
  3686. }
  3687. };
  3688. var updateYValuesAndTickPos = function (map,
  3689. numberOfSeries) {
  3690. var setValues = function (gridNode,
  3691. start,
  3692. result) {
  3693. var nodes = gridNode.nodes,
  3694. padding = 0.5;
  3695. var end = start + (start === -1 ? 0 : numberOfSeries - 1);
  3696. var diff = (end - start) / 2,
  3697. pos = start + diff;
  3698. nodes.forEach(function (node) {
  3699. var data = node.data;
  3700. if (isObject(data, true)) {
  3701. // Update point
  3702. data.y = start + (data.seriesIndex || 0);
  3703. // Remove the property once used
  3704. delete data.seriesIndex;
  3705. }
  3706. node.pos = pos;
  3707. });
  3708. result[pos] = gridNode;
  3709. gridNode.pos = pos;
  3710. gridNode.tickmarkOffset = diff + padding;
  3711. gridNode.collapseStart = end + padding;
  3712. gridNode.children.forEach(function (child) {
  3713. setValues(child, end + 1, result);
  3714. end = (child.collapseEnd || 0) - padding;
  3715. });
  3716. // Set collapseEnd to the end of the last child node.
  3717. gridNode.collapseEnd = end + padding;
  3718. return result;
  3719. };
  3720. return setValues(map['-1'], -1, {});
  3721. };
  3722. // Create tree from data
  3723. var tree = Tree.getTree(data,
  3724. treeParams);
  3725. // Update y values of data, and set calculate tick positions.
  3726. mapOfPosToGridNode = updateYValuesAndTickPos(mapOfPosToGridNode, numberOfSeries);
  3727. // Return the resulting data.
  3728. return {
  3729. categories: categories,
  3730. mapOfIdToNode: mapOfIdToNode,
  3731. mapOfPosToGridNode: mapOfPosToGridNode,
  3732. collapsedNodes: collapsedNodes,
  3733. tree: tree
  3734. };
  3735. }
  3736. /**
  3737. * Builds the tree of categories and calculates its positions.
  3738. * @private
  3739. * @param {object} e Event object
  3740. * @param {object} e.target The chart instance which the event was fired on.
  3741. * @param {object[]} e.target.axes The axes of the chart.
  3742. */
  3743. function onBeforeRender(e) {
  3744. var chart = e.target,
  3745. axes = chart.axes;
  3746. axes.filter(function (axis) {
  3747. return axis.options.type === 'treegrid';
  3748. }).forEach(function (axis) {
  3749. var options = axis.options || {},
  3750. labelOptions = options.labels,
  3751. uniqueNames = options.uniqueNames,
  3752. max = options.max,
  3753. // Check whether any of series is rendering for the first
  3754. // time, visibility has changed, or its data is dirty, and
  3755. // only then update. #10570, #10580
  3756. // Also check if mapOfPosToGridNode exists. #10887
  3757. isDirty = (!axis.treeGrid.mapOfPosToGridNode ||
  3758. axis.series.some(function (series) {
  3759. return !series.hasRendered ||
  3760. series.isDirtyData ||
  3761. series.isDirty;
  3762. }));
  3763. var numberOfSeries = 0,
  3764. data,
  3765. treeGrid;
  3766. if (isDirty) {
  3767. // Concatenate data from all series assigned to this axis.
  3768. data = axis.series.reduce(function (arr, s) {
  3769. if (s.visible) {
  3770. // Push all data to array
  3771. (s.options.data || []).forEach(function (data) {
  3772. // For using keys - rebuild the data structure
  3773. if (s.options.keys && s.options.keys.length) {
  3774. data = s.pointClass.prototype.optionsToObject.call({ series: s }, data);
  3775. s.pointClass.setGanttPointAliases(data);
  3776. }
  3777. if (isObject(data, true)) {
  3778. // Set series index on data. Removed again
  3779. // after use.
  3780. data.seriesIndex = numberOfSeries;
  3781. arr.push(data);
  3782. }
  3783. });
  3784. // Increment series index
  3785. if (uniqueNames === true) {
  3786. numberOfSeries++;
  3787. }
  3788. }
  3789. return arr;
  3790. }, []);
  3791. // If max is higher than set data - add a
  3792. // dummy data to render categories #10779
  3793. if (max && data.length < max) {
  3794. for (var i = data.length; i <= max; i++) {
  3795. data.push({
  3796. // Use the zero-width character
  3797. // to avoid conflict with uniqueNames
  3798. name: i + '\u200B'
  3799. });
  3800. }
  3801. }
  3802. // setScale is fired after all the series is initialized,
  3803. // which is an ideal time to update the axis.categories.
  3804. treeGrid = getTreeGridFromData(data, uniqueNames || false, (uniqueNames === true) ? numberOfSeries : 1);
  3805. // Assign values to the axis.
  3806. axis.categories = treeGrid.categories;
  3807. axis.treeGrid.mapOfPosToGridNode = treeGrid.mapOfPosToGridNode;
  3808. axis.hasNames = true;
  3809. axis.treeGrid.tree = treeGrid.tree;
  3810. // Update yData now that we have calculated the y values
  3811. axis.series.forEach(function (series) {
  3812. var axisData = (series.options.data || []).map(function (d) {
  3813. if (isArray(d) && series.options.keys && series.options.keys.length) {
  3814. // Get the axisData from the data array used to
  3815. // build the treeGrid where has been modified
  3816. data.forEach(function (point) {
  3817. if (d.indexOf(point.x) >= 0 && d.indexOf(point.x2) >= 0) {
  3818. d = point;
  3819. }
  3820. });
  3821. }
  3822. return isObject(d, true) ? merge(d) : d;
  3823. });
  3824. // Avoid destroying points when series is not visible
  3825. if (series.visible) {
  3826. series.setData(axisData, false);
  3827. }
  3828. });
  3829. // Calculate the label options for each level in the tree.
  3830. axis.treeGrid.mapOptionsToLevel =
  3831. getLevelOptions({
  3832. defaults: labelOptions,
  3833. from: 1,
  3834. levels: labelOptions && labelOptions.levels,
  3835. to: axis.treeGrid.tree && axis.treeGrid.tree.height
  3836. });
  3837. // Setting initial collapsed nodes
  3838. if (e.type === 'beforeRender') {
  3839. axis.treeGrid.collapsedNodes = treeGrid.collapsedNodes;
  3840. }
  3841. }
  3842. });
  3843. }
  3844. /**
  3845. * Generates a tick for initial positioning.
  3846. *
  3847. * @private
  3848. * @function Highcharts.GridAxis#generateTick
  3849. *
  3850. * @param {Function} proceed
  3851. * The original generateTick function.
  3852. *
  3853. * @param {number} pos
  3854. * The tick position in axis values.
  3855. */
  3856. function wrapGenerateTick(proceed, pos) {
  3857. var axis = this,
  3858. mapOptionsToLevel = axis.treeGrid.mapOptionsToLevel || {},
  3859. isTreeGrid = axis.options.type === 'treegrid',
  3860. ticks = axis.ticks;
  3861. var tick = ticks[pos],
  3862. levelOptions,
  3863. options,
  3864. gridNode;
  3865. if (isTreeGrid &&
  3866. axis.treeGrid.mapOfPosToGridNode) {
  3867. gridNode = axis.treeGrid.mapOfPosToGridNode[pos];
  3868. levelOptions = mapOptionsToLevel[gridNode.depth];
  3869. if (levelOptions) {
  3870. options = {
  3871. labels: levelOptions
  3872. };
  3873. }
  3874. if (!tick &&
  3875. TickConstructor) {
  3876. ticks[pos] = tick =
  3877. new TickConstructor(axis, pos, void 0, void 0, {
  3878. category: gridNode.name,
  3879. tickmarkOffset: gridNode.tickmarkOffset,
  3880. options: options
  3881. });
  3882. }
  3883. else {
  3884. // update labels depending on tick interval
  3885. tick.parameters.category = gridNode.name;
  3886. tick.options = options;
  3887. tick.addLabel();
  3888. }
  3889. }
  3890. else {
  3891. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  3892. }
  3893. }
  3894. /**
  3895. * @private
  3896. */
  3897. function wrapInit(proceed, chart, userOptions) {
  3898. var axis = this,
  3899. isTreeGrid = userOptions.type === 'treegrid';
  3900. if (!axis.treeGrid) {
  3901. axis.treeGrid = new Additions(axis);
  3902. }
  3903. // Set default and forced options for TreeGrid
  3904. if (isTreeGrid) {
  3905. // Add event for updating the categories of a treegrid.
  3906. // NOTE Preferably these events should be set on the axis.
  3907. addEvent(chart, 'beforeRender', onBeforeRender);
  3908. addEvent(chart, 'beforeRedraw', onBeforeRender);
  3909. // Add new collapsed nodes on addseries
  3910. addEvent(chart, 'addSeries', function (e) {
  3911. if (e.options.data) {
  3912. var treeGrid = getTreeGridFromData(e.options.data,
  3913. userOptions.uniqueNames || false, 1);
  3914. axis.treeGrid.collapsedNodes = (axis.treeGrid.collapsedNodes || []).concat(treeGrid.collapsedNodes);
  3915. }
  3916. });
  3917. // Collapse all nodes in axis.treegrid.collapsednodes
  3918. // where collapsed equals true.
  3919. addEvent(axis, 'foundExtremes', function () {
  3920. if (axis.treeGrid.collapsedNodes) {
  3921. axis.treeGrid.collapsedNodes.forEach(function (node) {
  3922. var breaks = axis.treeGrid.collapse(node);
  3923. if (axis.brokenAxis) {
  3924. axis.brokenAxis.setBreaks(breaks, false);
  3925. // remove the node from the axis collapsedNodes
  3926. if (axis.treeGrid.collapsedNodes) {
  3927. axis.treeGrid.collapsedNodes = axis.treeGrid.collapsedNodes.filter(function (n) {
  3928. return node.collapseStart !== n.collapseStart ||
  3929. node.collapseEnd !== n.collapseEnd;
  3930. });
  3931. }
  3932. }
  3933. });
  3934. }
  3935. });
  3936. // If staticScale is not defined on the yAxis
  3937. // and chart height is set, set axis.isDirty
  3938. // to ensure collapsing works (#12012)
  3939. addEvent(axis, 'afterBreaks', function () {
  3940. if (axis.coll === 'yAxis' &&
  3941. !axis.staticScale &&
  3942. axis.chart.options.chart.height) {
  3943. axis.isDirty = true;
  3944. }
  3945. });
  3946. userOptions = merge({
  3947. // Default options
  3948. grid: {
  3949. enabled: true
  3950. },
  3951. // TODO: add support for align in treegrid.
  3952. labels: {
  3953. align: 'left',
  3954. /**
  3955. * Set options on specific levels in a tree grid axis. Takes
  3956. * precedence over labels options.
  3957. *
  3958. * @sample {gantt} gantt/treegrid-axis/labels-levels
  3959. * Levels on TreeGrid Labels
  3960. *
  3961. * @type {Array<*>}
  3962. * @product gantt
  3963. * @apioption yAxis.labels.levels
  3964. *
  3965. * @private
  3966. */
  3967. levels: [{
  3968. /**
  3969. * Specify the level which the options within this object
  3970. * applies to.
  3971. *
  3972. * @type {number}
  3973. * @product gantt
  3974. * @apioption yAxis.labels.levels.level
  3975. *
  3976. * @private
  3977. */
  3978. level: void 0
  3979. }, {
  3980. level: 1,
  3981. /**
  3982. * @type {Highcharts.CSSObject}
  3983. * @product gantt
  3984. * @apioption yAxis.labels.levels.style
  3985. *
  3986. * @private
  3987. */
  3988. style: {
  3989. /** @ignore-option */
  3990. fontWeight: 'bold'
  3991. }
  3992. }],
  3993. /**
  3994. * The symbol for the collapse and expand icon in a
  3995. * treegrid.
  3996. *
  3997. * @product gantt
  3998. * @optionparent yAxis.labels.symbol
  3999. *
  4000. * @private
  4001. */
  4002. symbol: {
  4003. /**
  4004. * The symbol type. Points to a definition function in
  4005. * the `Highcharts.Renderer.symbols` collection.
  4006. *
  4007. * @type {Highcharts.SymbolKeyValue}
  4008. *
  4009. * @private
  4010. */
  4011. type: 'triangle',
  4012. x: -5,
  4013. y: -5,
  4014. height: 10,
  4015. width: 10,
  4016. padding: 5
  4017. }
  4018. },
  4019. uniqueNames: false
  4020. }, userOptions, {
  4021. // Forced options
  4022. reversed: true,
  4023. // grid.columns is not supported in treegrid
  4024. grid: {
  4025. columns: void 0
  4026. }
  4027. });
  4028. }
  4029. // Now apply the original function with the original arguments,
  4030. // which are sliced off this function's arguments
  4031. proceed.apply(axis, [chart, userOptions]);
  4032. if (isTreeGrid) {
  4033. axis.hasNames = true;
  4034. axis.options.showLastLabel = true;
  4035. }
  4036. }
  4037. /**
  4038. * Set the tick positions, tickInterval, axis min and max.
  4039. *
  4040. * @private
  4041. * @function Highcharts.GridAxis#setTickInterval
  4042. *
  4043. * @param {Function} proceed
  4044. * The original setTickInterval function.
  4045. */
  4046. function wrapSetTickInterval(proceed) {
  4047. var axis = this,
  4048. options = axis.options,
  4049. isTreeGrid = options.type === 'treegrid';
  4050. if (isTreeGrid) {
  4051. axis.min = pick(axis.userMin, options.min, axis.dataMin);
  4052. axis.max = pick(axis.userMax, options.max, axis.dataMax);
  4053. fireEvent(axis, 'foundExtremes');
  4054. // setAxisTranslation modifies the min and max according to
  4055. // axis breaks.
  4056. axis.setAxisTranslation();
  4057. axis.tickmarkOffset = 0.5;
  4058. axis.tickInterval = 1;
  4059. axis.tickPositions = axis.treeGrid.mapOfPosToGridNode ?
  4060. axis.treeGrid.getTickPositions() :
  4061. [];
  4062. }
  4063. else {
  4064. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  4065. }
  4066. }
  4067. /* *
  4068. *
  4069. * Classes
  4070. *
  4071. * */
  4072. /**
  4073. * @private
  4074. * @class
  4075. */
  4076. var Additions = /** @class */ (function () {
  4077. /* *
  4078. *
  4079. * Constructors
  4080. *
  4081. * */
  4082. /**
  4083. * @private
  4084. */
  4085. function Additions(axis) {
  4086. this.axis = axis;
  4087. }
  4088. /* *
  4089. *
  4090. * Functions
  4091. *
  4092. * */
  4093. /**
  4094. * Set the collapse status.
  4095. *
  4096. * @private
  4097. *
  4098. * @param {Highcharts.Axis} axis
  4099. * The axis to check against.
  4100. *
  4101. * @param {Highcharts.GridNode} node
  4102. * The node to collapse.
  4103. */
  4104. Additions.prototype.setCollapsedStatus = function (node) {
  4105. var axis = this.axis,
  4106. chart = axis.chart;
  4107. axis.series.forEach(function (series) {
  4108. var data = series.options.data;
  4109. if (node.id && data) {
  4110. var point = chart.get(node.id),
  4111. dataPoint = data[series.data.indexOf(point)];
  4112. if (point && dataPoint) {
  4113. point.collapsed = node.collapsed;
  4114. dataPoint.collapsed = node.collapsed;
  4115. }
  4116. }
  4117. });
  4118. };
  4119. /**
  4120. * Calculates the new axis breaks to collapse a node.
  4121. *
  4122. * @private
  4123. *
  4124. * @param {Highcharts.Axis} axis
  4125. * The axis to check against.
  4126. *
  4127. * @param {Highcharts.GridNode} node
  4128. * The node to collapse.
  4129. *
  4130. * @param {number} pos
  4131. * The tick position to collapse.
  4132. *
  4133. * @return {Array<object>}
  4134. * Returns an array of the new breaks for the axis.
  4135. */
  4136. Additions.prototype.collapse = function (node) {
  4137. var axis = this.axis,
  4138. breaks = (axis.options.breaks || []),
  4139. obj = getBreakFromNode(node,
  4140. axis.max);
  4141. breaks.push(obj);
  4142. // Change the collapsed flag #13838
  4143. node.collapsed = true;
  4144. axis.treeGrid.setCollapsedStatus(node);
  4145. return breaks;
  4146. };
  4147. /**
  4148. * Calculates the new axis breaks to expand a node.
  4149. *
  4150. * @private
  4151. *
  4152. * @param {Highcharts.Axis} axis
  4153. * The axis to check against.
  4154. *
  4155. * @param {Highcharts.GridNode} node
  4156. * The node to expand.
  4157. *
  4158. * @param {number} pos
  4159. * The tick position to expand.
  4160. *
  4161. * @return {Array<object>}
  4162. * Returns an array of the new breaks for the axis.
  4163. */
  4164. Additions.prototype.expand = function (node) {
  4165. var axis = this.axis,
  4166. breaks = (axis.options.breaks || []),
  4167. obj = getBreakFromNode(node,
  4168. axis.max);
  4169. // Change the collapsed flag #13838
  4170. node.collapsed = false;
  4171. axis.treeGrid.setCollapsedStatus(node);
  4172. // Remove the break from the axis breaks array.
  4173. return breaks.reduce(function (arr, b) {
  4174. if (b.to !== obj.to || b.from !== obj.from) {
  4175. arr.push(b);
  4176. }
  4177. return arr;
  4178. }, []);
  4179. };
  4180. /**
  4181. * Creates a list of positions for the ticks on the axis. Filters out
  4182. * positions that are outside min and max, or is inside an axis break.
  4183. *
  4184. * @private
  4185. *
  4186. * @return {Array<number>}
  4187. * List of positions.
  4188. */
  4189. Additions.prototype.getTickPositions = function () {
  4190. var axis = this.axis,
  4191. roundedMin = Math.floor(axis.min / axis.tickInterval) * axis.tickInterval,
  4192. roundedMax = Math.ceil(axis.max / axis.tickInterval) * axis.tickInterval;
  4193. return Object.keys(axis.treeGrid.mapOfPosToGridNode || {}).reduce(function (arr, key) {
  4194. var pos = +key;
  4195. if (pos >= roundedMin &&
  4196. pos <= roundedMax &&
  4197. !(axis.brokenAxis && axis.brokenAxis.isInAnyBreak(pos))) {
  4198. arr.push(pos);
  4199. }
  4200. return arr;
  4201. }, []);
  4202. };
  4203. /**
  4204. * Check if a node is collapsed.
  4205. *
  4206. * @private
  4207. *
  4208. * @param {Highcharts.Axis} axis
  4209. * The axis to check against.
  4210. *
  4211. * @param {object} node
  4212. * The node to check if is collapsed.
  4213. *
  4214. * @param {number} pos
  4215. * The tick position to collapse.
  4216. *
  4217. * @return {boolean}
  4218. * Returns true if collapsed, false if expanded.
  4219. */
  4220. Additions.prototype.isCollapsed = function (node) {
  4221. var axis = this.axis,
  4222. breaks = (axis.options.breaks || []),
  4223. obj = getBreakFromNode(node,
  4224. axis.max);
  4225. return breaks.some(function (b) {
  4226. return b.from === obj.from && b.to === obj.to;
  4227. });
  4228. };
  4229. /**
  4230. * Calculates the new axis breaks after toggling the collapse/expand
  4231. * state of a node. If it is collapsed it will be expanded, and if it is
  4232. * exapended it will be collapsed.
  4233. *
  4234. * @private
  4235. *
  4236. * @param {Highcharts.Axis} axis
  4237. * The axis to check against.
  4238. *
  4239. * @param {Highcharts.GridNode} node
  4240. * The node to toggle.
  4241. *
  4242. * @return {Array<object>}
  4243. * Returns an array of the new breaks for the axis.
  4244. */
  4245. Additions.prototype.toggleCollapse = function (node) {
  4246. return (this.isCollapsed(node) ?
  4247. this.expand(node) :
  4248. this.collapse(node));
  4249. };
  4250. return Additions;
  4251. }());
  4252. TreeGridAxis.Additions = Additions;
  4253. })(TreeGridAxis || (TreeGridAxis = {}));
  4254. return TreeGridAxis;
  4255. });
  4256. _registerModule(_modules, 'Extensions/CurrentDateIndication.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Color/Palette.js'], _modules['Core/Axis/PlotLineOrBand.js'], _modules['Core/Utilities.js']], function (Axis, Palette, PlotLineOrBand, U) {
  4257. /* *
  4258. *
  4259. * (c) 2016-2021 Highsoft AS
  4260. *
  4261. * Author: Lars A. V. Cabrera
  4262. *
  4263. * License: www.highcharts.com/license
  4264. *
  4265. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4266. *
  4267. * */
  4268. var addEvent = U.addEvent,
  4269. merge = U.merge,
  4270. wrap = U.wrap;
  4271. /**
  4272. * Show an indicator on the axis for the current date and time. Can be a
  4273. * boolean or a configuration object similar to
  4274. * [xAxis.plotLines](#xAxis.plotLines).
  4275. *
  4276. * @sample gantt/current-date-indicator/demo
  4277. * Current date indicator enabled
  4278. * @sample gantt/current-date-indicator/object-config
  4279. * Current date indicator with custom options
  4280. *
  4281. * @declare Highcharts.CurrentDateIndicatorOptions
  4282. * @type {boolean|CurrentDateIndicatorOptions}
  4283. * @default true
  4284. * @extends xAxis.plotLines
  4285. * @excluding value
  4286. * @product gantt
  4287. * @apioption xAxis.currentDateIndicator
  4288. */
  4289. var defaultOptions = {
  4290. color: Palette.highlightColor20,
  4291. width: 2,
  4292. /**
  4293. * @declare Highcharts.AxisCurrentDateIndicatorLabelOptions
  4294. */
  4295. label: {
  4296. /**
  4297. * Format of the label. This options is passed as the fist argument to
  4298. * [dateFormat](/class-reference/Highcharts#.dateFormat) function.
  4299. *
  4300. * @type {string}
  4301. * @default %a, %b %d %Y, %H:%M
  4302. * @product gantt
  4303. * @apioption xAxis.currentDateIndicator.label.format
  4304. */
  4305. format: '%a, %b %d %Y, %H:%M',
  4306. formatter: function (value, format) {
  4307. return this.axis.chart.time.dateFormat(format || '', value);
  4308. },
  4309. rotation: 0,
  4310. /**
  4311. * @type {Highcharts.CSSObject}
  4312. */
  4313. style: {
  4314. /** @internal */
  4315. fontSize: '10px'
  4316. }
  4317. }
  4318. };
  4319. /* eslint-disable no-invalid-this */
  4320. addEvent(Axis, 'afterSetOptions', function () {
  4321. var options = this.options,
  4322. cdiOptions = options.currentDateIndicator;
  4323. if (cdiOptions) {
  4324. var plotLineOptions = typeof cdiOptions === 'object' ?
  4325. merge(defaultOptions,
  4326. cdiOptions) :
  4327. merge(defaultOptions);
  4328. plotLineOptions.value = Date.now();
  4329. plotLineOptions.className = 'highcharts-current-date-indicator';
  4330. if (!options.plotLines) {
  4331. options.plotLines = [];
  4332. }
  4333. options.plotLines.push(plotLineOptions);
  4334. }
  4335. });
  4336. addEvent(PlotLineOrBand, 'render', function () {
  4337. // If the label already exists, update its text
  4338. if (this.label) {
  4339. this.label.attr({
  4340. text: this.getLabelText(this.options.label)
  4341. });
  4342. }
  4343. });
  4344. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  4345. var options = this.options;
  4346. if (options &&
  4347. options.className &&
  4348. options.className.indexOf('highcharts-current-date-indicator') !== -1 &&
  4349. options.label &&
  4350. typeof options.label.formatter === 'function') {
  4351. options.value = Date.now();
  4352. return options.label.formatter
  4353. .call(this, options.value, options.label.format);
  4354. }
  4355. return defaultMethod.call(this, defaultLabelOptions);
  4356. });
  4357. });
  4358. _registerModule(_modules, 'Extensions/StaticScale.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Utilities.js']], function (Axis, Chart, U) {
  4359. /* *
  4360. *
  4361. * (c) 2016-2021 Torstein Honsi, Lars Cabrera
  4362. *
  4363. * License: www.highcharts.com/license
  4364. *
  4365. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4366. *
  4367. * */
  4368. var addEvent = U.addEvent,
  4369. defined = U.defined,
  4370. isNumber = U.isNumber,
  4371. pick = U.pick;
  4372. /* eslint-disable no-invalid-this */
  4373. /**
  4374. * For vertical axes only. Setting the static scale ensures that each tick unit
  4375. * is translated into a fixed pixel height. For example, setting the static
  4376. * scale to 24 results in each Y axis category taking up 24 pixels, and the
  4377. * height of the chart adjusts. Adding or removing items will make the chart
  4378. * resize.
  4379. *
  4380. * @sample gantt/xrange-series/demo/
  4381. * X-range series with static scale
  4382. *
  4383. * @type {number}
  4384. * @default 50
  4385. * @since 6.2.0
  4386. * @product gantt
  4387. * @apioption yAxis.staticScale
  4388. */
  4389. addEvent(Axis, 'afterSetOptions', function () {
  4390. var chartOptions = this.chart.options.chart;
  4391. if (!this.horiz &&
  4392. isNumber(this.options.staticScale) &&
  4393. (!chartOptions.height ||
  4394. (chartOptions.scrollablePlotArea &&
  4395. chartOptions.scrollablePlotArea.minHeight))) {
  4396. this.staticScale = this.options.staticScale;
  4397. }
  4398. });
  4399. Chart.prototype.adjustHeight = function () {
  4400. if (this.redrawTrigger !== 'adjustHeight') {
  4401. (this.axes || []).forEach(function (axis) {
  4402. var chart = axis.chart,
  4403. animate = !!chart.initiatedScale &&
  4404. chart.options.animation,
  4405. staticScale = axis.options.staticScale,
  4406. height,
  4407. diff;
  4408. if (axis.staticScale && defined(axis.min)) {
  4409. height = pick(axis.brokenAxis && axis.brokenAxis.unitLength, axis.max + axis.tickInterval - axis.min) * staticScale;
  4410. // Minimum height is 1 x staticScale.
  4411. height = Math.max(height, staticScale);
  4412. diff = height - chart.plotHeight;
  4413. if (!chart.scrollablePixelsY && Math.abs(diff) >= 1) {
  4414. chart.plotHeight = height;
  4415. chart.redrawTrigger = 'adjustHeight';
  4416. chart.setSize(void 0, chart.chartHeight + diff, animate);
  4417. }
  4418. // Make sure clip rects have the right height before initial
  4419. // animation.
  4420. axis.series.forEach(function (series) {
  4421. var clipRect = series.sharedClipKey &&
  4422. chart.sharedClips[series.sharedClipKey];
  4423. if (clipRect) {
  4424. clipRect.attr(chart.inverted ? {
  4425. width: chart.plotHeight
  4426. } : {
  4427. height: chart.plotHeight
  4428. });
  4429. }
  4430. });
  4431. }
  4432. });
  4433. this.initiatedScale = true;
  4434. }
  4435. this.redrawTrigger = null;
  4436. };
  4437. addEvent(Chart, 'render', Chart.prototype.adjustHeight);
  4438. });
  4439. _registerModule(_modules, 'Extensions/ArrowSymbols.js', [_modules['Core/Renderer/SVG/SVGRenderer.js']], function (SVGRenderer) {
  4440. /* *
  4441. *
  4442. * (c) 2017 Highsoft AS
  4443. * Authors: Lars A. V. Cabrera
  4444. *
  4445. * License: www.highcharts.com/license
  4446. *
  4447. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4448. *
  4449. * */
  4450. var symbols = SVGRenderer.prototype.symbols;
  4451. /* *
  4452. *
  4453. * Functions
  4454. *
  4455. * */
  4456. /**
  4457. * Creates an arrow symbol. Like a triangle, except not filled.
  4458. * ```
  4459. * o
  4460. * o
  4461. * o
  4462. * o
  4463. * o
  4464. * o
  4465. * o
  4466. * ```
  4467. *
  4468. * @private
  4469. * @function
  4470. *
  4471. * @param {number} x
  4472. * x position of the arrow
  4473. *
  4474. * @param {number} y
  4475. * y position of the arrow
  4476. *
  4477. * @param {number} w
  4478. * width of the arrow
  4479. *
  4480. * @param {number} h
  4481. * height of the arrow
  4482. *
  4483. * @return {Highcharts.SVGPathArray}
  4484. * Path array
  4485. */
  4486. function arrow(x, y, w, h) {
  4487. return [
  4488. ['M', x, y + h / 2],
  4489. ['L', x + w, y],
  4490. ['L', x, y + h / 2],
  4491. ['L', x + w, y + h]
  4492. ];
  4493. }
  4494. /**
  4495. * Creates a half-width arrow symbol. Like a triangle, except not filled.
  4496. * ```
  4497. * o
  4498. * o
  4499. * o
  4500. * o
  4501. * o
  4502. * ```
  4503. *
  4504. * @private
  4505. * @function
  4506. *
  4507. * @param {number} x
  4508. * x position of the arrow
  4509. *
  4510. * @param {number} y
  4511. * y position of the arrow
  4512. *
  4513. * @param {number} w
  4514. * width of the arrow
  4515. *
  4516. * @param {number} h
  4517. * height of the arrow
  4518. *
  4519. * @return {Highcharts.SVGPathArray}
  4520. * Path array
  4521. */
  4522. function arrowHalf(x, y, w, h) {
  4523. return arrow(x, y, w / 2, h);
  4524. }
  4525. /**
  4526. * Creates a left-oriented triangle.
  4527. * ```
  4528. * o
  4529. * ooooooo
  4530. * ooooooooooooo
  4531. * ooooooo
  4532. * o
  4533. * ```
  4534. *
  4535. * @private
  4536. * @function
  4537. *
  4538. * @param {number} x
  4539. * x position of the triangle
  4540. *
  4541. * @param {number} y
  4542. * y position of the triangle
  4543. *
  4544. * @param {number} w
  4545. * width of the triangle
  4546. *
  4547. * @param {number} h
  4548. * height of the triangle
  4549. *
  4550. * @return {Highcharts.SVGPathArray}
  4551. * Path array
  4552. */
  4553. function triangleLeft(x, y, w, h) {
  4554. return [
  4555. ['M', x + w, y],
  4556. ['L', x, y + h / 2],
  4557. ['L', x + w, y + h],
  4558. ['Z']
  4559. ];
  4560. }
  4561. /**
  4562. * Creates a half-width, left-oriented triangle.
  4563. * ```
  4564. * o
  4565. * oooo
  4566. * ooooooo
  4567. * oooo
  4568. * o
  4569. * ```
  4570. *
  4571. * @private
  4572. * @function
  4573. *
  4574. * @param {number} x
  4575. * x position of the triangle
  4576. *
  4577. * @param {number} y
  4578. * y position of the triangle
  4579. *
  4580. * @param {number} w
  4581. * width of the triangle
  4582. *
  4583. * @param {number} h
  4584. * height of the triangle
  4585. *
  4586. * @return {Highcharts.SVGPathArray}
  4587. * Path array
  4588. */
  4589. function triangleLeftHalf(x, y, w, h) {
  4590. return triangleLeft(x, y, w / 2, h);
  4591. }
  4592. symbols.arrow = arrow;
  4593. symbols['arrow-filled'] = triangleLeft;
  4594. symbols['arrow-filled-half'] = triangleLeftHalf;
  4595. symbols['arrow-half'] = arrowHalf;
  4596. symbols['triangle-left'] = triangleLeft;
  4597. symbols['triangle-left-half'] = triangleLeftHalf;
  4598. /* *
  4599. *
  4600. * Default Export
  4601. *
  4602. * */
  4603. return symbols;
  4604. });
  4605. _registerModule(_modules, 'Gantt/Connection.js', [_modules['Core/Globals.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (H, D, Point, U) {
  4606. /* *
  4607. *
  4608. * (c) 2016 Highsoft AS
  4609. * Authors: Øystein Moseng, Lars A. V. Cabrera
  4610. *
  4611. * License: www.highcharts.com/license
  4612. *
  4613. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4614. *
  4615. * */
  4616. /**
  4617. * The default pathfinder algorithm to use for a chart. It is possible to define
  4618. * your own algorithms by adding them to the
  4619. * `Highcharts.Pathfinder.prototype.algorithms`
  4620. * object before the chart has been created.
  4621. *
  4622. * The default algorithms are as follows:
  4623. *
  4624. * `straight`: Draws a straight line between the connecting
  4625. * points. Does not avoid other points when drawing.
  4626. *
  4627. * `simpleConnect`: Finds a path between the points using right angles
  4628. * only. Takes only starting/ending points into
  4629. * account, and will not avoid other points.
  4630. *
  4631. * `fastAvoid`: Finds a path between the points using right angles
  4632. * only. Will attempt to avoid other points, but its
  4633. * focus is performance over accuracy. Works well with
  4634. * less dense datasets.
  4635. *
  4636. * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
  4637. */
  4638. ''; // detach doclets above
  4639. var defaultOptions = D.defaultOptions;
  4640. var addEvent = U.addEvent,
  4641. defined = U.defined,
  4642. error = U.error,
  4643. extend = U.extend,
  4644. merge = U.merge,
  4645. objectEach = U.objectEach,
  4646. pick = U.pick,
  4647. splat = U.splat;
  4648. var deg2rad = H.deg2rad,
  4649. max = Math.max,
  4650. min = Math.min;
  4651. /*
  4652. @todo:
  4653. - Document how to write your own algorithms
  4654. - Consider adding a Point.pathTo method that wraps creating a connection
  4655. and rendering it
  4656. */
  4657. // Set default Pathfinder options
  4658. extend(defaultOptions, {
  4659. /**
  4660. * The Pathfinder module allows you to define connections between any two
  4661. * points, represented as lines - optionally with markers for the start
  4662. * and/or end points. Multiple algorithms are available for calculating how
  4663. * the connecting lines are drawn.
  4664. *
  4665. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  4666. * charts, the connectors are used to draw dependencies between tasks.
  4667. *
  4668. * @see [dependency](series.gantt.data.dependency)
  4669. *
  4670. * @sample gantt/pathfinder/demo
  4671. * Pathfinder connections
  4672. *
  4673. * @declare Highcharts.ConnectorsOptions
  4674. * @product gantt
  4675. * @optionparent connectors
  4676. */
  4677. connectors: {
  4678. /**
  4679. * Enable connectors for this chart. Requires Highcharts Gantt.
  4680. *
  4681. * @type {boolean}
  4682. * @default true
  4683. * @since 6.2.0
  4684. * @apioption connectors.enabled
  4685. */
  4686. /**
  4687. * Set the default dash style for this chart's connecting lines.
  4688. *
  4689. * @type {string}
  4690. * @default solid
  4691. * @since 6.2.0
  4692. * @apioption connectors.dashStyle
  4693. */
  4694. /**
  4695. * Set the default color for this chart's Pathfinder connecting lines.
  4696. * Defaults to the color of the point being connected.
  4697. *
  4698. * @type {Highcharts.ColorString}
  4699. * @since 6.2.0
  4700. * @apioption connectors.lineColor
  4701. */
  4702. /**
  4703. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  4704. * algorithms attempt to avoid obstacles, such as other points in the
  4705. * chart. These algorithms use this margin to determine how close lines
  4706. * can be to an obstacle. The default is to compute this automatically
  4707. * from the size of the obstacles in the chart.
  4708. *
  4709. * To draw connecting lines close to existing points, set this to a low
  4710. * number. For more space around existing points, set this number
  4711. * higher.
  4712. *
  4713. * @sample gantt/pathfinder/algorithm-margin
  4714. * Small algorithmMargin
  4715. *
  4716. * @type {number}
  4717. * @since 6.2.0
  4718. * @apioption connectors.algorithmMargin
  4719. */
  4720. /**
  4721. * Set the default pathfinder algorithm to use for this chart. It is
  4722. * possible to define your own algorithms by adding them to the
  4723. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  4724. * has been created.
  4725. *
  4726. * The default algorithms are as follows:
  4727. *
  4728. * `straight`: Draws a straight line between the connecting
  4729. * points. Does not avoid other points when drawing.
  4730. *
  4731. * `simpleConnect`: Finds a path between the points using right angles
  4732. * only. Takes only starting/ending points into
  4733. * account, and will not avoid other points.
  4734. *
  4735. * `fastAvoid`: Finds a path between the points using right angles
  4736. * only. Will attempt to avoid other points, but its
  4737. * focus is performance over accuracy. Works well with
  4738. * less dense datasets.
  4739. *
  4740. * Default value: `straight` is used as default for most series types,
  4741. * while `simpleConnect` is used as default for Gantt series, to show
  4742. * dependencies between points.
  4743. *
  4744. * @sample gantt/pathfinder/demo
  4745. * Different types used
  4746. *
  4747. * @type {Highcharts.PathfinderTypeValue}
  4748. * @default undefined
  4749. * @since 6.2.0
  4750. */
  4751. type: 'straight',
  4752. /**
  4753. * Set the default pixel width for this chart's Pathfinder connecting
  4754. * lines.
  4755. *
  4756. * @since 6.2.0
  4757. */
  4758. lineWidth: 1,
  4759. /**
  4760. * Marker options for this chart's Pathfinder connectors. Note that
  4761. * this option is overridden by the `startMarker` and `endMarker`
  4762. * options.
  4763. *
  4764. * @declare Highcharts.ConnectorsMarkerOptions
  4765. * @since 6.2.0
  4766. */
  4767. marker: {
  4768. /**
  4769. * Set the radius of the connector markers. The default is
  4770. * automatically computed based on the algorithmMargin setting.
  4771. *
  4772. * Setting marker.width and marker.height will override this
  4773. * setting.
  4774. *
  4775. * @type {number}
  4776. * @since 6.2.0
  4777. * @apioption connectors.marker.radius
  4778. */
  4779. /**
  4780. * Set the width of the connector markers. If not supplied, this
  4781. * is inferred from the marker radius.
  4782. *
  4783. * @type {number}
  4784. * @since 6.2.0
  4785. * @apioption connectors.marker.width
  4786. */
  4787. /**
  4788. * Set the height of the connector markers. If not supplied, this
  4789. * is inferred from the marker radius.
  4790. *
  4791. * @type {number}
  4792. * @since 6.2.0
  4793. * @apioption connectors.marker.height
  4794. */
  4795. /**
  4796. * Set the color of the connector markers. By default this is the
  4797. * same as the connector color.
  4798. *
  4799. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  4800. * @since 6.2.0
  4801. * @apioption connectors.marker.color
  4802. */
  4803. /**
  4804. * Set the line/border color of the connector markers. By default
  4805. * this is the same as the marker color.
  4806. *
  4807. * @type {Highcharts.ColorString}
  4808. * @since 6.2.0
  4809. * @apioption connectors.marker.lineColor
  4810. */
  4811. /**
  4812. * Enable markers for the connectors.
  4813. */
  4814. enabled: false,
  4815. /**
  4816. * Horizontal alignment of the markers relative to the points.
  4817. *
  4818. * @type {Highcharts.AlignValue}
  4819. */
  4820. align: 'center',
  4821. /**
  4822. * Vertical alignment of the markers relative to the points.
  4823. *
  4824. * @type {Highcharts.VerticalAlignValue}
  4825. */
  4826. verticalAlign: 'middle',
  4827. /**
  4828. * Whether or not to draw the markers inside the points.
  4829. */
  4830. inside: false,
  4831. /**
  4832. * Set the line/border width of the pathfinder markers.
  4833. */
  4834. lineWidth: 1
  4835. },
  4836. /**
  4837. * Marker options specific to the start markers for this chart's
  4838. * Pathfinder connectors. Overrides the generic marker options.
  4839. *
  4840. * @declare Highcharts.ConnectorsStartMarkerOptions
  4841. * @extends connectors.marker
  4842. * @since 6.2.0
  4843. */
  4844. startMarker: {
  4845. /**
  4846. * Set the symbol of the connector start markers.
  4847. */
  4848. symbol: 'diamond'
  4849. },
  4850. /**
  4851. * Marker options specific to the end markers for this chart's
  4852. * Pathfinder connectors. Overrides the generic marker options.
  4853. *
  4854. * @declare Highcharts.ConnectorsEndMarkerOptions
  4855. * @extends connectors.marker
  4856. * @since 6.2.0
  4857. */
  4858. endMarker: {
  4859. /**
  4860. * Set the symbol of the connector end markers.
  4861. */
  4862. symbol: 'arrow-filled'
  4863. }
  4864. }
  4865. });
  4866. /**
  4867. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  4868. * to be loaded.
  4869. *
  4870. * @declare Highcharts.SeriesConnectorsOptionsObject
  4871. * @extends connectors
  4872. * @since 6.2.0
  4873. * @excluding enabled, algorithmMargin
  4874. * @product gantt
  4875. * @apioption plotOptions.series.connectors
  4876. */
  4877. /**
  4878. * Connect to a point. This option can be either a string, referring to the ID
  4879. * of another point, or an object, or an array of either. If the option is an
  4880. * array, each element defines a connection.
  4881. *
  4882. * @sample gantt/pathfinder/demo
  4883. * Different connection types
  4884. *
  4885. * @declare Highcharts.XrangePointConnectorsOptionsObject
  4886. * @type {string|Array<string|*>|*}
  4887. * @extends plotOptions.series.connectors
  4888. * @since 6.2.0
  4889. * @excluding enabled
  4890. * @product gantt
  4891. * @requires highcharts-gantt
  4892. * @apioption series.xrange.data.connect
  4893. */
  4894. /**
  4895. * The ID of the point to connect to.
  4896. *
  4897. * @type {string}
  4898. * @since 6.2.0
  4899. * @product gantt
  4900. * @apioption series.xrange.data.connect.to
  4901. */
  4902. /**
  4903. * Get point bounding box using plotX/plotY and shapeArgs. If using
  4904. * graphic.getBBox() directly, the bbox will be affected by animation.
  4905. *
  4906. * @private
  4907. * @function
  4908. *
  4909. * @param {Highcharts.Point} point
  4910. * The point to get BB of.
  4911. *
  4912. * @return {Highcharts.Dictionary<number>|null}
  4913. * Result xMax, xMin, yMax, yMin.
  4914. */
  4915. function getPointBB(point) {
  4916. var shapeArgs = point.shapeArgs,
  4917. bb;
  4918. // Prefer using shapeArgs (columns)
  4919. if (shapeArgs) {
  4920. return {
  4921. xMin: shapeArgs.x || 0,
  4922. xMax: (shapeArgs.x || 0) + (shapeArgs.width || 0),
  4923. yMin: shapeArgs.y || 0,
  4924. yMax: (shapeArgs.y || 0) + (shapeArgs.height || 0)
  4925. };
  4926. }
  4927. // Otherwise use plotX/plotY and bb
  4928. bb = point.graphic && point.graphic.getBBox();
  4929. return bb ? {
  4930. xMin: point.plotX - bb.width / 2,
  4931. xMax: point.plotX + bb.width / 2,
  4932. yMin: point.plotY - bb.height / 2,
  4933. yMax: point.plotY + bb.height / 2
  4934. } : null;
  4935. }
  4936. /**
  4937. * Calculate margin to place around obstacles for the pathfinder in pixels.
  4938. * Returns a minimum of 1 pixel margin.
  4939. *
  4940. * @private
  4941. * @function
  4942. *
  4943. * @param {Array<object>} obstacles
  4944. * Obstacles to calculate margin from.
  4945. *
  4946. * @return {number}
  4947. * The calculated margin in pixels. At least 1.
  4948. */
  4949. function calculateObstacleMargin(obstacles) {
  4950. var len = obstacles.length,
  4951. i = 0,
  4952. j,
  4953. obstacleDistance,
  4954. distances = [],
  4955. // Compute smallest distance between two rectangles
  4956. distance = function (a,
  4957. b,
  4958. bbMargin) {
  4959. // Count the distance even if we are slightly off
  4960. var margin = pick(bbMargin, 10),
  4961. yOverlap = a.yMax + margin > b.yMin - margin &&
  4962. a.yMin - margin < b.yMax + margin,
  4963. xOverlap = a.xMax + margin > b.xMin - margin &&
  4964. a.xMin - margin < b.xMax + margin,
  4965. xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
  4966. yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
  4967. // If the rectangles collide, try recomputing with smaller margin.
  4968. // If they collide anyway, discard the obstacle.
  4969. if (xOverlap && yOverlap) {
  4970. return (margin ?
  4971. distance(a, b, Math.floor(margin / 2)) :
  4972. Infinity);
  4973. }
  4974. return min(xDistance, yDistance);
  4975. };
  4976. // Go over all obstacles and compare them to the others.
  4977. for (; i < len; ++i) {
  4978. // Compare to all obstacles ahead. We will already have compared this
  4979. // obstacle to the ones before.
  4980. for (j = i + 1; j < len; ++j) {
  4981. obstacleDistance = distance(obstacles[i], obstacles[j]);
  4982. // TODO: Magic number 80
  4983. if (obstacleDistance < 80) { // Ignore large distances
  4984. distances.push(obstacleDistance);
  4985. }
  4986. }
  4987. }
  4988. // Ensure we always have at least one value, even in very spaceous charts
  4989. distances.push(80);
  4990. return max(Math.floor(distances.sort(function (a, b) {
  4991. return (a - b);
  4992. })[
  4993. // Discard first 10% of the relevant distances, and then grab
  4994. // the smallest one.
  4995. Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
  4996. ), 1 // 1 is the minimum margin
  4997. );
  4998. }
  4999. /* eslint-disable no-invalid-this, valid-jsdoc */
  5000. /**
  5001. * The Connection class. Used internally to represent a connection between two
  5002. * points.
  5003. *
  5004. * @private
  5005. * @class
  5006. * @name Highcharts.Connection
  5007. *
  5008. * @param {Highcharts.Point} from
  5009. * Connection runs from this Point.
  5010. *
  5011. * @param {Highcharts.Point} to
  5012. * Connection runs to this Point.
  5013. *
  5014. * @param {Highcharts.ConnectorsOptions} [options]
  5015. * Connection options.
  5016. */
  5017. var Connection = /** @class */ (function () {
  5018. function Connection(from, to, options) {
  5019. /* *
  5020. *
  5021. * Properties
  5022. *
  5023. * */
  5024. this.chart = void 0;
  5025. this.fromPoint = void 0;
  5026. this.graphics = void 0;
  5027. this.pathfinder = void 0;
  5028. this.toPoint = void 0;
  5029. this.init(from, to, options);
  5030. }
  5031. /**
  5032. * Initialize the Connection object. Used as constructor only.
  5033. *
  5034. * @function Highcharts.Connection#init
  5035. *
  5036. * @param {Highcharts.Point} from
  5037. * Connection runs from this Point.
  5038. *
  5039. * @param {Highcharts.Point} to
  5040. * Connection runs to this Point.
  5041. *
  5042. * @param {Highcharts.ConnectorsOptions} [options]
  5043. * Connection options.
  5044. */
  5045. Connection.prototype.init = function (from, to, options) {
  5046. this.fromPoint = from;
  5047. this.toPoint = to;
  5048. this.options = options;
  5049. this.chart = from.series.chart;
  5050. this.pathfinder = this.chart.pathfinder;
  5051. };
  5052. /**
  5053. * Add (or update) this connection's path on chart. Stores reference to the
  5054. * created element on this.graphics.path.
  5055. *
  5056. * @function Highcharts.Connection#renderPath
  5057. *
  5058. * @param {Highcharts.SVGPathArray} path
  5059. * Path to render, in array format. E.g. ['M', 0, 0, 'L', 10, 10]
  5060. *
  5061. * @param {Highcharts.SVGAttributes} [attribs]
  5062. * SVG attributes for the path.
  5063. *
  5064. * @param {Partial<Highcharts.AnimationOptionsObject>} [animation]
  5065. * Animation options for the rendering.
  5066. */
  5067. Connection.prototype.renderPath = function (path, attribs, animation) {
  5068. var connection = this,
  5069. chart = this.chart,
  5070. styledMode = chart.styledMode,
  5071. pathfinder = chart.pathfinder,
  5072. animate = !chart.options.chart.forExport && animation !== false,
  5073. pathGraphic = connection.graphics && connection.graphics.path,
  5074. anim;
  5075. // Add the SVG element of the pathfinder group if it doesn't exist
  5076. if (!pathfinder.group) {
  5077. pathfinder.group = chart.renderer.g()
  5078. .addClass('highcharts-pathfinder-group')
  5079. .attr({ zIndex: -1 })
  5080. .add(chart.seriesGroup);
  5081. }
  5082. // Shift the group to compensate for plot area.
  5083. // Note: Do this always (even when redrawing a path) to avoid issues
  5084. // when updating chart in a way that changes plot metrics.
  5085. pathfinder.group.translate(chart.plotLeft, chart.plotTop);
  5086. // Create path if does not exist
  5087. if (!(pathGraphic && pathGraphic.renderer)) {
  5088. pathGraphic = chart.renderer.path()
  5089. .add(pathfinder.group);
  5090. if (!styledMode) {
  5091. pathGraphic.attr({
  5092. opacity: 0
  5093. });
  5094. }
  5095. }
  5096. // Set path attribs and animate to the new path
  5097. pathGraphic.attr(attribs);
  5098. anim = { d: path };
  5099. if (!styledMode) {
  5100. anim.opacity = 1;
  5101. }
  5102. pathGraphic[animate ? 'animate' : 'attr'](anim, animation);
  5103. // Store reference on connection
  5104. this.graphics = this.graphics || {};
  5105. this.graphics.path = pathGraphic;
  5106. };
  5107. /**
  5108. * Calculate and add marker graphics for connection to the chart. The
  5109. * created/updated elements are stored on this.graphics.start and
  5110. * this.graphics.end.
  5111. *
  5112. * @function Highcharts.Connection#addMarker
  5113. *
  5114. * @param {string} type
  5115. * Marker type, either 'start' or 'end'.
  5116. *
  5117. * @param {Highcharts.ConnectorsMarkerOptions} options
  5118. * All options for this marker. Not calculated or merged with other
  5119. * options.
  5120. *
  5121. * @param {Highcharts.SVGPathArray} path
  5122. * Connection path in array format. This is used to calculate the
  5123. * rotation angle of the markers.
  5124. */
  5125. Connection.prototype.addMarker = function (type, options, path) {
  5126. var connection = this,
  5127. chart = connection.fromPoint.series.chart,
  5128. pathfinder = chart.pathfinder,
  5129. renderer = chart.renderer,
  5130. point = (type === 'start' ?
  5131. connection.fromPoint :
  5132. connection.toPoint),
  5133. anchor = point.getPathfinderAnchorPoint(options),
  5134. markerVector,
  5135. radians,
  5136. rotation,
  5137. box,
  5138. width,
  5139. height,
  5140. pathVector,
  5141. segment;
  5142. if (!options.enabled) {
  5143. return;
  5144. }
  5145. // Last vector before start/end of path, used to get angle
  5146. if (type === 'start') {
  5147. segment = path[1];
  5148. }
  5149. else { // 'end'
  5150. segment = path[path.length - 2];
  5151. }
  5152. if (segment && segment[0] === 'M' || segment[0] === 'L') {
  5153. pathVector = {
  5154. x: segment[1],
  5155. y: segment[2]
  5156. };
  5157. // Get angle between pathVector and anchor point and use it to
  5158. // create marker position.
  5159. radians = point.getRadiansToVector(pathVector, anchor);
  5160. markerVector = point.getMarkerVector(radians, options.radius, anchor);
  5161. // Rotation of marker is calculated from angle between pathVector
  5162. // and markerVector.
  5163. // (Note:
  5164. // Used to recalculate radians between markerVector and pathVector,
  5165. // but this should be the same as between pathVector and anchor.)
  5166. rotation = -radians / deg2rad;
  5167. if (options.width && options.height) {
  5168. width = options.width;
  5169. height = options.height;
  5170. }
  5171. else {
  5172. width = height = options.radius * 2;
  5173. }
  5174. // Add graphics object if it does not exist
  5175. connection.graphics = connection.graphics || {};
  5176. box = {
  5177. x: markerVector.x - (width / 2),
  5178. y: markerVector.y - (height / 2),
  5179. width: width,
  5180. height: height,
  5181. rotation: rotation,
  5182. rotationOriginX: markerVector.x,
  5183. rotationOriginY: markerVector.y
  5184. };
  5185. if (!connection.graphics[type]) {
  5186. // Create new marker element
  5187. connection.graphics[type] = renderer
  5188. .symbol(options.symbol)
  5189. .addClass('highcharts-point-connecting-path-' + type + '-marker')
  5190. .attr(box)
  5191. .add(pathfinder.group);
  5192. if (!renderer.styledMode) {
  5193. connection.graphics[type].attr({
  5194. fill: options.color || connection.fromPoint.color,
  5195. stroke: options.lineColor,
  5196. 'stroke-width': options.lineWidth,
  5197. opacity: 0
  5198. })
  5199. .animate({
  5200. opacity: 1
  5201. }, point.series.options.animation);
  5202. }
  5203. }
  5204. else {
  5205. connection.graphics[type].animate(box);
  5206. }
  5207. }
  5208. };
  5209. /**
  5210. * Calculate and return connection path.
  5211. * Note: Recalculates chart obstacles on demand if they aren't calculated.
  5212. *
  5213. * @function Highcharts.Connection#getPath
  5214. *
  5215. * @param {Highcharts.ConnectorsOptions} options
  5216. * Connector options. Not calculated or merged with other options.
  5217. *
  5218. * @return {object|undefined}
  5219. * Calculated SVG path data in array format.
  5220. */
  5221. Connection.prototype.getPath = function (options) {
  5222. var pathfinder = this.pathfinder,
  5223. chart = this.chart,
  5224. algorithm = pathfinder.algorithms[options.type],
  5225. chartObstacles = pathfinder.chartObstacles;
  5226. if (typeof algorithm !== 'function') {
  5227. error('"' + options.type + '" is not a Pathfinder algorithm.');
  5228. return {
  5229. path: [],
  5230. obstacles: []
  5231. };
  5232. }
  5233. // This function calculates obstacles on demand if they don't exist
  5234. if (algorithm.requiresObstacles && !chartObstacles) {
  5235. chartObstacles =
  5236. pathfinder.chartObstacles =
  5237. pathfinder.getChartObstacles(options);
  5238. // If the algorithmMargin was computed, store the result in default
  5239. // options.
  5240. chart.options.connectors.algorithmMargin =
  5241. options.algorithmMargin;
  5242. // Cache some metrics too
  5243. pathfinder.chartObstacleMetrics =
  5244. pathfinder.getObstacleMetrics(chartObstacles);
  5245. }
  5246. // Get the SVG path
  5247. return algorithm(
  5248. // From
  5249. this.fromPoint.getPathfinderAnchorPoint(options.startMarker),
  5250. // To
  5251. this.toPoint.getPathfinderAnchorPoint(options.endMarker), merge({
  5252. chartObstacles: chartObstacles,
  5253. lineObstacles: pathfinder.lineObstacles || [],
  5254. obstacleMetrics: pathfinder.chartObstacleMetrics,
  5255. hardBounds: {
  5256. xMin: 0,
  5257. xMax: chart.plotWidth,
  5258. yMin: 0,
  5259. yMax: chart.plotHeight
  5260. },
  5261. obstacleOptions: {
  5262. margin: options.algorithmMargin
  5263. },
  5264. startDirectionX: pathfinder.getAlgorithmStartDirection(options.startMarker)
  5265. }, options));
  5266. };
  5267. /**
  5268. * (re)Calculate and (re)draw the connection.
  5269. *
  5270. * @function Highcharts.Connection#render
  5271. */
  5272. Connection.prototype.render = function () {
  5273. var connection = this,
  5274. fromPoint = connection.fromPoint,
  5275. series = fromPoint.series,
  5276. chart = series.chart,
  5277. pathfinder = chart.pathfinder,
  5278. pathResult,
  5279. path,
  5280. options = merge(chart.options.connectors,
  5281. series.options.connectors,
  5282. fromPoint.options.connectors,
  5283. connection.options),
  5284. attribs = {};
  5285. // Set path attribs
  5286. if (!chart.styledMode) {
  5287. attribs.stroke = options.lineColor || fromPoint.color;
  5288. attribs['stroke-width'] = options.lineWidth;
  5289. if (options.dashStyle) {
  5290. attribs.dashstyle = options.dashStyle;
  5291. }
  5292. }
  5293. attribs['class'] = // eslint-disable-line dot-notation
  5294. 'highcharts-point-connecting-path ' +
  5295. 'highcharts-color-' + fromPoint.colorIndex;
  5296. options = merge(attribs, options);
  5297. // Set common marker options
  5298. if (!defined(options.marker.radius)) {
  5299. options.marker.radius = min(max(Math.ceil((options.algorithmMargin || 8) / 2) - 1, 1), 5);
  5300. }
  5301. // Get the path
  5302. pathResult = connection.getPath(options);
  5303. path = pathResult.path;
  5304. // Always update obstacle storage with obstacles from this path.
  5305. // We don't know if future calls will need this for their algorithm.
  5306. if (pathResult.obstacles) {
  5307. pathfinder.lineObstacles =
  5308. pathfinder.lineObstacles || [];
  5309. pathfinder.lineObstacles =
  5310. pathfinder.lineObstacles.concat(pathResult.obstacles);
  5311. }
  5312. // Add the calculated path to the pathfinder group
  5313. connection.renderPath(path, attribs, series.options.animation);
  5314. // Render the markers
  5315. connection.addMarker('start', merge(options.marker, options.startMarker), path);
  5316. connection.addMarker('end', merge(options.marker, options.endMarker), path);
  5317. };
  5318. /**
  5319. * Destroy connection by destroying the added graphics elements.
  5320. *
  5321. * @function Highcharts.Connection#destroy
  5322. */
  5323. Connection.prototype.destroy = function () {
  5324. if (this.graphics) {
  5325. objectEach(this.graphics, function (val) {
  5326. val.destroy();
  5327. });
  5328. delete this.graphics;
  5329. }
  5330. };
  5331. return Connection;
  5332. }());
  5333. // Add to Highcharts namespace
  5334. H.Connection = Connection;
  5335. // Add pathfinding capabilities to Points
  5336. extend(Point.prototype, /** @lends Point.prototype */ {
  5337. /**
  5338. * Get coordinates of anchor point for pathfinder connection.
  5339. *
  5340. * @private
  5341. * @function Highcharts.Point#getPathfinderAnchorPoint
  5342. *
  5343. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  5344. * Connection options for position on point.
  5345. *
  5346. * @return {Highcharts.PositionObject}
  5347. * An object with x/y properties for the position. Coordinates are
  5348. * in plot values, not relative to point.
  5349. */
  5350. getPathfinderAnchorPoint: function (markerOptions) {
  5351. var bb = getPointBB(this),
  5352. x,
  5353. y;
  5354. switch (markerOptions.align) { // eslint-disable-line default-case
  5355. case 'right':
  5356. x = 'xMax';
  5357. break;
  5358. case 'left':
  5359. x = 'xMin';
  5360. }
  5361. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  5362. case 'top':
  5363. y = 'yMin';
  5364. break;
  5365. case 'bottom':
  5366. y = 'yMax';
  5367. }
  5368. return {
  5369. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  5370. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  5371. };
  5372. },
  5373. /**
  5374. * Utility to get the angle from one point to another.
  5375. *
  5376. * @private
  5377. * @function Highcharts.Point#getRadiansToVector
  5378. *
  5379. * @param {Highcharts.PositionObject} v1
  5380. * The first vector, as an object with x/y properties.
  5381. *
  5382. * @param {Highcharts.PositionObject} v2
  5383. * The second vector, as an object with x/y properties.
  5384. *
  5385. * @return {number}
  5386. * The angle in degrees
  5387. */
  5388. getRadiansToVector: function (v1, v2) {
  5389. var box;
  5390. if (!defined(v2)) {
  5391. box = getPointBB(this);
  5392. if (box) {
  5393. v2 = {
  5394. x: (box.xMin + box.xMax) / 2,
  5395. y: (box.yMin + box.yMax) / 2
  5396. };
  5397. }
  5398. }
  5399. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  5400. },
  5401. /**
  5402. * Utility to get the position of the marker, based on the path angle and
  5403. * the marker's radius.
  5404. *
  5405. * @private
  5406. * @function Highcharts.Point#getMarkerVector
  5407. *
  5408. * @param {number} radians
  5409. * The angle in radians from the point center to another vector.
  5410. *
  5411. * @param {number} markerRadius
  5412. * The radius of the marker, to calculate the additional distance to
  5413. * the center of the marker.
  5414. *
  5415. * @param {object} anchor
  5416. * The anchor point of the path and marker as an object with x/y
  5417. * properties.
  5418. *
  5419. * @return {object}
  5420. * The marker vector as an object with x/y properties.
  5421. */
  5422. getMarkerVector: function (radians, markerRadius, anchor) {
  5423. var twoPI = Math.PI * 2.0,
  5424. theta = radians,
  5425. bb = getPointBB(this),
  5426. rectWidth = bb.xMax - bb.xMin,
  5427. rectHeight = bb.yMax - bb.yMin,
  5428. rAtan = Math.atan2(rectHeight,
  5429. rectWidth),
  5430. tanTheta = 1,
  5431. leftOrRightRegion = false,
  5432. rectHalfWidth = rectWidth / 2.0,
  5433. rectHalfHeight = rectHeight / 2.0,
  5434. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  5435. rectVerticalCenter = bb.yMin + rectHalfHeight,
  5436. edgePoint = {
  5437. x: rectHorizontalCenter,
  5438. y: rectVerticalCenter
  5439. },
  5440. xFactor = 1,
  5441. yFactor = 1;
  5442. while (theta < -Math.PI) {
  5443. theta += twoPI;
  5444. }
  5445. while (theta > Math.PI) {
  5446. theta -= twoPI;
  5447. }
  5448. tanTheta = Math.tan(theta);
  5449. if ((theta > -rAtan) && (theta <= rAtan)) {
  5450. // Right side
  5451. yFactor = -1;
  5452. leftOrRightRegion = true;
  5453. }
  5454. else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  5455. // Top side
  5456. yFactor = -1;
  5457. }
  5458. else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  5459. // Left side
  5460. xFactor = -1;
  5461. leftOrRightRegion = true;
  5462. }
  5463. else {
  5464. // Bottom side
  5465. xFactor = -1;
  5466. }
  5467. // Correct the edgePoint according to the placement of the marker
  5468. if (leftOrRightRegion) {
  5469. edgePoint.x += xFactor * (rectHalfWidth);
  5470. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  5471. }
  5472. else {
  5473. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  5474. edgePoint.y += yFactor * (rectHalfHeight);
  5475. }
  5476. if (anchor.x !== rectHorizontalCenter) {
  5477. edgePoint.x = anchor.x;
  5478. }
  5479. if (anchor.y !== rectVerticalCenter) {
  5480. edgePoint.y = anchor.y;
  5481. }
  5482. return {
  5483. x: edgePoint.x + (markerRadius * Math.cos(theta)),
  5484. y: edgePoint.y - (markerRadius * Math.sin(theta))
  5485. };
  5486. }
  5487. });
  5488. /**
  5489. * Warn if using legacy options. Copy the options over. Note that this will
  5490. * still break if using the legacy options in chart.update, addSeries etc.
  5491. * @private
  5492. */
  5493. function warnLegacy(chart) {
  5494. if (chart.options.pathfinder ||
  5495. chart.series.reduce(function (acc, series) {
  5496. if (series.options) {
  5497. merge(true, (series.options.connectors = series.options.connectors ||
  5498. {}), series.options.pathfinder);
  5499. }
  5500. return acc || series.options && series.options.pathfinder;
  5501. }, false)) {
  5502. merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
  5503. error('WARNING: Pathfinder options have been renamed. ' +
  5504. 'Use "chart.connectors" or "series.connectors" instead.');
  5505. }
  5506. }
  5507. return Connection;
  5508. });
  5509. _registerModule(_modules, 'Gantt/PathfinderAlgorithms.js', [_modules['Core/Utilities.js']], function (U) {
  5510. /* *
  5511. *
  5512. * (c) 2016 Highsoft AS
  5513. * Author: Øystein Moseng
  5514. *
  5515. * License: www.highcharts.com/license
  5516. *
  5517. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5518. *
  5519. * */
  5520. var extend = U.extend,
  5521. pick = U.pick;
  5522. var min = Math.min,
  5523. max = Math.max,
  5524. abs = Math.abs;
  5525. /**
  5526. * Get index of last obstacle before xMin. Employs a type of binary search, and
  5527. * thus requires that obstacles are sorted by xMin value.
  5528. *
  5529. * @private
  5530. * @function findLastObstacleBefore
  5531. *
  5532. * @param {Array<object>} obstacles
  5533. * Array of obstacles to search in.
  5534. *
  5535. * @param {number} xMin
  5536. * The xMin threshold.
  5537. *
  5538. * @param {number} [startIx]
  5539. * Starting index to search from. Must be within array range.
  5540. *
  5541. * @return {number}
  5542. * The index of the last obstacle element before xMin.
  5543. */
  5544. function findLastObstacleBefore(obstacles, xMin, startIx) {
  5545. var left = startIx || 0, // left limit
  5546. right = obstacles.length - 1, // right limit
  5547. min = xMin - 0.0000001, // Make sure we include all obstacles at xMin
  5548. cursor,
  5549. cmp;
  5550. while (left <= right) {
  5551. cursor = (right + left) >> 1;
  5552. cmp = min - obstacles[cursor].xMin;
  5553. if (cmp > 0) {
  5554. left = cursor + 1;
  5555. }
  5556. else if (cmp < 0) {
  5557. right = cursor - 1;
  5558. }
  5559. else {
  5560. return cursor;
  5561. }
  5562. }
  5563. return left > 0 ? left - 1 : 0;
  5564. }
  5565. /**
  5566. * Test if a point lays within an obstacle.
  5567. *
  5568. * @private
  5569. * @function pointWithinObstacle
  5570. *
  5571. * @param {object} obstacle
  5572. * Obstacle to test.
  5573. *
  5574. * @param {Highcharts.Point} point
  5575. * Point with x/y props.
  5576. *
  5577. * @return {boolean}
  5578. * Whether point is within the obstacle or not.
  5579. */
  5580. function pointWithinObstacle(obstacle, point) {
  5581. return (point.x <= obstacle.xMax &&
  5582. point.x >= obstacle.xMin &&
  5583. point.y <= obstacle.yMax &&
  5584. point.y >= obstacle.yMin);
  5585. }
  5586. /**
  5587. * Find the index of an obstacle that wraps around a point.
  5588. * Returns -1 if not found.
  5589. *
  5590. * @private
  5591. * @function findObstacleFromPoint
  5592. *
  5593. * @param {Array<object>} obstacles
  5594. * Obstacles to test.
  5595. *
  5596. * @param {Highcharts.Point} point
  5597. * Point with x/y props.
  5598. *
  5599. * @return {number}
  5600. * Ix of the obstacle in the array, or -1 if not found.
  5601. */
  5602. function findObstacleFromPoint(obstacles, point) {
  5603. var i = findLastObstacleBefore(obstacles,
  5604. point.x + 1) + 1;
  5605. while (i--) {
  5606. if (obstacles[i].xMax >= point.x &&
  5607. // optimization using lazy evaluation
  5608. pointWithinObstacle(obstacles[i], point)) {
  5609. return i;
  5610. }
  5611. }
  5612. return -1;
  5613. }
  5614. /**
  5615. * Get SVG path array from array of line segments.
  5616. *
  5617. * @private
  5618. * @function pathFromSegments
  5619. *
  5620. * @param {Array<object>} segments
  5621. * The segments to build the path from.
  5622. *
  5623. * @return {Highcharts.SVGPathArray}
  5624. * SVG path array as accepted by the SVG Renderer.
  5625. */
  5626. function pathFromSegments(segments) {
  5627. var path = [];
  5628. if (segments.length) {
  5629. path.push(['M', segments[0].start.x, segments[0].start.y]);
  5630. for (var i = 0; i < segments.length; ++i) {
  5631. path.push(['L', segments[i].end.x, segments[i].end.y]);
  5632. }
  5633. }
  5634. return path;
  5635. }
  5636. /**
  5637. * Limits obstacle max/mins in all directions to bounds. Modifies input
  5638. * obstacle.
  5639. *
  5640. * @private
  5641. * @function limitObstacleToBounds
  5642. *
  5643. * @param {object} obstacle
  5644. * Obstacle to limit.
  5645. *
  5646. * @param {object} bounds
  5647. * Bounds to use as limit.
  5648. *
  5649. * @return {void}
  5650. */
  5651. function limitObstacleToBounds(obstacle, bounds) {
  5652. obstacle.yMin = max(obstacle.yMin, bounds.yMin);
  5653. obstacle.yMax = min(obstacle.yMax, bounds.yMax);
  5654. obstacle.xMin = max(obstacle.xMin, bounds.xMin);
  5655. obstacle.xMax = min(obstacle.xMax, bounds.xMax);
  5656. }
  5657. /**
  5658. * Get an SVG path from a starting coordinate to an ending coordinate.
  5659. * Draws a straight line.
  5660. *
  5661. * @function Highcharts.Pathfinder.algorithms.straight
  5662. *
  5663. * @param {Highcharts.PositionObject} start
  5664. * Starting coordinate, object with x/y props.
  5665. *
  5666. * @param {Highcharts.PositionObject} end
  5667. * Ending coordinate, object with x/y props.
  5668. *
  5669. * @return {object}
  5670. * An object with the SVG path in Array form as accepted by the SVG
  5671. * renderer, as well as an array of new obstacles making up this
  5672. * path.
  5673. */
  5674. function straight(start, end) {
  5675. return {
  5676. path: [
  5677. ['M', start.x, start.y],
  5678. ['L', end.x, end.y]
  5679. ],
  5680. obstacles: [{ start: start, end: end }]
  5681. };
  5682. }
  5683. /**
  5684. * Find a path from a starting coordinate to an ending coordinate, using
  5685. * right angles only, and taking only starting/ending obstacle into
  5686. * consideration.
  5687. *
  5688. * @function Highcharts.Pathfinder.algorithms.simpleConnect
  5689. *
  5690. * @param {Highcharts.PositionObject} start
  5691. * Starting coordinate, object with x/y props.
  5692. *
  5693. * @param {Highcharts.PositionObject} end
  5694. * Ending coordinate, object with x/y props.
  5695. *
  5696. * @param {object} options
  5697. * Options for the algorithm:
  5698. * - chartObstacles: Array of chart obstacles to avoid
  5699. * - startDirectionX: Optional. True if starting in the X direction.
  5700. * If not provided, the algorithm starts in the direction that is
  5701. * the furthest between start/end.
  5702. *
  5703. * @return {object}
  5704. * An object with the SVG path in Array form as accepted by the SVG
  5705. * renderer, as well as an array of new obstacles making up this
  5706. * path.
  5707. */
  5708. var simpleConnect = function (start,
  5709. end,
  5710. options) {
  5711. var segments = [],
  5712. endSegment,
  5713. dir = pick(options.startDirectionX,
  5714. abs(end.x - start.x) > abs(end.y - start.y)) ? 'x' : 'y',
  5715. chartObstacles = options.chartObstacles,
  5716. startObstacleIx = findObstacleFromPoint(chartObstacles,
  5717. start),
  5718. endObstacleIx = findObstacleFromPoint(chartObstacles,
  5719. end),
  5720. startObstacle,
  5721. endObstacle,
  5722. prevWaypoint,
  5723. waypoint,
  5724. waypoint2,
  5725. useMax,
  5726. endPoint;
  5727. // eslint-disable-next-line valid-jsdoc
  5728. /**
  5729. * Return a clone of a point with a property set from a target object,
  5730. * optionally with an offset
  5731. * @private
  5732. */
  5733. function copyFromPoint(from, fromKey, to, toKey, offset) {
  5734. var point = {
  5735. x: from.x,
  5736. y: from.y
  5737. };
  5738. point[fromKey] = to[toKey || fromKey] + (offset || 0);
  5739. return point;
  5740. }
  5741. // eslint-disable-next-line valid-jsdoc
  5742. /**
  5743. * Return waypoint outside obstacle.
  5744. * @private
  5745. */
  5746. function getMeOut(obstacle, point, direction) {
  5747. var useMax = abs(point[direction] - obstacle[direction + 'Min']) >
  5748. abs(point[direction] - obstacle[direction + 'Max']);
  5749. return copyFromPoint(point, direction, obstacle, direction + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1);
  5750. }
  5751. // Pull out end point
  5752. if (endObstacleIx > -1) {
  5753. endObstacle = chartObstacles[endObstacleIx];
  5754. waypoint = getMeOut(endObstacle, end, dir);
  5755. endSegment = {
  5756. start: waypoint,
  5757. end: end
  5758. };
  5759. endPoint = waypoint;
  5760. }
  5761. else {
  5762. endPoint = end;
  5763. }
  5764. // If an obstacle envelops the start point, add a segment to get out,
  5765. // and around it.
  5766. if (startObstacleIx > -1) {
  5767. startObstacle = chartObstacles[startObstacleIx];
  5768. waypoint = getMeOut(startObstacle, start, dir);
  5769. segments.push({
  5770. start: start,
  5771. end: waypoint
  5772. });
  5773. // If we are going back again, switch direction to get around start
  5774. // obstacle.
  5775. if (
  5776. // Going towards max from start:
  5777. waypoint[dir] >= start[dir] ===
  5778. // Going towards min to end:
  5779. waypoint[dir] >= endPoint[dir]) {
  5780. dir = dir === 'y' ? 'x' : 'y';
  5781. useMax = start[dir] < end[dir];
  5782. segments.push({
  5783. start: waypoint,
  5784. end: copyFromPoint(waypoint, dir, startObstacle, dir + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1)
  5785. });
  5786. // Switch direction again
  5787. dir = dir === 'y' ? 'x' : 'y';
  5788. }
  5789. }
  5790. // We are around the start obstacle. Go towards the end in one
  5791. // direction.
  5792. prevWaypoint = segments.length ?
  5793. segments[segments.length - 1].end :
  5794. start;
  5795. waypoint = copyFromPoint(prevWaypoint, dir, endPoint);
  5796. segments.push({
  5797. start: prevWaypoint,
  5798. end: waypoint
  5799. });
  5800. // Final run to end point in the other direction
  5801. dir = dir === 'y' ? 'x' : 'y';
  5802. waypoint2 = copyFromPoint(waypoint, dir, endPoint);
  5803. segments.push({
  5804. start: waypoint,
  5805. end: waypoint2
  5806. });
  5807. // Finally add the endSegment
  5808. segments.push(endSegment);
  5809. return {
  5810. path: pathFromSegments(segments),
  5811. obstacles: segments
  5812. };
  5813. };
  5814. simpleConnect.requiresObstacles = true;
  5815. /**
  5816. * Find a path from a starting coordinate to an ending coordinate, taking
  5817. * obstacles into consideration. Might not always find the optimal path,
  5818. * but is fast, and usually good enough.
  5819. *
  5820. * @function Highcharts.Pathfinder.algorithms.fastAvoid
  5821. *
  5822. * @param {Highcharts.PositionObject} start
  5823. * Starting coordinate, object with x/y props.
  5824. *
  5825. * @param {Highcharts.PositionObject} end
  5826. * Ending coordinate, object with x/y props.
  5827. *
  5828. * @param {object} options
  5829. * Options for the algorithm.
  5830. * - chartObstacles: Array of chart obstacles to avoid
  5831. * - lineObstacles: Array of line obstacles to jump over
  5832. * - obstacleMetrics: Object with metrics of chartObstacles cached
  5833. * - hardBounds: Hard boundaries to not cross
  5834. * - obstacleOptions: Options for the obstacles, including margin
  5835. * - startDirectionX: Optional. True if starting in the X direction.
  5836. * If not provided, the algorithm starts in the
  5837. * direction that is the furthest between
  5838. * start/end.
  5839. *
  5840. * @return {object}
  5841. * An object with the SVG path in Array form as accepted by the SVG
  5842. * renderer, as well as an array of new obstacles making up this
  5843. * path.
  5844. */
  5845. var fastAvoid = function (start,
  5846. end,
  5847. options) {
  5848. /*
  5849. Algorithm rules/description
  5850. - Find initial direction
  5851. - Determine soft/hard max for each direction.
  5852. - Move along initial direction until obstacle.
  5853. - Change direction.
  5854. - If hitting obstacle,
  5855. first try to change length of previous line
  5856. before changing direction again.
  5857. Soft min/max x = start/destination x +/- widest obstacle + margin
  5858. Soft min/max y = start/destination y +/- tallest obstacle + margin
  5859. @todo:
  5860. - Make retrospective,
  5861. try changing prev segment to reduce
  5862. corners
  5863. - Fix logic for breaking out of end-points - not always picking
  5864. the best direction currently
  5865. - When going around the end obstacle we should not always go the
  5866. shortest route,
  5867. rather pick the one closer to the end point
  5868. */
  5869. var dirIsX = pick(options.startDirectionX,
  5870. abs(end.x - start.x) > abs(end.y - start.y)),
  5871. dir = dirIsX ? 'x' : 'y',
  5872. segments,
  5873. useMax,
  5874. extractedEndPoint,
  5875. endSegments = [],
  5876. forceObstacleBreak = false, // Used in clearPathTo to keep track of
  5877. // when to force break through an obstacle.
  5878. // Boundaries to stay within. If beyond soft boundary, prefer to
  5879. // change direction ASAP. If at hard max, always change immediately.
  5880. metrics = options.obstacleMetrics,
  5881. softMinX = min(start.x,
  5882. end.x) - metrics.maxWidth - 10,
  5883. softMaxX = max(start.x,
  5884. end.x) + metrics.maxWidth + 10,
  5885. softMinY = min(start.y,
  5886. end.y) - metrics.maxHeight - 10,
  5887. softMaxY = max(start.y,
  5888. end.y) + metrics.maxHeight + 10,
  5889. // Obstacles
  5890. chartObstacles = options.chartObstacles,
  5891. startObstacleIx = findLastObstacleBefore(chartObstacles,
  5892. softMinX),
  5893. endObstacleIx = findLastObstacleBefore(chartObstacles,
  5894. softMaxX);
  5895. // eslint-disable-next-line valid-jsdoc
  5896. /**
  5897. * How far can you go between two points before hitting an obstacle?
  5898. * Does not work for diagonal lines (because it doesn't have to).
  5899. * @private
  5900. */
  5901. function pivotPoint(fromPoint, toPoint, directionIsX) {
  5902. var firstPoint,
  5903. lastPoint,
  5904. highestPoint,
  5905. lowestPoint,
  5906. i,
  5907. searchDirection = fromPoint.x < toPoint.x ? 1 : -1;
  5908. if (fromPoint.x < toPoint.x) {
  5909. firstPoint = fromPoint;
  5910. lastPoint = toPoint;
  5911. }
  5912. else {
  5913. firstPoint = toPoint;
  5914. lastPoint = fromPoint;
  5915. }
  5916. if (fromPoint.y < toPoint.y) {
  5917. lowestPoint = fromPoint;
  5918. highestPoint = toPoint;
  5919. }
  5920. else {
  5921. lowestPoint = toPoint;
  5922. highestPoint = fromPoint;
  5923. }
  5924. // Go through obstacle range in reverse if toPoint is before
  5925. // fromPoint in the X-dimension.
  5926. i = searchDirection < 0 ?
  5927. // Searching backwards, start at last obstacle before last point
  5928. min(findLastObstacleBefore(chartObstacles, lastPoint.x), chartObstacles.length - 1) :
  5929. // Forwards. Since we're not sorted by xMax, we have to look
  5930. // at all obstacles.
  5931. 0;
  5932. // Go through obstacles in this X range
  5933. while (chartObstacles[i] && (searchDirection > 0 && chartObstacles[i].xMin <= lastPoint.x ||
  5934. searchDirection < 0 && chartObstacles[i].xMax >= firstPoint.x)) {
  5935. // If this obstacle is between from and to points in a straight
  5936. // line, pivot at the intersection.
  5937. if (chartObstacles[i].xMin <= lastPoint.x &&
  5938. chartObstacles[i].xMax >= firstPoint.x &&
  5939. chartObstacles[i].yMin <= highestPoint.y &&
  5940. chartObstacles[i].yMax >= lowestPoint.y) {
  5941. if (directionIsX) {
  5942. return {
  5943. y: fromPoint.y,
  5944. x: fromPoint.x < toPoint.x ?
  5945. chartObstacles[i].xMin - 1 :
  5946. chartObstacles[i].xMax + 1,
  5947. obstacle: chartObstacles[i]
  5948. };
  5949. }
  5950. // else ...
  5951. return {
  5952. x: fromPoint.x,
  5953. y: fromPoint.y < toPoint.y ?
  5954. chartObstacles[i].yMin - 1 :
  5955. chartObstacles[i].yMax + 1,
  5956. obstacle: chartObstacles[i]
  5957. };
  5958. }
  5959. i += searchDirection;
  5960. }
  5961. return toPoint;
  5962. }
  5963. /**
  5964. * Decide in which direction to dodge or get out of an obstacle.
  5965. * Considers desired direction, which way is shortest, soft and hard
  5966. * bounds.
  5967. *
  5968. * (? Returns a string, either xMin, xMax, yMin or yMax.)
  5969. *
  5970. * @private
  5971. * @function
  5972. *
  5973. * @param {object} obstacle
  5974. * Obstacle to dodge/escape.
  5975. *
  5976. * @param {object} fromPoint
  5977. * Point with x/y props that's dodging/escaping.
  5978. *
  5979. * @param {object} toPoint
  5980. * Goal point.
  5981. *
  5982. * @param {boolean} dirIsX
  5983. * Dodge in X dimension.
  5984. *
  5985. * @param {object} bounds
  5986. * Hard and soft boundaries.
  5987. *
  5988. * @return {boolean}
  5989. * Use max or not.
  5990. */
  5991. function getDodgeDirection(obstacle, fromPoint, toPoint, dirIsX, bounds) {
  5992. 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'] >=
  5993. softBounds[dir + 'Max'], minOutOfSoftBounds = obstacle[dir + 'Min'] <=
  5994. softBounds[dir + 'Min'], maxOutOfHardBounds = obstacle[dir + 'Max'] >=
  5995. hardBounds[dir + 'Max'], minOutOfHardBounds = obstacle[dir + 'Min'] <=
  5996. hardBounds[dir + 'Min'],
  5997. // Find out if we should prefer one direction over the other if
  5998. // we can choose freely
  5999. minDistance = abs(obstacle[dir + 'Min'] - fromPoint[dir]), maxDistance = abs(obstacle[dir + 'Max'] - fromPoint[dir]),
  6000. // If it's a small difference, pick the one leading towards dest
  6001. // point. Otherwise pick the shortest distance
  6002. useMax = abs(minDistance - maxDistance) < 10 ?
  6003. fromPoint[dir] < toPoint[dir] :
  6004. maxDistance < minDistance;
  6005. // Check if we hit any obstacles trying to go around in either
  6006. // direction.
  6007. toPointMin[dir] = obstacle[dir + 'Min'];
  6008. toPointMax[dir] = obstacle[dir + 'Max'];
  6009. minPivot = pivotPoint(fromPoint, toPointMin, dirIsX)[dir] !==
  6010. toPointMin[dir];
  6011. maxPivot = pivotPoint(fromPoint, toPointMax, dirIsX)[dir] !==
  6012. toPointMax[dir];
  6013. useMax = minPivot ?
  6014. (maxPivot ? useMax : true) :
  6015. (maxPivot ? false : useMax);
  6016. // useMax now contains our preferred choice, bounds not taken into
  6017. // account. If both or neither direction is out of bounds we want to
  6018. // use this.
  6019. // Deal with soft bounds
  6020. useMax = minOutOfSoftBounds ?
  6021. (maxOutOfSoftBounds ? useMax : true) : // Out on min
  6022. (maxOutOfSoftBounds ? false : useMax); // Not out on min
  6023. // Deal with hard bounds
  6024. useMax = minOutOfHardBounds ?
  6025. (maxOutOfHardBounds ? useMax : true) : // Out on min
  6026. (maxOutOfHardBounds ? false : useMax); // Not out on min
  6027. return useMax;
  6028. }
  6029. // eslint-disable-next-line valid-jsdoc
  6030. /**
  6031. * Find a clear path between point.
  6032. * @private
  6033. */
  6034. function clearPathTo(fromPoint, toPoint, dirIsX) {
  6035. // Don't waste time if we've hit goal
  6036. if (fromPoint.x === toPoint.x && fromPoint.y === toPoint.y) {
  6037. return [];
  6038. }
  6039. var dir = dirIsX ? 'x' : 'y',
  6040. pivot,
  6041. segments,
  6042. waypoint,
  6043. waypointUseMax,
  6044. envelopingObstacle,
  6045. secondEnvelopingObstacle,
  6046. envelopWaypoint,
  6047. obstacleMargin = options.obstacleOptions.margin,
  6048. bounds = {
  6049. soft: {
  6050. xMin: softMinX,
  6051. xMax: softMaxX,
  6052. yMin: softMinY,
  6053. yMax: softMaxY
  6054. },
  6055. hard: options.hardBounds
  6056. };
  6057. // If fromPoint is inside an obstacle we have a problem. Break out
  6058. // by just going to the outside of this obstacle. We prefer to go to
  6059. // the nearest edge in the chosen direction.
  6060. envelopingObstacle =
  6061. findObstacleFromPoint(chartObstacles, fromPoint);
  6062. if (envelopingObstacle > -1) {
  6063. envelopingObstacle = chartObstacles[envelopingObstacle];
  6064. waypointUseMax = getDodgeDirection(envelopingObstacle, fromPoint, toPoint, dirIsX, bounds);
  6065. // Cut obstacle to hard bounds to make sure we stay within
  6066. limitObstacleToBounds(envelopingObstacle, options.hardBounds);
  6067. envelopWaypoint = dirIsX ? {
  6068. y: fromPoint.y,
  6069. x: envelopingObstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  6070. (waypointUseMax ? 1 : -1)
  6071. } : {
  6072. x: fromPoint.x,
  6073. y: envelopingObstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  6074. (waypointUseMax ? 1 : -1)
  6075. };
  6076. // If we crashed into another obstacle doing this, we put the
  6077. // waypoint between them instead
  6078. secondEnvelopingObstacle = findObstacleFromPoint(chartObstacles, envelopWaypoint);
  6079. if (secondEnvelopingObstacle > -1) {
  6080. secondEnvelopingObstacle = chartObstacles[secondEnvelopingObstacle];
  6081. // Cut obstacle to hard bounds
  6082. limitObstacleToBounds(secondEnvelopingObstacle, options.hardBounds);
  6083. // Modify waypoint to lay between obstacles
  6084. envelopWaypoint[dir] = waypointUseMax ? max(envelopingObstacle[dir + 'Max'] - obstacleMargin + 1, (secondEnvelopingObstacle[dir + 'Min'] +
  6085. envelopingObstacle[dir + 'Max']) / 2) :
  6086. min((envelopingObstacle[dir + 'Min'] + obstacleMargin - 1), ((secondEnvelopingObstacle[dir + 'Max'] +
  6087. envelopingObstacle[dir + 'Min']) / 2));
  6088. // We are not going anywhere. If this happens for the first
  6089. // time, do nothing. Otherwise, try to go to the extreme of
  6090. // the obstacle pair in the current direction.
  6091. if (fromPoint.x === envelopWaypoint.x &&
  6092. fromPoint.y === envelopWaypoint.y) {
  6093. if (forceObstacleBreak) {
  6094. envelopWaypoint[dir] = waypointUseMax ?
  6095. max(envelopingObstacle[dir + 'Max'], secondEnvelopingObstacle[dir + 'Max']) + 1 :
  6096. min(envelopingObstacle[dir + 'Min'], secondEnvelopingObstacle[dir + 'Min']) - 1;
  6097. }
  6098. // Toggle on if off, and the opposite
  6099. forceObstacleBreak = !forceObstacleBreak;
  6100. }
  6101. else {
  6102. // This point is not identical to previous.
  6103. // Clear break trigger.
  6104. forceObstacleBreak = false;
  6105. }
  6106. }
  6107. segments = [{
  6108. start: fromPoint,
  6109. end: envelopWaypoint
  6110. }];
  6111. }
  6112. else { // If not enveloping, use standard pivot calculation
  6113. pivot = pivotPoint(fromPoint, {
  6114. x: dirIsX ? toPoint.x : fromPoint.x,
  6115. y: dirIsX ? fromPoint.y : toPoint.y
  6116. }, dirIsX);
  6117. segments = [{
  6118. start: fromPoint,
  6119. end: {
  6120. x: pivot.x,
  6121. y: pivot.y
  6122. }
  6123. }];
  6124. // Pivot before goal, use a waypoint to dodge obstacle
  6125. if (pivot[dirIsX ? 'x' : 'y'] !== toPoint[dirIsX ? 'x' : 'y']) {
  6126. // Find direction of waypoint
  6127. waypointUseMax = getDodgeDirection(pivot.obstacle, pivot, toPoint, !dirIsX, bounds);
  6128. // Cut waypoint to hard bounds
  6129. limitObstacleToBounds(pivot.obstacle, options.hardBounds);
  6130. waypoint = {
  6131. x: dirIsX ?
  6132. pivot.x :
  6133. pivot.obstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  6134. (waypointUseMax ? 1 : -1),
  6135. y: dirIsX ?
  6136. pivot.obstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  6137. (waypointUseMax ? 1 : -1) :
  6138. pivot.y
  6139. };
  6140. // We're changing direction here, store that to make sure we
  6141. // also change direction when adding the last segment array
  6142. // after handling waypoint.
  6143. dirIsX = !dirIsX;
  6144. segments = segments.concat(clearPathTo({
  6145. x: pivot.x,
  6146. y: pivot.y
  6147. }, waypoint, dirIsX));
  6148. }
  6149. }
  6150. // Get segments for the other direction too
  6151. // Recursion is our friend
  6152. segments = segments.concat(clearPathTo(segments[segments.length - 1].end, toPoint, !dirIsX));
  6153. return segments;
  6154. }
  6155. // eslint-disable-next-line valid-jsdoc
  6156. /**
  6157. * Extract point to outside of obstacle in whichever direction is
  6158. * closest. Returns new point outside obstacle.
  6159. * @private
  6160. */
  6161. function extractFromObstacle(obstacle, point, goalPoint) {
  6162. var dirIsX = min(obstacle.xMax - point.x,
  6163. point.x - obstacle.xMin) <
  6164. min(obstacle.yMax - point.y,
  6165. point.y - obstacle.yMin),
  6166. bounds = {
  6167. soft: options.hardBounds,
  6168. hard: options.hardBounds
  6169. },
  6170. useMax = getDodgeDirection(obstacle,
  6171. point,
  6172. goalPoint,
  6173. dirIsX,
  6174. bounds);
  6175. return dirIsX ? {
  6176. y: point.y,
  6177. x: obstacle[useMax ? 'xMax' : 'xMin'] + (useMax ? 1 : -1)
  6178. } : {
  6179. x: point.x,
  6180. y: obstacle[useMax ? 'yMax' : 'yMin'] + (useMax ? 1 : -1)
  6181. };
  6182. }
  6183. // Cut the obstacle array to soft bounds for optimization in large
  6184. // datasets.
  6185. chartObstacles =
  6186. chartObstacles.slice(startObstacleIx, endObstacleIx + 1);
  6187. // If an obstacle envelops the end point, move it out of there and add
  6188. // a little segment to where it was.
  6189. if ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  6190. extractedEndPoint = extractFromObstacle(chartObstacles[endObstacleIx], end, start);
  6191. endSegments.push({
  6192. end: end,
  6193. start: extractedEndPoint
  6194. });
  6195. end = extractedEndPoint;
  6196. }
  6197. // If it's still inside one or more obstacles, get out of there by
  6198. // force-moving towards the start point.
  6199. while ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  6200. useMax = end[dir] - start[dir] < 0;
  6201. extractedEndPoint = {
  6202. x: end.x,
  6203. y: end.y
  6204. };
  6205. extractedEndPoint[dir] = chartObstacles[endObstacleIx][useMax ? dir + 'Max' : dir + 'Min'] + (useMax ? 1 : -1);
  6206. endSegments.push({
  6207. end: end,
  6208. start: extractedEndPoint
  6209. });
  6210. end = extractedEndPoint;
  6211. }
  6212. // Find the path
  6213. segments = clearPathTo(start, end, dirIsX);
  6214. // Add the end-point segments
  6215. segments = segments.concat(endSegments.reverse());
  6216. return {
  6217. path: pathFromSegments(segments),
  6218. obstacles: segments
  6219. };
  6220. };
  6221. fastAvoid.requiresObstacles = true;
  6222. // Define the available pathfinding algorithms.
  6223. // Algorithms take up to 3 arguments: starting point, ending point, and an
  6224. // options object.
  6225. var algorithms = {
  6226. fastAvoid: fastAvoid,
  6227. straight: straight,
  6228. simpleConnect: simpleConnect
  6229. };
  6230. return algorithms;
  6231. });
  6232. _registerModule(_modules, 'Gantt/Pathfinder.js', [_modules['Gantt/Connection.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js'], _modules['Gantt/PathfinderAlgorithms.js']], function (Connection, Chart, H, D, Point, U, pathfinderAlgorithms) {
  6233. /* *
  6234. *
  6235. * (c) 2016 Highsoft AS
  6236. * Authors: Øystein Moseng, Lars A. V. Cabrera
  6237. *
  6238. * License: www.highcharts.com/license
  6239. *
  6240. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6241. *
  6242. * */
  6243. /**
  6244. * The default pathfinder algorithm to use for a chart. It is possible to define
  6245. * your own algorithms by adding them to the
  6246. * `Highcharts.Pathfinder.prototype.algorithms`
  6247. * object before the chart has been created.
  6248. *
  6249. * The default algorithms are as follows:
  6250. *
  6251. * `straight`: Draws a straight line between the connecting
  6252. * points. Does not avoid other points when drawing.
  6253. *
  6254. * `simpleConnect`: Finds a path between the points using right angles
  6255. * only. Takes only starting/ending points into
  6256. * account, and will not avoid other points.
  6257. *
  6258. * `fastAvoid`: Finds a path between the points using right angles
  6259. * only. Will attempt to avoid other points, but its
  6260. * focus is performance over accuracy. Works well with
  6261. * less dense datasets.
  6262. *
  6263. * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
  6264. */
  6265. ''; // detach doclets above
  6266. var defaultOptions = D.defaultOptions;
  6267. var addEvent = U.addEvent,
  6268. defined = U.defined,
  6269. error = U.error,
  6270. extend = U.extend,
  6271. merge = U.merge,
  6272. objectEach = U.objectEach,
  6273. pick = U.pick,
  6274. splat = U.splat;
  6275. var deg2rad = H.deg2rad,
  6276. max = Math.max,
  6277. min = Math.min;
  6278. /*
  6279. @todo:
  6280. - Document how to write your own algorithms
  6281. - Consider adding a Point.pathTo method that wraps creating a connection
  6282. and rendering it
  6283. */
  6284. // Set default Pathfinder options
  6285. extend(defaultOptions, {
  6286. /**
  6287. * The Pathfinder module allows you to define connections between any two
  6288. * points, represented as lines - optionally with markers for the start
  6289. * and/or end points. Multiple algorithms are available for calculating how
  6290. * the connecting lines are drawn.
  6291. *
  6292. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  6293. * charts, the connectors are used to draw dependencies between tasks.
  6294. *
  6295. * @see [dependency](series.gantt.data.dependency)
  6296. *
  6297. * @sample gantt/pathfinder/demo
  6298. * Pathfinder connections
  6299. *
  6300. * @declare Highcharts.ConnectorsOptions
  6301. * @product gantt
  6302. * @optionparent connectors
  6303. */
  6304. connectors: {
  6305. /**
  6306. * Enable connectors for this chart. Requires Highcharts Gantt.
  6307. *
  6308. * @type {boolean}
  6309. * @default true
  6310. * @since 6.2.0
  6311. * @apioption connectors.enabled
  6312. */
  6313. /**
  6314. * Set the default dash style for this chart's connecting lines.
  6315. *
  6316. * @type {string}
  6317. * @default solid
  6318. * @since 6.2.0
  6319. * @apioption connectors.dashStyle
  6320. */
  6321. /**
  6322. * Set the default color for this chart's Pathfinder connecting lines.
  6323. * Defaults to the color of the point being connected.
  6324. *
  6325. * @type {Highcharts.ColorString}
  6326. * @since 6.2.0
  6327. * @apioption connectors.lineColor
  6328. */
  6329. /**
  6330. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  6331. * algorithms attempt to avoid obstacles, such as other points in the
  6332. * chart. These algorithms use this margin to determine how close lines
  6333. * can be to an obstacle. The default is to compute this automatically
  6334. * from the size of the obstacles in the chart.
  6335. *
  6336. * To draw connecting lines close to existing points, set this to a low
  6337. * number. For more space around existing points, set this number
  6338. * higher.
  6339. *
  6340. * @sample gantt/pathfinder/algorithm-margin
  6341. * Small algorithmMargin
  6342. *
  6343. * @type {number}
  6344. * @since 6.2.0
  6345. * @apioption connectors.algorithmMargin
  6346. */
  6347. /**
  6348. * Set the default pathfinder algorithm to use for this chart. It is
  6349. * possible to define your own algorithms by adding them to the
  6350. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  6351. * has been created.
  6352. *
  6353. * The default algorithms are as follows:
  6354. *
  6355. * `straight`: Draws a straight line between the connecting
  6356. * points. Does not avoid other points when drawing.
  6357. *
  6358. * `simpleConnect`: Finds a path between the points using right angles
  6359. * only. Takes only starting/ending points into
  6360. * account, and will not avoid other points.
  6361. *
  6362. * `fastAvoid`: Finds a path between the points using right angles
  6363. * only. Will attempt to avoid other points, but its
  6364. * focus is performance over accuracy. Works well with
  6365. * less dense datasets.
  6366. *
  6367. * Default value: `straight` is used as default for most series types,
  6368. * while `simpleConnect` is used as default for Gantt series, to show
  6369. * dependencies between points.
  6370. *
  6371. * @sample gantt/pathfinder/demo
  6372. * Different types used
  6373. *
  6374. * @type {Highcharts.PathfinderTypeValue}
  6375. * @default undefined
  6376. * @since 6.2.0
  6377. */
  6378. type: 'straight',
  6379. /**
  6380. * Set the default pixel width for this chart's Pathfinder connecting
  6381. * lines.
  6382. *
  6383. * @since 6.2.0
  6384. */
  6385. lineWidth: 1,
  6386. /**
  6387. * Marker options for this chart's Pathfinder connectors. Note that
  6388. * this option is overridden by the `startMarker` and `endMarker`
  6389. * options.
  6390. *
  6391. * @declare Highcharts.ConnectorsMarkerOptions
  6392. * @since 6.2.0
  6393. */
  6394. marker: {
  6395. /**
  6396. * Set the radius of the connector markers. The default is
  6397. * automatically computed based on the algorithmMargin setting.
  6398. *
  6399. * Setting marker.width and marker.height will override this
  6400. * setting.
  6401. *
  6402. * @type {number}
  6403. * @since 6.2.0
  6404. * @apioption connectors.marker.radius
  6405. */
  6406. /**
  6407. * Set the width of the connector markers. If not supplied, this
  6408. * is inferred from the marker radius.
  6409. *
  6410. * @type {number}
  6411. * @since 6.2.0
  6412. * @apioption connectors.marker.width
  6413. */
  6414. /**
  6415. * Set the height of the connector markers. If not supplied, this
  6416. * is inferred from the marker radius.
  6417. *
  6418. * @type {number}
  6419. * @since 6.2.0
  6420. * @apioption connectors.marker.height
  6421. */
  6422. /**
  6423. * Set the color of the connector markers. By default this is the
  6424. * same as the connector color.
  6425. *
  6426. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  6427. * @since 6.2.0
  6428. * @apioption connectors.marker.color
  6429. */
  6430. /**
  6431. * Set the line/border color of the connector markers. By default
  6432. * this is the same as the marker color.
  6433. *
  6434. * @type {Highcharts.ColorString}
  6435. * @since 6.2.0
  6436. * @apioption connectors.marker.lineColor
  6437. */
  6438. /**
  6439. * Enable markers for the connectors.
  6440. */
  6441. enabled: false,
  6442. /**
  6443. * Horizontal alignment of the markers relative to the points.
  6444. *
  6445. * @type {Highcharts.AlignValue}
  6446. */
  6447. align: 'center',
  6448. /**
  6449. * Vertical alignment of the markers relative to the points.
  6450. *
  6451. * @type {Highcharts.VerticalAlignValue}
  6452. */
  6453. verticalAlign: 'middle',
  6454. /**
  6455. * Whether or not to draw the markers inside the points.
  6456. */
  6457. inside: false,
  6458. /**
  6459. * Set the line/border width of the pathfinder markers.
  6460. */
  6461. lineWidth: 1
  6462. },
  6463. /**
  6464. * Marker options specific to the start markers for this chart's
  6465. * Pathfinder connectors. Overrides the generic marker options.
  6466. *
  6467. * @declare Highcharts.ConnectorsStartMarkerOptions
  6468. * @extends connectors.marker
  6469. * @since 6.2.0
  6470. */
  6471. startMarker: {
  6472. /**
  6473. * Set the symbol of the connector start markers.
  6474. */
  6475. symbol: 'diamond'
  6476. },
  6477. /**
  6478. * Marker options specific to the end markers for this chart's
  6479. * Pathfinder connectors. Overrides the generic marker options.
  6480. *
  6481. * @declare Highcharts.ConnectorsEndMarkerOptions
  6482. * @extends connectors.marker
  6483. * @since 6.2.0
  6484. */
  6485. endMarker: {
  6486. /**
  6487. * Set the symbol of the connector end markers.
  6488. */
  6489. symbol: 'arrow-filled'
  6490. }
  6491. }
  6492. });
  6493. /**
  6494. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  6495. * to be loaded.
  6496. *
  6497. * @declare Highcharts.SeriesConnectorsOptionsObject
  6498. * @extends connectors
  6499. * @since 6.2.0
  6500. * @excluding enabled, algorithmMargin
  6501. * @product gantt
  6502. * @apioption plotOptions.series.connectors
  6503. */
  6504. /**
  6505. * Connect to a point. This option can be either a string, referring to the ID
  6506. * of another point, or an object, or an array of either. If the option is an
  6507. * array, each element defines a connection.
  6508. *
  6509. * @sample gantt/pathfinder/demo
  6510. * Different connection types
  6511. *
  6512. * @declare Highcharts.XrangePointConnectorsOptionsObject
  6513. * @type {string|Array<string|*>|*}
  6514. * @extends plotOptions.series.connectors
  6515. * @since 6.2.0
  6516. * @excluding enabled
  6517. * @product gantt
  6518. * @requires highcharts-gantt
  6519. * @apioption series.xrange.data.connect
  6520. */
  6521. /**
  6522. * The ID of the point to connect to.
  6523. *
  6524. * @type {string}
  6525. * @since 6.2.0
  6526. * @product gantt
  6527. * @apioption series.xrange.data.connect.to
  6528. */
  6529. /**
  6530. * Get point bounding box using plotX/plotY and shapeArgs. If using
  6531. * graphic.getBBox() directly, the bbox will be affected by animation.
  6532. *
  6533. * @private
  6534. * @function
  6535. *
  6536. * @param {Highcharts.Point} point
  6537. * The point to get BB of.
  6538. *
  6539. * @return {Highcharts.Dictionary<number>|null}
  6540. * Result xMax, xMin, yMax, yMin.
  6541. */
  6542. function getPointBB(point) {
  6543. var shapeArgs = point.shapeArgs,
  6544. bb;
  6545. // Prefer using shapeArgs (columns)
  6546. if (shapeArgs) {
  6547. return {
  6548. xMin: shapeArgs.x || 0,
  6549. xMax: (shapeArgs.x || 0) + (shapeArgs.width || 0),
  6550. yMin: shapeArgs.y || 0,
  6551. yMax: (shapeArgs.y || 0) + (shapeArgs.height || 0)
  6552. };
  6553. }
  6554. // Otherwise use plotX/plotY and bb
  6555. bb = point.graphic && point.graphic.getBBox();
  6556. return bb ? {
  6557. xMin: point.plotX - bb.width / 2,
  6558. xMax: point.plotX + bb.width / 2,
  6559. yMin: point.plotY - bb.height / 2,
  6560. yMax: point.plotY + bb.height / 2
  6561. } : null;
  6562. }
  6563. /**
  6564. * Calculate margin to place around obstacles for the pathfinder in pixels.
  6565. * Returns a minimum of 1 pixel margin.
  6566. *
  6567. * @private
  6568. * @function
  6569. *
  6570. * @param {Array<object>} obstacles
  6571. * Obstacles to calculate margin from.
  6572. *
  6573. * @return {number}
  6574. * The calculated margin in pixels. At least 1.
  6575. */
  6576. function calculateObstacleMargin(obstacles) {
  6577. var len = obstacles.length,
  6578. i = 0,
  6579. j,
  6580. obstacleDistance,
  6581. distances = [],
  6582. // Compute smallest distance between two rectangles
  6583. distance = function (a,
  6584. b,
  6585. bbMargin) {
  6586. // Count the distance even if we are slightly off
  6587. var margin = pick(bbMargin, 10),
  6588. yOverlap = a.yMax + margin > b.yMin - margin &&
  6589. a.yMin - margin < b.yMax + margin,
  6590. xOverlap = a.xMax + margin > b.xMin - margin &&
  6591. a.xMin - margin < b.xMax + margin,
  6592. xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
  6593. yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
  6594. // If the rectangles collide, try recomputing with smaller margin.
  6595. // If they collide anyway, discard the obstacle.
  6596. if (xOverlap && yOverlap) {
  6597. return (margin ?
  6598. distance(a, b, Math.floor(margin / 2)) :
  6599. Infinity);
  6600. }
  6601. return min(xDistance, yDistance);
  6602. };
  6603. // Go over all obstacles and compare them to the others.
  6604. for (; i < len; ++i) {
  6605. // Compare to all obstacles ahead. We will already have compared this
  6606. // obstacle to the ones before.
  6607. for (j = i + 1; j < len; ++j) {
  6608. obstacleDistance = distance(obstacles[i], obstacles[j]);
  6609. // TODO: Magic number 80
  6610. if (obstacleDistance < 80) { // Ignore large distances
  6611. distances.push(obstacleDistance);
  6612. }
  6613. }
  6614. }
  6615. // Ensure we always have at least one value, even in very spaceous charts
  6616. distances.push(80);
  6617. return max(Math.floor(distances.sort(function (a, b) {
  6618. return (a - b);
  6619. })[
  6620. // Discard first 10% of the relevant distances, and then grab
  6621. // the smallest one.
  6622. Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
  6623. ), 1 // 1 is the minimum margin
  6624. );
  6625. }
  6626. /* eslint-disable no-invalid-this, valid-jsdoc */
  6627. /**
  6628. * The Pathfinder class.
  6629. *
  6630. * @private
  6631. * @class
  6632. * @name Highcharts.Pathfinder
  6633. *
  6634. * @param {Highcharts.Chart} chart
  6635. * The chart to operate on.
  6636. */
  6637. var Pathfinder = /** @class */ (function () {
  6638. function Pathfinder(chart) {
  6639. /* *
  6640. *
  6641. * Properties
  6642. *
  6643. * */
  6644. this.chart = void 0;
  6645. this.chartObstacles = void 0;
  6646. this.chartObstacleMetrics = void 0;
  6647. this.connections = void 0;
  6648. this.group = void 0;
  6649. this.lineObstacles = void 0;
  6650. this.init(chart);
  6651. }
  6652. /**
  6653. * @name Highcharts.Pathfinder#algorithms
  6654. * @type {Highcharts.Dictionary<Function>}
  6655. */
  6656. /**
  6657. * Initialize the Pathfinder object.
  6658. *
  6659. * @function Highcharts.Pathfinder#init
  6660. *
  6661. * @param {Highcharts.Chart} chart
  6662. * The chart context.
  6663. */
  6664. Pathfinder.prototype.init = function (chart) {
  6665. // Initialize pathfinder with chart context
  6666. this.chart = chart;
  6667. // Init connection reference list
  6668. this.connections = [];
  6669. // Recalculate paths/obstacles on chart redraw
  6670. addEvent(chart, 'redraw', function () {
  6671. this.pathfinder.update();
  6672. });
  6673. };
  6674. /**
  6675. * Update Pathfinder connections from scratch.
  6676. *
  6677. * @function Highcharts.Pathfinder#update
  6678. *
  6679. * @param {boolean} [deferRender]
  6680. * Whether or not to defer rendering of connections until
  6681. * series.afterAnimate event has fired. Used on first render.
  6682. */
  6683. Pathfinder.prototype.update = function (deferRender) {
  6684. var chart = this.chart,
  6685. pathfinder = this,
  6686. oldConnections = pathfinder.connections;
  6687. // Rebuild pathfinder connections from options
  6688. pathfinder.connections = [];
  6689. chart.series.forEach(function (series) {
  6690. if (series.visible && !series.options.isInternal) {
  6691. series.points.forEach(function (point) {
  6692. var ganttPointOptions = point.options;
  6693. // For Gantt series the connect could be
  6694. // defined as a dependency
  6695. if (ganttPointOptions && ganttPointOptions.dependency) {
  6696. ganttPointOptions.connect = ganttPointOptions.dependency;
  6697. }
  6698. var to,
  6699. connects = (point.options &&
  6700. point.options.connect &&
  6701. splat(point.options.connect));
  6702. if (point.visible && point.isInside !== false && connects) {
  6703. connects.forEach(function (connect) {
  6704. to = chart.get(typeof connect === 'string' ?
  6705. connect : connect.to);
  6706. if (to instanceof Point &&
  6707. to.series.visible &&
  6708. to.visible &&
  6709. to.isInside !== false) {
  6710. // Add new connection
  6711. pathfinder.connections.push(new Connection(point, // from
  6712. to, typeof connect === 'string' ?
  6713. {} :
  6714. connect));
  6715. }
  6716. });
  6717. }
  6718. });
  6719. }
  6720. });
  6721. // Clear connections that should not be updated, and move old info over
  6722. // to new connections.
  6723. for (var j = 0, k = void 0, found = void 0, lenOld = oldConnections.length, lenNew = pathfinder.connections.length; j < lenOld; ++j) {
  6724. found = false;
  6725. for (k = 0; k < lenNew; ++k) {
  6726. if (oldConnections[j].fromPoint ===
  6727. pathfinder.connections[k].fromPoint &&
  6728. oldConnections[j].toPoint ===
  6729. pathfinder.connections[k].toPoint) {
  6730. pathfinder.connections[k].graphics =
  6731. oldConnections[j].graphics;
  6732. found = true;
  6733. break;
  6734. }
  6735. }
  6736. if (!found) {
  6737. oldConnections[j].destroy();
  6738. }
  6739. }
  6740. // Clear obstacles to force recalculation. This must be done on every
  6741. // redraw in case positions have changed. Recalculation is handled in
  6742. // Connection.getPath on demand.
  6743. delete this.chartObstacles;
  6744. delete this.lineObstacles;
  6745. // Draw the pending connections
  6746. pathfinder.renderConnections(deferRender);
  6747. };
  6748. /**
  6749. * Draw the chart's connecting paths.
  6750. *
  6751. * @function Highcharts.Pathfinder#renderConnections
  6752. *
  6753. * @param {boolean} [deferRender]
  6754. * Whether or not to defer render until series animation is finished.
  6755. * Used on first render.
  6756. */
  6757. Pathfinder.prototype.renderConnections = function (deferRender) {
  6758. if (deferRender) {
  6759. // Render after series are done animating
  6760. this.chart.series.forEach(function (series) {
  6761. var render = function () {
  6762. // Find pathfinder connections belonging to this series
  6763. // that haven't rendered, and render them now.
  6764. var pathfinder = series.chart.pathfinder,
  6765. conns = pathfinder && pathfinder.connections || [];
  6766. conns.forEach(function (connection) {
  6767. if (connection.fromPoint &&
  6768. connection.fromPoint.series === series) {
  6769. connection.render();
  6770. }
  6771. });
  6772. if (series.pathfinderRemoveRenderEvent) {
  6773. series.pathfinderRemoveRenderEvent();
  6774. delete series.pathfinderRemoveRenderEvent;
  6775. }
  6776. };
  6777. if (series.options.animation === false) {
  6778. render();
  6779. }
  6780. else {
  6781. series.pathfinderRemoveRenderEvent = addEvent(series, 'afterAnimate', render);
  6782. }
  6783. });
  6784. }
  6785. else {
  6786. // Go through connections and render them
  6787. this.connections.forEach(function (connection) {
  6788. connection.render();
  6789. });
  6790. }
  6791. };
  6792. /**
  6793. * Get obstacles for the points in the chart. Does not include connecting
  6794. * lines from Pathfinder. Applies algorithmMargin to the obstacles.
  6795. *
  6796. * @function Highcharts.Pathfinder#getChartObstacles
  6797. *
  6798. * @param {object} options
  6799. * Options for the calculation. Currenlty only
  6800. * options.algorithmMargin.
  6801. *
  6802. * @return {Array<object>}
  6803. * An array of calculated obstacles. Each obstacle is defined as an
  6804. * object with xMin, xMax, yMin and yMax properties.
  6805. */
  6806. Pathfinder.prototype.getChartObstacles = function (options) {
  6807. var obstacles = [],
  6808. series = this.chart.series,
  6809. margin = pick(options.algorithmMargin, 0),
  6810. calculatedMargin;
  6811. for (var i = 0, sLen = series.length; i < sLen; ++i) {
  6812. if (series[i].visible && !series[i].options.isInternal) {
  6813. for (var j = 0, pLen = series[i].points.length, bb = void 0, point = void 0; j < pLen; ++j) {
  6814. point = series[i].points[j];
  6815. if (point.visible) {
  6816. bb = getPointBB(point);
  6817. if (bb) {
  6818. obstacles.push({
  6819. xMin: bb.xMin - margin,
  6820. xMax: bb.xMax + margin,
  6821. yMin: bb.yMin - margin,
  6822. yMax: bb.yMax + margin
  6823. });
  6824. }
  6825. }
  6826. }
  6827. }
  6828. }
  6829. // Sort obstacles by xMin for optimization
  6830. obstacles = obstacles.sort(function (a, b) {
  6831. return a.xMin - b.xMin;
  6832. });
  6833. // Add auto-calculated margin if the option is not defined
  6834. if (!defined(options.algorithmMargin)) {
  6835. calculatedMargin =
  6836. options.algorithmMargin =
  6837. calculateObstacleMargin(obstacles);
  6838. obstacles.forEach(function (obstacle) {
  6839. obstacle.xMin -= calculatedMargin;
  6840. obstacle.xMax += calculatedMargin;
  6841. obstacle.yMin -= calculatedMargin;
  6842. obstacle.yMax += calculatedMargin;
  6843. });
  6844. }
  6845. return obstacles;
  6846. };
  6847. /**
  6848. * Utility function to get metrics for obstacles:
  6849. * - Widest obstacle width
  6850. * - Tallest obstacle height
  6851. *
  6852. * @function Highcharts.Pathfinder#getObstacleMetrics
  6853. *
  6854. * @param {Array<object>} obstacles
  6855. * An array of obstacles to inspect.
  6856. *
  6857. * @return {object}
  6858. * The calculated metrics, as an object with maxHeight and maxWidth
  6859. * properties.
  6860. */
  6861. Pathfinder.prototype.getObstacleMetrics = function (obstacles) {
  6862. var maxWidth = 0,
  6863. maxHeight = 0,
  6864. width,
  6865. height,
  6866. i = obstacles.length;
  6867. while (i--) {
  6868. width = obstacles[i].xMax - obstacles[i].xMin;
  6869. height = obstacles[i].yMax - obstacles[i].yMin;
  6870. if (maxWidth < width) {
  6871. maxWidth = width;
  6872. }
  6873. if (maxHeight < height) {
  6874. maxHeight = height;
  6875. }
  6876. }
  6877. return {
  6878. maxHeight: maxHeight,
  6879. maxWidth: maxWidth
  6880. };
  6881. };
  6882. /**
  6883. * Utility to get which direction to start the pathfinding algorithm
  6884. * (X vs Y), calculated from a set of marker options.
  6885. *
  6886. * @function Highcharts.Pathfinder#getAlgorithmStartDirection
  6887. *
  6888. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  6889. * Marker options to calculate from.
  6890. *
  6891. * @return {boolean}
  6892. * Returns true for X, false for Y, and undefined for autocalculate.
  6893. */
  6894. Pathfinder.prototype.getAlgorithmStartDirection = function (markerOptions) {
  6895. var xCenter = markerOptions.align !== 'left' &&
  6896. markerOptions.align !== 'right', yCenter = markerOptions.verticalAlign !== 'top' &&
  6897. markerOptions.verticalAlign !== 'bottom', undef;
  6898. return xCenter ?
  6899. (yCenter ? undef : false) : // x is centered
  6900. (yCenter ? true : undef); // x is off-center
  6901. };
  6902. return Pathfinder;
  6903. }());
  6904. Pathfinder.prototype.algorithms = pathfinderAlgorithms;
  6905. // Add to Highcharts namespace
  6906. H.Pathfinder = Pathfinder;
  6907. // Add pathfinding capabilities to Points
  6908. extend(Point.prototype, /** @lends Point.prototype */ {
  6909. /**
  6910. * Get coordinates of anchor point for pathfinder connection.
  6911. *
  6912. * @private
  6913. * @function Highcharts.Point#getPathfinderAnchorPoint
  6914. *
  6915. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  6916. * Connection options for position on point.
  6917. *
  6918. * @return {Highcharts.PositionObject}
  6919. * An object with x/y properties for the position. Coordinates are
  6920. * in plot values, not relative to point.
  6921. */
  6922. getPathfinderAnchorPoint: function (markerOptions) {
  6923. var bb = getPointBB(this),
  6924. x,
  6925. y;
  6926. switch (markerOptions.align) { // eslint-disable-line default-case
  6927. case 'right':
  6928. x = 'xMax';
  6929. break;
  6930. case 'left':
  6931. x = 'xMin';
  6932. }
  6933. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  6934. case 'top':
  6935. y = 'yMin';
  6936. break;
  6937. case 'bottom':
  6938. y = 'yMax';
  6939. }
  6940. return {
  6941. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  6942. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  6943. };
  6944. },
  6945. /**
  6946. * Utility to get the angle from one point to another.
  6947. *
  6948. * @private
  6949. * @function Highcharts.Point#getRadiansToVector
  6950. *
  6951. * @param {Highcharts.PositionObject} v1
  6952. * The first vector, as an object with x/y properties.
  6953. *
  6954. * @param {Highcharts.PositionObject} v2
  6955. * The second vector, as an object with x/y properties.
  6956. *
  6957. * @return {number}
  6958. * The angle in degrees
  6959. */
  6960. getRadiansToVector: function (v1, v2) {
  6961. var box;
  6962. if (!defined(v2)) {
  6963. box = getPointBB(this);
  6964. if (box) {
  6965. v2 = {
  6966. x: (box.xMin + box.xMax) / 2,
  6967. y: (box.yMin + box.yMax) / 2
  6968. };
  6969. }
  6970. }
  6971. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  6972. },
  6973. /**
  6974. * Utility to get the position of the marker, based on the path angle and
  6975. * the marker's radius.
  6976. *
  6977. * @private
  6978. * @function Highcharts.Point#getMarkerVector
  6979. *
  6980. * @param {number} radians
  6981. * The angle in radians from the point center to another vector.
  6982. *
  6983. * @param {number} markerRadius
  6984. * The radius of the marker, to calculate the additional distance to
  6985. * the center of the marker.
  6986. *
  6987. * @param {object} anchor
  6988. * The anchor point of the path and marker as an object with x/y
  6989. * properties.
  6990. *
  6991. * @return {object}
  6992. * The marker vector as an object with x/y properties.
  6993. */
  6994. getMarkerVector: function (radians, markerRadius, anchor) {
  6995. var twoPI = Math.PI * 2.0,
  6996. theta = radians,
  6997. bb = getPointBB(this),
  6998. rectWidth = bb.xMax - bb.xMin,
  6999. rectHeight = bb.yMax - bb.yMin,
  7000. rAtan = Math.atan2(rectHeight,
  7001. rectWidth),
  7002. tanTheta = 1,
  7003. leftOrRightRegion = false,
  7004. rectHalfWidth = rectWidth / 2.0,
  7005. rectHalfHeight = rectHeight / 2.0,
  7006. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  7007. rectVerticalCenter = bb.yMin + rectHalfHeight,
  7008. edgePoint = {
  7009. x: rectHorizontalCenter,
  7010. y: rectVerticalCenter
  7011. },
  7012. xFactor = 1,
  7013. yFactor = 1;
  7014. while (theta < -Math.PI) {
  7015. theta += twoPI;
  7016. }
  7017. while (theta > Math.PI) {
  7018. theta -= twoPI;
  7019. }
  7020. tanTheta = Math.tan(theta);
  7021. if ((theta > -rAtan) && (theta <= rAtan)) {
  7022. // Right side
  7023. yFactor = -1;
  7024. leftOrRightRegion = true;
  7025. }
  7026. else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  7027. // Top side
  7028. yFactor = -1;
  7029. }
  7030. else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  7031. // Left side
  7032. xFactor = -1;
  7033. leftOrRightRegion = true;
  7034. }
  7035. else {
  7036. // Bottom side
  7037. xFactor = -1;
  7038. }
  7039. // Correct the edgePoint according to the placement of the marker
  7040. if (leftOrRightRegion) {
  7041. edgePoint.x += xFactor * (rectHalfWidth);
  7042. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  7043. }
  7044. else {
  7045. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  7046. edgePoint.y += yFactor * (rectHalfHeight);
  7047. }
  7048. if (anchor.x !== rectHorizontalCenter) {
  7049. edgePoint.x = anchor.x;
  7050. }
  7051. if (anchor.y !== rectVerticalCenter) {
  7052. edgePoint.y = anchor.y;
  7053. }
  7054. return {
  7055. x: edgePoint.x + (markerRadius * Math.cos(theta)),
  7056. y: edgePoint.y - (markerRadius * Math.sin(theta))
  7057. };
  7058. }
  7059. });
  7060. /**
  7061. * Warn if using legacy options. Copy the options over. Note that this will
  7062. * still break if using the legacy options in chart.update, addSeries etc.
  7063. * @private
  7064. */
  7065. function warnLegacy(chart) {
  7066. if (chart.options.pathfinder ||
  7067. chart.series.reduce(function (acc, series) {
  7068. if (series.options) {
  7069. merge(true, (series.options.connectors = series.options.connectors ||
  7070. {}), series.options.pathfinder);
  7071. }
  7072. return acc || series.options && series.options.pathfinder;
  7073. }, false)) {
  7074. merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
  7075. error('WARNING: Pathfinder options have been renamed. ' +
  7076. 'Use "chart.connectors" or "series.connectors" instead.');
  7077. }
  7078. }
  7079. // Initialize Pathfinder for charts
  7080. Chart.prototype.callbacks.push(function (chart) {
  7081. var options = chart.options;
  7082. if (options.connectors.enabled !== false) {
  7083. warnLegacy(chart);
  7084. this.pathfinder = new Pathfinder(this);
  7085. this.pathfinder.update(true); // First draw, defer render
  7086. }
  7087. });
  7088. return Pathfinder;
  7089. });
  7090. _registerModule(_modules, 'Series/Gantt/GanttSeries.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Series/Gantt/GanttPoint.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/TreeGridAxis.js']], function (Axis, Chart, GanttPoint, SeriesRegistry, Tick, U, TreeGridAxis) {
  7091. /* *
  7092. *
  7093. * (c) 2016-2021 Highsoft AS
  7094. *
  7095. * Author: Lars A. V. Cabrera
  7096. *
  7097. * License: www.highcharts.com/license
  7098. *
  7099. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7100. *
  7101. * */
  7102. var __extends = (this && this.__extends) || (function () {
  7103. var extendStatics = function (d,
  7104. b) {
  7105. extendStatics = Object.setPrototypeOf ||
  7106. ({ __proto__: [] } instanceof Array && function (d,
  7107. b) { d.__proto__ = b; }) ||
  7108. function (d,
  7109. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7110. return extendStatics(d, b);
  7111. };
  7112. return function (d, b) {
  7113. extendStatics(d, b);
  7114. function __() { this.constructor = d; }
  7115. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7116. };
  7117. })();
  7118. var Series = SeriesRegistry.series,
  7119. XRangeSeries = SeriesRegistry.seriesTypes.xrange;
  7120. var extend = U.extend,
  7121. isNumber = U.isNumber,
  7122. merge = U.merge,
  7123. splat = U.splat;
  7124. TreeGridAxis.compose(Axis, Chart, Series, Tick);
  7125. /* *
  7126. *
  7127. * Class
  7128. *
  7129. * */
  7130. /**
  7131. * @private
  7132. * @class
  7133. * @name Highcharts.seriesTypes.gantt
  7134. *
  7135. * @augments Highcharts.Series
  7136. */
  7137. var GanttSeries = /** @class */ (function (_super) {
  7138. __extends(GanttSeries, _super);
  7139. function GanttSeries() {
  7140. var _this = _super !== null && _super.apply(this,
  7141. arguments) || this;
  7142. /* *
  7143. *
  7144. * Properties
  7145. *
  7146. * */
  7147. _this.data = void 0;
  7148. _this.options = void 0;
  7149. _this.points = void 0;
  7150. return _this;
  7151. /* eslint-enable valid-jsdoc */
  7152. }
  7153. /* *
  7154. *
  7155. * Functions
  7156. *
  7157. * */
  7158. /* eslint-disable valid-jsdoc */
  7159. /**
  7160. * Draws a single point in the series.
  7161. *
  7162. * This override draws the point as a diamond if point.options.milestone
  7163. * is true, and uses the original drawPoint() if it is false or not set.
  7164. *
  7165. * @requires highcharts-gantt
  7166. *
  7167. * @private
  7168. * @function Highcharts.seriesTypes.gantt#drawPoint
  7169. *
  7170. * @param {Highcharts.Point} point
  7171. * An instance of Point in the series
  7172. *
  7173. * @param {"animate"|"attr"} verb
  7174. * 'animate' (animates changes) or 'attr' (sets options)
  7175. */
  7176. GanttSeries.prototype.drawPoint = function (point, verb) {
  7177. var series = this,
  7178. seriesOpts = series.options,
  7179. renderer = series.chart.renderer,
  7180. shapeArgs = point.shapeArgs,
  7181. plotY = point.plotY,
  7182. graphic = point.graphic,
  7183. state = point.selected && 'select',
  7184. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  7185. diamondShape;
  7186. if (point.options.milestone) {
  7187. if (isNumber(plotY) && point.y !== null && point.visible !== false) {
  7188. diamondShape = renderer.symbols.diamond(shapeArgs.x || 0, shapeArgs.y || 0, shapeArgs.width || 0, shapeArgs.height || 0);
  7189. if (graphic) {
  7190. graphic[verb]({
  7191. d: diamondShape
  7192. });
  7193. }
  7194. else {
  7195. point.graphic = graphic = renderer.path(diamondShape)
  7196. .addClass(point.getClassName(), true)
  7197. .add(point.group || series.group);
  7198. }
  7199. // Presentational
  7200. if (!series.chart.styledMode) {
  7201. point.graphic
  7202. .attr(series.pointAttribs(point, state))
  7203. .shadow(seriesOpts.shadow, null, cutOff);
  7204. }
  7205. }
  7206. else if (graphic) {
  7207. point.graphic = graphic.destroy(); // #1269
  7208. }
  7209. }
  7210. else {
  7211. XRangeSeries.prototype.drawPoint.call(series, point, verb);
  7212. }
  7213. };
  7214. /**
  7215. * Handle milestones, as they have no x2.
  7216. * @private
  7217. */
  7218. GanttSeries.prototype.translatePoint = function (point) {
  7219. var series = this,
  7220. shapeArgs,
  7221. size;
  7222. XRangeSeries.prototype.translatePoint.call(series, point);
  7223. if (point.options.milestone) {
  7224. shapeArgs = point.shapeArgs;
  7225. size = shapeArgs.height || 0;
  7226. point.shapeArgs = {
  7227. x: (shapeArgs.x || 0) - (size / 2),
  7228. y: shapeArgs.y,
  7229. width: size,
  7230. height: size
  7231. };
  7232. }
  7233. };
  7234. /**
  7235. * A `gantt` series. If the [type](#series.gantt.type) option is not specified,
  7236. * it is inherited from [chart.type](#chart.type).
  7237. *
  7238. * @extends plotOptions.xrange
  7239. * @product gantt
  7240. * @requires highcharts-gantt
  7241. * @optionparent plotOptions.gantt
  7242. */
  7243. GanttSeries.defaultOptions = merge(XRangeSeries.defaultOptions, {
  7244. // options - default options merged with parent
  7245. grouping: false,
  7246. dataLabels: {
  7247. enabled: true
  7248. },
  7249. tooltip: {
  7250. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  7251. pointFormat: null,
  7252. pointFormatter: function () {
  7253. var point = this,
  7254. series = point.series,
  7255. tooltip = series.chart.tooltip,
  7256. xAxis = series.xAxis,
  7257. formats = series.tooltipOptions.dateTimeLabelFormats,
  7258. startOfWeek = xAxis.options.startOfWeek,
  7259. ttOptions = series.tooltipOptions,
  7260. format = ttOptions.xDateFormat,
  7261. start,
  7262. end,
  7263. milestone = point.options.milestone,
  7264. retVal = '<b>' + (point.name || point.yCategory) + '</b>';
  7265. if (ttOptions.pointFormat) {
  7266. return point.tooltipFormatter(ttOptions.pointFormat);
  7267. }
  7268. if (!format) {
  7269. format = splat(tooltip.getDateFormat(xAxis.closestPointRange, point.start, startOfWeek, formats))[0];
  7270. }
  7271. start = series.chart.time.dateFormat(format, point.start);
  7272. end = series.chart.time.dateFormat(format, point.end);
  7273. retVal += '<br/>';
  7274. if (!milestone) {
  7275. retVal += 'Start: ' + start + '<br/>';
  7276. retVal += 'End: ' + end + '<br/>';
  7277. }
  7278. else {
  7279. retVal += start + '<br/>';
  7280. }
  7281. return retVal;
  7282. }
  7283. },
  7284. connectors: {
  7285. type: 'simpleConnect',
  7286. /**
  7287. * @declare Highcharts.ConnectorsAnimationOptionsObject
  7288. */
  7289. animation: {
  7290. reversed: true // Dependencies go from child to parent
  7291. },
  7292. startMarker: {
  7293. enabled: true,
  7294. symbol: 'arrow-filled',
  7295. radius: 4,
  7296. fill: '#fa0',
  7297. align: 'left'
  7298. },
  7299. endMarker: {
  7300. enabled: false,
  7301. align: 'right'
  7302. }
  7303. }
  7304. });
  7305. return GanttSeries;
  7306. }(XRangeSeries));
  7307. extend(GanttSeries.prototype, {
  7308. // Keyboard navigation, don't use nearest vertical mode
  7309. keyboardMoveVertical: false,
  7310. pointArrayMap: ['start', 'end', 'y'],
  7311. pointClass: GanttPoint,
  7312. setData: Series.prototype.setData
  7313. });
  7314. SeriesRegistry.registerSeriesType('gantt', GanttSeries);
  7315. /* *
  7316. *
  7317. * Default Export
  7318. *
  7319. * */
  7320. /* *
  7321. *
  7322. * API Options
  7323. *
  7324. * */
  7325. /**
  7326. * A `gantt` series.
  7327. *
  7328. * @extends series,plotOptions.gantt
  7329. * @excluding boostThreshold, connectors, dashStyle, findNearestPointBy,
  7330. * getExtremesFromAll, marker, negativeColor, pointInterval,
  7331. * pointIntervalUnit, pointPlacement, pointStart
  7332. * @product gantt
  7333. * @requires highcharts-gantt
  7334. * @apioption series.gantt
  7335. */
  7336. /**
  7337. * Data for a Gantt series.
  7338. *
  7339. * @declare Highcharts.GanttPointOptionsObject
  7340. * @type {Array<*>}
  7341. * @extends series.xrange.data
  7342. * @excluding className, connect, dataLabels, events,
  7343. * partialFill, selected, x, x2
  7344. * @product gantt
  7345. * @apioption series.gantt.data
  7346. */
  7347. /**
  7348. * Whether the grid node belonging to this point should start as collapsed. Used
  7349. * in axes of type treegrid.
  7350. *
  7351. * @sample {gantt} gantt/treegrid-axis/collapsed/
  7352. * Start as collapsed
  7353. *
  7354. * @type {boolean}
  7355. * @default false
  7356. * @product gantt
  7357. * @apioption series.gantt.data.collapsed
  7358. */
  7359. /**
  7360. * The start time of a task.
  7361. *
  7362. * @type {number}
  7363. * @product gantt
  7364. * @apioption series.gantt.data.start
  7365. */
  7366. /**
  7367. * The end time of a task.
  7368. *
  7369. * @type {number}
  7370. * @product gantt
  7371. * @apioption series.gantt.data.end
  7372. */
  7373. /**
  7374. * The Y value of a task.
  7375. *
  7376. * @type {number}
  7377. * @product gantt
  7378. * @apioption series.gantt.data.y
  7379. */
  7380. /**
  7381. * The name of a task. If a `treegrid` y-axis is used (default in Gantt charts),
  7382. * this will be picked up automatically, and used to calculate the y-value.
  7383. *
  7384. * @type {string}
  7385. * @product gantt
  7386. * @apioption series.gantt.data.name
  7387. */
  7388. /**
  7389. * Progress indicator, how much of the task completed. If it is a number, the
  7390. * `fill` will be applied automatically.
  7391. *
  7392. * @sample {gantt} gantt/demo/progress-indicator
  7393. * Progress indicator
  7394. *
  7395. * @type {number|*}
  7396. * @extends series.xrange.data.partialFill
  7397. * @product gantt
  7398. * @apioption series.gantt.data.completed
  7399. */
  7400. /**
  7401. * The amount of the progress indicator, ranging from 0 (not started) to 1
  7402. * (finished).
  7403. *
  7404. * @type {number}
  7405. * @default 0
  7406. * @apioption series.gantt.data.completed.amount
  7407. */
  7408. /**
  7409. * The fill of the progress indicator. Defaults to a darkened variety of the
  7410. * main color.
  7411. *
  7412. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7413. * @apioption series.gantt.data.completed.fill
  7414. */
  7415. /**
  7416. * The ID of the point (task) that this point depends on in Gantt charts.
  7417. * Aliases [connect](series.xrange.data.connect). Can also be an object,
  7418. * specifying further connecting [options](series.gantt.connectors) between the
  7419. * points. Multiple connections can be specified by providing an array.
  7420. *
  7421. * @sample gantt/demo/project-management
  7422. * Dependencies
  7423. * @sample gantt/pathfinder/demo
  7424. * Different connection types
  7425. *
  7426. * @type {string|Array<string|*>|*}
  7427. * @extends series.xrange.data.connect
  7428. * @since 6.2.0
  7429. * @product gantt
  7430. * @apioption series.gantt.data.dependency
  7431. */
  7432. /**
  7433. * Whether this point is a milestone. If so, only the `start` option is handled,
  7434. * while `end` is ignored.
  7435. *
  7436. * @sample gantt/gantt/milestones
  7437. * Milestones
  7438. *
  7439. * @type {boolean}
  7440. * @since 6.2.0
  7441. * @product gantt
  7442. * @apioption series.gantt.data.milestone
  7443. */
  7444. /**
  7445. * The ID of the parent point (task) of this point in Gantt charts.
  7446. *
  7447. * @sample gantt/demo/subtasks
  7448. * Gantt chart with subtasks
  7449. *
  7450. * @type {string}
  7451. * @since 6.2.0
  7452. * @product gantt
  7453. * @apioption series.gantt.data.parent
  7454. */
  7455. /**
  7456. * @excluding afterAnimate
  7457. * @apioption series.gantt.events
  7458. */
  7459. ''; // adds doclets above to the transpiled file
  7460. return GanttSeries;
  7461. });
  7462. _registerModule(_modules, 'Core/Chart/GanttChart.js', [_modules['Core/Chart/Chart.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Utilities.js']], function (Chart, D, U) {
  7463. /* *
  7464. *
  7465. * (c) 2016-2021 Highsoft AS
  7466. *
  7467. * Author: Lars A. V. Cabrera
  7468. *
  7469. * License: www.highcharts.com/license
  7470. *
  7471. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7472. *
  7473. * */
  7474. var __extends = (this && this.__extends) || (function () {
  7475. var extendStatics = function (d,
  7476. b) {
  7477. extendStatics = Object.setPrototypeOf ||
  7478. ({ __proto__: [] } instanceof Array && function (d,
  7479. b) { d.__proto__ = b; }) ||
  7480. function (d,
  7481. b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7482. return extendStatics(d, b);
  7483. };
  7484. return function (d, b) {
  7485. extendStatics(d, b);
  7486. function __() { this.constructor = d; }
  7487. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  7488. };
  7489. })();
  7490. var getOptions = D.getOptions;
  7491. var isArray = U.isArray,
  7492. merge = U.merge,
  7493. splat = U.splat;
  7494. /* *
  7495. *
  7496. * Class
  7497. *
  7498. * */
  7499. /**
  7500. * Gantt-optimized chart. Use {@link Highcharts.Chart|Chart} for common charts.
  7501. *
  7502. * @requires modules/gantt
  7503. *
  7504. * @class
  7505. * @name Highcharts.GanttChart
  7506. * @extends Highcharts.Chart
  7507. */
  7508. var GanttChart = /** @class */ (function (_super) {
  7509. __extends(GanttChart, _super);
  7510. function GanttChart() {
  7511. return _super !== null && _super.apply(this, arguments) || this;
  7512. }
  7513. /**
  7514. * Initializes the chart. The constructor's arguments are passed on
  7515. * directly.
  7516. *
  7517. * @function Highcharts.GanttChart#init
  7518. *
  7519. * @param {Highcharts.Options} userOptions
  7520. * Custom options.
  7521. *
  7522. * @param {Function} [callback]
  7523. * Function to run when the chart has loaded and and all external
  7524. * images are loaded.
  7525. *
  7526. * @return {void}
  7527. *
  7528. * @fires Highcharts.GanttChart#event:init
  7529. * @fires Highcharts.GanttChart#event:afterInit
  7530. */
  7531. GanttChart.prototype.init = function (userOptions, callback) {
  7532. var defaultOptions = getOptions(),
  7533. xAxisOptions = userOptions.xAxis,
  7534. yAxisOptions = userOptions.yAxis;
  7535. var defaultLinkedTo;
  7536. // Avoid doing these twice
  7537. userOptions.xAxis = userOptions.yAxis = void 0;
  7538. var options = merge(true, {
  7539. chart: {
  7540. type: 'gantt'
  7541. },
  7542. title: {
  7543. text: null
  7544. },
  7545. legend: {
  7546. enabled: false
  7547. },
  7548. navigator: {
  7549. series: { type: 'gantt' },
  7550. // Bars were clipped, #14060.
  7551. yAxis: {
  7552. type: 'category'
  7553. }
  7554. }
  7555. },
  7556. userOptions, // user's options
  7557. // forced options
  7558. {
  7559. isGantt: true
  7560. });
  7561. userOptions.xAxis = xAxisOptions;
  7562. userOptions.yAxis = yAxisOptions;
  7563. // apply X axis options to both single and multi x axes
  7564. // If user hasn't defined axes as array, make it into an array and add a
  7565. // second axis by default.
  7566. options.xAxis = (!isArray(userOptions.xAxis) ?
  7567. [userOptions.xAxis || {}, {}] :
  7568. userOptions.xAxis).map(function (xAxisOptions, i) {
  7569. if (i === 1) { // Second xAxis
  7570. defaultLinkedTo = 0;
  7571. }
  7572. return merge(defaultOptions.xAxis, {
  7573. grid: {
  7574. enabled: true
  7575. },
  7576. opposite: true,
  7577. linkedTo: defaultLinkedTo
  7578. }, xAxisOptions, // user options
  7579. {
  7580. type: 'datetime'
  7581. });
  7582. });
  7583. // apply Y axis options to both single and multi y axes
  7584. options.yAxis = (splat(userOptions.yAxis || {})).map(function (yAxisOptions) {
  7585. return merge(defaultOptions.yAxis, // #3802
  7586. {
  7587. grid: {
  7588. enabled: true
  7589. },
  7590. staticScale: 50,
  7591. reversed: true,
  7592. // Set default type treegrid, but only if 'categories' is
  7593. // undefined
  7594. type: yAxisOptions.categories ? yAxisOptions.type : 'treegrid'
  7595. }, yAxisOptions // user options
  7596. );
  7597. });
  7598. _super.prototype.init.call(this, options, callback);
  7599. };
  7600. return GanttChart;
  7601. }(Chart));
  7602. /* eslint-disable valid-jsdoc */
  7603. (function (GanttChart) {
  7604. /**
  7605. * The factory function for creating new gantt charts. Creates a new {@link
  7606. * Highcharts.GanttChart|GanttChart} object with different default options
  7607. * than the basic Chart.
  7608. *
  7609. * @example
  7610. * // Render a chart in to div#container
  7611. * let chart = Highcharts.ganttChart('container', {
  7612. * title: {
  7613. * text: 'My chart'
  7614. * },
  7615. * series: [{
  7616. * data: ...
  7617. * }]
  7618. * });
  7619. *
  7620. * @function Highcharts.ganttChart
  7621. *
  7622. * @param {string|Highcharts.HTMLDOMElement} renderTo
  7623. * The DOM element to render to, or its id.
  7624. *
  7625. * @param {Highcharts.Options} options
  7626. * The chart options structure.
  7627. *
  7628. * @param {Highcharts.ChartCallbackFunction} [callback]
  7629. * Function to run when the chart has loaded and and all external
  7630. * images are loaded. Defining a
  7631. * [chart.events.load](https://api.highcharts.com/highcharts/chart.events.load)
  7632. * handler is equivalent.
  7633. *
  7634. * @return {Highcharts.GanttChart}
  7635. * Returns the Chart object.
  7636. */
  7637. function ganttChart(a, b, c) {
  7638. return new GanttChart(a, b, c);
  7639. }
  7640. GanttChart.ganttChart = ganttChart;
  7641. })(GanttChart || (GanttChart = {}));
  7642. return GanttChart;
  7643. });
  7644. _registerModule(_modules, 'Core/Axis/ScrollbarAxis.js', [_modules['Core/Utilities.js']], function (U) {
  7645. /* *
  7646. *
  7647. * (c) 2010-2021 Torstein Honsi
  7648. *
  7649. * License: www.highcharts.com/license
  7650. *
  7651. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7652. *
  7653. * */
  7654. var addEvent = U.addEvent,
  7655. defined = U.defined,
  7656. pick = U.pick;
  7657. /* *
  7658. *
  7659. * Composition
  7660. *
  7661. * */
  7662. /* eslint-disable no-invalid-this, valid-jsdoc */
  7663. /**
  7664. * Creates scrollbars if enabled.
  7665. * @private
  7666. */
  7667. var ScrollbarAxis = /** @class */ (function () {
  7668. function ScrollbarAxis() {
  7669. }
  7670. /**
  7671. * Attaches to axis events to create scrollbars if enabled.
  7672. *
  7673. * @private
  7674. *
  7675. * @param AxisClass
  7676. * Axis class to extend.
  7677. *
  7678. * @param ScrollbarClass
  7679. * Scrollbar class to use.
  7680. */
  7681. ScrollbarAxis.compose = function (AxisClass, ScrollbarClass) {
  7682. var getExtremes = function (axis) {
  7683. var axisMin = pick(axis.options && axis.options.min, axis.min);
  7684. var axisMax = pick(axis.options && axis.options.max,
  7685. axis.max);
  7686. return {
  7687. axisMin: axisMin,
  7688. axisMax: axisMax,
  7689. scrollMin: defined(axis.dataMin) ?
  7690. Math.min(axisMin, axis.min, axis.dataMin, pick(axis.threshold, Infinity)) : axisMin,
  7691. scrollMax: defined(axis.dataMax) ?
  7692. Math.max(axisMax, axis.max, axis.dataMax, pick(axis.threshold, -Infinity)) : axisMax
  7693. };
  7694. };
  7695. // Wrap axis initialization and create scrollbar if enabled:
  7696. addEvent(AxisClass, 'afterInit', function () {
  7697. var axis = this;
  7698. if (axis.options &&
  7699. axis.options.scrollbar &&
  7700. axis.options.scrollbar.enabled) {
  7701. // Predefined options:
  7702. axis.options.scrollbar.vertical = !axis.horiz;
  7703. axis.options.startOnTick = axis.options.endOnTick = false;
  7704. axis.scrollbar = new ScrollbarClass(axis.chart.renderer, axis.options.scrollbar, axis.chart);
  7705. addEvent(axis.scrollbar, 'changed', function (e) {
  7706. var _a = getExtremes(axis),
  7707. axisMin = _a.axisMin,
  7708. axisMax = _a.axisMax,
  7709. unitedMin = _a.scrollMin,
  7710. unitedMax = _a.scrollMax,
  7711. range = unitedMax - unitedMin,
  7712. to,
  7713. from;
  7714. // #12834, scroll when show/hide series, wrong extremes
  7715. if (!defined(axisMin) || !defined(axisMax)) {
  7716. return;
  7717. }
  7718. if ((axis.horiz && !axis.reversed) ||
  7719. (!axis.horiz && axis.reversed)) {
  7720. to = unitedMin + range * this.to;
  7721. from = unitedMin + range * this.from;
  7722. }
  7723. else {
  7724. // y-values in browser are reversed, but this also
  7725. // applies for reversed horizontal axis:
  7726. to = unitedMin + range * (1 - this.from);
  7727. from = unitedMin + range * (1 - this.to);
  7728. }
  7729. if (this.shouldUpdateExtremes(e.DOMType)) {
  7730. axis.setExtremes(from, to, true, e.DOMType !== 'mousemove' && e.DOMType !== 'touchmove', e);
  7731. }
  7732. else {
  7733. // When live redraw is disabled, don't change extremes
  7734. // Only change the position of the scollbar thumb
  7735. this.setRange(this.from, this.to);
  7736. }
  7737. });
  7738. }
  7739. });
  7740. // Wrap rendering axis, and update scrollbar if one is created:
  7741. addEvent(AxisClass, 'afterRender', function () {
  7742. var axis = this,
  7743. _a = getExtremes(axis),
  7744. scrollMin = _a.scrollMin,
  7745. scrollMax = _a.scrollMax,
  7746. scrollbar = axis.scrollbar,
  7747. offset = axis.axisTitleMargin + (axis.titleOffset || 0),
  7748. scrollbarsOffsets = axis.chart.scrollbarsOffsets,
  7749. axisMargin = axis.options.margin || 0,
  7750. offsetsIndex,
  7751. from,
  7752. to;
  7753. if (scrollbar) {
  7754. if (axis.horiz) {
  7755. // Reserve space for labels/title
  7756. if (!axis.opposite) {
  7757. scrollbarsOffsets[1] += offset;
  7758. }
  7759. scrollbar.position(axis.left, axis.top + axis.height + 2 + scrollbarsOffsets[1] -
  7760. (axis.opposite ? axisMargin : 0), axis.width, axis.height);
  7761. // Next scrollbar should reserve space for margin (if set)
  7762. if (!axis.opposite) {
  7763. scrollbarsOffsets[1] += axisMargin;
  7764. }
  7765. offsetsIndex = 1;
  7766. }
  7767. else {
  7768. // Reserve space for labels/title
  7769. if (axis.opposite) {
  7770. scrollbarsOffsets[0] += offset;
  7771. }
  7772. scrollbar.position(axis.left + axis.width + 2 + scrollbarsOffsets[0] -
  7773. (axis.opposite ? 0 : axisMargin), axis.top, axis.width, axis.height);
  7774. // Next scrollbar should reserve space for margin (if set)
  7775. if (axis.opposite) {
  7776. scrollbarsOffsets[0] += axisMargin;
  7777. }
  7778. offsetsIndex = 0;
  7779. }
  7780. scrollbarsOffsets[offsetsIndex] += scrollbar.size +
  7781. scrollbar.options.margin;
  7782. if (isNaN(scrollMin) ||
  7783. isNaN(scrollMax) ||
  7784. !defined(axis.min) ||
  7785. !defined(axis.max) ||
  7786. axis.min === axis.max // #10733
  7787. ) {
  7788. // default action: when extremes are the same or there is
  7789. // not extremes on the axis, but scrollbar exists, make it
  7790. // full size
  7791. scrollbar.setRange(0, 1);
  7792. }
  7793. else {
  7794. from =
  7795. (axis.min - scrollMin) / (scrollMax - scrollMin);
  7796. to =
  7797. (axis.max - scrollMin) / (scrollMax - scrollMin);
  7798. if ((axis.horiz && !axis.reversed) ||
  7799. (!axis.horiz && axis.reversed)) {
  7800. scrollbar.setRange(from, to);
  7801. }
  7802. else {
  7803. // inverse vertical axis
  7804. scrollbar.setRange(1 - to, 1 - from);
  7805. }
  7806. }
  7807. }
  7808. });
  7809. // Make space for a scrollbar:
  7810. addEvent(AxisClass, 'afterGetOffset', function () {
  7811. var axis = this,
  7812. index = axis.horiz ? 2 : 1,
  7813. scrollbar = axis.scrollbar;
  7814. if (scrollbar) {
  7815. axis.chart.scrollbarsOffsets = [0, 0]; // reset scrollbars offsets
  7816. axis.chart.axisOffset[index] +=
  7817. scrollbar.size + scrollbar.options.margin;
  7818. }
  7819. });
  7820. return AxisClass;
  7821. };
  7822. return ScrollbarAxis;
  7823. }());
  7824. return ScrollbarAxis;
  7825. });
  7826. _registerModule(_modules, 'Core/ScrollbarDefaults.js', [_modules['Core/Globals.js'], _modules['Core/Color/Palette.js']], function (H, Palette) {
  7827. /* *
  7828. *
  7829. * (c) 2010-2021 Torstein Honsi
  7830. *
  7831. * License: www.highcharts.com/license
  7832. *
  7833. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7834. *
  7835. * */
  7836. var isTouchDevice = H.isTouchDevice;
  7837. /* *
  7838. *
  7839. * Constant
  7840. *
  7841. * */
  7842. /**
  7843. *
  7844. * The scrollbar is a means of panning over the X axis of a stock chart.
  7845. * Scrollbars can also be applied to other types of axes.
  7846. *
  7847. * Another approach to scrollable charts is the [chart.scrollablePlotArea](
  7848. * https://api.highcharts.com/highcharts/chart.scrollablePlotArea) option that
  7849. * is especially suitable for simpler cartesian charts on mobile.
  7850. *
  7851. * In styled mode, all the presentational options for the
  7852. * scrollbar are replaced by the classes `.highcharts-scrollbar-thumb`,
  7853. * `.highcharts-scrollbar-arrow`, `.highcharts-scrollbar-button`,
  7854. * `.highcharts-scrollbar-rifles` and `.highcharts-scrollbar-track`.
  7855. *
  7856. * @sample stock/yaxis/inverted-bar-scrollbar/
  7857. * A scrollbar on a simple bar chart
  7858. *
  7859. * @product highstock gantt
  7860. * @optionparent scrollbar
  7861. *
  7862. * @private
  7863. */
  7864. var ScrollbarDefaults = {
  7865. /**
  7866. * The height of the scrollbar. The height also applies to the width
  7867. * of the scroll arrows so that they are always squares. Defaults to
  7868. * 20 for touch devices and 14 for mouse devices.
  7869. *
  7870. * @sample stock/scrollbar/height/
  7871. * A 30px scrollbar
  7872. *
  7873. * @type {number}
  7874. * @default 20/14
  7875. */
  7876. height: isTouchDevice ? 20 : 14,
  7877. /**
  7878. * The border rounding radius of the bar.
  7879. *
  7880. * @sample stock/scrollbar/style/
  7881. * Scrollbar styling
  7882. */
  7883. barBorderRadius: 0,
  7884. /**
  7885. * The corner radius of the scrollbar buttons.
  7886. *
  7887. * @sample stock/scrollbar/style/
  7888. * Scrollbar styling
  7889. */
  7890. buttonBorderRadius: 0,
  7891. /**
  7892. * Enable or disable the scrollbar.
  7893. *
  7894. * @sample stock/scrollbar/enabled/
  7895. * Disable the scrollbar,
  7896. only use navigator
  7897. *
  7898. * @type {boolean}
  7899. * @default true
  7900. * @apioption scrollbar.enabled
  7901. */
  7902. /**
  7903. * Whether to redraw the main chart as the scrollbar or the navigator
  7904. * zoomed window is moved. Defaults to `true` for modern browsers and
  7905. * `false` for legacy IE browsers as well as mobile devices.
  7906. *
  7907. * @sample stock/scrollbar/liveredraw
  7908. * Setting live redraw to false
  7909. *
  7910. * @type {boolean}
  7911. * @since 1.3
  7912. */
  7913. liveRedraw: void 0,
  7914. /**
  7915. * The margin between the scrollbar and its axis when the scrollbar is
  7916. * applied directly to an axis.
  7917. */
  7918. margin: 10,
  7919. /**
  7920. * The minimum width of the scrollbar.
  7921. *
  7922. * @since 1.2.5
  7923. */
  7924. minWidth: 6,
  7925. /**
  7926. * Whether to show or hide the scrollbar when the scrolled content is
  7927. * zoomed out to it full extent.
  7928. *
  7929. * @type {boolean}
  7930. * @default true
  7931. * @apioption scrollbar.showFull
  7932. */
  7933. step: 0.2,
  7934. /**
  7935. * The z index of the scrollbar group.
  7936. */
  7937. zIndex: 3,
  7938. /**
  7939. * The background color of the scrollbar itself.
  7940. *
  7941. * @sample stock/scrollbar/style/
  7942. * Scrollbar styling
  7943. *
  7944. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7945. */
  7946. barBackgroundColor: Palette.neutralColor20,
  7947. /**
  7948. * The width of the bar's border.
  7949. *
  7950. * @sample stock/scrollbar/style/
  7951. * Scrollbar styling
  7952. */
  7953. barBorderWidth: 1,
  7954. /**
  7955. * The color of the scrollbar's border.
  7956. *
  7957. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7958. */
  7959. barBorderColor: Palette.neutralColor20,
  7960. /**
  7961. * The color of the small arrow inside the scrollbar buttons.
  7962. *
  7963. * @sample stock/scrollbar/style/
  7964. * Scrollbar styling
  7965. *
  7966. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7967. */
  7968. buttonArrowColor: Palette.neutralColor80,
  7969. /**
  7970. * The color of scrollbar buttons.
  7971. *
  7972. * @sample stock/scrollbar/style/
  7973. * Scrollbar styling
  7974. *
  7975. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7976. */
  7977. buttonBackgroundColor: Palette.neutralColor10,
  7978. /**
  7979. * The color of the border of the scrollbar buttons.
  7980. *
  7981. * @sample stock/scrollbar/style/
  7982. * Scrollbar styling
  7983. *
  7984. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7985. */
  7986. buttonBorderColor: Palette.neutralColor20,
  7987. /**
  7988. * The border width of the scrollbar buttons.
  7989. *
  7990. * @sample stock/scrollbar/style/
  7991. * Scrollbar styling
  7992. */
  7993. buttonBorderWidth: 1,
  7994. /**
  7995. * The color of the small rifles in the middle of the scrollbar.
  7996. *
  7997. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  7998. */
  7999. rifleColor: Palette.neutralColor80,
  8000. /**
  8001. * The color of the track background.
  8002. *
  8003. * @sample stock/scrollbar/style/
  8004. * Scrollbar styling
  8005. *
  8006. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8007. */
  8008. trackBackgroundColor: Palette.neutralColor5,
  8009. /**
  8010. * The color of the border of the scrollbar track.
  8011. *
  8012. * @sample stock/scrollbar/style/
  8013. * Scrollbar styling
  8014. *
  8015. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8016. */
  8017. trackBorderColor: Palette.neutralColor5,
  8018. /**
  8019. * The corner radius of the border of the scrollbar track.
  8020. *
  8021. * @sample stock/scrollbar/style/
  8022. * Scrollbar styling
  8023. *
  8024. * @type {number}
  8025. * @default 0
  8026. * @apioption scrollbar.trackBorderRadius
  8027. */
  8028. /**
  8029. * The width of the border of the scrollbar track.
  8030. *
  8031. * @sample stock/scrollbar/style/
  8032. * Scrollbar styling
  8033. */
  8034. trackBorderWidth: 1
  8035. };
  8036. /* *
  8037. *
  8038. * Default Export
  8039. *
  8040. * */
  8041. return ScrollbarDefaults;
  8042. });
  8043. _registerModule(_modules, 'Core/Scrollbar.js', [_modules['Core/DefaultOptions.js'], _modules['Core/Globals.js'], _modules['Core/Axis/ScrollbarAxis.js'], _modules['Core/ScrollbarDefaults.js'], _modules['Core/Utilities.js']], function (D, H, ScrollbarAxis, ScrollbarDefaults, U) {
  8044. /* *
  8045. *
  8046. * (c) 2010-2021 Torstein Honsi
  8047. *
  8048. * License: www.highcharts.com/license
  8049. *
  8050. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8051. *
  8052. * */
  8053. var defaultOptions = D.defaultOptions;
  8054. var addEvent = U.addEvent,
  8055. correctFloat = U.correctFloat,
  8056. defined = U.defined,
  8057. destroyObjectProperties = U.destroyObjectProperties,
  8058. fireEvent = U.fireEvent,
  8059. merge = U.merge,
  8060. pick = U.pick,
  8061. removeEvent = U.removeEvent;
  8062. /* *
  8063. *
  8064. * Constants
  8065. *
  8066. * */
  8067. /* eslint-disable no-invalid-this, valid-jsdoc */
  8068. /**
  8069. * A reusable scrollbar, internally used in Highcharts Stock's
  8070. * navigator and optionally on individual axes.
  8071. *
  8072. * @private
  8073. * @class
  8074. * @name Highcharts.Scrollbar
  8075. * @param {Highcharts.SVGRenderer} renderer
  8076. * @param {Highcharts.ScrollbarOptions} options
  8077. * @param {Highcharts.Chart} chart
  8078. */
  8079. var Scrollbar = /** @class */ (function () {
  8080. /* *
  8081. *
  8082. * Constructors
  8083. *
  8084. * */
  8085. function Scrollbar(renderer, options, chart) {
  8086. /* *
  8087. *
  8088. * Properties
  8089. *
  8090. * */
  8091. this._events = [];
  8092. this.chart = void 0;
  8093. this.chartX = 0;
  8094. this.chartY = 0;
  8095. this.from = 0;
  8096. this.group = void 0;
  8097. this.options = void 0;
  8098. this.renderer = void 0;
  8099. this.scrollbar = void 0;
  8100. this.scrollbarButtons = [];
  8101. this.scrollbarGroup = void 0;
  8102. this.scrollbarLeft = 0;
  8103. this.scrollbarRifles = void 0;
  8104. this.scrollbarStrokeWidth = 1;
  8105. this.scrollbarTop = 0;
  8106. this.size = 0;
  8107. this.to = 0;
  8108. this.track = void 0;
  8109. this.trackBorderWidth = 1;
  8110. this.userOptions = void 0;
  8111. this.x = 0;
  8112. this.y = 0;
  8113. this.init(renderer, options, chart);
  8114. }
  8115. /* *
  8116. *
  8117. * Static Functions
  8118. *
  8119. * */
  8120. Scrollbar.compose = function (AxisClass) {
  8121. ScrollbarAxis.compose(AxisClass, Scrollbar);
  8122. };
  8123. /**
  8124. * When we have vertical scrollbar, rifles and arrow in buttons should be
  8125. * rotated. The same method is used in Navigator's handles, to rotate them.
  8126. *
  8127. * @function Highcharts.swapXY
  8128. *
  8129. * @param {Highcharts.SVGPathArray} path
  8130. * Path to be rotated.
  8131. *
  8132. * @param {boolean} [vertical]
  8133. * If vertical scrollbar, swap x-y values.
  8134. *
  8135. * @return {Highcharts.SVGPathArray}
  8136. * Rotated path.
  8137. *
  8138. * @requires modules/stock
  8139. */
  8140. Scrollbar.swapXY = function (path, vertical) {
  8141. if (vertical) {
  8142. path.forEach(function (seg) {
  8143. var len = seg.length;
  8144. var temp;
  8145. for (var i = 0; i < len; i += 2) {
  8146. temp = seg[i + 1];
  8147. if (typeof temp === 'number') {
  8148. seg[i + 1] = seg[i + 2];
  8149. seg[i + 2] = temp;
  8150. }
  8151. }
  8152. });
  8153. }
  8154. return path;
  8155. };
  8156. /* *
  8157. *
  8158. * Functions
  8159. *
  8160. * */
  8161. /**
  8162. * Set up the mouse and touch events for the Scrollbar
  8163. *
  8164. * @private
  8165. * @function Highcharts.Scrollbar#addEvents
  8166. */
  8167. Scrollbar.prototype.addEvents = function () {
  8168. var buttonsOrder = this.options.inverted ? [1, 0] : [0, 1],
  8169. buttons = this.scrollbarButtons,
  8170. bar = this.scrollbarGroup.element,
  8171. track = this.track.element,
  8172. mouseDownHandler = this.mouseDownHandler.bind(this),
  8173. mouseMoveHandler = this.mouseMoveHandler.bind(this),
  8174. mouseUpHandler = this.mouseUpHandler.bind(this);
  8175. // Mouse events
  8176. var _events = [
  8177. [buttons[buttonsOrder[0]].element, 'click',
  8178. this.buttonToMinClick.bind(this)],
  8179. [buttons[buttonsOrder[1]].element, 'click',
  8180. this.buttonToMaxClick.bind(this)],
  8181. [track, 'click',
  8182. this.trackClick.bind(this)],
  8183. [bar, 'mousedown',
  8184. mouseDownHandler],
  8185. [bar.ownerDocument, 'mousemove',
  8186. mouseMoveHandler],
  8187. [bar.ownerDocument, 'mouseup',
  8188. mouseUpHandler]
  8189. ];
  8190. // Touch events
  8191. if (H.hasTouch) {
  8192. _events.push([bar, 'touchstart', mouseDownHandler], [bar.ownerDocument, 'touchmove', mouseMoveHandler], [bar.ownerDocument, 'touchend', mouseUpHandler]);
  8193. }
  8194. // Add them all
  8195. _events.forEach(function (args) {
  8196. addEvent.apply(null, args);
  8197. });
  8198. this._events = _events;
  8199. };
  8200. Scrollbar.prototype.buttonToMaxClick = function (e) {
  8201. var scroller = this;
  8202. var range = (scroller.to - scroller.from) * pick(scroller.options.step, 0.2);
  8203. scroller.updatePosition(scroller.from + range, scroller.to + range);
  8204. fireEvent(scroller, 'changed', {
  8205. from: scroller.from,
  8206. to: scroller.to,
  8207. trigger: 'scrollbar',
  8208. DOMEvent: e
  8209. });
  8210. };
  8211. Scrollbar.prototype.buttonToMinClick = function (e) {
  8212. var scroller = this;
  8213. var range = correctFloat(scroller.to - scroller.from) *
  8214. pick(scroller.options.step, 0.2);
  8215. scroller.updatePosition(correctFloat(scroller.from - range), correctFloat(scroller.to - range));
  8216. fireEvent(scroller, 'changed', {
  8217. from: scroller.from,
  8218. to: scroller.to,
  8219. trigger: 'scrollbar',
  8220. DOMEvent: e
  8221. });
  8222. };
  8223. /**
  8224. * Get normalized (0-1) cursor position over the scrollbar
  8225. *
  8226. * @private
  8227. * @function Highcharts.Scrollbar#cursorToScrollbarPosition
  8228. *
  8229. * @param {*} normalizedEvent
  8230. * normalized event, with chartX and chartY values
  8231. *
  8232. * @return {Highcharts.Dictionary<number>}
  8233. * Local position {chartX, chartY}
  8234. */
  8235. Scrollbar.prototype.cursorToScrollbarPosition = function (normalizedEvent) {
  8236. var scroller = this,
  8237. options = scroller.options,
  8238. minWidthDifference = options.minWidth > scroller.calculatedWidth ?
  8239. options.minWidth :
  8240. 0; // minWidth distorts translation
  8241. return {
  8242. chartX: (normalizedEvent.chartX - scroller.x -
  8243. scroller.xOffset) /
  8244. (scroller.barWidth - minWidthDifference),
  8245. chartY: (normalizedEvent.chartY - scroller.y -
  8246. scroller.yOffset) /
  8247. (scroller.barWidth - minWidthDifference)
  8248. };
  8249. };
  8250. /**
  8251. * Destroys allocated elements.
  8252. *
  8253. * @private
  8254. * @function Highcharts.Scrollbar#destroy
  8255. * @return {void}
  8256. */
  8257. Scrollbar.prototype.destroy = function () {
  8258. var scroller = this,
  8259. navigator = scroller.chart.scroller;
  8260. // Disconnect events added in addEvents
  8261. scroller.removeEvents();
  8262. // Destroy properties
  8263. [
  8264. 'track',
  8265. 'scrollbarRifles',
  8266. 'scrollbar',
  8267. 'scrollbarGroup',
  8268. 'group'
  8269. ].forEach(function (prop) {
  8270. if (scroller[prop] && scroller[prop].destroy) {
  8271. scroller[prop] = scroller[prop].destroy();
  8272. }
  8273. });
  8274. // #6421, chart may have more scrollbars
  8275. if (navigator && scroller === navigator.scrollbar) {
  8276. navigator.scrollbar = null;
  8277. // Destroy elements in collection
  8278. destroyObjectProperties(navigator.scrollbarButtons);
  8279. }
  8280. };
  8281. /**
  8282. * Draw the scrollbar buttons with arrows
  8283. *
  8284. * @private
  8285. * @function Highcharts.Scrollbar#drawScrollbarButton
  8286. * @param {number} index
  8287. * 0 is left, 1 is right
  8288. * @return {void}
  8289. */
  8290. Scrollbar.prototype.drawScrollbarButton = function (index) {
  8291. var scroller = this,
  8292. renderer = scroller.renderer,
  8293. scrollbarButtons = scroller.scrollbarButtons,
  8294. options = scroller.options,
  8295. size = scroller.size,
  8296. group = renderer.g().add(scroller.group);
  8297. var tempElem;
  8298. scrollbarButtons.push(group);
  8299. // Create a rectangle for the scrollbar button
  8300. tempElem = renderer.rect()
  8301. .addClass('highcharts-scrollbar-button')
  8302. .add(group);
  8303. // Presentational attributes
  8304. if (!scroller.chart.styledMode) {
  8305. tempElem.attr({
  8306. stroke: options.buttonBorderColor,
  8307. 'stroke-width': options.buttonBorderWidth,
  8308. fill: options.buttonBackgroundColor
  8309. });
  8310. }
  8311. // Place the rectangle based on the rendered stroke width
  8312. tempElem.attr(tempElem.crisp({
  8313. x: -0.5,
  8314. y: -0.5,
  8315. width: size + 1,
  8316. height: size + 1,
  8317. r: options.buttonBorderRadius
  8318. }, tempElem.strokeWidth()));
  8319. // Button arrow
  8320. tempElem = renderer
  8321. .path(Scrollbar.swapXY([[
  8322. 'M',
  8323. size / 2 + (index ? -1 : 1),
  8324. size / 2 - 3
  8325. ], [
  8326. 'L',
  8327. size / 2 + (index ? -1 : 1),
  8328. size / 2 + 3
  8329. ], [
  8330. 'L',
  8331. size / 2 + (index ? 2 : -2),
  8332. size / 2
  8333. ]], options.vertical))
  8334. .addClass('highcharts-scrollbar-arrow')
  8335. .add(scrollbarButtons[index]);
  8336. if (!scroller.chart.styledMode) {
  8337. tempElem.attr({
  8338. fill: options.buttonArrowColor
  8339. });
  8340. }
  8341. };
  8342. /**
  8343. * @private
  8344. * @function Highcharts.Scrollbar#init
  8345. * @param {Highcharts.SVGRenderer} renderer
  8346. * @param {Highcharts.ScrollbarOptions} options
  8347. * @param {Highcharts.Chart} chart
  8348. */
  8349. Scrollbar.prototype.init = function (renderer, options, chart) {
  8350. var scroller = this;
  8351. scroller.scrollbarButtons = [];
  8352. scroller.renderer = renderer;
  8353. scroller.userOptions = options;
  8354. scroller.options = merge(ScrollbarDefaults, defaultOptions.scrollbar, options);
  8355. scroller.chart = chart;
  8356. // backward compatibility
  8357. scroller.size = pick(scroller.options.size, scroller.options.height);
  8358. // Init
  8359. if (options.enabled) {
  8360. scroller.render();
  8361. scroller.addEvents();
  8362. }
  8363. };
  8364. Scrollbar.prototype.mouseDownHandler = function (e) {
  8365. var scroller = this,
  8366. normalizedEvent = scroller.chart.pointer.normalize(e),
  8367. mousePosition = scroller.cursorToScrollbarPosition(normalizedEvent);
  8368. scroller.chartX = mousePosition.chartX;
  8369. scroller.chartY = mousePosition.chartY;
  8370. scroller.initPositions = [scroller.from, scroller.to];
  8371. scroller.grabbedCenter = true;
  8372. };
  8373. /**
  8374. * Event handler for the mouse move event.
  8375. * @private
  8376. */
  8377. Scrollbar.prototype.mouseMoveHandler = function (e) {
  8378. var scroller = this,
  8379. normalizedEvent = scroller.chart.pointer.normalize(e),
  8380. options = scroller.options,
  8381. direction = options.vertical ? 'chartY' : 'chartX',
  8382. initPositions = scroller.initPositions || [];
  8383. var scrollPosition,
  8384. chartPosition,
  8385. change;
  8386. // In iOS, a mousemove event with e.pageX === 0 is fired when
  8387. // holding the finger down in the center of the scrollbar. This
  8388. // should be ignored.
  8389. if (scroller.grabbedCenter &&
  8390. // #4696, scrollbar failed on Android
  8391. (!e.touches || e.touches[0][direction] !== 0)) {
  8392. chartPosition = scroller.cursorToScrollbarPosition(normalizedEvent)[direction];
  8393. scrollPosition = scroller[direction];
  8394. change = chartPosition - scrollPosition;
  8395. scroller.hasDragged = true;
  8396. scroller.updatePosition(initPositions[0] + change, initPositions[1] + change);
  8397. if (scroller.hasDragged) {
  8398. fireEvent(scroller, 'changed', {
  8399. from: scroller.from,
  8400. to: scroller.to,
  8401. trigger: 'scrollbar',
  8402. DOMType: e.type,
  8403. DOMEvent: e
  8404. });
  8405. }
  8406. }
  8407. };
  8408. /**
  8409. * Event handler for the mouse up event.
  8410. * @private
  8411. */
  8412. Scrollbar.prototype.mouseUpHandler = function (e) {
  8413. var scroller = this;
  8414. if (scroller.hasDragged) {
  8415. fireEvent(scroller, 'changed', {
  8416. from: scroller.from,
  8417. to: scroller.to,
  8418. trigger: 'scrollbar',
  8419. DOMType: e.type,
  8420. DOMEvent: e
  8421. });
  8422. }
  8423. scroller.grabbedCenter =
  8424. scroller.hasDragged =
  8425. scroller.chartX =
  8426. scroller.chartY = null;
  8427. };
  8428. /**
  8429. * Position the scrollbar, method called from a parent with defined
  8430. * dimensions.
  8431. *
  8432. * @private
  8433. * @function Highcharts.Scrollbar#position
  8434. * @param {number} x
  8435. * x-position on the chart
  8436. * @param {number} y
  8437. * y-position on the chart
  8438. * @param {number} width
  8439. * width of the scrollbar
  8440. * @param {number} height
  8441. * height of the scorllbar
  8442. * @return {void}
  8443. */
  8444. Scrollbar.prototype.position = function (x, y, width, height) {
  8445. var scroller = this,
  8446. options = scroller.options,
  8447. vertical = options.vertical,
  8448. method = scroller.rendered ? 'animate' : 'attr';
  8449. var xOffset = height,
  8450. yOffset = 0;
  8451. scroller.x = x;
  8452. scroller.y = y + this.trackBorderWidth;
  8453. scroller.width = width; // width with buttons
  8454. scroller.height = height;
  8455. scroller.xOffset = xOffset;
  8456. scroller.yOffset = yOffset;
  8457. // If Scrollbar is a vertical type, swap options:
  8458. if (vertical) {
  8459. scroller.width = scroller.yOffset = width = yOffset = scroller.size;
  8460. scroller.xOffset = xOffset = 0;
  8461. scroller.barWidth = height - width * 2; // width without buttons
  8462. scroller.x = x = x + scroller.options.margin;
  8463. }
  8464. else {
  8465. scroller.height = scroller.xOffset = height = xOffset =
  8466. scroller.size;
  8467. scroller.barWidth = width - height * 2; // width without buttons
  8468. scroller.y = scroller.y + scroller.options.margin;
  8469. }
  8470. // Set general position for a group:
  8471. scroller.group[method]({
  8472. translateX: x,
  8473. translateY: scroller.y
  8474. });
  8475. // Resize background/track:
  8476. scroller.track[method]({
  8477. width: width,
  8478. height: height
  8479. });
  8480. // Move right/bottom button ot it's place:
  8481. scroller.scrollbarButtons[1][method]({
  8482. translateX: vertical ? 0 : width - xOffset,
  8483. translateY: vertical ? height - yOffset : 0
  8484. });
  8485. };
  8486. /**
  8487. * Removes the event handlers attached previously with addEvents.
  8488. *
  8489. * @private
  8490. * @function Highcharts.Scrollbar#removeEvents
  8491. * @return {void}
  8492. */
  8493. Scrollbar.prototype.removeEvents = function () {
  8494. this._events.forEach(function (args) {
  8495. removeEvent.apply(null, args);
  8496. });
  8497. this._events.length = 0;
  8498. };
  8499. /**
  8500. * Render scrollbar with all required items.
  8501. *
  8502. * @private
  8503. * @function Highcharts.Scrollbar#render
  8504. */
  8505. Scrollbar.prototype.render = function () {
  8506. var scroller = this,
  8507. renderer = scroller.renderer,
  8508. options = scroller.options,
  8509. size = scroller.size,
  8510. styledMode = scroller.chart.styledMode,
  8511. group = renderer.g('scrollbar').attr({
  8512. zIndex: options.zIndex,
  8513. translateY: -99999
  8514. }).add();
  8515. // Draw the scrollbar group
  8516. scroller.group = group;
  8517. // Draw the scrollbar track:
  8518. scroller.track = renderer.rect()
  8519. .addClass('highcharts-scrollbar-track')
  8520. .attr({
  8521. x: 0,
  8522. r: options.trackBorderRadius || 0,
  8523. height: size,
  8524. width: size
  8525. }).add(group);
  8526. if (!styledMode) {
  8527. scroller.track.attr({
  8528. fill: options.trackBackgroundColor,
  8529. stroke: options.trackBorderColor,
  8530. 'stroke-width': options.trackBorderWidth
  8531. });
  8532. }
  8533. scroller.trackBorderWidth = scroller.track.strokeWidth();
  8534. scroller.track.attr({
  8535. y: -this.trackBorderWidth % 2 / 2
  8536. });
  8537. // Draw the scrollbar itself
  8538. scroller.scrollbarGroup = renderer.g().add(group);
  8539. scroller.scrollbar = renderer.rect()
  8540. .addClass('highcharts-scrollbar-thumb')
  8541. .attr({
  8542. height: size,
  8543. width: size,
  8544. r: options.barBorderRadius || 0
  8545. }).add(scroller.scrollbarGroup);
  8546. scroller.scrollbarRifles = renderer
  8547. .path(Scrollbar.swapXY([
  8548. ['M', -3, size / 4],
  8549. ['L', -3, 2 * size / 3],
  8550. ['M', 0, size / 4],
  8551. ['L', 0, 2 * size / 3],
  8552. ['M', 3, size / 4],
  8553. ['L', 3, 2 * size / 3]
  8554. ], options.vertical))
  8555. .addClass('highcharts-scrollbar-rifles')
  8556. .add(scroller.scrollbarGroup);
  8557. if (!styledMode) {
  8558. scroller.scrollbar.attr({
  8559. fill: options.barBackgroundColor,
  8560. stroke: options.barBorderColor,
  8561. 'stroke-width': options.barBorderWidth
  8562. });
  8563. scroller.scrollbarRifles.attr({
  8564. stroke: options.rifleColor,
  8565. 'stroke-width': 1
  8566. });
  8567. }
  8568. scroller.scrollbarStrokeWidth = scroller.scrollbar.strokeWidth();
  8569. scroller.scrollbarGroup.translate(-scroller.scrollbarStrokeWidth % 2 / 2, -scroller.scrollbarStrokeWidth % 2 / 2);
  8570. // Draw the buttons:
  8571. scroller.drawScrollbarButton(0);
  8572. scroller.drawScrollbarButton(1);
  8573. };
  8574. /**
  8575. * Set scrollbar size, with a given scale.
  8576. *
  8577. * @private
  8578. * @function Highcharts.Scrollbar#setRange
  8579. * @param {number} from
  8580. * scale (0-1) where bar should start
  8581. * @param {number} to
  8582. * scale (0-1) where bar should end
  8583. * @return {void}
  8584. */
  8585. Scrollbar.prototype.setRange = function (from, to) {
  8586. var scroller = this,
  8587. options = scroller.options,
  8588. vertical = options.vertical,
  8589. minWidth = options.minWidth,
  8590. fullWidth = scroller.barWidth,
  8591. method = (this.rendered &&
  8592. !this.hasDragged &&
  8593. !(this.chart.navigator && this.chart.navigator.hasDragged)) ? 'animate' : 'attr';
  8594. if (!defined(fullWidth)) {
  8595. return;
  8596. }
  8597. var toPX = fullWidth * Math.min(to, 1);
  8598. var fromPX,
  8599. newSize;
  8600. from = Math.max(from, 0);
  8601. fromPX = Math.ceil(fullWidth * from);
  8602. scroller.calculatedWidth = newSize = correctFloat(toPX - fromPX);
  8603. // We need to recalculate position, if minWidth is used
  8604. if (newSize < minWidth) {
  8605. fromPX = (fullWidth - minWidth + newSize) * from;
  8606. newSize = minWidth;
  8607. }
  8608. var newPos = Math.floor(fromPX + scroller.xOffset + scroller.yOffset);
  8609. var newRiflesPos = newSize / 2 - 0.5; // -0.5 -> rifle line width / 2
  8610. // Store current position:
  8611. scroller.from = from;
  8612. scroller.to = to;
  8613. if (!vertical) {
  8614. scroller.scrollbarGroup[method]({
  8615. translateX: newPos
  8616. });
  8617. scroller.scrollbar[method]({
  8618. width: newSize
  8619. });
  8620. scroller.scrollbarRifles[method]({
  8621. translateX: newRiflesPos
  8622. });
  8623. scroller.scrollbarLeft = newPos;
  8624. scroller.scrollbarTop = 0;
  8625. }
  8626. else {
  8627. scroller.scrollbarGroup[method]({
  8628. translateY: newPos
  8629. });
  8630. scroller.scrollbar[method]({
  8631. height: newSize
  8632. });
  8633. scroller.scrollbarRifles[method]({
  8634. translateY: newRiflesPos
  8635. });
  8636. scroller.scrollbarTop = newPos;
  8637. scroller.scrollbarLeft = 0;
  8638. }
  8639. if (newSize <= 12) {
  8640. scroller.scrollbarRifles.hide();
  8641. }
  8642. else {
  8643. scroller.scrollbarRifles.show(true);
  8644. }
  8645. // Show or hide the scrollbar based on the showFull setting
  8646. if (options.showFull === false) {
  8647. if (from <= 0 && to >= 1) {
  8648. scroller.group.hide();
  8649. }
  8650. else {
  8651. scroller.group.show();
  8652. }
  8653. }
  8654. scroller.rendered = true;
  8655. };
  8656. /**
  8657. * Checks if the extremes should be updated in response to a scrollbar
  8658. * change event.
  8659. *
  8660. * @private
  8661. * @function Highcharts.Scrollbar#shouldUpdateExtremes
  8662. * @param {string} [eventType]
  8663. * @return {boolean}
  8664. */
  8665. Scrollbar.prototype.shouldUpdateExtremes = function (eventType) {
  8666. return (pick(this.options.liveRedraw, H.svg && !H.isTouchDevice && !this.chart.isBoosting) ||
  8667. // Mouseup always should change extremes
  8668. eventType === 'mouseup' ||
  8669. eventType === 'touchend' ||
  8670. // Internal events
  8671. !defined(eventType));
  8672. };
  8673. Scrollbar.prototype.trackClick = function (e) {
  8674. var scroller = this;
  8675. var normalizedEvent = scroller.chart.pointer.normalize(e),
  8676. range = scroller.to - scroller.from,
  8677. top = scroller.y + scroller.scrollbarTop,
  8678. left = scroller.x + scroller.scrollbarLeft;
  8679. if ((scroller.options.vertical && normalizedEvent.chartY > top) ||
  8680. (!scroller.options.vertical && normalizedEvent.chartX > left)) {
  8681. // On the top or on the left side of the track:
  8682. scroller.updatePosition(scroller.from + range, scroller.to + range);
  8683. }
  8684. else {
  8685. // On the bottom or the right side of the track:
  8686. scroller.updatePosition(scroller.from - range, scroller.to - range);
  8687. }
  8688. fireEvent(scroller, 'changed', {
  8689. from: scroller.from,
  8690. to: scroller.to,
  8691. trigger: 'scrollbar',
  8692. DOMEvent: e
  8693. });
  8694. };
  8695. /**
  8696. * Update the scrollbar with new options
  8697. *
  8698. * @private
  8699. * @function Highcharts.Scrollbar#update
  8700. * @param {Highcharts.ScrollbarOptions} options
  8701. */
  8702. Scrollbar.prototype.update = function (options) {
  8703. this.destroy();
  8704. this.init(this.chart.renderer, merge(true, this.options, options), this.chart);
  8705. };
  8706. /**
  8707. * Update position option in the Scrollbar, with normalized 0-1 scale
  8708. *
  8709. * @private
  8710. * @function Highcharts.Scrollbar#updatePosition
  8711. * @param {number} from
  8712. * @param {number} to
  8713. * @return {void}
  8714. */
  8715. Scrollbar.prototype.updatePosition = function (from, to) {
  8716. if (to > 1) {
  8717. from = correctFloat(1 - correctFloat(to - from));
  8718. to = 1;
  8719. }
  8720. if (from < 0) {
  8721. to = correctFloat(to - from);
  8722. from = 0;
  8723. }
  8724. this.from = from;
  8725. this.to = to;
  8726. };
  8727. /* *
  8728. *
  8729. * Static Properties
  8730. *
  8731. * */
  8732. Scrollbar.defaultOptions = ScrollbarDefaults;
  8733. return Scrollbar;
  8734. }());
  8735. /* *
  8736. *
  8737. * Registry
  8738. *
  8739. * */
  8740. defaultOptions.scrollbar = merge(true, Scrollbar.defaultOptions, defaultOptions.scrollbar);
  8741. /* *
  8742. *
  8743. * Default Export
  8744. *
  8745. * */
  8746. return Scrollbar;
  8747. });
  8748. _registerModule(_modules, 'Extensions/RangeSelector.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Color/Palette.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Utilities.js']], function (Axis, Chart, H, D, palette, SVGElement, U) {
  8749. /* *
  8750. *
  8751. * (c) 2010-2021 Torstein Honsi
  8752. *
  8753. * License: www.highcharts.com/license
  8754. *
  8755. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8756. *
  8757. * */
  8758. var defaultOptions = D.defaultOptions;
  8759. var addEvent = U.addEvent,
  8760. createElement = U.createElement,
  8761. css = U.css,
  8762. defined = U.defined,
  8763. destroyObjectProperties = U.destroyObjectProperties,
  8764. discardElement = U.discardElement,
  8765. extend = U.extend,
  8766. find = U.find,
  8767. fireEvent = U.fireEvent,
  8768. isNumber = U.isNumber,
  8769. merge = U.merge,
  8770. objectEach = U.objectEach,
  8771. pad = U.pad,
  8772. pick = U.pick,
  8773. pInt = U.pInt,
  8774. splat = U.splat;
  8775. /**
  8776. * Define the time span for the button
  8777. *
  8778. * @typedef {"all"|"day"|"hour"|"millisecond"|"minute"|"month"|"second"|"week"|"year"|"ytd"} Highcharts.RangeSelectorButtonTypeValue
  8779. */
  8780. /**
  8781. * Callback function to react on button clicks.
  8782. *
  8783. * @callback Highcharts.RangeSelectorClickCallbackFunction
  8784. *
  8785. * @param {global.Event} e
  8786. * Event arguments.
  8787. *
  8788. * @param {boolean|undefined}
  8789. * Return false to cancel the default button event.
  8790. */
  8791. /**
  8792. * Callback function to parse values entered in the input boxes and return a
  8793. * valid JavaScript time as milliseconds since 1970.
  8794. *
  8795. * @callback Highcharts.RangeSelectorParseCallbackFunction
  8796. *
  8797. * @param {string} value
  8798. * Input value to parse.
  8799. *
  8800. * @return {number}
  8801. * Parsed JavaScript time value.
  8802. */
  8803. /* ************************************************************************** *
  8804. * Start Range Selector code *
  8805. * ************************************************************************** */
  8806. extend(defaultOptions, {
  8807. /**
  8808. * The range selector is a tool for selecting ranges to display within
  8809. * the chart. It provides buttons to select preconfigured ranges in
  8810. * the chart, like 1 day, 1 week, 1 month etc. It also provides input
  8811. * boxes where min and max dates can be manually input.
  8812. *
  8813. * @product highstock gantt
  8814. * @optionparent rangeSelector
  8815. */
  8816. rangeSelector: {
  8817. /**
  8818. * Whether to enable all buttons from the start. By default buttons are
  8819. * only enabled if the corresponding time range exists on the X axis,
  8820. * but enabling all buttons allows for dynamically loading different
  8821. * time ranges.
  8822. *
  8823. * @sample {highstock} stock/rangeselector/allbuttonsenabled-true/
  8824. * All buttons enabled
  8825. *
  8826. * @since 2.0.3
  8827. */
  8828. allButtonsEnabled: false,
  8829. /**
  8830. * An array of configuration objects for the buttons.
  8831. *
  8832. * Defaults to:
  8833. * ```js
  8834. * buttons: [{
  8835. * type: 'month',
  8836. * count: 1,
  8837. * text: '1m',
  8838. * title: 'View 1 month'
  8839. * }, {
  8840. * type: 'month',
  8841. * count: 3,
  8842. * text: '3m',
  8843. * title: 'View 3 months'
  8844. * }, {
  8845. * type: 'month',
  8846. * count: 6,
  8847. * text: '6m',
  8848. * title: 'View 6 months'
  8849. * }, {
  8850. * type: 'ytd',
  8851. * text: 'YTD',
  8852. * title: 'View year to date'
  8853. * }, {
  8854. * type: 'year',
  8855. * count: 1,
  8856. * text: '1y',
  8857. * title: 'View 1 year'
  8858. * }, {
  8859. * type: 'all',
  8860. * text: 'All',
  8861. * title: 'View all'
  8862. * }]
  8863. * ```
  8864. *
  8865. * @sample {highstock} stock/rangeselector/datagrouping/
  8866. * Data grouping by buttons
  8867. *
  8868. * @type {Array<*>}
  8869. */
  8870. buttons: void 0,
  8871. /**
  8872. * How many units of the defined type the button should span. If `type`
  8873. * is "month" and `count` is 3, the button spans three months.
  8874. *
  8875. * @type {number}
  8876. * @default 1
  8877. * @apioption rangeSelector.buttons.count
  8878. */
  8879. /**
  8880. * Fires when clicking on the rangeSelector button. One parameter,
  8881. * event, is passed to the function, containing common event
  8882. * information.
  8883. *
  8884. * ```js
  8885. * click: function(e) {
  8886. * console.log(this);
  8887. * }
  8888. * ```
  8889. *
  8890. * Return false to stop default button's click action.
  8891. *
  8892. * @sample {highstock} stock/rangeselector/button-click/
  8893. * Click event on the button
  8894. *
  8895. * @type {Highcharts.RangeSelectorClickCallbackFunction}
  8896. * @apioption rangeSelector.buttons.events.click
  8897. */
  8898. /**
  8899. * Additional range (in milliseconds) added to the end of the calculated
  8900. * time span.
  8901. *
  8902. * @sample {highstock} stock/rangeselector/min-max-offsets/
  8903. * Button offsets
  8904. *
  8905. * @type {number}
  8906. * @default 0
  8907. * @since 6.0.0
  8908. * @apioption rangeSelector.buttons.offsetMax
  8909. */
  8910. /**
  8911. * Additional range (in milliseconds) added to the start of the
  8912. * calculated time span.
  8913. *
  8914. * @sample {highstock} stock/rangeselector/min-max-offsets/
  8915. * Button offsets
  8916. *
  8917. * @type {number}
  8918. * @default 0
  8919. * @since 6.0.0
  8920. * @apioption rangeSelector.buttons.offsetMin
  8921. */
  8922. /**
  8923. * When buttons apply dataGrouping on a series, by default zooming
  8924. * in/out will deselect buttons and unset dataGrouping. Enable this
  8925. * option to keep buttons selected when extremes change.
  8926. *
  8927. * @sample {highstock} stock/rangeselector/preserve-datagrouping/
  8928. * Different preserveDataGrouping settings
  8929. *
  8930. * @type {boolean}
  8931. * @default false
  8932. * @since 6.1.2
  8933. * @apioption rangeSelector.buttons.preserveDataGrouping
  8934. */
  8935. /**
  8936. * A custom data grouping object for each button.
  8937. *
  8938. * @see [series.dataGrouping](#plotOptions.series.dataGrouping)
  8939. *
  8940. * @sample {highstock} stock/rangeselector/datagrouping/
  8941. * Data grouping by range selector buttons
  8942. *
  8943. * @type {*}
  8944. * @extends plotOptions.series.dataGrouping
  8945. * @apioption rangeSelector.buttons.dataGrouping
  8946. */
  8947. /**
  8948. * The text for the button itself.
  8949. *
  8950. * @type {string}
  8951. * @apioption rangeSelector.buttons.text
  8952. */
  8953. /**
  8954. * Explanation for the button, shown as a tooltip on hover, and used by
  8955. * assistive technology.
  8956. *
  8957. * @type {string}
  8958. * @apioption rangeSelector.buttons.title
  8959. */
  8960. /**
  8961. * Defined the time span for the button. Can be one of `millisecond`,
  8962. * `second`, `minute`, `hour`, `day`, `week`, `month`, `year`, `ytd`,
  8963. * and `all`.
  8964. *
  8965. * @type {Highcharts.RangeSelectorButtonTypeValue}
  8966. * @apioption rangeSelector.buttons.type
  8967. */
  8968. /**
  8969. * The space in pixels between the buttons in the range selector.
  8970. */
  8971. buttonSpacing: 5,
  8972. /**
  8973. * Whether to collapse the range selector buttons into a dropdown when
  8974. * there is not enough room to show everything in a single row, instead
  8975. * of dividing the range selector into multiple rows.
  8976. * Can be one of the following:
  8977. * - `always`: Always collapse
  8978. * - `responsive`: Only collapse when there is not enough room
  8979. * - `never`: Never collapse
  8980. *
  8981. * @sample {highstock} stock/rangeselector/dropdown/
  8982. * Dropdown option
  8983. *
  8984. * @validvalue ["always", "responsive", "never"]
  8985. * @since 9.0.0
  8986. */
  8987. dropdown: 'responsive',
  8988. /**
  8989. * Enable or disable the range selector. Default to `true` for stock
  8990. * charts, using the `stockChart` factory.
  8991. *
  8992. * @sample {highstock} stock/rangeselector/enabled/
  8993. * Disable the range selector
  8994. *
  8995. * @type {boolean|undefined}
  8996. * @default {highstock} true
  8997. */
  8998. enabled: void 0,
  8999. /**
  9000. * The vertical alignment of the rangeselector box. Allowed properties
  9001. * are `top`, `middle`, `bottom`.
  9002. *
  9003. * @sample {highstock} stock/rangeselector/vertical-align-middle/
  9004. * Middle
  9005. * @sample {highstock} stock/rangeselector/vertical-align-bottom/
  9006. * Bottom
  9007. *
  9008. * @type {Highcharts.VerticalAlignValue}
  9009. * @since 6.0.0
  9010. */
  9011. verticalAlign: 'top',
  9012. /**
  9013. * A collection of attributes for the buttons. The object takes SVG
  9014. * attributes like `fill`, `stroke`, `stroke-width`, as well as `style`,
  9015. * a collection of CSS properties for the text.
  9016. *
  9017. * The object can also be extended with states, so you can set
  9018. * presentational options for `hover`, `select` or `disabled` button
  9019. * states.
  9020. *
  9021. * CSS styles for the text label.
  9022. *
  9023. * In styled mode, the buttons are styled by the
  9024. * `.highcharts-range-selector-buttons .highcharts-button` rule with its
  9025. * different states.
  9026. *
  9027. * @sample {highstock} stock/rangeselector/styling/
  9028. * Styling the buttons and inputs
  9029. *
  9030. * @type {Highcharts.SVGAttributes}
  9031. */
  9032. buttonTheme: {
  9033. /** @ignore */
  9034. width: 28,
  9035. /** @ignore */
  9036. height: 18,
  9037. /** @ignore */
  9038. padding: 2,
  9039. /** @ignore */
  9040. zIndex: 7 // #484, #852
  9041. },
  9042. /**
  9043. * When the rangeselector is floating, the plot area does not reserve
  9044. * space for it. This opens for positioning anywhere on the chart.
  9045. *
  9046. * @sample {highstock} stock/rangeselector/floating/
  9047. * Placing the range selector between the plot area and the
  9048. * navigator
  9049. *
  9050. * @since 6.0.0
  9051. */
  9052. floating: false,
  9053. /**
  9054. * The x offset of the range selector relative to its horizontal
  9055. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  9056. *
  9057. * @since 6.0.0
  9058. */
  9059. x: 0,
  9060. /**
  9061. * The y offset of the range selector relative to its horizontal
  9062. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  9063. *
  9064. * @since 6.0.0
  9065. */
  9066. y: 0,
  9067. /**
  9068. * Deprecated. The height of the range selector. Currently it is
  9069. * calculated dynamically.
  9070. *
  9071. * @deprecated
  9072. * @type {number|undefined}
  9073. * @since 2.1.9
  9074. */
  9075. height: void 0,
  9076. /**
  9077. * The border color of the date input boxes.
  9078. *
  9079. * @sample {highstock} stock/rangeselector/styling/
  9080. * Styling the buttons and inputs
  9081. *
  9082. * @type {Highcharts.ColorString}
  9083. * @since 1.3.7
  9084. */
  9085. inputBoxBorderColor: 'none',
  9086. /**
  9087. * The pixel height of the date input boxes.
  9088. *
  9089. * @sample {highstock} stock/rangeselector/styling/
  9090. * Styling the buttons and inputs
  9091. *
  9092. * @since 1.3.7
  9093. */
  9094. inputBoxHeight: 17,
  9095. /**
  9096. * The pixel width of the date input boxes. When `undefined`, the width
  9097. * is fitted to the rendered content.
  9098. *
  9099. * @sample {highstock} stock/rangeselector/styling/
  9100. * Styling the buttons and inputs
  9101. *
  9102. * @type {number|undefined}
  9103. * @since 1.3.7
  9104. */
  9105. inputBoxWidth: void 0,
  9106. /**
  9107. * The date format in the input boxes when not selected for editing.
  9108. * Defaults to `%b %e, %Y`.
  9109. *
  9110. * This is used to determine which type of input to show,
  9111. * `datetime-local`, `date` or `time` and falling back to `text` when
  9112. * the browser does not support the input type or the format contains
  9113. * milliseconds.
  9114. *
  9115. * @sample {highstock} stock/rangeselector/input-type/
  9116. * Input types
  9117. * @sample {highstock} stock/rangeselector/input-format/
  9118. * Milliseconds in the range selector
  9119. *
  9120. */
  9121. inputDateFormat: '%b %e, %Y',
  9122. /**
  9123. * A custom callback function to parse values entered in the input boxes
  9124. * and return a valid JavaScript time as milliseconds since 1970.
  9125. * The first argument passed is a value to parse,
  9126. * second is a boolean indicating use of the UTC time.
  9127. *
  9128. * This will only get called for inputs of type `text`. Since v8.2.3,
  9129. * the input type is dynamically determined based on the granularity
  9130. * of the `inputDateFormat` and the browser support.
  9131. *
  9132. * @sample {highstock} stock/rangeselector/input-format/
  9133. * Milliseconds in the range selector
  9134. *
  9135. * @type {Highcharts.RangeSelectorParseCallbackFunction}
  9136. * @since 1.3.3
  9137. */
  9138. inputDateParser: void 0,
  9139. /**
  9140. * The date format in the input boxes when they are selected for
  9141. * editing. This must be a format that is recognized by JavaScript
  9142. * Date.parse.
  9143. *
  9144. * This will only be used for inputs of type `text`. Since v8.2.3,
  9145. * the input type is dynamically determined based on the granularity
  9146. * of the `inputDateFormat` and the browser support.
  9147. *
  9148. * @sample {highstock} stock/rangeselector/input-format/
  9149. * Milliseconds in the range selector
  9150. *
  9151. */
  9152. inputEditDateFormat: '%Y-%m-%d',
  9153. /**
  9154. * Enable or disable the date input boxes.
  9155. */
  9156. inputEnabled: true,
  9157. /**
  9158. * Positioning for the input boxes. Allowed properties are `align`,
  9159. * `x` and `y`.
  9160. *
  9161. * @since 1.2.4
  9162. */
  9163. inputPosition: {
  9164. /**
  9165. * The alignment of the input box. Allowed properties are `left`,
  9166. * `center`, `right`.
  9167. *
  9168. * @sample {highstock} stock/rangeselector/input-button-position/
  9169. * Alignment
  9170. *
  9171. * @type {Highcharts.AlignValue}
  9172. * @since 6.0.0
  9173. */
  9174. align: 'right',
  9175. /**
  9176. * X offset of the input row.
  9177. */
  9178. x: 0,
  9179. /**
  9180. * Y offset of the input row.
  9181. */
  9182. y: 0
  9183. },
  9184. /**
  9185. * The space in pixels between the labels and the date input boxes in
  9186. * the range selector.
  9187. *
  9188. * @since 9.0.0
  9189. */
  9190. inputSpacing: 5,
  9191. /**
  9192. * The index of the button to appear pre-selected.
  9193. *
  9194. * @type {number}
  9195. */
  9196. selected: void 0,
  9197. /**
  9198. * Positioning for the button row.
  9199. *
  9200. * @since 1.2.4
  9201. */
  9202. buttonPosition: {
  9203. /**
  9204. * The alignment of the input box. Allowed properties are `left`,
  9205. * `center`, `right`.
  9206. *
  9207. * @sample {highstock} stock/rangeselector/input-button-position/
  9208. * Alignment
  9209. *
  9210. * @type {Highcharts.AlignValue}
  9211. * @since 6.0.0
  9212. */
  9213. align: 'left',
  9214. /**
  9215. * X offset of the button row.
  9216. */
  9217. x: 0,
  9218. /**
  9219. * Y offset of the button row.
  9220. */
  9221. y: 0
  9222. },
  9223. /**
  9224. * CSS for the HTML inputs in the range selector.
  9225. *
  9226. * In styled mode, the inputs are styled by the
  9227. * `.highcharts-range-input text` rule in SVG mode, and
  9228. * `input.highcharts-range-selector` when active.
  9229. *
  9230. * @sample {highstock} stock/rangeselector/styling/
  9231. * Styling the buttons and inputs
  9232. *
  9233. * @type {Highcharts.CSSObject}
  9234. * @apioption rangeSelector.inputStyle
  9235. */
  9236. inputStyle: {
  9237. /** @ignore */
  9238. color: palette.highlightColor80,
  9239. /** @ignore */
  9240. cursor: 'pointer'
  9241. },
  9242. /**
  9243. * CSS styles for the labels - the Zoom, From and To texts.
  9244. *
  9245. * In styled mode, the labels are styled by the
  9246. * `.highcharts-range-label` class.
  9247. *
  9248. * @sample {highstock} stock/rangeselector/styling/
  9249. * Styling the buttons and inputs
  9250. *
  9251. * @type {Highcharts.CSSObject}
  9252. */
  9253. labelStyle: {
  9254. /** @ignore */
  9255. color: palette.neutralColor60
  9256. }
  9257. }
  9258. });
  9259. extend(defaultOptions.lang,
  9260. /**
  9261. * Language object. The language object is global and it can't be set
  9262. * on each chart initialization. Instead, use `Highcharts.setOptions` to
  9263. * set it before any chart is initialized.
  9264. *
  9265. * ```js
  9266. * Highcharts.setOptions({
  9267. * lang: {
  9268. * months: [
  9269. * 'Janvier', 'Février', 'Mars', 'Avril',
  9270. * 'Mai', 'Juin', 'Juillet', 'Août',
  9271. * 'Septembre', 'Octobre', 'Novembre', 'Décembre'
  9272. * ],
  9273. * weekdays: [
  9274. * 'Dimanche', 'Lundi', 'Mardi', 'Mercredi',
  9275. * 'Jeudi', 'Vendredi', 'Samedi'
  9276. * ]
  9277. * }
  9278. * });
  9279. * ```
  9280. *
  9281. * @optionparent lang
  9282. */
  9283. {
  9284. /**
  9285. * The text for the label for the range selector buttons.
  9286. *
  9287. * @product highstock gantt
  9288. */
  9289. rangeSelectorZoom: 'Zoom',
  9290. /**
  9291. * The text for the label for the "from" input box in the range
  9292. * selector. Since v9.0, this string is empty as the label is not
  9293. * rendered by default.
  9294. *
  9295. * @product highstock gantt
  9296. */
  9297. rangeSelectorFrom: '',
  9298. /**
  9299. * The text for the label for the "to" input box in the range selector.
  9300. *
  9301. * @product highstock gantt
  9302. */
  9303. rangeSelectorTo: '→'
  9304. });
  9305. /* eslint-disable no-invalid-this, valid-jsdoc */
  9306. /**
  9307. * The range selector.
  9308. *
  9309. * @private
  9310. * @class
  9311. * @name Highcharts.RangeSelector
  9312. * @param {Highcharts.Chart} chart
  9313. */
  9314. var RangeSelector = /** @class */ (function () {
  9315. function RangeSelector(chart) {
  9316. /* *
  9317. *
  9318. * Properties
  9319. *
  9320. * */
  9321. this.buttons = void 0;
  9322. this.buttonOptions = RangeSelector.prototype.defaultButtons;
  9323. this.initialButtonGroupWidth = 0;
  9324. this.options = void 0;
  9325. this.chart = chart;
  9326. // Run RangeSelector
  9327. this.init(chart);
  9328. }
  9329. /**
  9330. * The method to run when one of the buttons in the range selectors is
  9331. * clicked
  9332. *
  9333. * @private
  9334. * @function Highcharts.RangeSelector#clickButton
  9335. * @param {number} i
  9336. * The index of the button
  9337. * @param {boolean} [redraw]
  9338. * @return {void}
  9339. */
  9340. RangeSelector.prototype.clickButton = function (i, redraw) {
  9341. var rangeSelector = this,
  9342. chart = rangeSelector.chart,
  9343. rangeOptions = rangeSelector.buttonOptions[i],
  9344. baseAxis = chart.xAxis[0],
  9345. unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || baseAxis || {},
  9346. dataMin = unionExtremes.dataMin,
  9347. dataMax = unionExtremes.dataMax,
  9348. newMin,
  9349. newMax = baseAxis && Math.round(Math.min(baseAxis.max,
  9350. pick(dataMax,
  9351. baseAxis.max))), // #1568
  9352. type = rangeOptions.type,
  9353. baseXAxisOptions,
  9354. range = rangeOptions._range,
  9355. rangeMin,
  9356. minSetting,
  9357. rangeSetting,
  9358. ctx,
  9359. ytdExtremes,
  9360. dataGrouping = rangeOptions.dataGrouping;
  9361. // chart has no data, base series is removed
  9362. if (dataMin === null || dataMax === null) {
  9363. return;
  9364. }
  9365. // Set the fixed range before range is altered
  9366. chart.fixedRange = range;
  9367. rangeSelector.setSelected(i);
  9368. // Apply dataGrouping associated to button
  9369. if (dataGrouping) {
  9370. this.forcedDataGrouping = true;
  9371. Axis.prototype.setDataGrouping.call(baseAxis || { chart: this.chart }, dataGrouping, false);
  9372. this.frozenStates = rangeOptions.preserveDataGrouping;
  9373. }
  9374. // Apply range
  9375. if (type === 'month' || type === 'year') {
  9376. if (!baseAxis) {
  9377. // This is set to the user options and picked up later when the
  9378. // axis is instantiated so that we know the min and max.
  9379. range = rangeOptions;
  9380. }
  9381. else {
  9382. ctx = {
  9383. range: rangeOptions,
  9384. max: newMax,
  9385. chart: chart,
  9386. dataMin: dataMin,
  9387. dataMax: dataMax
  9388. };
  9389. newMin = baseAxis.minFromRange.call(ctx);
  9390. if (isNumber(ctx.newMax)) {
  9391. newMax = ctx.newMax;
  9392. }
  9393. }
  9394. // Fixed times like minutes, hours, days
  9395. }
  9396. else if (range) {
  9397. newMin = Math.max(newMax - range, dataMin);
  9398. newMax = Math.min(newMin + range, dataMax);
  9399. }
  9400. else if (type === 'ytd') {
  9401. // On user clicks on the buttons, or a delayed action running from
  9402. // the beforeRender event (below), the baseAxis is defined.
  9403. if (baseAxis) {
  9404. // When "ytd" is the pre-selected button for the initial view,
  9405. // its calculation is delayed and rerun in the beforeRender
  9406. // event (below). When the series are initialized, but before
  9407. // the chart is rendered, we have access to the xData array
  9408. // (#942).
  9409. if (typeof dataMax === 'undefined') {
  9410. dataMin = Number.MAX_VALUE;
  9411. dataMax = Number.MIN_VALUE;
  9412. chart.series.forEach(function (series) {
  9413. // reassign it to the last item
  9414. var xData = series.xData;
  9415. dataMin = Math.min(xData[0], dataMin);
  9416. dataMax = Math.max(xData[xData.length - 1], dataMax);
  9417. });
  9418. redraw = false;
  9419. }
  9420. ytdExtremes = rangeSelector.getYTDExtremes(dataMax, dataMin, chart.time.useUTC);
  9421. newMin = rangeMin = ytdExtremes.min;
  9422. newMax = ytdExtremes.max;
  9423. // "ytd" is pre-selected. We don't yet have access to processed
  9424. // point and extremes data (things like pointStart and pointInterval
  9425. // are missing), so we delay the process (#942)
  9426. }
  9427. else {
  9428. rangeSelector.deferredYTDClick = i;
  9429. return;
  9430. }
  9431. }
  9432. else if (type === 'all' && baseAxis) {
  9433. // If the navigator exist and the axis range is declared reset that
  9434. // range and from now on only use the range set by a user, #14742.
  9435. if (chart.navigator && chart.navigator.baseSeries[0]) {
  9436. chart.navigator.baseSeries[0].xAxis.options.range = void 0;
  9437. }
  9438. newMin = dataMin;
  9439. newMax = dataMax;
  9440. }
  9441. if (defined(newMin)) {
  9442. newMin += rangeOptions._offsetMin;
  9443. }
  9444. if (defined(newMax)) {
  9445. newMax += rangeOptions._offsetMax;
  9446. }
  9447. if (this.dropdown) {
  9448. this.dropdown.selectedIndex = i + 1;
  9449. }
  9450. // Update the chart
  9451. if (!baseAxis) {
  9452. // Axis not yet instanciated. Temporarily set min and range
  9453. // options and remove them on chart load (#4317).
  9454. baseXAxisOptions = splat(chart.options.xAxis)[0];
  9455. rangeSetting = baseXAxisOptions.range;
  9456. baseXAxisOptions.range = range;
  9457. minSetting = baseXAxisOptions.min;
  9458. baseXAxisOptions.min = rangeMin;
  9459. addEvent(chart, 'load', function resetMinAndRange() {
  9460. baseXAxisOptions.range = rangeSetting;
  9461. baseXAxisOptions.min = minSetting;
  9462. });
  9463. }
  9464. else {
  9465. // Existing axis object. Set extremes after render time.
  9466. baseAxis.setExtremes(newMin, newMax, pick(redraw, true), void 0, // auto animation
  9467. {
  9468. trigger: 'rangeSelectorButton',
  9469. rangeSelectorButton: rangeOptions
  9470. });
  9471. }
  9472. fireEvent(this, 'afterBtnClick');
  9473. };
  9474. /**
  9475. * Set the selected option. This method only sets the internal flag, it
  9476. * doesn't update the buttons or the actual zoomed range.
  9477. *
  9478. * @private
  9479. * @function Highcharts.RangeSelector#setSelected
  9480. * @param {number} [selected]
  9481. * @return {void}
  9482. */
  9483. RangeSelector.prototype.setSelected = function (selected) {
  9484. this.selected = this.options.selected = selected;
  9485. };
  9486. /**
  9487. * Initialize the range selector
  9488. *
  9489. * @private
  9490. * @function Highcharts.RangeSelector#init
  9491. * @param {Highcharts.Chart} chart
  9492. * @return {void}
  9493. */
  9494. RangeSelector.prototype.init = function (chart) {
  9495. var rangeSelector = this,
  9496. options = chart.options.rangeSelector,
  9497. buttonOptions = options.buttons || rangeSelector.defaultButtons.slice(),
  9498. selectedOption = options.selected,
  9499. blurInputs = function () {
  9500. var minInput = rangeSelector.minInput,
  9501. maxInput = rangeSelector.maxInput;
  9502. // #3274 in some case blur is not defined
  9503. if (minInput && minInput.blur) {
  9504. fireEvent(minInput, 'blur');
  9505. }
  9506. if (maxInput && maxInput.blur) {
  9507. fireEvent(maxInput, 'blur');
  9508. }
  9509. };
  9510. rangeSelector.chart = chart;
  9511. rangeSelector.options = options;
  9512. rangeSelector.buttons = [];
  9513. rangeSelector.buttonOptions = buttonOptions;
  9514. this.eventsToUnbind = [];
  9515. this.eventsToUnbind.push(addEvent(chart.container, 'mousedown', blurInputs));
  9516. this.eventsToUnbind.push(addEvent(chart, 'resize', blurInputs));
  9517. // Extend the buttonOptions with actual range
  9518. buttonOptions.forEach(rangeSelector.computeButtonRange);
  9519. // zoomed range based on a pre-selected button index
  9520. if (typeof selectedOption !== 'undefined' &&
  9521. buttonOptions[selectedOption]) {
  9522. this.clickButton(selectedOption, false);
  9523. }
  9524. this.eventsToUnbind.push(addEvent(chart, 'load', function () {
  9525. // If a data grouping is applied to the current button, release it
  9526. // when extremes change
  9527. if (chart.xAxis && chart.xAxis[0]) {
  9528. addEvent(chart.xAxis[0], 'setExtremes', function (e) {
  9529. if (this.max - this.min !==
  9530. chart.fixedRange &&
  9531. e.trigger !== 'rangeSelectorButton' &&
  9532. e.trigger !== 'updatedData' &&
  9533. rangeSelector.forcedDataGrouping &&
  9534. !rangeSelector.frozenStates) {
  9535. this.setDataGrouping(false, false);
  9536. }
  9537. });
  9538. }
  9539. }));
  9540. };
  9541. /**
  9542. * Dynamically update the range selector buttons after a new range has been
  9543. * set
  9544. *
  9545. * @private
  9546. * @function Highcharts.RangeSelector#updateButtonStates
  9547. * @return {void}
  9548. */
  9549. RangeSelector.prototype.updateButtonStates = function () {
  9550. var rangeSelector = this,
  9551. chart = this.chart,
  9552. dropdown = this.dropdown,
  9553. baseAxis = chart.xAxis[0],
  9554. actualRange = Math.round(baseAxis.max - baseAxis.min),
  9555. hasNoData = !baseAxis.hasVisibleSeries,
  9556. day = 24 * 36e5, // A single day in milliseconds
  9557. unionExtremes = (chart.scroller &&
  9558. chart.scroller.getUnionExtremes()) || baseAxis,
  9559. dataMin = unionExtremes.dataMin,
  9560. dataMax = unionExtremes.dataMax,
  9561. ytdExtremes = rangeSelector.getYTDExtremes(dataMax,
  9562. dataMin,
  9563. chart.time.useUTC),
  9564. ytdMin = ytdExtremes.min,
  9565. ytdMax = ytdExtremes.max,
  9566. selected = rangeSelector.selected,
  9567. selectedExists = isNumber(selected),
  9568. allButtonsEnabled = rangeSelector.options.allButtonsEnabled,
  9569. buttons = rangeSelector.buttons;
  9570. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  9571. var range = rangeOptions._range,
  9572. type = rangeOptions.type,
  9573. count = rangeOptions.count || 1,
  9574. button = buttons[i],
  9575. state = 0,
  9576. disable,
  9577. select,
  9578. offsetRange = rangeOptions._offsetMax -
  9579. rangeOptions._offsetMin,
  9580. isSelected = i === selected,
  9581. // Disable buttons where the range exceeds what is allowed in
  9582. // the current view
  9583. isTooGreatRange = range >
  9584. dataMax - dataMin,
  9585. // Disable buttons where the range is smaller than the minimum
  9586. // range
  9587. isTooSmallRange = range < baseAxis.minRange,
  9588. // Do not select the YTD button if not explicitly told so
  9589. isYTDButNotSelected = false,
  9590. // Disable the All button if we're already showing all
  9591. isAllButAlreadyShowingAll = false,
  9592. isSameRange = range === actualRange;
  9593. // Months and years have a variable range so we check the extremes
  9594. if ((type === 'month' || type === 'year') &&
  9595. (actualRange + 36e5 >=
  9596. { month: 28, year: 365 }[type] * day * count - offsetRange) &&
  9597. (actualRange - 36e5 <=
  9598. { month: 31, year: 366 }[type] * day * count + offsetRange)) {
  9599. isSameRange = true;
  9600. }
  9601. else if (type === 'ytd') {
  9602. isSameRange = (ytdMax - ytdMin + offsetRange) === actualRange;
  9603. isYTDButNotSelected = !isSelected;
  9604. }
  9605. else if (type === 'all') {
  9606. isSameRange = (baseAxis.max - baseAxis.min >=
  9607. dataMax - dataMin);
  9608. isAllButAlreadyShowingAll = (!isSelected &&
  9609. selectedExists &&
  9610. isSameRange);
  9611. }
  9612. // The new zoom area happens to match the range for a button - mark
  9613. // it selected. This happens when scrolling across an ordinal gap.
  9614. // It can be seen in the intraday demos when selecting 1h and scroll
  9615. // across the night gap.
  9616. disable = (!allButtonsEnabled &&
  9617. (isTooGreatRange ||
  9618. isTooSmallRange ||
  9619. isAllButAlreadyShowingAll ||
  9620. hasNoData));
  9621. select = ((isSelected && isSameRange) ||
  9622. (isSameRange && !selectedExists && !isYTDButNotSelected) ||
  9623. (isSelected && rangeSelector.frozenStates));
  9624. if (disable) {
  9625. state = 3;
  9626. }
  9627. else if (select) {
  9628. selectedExists = true; // Only one button can be selected
  9629. state = 2;
  9630. }
  9631. // If state has changed, update the button
  9632. if (button.state !== state) {
  9633. button.setState(state);
  9634. if (dropdown) {
  9635. dropdown.options[i + 1].disabled = disable;
  9636. if (state === 2) {
  9637. dropdown.selectedIndex = i + 1;
  9638. }
  9639. }
  9640. // Reset (#9209)
  9641. if (state === 0 && selected === i) {
  9642. rangeSelector.setSelected();
  9643. }
  9644. }
  9645. });
  9646. };
  9647. /**
  9648. * Compute and cache the range for an individual button
  9649. *
  9650. * @private
  9651. * @function Highcharts.RangeSelector#computeButtonRange
  9652. * @param {Highcharts.RangeSelectorButtonsOptions} rangeOptions
  9653. * @return {void}
  9654. */
  9655. RangeSelector.prototype.computeButtonRange = function (rangeOptions) {
  9656. var type = rangeOptions.type,
  9657. count = rangeOptions.count || 1,
  9658. // these time intervals have a fixed number of milliseconds, as
  9659. // opposed to month, ytd and year
  9660. fixedTimes = {
  9661. millisecond: 1,
  9662. second: 1000,
  9663. minute: 60 * 1000,
  9664. hour: 3600 * 1000,
  9665. day: 24 * 3600 * 1000,
  9666. week: 7 * 24 * 3600 * 1000
  9667. };
  9668. // Store the range on the button object
  9669. if (fixedTimes[type]) {
  9670. rangeOptions._range = fixedTimes[type] * count;
  9671. }
  9672. else if (type === 'month' || type === 'year') {
  9673. rangeOptions._range = {
  9674. month: 30,
  9675. year: 365
  9676. }[type] * 24 * 36e5 * count;
  9677. }
  9678. rangeOptions._offsetMin = pick(rangeOptions.offsetMin, 0);
  9679. rangeOptions._offsetMax = pick(rangeOptions.offsetMax, 0);
  9680. rangeOptions._range +=
  9681. rangeOptions._offsetMax - rangeOptions._offsetMin;
  9682. };
  9683. /**
  9684. * Get the unix timestamp of a HTML input for the dates
  9685. *
  9686. * @private
  9687. * @function Highcharts.RangeSelector#getInputValue
  9688. * @param {string} name
  9689. * @return {number}
  9690. */
  9691. RangeSelector.prototype.getInputValue = function (name) {
  9692. var input = name === 'min' ? this.minInput : this.maxInput;
  9693. var options = this.chart.options.rangeSelector;
  9694. var time = this.chart.time;
  9695. if (input) {
  9696. return ((input.type === 'text' && options.inputDateParser) ||
  9697. this.defaultInputDateParser)(input.value, time.useUTC, time);
  9698. }
  9699. return 0;
  9700. };
  9701. /**
  9702. * Set the internal and displayed value of a HTML input for the dates
  9703. *
  9704. * @private
  9705. * @function Highcharts.RangeSelector#setInputValue
  9706. * @param {string} name
  9707. * @param {number} [inputTime]
  9708. * @return {void}
  9709. */
  9710. RangeSelector.prototype.setInputValue = function (name, inputTime) {
  9711. var options = this.options, time = this.chart.time, input = name === 'min' ? this.minInput : this.maxInput, dateBox = name === 'min' ? this.minDateBox : this.maxDateBox;
  9712. if (input) {
  9713. var hcTimeAttr = input.getAttribute('data-hc-time');
  9714. var updatedTime = defined(hcTimeAttr) ? Number(hcTimeAttr) : void 0;
  9715. if (defined(inputTime)) {
  9716. var previousTime = updatedTime;
  9717. if (defined(previousTime)) {
  9718. input.setAttribute('data-hc-time-previous', previousTime);
  9719. }
  9720. input.setAttribute('data-hc-time', inputTime);
  9721. updatedTime = inputTime;
  9722. }
  9723. input.value = time.dateFormat(this.inputTypeFormats[input.type] || options.inputEditDateFormat, updatedTime);
  9724. if (dateBox) {
  9725. dateBox.attr({
  9726. text: time.dateFormat(options.inputDateFormat, updatedTime)
  9727. });
  9728. }
  9729. }
  9730. };
  9731. /**
  9732. * Set the min and max value of a HTML input for the dates
  9733. *
  9734. * @private
  9735. * @function Highcharts.RangeSelector#setInputExtremes
  9736. * @param {string} name
  9737. * @param {number} min
  9738. * @param {number} max
  9739. * @return {void}
  9740. */
  9741. RangeSelector.prototype.setInputExtremes = function (name, min, max) {
  9742. var input = name === 'min' ? this.minInput : this.maxInput;
  9743. if (input) {
  9744. var format = this.inputTypeFormats[input.type];
  9745. var time = this.chart.time;
  9746. if (format) {
  9747. var newMin = time.dateFormat(format,
  9748. min);
  9749. if (input.min !== newMin) {
  9750. input.min = newMin;
  9751. }
  9752. var newMax = time.dateFormat(format,
  9753. max);
  9754. if (input.max !== newMax) {
  9755. input.max = newMax;
  9756. }
  9757. }
  9758. }
  9759. };
  9760. /**
  9761. * @private
  9762. * @function Highcharts.RangeSelector#showInput
  9763. * @param {string} name
  9764. * @return {void}
  9765. */
  9766. RangeSelector.prototype.showInput = function (name) {
  9767. var dateBox = name === 'min' ? this.minDateBox : this.maxDateBox;
  9768. var input = name === 'min' ? this.minInput : this.maxInput;
  9769. if (input && dateBox && this.inputGroup) {
  9770. var isTextInput = input.type === 'text';
  9771. var _a = this.inputGroup,
  9772. translateX = _a.translateX,
  9773. translateY = _a.translateY;
  9774. var inputBoxWidth = this.options.inputBoxWidth;
  9775. css(input, {
  9776. width: isTextInput ? ((dateBox.width + (inputBoxWidth ? -2 : 20)) + 'px') : 'auto',
  9777. height: isTextInput ? ((dateBox.height - 2) + 'px') : 'auto',
  9778. border: '2px solid silver'
  9779. });
  9780. if (isTextInput && inputBoxWidth) {
  9781. css(input, {
  9782. left: (translateX + dateBox.x) + 'px',
  9783. top: translateY + 'px'
  9784. });
  9785. // Inputs of types date, time or datetime-local should be centered
  9786. // on top of the dateBox
  9787. }
  9788. else {
  9789. css(input, {
  9790. left: Math.min(Math.round(dateBox.x +
  9791. translateX -
  9792. (input.offsetWidth - dateBox.width) / 2), this.chart.chartWidth - input.offsetWidth) + 'px',
  9793. top: (translateY - (input.offsetHeight - dateBox.height) / 2) + 'px'
  9794. });
  9795. }
  9796. }
  9797. };
  9798. /**
  9799. * @private
  9800. * @function Highcharts.RangeSelector#hideInput
  9801. * @param {string} name
  9802. * @return {void}
  9803. */
  9804. RangeSelector.prototype.hideInput = function (name) {
  9805. var input = name === 'min' ? this.minInput : this.maxInput;
  9806. if (input) {
  9807. css(input, {
  9808. top: '-9999em',
  9809. border: 0,
  9810. width: '1px',
  9811. height: '1px'
  9812. });
  9813. }
  9814. };
  9815. /**
  9816. * @private
  9817. * @function Highcharts.RangeSelector#defaultInputDateParser
  9818. */
  9819. RangeSelector.prototype.defaultInputDateParser = function (inputDate, useUTC, time) {
  9820. var hasTimezone = function (str) {
  9821. return str.length > 6 &&
  9822. (str.lastIndexOf('-') === str.length - 6 ||
  9823. str.lastIndexOf('+') === str.length - 6);
  9824. };
  9825. var input = inputDate.split('/').join('-').split(' ').join('T');
  9826. if (input.indexOf('T') === -1) {
  9827. input += 'T00:00';
  9828. }
  9829. if (useUTC) {
  9830. input += 'Z';
  9831. }
  9832. else if (H.isSafari && !hasTimezone(input)) {
  9833. var offset = new Date(input).getTimezoneOffset() / 60;
  9834. input += offset <= 0 ? "+" + pad(-offset) + ":00" : "-" + pad(offset) + ":00";
  9835. }
  9836. var date = Date.parse(input);
  9837. // If the value isn't parsed directly to a value by the
  9838. // browser's Date.parse method, like YYYY-MM-DD in IE8, try
  9839. // parsing it a different way
  9840. if (!isNumber(date)) {
  9841. var parts = inputDate.split('-');
  9842. date = Date.UTC(pInt(parts[0]), pInt(parts[1]) - 1, pInt(parts[2]));
  9843. }
  9844. if (time && useUTC && isNumber(date)) {
  9845. date += time.getTimezoneOffset(date);
  9846. }
  9847. return date;
  9848. };
  9849. /**
  9850. * Draw either the 'from' or the 'to' HTML input box of the range selector
  9851. *
  9852. * @private
  9853. * @function Highcharts.RangeSelector#drawInput
  9854. * @param {string} name
  9855. * @return {RangeSelectorInputElements}
  9856. */
  9857. RangeSelector.prototype.drawInput = function (name) {
  9858. var _a = this,
  9859. chart = _a.chart,
  9860. div = _a.div,
  9861. inputGroup = _a.inputGroup;
  9862. var rangeSelector = this,
  9863. chartStyle = chart.renderer.style || {},
  9864. renderer = chart.renderer,
  9865. options = chart.options.rangeSelector,
  9866. lang = defaultOptions.lang,
  9867. isMin = name === 'min';
  9868. /**
  9869. * @private
  9870. */
  9871. function updateExtremes() {
  9872. var value = rangeSelector.getInputValue(name),
  9873. chartAxis = chart.xAxis[0],
  9874. dataAxis = chart.scroller && chart.scroller.xAxis ?
  9875. chart.scroller.xAxis :
  9876. chartAxis,
  9877. dataMin = dataAxis.dataMin,
  9878. dataMax = dataAxis.dataMax;
  9879. var maxInput = rangeSelector.maxInput,
  9880. minInput = rangeSelector.minInput;
  9881. if (value !== Number(input.getAttribute('data-hc-time-previous')) &&
  9882. isNumber(value)) {
  9883. input.setAttribute('data-hc-time-previous', value);
  9884. // Validate the extremes. If it goes beyound the data min or
  9885. // max, use the actual data extreme (#2438).
  9886. if (isMin && maxInput && isNumber(dataMin)) {
  9887. if (value > Number(maxInput.getAttribute('data-hc-time'))) {
  9888. value = void 0;
  9889. }
  9890. else if (value < dataMin) {
  9891. value = dataMin;
  9892. }
  9893. }
  9894. else if (minInput && isNumber(dataMax)) {
  9895. if (value < Number(minInput.getAttribute('data-hc-time'))) {
  9896. value = void 0;
  9897. }
  9898. else if (value > dataMax) {
  9899. value = dataMax;
  9900. }
  9901. }
  9902. // Set the extremes
  9903. if (typeof value !== 'undefined') { // @todo typof undefined
  9904. chartAxis.setExtremes(isMin ? value : chartAxis.min, isMin ? chartAxis.max : value, void 0, void 0, { trigger: 'rangeSelectorInput' });
  9905. }
  9906. }
  9907. }
  9908. // Create the text label
  9909. var text = lang[isMin ? 'rangeSelectorFrom' : 'rangeSelectorTo'];
  9910. var label = renderer
  9911. .label(text, 0)
  9912. .addClass('highcharts-range-label')
  9913. .attr({
  9914. padding: text ? 2 : 0,
  9915. height: text ? options.inputBoxHeight : 0
  9916. })
  9917. .add(inputGroup);
  9918. // Create an SVG label that shows updated date ranges and and records
  9919. // click events that bring in the HTML input.
  9920. var dateBox = renderer
  9921. .label('', 0)
  9922. .addClass('highcharts-range-input')
  9923. .attr({
  9924. padding: 2,
  9925. width: options.inputBoxWidth,
  9926. height: options.inputBoxHeight,
  9927. 'text-align': 'center'
  9928. })
  9929. .on('click',
  9930. function () {
  9931. // If it is already focused, the onfocus event doesn't fire
  9932. // (#3713)
  9933. rangeSelector.showInput(name);
  9934. rangeSelector[name + 'Input'].focus();
  9935. });
  9936. if (!chart.styledMode) {
  9937. dateBox.attr({
  9938. stroke: options.inputBoxBorderColor,
  9939. 'stroke-width': 1
  9940. });
  9941. }
  9942. dateBox.add(inputGroup);
  9943. // Create the HTML input element. This is rendered as 1x1 pixel then set
  9944. // to the right size when focused.
  9945. var input = createElement('input', {
  9946. name: name,
  9947. className: 'highcharts-range-selector'
  9948. },
  9949. void 0,
  9950. div);
  9951. // #14788: Setting input.type to an unsupported type throws in IE, so
  9952. // we need to use setAttribute instead
  9953. input.setAttribute('type', preferredInputType(options.inputDateFormat || '%b %e, %Y'));
  9954. if (!chart.styledMode) {
  9955. // Styles
  9956. label.css(merge(chartStyle, options.labelStyle));
  9957. dateBox.css(merge({
  9958. color: palette.neutralColor80
  9959. }, chartStyle, options.inputStyle));
  9960. css(input, extend({
  9961. position: 'absolute',
  9962. border: 0,
  9963. boxShadow: '0 0 15px rgba(0,0,0,0.3)',
  9964. width: '1px',
  9965. height: '1px',
  9966. padding: 0,
  9967. textAlign: 'center',
  9968. fontSize: chartStyle.fontSize,
  9969. fontFamily: chartStyle.fontFamily,
  9970. top: '-9999em' // #4798
  9971. }, options.inputStyle));
  9972. }
  9973. // Blow up the input box
  9974. input.onfocus = function () {
  9975. rangeSelector.showInput(name);
  9976. };
  9977. // Hide away the input box
  9978. input.onblur = function () {
  9979. // update extermes only when inputs are active
  9980. if (input === H.doc.activeElement) { // Only when focused
  9981. // Update also when no `change` event is triggered, like when
  9982. // clicking inside the SVG (#4710)
  9983. updateExtremes();
  9984. }
  9985. // #10404 - move hide and blur outside focus
  9986. rangeSelector.hideInput(name);
  9987. rangeSelector.setInputValue(name);
  9988. input.blur(); // #4606
  9989. };
  9990. var keyDown = false;
  9991. // handle changes in the input boxes
  9992. input.onchange = function () {
  9993. // Update extremes and blur input when clicking date input calendar
  9994. if (!keyDown) {
  9995. updateExtremes();
  9996. rangeSelector.hideInput(name);
  9997. input.blur();
  9998. }
  9999. };
  10000. input.onkeypress = function (event) {
  10001. // IE does not fire onchange on enter
  10002. if (event.keyCode === 13) {
  10003. updateExtremes();
  10004. }
  10005. };
  10006. input.onkeydown = function (event) {
  10007. keyDown = true;
  10008. // Arrow keys
  10009. if (event.keyCode === 38 || event.keyCode === 40) {
  10010. updateExtremes();
  10011. }
  10012. };
  10013. input.onkeyup = function () {
  10014. keyDown = false;
  10015. };
  10016. return { dateBox: dateBox, input: input, label: label };
  10017. };
  10018. /**
  10019. * Get the position of the range selector buttons and inputs. This can be
  10020. * overridden from outside for custom positioning.
  10021. *
  10022. * @private
  10023. * @function Highcharts.RangeSelector#getPosition
  10024. *
  10025. * @return {Highcharts.Dictionary<number>}
  10026. */
  10027. RangeSelector.prototype.getPosition = function () {
  10028. var chart = this.chart,
  10029. options = chart.options.rangeSelector,
  10030. top = options.verticalAlign === 'top' ?
  10031. chart.plotTop - chart.axisOffset[0] :
  10032. 0; // set offset only for varticalAlign top
  10033. return {
  10034. buttonTop: top + options.buttonPosition.y,
  10035. inputTop: top + options.inputPosition.y - 10
  10036. };
  10037. };
  10038. /**
  10039. * Get the extremes of YTD. Will choose dataMax if its value is lower than
  10040. * the current timestamp. Will choose dataMin if its value is higher than
  10041. * the timestamp for the start of current year.
  10042. *
  10043. * @private
  10044. * @function Highcharts.RangeSelector#getYTDExtremes
  10045. *
  10046. * @param {number} dataMax
  10047. *
  10048. * @param {number} dataMin
  10049. *
  10050. * @return {*}
  10051. * Returns min and max for the YTD
  10052. */
  10053. RangeSelector.prototype.getYTDExtremes = function (dataMax, dataMin, useUTC) {
  10054. var time = this.chart.time,
  10055. min,
  10056. now = new time.Date(dataMax),
  10057. year = time.get('FullYear',
  10058. now),
  10059. startOfYear = useUTC ?
  10060. time.Date.UTC(year, 0, 1) : // eslint-disable-line new-cap
  10061. +new time.Date(year, 0, 1);
  10062. min = Math.max(dataMin, startOfYear);
  10063. var ts = now.getTime();
  10064. return {
  10065. max: Math.min(dataMax || ts, ts),
  10066. min: min
  10067. };
  10068. };
  10069. /**
  10070. * Render the range selector including the buttons and the inputs. The first
  10071. * time render is called, the elements are created and positioned. On
  10072. * subsequent calls, they are moved and updated.
  10073. *
  10074. * @private
  10075. * @function Highcharts.RangeSelector#render
  10076. * @param {number} [min]
  10077. * X axis minimum
  10078. * @param {number} [max]
  10079. * X axis maximum
  10080. * @return {void}
  10081. */
  10082. RangeSelector.prototype.render = function (min, max) {
  10083. var chart = this.chart,
  10084. renderer = chart.renderer,
  10085. container = chart.container,
  10086. chartOptions = chart.options,
  10087. options = chartOptions.rangeSelector,
  10088. // Place inputs above the container
  10089. inputsZIndex = pick(chartOptions.chart.style &&
  10090. chartOptions.chart.style.zIndex, 0) + 1,
  10091. inputEnabled = options.inputEnabled,
  10092. rendered = this.rendered;
  10093. if (options.enabled === false) {
  10094. return;
  10095. }
  10096. // create the elements
  10097. if (!rendered) {
  10098. this.group = renderer.g('range-selector-group')
  10099. .attr({
  10100. zIndex: 7
  10101. })
  10102. .add();
  10103. this.div = createElement('div', void 0, {
  10104. position: 'relative',
  10105. height: 0,
  10106. zIndex: inputsZIndex
  10107. });
  10108. if (this.buttonOptions.length) {
  10109. this.renderButtons();
  10110. }
  10111. // First create a wrapper outside the container in order to make
  10112. // the inputs work and make export correct
  10113. if (container.parentNode) {
  10114. container.parentNode.insertBefore(this.div, container);
  10115. }
  10116. if (inputEnabled) {
  10117. // Create the group to keep the inputs
  10118. this.inputGroup = renderer.g('input-group').add(this.group);
  10119. var minElems = this.drawInput('min');
  10120. this.minDateBox = minElems.dateBox;
  10121. this.minLabel = minElems.label;
  10122. this.minInput = minElems.input;
  10123. var maxElems = this.drawInput('max');
  10124. this.maxDateBox = maxElems.dateBox;
  10125. this.maxLabel = maxElems.label;
  10126. this.maxInput = maxElems.input;
  10127. }
  10128. }
  10129. if (inputEnabled) {
  10130. // Set or reset the input values
  10131. this.setInputValue('min', min);
  10132. this.setInputValue('max', max);
  10133. var unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || chart.xAxis[0] || {};
  10134. if (defined(unionExtremes.dataMin) && defined(unionExtremes.dataMax)) {
  10135. var minRange = chart.xAxis[0].minRange || 0;
  10136. this.setInputExtremes('min', unionExtremes.dataMin, Math.min(unionExtremes.dataMax, this.getInputValue('max')) - minRange);
  10137. this.setInputExtremes('max', Math.max(unionExtremes.dataMin, this.getInputValue('min')) + minRange, unionExtremes.dataMax);
  10138. }
  10139. // Reflow
  10140. if (this.inputGroup) {
  10141. var x_1 = 0;
  10142. [
  10143. this.minLabel,
  10144. this.minDateBox,
  10145. this.maxLabel,
  10146. this.maxDateBox
  10147. ].forEach(function (label) {
  10148. if (label) {
  10149. var width = label.getBBox().width;
  10150. if (width) {
  10151. label.attr({ x: x_1 });
  10152. x_1 += width + options.inputSpacing;
  10153. }
  10154. }
  10155. });
  10156. }
  10157. }
  10158. this.alignElements();
  10159. this.rendered = true;
  10160. };
  10161. /**
  10162. * Render the range buttons. This only runs the first time, later the
  10163. * positioning is laid out in alignElements.
  10164. *
  10165. * @private
  10166. * @function Highcharts.RangeSelector#renderButtons
  10167. * @return {void}
  10168. */
  10169. RangeSelector.prototype.renderButtons = function () {
  10170. var _this = this;
  10171. var _a = this,
  10172. buttons = _a.buttons,
  10173. chart = _a.chart,
  10174. options = _a.options;
  10175. var lang = defaultOptions.lang;
  10176. var renderer = chart.renderer;
  10177. var buttonTheme = merge(options.buttonTheme);
  10178. var states = buttonTheme && buttonTheme.states;
  10179. // Prevent the button from resetting the width when the button state
  10180. // changes since we need more control over the width when collapsing
  10181. // the buttons
  10182. var width = buttonTheme.width || 28;
  10183. delete buttonTheme.width;
  10184. delete buttonTheme.states;
  10185. this.buttonGroup = renderer.g('range-selector-buttons').add(this.group);
  10186. var dropdown = this.dropdown = createElement('select',
  10187. void 0, {
  10188. position: 'absolute',
  10189. width: '1px',
  10190. height: '1px',
  10191. padding: 0,
  10192. border: 0,
  10193. top: '-9999em',
  10194. cursor: 'pointer',
  10195. opacity: 0.0001
  10196. },
  10197. this.div);
  10198. // Prevent page zoom on iPhone
  10199. addEvent(dropdown, 'touchstart', function () {
  10200. dropdown.style.fontSize = '16px';
  10201. });
  10202. // Forward events from select to button
  10203. [
  10204. [H.isMS ? 'mouseover' : 'mouseenter'],
  10205. [H.isMS ? 'mouseout' : 'mouseleave'],
  10206. ['change', 'click']
  10207. ].forEach(function (_a) {
  10208. var from = _a[0],
  10209. to = _a[1];
  10210. addEvent(dropdown, from, function () {
  10211. var button = buttons[_this.currentButtonIndex()];
  10212. if (button) {
  10213. fireEvent(button.element, to || from);
  10214. }
  10215. });
  10216. });
  10217. this.zoomText = renderer
  10218. .label((lang && lang.rangeSelectorZoom) || '', 0)
  10219. .attr({
  10220. padding: options.buttonTheme.padding,
  10221. height: options.buttonTheme.height,
  10222. paddingLeft: 0,
  10223. paddingRight: 0
  10224. })
  10225. .add(this.buttonGroup);
  10226. if (!this.chart.styledMode) {
  10227. this.zoomText.css(options.labelStyle);
  10228. buttonTheme['stroke-width'] = pick(buttonTheme['stroke-width'], 0);
  10229. }
  10230. createElement('option', {
  10231. textContent: this.zoomText.textStr,
  10232. disabled: true
  10233. }, void 0, dropdown);
  10234. this.buttonOptions.forEach(function (rangeOptions, i) {
  10235. createElement('option', {
  10236. textContent: rangeOptions.title || rangeOptions.text
  10237. }, void 0, dropdown);
  10238. buttons[i] = renderer
  10239. .button(rangeOptions.text, 0, 0, function (e) {
  10240. // extract events from button object and call
  10241. var buttonEvents = (rangeOptions.events &&
  10242. rangeOptions.events.click),
  10243. callDefaultEvent;
  10244. if (buttonEvents) {
  10245. callDefaultEvent =
  10246. buttonEvents.call(rangeOptions, e);
  10247. }
  10248. if (callDefaultEvent !== false) {
  10249. _this.clickButton(i);
  10250. }
  10251. _this.isActive = true;
  10252. }, buttonTheme, states && states.hover, states && states.select, states && states.disabled)
  10253. .attr({
  10254. 'text-align': 'center',
  10255. width: width
  10256. })
  10257. .add(_this.buttonGroup);
  10258. if (rangeOptions.title) {
  10259. buttons[i].attr('title', rangeOptions.title);
  10260. }
  10261. });
  10262. };
  10263. /**
  10264. * Align the elements horizontally and vertically.
  10265. *
  10266. * @private
  10267. * @function Highcharts.RangeSelector#alignElements
  10268. * @return {void}
  10269. */
  10270. RangeSelector.prototype.alignElements = function () {
  10271. var _this = this;
  10272. var _a = this,
  10273. buttonGroup = _a.buttonGroup,
  10274. buttons = _a.buttons,
  10275. chart = _a.chart,
  10276. group = _a.group,
  10277. inputGroup = _a.inputGroup,
  10278. options = _a.options,
  10279. zoomText = _a.zoomText;
  10280. var chartOptions = chart.options;
  10281. var navButtonOptions = (chartOptions.exporting &&
  10282. chartOptions.exporting.enabled !== false &&
  10283. chartOptions.navigation &&
  10284. chartOptions.navigation.buttonOptions);
  10285. var buttonPosition = options.buttonPosition,
  10286. inputPosition = options.inputPosition,
  10287. verticalAlign = options.verticalAlign;
  10288. // Get the X offset required to avoid overlapping with the exporting
  10289. // button. This is is used both by the buttonGroup and the inputGroup.
  10290. var getXOffsetForExportButton = function (group,
  10291. position) {
  10292. if (navButtonOptions &&
  10293. _this.titleCollision(chart) &&
  10294. verticalAlign === 'top' &&
  10295. position.align === 'right' && ((position.y -
  10296. group.getBBox().height - 12) <
  10297. ((navButtonOptions.y || 0) +
  10298. (navButtonOptions.height || 0) +
  10299. chart.spacing[0]))) {
  10300. return -40;
  10301. }
  10302. return 0;
  10303. };
  10304. var plotLeft = chart.plotLeft;
  10305. if (group && buttonPosition && inputPosition) {
  10306. var translateX = buttonPosition.x - chart.spacing[3];
  10307. if (buttonGroup) {
  10308. this.positionButtons();
  10309. if (!this.initialButtonGroupWidth) {
  10310. var width_1 = 0;
  10311. if (zoomText) {
  10312. width_1 += zoomText.getBBox().width + 5;
  10313. }
  10314. buttons.forEach(function (button, i) {
  10315. width_1 += button.width;
  10316. if (i !== buttons.length - 1) {
  10317. width_1 += options.buttonSpacing;
  10318. }
  10319. });
  10320. this.initialButtonGroupWidth = width_1;
  10321. }
  10322. plotLeft -= chart.spacing[3];
  10323. this.updateButtonStates();
  10324. // Detect collision between button group and exporting
  10325. var xOffsetForExportButton_1 = getXOffsetForExportButton(buttonGroup,
  10326. buttonPosition);
  10327. this.alignButtonGroup(xOffsetForExportButton_1);
  10328. // Skip animation
  10329. group.placed = buttonGroup.placed = chart.hasLoaded;
  10330. }
  10331. var xOffsetForExportButton = 0;
  10332. if (inputGroup) {
  10333. // Detect collision between the input group and exporting button
  10334. xOffsetForExportButton = getXOffsetForExportButton(inputGroup, inputPosition);
  10335. if (inputPosition.align === 'left') {
  10336. translateX = plotLeft;
  10337. }
  10338. else if (inputPosition.align === 'right') {
  10339. translateX = -Math.max(chart.axisOffset[1], -xOffsetForExportButton);
  10340. }
  10341. // Update the alignment to the updated spacing box
  10342. inputGroup.align({
  10343. y: inputPosition.y,
  10344. width: inputGroup.getBBox().width,
  10345. align: inputPosition.align,
  10346. // fix wrong getBBox() value on right align
  10347. x: inputPosition.x + translateX - 2
  10348. }, true, chart.spacingBox);
  10349. // Skip animation
  10350. inputGroup.placed = chart.hasLoaded;
  10351. }
  10352. this.handleCollision(xOffsetForExportButton);
  10353. // Vertical align
  10354. group.align({
  10355. verticalAlign: verticalAlign
  10356. }, true, chart.spacingBox);
  10357. var alignTranslateY = group.alignAttr.translateY;
  10358. // Set position
  10359. var groupHeight = group.getBBox().height + 20; // # 20 padding
  10360. var translateY = 0;
  10361. // Calculate bottom position
  10362. if (verticalAlign === 'bottom') {
  10363. var legendOptions = chart.legend && chart.legend.options;
  10364. var legendHeight = (legendOptions &&
  10365. legendOptions.verticalAlign === 'bottom' &&
  10366. legendOptions.enabled &&
  10367. !legendOptions.floating ?
  10368. (chart.legend.legendHeight +
  10369. pick(legendOptions.margin, 10)) :
  10370. 0);
  10371. groupHeight = groupHeight + legendHeight - 20;
  10372. translateY = (alignTranslateY -
  10373. groupHeight -
  10374. (options.floating ? 0 : options.y) -
  10375. (chart.titleOffset ? chart.titleOffset[2] : 0) -
  10376. 10 // 10 spacing
  10377. );
  10378. }
  10379. if (verticalAlign === 'top') {
  10380. if (options.floating) {
  10381. translateY = 0;
  10382. }
  10383. if (chart.titleOffset && chart.titleOffset[0]) {
  10384. translateY = chart.titleOffset[0];
  10385. }
  10386. translateY += ((chart.margin[0] - chart.spacing[0]) || 0);
  10387. }
  10388. else if (verticalAlign === 'middle') {
  10389. if (inputPosition.y === buttonPosition.y) {
  10390. translateY = alignTranslateY;
  10391. }
  10392. else if (inputPosition.y || buttonPosition.y) {
  10393. if (inputPosition.y < 0 ||
  10394. buttonPosition.y < 0) {
  10395. translateY -= Math.min(inputPosition.y, buttonPosition.y);
  10396. }
  10397. else {
  10398. translateY = alignTranslateY - groupHeight;
  10399. }
  10400. }
  10401. }
  10402. group.translate(options.x, options.y + Math.floor(translateY));
  10403. // Translate HTML inputs
  10404. var _b = this,
  10405. minInput = _b.minInput,
  10406. maxInput = _b.maxInput,
  10407. dropdown = _b.dropdown;
  10408. if (options.inputEnabled && minInput && maxInput) {
  10409. minInput.style.marginTop = group.translateY + 'px';
  10410. maxInput.style.marginTop = group.translateY + 'px';
  10411. }
  10412. if (dropdown) {
  10413. dropdown.style.marginTop = group.translateY + 'px';
  10414. }
  10415. }
  10416. };
  10417. /**
  10418. * Align the button group horizontally and vertically.
  10419. *
  10420. * @private
  10421. * @function Highcharts.RangeSelector#alignButtonGroup
  10422. * @param {number} xOffsetForExportButton
  10423. * @param {number} [width]
  10424. * @return {void}
  10425. */
  10426. RangeSelector.prototype.alignButtonGroup = function (xOffsetForExportButton, width) {
  10427. var _a = this,
  10428. chart = _a.chart,
  10429. options = _a.options,
  10430. buttonGroup = _a.buttonGroup,
  10431. buttons = _a.buttons;
  10432. var buttonPosition = options.buttonPosition;
  10433. var plotLeft = chart.plotLeft - chart.spacing[3];
  10434. var translateX = buttonPosition.x - chart.spacing[3];
  10435. if (buttonPosition.align === 'right') {
  10436. translateX += xOffsetForExportButton - plotLeft; // #13014
  10437. }
  10438. else if (buttonPosition.align === 'center') {
  10439. translateX -= plotLeft / 2;
  10440. }
  10441. if (buttonGroup) {
  10442. // Align button group
  10443. buttonGroup.align({
  10444. y: buttonPosition.y,
  10445. width: pick(width, this.initialButtonGroupWidth),
  10446. align: buttonPosition.align,
  10447. x: translateX
  10448. }, true, chart.spacingBox);
  10449. }
  10450. };
  10451. /**
  10452. * @private
  10453. * @function Highcharts.RangeSelector#positionButtons
  10454. * @return {void}
  10455. */
  10456. RangeSelector.prototype.positionButtons = function () {
  10457. var _a = this,
  10458. buttons = _a.buttons,
  10459. chart = _a.chart,
  10460. options = _a.options,
  10461. zoomText = _a.zoomText;
  10462. var verb = chart.hasLoaded ? 'animate' : 'attr';
  10463. var buttonPosition = options.buttonPosition;
  10464. var plotLeft = chart.plotLeft;
  10465. var buttonLeft = plotLeft;
  10466. if (zoomText && zoomText.visibility !== 'hidden') {
  10467. // #8769, allow dynamically updating margins
  10468. zoomText[verb]({
  10469. x: pick(plotLeft + buttonPosition.x, plotLeft)
  10470. });
  10471. // Button start position
  10472. buttonLeft += buttonPosition.x +
  10473. zoomText.getBBox().width + 5;
  10474. }
  10475. this.buttonOptions.forEach(function (rangeOptions, i) {
  10476. if (buttons[i].visibility !== 'hidden') {
  10477. buttons[i][verb]({ x: buttonLeft });
  10478. // increase button position for the next button
  10479. buttonLeft += buttons[i].width + options.buttonSpacing;
  10480. }
  10481. else {
  10482. buttons[i][verb]({ x: plotLeft });
  10483. }
  10484. });
  10485. };
  10486. /**
  10487. * Handle collision between the button group and the input group
  10488. *
  10489. * @private
  10490. * @function Highcharts.RangeSelector#handleCollision
  10491. *
  10492. * @param {number} xOffsetForExportButton
  10493. * The X offset of the group required to make room for the
  10494. * exporting button
  10495. * @return {void}
  10496. */
  10497. RangeSelector.prototype.handleCollision = function (xOffsetForExportButton) {
  10498. var _this = this;
  10499. var _a = this,
  10500. chart = _a.chart,
  10501. buttonGroup = _a.buttonGroup,
  10502. inputGroup = _a.inputGroup;
  10503. var _b = this.options,
  10504. buttonPosition = _b.buttonPosition,
  10505. dropdown = _b.dropdown,
  10506. inputPosition = _b.inputPosition;
  10507. var maxButtonWidth = function () {
  10508. var buttonWidth = 0;
  10509. _this.buttons.forEach(function (button) {
  10510. var bBox = button.getBBox();
  10511. if (bBox.width > buttonWidth) {
  10512. buttonWidth = bBox.width;
  10513. }
  10514. });
  10515. return buttonWidth;
  10516. };
  10517. var groupsOverlap = function (buttonGroupWidth) {
  10518. if (inputGroup && buttonGroup) {
  10519. var inputGroupX = (inputGroup.alignAttr.translateX +
  10520. inputGroup.alignOptions.x -
  10521. xOffsetForExportButton +
  10522. // getBBox for detecing left margin
  10523. inputGroup.getBBox().x +
  10524. // 2px padding to not overlap input and label
  10525. 2);
  10526. var inputGroupWidth = inputGroup.alignOptions.width;
  10527. var buttonGroupX = buttonGroup.alignAttr.translateX +
  10528. buttonGroup.getBBox().x;
  10529. return (buttonGroupX + buttonGroupWidth > inputGroupX) &&
  10530. (inputGroupX + inputGroupWidth > buttonGroupX) &&
  10531. (buttonPosition.y <
  10532. (inputPosition.y +
  10533. inputGroup.getBBox().height));
  10534. }
  10535. return false;
  10536. };
  10537. var moveInputsDown = function () {
  10538. if (inputGroup && buttonGroup) {
  10539. inputGroup.attr({
  10540. translateX: inputGroup.alignAttr.translateX + (chart.axisOffset[1] >= -xOffsetForExportButton ?
  10541. 0 :
  10542. -xOffsetForExportButton),
  10543. translateY: inputGroup.alignAttr.translateY +
  10544. buttonGroup.getBBox().height + 10
  10545. });
  10546. }
  10547. };
  10548. if (buttonGroup) {
  10549. if (dropdown === 'always') {
  10550. this.collapseButtons(xOffsetForExportButton);
  10551. if (groupsOverlap(maxButtonWidth())) {
  10552. // Move the inputs down if there is still a collision
  10553. // after collapsing the buttons
  10554. moveInputsDown();
  10555. }
  10556. return;
  10557. }
  10558. if (dropdown === 'never') {
  10559. this.expandButtons();
  10560. }
  10561. }
  10562. // Detect collision
  10563. if (inputGroup && buttonGroup) {
  10564. if ((inputPosition.align === buttonPosition.align) ||
  10565. // 20 is minimal spacing between elements
  10566. groupsOverlap(this.initialButtonGroupWidth + 20)) {
  10567. if (dropdown === 'responsive') {
  10568. this.collapseButtons(xOffsetForExportButton);
  10569. if (groupsOverlap(maxButtonWidth())) {
  10570. moveInputsDown();
  10571. }
  10572. }
  10573. else {
  10574. moveInputsDown();
  10575. }
  10576. }
  10577. else if (dropdown === 'responsive') {
  10578. this.expandButtons();
  10579. }
  10580. }
  10581. else if (buttonGroup && dropdown === 'responsive') {
  10582. if (this.initialButtonGroupWidth > chart.plotWidth) {
  10583. this.collapseButtons(xOffsetForExportButton);
  10584. }
  10585. else {
  10586. this.expandButtons();
  10587. }
  10588. }
  10589. };
  10590. /**
  10591. * Collapse the buttons and put the select element on top.
  10592. *
  10593. * @private
  10594. * @function Highcharts.RangeSelector#collapseButtons
  10595. * @param {number} xOffsetForExportButton
  10596. * @return {void}
  10597. */
  10598. RangeSelector.prototype.collapseButtons = function (xOffsetForExportButton) {
  10599. var _a = this,
  10600. buttons = _a.buttons,
  10601. buttonOptions = _a.buttonOptions,
  10602. chart = _a.chart,
  10603. dropdown = _a.dropdown,
  10604. options = _a.options,
  10605. zoomText = _a.zoomText;
  10606. var userButtonTheme = (chart.userOptions.rangeSelector &&
  10607. chart.userOptions.rangeSelector.buttonTheme) || {};
  10608. var getAttribs = function (text) { return ({
  10609. text: text ? text + " \u25BE" : '▾',
  10610. width: 'auto',
  10611. paddingLeft: pick(options.buttonTheme.paddingLeft,
  10612. userButtonTheme.padding, 8),
  10613. paddingRight: pick(options.buttonTheme.paddingRight,
  10614. userButtonTheme.padding, 8)
  10615. }); };
  10616. if (zoomText) {
  10617. zoomText.hide();
  10618. }
  10619. var hasActiveButton = false;
  10620. buttonOptions.forEach(function (rangeOptions, i) {
  10621. var button = buttons[i];
  10622. if (button.state !== 2) {
  10623. button.hide();
  10624. }
  10625. else {
  10626. button.show();
  10627. button.attr(getAttribs(rangeOptions.text));
  10628. hasActiveButton = true;
  10629. }
  10630. });
  10631. if (!hasActiveButton) {
  10632. if (dropdown) {
  10633. dropdown.selectedIndex = 0;
  10634. }
  10635. buttons[0].show();
  10636. buttons[0].attr(getAttribs(this.zoomText && this.zoomText.textStr));
  10637. }
  10638. var align = options.buttonPosition.align;
  10639. this.positionButtons();
  10640. if (align === 'right' || align === 'center') {
  10641. this.alignButtonGroup(xOffsetForExportButton, buttons[this.currentButtonIndex()].getBBox().width);
  10642. }
  10643. this.showDropdown();
  10644. };
  10645. /**
  10646. * Show all the buttons and hide the select element.
  10647. *
  10648. * @private
  10649. * @function Highcharts.RangeSelector#expandButtons
  10650. * @return {void}
  10651. */
  10652. RangeSelector.prototype.expandButtons = function () {
  10653. var _a = this,
  10654. buttons = _a.buttons,
  10655. buttonOptions = _a.buttonOptions,
  10656. options = _a.options,
  10657. zoomText = _a.zoomText;
  10658. this.hideDropdown();
  10659. if (zoomText) {
  10660. zoomText.show();
  10661. }
  10662. buttonOptions.forEach(function (rangeOptions, i) {
  10663. var button = buttons[i];
  10664. button.show();
  10665. button.attr({
  10666. text: rangeOptions.text,
  10667. width: options.buttonTheme.width || 28,
  10668. paddingLeft: pick(options.buttonTheme.paddingLeft, 'unset'),
  10669. paddingRight: pick(options.buttonTheme.paddingRight, 'unset')
  10670. });
  10671. if (button.state < 2) {
  10672. button.setState(0);
  10673. }
  10674. });
  10675. this.positionButtons();
  10676. };
  10677. /**
  10678. * Get the index of the visible button when the buttons are collapsed.
  10679. *
  10680. * @private
  10681. * @function Highcharts.RangeSelector#currentButtonIndex
  10682. * @return {number}
  10683. */
  10684. RangeSelector.prototype.currentButtonIndex = function () {
  10685. var dropdown = this.dropdown;
  10686. if (dropdown && dropdown.selectedIndex > 0) {
  10687. return dropdown.selectedIndex - 1;
  10688. }
  10689. return 0;
  10690. };
  10691. /**
  10692. * Position the select element on top of the button.
  10693. *
  10694. * @private
  10695. * @function Highcharts.RangeSelector#showDropdown
  10696. * @return {void}
  10697. */
  10698. RangeSelector.prototype.showDropdown = function () {
  10699. var _a = this,
  10700. buttonGroup = _a.buttonGroup,
  10701. buttons = _a.buttons,
  10702. chart = _a.chart,
  10703. dropdown = _a.dropdown;
  10704. if (buttonGroup && dropdown) {
  10705. var translateX = buttonGroup.translateX,
  10706. translateY = buttonGroup.translateY;
  10707. var bBox = buttons[this.currentButtonIndex()].getBBox();
  10708. css(dropdown, {
  10709. left: (chart.plotLeft + translateX) + 'px',
  10710. top: (translateY + 0.5) + 'px',
  10711. width: bBox.width + 'px',
  10712. height: bBox.height + 'px'
  10713. });
  10714. this.hasVisibleDropdown = true;
  10715. }
  10716. };
  10717. /**
  10718. * @private
  10719. * @function Highcharts.RangeSelector#hideDropdown
  10720. * @return {void}
  10721. */
  10722. RangeSelector.prototype.hideDropdown = function () {
  10723. var dropdown = this.dropdown;
  10724. if (dropdown) {
  10725. css(dropdown, {
  10726. top: '-9999em',
  10727. width: '1px',
  10728. height: '1px'
  10729. });
  10730. this.hasVisibleDropdown = false;
  10731. }
  10732. };
  10733. /**
  10734. * Extracts height of range selector
  10735. *
  10736. * @private
  10737. * @function Highcharts.RangeSelector#getHeight
  10738. * @return {number}
  10739. * Returns rangeSelector height
  10740. */
  10741. RangeSelector.prototype.getHeight = function () {
  10742. var rangeSelector = this,
  10743. options = rangeSelector.options,
  10744. rangeSelectorGroup = rangeSelector.group,
  10745. inputPosition = options.inputPosition,
  10746. buttonPosition = options.buttonPosition,
  10747. yPosition = options.y,
  10748. buttonPositionY = buttonPosition.y,
  10749. inputPositionY = inputPosition.y,
  10750. rangeSelectorHeight = 0,
  10751. minPosition;
  10752. if (options.height) {
  10753. return options.height;
  10754. }
  10755. // Align the elements before we read the height in case we're switching
  10756. // between wrapped and non-wrapped layout
  10757. this.alignElements();
  10758. rangeSelectorHeight = rangeSelectorGroup ?
  10759. // 13px to keep back compatibility
  10760. (rangeSelectorGroup.getBBox(true).height) + 13 +
  10761. yPosition :
  10762. 0;
  10763. minPosition = Math.min(inputPositionY, buttonPositionY);
  10764. if ((inputPositionY < 0 && buttonPositionY < 0) ||
  10765. (inputPositionY > 0 && buttonPositionY > 0)) {
  10766. rangeSelectorHeight += Math.abs(minPosition);
  10767. }
  10768. return rangeSelectorHeight;
  10769. };
  10770. /**
  10771. * Detect collision with title or subtitle
  10772. *
  10773. * @private
  10774. * @function Highcharts.RangeSelector#titleCollision
  10775. *
  10776. * @param {Highcharts.Chart} chart
  10777. *
  10778. * @return {boolean}
  10779. * Returns collision status
  10780. */
  10781. RangeSelector.prototype.titleCollision = function (chart) {
  10782. return !(chart.options.title.text ||
  10783. chart.options.subtitle.text);
  10784. };
  10785. /**
  10786. * Update the range selector with new options
  10787. *
  10788. * @private
  10789. * @function Highcharts.RangeSelector#update
  10790. * @param {Highcharts.RangeSelectorOptions} options
  10791. * @return {void}
  10792. */
  10793. RangeSelector.prototype.update = function (options) {
  10794. var chart = this.chart;
  10795. merge(true, chart.options.rangeSelector, options);
  10796. this.destroy();
  10797. this.init(chart);
  10798. this.render();
  10799. };
  10800. /**
  10801. * Destroys allocated elements.
  10802. *
  10803. * @private
  10804. * @function Highcharts.RangeSelector#destroy
  10805. */
  10806. RangeSelector.prototype.destroy = function () {
  10807. var rSelector = this,
  10808. minInput = rSelector.minInput,
  10809. maxInput = rSelector.maxInput;
  10810. if (rSelector.eventsToUnbind) {
  10811. rSelector.eventsToUnbind.forEach(function (unbind) { return unbind(); });
  10812. rSelector.eventsToUnbind = void 0;
  10813. }
  10814. // Destroy elements in collections
  10815. destroyObjectProperties(rSelector.buttons);
  10816. // Clear input element events
  10817. if (minInput) {
  10818. minInput.onfocus = minInput.onblur = minInput.onchange = null;
  10819. }
  10820. if (maxInput) {
  10821. maxInput.onfocus = maxInput.onblur = maxInput.onchange = null;
  10822. }
  10823. // Destroy HTML and SVG elements
  10824. objectEach(rSelector, function (val, key) {
  10825. if (val && key !== 'chart') {
  10826. if (val instanceof SVGElement) {
  10827. // SVGElement
  10828. val.destroy();
  10829. }
  10830. else if (val instanceof window.HTMLElement) {
  10831. // HTML element
  10832. discardElement(val);
  10833. }
  10834. }
  10835. if (val !== RangeSelector.prototype[key]) {
  10836. rSelector[key] = null;
  10837. }
  10838. }, this);
  10839. };
  10840. return RangeSelector;
  10841. }());
  10842. /**
  10843. * The default buttons for pre-selecting time frames
  10844. */
  10845. RangeSelector.prototype.defaultButtons = [{
  10846. type: 'month',
  10847. count: 1,
  10848. text: '1m',
  10849. title: 'View 1 month'
  10850. }, {
  10851. type: 'month',
  10852. count: 3,
  10853. text: '3m',
  10854. title: 'View 3 months'
  10855. }, {
  10856. type: 'month',
  10857. count: 6,
  10858. text: '6m',
  10859. title: 'View 6 months'
  10860. }, {
  10861. type: 'ytd',
  10862. text: 'YTD',
  10863. title: 'View year to date'
  10864. }, {
  10865. type: 'year',
  10866. count: 1,
  10867. text: '1y',
  10868. title: 'View 1 year'
  10869. }, {
  10870. type: 'all',
  10871. text: 'All',
  10872. title: 'View all'
  10873. }];
  10874. /**
  10875. * The date formats to use when setting min, max and value on date inputs
  10876. */
  10877. RangeSelector.prototype.inputTypeFormats = {
  10878. 'datetime-local': '%Y-%m-%dT%H:%M:%S',
  10879. 'date': '%Y-%m-%d',
  10880. 'time': '%H:%M:%S'
  10881. };
  10882. /**
  10883. * Get the preferred input type based on a date format string.
  10884. *
  10885. * @private
  10886. * @function preferredInputType
  10887. * @param {string} format
  10888. * @return {string}
  10889. */
  10890. function preferredInputType(format) {
  10891. var ms = format.indexOf('%L') !== -1;
  10892. if (ms) {
  10893. return 'text';
  10894. }
  10895. var date = ['a', 'A', 'd', 'e', 'w', 'b', 'B', 'm', 'o', 'y', 'Y'].some(function (char) {
  10896. return format.indexOf('%' + char) !== -1;
  10897. });
  10898. var time = ['H', 'k', 'I', 'l', 'M', 'S'].some(function (char) {
  10899. return format.indexOf('%' + char) !== -1;
  10900. });
  10901. if (date && time) {
  10902. return 'datetime-local';
  10903. }
  10904. if (date) {
  10905. return 'date';
  10906. }
  10907. if (time) {
  10908. return 'time';
  10909. }
  10910. return 'text';
  10911. }
  10912. /**
  10913. * Get the axis min value based on the range option and the current max. For
  10914. * stock charts this is extended via the {@link RangeSelector} so that if the
  10915. * selected range is a multiple of months or years, it is compensated for
  10916. * various month lengths.
  10917. *
  10918. * @private
  10919. * @function Highcharts.Axis#minFromRange
  10920. * @return {number|undefined}
  10921. * The new minimum value.
  10922. */
  10923. Axis.prototype.minFromRange = function () {
  10924. var rangeOptions = this.range,
  10925. type = rangeOptions.type,
  10926. min,
  10927. max = this.max,
  10928. dataMin,
  10929. range,
  10930. time = this.chart.time,
  10931. // Get the true range from a start date
  10932. getTrueRange = function (base,
  10933. count) {
  10934. var timeName = type === 'year' ? 'FullYear' : 'Month';
  10935. var date = new time.Date(base);
  10936. var basePeriod = time.get(timeName,
  10937. date);
  10938. time.set(timeName, date, basePeriod + count);
  10939. if (basePeriod === time.get(timeName, date)) {
  10940. time.set('Date', date, 0); // #6537
  10941. }
  10942. return date.getTime() - base;
  10943. };
  10944. if (isNumber(rangeOptions)) {
  10945. min = max - rangeOptions;
  10946. range = rangeOptions;
  10947. }
  10948. else {
  10949. min = max + getTrueRange(max, -rangeOptions.count);
  10950. // Let the fixedRange reflect initial settings (#5930)
  10951. if (this.chart) {
  10952. this.chart.fixedRange = max - min;
  10953. }
  10954. }
  10955. dataMin = pick(this.dataMin, Number.MIN_VALUE);
  10956. if (!isNumber(min)) {
  10957. min = dataMin;
  10958. }
  10959. if (min <= dataMin) {
  10960. min = dataMin;
  10961. if (typeof range === 'undefined') { // #4501
  10962. range = getTrueRange(min, rangeOptions.count);
  10963. }
  10964. this.newMax = Math.min(min + range, this.dataMax);
  10965. }
  10966. if (!isNumber(max)) {
  10967. min = void 0;
  10968. }
  10969. return min;
  10970. };
  10971. if (!H.RangeSelector) {
  10972. var chartDestroyEvents_1 = [];
  10973. var initRangeSelector_1 = function (chart) {
  10974. var extremes,
  10975. rangeSelector = chart.rangeSelector,
  10976. legend,
  10977. alignTo,
  10978. verticalAlign;
  10979. /**
  10980. * @private
  10981. */
  10982. function render() {
  10983. if (rangeSelector) {
  10984. extremes = chart.xAxis[0].getExtremes();
  10985. legend = chart.legend;
  10986. verticalAlign = (rangeSelector &&
  10987. rangeSelector.options.verticalAlign);
  10988. if (isNumber(extremes.min)) {
  10989. rangeSelector.render(extremes.min, extremes.max);
  10990. }
  10991. // Re-align the legend so that it's below the rangeselector
  10992. if (legend.display &&
  10993. verticalAlign === 'top' &&
  10994. verticalAlign === legend.options.verticalAlign) {
  10995. // Create a new alignment box for the legend.
  10996. alignTo = merge(chart.spacingBox);
  10997. if (legend.options.layout === 'vertical') {
  10998. alignTo.y = chart.plotTop;
  10999. }
  11000. else {
  11001. alignTo.y += rangeSelector.getHeight();
  11002. }
  11003. legend.group.placed = false; // Don't animate the alignment.
  11004. legend.align(alignTo);
  11005. }
  11006. }
  11007. }
  11008. if (rangeSelector) {
  11009. var events = find(chartDestroyEvents_1,
  11010. function (e) { return e[0] === chart; });
  11011. if (!events) {
  11012. chartDestroyEvents_1.push([chart, [
  11013. // redraw the scroller on setExtremes
  11014. addEvent(chart.xAxis[0], 'afterSetExtremes', function (e) {
  11015. if (rangeSelector) {
  11016. rangeSelector.render(e.min, e.max);
  11017. }
  11018. }),
  11019. // redraw the scroller chart resize
  11020. addEvent(chart, 'redraw', render)
  11021. ]]);
  11022. }
  11023. // do it now
  11024. render();
  11025. }
  11026. };
  11027. // Initialize rangeselector for stock charts
  11028. addEvent(Chart, 'afterGetContainer', function () {
  11029. if (this.options.rangeSelector &&
  11030. this.options.rangeSelector.enabled) {
  11031. this.rangeSelector = new RangeSelector(this);
  11032. }
  11033. });
  11034. addEvent(Chart, 'beforeRender', function () {
  11035. var chart = this,
  11036. axes = chart.axes,
  11037. rangeSelector = chart.rangeSelector,
  11038. verticalAlign;
  11039. if (rangeSelector) {
  11040. if (isNumber(rangeSelector.deferredYTDClick)) {
  11041. rangeSelector.clickButton(rangeSelector.deferredYTDClick);
  11042. delete rangeSelector.deferredYTDClick;
  11043. }
  11044. axes.forEach(function (axis) {
  11045. axis.updateNames();
  11046. axis.setScale();
  11047. });
  11048. chart.getAxisMargins();
  11049. rangeSelector.render();
  11050. verticalAlign = rangeSelector.options.verticalAlign;
  11051. if (!rangeSelector.options.floating) {
  11052. if (verticalAlign === 'bottom') {
  11053. this.extraBottomMargin = true;
  11054. }
  11055. else if (verticalAlign !== 'middle') {
  11056. this.extraTopMargin = true;
  11057. }
  11058. }
  11059. }
  11060. });
  11061. addEvent(Chart, 'update', function (e) {
  11062. var chart = this,
  11063. options = e.options,
  11064. optionsRangeSelector = options.rangeSelector,
  11065. rangeSelector = chart.rangeSelector,
  11066. verticalAlign,
  11067. extraBottomMarginWas = this.extraBottomMargin,
  11068. extraTopMarginWas = this.extraTopMargin;
  11069. if (optionsRangeSelector &&
  11070. optionsRangeSelector.enabled &&
  11071. !defined(rangeSelector) &&
  11072. this.options.rangeSelector) {
  11073. this.options.rangeSelector.enabled = true;
  11074. this.rangeSelector = rangeSelector = new RangeSelector(this);
  11075. }
  11076. this.extraBottomMargin = false;
  11077. this.extraTopMargin = false;
  11078. if (rangeSelector) {
  11079. initRangeSelector_1(this);
  11080. verticalAlign = (optionsRangeSelector &&
  11081. optionsRangeSelector.verticalAlign) || (rangeSelector.options && rangeSelector.options.verticalAlign);
  11082. if (!rangeSelector.options.floating) {
  11083. if (verticalAlign === 'bottom') {
  11084. this.extraBottomMargin = true;
  11085. }
  11086. else if (verticalAlign !== 'middle') {
  11087. this.extraTopMargin = true;
  11088. }
  11089. }
  11090. if (this.extraBottomMargin !== extraBottomMarginWas ||
  11091. this.extraTopMargin !== extraTopMarginWas) {
  11092. this.isDirtyBox = true;
  11093. }
  11094. }
  11095. });
  11096. addEvent(Chart, 'render', function () {
  11097. var chart = this,
  11098. rangeSelector = chart.rangeSelector,
  11099. verticalAlign;
  11100. if (rangeSelector && !rangeSelector.options.floating) {
  11101. rangeSelector.render();
  11102. verticalAlign = rangeSelector.options.verticalAlign;
  11103. if (verticalAlign === 'bottom') {
  11104. this.extraBottomMargin = true;
  11105. }
  11106. else if (verticalAlign !== 'middle') {
  11107. this.extraTopMargin = true;
  11108. }
  11109. }
  11110. });
  11111. addEvent(Chart, 'getMargins', function () {
  11112. var rangeSelector = this.rangeSelector,
  11113. rangeSelectorHeight;
  11114. if (rangeSelector) {
  11115. rangeSelectorHeight = rangeSelector.getHeight();
  11116. if (this.extraTopMargin) {
  11117. this.plotTop += rangeSelectorHeight;
  11118. }
  11119. if (this.extraBottomMargin) {
  11120. this.marginBottom += rangeSelectorHeight;
  11121. }
  11122. }
  11123. });
  11124. Chart.prototype.callbacks.push(initRangeSelector_1);
  11125. // Remove resize/afterSetExtremes at chart destroy
  11126. addEvent(Chart, 'destroy', function destroyEvents() {
  11127. for (var i = 0; i < chartDestroyEvents_1.length; i++) {
  11128. var events = chartDestroyEvents_1[i];
  11129. if (events[0] === this) {
  11130. events[1].forEach(function (unbind) { return unbind(); });
  11131. chartDestroyEvents_1.splice(i, 1);
  11132. return;
  11133. }
  11134. }
  11135. });
  11136. H.RangeSelector = RangeSelector;
  11137. }
  11138. return RangeSelector;
  11139. });
  11140. _registerModule(_modules, 'Core/Axis/NavigatorAxis.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  11141. /* *
  11142. *
  11143. * (c) 2010-2021 Torstein Honsi
  11144. *
  11145. * License: www.highcharts.com/license
  11146. *
  11147. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  11148. *
  11149. * */
  11150. var isTouchDevice = H.isTouchDevice;
  11151. var addEvent = U.addEvent,
  11152. correctFloat = U.correctFloat,
  11153. defined = U.defined,
  11154. isNumber = U.isNumber,
  11155. pick = U.pick;
  11156. /* eslint-disable valid-jsdoc */
  11157. /**
  11158. * @private
  11159. * @class
  11160. */
  11161. var NavigatorAxisAdditions = /** @class */ (function () {
  11162. /* *
  11163. *
  11164. * Constructors
  11165. *
  11166. * */
  11167. function NavigatorAxisAdditions(axis) {
  11168. this.axis = axis;
  11169. }
  11170. /* *
  11171. *
  11172. * Functions
  11173. *
  11174. * */
  11175. /**
  11176. * @private
  11177. */
  11178. NavigatorAxisAdditions.prototype.destroy = function () {
  11179. this.axis = void 0;
  11180. };
  11181. /**
  11182. * Add logic to normalize the zoomed range in order to preserve the pressed
  11183. * state of range selector buttons
  11184. *
  11185. * @private
  11186. * @function Highcharts.Axis#toFixedRange
  11187. * @param {number} [pxMin]
  11188. * @param {number} [pxMax]
  11189. * @param {number} [fixedMin]
  11190. * @param {number} [fixedMax]
  11191. * @return {*}
  11192. */
  11193. NavigatorAxisAdditions.prototype.toFixedRange = function (pxMin, pxMax, fixedMin, fixedMax) {
  11194. var navigator = this;
  11195. var axis = navigator.axis;
  11196. var chart = axis.chart;
  11197. var fixedRange = chart && chart.fixedRange,
  11198. halfPointRange = (axis.pointRange || 0) / 2,
  11199. newMin = pick(fixedMin,
  11200. axis.translate(pxMin,
  11201. true, !axis.horiz)),
  11202. newMax = pick(fixedMax,
  11203. axis.translate(pxMax,
  11204. true, !axis.horiz)),
  11205. changeRatio = fixedRange && (newMax - newMin) / fixedRange;
  11206. // Add/remove half point range to/from the extremes (#1172)
  11207. if (!defined(fixedMin)) {
  11208. newMin = correctFloat(newMin + halfPointRange);
  11209. }
  11210. if (!defined(fixedMax)) {
  11211. newMax = correctFloat(newMax - halfPointRange);
  11212. }
  11213. // If the difference between the fixed range and the actual requested
  11214. // range is too great, the user is dragging across an ordinal gap, and
  11215. // we need to release the range selector button.
  11216. if (changeRatio > 0.7 && changeRatio < 1.3) {
  11217. if (fixedMax) {
  11218. newMin = newMax - fixedRange;
  11219. }
  11220. else {
  11221. newMax = newMin + fixedRange;
  11222. }
  11223. }
  11224. if (!isNumber(newMin) || !isNumber(newMax)) { // #1195, #7411
  11225. newMin = newMax = void 0;
  11226. }
  11227. return {
  11228. min: newMin,
  11229. max: newMax
  11230. };
  11231. };
  11232. return NavigatorAxisAdditions;
  11233. }());
  11234. /**
  11235. * @private
  11236. * @class
  11237. */
  11238. var NavigatorAxis = /** @class */ (function () {
  11239. function NavigatorAxis() {
  11240. }
  11241. /* *
  11242. *
  11243. * Static Functions
  11244. *
  11245. * */
  11246. /**
  11247. * @private
  11248. */
  11249. NavigatorAxis.compose = function (AxisClass) {
  11250. AxisClass.keepProps.push('navigatorAxis');
  11251. /* eslint-disable no-invalid-this */
  11252. addEvent(AxisClass, 'init', function () {
  11253. var axis = this;
  11254. if (!axis.navigatorAxis) {
  11255. axis.navigatorAxis = new NavigatorAxisAdditions(axis);
  11256. }
  11257. });
  11258. // For Stock charts, override selection zooming with some special
  11259. // features because X axis zooming is already allowed by the Navigator
  11260. // and Range selector.
  11261. addEvent(AxisClass, 'zoom', function (e) {
  11262. var axis = this;
  11263. var chart = axis.chart;
  11264. var chartOptions = chart.options;
  11265. var navigator = chartOptions.navigator;
  11266. var navigatorAxis = axis.navigatorAxis;
  11267. var pinchType = chartOptions.chart.pinchType;
  11268. var rangeSelector = chartOptions.rangeSelector;
  11269. var zoomType = chartOptions.chart.zoomType;
  11270. var previousZoom;
  11271. if (axis.isXAxis && ((navigator && navigator.enabled) ||
  11272. (rangeSelector && rangeSelector.enabled))) {
  11273. // For y only zooming, ignore the X axis completely
  11274. if (zoomType === 'y') {
  11275. e.zoomed = false;
  11276. // For xy zooming, record the state of the zoom before zoom
  11277. // selection, then when the reset button is pressed, revert to
  11278. // this state. This should apply only if the chart is
  11279. // initialized with a range (#6612), otherwise zoom all the way
  11280. // out.
  11281. }
  11282. else if (((!isTouchDevice && zoomType === 'xy') ||
  11283. (isTouchDevice && pinchType === 'xy')) &&
  11284. axis.options.range) {
  11285. previousZoom = navigatorAxis.previousZoom;
  11286. if (defined(e.newMin)) {
  11287. navigatorAxis.previousZoom = [axis.min, axis.max];
  11288. }
  11289. else if (previousZoom) {
  11290. e.newMin = previousZoom[0];
  11291. e.newMax = previousZoom[1];
  11292. navigatorAxis.previousZoom = void 0;
  11293. }
  11294. }
  11295. }
  11296. if (typeof e.zoomed !== 'undefined') {
  11297. e.preventDefault();
  11298. }
  11299. });
  11300. /* eslint-enable no-invalid-this */
  11301. };
  11302. /* *
  11303. *
  11304. * Static Properties
  11305. *
  11306. * */
  11307. /**
  11308. * @private
  11309. */
  11310. NavigatorAxis.AdditionsClass = NavigatorAxisAdditions;
  11311. return NavigatorAxis;
  11312. }());
  11313. return NavigatorAxis;
  11314. });
  11315. _registerModule(_modules, 'Core/Navigator.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Color/Color.js'], _modules['Core/Globals.js'], _modules['Core/Axis/NavigatorAxis.js'], _modules['Core/DefaultOptions.js'], _modules['Core/Color/Palette.js'], _modules['Core/Renderer/RendererRegistry.js'], _modules['Core/Scrollbar.js'], _modules['Core/Series/Series.js'], _modules['Core/Series/SeriesRegistry.js'], _modules['Core/Utilities.js']], function (Axis, Chart, Color, H, NavigatorAxis, D, Palette, RendererRegistry, Scrollbar, Series, SeriesRegistry, U) {
  11316. /* *
  11317. *
  11318. * (c) 2010-2021 Torstein Honsi
  11319. *
  11320. * License: www.highcharts.com/license
  11321. *
  11322. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  11323. *
  11324. * */
  11325. var color = Color.parse;
  11326. var hasTouch = H.hasTouch,
  11327. isTouchDevice = H.isTouchDevice;
  11328. var defaultOptions = D.defaultOptions;
  11329. var seriesTypes = SeriesRegistry.seriesTypes;
  11330. var addEvent = U.addEvent,
  11331. clamp = U.clamp,
  11332. correctFloat = U.correctFloat,
  11333. defined = U.defined,
  11334. destroyObjectProperties = U.destroyObjectProperties,
  11335. erase = U.erase,
  11336. extend = U.extend,
  11337. find = U.find,
  11338. isArray = U.isArray,
  11339. isNumber = U.isNumber,
  11340. merge = U.merge,
  11341. pick = U.pick,
  11342. removeEvent = U.removeEvent,
  11343. splat = U.splat;
  11344. var defaultSeriesType,
  11345. // Finding the min or max of a set of variables where we don't know if they
  11346. // are defined, is a pattern that is repeated several places in Highcharts.
  11347. // Consider making this a global utility method.
  11348. numExt = function (extreme) {
  11349. var args = [];
  11350. for (var _i = 1; _i < arguments.length; _i++) {
  11351. args[_i - 1] = arguments[_i];
  11352. }
  11353. var numbers = [].filter.call(args,
  11354. isNumber);
  11355. if (numbers.length) {
  11356. return Math[extreme].apply(0, numbers);
  11357. }
  11358. };
  11359. defaultSeriesType = typeof seriesTypes.areaspline === 'undefined' ?
  11360. 'line' :
  11361. 'areaspline';
  11362. extend(defaultOptions, {
  11363. /**
  11364. * Maximum range which can be set using the navigator's handles.
  11365. * Opposite of [xAxis.minRange](#xAxis.minRange).
  11366. *
  11367. * @sample {highstock} stock/navigator/maxrange/
  11368. * Defined max and min range
  11369. *
  11370. * @type {number}
  11371. * @since 6.0.0
  11372. * @product highstock gantt
  11373. * @apioption xAxis.maxRange
  11374. */
  11375. /**
  11376. * The navigator is a small series below the main series, displaying
  11377. * a view of the entire data set. It provides tools to zoom in and
  11378. * out on parts of the data as well as panning across the dataset.
  11379. *
  11380. * @product highstock gantt
  11381. * @optionparent navigator
  11382. */
  11383. navigator: {
  11384. /**
  11385. * Whether the navigator and scrollbar should adapt to updated data
  11386. * in the base X axis. When loading data async, as in the demo below,
  11387. * this should be `false`. Otherwise new data will trigger navigator
  11388. * redraw, which will cause unwanted looping. In the demo below, the
  11389. * data in the navigator is set only once. On navigating, only the main
  11390. * chart content is updated.
  11391. *
  11392. * @sample {highstock} stock/demo/lazy-loading/
  11393. * Set to false with async data loading
  11394. *
  11395. * @type {boolean}
  11396. * @default true
  11397. * @apioption navigator.adaptToUpdatedData
  11398. */
  11399. /**
  11400. * An integer identifying the index to use for the base series, or a
  11401. * string representing the id of the series.
  11402. *
  11403. * **Note**: As of Highcharts 5.0, this is now a deprecated option.
  11404. * Prefer [series.showInNavigator](#plotOptions.series.showInNavigator).
  11405. *
  11406. * @see [series.showInNavigator](#plotOptions.series.showInNavigator)
  11407. *
  11408. * @deprecated
  11409. * @type {number|string}
  11410. * @default 0
  11411. * @apioption navigator.baseSeries
  11412. */
  11413. /**
  11414. * Enable or disable the navigator.
  11415. *
  11416. * @sample {highstock} stock/navigator/enabled/
  11417. * Disable the navigator
  11418. *
  11419. * @type {boolean}
  11420. * @default true
  11421. * @apioption navigator.enabled
  11422. */
  11423. /**
  11424. * When the chart is inverted, whether to draw the navigator on the
  11425. * opposite side.
  11426. *
  11427. * @type {boolean}
  11428. * @default false
  11429. * @since 5.0.8
  11430. * @apioption navigator.opposite
  11431. */
  11432. /**
  11433. * The height of the navigator.
  11434. *
  11435. * @sample {highstock} stock/navigator/height/
  11436. * A higher navigator
  11437. */
  11438. height: 40,
  11439. /**
  11440. * The distance from the nearest element, the X axis or X axis labels.
  11441. *
  11442. * @sample {highstock} stock/navigator/margin/
  11443. * A margin of 2 draws the navigator closer to the X axis labels
  11444. */
  11445. margin: 25,
  11446. /**
  11447. * Whether the mask should be inside the range marking the zoomed
  11448. * range, or outside. In Highcharts Stock 1.x it was always `false`.
  11449. *
  11450. * @sample {highstock} stock/navigator/maskinside-false/
  11451. * False, mask outside
  11452. *
  11453. * @since 2.0
  11454. */
  11455. maskInside: true,
  11456. /**
  11457. * Options for the handles for dragging the zoomed area.
  11458. *
  11459. * @sample {highstock} stock/navigator/handles/
  11460. * Colored handles
  11461. */
  11462. handles: {
  11463. /**
  11464. * Width for handles.
  11465. *
  11466. * @sample {highstock} stock/navigator/styled-handles/
  11467. * Styled handles
  11468. *
  11469. * @since 6.0.0
  11470. */
  11471. width: 7,
  11472. /**
  11473. * Height for handles.
  11474. *
  11475. * @sample {highstock} stock/navigator/styled-handles/
  11476. * Styled handles
  11477. *
  11478. * @since 6.0.0
  11479. */
  11480. height: 15,
  11481. /**
  11482. * Array to define shapes of handles. 0-index for left, 1-index for
  11483. * right.
  11484. *
  11485. * Additionally, the URL to a graphic can be given on this form:
  11486. * `url(graphic.png)`. Note that for the image to be applied to
  11487. * exported charts, its URL needs to be accessible by the export
  11488. * server.
  11489. *
  11490. * Custom callbacks for symbol path generation can also be added to
  11491. * `Highcharts.SVGRenderer.prototype.symbols`. The callback is then
  11492. * used by its method name, as shown in the demo.
  11493. *
  11494. * @sample {highstock} stock/navigator/styled-handles/
  11495. * Styled handles
  11496. *
  11497. * @type {Array<string>}
  11498. * @default ["navigator-handle", "navigator-handle"]
  11499. * @since 6.0.0
  11500. */
  11501. symbols: ['navigator-handle', 'navigator-handle'],
  11502. /**
  11503. * Allows to enable/disable handles.
  11504. *
  11505. * @since 6.0.0
  11506. */
  11507. enabled: true,
  11508. /**
  11509. * The width for the handle border and the stripes inside.
  11510. *
  11511. * @sample {highstock} stock/navigator/styled-handles/
  11512. * Styled handles
  11513. *
  11514. * @since 6.0.0
  11515. * @apioption navigator.handles.lineWidth
  11516. */
  11517. lineWidth: 1,
  11518. /**
  11519. * The fill for the handle.
  11520. *
  11521. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  11522. */
  11523. backgroundColor: Palette.neutralColor5,
  11524. /**
  11525. * The stroke for the handle border and the stripes inside.
  11526. *
  11527. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  11528. */
  11529. borderColor: Palette.neutralColor40
  11530. },
  11531. /**
  11532. * The color of the mask covering the areas of the navigator series
  11533. * that are currently not visible in the main series. The default
  11534. * color is bluish with an opacity of 0.3 to see the series below.
  11535. *
  11536. * @see In styled mode, the mask is styled with the
  11537. * `.highcharts-navigator-mask` and
  11538. * `.highcharts-navigator-mask-inside` classes.
  11539. *
  11540. * @sample {highstock} stock/navigator/maskfill/
  11541. * Blue, semi transparent mask
  11542. *
  11543. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  11544. * @default rgba(102,133,194,0.3)
  11545. */
  11546. maskFill: color(Palette.highlightColor60).setOpacity(0.3).get(),
  11547. /**
  11548. * The color of the line marking the currently zoomed area in the
  11549. * navigator.
  11550. *
  11551. * @sample {highstock} stock/navigator/outline/
  11552. * 2px blue outline
  11553. *
  11554. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  11555. * @default #cccccc
  11556. */
  11557. outlineColor: Palette.neutralColor20,
  11558. /**
  11559. * The width of the line marking the currently zoomed area in the
  11560. * navigator.
  11561. *
  11562. * @see In styled mode, the outline stroke width is set with the
  11563. * `.highcharts-navigator-outline` class.
  11564. *
  11565. * @sample {highstock} stock/navigator/outline/
  11566. * 2px blue outline
  11567. *
  11568. * @type {number}
  11569. */
  11570. outlineWidth: 1,
  11571. /**
  11572. * Options for the navigator series. Available options are the same
  11573. * as any series, documented at [plotOptions](#plotOptions.series)
  11574. * and [series](#series).
  11575. *
  11576. * Unless data is explicitly defined on navigator.series, the data
  11577. * is borrowed from the first series in the chart.
  11578. *
  11579. * Default series options for the navigator series are:
  11580. * ```js
  11581. * series: {
  11582. * type: 'areaspline',
  11583. * fillOpacity: 0.05,
  11584. * dataGrouping: {
  11585. * smoothed: true
  11586. * },
  11587. * lineWidth: 1,
  11588. * marker: {
  11589. * enabled: false
  11590. * }
  11591. * }
  11592. * ```
  11593. *
  11594. * @see In styled mode, the navigator series is styled with the
  11595. * `.highcharts-navigator-series` class.
  11596. *
  11597. * @sample {highstock} stock/navigator/series-data/
  11598. * Using a separate data set for the navigator
  11599. * @sample {highstock} stock/navigator/series/
  11600. * A green navigator series
  11601. *
  11602. * @type {*|Array<*>|Highcharts.SeriesOptionsType|Array<Highcharts.SeriesOptionsType>}
  11603. */
  11604. series: {
  11605. /**
  11606. * The type of the navigator series.
  11607. *
  11608. * Heads up:
  11609. * In column-type navigator, zooming is limited to at least one
  11610. * point with its `pointRange`.
  11611. *
  11612. * @sample {highstock} stock/navigator/column/
  11613. * Column type navigator
  11614. *
  11615. * @type {string}
  11616. * @default {highstock} `areaspline` if defined, otherwise `line`
  11617. * @default {gantt} gantt
  11618. */
  11619. type: defaultSeriesType,
  11620. /**
  11621. * The fill opacity of the navigator series.
  11622. */
  11623. fillOpacity: 0.05,
  11624. /**
  11625. * The pixel line width of the navigator series.
  11626. */
  11627. lineWidth: 1,
  11628. /**
  11629. * @ignore-option
  11630. */
  11631. compare: null,
  11632. /**
  11633. * Unless data is explicitly defined, the data is borrowed from the
  11634. * first series in the chart.
  11635. *
  11636. * @type {Array<number|Array<number|string|null>|object|null>}
  11637. * @product highstock
  11638. * @apioption navigator.series.data
  11639. */
  11640. /**
  11641. * Data grouping options for the navigator series.
  11642. *
  11643. * @extends plotOptions.series.dataGrouping
  11644. */
  11645. dataGrouping: {
  11646. approximation: 'average',
  11647. enabled: true,
  11648. groupPixelWidth: 2,
  11649. // Replace smoothed property by anchors, #12455.
  11650. firstAnchor: 'firstPoint',
  11651. anchor: 'middle',
  11652. lastAnchor: 'lastPoint',
  11653. // Day and week differs from plotOptions.series.dataGrouping
  11654. units: [
  11655. ['millisecond', [1, 2, 5, 10, 20, 25, 50, 100, 200, 500]],
  11656. ['second', [1, 2, 5, 10, 15, 30]],
  11657. ['minute', [1, 2, 5, 10, 15, 30]],
  11658. ['hour', [1, 2, 3, 4, 6, 8, 12]],
  11659. ['day', [1, 2, 3, 4]],
  11660. ['week', [1, 2, 3]],
  11661. ['month', [1, 3, 6]],
  11662. ['year', null]
  11663. ]
  11664. },
  11665. /**
  11666. * Data label options for the navigator series. Data labels are
  11667. * disabled by default on the navigator series.
  11668. *
  11669. * @extends plotOptions.series.dataLabels
  11670. */
  11671. dataLabels: {
  11672. enabled: false,
  11673. zIndex: 2 // #1839
  11674. },
  11675. id: 'highcharts-navigator-series',
  11676. className: 'highcharts-navigator-series',
  11677. /**
  11678. * Sets the fill color of the navigator series.
  11679. *
  11680. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  11681. * @apioption navigator.series.color
  11682. */
  11683. /**
  11684. * Line color for the navigator series. Allows setting the color
  11685. * while disallowing the default candlestick setting.
  11686. *
  11687. * @type {Highcharts.ColorString|null}
  11688. */
  11689. lineColor: null,
  11690. marker: {
  11691. enabled: false
  11692. },
  11693. /**
  11694. * Since Highcharts Stock v8, default value is the same as default
  11695. * `pointRange` defined for a specific type (e.g. `null` for
  11696. * column type).
  11697. *
  11698. * In Highcharts Stock version < 8, defaults to 0.
  11699. *
  11700. * @extends plotOptions.series.pointRange
  11701. * @type {number|null}
  11702. * @apioption navigator.series.pointRange
  11703. */
  11704. /**
  11705. * The threshold option. Setting it to 0 will make the default
  11706. * navigator area series draw its area from the 0 value and up.
  11707. *
  11708. * @type {number|null}
  11709. */
  11710. threshold: null
  11711. },
  11712. /**
  11713. * Options for the navigator X axis. Default series options for the
  11714. * navigator xAxis are:
  11715. * ```js
  11716. * xAxis: {
  11717. * tickWidth: 0,
  11718. * lineWidth: 0,
  11719. * gridLineWidth: 1,
  11720. * tickPixelInterval: 200,
  11721. * labels: {
  11722. * align: 'left',
  11723. * style: {
  11724. * color: '#888'
  11725. * },
  11726. * x: 3,
  11727. * y: -4
  11728. * }
  11729. * }
  11730. * ```
  11731. *
  11732. * @extends xAxis
  11733. * @excluding linkedTo, maxZoom, minRange, opposite, range, scrollbar,
  11734. * showEmpty, maxRange
  11735. */
  11736. xAxis: {
  11737. /**
  11738. * Additional range on the right side of the xAxis. Works similar to
  11739. * xAxis.maxPadding, but value is set in milliseconds.
  11740. * Can be set for both, main xAxis and navigator's xAxis.
  11741. *
  11742. * @since 6.0.0
  11743. */
  11744. overscroll: 0,
  11745. className: 'highcharts-navigator-xaxis',
  11746. tickLength: 0,
  11747. lineWidth: 0,
  11748. gridLineColor: Palette.neutralColor10,
  11749. gridLineWidth: 1,
  11750. tickPixelInterval: 200,
  11751. labels: {
  11752. align: 'left',
  11753. /**
  11754. * @type {Highcharts.CSSObject}
  11755. */
  11756. style: {
  11757. /** @ignore */
  11758. color: Palette.neutralColor40
  11759. },
  11760. x: 3,
  11761. y: -4
  11762. },
  11763. crosshair: false
  11764. },
  11765. /**
  11766. * Options for the navigator Y axis. Default series options for the
  11767. * navigator yAxis are:
  11768. * ```js
  11769. * yAxis: {
  11770. * gridLineWidth: 0,
  11771. * startOnTick: false,
  11772. * endOnTick: false,
  11773. * minPadding: 0.1,
  11774. * maxPadding: 0.1,
  11775. * labels: {
  11776. * enabled: false
  11777. * },
  11778. * title: {
  11779. * text: null
  11780. * },
  11781. * tickWidth: 0
  11782. * }
  11783. * ```
  11784. *
  11785. * @extends yAxis
  11786. * @excluding height, linkedTo, maxZoom, minRange, ordinal, range,
  11787. * showEmpty, scrollbar, top, units, maxRange, minLength,
  11788. * maxLength, resize
  11789. */
  11790. yAxis: {
  11791. className: 'highcharts-navigator-yaxis',
  11792. gridLineWidth: 0,
  11793. startOnTick: false,
  11794. endOnTick: false,
  11795. minPadding: 0.1,
  11796. maxPadding: 0.1,
  11797. labels: {
  11798. enabled: false
  11799. },
  11800. crosshair: false,
  11801. title: {
  11802. text: null
  11803. },
  11804. tickLength: 0,
  11805. tickWidth: 0
  11806. }
  11807. }
  11808. });
  11809. /* eslint-disable no-invalid-this, valid-jsdoc */
  11810. /**
  11811. * Draw one of the handles on the side of the zoomed range in the navigator
  11812. *
  11813. * @private
  11814. * @function Highcharts.Renderer#symbols.navigator-handle
  11815. * @param {number} x
  11816. * @param {number} y
  11817. * @param {number} w
  11818. * @param {number} h
  11819. * @param {Highcharts.NavigatorHandlesOptions} options
  11820. * @return {Highcharts.SVGPathArray}
  11821. * Path to be used in a handle
  11822. */
  11823. RendererRegistry.getRendererType().prototype.symbols['navigator-handle'] = function (_x, _y, _w, _h, options) {
  11824. var halfWidth = (options && options.width || 0) / 2,
  11825. markerPosition = Math.round(halfWidth / 3) + 0.5,
  11826. height = options && options.height || 0;
  11827. return [
  11828. ['M', -halfWidth - 1, 0.5],
  11829. ['L', halfWidth, 0.5],
  11830. ['L', halfWidth, height + 0.5],
  11831. ['L', -halfWidth - 1, height + 0.5],
  11832. ['L', -halfWidth - 1, 0.5],
  11833. ['M', -markerPosition, 4],
  11834. ['L', -markerPosition, height - 3],
  11835. ['M', markerPosition - 1, 4],
  11836. ['L', markerPosition - 1, height - 3]
  11837. ];
  11838. };
  11839. /**
  11840. * The Navigator class
  11841. *
  11842. * @private
  11843. * @class
  11844. * @name Highcharts.Navigator
  11845. *
  11846. * @param {Highcharts.Chart} chart
  11847. * Chart object
  11848. */
  11849. var Navigator = /** @class */ (function () {
  11850. function Navigator(chart) {
  11851. this.baseSeries = void 0;
  11852. this.chart = void 0;
  11853. this.handles = void 0;
  11854. this.height = void 0;
  11855. this.left = void 0;
  11856. this.navigatorEnabled = void 0;
  11857. this.navigatorGroup = void 0;
  11858. this.navigatorOptions = void 0;
  11859. this.navigatorSeries = void 0;
  11860. this.navigatorSize = void 0;
  11861. this.opposite = void 0;
  11862. this.outline = void 0;
  11863. this.outlineHeight = void 0;
  11864. this.range = void 0;
  11865. this.rendered = void 0;
  11866. this.shades = void 0;
  11867. this.size = void 0;
  11868. this.top = void 0;
  11869. this.xAxis = void 0;
  11870. this.yAxis = void 0;
  11871. this.zoomedMax = void 0;
  11872. this.zoomedMin = void 0;
  11873. this.init(chart);
  11874. }
  11875. /**
  11876. * Draw one of the handles on the side of the zoomed range in the navigator
  11877. *
  11878. * @private
  11879. * @function Highcharts.Navigator#drawHandle
  11880. *
  11881. * @param {number} x
  11882. * The x center for the handle
  11883. *
  11884. * @param {number} index
  11885. * 0 for left and 1 for right
  11886. *
  11887. * @param {boolean|undefined} inverted
  11888. * flag for chart.inverted
  11889. *
  11890. * @param {string} verb
  11891. * use 'animate' or 'attr'
  11892. */
  11893. Navigator.prototype.drawHandle = function (x, index, inverted, verb) {
  11894. var navigator = this,
  11895. height = navigator.navigatorOptions.handles.height;
  11896. // Place it
  11897. navigator.handles[index][verb](inverted ? {
  11898. translateX: Math.round(navigator.left + navigator.height / 2),
  11899. translateY: Math.round(navigator.top + parseInt(x, 10) + 0.5 - height)
  11900. } : {
  11901. translateX: Math.round(navigator.left + parseInt(x, 10)),
  11902. translateY: Math.round(navigator.top + navigator.height / 2 - height / 2 - 1)
  11903. });
  11904. };
  11905. /**
  11906. * Render outline around the zoomed range
  11907. *
  11908. * @private
  11909. * @function Highcharts.Navigator#drawOutline
  11910. *
  11911. * @param {number} zoomedMin
  11912. * in pixels position where zoomed range starts
  11913. *
  11914. * @param {number} zoomedMax
  11915. * in pixels position where zoomed range ends
  11916. *
  11917. * @param {boolean|undefined} inverted
  11918. * flag if chart is inverted
  11919. *
  11920. * @param {string} verb
  11921. * use 'animate' or 'attr'
  11922. */
  11923. Navigator.prototype.drawOutline = function (zoomedMin, zoomedMax, inverted, verb) {
  11924. var navigator = this,
  11925. maskInside = navigator.navigatorOptions.maskInside,
  11926. outlineWidth = navigator.outline.strokeWidth(),
  11927. halfOutline = outlineWidth / 2,
  11928. outlineCorrection = (outlineWidth % 2) / 2, // #5800
  11929. outlineHeight = navigator.outlineHeight,
  11930. scrollbarHeight = navigator.scrollbarHeight || 0,
  11931. navigatorSize = navigator.size,
  11932. left = navigator.left - scrollbarHeight,
  11933. navigatorTop = navigator.top,
  11934. verticalMin,
  11935. path;
  11936. if (inverted) {
  11937. left -= halfOutline;
  11938. verticalMin = navigatorTop + zoomedMax + outlineCorrection;
  11939. zoomedMax = navigatorTop + zoomedMin + outlineCorrection;
  11940. path = [
  11941. ['M', left + outlineHeight, navigatorTop - scrollbarHeight - outlineCorrection],
  11942. ['L', left + outlineHeight, verticalMin],
  11943. ['L', left, verticalMin],
  11944. ['L', left, zoomedMax],
  11945. ['L', left + outlineHeight, zoomedMax],
  11946. ['L', left + outlineHeight, navigatorTop + navigatorSize + scrollbarHeight]
  11947. ];
  11948. if (maskInside) {
  11949. path.push(['M', left + outlineHeight, verticalMin - halfOutline], // upper left of zoomed range
  11950. ['L', left + outlineHeight, zoomedMax + halfOutline] // upper right of z.r.
  11951. );
  11952. }
  11953. }
  11954. else {
  11955. zoomedMin += left + scrollbarHeight - outlineCorrection;
  11956. zoomedMax += left + scrollbarHeight - outlineCorrection;
  11957. navigatorTop += halfOutline;
  11958. path = [
  11959. ['M', left, navigatorTop],
  11960. ['L', zoomedMin, navigatorTop],
  11961. ['L', zoomedMin, navigatorTop + outlineHeight],
  11962. ['L', zoomedMax, navigatorTop + outlineHeight],
  11963. ['L', zoomedMax, navigatorTop],
  11964. ['L', left + navigatorSize + scrollbarHeight * 2, navigatorTop] // right
  11965. ];
  11966. if (maskInside) {
  11967. path.push(['M', zoomedMin - halfOutline, navigatorTop], // upper left of zoomed range
  11968. ['L', zoomedMax + halfOutline, navigatorTop] // upper right of z.r.
  11969. );
  11970. }
  11971. }
  11972. navigator.outline[verb]({
  11973. d: path
  11974. });
  11975. };
  11976. /**
  11977. * Render outline around the zoomed range
  11978. *
  11979. * @private
  11980. * @function Highcharts.Navigator#drawMasks
  11981. *
  11982. * @param {number} zoomedMin
  11983. * in pixels position where zoomed range starts
  11984. *
  11985. * @param {number} zoomedMax
  11986. * in pixels position where zoomed range ends
  11987. *
  11988. * @param {boolean|undefined} inverted
  11989. * flag if chart is inverted
  11990. *
  11991. * @param {string} verb
  11992. * use 'animate' or 'attr'
  11993. */
  11994. Navigator.prototype.drawMasks = function (zoomedMin, zoomedMax, inverted, verb) {
  11995. var navigator = this,
  11996. left = navigator.left,
  11997. top = navigator.top,
  11998. navigatorHeight = navigator.height,
  11999. height,
  12000. width,
  12001. x,
  12002. y;
  12003. // Determine rectangle position & size
  12004. // According to (non)inverted position:
  12005. if (inverted) {
  12006. x = [left, left, left];
  12007. y = [top, top + zoomedMin, top + zoomedMax];
  12008. width = [navigatorHeight, navigatorHeight, navigatorHeight];
  12009. height = [
  12010. zoomedMin,
  12011. zoomedMax - zoomedMin,
  12012. navigator.size - zoomedMax
  12013. ];
  12014. }
  12015. else {
  12016. x = [left, left + zoomedMin, left + zoomedMax];
  12017. y = [top, top, top];
  12018. width = [
  12019. zoomedMin,
  12020. zoomedMax - zoomedMin,
  12021. navigator.size - zoomedMax
  12022. ];
  12023. height = [navigatorHeight, navigatorHeight, navigatorHeight];
  12024. }
  12025. navigator.shades.forEach(function (shade, i) {
  12026. shade[verb]({
  12027. x: x[i],
  12028. y: y[i],
  12029. width: width[i],
  12030. height: height[i]
  12031. });
  12032. });
  12033. };
  12034. /**
  12035. * Generate DOM elements for a navigator:
  12036. *
  12037. * - main navigator group
  12038. *
  12039. * - all shades
  12040. *
  12041. * - outline
  12042. *
  12043. * - handles
  12044. *
  12045. * @private
  12046. * @function Highcharts.Navigator#renderElements
  12047. */
  12048. Navigator.prototype.renderElements = function () {
  12049. var navigator = this,
  12050. navigatorOptions = navigator.navigatorOptions,
  12051. maskInside = navigatorOptions.maskInside,
  12052. chart = navigator.chart,
  12053. inverted = chart.inverted,
  12054. renderer = chart.renderer,
  12055. navigatorGroup,
  12056. mouseCursor = {
  12057. cursor: inverted ? 'ns-resize' : 'ew-resize'
  12058. };
  12059. // Create the main navigator group
  12060. navigator.navigatorGroup = navigatorGroup = renderer.g('navigator')
  12061. .attr({
  12062. zIndex: 8,
  12063. visibility: 'hidden'
  12064. })
  12065. .add();
  12066. // Create masks, each mask will get events and fill:
  12067. [
  12068. !maskInside,
  12069. maskInside,
  12070. !maskInside
  12071. ].forEach(function (hasMask, index) {
  12072. navigator.shades[index] = renderer.rect()
  12073. .addClass('highcharts-navigator-mask' +
  12074. (index === 1 ? '-inside' : '-outside'))
  12075. .add(navigatorGroup);
  12076. if (!chart.styledMode) {
  12077. navigator.shades[index]
  12078. .attr({
  12079. fill: hasMask ?
  12080. navigatorOptions.maskFill :
  12081. 'rgba(0,0,0,0)'
  12082. })
  12083. .css((index === 1) && mouseCursor);
  12084. }
  12085. });
  12086. // Create the outline:
  12087. navigator.outline = renderer.path()
  12088. .addClass('highcharts-navigator-outline')
  12089. .add(navigatorGroup);
  12090. if (!chart.styledMode) {
  12091. navigator.outline.attr({
  12092. 'stroke-width': navigatorOptions.outlineWidth,
  12093. stroke: navigatorOptions.outlineColor
  12094. });
  12095. }
  12096. // Create the handlers:
  12097. if (navigatorOptions.handles.enabled) {
  12098. [0, 1].forEach(function (index) {
  12099. navigatorOptions.handles.inverted = chart.inverted;
  12100. navigator.handles[index] = renderer.symbol(navigatorOptions.handles.symbols[index], -navigatorOptions.handles.width / 2 - 1, 0, navigatorOptions.handles.width, navigatorOptions.handles.height, navigatorOptions.handles);
  12101. // zIndex = 6 for right handle, 7 for left.
  12102. // Can't be 10, because of the tooltip in inverted chart #2908
  12103. navigator.handles[index].attr({ zIndex: 7 - index })
  12104. .addClass('highcharts-navigator-handle ' +
  12105. 'highcharts-navigator-handle-' +
  12106. ['left', 'right'][index]).add(navigatorGroup);
  12107. if (!chart.styledMode) {
  12108. var handlesOptions = navigatorOptions.handles;
  12109. navigator.handles[index]
  12110. .attr({
  12111. fill: handlesOptions.backgroundColor,
  12112. stroke: handlesOptions.borderColor,
  12113. 'stroke-width': handlesOptions.lineWidth
  12114. })
  12115. .css(mouseCursor);
  12116. }
  12117. });
  12118. }
  12119. };
  12120. /**
  12121. * Update navigator
  12122. *
  12123. * @private
  12124. * @function Highcharts.Navigator#update
  12125. *
  12126. * @param {Highcharts.NavigatorOptions} options
  12127. * Options to merge in when updating navigator
  12128. */
  12129. Navigator.prototype.update = function (options) {
  12130. // Remove references to old navigator series in base series
  12131. (this.series || []).forEach(function (series) {
  12132. if (series.baseSeries) {
  12133. delete series.baseSeries.navigatorSeries;
  12134. }
  12135. });
  12136. // Destroy and rebuild navigator
  12137. this.destroy();
  12138. var chartOptions = this.chart.options;
  12139. merge(true, chartOptions.navigator, this.options, options);
  12140. this.init(this.chart);
  12141. };
  12142. /**
  12143. * Render the navigator
  12144. *
  12145. * @private
  12146. * @function Highcharts.Navigator#render
  12147. * @param {number} min
  12148. * X axis value minimum
  12149. * @param {number} max
  12150. * X axis value maximum
  12151. * @param {number} [pxMin]
  12152. * Pixel value minimum
  12153. * @param {number} [pxMax]
  12154. * Pixel value maximum
  12155. * @return {void}
  12156. */
  12157. Navigator.prototype.render = function (min, max, pxMin, pxMax) {
  12158. var navigator = this,
  12159. chart = navigator.chart,
  12160. navigatorWidth,
  12161. scrollbarLeft,
  12162. scrollbarTop,
  12163. scrollbarHeight = navigator.scrollbarHeight,
  12164. navigatorSize,
  12165. xAxis = navigator.xAxis,
  12166. pointRange = xAxis.pointRange || 0,
  12167. scrollbarXAxis = xAxis.navigatorAxis.fake ? chart.xAxis[0] : xAxis,
  12168. navigatorEnabled = navigator.navigatorEnabled,
  12169. zoomedMin,
  12170. zoomedMax,
  12171. rendered = navigator.rendered,
  12172. inverted = chart.inverted,
  12173. verb,
  12174. newMin,
  12175. newMax,
  12176. currentRange,
  12177. minRange = chart.xAxis[0].minRange,
  12178. maxRange = chart.xAxis[0].options.maxRange;
  12179. // Don't redraw while moving the handles (#4703).
  12180. if (this.hasDragged && !defined(pxMin)) {
  12181. return;
  12182. }
  12183. min = correctFloat(min - pointRange / 2);
  12184. max = correctFloat(max + pointRange / 2);
  12185. // Don't render the navigator until we have data (#486, #4202, #5172).
  12186. if (!isNumber(min) || !isNumber(max)) {
  12187. // However, if navigator was already rendered, we may need to resize
  12188. // it. For example hidden series, but visible navigator (#6022).
  12189. if (rendered) {
  12190. pxMin = 0;
  12191. pxMax = pick(xAxis.width, scrollbarXAxis.width);
  12192. }
  12193. else {
  12194. return;
  12195. }
  12196. }
  12197. navigator.left = pick(xAxis.left,
  12198. // in case of scrollbar only, without navigator
  12199. chart.plotLeft + scrollbarHeight +
  12200. (inverted ? chart.plotWidth : 0));
  12201. navigator.size = zoomedMax = navigatorSize = pick(xAxis.len, (inverted ? chart.plotHeight : chart.plotWidth) -
  12202. 2 * scrollbarHeight);
  12203. if (inverted) {
  12204. navigatorWidth = scrollbarHeight;
  12205. }
  12206. else {
  12207. navigatorWidth = navigatorSize + 2 * scrollbarHeight;
  12208. }
  12209. // Get the pixel position of the handles
  12210. pxMin = pick(pxMin, xAxis.toPixels(min, true));
  12211. pxMax = pick(pxMax, xAxis.toPixels(max, true));
  12212. // Verify (#1851, #2238)
  12213. if (!isNumber(pxMin) || Math.abs(pxMin) === Infinity) {
  12214. pxMin = 0;
  12215. pxMax = navigatorWidth;
  12216. }
  12217. // Are we below the minRange? (#2618, #6191)
  12218. newMin = xAxis.toValue(pxMin, true);
  12219. newMax = xAxis.toValue(pxMax, true);
  12220. currentRange = Math.abs(correctFloat(newMax - newMin));
  12221. if (currentRange < minRange) {
  12222. if (this.grabbedLeft) {
  12223. pxMin = xAxis.toPixels(newMax - minRange - pointRange, true);
  12224. }
  12225. else if (this.grabbedRight) {
  12226. pxMax = xAxis.toPixels(newMin + minRange + pointRange, true);
  12227. }
  12228. }
  12229. else if (defined(maxRange) &&
  12230. correctFloat(currentRange - pointRange) > maxRange) {
  12231. if (this.grabbedLeft) {
  12232. pxMin = xAxis.toPixels(newMax - maxRange - pointRange, true);
  12233. }
  12234. else if (this.grabbedRight) {
  12235. pxMax = xAxis.toPixels(newMin + maxRange + pointRange, true);
  12236. }
  12237. }
  12238. // Handles are allowed to cross, but never exceed the plot area
  12239. navigator.zoomedMax = clamp(Math.max(pxMin, pxMax), 0, zoomedMax);
  12240. navigator.zoomedMin = clamp(navigator.fixedWidth ?
  12241. navigator.zoomedMax - navigator.fixedWidth :
  12242. Math.min(pxMin, pxMax), 0, zoomedMax);
  12243. navigator.range = navigator.zoomedMax - navigator.zoomedMin;
  12244. zoomedMax = Math.round(navigator.zoomedMax);
  12245. zoomedMin = Math.round(navigator.zoomedMin);
  12246. if (navigatorEnabled) {
  12247. navigator.navigatorGroup.attr({
  12248. visibility: 'visible'
  12249. });
  12250. // Place elements
  12251. verb = rendered && !navigator.hasDragged ? 'animate' : 'attr';
  12252. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  12253. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  12254. if (navigator.navigatorOptions.handles.enabled) {
  12255. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  12256. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  12257. }
  12258. }
  12259. if (navigator.scrollbar) {
  12260. if (inverted) {
  12261. scrollbarTop = navigator.top - scrollbarHeight;
  12262. scrollbarLeft = navigator.left - scrollbarHeight +
  12263. (navigatorEnabled || !scrollbarXAxis.opposite ? 0 :
  12264. // Multiple axes has offsets:
  12265. (scrollbarXAxis.titleOffset || 0) +
  12266. // Self margin from the axis.title
  12267. scrollbarXAxis.axisTitleMargin);
  12268. scrollbarHeight = navigatorSize + 2 * scrollbarHeight;
  12269. }
  12270. else {
  12271. scrollbarTop = navigator.top + (navigatorEnabled ?
  12272. navigator.height :
  12273. -scrollbarHeight);
  12274. scrollbarLeft = navigator.left - scrollbarHeight;
  12275. }
  12276. // Reposition scrollbar
  12277. navigator.scrollbar.position(scrollbarLeft, scrollbarTop, navigatorWidth, scrollbarHeight);
  12278. // Keep scale 0-1
  12279. navigator.scrollbar.setRange(
  12280. // Use real value, not rounded because range can be very small
  12281. // (#1716)
  12282. navigator.zoomedMin / (navigatorSize || 1), navigator.zoomedMax / (navigatorSize || 1));
  12283. }
  12284. navigator.rendered = true;
  12285. };
  12286. /**
  12287. * Set up the mouse and touch events for the navigator
  12288. *
  12289. * @private
  12290. * @function Highcharts.Navigator#addMouseEvents
  12291. */
  12292. Navigator.prototype.addMouseEvents = function () {
  12293. var navigator = this,
  12294. chart = navigator.chart,
  12295. container = chart.container,
  12296. eventsToUnbind = [],
  12297. mouseMoveHandler,
  12298. mouseUpHandler;
  12299. /**
  12300. * Create mouse events' handlers.
  12301. * Make them as separate functions to enable wrapping them:
  12302. */
  12303. navigator.mouseMoveHandler = mouseMoveHandler = function (e) {
  12304. navigator.onMouseMove(e);
  12305. };
  12306. navigator.mouseUpHandler = mouseUpHandler = function (e) {
  12307. navigator.onMouseUp(e);
  12308. };
  12309. // Add shades and handles mousedown events
  12310. eventsToUnbind = navigator.getPartsEvents('mousedown');
  12311. // Add mouse move and mouseup events. These are bind to doc/container,
  12312. // because Navigator.grabbedSomething flags are stored in mousedown
  12313. // events
  12314. eventsToUnbind.push(addEvent(chart.renderTo, 'mousemove', mouseMoveHandler), addEvent(container.ownerDocument, 'mouseup', mouseUpHandler));
  12315. // Touch events
  12316. if (hasTouch) {
  12317. eventsToUnbind.push(addEvent(chart.renderTo, 'touchmove', mouseMoveHandler), addEvent(container.ownerDocument, 'touchend', mouseUpHandler));
  12318. eventsToUnbind.concat(navigator.getPartsEvents('touchstart'));
  12319. }
  12320. navigator.eventsToUnbind = eventsToUnbind;
  12321. // Data events
  12322. if (navigator.series && navigator.series[0]) {
  12323. eventsToUnbind.push(addEvent(navigator.series[0].xAxis, 'foundExtremes', function () {
  12324. chart.navigator.modifyNavigatorAxisExtremes();
  12325. }));
  12326. }
  12327. };
  12328. /**
  12329. * Generate events for handles and masks
  12330. *
  12331. * @private
  12332. * @function Highcharts.Navigator#getPartsEvents
  12333. *
  12334. * @param {string} eventName
  12335. * Event name handler, 'mousedown' or 'touchstart'
  12336. *
  12337. * @return {Array<Function>}
  12338. * An array of functions to remove navigator functions from the
  12339. * events again.
  12340. */
  12341. Navigator.prototype.getPartsEvents = function (eventName) {
  12342. var navigator = this,
  12343. events = [];
  12344. ['shades', 'handles'].forEach(function (name) {
  12345. navigator[name].forEach(function (navigatorItem, index) {
  12346. events.push(addEvent(navigatorItem.element, eventName, function (e) {
  12347. navigator[name + 'Mousedown'](e, index);
  12348. }));
  12349. });
  12350. });
  12351. return events;
  12352. };
  12353. /**
  12354. * Mousedown on a shaded mask, either:
  12355. *
  12356. * - will be stored for future drag&drop
  12357. *
  12358. * - will directly shift to a new range
  12359. *
  12360. * @private
  12361. * @function Highcharts.Navigator#shadesMousedown
  12362. *
  12363. * @param {Highcharts.PointerEventObject} e
  12364. * Mouse event
  12365. *
  12366. * @param {number} index
  12367. * Index of a mask in Navigator.shades array
  12368. */
  12369. Navigator.prototype.shadesMousedown = function (e, index) {
  12370. e = this.chart.pointer.normalize(e);
  12371. var navigator = this,
  12372. chart = navigator.chart,
  12373. xAxis = navigator.xAxis,
  12374. zoomedMin = navigator.zoomedMin,
  12375. navigatorPosition = navigator.left,
  12376. navigatorSize = navigator.size,
  12377. range = navigator.range,
  12378. chartX = e.chartX,
  12379. fixedMax,
  12380. fixedMin,
  12381. ext,
  12382. left;
  12383. // For inverted chart, swap some options:
  12384. if (chart.inverted) {
  12385. chartX = e.chartY;
  12386. navigatorPosition = navigator.top;
  12387. }
  12388. if (index === 1) {
  12389. // Store information for drag&drop
  12390. navigator.grabbedCenter = chartX;
  12391. navigator.fixedWidth = range;
  12392. navigator.dragOffset = chartX - zoomedMin;
  12393. }
  12394. else {
  12395. // Shift the range by clicking on shaded areas
  12396. left = chartX - navigatorPosition - range / 2;
  12397. if (index === 0) {
  12398. left = Math.max(0, left);
  12399. }
  12400. else if (index === 2 && left + range >= navigatorSize) {
  12401. left = navigatorSize - range;
  12402. if (navigator.reversedExtremes) {
  12403. // #7713
  12404. left -= range;
  12405. fixedMin = navigator.getUnionExtremes().dataMin;
  12406. }
  12407. else {
  12408. // #2293, #3543
  12409. fixedMax = navigator.getUnionExtremes().dataMax;
  12410. }
  12411. }
  12412. if (left !== zoomedMin) { // it has actually moved
  12413. navigator.fixedWidth = range; // #1370
  12414. ext = xAxis.navigatorAxis.toFixedRange(left, left + range, fixedMin, fixedMax);
  12415. if (defined(ext.min)) { // #7411
  12416. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true, null, // auto animation
  12417. { trigger: 'navigator' });
  12418. }
  12419. }
  12420. }
  12421. };
  12422. /**
  12423. * Mousedown on a handle mask.
  12424. * Will store necessary information for drag&drop.
  12425. *
  12426. * @private
  12427. * @function Highcharts.Navigator#handlesMousedown
  12428. * @param {Highcharts.PointerEventObject} e
  12429. * Mouse event
  12430. * @param {number} index
  12431. * Index of a handle in Navigator.handles array
  12432. * @return {void}
  12433. */
  12434. Navigator.prototype.handlesMousedown = function (e, index) {
  12435. e = this.chart.pointer.normalize(e);
  12436. var navigator = this,
  12437. chart = navigator.chart,
  12438. baseXAxis = chart.xAxis[0],
  12439. // For reversed axes, min and max are changed,
  12440. // so the other extreme should be stored
  12441. reverse = navigator.reversedExtremes;
  12442. if (index === 0) {
  12443. // Grab the left handle
  12444. navigator.grabbedLeft = true;
  12445. navigator.otherHandlePos = navigator.zoomedMax;
  12446. navigator.fixedExtreme = reverse ? baseXAxis.min : baseXAxis.max;
  12447. }
  12448. else {
  12449. // Grab the right handle
  12450. navigator.grabbedRight = true;
  12451. navigator.otherHandlePos = navigator.zoomedMin;
  12452. navigator.fixedExtreme = reverse ? baseXAxis.max : baseXAxis.min;
  12453. }
  12454. chart.fixedRange = null;
  12455. };
  12456. /**
  12457. * Mouse move event based on x/y mouse position.
  12458. *
  12459. * @private
  12460. * @function Highcharts.Navigator#onMouseMove
  12461. *
  12462. * @param {Highcharts.PointerEventObject} e
  12463. * Mouse event
  12464. */
  12465. Navigator.prototype.onMouseMove = function (e) {
  12466. var navigator = this,
  12467. chart = navigator.chart,
  12468. left = navigator.left,
  12469. navigatorSize = navigator.navigatorSize,
  12470. range = navigator.range,
  12471. dragOffset = navigator.dragOffset,
  12472. inverted = chart.inverted,
  12473. chartX;
  12474. // In iOS, a mousemove event with e.pageX === 0 is fired when holding
  12475. // the finger down in the center of the scrollbar. This should be
  12476. // ignored.
  12477. if (!e.touches || e.touches[0].pageX !== 0) { // #4696
  12478. e = chart.pointer.normalize(e);
  12479. chartX = e.chartX;
  12480. // Swap some options for inverted chart
  12481. if (inverted) {
  12482. left = navigator.top;
  12483. chartX = e.chartY;
  12484. }
  12485. // Drag left handle or top handle
  12486. if (navigator.grabbedLeft) {
  12487. navigator.hasDragged = true;
  12488. navigator.render(0, 0, chartX - left, navigator.otherHandlePos);
  12489. // Drag right handle or bottom handle
  12490. }
  12491. else if (navigator.grabbedRight) {
  12492. navigator.hasDragged = true;
  12493. navigator.render(0, 0, navigator.otherHandlePos, chartX - left);
  12494. // Drag scrollbar or open area in navigator
  12495. }
  12496. else if (navigator.grabbedCenter) {
  12497. navigator.hasDragged = true;
  12498. if (chartX < dragOffset) { // outside left
  12499. chartX = dragOffset;
  12500. // outside right
  12501. }
  12502. else if (chartX >
  12503. navigatorSize + dragOffset - range) {
  12504. chartX = navigatorSize + dragOffset - range;
  12505. }
  12506. navigator.render(0, 0, chartX - dragOffset, chartX - dragOffset + range);
  12507. }
  12508. if (navigator.hasDragged &&
  12509. navigator.scrollbar &&
  12510. pick(navigator.scrollbar.options.liveRedraw,
  12511. // By default, don't run live redraw on VML, on touch
  12512. // devices or if the chart is in boost.
  12513. H.svg && !isTouchDevice && !this.chart.isBoosting)) {
  12514. e.DOMType = e.type; // DOMType is for IE8
  12515. setTimeout(function () {
  12516. navigator.onMouseUp(e);
  12517. }, 0);
  12518. }
  12519. }
  12520. };
  12521. /**
  12522. * Mouse up event based on x/y mouse position.
  12523. *
  12524. * @private
  12525. * @function Highcharts.Navigator#onMouseUp
  12526. * @param {Highcharts.PointerEventObject} e
  12527. * Mouse event
  12528. * @return {void}
  12529. */
  12530. Navigator.prototype.onMouseUp = function (e) {
  12531. var navigator = this,
  12532. chart = navigator.chart,
  12533. xAxis = navigator.xAxis,
  12534. scrollbar = navigator.scrollbar,
  12535. DOMEvent = e.DOMEvent || e,
  12536. inverted = chart.inverted,
  12537. verb = navigator.rendered && !navigator.hasDragged ?
  12538. 'animate' : 'attr',
  12539. zoomedMax,
  12540. zoomedMin,
  12541. unionExtremes,
  12542. fixedMin,
  12543. fixedMax,
  12544. ext;
  12545. if (
  12546. // MouseUp is called for both, navigator and scrollbar (that order),
  12547. // which causes calling afterSetExtremes twice. Prevent first call
  12548. // by checking if scrollbar is going to set new extremes (#6334)
  12549. (navigator.hasDragged && (!scrollbar || !scrollbar.hasDragged)) ||
  12550. e.trigger === 'scrollbar') {
  12551. unionExtremes = navigator.getUnionExtremes();
  12552. // When dragging one handle, make sure the other one doesn't change
  12553. if (navigator.zoomedMin === navigator.otherHandlePos) {
  12554. fixedMin = navigator.fixedExtreme;
  12555. }
  12556. else if (navigator.zoomedMax === navigator.otherHandlePos) {
  12557. fixedMax = navigator.fixedExtreme;
  12558. }
  12559. // Snap to right edge (#4076)
  12560. if (navigator.zoomedMax === navigator.size) {
  12561. fixedMax = navigator.reversedExtremes ?
  12562. unionExtremes.dataMin :
  12563. unionExtremes.dataMax;
  12564. }
  12565. // Snap to left edge (#7576)
  12566. if (navigator.zoomedMin === 0) {
  12567. fixedMin = navigator.reversedExtremes ?
  12568. unionExtremes.dataMax :
  12569. unionExtremes.dataMin;
  12570. }
  12571. ext = xAxis.navigatorAxis.toFixedRange(navigator.zoomedMin, navigator.zoomedMax, fixedMin, fixedMax);
  12572. if (defined(ext.min)) {
  12573. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true,
  12574. // Run animation when clicking buttons, scrollbar track etc,
  12575. // but not when dragging handles or scrollbar
  12576. navigator.hasDragged ? false : null, {
  12577. trigger: 'navigator',
  12578. triggerOp: 'navigator-drag',
  12579. DOMEvent: DOMEvent // #1838
  12580. });
  12581. }
  12582. }
  12583. if (e.DOMType !== 'mousemove' &&
  12584. e.DOMType !== 'touchmove') {
  12585. navigator.grabbedLeft = navigator.grabbedRight =
  12586. navigator.grabbedCenter = navigator.fixedWidth =
  12587. navigator.fixedExtreme = navigator.otherHandlePos =
  12588. navigator.hasDragged = navigator.dragOffset = null;
  12589. }
  12590. // Update position of navigator shades, outline and handles (#12573)
  12591. if (navigator.navigatorEnabled &&
  12592. isNumber(navigator.zoomedMin) &&
  12593. isNumber(navigator.zoomedMax)) {
  12594. zoomedMin = Math.round(navigator.zoomedMin);
  12595. zoomedMax = Math.round(navigator.zoomedMax);
  12596. if (navigator.shades) {
  12597. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  12598. }
  12599. if (navigator.outline) {
  12600. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  12601. }
  12602. if (navigator.navigatorOptions.handles.enabled &&
  12603. Object.keys(navigator.handles).length ===
  12604. navigator.handles.length) {
  12605. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  12606. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  12607. }
  12608. }
  12609. };
  12610. /**
  12611. * Removes the event handlers attached previously with addEvents.
  12612. *
  12613. * @private
  12614. * @function Highcharts.Navigator#removeEvents
  12615. * @return {void}
  12616. */
  12617. Navigator.prototype.removeEvents = function () {
  12618. if (this.eventsToUnbind) {
  12619. this.eventsToUnbind.forEach(function (unbind) {
  12620. unbind();
  12621. });
  12622. this.eventsToUnbind = void 0;
  12623. }
  12624. this.removeBaseSeriesEvents();
  12625. };
  12626. /**
  12627. * Remove data events.
  12628. *
  12629. * @private
  12630. * @function Highcharts.Navigator#removeBaseSeriesEvents
  12631. * @return {void}
  12632. */
  12633. Navigator.prototype.removeBaseSeriesEvents = function () {
  12634. var baseSeries = this.baseSeries || [];
  12635. if (this.navigatorEnabled && baseSeries[0]) {
  12636. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  12637. baseSeries.forEach(function (series) {
  12638. removeEvent(series, 'updatedData', this.updatedDataHandler);
  12639. }, this);
  12640. }
  12641. // We only listen for extremes-events on the first baseSeries
  12642. if (baseSeries[0].xAxis) {
  12643. removeEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  12644. }
  12645. }
  12646. };
  12647. /**
  12648. * Initialize the Navigator object
  12649. *
  12650. * @private
  12651. * @function Highcharts.Navigator#init
  12652. *
  12653. * @param {Highcharts.Chart} chart
  12654. */
  12655. Navigator.prototype.init = function (chart) {
  12656. var chartOptions = chart.options,
  12657. navigatorOptions = chartOptions.navigator,
  12658. navigatorEnabled = navigatorOptions.enabled,
  12659. scrollbarOptions = chartOptions.scrollbar,
  12660. scrollbarEnabled = scrollbarOptions.enabled,
  12661. height = navigatorEnabled ? navigatorOptions.height : 0,
  12662. scrollbarHeight = scrollbarEnabled ?
  12663. scrollbarOptions.height :
  12664. 0;
  12665. this.handles = [];
  12666. this.shades = [];
  12667. this.chart = chart;
  12668. this.setBaseSeries();
  12669. this.height = height;
  12670. this.scrollbarHeight = scrollbarHeight;
  12671. this.scrollbarEnabled = scrollbarEnabled;
  12672. this.navigatorEnabled = navigatorEnabled;
  12673. this.navigatorOptions = navigatorOptions;
  12674. this.scrollbarOptions = scrollbarOptions;
  12675. this.outlineHeight = height + scrollbarHeight;
  12676. this.opposite = pick(navigatorOptions.opposite, Boolean(!navigatorEnabled && chart.inverted)); // #6262
  12677. var navigator = this,
  12678. baseSeries = navigator.baseSeries,
  12679. xAxisIndex = chart.xAxis.length,
  12680. yAxisIndex = chart.yAxis.length,
  12681. baseXaxis = baseSeries && baseSeries[0] && baseSeries[0].xAxis ||
  12682. chart.xAxis[0] || { options: {} };
  12683. chart.isDirtyBox = true;
  12684. if (navigator.navigatorEnabled) {
  12685. // an x axis is required for scrollbar also
  12686. navigator.xAxis = new Axis(chart, merge({
  12687. // inherit base xAxis' break and ordinal options
  12688. breaks: baseXaxis.options.breaks,
  12689. ordinal: baseXaxis.options.ordinal
  12690. }, navigatorOptions.xAxis, {
  12691. id: 'navigator-x-axis',
  12692. yAxis: 'navigator-y-axis',
  12693. isX: true,
  12694. type: 'datetime',
  12695. index: xAxisIndex,
  12696. isInternal: true,
  12697. offset: 0,
  12698. keepOrdinalPadding: true,
  12699. startOnTick: false,
  12700. endOnTick: false,
  12701. minPadding: 0,
  12702. maxPadding: 0,
  12703. zoomEnabled: false
  12704. }, chart.inverted ? {
  12705. offsets: [scrollbarHeight, 0, -scrollbarHeight, 0],
  12706. width: height
  12707. } : {
  12708. offsets: [0, -scrollbarHeight, 0, scrollbarHeight],
  12709. height: height
  12710. }));
  12711. navigator.yAxis = new Axis(chart, merge(navigatorOptions.yAxis, {
  12712. id: 'navigator-y-axis',
  12713. alignTicks: false,
  12714. offset: 0,
  12715. index: yAxisIndex,
  12716. isInternal: true,
  12717. reversed: pick((navigatorOptions.yAxis && navigatorOptions.yAxis.reversed), (chart.yAxis[0] && chart.yAxis[0].reversed), false),
  12718. zoomEnabled: false
  12719. }, chart.inverted ? {
  12720. width: height
  12721. } : {
  12722. height: height
  12723. }));
  12724. // If we have a base series, initialize the navigator series
  12725. if (baseSeries || navigatorOptions.series.data) {
  12726. navigator.updateNavigatorSeries(false);
  12727. // If not, set up an event to listen for added series
  12728. }
  12729. else if (chart.series.length === 0) {
  12730. navigator.unbindRedraw = addEvent(chart, 'beforeRedraw', function () {
  12731. // We've got one, now add it as base
  12732. if (chart.series.length > 0 && !navigator.series) {
  12733. navigator.setBaseSeries();
  12734. navigator.unbindRedraw(); // reset
  12735. }
  12736. });
  12737. }
  12738. navigator.reversedExtremes = (chart.inverted && !navigator.xAxis.reversed) || (!chart.inverted && navigator.xAxis.reversed);
  12739. // Render items, so we can bind events to them:
  12740. navigator.renderElements();
  12741. // Add mouse events
  12742. navigator.addMouseEvents();
  12743. // in case of scrollbar only, fake an x axis to get translation
  12744. }
  12745. else {
  12746. navigator.xAxis = {
  12747. chart: chart,
  12748. navigatorAxis: {
  12749. fake: true
  12750. },
  12751. translate: function (value, reverse) {
  12752. 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;
  12753. return reverse ?
  12754. // from pixel to value
  12755. (value * valueRange / scrollTrackWidth) + min :
  12756. // from value to pixel
  12757. scrollTrackWidth * (value - min) / valueRange;
  12758. },
  12759. toPixels: function (value) {
  12760. return this.translate(value);
  12761. },
  12762. toValue: function (value) {
  12763. return this.translate(value, true);
  12764. }
  12765. };
  12766. navigator.xAxis.navigatorAxis.axis = navigator.xAxis;
  12767. navigator.xAxis.navigatorAxis.toFixedRange = (NavigatorAxis.AdditionsClass.prototype.toFixedRange.bind(navigator.xAxis.navigatorAxis));
  12768. }
  12769. // Initialize the scrollbar
  12770. if (chart.options.scrollbar.enabled) {
  12771. chart.scrollbar = navigator.scrollbar = new Scrollbar(chart.renderer, merge(chart.options.scrollbar, {
  12772. margin: navigator.navigatorEnabled ? 0 : 10,
  12773. vertical: chart.inverted
  12774. }), chart);
  12775. addEvent(navigator.scrollbar, 'changed', function (e) {
  12776. var range = navigator.size,
  12777. to = range * this.to,
  12778. from = range * this.from;
  12779. navigator.hasDragged = navigator.scrollbar.hasDragged;
  12780. navigator.render(0, 0, from, to);
  12781. if (this.shouldUpdateExtremes(e.DOMType)) {
  12782. setTimeout(function () {
  12783. navigator.onMouseUp(e);
  12784. });
  12785. }
  12786. });
  12787. }
  12788. // Add data events
  12789. navigator.addBaseSeriesEvents();
  12790. // Add redraw events
  12791. navigator.addChartEvents();
  12792. };
  12793. /**
  12794. * Get the union data extremes of the chart - the outer data extremes of the
  12795. * base X axis and the navigator axis.
  12796. *
  12797. * @private
  12798. * @function Highcharts.Navigator#getUnionExtremes
  12799. * @param {boolean} [returnFalseOnNoBaseSeries]
  12800. * as the param says.
  12801. * @return {Highcharts.Dictionary<(number|undefined)>|undefined}
  12802. */
  12803. Navigator.prototype.getUnionExtremes = function (returnFalseOnNoBaseSeries) {
  12804. var baseAxis = this.chart.xAxis[0],
  12805. navAxis = this.xAxis,
  12806. navAxisOptions = navAxis.options,
  12807. baseAxisOptions = baseAxis.options,
  12808. ret;
  12809. if (!returnFalseOnNoBaseSeries || baseAxis.dataMin !== null) {
  12810. ret = {
  12811. dataMin: pick(// #4053
  12812. navAxisOptions && navAxisOptions.min, numExt('min', baseAxisOptions.min, baseAxis.dataMin, navAxis.dataMin, navAxis.min)),
  12813. dataMax: pick(navAxisOptions && navAxisOptions.max, numExt('max', baseAxisOptions.max, baseAxis.dataMax, navAxis.dataMax, navAxis.max))
  12814. };
  12815. }
  12816. return ret;
  12817. };
  12818. /**
  12819. * Set the base series and update the navigator series from this. With a bit
  12820. * of modification we should be able to make this an API method to be called
  12821. * from the outside
  12822. *
  12823. * @private
  12824. * @function Highcharts.Navigator#setBaseSeries
  12825. * @param {Highcharts.SeriesOptionsType} [baseSeriesOptions]
  12826. * Additional series options for a navigator
  12827. * @param {boolean} [redraw]
  12828. * Whether to redraw after update.
  12829. * @return {void}
  12830. */
  12831. Navigator.prototype.setBaseSeries = function (baseSeriesOptions, redraw) {
  12832. var chart = this.chart,
  12833. baseSeries = this.baseSeries = [];
  12834. baseSeriesOptions = (baseSeriesOptions ||
  12835. chart.options && chart.options.navigator.baseSeries ||
  12836. (chart.series.length ?
  12837. // Find the first non-navigator series (#8430)
  12838. find(chart.series, function (s) {
  12839. return !s.options.isInternal;
  12840. }).index :
  12841. 0));
  12842. // Iterate through series and add the ones that should be shown in
  12843. // navigator.
  12844. (chart.series || []).forEach(function (series, i) {
  12845. if (
  12846. // Don't include existing nav series
  12847. !series.options.isInternal &&
  12848. (series.options.showInNavigator ||
  12849. (i === baseSeriesOptions ||
  12850. series.options.id === baseSeriesOptions) &&
  12851. series.options.showInNavigator !== false)) {
  12852. baseSeries.push(series);
  12853. }
  12854. });
  12855. // When run after render, this.xAxis already exists
  12856. if (this.xAxis && !this.xAxis.navigatorAxis.fake) {
  12857. this.updateNavigatorSeries(true, redraw);
  12858. }
  12859. };
  12860. /**
  12861. * Update series in the navigator from baseSeries, adding new if does not
  12862. * exist.
  12863. *
  12864. * @private
  12865. * @function Highcharts.Navigator.updateNavigatorSeries
  12866. * @param {boolean} addEvents
  12867. * @param {boolean} [redraw]
  12868. * @return {void}
  12869. */
  12870. Navigator.prototype.updateNavigatorSeries = function (addEvents, redraw) {
  12871. var navigator = this,
  12872. chart = navigator.chart,
  12873. baseSeries = navigator.baseSeries,
  12874. baseOptions,
  12875. mergedNavSeriesOptions,
  12876. chartNavigatorSeriesOptions = navigator.navigatorOptions.series,
  12877. baseNavigatorOptions,
  12878. navSeriesMixin = {
  12879. enableMouseTracking: false,
  12880. index: null,
  12881. linkedTo: null,
  12882. group: 'nav',
  12883. padXAxis: false,
  12884. xAxis: 'navigator-x-axis',
  12885. yAxis: 'navigator-y-axis',
  12886. showInLegend: false,
  12887. stacking: void 0,
  12888. isInternal: true,
  12889. states: {
  12890. inactive: {
  12891. opacity: 1
  12892. }
  12893. }
  12894. },
  12895. // Remove navigator series that are no longer in the baseSeries
  12896. navigatorSeries = navigator.series =
  12897. (navigator.series || []).filter(function (navSeries) {
  12898. var base = navSeries.baseSeries;
  12899. if (baseSeries.indexOf(base) < 0) { // Not in array
  12900. // If there is still a base series connected to this
  12901. // series, remove event handler and reference.
  12902. if (base) {
  12903. removeEvent(base, 'updatedData', navigator.updatedDataHandler);
  12904. delete base.navigatorSeries;
  12905. }
  12906. // Kill the nav series. It may already have been
  12907. // destroyed (#8715).
  12908. if (navSeries.chart) {
  12909. navSeries.destroy();
  12910. }
  12911. return false;
  12912. }
  12913. return true;
  12914. });
  12915. // Go through each base series and merge the options to create new
  12916. // series
  12917. if (baseSeries && baseSeries.length) {
  12918. baseSeries.forEach(function eachBaseSeries(base) {
  12919. var linkedNavSeries = base.navigatorSeries,
  12920. userNavOptions = extend(
  12921. // Grab color and visibility from base as default
  12922. {
  12923. color: base.color,
  12924. visible: base.visible
  12925. }, !isArray(chartNavigatorSeriesOptions) ?
  12926. chartNavigatorSeriesOptions :
  12927. defaultOptions.navigator.series);
  12928. // Don't update if the series exists in nav and we have disabled
  12929. // adaptToUpdatedData.
  12930. if (linkedNavSeries &&
  12931. navigator.navigatorOptions.adaptToUpdatedData === false) {
  12932. return;
  12933. }
  12934. navSeriesMixin.name = 'Navigator ' + baseSeries.length;
  12935. baseOptions = base.options || {};
  12936. baseNavigatorOptions = baseOptions.navigatorOptions || {};
  12937. // The dataLabels options are not merged correctly
  12938. // if the settings are an array, #13847.
  12939. userNavOptions.dataLabels = splat(userNavOptions.dataLabels);
  12940. mergedNavSeriesOptions = merge(baseOptions, navSeriesMixin, userNavOptions, baseNavigatorOptions);
  12941. // Once nav series type is resolved, pick correct pointRange
  12942. mergedNavSeriesOptions.pointRange = pick(
  12943. // Stricte set pointRange in options
  12944. userNavOptions.pointRange, baseNavigatorOptions.pointRange,
  12945. // Fallback to default values, e.g. `null` for column
  12946. defaultOptions.plotOptions[mergedNavSeriesOptions.type || 'line'].pointRange);
  12947. // Merge data separately. Do a slice to avoid mutating the
  12948. // navigator options from base series (#4923).
  12949. var navigatorSeriesData = baseNavigatorOptions.data || userNavOptions.data;
  12950. navigator.hasNavigatorData =
  12951. navigator.hasNavigatorData || !!navigatorSeriesData;
  12952. mergedNavSeriesOptions.data =
  12953. navigatorSeriesData ||
  12954. baseOptions.data && baseOptions.data.slice(0);
  12955. // Update or add the series
  12956. if (linkedNavSeries && linkedNavSeries.options) {
  12957. linkedNavSeries.update(mergedNavSeriesOptions, redraw);
  12958. }
  12959. else {
  12960. base.navigatorSeries = chart.initSeries(mergedNavSeriesOptions);
  12961. base.navigatorSeries.baseSeries = base; // Store ref
  12962. navigatorSeries.push(base.navigatorSeries);
  12963. }
  12964. });
  12965. }
  12966. // If user has defined data (and no base series) or explicitly defined
  12967. // navigator.series as an array, we create these series on top of any
  12968. // base series.
  12969. if (chartNavigatorSeriesOptions.data &&
  12970. !(baseSeries && baseSeries.length) ||
  12971. isArray(chartNavigatorSeriesOptions)) {
  12972. navigator.hasNavigatorData = false;
  12973. // Allow navigator.series to be an array
  12974. chartNavigatorSeriesOptions =
  12975. splat(chartNavigatorSeriesOptions);
  12976. chartNavigatorSeriesOptions.forEach(function (userSeriesOptions, i) {
  12977. navSeriesMixin.name =
  12978. 'Navigator ' + (navigatorSeries.length + 1);
  12979. mergedNavSeriesOptions = merge(defaultOptions.navigator.series, {
  12980. // Since we don't have a base series to pull color from,
  12981. // try to fake it by using color from series with same
  12982. // index. Otherwise pull from the colors array. We need
  12983. // an explicit color as otherwise updates will increment
  12984. // color counter and we'll get a new color for each
  12985. // update of the nav series.
  12986. color: chart.series[i] &&
  12987. !chart.series[i].options.isInternal &&
  12988. chart.series[i].color ||
  12989. chart.options.colors[i] ||
  12990. chart.options.colors[0]
  12991. }, navSeriesMixin, userSeriesOptions);
  12992. mergedNavSeriesOptions.data = userSeriesOptions.data;
  12993. if (mergedNavSeriesOptions.data) {
  12994. navigator.hasNavigatorData = true;
  12995. navigatorSeries.push(chart.initSeries(mergedNavSeriesOptions));
  12996. }
  12997. });
  12998. }
  12999. if (addEvents) {
  13000. this.addBaseSeriesEvents();
  13001. }
  13002. };
  13003. /**
  13004. * Add data events.
  13005. * For example when main series is updated we need to recalculate extremes
  13006. *
  13007. * @private
  13008. * @function Highcharts.Navigator#addBaseSeriesEvent
  13009. * @return {void}
  13010. */
  13011. Navigator.prototype.addBaseSeriesEvents = function () {
  13012. var navigator = this,
  13013. baseSeries = navigator.baseSeries || [];
  13014. // Bind modified extremes event to first base's xAxis only.
  13015. // In event of > 1 base-xAxes, the navigator will ignore those.
  13016. // Adding this multiple times to the same axis is no problem, as
  13017. // duplicates should be discarded by the browser.
  13018. if (baseSeries[0] && baseSeries[0].xAxis) {
  13019. baseSeries[0].eventsToUnbind.push(addEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes));
  13020. }
  13021. baseSeries.forEach(function (base) {
  13022. // Link base series show/hide to navigator series visibility
  13023. base.eventsToUnbind.push(addEvent(base, 'show', function () {
  13024. if (this.navigatorSeries) {
  13025. this.navigatorSeries.setVisible(true, false);
  13026. }
  13027. }));
  13028. base.eventsToUnbind.push(addEvent(base, 'hide', function () {
  13029. if (this.navigatorSeries) {
  13030. this.navigatorSeries.setVisible(false, false);
  13031. }
  13032. }));
  13033. // Respond to updated data in the base series, unless explicitily
  13034. // not adapting to data changes.
  13035. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  13036. if (base.xAxis) {
  13037. base.eventsToUnbind.push(addEvent(base, 'updatedData', this.updatedDataHandler));
  13038. }
  13039. }
  13040. // Handle series removal
  13041. base.eventsToUnbind.push(addEvent(base, 'remove', function () {
  13042. if (this.navigatorSeries) {
  13043. erase(navigator.series, this.navigatorSeries);
  13044. if (defined(this.navigatorSeries.options)) {
  13045. this.navigatorSeries.remove(false);
  13046. }
  13047. delete this.navigatorSeries;
  13048. }
  13049. }));
  13050. }, this);
  13051. };
  13052. /**
  13053. * Get minimum from all base series connected to the navigator
  13054. * @private
  13055. * @param {number} currentSeriesMin
  13056. * Minium from the current series
  13057. * @return {number} Minimum from all series
  13058. */
  13059. Navigator.prototype.getBaseSeriesMin = function (currentSeriesMin) {
  13060. return this.baseSeries.reduce(function (min, series) {
  13061. // (#10193)
  13062. return Math.min(min, series.xData ? series.xData[0] : min);
  13063. }, currentSeriesMin);
  13064. };
  13065. /**
  13066. * Set the navigator x axis extremes to reflect the total. The navigator
  13067. * extremes should always be the extremes of the union of all series in the
  13068. * chart as well as the navigator series.
  13069. *
  13070. * @private
  13071. * @function Highcharts.Navigator#modifyNavigatorAxisExtremes
  13072. */
  13073. Navigator.prototype.modifyNavigatorAxisExtremes = function () {
  13074. var xAxis = this.xAxis,
  13075. unionExtremes;
  13076. if (typeof xAxis.getExtremes !== 'undefined') {
  13077. unionExtremes = this.getUnionExtremes(true);
  13078. if (unionExtremes &&
  13079. (unionExtremes.dataMin !== xAxis.min ||
  13080. unionExtremes.dataMax !== xAxis.max)) {
  13081. xAxis.min = unionExtremes.dataMin;
  13082. xAxis.max = unionExtremes.dataMax;
  13083. }
  13084. }
  13085. };
  13086. /**
  13087. * Hook to modify the base axis extremes with information from the Navigator
  13088. *
  13089. * @private
  13090. * @function Highcharts.Navigator#modifyBaseAxisExtremes
  13091. */
  13092. Navigator.prototype.modifyBaseAxisExtremes = function () {
  13093. var baseXAxis = this,
  13094. navigator = baseXAxis.chart.navigator,
  13095. baseExtremes = baseXAxis.getExtremes(),
  13096. baseMin = baseExtremes.min,
  13097. baseMax = baseExtremes.max,
  13098. baseDataMin = baseExtremes.dataMin,
  13099. baseDataMax = baseExtremes.dataMax,
  13100. range = baseMax - baseMin,
  13101. stickToMin = navigator.stickToMin,
  13102. stickToMax = navigator.stickToMax,
  13103. overscroll = pick(baseXAxis.options.overscroll, 0),
  13104. newMax,
  13105. newMin,
  13106. navigatorSeries = navigator.series && navigator.series[0],
  13107. hasSetExtremes = !!baseXAxis.setExtremes,
  13108. // When the extremes have been set by range selector button, don't
  13109. // stick to min or max. The range selector buttons will handle the
  13110. // extremes. (#5489)
  13111. unmutable = baseXAxis.eventArgs &&
  13112. baseXAxis.eventArgs.trigger === 'rangeSelectorButton';
  13113. if (!unmutable) {
  13114. // If the zoomed range is already at the min, move it to the right
  13115. // as new data comes in
  13116. if (stickToMin) {
  13117. newMin = baseDataMin;
  13118. newMax = newMin + range;
  13119. }
  13120. // If the zoomed range is already at the max, move it to the right
  13121. // as new data comes in
  13122. if (stickToMax) {
  13123. newMax = baseDataMax + overscroll;
  13124. // If stickToMin is true, the new min value is set above
  13125. if (!stickToMin) {
  13126. newMin = Math.max(baseDataMin, // don't go below data extremes (#13184)
  13127. newMax - range, navigator.getBaseSeriesMin(navigatorSeries && navigatorSeries.xData ?
  13128. navigatorSeries.xData[0] :
  13129. -Number.MAX_VALUE));
  13130. }
  13131. }
  13132. // Update the extremes
  13133. if (hasSetExtremes && (stickToMin || stickToMax)) {
  13134. if (isNumber(newMin)) {
  13135. baseXAxis.min = baseXAxis.userMin = newMin;
  13136. baseXAxis.max = baseXAxis.userMax = newMax;
  13137. }
  13138. }
  13139. }
  13140. // Reset
  13141. navigator.stickToMin =
  13142. navigator.stickToMax = null;
  13143. };
  13144. /**
  13145. * Handler for updated data on the base series. When data is modified, the
  13146. * navigator series must reflect it. This is called from the Chart.redraw
  13147. * function before axis and series extremes are computed.
  13148. *
  13149. * @private
  13150. * @function Highcharts.Navigator#updateDataHandler
  13151. */
  13152. Navigator.prototype.updatedDataHandler = function () {
  13153. var navigator = this.chart.navigator,
  13154. baseSeries = this,
  13155. navigatorSeries = this.navigatorSeries;
  13156. // If the scrollbar is scrolled all the way to the right, keep right as
  13157. // new data comes in.
  13158. navigator.stickToMax = navigator.reversedExtremes ?
  13159. Math.round(navigator.zoomedMin) === 0 :
  13160. Math.round(navigator.zoomedMax) >= Math.round(navigator.size);
  13161. navigator.stickToMin = navigator.shouldStickToMin(baseSeries, navigator);
  13162. // Set the navigator series data to the new data of the base series
  13163. if (navigatorSeries && !navigator.hasNavigatorData) {
  13164. navigatorSeries.options.pointStart = baseSeries.xData[0];
  13165. navigatorSeries.setData(baseSeries.options.data, false, null, false); // #5414
  13166. }
  13167. };
  13168. /**
  13169. * Detect if the zoomed area should stick to the minimum, #14742.
  13170. *
  13171. * @private
  13172. * @function Highcharts.Navigator#shouldStickToMin
  13173. */
  13174. Navigator.prototype.shouldStickToMin = function (baseSeries, navigator) {
  13175. var xDataMin = navigator.getBaseSeriesMin(baseSeries.xData[0]),
  13176. xAxis = baseSeries.xAxis,
  13177. max = xAxis.max,
  13178. min = xAxis.min,
  13179. range = xAxis.options.range;
  13180. var stickToMin = true;
  13181. if (isNumber(max) && isNumber(min)) {
  13182. // If range declared, stick to the minimum only if the range
  13183. // is smaller than the data set range.
  13184. if (range && max - xDataMin > 0) {
  13185. stickToMin = max - xDataMin < range && (!this.chart.fixedRange);
  13186. }
  13187. else {
  13188. // If the current axis minimum falls outside the new
  13189. // updated dataset, we must adjust.
  13190. stickToMin = min <= xDataMin;
  13191. }
  13192. }
  13193. return stickToMin;
  13194. };
  13195. /**
  13196. * Add chart events, like redrawing navigator, when chart requires that.
  13197. *
  13198. * @private
  13199. * @function Highcharts.Navigator#addChartEvents
  13200. * @return {void}
  13201. */
  13202. Navigator.prototype.addChartEvents = function () {
  13203. if (!this.eventsToUnbind) {
  13204. this.eventsToUnbind = [];
  13205. }
  13206. this.eventsToUnbind.push(
  13207. // Move the scrollbar after redraw, like after data updata even if
  13208. // axes don't redraw
  13209. addEvent(this.chart, 'redraw', function () {
  13210. var navigator = this.navigator,
  13211. xAxis = navigator && (navigator.baseSeries &&
  13212. navigator.baseSeries[0] &&
  13213. navigator.baseSeries[0].xAxis ||
  13214. this.xAxis[0]); // #5709, #13114
  13215. if (xAxis) {
  13216. navigator.render(xAxis.min,
  13217. xAxis.max);
  13218. }
  13219. }),
  13220. // Make room for the navigator, can be placed around the chart:
  13221. addEvent(this.chart, 'getMargins', function () {
  13222. var chart = this,
  13223. navigator = chart.navigator,
  13224. marginName = navigator.opposite ?
  13225. 'plotTop' : 'marginBottom';
  13226. if (chart.inverted) {
  13227. marginName = navigator.opposite ?
  13228. 'marginRight' : 'plotLeft';
  13229. }
  13230. chart[marginName] =
  13231. (chart[marginName] || 0) + (navigator.navigatorEnabled || !chart.inverted ?
  13232. navigator.outlineHeight :
  13233. 0) + navigator.navigatorOptions.margin;
  13234. }));
  13235. };
  13236. /**
  13237. * Destroys allocated elements.
  13238. *
  13239. * @private
  13240. * @function Highcharts.Navigator#destroy
  13241. */
  13242. Navigator.prototype.destroy = function () {
  13243. // Disconnect events added in addEvents
  13244. this.removeEvents();
  13245. if (this.xAxis) {
  13246. erase(this.chart.xAxis, this.xAxis);
  13247. erase(this.chart.axes, this.xAxis);
  13248. }
  13249. if (this.yAxis) {
  13250. erase(this.chart.yAxis, this.yAxis);
  13251. erase(this.chart.axes, this.yAxis);
  13252. }
  13253. // Destroy series
  13254. (this.series || []).forEach(function (s) {
  13255. if (s.destroy) {
  13256. s.destroy();
  13257. }
  13258. });
  13259. // Destroy properties
  13260. [
  13261. 'series', 'xAxis', 'yAxis', 'shades', 'outline', 'scrollbarTrack',
  13262. 'scrollbarRifles', 'scrollbarGroup', 'scrollbar', 'navigatorGroup',
  13263. 'rendered'
  13264. ].forEach(function (prop) {
  13265. if (this[prop] && this[prop].destroy) {
  13266. this[prop].destroy();
  13267. }
  13268. this[prop] = null;
  13269. }, this);
  13270. // Destroy elements in collection
  13271. [this.handles].forEach(function (coll) {
  13272. destroyObjectProperties(coll);
  13273. }, this);
  13274. };
  13275. return Navigator;
  13276. }());
  13277. // End of prototype
  13278. if (!H.Navigator) {
  13279. H.Navigator = Navigator;
  13280. NavigatorAxis.compose(Axis);
  13281. // For Stock charts. For x only zooming, do not to create the zoom button
  13282. // because X axis zooming is already allowed by the Navigator and Range
  13283. // selector. (#9285)
  13284. addEvent(Chart, 'beforeShowResetZoom', function () {
  13285. var chartOptions = this.options,
  13286. navigator = chartOptions.navigator,
  13287. rangeSelector = chartOptions.rangeSelector;
  13288. if (((navigator && navigator.enabled) ||
  13289. (rangeSelector && rangeSelector.enabled)) &&
  13290. ((!isTouchDevice && chartOptions.chart.zoomType === 'x') ||
  13291. (isTouchDevice && chartOptions.chart.pinchType === 'x'))) {
  13292. return false;
  13293. }
  13294. });
  13295. // Initialize navigator for stock charts
  13296. addEvent(Chart, 'beforeRender', function () {
  13297. var options = this.options;
  13298. if (options.navigator.enabled ||
  13299. options.scrollbar.enabled) {
  13300. this.scroller = this.navigator = new Navigator(this);
  13301. }
  13302. });
  13303. // For stock charts, extend the Chart.setChartSize method so that we can set
  13304. // the final top position of the navigator once the height of the chart,
  13305. // including the legend, is determined. #367. We can't use Chart.getMargins,
  13306. // because labels offsets are not calculated yet.
  13307. addEvent(Chart, 'afterSetChartSize', function () {
  13308. var legend = this.legend,
  13309. navigator = this.navigator,
  13310. scrollbarHeight,
  13311. legendOptions,
  13312. xAxis,
  13313. yAxis;
  13314. if (navigator) {
  13315. legendOptions = legend && legend.options;
  13316. xAxis = navigator.xAxis;
  13317. yAxis = navigator.yAxis;
  13318. scrollbarHeight = navigator.scrollbarHeight;
  13319. // Compute the top position
  13320. if (this.inverted) {
  13321. navigator.left = navigator.opposite ?
  13322. this.chartWidth - scrollbarHeight -
  13323. navigator.height :
  13324. this.spacing[3] + scrollbarHeight;
  13325. navigator.top = this.plotTop + scrollbarHeight;
  13326. }
  13327. else {
  13328. navigator.left = pick(xAxis.left, this.plotLeft + scrollbarHeight);
  13329. navigator.top = navigator.navigatorOptions.top ||
  13330. this.chartHeight -
  13331. navigator.height -
  13332. scrollbarHeight -
  13333. this.spacing[2] -
  13334. (this.rangeSelector && this.extraBottomMargin ?
  13335. this.rangeSelector.getHeight() :
  13336. 0) -
  13337. ((legendOptions &&
  13338. legendOptions.verticalAlign === 'bottom' &&
  13339. legendOptions.layout !== 'proximate' && // #13392
  13340. legendOptions.enabled &&
  13341. !legendOptions.floating) ?
  13342. legend.legendHeight +
  13343. pick(legendOptions.margin, 10) :
  13344. 0) -
  13345. (this.titleOffset ? this.titleOffset[2] : 0);
  13346. }
  13347. if (xAxis && yAxis) { // false if navigator is disabled (#904)
  13348. if (this.inverted) {
  13349. xAxis.options.left = yAxis.options.left = navigator.left;
  13350. }
  13351. else {
  13352. xAxis.options.top = yAxis.options.top = navigator.top;
  13353. }
  13354. xAxis.setAxisSize();
  13355. yAxis.setAxisSize();
  13356. }
  13357. }
  13358. });
  13359. // Merge options, if no scrolling exists yet
  13360. addEvent(Chart, 'update', function (e) {
  13361. var navigatorOptions = (e.options.navigator || {}),
  13362. scrollbarOptions = (e.options.scrollbar || {});
  13363. if (!this.navigator && !this.scroller &&
  13364. (navigatorOptions.enabled || scrollbarOptions.enabled)) {
  13365. merge(true, this.options.navigator, navigatorOptions);
  13366. merge(true, this.options.scrollbar, scrollbarOptions);
  13367. delete e.options.navigator;
  13368. delete e.options.scrollbar;
  13369. }
  13370. });
  13371. // Initialize navigator, if no scrolling exists yet
  13372. addEvent(Chart, 'afterUpdate', function (event) {
  13373. if (!this.navigator && !this.scroller &&
  13374. (this.options.navigator.enabled ||
  13375. this.options.scrollbar.enabled)) {
  13376. this.scroller = this.navigator = new Navigator(this);
  13377. if (pick(event.redraw, true)) {
  13378. this.redraw(event.animation); // #7067
  13379. }
  13380. }
  13381. });
  13382. // Handle adding new series
  13383. addEvent(Chart, 'afterAddSeries', function () {
  13384. if (this.navigator) {
  13385. // Recompute which series should be shown in navigator, and add them
  13386. this.navigator.setBaseSeries(null, false);
  13387. }
  13388. });
  13389. // Handle updating series
  13390. addEvent(Series, 'afterUpdate', function () {
  13391. if (this.chart.navigator && !this.options.isInternal) {
  13392. this.chart.navigator.setBaseSeries(null, false);
  13393. }
  13394. });
  13395. Chart.prototype.callbacks.push(function (chart) {
  13396. var extremes,
  13397. navigator = chart.navigator;
  13398. // Initialize the navigator
  13399. if (navigator && chart.xAxis[0]) {
  13400. extremes = chart.xAxis[0].getExtremes();
  13401. navigator.render(extremes.min, extremes.max);
  13402. }
  13403. });
  13404. }
  13405. H.Navigator = Navigator;
  13406. return H.Navigator;
  13407. });
  13408. _registerModule(_modules, 'masters/modules/gantt.src.js', [_modules['Core/Globals.js'], _modules['Core/Chart/GanttChart.js']], function (Highcharts, GanttChart) {
  13409. Highcharts.GanttChart = GanttChart;
  13410. Highcharts.ganttChart = GanttChart.ganttChart;
  13411. });
  13412. }));