gantt.src.js 525 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203
  1. /**
  2. * @license Highcharts Gantt JS v8.2.0 (2020-08-20)
  3. *
  4. * Gantt series
  5. *
  6. * (c) 2016-2019 Lars A. V. Cabrera
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/gantt', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'Gantt/Tree.js', [_modules['Core/Utilities.js']], function (U) {
  32. /* *
  33. *
  34. * (c) 2016-2020 Highsoft AS
  35. *
  36. * Authors: Jon Arild Nygard
  37. *
  38. * License: www.highcharts.com/license
  39. *
  40. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  41. *
  42. * */
  43. /* eslint no-console: 0 */
  44. var extend = U.extend,
  45. isNumber = U.isNumber,
  46. pick = U.pick;
  47. /**
  48. * Creates an object map from parent id to childrens index.
  49. *
  50. * @private
  51. * @function Highcharts.Tree#getListOfParents
  52. *
  53. * @param {Array<*>} data
  54. * List of points set in options. `Array.parent` is parent id of point.
  55. *
  56. * @param {Array<string>} ids
  57. * List of all point ids.
  58. *
  59. * @return {Highcharts.Dictionary<Array<*>>}
  60. * Map from parent id to children index in data
  61. */
  62. var getListOfParents = function (data,
  63. ids) {
  64. var listOfParents = data.reduce(function (prev,
  65. curr) {
  66. var parent = pick(curr.parent, '');
  67. if (typeof prev[parent] === 'undefined') {
  68. prev[parent] = [];
  69. }
  70. prev[parent].push(curr);
  71. return prev;
  72. }, {}), parents = Object.keys(listOfParents);
  73. // If parent does not exist, hoist parent to root of tree.
  74. parents.forEach(function (parent, list) {
  75. var children = listOfParents[parent];
  76. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  77. children.forEach(function (child) {
  78. list[''].push(child);
  79. });
  80. delete list[parent];
  81. }
  82. });
  83. return listOfParents;
  84. };
  85. var getNode = function (id,
  86. parent,
  87. level,
  88. data,
  89. mapOfIdToChildren,
  90. options) {
  91. var descendants = 0,
  92. height = 0,
  93. after = options && options.after,
  94. before = options && options.before,
  95. node = {
  96. data: data,
  97. depth: level - 1,
  98. id: id,
  99. level: level,
  100. parent: parent
  101. },
  102. start,
  103. end,
  104. children;
  105. // Allow custom logic before the children has been created.
  106. if (typeof before === 'function') {
  107. before(node, options);
  108. }
  109. // Call getNode recursively on the children. Calulate the height of the
  110. // node, and the number of descendants.
  111. children = ((mapOfIdToChildren[id] || [])).map(function (child) {
  112. var node = getNode(child.id,
  113. id, (level + 1),
  114. child,
  115. mapOfIdToChildren,
  116. options),
  117. childStart = child.start,
  118. childEnd = (child.milestone === true ?
  119. childStart :
  120. child.end);
  121. // Start should be the lowest child.start.
  122. start = ((!isNumber(start) || childStart < start) ?
  123. childStart :
  124. start);
  125. // End should be the largest child.end.
  126. // If child is milestone, then use start as end.
  127. end = ((!isNumber(end) || childEnd > end) ?
  128. childEnd :
  129. end);
  130. descendants = descendants + 1 + node.descendants;
  131. height = Math.max(node.height + 1, height);
  132. return node;
  133. });
  134. // Calculate start and end for point if it is not already explicitly set.
  135. if (data) {
  136. data.start = pick(data.start, start);
  137. data.end = pick(data.end, end);
  138. }
  139. extend(node, {
  140. children: children,
  141. descendants: descendants,
  142. height: height
  143. });
  144. // Allow custom logic after the children has been created.
  145. if (typeof after === 'function') {
  146. after(node, options);
  147. }
  148. return node;
  149. };
  150. var getTree = function (data,
  151. options) {
  152. var ids = data.map(function (d) {
  153. return d.id;
  154. }), mapOfIdToChildren = getListOfParents(data, ids);
  155. return getNode('', null, 1, null, mapOfIdToChildren, options);
  156. };
  157. var Tree = {
  158. getListOfParents: getListOfParents,
  159. getNode: getNode,
  160. getTree: getTree
  161. };
  162. return Tree;
  163. });
  164. _registerModule(_modules, 'Core/Axis/TreeGridTick.js', [_modules['Core/Utilities.js']], function (U) {
  165. /* *
  166. *
  167. * (c) 2016 Highsoft AS
  168. * Authors: Jon Arild Nygard
  169. *
  170. * License: www.highcharts.com/license
  171. *
  172. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  173. *
  174. * */
  175. var addEvent = U.addEvent,
  176. defined = U.defined,
  177. isObject = U.isObject,
  178. isNumber = U.isNumber,
  179. pick = U.pick,
  180. wrap = U.wrap;
  181. /**
  182. * @private
  183. */
  184. var TreeGridTick;
  185. (function (TreeGridTick) {
  186. /* *
  187. *
  188. * Interfaces
  189. *
  190. * */
  191. /* *
  192. *
  193. * Variables
  194. *
  195. * */
  196. var applied = false;
  197. /* *
  198. *
  199. * Functions
  200. *
  201. * */
  202. /**
  203. * @private
  204. */
  205. function compose(TickClass) {
  206. if (!applied) {
  207. addEvent(TickClass, 'init', onInit);
  208. wrap(TickClass.prototype, 'getLabelPosition', wrapGetLabelPosition);
  209. wrap(TickClass.prototype, 'renderLabel', wrapRenderLabel);
  210. // backwards compatibility
  211. TickClass.prototype.collapse = function (redraw) {
  212. this.treeGrid.collapse(redraw);
  213. };
  214. TickClass.prototype.expand = function (redraw) {
  215. this.treeGrid.expand(redraw);
  216. };
  217. TickClass.prototype.toggleCollapse = function (redraw) {
  218. this.treeGrid.toggleCollapse(redraw);
  219. };
  220. applied = true;
  221. }
  222. }
  223. TreeGridTick.compose = compose;
  224. /**
  225. * @private
  226. */
  227. function onInit() {
  228. var tick = this;
  229. if (!tick.treeGrid) {
  230. tick.treeGrid = new Additions(tick);
  231. }
  232. }
  233. /**
  234. * @private
  235. */
  236. function onTickHover(label) {
  237. label.addClass('highcharts-treegrid-node-active');
  238. if (!label.renderer.styledMode) {
  239. label.css({
  240. textDecoration: 'underline'
  241. });
  242. }
  243. }
  244. /**
  245. * @private
  246. */
  247. function onTickHoverExit(label, options) {
  248. var css = defined(options.style) ? options.style : {};
  249. label.removeClass('highcharts-treegrid-node-active');
  250. if (!label.renderer.styledMode) {
  251. label.css({ textDecoration: css.textDecoration });
  252. }
  253. }
  254. /**
  255. * @private
  256. */
  257. function renderLabelIcon(tick, params) {
  258. var treeGrid = tick.treeGrid,
  259. isNew = !treeGrid.labelIcon,
  260. renderer = params.renderer,
  261. labelBox = params.xy,
  262. options = params.options,
  263. width = options.width,
  264. height = options.height,
  265. iconCenter = {
  266. x: labelBox.x - (width / 2) - options.padding,
  267. y: labelBox.y - (height / 2)
  268. },
  269. rotation = params.collapsed ? 90 : 180,
  270. shouldRender = params.show && isNumber(iconCenter.y);
  271. var icon = treeGrid.labelIcon;
  272. if (!icon) {
  273. treeGrid.labelIcon = icon = renderer
  274. .path(renderer.symbols[options.type](options.x, options.y, width, height))
  275. .addClass('highcharts-label-icon')
  276. .add(params.group);
  277. }
  278. // Set the new position, and show or hide
  279. if (!shouldRender) {
  280. icon.attr({ y: -9999 }); // #1338
  281. }
  282. // Presentational attributes
  283. if (!renderer.styledMode) {
  284. icon
  285. .attr({
  286. 'stroke-width': 1,
  287. 'fill': pick(params.color, '#666666')
  288. })
  289. .css({
  290. cursor: 'pointer',
  291. stroke: options.lineColor,
  292. strokeWidth: options.lineWidth
  293. });
  294. }
  295. // Update the icon positions
  296. icon[isNew ? 'attr' : 'animate']({
  297. translateX: iconCenter.x,
  298. translateY: iconCenter.y,
  299. rotation: rotation
  300. });
  301. }
  302. /**
  303. * @private
  304. */
  305. function wrapGetLabelPosition(proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
  306. var tick = this,
  307. lbOptions = pick(tick.options && tick.options.labels,
  308. labelOptions),
  309. pos = tick.pos,
  310. axis = tick.axis,
  311. options = axis.options,
  312. isTreeGrid = options.type === 'treegrid',
  313. result = proceed.apply(tick,
  314. [x,
  315. y,
  316. label,
  317. horiz,
  318. lbOptions,
  319. tickmarkOffset,
  320. index,
  321. step]);
  322. var symbolOptions,
  323. indentation,
  324. mapOfPosToGridNode,
  325. node,
  326. level;
  327. if (isTreeGrid) {
  328. symbolOptions = (lbOptions && isObject(lbOptions.symbol, true) ?
  329. lbOptions.symbol :
  330. {});
  331. indentation = (lbOptions && isNumber(lbOptions.indentation) ?
  332. lbOptions.indentation :
  333. 0);
  334. mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode;
  335. node = mapOfPosToGridNode && mapOfPosToGridNode[pos];
  336. level = (node && node.depth) || 1;
  337. result.x += (
  338. // Add space for symbols
  339. ((symbolOptions.width) + (symbolOptions.padding * 2)) +
  340. // Apply indentation
  341. ((level - 1) * indentation));
  342. }
  343. return result;
  344. }
  345. /**
  346. * @private
  347. */
  348. function wrapRenderLabel(proceed) {
  349. var tick = this, pos = tick.pos, axis = tick.axis, label = tick.label, mapOfPosToGridNode = axis.treeGrid.mapOfPosToGridNode, options = axis.options, labelOptions = pick(tick.options && tick.options.labels, options && options.labels), symbolOptions = (labelOptions && isObject(labelOptions.symbol, true) ?
  350. labelOptions.symbol :
  351. {}), node = mapOfPosToGridNode && mapOfPosToGridNode[pos], level = node && node.depth, isTreeGrid = options.type === 'treegrid', shouldRender = axis.tickPositions.indexOf(pos) > -1, prefixClassName = 'highcharts-treegrid-node-', styledMode = axis.chart.styledMode;
  352. var collapsed,
  353. addClassName,
  354. removeClassName;
  355. if (isTreeGrid && node) {
  356. // Add class name for hierarchical styling.
  357. if (label &&
  358. label.element) {
  359. label.addClass(prefixClassName + 'level-' + level);
  360. }
  361. }
  362. proceed.apply(tick, Array.prototype.slice.call(arguments, 1));
  363. if (isTreeGrid &&
  364. label &&
  365. label.element &&
  366. node &&
  367. node.descendants &&
  368. node.descendants > 0) {
  369. collapsed = axis.treeGrid.isCollapsed(node);
  370. renderLabelIcon(tick, {
  371. color: !styledMode && label.styles && label.styles.color || '',
  372. collapsed: collapsed,
  373. group: label.parentGroup,
  374. options: symbolOptions,
  375. renderer: label.renderer,
  376. show: shouldRender,
  377. xy: label.xy
  378. });
  379. // Add class name for the node.
  380. addClassName = prefixClassName +
  381. (collapsed ? 'collapsed' : 'expanded');
  382. removeClassName = prefixClassName +
  383. (collapsed ? 'expanded' : 'collapsed');
  384. label
  385. .addClass(addClassName)
  386. .removeClass(removeClassName);
  387. if (!styledMode) {
  388. label.css({
  389. cursor: 'pointer'
  390. });
  391. }
  392. // Add events to both label text and icon
  393. [label, tick.treeGrid.labelIcon].forEach(function (object) {
  394. if (object && !object.attachedTreeGridEvents) {
  395. // On hover
  396. addEvent(object.element, 'mouseover', function () {
  397. onTickHover(label);
  398. });
  399. // On hover out
  400. addEvent(object.element, 'mouseout', function () {
  401. onTickHoverExit(label, labelOptions);
  402. });
  403. addEvent(object.element, 'click', function () {
  404. tick.treeGrid.toggleCollapse();
  405. });
  406. object.attachedTreeGridEvents = true;
  407. }
  408. });
  409. }
  410. }
  411. /* *
  412. *
  413. * Classes
  414. *
  415. * */
  416. /**
  417. * @private
  418. * @class
  419. */
  420. var Additions = /** @class */ (function () {
  421. /* *
  422. *
  423. * Constructors
  424. *
  425. * */
  426. /**
  427. * @private
  428. */
  429. function Additions(tick) {
  430. this.tick = tick;
  431. }
  432. /* *
  433. *
  434. * Functions
  435. *
  436. * */
  437. /**
  438. * Collapse the grid cell. Used when axis is of type treegrid.
  439. *
  440. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  441. *
  442. * @private
  443. * @function Highcharts.Tick#collapse
  444. *
  445. * @param {boolean} [redraw=true]
  446. * Whether to redraw the chart or wait for an explicit call to
  447. * {@link Highcharts.Chart#redraw}
  448. */
  449. Additions.prototype.collapse = function (redraw) {
  450. var tick = this.tick,
  451. axis = tick.axis,
  452. brokenAxis = axis.brokenAxis;
  453. if (brokenAxis &&
  454. axis.treeGrid.mapOfPosToGridNode) {
  455. var pos = tick.pos,
  456. node = axis.treeGrid.mapOfPosToGridNode[pos],
  457. breaks = axis.treeGrid.collapse(node);
  458. brokenAxis.setBreaks(breaks, pick(redraw, true));
  459. }
  460. };
  461. /**
  462. * Expand the grid cell. Used when axis is of type treegrid.
  463. *
  464. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  465. *
  466. * @private
  467. * @function Highcharts.Tick#expand
  468. *
  469. * @param {boolean} [redraw=true]
  470. * Whether to redraw the chart or wait for an explicit call to
  471. * {@link Highcharts.Chart#redraw}
  472. */
  473. Additions.prototype.expand = function (redraw) {
  474. var tick = this.tick,
  475. axis = tick.axis,
  476. brokenAxis = axis.brokenAxis;
  477. if (brokenAxis &&
  478. axis.treeGrid.mapOfPosToGridNode) {
  479. var pos = tick.pos,
  480. node = axis.treeGrid.mapOfPosToGridNode[pos],
  481. breaks = axis.treeGrid.expand(node);
  482. brokenAxis.setBreaks(breaks, pick(redraw, true));
  483. }
  484. };
  485. /**
  486. * Toggle the collapse/expand state of the grid cell. Used when axis is
  487. * of type treegrid.
  488. *
  489. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  490. *
  491. * @private
  492. * @function Highcharts.Tick#toggleCollapse
  493. *
  494. * @param {boolean} [redraw=true]
  495. * Whether to redraw the chart or wait for an explicit call to
  496. * {@link Highcharts.Chart#redraw}
  497. */
  498. Additions.prototype.toggleCollapse = function (redraw) {
  499. var tick = this.tick,
  500. axis = tick.axis,
  501. brokenAxis = axis.brokenAxis;
  502. if (brokenAxis &&
  503. axis.treeGrid.mapOfPosToGridNode) {
  504. var pos = tick.pos,
  505. node = axis.treeGrid.mapOfPosToGridNode[pos],
  506. breaks = axis.treeGrid.toggleCollapse(node);
  507. brokenAxis.setBreaks(breaks, pick(redraw, true));
  508. }
  509. };
  510. return Additions;
  511. }());
  512. TreeGridTick.Additions = Additions;
  513. })(TreeGridTick || (TreeGridTick = {}));
  514. return TreeGridTick;
  515. });
  516. _registerModule(_modules, 'Mixins/TreeSeries.js', [_modules['Core/Color.js'], _modules['Core/Utilities.js']], function (Color, U) {
  517. /* *
  518. *
  519. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  520. *
  521. * */
  522. var extend = U.extend,
  523. isArray = U.isArray,
  524. isNumber = U.isNumber,
  525. isObject = U.isObject,
  526. merge = U.merge,
  527. pick = U.pick;
  528. var isBoolean = function (x) {
  529. return typeof x === 'boolean';
  530. }, isFn = function (x) {
  531. return typeof x === 'function';
  532. };
  533. /* eslint-disable valid-jsdoc */
  534. /**
  535. * @todo Combine buildTree and buildNode with setTreeValues
  536. * @todo Remove logic from Treemap and make it utilize this mixin.
  537. * @private
  538. */
  539. var setTreeValues = function setTreeValues(tree,
  540. options) {
  541. var before = options.before,
  542. idRoot = options.idRoot,
  543. mapIdToNode = options.mapIdToNode,
  544. nodeRoot = mapIdToNode[idRoot],
  545. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  546. options.levelIsConstant :
  547. true),
  548. points = options.points,
  549. point = points[tree.i],
  550. optionsPoint = point && point.options || {},
  551. childrenTotal = 0,
  552. children = [],
  553. value;
  554. extend(tree, {
  555. levelDynamic: tree.level - (levelIsConstant ? 0 : nodeRoot.level),
  556. name: pick(point && point.name, ''),
  557. visible: (idRoot === tree.id ||
  558. (isBoolean(options.visible) ? options.visible : false))
  559. });
  560. if (isFn(before)) {
  561. tree = before(tree, options);
  562. }
  563. // First give the children some values
  564. tree.children.forEach(function (child, i) {
  565. var newOptions = extend({},
  566. options);
  567. extend(newOptions, {
  568. index: i,
  569. siblings: tree.children.length,
  570. visible: tree.visible
  571. });
  572. child = setTreeValues(child, newOptions);
  573. children.push(child);
  574. if (child.visible) {
  575. childrenTotal += child.val;
  576. }
  577. });
  578. tree.visible = childrenTotal > 0 || tree.visible;
  579. // Set the values
  580. value = pick(optionsPoint.value, childrenTotal);
  581. extend(tree, {
  582. children: children,
  583. childrenTotal: childrenTotal,
  584. isLeaf: tree.visible && !childrenTotal,
  585. val: value
  586. });
  587. return tree;
  588. };
  589. /**
  590. * @private
  591. */
  592. var getColor = function getColor(node,
  593. options) {
  594. var index = options.index,
  595. mapOptionsToLevel = options.mapOptionsToLevel,
  596. parentColor = options.parentColor,
  597. parentColorIndex = options.parentColorIndex,
  598. series = options.series,
  599. colors = options.colors,
  600. siblings = options.siblings,
  601. points = series.points,
  602. getColorByPoint,
  603. chartOptionsChart = series.chart.options.chart,
  604. point,
  605. level,
  606. colorByPoint,
  607. colorIndexByPoint,
  608. color,
  609. colorIndex;
  610. /**
  611. * @private
  612. */
  613. function variation(color) {
  614. var colorVariation = level && level.colorVariation;
  615. if (colorVariation) {
  616. if (colorVariation.key === 'brightness') {
  617. return Color.parse(color).brighten(colorVariation.to * (index / siblings)).get();
  618. }
  619. }
  620. return color;
  621. }
  622. if (node) {
  623. point = points[node.i];
  624. level = mapOptionsToLevel[node.level] || {};
  625. getColorByPoint = point && level.colorByPoint;
  626. if (getColorByPoint) {
  627. colorIndexByPoint = point.index % (colors ?
  628. colors.length :
  629. chartOptionsChart.colorCount);
  630. colorByPoint = colors && colors[colorIndexByPoint];
  631. }
  632. // Select either point color, level color or inherited color.
  633. if (!series.chart.styledMode) {
  634. color = pick(point && point.options.color, level && level.color, colorByPoint, parentColor && variation(parentColor), series.color);
  635. }
  636. colorIndex = pick(point && point.options.colorIndex, level && level.colorIndex, colorIndexByPoint, parentColorIndex, options.colorIndex);
  637. }
  638. return {
  639. color: color,
  640. colorIndex: colorIndex
  641. };
  642. };
  643. /**
  644. * Creates a map from level number to its given options.
  645. *
  646. * @private
  647. * @function getLevelOptions
  648. * @param {object} params
  649. * Object containing parameters.
  650. * - `defaults` Object containing default options. The default options
  651. * are merged with the userOptions to get the final options for a
  652. * specific level.
  653. * - `from` The lowest level number.
  654. * - `levels` User options from series.levels.
  655. * - `to` The highest level number.
  656. * @return {Highcharts.Dictionary<object>|null}
  657. * Returns a map from level number to its given options.
  658. */
  659. var getLevelOptions = function getLevelOptions(params) {
  660. var result = null,
  661. defaults,
  662. converted,
  663. i,
  664. from,
  665. to,
  666. levels;
  667. if (isObject(params)) {
  668. result = {};
  669. from = isNumber(params.from) ? params.from : 1;
  670. levels = params.levels;
  671. converted = {};
  672. defaults = isObject(params.defaults) ? params.defaults : {};
  673. if (isArray(levels)) {
  674. converted = levels.reduce(function (obj, item) {
  675. var level,
  676. levelIsConstant,
  677. options;
  678. if (isObject(item) && isNumber(item.level)) {
  679. options = merge({}, item);
  680. levelIsConstant = (isBoolean(options.levelIsConstant) ?
  681. options.levelIsConstant :
  682. defaults.levelIsConstant);
  683. // Delete redundant properties.
  684. delete options.levelIsConstant;
  685. delete options.level;
  686. // Calculate which level these options apply to.
  687. level = item.level + (levelIsConstant ? 0 : from - 1);
  688. if (isObject(obj[level])) {
  689. extend(obj[level], options);
  690. }
  691. else {
  692. obj[level] = options;
  693. }
  694. }
  695. return obj;
  696. }, {});
  697. }
  698. to = isNumber(params.to) ? params.to : 1;
  699. for (i = 0; i <= to; i++) {
  700. result[i] = merge({}, defaults, isObject(converted[i]) ? converted[i] : {});
  701. }
  702. }
  703. return result;
  704. };
  705. /**
  706. * Update the rootId property on the series. Also makes sure that it is
  707. * accessible to exporting.
  708. *
  709. * @private
  710. * @function updateRootId
  711. *
  712. * @param {object} series
  713. * The series to operate on.
  714. *
  715. * @return {string}
  716. * Returns the resulting rootId after update.
  717. */
  718. var updateRootId = function (series) {
  719. var rootId,
  720. options;
  721. if (isObject(series)) {
  722. // Get the series options.
  723. options = isObject(series.options) ? series.options : {};
  724. // Calculate the rootId.
  725. rootId = pick(series.rootNode, options.rootId, '');
  726. // Set rootId on series.userOptions to pick it up in exporting.
  727. if (isObject(series.userOptions)) {
  728. series.userOptions.rootId = rootId;
  729. }
  730. // Set rootId on series to pick it up on next update.
  731. series.rootNode = rootId;
  732. }
  733. return rootId;
  734. };
  735. var result = {
  736. getColor: getColor,
  737. getLevelOptions: getLevelOptions,
  738. setTreeValues: setTreeValues,
  739. updateRootId: updateRootId
  740. };
  741. return result;
  742. });
  743. _registerModule(_modules, 'Core/Axis/GridAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Axis/Tick.js'], _modules['Core/Utilities.js']], function (Axis, H, O, Tick, U) {
  744. /* *
  745. *
  746. * (c) 2016 Highsoft AS
  747. * Authors: Lars A. V. Cabrera
  748. *
  749. * License: www.highcharts.com/license
  750. *
  751. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  752. *
  753. * */
  754. var dateFormat = O.dateFormat;
  755. var addEvent = U.addEvent,
  756. defined = U.defined,
  757. erase = U.erase,
  758. find = U.find,
  759. isArray = U.isArray,
  760. isNumber = U.isNumber,
  761. merge = U.merge,
  762. pick = U.pick,
  763. timeUnits = U.timeUnits,
  764. wrap = U.wrap;
  765. var argsToArray = function (args) {
  766. return Array.prototype.slice.call(args, 1);
  767. }, isObject = function (x) {
  768. // Always use strict mode
  769. return U.isObject(x, true);
  770. }, Chart = H.Chart;
  771. var applyGridOptions = function applyGridOptions(axis) {
  772. var options = axis.options;
  773. // Center-align by default
  774. if (!options.labels) {
  775. options.labels = {};
  776. }
  777. options.labels.align = pick(options.labels.align, 'center');
  778. // @todo: Check against tickLabelPlacement between/on etc
  779. /* Prevents adding the last tick label if the axis is not a category
  780. axis.
  781. Since numeric labels are normally placed at starts and ends of a
  782. range of value, and this module makes the label point at the value,
  783. an "extra" label would appear. */
  784. if (!axis.categories) {
  785. options.showLastLabel = false;
  786. }
  787. // Prevents rotation of labels when squished, as rotating them would not
  788. // help.
  789. axis.labelRotation = 0;
  790. options.labels.rotation = 0;
  791. };
  792. /**
  793. * For a datetime axis, the scale will automatically adjust to the
  794. * appropriate unit. This member gives the default string
  795. * representations used for each unit. For intermediate values,
  796. * different units may be used, for example the `day` unit can be used
  797. * on midnight and `hour` unit be used for intermediate values on the
  798. * same axis.
  799. * For grid axes (like in Gantt charts),
  800. * it is possible to declare as a list to provide different
  801. * formats depending on available space.
  802. * For an overview of the replacement codes, see
  803. * [dateFormat](/class-reference/Highcharts#dateFormat).
  804. *
  805. * Defaults to:
  806. * ```js
  807. * {
  808. hour: {
  809. list: ['%H:%M', '%H']
  810. },
  811. day: {
  812. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  813. },
  814. week: {
  815. list: ['Week %W', 'W%W']
  816. },
  817. month: {
  818. list: ['%B', '%b', '%o']
  819. }
  820. },
  821. * ```
  822. *
  823. * @sample {gantt} gantt/demo/left-axis-table
  824. * Gantt Chart with custom axis date format.
  825. *
  826. * @product gantt
  827. * @apioption xAxis.dateTimeLabelFormats
  828. */
  829. /**
  830. * Set grid options for the axis labels. Requires Highcharts Gantt.
  831. *
  832. * @since 6.2.0
  833. * @product gantt
  834. * @apioption xAxis.grid
  835. */
  836. /**
  837. * Enable grid on the axis labels. Defaults to true for Gantt charts.
  838. *
  839. * @type {boolean}
  840. * @default true
  841. * @since 6.2.0
  842. * @product gantt
  843. * @apioption xAxis.grid.enabled
  844. */
  845. /**
  846. * Set specific options for each column (or row for horizontal axes) in the
  847. * grid. Each extra column/row is its own axis, and the axis options can be set
  848. * here.
  849. *
  850. * @sample gantt/demo/left-axis-table
  851. * Left axis as a table
  852. *
  853. * @type {Array<Highcharts.XAxisOptions>}
  854. * @apioption xAxis.grid.columns
  855. */
  856. /**
  857. * Set border color for the label grid lines.
  858. *
  859. * @type {Highcharts.ColorString}
  860. * @apioption xAxis.grid.borderColor
  861. */
  862. /**
  863. * Set border width of the label grid lines.
  864. *
  865. * @type {number}
  866. * @default 1
  867. * @apioption xAxis.grid.borderWidth
  868. */
  869. /**
  870. * Set cell height for grid axis labels. By default this is calculated from font
  871. * size. This option only applies to horizontal axes.
  872. *
  873. * @sample gantt/grid-axis/cellheight
  874. * Gant chart with custom cell height
  875. * @type {number}
  876. * @apioption xAxis.grid.cellHeight
  877. */
  878. ''; // detach doclets above
  879. /**
  880. * Get the largest label width and height.
  881. *
  882. * @private
  883. * @function Highcharts.Axis#getMaxLabelDimensions
  884. *
  885. * @param {Highcharts.Dictionary<Highcharts.Tick>} ticks
  886. * All the ticks on one axis.
  887. *
  888. * @param {Array<number|string>} tickPositions
  889. * All the tick positions on one axis.
  890. *
  891. * @return {Highcharts.SizeObject}
  892. * Object containing the properties height and width.
  893. *
  894. * @todo Move this to the generic axis implementation, as it is used there.
  895. */
  896. Axis.prototype.getMaxLabelDimensions = function (ticks, tickPositions) {
  897. var dimensions = {
  898. width: 0,
  899. height: 0
  900. };
  901. tickPositions.forEach(function (pos) {
  902. var tick = ticks[pos],
  903. tickHeight = 0,
  904. tickWidth = 0,
  905. label;
  906. if (isObject(tick)) {
  907. label = isObject(tick.label) ? tick.label : {};
  908. // Find width and height of tick
  909. tickHeight = label.getBBox ? label.getBBox().height : 0;
  910. if (label.textStr) {
  911. // Set the tickWidth same as the label width after ellipsis
  912. // applied #10281
  913. tickWidth = Math.round(label.getBBox().width);
  914. }
  915. // Update the result if width and/or height are larger
  916. dimensions.height = Math.max(tickHeight, dimensions.height);
  917. dimensions.width = Math.max(tickWidth, dimensions.width);
  918. }
  919. });
  920. return dimensions;
  921. };
  922. // Adds week date format
  923. H.dateFormats.W = function (timestamp) {
  924. var d = new this.Date(timestamp);
  925. var firstDay = (this.get('Day',
  926. d) + 6) % 7;
  927. var thursday = new this.Date(d.valueOf());
  928. this.set('Date', thursday, this.get('Date', d) - firstDay + 3);
  929. var firstThursday = new this.Date(this.get('FullYear',
  930. thursday), 0, 1);
  931. if (this.get('Day', firstThursday) !== 4) {
  932. this.set('Month', d, 0);
  933. this.set('Date', d, 1 + (11 - this.get('Day', firstThursday)) % 7);
  934. }
  935. return (1 +
  936. Math.floor((thursday.valueOf() - firstThursday.valueOf()) / 604800000)).toString();
  937. };
  938. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  939. H.dateFormats.E = function (timestamp) {
  940. return dateFormat('%a', timestamp, true).charAt(0);
  941. };
  942. /* eslint-disable no-invalid-this */
  943. addEvent(Chart, 'afterSetChartSize', function () {
  944. this.axes.forEach(function (axis) {
  945. (axis.grid && axis.grid.columns || []).forEach(function (column) {
  946. column.setAxisSize();
  947. column.setAxisTranslation();
  948. });
  949. });
  950. });
  951. // Center tick labels in cells.
  952. addEvent(Tick, 'afterGetLabelPosition', function (e) {
  953. var tick = this,
  954. label = tick.label,
  955. axis = tick.axis,
  956. reversed = axis.reversed,
  957. chart = axis.chart,
  958. options = axis.options,
  959. gridOptions = options.grid || {},
  960. labelOpts = axis.options.labels,
  961. align = labelOpts.align,
  962. // verticalAlign is currently not supported for axis.labels.
  963. verticalAlign = 'middle', // labelOpts.verticalAlign,
  964. side = GridAxis.Side[axis.side],
  965. tickmarkOffset = e.tickmarkOffset,
  966. tickPositions = axis.tickPositions,
  967. tickPos = tick.pos - tickmarkOffset,
  968. nextTickPos = (isNumber(tickPositions[e.index + 1]) ?
  969. tickPositions[e.index + 1] - tickmarkOffset :
  970. axis.max + tickmarkOffset),
  971. tickSize = axis.tickSize('tick'),
  972. tickWidth = tickSize ? tickSize[0] : 0,
  973. crispCorr = tickSize ? tickSize[1] / 2 : 0,
  974. labelHeight,
  975. lblMetrics,
  976. lines,
  977. bottom,
  978. top,
  979. left,
  980. right;
  981. // Only center tick labels in grid axes
  982. if (gridOptions.enabled === true) {
  983. // Calculate top and bottom positions of the cell.
  984. if (side === 'top') {
  985. bottom = axis.top + axis.offset;
  986. top = bottom - tickWidth;
  987. }
  988. else if (side === 'bottom') {
  989. top = chart.chartHeight - axis.bottom + axis.offset;
  990. bottom = top + tickWidth;
  991. }
  992. else {
  993. bottom = axis.top + axis.len - axis.translate(reversed ? nextTickPos : tickPos);
  994. top = axis.top + axis.len - axis.translate(reversed ? tickPos : nextTickPos);
  995. }
  996. // Calculate left and right positions of the cell.
  997. if (side === 'right') {
  998. left = chart.chartWidth - axis.right + axis.offset;
  999. right = left + tickWidth;
  1000. }
  1001. else if (side === 'left') {
  1002. right = axis.left + axis.offset;
  1003. left = right - tickWidth;
  1004. }
  1005. else {
  1006. left = Math.round(axis.left + axis.translate(reversed ? nextTickPos : tickPos)) - crispCorr;
  1007. right = Math.round(axis.left + axis.translate(reversed ? tickPos : nextTickPos)) - crispCorr;
  1008. }
  1009. tick.slotWidth = right - left;
  1010. // Calculate the positioning of the label based on
  1011. // alignment.
  1012. e.pos.x = (align === 'left' ?
  1013. left :
  1014. align === 'right' ?
  1015. right :
  1016. left + ((right - left) / 2) // default to center
  1017. );
  1018. e.pos.y = (verticalAlign === 'top' ?
  1019. top :
  1020. verticalAlign === 'bottom' ?
  1021. bottom :
  1022. top + ((bottom - top) / 2) // default to middle
  1023. );
  1024. lblMetrics = chart.renderer.fontMetrics(labelOpts.style.fontSize, label.element);
  1025. labelHeight = label.getBBox().height;
  1026. // Adjustment to y position to align the label correctly.
  1027. // Would be better to have a setter or similar for this.
  1028. if (!labelOpts.useHTML) {
  1029. lines = Math.round(labelHeight / lblMetrics.h);
  1030. e.pos.y += (
  1031. // Center the label
  1032. // TODO: why does this actually center the label?
  1033. ((lblMetrics.b - (lblMetrics.h - lblMetrics.f)) / 2) +
  1034. // Adjust for height of additional lines.
  1035. -(((lines - 1) * lblMetrics.h) / 2));
  1036. }
  1037. else {
  1038. e.pos.y += (
  1039. // Readjust yCorr in htmlUpdateTransform
  1040. lblMetrics.b +
  1041. // Adjust for height of html label
  1042. -(labelHeight / 2));
  1043. }
  1044. e.pos.x += (axis.horiz && labelOpts.x || 0);
  1045. }
  1046. });
  1047. /* eslint-enable no-invalid-this */
  1048. /**
  1049. * Additions for grid axes.
  1050. * @private
  1051. * @class
  1052. */
  1053. var GridAxisAdditions = /** @class */ (function () {
  1054. /* *
  1055. *
  1056. * Constructors
  1057. *
  1058. * */
  1059. function GridAxisAdditions(axis) {
  1060. this.axis = axis;
  1061. }
  1062. /* *
  1063. *
  1064. * Functions
  1065. *
  1066. * */
  1067. /**
  1068. * Checks if an axis is the outer axis in its dimension. Since
  1069. * axes are placed outwards in order, the axis with the highest
  1070. * index is the outermost axis.
  1071. *
  1072. * Example: If there are multiple x-axes at the top of the chart,
  1073. * this function returns true if the axis supplied is the last
  1074. * of the x-axes.
  1075. *
  1076. * @private
  1077. *
  1078. * @return {boolean}
  1079. * True if the axis is the outermost axis in its dimension; false if
  1080. * not.
  1081. */
  1082. GridAxisAdditions.prototype.isOuterAxis = function () {
  1083. var axis = this.axis;
  1084. var chart = axis.chart;
  1085. var columnIndex = axis.grid.columnIndex;
  1086. var columns = (axis.linkedParent && axis.linkedParent.grid.columns ||
  1087. axis.grid.columns);
  1088. var parentAxis = columnIndex ? axis.linkedParent : axis;
  1089. var thisIndex = -1,
  1090. lastIndex = 0;
  1091. chart[axis.coll].forEach(function (otherAxis, index) {
  1092. if (otherAxis.side === axis.side && !otherAxis.options.isInternal) {
  1093. lastIndex = index;
  1094. if (otherAxis === parentAxis) {
  1095. // Get the index of the axis in question
  1096. thisIndex = index;
  1097. }
  1098. }
  1099. });
  1100. return (lastIndex === thisIndex &&
  1101. (isNumber(columnIndex) ? columns.length === columnIndex : true));
  1102. };
  1103. return GridAxisAdditions;
  1104. }());
  1105. /**
  1106. * Axis with grid support.
  1107. * @private
  1108. * @class
  1109. */
  1110. var GridAxis = /** @class */ (function () {
  1111. function GridAxis() {
  1112. }
  1113. /* *
  1114. *
  1115. * Static Functions
  1116. *
  1117. * */
  1118. /* eslint-disable valid-jsdoc */
  1119. /**
  1120. * Extends axis class with grid support.
  1121. * @private
  1122. */
  1123. GridAxis.compose = function (AxisClass) {
  1124. Axis.keepProps.push('grid');
  1125. wrap(AxisClass.prototype, 'unsquish', GridAxis.wrapUnsquish);
  1126. // Add event handlers
  1127. addEvent(AxisClass, 'init', GridAxis.onInit);
  1128. addEvent(AxisClass, 'afterGetOffset', GridAxis.onAfterGetOffset);
  1129. addEvent(AxisClass, 'afterGetTitlePosition', GridAxis.onAfterGetTitlePosition);
  1130. addEvent(AxisClass, 'afterInit', GridAxis.onAfterInit);
  1131. addEvent(AxisClass, 'afterRender', GridAxis.onAfterRender);
  1132. addEvent(AxisClass, 'afterSetAxisTranslation', GridAxis.onAfterSetAxisTranslation);
  1133. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions);
  1134. addEvent(AxisClass, 'afterSetOptions', GridAxis.onAfterSetOptions2);
  1135. addEvent(AxisClass, 'afterSetScale', GridAxis.onAfterSetScale);
  1136. addEvent(AxisClass, 'afterTickSize', GridAxis.onAfterTickSize);
  1137. addEvent(AxisClass, 'trimTicks', GridAxis.onTrimTicks);
  1138. addEvent(AxisClass, 'destroy', GridAxis.onDestroy);
  1139. };
  1140. /**
  1141. * Handle columns and getOffset.
  1142. * @private
  1143. */
  1144. GridAxis.onAfterGetOffset = function () {
  1145. var grid = this.grid;
  1146. (grid && grid.columns || []).forEach(function (column) {
  1147. column.getOffset();
  1148. });
  1149. };
  1150. /**
  1151. * @private
  1152. */
  1153. GridAxis.onAfterGetTitlePosition = function (e) {
  1154. var axis = this;
  1155. var options = axis.options;
  1156. var gridOptions = options.grid || {};
  1157. if (gridOptions.enabled === true) {
  1158. // compute anchor points for each of the title align options
  1159. var title = axis.axisTitle,
  1160. axisHeight = axis.height,
  1161. horiz = axis.horiz,
  1162. axisLeft = axis.left,
  1163. offset = axis.offset,
  1164. opposite = axis.opposite,
  1165. _a = axis.options.title,
  1166. axisTitleOptions = _a === void 0 ? {} : _a,
  1167. axisTop = axis.top,
  1168. axisWidth = axis.width;
  1169. var tickSize = axis.tickSize();
  1170. var titleWidth = title && title.getBBox().width;
  1171. var xOption = axisTitleOptions.x || 0;
  1172. var yOption = axisTitleOptions.y || 0;
  1173. var titleMargin = pick(axisTitleOptions.margin,
  1174. horiz ? 5 : 10);
  1175. var titleFontSize = axis.chart.renderer.fontMetrics(axisTitleOptions.style &&
  1176. axisTitleOptions.style.fontSize,
  1177. title).f;
  1178. var crispCorr = tickSize ? tickSize[0] / 2 : 0;
  1179. // TODO account for alignment
  1180. // the position in the perpendicular direction of the axis
  1181. var offAxis = ((horiz ? axisTop + axisHeight : axisLeft) +
  1182. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  1183. (opposite ? -1 : 1) * // so does opposite axes
  1184. crispCorr +
  1185. (axis.side === GridAxis.Side.bottom ? titleFontSize : 0));
  1186. e.titlePosition.x = horiz ?
  1187. axisLeft - titleWidth / 2 - titleMargin + xOption :
  1188. offAxis + (opposite ? axisWidth : 0) + offset + xOption;
  1189. e.titlePosition.y = horiz ?
  1190. (offAxis -
  1191. (opposite ? axisHeight : 0) +
  1192. (opposite ? titleFontSize : -titleFontSize) / 2 +
  1193. offset +
  1194. yOption) :
  1195. axisTop - titleMargin + yOption;
  1196. }
  1197. };
  1198. /**
  1199. * @private
  1200. */
  1201. GridAxis.onAfterInit = function () {
  1202. var axis = this;
  1203. var chart = axis.chart,
  1204. _a = axis.options.grid,
  1205. gridOptions = _a === void 0 ? {} : _a,
  1206. userOptions = axis.userOptions;
  1207. if (gridOptions.enabled) {
  1208. applyGridOptions(axis);
  1209. /* eslint-disable no-invalid-this */
  1210. // TODO: wrap the axis instead
  1211. wrap(axis, 'labelFormatter', function (proceed) {
  1212. var _a = this,
  1213. axis = _a.axis,
  1214. value = _a.value;
  1215. var tickPos = axis.tickPositions;
  1216. var series = (axis.isLinked ?
  1217. axis.linkedParent :
  1218. axis).series[0];
  1219. var isFirst = value === tickPos[0];
  1220. var isLast = value === tickPos[tickPos.length - 1];
  1221. var point = series && find(series.options.data,
  1222. function (p) {
  1223. return p[axis.isXAxis ? 'x' : 'y'] === value;
  1224. });
  1225. // Make additional properties available for the
  1226. // formatter
  1227. this.isFirst = isFirst;
  1228. this.isLast = isLast;
  1229. this.point = point;
  1230. // Call original labelFormatter
  1231. return proceed.call(this);
  1232. });
  1233. /* eslint-enable no-invalid-this */
  1234. }
  1235. if (gridOptions.columns) {
  1236. var columns = axis.grid.columns = [],
  1237. columnIndex = axis.grid.columnIndex = 0;
  1238. // Handle columns, each column is a grid axis
  1239. while (++columnIndex < gridOptions.columns.length) {
  1240. var columnOptions = merge(userOptions,
  1241. gridOptions.columns[gridOptions.columns.length - columnIndex - 1], {
  1242. linkedTo: 0,
  1243. // Force to behave like category axis
  1244. type: 'category',
  1245. // Disable by default the scrollbar on the grid axis
  1246. scrollbar: {
  1247. enabled: false
  1248. }
  1249. });
  1250. delete columnOptions.grid.columns; // Prevent recursion
  1251. var column = new Axis(axis.chart,
  1252. columnOptions);
  1253. column.grid.isColumn = true;
  1254. column.grid.columnIndex = columnIndex;
  1255. // Remove column axis from chart axes array, and place it
  1256. // in the columns array.
  1257. erase(chart.axes, column);
  1258. erase(chart[axis.coll], column);
  1259. columns.push(column);
  1260. }
  1261. }
  1262. };
  1263. /**
  1264. * Draw an extra line on the far side of the outermost axis,
  1265. * creating floor/roof/wall of a grid. And some padding.
  1266. * ```
  1267. * Make this:
  1268. * (axis.min) __________________________ (axis.max)
  1269. * | | | | |
  1270. * Into this:
  1271. * (axis.min) __________________________ (axis.max)
  1272. * ___|____|____|____|____|__
  1273. * ```
  1274. * @private
  1275. */
  1276. GridAxis.onAfterRender = function () {
  1277. var axis = this;
  1278. var grid = axis.grid;
  1279. var options = axis.options;
  1280. var renderer = axis.chart.renderer;
  1281. var gridOptions = options.grid || {};
  1282. var yStartIndex,
  1283. yEndIndex,
  1284. xStartIndex,
  1285. xEndIndex;
  1286. if (gridOptions.enabled === true) {
  1287. // @todo acutual label padding (top, bottom, left, right)
  1288. axis.maxLabelDimensions = axis.getMaxLabelDimensions(axis.ticks, axis.tickPositions);
  1289. // Remove right wall before rendering if updating
  1290. if (axis.rightWall) {
  1291. axis.rightWall.destroy();
  1292. }
  1293. /*
  1294. Draw an extra axis line on outer axes
  1295. >
  1296. Make this: |______|______|______|___
  1297. > _________________________
  1298. Into this: |______|______|______|__|
  1299. */
  1300. if (axis.grid && axis.grid.isOuterAxis() && axis.axisLine) {
  1301. var lineWidth = options.lineWidth;
  1302. if (lineWidth) {
  1303. var linePath = axis.getLinePath(lineWidth);
  1304. var startPoint = linePath[0];
  1305. var endPoint = linePath[1];
  1306. // Negate distance if top or left axis
  1307. // Subtract 1px to draw the line at the end of the tick
  1308. var tickLength = (axis.tickSize('tick') || [1])[0];
  1309. var distance = (tickLength - 1) * ((axis.side === GridAxis.Side.top ||
  1310. axis.side === GridAxis.Side.left) ? -1 : 1);
  1311. // If axis is horizontal, reposition line path vertically
  1312. if (startPoint[0] === 'M' && endPoint[0] === 'L') {
  1313. if (axis.horiz) {
  1314. startPoint[2] += distance;
  1315. endPoint[2] += distance;
  1316. }
  1317. else {
  1318. // If axis is vertical, reposition line path
  1319. // horizontally
  1320. startPoint[1] += distance;
  1321. endPoint[1] += distance;
  1322. }
  1323. }
  1324. if (!axis.grid.axisLineExtra) {
  1325. axis.grid.axisLineExtra = renderer
  1326. .path(linePath)
  1327. .attr({
  1328. zIndex: 7
  1329. })
  1330. .addClass('highcharts-axis-line')
  1331. .add(axis.axisGroup);
  1332. if (!renderer.styledMode) {
  1333. axis.grid.axisLineExtra.attr({
  1334. stroke: options.lineColor,
  1335. 'stroke-width': lineWidth
  1336. });
  1337. }
  1338. }
  1339. else {
  1340. axis.grid.axisLineExtra.animate({
  1341. d: linePath
  1342. });
  1343. }
  1344. // show or hide the line depending on
  1345. // options.showEmpty
  1346. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  1347. }
  1348. }
  1349. (grid && grid.columns || []).forEach(function (column) {
  1350. column.render();
  1351. });
  1352. }
  1353. };
  1354. /**
  1355. * @private
  1356. */
  1357. GridAxis.onAfterSetAxisTranslation = function () {
  1358. var axis = this;
  1359. var tickInfo = axis.tickPositions && axis.tickPositions.info;
  1360. var options = axis.options;
  1361. var gridOptions = options.grid || {};
  1362. var userLabels = axis.userOptions.labels || {};
  1363. if (axis.horiz) {
  1364. if (gridOptions.enabled === true) {
  1365. axis.series.forEach(function (series) {
  1366. series.options.pointRange = 0;
  1367. });
  1368. }
  1369. // Lower level time ticks, like hours or minutes, represent
  1370. // points in time and not ranges. These should be aligned
  1371. // left in the grid cell by default. The same applies to
  1372. // years of higher order.
  1373. if (tickInfo &&
  1374. options.dateTimeLabelFormats &&
  1375. options.labels &&
  1376. !defined(userLabels.align) &&
  1377. (options.dateTimeLabelFormats[tickInfo.unitName].range === false ||
  1378. tickInfo.count > 1 // years
  1379. )) {
  1380. options.labels.align = 'left';
  1381. if (!defined(userLabels.x)) {
  1382. options.labels.x = 3;
  1383. }
  1384. }
  1385. }
  1386. };
  1387. /**
  1388. * Creates a left and right wall on horizontal axes:
  1389. * - Places leftmost tick at the start of the axis, to create a left
  1390. * wall
  1391. * - Ensures that the rightmost tick is at the end of the axis, to
  1392. * create a right wall.
  1393. * @private
  1394. */
  1395. GridAxis.onAfterSetOptions = function (e) {
  1396. var options = this.options,
  1397. userOptions = e.userOptions,
  1398. gridAxisOptions,
  1399. gridOptions = ((options && isObject(options.grid)) ? options.grid : {});
  1400. if (gridOptions.enabled === true) {
  1401. // Merge the user options into default grid axis options so
  1402. // that when a user option is set, it takes presedence.
  1403. gridAxisOptions = merge(true, {
  1404. className: ('highcharts-grid-axis ' + (userOptions.className || '')),
  1405. dateTimeLabelFormats: {
  1406. hour: {
  1407. list: ['%H:%M', '%H']
  1408. },
  1409. day: {
  1410. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  1411. },
  1412. week: {
  1413. list: ['Week %W', 'W%W']
  1414. },
  1415. month: {
  1416. list: ['%B', '%b', '%o']
  1417. }
  1418. },
  1419. grid: {
  1420. borderWidth: 1
  1421. },
  1422. labels: {
  1423. padding: 2,
  1424. style: {
  1425. fontSize: '13px'
  1426. }
  1427. },
  1428. margin: 0,
  1429. title: {
  1430. text: null,
  1431. reserveSpace: false,
  1432. rotation: 0
  1433. },
  1434. // In a grid axis, only allow one unit of certain types,
  1435. // for example we shouln't have one grid cell spanning
  1436. // two days.
  1437. units: [[
  1438. 'millisecond',
  1439. [1, 10, 100]
  1440. ], [
  1441. 'second',
  1442. [1, 10]
  1443. ], [
  1444. 'minute',
  1445. [1, 5, 15]
  1446. ], [
  1447. 'hour',
  1448. [1, 6]
  1449. ], [
  1450. 'day',
  1451. [1]
  1452. ], [
  1453. 'week',
  1454. [1]
  1455. ], [
  1456. 'month',
  1457. [1]
  1458. ], [
  1459. 'year',
  1460. null
  1461. ]]
  1462. }, userOptions);
  1463. // X-axis specific options
  1464. if (this.coll === 'xAxis') {
  1465. // For linked axes, tickPixelInterval is used only if
  1466. // the tickPositioner below doesn't run or returns
  1467. // undefined (like multiple years)
  1468. if (defined(userOptions.linkedTo) &&
  1469. !defined(userOptions.tickPixelInterval)) {
  1470. gridAxisOptions.tickPixelInterval = 350;
  1471. }
  1472. // For the secondary grid axis, use the primary axis'
  1473. // tick intervals and return ticks one level higher.
  1474. if (
  1475. // Check for tick pixel interval in options
  1476. !defined(userOptions.tickPixelInterval) &&
  1477. // Only for linked axes
  1478. defined(userOptions.linkedTo) &&
  1479. !defined(userOptions.tickPositioner) &&
  1480. !defined(userOptions.tickInterval)) {
  1481. gridAxisOptions.tickPositioner = function (min, max) {
  1482. var parentInfo = (this.linkedParent &&
  1483. this.linkedParent.tickPositions &&
  1484. this.linkedParent.tickPositions.info);
  1485. if (parentInfo) {
  1486. var unitIdx,
  1487. count,
  1488. unitName,
  1489. i,
  1490. units = gridAxisOptions.units,
  1491. unitRange;
  1492. for (i = 0; i < units.length; i++) {
  1493. if (units[i][0] ===
  1494. parentInfo.unitName) {
  1495. unitIdx = i;
  1496. break;
  1497. }
  1498. }
  1499. // Get the first allowed count on the next
  1500. // unit.
  1501. if (units[unitIdx + 1]) {
  1502. unitName = units[unitIdx + 1][0];
  1503. count =
  1504. (units[unitIdx + 1][1] || [1])[0];
  1505. // In case the base X axis shows years, make
  1506. // the secondary axis show ten times the
  1507. // years (#11427)
  1508. }
  1509. else if (parentInfo.unitName === 'year') {
  1510. unitName = 'year';
  1511. count = parentInfo.count * 10;
  1512. }
  1513. unitRange = timeUnits[unitName];
  1514. this.tickInterval = unitRange * count;
  1515. return this.getTimeTicks({
  1516. unitRange: unitRange,
  1517. count: count,
  1518. unitName: unitName
  1519. }, min, max, this.options.startOfWeek);
  1520. }
  1521. };
  1522. }
  1523. }
  1524. // Now merge the combined options into the axis options
  1525. merge(true, this.options, gridAxisOptions);
  1526. if (this.horiz) {
  1527. /* _________________________
  1528. Make this: ___|_____|_____|_____|__|
  1529. ^ ^
  1530. _________________________
  1531. Into this: |_____|_____|_____|_____|
  1532. ^ ^ */
  1533. options.minPadding = pick(userOptions.minPadding, 0);
  1534. options.maxPadding = pick(userOptions.maxPadding, 0);
  1535. }
  1536. // If borderWidth is set, then use its value for tick and
  1537. // line width.
  1538. if (isNumber(options.grid.borderWidth)) {
  1539. options.tickWidth = options.lineWidth = gridOptions.borderWidth;
  1540. }
  1541. }
  1542. };
  1543. /**
  1544. * @private
  1545. */
  1546. GridAxis.onAfterSetOptions2 = function (e) {
  1547. var axis = this;
  1548. var userOptions = e.userOptions;
  1549. var gridOptions = userOptions && userOptions.grid || {};
  1550. var columns = gridOptions.columns;
  1551. // Add column options to the parent axis. Children has their column
  1552. // options set on init in onGridAxisAfterInit.
  1553. if (gridOptions.enabled && columns) {
  1554. merge(true, axis.options, columns[columns.length - 1]);
  1555. }
  1556. };
  1557. /**
  1558. * Handle columns and setScale.
  1559. * @private
  1560. */
  1561. GridAxis.onAfterSetScale = function () {
  1562. var axis = this;
  1563. (axis.grid.columns || []).forEach(function (column) {
  1564. column.setScale();
  1565. });
  1566. };
  1567. /**
  1568. * Draw vertical axis ticks extra long to create cell floors and roofs.
  1569. * Overrides the tickLength for vertical axes.
  1570. * @private
  1571. */
  1572. GridAxis.onAfterTickSize = function (e) {
  1573. var defaultLeftAxisOptions = Axis.defaultLeftAxisOptions;
  1574. var _a = this,
  1575. horiz = _a.horiz,
  1576. maxLabelDimensions = _a.maxLabelDimensions,
  1577. _b = _a.options.grid,
  1578. gridOptions = _b === void 0 ? {} : _b;
  1579. if (gridOptions.enabled && maxLabelDimensions) {
  1580. var labelPadding = (Math.abs(defaultLeftAxisOptions.labels.x) * 2);
  1581. var distance = horiz ?
  1582. gridOptions.cellHeight || labelPadding + maxLabelDimensions.height :
  1583. labelPadding + maxLabelDimensions.width;
  1584. if (isArray(e.tickSize)) {
  1585. e.tickSize[0] = distance;
  1586. }
  1587. else {
  1588. e.tickSize = [distance, 0];
  1589. }
  1590. }
  1591. };
  1592. /**
  1593. * @private
  1594. */
  1595. GridAxis.onDestroy = function (e) {
  1596. var grid = this.grid;
  1597. (grid.columns || []).forEach(function (column) {
  1598. column.destroy(e.keepEvents);
  1599. });
  1600. grid.columns = void 0;
  1601. };
  1602. /**
  1603. * Wraps axis init to draw cell walls on vertical axes.
  1604. * @private
  1605. */
  1606. GridAxis.onInit = function (e) {
  1607. var axis = this;
  1608. var userOptions = e.userOptions || {};
  1609. var gridOptions = userOptions.grid || {};
  1610. if (gridOptions.enabled && defined(gridOptions.borderColor)) {
  1611. userOptions.tickColor = userOptions.lineColor = gridOptions.borderColor;
  1612. }
  1613. if (!axis.grid) {
  1614. axis.grid = new GridAxisAdditions(axis);
  1615. }
  1616. };
  1617. /**
  1618. * Makes tick labels which are usually ignored in a linked axis
  1619. * displayed if they are within range of linkedParent.min.
  1620. * ```
  1621. * _____________________________
  1622. * | | | | |
  1623. * Make this: | | 2 | 3 | 4 |
  1624. * |___|_______|_______|_______|
  1625. * ^
  1626. * _____________________________
  1627. * | | | | |
  1628. * Into this: | 1 | 2 | 3 | 4 |
  1629. * |___|_______|_______|_______|
  1630. * ^
  1631. * ```
  1632. * @private
  1633. * @todo Does this function do what the drawing says? Seems to affect
  1634. * ticks and not the labels directly?
  1635. */
  1636. GridAxis.onTrimTicks = function () {
  1637. var axis = this;
  1638. var options = axis.options;
  1639. var gridOptions = options.grid || {};
  1640. var categoryAxis = axis.categories;
  1641. var tickPositions = axis.tickPositions;
  1642. var firstPos = tickPositions[0];
  1643. var lastPos = tickPositions[tickPositions.length - 1];
  1644. var linkedMin = axis.linkedParent && axis.linkedParent.min;
  1645. var linkedMax = axis.linkedParent && axis.linkedParent.max;
  1646. var min = linkedMin || axis.min;
  1647. var max = linkedMax || axis.max;
  1648. var tickInterval = axis.tickInterval;
  1649. var endMoreThanMin = (firstPos < min &&
  1650. firstPos + tickInterval > min);
  1651. var startLessThanMax = (lastPos > max &&
  1652. lastPos - tickInterval < max);
  1653. if (gridOptions.enabled === true &&
  1654. !categoryAxis &&
  1655. (axis.horiz || axis.isLinked)) {
  1656. if (endMoreThanMin && !options.startOnTick) {
  1657. tickPositions[0] = min;
  1658. }
  1659. if (startLessThanMax && !options.endOnTick) {
  1660. tickPositions[tickPositions.length - 1] = max;
  1661. }
  1662. }
  1663. };
  1664. /**
  1665. * Avoid altering tickInterval when reserving space.
  1666. * @private
  1667. */
  1668. GridAxis.wrapUnsquish = function (proceed) {
  1669. var axis = this;
  1670. var _a = axis.options.grid,
  1671. gridOptions = _a === void 0 ? {} : _a;
  1672. if (gridOptions.enabled === true && axis.categories) {
  1673. return axis.tickInterval;
  1674. }
  1675. return proceed.apply(axis, argsToArray(arguments));
  1676. };
  1677. return GridAxis;
  1678. }());
  1679. (function (GridAxis) {
  1680. /**
  1681. * Enum for which side the axis is on. Maps to axis.side.
  1682. * @private
  1683. */
  1684. var Side;
  1685. (function (Side) {
  1686. Side[Side["top"] = 0] = "top";
  1687. Side[Side["right"] = 1] = "right";
  1688. Side[Side["bottom"] = 2] = "bottom";
  1689. Side[Side["left"] = 3] = "left";
  1690. })(Side = GridAxis.Side || (GridAxis.Side = {}));
  1691. })(GridAxis || (GridAxis = {}));
  1692. GridAxis.compose(Axis);
  1693. return GridAxis;
  1694. });
  1695. _registerModule(_modules, 'Core/Axis/BrokenAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js'], _modules['Extensions/Stacking.js']], function (Axis, H, U, StackItem) {
  1696. /* *
  1697. *
  1698. * (c) 2009-2020 Torstein Honsi
  1699. *
  1700. * License: www.highcharts.com/license
  1701. *
  1702. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  1703. *
  1704. * */
  1705. var addEvent = U.addEvent,
  1706. find = U.find,
  1707. fireEvent = U.fireEvent,
  1708. isArray = U.isArray,
  1709. isNumber = U.isNumber,
  1710. pick = U.pick;
  1711. var Series = H.Series;
  1712. /* eslint-disable valid-jsdoc */
  1713. /**
  1714. * Provides support for broken axes.
  1715. * @private
  1716. * @class
  1717. */
  1718. var BrokenAxisAdditions = /** @class */ (function () {
  1719. /* *
  1720. *
  1721. * Constructors
  1722. *
  1723. * */
  1724. function BrokenAxisAdditions(axis) {
  1725. this.hasBreaks = false;
  1726. this.axis = axis;
  1727. }
  1728. /* *
  1729. *
  1730. * Static Functions
  1731. *
  1732. * */
  1733. /**
  1734. * @private
  1735. */
  1736. BrokenAxisAdditions.isInBreak = function (brk, val) {
  1737. var ret,
  1738. repeat = brk.repeat || Infinity,
  1739. from = brk.from,
  1740. length = brk.to - brk.from,
  1741. test = (val >= from ?
  1742. (val - from) % repeat :
  1743. repeat - ((from - val) % repeat));
  1744. if (!brk.inclusive) {
  1745. ret = test < length && test !== 0;
  1746. }
  1747. else {
  1748. ret = test <= length;
  1749. }
  1750. return ret;
  1751. };
  1752. /**
  1753. * @private
  1754. */
  1755. BrokenAxisAdditions.lin2Val = function (val) {
  1756. var axis = this;
  1757. var brokenAxis = axis.brokenAxis;
  1758. var breakArray = brokenAxis && brokenAxis.breakArray;
  1759. if (!breakArray) {
  1760. return val;
  1761. }
  1762. var nval = val,
  1763. brk,
  1764. i;
  1765. for (i = 0; i < breakArray.length; i++) {
  1766. brk = breakArray[i];
  1767. if (brk.from >= nval) {
  1768. break;
  1769. }
  1770. else if (brk.to < nval) {
  1771. nval += brk.len;
  1772. }
  1773. else if (BrokenAxisAdditions.isInBreak(brk, nval)) {
  1774. nval += brk.len;
  1775. }
  1776. }
  1777. return nval;
  1778. };
  1779. /**
  1780. * @private
  1781. */
  1782. BrokenAxisAdditions.val2Lin = function (val) {
  1783. var axis = this;
  1784. var brokenAxis = axis.brokenAxis;
  1785. var breakArray = brokenAxis && brokenAxis.breakArray;
  1786. if (!breakArray) {
  1787. return val;
  1788. }
  1789. var nval = val,
  1790. brk,
  1791. i;
  1792. for (i = 0; i < breakArray.length; i++) {
  1793. brk = breakArray[i];
  1794. if (brk.to <= val) {
  1795. nval -= brk.len;
  1796. }
  1797. else if (brk.from >= val) {
  1798. break;
  1799. }
  1800. else if (BrokenAxisAdditions.isInBreak(brk, val)) {
  1801. nval -= (val - brk.from);
  1802. break;
  1803. }
  1804. }
  1805. return nval;
  1806. };
  1807. /* *
  1808. *
  1809. * Functions
  1810. *
  1811. * */
  1812. /**
  1813. * Returns the first break found where the x is larger then break.from and
  1814. * smaller then break.to.
  1815. *
  1816. * @param {number} x
  1817. * The number which should be within a break.
  1818. *
  1819. * @param {Array<Highcharts.XAxisBreaksOptions>} breaks
  1820. * The array of breaks to search within.
  1821. *
  1822. * @return {Highcharts.XAxisBreaksOptions|undefined}
  1823. * Returns the first break found that matches, returns false if no break is
  1824. * found.
  1825. */
  1826. BrokenAxisAdditions.prototype.findBreakAt = function (x, breaks) {
  1827. return find(breaks, function (b) {
  1828. return b.from < x && x < b.to;
  1829. });
  1830. };
  1831. /**
  1832. * @private
  1833. */
  1834. BrokenAxisAdditions.prototype.isInAnyBreak = function (val, testKeep) {
  1835. var brokenAxis = this;
  1836. var axis = brokenAxis.axis;
  1837. var breaks = axis.options.breaks,
  1838. i = breaks && breaks.length,
  1839. inbrk,
  1840. keep,
  1841. ret;
  1842. if (i) {
  1843. while (i--) {
  1844. if (BrokenAxisAdditions.isInBreak(breaks[i], val)) {
  1845. inbrk = true;
  1846. if (!keep) {
  1847. keep = pick(breaks[i].showPoints, !axis.isXAxis);
  1848. }
  1849. }
  1850. }
  1851. if (inbrk && testKeep) {
  1852. ret = inbrk && !keep;
  1853. }
  1854. else {
  1855. ret = inbrk;
  1856. }
  1857. }
  1858. return ret;
  1859. };
  1860. /**
  1861. * Dynamically set or unset breaks in an axis. This function in lighter than
  1862. * usin Axis.update, and it also preserves animation.
  1863. *
  1864. * @private
  1865. * @function Highcharts.Axis#setBreaks
  1866. *
  1867. * @param {Array<Highcharts.XAxisBreaksOptions>} [breaks]
  1868. * The breaks to add. When `undefined` it removes existing breaks.
  1869. *
  1870. * @param {boolean} [redraw=true]
  1871. * Whether to redraw the chart immediately.
  1872. *
  1873. * @return {void}
  1874. */
  1875. BrokenAxisAdditions.prototype.setBreaks = function (breaks, redraw) {
  1876. var brokenAxis = this;
  1877. var axis = brokenAxis.axis;
  1878. var hasBreaks = (isArray(breaks) && !!breaks.length);
  1879. axis.isDirty = brokenAxis.hasBreaks !== hasBreaks;
  1880. brokenAxis.hasBreaks = hasBreaks;
  1881. axis.options.breaks = axis.userOptions.breaks = breaks;
  1882. axis.forceRedraw = true; // Force recalculation in setScale
  1883. // Recalculate series related to the axis.
  1884. axis.series.forEach(function (series) {
  1885. series.isDirty = true;
  1886. });
  1887. if (!hasBreaks && axis.val2lin === BrokenAxisAdditions.val2Lin) {
  1888. // Revert to prototype functions
  1889. delete axis.val2lin;
  1890. delete axis.lin2val;
  1891. }
  1892. if (hasBreaks) {
  1893. axis.userOptions.ordinal = false;
  1894. axis.lin2val = BrokenAxisAdditions.lin2Val;
  1895. axis.val2lin = BrokenAxisAdditions.val2Lin;
  1896. axis.setExtremes = function (newMin, newMax, redraw, animation, eventArguments) {
  1897. // If trying to set extremes inside a break, extend min to
  1898. // after, and max to before the break ( #3857 )
  1899. if (brokenAxis.hasBreaks) {
  1900. var axisBreak,
  1901. breaks = this.options.breaks;
  1902. while ((axisBreak = brokenAxis.findBreakAt(newMin, breaks))) {
  1903. newMin = axisBreak.to;
  1904. }
  1905. while ((axisBreak = brokenAxis.findBreakAt(newMax, breaks))) {
  1906. newMax = axisBreak.from;
  1907. }
  1908. // If both min and max is within the same break.
  1909. if (newMax < newMin) {
  1910. newMax = newMin;
  1911. }
  1912. }
  1913. Axis.prototype.setExtremes.call(this, newMin, newMax, redraw, animation, eventArguments);
  1914. };
  1915. axis.setAxisTranslation = function (saveOld) {
  1916. Axis.prototype.setAxisTranslation.call(this, saveOld);
  1917. brokenAxis.unitLength = null;
  1918. if (brokenAxis.hasBreaks) {
  1919. var breaks = axis.options.breaks || [],
  1920. // Temporary one:
  1921. breakArrayT = [],
  1922. breakArray = [],
  1923. length = 0,
  1924. inBrk,
  1925. repeat,
  1926. min = axis.userMin || axis.min,
  1927. max = axis.userMax || axis.max,
  1928. pointRangePadding = pick(axis.pointRangePadding, 0),
  1929. start,
  1930. i;
  1931. // Min & max check (#4247)
  1932. breaks.forEach(function (brk) {
  1933. repeat = brk.repeat || Infinity;
  1934. if (BrokenAxisAdditions.isInBreak(brk, min)) {
  1935. min +=
  1936. (brk.to % repeat) -
  1937. (min % repeat);
  1938. }
  1939. if (BrokenAxisAdditions.isInBreak(brk, max)) {
  1940. max -=
  1941. (max % repeat) -
  1942. (brk.from % repeat);
  1943. }
  1944. });
  1945. // Construct an array holding all breaks in the axis
  1946. breaks.forEach(function (brk) {
  1947. start = brk.from;
  1948. repeat = brk.repeat || Infinity;
  1949. while (start - repeat > min) {
  1950. start -= repeat;
  1951. }
  1952. while (start < min) {
  1953. start += repeat;
  1954. }
  1955. for (i = start; i < max; i += repeat) {
  1956. breakArrayT.push({
  1957. value: i,
  1958. move: 'in'
  1959. });
  1960. breakArrayT.push({
  1961. value: i + (brk.to - brk.from),
  1962. move: 'out',
  1963. size: brk.breakSize
  1964. });
  1965. }
  1966. });
  1967. breakArrayT.sort(function (a, b) {
  1968. return ((a.value === b.value) ?
  1969. ((a.move === 'in' ? 0 : 1) -
  1970. (b.move === 'in' ? 0 : 1)) :
  1971. a.value - b.value);
  1972. });
  1973. // Simplify the breaks
  1974. inBrk = 0;
  1975. start = min;
  1976. breakArrayT.forEach(function (brk) {
  1977. inBrk += (brk.move === 'in' ? 1 : -1);
  1978. if (inBrk === 1 && brk.move === 'in') {
  1979. start = brk.value;
  1980. }
  1981. if (inBrk === 0) {
  1982. breakArray.push({
  1983. from: start,
  1984. to: brk.value,
  1985. len: brk.value - start - (brk.size || 0)
  1986. });
  1987. length += brk.value - start - (brk.size || 0);
  1988. }
  1989. });
  1990. /**
  1991. * HC <= 8 backwards compatibility, used by demo samples.
  1992. * @deprecated
  1993. * @private
  1994. * @requires modules/broken-axis
  1995. */
  1996. axis.breakArray = brokenAxis.breakArray = breakArray;
  1997. // Used with staticScale, and below the actual axis length,
  1998. // when breaks are substracted.
  1999. brokenAxis.unitLength = max - min - length + pointRangePadding;
  2000. fireEvent(axis, 'afterBreaks');
  2001. if (axis.staticScale) {
  2002. axis.transA = axis.staticScale;
  2003. }
  2004. else if (brokenAxis.unitLength) {
  2005. axis.transA *=
  2006. (max - axis.min + pointRangePadding) /
  2007. brokenAxis.unitLength;
  2008. }
  2009. if (pointRangePadding) {
  2010. axis.minPixelPadding =
  2011. axis.transA * axis.minPointOffset;
  2012. }
  2013. axis.min = min;
  2014. axis.max = max;
  2015. }
  2016. };
  2017. }
  2018. if (pick(redraw, true)) {
  2019. axis.chart.redraw();
  2020. }
  2021. };
  2022. return BrokenAxisAdditions;
  2023. }());
  2024. /**
  2025. * Axis with support of broken data rows.
  2026. * @private
  2027. * @class
  2028. */
  2029. var BrokenAxis = /** @class */ (function () {
  2030. function BrokenAxis() {
  2031. }
  2032. /**
  2033. * Adds support for broken axes.
  2034. * @private
  2035. */
  2036. BrokenAxis.compose = function (AxisClass, SeriesClass) {
  2037. AxisClass.keepProps.push('brokenAxis');
  2038. var seriesProto = Series.prototype;
  2039. /**
  2040. * @private
  2041. */
  2042. seriesProto.drawBreaks = function (axis, keys) {
  2043. var series = this,
  2044. points = series.points,
  2045. breaks,
  2046. threshold,
  2047. eventName,
  2048. y;
  2049. if (axis && // #5950
  2050. axis.brokenAxis &&
  2051. axis.brokenAxis.hasBreaks) {
  2052. var brokenAxis_1 = axis.brokenAxis;
  2053. keys.forEach(function (key) {
  2054. breaks = brokenAxis_1 && brokenAxis_1.breakArray || [];
  2055. threshold = axis.isXAxis ?
  2056. axis.min :
  2057. pick(series.options.threshold, axis.min);
  2058. points.forEach(function (point) {
  2059. y = pick(point['stack' + key.toUpperCase()], point[key]);
  2060. breaks.forEach(function (brk) {
  2061. if (isNumber(threshold) && isNumber(y)) {
  2062. eventName = false;
  2063. if ((threshold < brk.from && y > brk.to) ||
  2064. (threshold > brk.from && y < brk.from)) {
  2065. eventName = 'pointBreak';
  2066. }
  2067. else if ((threshold < brk.from && y > brk.from && y < brk.to) ||
  2068. (threshold > brk.from && y > brk.to && y < brk.from)) {
  2069. eventName = 'pointInBreak';
  2070. }
  2071. if (eventName) {
  2072. fireEvent(axis, eventName, { point: point, brk: brk });
  2073. }
  2074. }
  2075. });
  2076. });
  2077. });
  2078. }
  2079. };
  2080. /**
  2081. * Extend getGraphPath by identifying gaps in the data so that we can
  2082. * draw a gap in the line or area. This was moved from ordinal axis
  2083. * module to broken axis module as of #5045.
  2084. *
  2085. * @private
  2086. * @function Highcharts.Series#gappedPath
  2087. *
  2088. * @return {Highcharts.SVGPathArray}
  2089. * Gapped path
  2090. */
  2091. seriesProto.gappedPath = function () {
  2092. var currentDataGrouping = this.currentDataGrouping,
  2093. groupingSize = currentDataGrouping && currentDataGrouping.gapSize,
  2094. gapSize = this.options.gapSize,
  2095. points = this.points.slice(),
  2096. i = points.length - 1,
  2097. yAxis = this.yAxis,
  2098. stack;
  2099. /**
  2100. * Defines when to display a gap in the graph, together with the
  2101. * [gapUnit](plotOptions.series.gapUnit) option.
  2102. *
  2103. * In case when `dataGrouping` is enabled, points can be grouped
  2104. * into a larger time span. This can make the grouped points to have
  2105. * a greater distance than the absolute value of `gapSize` property,
  2106. * which will result in disappearing graph completely. To prevent
  2107. * this situation the mentioned distance between grouped points is
  2108. * used instead of previously defined `gapSize`.
  2109. *
  2110. * In practice, this option is most often used to visualize gaps in
  2111. * time series. In a stock chart, intraday data is available for
  2112. * daytime hours, while gaps will appear in nights and weekends.
  2113. *
  2114. * @see [gapUnit](plotOptions.series.gapUnit)
  2115. * @see [xAxis.breaks](#xAxis.breaks)
  2116. *
  2117. * @sample {highstock} stock/plotoptions/series-gapsize/
  2118. * Setting the gap size to 2 introduces gaps for weekends
  2119. * in daily datasets.
  2120. *
  2121. * @type {number}
  2122. * @default 0
  2123. * @product highstock
  2124. * @requires modules/broken-axis
  2125. * @apioption plotOptions.series.gapSize
  2126. */
  2127. /**
  2128. * Together with [gapSize](plotOptions.series.gapSize), this option
  2129. * defines where to draw gaps in the graph.
  2130. *
  2131. * When the `gapUnit` is `"relative"` (default), a gap size of 5
  2132. * means that if the distance between two points is greater than
  2133. * 5 times that of the two closest points, the graph will be broken.
  2134. *
  2135. * When the `gapUnit` is `"value"`, the gap is based on absolute
  2136. * axis values, which on a datetime axis is milliseconds. This also
  2137. * applies to the navigator series that inherits gap options from
  2138. * the base series.
  2139. *
  2140. * @see [gapSize](plotOptions.series.gapSize)
  2141. *
  2142. * @type {string}
  2143. * @default relative
  2144. * @since 5.0.13
  2145. * @product highstock
  2146. * @validvalue ["relative", "value"]
  2147. * @requires modules/broken-axis
  2148. * @apioption plotOptions.series.gapUnit
  2149. */
  2150. if (gapSize && i > 0) { // #5008
  2151. // Gap unit is relative
  2152. if (this.options.gapUnit !== 'value') {
  2153. gapSize *= this.basePointRange;
  2154. }
  2155. // Setting a new gapSize in case dataGrouping is enabled (#7686)
  2156. if (groupingSize &&
  2157. groupingSize > gapSize &&
  2158. // Except when DG is forced (e.g. from other series)
  2159. // and has lower granularity than actual points (#11351)
  2160. groupingSize >= this.basePointRange) {
  2161. gapSize = groupingSize;
  2162. }
  2163. // extension for ordinal breaks
  2164. var current = void 0,
  2165. next = void 0;
  2166. while (i--) {
  2167. // Reassign next if it is not visible
  2168. if (!(next && next.visible !== false)) {
  2169. next = points[i + 1];
  2170. }
  2171. current = points[i];
  2172. // Skip iteration if one of the points is not visible
  2173. if (next.visible === false || current.visible === false) {
  2174. continue;
  2175. }
  2176. if (next.x - current.x > gapSize) {
  2177. var xRange = (current.x + next.x) / 2;
  2178. points.splice(// insert after this one
  2179. i + 1, 0, {
  2180. isNull: true,
  2181. x: xRange
  2182. });
  2183. // For stacked chart generate empty stack items, #6546
  2184. if (yAxis.stacking && this.options.stacking) {
  2185. stack = yAxis.stacking.stacks[this.stackKey][xRange] =
  2186. new StackItem(yAxis, yAxis.options
  2187. .stackLabels, false, xRange, this.stack);
  2188. stack.total = 0;
  2189. }
  2190. }
  2191. // Assign current to next for the upcoming iteration
  2192. next = current;
  2193. }
  2194. }
  2195. // Call base method
  2196. return this.getGraphPath(points);
  2197. };
  2198. /* eslint-disable no-invalid-this */
  2199. addEvent(AxisClass, 'init', function () {
  2200. var axis = this;
  2201. if (!axis.brokenAxis) {
  2202. axis.brokenAxis = new BrokenAxisAdditions(axis);
  2203. }
  2204. });
  2205. addEvent(AxisClass, 'afterInit', function () {
  2206. if (typeof this.brokenAxis !== 'undefined') {
  2207. this.brokenAxis.setBreaks(this.options.breaks, false);
  2208. }
  2209. });
  2210. addEvent(AxisClass, 'afterSetTickPositions', function () {
  2211. var axis = this;
  2212. var brokenAxis = axis.brokenAxis;
  2213. if (brokenAxis &&
  2214. brokenAxis.hasBreaks) {
  2215. var tickPositions = this.tickPositions,
  2216. info = this.tickPositions.info,
  2217. newPositions = [],
  2218. i;
  2219. for (i = 0; i < tickPositions.length; i++) {
  2220. if (!brokenAxis.isInAnyBreak(tickPositions[i])) {
  2221. newPositions.push(tickPositions[i]);
  2222. }
  2223. }
  2224. this.tickPositions = newPositions;
  2225. this.tickPositions.info = info;
  2226. }
  2227. });
  2228. // Force Axis to be not-ordinal when breaks are defined
  2229. addEvent(AxisClass, 'afterSetOptions', function () {
  2230. if (this.brokenAxis && this.brokenAxis.hasBreaks) {
  2231. this.options.ordinal = false;
  2232. }
  2233. });
  2234. addEvent(SeriesClass, 'afterGeneratePoints', function () {
  2235. var _a = this,
  2236. isDirty = _a.isDirty,
  2237. connectNulls = _a.options.connectNulls,
  2238. points = _a.points,
  2239. xAxis = _a.xAxis,
  2240. yAxis = _a.yAxis;
  2241. // Set, or reset visibility of the points. Axis.setBreaks marks the
  2242. // series as isDirty
  2243. if (isDirty) {
  2244. var i = points.length;
  2245. while (i--) {
  2246. var point = points[i];
  2247. // Respect nulls inside the break (#4275)
  2248. var nullGap = point.y === null && connectNulls === false;
  2249. var isPointInBreak = (!nullGap && ((xAxis &&
  2250. xAxis.brokenAxis &&
  2251. xAxis.brokenAxis.isInAnyBreak(point.x,
  2252. true)) || (yAxis &&
  2253. yAxis.brokenAxis &&
  2254. yAxis.brokenAxis.isInAnyBreak(point.y,
  2255. true))));
  2256. // Set point.visible if in any break.
  2257. // If not in break, reset visible to original value.
  2258. point.visible = isPointInBreak ?
  2259. false :
  2260. point.options.visible !== false;
  2261. }
  2262. }
  2263. });
  2264. addEvent(SeriesClass, 'afterRender', function drawPointsWrapped() {
  2265. this.drawBreaks(this.xAxis, ['x']);
  2266. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  2267. });
  2268. };
  2269. return BrokenAxis;
  2270. }());
  2271. BrokenAxis.compose(Axis, Series); // @todo remove automatism
  2272. return BrokenAxis;
  2273. });
  2274. _registerModule(_modules, 'Core/Axis/TreeGridAxis.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Axis/Tick.js'], _modules['Gantt/Tree.js'], _modules['Core/Axis/TreeGridTick.js'], _modules['Mixins/TreeSeries.js'], _modules['Core/Utilities.js']], function (Axis, Tick, Tree, TreeGridTick, mixinTreeSeries, U) {
  2275. /* *
  2276. *
  2277. * (c) 2016 Highsoft AS
  2278. * Authors: Jon Arild Nygard
  2279. *
  2280. * License: www.highcharts.com/license
  2281. *
  2282. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2283. *
  2284. * */
  2285. var getLevelOptions = mixinTreeSeries.getLevelOptions;
  2286. var addEvent = U.addEvent,
  2287. find = U.find,
  2288. fireEvent = U.fireEvent,
  2289. isNumber = U.isNumber,
  2290. isObject = U.isObject,
  2291. isString = U.isString,
  2292. merge = U.merge,
  2293. pick = U.pick,
  2294. wrap = U.wrap;
  2295. /**
  2296. * @private
  2297. */
  2298. var TreeGridAxis;
  2299. (function (TreeGridAxis) {
  2300. /* *
  2301. *
  2302. * Interfaces
  2303. *
  2304. * */
  2305. /* *
  2306. *
  2307. * Variables
  2308. *
  2309. * */
  2310. var applied = false;
  2311. /* *
  2312. *
  2313. * Functions
  2314. *
  2315. * */
  2316. /**
  2317. * @private
  2318. */
  2319. function compose(AxisClass) {
  2320. if (!applied) {
  2321. wrap(AxisClass.prototype, 'generateTick', wrapGenerateTick);
  2322. wrap(AxisClass.prototype, 'getMaxLabelDimensions', wrapGetMaxLabelDimensions);
  2323. wrap(AxisClass.prototype, 'init', wrapInit);
  2324. wrap(AxisClass.prototype, 'setTickInterval', wrapSetTickInterval);
  2325. TreeGridTick.compose(Tick);
  2326. applied = true;
  2327. }
  2328. }
  2329. TreeGridAxis.compose = compose;
  2330. /**
  2331. * @private
  2332. */
  2333. function getBreakFromNode(node, max) {
  2334. var from = node.collapseStart || 0,
  2335. to = node.collapseEnd || 0;
  2336. // In broken-axis, the axis.max is minimized until it is not within a
  2337. // break. Therefore, if break.to is larger than axis.max, the axis.to
  2338. // should not add the 0.5 axis.tickMarkOffset, to avoid adding a break
  2339. // larger than axis.max.
  2340. // TODO consider simplifying broken-axis and this might solve itself
  2341. if (to >= max) {
  2342. from -= 0.5;
  2343. }
  2344. return {
  2345. from: from,
  2346. to: to,
  2347. showPoints: false
  2348. };
  2349. }
  2350. /**
  2351. * Creates a tree structure of the data, and the treegrid. Calculates
  2352. * categories, and y-values of points based on the tree.
  2353. *
  2354. * @private
  2355. * @function getTreeGridFromData
  2356. *
  2357. * @param {Array<Highcharts.GanttPointOptions>} data
  2358. * All the data points to display in the axis.
  2359. *
  2360. * @param {boolean} uniqueNames
  2361. * Wether or not the data node with the same name should share grid cell. If
  2362. * true they do share cell. False by default.
  2363. *
  2364. * @param {number} numberOfSeries
  2365. *
  2366. * @return {object}
  2367. * Returns an object containing categories, mapOfIdToNode,
  2368. * mapOfPosToGridNode, and tree.
  2369. *
  2370. * @todo There should be only one point per line.
  2371. * @todo It should be optional to have one category per point, or merge
  2372. * cells
  2373. * @todo Add unit-tests.
  2374. */
  2375. function getTreeGridFromData(data, uniqueNames, numberOfSeries) {
  2376. var categories = [],
  2377. collapsedNodes = [],
  2378. mapOfIdToNode = {},
  2379. mapOfPosToGridNode = {},
  2380. posIterator = -1,
  2381. uniqueNamesEnabled = typeof uniqueNames === 'boolean' ? uniqueNames : false,
  2382. tree;
  2383. // Build the tree from the series data.
  2384. var treeParams = {
  2385. // After the children has been created.
  2386. after: function (node) {
  2387. var gridNode = mapOfPosToGridNode[node.pos],
  2388. height = 0,
  2389. descendants = 0;
  2390. gridNode.children.forEach(function (child) {
  2391. descendants += (child.descendants || 0) + 1;
  2392. height = Math.max((child.height || 0) + 1, height);
  2393. });
  2394. gridNode.descendants = descendants;
  2395. gridNode.height = height;
  2396. if (gridNode.collapsed) {
  2397. collapsedNodes.push(gridNode);
  2398. }
  2399. },
  2400. // Before the children has been created.
  2401. before: function (node) {
  2402. var data = isObject(node.data,
  2403. true) ? node.data : {},
  2404. name = isString(data.name) ? data.name : '',
  2405. parentNode = mapOfIdToNode[node.parent],
  2406. parentGridNode = (isObject(parentNode,
  2407. true) ?
  2408. mapOfPosToGridNode[parentNode.pos] :
  2409. null),
  2410. hasSameName = function (x) {
  2411. return x.name === name;
  2412. }, gridNode, pos;
  2413. // If not unique names, look for sibling node with the same name
  2414. if (uniqueNamesEnabled &&
  2415. isObject(parentGridNode, true) &&
  2416. !!(gridNode = find(parentGridNode.children, hasSameName))) {
  2417. // If there is a gridNode with the same name, reuse position
  2418. pos = gridNode.pos;
  2419. // Add data node to list of nodes in the grid node.
  2420. gridNode.nodes.push(node);
  2421. }
  2422. else {
  2423. // If it is a new grid node, increment position.
  2424. pos = posIterator++;
  2425. }
  2426. // Add new grid node to map.
  2427. if (!mapOfPosToGridNode[pos]) {
  2428. mapOfPosToGridNode[pos] = gridNode = {
  2429. depth: parentGridNode ? parentGridNode.depth + 1 : 0,
  2430. name: name,
  2431. nodes: [node],
  2432. children: [],
  2433. pos: pos
  2434. };
  2435. // If not root, then add name to categories.
  2436. if (pos !== -1) {
  2437. categories.push(name);
  2438. }
  2439. // Add name to list of children.
  2440. if (isObject(parentGridNode, true)) {
  2441. parentGridNode.children.push(gridNode);
  2442. }
  2443. }
  2444. // Add data node to map
  2445. if (isString(node.id)) {
  2446. mapOfIdToNode[node.id] = node;
  2447. }
  2448. // If one of the points are collapsed, then start the grid node
  2449. // in collapsed state.
  2450. if (gridNode &&
  2451. data.collapsed === true) {
  2452. gridNode.collapsed = true;
  2453. }
  2454. // Assign pos to data node
  2455. node.pos = pos;
  2456. }
  2457. };
  2458. var updateYValuesAndTickPos = function (map,
  2459. numberOfSeries) {
  2460. var setValues = function (gridNode,
  2461. start,
  2462. result) {
  2463. var nodes = gridNode.nodes,
  2464. end = start + (start === -1 ? 0 : numberOfSeries - 1),
  2465. diff = (end - start) / 2,
  2466. padding = 0.5,
  2467. pos = start + diff;
  2468. nodes.forEach(function (node) {
  2469. var data = node.data;
  2470. if (isObject(data, true)) {
  2471. // Update point
  2472. data.y = start + (data.seriesIndex || 0);
  2473. // Remove the property once used
  2474. delete data.seriesIndex;
  2475. }
  2476. node.pos = pos;
  2477. });
  2478. result[pos] = gridNode;
  2479. gridNode.pos = pos;
  2480. gridNode.tickmarkOffset = diff + padding;
  2481. gridNode.collapseStart = end + padding;
  2482. gridNode.children.forEach(function (child) {
  2483. setValues(child, end + 1, result);
  2484. end = (child.collapseEnd || 0) - padding;
  2485. });
  2486. // Set collapseEnd to the end of the last child node.
  2487. gridNode.collapseEnd = end + padding;
  2488. return result;
  2489. };
  2490. return setValues(map['-1'], -1, {});
  2491. };
  2492. // Create tree from data
  2493. tree = Tree.getTree(data, treeParams);
  2494. // Update y values of data, and set calculate tick positions.
  2495. mapOfPosToGridNode = updateYValuesAndTickPos(mapOfPosToGridNode, numberOfSeries);
  2496. // Return the resulting data.
  2497. return {
  2498. categories: categories,
  2499. mapOfIdToNode: mapOfIdToNode,
  2500. mapOfPosToGridNode: mapOfPosToGridNode,
  2501. collapsedNodes: collapsedNodes,
  2502. tree: tree
  2503. };
  2504. }
  2505. /**
  2506. * Builds the tree of categories and calculates its positions.
  2507. * @private
  2508. * @param {object} e Event object
  2509. * @param {object} e.target The chart instance which the event was fired on.
  2510. * @param {object[]} e.target.axes The axes of the chart.
  2511. */
  2512. function onBeforeRender(e) {
  2513. var chart = e.target,
  2514. axes = chart.axes;
  2515. axes.filter(function (axis) {
  2516. return axis.options.type === 'treegrid';
  2517. }).forEach(function (axis) {
  2518. var options = axis.options || {},
  2519. labelOptions = options.labels,
  2520. uniqueNames = options.uniqueNames,
  2521. numberOfSeries = 0,
  2522. isDirty,
  2523. data,
  2524. treeGrid,
  2525. max = options.max;
  2526. // Check whether any of series is rendering for the first time,
  2527. // visibility has changed, or its data is dirty,
  2528. // and only then update. #10570, #10580
  2529. // Also check if mapOfPosToGridNode exists. #10887
  2530. isDirty = (!axis.treeGrid.mapOfPosToGridNode ||
  2531. axis.series.some(function (series) {
  2532. return !series.hasRendered ||
  2533. series.isDirtyData ||
  2534. series.isDirty;
  2535. }));
  2536. if (isDirty) {
  2537. // Concatenate data from all series assigned to this axis.
  2538. data = axis.series.reduce(function (arr, s) {
  2539. if (s.visible) {
  2540. // Push all data to array
  2541. (s.options.data || []).forEach(function (data) {
  2542. if (isObject(data, true)) {
  2543. // Set series index on data. Removed again
  2544. // after use.
  2545. data.seriesIndex = numberOfSeries;
  2546. arr.push(data);
  2547. }
  2548. });
  2549. // Increment series index
  2550. if (uniqueNames === true) {
  2551. numberOfSeries++;
  2552. }
  2553. }
  2554. return arr;
  2555. }, []);
  2556. // If max is higher than set data - add a
  2557. // dummy data to render categories #10779
  2558. if (max && data.length < max) {
  2559. for (var i = data.length; i <= max; i++) {
  2560. data.push({
  2561. // Use the zero-width character
  2562. // to avoid conflict with uniqueNames
  2563. name: i + '\u200B'
  2564. });
  2565. }
  2566. }
  2567. // setScale is fired after all the series is initialized,
  2568. // which is an ideal time to update the axis.categories.
  2569. treeGrid = getTreeGridFromData(data, uniqueNames || false, (uniqueNames === true) ? numberOfSeries : 1);
  2570. // Assign values to the axis.
  2571. axis.categories = treeGrid.categories;
  2572. axis.treeGrid.mapOfPosToGridNode = treeGrid.mapOfPosToGridNode;
  2573. axis.hasNames = true;
  2574. axis.treeGrid.tree = treeGrid.tree;
  2575. // Update yData now that we have calculated the y values
  2576. axis.series.forEach(function (series) {
  2577. var data = (series.options.data || []).map(function (d) {
  2578. return isObject(d,
  2579. true) ? merge(d) : d;
  2580. });
  2581. // Avoid destroying points when series is not visible
  2582. if (series.visible) {
  2583. series.setData(data, false);
  2584. }
  2585. });
  2586. // Calculate the label options for each level in the tree.
  2587. axis.treeGrid.mapOptionsToLevel =
  2588. getLevelOptions({
  2589. defaults: labelOptions,
  2590. from: 1,
  2591. levels: labelOptions && labelOptions.levels,
  2592. to: axis.treeGrid.tree && axis.treeGrid.tree.height
  2593. });
  2594. // Setting initial collapsed nodes
  2595. if (e.type === 'beforeRender') {
  2596. axis.treeGrid.collapsedNodes = treeGrid.collapsedNodes;
  2597. }
  2598. }
  2599. });
  2600. }
  2601. /**
  2602. * Generates a tick for initial positioning.
  2603. *
  2604. * @private
  2605. * @function Highcharts.GridAxis#generateTick
  2606. *
  2607. * @param {Function} proceed
  2608. * The original generateTick function.
  2609. *
  2610. * @param {number} pos
  2611. * The tick position in axis values.
  2612. */
  2613. function wrapGenerateTick(proceed, pos) {
  2614. var axis = this,
  2615. mapOptionsToLevel = axis.treeGrid.mapOptionsToLevel || {},
  2616. isTreeGrid = axis.options.type === 'treegrid',
  2617. ticks = axis.ticks;
  2618. var tick = ticks[pos],
  2619. levelOptions,
  2620. options,
  2621. gridNode;
  2622. if (isTreeGrid &&
  2623. axis.treeGrid.mapOfPosToGridNode) {
  2624. gridNode = axis.treeGrid.mapOfPosToGridNode[pos];
  2625. levelOptions = mapOptionsToLevel[gridNode.depth];
  2626. if (levelOptions) {
  2627. options = {
  2628. labels: levelOptions
  2629. };
  2630. }
  2631. if (!tick) {
  2632. ticks[pos] = tick =
  2633. new Tick(axis, pos, void 0, void 0, {
  2634. category: gridNode.name,
  2635. tickmarkOffset: gridNode.tickmarkOffset,
  2636. options: options
  2637. });
  2638. }
  2639. else {
  2640. // update labels depending on tick interval
  2641. tick.parameters.category = gridNode.name;
  2642. tick.options = options;
  2643. tick.addLabel();
  2644. }
  2645. }
  2646. else {
  2647. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2648. }
  2649. }
  2650. /**
  2651. * Override to add indentation to axis.maxLabelDimensions.
  2652. *
  2653. * @private
  2654. * @function Highcharts.GridAxis#getMaxLabelDimensions
  2655. *
  2656. * @param {Function} proceed
  2657. * The original function
  2658. */
  2659. function wrapGetMaxLabelDimensions(proceed) {
  2660. var axis = this,
  2661. options = axis.options,
  2662. labelOptions = options && options.labels,
  2663. indentation = (labelOptions && isNumber(labelOptions.indentation) ?
  2664. labelOptions.indentation :
  2665. 0),
  2666. retVal = proceed.apply(axis,
  2667. Array.prototype.slice.call(arguments, 1)),
  2668. isTreeGrid = axis.options.type === 'treegrid';
  2669. var treeDepth;
  2670. if (isTreeGrid && axis.treeGrid.mapOfPosToGridNode) {
  2671. treeDepth = axis.treeGrid.mapOfPosToGridNode[-1].height || 0;
  2672. retVal.width += indentation * (treeDepth - 1);
  2673. }
  2674. return retVal;
  2675. }
  2676. /**
  2677. * @private
  2678. */
  2679. function wrapInit(proceed, chart, userOptions) {
  2680. var axis = this,
  2681. isTreeGrid = userOptions.type === 'treegrid';
  2682. if (!axis.treeGrid) {
  2683. axis.treeGrid = new Additions(axis);
  2684. }
  2685. // Set default and forced options for TreeGrid
  2686. if (isTreeGrid) {
  2687. // Add event for updating the categories of a treegrid.
  2688. // NOTE Preferably these events should be set on the axis.
  2689. addEvent(chart, 'beforeRender', onBeforeRender);
  2690. addEvent(chart, 'beforeRedraw', onBeforeRender);
  2691. // Add new collapsed nodes on addseries
  2692. addEvent(chart, 'addSeries', function (e) {
  2693. if (e.options.data) {
  2694. var treeGrid = getTreeGridFromData(e.options.data,
  2695. userOptions.uniqueNames || false, 1);
  2696. axis.treeGrid.collapsedNodes = (axis.treeGrid.collapsedNodes || []).concat(treeGrid.collapsedNodes);
  2697. }
  2698. });
  2699. // Collapse all nodes in axis.treegrid.collapsednodes
  2700. // where collapsed equals true.
  2701. addEvent(axis, 'foundExtremes', function () {
  2702. if (axis.treeGrid.collapsedNodes) {
  2703. axis.treeGrid.collapsedNodes.forEach(function (node) {
  2704. var breaks = axis.treeGrid.collapse(node);
  2705. if (axis.brokenAxis) {
  2706. axis.brokenAxis.setBreaks(breaks, false);
  2707. // remove the node from the axis collapsedNodes
  2708. if (axis.treeGrid.collapsedNodes) {
  2709. axis.treeGrid.collapsedNodes = axis.treeGrid.collapsedNodes.filter(function (n) {
  2710. return node.collapseStart !== n.collapseStart ||
  2711. node.collapseEnd !== n.collapseEnd;
  2712. });
  2713. }
  2714. }
  2715. });
  2716. }
  2717. });
  2718. // If staticScale is not defined on the yAxis
  2719. // and chart height is set, set axis.isDirty
  2720. // to ensure collapsing works (#12012)
  2721. addEvent(axis, 'afterBreaks', function () {
  2722. var _a;
  2723. if (axis.coll === 'yAxis' && !axis.staticScale && ((_a = axis.chart.options.chart) === null || _a === void 0 ? void 0 : _a.height)) {
  2724. axis.isDirty = true;
  2725. }
  2726. });
  2727. userOptions = merge({
  2728. // Default options
  2729. grid: {
  2730. enabled: true
  2731. },
  2732. // TODO: add support for align in treegrid.
  2733. labels: {
  2734. align: 'left',
  2735. /**
  2736. * Set options on specific levels in a tree grid axis. Takes
  2737. * precedence over labels options.
  2738. *
  2739. * @sample {gantt} gantt/treegrid-axis/labels-levels
  2740. * Levels on TreeGrid Labels
  2741. *
  2742. * @type {Array<*>}
  2743. * @product gantt
  2744. * @apioption yAxis.labels.levels
  2745. *
  2746. * @private
  2747. */
  2748. levels: [{
  2749. /**
  2750. * Specify the level which the options within this object
  2751. * applies to.
  2752. *
  2753. * @type {number}
  2754. * @product gantt
  2755. * @apioption yAxis.labels.levels.level
  2756. *
  2757. * @private
  2758. */
  2759. level: void 0
  2760. }, {
  2761. level: 1,
  2762. /**
  2763. * @type {Highcharts.CSSObject}
  2764. * @product gantt
  2765. * @apioption yAxis.labels.levels.style
  2766. *
  2767. * @private
  2768. */
  2769. style: {
  2770. /** @ignore-option */
  2771. fontWeight: 'bold'
  2772. }
  2773. }],
  2774. /**
  2775. * The symbol for the collapse and expand icon in a
  2776. * treegrid.
  2777. *
  2778. * @product gantt
  2779. * @optionparent yAxis.labels.symbol
  2780. *
  2781. * @private
  2782. */
  2783. symbol: {
  2784. /**
  2785. * The symbol type. Points to a definition function in
  2786. * the `Highcharts.Renderer.symbols` collection.
  2787. *
  2788. * @type {Highcharts.SymbolKeyValue}
  2789. *
  2790. * @private
  2791. */
  2792. type: 'triangle',
  2793. x: -5,
  2794. y: -5,
  2795. height: 10,
  2796. width: 10,
  2797. padding: 5
  2798. }
  2799. },
  2800. uniqueNames: false
  2801. }, userOptions, {
  2802. // Forced options
  2803. reversed: true,
  2804. // grid.columns is not supported in treegrid
  2805. grid: {
  2806. columns: void 0
  2807. }
  2808. });
  2809. }
  2810. // Now apply the original function with the original arguments,
  2811. // which are sliced off this function's arguments
  2812. proceed.apply(axis, [chart, userOptions]);
  2813. if (isTreeGrid) {
  2814. axis.hasNames = true;
  2815. axis.options.showLastLabel = true;
  2816. }
  2817. }
  2818. /**
  2819. * Set the tick positions, tickInterval, axis min and max.
  2820. *
  2821. * @private
  2822. * @function Highcharts.GridAxis#setTickInterval
  2823. *
  2824. * @param {Function} proceed
  2825. * The original setTickInterval function.
  2826. */
  2827. function wrapSetTickInterval(proceed) {
  2828. var axis = this,
  2829. options = axis.options,
  2830. isTreeGrid = options.type === 'treegrid';
  2831. if (isTreeGrid) {
  2832. axis.min = pick(axis.userMin, options.min, axis.dataMin);
  2833. axis.max = pick(axis.userMax, options.max, axis.dataMax);
  2834. fireEvent(axis, 'foundExtremes');
  2835. // setAxisTranslation modifies the min and max according to
  2836. // axis breaks.
  2837. axis.setAxisTranslation(true);
  2838. axis.tickmarkOffset = 0.5;
  2839. axis.tickInterval = 1;
  2840. axis.tickPositions = axis.treeGrid.mapOfPosToGridNode ?
  2841. axis.treeGrid.getTickPositions() :
  2842. [];
  2843. }
  2844. else {
  2845. proceed.apply(axis, Array.prototype.slice.call(arguments, 1));
  2846. }
  2847. }
  2848. /* *
  2849. *
  2850. * Classes
  2851. *
  2852. * */
  2853. /**
  2854. * @private
  2855. * @class
  2856. */
  2857. var Additions = /** @class */ (function () {
  2858. /* *
  2859. *
  2860. * Constructors
  2861. *
  2862. * */
  2863. /**
  2864. * @private
  2865. */
  2866. function Additions(axis) {
  2867. this.axis = axis;
  2868. }
  2869. /* *
  2870. *
  2871. * Functions
  2872. *
  2873. * */
  2874. /**
  2875. * Calculates the new axis breaks to collapse a node.
  2876. *
  2877. * @private
  2878. *
  2879. * @param {Highcharts.Axis} axis
  2880. * The axis to check against.
  2881. *
  2882. * @param {Highcharts.GridNode} node
  2883. * The node to collapse.
  2884. *
  2885. * @param {number} pos
  2886. * The tick position to collapse.
  2887. *
  2888. * @return {Array<object>}
  2889. * Returns an array of the new breaks for the axis.
  2890. */
  2891. Additions.prototype.collapse = function (node) {
  2892. var axis = this.axis,
  2893. breaks = (axis.options.breaks || []),
  2894. obj = getBreakFromNode(node,
  2895. axis.max);
  2896. breaks.push(obj);
  2897. return breaks;
  2898. };
  2899. /**
  2900. * Calculates the new axis breaks to expand a node.
  2901. *
  2902. * @private
  2903. *
  2904. * @param {Highcharts.Axis} axis
  2905. * The axis to check against.
  2906. *
  2907. * @param {Highcharts.GridNode} node
  2908. * The node to expand.
  2909. *
  2910. * @param {number} pos
  2911. * The tick position to expand.
  2912. *
  2913. * @return {Array<object>}
  2914. * Returns an array of the new breaks for the axis.
  2915. */
  2916. Additions.prototype.expand = function (node) {
  2917. var axis = this.axis,
  2918. breaks = (axis.options.breaks || []),
  2919. obj = getBreakFromNode(node,
  2920. axis.max);
  2921. // Remove the break from the axis breaks array.
  2922. return breaks.reduce(function (arr, b) {
  2923. if (b.to !== obj.to || b.from !== obj.from) {
  2924. arr.push(b);
  2925. }
  2926. return arr;
  2927. }, []);
  2928. };
  2929. /**
  2930. * Creates a list of positions for the ticks on the axis. Filters out
  2931. * positions that are outside min and max, or is inside an axis break.
  2932. *
  2933. * @private
  2934. *
  2935. * @return {Array<number>}
  2936. * List of positions.
  2937. */
  2938. Additions.prototype.getTickPositions = function () {
  2939. var axis = this.axis;
  2940. return Object.keys(axis.treeGrid.mapOfPosToGridNode || {}).reduce(function (arr, key) {
  2941. var pos = +key;
  2942. if (axis.min <= pos &&
  2943. axis.max >= pos &&
  2944. !(axis.brokenAxis && axis.brokenAxis.isInAnyBreak(pos))) {
  2945. arr.push(pos);
  2946. }
  2947. return arr;
  2948. }, []);
  2949. };
  2950. /**
  2951. * Check if a node is collapsed.
  2952. *
  2953. * @private
  2954. *
  2955. * @param {Highcharts.Axis} axis
  2956. * The axis to check against.
  2957. *
  2958. * @param {object} node
  2959. * The node to check if is collapsed.
  2960. *
  2961. * @param {number} pos
  2962. * The tick position to collapse.
  2963. *
  2964. * @return {boolean}
  2965. * Returns true if collapsed, false if expanded.
  2966. */
  2967. Additions.prototype.isCollapsed = function (node) {
  2968. var axis = this.axis,
  2969. breaks = (axis.options.breaks || []),
  2970. obj = getBreakFromNode(node,
  2971. axis.max);
  2972. return breaks.some(function (b) {
  2973. return b.from === obj.from && b.to === obj.to;
  2974. });
  2975. };
  2976. /**
  2977. * Calculates the new axis breaks after toggling the collapse/expand
  2978. * state of a node. If it is collapsed it will be expanded, and if it is
  2979. * exapended it will be collapsed.
  2980. *
  2981. * @private
  2982. *
  2983. * @param {Highcharts.Axis} axis
  2984. * The axis to check against.
  2985. *
  2986. * @param {Highcharts.GridNode} node
  2987. * The node to toggle.
  2988. *
  2989. * @return {Array<object>}
  2990. * Returns an array of the new breaks for the axis.
  2991. */
  2992. Additions.prototype.toggleCollapse = function (node) {
  2993. return (this.isCollapsed(node) ?
  2994. this.expand(node) :
  2995. this.collapse(node));
  2996. };
  2997. return Additions;
  2998. }());
  2999. TreeGridAxis.Additions = Additions;
  3000. })(TreeGridAxis || (TreeGridAxis = {}));
  3001. // Make utility functions available for testing.
  3002. Axis.prototype.utils = {
  3003. getNode: Tree.getNode
  3004. };
  3005. TreeGridAxis.compose(Axis);
  3006. return TreeGridAxis;
  3007. });
  3008. _registerModule(_modules, 'Extensions/CurrentDateIndication.js', [_modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Utilities.js'], _modules['Core/Axis/PlotLineOrBand.js']], function (H, O, U, PlotLineOrBand) {
  3009. /* *
  3010. *
  3011. * (c) 2016-2020 Highsoft AS
  3012. *
  3013. * Author: Lars A. V. Cabrera
  3014. *
  3015. * License: www.highcharts.com/license
  3016. *
  3017. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3018. *
  3019. * */
  3020. var dateFormat = O.dateFormat;
  3021. var addEvent = U.addEvent,
  3022. merge = U.merge,
  3023. wrap = U.wrap;
  3024. var Axis = H.Axis;
  3025. var defaultConfig = {
  3026. /**
  3027. * Show an indicator on the axis for the current date and time. Can be a
  3028. * boolean or a configuration object similar to
  3029. * [xAxis.plotLines](#xAxis.plotLines).
  3030. *
  3031. * @sample gantt/current-date-indicator/demo
  3032. * Current date indicator enabled
  3033. * @sample gantt/current-date-indicator/object-config
  3034. * Current date indicator with custom options
  3035. *
  3036. * @declare Highcharts.AxisCurrentDateIndicatorOptions
  3037. * @type {boolean|*}
  3038. * @default true
  3039. * @extends xAxis.plotLines
  3040. * @excluding value
  3041. * @product gantt
  3042. * @apioption xAxis.currentDateIndicator
  3043. */
  3044. currentDateIndicator: true,
  3045. color: '#ccd6eb',
  3046. width: 2,
  3047. /**
  3048. * @declare Highcharts.AxisCurrentDateIndicatorLabelOptions
  3049. */
  3050. label: {
  3051. /**
  3052. * Format of the label. This options is passed as the fist argument to
  3053. * [dateFormat](/class-reference/Highcharts#dateFormat) function.
  3054. *
  3055. * @type {string}
  3056. * @default '%a, %b %d %Y, %H:%M'
  3057. * @product gantt
  3058. * @apioption xAxis.currentDateIndicator.label.format
  3059. */
  3060. format: '%a, %b %d %Y, %H:%M',
  3061. formatter: function (value, format) {
  3062. return dateFormat(format, value);
  3063. },
  3064. rotation: 0,
  3065. /**
  3066. * @type {Highcharts.CSSObject}
  3067. */
  3068. style: {
  3069. /** @internal */
  3070. fontSize: '10px'
  3071. }
  3072. }
  3073. };
  3074. /* eslint-disable no-invalid-this */
  3075. addEvent(Axis, 'afterSetOptions', function () {
  3076. var options = this.options,
  3077. cdiOptions = options.currentDateIndicator;
  3078. if (cdiOptions) {
  3079. cdiOptions = typeof cdiOptions === 'object' ?
  3080. merge(defaultConfig, cdiOptions) : merge(defaultConfig);
  3081. cdiOptions.value = new Date();
  3082. if (!options.plotLines) {
  3083. options.plotLines = [];
  3084. }
  3085. options.plotLines.push(cdiOptions);
  3086. }
  3087. });
  3088. addEvent(PlotLineOrBand, 'render', function () {
  3089. // If the label already exists, update its text
  3090. if (this.label) {
  3091. this.label.attr({
  3092. text: this.getLabelText(this.options.label)
  3093. });
  3094. }
  3095. });
  3096. wrap(PlotLineOrBand.prototype, 'getLabelText', function (defaultMethod, defaultLabelOptions) {
  3097. var options = this.options;
  3098. if (options.currentDateIndicator && options.label &&
  3099. typeof options.label.formatter === 'function') {
  3100. options.value = new Date();
  3101. return options.label.formatter
  3102. .call(this, options.value, options.label.format);
  3103. }
  3104. return defaultMethod.call(this, defaultLabelOptions);
  3105. });
  3106. });
  3107. _registerModule(_modules, 'Extensions/StaticScale.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  3108. /* *
  3109. *
  3110. * (c) 2016-2020 Torstein Honsi, Lars Cabrera
  3111. *
  3112. * License: www.highcharts.com/license
  3113. *
  3114. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3115. *
  3116. * */
  3117. var addEvent = U.addEvent,
  3118. defined = U.defined,
  3119. isNumber = U.isNumber,
  3120. pick = U.pick;
  3121. var Chart = H.Chart;
  3122. /* eslint-disable no-invalid-this */
  3123. /**
  3124. * For vertical axes only. Setting the static scale ensures that each tick unit
  3125. * is translated into a fixed pixel height. For example, setting the static
  3126. * scale to 24 results in each Y axis category taking up 24 pixels, and the
  3127. * height of the chart adjusts. Adding or removing items will make the chart
  3128. * resize.
  3129. *
  3130. * @sample gantt/xrange-series/demo/
  3131. * X-range series with static scale
  3132. *
  3133. * @type {number}
  3134. * @default 50
  3135. * @since 6.2.0
  3136. * @product gantt
  3137. * @apioption yAxis.staticScale
  3138. */
  3139. addEvent(H.Axis, 'afterSetOptions', function () {
  3140. var chartOptions = this.chart.options && this.chart.options.chart;
  3141. if (!this.horiz &&
  3142. isNumber(this.options.staticScale) &&
  3143. (!chartOptions.height ||
  3144. (chartOptions.scrollablePlotArea &&
  3145. chartOptions.scrollablePlotArea.minHeight))) {
  3146. this.staticScale = this.options.staticScale;
  3147. }
  3148. });
  3149. Chart.prototype.adjustHeight = function () {
  3150. if (this.redrawTrigger !== 'adjustHeight') {
  3151. (this.axes || []).forEach(function (axis) {
  3152. var chart = axis.chart,
  3153. animate = !!chart.initiatedScale &&
  3154. chart.options.animation,
  3155. staticScale = axis.options.staticScale,
  3156. height,
  3157. diff;
  3158. if (axis.staticScale && defined(axis.min)) {
  3159. height = pick(axis.brokenAxis && axis.brokenAxis.unitLength, axis.max + axis.tickInterval - axis.min) * staticScale;
  3160. // Minimum height is 1 x staticScale.
  3161. height = Math.max(height, staticScale);
  3162. diff = height - chart.plotHeight;
  3163. if (Math.abs(diff) >= 1) {
  3164. chart.plotHeight = height;
  3165. chart.redrawTrigger = 'adjustHeight';
  3166. chart.setSize(void 0, chart.chartHeight + diff, animate);
  3167. }
  3168. // Make sure clip rects have the right height before initial
  3169. // animation.
  3170. axis.series.forEach(function (series) {
  3171. var clipRect = series.sharedClipKey &&
  3172. chart[series.sharedClipKey];
  3173. if (clipRect) {
  3174. clipRect.attr({
  3175. height: chart.plotHeight
  3176. });
  3177. }
  3178. });
  3179. }
  3180. });
  3181. this.initiatedScale = true;
  3182. }
  3183. this.redrawTrigger = null;
  3184. };
  3185. addEvent(Chart, 'render', Chart.prototype.adjustHeight);
  3186. });
  3187. _registerModule(_modules, 'Extensions/ArrowSymbols.js', [_modules['Core/Renderer/SVG/SVGRenderer.js']], function (SVGRenderer) {
  3188. /* *
  3189. *
  3190. * (c) 2017 Highsoft AS
  3191. * Authors: Lars A. V. Cabrera
  3192. *
  3193. * License: www.highcharts.com/license
  3194. *
  3195. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3196. *
  3197. * */
  3198. /**
  3199. * Creates an arrow symbol. Like a triangle, except not filled.
  3200. * ```
  3201. * o
  3202. * o
  3203. * o
  3204. * o
  3205. * o
  3206. * o
  3207. * o
  3208. * ```
  3209. *
  3210. * @private
  3211. * @function
  3212. *
  3213. * @param {number} x
  3214. * x position of the arrow
  3215. *
  3216. * @param {number} y
  3217. * y position of the arrow
  3218. *
  3219. * @param {number} w
  3220. * width of the arrow
  3221. *
  3222. * @param {number} h
  3223. * height of the arrow
  3224. *
  3225. * @return {Highcharts.SVGPathArray}
  3226. * Path array
  3227. */
  3228. SVGRenderer.prototype.symbols.arrow = function (x, y, w, h) {
  3229. return [
  3230. ['M', x, y + h / 2],
  3231. ['L', x + w, y],
  3232. ['L', x, y + h / 2],
  3233. ['L', x + w, y + h]
  3234. ];
  3235. };
  3236. /**
  3237. * Creates a half-width arrow symbol. Like a triangle, except not filled.
  3238. * ```
  3239. * o
  3240. * o
  3241. * o
  3242. * o
  3243. * o
  3244. * ```
  3245. *
  3246. * @private
  3247. * @function
  3248. *
  3249. * @param {number} x
  3250. * x position of the arrow
  3251. *
  3252. * @param {number} y
  3253. * y position of the arrow
  3254. *
  3255. * @param {number} w
  3256. * width of the arrow
  3257. *
  3258. * @param {number} h
  3259. * height of the arrow
  3260. *
  3261. * @return {Highcharts.SVGPathArray}
  3262. * Path array
  3263. */
  3264. SVGRenderer.prototype.symbols['arrow-half'] = function (x, y, w, h) {
  3265. return SVGRenderer.prototype.symbols.arrow(x, y, w / 2, h);
  3266. };
  3267. /**
  3268. * Creates a left-oriented triangle.
  3269. * ```
  3270. * o
  3271. * ooooooo
  3272. * ooooooooooooo
  3273. * ooooooo
  3274. * o
  3275. * ```
  3276. *
  3277. * @private
  3278. * @function
  3279. *
  3280. * @param {number} x
  3281. * x position of the triangle
  3282. *
  3283. * @param {number} y
  3284. * y position of the triangle
  3285. *
  3286. * @param {number} w
  3287. * width of the triangle
  3288. *
  3289. * @param {number} h
  3290. * height of the triangle
  3291. *
  3292. * @return {Highcharts.SVGPathArray}
  3293. * Path array
  3294. */
  3295. SVGRenderer.prototype.symbols['triangle-left'] = function (x, y, w, h) {
  3296. return [
  3297. ['M', x + w, y],
  3298. ['L', x, y + h / 2],
  3299. ['L', x + w, y + h],
  3300. ['Z']
  3301. ];
  3302. };
  3303. /**
  3304. * Alias function for triangle-left.
  3305. *
  3306. * @private
  3307. * @function
  3308. *
  3309. * @param {number} x
  3310. * x position of the arrow
  3311. *
  3312. * @param {number} y
  3313. * y position of the arrow
  3314. *
  3315. * @param {number} w
  3316. * width of the arrow
  3317. *
  3318. * @param {number} h
  3319. * height of the arrow
  3320. *
  3321. * @return {Highcharts.SVGPathArray}
  3322. * Path array
  3323. */
  3324. SVGRenderer.prototype.symbols['arrow-filled'] = SVGRenderer.prototype.symbols['triangle-left'];
  3325. /**
  3326. * Creates a half-width, left-oriented triangle.
  3327. * ```
  3328. * o
  3329. * oooo
  3330. * ooooooo
  3331. * oooo
  3332. * o
  3333. * ```
  3334. *
  3335. * @private
  3336. * @function
  3337. *
  3338. * @param {number} x
  3339. * x position of the triangle
  3340. *
  3341. * @param {number} y
  3342. * y position of the triangle
  3343. *
  3344. * @param {number} w
  3345. * width of the triangle
  3346. *
  3347. * @param {number} h
  3348. * height of the triangle
  3349. *
  3350. * @return {Highcharts.SVGPathArray}
  3351. * Path array
  3352. */
  3353. SVGRenderer.prototype.symbols['triangle-left-half'] = function (x, y, w, h) {
  3354. return SVGRenderer.prototype.symbols['triangle-left'](x, y, w / 2, h);
  3355. };
  3356. /**
  3357. * Alias function for triangle-left-half.
  3358. *
  3359. * @private
  3360. * @function
  3361. *
  3362. * @param {number} x
  3363. * x position of the arrow
  3364. *
  3365. * @param {number} y
  3366. * y position of the arrow
  3367. *
  3368. * @param {number} w
  3369. * width of the arrow
  3370. *
  3371. * @param {number} h
  3372. * height of the arrow
  3373. *
  3374. * @return {Highcharts.SVGPathArray}
  3375. * Path array
  3376. */
  3377. SVGRenderer.prototype.symbols['arrow-filled-half'] = SVGRenderer.prototype.symbols['triangle-left-half'];
  3378. });
  3379. _registerModule(_modules, 'Gantt/Connection.js', [_modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (H, O, Point, U) {
  3380. /* *
  3381. *
  3382. * (c) 2016 Highsoft AS
  3383. * Authors: Øystein Moseng, Lars A. V. Cabrera
  3384. *
  3385. * License: www.highcharts.com/license
  3386. *
  3387. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3388. *
  3389. * */
  3390. /**
  3391. * The default pathfinder algorithm to use for a chart. It is possible to define
  3392. * your own algorithms by adding them to the
  3393. * `Highcharts.Pathfinder.prototype.algorithms`
  3394. * object before the chart has been created.
  3395. *
  3396. * The default algorithms are as follows:
  3397. *
  3398. * `straight`: Draws a straight line between the connecting
  3399. * points. Does not avoid other points when drawing.
  3400. *
  3401. * `simpleConnect`: Finds a path between the points using right angles
  3402. * only. Takes only starting/ending points into
  3403. * account, and will not avoid other points.
  3404. *
  3405. * `fastAvoid`: Finds a path between the points using right angles
  3406. * only. Will attempt to avoid other points, but its
  3407. * focus is performance over accuracy. Works well with
  3408. * less dense datasets.
  3409. *
  3410. * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
  3411. */
  3412. ''; // detach doclets above
  3413. var defaultOptions = O.defaultOptions;
  3414. var addEvent = U.addEvent,
  3415. defined = U.defined,
  3416. error = U.error,
  3417. extend = U.extend,
  3418. merge = U.merge,
  3419. objectEach = U.objectEach,
  3420. pick = U.pick,
  3421. splat = U.splat;
  3422. var deg2rad = H.deg2rad,
  3423. max = Math.max,
  3424. min = Math.min;
  3425. /*
  3426. @todo:
  3427. - Document how to write your own algorithms
  3428. - Consider adding a Point.pathTo method that wraps creating a connection
  3429. and rendering it
  3430. */
  3431. // Set default Pathfinder options
  3432. extend(defaultOptions, {
  3433. /**
  3434. * The Pathfinder module allows you to define connections between any two
  3435. * points, represented as lines - optionally with markers for the start
  3436. * and/or end points. Multiple algorithms are available for calculating how
  3437. * the connecting lines are drawn.
  3438. *
  3439. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  3440. * charts, the connectors are used to draw dependencies between tasks.
  3441. *
  3442. * @see [dependency](series.gantt.data.dependency)
  3443. *
  3444. * @sample gantt/pathfinder/demo
  3445. * Pathfinder connections
  3446. *
  3447. * @declare Highcharts.ConnectorsOptions
  3448. * @product gantt
  3449. * @optionparent connectors
  3450. */
  3451. connectors: {
  3452. /**
  3453. * Enable connectors for this chart. Requires Highcharts Gantt.
  3454. *
  3455. * @type {boolean}
  3456. * @default true
  3457. * @since 6.2.0
  3458. * @apioption connectors.enabled
  3459. */
  3460. /**
  3461. * Set the default dash style for this chart's connecting lines.
  3462. *
  3463. * @type {string}
  3464. * @default solid
  3465. * @since 6.2.0
  3466. * @apioption connectors.dashStyle
  3467. */
  3468. /**
  3469. * Set the default color for this chart's Pathfinder connecting lines.
  3470. * Defaults to the color of the point being connected.
  3471. *
  3472. * @type {Highcharts.ColorString}
  3473. * @since 6.2.0
  3474. * @apioption connectors.lineColor
  3475. */
  3476. /**
  3477. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  3478. * algorithms attempt to avoid obstacles, such as other points in the
  3479. * chart. These algorithms use this margin to determine how close lines
  3480. * can be to an obstacle. The default is to compute this automatically
  3481. * from the size of the obstacles in the chart.
  3482. *
  3483. * To draw connecting lines close to existing points, set this to a low
  3484. * number. For more space around existing points, set this number
  3485. * higher.
  3486. *
  3487. * @sample gantt/pathfinder/algorithm-margin
  3488. * Small algorithmMargin
  3489. *
  3490. * @type {number}
  3491. * @since 6.2.0
  3492. * @apioption connectors.algorithmMargin
  3493. */
  3494. /**
  3495. * Set the default pathfinder algorithm to use for this chart. It is
  3496. * possible to define your own algorithms by adding them to the
  3497. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  3498. * has been created.
  3499. *
  3500. * The default algorithms are as follows:
  3501. *
  3502. * `straight`: Draws a straight line between the connecting
  3503. * points. Does not avoid other points when drawing.
  3504. *
  3505. * `simpleConnect`: Finds a path between the points using right angles
  3506. * only. Takes only starting/ending points into
  3507. * account, and will not avoid other points.
  3508. *
  3509. * `fastAvoid`: Finds a path between the points using right angles
  3510. * only. Will attempt to avoid other points, but its
  3511. * focus is performance over accuracy. Works well with
  3512. * less dense datasets.
  3513. *
  3514. * Default value: `straight` is used as default for most series types,
  3515. * while `simpleConnect` is used as default for Gantt series, to show
  3516. * dependencies between points.
  3517. *
  3518. * @sample gantt/pathfinder/demo
  3519. * Different types used
  3520. *
  3521. * @type {Highcharts.PathfinderTypeValue}
  3522. * @default undefined
  3523. * @since 6.2.0
  3524. */
  3525. type: 'straight',
  3526. /**
  3527. * Set the default pixel width for this chart's Pathfinder connecting
  3528. * lines.
  3529. *
  3530. * @since 6.2.0
  3531. */
  3532. lineWidth: 1,
  3533. /**
  3534. * Marker options for this chart's Pathfinder connectors. Note that
  3535. * this option is overridden by the `startMarker` and `endMarker`
  3536. * options.
  3537. *
  3538. * @declare Highcharts.ConnectorsMarkerOptions
  3539. * @since 6.2.0
  3540. */
  3541. marker: {
  3542. /**
  3543. * Set the radius of the connector markers. The default is
  3544. * automatically computed based on the algorithmMargin setting.
  3545. *
  3546. * Setting marker.width and marker.height will override this
  3547. * setting.
  3548. *
  3549. * @type {number}
  3550. * @since 6.2.0
  3551. * @apioption connectors.marker.radius
  3552. */
  3553. /**
  3554. * Set the width of the connector markers. If not supplied, this
  3555. * is inferred from the marker radius.
  3556. *
  3557. * @type {number}
  3558. * @since 6.2.0
  3559. * @apioption connectors.marker.width
  3560. */
  3561. /**
  3562. * Set the height of the connector markers. If not supplied, this
  3563. * is inferred from the marker radius.
  3564. *
  3565. * @type {number}
  3566. * @since 6.2.0
  3567. * @apioption connectors.marker.height
  3568. */
  3569. /**
  3570. * Set the color of the connector markers. By default this is the
  3571. * same as the connector color.
  3572. *
  3573. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3574. * @since 6.2.0
  3575. * @apioption connectors.marker.color
  3576. */
  3577. /**
  3578. * Set the line/border color of the connector markers. By default
  3579. * this is the same as the marker color.
  3580. *
  3581. * @type {Highcharts.ColorString}
  3582. * @since 6.2.0
  3583. * @apioption connectors.marker.lineColor
  3584. */
  3585. /**
  3586. * Enable markers for the connectors.
  3587. */
  3588. enabled: false,
  3589. /**
  3590. * Horizontal alignment of the markers relative to the points.
  3591. *
  3592. * @type {Highcharts.AlignValue}
  3593. */
  3594. align: 'center',
  3595. /**
  3596. * Vertical alignment of the markers relative to the points.
  3597. *
  3598. * @type {Highcharts.VerticalAlignValue}
  3599. */
  3600. verticalAlign: 'middle',
  3601. /**
  3602. * Whether or not to draw the markers inside the points.
  3603. */
  3604. inside: false,
  3605. /**
  3606. * Set the line/border width of the pathfinder markers.
  3607. */
  3608. lineWidth: 1
  3609. },
  3610. /**
  3611. * Marker options specific to the start markers for this chart's
  3612. * Pathfinder connectors. Overrides the generic marker options.
  3613. *
  3614. * @declare Highcharts.ConnectorsStartMarkerOptions
  3615. * @extends connectors.marker
  3616. * @since 6.2.0
  3617. */
  3618. startMarker: {
  3619. /**
  3620. * Set the symbol of the connector start markers.
  3621. */
  3622. symbol: 'diamond'
  3623. },
  3624. /**
  3625. * Marker options specific to the end markers for this chart's
  3626. * Pathfinder connectors. Overrides the generic marker options.
  3627. *
  3628. * @declare Highcharts.ConnectorsEndMarkerOptions
  3629. * @extends connectors.marker
  3630. * @since 6.2.0
  3631. */
  3632. endMarker: {
  3633. /**
  3634. * Set the symbol of the connector end markers.
  3635. */
  3636. symbol: 'arrow-filled'
  3637. }
  3638. }
  3639. });
  3640. /**
  3641. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  3642. * to be loaded.
  3643. *
  3644. * @declare Highcharts.SeriesConnectorsOptionsObject
  3645. * @extends connectors
  3646. * @since 6.2.0
  3647. * @excluding enabled, algorithmMargin
  3648. * @product gantt
  3649. * @apioption plotOptions.series.connectors
  3650. */
  3651. /**
  3652. * Connect to a point. This option can be either a string, referring to the ID
  3653. * of another point, or an object, or an array of either. If the option is an
  3654. * array, each element defines a connection.
  3655. *
  3656. * @sample gantt/pathfinder/demo
  3657. * Different connection types
  3658. *
  3659. * @declare Highcharts.XrangePointConnectorsOptionsObject
  3660. * @type {string|Array<string|*>|*}
  3661. * @extends plotOptions.series.connectors
  3662. * @since 6.2.0
  3663. * @excluding enabled
  3664. * @product gantt
  3665. * @requires highcharts-gantt
  3666. * @apioption series.xrange.data.connect
  3667. */
  3668. /**
  3669. * The ID of the point to connect to.
  3670. *
  3671. * @type {string}
  3672. * @since 6.2.0
  3673. * @product gantt
  3674. * @apioption series.xrange.data.connect.to
  3675. */
  3676. /**
  3677. * Get point bounding box using plotX/plotY and shapeArgs. If using
  3678. * graphic.getBBox() directly, the bbox will be affected by animation.
  3679. *
  3680. * @private
  3681. * @function
  3682. *
  3683. * @param {Highcharts.Point} point
  3684. * The point to get BB of.
  3685. *
  3686. * @return {Highcharts.Dictionary<number>|null}
  3687. * Result xMax, xMin, yMax, yMin.
  3688. */
  3689. function getPointBB(point) {
  3690. var shapeArgs = point.shapeArgs,
  3691. bb;
  3692. // Prefer using shapeArgs (columns)
  3693. if (shapeArgs) {
  3694. return {
  3695. xMin: shapeArgs.x,
  3696. xMax: shapeArgs.x + shapeArgs.width,
  3697. yMin: shapeArgs.y,
  3698. yMax: shapeArgs.y + shapeArgs.height
  3699. };
  3700. }
  3701. // Otherwise use plotX/plotY and bb
  3702. bb = point.graphic && point.graphic.getBBox();
  3703. return bb ? {
  3704. xMin: point.plotX - bb.width / 2,
  3705. xMax: point.plotX + bb.width / 2,
  3706. yMin: point.plotY - bb.height / 2,
  3707. yMax: point.plotY + bb.height / 2
  3708. } : null;
  3709. }
  3710. /**
  3711. * Calculate margin to place around obstacles for the pathfinder in pixels.
  3712. * Returns a minimum of 1 pixel margin.
  3713. *
  3714. * @private
  3715. * @function
  3716. *
  3717. * @param {Array<object>} obstacles
  3718. * Obstacles to calculate margin from.
  3719. *
  3720. * @return {number}
  3721. * The calculated margin in pixels. At least 1.
  3722. */
  3723. function calculateObstacleMargin(obstacles) {
  3724. var len = obstacles.length,
  3725. i = 0,
  3726. j,
  3727. obstacleDistance,
  3728. distances = [],
  3729. // Compute smallest distance between two rectangles
  3730. distance = function (a,
  3731. b,
  3732. bbMargin) {
  3733. // Count the distance even if we are slightly off
  3734. var margin = pick(bbMargin, 10),
  3735. yOverlap = a.yMax + margin > b.yMin - margin &&
  3736. a.yMin - margin < b.yMax + margin,
  3737. xOverlap = a.xMax + margin > b.xMin - margin &&
  3738. a.xMin - margin < b.xMax + margin,
  3739. xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
  3740. yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
  3741. // If the rectangles collide, try recomputing with smaller margin.
  3742. // If they collide anyway, discard the obstacle.
  3743. if (xOverlap && yOverlap) {
  3744. return (margin ?
  3745. distance(a, b, Math.floor(margin / 2)) :
  3746. Infinity);
  3747. }
  3748. return min(xDistance, yDistance);
  3749. };
  3750. // Go over all obstacles and compare them to the others.
  3751. for (; i < len; ++i) {
  3752. // Compare to all obstacles ahead. We will already have compared this
  3753. // obstacle to the ones before.
  3754. for (j = i + 1; j < len; ++j) {
  3755. obstacleDistance = distance(obstacles[i], obstacles[j]);
  3756. // TODO: Magic number 80
  3757. if (obstacleDistance < 80) { // Ignore large distances
  3758. distances.push(obstacleDistance);
  3759. }
  3760. }
  3761. }
  3762. // Ensure we always have at least one value, even in very spaceous charts
  3763. distances.push(80);
  3764. return max(Math.floor(distances.sort(function (a, b) {
  3765. return (a - b);
  3766. })[
  3767. // Discard first 10% of the relevant distances, and then grab
  3768. // the smallest one.
  3769. Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
  3770. ), 1 // 1 is the minimum margin
  3771. );
  3772. }
  3773. /* eslint-disable no-invalid-this, valid-jsdoc */
  3774. /**
  3775. * The Connection class. Used internally to represent a connection between two
  3776. * points.
  3777. *
  3778. * @private
  3779. * @class
  3780. * @name Highcharts.Connection
  3781. *
  3782. * @param {Highcharts.Point} from
  3783. * Connection runs from this Point.
  3784. *
  3785. * @param {Highcharts.Point} to
  3786. * Connection runs to this Point.
  3787. *
  3788. * @param {Highcharts.ConnectorsOptions} [options]
  3789. * Connection options.
  3790. */
  3791. var Connection = /** @class */ (function () {
  3792. function Connection(from, to, options) {
  3793. /* *
  3794. *
  3795. * Properties
  3796. *
  3797. * */
  3798. this.chart = void 0;
  3799. this.fromPoint = void 0;
  3800. this.graphics = void 0;
  3801. this.pathfinder = void 0;
  3802. this.toPoint = void 0;
  3803. this.init(from, to, options);
  3804. }
  3805. /**
  3806. * Initialize the Connection object. Used as constructor only.
  3807. *
  3808. * @function Highcharts.Connection#init
  3809. *
  3810. * @param {Highcharts.Point} from
  3811. * Connection runs from this Point.
  3812. *
  3813. * @param {Highcharts.Point} to
  3814. * Connection runs to this Point.
  3815. *
  3816. * @param {Highcharts.ConnectorsOptions} [options]
  3817. * Connection options.
  3818. */
  3819. Connection.prototype.init = function (from, to, options) {
  3820. this.fromPoint = from;
  3821. this.toPoint = to;
  3822. this.options = options;
  3823. this.chart = from.series.chart;
  3824. this.pathfinder = this.chart.pathfinder;
  3825. };
  3826. /**
  3827. * Add (or update) this connection's path on chart. Stores reference to the
  3828. * created element on this.graphics.path.
  3829. *
  3830. * @function Highcharts.Connection#renderPath
  3831. *
  3832. * @param {Highcharts.SVGPathArray} path
  3833. * Path to render, in array format. E.g. ['M', 0, 0, 'L', 10, 10]
  3834. *
  3835. * @param {Highcharts.SVGAttributes} [attribs]
  3836. * SVG attributes for the path.
  3837. *
  3838. * @param {Partial<Highcharts.AnimationOptionsObject>} [animation]
  3839. * Animation options for the rendering.
  3840. */
  3841. Connection.prototype.renderPath = function (path, attribs, animation) {
  3842. var connection = this,
  3843. chart = this.chart,
  3844. styledMode = chart.styledMode,
  3845. pathfinder = chart.pathfinder,
  3846. animate = !chart.options.chart.forExport && animation !== false,
  3847. pathGraphic = connection.graphics && connection.graphics.path,
  3848. anim;
  3849. // Add the SVG element of the pathfinder group if it doesn't exist
  3850. if (!pathfinder.group) {
  3851. pathfinder.group = chart.renderer.g()
  3852. .addClass('highcharts-pathfinder-group')
  3853. .attr({ zIndex: -1 })
  3854. .add(chart.seriesGroup);
  3855. }
  3856. // Shift the group to compensate for plot area.
  3857. // Note: Do this always (even when redrawing a path) to avoid issues
  3858. // when updating chart in a way that changes plot metrics.
  3859. pathfinder.group.translate(chart.plotLeft, chart.plotTop);
  3860. // Create path if does not exist
  3861. if (!(pathGraphic && pathGraphic.renderer)) {
  3862. pathGraphic = chart.renderer.path()
  3863. .add(pathfinder.group);
  3864. if (!styledMode) {
  3865. pathGraphic.attr({
  3866. opacity: 0
  3867. });
  3868. }
  3869. }
  3870. // Set path attribs and animate to the new path
  3871. pathGraphic.attr(attribs);
  3872. anim = { d: path };
  3873. if (!styledMode) {
  3874. anim.opacity = 1;
  3875. }
  3876. pathGraphic[animate ? 'animate' : 'attr'](anim, animation);
  3877. // Store reference on connection
  3878. this.graphics = this.graphics || {};
  3879. this.graphics.path = pathGraphic;
  3880. };
  3881. /**
  3882. * Calculate and add marker graphics for connection to the chart. The
  3883. * created/updated elements are stored on this.graphics.start and
  3884. * this.graphics.end.
  3885. *
  3886. * @function Highcharts.Connection#addMarker
  3887. *
  3888. * @param {string} type
  3889. * Marker type, either 'start' or 'end'.
  3890. *
  3891. * @param {Highcharts.ConnectorsMarkerOptions} options
  3892. * All options for this marker. Not calculated or merged with other
  3893. * options.
  3894. *
  3895. * @param {Highcharts.SVGPathArray} path
  3896. * Connection path in array format. This is used to calculate the
  3897. * rotation angle of the markers.
  3898. */
  3899. Connection.prototype.addMarker = function (type, options, path) {
  3900. var connection = this,
  3901. chart = connection.fromPoint.series.chart,
  3902. pathfinder = chart.pathfinder,
  3903. renderer = chart.renderer,
  3904. point = (type === 'start' ?
  3905. connection.fromPoint :
  3906. connection.toPoint),
  3907. anchor = point.getPathfinderAnchorPoint(options),
  3908. markerVector,
  3909. radians,
  3910. rotation,
  3911. box,
  3912. width,
  3913. height,
  3914. pathVector,
  3915. segment;
  3916. if (!options.enabled) {
  3917. return;
  3918. }
  3919. // Last vector before start/end of path, used to get angle
  3920. if (type === 'start') {
  3921. segment = path[1];
  3922. }
  3923. else { // 'end'
  3924. segment = path[path.length - 2];
  3925. }
  3926. if (segment && segment[0] === 'M' || segment[0] === 'L') {
  3927. pathVector = {
  3928. x: segment[1],
  3929. y: segment[2]
  3930. };
  3931. // Get angle between pathVector and anchor point and use it to
  3932. // create marker position.
  3933. radians = point.getRadiansToVector(pathVector, anchor);
  3934. markerVector = point.getMarkerVector(radians, options.radius, anchor);
  3935. // Rotation of marker is calculated from angle between pathVector
  3936. // and markerVector.
  3937. // (Note:
  3938. // Used to recalculate radians between markerVector and pathVector,
  3939. // but this should be the same as between pathVector and anchor.)
  3940. rotation = -radians / deg2rad;
  3941. if (options.width && options.height) {
  3942. width = options.width;
  3943. height = options.height;
  3944. }
  3945. else {
  3946. width = height = options.radius * 2;
  3947. }
  3948. // Add graphics object if it does not exist
  3949. connection.graphics = connection.graphics || {};
  3950. box = {
  3951. x: markerVector.x - (width / 2),
  3952. y: markerVector.y - (height / 2),
  3953. width: width,
  3954. height: height,
  3955. rotation: rotation,
  3956. rotationOriginX: markerVector.x,
  3957. rotationOriginY: markerVector.y
  3958. };
  3959. if (!connection.graphics[type]) {
  3960. // Create new marker element
  3961. connection.graphics[type] = renderer
  3962. .symbol(options.symbol)
  3963. .addClass('highcharts-point-connecting-path-' + type + '-marker')
  3964. .attr(box)
  3965. .add(pathfinder.group);
  3966. if (!renderer.styledMode) {
  3967. connection.graphics[type].attr({
  3968. fill: options.color || connection.fromPoint.color,
  3969. stroke: options.lineColor,
  3970. 'stroke-width': options.lineWidth,
  3971. opacity: 0
  3972. })
  3973. .animate({
  3974. opacity: 1
  3975. }, point.series.options.animation);
  3976. }
  3977. }
  3978. else {
  3979. connection.graphics[type].animate(box);
  3980. }
  3981. }
  3982. };
  3983. /**
  3984. * Calculate and return connection path.
  3985. * Note: Recalculates chart obstacles on demand if they aren't calculated.
  3986. *
  3987. * @function Highcharts.Connection#getPath
  3988. *
  3989. * @param {Highcharts.ConnectorsOptions} options
  3990. * Connector options. Not calculated or merged with other options.
  3991. *
  3992. * @return {object|undefined}
  3993. * Calculated SVG path data in array format.
  3994. */
  3995. Connection.prototype.getPath = function (options) {
  3996. var pathfinder = this.pathfinder,
  3997. chart = this.chart,
  3998. algorithm = pathfinder.algorithms[options.type],
  3999. chartObstacles = pathfinder.chartObstacles;
  4000. if (typeof algorithm !== 'function') {
  4001. error('"' + options.type + '" is not a Pathfinder algorithm.');
  4002. return {
  4003. path: [],
  4004. obstacles: []
  4005. };
  4006. }
  4007. // This function calculates obstacles on demand if they don't exist
  4008. if (algorithm.requiresObstacles && !chartObstacles) {
  4009. chartObstacles =
  4010. pathfinder.chartObstacles =
  4011. pathfinder.getChartObstacles(options);
  4012. // If the algorithmMargin was computed, store the result in default
  4013. // options.
  4014. chart.options.connectors.algorithmMargin =
  4015. options.algorithmMargin;
  4016. // Cache some metrics too
  4017. pathfinder.chartObstacleMetrics =
  4018. pathfinder.getObstacleMetrics(chartObstacles);
  4019. }
  4020. // Get the SVG path
  4021. return algorithm(
  4022. // From
  4023. this.fromPoint.getPathfinderAnchorPoint(options.startMarker),
  4024. // To
  4025. this.toPoint.getPathfinderAnchorPoint(options.endMarker), merge({
  4026. chartObstacles: chartObstacles,
  4027. lineObstacles: pathfinder.lineObstacles || [],
  4028. obstacleMetrics: pathfinder.chartObstacleMetrics,
  4029. hardBounds: {
  4030. xMin: 0,
  4031. xMax: chart.plotWidth,
  4032. yMin: 0,
  4033. yMax: chart.plotHeight
  4034. },
  4035. obstacleOptions: {
  4036. margin: options.algorithmMargin
  4037. },
  4038. startDirectionX: pathfinder.getAlgorithmStartDirection(options.startMarker)
  4039. }, options));
  4040. };
  4041. /**
  4042. * (re)Calculate and (re)draw the connection.
  4043. *
  4044. * @function Highcharts.Connection#render
  4045. */
  4046. Connection.prototype.render = function () {
  4047. var connection = this,
  4048. fromPoint = connection.fromPoint,
  4049. series = fromPoint.series,
  4050. chart = series.chart,
  4051. pathfinder = chart.pathfinder,
  4052. pathResult,
  4053. path,
  4054. options = merge(chart.options.connectors,
  4055. series.options.connectors,
  4056. fromPoint.options.connectors,
  4057. connection.options),
  4058. attribs = {};
  4059. // Set path attribs
  4060. if (!chart.styledMode) {
  4061. attribs.stroke = options.lineColor || fromPoint.color;
  4062. attribs['stroke-width'] = options.lineWidth;
  4063. if (options.dashStyle) {
  4064. attribs.dashstyle = options.dashStyle;
  4065. }
  4066. }
  4067. attribs['class'] = // eslint-disable-line dot-notation
  4068. 'highcharts-point-connecting-path ' +
  4069. 'highcharts-color-' + fromPoint.colorIndex;
  4070. options = merge(attribs, options);
  4071. // Set common marker options
  4072. if (!defined(options.marker.radius)) {
  4073. options.marker.radius = min(max(Math.ceil((options.algorithmMargin || 8) / 2) - 1, 1), 5);
  4074. }
  4075. // Get the path
  4076. pathResult = connection.getPath(options);
  4077. path = pathResult.path;
  4078. // Always update obstacle storage with obstacles from this path.
  4079. // We don't know if future calls will need this for their algorithm.
  4080. if (pathResult.obstacles) {
  4081. pathfinder.lineObstacles =
  4082. pathfinder.lineObstacles || [];
  4083. pathfinder.lineObstacles =
  4084. pathfinder.lineObstacles.concat(pathResult.obstacles);
  4085. }
  4086. // Add the calculated path to the pathfinder group
  4087. connection.renderPath(path, attribs, series.options.animation);
  4088. // Render the markers
  4089. connection.addMarker('start', merge(options.marker, options.startMarker), path);
  4090. connection.addMarker('end', merge(options.marker, options.endMarker), path);
  4091. };
  4092. /**
  4093. * Destroy connection by destroying the added graphics elements.
  4094. *
  4095. * @function Highcharts.Connection#destroy
  4096. */
  4097. Connection.prototype.destroy = function () {
  4098. if (this.graphics) {
  4099. objectEach(this.graphics, function (val) {
  4100. val.destroy();
  4101. });
  4102. delete this.graphics;
  4103. }
  4104. };
  4105. return Connection;
  4106. }());
  4107. // Add to Highcharts namespace
  4108. H.Connection = Connection;
  4109. // Add pathfinding capabilities to Points
  4110. extend(Point.prototype, /** @lends Point.prototype */ {
  4111. /**
  4112. * Get coordinates of anchor point for pathfinder connection.
  4113. *
  4114. * @private
  4115. * @function Highcharts.Point#getPathfinderAnchorPoint
  4116. *
  4117. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  4118. * Connection options for position on point.
  4119. *
  4120. * @return {Highcharts.PositionObject}
  4121. * An object with x/y properties for the position. Coordinates are
  4122. * in plot values, not relative to point.
  4123. */
  4124. getPathfinderAnchorPoint: function (markerOptions) {
  4125. var bb = getPointBB(this),
  4126. x,
  4127. y;
  4128. switch (markerOptions.align) { // eslint-disable-line default-case
  4129. case 'right':
  4130. x = 'xMax';
  4131. break;
  4132. case 'left':
  4133. x = 'xMin';
  4134. }
  4135. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  4136. case 'top':
  4137. y = 'yMin';
  4138. break;
  4139. case 'bottom':
  4140. y = 'yMax';
  4141. }
  4142. return {
  4143. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  4144. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  4145. };
  4146. },
  4147. /**
  4148. * Utility to get the angle from one point to another.
  4149. *
  4150. * @private
  4151. * @function Highcharts.Point#getRadiansToVector
  4152. *
  4153. * @param {Highcharts.PositionObject} v1
  4154. * The first vector, as an object with x/y properties.
  4155. *
  4156. * @param {Highcharts.PositionObject} v2
  4157. * The second vector, as an object with x/y properties.
  4158. *
  4159. * @return {number}
  4160. * The angle in degrees
  4161. */
  4162. getRadiansToVector: function (v1, v2) {
  4163. var box;
  4164. if (!defined(v2)) {
  4165. box = getPointBB(this);
  4166. if (box) {
  4167. v2 = {
  4168. x: (box.xMin + box.xMax) / 2,
  4169. y: (box.yMin + box.yMax) / 2
  4170. };
  4171. }
  4172. }
  4173. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  4174. },
  4175. /**
  4176. * Utility to get the position of the marker, based on the path angle and
  4177. * the marker's radius.
  4178. *
  4179. * @private
  4180. * @function Highcharts.Point#getMarkerVector
  4181. *
  4182. * @param {number} radians
  4183. * The angle in radians from the point center to another vector.
  4184. *
  4185. * @param {number} markerRadius
  4186. * The radius of the marker, to calculate the additional distance to
  4187. * the center of the marker.
  4188. *
  4189. * @param {object} anchor
  4190. * The anchor point of the path and marker as an object with x/y
  4191. * properties.
  4192. *
  4193. * @return {object}
  4194. * The marker vector as an object with x/y properties.
  4195. */
  4196. getMarkerVector: function (radians, markerRadius, anchor) {
  4197. var twoPI = Math.PI * 2.0,
  4198. theta = radians,
  4199. bb = getPointBB(this),
  4200. rectWidth = bb.xMax - bb.xMin,
  4201. rectHeight = bb.yMax - bb.yMin,
  4202. rAtan = Math.atan2(rectHeight,
  4203. rectWidth),
  4204. tanTheta = 1,
  4205. leftOrRightRegion = false,
  4206. rectHalfWidth = rectWidth / 2.0,
  4207. rectHalfHeight = rectHeight / 2.0,
  4208. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  4209. rectVerticalCenter = bb.yMin + rectHalfHeight,
  4210. edgePoint = {
  4211. x: rectHorizontalCenter,
  4212. y: rectVerticalCenter
  4213. },
  4214. markerPoint = {},
  4215. xFactor = 1,
  4216. yFactor = 1;
  4217. while (theta < -Math.PI) {
  4218. theta += twoPI;
  4219. }
  4220. while (theta > Math.PI) {
  4221. theta -= twoPI;
  4222. }
  4223. tanTheta = Math.tan(theta);
  4224. if ((theta > -rAtan) && (theta <= rAtan)) {
  4225. // Right side
  4226. yFactor = -1;
  4227. leftOrRightRegion = true;
  4228. }
  4229. else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  4230. // Top side
  4231. yFactor = -1;
  4232. }
  4233. else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  4234. // Left side
  4235. xFactor = -1;
  4236. leftOrRightRegion = true;
  4237. }
  4238. else {
  4239. // Bottom side
  4240. xFactor = -1;
  4241. }
  4242. // Correct the edgePoint according to the placement of the marker
  4243. if (leftOrRightRegion) {
  4244. edgePoint.x += xFactor * (rectHalfWidth);
  4245. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  4246. }
  4247. else {
  4248. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  4249. edgePoint.y += yFactor * (rectHalfHeight);
  4250. }
  4251. if (anchor.x !== rectHorizontalCenter) {
  4252. edgePoint.x = anchor.x;
  4253. }
  4254. if (anchor.y !== rectVerticalCenter) {
  4255. edgePoint.y = anchor.y;
  4256. }
  4257. markerPoint.x = edgePoint.x + (markerRadius * Math.cos(theta));
  4258. markerPoint.y = edgePoint.y - (markerRadius * Math.sin(theta));
  4259. return markerPoint;
  4260. }
  4261. });
  4262. /**
  4263. * Warn if using legacy options. Copy the options over. Note that this will
  4264. * still break if using the legacy options in chart.update, addSeries etc.
  4265. * @private
  4266. */
  4267. function warnLegacy(chart) {
  4268. if (chart.options.pathfinder ||
  4269. chart.series.reduce(function (acc, series) {
  4270. if (series.options) {
  4271. merge(true, (series.options.connectors = series.options.connectors ||
  4272. {}), series.options.pathfinder);
  4273. }
  4274. return acc || series.options && series.options.pathfinder;
  4275. }, false)) {
  4276. merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
  4277. error('WARNING: Pathfinder options have been renamed. ' +
  4278. 'Use "chart.connectors" or "series.connectors" instead.');
  4279. }
  4280. }
  4281. return Connection;
  4282. });
  4283. _registerModule(_modules, 'Gantt/PathfinderAlgorithms.js', [_modules['Core/Utilities.js']], function (U) {
  4284. /* *
  4285. *
  4286. * (c) 2016 Highsoft AS
  4287. * Author: Øystein Moseng
  4288. *
  4289. * License: www.highcharts.com/license
  4290. *
  4291. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4292. *
  4293. * */
  4294. var extend = U.extend,
  4295. pick = U.pick;
  4296. var min = Math.min,
  4297. max = Math.max,
  4298. abs = Math.abs;
  4299. /**
  4300. * Get index of last obstacle before xMin. Employs a type of binary search, and
  4301. * thus requires that obstacles are sorted by xMin value.
  4302. *
  4303. * @private
  4304. * @function findLastObstacleBefore
  4305. *
  4306. * @param {Array<object>} obstacles
  4307. * Array of obstacles to search in.
  4308. *
  4309. * @param {number} xMin
  4310. * The xMin threshold.
  4311. *
  4312. * @param {number} [startIx]
  4313. * Starting index to search from. Must be within array range.
  4314. *
  4315. * @return {number}
  4316. * The index of the last obstacle element before xMin.
  4317. */
  4318. function findLastObstacleBefore(obstacles, xMin, startIx) {
  4319. var left = startIx || 0, // left limit
  4320. right = obstacles.length - 1, // right limit
  4321. min = xMin - 0.0000001, // Make sure we include all obstacles at xMin
  4322. cursor,
  4323. cmp;
  4324. while (left <= right) {
  4325. cursor = (right + left) >> 1;
  4326. cmp = min - obstacles[cursor].xMin;
  4327. if (cmp > 0) {
  4328. left = cursor + 1;
  4329. }
  4330. else if (cmp < 0) {
  4331. right = cursor - 1;
  4332. }
  4333. else {
  4334. return cursor;
  4335. }
  4336. }
  4337. return left > 0 ? left - 1 : 0;
  4338. }
  4339. /**
  4340. * Test if a point lays within an obstacle.
  4341. *
  4342. * @private
  4343. * @function pointWithinObstacle
  4344. *
  4345. * @param {object} obstacle
  4346. * Obstacle to test.
  4347. *
  4348. * @param {Highcharts.Point} point
  4349. * Point with x/y props.
  4350. *
  4351. * @return {boolean}
  4352. * Whether point is within the obstacle or not.
  4353. */
  4354. function pointWithinObstacle(obstacle, point) {
  4355. return (point.x <= obstacle.xMax &&
  4356. point.x >= obstacle.xMin &&
  4357. point.y <= obstacle.yMax &&
  4358. point.y >= obstacle.yMin);
  4359. }
  4360. /**
  4361. * Find the index of an obstacle that wraps around a point.
  4362. * Returns -1 if not found.
  4363. *
  4364. * @private
  4365. * @function findObstacleFromPoint
  4366. *
  4367. * @param {Array<object>} obstacles
  4368. * Obstacles to test.
  4369. *
  4370. * @param {Highcharts.Point} point
  4371. * Point with x/y props.
  4372. *
  4373. * @return {number}
  4374. * Ix of the obstacle in the array, or -1 if not found.
  4375. */
  4376. function findObstacleFromPoint(obstacles, point) {
  4377. var i = findLastObstacleBefore(obstacles,
  4378. point.x + 1) + 1;
  4379. while (i--) {
  4380. if (obstacles[i].xMax >= point.x &&
  4381. // optimization using lazy evaluation
  4382. pointWithinObstacle(obstacles[i], point)) {
  4383. return i;
  4384. }
  4385. }
  4386. return -1;
  4387. }
  4388. /**
  4389. * Get SVG path array from array of line segments.
  4390. *
  4391. * @private
  4392. * @function pathFromSegments
  4393. *
  4394. * @param {Array<object>} segments
  4395. * The segments to build the path from.
  4396. *
  4397. * @return {Highcharts.SVGPathArray}
  4398. * SVG path array as accepted by the SVG Renderer.
  4399. */
  4400. function pathFromSegments(segments) {
  4401. var path = [];
  4402. if (segments.length) {
  4403. path.push(['M', segments[0].start.x, segments[0].start.y]);
  4404. for (var i = 0; i < segments.length; ++i) {
  4405. path.push(['L', segments[i].end.x, segments[i].end.y]);
  4406. }
  4407. }
  4408. return path;
  4409. }
  4410. /**
  4411. * Limits obstacle max/mins in all directions to bounds. Modifies input
  4412. * obstacle.
  4413. *
  4414. * @private
  4415. * @function limitObstacleToBounds
  4416. *
  4417. * @param {object} obstacle
  4418. * Obstacle to limit.
  4419. *
  4420. * @param {object} bounds
  4421. * Bounds to use as limit.
  4422. *
  4423. * @return {void}
  4424. */
  4425. function limitObstacleToBounds(obstacle, bounds) {
  4426. obstacle.yMin = max(obstacle.yMin, bounds.yMin);
  4427. obstacle.yMax = min(obstacle.yMax, bounds.yMax);
  4428. obstacle.xMin = max(obstacle.xMin, bounds.xMin);
  4429. obstacle.xMax = min(obstacle.xMax, bounds.xMax);
  4430. }
  4431. /**
  4432. * Get an SVG path from a starting coordinate to an ending coordinate.
  4433. * Draws a straight line.
  4434. *
  4435. * @function Highcharts.Pathfinder.algorithms.straight
  4436. *
  4437. * @param {Highcharts.PositionObject} start
  4438. * Starting coordinate, object with x/y props.
  4439. *
  4440. * @param {Highcharts.PositionObject} end
  4441. * Ending coordinate, object with x/y props.
  4442. *
  4443. * @return {object}
  4444. * An object with the SVG path in Array form as accepted by the SVG
  4445. * renderer, as well as an array of new obstacles making up this
  4446. * path.
  4447. */
  4448. function straight(start, end) {
  4449. return {
  4450. path: [
  4451. ['M', start.x, start.y],
  4452. ['L', end.x, end.y]
  4453. ],
  4454. obstacles: [{ start: start, end: end }]
  4455. };
  4456. }
  4457. /**
  4458. * Find a path from a starting coordinate to an ending coordinate, using
  4459. * right angles only, and taking only starting/ending obstacle into
  4460. * consideration.
  4461. *
  4462. * @function Highcharts.Pathfinder.algorithms.simpleConnect
  4463. *
  4464. * @param {Highcharts.PositionObject} start
  4465. * Starting coordinate, object with x/y props.
  4466. *
  4467. * @param {Highcharts.PositionObject} end
  4468. * Ending coordinate, object with x/y props.
  4469. *
  4470. * @param {object} options
  4471. * Options for the algorithm:
  4472. * - chartObstacles: Array of chart obstacles to avoid
  4473. * - startDirectionX: Optional. True if starting in the X direction.
  4474. * If not provided, the algorithm starts in the direction that is
  4475. * the furthest between start/end.
  4476. *
  4477. * @return {object}
  4478. * An object with the SVG path in Array form as accepted by the SVG
  4479. * renderer, as well as an array of new obstacles making up this
  4480. * path.
  4481. */
  4482. var simpleConnect = extend(function (start,
  4483. end,
  4484. options) {
  4485. var segments = [],
  4486. endSegment,
  4487. dir = pick(options.startDirectionX,
  4488. abs(end.x - start.x) > abs(end.y - start.y)) ? 'x' : 'y',
  4489. chartObstacles = options.chartObstacles,
  4490. startObstacleIx = findObstacleFromPoint(chartObstacles,
  4491. start),
  4492. endObstacleIx = findObstacleFromPoint(chartObstacles,
  4493. end),
  4494. startObstacle,
  4495. endObstacle,
  4496. prevWaypoint,
  4497. waypoint,
  4498. waypoint2,
  4499. useMax,
  4500. endPoint;
  4501. // eslint-disable-next-line valid-jsdoc
  4502. /**
  4503. * Return a clone of a point with a property set from a target object,
  4504. * optionally with an offset
  4505. * @private
  4506. */
  4507. function copyFromPoint(from, fromKey, to, toKey, offset) {
  4508. var point = {
  4509. x: from.x,
  4510. y: from.y
  4511. };
  4512. point[fromKey] = to[toKey || fromKey] + (offset || 0);
  4513. return point;
  4514. }
  4515. // eslint-disable-next-line valid-jsdoc
  4516. /**
  4517. * Return waypoint outside obstacle.
  4518. * @private
  4519. */
  4520. function getMeOut(obstacle, point, direction) {
  4521. var useMax = abs(point[direction] - obstacle[direction + 'Min']) >
  4522. abs(point[direction] - obstacle[direction + 'Max']);
  4523. return copyFromPoint(point, direction, obstacle, direction + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1);
  4524. }
  4525. // Pull out end point
  4526. if (endObstacleIx > -1) {
  4527. endObstacle = chartObstacles[endObstacleIx];
  4528. waypoint = getMeOut(endObstacle, end, dir);
  4529. endSegment = {
  4530. start: waypoint,
  4531. end: end
  4532. };
  4533. endPoint = waypoint;
  4534. }
  4535. else {
  4536. endPoint = end;
  4537. }
  4538. // If an obstacle envelops the start point, add a segment to get out,
  4539. // and around it.
  4540. if (startObstacleIx > -1) {
  4541. startObstacle = chartObstacles[startObstacleIx];
  4542. waypoint = getMeOut(startObstacle, start, dir);
  4543. segments.push({
  4544. start: start,
  4545. end: waypoint
  4546. });
  4547. // If we are going back again, switch direction to get around start
  4548. // obstacle.
  4549. if (
  4550. // Going towards max from start:
  4551. waypoint[dir] >= start[dir] ===
  4552. // Going towards min to end:
  4553. waypoint[dir] >= endPoint[dir]) {
  4554. dir = dir === 'y' ? 'x' : 'y';
  4555. useMax = start[dir] < end[dir];
  4556. segments.push({
  4557. start: waypoint,
  4558. end: copyFromPoint(waypoint, dir, startObstacle, dir + (useMax ? 'Max' : 'Min'), useMax ? 1 : -1)
  4559. });
  4560. // Switch direction again
  4561. dir = dir === 'y' ? 'x' : 'y';
  4562. }
  4563. }
  4564. // We are around the start obstacle. Go towards the end in one
  4565. // direction.
  4566. prevWaypoint = segments.length ?
  4567. segments[segments.length - 1].end :
  4568. start;
  4569. waypoint = copyFromPoint(prevWaypoint, dir, endPoint);
  4570. segments.push({
  4571. start: prevWaypoint,
  4572. end: waypoint
  4573. });
  4574. // Final run to end point in the other direction
  4575. dir = dir === 'y' ? 'x' : 'y';
  4576. waypoint2 = copyFromPoint(waypoint, dir, endPoint);
  4577. segments.push({
  4578. start: waypoint,
  4579. end: waypoint2
  4580. });
  4581. // Finally add the endSegment
  4582. segments.push(endSegment);
  4583. return {
  4584. path: pathFromSegments(segments),
  4585. obstacles: segments
  4586. };
  4587. }, {
  4588. requiresObstacles: true
  4589. });
  4590. /**
  4591. * Find a path from a starting coordinate to an ending coordinate, taking
  4592. * obstacles into consideration. Might not always find the optimal path,
  4593. * but is fast, and usually good enough.
  4594. *
  4595. * @function Highcharts.Pathfinder.algorithms.fastAvoid
  4596. *
  4597. * @param {Highcharts.PositionObject} start
  4598. * Starting coordinate, object with x/y props.
  4599. *
  4600. * @param {Highcharts.PositionObject} end
  4601. * Ending coordinate, object with x/y props.
  4602. *
  4603. * @param {object} options
  4604. * Options for the algorithm.
  4605. * - chartObstacles: Array of chart obstacles to avoid
  4606. * - lineObstacles: Array of line obstacles to jump over
  4607. * - obstacleMetrics: Object with metrics of chartObstacles cached
  4608. * - hardBounds: Hard boundaries to not cross
  4609. * - obstacleOptions: Options for the obstacles, including margin
  4610. * - startDirectionX: Optional. True if starting in the X direction.
  4611. * If not provided, the algorithm starts in the
  4612. * direction that is the furthest between
  4613. * start/end.
  4614. *
  4615. * @return {object}
  4616. * An object with the SVG path in Array form as accepted by the SVG
  4617. * renderer, as well as an array of new obstacles making up this
  4618. * path.
  4619. */
  4620. var fastAvoid = extend(function (start,
  4621. end,
  4622. options) {
  4623. /*
  4624. Algorithm rules/description
  4625. - Find initial direction
  4626. - Determine soft/hard max for each direction.
  4627. - Move along initial direction until obstacle.
  4628. - Change direction.
  4629. - If hitting obstacle,
  4630. first try to change length of previous line
  4631. before changing direction again.
  4632. Soft min/max x = start/destination x +/- widest obstacle + margin
  4633. Soft min/max y = start/destination y +/- tallest obstacle + margin
  4634. @todo:
  4635. - Make retrospective,
  4636. try changing prev segment to reduce
  4637. corners
  4638. - Fix logic for breaking out of end-points - not always picking
  4639. the best direction currently
  4640. - When going around the end obstacle we should not always go the
  4641. shortest route,
  4642. rather pick the one closer to the end point
  4643. */
  4644. var dirIsX = pick(options.startDirectionX,
  4645. abs(end.x - start.x) > abs(end.y - start.y)),
  4646. dir = dirIsX ? 'x' : 'y',
  4647. segments,
  4648. useMax,
  4649. extractedEndPoint,
  4650. endSegments = [],
  4651. forceObstacleBreak = false, // Used in clearPathTo to keep track of
  4652. // when to force break through an obstacle.
  4653. // Boundaries to stay within. If beyond soft boundary, prefer to
  4654. // change direction ASAP. If at hard max, always change immediately.
  4655. metrics = options.obstacleMetrics,
  4656. softMinX = min(start.x,
  4657. end.x) - metrics.maxWidth - 10,
  4658. softMaxX = max(start.x,
  4659. end.x) + metrics.maxWidth + 10,
  4660. softMinY = min(start.y,
  4661. end.y) - metrics.maxHeight - 10,
  4662. softMaxY = max(start.y,
  4663. end.y) + metrics.maxHeight + 10,
  4664. // Obstacles
  4665. chartObstacles = options.chartObstacles,
  4666. startObstacleIx = findLastObstacleBefore(chartObstacles,
  4667. softMinX),
  4668. endObstacleIx = findLastObstacleBefore(chartObstacles,
  4669. softMaxX);
  4670. // eslint-disable-next-line valid-jsdoc
  4671. /**
  4672. * How far can you go between two points before hitting an obstacle?
  4673. * Does not work for diagonal lines (because it doesn't have to).
  4674. * @private
  4675. */
  4676. function pivotPoint(fromPoint, toPoint, directionIsX) {
  4677. var firstPoint,
  4678. lastPoint,
  4679. highestPoint,
  4680. lowestPoint,
  4681. i,
  4682. searchDirection = fromPoint.x < toPoint.x ? 1 : -1;
  4683. if (fromPoint.x < toPoint.x) {
  4684. firstPoint = fromPoint;
  4685. lastPoint = toPoint;
  4686. }
  4687. else {
  4688. firstPoint = toPoint;
  4689. lastPoint = fromPoint;
  4690. }
  4691. if (fromPoint.y < toPoint.y) {
  4692. lowestPoint = fromPoint;
  4693. highestPoint = toPoint;
  4694. }
  4695. else {
  4696. lowestPoint = toPoint;
  4697. highestPoint = fromPoint;
  4698. }
  4699. // Go through obstacle range in reverse if toPoint is before
  4700. // fromPoint in the X-dimension.
  4701. i = searchDirection < 0 ?
  4702. // Searching backwards, start at last obstacle before last point
  4703. min(findLastObstacleBefore(chartObstacles, lastPoint.x), chartObstacles.length - 1) :
  4704. // Forwards. Since we're not sorted by xMax, we have to look
  4705. // at all obstacles.
  4706. 0;
  4707. // Go through obstacles in this X range
  4708. while (chartObstacles[i] && (searchDirection > 0 && chartObstacles[i].xMin <= lastPoint.x ||
  4709. searchDirection < 0 && chartObstacles[i].xMax >= firstPoint.x)) {
  4710. // If this obstacle is between from and to points in a straight
  4711. // line, pivot at the intersection.
  4712. if (chartObstacles[i].xMin <= lastPoint.x &&
  4713. chartObstacles[i].xMax >= firstPoint.x &&
  4714. chartObstacles[i].yMin <= highestPoint.y &&
  4715. chartObstacles[i].yMax >= lowestPoint.y) {
  4716. if (directionIsX) {
  4717. return {
  4718. y: fromPoint.y,
  4719. x: fromPoint.x < toPoint.x ?
  4720. chartObstacles[i].xMin - 1 :
  4721. chartObstacles[i].xMax + 1,
  4722. obstacle: chartObstacles[i]
  4723. };
  4724. }
  4725. // else ...
  4726. return {
  4727. x: fromPoint.x,
  4728. y: fromPoint.y < toPoint.y ?
  4729. chartObstacles[i].yMin - 1 :
  4730. chartObstacles[i].yMax + 1,
  4731. obstacle: chartObstacles[i]
  4732. };
  4733. }
  4734. i += searchDirection;
  4735. }
  4736. return toPoint;
  4737. }
  4738. /**
  4739. * Decide in which direction to dodge or get out of an obstacle.
  4740. * Considers desired direction, which way is shortest, soft and hard
  4741. * bounds.
  4742. *
  4743. * (? Returns a string, either xMin, xMax, yMin or yMax.)
  4744. *
  4745. * @private
  4746. * @function
  4747. *
  4748. * @param {object} obstacle
  4749. * Obstacle to dodge/escape.
  4750. *
  4751. * @param {object} fromPoint
  4752. * Point with x/y props that's dodging/escaping.
  4753. *
  4754. * @param {object} toPoint
  4755. * Goal point.
  4756. *
  4757. * @param {boolean} dirIsX
  4758. * Dodge in X dimension.
  4759. *
  4760. * @param {object} bounds
  4761. * Hard and soft boundaries.
  4762. *
  4763. * @return {boolean}
  4764. * Use max or not.
  4765. */
  4766. function getDodgeDirection(obstacle, fromPoint, toPoint, dirIsX, bounds) {
  4767. 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'] >=
  4768. softBounds[dir + 'Max'], minOutOfSoftBounds = obstacle[dir + 'Min'] <=
  4769. softBounds[dir + 'Min'], maxOutOfHardBounds = obstacle[dir + 'Max'] >=
  4770. hardBounds[dir + 'Max'], minOutOfHardBounds = obstacle[dir + 'Min'] <=
  4771. hardBounds[dir + 'Min'],
  4772. // Find out if we should prefer one direction over the other if
  4773. // we can choose freely
  4774. minDistance = abs(obstacle[dir + 'Min'] - fromPoint[dir]), maxDistance = abs(obstacle[dir + 'Max'] - fromPoint[dir]),
  4775. // If it's a small difference, pick the one leading towards dest
  4776. // point. Otherwise pick the shortest distance
  4777. useMax = abs(minDistance - maxDistance) < 10 ?
  4778. fromPoint[dir] < toPoint[dir] :
  4779. maxDistance < minDistance;
  4780. // Check if we hit any obstacles trying to go around in either
  4781. // direction.
  4782. toPointMin[dir] = obstacle[dir + 'Min'];
  4783. toPointMax[dir] = obstacle[dir + 'Max'];
  4784. minPivot = pivotPoint(fromPoint, toPointMin, dirIsX)[dir] !==
  4785. toPointMin[dir];
  4786. maxPivot = pivotPoint(fromPoint, toPointMax, dirIsX)[dir] !==
  4787. toPointMax[dir];
  4788. useMax = minPivot ?
  4789. (maxPivot ? useMax : true) :
  4790. (maxPivot ? false : useMax);
  4791. // useMax now contains our preferred choice, bounds not taken into
  4792. // account. If both or neither direction is out of bounds we want to
  4793. // use this.
  4794. // Deal with soft bounds
  4795. useMax = minOutOfSoftBounds ?
  4796. (maxOutOfSoftBounds ? useMax : true) : // Out on min
  4797. (maxOutOfSoftBounds ? false : useMax); // Not out on min
  4798. // Deal with hard bounds
  4799. useMax = minOutOfHardBounds ?
  4800. (maxOutOfHardBounds ? useMax : true) : // Out on min
  4801. (maxOutOfHardBounds ? false : useMax); // Not out on min
  4802. return useMax;
  4803. }
  4804. // eslint-disable-next-line valid-jsdoc
  4805. /**
  4806. * Find a clear path between point.
  4807. * @private
  4808. */
  4809. function clearPathTo(fromPoint, toPoint, dirIsX) {
  4810. // Don't waste time if we've hit goal
  4811. if (fromPoint.x === toPoint.x && fromPoint.y === toPoint.y) {
  4812. return [];
  4813. }
  4814. var dir = dirIsX ? 'x' : 'y',
  4815. pivot,
  4816. segments,
  4817. waypoint,
  4818. waypointUseMax,
  4819. envelopingObstacle,
  4820. secondEnvelopingObstacle,
  4821. envelopWaypoint,
  4822. obstacleMargin = options.obstacleOptions.margin,
  4823. bounds = {
  4824. soft: {
  4825. xMin: softMinX,
  4826. xMax: softMaxX,
  4827. yMin: softMinY,
  4828. yMax: softMaxY
  4829. },
  4830. hard: options.hardBounds
  4831. };
  4832. // If fromPoint is inside an obstacle we have a problem. Break out
  4833. // by just going to the outside of this obstacle. We prefer to go to
  4834. // the nearest edge in the chosen direction.
  4835. envelopingObstacle =
  4836. findObstacleFromPoint(chartObstacles, fromPoint);
  4837. if (envelopingObstacle > -1) {
  4838. envelopingObstacle = chartObstacles[envelopingObstacle];
  4839. waypointUseMax = getDodgeDirection(envelopingObstacle, fromPoint, toPoint, dirIsX, bounds);
  4840. // Cut obstacle to hard bounds to make sure we stay within
  4841. limitObstacleToBounds(envelopingObstacle, options.hardBounds);
  4842. envelopWaypoint = dirIsX ? {
  4843. y: fromPoint.y,
  4844. x: envelopingObstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  4845. (waypointUseMax ? 1 : -1)
  4846. } : {
  4847. x: fromPoint.x,
  4848. y: envelopingObstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  4849. (waypointUseMax ? 1 : -1)
  4850. };
  4851. // If we crashed into another obstacle doing this, we put the
  4852. // waypoint between them instead
  4853. secondEnvelopingObstacle = findObstacleFromPoint(chartObstacles, envelopWaypoint);
  4854. if (secondEnvelopingObstacle > -1) {
  4855. secondEnvelopingObstacle = chartObstacles[secondEnvelopingObstacle];
  4856. // Cut obstacle to hard bounds
  4857. limitObstacleToBounds(secondEnvelopingObstacle, options.hardBounds);
  4858. // Modify waypoint to lay between obstacles
  4859. envelopWaypoint[dir] = waypointUseMax ? max(envelopingObstacle[dir + 'Max'] - obstacleMargin + 1, (secondEnvelopingObstacle[dir + 'Min'] +
  4860. envelopingObstacle[dir + 'Max']) / 2) :
  4861. min((envelopingObstacle[dir + 'Min'] + obstacleMargin - 1), ((secondEnvelopingObstacle[dir + 'Max'] +
  4862. envelopingObstacle[dir + 'Min']) / 2));
  4863. // We are not going anywhere. If this happens for the first
  4864. // time, do nothing. Otherwise, try to go to the extreme of
  4865. // the obstacle pair in the current direction.
  4866. if (fromPoint.x === envelopWaypoint.x &&
  4867. fromPoint.y === envelopWaypoint.y) {
  4868. if (forceObstacleBreak) {
  4869. envelopWaypoint[dir] = waypointUseMax ?
  4870. max(envelopingObstacle[dir + 'Max'], secondEnvelopingObstacle[dir + 'Max']) + 1 :
  4871. min(envelopingObstacle[dir + 'Min'], secondEnvelopingObstacle[dir + 'Min']) - 1;
  4872. }
  4873. // Toggle on if off, and the opposite
  4874. forceObstacleBreak = !forceObstacleBreak;
  4875. }
  4876. else {
  4877. // This point is not identical to previous.
  4878. // Clear break trigger.
  4879. forceObstacleBreak = false;
  4880. }
  4881. }
  4882. segments = [{
  4883. start: fromPoint,
  4884. end: envelopWaypoint
  4885. }];
  4886. }
  4887. else { // If not enveloping, use standard pivot calculation
  4888. pivot = pivotPoint(fromPoint, {
  4889. x: dirIsX ? toPoint.x : fromPoint.x,
  4890. y: dirIsX ? fromPoint.y : toPoint.y
  4891. }, dirIsX);
  4892. segments = [{
  4893. start: fromPoint,
  4894. end: {
  4895. x: pivot.x,
  4896. y: pivot.y
  4897. }
  4898. }];
  4899. // Pivot before goal, use a waypoint to dodge obstacle
  4900. if (pivot[dirIsX ? 'x' : 'y'] !== toPoint[dirIsX ? 'x' : 'y']) {
  4901. // Find direction of waypoint
  4902. waypointUseMax = getDodgeDirection(pivot.obstacle, pivot, toPoint, !dirIsX, bounds);
  4903. // Cut waypoint to hard bounds
  4904. limitObstacleToBounds(pivot.obstacle, options.hardBounds);
  4905. waypoint = {
  4906. x: dirIsX ?
  4907. pivot.x :
  4908. pivot.obstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  4909. (waypointUseMax ? 1 : -1),
  4910. y: dirIsX ?
  4911. pivot.obstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  4912. (waypointUseMax ? 1 : -1) :
  4913. pivot.y
  4914. };
  4915. // We're changing direction here, store that to make sure we
  4916. // also change direction when adding the last segment array
  4917. // after handling waypoint.
  4918. dirIsX = !dirIsX;
  4919. segments = segments.concat(clearPathTo({
  4920. x: pivot.x,
  4921. y: pivot.y
  4922. }, waypoint, dirIsX));
  4923. }
  4924. }
  4925. // Get segments for the other direction too
  4926. // Recursion is our friend
  4927. segments = segments.concat(clearPathTo(segments[segments.length - 1].end, toPoint, !dirIsX));
  4928. return segments;
  4929. }
  4930. // eslint-disable-next-line valid-jsdoc
  4931. /**
  4932. * Extract point to outside of obstacle in whichever direction is
  4933. * closest. Returns new point outside obstacle.
  4934. * @private
  4935. */
  4936. function extractFromObstacle(obstacle, point, goalPoint) {
  4937. var dirIsX = min(obstacle.xMax - point.x,
  4938. point.x - obstacle.xMin) <
  4939. min(obstacle.yMax - point.y,
  4940. point.y - obstacle.yMin),
  4941. bounds = {
  4942. soft: options.hardBounds,
  4943. hard: options.hardBounds
  4944. },
  4945. useMax = getDodgeDirection(obstacle,
  4946. point,
  4947. goalPoint,
  4948. dirIsX,
  4949. bounds);
  4950. return dirIsX ? {
  4951. y: point.y,
  4952. x: obstacle[useMax ? 'xMax' : 'xMin'] + (useMax ? 1 : -1)
  4953. } : {
  4954. x: point.x,
  4955. y: obstacle[useMax ? 'yMax' : 'yMin'] + (useMax ? 1 : -1)
  4956. };
  4957. }
  4958. // Cut the obstacle array to soft bounds for optimization in large
  4959. // datasets.
  4960. chartObstacles =
  4961. chartObstacles.slice(startObstacleIx, endObstacleIx + 1);
  4962. // If an obstacle envelops the end point, move it out of there and add
  4963. // a little segment to where it was.
  4964. if ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  4965. extractedEndPoint = extractFromObstacle(chartObstacles[endObstacleIx], end, start);
  4966. endSegments.push({
  4967. end: end,
  4968. start: extractedEndPoint
  4969. });
  4970. end = extractedEndPoint;
  4971. }
  4972. // If it's still inside one or more obstacles, get out of there by
  4973. // force-moving towards the start point.
  4974. while ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  4975. useMax = end[dir] - start[dir] < 0;
  4976. extractedEndPoint = {
  4977. x: end.x,
  4978. y: end.y
  4979. };
  4980. extractedEndPoint[dir] = chartObstacles[endObstacleIx][useMax ? dir + 'Max' : dir + 'Min'] + (useMax ? 1 : -1);
  4981. endSegments.push({
  4982. end: end,
  4983. start: extractedEndPoint
  4984. });
  4985. end = extractedEndPoint;
  4986. }
  4987. // Find the path
  4988. segments = clearPathTo(start, end, dirIsX);
  4989. // Add the end-point segments
  4990. segments = segments.concat(endSegments.reverse());
  4991. return {
  4992. path: pathFromSegments(segments),
  4993. obstacles: segments
  4994. };
  4995. }, {
  4996. requiresObstacles: true
  4997. });
  4998. // Define the available pathfinding algorithms.
  4999. // Algorithms take up to 3 arguments: starting point, ending point, and an
  5000. // options object.
  5001. var algorithms = {
  5002. fastAvoid: fastAvoid,
  5003. straight: straight,
  5004. simpleConnect: simpleConnect
  5005. };
  5006. return algorithms;
  5007. });
  5008. _registerModule(_modules, 'Gantt/Pathfinder.js', [_modules['Gantt/Connection.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js'], _modules['Gantt/PathfinderAlgorithms.js']], function (Connection, Chart, H, O, Point, U, pathfinderAlgorithms) {
  5009. /* *
  5010. *
  5011. * (c) 2016 Highsoft AS
  5012. * Authors: Øystein Moseng, Lars A. V. Cabrera
  5013. *
  5014. * License: www.highcharts.com/license
  5015. *
  5016. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5017. *
  5018. * */
  5019. /**
  5020. * The default pathfinder algorithm to use for a chart. It is possible to define
  5021. * your own algorithms by adding them to the
  5022. * `Highcharts.Pathfinder.prototype.algorithms`
  5023. * object before the chart has been created.
  5024. *
  5025. * The default algorithms are as follows:
  5026. *
  5027. * `straight`: Draws a straight line between the connecting
  5028. * points. Does not avoid other points when drawing.
  5029. *
  5030. * `simpleConnect`: Finds a path between the points using right angles
  5031. * only. Takes only starting/ending points into
  5032. * account, and will not avoid other points.
  5033. *
  5034. * `fastAvoid`: Finds a path between the points using right angles
  5035. * only. Will attempt to avoid other points, but its
  5036. * focus is performance over accuracy. Works well with
  5037. * less dense datasets.
  5038. *
  5039. * @typedef {"fastAvoid"|"simpleConnect"|"straight"|string} Highcharts.PathfinderTypeValue
  5040. */
  5041. ''; // detach doclets above
  5042. var defaultOptions = O.defaultOptions;
  5043. var addEvent = U.addEvent,
  5044. defined = U.defined,
  5045. error = U.error,
  5046. extend = U.extend,
  5047. merge = U.merge,
  5048. objectEach = U.objectEach,
  5049. pick = U.pick,
  5050. splat = U.splat;
  5051. var deg2rad = H.deg2rad,
  5052. max = Math.max,
  5053. min = Math.min;
  5054. /*
  5055. @todo:
  5056. - Document how to write your own algorithms
  5057. - Consider adding a Point.pathTo method that wraps creating a connection
  5058. and rendering it
  5059. */
  5060. // Set default Pathfinder options
  5061. extend(defaultOptions, {
  5062. /**
  5063. * The Pathfinder module allows you to define connections between any two
  5064. * points, represented as lines - optionally with markers for the start
  5065. * and/or end points. Multiple algorithms are available for calculating how
  5066. * the connecting lines are drawn.
  5067. *
  5068. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  5069. * charts, the connectors are used to draw dependencies between tasks.
  5070. *
  5071. * @see [dependency](series.gantt.data.dependency)
  5072. *
  5073. * @sample gantt/pathfinder/demo
  5074. * Pathfinder connections
  5075. *
  5076. * @declare Highcharts.ConnectorsOptions
  5077. * @product gantt
  5078. * @optionparent connectors
  5079. */
  5080. connectors: {
  5081. /**
  5082. * Enable connectors for this chart. Requires Highcharts Gantt.
  5083. *
  5084. * @type {boolean}
  5085. * @default true
  5086. * @since 6.2.0
  5087. * @apioption connectors.enabled
  5088. */
  5089. /**
  5090. * Set the default dash style for this chart's connecting lines.
  5091. *
  5092. * @type {string}
  5093. * @default solid
  5094. * @since 6.2.0
  5095. * @apioption connectors.dashStyle
  5096. */
  5097. /**
  5098. * Set the default color for this chart's Pathfinder connecting lines.
  5099. * Defaults to the color of the point being connected.
  5100. *
  5101. * @type {Highcharts.ColorString}
  5102. * @since 6.2.0
  5103. * @apioption connectors.lineColor
  5104. */
  5105. /**
  5106. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  5107. * algorithms attempt to avoid obstacles, such as other points in the
  5108. * chart. These algorithms use this margin to determine how close lines
  5109. * can be to an obstacle. The default is to compute this automatically
  5110. * from the size of the obstacles in the chart.
  5111. *
  5112. * To draw connecting lines close to existing points, set this to a low
  5113. * number. For more space around existing points, set this number
  5114. * higher.
  5115. *
  5116. * @sample gantt/pathfinder/algorithm-margin
  5117. * Small algorithmMargin
  5118. *
  5119. * @type {number}
  5120. * @since 6.2.0
  5121. * @apioption connectors.algorithmMargin
  5122. */
  5123. /**
  5124. * Set the default pathfinder algorithm to use for this chart. It is
  5125. * possible to define your own algorithms by adding them to the
  5126. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  5127. * has been created.
  5128. *
  5129. * The default algorithms are as follows:
  5130. *
  5131. * `straight`: Draws a straight line between the connecting
  5132. * points. Does not avoid other points when drawing.
  5133. *
  5134. * `simpleConnect`: Finds a path between the points using right angles
  5135. * only. Takes only starting/ending points into
  5136. * account, and will not avoid other points.
  5137. *
  5138. * `fastAvoid`: Finds a path between the points using right angles
  5139. * only. Will attempt to avoid other points, but its
  5140. * focus is performance over accuracy. Works well with
  5141. * less dense datasets.
  5142. *
  5143. * Default value: `straight` is used as default for most series types,
  5144. * while `simpleConnect` is used as default for Gantt series, to show
  5145. * dependencies between points.
  5146. *
  5147. * @sample gantt/pathfinder/demo
  5148. * Different types used
  5149. *
  5150. * @type {Highcharts.PathfinderTypeValue}
  5151. * @default undefined
  5152. * @since 6.2.0
  5153. */
  5154. type: 'straight',
  5155. /**
  5156. * Set the default pixel width for this chart's Pathfinder connecting
  5157. * lines.
  5158. *
  5159. * @since 6.2.0
  5160. */
  5161. lineWidth: 1,
  5162. /**
  5163. * Marker options for this chart's Pathfinder connectors. Note that
  5164. * this option is overridden by the `startMarker` and `endMarker`
  5165. * options.
  5166. *
  5167. * @declare Highcharts.ConnectorsMarkerOptions
  5168. * @since 6.2.0
  5169. */
  5170. marker: {
  5171. /**
  5172. * Set the radius of the connector markers. The default is
  5173. * automatically computed based on the algorithmMargin setting.
  5174. *
  5175. * Setting marker.width and marker.height will override this
  5176. * setting.
  5177. *
  5178. * @type {number}
  5179. * @since 6.2.0
  5180. * @apioption connectors.marker.radius
  5181. */
  5182. /**
  5183. * Set the width of the connector markers. If not supplied, this
  5184. * is inferred from the marker radius.
  5185. *
  5186. * @type {number}
  5187. * @since 6.2.0
  5188. * @apioption connectors.marker.width
  5189. */
  5190. /**
  5191. * Set the height of the connector markers. If not supplied, this
  5192. * is inferred from the marker radius.
  5193. *
  5194. * @type {number}
  5195. * @since 6.2.0
  5196. * @apioption connectors.marker.height
  5197. */
  5198. /**
  5199. * Set the color of the connector markers. By default this is the
  5200. * same as the connector color.
  5201. *
  5202. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5203. * @since 6.2.0
  5204. * @apioption connectors.marker.color
  5205. */
  5206. /**
  5207. * Set the line/border color of the connector markers. By default
  5208. * this is the same as the marker color.
  5209. *
  5210. * @type {Highcharts.ColorString}
  5211. * @since 6.2.0
  5212. * @apioption connectors.marker.lineColor
  5213. */
  5214. /**
  5215. * Enable markers for the connectors.
  5216. */
  5217. enabled: false,
  5218. /**
  5219. * Horizontal alignment of the markers relative to the points.
  5220. *
  5221. * @type {Highcharts.AlignValue}
  5222. */
  5223. align: 'center',
  5224. /**
  5225. * Vertical alignment of the markers relative to the points.
  5226. *
  5227. * @type {Highcharts.VerticalAlignValue}
  5228. */
  5229. verticalAlign: 'middle',
  5230. /**
  5231. * Whether or not to draw the markers inside the points.
  5232. */
  5233. inside: false,
  5234. /**
  5235. * Set the line/border width of the pathfinder markers.
  5236. */
  5237. lineWidth: 1
  5238. },
  5239. /**
  5240. * Marker options specific to the start markers for this chart's
  5241. * Pathfinder connectors. Overrides the generic marker options.
  5242. *
  5243. * @declare Highcharts.ConnectorsStartMarkerOptions
  5244. * @extends connectors.marker
  5245. * @since 6.2.0
  5246. */
  5247. startMarker: {
  5248. /**
  5249. * Set the symbol of the connector start markers.
  5250. */
  5251. symbol: 'diamond'
  5252. },
  5253. /**
  5254. * Marker options specific to the end markers for this chart's
  5255. * Pathfinder connectors. Overrides the generic marker options.
  5256. *
  5257. * @declare Highcharts.ConnectorsEndMarkerOptions
  5258. * @extends connectors.marker
  5259. * @since 6.2.0
  5260. */
  5261. endMarker: {
  5262. /**
  5263. * Set the symbol of the connector end markers.
  5264. */
  5265. symbol: 'arrow-filled'
  5266. }
  5267. }
  5268. });
  5269. /**
  5270. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  5271. * to be loaded.
  5272. *
  5273. * @declare Highcharts.SeriesConnectorsOptionsObject
  5274. * @extends connectors
  5275. * @since 6.2.0
  5276. * @excluding enabled, algorithmMargin
  5277. * @product gantt
  5278. * @apioption plotOptions.series.connectors
  5279. */
  5280. /**
  5281. * Connect to a point. This option can be either a string, referring to the ID
  5282. * of another point, or an object, or an array of either. If the option is an
  5283. * array, each element defines a connection.
  5284. *
  5285. * @sample gantt/pathfinder/demo
  5286. * Different connection types
  5287. *
  5288. * @declare Highcharts.XrangePointConnectorsOptionsObject
  5289. * @type {string|Array<string|*>|*}
  5290. * @extends plotOptions.series.connectors
  5291. * @since 6.2.0
  5292. * @excluding enabled
  5293. * @product gantt
  5294. * @requires highcharts-gantt
  5295. * @apioption series.xrange.data.connect
  5296. */
  5297. /**
  5298. * The ID of the point to connect to.
  5299. *
  5300. * @type {string}
  5301. * @since 6.2.0
  5302. * @product gantt
  5303. * @apioption series.xrange.data.connect.to
  5304. */
  5305. /**
  5306. * Get point bounding box using plotX/plotY and shapeArgs. If using
  5307. * graphic.getBBox() directly, the bbox will be affected by animation.
  5308. *
  5309. * @private
  5310. * @function
  5311. *
  5312. * @param {Highcharts.Point} point
  5313. * The point to get BB of.
  5314. *
  5315. * @return {Highcharts.Dictionary<number>|null}
  5316. * Result xMax, xMin, yMax, yMin.
  5317. */
  5318. function getPointBB(point) {
  5319. var shapeArgs = point.shapeArgs,
  5320. bb;
  5321. // Prefer using shapeArgs (columns)
  5322. if (shapeArgs) {
  5323. return {
  5324. xMin: shapeArgs.x,
  5325. xMax: shapeArgs.x + shapeArgs.width,
  5326. yMin: shapeArgs.y,
  5327. yMax: shapeArgs.y + shapeArgs.height
  5328. };
  5329. }
  5330. // Otherwise use plotX/plotY and bb
  5331. bb = point.graphic && point.graphic.getBBox();
  5332. return bb ? {
  5333. xMin: point.plotX - bb.width / 2,
  5334. xMax: point.plotX + bb.width / 2,
  5335. yMin: point.plotY - bb.height / 2,
  5336. yMax: point.plotY + bb.height / 2
  5337. } : null;
  5338. }
  5339. /**
  5340. * Calculate margin to place around obstacles for the pathfinder in pixels.
  5341. * Returns a minimum of 1 pixel margin.
  5342. *
  5343. * @private
  5344. * @function
  5345. *
  5346. * @param {Array<object>} obstacles
  5347. * Obstacles to calculate margin from.
  5348. *
  5349. * @return {number}
  5350. * The calculated margin in pixels. At least 1.
  5351. */
  5352. function calculateObstacleMargin(obstacles) {
  5353. var len = obstacles.length,
  5354. i = 0,
  5355. j,
  5356. obstacleDistance,
  5357. distances = [],
  5358. // Compute smallest distance between two rectangles
  5359. distance = function (a,
  5360. b,
  5361. bbMargin) {
  5362. // Count the distance even if we are slightly off
  5363. var margin = pick(bbMargin, 10),
  5364. yOverlap = a.yMax + margin > b.yMin - margin &&
  5365. a.yMin - margin < b.yMax + margin,
  5366. xOverlap = a.xMax + margin > b.xMin - margin &&
  5367. a.xMin - margin < b.xMax + margin,
  5368. xDistance = yOverlap ? (a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax) : Infinity,
  5369. yDistance = xOverlap ? (a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax) : Infinity;
  5370. // If the rectangles collide, try recomputing with smaller margin.
  5371. // If they collide anyway, discard the obstacle.
  5372. if (xOverlap && yOverlap) {
  5373. return (margin ?
  5374. distance(a, b, Math.floor(margin / 2)) :
  5375. Infinity);
  5376. }
  5377. return min(xDistance, yDistance);
  5378. };
  5379. // Go over all obstacles and compare them to the others.
  5380. for (; i < len; ++i) {
  5381. // Compare to all obstacles ahead. We will already have compared this
  5382. // obstacle to the ones before.
  5383. for (j = i + 1; j < len; ++j) {
  5384. obstacleDistance = distance(obstacles[i], obstacles[j]);
  5385. // TODO: Magic number 80
  5386. if (obstacleDistance < 80) { // Ignore large distances
  5387. distances.push(obstacleDistance);
  5388. }
  5389. }
  5390. }
  5391. // Ensure we always have at least one value, even in very spaceous charts
  5392. distances.push(80);
  5393. return max(Math.floor(distances.sort(function (a, b) {
  5394. return (a - b);
  5395. })[
  5396. // Discard first 10% of the relevant distances, and then grab
  5397. // the smallest one.
  5398. Math.floor(distances.length / 10)] / 2 - 1 // Divide the distance by 2 and subtract 1.
  5399. ), 1 // 1 is the minimum margin
  5400. );
  5401. }
  5402. /* eslint-disable no-invalid-this, valid-jsdoc */
  5403. /**
  5404. * The Pathfinder class.
  5405. *
  5406. * @private
  5407. * @class
  5408. * @name Highcharts.Pathfinder
  5409. *
  5410. * @param {Highcharts.Chart} chart
  5411. * The chart to operate on.
  5412. */
  5413. var Pathfinder = /** @class */ (function () {
  5414. function Pathfinder(chart) {
  5415. /* *
  5416. *
  5417. * Properties
  5418. *
  5419. * */
  5420. this.chart = void 0;
  5421. this.chartObstacles = void 0;
  5422. this.chartObstacleMetrics = void 0;
  5423. this.connections = void 0;
  5424. this.group = void 0;
  5425. this.lineObstacles = void 0;
  5426. this.init(chart);
  5427. }
  5428. /**
  5429. * @name Highcharts.Pathfinder#algorithms
  5430. * @type {Highcharts.Dictionary<Function>}
  5431. */
  5432. /**
  5433. * Initialize the Pathfinder object.
  5434. *
  5435. * @function Highcharts.Pathfinder#init
  5436. *
  5437. * @param {Highcharts.Chart} chart
  5438. * The chart context.
  5439. */
  5440. Pathfinder.prototype.init = function (chart) {
  5441. // Initialize pathfinder with chart context
  5442. this.chart = chart;
  5443. // Init connection reference list
  5444. this.connections = [];
  5445. // Recalculate paths/obstacles on chart redraw
  5446. addEvent(chart, 'redraw', function () {
  5447. this.pathfinder.update();
  5448. });
  5449. };
  5450. /**
  5451. * Update Pathfinder connections from scratch.
  5452. *
  5453. * @function Highcharts.Pathfinder#update
  5454. *
  5455. * @param {boolean} [deferRender]
  5456. * Whether or not to defer rendering of connections until
  5457. * series.afterAnimate event has fired. Used on first render.
  5458. */
  5459. Pathfinder.prototype.update = function (deferRender) {
  5460. var chart = this.chart,
  5461. pathfinder = this,
  5462. oldConnections = pathfinder.connections;
  5463. // Rebuild pathfinder connections from options
  5464. pathfinder.connections = [];
  5465. chart.series.forEach(function (series) {
  5466. if (series.visible && !series.options.isInternal) {
  5467. series.points.forEach(function (point) {
  5468. var to,
  5469. connects = (point.options &&
  5470. point.options.connect &&
  5471. splat(point.options.connect));
  5472. if (point.visible && point.isInside !== false && connects) {
  5473. connects.forEach(function (connect) {
  5474. to = chart.get(typeof connect === 'string' ?
  5475. connect : connect.to);
  5476. if (to instanceof Point &&
  5477. to.series.visible &&
  5478. to.visible &&
  5479. to.isInside !== false) {
  5480. // Add new connection
  5481. pathfinder.connections.push(new Connection(point, // from
  5482. to, typeof connect === 'string' ?
  5483. {} :
  5484. connect));
  5485. }
  5486. });
  5487. }
  5488. });
  5489. }
  5490. });
  5491. // Clear connections that should not be updated, and move old info over
  5492. // to new connections.
  5493. for (var j = 0, k, found, lenOld = oldConnections.length, lenNew = pathfinder.connections.length; j < lenOld; ++j) {
  5494. found = false;
  5495. for (k = 0; k < lenNew; ++k) {
  5496. if (oldConnections[j].fromPoint ===
  5497. pathfinder.connections[k].fromPoint &&
  5498. oldConnections[j].toPoint ===
  5499. pathfinder.connections[k].toPoint) {
  5500. pathfinder.connections[k].graphics =
  5501. oldConnections[j].graphics;
  5502. found = true;
  5503. break;
  5504. }
  5505. }
  5506. if (!found) {
  5507. oldConnections[j].destroy();
  5508. }
  5509. }
  5510. // Clear obstacles to force recalculation. This must be done on every
  5511. // redraw in case positions have changed. Recalculation is handled in
  5512. // Connection.getPath on demand.
  5513. delete this.chartObstacles;
  5514. delete this.lineObstacles;
  5515. // Draw the pending connections
  5516. pathfinder.renderConnections(deferRender);
  5517. };
  5518. /**
  5519. * Draw the chart's connecting paths.
  5520. *
  5521. * @function Highcharts.Pathfinder#renderConnections
  5522. *
  5523. * @param {boolean} [deferRender]
  5524. * Whether or not to defer render until series animation is finished.
  5525. * Used on first render.
  5526. */
  5527. Pathfinder.prototype.renderConnections = function (deferRender) {
  5528. if (deferRender) {
  5529. // Render after series are done animating
  5530. this.chart.series.forEach(function (series) {
  5531. var render = function () {
  5532. // Find pathfinder connections belonging to this series
  5533. // that haven't rendered, and render them now.
  5534. var pathfinder = series.chart.pathfinder,
  5535. conns = pathfinder && pathfinder.connections || [];
  5536. conns.forEach(function (connection) {
  5537. if (connection.fromPoint &&
  5538. connection.fromPoint.series === series) {
  5539. connection.render();
  5540. }
  5541. });
  5542. if (series.pathfinderRemoveRenderEvent) {
  5543. series.pathfinderRemoveRenderEvent();
  5544. delete series.pathfinderRemoveRenderEvent;
  5545. }
  5546. };
  5547. if (series.options.animation === false) {
  5548. render();
  5549. }
  5550. else {
  5551. series.pathfinderRemoveRenderEvent = addEvent(series, 'afterAnimate', render);
  5552. }
  5553. });
  5554. }
  5555. else {
  5556. // Go through connections and render them
  5557. this.connections.forEach(function (connection) {
  5558. connection.render();
  5559. });
  5560. }
  5561. };
  5562. /**
  5563. * Get obstacles for the points in the chart. Does not include connecting
  5564. * lines from Pathfinder. Applies algorithmMargin to the obstacles.
  5565. *
  5566. * @function Highcharts.Pathfinder#getChartObstacles
  5567. *
  5568. * @param {object} options
  5569. * Options for the calculation. Currenlty only
  5570. * options.algorithmMargin.
  5571. *
  5572. * @return {Array<object>}
  5573. * An array of calculated obstacles. Each obstacle is defined as an
  5574. * object with xMin, xMax, yMin and yMax properties.
  5575. */
  5576. Pathfinder.prototype.getChartObstacles = function (options) {
  5577. var obstacles = [],
  5578. series = this.chart.series,
  5579. margin = pick(options.algorithmMargin, 0),
  5580. calculatedMargin;
  5581. for (var i = 0, sLen = series.length; i < sLen; ++i) {
  5582. if (series[i].visible && !series[i].options.isInternal) {
  5583. for (var j = 0, pLen = series[i].points.length, bb, point; j < pLen; ++j) {
  5584. point = series[i].points[j];
  5585. if (point.visible) {
  5586. bb = getPointBB(point);
  5587. if (bb) {
  5588. obstacles.push({
  5589. xMin: bb.xMin - margin,
  5590. xMax: bb.xMax + margin,
  5591. yMin: bb.yMin - margin,
  5592. yMax: bb.yMax + margin
  5593. });
  5594. }
  5595. }
  5596. }
  5597. }
  5598. }
  5599. // Sort obstacles by xMin for optimization
  5600. obstacles = obstacles.sort(function (a, b) {
  5601. return a.xMin - b.xMin;
  5602. });
  5603. // Add auto-calculated margin if the option is not defined
  5604. if (!defined(options.algorithmMargin)) {
  5605. calculatedMargin =
  5606. options.algorithmMargin =
  5607. calculateObstacleMargin(obstacles);
  5608. obstacles.forEach(function (obstacle) {
  5609. obstacle.xMin -= calculatedMargin;
  5610. obstacle.xMax += calculatedMargin;
  5611. obstacle.yMin -= calculatedMargin;
  5612. obstacle.yMax += calculatedMargin;
  5613. });
  5614. }
  5615. return obstacles;
  5616. };
  5617. /**
  5618. * Utility function to get metrics for obstacles:
  5619. * - Widest obstacle width
  5620. * - Tallest obstacle height
  5621. *
  5622. * @function Highcharts.Pathfinder#getObstacleMetrics
  5623. *
  5624. * @param {Array<object>} obstacles
  5625. * An array of obstacles to inspect.
  5626. *
  5627. * @return {object}
  5628. * The calculated metrics, as an object with maxHeight and maxWidth
  5629. * properties.
  5630. */
  5631. Pathfinder.prototype.getObstacleMetrics = function (obstacles) {
  5632. var maxWidth = 0,
  5633. maxHeight = 0,
  5634. width,
  5635. height,
  5636. i = obstacles.length;
  5637. while (i--) {
  5638. width = obstacles[i].xMax - obstacles[i].xMin;
  5639. height = obstacles[i].yMax - obstacles[i].yMin;
  5640. if (maxWidth < width) {
  5641. maxWidth = width;
  5642. }
  5643. if (maxHeight < height) {
  5644. maxHeight = height;
  5645. }
  5646. }
  5647. return {
  5648. maxHeight: maxHeight,
  5649. maxWidth: maxWidth
  5650. };
  5651. };
  5652. /**
  5653. * Utility to get which direction to start the pathfinding algorithm
  5654. * (X vs Y), calculated from a set of marker options.
  5655. *
  5656. * @function Highcharts.Pathfinder#getAlgorithmStartDirection
  5657. *
  5658. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  5659. * Marker options to calculate from.
  5660. *
  5661. * @return {boolean}
  5662. * Returns true for X, false for Y, and undefined for autocalculate.
  5663. */
  5664. Pathfinder.prototype.getAlgorithmStartDirection = function (markerOptions) {
  5665. var xCenter = markerOptions.align !== 'left' &&
  5666. markerOptions.align !== 'right', yCenter = markerOptions.verticalAlign !== 'top' &&
  5667. markerOptions.verticalAlign !== 'bottom', undef;
  5668. return xCenter ?
  5669. (yCenter ? undef : false) : // x is centered
  5670. (yCenter ? true : undef); // x is off-center
  5671. };
  5672. return Pathfinder;
  5673. }());
  5674. Pathfinder.prototype.algorithms = pathfinderAlgorithms;
  5675. // Add to Highcharts namespace
  5676. H.Pathfinder = Pathfinder;
  5677. // Add pathfinding capabilities to Points
  5678. extend(Point.prototype, /** @lends Point.prototype */ {
  5679. /**
  5680. * Get coordinates of anchor point for pathfinder connection.
  5681. *
  5682. * @private
  5683. * @function Highcharts.Point#getPathfinderAnchorPoint
  5684. *
  5685. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  5686. * Connection options for position on point.
  5687. *
  5688. * @return {Highcharts.PositionObject}
  5689. * An object with x/y properties for the position. Coordinates are
  5690. * in plot values, not relative to point.
  5691. */
  5692. getPathfinderAnchorPoint: function (markerOptions) {
  5693. var bb = getPointBB(this),
  5694. x,
  5695. y;
  5696. switch (markerOptions.align) { // eslint-disable-line default-case
  5697. case 'right':
  5698. x = 'xMax';
  5699. break;
  5700. case 'left':
  5701. x = 'xMin';
  5702. }
  5703. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  5704. case 'top':
  5705. y = 'yMin';
  5706. break;
  5707. case 'bottom':
  5708. y = 'yMax';
  5709. }
  5710. return {
  5711. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  5712. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  5713. };
  5714. },
  5715. /**
  5716. * Utility to get the angle from one point to another.
  5717. *
  5718. * @private
  5719. * @function Highcharts.Point#getRadiansToVector
  5720. *
  5721. * @param {Highcharts.PositionObject} v1
  5722. * The first vector, as an object with x/y properties.
  5723. *
  5724. * @param {Highcharts.PositionObject} v2
  5725. * The second vector, as an object with x/y properties.
  5726. *
  5727. * @return {number}
  5728. * The angle in degrees
  5729. */
  5730. getRadiansToVector: function (v1, v2) {
  5731. var box;
  5732. if (!defined(v2)) {
  5733. box = getPointBB(this);
  5734. if (box) {
  5735. v2 = {
  5736. x: (box.xMin + box.xMax) / 2,
  5737. y: (box.yMin + box.yMax) / 2
  5738. };
  5739. }
  5740. }
  5741. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  5742. },
  5743. /**
  5744. * Utility to get the position of the marker, based on the path angle and
  5745. * the marker's radius.
  5746. *
  5747. * @private
  5748. * @function Highcharts.Point#getMarkerVector
  5749. *
  5750. * @param {number} radians
  5751. * The angle in radians from the point center to another vector.
  5752. *
  5753. * @param {number} markerRadius
  5754. * The radius of the marker, to calculate the additional distance to
  5755. * the center of the marker.
  5756. *
  5757. * @param {object} anchor
  5758. * The anchor point of the path and marker as an object with x/y
  5759. * properties.
  5760. *
  5761. * @return {object}
  5762. * The marker vector as an object with x/y properties.
  5763. */
  5764. getMarkerVector: function (radians, markerRadius, anchor) {
  5765. var twoPI = Math.PI * 2.0,
  5766. theta = radians,
  5767. bb = getPointBB(this),
  5768. rectWidth = bb.xMax - bb.xMin,
  5769. rectHeight = bb.yMax - bb.yMin,
  5770. rAtan = Math.atan2(rectHeight,
  5771. rectWidth),
  5772. tanTheta = 1,
  5773. leftOrRightRegion = false,
  5774. rectHalfWidth = rectWidth / 2.0,
  5775. rectHalfHeight = rectHeight / 2.0,
  5776. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  5777. rectVerticalCenter = bb.yMin + rectHalfHeight,
  5778. edgePoint = {
  5779. x: rectHorizontalCenter,
  5780. y: rectVerticalCenter
  5781. },
  5782. markerPoint = {},
  5783. xFactor = 1,
  5784. yFactor = 1;
  5785. while (theta < -Math.PI) {
  5786. theta += twoPI;
  5787. }
  5788. while (theta > Math.PI) {
  5789. theta -= twoPI;
  5790. }
  5791. tanTheta = Math.tan(theta);
  5792. if ((theta > -rAtan) && (theta <= rAtan)) {
  5793. // Right side
  5794. yFactor = -1;
  5795. leftOrRightRegion = true;
  5796. }
  5797. else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  5798. // Top side
  5799. yFactor = -1;
  5800. }
  5801. else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  5802. // Left side
  5803. xFactor = -1;
  5804. leftOrRightRegion = true;
  5805. }
  5806. else {
  5807. // Bottom side
  5808. xFactor = -1;
  5809. }
  5810. // Correct the edgePoint according to the placement of the marker
  5811. if (leftOrRightRegion) {
  5812. edgePoint.x += xFactor * (rectHalfWidth);
  5813. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  5814. }
  5815. else {
  5816. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  5817. edgePoint.y += yFactor * (rectHalfHeight);
  5818. }
  5819. if (anchor.x !== rectHorizontalCenter) {
  5820. edgePoint.x = anchor.x;
  5821. }
  5822. if (anchor.y !== rectVerticalCenter) {
  5823. edgePoint.y = anchor.y;
  5824. }
  5825. markerPoint.x = edgePoint.x + (markerRadius * Math.cos(theta));
  5826. markerPoint.y = edgePoint.y - (markerRadius * Math.sin(theta));
  5827. return markerPoint;
  5828. }
  5829. });
  5830. /**
  5831. * Warn if using legacy options. Copy the options over. Note that this will
  5832. * still break if using the legacy options in chart.update, addSeries etc.
  5833. * @private
  5834. */
  5835. function warnLegacy(chart) {
  5836. if (chart.options.pathfinder ||
  5837. chart.series.reduce(function (acc, series) {
  5838. if (series.options) {
  5839. merge(true, (series.options.connectors = series.options.connectors ||
  5840. {}), series.options.pathfinder);
  5841. }
  5842. return acc || series.options && series.options.pathfinder;
  5843. }, false)) {
  5844. merge(true, (chart.options.connectors = chart.options.connectors || {}), chart.options.pathfinder);
  5845. error('WARNING: Pathfinder options have been renamed. ' +
  5846. 'Use "chart.connectors" or "series.connectors" instead.');
  5847. }
  5848. }
  5849. // Initialize Pathfinder for charts
  5850. Chart.prototype.callbacks.push(function (chart) {
  5851. var options = chart.options;
  5852. if (options.connectors.enabled !== false) {
  5853. warnLegacy(chart);
  5854. this.pathfinder = new Pathfinder(this);
  5855. this.pathfinder.update(true); // First draw, defer render
  5856. }
  5857. });
  5858. return Pathfinder;
  5859. });
  5860. _registerModule(_modules, 'Series/XRangeSeries.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Color.js'], _modules['Core/Series/Point.js'], _modules['Core/Utilities.js']], function (Axis, H, Color, Point, U) {
  5861. /* *
  5862. *
  5863. * X-range series module
  5864. *
  5865. * (c) 2010-2020 Torstein Honsi, Lars A. V. Cabrera
  5866. *
  5867. * License: www.highcharts.com/license
  5868. *
  5869. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5870. *
  5871. * */
  5872. var color = Color.parse;
  5873. var addEvent = U.addEvent,
  5874. clamp = U.clamp,
  5875. correctFloat = U.correctFloat,
  5876. defined = U.defined,
  5877. find = U.find,
  5878. isNumber = U.isNumber,
  5879. isObject = U.isObject,
  5880. merge = U.merge,
  5881. pick = U.pick,
  5882. seriesType = U.seriesType;
  5883. /* *
  5884. * @interface Highcharts.PointOptionsObject in parts/Point.ts
  5885. */ /**
  5886. * The ending X value of the range point.
  5887. * @name Highcharts.PointOptionsObject#x2
  5888. * @type {number|undefined}
  5889. * @requires modules/xrange
  5890. */
  5891. var columnType = H.seriesTypes.column,
  5892. seriesTypes = H.seriesTypes,
  5893. Series = H.Series;
  5894. /**
  5895. * Return color of a point based on its category.
  5896. *
  5897. * @private
  5898. * @function getColorByCategory
  5899. *
  5900. * @param {object} series
  5901. * The series which the point belongs to.
  5902. *
  5903. * @param {object} point
  5904. * The point to calculate its color for.
  5905. *
  5906. * @return {object}
  5907. * Returns an object containing the properties color and colorIndex.
  5908. */
  5909. function getColorByCategory(series, point) {
  5910. var colors = series.options.colors || series.chart.options.colors,
  5911. colorCount = colors ?
  5912. colors.length :
  5913. series.chart.options.chart.colorCount,
  5914. colorIndex = point.y % colorCount,
  5915. color = colors && colors[colorIndex];
  5916. return {
  5917. colorIndex: colorIndex,
  5918. color: color
  5919. };
  5920. }
  5921. /**
  5922. * @private
  5923. * @class
  5924. * @name Highcharts.seriesTypes.xrange
  5925. *
  5926. * @augments Highcharts.Series
  5927. */
  5928. seriesType('xrange', 'column'
  5929. /**
  5930. * The X-range series displays ranges on the X axis, typically time
  5931. * intervals with a start and end date.
  5932. *
  5933. * @sample {highcharts} highcharts/demo/x-range/
  5934. * X-range
  5935. * @sample {highcharts} highcharts/css/x-range/
  5936. * Styled mode X-range
  5937. * @sample {highcharts} highcharts/chart/inverted-xrange/
  5938. * Inverted X-range
  5939. *
  5940. * @extends plotOptions.column
  5941. * @since 6.0.0
  5942. * @product highcharts highstock gantt
  5943. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor,
  5944. * edgeWidth, findNearestPointBy, getExtremesFromAll,
  5945. * negativeColor, pointInterval, pointIntervalUnit,
  5946. * pointPlacement, pointRange, pointStart, softThreshold,
  5947. * stacking, threshold, data, dataSorting, boostBlending
  5948. * @requires modules/xrange
  5949. * @optionparent plotOptions.xrange
  5950. */
  5951. , {
  5952. /**
  5953. * A partial fill for each point, typically used to visualize how much
  5954. * of a task is performed. The partial fill object can be set either on
  5955. * series or point level.
  5956. *
  5957. * @sample {highcharts} highcharts/demo/x-range
  5958. * X-range with partial fill
  5959. *
  5960. * @product highcharts highstock gantt
  5961. * @apioption plotOptions.xrange.partialFill
  5962. */
  5963. /**
  5964. * The fill color to be used for partial fills. Defaults to a darker
  5965. * shade of the point color.
  5966. *
  5967. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5968. * @product highcharts highstock gantt
  5969. * @apioption plotOptions.xrange.partialFill.fill
  5970. */
  5971. /**
  5972. * A partial fill for each point, typically used to visualize how much
  5973. * of a task is performed. See [completed](series.gantt.data.completed).
  5974. *
  5975. * @sample gantt/demo/progress-indicator
  5976. * Gantt with progress indicator
  5977. *
  5978. * @product gantt
  5979. * @apioption plotOptions.gantt.partialFill
  5980. */
  5981. /**
  5982. * In an X-range series, this option makes all points of the same Y-axis
  5983. * category the same color.
  5984. */
  5985. colorByPoint: true,
  5986. dataLabels: {
  5987. formatter: function () {
  5988. var point = this.point,
  5989. amount = point.partialFill;
  5990. if (isObject(amount)) {
  5991. amount = amount.amount;
  5992. }
  5993. if (isNumber(amount) && amount > 0) {
  5994. return correctFloat(amount * 100) + '%';
  5995. }
  5996. },
  5997. inside: true,
  5998. verticalAlign: 'middle'
  5999. },
  6000. tooltip: {
  6001. headerFormat: '<span style="font-size: 10px">{point.x} - {point.x2}</span><br/>',
  6002. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
  6003. },
  6004. borderRadius: 3,
  6005. pointRange: 0
  6006. }, {
  6007. type: 'xrange',
  6008. parallelArrays: ['x', 'x2', 'y'],
  6009. requireSorting: false,
  6010. animate: seriesTypes.line.prototype.animate,
  6011. cropShoulder: 1,
  6012. getExtremesFromAll: true,
  6013. autoIncrement: H.noop,
  6014. buildKDTree: H.noop,
  6015. /* eslint-disable valid-jsdoc */
  6016. /**
  6017. * @private
  6018. * @function Highcarts.seriesTypes.xrange#init
  6019. * @return {void}
  6020. */
  6021. init: function () {
  6022. seriesTypes.column.prototype.init.apply(this, arguments);
  6023. this.options.stacking = void 0; // #13161
  6024. },
  6025. /**
  6026. * Borrow the column series metrics, but with swapped axes. This gives
  6027. * free access to features like groupPadding, grouping, pointWidth etc.
  6028. *
  6029. * @private
  6030. * @function Highcharts.Series#getColumnMetrics
  6031. *
  6032. * @return {Highcharts.ColumnMetricsObject}
  6033. */
  6034. getColumnMetrics: function () {
  6035. var metrics,
  6036. chart = this.chart;
  6037. /**
  6038. * @private
  6039. */
  6040. function swapAxes() {
  6041. chart.series.forEach(function (s) {
  6042. var xAxis = s.xAxis;
  6043. s.xAxis = s.yAxis;
  6044. s.yAxis = xAxis;
  6045. });
  6046. }
  6047. swapAxes();
  6048. metrics = columnType.prototype.getColumnMetrics.call(this);
  6049. swapAxes();
  6050. return metrics;
  6051. },
  6052. /**
  6053. * Override cropData to show a point where x or x2 is outside visible
  6054. * range, but one of them is inside.
  6055. *
  6056. * @private
  6057. * @function Highcharts.Series#cropData
  6058. *
  6059. * @param {Array<number>} xData
  6060. *
  6061. * @param {Array<number>} yData
  6062. *
  6063. * @param {number} min
  6064. *
  6065. * @param {number} max
  6066. *
  6067. * @param {number} [cropShoulder]
  6068. *
  6069. * @return {*}
  6070. */
  6071. cropData: function (xData, yData, min, max) {
  6072. // Replace xData with x2Data to find the appropriate cropStart
  6073. var cropData = Series.prototype.cropData,
  6074. crop = cropData.call(this,
  6075. this.x2Data,
  6076. yData,
  6077. min,
  6078. max);
  6079. // Re-insert the cropped xData
  6080. crop.xData = xData.slice(crop.start, crop.end);
  6081. return crop;
  6082. },
  6083. /**
  6084. * Finds the index of an existing point that matches the given point
  6085. * options.
  6086. *
  6087. * @private
  6088. * @function Highcharts.Series#findPointIndex
  6089. * @param {object} options The options of the point.
  6090. * @returns {number|undefined} Returns index of a matching point,
  6091. * returns undefined if no match is found.
  6092. */
  6093. findPointIndex: function (options) {
  6094. var _a = this,
  6095. cropped = _a.cropped,
  6096. cropStart = _a.cropStart,
  6097. points = _a.points;
  6098. var id = options.id;
  6099. var pointIndex;
  6100. if (id) {
  6101. var point = find(points,
  6102. function (point) {
  6103. return point.id === id;
  6104. });
  6105. pointIndex = point ? point.index : void 0;
  6106. }
  6107. if (typeof pointIndex === 'undefined') {
  6108. var point = find(points,
  6109. function (point) {
  6110. return (point.x === options.x &&
  6111. point.x2 === options.x2 &&
  6112. !point.touched);
  6113. });
  6114. pointIndex = point ? point.index : void 0;
  6115. }
  6116. // Reduce pointIndex if data is cropped
  6117. if (cropped &&
  6118. isNumber(pointIndex) &&
  6119. isNumber(cropStart) &&
  6120. pointIndex >= cropStart) {
  6121. pointIndex -= cropStart;
  6122. }
  6123. return pointIndex;
  6124. },
  6125. /**
  6126. * @private
  6127. * @function Highcharts.Series#translatePoint
  6128. *
  6129. * @param {Highcharts.Point} point
  6130. */
  6131. translatePoint: function (point) {
  6132. var series = this,
  6133. xAxis = series.xAxis,
  6134. yAxis = series.yAxis,
  6135. metrics = series.columnMetrics,
  6136. options = series.options,
  6137. minPointLength = options.minPointLength || 0,
  6138. plotX = point.plotX,
  6139. posX = pick(point.x2,
  6140. point.x + (point.len || 0)),
  6141. plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
  6142. length = Math.abs(plotX2 - plotX),
  6143. widthDifference,
  6144. shapeArgs,
  6145. partialFill,
  6146. inverted = this.chart.inverted,
  6147. borderWidth = pick(options.borderWidth, 1),
  6148. crisper = borderWidth % 2 / 2,
  6149. yOffset = metrics.offset,
  6150. pointHeight = Math.round(metrics.width),
  6151. dlLeft,
  6152. dlRight,
  6153. dlWidth,
  6154. clipRectWidth,
  6155. tooltipYOffset;
  6156. if (minPointLength) {
  6157. widthDifference = minPointLength - length;
  6158. if (widthDifference < 0) {
  6159. widthDifference = 0;
  6160. }
  6161. plotX -= widthDifference / 2;
  6162. plotX2 += widthDifference / 2;
  6163. }
  6164. plotX = Math.max(plotX, -10);
  6165. plotX2 = clamp(plotX2, -10, xAxis.len + 10);
  6166. // Handle individual pointWidth
  6167. if (defined(point.options.pointWidth)) {
  6168. yOffset -= ((Math.ceil(point.options.pointWidth) - pointHeight) / 2);
  6169. pointHeight = Math.ceil(point.options.pointWidth);
  6170. }
  6171. // Apply pointPlacement to the Y axis
  6172. if (options.pointPlacement &&
  6173. isNumber(point.plotY) &&
  6174. yAxis.categories) {
  6175. point.plotY = yAxis.translate(point.y, 0, 1, 0, 1, options.pointPlacement);
  6176. }
  6177. point.shapeArgs = {
  6178. x: Math.floor(Math.min(plotX, plotX2)) + crisper,
  6179. y: Math.floor(point.plotY + yOffset) + crisper,
  6180. width: Math.round(Math.abs(plotX2 - plotX)),
  6181. height: pointHeight,
  6182. r: series.options.borderRadius
  6183. };
  6184. // Align data labels inside the shape and inside the plot area
  6185. dlLeft = point.shapeArgs.x;
  6186. dlRight = dlLeft + point.shapeArgs.width;
  6187. if (dlLeft < 0 || dlRight > xAxis.len) {
  6188. dlLeft = clamp(dlLeft, 0, xAxis.len);
  6189. dlRight = clamp(dlRight, 0, xAxis.len);
  6190. dlWidth = dlRight - dlLeft;
  6191. point.dlBox = merge(point.shapeArgs, {
  6192. x: dlLeft,
  6193. width: dlRight - dlLeft,
  6194. centerX: dlWidth ? dlWidth / 2 : null
  6195. });
  6196. }
  6197. else {
  6198. point.dlBox = null;
  6199. }
  6200. // Tooltip position
  6201. var tooltipPos = point.tooltipPos;
  6202. var xIndex = !inverted ? 0 : 1;
  6203. var yIndex = !inverted ? 1 : 0;
  6204. tooltipYOffset = series.columnMetrics ?
  6205. series.columnMetrics.offset : -metrics.width / 2;
  6206. // Limit position by the correct axis size (#9727)
  6207. tooltipPos[xIndex] = clamp(tooltipPos[xIndex] + ((!inverted ? 1 : -1) * (xAxis.reversed ? -1 : 1) *
  6208. (length / 2)), 0, xAxis.len - 1);
  6209. tooltipPos[yIndex] = clamp(tooltipPos[yIndex] + ((inverted ? -1 : 1) * tooltipYOffset), 0, yAxis.len - 1);
  6210. // Add a partShapeArgs to the point, based on the shapeArgs property
  6211. partialFill = point.partialFill;
  6212. if (partialFill) {
  6213. // Get the partial fill amount
  6214. if (isObject(partialFill)) {
  6215. partialFill = partialFill.amount;
  6216. }
  6217. // If it was not a number, assume 0
  6218. if (!isNumber(partialFill)) {
  6219. partialFill = 0;
  6220. }
  6221. shapeArgs = point.shapeArgs;
  6222. point.partShapeArgs = {
  6223. x: shapeArgs.x,
  6224. y: shapeArgs.y,
  6225. width: shapeArgs.width,
  6226. height: shapeArgs.height,
  6227. r: series.options.borderRadius
  6228. };
  6229. clipRectWidth = Math.max(Math.round(length * partialFill + point.plotX -
  6230. plotX), 0);
  6231. point.clipRectArgs = {
  6232. x: xAxis.reversed ? // #10717
  6233. shapeArgs.x + length - clipRectWidth :
  6234. shapeArgs.x,
  6235. y: shapeArgs.y,
  6236. width: clipRectWidth,
  6237. height: shapeArgs.height
  6238. };
  6239. }
  6240. },
  6241. /**
  6242. * @private
  6243. * @function Highcharts.Series#translate
  6244. */
  6245. translate: function () {
  6246. columnType.prototype.translate.apply(this, arguments);
  6247. this.points.forEach(function (point) {
  6248. this.translatePoint(point);
  6249. }, this);
  6250. },
  6251. /**
  6252. * Draws a single point in the series. Needed for partial fill.
  6253. *
  6254. * This override turns point.graphic into a group containing the
  6255. * original graphic and an overlay displaying the partial fill.
  6256. *
  6257. * @private
  6258. * @function Highcharts.Series#drawPoint
  6259. *
  6260. * @param {Highcharts.Point} point
  6261. * An instance of Point in the series.
  6262. *
  6263. * @param {"animate"|"attr"} verb
  6264. * 'animate' (animates changes) or 'attr' (sets options)
  6265. */
  6266. drawPoint: function (point, verb) {
  6267. var series = this,
  6268. seriesOpts = series.options,
  6269. renderer = series.chart.renderer,
  6270. graphic = point.graphic,
  6271. type = point.shapeType,
  6272. shapeArgs = point.shapeArgs,
  6273. partShapeArgs = point.partShapeArgs,
  6274. clipRectArgs = point.clipRectArgs,
  6275. pfOptions = point.partialFill,
  6276. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  6277. pointState = point.state,
  6278. stateOpts = (seriesOpts.states[pointState || 'normal'] ||
  6279. {}),
  6280. pointStateVerb = typeof pointState === 'undefined' ?
  6281. 'attr' : verb,
  6282. pointAttr = series.pointAttribs(point,
  6283. pointState),
  6284. animation = pick(series.chart.options.chart.animation,
  6285. stateOpts.animation),
  6286. fill;
  6287. if (!point.isNull && point.visible !== false) {
  6288. // Original graphic
  6289. if (graphic) { // update
  6290. graphic.rect[verb](shapeArgs);
  6291. }
  6292. else {
  6293. point.graphic = graphic = renderer.g('point')
  6294. .addClass(point.getClassName())
  6295. .add(point.group || series.group);
  6296. graphic.rect = renderer[type](merge(shapeArgs))
  6297. .addClass(point.getClassName())
  6298. .addClass('highcharts-partfill-original')
  6299. .add(graphic);
  6300. }
  6301. // Partial fill graphic
  6302. if (partShapeArgs) {
  6303. if (graphic.partRect) {
  6304. graphic.partRect[verb](merge(partShapeArgs));
  6305. graphic.partialClipRect[verb](merge(clipRectArgs));
  6306. }
  6307. else {
  6308. graphic.partialClipRect = renderer.clipRect(clipRectArgs.x, clipRectArgs.y, clipRectArgs.width, clipRectArgs.height);
  6309. graphic.partRect =
  6310. renderer[type](partShapeArgs)
  6311. .addClass('highcharts-partfill-overlay')
  6312. .add(graphic)
  6313. .clip(graphic.partialClipRect);
  6314. }
  6315. }
  6316. // Presentational
  6317. if (!series.chart.styledMode) {
  6318. graphic
  6319. .rect[verb](pointAttr, animation)
  6320. .shadow(seriesOpts.shadow, null, cutOff);
  6321. if (partShapeArgs) {
  6322. // Ensure pfOptions is an object
  6323. if (!isObject(pfOptions)) {
  6324. pfOptions = {};
  6325. }
  6326. if (isObject(seriesOpts.partialFill)) {
  6327. pfOptions = merge(pfOptions, seriesOpts.partialFill);
  6328. }
  6329. fill = (pfOptions.fill ||
  6330. color(pointAttr.fill).brighten(-0.3).get() ||
  6331. color(point.color || series.color)
  6332. .brighten(-0.3).get());
  6333. pointAttr.fill = fill;
  6334. graphic
  6335. .partRect[pointStateVerb](pointAttr, animation)
  6336. .shadow(seriesOpts.shadow, null, cutOff);
  6337. }
  6338. }
  6339. }
  6340. else if (graphic) {
  6341. point.graphic = graphic.destroy(); // #1269
  6342. }
  6343. },
  6344. /**
  6345. * @private
  6346. * @function Highcharts.Series#drawPoints
  6347. */
  6348. drawPoints: function () {
  6349. var series = this,
  6350. verb = series.getAnimationVerb();
  6351. // Draw the columns
  6352. series.points.forEach(function (point) {
  6353. series.drawPoint(point, verb);
  6354. });
  6355. },
  6356. /**
  6357. * Returns "animate", or "attr" if the number of points is above the
  6358. * animation limit.
  6359. *
  6360. * @private
  6361. * @function Highcharts.Series#getAnimationVerb
  6362. *
  6363. * @return {string}
  6364. */
  6365. getAnimationVerb: function () {
  6366. return (this.chart.pointCount < (this.options.animationLimit || 250) ?
  6367. 'animate' :
  6368. 'attr');
  6369. }
  6370. /*
  6371. // Override to remove stroke from points. For partial fill.
  6372. pointAttribs: function () {
  6373. var series = this,
  6374. retVal = columnType.prototype.pointAttribs
  6375. .apply(series,
  6376. arguments);
  6377. //retVal['stroke-width'] = 0;
  6378. return retVal;
  6379. }
  6380. //*/
  6381. /* eslint-enable valid-jsdoc */
  6382. }, {
  6383. /**
  6384. * The ending X value of the range point.
  6385. * @name Highcharts.Point#x2
  6386. * @type {number|undefined}
  6387. * @requires modules/xrange
  6388. */
  6389. /**
  6390. * Extend applyOptions so that `colorByPoint` for x-range means that one
  6391. * color is applied per Y axis category.
  6392. *
  6393. * @private
  6394. * @function Highcharts.Point#applyOptions
  6395. *
  6396. * @return {Highcharts.Series}
  6397. */
  6398. /* eslint-disable valid-jsdoc */
  6399. /**
  6400. * @private
  6401. */
  6402. resolveColor: function () {
  6403. var series = this.series,
  6404. colorByPoint;
  6405. if (series.options.colorByPoint && !this.options.color) {
  6406. colorByPoint = getColorByCategory(series, this);
  6407. if (!series.chart.styledMode) {
  6408. this.color = colorByPoint.color;
  6409. }
  6410. if (!this.options.colorIndex) {
  6411. this.colorIndex = colorByPoint.colorIndex;
  6412. }
  6413. }
  6414. else if (!this.color) {
  6415. this.color = series.color;
  6416. }
  6417. },
  6418. /**
  6419. * Extend init to have y default to 0.
  6420. *
  6421. * @private
  6422. * @function Highcharts.Point#init
  6423. *
  6424. * @return {Highcharts.Point}
  6425. */
  6426. init: function () {
  6427. Point.prototype.init.apply(this, arguments);
  6428. if (!this.y) {
  6429. this.y = 0;
  6430. }
  6431. return this;
  6432. },
  6433. /**
  6434. * @private
  6435. * @function Highcharts.Point#setState
  6436. */
  6437. setState: function () {
  6438. Point.prototype.setState.apply(this, arguments);
  6439. this.series.drawPoint(this, this.series.getAnimationVerb());
  6440. },
  6441. /**
  6442. * @private
  6443. * @function Highcharts.Point#getLabelConfig
  6444. *
  6445. * @return {Highcharts.PointLabelObject}
  6446. */
  6447. // Add x2 and yCategory to the available properties for tooltip formats
  6448. getLabelConfig: function () {
  6449. var point = this,
  6450. cfg = Point.prototype.getLabelConfig.call(point),
  6451. yCats = point.series.yAxis.categories;
  6452. cfg.x2 = point.x2;
  6453. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  6454. return cfg;
  6455. },
  6456. tooltipDateKeys: ['x', 'x2'],
  6457. /**
  6458. * @private
  6459. * @function Highcharts.Point#isValid
  6460. *
  6461. * @return {boolean}
  6462. */
  6463. isValid: function () {
  6464. return typeof this.x === 'number' &&
  6465. typeof this.x2 === 'number';
  6466. }
  6467. /* eslint-enable valid-jsdoc */
  6468. });
  6469. /**
  6470. * Max x2 should be considered in xAxis extremes
  6471. */
  6472. addEvent(Axis, 'afterGetSeriesExtremes', function () {
  6473. var axis = this, // eslint-disable-line no-invalid-this
  6474. axisSeries = axis.series,
  6475. dataMax,
  6476. modMax;
  6477. if (axis.isXAxis) {
  6478. dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
  6479. axisSeries.forEach(function (series) {
  6480. if (series.x2Data) {
  6481. series.x2Data
  6482. .forEach(function (val) {
  6483. if (val > dataMax) {
  6484. dataMax = val;
  6485. modMax = true;
  6486. }
  6487. });
  6488. }
  6489. });
  6490. if (modMax) {
  6491. axis.dataMax = dataMax;
  6492. }
  6493. }
  6494. });
  6495. /**
  6496. * An `xrange` series. If the [type](#series.xrange.type) option is not
  6497. * specified, it is inherited from [chart.type](#chart.type).
  6498. *
  6499. * @extends series,plotOptions.xrange
  6500. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor, edgeWidth,
  6501. * findNearestPointBy, getExtremesFromAll, negativeColor,
  6502. * pointInterval, pointIntervalUnit, pointPlacement, pointRange,
  6503. * pointStart, softThreshold, stacking, threshold, dataSorting,
  6504. * boostBlending
  6505. * @product highcharts highstock gantt
  6506. * @requires modules/xrange
  6507. * @apioption series.xrange
  6508. */
  6509. /**
  6510. * An array of data points for the series. For the `xrange` series type,
  6511. * points can be given in the following ways:
  6512. *
  6513. * 1. An array of objects with named values. The objects are point configuration
  6514. * objects as seen below.
  6515. * ```js
  6516. * data: [{
  6517. * x: Date.UTC(2017, 0, 1),
  6518. * x2: Date.UTC(2017, 0, 3),
  6519. * name: "Test",
  6520. * y: 0,
  6521. * color: "#00FF00"
  6522. * }, {
  6523. * x: Date.UTC(2017, 0, 4),
  6524. * x2: Date.UTC(2017, 0, 5),
  6525. * name: "Deploy",
  6526. * y: 1,
  6527. * color: "#FF0000"
  6528. * }]
  6529. * ```
  6530. *
  6531. * @sample {highcharts} highcharts/series/data-array-of-objects/
  6532. * Config objects
  6533. *
  6534. * @declare Highcharts.XrangePointOptionsObject
  6535. * @type {Array<*>}
  6536. * @extends series.line.data
  6537. * @product highcharts highstock gantt
  6538. * @apioption series.xrange.data
  6539. */
  6540. /**
  6541. * The starting X value of the range point.
  6542. *
  6543. * @sample {highcharts} highcharts/demo/x-range
  6544. * X-range
  6545. *
  6546. * @type {number}
  6547. * @product highcharts highstock gantt
  6548. * @apioption series.xrange.data.x
  6549. */
  6550. /**
  6551. * The ending X value of the range point.
  6552. *
  6553. * @sample {highcharts} highcharts/demo/x-range
  6554. * X-range
  6555. *
  6556. * @type {number}
  6557. * @product highcharts highstock gantt
  6558. * @apioption series.xrange.data.x2
  6559. */
  6560. /**
  6561. * The Y value of the range point.
  6562. *
  6563. * @sample {highcharts} highcharts/demo/x-range
  6564. * X-range
  6565. *
  6566. * @type {number}
  6567. * @product highcharts highstock gantt
  6568. * @apioption series.xrange.data.y
  6569. */
  6570. /**
  6571. * A partial fill for each point, typically used to visualize how much of
  6572. * a task is performed. The partial fill object can be set either on series
  6573. * or point level.
  6574. *
  6575. * @sample {highcharts} highcharts/demo/x-range
  6576. * X-range with partial fill
  6577. *
  6578. * @declare Highcharts.XrangePointPartialFillOptionsObject
  6579. * @product highcharts highstock gantt
  6580. * @apioption series.xrange.data.partialFill
  6581. */
  6582. /**
  6583. * The amount of the X-range point to be filled. Values can be 0-1 and are
  6584. * converted to percentages in the default data label formatter.
  6585. *
  6586. * @type {number}
  6587. * @product highcharts highstock gantt
  6588. * @apioption series.xrange.data.partialFill.amount
  6589. */
  6590. /**
  6591. * The fill color to be used for partial fills. Defaults to a darker shade
  6592. * of the point color.
  6593. *
  6594. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  6595. * @product highcharts highstock gantt
  6596. * @apioption series.xrange.data.partialFill.fill
  6597. */
  6598. ''; // adds doclets above to transpiled file
  6599. });
  6600. _registerModule(_modules, 'Series/GanttSeries.js', [_modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Utilities.js']], function (H, O, U) {
  6601. /* *
  6602. *
  6603. * (c) 2016-2020 Highsoft AS
  6604. *
  6605. * Author: Lars A. V. Cabrera
  6606. *
  6607. * License: www.highcharts.com/license
  6608. *
  6609. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6610. *
  6611. * */
  6612. var dateFormat = O.dateFormat;
  6613. var isNumber = U.isNumber,
  6614. merge = U.merge,
  6615. pick = U.pick,
  6616. seriesType = U.seriesType,
  6617. splat = U.splat;
  6618. var seriesTypes = H.seriesTypes,
  6619. Series = H.Series,
  6620. parent = seriesTypes.xrange;
  6621. /**
  6622. * @private
  6623. * @class
  6624. * @name Highcharts.seriesTypes.gantt
  6625. *
  6626. * @augments Highcharts.Series
  6627. */
  6628. seriesType('gantt', 'xrange'
  6629. /**
  6630. * A `gantt` series. If the [type](#series.gantt.type) option is not specified,
  6631. * it is inherited from [chart.type](#chart.type).
  6632. *
  6633. * @extends plotOptions.xrange
  6634. * @product gantt
  6635. * @requires highcharts-gantt
  6636. * @optionparent plotOptions.gantt
  6637. */
  6638. , {
  6639. // options - default options merged with parent
  6640. grouping: false,
  6641. dataLabels: {
  6642. enabled: true
  6643. },
  6644. tooltip: {
  6645. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  6646. pointFormat: null,
  6647. pointFormatter: function () {
  6648. var point = this,
  6649. series = point.series,
  6650. tooltip = series.chart.tooltip,
  6651. xAxis = series.xAxis,
  6652. formats = series.tooltipOptions.dateTimeLabelFormats,
  6653. startOfWeek = xAxis.options.startOfWeek,
  6654. ttOptions = series.tooltipOptions,
  6655. format = ttOptions.xDateFormat,
  6656. start,
  6657. end,
  6658. milestone = point.options.milestone,
  6659. retVal = '<b>' + (point.name || point.yCategory) + '</b>';
  6660. if (ttOptions.pointFormat) {
  6661. return point.tooltipFormatter(ttOptions.pointFormat);
  6662. }
  6663. if (!format) {
  6664. format = splat(tooltip.getDateFormat(xAxis.closestPointRange, point.start, startOfWeek, formats))[0];
  6665. }
  6666. start = dateFormat(format, point.start);
  6667. end = dateFormat(format, point.end);
  6668. retVal += '<br/>';
  6669. if (!milestone) {
  6670. retVal += 'Start: ' + start + '<br/>';
  6671. retVal += 'End: ' + end + '<br/>';
  6672. }
  6673. else {
  6674. retVal += start + '<br/>';
  6675. }
  6676. return retVal;
  6677. }
  6678. },
  6679. connectors: {
  6680. type: 'simpleConnect',
  6681. /**
  6682. * @declare Highcharts.ConnectorsAnimationOptionsObject
  6683. */
  6684. animation: {
  6685. reversed: true // Dependencies go from child to parent
  6686. },
  6687. startMarker: {
  6688. enabled: true,
  6689. symbol: 'arrow-filled',
  6690. radius: 4,
  6691. fill: '#fa0',
  6692. align: 'left'
  6693. },
  6694. endMarker: {
  6695. enabled: false,
  6696. align: 'right'
  6697. }
  6698. }
  6699. }, {
  6700. pointArrayMap: ['start', 'end', 'y'],
  6701. // Keyboard navigation, don't use nearest vertical mode
  6702. keyboardMoveVertical: false,
  6703. /* eslint-disable valid-jsdoc */
  6704. /**
  6705. * Handle milestones, as they have no x2.
  6706. * @private
  6707. */
  6708. translatePoint: function (point) {
  6709. var series = this,
  6710. shapeArgs,
  6711. size;
  6712. parent.prototype.translatePoint.call(series, point);
  6713. if (point.options.milestone) {
  6714. shapeArgs = point.shapeArgs;
  6715. size = shapeArgs.height;
  6716. point.shapeArgs = {
  6717. x: shapeArgs.x - (size / 2),
  6718. y: shapeArgs.y,
  6719. width: size,
  6720. height: size
  6721. };
  6722. }
  6723. },
  6724. /**
  6725. * Draws a single point in the series.
  6726. *
  6727. * This override draws the point as a diamond if point.options.milestone
  6728. * is true, and uses the original drawPoint() if it is false or not set.
  6729. *
  6730. * @requires highcharts-gantt
  6731. *
  6732. * @private
  6733. * @function Highcharts.seriesTypes.gantt#drawPoint
  6734. *
  6735. * @param {Highcharts.Point} point
  6736. * An instance of Point in the series
  6737. *
  6738. * @param {"animate"|"attr"} verb
  6739. * 'animate' (animates changes) or 'attr' (sets options)
  6740. *
  6741. * @return {void}
  6742. */
  6743. drawPoint: function (point, verb) {
  6744. var series = this,
  6745. seriesOpts = series.options,
  6746. renderer = series.chart.renderer,
  6747. shapeArgs = point.shapeArgs,
  6748. plotY = point.plotY,
  6749. graphic = point.graphic,
  6750. state = point.selected && 'select',
  6751. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  6752. diamondShape;
  6753. if (point.options.milestone) {
  6754. if (isNumber(plotY) && point.y !== null && point.visible !== false) {
  6755. diamondShape = renderer.symbols.diamond(shapeArgs.x, shapeArgs.y, shapeArgs.width, shapeArgs.height);
  6756. if (graphic) {
  6757. graphic[verb]({
  6758. d: diamondShape
  6759. });
  6760. }
  6761. else {
  6762. point.graphic = graphic = renderer.path(diamondShape)
  6763. .addClass(point.getClassName(), true)
  6764. .add(point.group || series.group);
  6765. }
  6766. // Presentational
  6767. if (!series.chart.styledMode) {
  6768. point.graphic
  6769. .attr(series.pointAttribs(point, state))
  6770. .shadow(seriesOpts.shadow, null, cutOff);
  6771. }
  6772. }
  6773. else if (graphic) {
  6774. point.graphic = graphic.destroy(); // #1269
  6775. }
  6776. }
  6777. else {
  6778. parent.prototype.drawPoint.call(series, point, verb);
  6779. }
  6780. },
  6781. setData: Series.prototype.setData,
  6782. /**
  6783. * @private
  6784. */
  6785. setGanttPointAliases: function (options) {
  6786. /**
  6787. * Add a value to options if the value exists.
  6788. * @private
  6789. */
  6790. function addIfExists(prop, val) {
  6791. if (typeof val !== 'undefined') {
  6792. options[prop] = val;
  6793. }
  6794. }
  6795. addIfExists('x', pick(options.start, options.x));
  6796. addIfExists('x2', pick(options.end, options.x2));
  6797. addIfExists('partialFill', pick(options.completed, options.partialFill));
  6798. addIfExists('connect', pick(options.dependency, options.connect));
  6799. }
  6800. /* eslint-enable valid-jsdoc */
  6801. }, merge(parent.prototype.pointClass.prototype, {
  6802. // pointProps - point member overrides. We inherit from parent as well.
  6803. /* eslint-disable valid-jsdoc */
  6804. /**
  6805. * Applies the options containing the x and y data and possible some
  6806. * extra properties. This is called on point init or from point.update.
  6807. *
  6808. * @private
  6809. * @function Highcharts.Point#applyOptions
  6810. *
  6811. * @param {object} options
  6812. * The point options
  6813. *
  6814. * @param {number} x
  6815. * The x value
  6816. *
  6817. * @return {Highcharts.Point}
  6818. * The Point instance
  6819. */
  6820. applyOptions: function (options, x) {
  6821. var point = this,
  6822. retVal = merge(options);
  6823. H.seriesTypes.gantt.prototype.setGanttPointAliases(retVal);
  6824. retVal = parent.prototype.pointClass.prototype.applyOptions
  6825. .call(point, retVal, x);
  6826. return retVal;
  6827. },
  6828. isValid: function () {
  6829. return ((typeof this.start === 'number' ||
  6830. typeof this.x === 'number') &&
  6831. (typeof this.end === 'number' ||
  6832. typeof this.x2 === 'number' ||
  6833. this.milestone));
  6834. }
  6835. /* eslint-enable valid-jsdoc */
  6836. }));
  6837. /**
  6838. * A `gantt` series.
  6839. *
  6840. * @extends series,plotOptions.gantt
  6841. * @excluding boostThreshold, connectors, dashStyle, findNearestPointBy,
  6842. * getExtremesFromAll, marker, negativeColor, pointInterval,
  6843. * pointIntervalUnit, pointPlacement, pointStart
  6844. * @product gantt
  6845. * @requires highcharts-gantt
  6846. * @apioption series.gantt
  6847. */
  6848. /**
  6849. * Data for a Gantt series.
  6850. *
  6851. * @declare Highcharts.GanttPointOptionsObject
  6852. * @type {Array<*>}
  6853. * @extends series.xrange.data
  6854. * @excluding className, color, colorIndex, connect, dataLabels, events,
  6855. * partialFill, selected, x, x2
  6856. * @product gantt
  6857. * @apioption series.gantt.data
  6858. */
  6859. /**
  6860. * Whether the grid node belonging to this point should start as collapsed. Used
  6861. * in axes of type treegrid.
  6862. *
  6863. * @sample {gantt} gantt/treegrid-axis/collapsed/
  6864. * Start as collapsed
  6865. *
  6866. * @type {boolean}
  6867. * @default false
  6868. * @product gantt
  6869. * @apioption series.gantt.data.collapsed
  6870. */
  6871. /**
  6872. * The start time of a task.
  6873. *
  6874. * @type {number}
  6875. * @product gantt
  6876. * @apioption series.gantt.data.start
  6877. */
  6878. /**
  6879. * The end time of a task.
  6880. *
  6881. * @type {number}
  6882. * @product gantt
  6883. * @apioption series.gantt.data.end
  6884. */
  6885. /**
  6886. * The Y value of a task.
  6887. *
  6888. * @type {number}
  6889. * @product gantt
  6890. * @apioption series.gantt.data.y
  6891. */
  6892. /**
  6893. * The name of a task. If a `treegrid` y-axis is used (default in Gantt charts),
  6894. * this will be picked up automatically, and used to calculate the y-value.
  6895. *
  6896. * @type {string}
  6897. * @product gantt
  6898. * @apioption series.gantt.data.name
  6899. */
  6900. /**
  6901. * Progress indicator, how much of the task completed. If it is a number, the
  6902. * `fill` will be applied automatically.
  6903. *
  6904. * @sample {gantt} gantt/demo/progress-indicator
  6905. * Progress indicator
  6906. *
  6907. * @type {number|*}
  6908. * @extends series.xrange.data.partialFill
  6909. * @product gantt
  6910. * @apioption series.gantt.data.completed
  6911. */
  6912. /**
  6913. * The amount of the progress indicator, ranging from 0 (not started) to 1
  6914. * (finished).
  6915. *
  6916. * @type {number}
  6917. * @default 0
  6918. * @apioption series.gantt.data.completed.amount
  6919. */
  6920. /**
  6921. * The fill of the progress indicator. Defaults to a darkened variety of the
  6922. * main color.
  6923. *
  6924. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  6925. * @apioption series.gantt.data.completed.fill
  6926. */
  6927. /**
  6928. * The ID of the point (task) that this point depends on in Gantt charts.
  6929. * Aliases [connect](series.xrange.data.connect). Can also be an object,
  6930. * specifying further connecting [options](series.gantt.connectors) between the
  6931. * points. Multiple connections can be specified by providing an array.
  6932. *
  6933. * @sample gantt/demo/project-management
  6934. * Dependencies
  6935. * @sample gantt/pathfinder/demo
  6936. * Different connection types
  6937. *
  6938. * @type {string|Array<string|*>|*}
  6939. * @extends series.xrange.data.connect
  6940. * @since 6.2.0
  6941. * @product gantt
  6942. * @apioption series.gantt.data.dependency
  6943. */
  6944. /**
  6945. * Whether this point is a milestone. If so, only the `start` option is handled,
  6946. * while `end` is ignored.
  6947. *
  6948. * @sample gantt/gantt/milestones
  6949. * Milestones
  6950. *
  6951. * @type {boolean}
  6952. * @since 6.2.0
  6953. * @product gantt
  6954. * @apioption series.gantt.data.milestone
  6955. */
  6956. /**
  6957. * The ID of the parent point (task) of this point in Gantt charts.
  6958. *
  6959. * @sample gantt/demo/subtasks
  6960. * Gantt chart with subtasks
  6961. *
  6962. * @type {string}
  6963. * @since 6.2.0
  6964. * @product gantt
  6965. * @apioption series.gantt.data.parent
  6966. */
  6967. /**
  6968. * @excluding afterAnimate
  6969. * @apioption series.gantt.events
  6970. */
  6971. ''; // adds doclets above to the transpiled file
  6972. });
  6973. _registerModule(_modules, 'Core/Chart/GanttChart.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Chart, H, U) {
  6974. /* *
  6975. *
  6976. * (c) 2016-2020 Highsoft AS
  6977. *
  6978. * Author: Lars A. V. Cabrera
  6979. *
  6980. * License: www.highcharts.com/license
  6981. *
  6982. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6983. *
  6984. * */
  6985. var getOptions = U.getOptions,
  6986. isArray = U.isArray,
  6987. merge = U.merge,
  6988. splat = U.splat;
  6989. /**
  6990. * Factory function for Gantt charts.
  6991. *
  6992. * @example
  6993. * // Render a chart in to div#container
  6994. * var chart = Highcharts.ganttChart('container', {
  6995. * title: {
  6996. * text: 'My chart'
  6997. * },
  6998. * series: [{
  6999. * data: ...
  7000. * }]
  7001. * });
  7002. *
  7003. * @function Highcharts.ganttChart
  7004. *
  7005. * @param {string|Highcharts.HTMLDOMElement} renderTo
  7006. * The DOM element to render to, or its id.
  7007. *
  7008. * @param {Highcharts.Options} options
  7009. * The chart options structure.
  7010. *
  7011. * @param {Highcharts.ChartCallbackFunction} [callback]
  7012. * Function to run when the chart has loaded and and all external images
  7013. * are loaded. Defining a
  7014. * [chart.events.load](https://api.highcharts.com/highcharts/chart.events.load)
  7015. * handler is equivalent.
  7016. *
  7017. * @return {Highcharts.Chart}
  7018. * Returns the Chart object.
  7019. */
  7020. H.ganttChart = function (renderTo, options, callback) {
  7021. var hasRenderToArg = typeof renderTo === 'string' || renderTo.nodeName,
  7022. seriesOptions = options.series,
  7023. defaultOptions = getOptions(),
  7024. defaultLinkedTo,
  7025. userOptions = options;
  7026. options = arguments[hasRenderToArg ? 1 : 0];
  7027. // If user hasn't defined axes as array, make it into an array and add a
  7028. // second axis by default.
  7029. if (!isArray(options.xAxis)) {
  7030. options.xAxis = [options.xAxis || {}, {}];
  7031. }
  7032. // apply X axis options to both single and multi x axes
  7033. options.xAxis = options.xAxis.map(function (xAxisOptions, i) {
  7034. if (i === 1) { // Second xAxis
  7035. defaultLinkedTo = 0;
  7036. }
  7037. return merge(defaultOptions.xAxis, {
  7038. grid: {
  7039. enabled: true
  7040. },
  7041. opposite: true,
  7042. linkedTo: defaultLinkedTo
  7043. }, xAxisOptions, // user options
  7044. {
  7045. type: 'datetime'
  7046. });
  7047. });
  7048. // apply Y axis options to both single and multi y axes
  7049. options.yAxis = (splat(options.yAxis || {})).map(function (yAxisOptions) {
  7050. return merge(defaultOptions.yAxis, // #3802
  7051. {
  7052. grid: {
  7053. enabled: true
  7054. },
  7055. staticScale: 50,
  7056. reversed: true,
  7057. // Set default type treegrid, but only if 'categories' is
  7058. // undefined
  7059. type: yAxisOptions.categories ? yAxisOptions.type : 'treegrid'
  7060. }, yAxisOptions // user options
  7061. );
  7062. });
  7063. options.series = null;
  7064. options = merge(true, {
  7065. chart: {
  7066. type: 'gantt'
  7067. },
  7068. title: {
  7069. text: null
  7070. },
  7071. legend: {
  7072. enabled: false
  7073. },
  7074. navigator: {
  7075. series: { type: 'gantt' }
  7076. }
  7077. }, options, // user's options
  7078. // forced options
  7079. {
  7080. isGantt: true
  7081. });
  7082. options.series = userOptions.series = seriesOptions;
  7083. (options.series || []).forEach(function (series) {
  7084. if (series.data) {
  7085. series.data.forEach(function (point) {
  7086. H.seriesTypes.gantt.prototype.setGanttPointAliases(point);
  7087. });
  7088. }
  7089. });
  7090. return hasRenderToArg ?
  7091. new Chart(renderTo, options, callback) :
  7092. new Chart(options, options); // @todo does not look correct
  7093. };
  7094. });
  7095. _registerModule(_modules, 'Core/Axis/ScrollbarAxis.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  7096. /* *
  7097. *
  7098. * (c) 2010-2020 Torstein Honsi
  7099. *
  7100. * License: www.highcharts.com/license
  7101. *
  7102. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7103. *
  7104. * */
  7105. var addEvent = U.addEvent,
  7106. defined = U.defined,
  7107. pick = U.pick;
  7108. /* eslint-disable no-invalid-this, valid-jsdoc */
  7109. /**
  7110. * Creates scrollbars if enabled.
  7111. *
  7112. * @private
  7113. */
  7114. var ScrollbarAxis = /** @class */ (function () {
  7115. function ScrollbarAxis() {
  7116. }
  7117. /**
  7118. * Attaches to axis events to create scrollbars if enabled.
  7119. *
  7120. * @private
  7121. *
  7122. * @param AxisClass
  7123. * Axis class to extend.
  7124. *
  7125. * @param ScrollbarClass
  7126. * Scrollbar class to use.
  7127. */
  7128. ScrollbarAxis.compose = function (AxisClass, ScrollbarClass) {
  7129. // Wrap axis initialization and create scrollbar if enabled:
  7130. addEvent(AxisClass, 'afterInit', function () {
  7131. var axis = this;
  7132. if (axis.options &&
  7133. axis.options.scrollbar &&
  7134. axis.options.scrollbar.enabled) {
  7135. // Predefined options:
  7136. axis.options.scrollbar.vertical = !axis.horiz;
  7137. axis.options.startOnTick = axis.options.endOnTick = false;
  7138. axis.scrollbar = new ScrollbarClass(axis.chart.renderer, axis.options.scrollbar, axis.chart);
  7139. addEvent(axis.scrollbar, 'changed', function (e) {
  7140. var axisMin = pick(axis.options && axis.options.min,
  7141. axis.min),
  7142. axisMax = pick(axis.options && axis.options.max,
  7143. axis.max),
  7144. unitedMin = defined(axis.dataMin) ?
  7145. Math.min(axisMin,
  7146. axis.min,
  7147. axis.dataMin) : axisMin,
  7148. unitedMax = defined(axis.dataMax) ?
  7149. Math.max(axisMax,
  7150. axis.max,
  7151. axis.dataMax) : axisMax,
  7152. range = unitedMax - unitedMin,
  7153. to,
  7154. from;
  7155. // #12834, scroll when show/hide series, wrong extremes
  7156. if (!defined(axisMin) || !defined(axisMax)) {
  7157. return;
  7158. }
  7159. if ((axis.horiz && !axis.reversed) ||
  7160. (!axis.horiz && axis.reversed)) {
  7161. to = unitedMin + range * this.to;
  7162. from = unitedMin + range * this.from;
  7163. }
  7164. else {
  7165. // y-values in browser are reversed, but this also
  7166. // applies for reversed horizontal axis:
  7167. to = unitedMin + range * (1 - this.from);
  7168. from = unitedMin + range * (1 - this.to);
  7169. }
  7170. if (pick(this.options.liveRedraw, H.svg && !H.isTouchDevice && !this.chart.isBoosting) ||
  7171. // Mouseup always should change extremes
  7172. e.DOMType === 'mouseup' ||
  7173. // Internal events
  7174. !defined(e.DOMType)) {
  7175. axis.setExtremes(from, to, true, e.DOMType !== 'mousemove', e);
  7176. }
  7177. else {
  7178. // When live redraw is disabled, don't change extremes
  7179. // Only change the position of the scollbar thumb
  7180. this.setRange(this.from, this.to);
  7181. }
  7182. });
  7183. }
  7184. });
  7185. // Wrap rendering axis, and update scrollbar if one is created:
  7186. addEvent(AxisClass, 'afterRender', function () {
  7187. var axis = this,
  7188. scrollMin = Math.min(pick(axis.options.min,
  7189. axis.min),
  7190. axis.min,
  7191. pick(axis.dataMin,
  7192. axis.min) // #6930
  7193. ),
  7194. scrollMax = Math.max(pick(axis.options.max,
  7195. axis.max),
  7196. axis.max,
  7197. pick(axis.dataMax,
  7198. axis.max) // #6930
  7199. ),
  7200. scrollbar = axis.scrollbar,
  7201. offset = axis.axisTitleMargin + (axis.titleOffset || 0),
  7202. scrollbarsOffsets = axis.chart.scrollbarsOffsets,
  7203. axisMargin = axis.options.margin || 0,
  7204. offsetsIndex,
  7205. from,
  7206. to;
  7207. if (scrollbar) {
  7208. if (axis.horiz) {
  7209. // Reserve space for labels/title
  7210. if (!axis.opposite) {
  7211. scrollbarsOffsets[1] += offset;
  7212. }
  7213. scrollbar.position(axis.left, axis.top + axis.height + 2 + scrollbarsOffsets[1] -
  7214. (axis.opposite ? axisMargin : 0), axis.width, axis.height);
  7215. // Next scrollbar should reserve space for margin (if set)
  7216. if (!axis.opposite) {
  7217. scrollbarsOffsets[1] += axisMargin;
  7218. }
  7219. offsetsIndex = 1;
  7220. }
  7221. else {
  7222. // Reserve space for labels/title
  7223. if (axis.opposite) {
  7224. scrollbarsOffsets[0] += offset;
  7225. }
  7226. scrollbar.position(axis.left + axis.width + 2 + scrollbarsOffsets[0] -
  7227. (axis.opposite ? 0 : axisMargin), axis.top, axis.width, axis.height);
  7228. // Next scrollbar should reserve space for margin (if set)
  7229. if (axis.opposite) {
  7230. scrollbarsOffsets[0] += axisMargin;
  7231. }
  7232. offsetsIndex = 0;
  7233. }
  7234. scrollbarsOffsets[offsetsIndex] += scrollbar.size +
  7235. scrollbar.options.margin;
  7236. if (isNaN(scrollMin) ||
  7237. isNaN(scrollMax) ||
  7238. !defined(axis.min) ||
  7239. !defined(axis.max) ||
  7240. axis.min === axis.max // #10733
  7241. ) {
  7242. // default action: when extremes are the same or there is
  7243. // not extremes on the axis, but scrollbar exists, make it
  7244. // full size
  7245. scrollbar.setRange(0, 1);
  7246. }
  7247. else {
  7248. from =
  7249. (axis.min - scrollMin) / (scrollMax - scrollMin);
  7250. to =
  7251. (axis.max - scrollMin) / (scrollMax - scrollMin);
  7252. if ((axis.horiz && !axis.reversed) ||
  7253. (!axis.horiz && axis.reversed)) {
  7254. scrollbar.setRange(from, to);
  7255. }
  7256. else {
  7257. // inverse vertical axis
  7258. scrollbar.setRange(1 - to, 1 - from);
  7259. }
  7260. }
  7261. }
  7262. });
  7263. // Make space for a scrollbar:
  7264. addEvent(AxisClass, 'afterGetOffset', function () {
  7265. var axis = this,
  7266. index = axis.horiz ? 2 : 1,
  7267. scrollbar = axis.scrollbar;
  7268. if (scrollbar) {
  7269. axis.chart.scrollbarsOffsets = [0, 0]; // reset scrollbars offsets
  7270. axis.chart.axisOffset[index] +=
  7271. scrollbar.size + scrollbar.options.margin;
  7272. }
  7273. });
  7274. };
  7275. return ScrollbarAxis;
  7276. }());
  7277. return ScrollbarAxis;
  7278. });
  7279. _registerModule(_modules, 'Core/Scrollbar.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Globals.js'], _modules['Core/Axis/ScrollbarAxis.js'], _modules['Core/Utilities.js'], _modules['Core/Options.js']], function (Axis, H, ScrollbarAxis, U, O) {
  7280. /* *
  7281. *
  7282. * (c) 2010-2020 Torstein Honsi
  7283. *
  7284. * License: www.highcharts.com/license
  7285. *
  7286. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7287. *
  7288. * */
  7289. var addEvent = U.addEvent,
  7290. correctFloat = U.correctFloat,
  7291. defined = U.defined,
  7292. destroyObjectProperties = U.destroyObjectProperties,
  7293. fireEvent = U.fireEvent,
  7294. merge = U.merge,
  7295. pick = U.pick,
  7296. removeEvent = U.removeEvent;
  7297. var defaultOptions = O.defaultOptions;
  7298. var hasTouch = H.hasTouch,
  7299. isTouchDevice = H.isTouchDevice;
  7300. /**
  7301. * When we have vertical scrollbar, rifles and arrow in buttons should be
  7302. * rotated. The same method is used in Navigator's handles, to rotate them.
  7303. *
  7304. * @function Highcharts.swapXY
  7305. *
  7306. * @param {Highcharts.SVGPathArray} path
  7307. * Path to be rotated.
  7308. *
  7309. * @param {boolean} [vertical]
  7310. * If vertical scrollbar, swap x-y values.
  7311. *
  7312. * @return {Highcharts.SVGPathArray}
  7313. * Rotated path.
  7314. *
  7315. * @requires modules/stock
  7316. */
  7317. var swapXY = H.swapXY = function (path,
  7318. vertical) {
  7319. if (vertical) {
  7320. path.forEach(function (seg) {
  7321. var len = seg.length;
  7322. var temp;
  7323. for (var i = 0; i < len; i += 2) {
  7324. temp = seg[i + 1];
  7325. if (typeof temp === 'number') {
  7326. seg[i + 1] = seg[i + 2];
  7327. seg[i + 2] = temp;
  7328. }
  7329. }
  7330. });
  7331. }
  7332. return path;
  7333. };
  7334. /* eslint-disable no-invalid-this, valid-jsdoc */
  7335. /**
  7336. * A reusable scrollbar, internally used in Highstock's navigator and optionally
  7337. * on individual axes.
  7338. *
  7339. * @private
  7340. * @class
  7341. * @name Highcharts.Scrollbar
  7342. * @param {Highcharts.SVGRenderer} renderer
  7343. * @param {Highcharts.ScrollbarOptions} options
  7344. * @param {Highcharts.Chart} chart
  7345. */
  7346. var Scrollbar = /** @class */ (function () {
  7347. /* *
  7348. *
  7349. * Constructors
  7350. *
  7351. * */
  7352. function Scrollbar(renderer, options, chart) {
  7353. /* *
  7354. *
  7355. * Properties
  7356. *
  7357. * */
  7358. this._events = [];
  7359. this.chartX = 0;
  7360. this.chartY = 0;
  7361. this.from = 0;
  7362. this.group = void 0;
  7363. this.scrollbar = void 0;
  7364. this.scrollbarButtons = [];
  7365. this.scrollbarGroup = void 0;
  7366. this.scrollbarLeft = 0;
  7367. this.scrollbarRifles = void 0;
  7368. this.scrollbarStrokeWidth = 1;
  7369. this.scrollbarTop = 0;
  7370. this.size = 0;
  7371. this.to = 0;
  7372. this.track = void 0;
  7373. this.trackBorderWidth = 1;
  7374. this.userOptions = {};
  7375. this.x = 0;
  7376. this.y = 0;
  7377. this.chart = chart;
  7378. this.options = options;
  7379. this.renderer = chart.renderer;
  7380. this.init(renderer, options, chart);
  7381. }
  7382. /* *
  7383. *
  7384. * Functions
  7385. *
  7386. * */
  7387. /**
  7388. * Set up the mouse and touch events for the Scrollbar
  7389. *
  7390. * @private
  7391. * @function Highcharts.Scrollbar#addEvents
  7392. * @return {void}
  7393. */
  7394. Scrollbar.prototype.addEvents = function () {
  7395. var buttonsOrder = this.options.inverted ? [1, 0] : [0, 1],
  7396. buttons = this.scrollbarButtons,
  7397. bar = this.scrollbarGroup.element,
  7398. track = this.track.element,
  7399. mouseDownHandler = this.mouseDownHandler.bind(this),
  7400. mouseMoveHandler = this.mouseMoveHandler.bind(this),
  7401. mouseUpHandler = this.mouseUpHandler.bind(this),
  7402. _events;
  7403. // Mouse events
  7404. _events = [
  7405. [buttons[buttonsOrder[0]].element, 'click', this.buttonToMinClick.bind(this)],
  7406. [buttons[buttonsOrder[1]].element, 'click', this.buttonToMaxClick.bind(this)],
  7407. [track, 'click', this.trackClick.bind(this)],
  7408. [bar, 'mousedown', mouseDownHandler],
  7409. [bar.ownerDocument, 'mousemove', mouseMoveHandler],
  7410. [bar.ownerDocument, 'mouseup', mouseUpHandler]
  7411. ];
  7412. // Touch events
  7413. if (hasTouch) {
  7414. _events.push([bar, 'touchstart', mouseDownHandler], [bar.ownerDocument, 'touchmove', mouseMoveHandler], [bar.ownerDocument, 'touchend', mouseUpHandler]);
  7415. }
  7416. // Add them all
  7417. _events.forEach(function (args) {
  7418. addEvent.apply(null, args);
  7419. });
  7420. this._events = _events;
  7421. };
  7422. Scrollbar.prototype.buttonToMaxClick = function (e) {
  7423. var scroller = this;
  7424. var range = (scroller.to - scroller.from) * pick(scroller.options.step, 0.2);
  7425. scroller.updatePosition(scroller.from + range, scroller.to + range);
  7426. fireEvent(scroller, 'changed', {
  7427. from: scroller.from,
  7428. to: scroller.to,
  7429. trigger: 'scrollbar',
  7430. DOMEvent: e
  7431. });
  7432. };
  7433. Scrollbar.prototype.buttonToMinClick = function (e) {
  7434. var scroller = this;
  7435. var range = correctFloat(scroller.to - scroller.from) *
  7436. pick(scroller.options.step, 0.2);
  7437. scroller.updatePosition(correctFloat(scroller.from - range), correctFloat(scroller.to - range));
  7438. fireEvent(scroller, 'changed', {
  7439. from: scroller.from,
  7440. to: scroller.to,
  7441. trigger: 'scrollbar',
  7442. DOMEvent: e
  7443. });
  7444. };
  7445. /**
  7446. * Get normalized (0-1) cursor position over the scrollbar
  7447. *
  7448. * @private
  7449. * @function Highcharts.Scrollbar#cursorToScrollbarPosition
  7450. *
  7451. * @param {*} normalizedEvent
  7452. * normalized event, with chartX and chartY values
  7453. *
  7454. * @return {Highcharts.Dictionary<number>}
  7455. * Local position {chartX, chartY}
  7456. */
  7457. Scrollbar.prototype.cursorToScrollbarPosition = function (normalizedEvent) {
  7458. var scroller = this,
  7459. options = scroller.options,
  7460. minWidthDifference = options.minWidth > scroller.calculatedWidth ?
  7461. options.minWidth :
  7462. 0; // minWidth distorts translation
  7463. return {
  7464. chartX: (normalizedEvent.chartX - scroller.x -
  7465. scroller.xOffset) /
  7466. (scroller.barWidth - minWidthDifference),
  7467. chartY: (normalizedEvent.chartY - scroller.y -
  7468. scroller.yOffset) /
  7469. (scroller.barWidth - minWidthDifference)
  7470. };
  7471. };
  7472. /**
  7473. * Destroys allocated elements.
  7474. *
  7475. * @private
  7476. * @function Highcharts.Scrollbar#destroy
  7477. * @return {void}
  7478. */
  7479. Scrollbar.prototype.destroy = function () {
  7480. var scroller = this.chart.scroller;
  7481. // Disconnect events added in addEvents
  7482. this.removeEvents();
  7483. // Destroy properties
  7484. [
  7485. 'track',
  7486. 'scrollbarRifles',
  7487. 'scrollbar',
  7488. 'scrollbarGroup',
  7489. 'group'
  7490. ].forEach(function (prop) {
  7491. if (this[prop] && this[prop].destroy) {
  7492. this[prop] = this[prop].destroy();
  7493. }
  7494. }, this);
  7495. // #6421, chart may have more scrollbars
  7496. if (scroller && this === scroller.scrollbar) {
  7497. scroller.scrollbar = null;
  7498. // Destroy elements in collection
  7499. destroyObjectProperties(scroller.scrollbarButtons);
  7500. }
  7501. };
  7502. /**
  7503. * Draw the scrollbar buttons with arrows
  7504. *
  7505. * @private
  7506. * @function Highcharts.Scrollbar#drawScrollbarButton
  7507. * @param {number} index
  7508. * 0 is left, 1 is right
  7509. * @return {void}
  7510. */
  7511. Scrollbar.prototype.drawScrollbarButton = function (index) {
  7512. var scroller = this,
  7513. renderer = scroller.renderer,
  7514. scrollbarButtons = scroller.scrollbarButtons,
  7515. options = scroller.options,
  7516. size = scroller.size,
  7517. group,
  7518. tempElem;
  7519. group = renderer.g().add(scroller.group);
  7520. scrollbarButtons.push(group);
  7521. // Create a rectangle for the scrollbar button
  7522. tempElem = renderer.rect()
  7523. .addClass('highcharts-scrollbar-button')
  7524. .add(group);
  7525. // Presentational attributes
  7526. if (!this.chart.styledMode) {
  7527. tempElem.attr({
  7528. stroke: options.buttonBorderColor,
  7529. 'stroke-width': options.buttonBorderWidth,
  7530. fill: options.buttonBackgroundColor
  7531. });
  7532. }
  7533. // Place the rectangle based on the rendered stroke width
  7534. tempElem.attr(tempElem.crisp({
  7535. x: -0.5,
  7536. y: -0.5,
  7537. width: size + 1,
  7538. height: size + 1,
  7539. r: options.buttonBorderRadius
  7540. }, tempElem.strokeWidth()));
  7541. // Button arrow
  7542. tempElem = renderer
  7543. .path(swapXY([[
  7544. 'M',
  7545. size / 2 + (index ? -1 : 1),
  7546. size / 2 - 3
  7547. ], [
  7548. 'L',
  7549. size / 2 + (index ? -1 : 1),
  7550. size / 2 + 3
  7551. ], [
  7552. 'L',
  7553. size / 2 + (index ? 2 : -2),
  7554. size / 2
  7555. ]], options.vertical))
  7556. .addClass('highcharts-scrollbar-arrow')
  7557. .add(scrollbarButtons[index]);
  7558. if (!this.chart.styledMode) {
  7559. tempElem.attr({
  7560. fill: options.buttonArrowColor
  7561. });
  7562. }
  7563. };
  7564. /**
  7565. * @private
  7566. * @function Highcharts.Scrollbar#init
  7567. * @param {Highcharts.SVGRenderer} renderer
  7568. * @param {Highcharts.ScrollbarOptions} options
  7569. * @param {Highcharts.Chart} chart
  7570. */
  7571. Scrollbar.prototype.init = function (renderer, options, chart) {
  7572. this.scrollbarButtons = [];
  7573. this.renderer = renderer;
  7574. this.userOptions = options;
  7575. this.options = merge(Scrollbar.defaultOptions, options);
  7576. this.chart = chart;
  7577. // backward compatibility
  7578. this.size = pick(this.options.size, this.options.height);
  7579. // Init
  7580. if (options.enabled) {
  7581. this.render();
  7582. this.addEvents();
  7583. }
  7584. };
  7585. Scrollbar.prototype.mouseDownHandler = function (e) {
  7586. var scroller = this;
  7587. var normalizedEvent = scroller.chart.pointer.normalize(e),
  7588. mousePosition = scroller.cursorToScrollbarPosition(normalizedEvent);
  7589. scroller.chartX = mousePosition.chartX;
  7590. scroller.chartY = mousePosition.chartY;
  7591. scroller.initPositions = [scroller.from, scroller.to];
  7592. scroller.grabbedCenter = true;
  7593. };
  7594. /**
  7595. * Event handler for the mouse move event.
  7596. * @private
  7597. */
  7598. Scrollbar.prototype.mouseMoveHandler = function (e) {
  7599. var scroller = this;
  7600. var normalizedEvent = scroller.chart.pointer.normalize(e),
  7601. options = scroller.options,
  7602. direction = options.vertical ? 'chartY' : 'chartX',
  7603. initPositions = scroller.initPositions || [],
  7604. scrollPosition,
  7605. chartPosition,
  7606. change;
  7607. // In iOS, a mousemove event with e.pageX === 0 is fired when
  7608. // holding the finger down in the center of the scrollbar. This
  7609. // should be ignored.
  7610. if (scroller.grabbedCenter &&
  7611. // #4696, scrollbar failed on Android
  7612. (!e.touches || e.touches[0][direction] !== 0)) {
  7613. chartPosition = scroller.cursorToScrollbarPosition(normalizedEvent)[direction];
  7614. scrollPosition = scroller[direction];
  7615. change = chartPosition - scrollPosition;
  7616. scroller.hasDragged = true;
  7617. scroller.updatePosition(initPositions[0] + change, initPositions[1] + change);
  7618. if (scroller.hasDragged) {
  7619. fireEvent(scroller, 'changed', {
  7620. from: scroller.from,
  7621. to: scroller.to,
  7622. trigger: 'scrollbar',
  7623. DOMType: e.type,
  7624. DOMEvent: e
  7625. });
  7626. }
  7627. }
  7628. };
  7629. /**
  7630. * Event handler for the mouse up event.
  7631. * @private
  7632. */
  7633. Scrollbar.prototype.mouseUpHandler = function (e) {
  7634. var scroller = this;
  7635. if (scroller.hasDragged) {
  7636. fireEvent(scroller, 'changed', {
  7637. from: scroller.from,
  7638. to: scroller.to,
  7639. trigger: 'scrollbar',
  7640. DOMType: e.type,
  7641. DOMEvent: e
  7642. });
  7643. }
  7644. scroller.grabbedCenter =
  7645. scroller.hasDragged =
  7646. scroller.chartX =
  7647. scroller.chartY = null;
  7648. };
  7649. /**
  7650. * Position the scrollbar, method called from a parent with defined
  7651. * dimensions.
  7652. *
  7653. * @private
  7654. * @function Highcharts.Scrollbar#position
  7655. * @param {number} x
  7656. * x-position on the chart
  7657. * @param {number} y
  7658. * y-position on the chart
  7659. * @param {number} width
  7660. * width of the scrollbar
  7661. * @param {number} height
  7662. * height of the scorllbar
  7663. * @return {void}
  7664. */
  7665. Scrollbar.prototype.position = function (x, y, width, height) {
  7666. var scroller = this,
  7667. options = scroller.options,
  7668. vertical = options.vertical,
  7669. xOffset = height,
  7670. yOffset = 0,
  7671. method = scroller.rendered ? 'animate' : 'attr';
  7672. scroller.x = x;
  7673. scroller.y = y + this.trackBorderWidth;
  7674. scroller.width = width; // width with buttons
  7675. scroller.height = height;
  7676. scroller.xOffset = xOffset;
  7677. scroller.yOffset = yOffset;
  7678. // If Scrollbar is a vertical type, swap options:
  7679. if (vertical) {
  7680. scroller.width = scroller.yOffset = width = yOffset = scroller.size;
  7681. scroller.xOffset = xOffset = 0;
  7682. scroller.barWidth = height - width * 2; // width without buttons
  7683. scroller.x = x = x + scroller.options.margin;
  7684. }
  7685. else {
  7686. scroller.height = scroller.xOffset = height = xOffset =
  7687. scroller.size;
  7688. scroller.barWidth = width - height * 2; // width without buttons
  7689. scroller.y = scroller.y + scroller.options.margin;
  7690. }
  7691. // Set general position for a group:
  7692. scroller.group[method]({
  7693. translateX: x,
  7694. translateY: scroller.y
  7695. });
  7696. // Resize background/track:
  7697. scroller.track[method]({
  7698. width: width,
  7699. height: height
  7700. });
  7701. // Move right/bottom button ot it's place:
  7702. scroller.scrollbarButtons[1][method]({
  7703. translateX: vertical ? 0 : width - xOffset,
  7704. translateY: vertical ? height - yOffset : 0
  7705. });
  7706. };
  7707. /**
  7708. * Removes the event handlers attached previously with addEvents.
  7709. *
  7710. * @private
  7711. * @function Highcharts.Scrollbar#removeEvents
  7712. * @return {void}
  7713. */
  7714. Scrollbar.prototype.removeEvents = function () {
  7715. this._events.forEach(function (args) {
  7716. removeEvent.apply(null, args);
  7717. });
  7718. this._events.length = 0;
  7719. };
  7720. /**
  7721. * Render scrollbar with all required items.
  7722. *
  7723. * @private
  7724. * @function Highcharts.Scrollbar#render
  7725. */
  7726. Scrollbar.prototype.render = function () {
  7727. var scroller = this,
  7728. renderer = scroller.renderer,
  7729. options = scroller.options,
  7730. size = scroller.size,
  7731. styledMode = this.chart.styledMode,
  7732. group;
  7733. // Draw the scrollbar group
  7734. scroller.group = group = renderer.g('scrollbar').attr({
  7735. zIndex: options.zIndex,
  7736. translateY: -99999
  7737. }).add();
  7738. // Draw the scrollbar track:
  7739. scroller.track = renderer.rect()
  7740. .addClass('highcharts-scrollbar-track')
  7741. .attr({
  7742. x: 0,
  7743. r: options.trackBorderRadius || 0,
  7744. height: size,
  7745. width: size
  7746. }).add(group);
  7747. if (!styledMode) {
  7748. scroller.track.attr({
  7749. fill: options.trackBackgroundColor,
  7750. stroke: options.trackBorderColor,
  7751. 'stroke-width': options.trackBorderWidth
  7752. });
  7753. }
  7754. this.trackBorderWidth = scroller.track.strokeWidth();
  7755. scroller.track.attr({
  7756. y: -this.trackBorderWidth % 2 / 2
  7757. });
  7758. // Draw the scrollbar itself
  7759. scroller.scrollbarGroup = renderer.g().add(group);
  7760. scroller.scrollbar = renderer.rect()
  7761. .addClass('highcharts-scrollbar-thumb')
  7762. .attr({
  7763. height: size,
  7764. width: size,
  7765. r: options.barBorderRadius || 0
  7766. }).add(scroller.scrollbarGroup);
  7767. scroller.scrollbarRifles = renderer
  7768. .path(swapXY([
  7769. ['M', -3, size / 4],
  7770. ['L', -3, 2 * size / 3],
  7771. ['M', 0, size / 4],
  7772. ['L', 0, 2 * size / 3],
  7773. ['M', 3, size / 4],
  7774. ['L', 3, 2 * size / 3]
  7775. ], options.vertical))
  7776. .addClass('highcharts-scrollbar-rifles')
  7777. .add(scroller.scrollbarGroup);
  7778. if (!styledMode) {
  7779. scroller.scrollbar.attr({
  7780. fill: options.barBackgroundColor,
  7781. stroke: options.barBorderColor,
  7782. 'stroke-width': options.barBorderWidth
  7783. });
  7784. scroller.scrollbarRifles.attr({
  7785. stroke: options.rifleColor,
  7786. 'stroke-width': 1
  7787. });
  7788. }
  7789. scroller.scrollbarStrokeWidth = scroller.scrollbar.strokeWidth();
  7790. scroller.scrollbarGroup.translate(-scroller.scrollbarStrokeWidth % 2 / 2, -scroller.scrollbarStrokeWidth % 2 / 2);
  7791. // Draw the buttons:
  7792. scroller.drawScrollbarButton(0);
  7793. scroller.drawScrollbarButton(1);
  7794. };
  7795. /**
  7796. * Set scrollbar size, with a given scale.
  7797. *
  7798. * @private
  7799. * @function Highcharts.Scrollbar#setRange
  7800. * @param {number} from
  7801. * scale (0-1) where bar should start
  7802. * @param {number} to
  7803. * scale (0-1) where bar should end
  7804. * @return {void}
  7805. */
  7806. Scrollbar.prototype.setRange = function (from, to) {
  7807. var scroller = this,
  7808. options = scroller.options,
  7809. vertical = options.vertical,
  7810. minWidth = options.minWidth,
  7811. fullWidth = scroller.barWidth,
  7812. fromPX,
  7813. toPX,
  7814. newPos,
  7815. newSize,
  7816. newRiflesPos,
  7817. method = (this.rendered &&
  7818. !this.hasDragged &&
  7819. !(this.chart.navigator && this.chart.navigator.hasDragged)) ? 'animate' : 'attr';
  7820. if (!defined(fullWidth)) {
  7821. return;
  7822. }
  7823. from = Math.max(from, 0);
  7824. fromPX = Math.ceil(fullWidth * from);
  7825. toPX = fullWidth * Math.min(to, 1);
  7826. scroller.calculatedWidth = newSize = correctFloat(toPX - fromPX);
  7827. // We need to recalculate position, if minWidth is used
  7828. if (newSize < minWidth) {
  7829. fromPX = (fullWidth - minWidth + newSize) * from;
  7830. newSize = minWidth;
  7831. }
  7832. newPos = Math.floor(fromPX + scroller.xOffset + scroller.yOffset);
  7833. newRiflesPos = newSize / 2 - 0.5; // -0.5 -> rifle line width / 2
  7834. // Store current position:
  7835. scroller.from = from;
  7836. scroller.to = to;
  7837. if (!vertical) {
  7838. scroller.scrollbarGroup[method]({
  7839. translateX: newPos
  7840. });
  7841. scroller.scrollbar[method]({
  7842. width: newSize
  7843. });
  7844. scroller.scrollbarRifles[method]({
  7845. translateX: newRiflesPos
  7846. });
  7847. scroller.scrollbarLeft = newPos;
  7848. scroller.scrollbarTop = 0;
  7849. }
  7850. else {
  7851. scroller.scrollbarGroup[method]({
  7852. translateY: newPos
  7853. });
  7854. scroller.scrollbar[method]({
  7855. height: newSize
  7856. });
  7857. scroller.scrollbarRifles[method]({
  7858. translateY: newRiflesPos
  7859. });
  7860. scroller.scrollbarTop = newPos;
  7861. scroller.scrollbarLeft = 0;
  7862. }
  7863. if (newSize <= 12) {
  7864. scroller.scrollbarRifles.hide();
  7865. }
  7866. else {
  7867. scroller.scrollbarRifles.show(true);
  7868. }
  7869. // Show or hide the scrollbar based on the showFull setting
  7870. if (options.showFull === false) {
  7871. if (from <= 0 && to >= 1) {
  7872. scroller.group.hide();
  7873. }
  7874. else {
  7875. scroller.group.show();
  7876. }
  7877. }
  7878. scroller.rendered = true;
  7879. };
  7880. Scrollbar.prototype.trackClick = function (e) {
  7881. var scroller = this;
  7882. var normalizedEvent = scroller.chart.pointer.normalize(e),
  7883. range = scroller.to - scroller.from,
  7884. top = scroller.y + scroller.scrollbarTop,
  7885. left = scroller.x + scroller.scrollbarLeft;
  7886. if ((scroller.options.vertical && normalizedEvent.chartY > top) ||
  7887. (!scroller.options.vertical && normalizedEvent.chartX > left)) {
  7888. // On the top or on the left side of the track:
  7889. scroller.updatePosition(scroller.from + range, scroller.to + range);
  7890. }
  7891. else {
  7892. // On the bottom or the right side of the track:
  7893. scroller.updatePosition(scroller.from - range, scroller.to - range);
  7894. }
  7895. fireEvent(scroller, 'changed', {
  7896. from: scroller.from,
  7897. to: scroller.to,
  7898. trigger: 'scrollbar',
  7899. DOMEvent: e
  7900. });
  7901. };
  7902. /**
  7903. * Update the scrollbar with new options
  7904. *
  7905. * @private
  7906. * @function Highcharts.Scrollbar#update
  7907. * @param {Highcharts.ScrollbarOptions} options
  7908. * @return {void}
  7909. */
  7910. Scrollbar.prototype.update = function (options) {
  7911. this.destroy();
  7912. this.init(this.chart.renderer, merge(true, this.options, options), this.chart);
  7913. };
  7914. /**
  7915. * Update position option in the Scrollbar, with normalized 0-1 scale
  7916. *
  7917. * @private
  7918. * @function Highcharts.Scrollbar#updatePosition
  7919. * @param {number} from
  7920. * @param {number} to
  7921. * @return {void}
  7922. */
  7923. Scrollbar.prototype.updatePosition = function (from, to) {
  7924. if (to > 1) {
  7925. from = correctFloat(1 - correctFloat(to - from));
  7926. to = 1;
  7927. }
  7928. if (from < 0) {
  7929. to = correctFloat(to - from);
  7930. from = 0;
  7931. }
  7932. this.from = from;
  7933. this.to = to;
  7934. };
  7935. /* *
  7936. *
  7937. * Static Properties
  7938. *
  7939. * */
  7940. /**
  7941. *
  7942. * The scrollbar is a means of panning over the X axis of a stock chart.
  7943. * Scrollbars can also be applied to other types of axes.
  7944. *
  7945. * Another approach to scrollable charts is the [chart.scrollablePlotArea](
  7946. * https://api.highcharts.com/highcharts/chart.scrollablePlotArea) option that
  7947. * is especially suitable for simpler cartesian charts on mobile.
  7948. *
  7949. * In styled mode, all the presentational options for the
  7950. * scrollbar are replaced by the classes `.highcharts-scrollbar-thumb`,
  7951. * `.highcharts-scrollbar-arrow`, `.highcharts-scrollbar-button`,
  7952. * `.highcharts-scrollbar-rifles` and `.highcharts-scrollbar-track`.
  7953. *
  7954. * @sample stock/yaxis/inverted-bar-scrollbar/
  7955. * A scrollbar on a simple bar chart
  7956. *
  7957. * @product highstock gantt
  7958. * @optionparent scrollbar
  7959. *
  7960. * @private
  7961. */
  7962. Scrollbar.defaultOptions = {
  7963. /**
  7964. * The height of the scrollbar. The height also applies to the width
  7965. * of the scroll arrows so that they are always squares. Defaults to
  7966. * 20 for touch devices and 14 for mouse devices.
  7967. *
  7968. * @sample stock/scrollbar/height/
  7969. * A 30px scrollbar
  7970. *
  7971. * @type {number}
  7972. * @default 20/14
  7973. */
  7974. height: isTouchDevice ? 20 : 14,
  7975. /**
  7976. * The border rounding radius of the bar.
  7977. *
  7978. * @sample stock/scrollbar/style/
  7979. * Scrollbar styling
  7980. */
  7981. barBorderRadius: 0,
  7982. /**
  7983. * The corner radius of the scrollbar buttons.
  7984. *
  7985. * @sample stock/scrollbar/style/
  7986. * Scrollbar styling
  7987. */
  7988. buttonBorderRadius: 0,
  7989. /**
  7990. * Enable or disable the scrollbar.
  7991. *
  7992. * @sample stock/scrollbar/enabled/
  7993. * Disable the scrollbar, only use navigator
  7994. *
  7995. * @type {boolean}
  7996. * @default true
  7997. * @apioption scrollbar.enabled
  7998. */
  7999. /**
  8000. * Whether to redraw the main chart as the scrollbar or the navigator
  8001. * zoomed window is moved. Defaults to `true` for modern browsers and
  8002. * `false` for legacy IE browsers as well as mobile devices.
  8003. *
  8004. * @sample stock/scrollbar/liveredraw
  8005. * Setting live redraw to false
  8006. *
  8007. * @type {boolean}
  8008. * @since 1.3
  8009. */
  8010. liveRedraw: void 0,
  8011. /**
  8012. * The margin between the scrollbar and its axis when the scrollbar is
  8013. * applied directly to an axis.
  8014. */
  8015. margin: 10,
  8016. /**
  8017. * The minimum width of the scrollbar.
  8018. *
  8019. * @since 1.2.5
  8020. */
  8021. minWidth: 6,
  8022. /**
  8023. * Whether to show or hide the scrollbar when the scrolled content is
  8024. * zoomed out to it full extent.
  8025. *
  8026. * @type {boolean}
  8027. * @default true
  8028. * @apioption scrollbar.showFull
  8029. */
  8030. step: 0.2,
  8031. /**
  8032. * The z index of the scrollbar group.
  8033. */
  8034. zIndex: 3,
  8035. /**
  8036. * The background color of the scrollbar itself.
  8037. *
  8038. * @sample stock/scrollbar/style/
  8039. * Scrollbar styling
  8040. *
  8041. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8042. */
  8043. barBackgroundColor: '#cccccc',
  8044. /**
  8045. * The width of the bar's border.
  8046. *
  8047. * @sample stock/scrollbar/style/
  8048. * Scrollbar styling
  8049. */
  8050. barBorderWidth: 1,
  8051. /**
  8052. * The color of the scrollbar's border.
  8053. *
  8054. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8055. */
  8056. barBorderColor: '#cccccc',
  8057. /**
  8058. * The color of the small arrow inside the scrollbar buttons.
  8059. *
  8060. * @sample stock/scrollbar/style/
  8061. * Scrollbar styling
  8062. *
  8063. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8064. */
  8065. buttonArrowColor: '#333333',
  8066. /**
  8067. * The color of scrollbar buttons.
  8068. *
  8069. * @sample stock/scrollbar/style/
  8070. * Scrollbar styling
  8071. *
  8072. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8073. */
  8074. buttonBackgroundColor: '#e6e6e6',
  8075. /**
  8076. * The color of the border of the scrollbar buttons.
  8077. *
  8078. * @sample stock/scrollbar/style/
  8079. * Scrollbar styling
  8080. *
  8081. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8082. */
  8083. buttonBorderColor: '#cccccc',
  8084. /**
  8085. * The border width of the scrollbar buttons.
  8086. *
  8087. * @sample stock/scrollbar/style/
  8088. * Scrollbar styling
  8089. */
  8090. buttonBorderWidth: 1,
  8091. /**
  8092. * The color of the small rifles in the middle of the scrollbar.
  8093. *
  8094. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8095. */
  8096. rifleColor: '#333333',
  8097. /**
  8098. * The color of the track background.
  8099. *
  8100. * @sample stock/scrollbar/style/
  8101. * Scrollbar styling
  8102. *
  8103. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8104. */
  8105. trackBackgroundColor: '#f2f2f2',
  8106. /**
  8107. * The color of the border of the scrollbar track.
  8108. *
  8109. * @sample stock/scrollbar/style/
  8110. * Scrollbar styling
  8111. *
  8112. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  8113. */
  8114. trackBorderColor: '#f2f2f2',
  8115. /**
  8116. * The corner radius of the border of the scrollbar track.
  8117. *
  8118. * @sample stock/scrollbar/style/
  8119. * Scrollbar styling
  8120. *
  8121. * @type {number}
  8122. * @default 0
  8123. * @apioption scrollbar.trackBorderRadius
  8124. */
  8125. /**
  8126. * The width of the border of the scrollbar track.
  8127. *
  8128. * @sample stock/scrollbar/style/
  8129. * Scrollbar styling
  8130. */
  8131. trackBorderWidth: 1
  8132. };
  8133. return Scrollbar;
  8134. }());
  8135. if (!H.Scrollbar) {
  8136. defaultOptions.scrollbar = merge(true, Scrollbar.defaultOptions, defaultOptions.scrollbar);
  8137. H.Scrollbar = Scrollbar;
  8138. ScrollbarAxis.compose(Axis, Scrollbar);
  8139. }
  8140. return H.Scrollbar;
  8141. });
  8142. _registerModule(_modules, 'Extensions/RangeSelector.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Options.js'], _modules['Core/Renderer/SVG/SVGElement.js'], _modules['Core/Utilities.js']], function (Axis, Chart, H, O, SVGElement, U) {
  8143. /* *
  8144. *
  8145. * (c) 2010-2020 Torstein Honsi
  8146. *
  8147. * License: www.highcharts.com/license
  8148. *
  8149. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8150. *
  8151. * */
  8152. var defaultOptions = O.defaultOptions;
  8153. var addEvent = U.addEvent,
  8154. createElement = U.createElement,
  8155. css = U.css,
  8156. defined = U.defined,
  8157. destroyObjectProperties = U.destroyObjectProperties,
  8158. discardElement = U.discardElement,
  8159. extend = U.extend,
  8160. fireEvent = U.fireEvent,
  8161. isNumber = U.isNumber,
  8162. merge = U.merge,
  8163. objectEach = U.objectEach,
  8164. pick = U.pick,
  8165. pInt = U.pInt,
  8166. splat = U.splat;
  8167. /**
  8168. * Define the time span for the button
  8169. *
  8170. * @typedef {"all"|"day"|"hour"|"millisecond"|"minute"|"month"|"second"|"week"|"year"|"ytd"} Highcharts.RangeSelectorButtonTypeValue
  8171. */
  8172. /**
  8173. * Callback function to react on button clicks.
  8174. *
  8175. * @callback Highcharts.RangeSelectorClickCallbackFunction
  8176. *
  8177. * @param {global.Event} e
  8178. * Event arguments.
  8179. *
  8180. * @param {boolean|undefined}
  8181. * Return false to cancel the default button event.
  8182. */
  8183. /**
  8184. * Callback function to parse values entered in the input boxes and return a
  8185. * valid JavaScript time as milliseconds since 1970.
  8186. *
  8187. * @callback Highcharts.RangeSelectorParseCallbackFunction
  8188. *
  8189. * @param {string} value
  8190. * Input value to parse.
  8191. *
  8192. * @return {number}
  8193. * Parsed JavaScript time value.
  8194. */
  8195. /* ************************************************************************** *
  8196. * Start Range Selector code *
  8197. * ************************************************************************** */
  8198. extend(defaultOptions, {
  8199. /**
  8200. * The range selector is a tool for selecting ranges to display within
  8201. * the chart. It provides buttons to select preconfigured ranges in
  8202. * the chart, like 1 day, 1 week, 1 month etc. It also provides input
  8203. * boxes where min and max dates can be manually input.
  8204. *
  8205. * @product highstock gantt
  8206. * @optionparent rangeSelector
  8207. */
  8208. rangeSelector: {
  8209. /**
  8210. * Whether to enable all buttons from the start. By default buttons are
  8211. * only enabled if the corresponding time range exists on the X axis,
  8212. * but enabling all buttons allows for dynamically loading different
  8213. * time ranges.
  8214. *
  8215. * @sample {highstock} stock/rangeselector/allbuttonsenabled-true/
  8216. * All buttons enabled
  8217. *
  8218. * @type {boolean}
  8219. * @default false
  8220. * @since 2.0.3
  8221. * @apioption rangeSelector.allButtonsEnabled
  8222. */
  8223. /**
  8224. * An array of configuration objects for the buttons.
  8225. *
  8226. * Defaults to:
  8227. * ```js
  8228. * buttons: [{
  8229. * type: 'month',
  8230. * count: 1,
  8231. * text: '1m'
  8232. * }, {
  8233. * type: 'month',
  8234. * count: 3,
  8235. * text: '3m'
  8236. * }, {
  8237. * type: 'month',
  8238. * count: 6,
  8239. * text: '6m'
  8240. * }, {
  8241. * type: 'ytd',
  8242. * text: 'YTD'
  8243. * }, {
  8244. * type: 'year',
  8245. * count: 1,
  8246. * text: '1y'
  8247. * }, {
  8248. * type: 'all',
  8249. * text: 'All'
  8250. * }]
  8251. * ```
  8252. *
  8253. * @sample {highstock} stock/rangeselector/datagrouping/
  8254. * Data grouping by buttons
  8255. *
  8256. * @type {Array<*>}
  8257. * @apioption rangeSelector.buttons
  8258. */
  8259. /**
  8260. * How many units of the defined type the button should span. If `type`
  8261. * is "month" and `count` is 3, the button spans three months.
  8262. *
  8263. * @type {number}
  8264. * @default 1
  8265. * @apioption rangeSelector.buttons.count
  8266. */
  8267. /**
  8268. * Fires when clicking on the rangeSelector button. One parameter,
  8269. * event, is passed to the function, containing common event
  8270. * information.
  8271. *
  8272. * ```js
  8273. * click: function(e) {
  8274. * console.log(this);
  8275. * }
  8276. * ```
  8277. *
  8278. * Return false to stop default button's click action.
  8279. *
  8280. * @sample {highstock} stock/rangeselector/button-click/
  8281. * Click event on the button
  8282. *
  8283. * @type {Highcharts.RangeSelectorClickCallbackFunction}
  8284. * @apioption rangeSelector.buttons.events.click
  8285. */
  8286. /**
  8287. * Additional range (in milliseconds) added to the end of the calculated
  8288. * time span.
  8289. *
  8290. * @sample {highstock} stock/rangeselector/min-max-offsets/
  8291. * Button offsets
  8292. *
  8293. * @type {number}
  8294. * @default 0
  8295. * @since 6.0.0
  8296. * @apioption rangeSelector.buttons.offsetMax
  8297. */
  8298. /**
  8299. * Additional range (in milliseconds) added to the start of the
  8300. * calculated time span.
  8301. *
  8302. * @sample {highstock} stock/rangeselector/min-max-offsets/
  8303. * Button offsets
  8304. *
  8305. * @type {number}
  8306. * @default 0
  8307. * @since 6.0.0
  8308. * @apioption rangeSelector.buttons.offsetMin
  8309. */
  8310. /**
  8311. * When buttons apply dataGrouping on a series, by default zooming
  8312. * in/out will deselect buttons and unset dataGrouping. Enable this
  8313. * option to keep buttons selected when extremes change.
  8314. *
  8315. * @sample {highstock} stock/rangeselector/preserve-datagrouping/
  8316. * Different preserveDataGrouping settings
  8317. *
  8318. * @type {boolean}
  8319. * @default false
  8320. * @since 6.1.2
  8321. * @apioption rangeSelector.buttons.preserveDataGrouping
  8322. */
  8323. /**
  8324. * A custom data grouping object for each button.
  8325. *
  8326. * @see [series.dataGrouping](#plotOptions.series.dataGrouping)
  8327. *
  8328. * @sample {highstock} stock/rangeselector/datagrouping/
  8329. * Data grouping by range selector buttons
  8330. *
  8331. * @type {*}
  8332. * @extends plotOptions.series.dataGrouping
  8333. * @apioption rangeSelector.buttons.dataGrouping
  8334. */
  8335. /**
  8336. * The text for the button itself.
  8337. *
  8338. * @type {string}
  8339. * @apioption rangeSelector.buttons.text
  8340. */
  8341. /**
  8342. * Defined the time span for the button. Can be one of `millisecond`,
  8343. * `second`, `minute`, `hour`, `day`, `week`, `month`, `year`, `ytd`,
  8344. * and `all`.
  8345. *
  8346. * @type {Highcharts.RangeSelectorButtonTypeValue}
  8347. * @apioption rangeSelector.buttons.type
  8348. */
  8349. /**
  8350. * The space in pixels between the buttons in the range selector.
  8351. *
  8352. * @type {number}
  8353. * @default 0
  8354. * @apioption rangeSelector.buttonSpacing
  8355. */
  8356. /**
  8357. * Enable or disable the range selector.
  8358. *
  8359. * @sample {highstock} stock/rangeselector/enabled/
  8360. * Disable the range selector
  8361. *
  8362. * @type {boolean}
  8363. * @default true
  8364. * @apioption rangeSelector.enabled
  8365. */
  8366. /**
  8367. * The vertical alignment of the rangeselector box. Allowed properties
  8368. * are `top`, `middle`, `bottom`.
  8369. *
  8370. * @sample {highstock} stock/rangeselector/vertical-align-middle/
  8371. * Middle
  8372. * @sample {highstock} stock/rangeselector/vertical-align-bottom/
  8373. * Bottom
  8374. *
  8375. * @type {Highcharts.VerticalAlignValue}
  8376. * @since 6.0.0
  8377. */
  8378. verticalAlign: 'top',
  8379. /**
  8380. * A collection of attributes for the buttons. The object takes SVG
  8381. * attributes like `fill`, `stroke`, `stroke-width`, as well as `style`,
  8382. * a collection of CSS properties for the text.
  8383. *
  8384. * The object can also be extended with states, so you can set
  8385. * presentational options for `hover`, `select` or `disabled` button
  8386. * states.
  8387. *
  8388. * CSS styles for the text label.
  8389. *
  8390. * In styled mode, the buttons are styled by the
  8391. * `.highcharts-range-selector-buttons .highcharts-button` rule with its
  8392. * different states.
  8393. *
  8394. * @sample {highstock} stock/rangeselector/styling/
  8395. * Styling the buttons and inputs
  8396. *
  8397. * @type {Highcharts.SVGAttributes}
  8398. */
  8399. buttonTheme: {
  8400. /** @ignore */
  8401. width: 28,
  8402. /** @ignore */
  8403. height: 18,
  8404. /** @ignore */
  8405. padding: 2,
  8406. /** @ignore */
  8407. zIndex: 7 // #484, #852
  8408. },
  8409. /**
  8410. * When the rangeselector is floating, the plot area does not reserve
  8411. * space for it. This opens for positioning anywhere on the chart.
  8412. *
  8413. * @sample {highstock} stock/rangeselector/floating/
  8414. * Placing the range selector between the plot area and the
  8415. * navigator
  8416. *
  8417. * @since 6.0.0
  8418. */
  8419. floating: false,
  8420. /**
  8421. * The x offset of the range selector relative to its horizontal
  8422. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  8423. *
  8424. * @since 6.0.0
  8425. */
  8426. x: 0,
  8427. /**
  8428. * The y offset of the range selector relative to its horizontal
  8429. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  8430. *
  8431. * @since 6.0.0
  8432. */
  8433. y: 0,
  8434. /**
  8435. * Deprecated. The height of the range selector. Currently it is
  8436. * calculated dynamically.
  8437. *
  8438. * @deprecated
  8439. * @type {number|undefined}
  8440. * @since 2.1.9
  8441. */
  8442. height: void 0,
  8443. /**
  8444. * The border color of the date input boxes.
  8445. *
  8446. * @sample {highstock} stock/rangeselector/styling/
  8447. * Styling the buttons and inputs
  8448. *
  8449. * @type {Highcharts.ColorString}
  8450. * @default #cccccc
  8451. * @since 1.3.7
  8452. * @apioption rangeSelector.inputBoxBorderColor
  8453. */
  8454. /**
  8455. * The pixel height of the date input boxes.
  8456. *
  8457. * @sample {highstock} stock/rangeselector/styling/
  8458. * Styling the buttons and inputs
  8459. *
  8460. * @type {number}
  8461. * @default 17
  8462. * @since 1.3.7
  8463. * @apioption rangeSelector.inputBoxHeight
  8464. */
  8465. /**
  8466. * CSS for the container DIV holding the input boxes. Deprecated as
  8467. * of 1.2.5\. Use [inputPosition](#rangeSelector.inputPosition) instead.
  8468. *
  8469. * @sample {highstock} stock/rangeselector/styling/
  8470. * Styling the buttons and inputs
  8471. *
  8472. * @deprecated
  8473. * @type {Highcharts.CSSObject}
  8474. * @apioption rangeSelector.inputBoxStyle
  8475. */
  8476. /**
  8477. * The pixel width of the date input boxes.
  8478. *
  8479. * @sample {highstock} stock/rangeselector/styling/
  8480. * Styling the buttons and inputs
  8481. *
  8482. * @type {number}
  8483. * @default 90
  8484. * @since 1.3.7
  8485. * @apioption rangeSelector.inputBoxWidth
  8486. */
  8487. /**
  8488. * The date format in the input boxes when not selected for editing.
  8489. * Defaults to `%b %e, %Y`.
  8490. *
  8491. * @sample {highstock} stock/rangeselector/input-format/
  8492. * Milliseconds in the range selector
  8493. *
  8494. * @type {string}
  8495. * @default %b %e, %Y
  8496. * @apioption rangeSelector.inputDateFormat
  8497. */
  8498. /**
  8499. * A custom callback function to parse values entered in the input boxes
  8500. * and return a valid JavaScript time as milliseconds since 1970.
  8501. * The first argument passed is a value to parse,
  8502. * second is a boolean indicating use of the UTC time.
  8503. *
  8504. * @sample {highstock} stock/rangeselector/input-format/
  8505. * Milliseconds in the range selector
  8506. *
  8507. * @type {Highcharts.RangeSelectorParseCallbackFunction}
  8508. * @since 1.3.3
  8509. * @apioption rangeSelector.inputDateParser
  8510. */
  8511. /**
  8512. * The date format in the input boxes when they are selected for
  8513. * editing. This must be a format that is recognized by JavaScript
  8514. * Date.parse.
  8515. *
  8516. * @sample {highstock} stock/rangeselector/input-format/
  8517. * Milliseconds in the range selector
  8518. *
  8519. * @type {string}
  8520. * @default %Y-%m-%d
  8521. * @apioption rangeSelector.inputEditDateFormat
  8522. */
  8523. /**
  8524. * Enable or disable the date input boxes. Defaults to enabled when
  8525. * there is enough space, disabled if not (typically mobile).
  8526. *
  8527. * @sample {highstock} stock/rangeselector/input-datepicker/
  8528. * Extending the input with a jQuery UI datepicker
  8529. *
  8530. * @type {boolean}
  8531. * @default true
  8532. * @apioption rangeSelector.inputEnabled
  8533. */
  8534. /**
  8535. * Positioning for the input boxes. Allowed properties are `align`,
  8536. * `x` and `y`.
  8537. *
  8538. * @since 1.2.4
  8539. */
  8540. inputPosition: {
  8541. /**
  8542. * The alignment of the input box. Allowed properties are `left`,
  8543. * `center`, `right`.
  8544. *
  8545. * @sample {highstock} stock/rangeselector/input-button-position/
  8546. * Alignment
  8547. *
  8548. * @type {Highcharts.AlignValue}
  8549. * @since 6.0.0
  8550. */
  8551. align: 'right',
  8552. /**
  8553. * X offset of the input row.
  8554. */
  8555. x: 0,
  8556. /**
  8557. * Y offset of the input row.
  8558. */
  8559. y: 0
  8560. },
  8561. /**
  8562. * The index of the button to appear pre-selected.
  8563. *
  8564. * @type {number}
  8565. * @apioption rangeSelector.selected
  8566. */
  8567. /**
  8568. * Positioning for the button row.
  8569. *
  8570. * @since 1.2.4
  8571. */
  8572. buttonPosition: {
  8573. /**
  8574. * The alignment of the input box. Allowed properties are `left`,
  8575. * `center`, `right`.
  8576. *
  8577. * @sample {highstock} stock/rangeselector/input-button-position/
  8578. * Alignment
  8579. *
  8580. * @type {Highcharts.AlignValue}
  8581. * @since 6.0.0
  8582. */
  8583. align: 'left',
  8584. /**
  8585. * X offset of the button row.
  8586. */
  8587. x: 0,
  8588. /**
  8589. * Y offset of the button row.
  8590. */
  8591. y: 0
  8592. },
  8593. /**
  8594. * CSS for the HTML inputs in the range selector.
  8595. *
  8596. * In styled mode, the inputs are styled by the
  8597. * `.highcharts-range-input text` rule in SVG mode, and
  8598. * `input.highcharts-range-selector` when active.
  8599. *
  8600. * @sample {highstock} stock/rangeselector/styling/
  8601. * Styling the buttons and inputs
  8602. *
  8603. * @type {Highcharts.CSSObject}
  8604. * @apioption rangeSelector.inputStyle
  8605. */
  8606. /**
  8607. * CSS styles for the labels - the Zoom, From and To texts.
  8608. *
  8609. * In styled mode, the labels are styled by the
  8610. * `.highcharts-range-label` class.
  8611. *
  8612. * @sample {highstock} stock/rangeselector/styling/
  8613. * Styling the buttons and inputs
  8614. *
  8615. * @type {Highcharts.CSSObject}
  8616. */
  8617. labelStyle: {
  8618. /** @ignore */
  8619. color: '#666666'
  8620. }
  8621. }
  8622. });
  8623. defaultOptions.lang = merge(defaultOptions.lang,
  8624. /**
  8625. * Language object. The language object is global and it can't be set
  8626. * on each chart initialization. Instead, use `Highcharts.setOptions` to
  8627. * set it before any chart is initialized.
  8628. *
  8629. * ```js
  8630. * Highcharts.setOptions({
  8631. * lang: {
  8632. * months: [
  8633. * 'Janvier', 'Février', 'Mars', 'Avril',
  8634. * 'Mai', 'Juin', 'Juillet', 'Août',
  8635. * 'Septembre', 'Octobre', 'Novembre', 'Décembre'
  8636. * ],
  8637. * weekdays: [
  8638. * 'Dimanche', 'Lundi', 'Mardi', 'Mercredi',
  8639. * 'Jeudi', 'Vendredi', 'Samedi'
  8640. * ]
  8641. * }
  8642. * });
  8643. * ```
  8644. *
  8645. * @optionparent lang
  8646. */
  8647. {
  8648. /**
  8649. * The text for the label for the range selector buttons.
  8650. *
  8651. * @product highstock gantt
  8652. */
  8653. rangeSelectorZoom: 'Zoom',
  8654. /**
  8655. * The text for the label for the "from" input box in the range
  8656. * selector.
  8657. *
  8658. * @product highstock gantt
  8659. */
  8660. rangeSelectorFrom: 'From',
  8661. /**
  8662. * The text for the label for the "to" input box in the range selector.
  8663. *
  8664. * @product highstock gantt
  8665. */
  8666. rangeSelectorTo: 'To'
  8667. });
  8668. /* eslint-disable no-invalid-this, valid-jsdoc */
  8669. /**
  8670. * The range selector.
  8671. *
  8672. * @private
  8673. * @class
  8674. * @name Highcharts.RangeSelector
  8675. * @param {Highcharts.Chart} chart
  8676. */
  8677. var RangeSelector = /** @class */ (function () {
  8678. function RangeSelector(chart) {
  8679. /* *
  8680. *
  8681. * Properties
  8682. *
  8683. * */
  8684. this.buttons = void 0;
  8685. this.buttonOptions = RangeSelector.prototype.defaultButtons;
  8686. this.options = void 0;
  8687. this.chart = chart;
  8688. // Run RangeSelector
  8689. this.init(chart);
  8690. }
  8691. /**
  8692. * The method to run when one of the buttons in the range selectors is
  8693. * clicked
  8694. *
  8695. * @private
  8696. * @function Highcharts.RangeSelector#clickButton
  8697. * @param {number} i
  8698. * The index of the button
  8699. * @param {boolean} [redraw]
  8700. * @return {void}
  8701. */
  8702. RangeSelector.prototype.clickButton = function (i, redraw) {
  8703. var rangeSelector = this,
  8704. chart = rangeSelector.chart,
  8705. rangeOptions = rangeSelector.buttonOptions[i],
  8706. baseAxis = chart.xAxis[0],
  8707. unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || baseAxis || {},
  8708. dataMin = unionExtremes.dataMin,
  8709. dataMax = unionExtremes.dataMax,
  8710. newMin,
  8711. newMax = baseAxis && Math.round(Math.min(baseAxis.max,
  8712. pick(dataMax,
  8713. baseAxis.max))), // #1568
  8714. type = rangeOptions.type,
  8715. baseXAxisOptions,
  8716. range = rangeOptions._range,
  8717. rangeMin,
  8718. minSetting,
  8719. rangeSetting,
  8720. ctx,
  8721. ytdExtremes,
  8722. dataGrouping = rangeOptions.dataGrouping;
  8723. // chart has no data, base series is removed
  8724. if (dataMin === null || dataMax === null) {
  8725. return;
  8726. }
  8727. // Set the fixed range before range is altered
  8728. chart.fixedRange = range;
  8729. // Apply dataGrouping associated to button
  8730. if (dataGrouping) {
  8731. this.forcedDataGrouping = true;
  8732. Axis.prototype.setDataGrouping.call(baseAxis || { chart: this.chart }, dataGrouping, false);
  8733. this.frozenStates = rangeOptions.preserveDataGrouping;
  8734. }
  8735. // Apply range
  8736. if (type === 'month' || type === 'year') {
  8737. if (!baseAxis) {
  8738. // This is set to the user options and picked up later when the
  8739. // axis is instantiated so that we know the min and max.
  8740. range = rangeOptions;
  8741. }
  8742. else {
  8743. ctx = {
  8744. range: rangeOptions,
  8745. max: newMax,
  8746. chart: chart,
  8747. dataMin: dataMin,
  8748. dataMax: dataMax
  8749. };
  8750. newMin = baseAxis.minFromRange.call(ctx);
  8751. if (isNumber(ctx.newMax)) {
  8752. newMax = ctx.newMax;
  8753. }
  8754. }
  8755. // Fixed times like minutes, hours, days
  8756. }
  8757. else if (range) {
  8758. newMin = Math.max(newMax - range, dataMin);
  8759. newMax = Math.min(newMin + range, dataMax);
  8760. }
  8761. else if (type === 'ytd') {
  8762. // On user clicks on the buttons, or a delayed action running from
  8763. // the beforeRender event (below), the baseAxis is defined.
  8764. if (baseAxis) {
  8765. // When "ytd" is the pre-selected button for the initial view,
  8766. // its calculation is delayed and rerun in the beforeRender
  8767. // event (below). When the series are initialized, but before
  8768. // the chart is rendered, we have access to the xData array
  8769. // (#942).
  8770. if (typeof dataMax === 'undefined') {
  8771. dataMin = Number.MAX_VALUE;
  8772. dataMax = Number.MIN_VALUE;
  8773. chart.series.forEach(function (series) {
  8774. // reassign it to the last item
  8775. var xData = series.xData;
  8776. dataMin = Math.min(xData[0], dataMin);
  8777. dataMax = Math.max(xData[xData.length - 1], dataMax);
  8778. });
  8779. redraw = false;
  8780. }
  8781. ytdExtremes = rangeSelector.getYTDExtremes(dataMax, dataMin, chart.time.useUTC);
  8782. newMin = rangeMin = ytdExtremes.min;
  8783. newMax = ytdExtremes.max;
  8784. // "ytd" is pre-selected. We don't yet have access to processed
  8785. // point and extremes data (things like pointStart and pointInterval
  8786. // are missing), so we delay the process (#942)
  8787. }
  8788. else {
  8789. rangeSelector.deferredYTDClick = i;
  8790. return;
  8791. }
  8792. }
  8793. else if (type === 'all' && baseAxis) {
  8794. newMin = dataMin;
  8795. newMax = dataMax;
  8796. }
  8797. if (defined(newMin)) {
  8798. newMin += rangeOptions._offsetMin;
  8799. }
  8800. if (defined(newMax)) {
  8801. newMax += rangeOptions._offsetMax;
  8802. }
  8803. rangeSelector.setSelected(i);
  8804. // Update the chart
  8805. if (!baseAxis) {
  8806. // Axis not yet instanciated. Temporarily set min and range
  8807. // options and remove them on chart load (#4317).
  8808. baseXAxisOptions = splat(chart.options.xAxis)[0];
  8809. rangeSetting = baseXAxisOptions.range;
  8810. baseXAxisOptions.range = range;
  8811. minSetting = baseXAxisOptions.min;
  8812. baseXAxisOptions.min = rangeMin;
  8813. addEvent(chart, 'load', function resetMinAndRange() {
  8814. baseXAxisOptions.range = rangeSetting;
  8815. baseXAxisOptions.min = minSetting;
  8816. });
  8817. }
  8818. else {
  8819. // Existing axis object. Set extremes after render time.
  8820. baseAxis.setExtremes(newMin, newMax, pick(redraw, 1), null, // auto animation
  8821. {
  8822. trigger: 'rangeSelectorButton',
  8823. rangeSelectorButton: rangeOptions
  8824. });
  8825. }
  8826. };
  8827. /**
  8828. * Set the selected option. This method only sets the internal flag, it
  8829. * doesn't update the buttons or the actual zoomed range.
  8830. *
  8831. * @private
  8832. * @function Highcharts.RangeSelector#setSelected
  8833. * @param {number} [selected]
  8834. * @return {void}
  8835. */
  8836. RangeSelector.prototype.setSelected = function (selected) {
  8837. this.selected = this.options.selected = selected;
  8838. };
  8839. /**
  8840. * Initialize the range selector
  8841. *
  8842. * @private
  8843. * @function Highcharts.RangeSelector#init
  8844. * @param {Highcharts.Chart} chart
  8845. * @return {void}
  8846. */
  8847. RangeSelector.prototype.init = function (chart) {
  8848. var rangeSelector = this,
  8849. options = chart.options.rangeSelector,
  8850. buttonOptions = options.buttons || rangeSelector.defaultButtons.slice(),
  8851. selectedOption = options.selected,
  8852. blurInputs = function () {
  8853. var minInput = rangeSelector.minInput,
  8854. maxInput = rangeSelector.maxInput;
  8855. // #3274 in some case blur is not defined
  8856. if (minInput && minInput.blur) {
  8857. fireEvent(minInput, 'blur');
  8858. }
  8859. if (maxInput && maxInput.blur) {
  8860. fireEvent(maxInput, 'blur');
  8861. }
  8862. };
  8863. rangeSelector.chart = chart;
  8864. rangeSelector.options = options;
  8865. rangeSelector.buttons = [];
  8866. rangeSelector.buttonOptions = buttonOptions;
  8867. this.unMouseDown = addEvent(chart.container, 'mousedown', blurInputs);
  8868. this.unResize = addEvent(chart, 'resize', blurInputs);
  8869. // Extend the buttonOptions with actual range
  8870. buttonOptions.forEach(rangeSelector.computeButtonRange);
  8871. // zoomed range based on a pre-selected button index
  8872. if (typeof selectedOption !== 'undefined' &&
  8873. buttonOptions[selectedOption]) {
  8874. this.clickButton(selectedOption, false);
  8875. }
  8876. addEvent(chart, 'load', function () {
  8877. // If a data grouping is applied to the current button, release it
  8878. // when extremes change
  8879. if (chart.xAxis && chart.xAxis[0]) {
  8880. addEvent(chart.xAxis[0], 'setExtremes', function (e) {
  8881. if (this.max - this.min !==
  8882. chart.fixedRange &&
  8883. e.trigger !== 'rangeSelectorButton' &&
  8884. e.trigger !== 'updatedData' &&
  8885. rangeSelector.forcedDataGrouping &&
  8886. !rangeSelector.frozenStates) {
  8887. this.setDataGrouping(false, false);
  8888. }
  8889. });
  8890. }
  8891. });
  8892. };
  8893. /**
  8894. * Dynamically update the range selector buttons after a new range has been
  8895. * set
  8896. *
  8897. * @private
  8898. * @function Highcharts.RangeSelector#updateButtonStates
  8899. * @return {void}
  8900. */
  8901. RangeSelector.prototype.updateButtonStates = function () {
  8902. var rangeSelector = this,
  8903. chart = this.chart,
  8904. baseAxis = chart.xAxis[0],
  8905. actualRange = Math.round(baseAxis.max - baseAxis.min),
  8906. hasNoData = !baseAxis.hasVisibleSeries,
  8907. day = 24 * 36e5, // A single day in milliseconds
  8908. unionExtremes = (chart.scroller &&
  8909. chart.scroller.getUnionExtremes()) || baseAxis,
  8910. dataMin = unionExtremes.dataMin,
  8911. dataMax = unionExtremes.dataMax,
  8912. ytdExtremes = rangeSelector.getYTDExtremes(dataMax,
  8913. dataMin,
  8914. chart.time.useUTC),
  8915. ytdMin = ytdExtremes.min,
  8916. ytdMax = ytdExtremes.max,
  8917. selected = rangeSelector.selected,
  8918. selectedExists = isNumber(selected),
  8919. allButtonsEnabled = rangeSelector.options.allButtonsEnabled,
  8920. buttons = rangeSelector.buttons;
  8921. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  8922. var range = rangeOptions._range,
  8923. type = rangeOptions.type,
  8924. count = rangeOptions.count || 1,
  8925. button = buttons[i],
  8926. state = 0,
  8927. disable,
  8928. select,
  8929. offsetRange = rangeOptions._offsetMax -
  8930. rangeOptions._offsetMin,
  8931. isSelected = i === selected,
  8932. // Disable buttons where the range exceeds what is allowed in
  8933. // the current view
  8934. isTooGreatRange = range >
  8935. dataMax - dataMin,
  8936. // Disable buttons where the range is smaller than the minimum
  8937. // range
  8938. isTooSmallRange = range < baseAxis.minRange,
  8939. // Do not select the YTD button if not explicitly told so
  8940. isYTDButNotSelected = false,
  8941. // Disable the All button if we're already showing all
  8942. isAllButAlreadyShowingAll = false,
  8943. isSameRange = range === actualRange;
  8944. // Months and years have a variable range so we check the extremes
  8945. if ((type === 'month' || type === 'year') &&
  8946. (actualRange + 36e5 >=
  8947. { month: 28, year: 365 }[type] * day * count - offsetRange) &&
  8948. (actualRange - 36e5 <=
  8949. { month: 31, year: 366 }[type] * day * count + offsetRange)) {
  8950. isSameRange = true;
  8951. }
  8952. else if (type === 'ytd') {
  8953. isSameRange = (ytdMax - ytdMin + offsetRange) === actualRange;
  8954. isYTDButNotSelected = !isSelected;
  8955. }
  8956. else if (type === 'all') {
  8957. isSameRange = (baseAxis.max - baseAxis.min >=
  8958. dataMax - dataMin);
  8959. isAllButAlreadyShowingAll = (!isSelected &&
  8960. selectedExists &&
  8961. isSameRange);
  8962. }
  8963. // The new zoom area happens to match the range for a button - mark
  8964. // it selected. This happens when scrolling across an ordinal gap.
  8965. // It can be seen in the intraday demos when selecting 1h and scroll
  8966. // across the night gap.
  8967. disable = (!allButtonsEnabled &&
  8968. (isTooGreatRange ||
  8969. isTooSmallRange ||
  8970. isAllButAlreadyShowingAll ||
  8971. hasNoData));
  8972. select = ((isSelected && isSameRange) ||
  8973. (isSameRange && !selectedExists && !isYTDButNotSelected) ||
  8974. (isSelected && rangeSelector.frozenStates));
  8975. if (disable) {
  8976. state = 3;
  8977. }
  8978. else if (select) {
  8979. selectedExists = true; // Only one button can be selected
  8980. state = 2;
  8981. }
  8982. // If state has changed, update the button
  8983. if (button.state !== state) {
  8984. button.setState(state);
  8985. // Reset (#9209)
  8986. if (state === 0 && selected === i) {
  8987. rangeSelector.setSelected(null);
  8988. }
  8989. }
  8990. });
  8991. };
  8992. /**
  8993. * Compute and cache the range for an individual button
  8994. *
  8995. * @private
  8996. * @function Highcharts.RangeSelector#computeButtonRange
  8997. * @param {Highcharts.RangeSelectorButtonsOptions} rangeOptions
  8998. * @return {void}
  8999. */
  9000. RangeSelector.prototype.computeButtonRange = function (rangeOptions) {
  9001. var type = rangeOptions.type,
  9002. count = rangeOptions.count || 1,
  9003. // these time intervals have a fixed number of milliseconds, as
  9004. // opposed to month, ytd and year
  9005. fixedTimes = {
  9006. millisecond: 1,
  9007. second: 1000,
  9008. minute: 60 * 1000,
  9009. hour: 3600 * 1000,
  9010. day: 24 * 3600 * 1000,
  9011. week: 7 * 24 * 3600 * 1000
  9012. };
  9013. // Store the range on the button object
  9014. if (fixedTimes[type]) {
  9015. rangeOptions._range = fixedTimes[type] * count;
  9016. }
  9017. else if (type === 'month' || type === 'year') {
  9018. rangeOptions._range = {
  9019. month: 30,
  9020. year: 365
  9021. }[type] * 24 * 36e5 * count;
  9022. }
  9023. rangeOptions._offsetMin = pick(rangeOptions.offsetMin, 0);
  9024. rangeOptions._offsetMax = pick(rangeOptions.offsetMax, 0);
  9025. rangeOptions._range +=
  9026. rangeOptions._offsetMax - rangeOptions._offsetMin;
  9027. };
  9028. /**
  9029. * Set the internal and displayed value of a HTML input for the dates
  9030. *
  9031. * @private
  9032. * @function Highcharts.RangeSelector#setInputValue
  9033. * @param {string} name
  9034. * @param {number} [inputTime]
  9035. * @return {void}
  9036. */
  9037. RangeSelector.prototype.setInputValue = function (name, inputTime) {
  9038. var options = this.chart.options.rangeSelector,
  9039. time = this.chart.time,
  9040. input = this[name + 'Input'];
  9041. if (defined(inputTime)) {
  9042. input.previousValue = input.HCTime;
  9043. input.HCTime = inputTime;
  9044. }
  9045. input.value = time.dateFormat(options.inputEditDateFormat || '%Y-%m-%d', input.HCTime);
  9046. this[name + 'DateBox'].attr({
  9047. text: time.dateFormat(options.inputDateFormat || '%b %e, %Y', input.HCTime)
  9048. });
  9049. };
  9050. /**
  9051. * @private
  9052. * @function Highcharts.RangeSelector#showInput
  9053. * @param {string} name
  9054. * @return {void}
  9055. */
  9056. RangeSelector.prototype.showInput = function (name) {
  9057. var inputGroup = this.inputGroup,
  9058. dateBox = this[name + 'DateBox'];
  9059. css(this[name + 'Input'], {
  9060. left: (inputGroup.translateX + dateBox.x) + 'px',
  9061. top: inputGroup.translateY + 'px',
  9062. width: (dateBox.width - 2) + 'px',
  9063. height: (dateBox.height - 2) + 'px',
  9064. border: '2px solid silver'
  9065. });
  9066. };
  9067. /**
  9068. * @private
  9069. * @function Highcharts.RangeSelector#hideInput
  9070. * @param {string} name
  9071. * @return {void}
  9072. */
  9073. RangeSelector.prototype.hideInput = function (name) {
  9074. css(this[name + 'Input'], {
  9075. border: 0,
  9076. width: '1px',
  9077. height: '1px'
  9078. });
  9079. this.setInputValue(name);
  9080. };
  9081. /**
  9082. * @private
  9083. * @function Highcharts.RangeSelector#defaultInputDateParser
  9084. */
  9085. RangeSelector.prototype.defaultInputDateParser = function (inputDate, useUTC) {
  9086. var date = new Date();
  9087. if (H.isSafari) {
  9088. return Date.parse(inputDate.split(' ').join('T'));
  9089. }
  9090. if (useUTC) {
  9091. return Date.parse(inputDate + 'Z');
  9092. }
  9093. return Date.parse(inputDate) - date.getTimezoneOffset() * 60 * 1000;
  9094. };
  9095. /**
  9096. * Draw either the 'from' or the 'to' HTML input box of the range selector
  9097. *
  9098. * @private
  9099. * @function Highcharts.RangeSelector#drawInput
  9100. * @param {string} name
  9101. * @return {void}
  9102. */
  9103. RangeSelector.prototype.drawInput = function (name) {
  9104. var rangeSelector = this,
  9105. chart = rangeSelector.chart,
  9106. chartStyle = chart.renderer.style || {},
  9107. renderer = chart.renderer,
  9108. options = chart.options.rangeSelector,
  9109. lang = defaultOptions.lang,
  9110. div = rangeSelector.div,
  9111. isMin = name === 'min',
  9112. input,
  9113. label,
  9114. dateBox,
  9115. inputGroup = this.inputGroup,
  9116. defaultInputDateParser = this.defaultInputDateParser;
  9117. /**
  9118. * @private
  9119. */
  9120. function updateExtremes() {
  9121. var inputValue = input.value,
  9122. value,
  9123. chartAxis = chart.xAxis[0],
  9124. dataAxis = chart.scroller && chart.scroller.xAxis ?
  9125. chart.scroller.xAxis :
  9126. chartAxis,
  9127. dataMin = dataAxis.dataMin,
  9128. dataMax = dataAxis.dataMax;
  9129. value = (options.inputDateParser || defaultInputDateParser)(inputValue, chart.time.useUTC);
  9130. if (value !== input.previousValue) {
  9131. input.previousValue = value;
  9132. // If the value isn't parsed directly to a value by the
  9133. // browser's Date.parse method, like YYYY-MM-DD in IE, try
  9134. // parsing it a different way
  9135. if (!isNumber(value)) {
  9136. value = inputValue.split('-');
  9137. value = Date.UTC(pInt(value[0]), pInt(value[1]) - 1, pInt(value[2]));
  9138. }
  9139. if (isNumber(value)) {
  9140. // Correct for timezone offset (#433)
  9141. if (!chart.time.useUTC) {
  9142. value =
  9143. value + new Date().getTimezoneOffset() * 60 * 1000;
  9144. }
  9145. // Validate the extremes. If it goes beyound the data min or
  9146. // max, use the actual data extreme (#2438).
  9147. if (isMin) {
  9148. if (value > rangeSelector.maxInput.HCTime) {
  9149. value = void 0;
  9150. }
  9151. else if (value < dataMin) {
  9152. value = dataMin;
  9153. }
  9154. }
  9155. else {
  9156. if (value < rangeSelector.minInput.HCTime) {
  9157. value = void 0;
  9158. }
  9159. else if (value > dataMax) {
  9160. value = dataMax;
  9161. }
  9162. }
  9163. // Set the extremes
  9164. if (typeof value !== 'undefined') { // @todo typof undefined
  9165. chartAxis.setExtremes(isMin ? value : chartAxis.min, isMin ? chartAxis.max : value, void 0, void 0, { trigger: 'rangeSelectorInput' });
  9166. }
  9167. }
  9168. }
  9169. }
  9170. // Create the text label
  9171. this[name + 'Label'] = label = renderer
  9172. .label(lang[isMin ? 'rangeSelectorFrom' : 'rangeSelectorTo'], this.inputGroup.offset)
  9173. .addClass('highcharts-range-label')
  9174. .attr({
  9175. padding: 2
  9176. })
  9177. .add(inputGroup);
  9178. inputGroup.offset += label.width + 5;
  9179. // Create an SVG label that shows updated date ranges and and records
  9180. // click events that bring in the HTML input.
  9181. this[name + 'DateBox'] = dateBox = renderer
  9182. .label('', inputGroup.offset)
  9183. .addClass('highcharts-range-input')
  9184. .attr({
  9185. padding: 2,
  9186. width: options.inputBoxWidth || 90,
  9187. height: options.inputBoxHeight || 17,
  9188. 'text-align': 'center'
  9189. })
  9190. .on('click', function () {
  9191. // If it is already focused, the onfocus event doesn't fire
  9192. // (#3713)
  9193. rangeSelector.showInput(name);
  9194. rangeSelector[name + 'Input'].focus();
  9195. });
  9196. if (!chart.styledMode) {
  9197. dateBox.attr({
  9198. stroke: options.inputBoxBorderColor || '#cccccc',
  9199. 'stroke-width': 1
  9200. });
  9201. }
  9202. dateBox.add(inputGroup);
  9203. inputGroup.offset += dateBox.width + (isMin ? 10 : 0);
  9204. // Create the HTML input element. This is rendered as 1x1 pixel then set
  9205. // to the right size when focused.
  9206. this[name + 'Input'] = input = createElement('input', {
  9207. name: name,
  9208. className: 'highcharts-range-selector',
  9209. type: 'text'
  9210. }, {
  9211. top: chart.plotTop + 'px' // prevent jump on focus in Firefox
  9212. }, div);
  9213. if (!chart.styledMode) {
  9214. // Styles
  9215. label.css(merge(chartStyle, options.labelStyle));
  9216. dateBox.css(merge({
  9217. color: '#333333'
  9218. }, chartStyle, options.inputStyle));
  9219. css(input, extend({
  9220. position: 'absolute',
  9221. border: 0,
  9222. width: '1px',
  9223. height: '1px',
  9224. padding: 0,
  9225. textAlign: 'center',
  9226. fontSize: chartStyle.fontSize,
  9227. fontFamily: chartStyle.fontFamily,
  9228. top: '-9999em' // #4798
  9229. }, options.inputStyle));
  9230. }
  9231. // Blow up the input box
  9232. input.onfocus = function () {
  9233. rangeSelector.showInput(name);
  9234. };
  9235. // Hide away the input box
  9236. input.onblur = function () {
  9237. // update extermes only when inputs are active
  9238. if (input === H.doc.activeElement) { // Only when focused
  9239. // Update also when no `change` event is triggered, like when
  9240. // clicking inside the SVG (#4710)
  9241. updateExtremes();
  9242. }
  9243. // #10404 - move hide and blur outside focus
  9244. rangeSelector.hideInput(name);
  9245. input.blur(); // #4606
  9246. };
  9247. // handle changes in the input boxes
  9248. input.onchange = updateExtremes;
  9249. input.onkeypress = function (event) {
  9250. // IE does not fire onchange on enter
  9251. if (event.keyCode === 13) {
  9252. updateExtremes();
  9253. }
  9254. };
  9255. };
  9256. /**
  9257. * Get the position of the range selector buttons and inputs. This can be
  9258. * overridden from outside for custom positioning.
  9259. *
  9260. * @private
  9261. * @function Highcharts.RangeSelector#getPosition
  9262. *
  9263. * @return {Highcharts.Dictionary<number>}
  9264. */
  9265. RangeSelector.prototype.getPosition = function () {
  9266. var chart = this.chart,
  9267. options = chart.options.rangeSelector,
  9268. top = options.verticalAlign === 'top' ?
  9269. chart.plotTop - chart.axisOffset[0] :
  9270. 0; // set offset only for varticalAlign top
  9271. return {
  9272. buttonTop: top + options.buttonPosition.y,
  9273. inputTop: top + options.inputPosition.y - 10
  9274. };
  9275. };
  9276. /**
  9277. * Get the extremes of YTD. Will choose dataMax if its value is lower than
  9278. * the current timestamp. Will choose dataMin if its value is higher than
  9279. * the timestamp for the start of current year.
  9280. *
  9281. * @private
  9282. * @function Highcharts.RangeSelector#getYTDExtremes
  9283. *
  9284. * @param {number} dataMax
  9285. *
  9286. * @param {number} dataMin
  9287. *
  9288. * @return {*}
  9289. * Returns min and max for the YTD
  9290. */
  9291. RangeSelector.prototype.getYTDExtremes = function (dataMax, dataMin, useUTC) {
  9292. var time = this.chart.time,
  9293. min,
  9294. now = new time.Date(dataMax),
  9295. year = time.get('FullYear',
  9296. now),
  9297. startOfYear = useUTC ?
  9298. time.Date.UTC(year, 0, 1) : // eslint-disable-line new-cap
  9299. +new time.Date(year, 0, 1);
  9300. min = Math.max(dataMin || 0, startOfYear);
  9301. now = now.getTime();
  9302. return {
  9303. max: Math.min(dataMax || now, now),
  9304. min: min
  9305. };
  9306. };
  9307. /**
  9308. * Render the range selector including the buttons and the inputs. The first
  9309. * time render is called, the elements are created and positioned. On
  9310. * subsequent calls, they are moved and updated.
  9311. *
  9312. * @private
  9313. * @function Highcharts.RangeSelector#render
  9314. * @param {number} [min]
  9315. * X axis minimum
  9316. * @param {number} [max]
  9317. * X axis maximum
  9318. * @return {void}
  9319. */
  9320. RangeSelector.prototype.render = function (min, max) {
  9321. var rangeSelector = this,
  9322. chart = rangeSelector.chart,
  9323. renderer = chart.renderer,
  9324. container = chart.container,
  9325. chartOptions = chart.options,
  9326. navButtonOptions = (chartOptions.exporting &&
  9327. chartOptions.exporting.enabled !== false &&
  9328. chartOptions.navigation &&
  9329. chartOptions.navigation.buttonOptions),
  9330. lang = defaultOptions.lang,
  9331. div = rangeSelector.div,
  9332. options = chartOptions.rangeSelector,
  9333. // Place inputs above the container
  9334. inputsZIndex = pick(chartOptions.chart.style &&
  9335. chartOptions.chart.style.zIndex, 0) + 1,
  9336. floating = options.floating,
  9337. buttons = rangeSelector.buttons,
  9338. inputGroup = rangeSelector.inputGroup,
  9339. buttonTheme = options.buttonTheme,
  9340. buttonPosition = options.buttonPosition,
  9341. inputPosition = options.inputPosition,
  9342. inputEnabled = options.inputEnabled,
  9343. states = buttonTheme && buttonTheme.states,
  9344. plotLeft = chart.plotLeft,
  9345. buttonLeft,
  9346. buttonGroup = rangeSelector.buttonGroup,
  9347. group,
  9348. groupHeight,
  9349. rendered = rangeSelector.rendered,
  9350. verticalAlign = rangeSelector.options.verticalAlign,
  9351. legend = chart.legend,
  9352. legendOptions = legend && legend.options,
  9353. buttonPositionY = buttonPosition.y,
  9354. inputPositionY = inputPosition.y,
  9355. animate = chart.hasLoaded,
  9356. verb = animate ? 'animate' : 'attr',
  9357. exportingX = 0,
  9358. alignTranslateY,
  9359. legendHeight,
  9360. minPosition,
  9361. translateY = 0,
  9362. translateX;
  9363. if (options.enabled === false) {
  9364. return;
  9365. }
  9366. // create the elements
  9367. if (!rendered) {
  9368. rangeSelector.group = group = renderer.g('range-selector-group')
  9369. .attr({
  9370. zIndex: 7
  9371. })
  9372. .add();
  9373. rangeSelector.buttonGroup = buttonGroup =
  9374. renderer.g('range-selector-buttons').add(group);
  9375. rangeSelector.zoomText = renderer
  9376. .text(lang.rangeSelectorZoom, 0, 15)
  9377. .add(buttonGroup);
  9378. if (!chart.styledMode) {
  9379. rangeSelector.zoomText.css(options.labelStyle);
  9380. buttonTheme['stroke-width'] =
  9381. pick(buttonTheme['stroke-width'], 0);
  9382. }
  9383. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  9384. buttons[i] = renderer
  9385. .button(rangeOptions.text, 0, 0, function (e) {
  9386. // extract events from button object and call
  9387. var buttonEvents = (rangeOptions.events &&
  9388. rangeOptions.events.click),
  9389. callDefaultEvent;
  9390. if (buttonEvents) {
  9391. callDefaultEvent =
  9392. buttonEvents.call(rangeOptions, e);
  9393. }
  9394. if (callDefaultEvent !== false) {
  9395. rangeSelector.clickButton(i);
  9396. }
  9397. rangeSelector.isActive = true;
  9398. }, buttonTheme, states && states.hover, states && states.select, states && states.disabled)
  9399. .attr({
  9400. 'text-align': 'center'
  9401. })
  9402. .add(buttonGroup);
  9403. });
  9404. // first create a wrapper outside the container in order to make
  9405. // the inputs work and make export correct
  9406. if (inputEnabled !== false) {
  9407. rangeSelector.div = div = createElement('div', null, {
  9408. position: 'relative',
  9409. height: 0,
  9410. zIndex: inputsZIndex
  9411. });
  9412. container.parentNode.insertBefore(div, container);
  9413. // Create the group to keep the inputs
  9414. rangeSelector.inputGroup = inputGroup =
  9415. renderer.g('input-group').add(group);
  9416. inputGroup.offset = 0;
  9417. rangeSelector.drawInput('min');
  9418. rangeSelector.drawInput('max');
  9419. }
  9420. }
  9421. // #8769, allow dynamically updating margins
  9422. rangeSelector.zoomText[verb]({
  9423. x: pick(plotLeft + buttonPosition.x, plotLeft)
  9424. });
  9425. // button start position
  9426. buttonLeft = pick(plotLeft + buttonPosition.x, plotLeft) +
  9427. rangeSelector.zoomText.getBBox().width + 5;
  9428. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  9429. buttons[i][verb]({ x: buttonLeft });
  9430. // increase button position for the next button
  9431. buttonLeft += buttons[i].width + pick(options.buttonSpacing, 5);
  9432. });
  9433. plotLeft = chart.plotLeft - chart.spacing[3];
  9434. rangeSelector.updateButtonStates();
  9435. // detect collisiton with exporting
  9436. if (navButtonOptions &&
  9437. this.titleCollision(chart) &&
  9438. verticalAlign === 'top' &&
  9439. buttonPosition.align === 'right' && ((buttonPosition.y +
  9440. buttonGroup.getBBox().height - 12) <
  9441. ((navButtonOptions.y || 0) +
  9442. navButtonOptions.height))) {
  9443. exportingX = -40;
  9444. }
  9445. translateX = buttonPosition.x - chart.spacing[3];
  9446. if (buttonPosition.align === 'right') {
  9447. translateX += exportingX - plotLeft; // (#13014)
  9448. }
  9449. else if (buttonPosition.align === 'center') {
  9450. translateX -= plotLeft / 2;
  9451. }
  9452. // align button group
  9453. buttonGroup.align({
  9454. y: buttonPosition.y,
  9455. width: buttonGroup.getBBox().width,
  9456. align: buttonPosition.align,
  9457. x: translateX
  9458. }, true, chart.spacingBox);
  9459. // skip animation
  9460. rangeSelector.group.placed = animate;
  9461. rangeSelector.buttonGroup.placed = animate;
  9462. if (inputEnabled !== false) {
  9463. var inputGroupX,
  9464. inputGroupWidth,
  9465. buttonGroupX,
  9466. buttonGroupWidth;
  9467. // detect collision with exporting
  9468. if (navButtonOptions &&
  9469. this.titleCollision(chart) &&
  9470. verticalAlign === 'top' &&
  9471. inputPosition.align === 'right' && ((inputPosition.y -
  9472. inputGroup.getBBox().height - 12) <
  9473. ((navButtonOptions.y || 0) +
  9474. navButtonOptions.height +
  9475. chart.spacing[0]))) {
  9476. exportingX = -40;
  9477. }
  9478. else {
  9479. exportingX = 0;
  9480. }
  9481. if (inputPosition.align === 'left') {
  9482. translateX = plotLeft;
  9483. }
  9484. else if (inputPosition.align === 'right') {
  9485. translateX = -Math.max(chart.axisOffset[1], -exportingX);
  9486. }
  9487. // Update the alignment to the updated spacing box
  9488. inputGroup.align({
  9489. y: inputPosition.y,
  9490. width: inputGroup.getBBox().width,
  9491. align: inputPosition.align,
  9492. // fix wrong getBBox() value on right align
  9493. x: inputPosition.x + translateX - 2
  9494. }, true, chart.spacingBox);
  9495. // detect collision
  9496. inputGroupX = (inputGroup.alignAttr.translateX +
  9497. inputGroup.alignOptions.x -
  9498. exportingX +
  9499. // getBBox for detecing left margin
  9500. inputGroup.getBBox().x +
  9501. // 2px padding to not overlap input and label
  9502. 2);
  9503. inputGroupWidth = inputGroup.alignOptions.width;
  9504. buttonGroupX = buttonGroup.alignAttr.translateX +
  9505. buttonGroup.getBBox().x;
  9506. // 20 is minimal spacing between elements
  9507. buttonGroupWidth = buttonGroup.getBBox().width + 20;
  9508. if ((inputPosition.align ===
  9509. buttonPosition.align) || ((buttonGroupX + buttonGroupWidth > inputGroupX) &&
  9510. (inputGroupX + inputGroupWidth > buttonGroupX) &&
  9511. (buttonPositionY <
  9512. (inputPositionY +
  9513. inputGroup.getBBox().height)))) {
  9514. inputGroup.attr({
  9515. translateX: inputGroup.alignAttr.translateX +
  9516. (chart.axisOffset[1] >= -exportingX ? 0 : -exportingX),
  9517. translateY: inputGroup.alignAttr.translateY +
  9518. buttonGroup.getBBox().height + 10
  9519. });
  9520. }
  9521. // Set or reset the input values
  9522. rangeSelector.setInputValue('min', min);
  9523. rangeSelector.setInputValue('max', max);
  9524. // skip animation
  9525. rangeSelector.inputGroup.placed = animate;
  9526. }
  9527. // vertical align
  9528. rangeSelector.group.align({
  9529. verticalAlign: verticalAlign
  9530. }, true, chart.spacingBox);
  9531. // set position
  9532. groupHeight =
  9533. rangeSelector.group.getBBox().height + 20; // # 20 padding
  9534. alignTranslateY =
  9535. rangeSelector.group.alignAttr.translateY;
  9536. // calculate bottom position
  9537. if (verticalAlign === 'bottom') {
  9538. legendHeight = (legendOptions &&
  9539. legendOptions.verticalAlign === 'bottom' &&
  9540. legendOptions.enabled &&
  9541. !legendOptions.floating ?
  9542. legend.legendHeight + pick(legendOptions.margin, 10) :
  9543. 0);
  9544. groupHeight = groupHeight + legendHeight - 20;
  9545. translateY = (alignTranslateY -
  9546. groupHeight -
  9547. (floating ? 0 : options.y) -
  9548. (chart.titleOffset ? chart.titleOffset[2] : 0) -
  9549. 10 // 10 spacing
  9550. );
  9551. }
  9552. if (verticalAlign === 'top') {
  9553. if (floating) {
  9554. translateY = 0;
  9555. }
  9556. if (chart.titleOffset && chart.titleOffset[0]) {
  9557. translateY = chart.titleOffset[0];
  9558. }
  9559. translateY += ((chart.margin[0] - chart.spacing[0]) || 0);
  9560. }
  9561. else if (verticalAlign === 'middle') {
  9562. if (inputPositionY === buttonPositionY) {
  9563. if (inputPositionY < 0) {
  9564. translateY = alignTranslateY + minPosition;
  9565. }
  9566. else {
  9567. translateY = alignTranslateY;
  9568. }
  9569. }
  9570. else if (inputPositionY || buttonPositionY) {
  9571. if (inputPositionY < 0 ||
  9572. buttonPositionY < 0) {
  9573. translateY -= Math.min(inputPositionY, buttonPositionY);
  9574. }
  9575. else {
  9576. translateY =
  9577. alignTranslateY - groupHeight + minPosition;
  9578. }
  9579. }
  9580. }
  9581. rangeSelector.group.translate(options.x, options.y + Math.floor(translateY));
  9582. // translate HTML inputs
  9583. if (inputEnabled !== false) {
  9584. rangeSelector.minInput.style.marginTop =
  9585. rangeSelector.group.translateY + 'px';
  9586. rangeSelector.maxInput.style.marginTop =
  9587. rangeSelector.group.translateY + 'px';
  9588. }
  9589. rangeSelector.rendered = true;
  9590. };
  9591. /**
  9592. * Extracts height of range selector
  9593. *
  9594. * @private
  9595. * @function Highcharts.RangeSelector#getHeight
  9596. * @return {number}
  9597. * Returns rangeSelector height
  9598. */
  9599. RangeSelector.prototype.getHeight = function () {
  9600. var rangeSelector = this,
  9601. options = rangeSelector.options,
  9602. rangeSelectorGroup = rangeSelector.group,
  9603. inputPosition = options.inputPosition,
  9604. buttonPosition = options.buttonPosition,
  9605. yPosition = options.y,
  9606. buttonPositionY = buttonPosition.y,
  9607. inputPositionY = inputPosition.y,
  9608. rangeSelectorHeight = 0,
  9609. minPosition;
  9610. if (options.height) {
  9611. return options.height;
  9612. }
  9613. rangeSelectorHeight = rangeSelectorGroup ?
  9614. // 13px to keep back compatibility
  9615. (rangeSelectorGroup.getBBox(true).height) + 13 +
  9616. yPosition :
  9617. 0;
  9618. minPosition = Math.min(inputPositionY, buttonPositionY);
  9619. if ((inputPositionY < 0 && buttonPositionY < 0) ||
  9620. (inputPositionY > 0 && buttonPositionY > 0)) {
  9621. rangeSelectorHeight += Math.abs(minPosition);
  9622. }
  9623. return rangeSelectorHeight;
  9624. };
  9625. /**
  9626. * Detect collision with title or subtitle
  9627. *
  9628. * @private
  9629. * @function Highcharts.RangeSelector#titleCollision
  9630. *
  9631. * @param {Highcharts.Chart} chart
  9632. *
  9633. * @return {boolean}
  9634. * Returns collision status
  9635. */
  9636. RangeSelector.prototype.titleCollision = function (chart) {
  9637. return !(chart.options.title.text ||
  9638. chart.options.subtitle.text);
  9639. };
  9640. /**
  9641. * Update the range selector with new options
  9642. *
  9643. * @private
  9644. * @function Highcharts.RangeSelector#update
  9645. * @param {Highcharts.RangeSelectorOptions} options
  9646. * @return {void}
  9647. */
  9648. RangeSelector.prototype.update = function (options) {
  9649. var chart = this.chart;
  9650. merge(true, chart.options.rangeSelector, options);
  9651. this.destroy();
  9652. this.init(chart);
  9653. chart.rangeSelector.render();
  9654. };
  9655. /**
  9656. * Destroys allocated elements.
  9657. *
  9658. * @private
  9659. * @function Highcharts.RangeSelector#destroy
  9660. */
  9661. RangeSelector.prototype.destroy = function () {
  9662. var rSelector = this,
  9663. minInput = rSelector.minInput,
  9664. maxInput = rSelector.maxInput;
  9665. rSelector.unMouseDown();
  9666. rSelector.unResize();
  9667. // Destroy elements in collections
  9668. destroyObjectProperties(rSelector.buttons);
  9669. // Clear input element events
  9670. if (minInput) {
  9671. minInput.onfocus = minInput.onblur = minInput.onchange = null;
  9672. }
  9673. if (maxInput) {
  9674. maxInput.onfocus = maxInput.onblur = maxInput.onchange = null;
  9675. }
  9676. // Destroy HTML and SVG elements
  9677. objectEach(rSelector, function (val, key) {
  9678. if (val && key !== 'chart') {
  9679. if (val instanceof SVGElement) {
  9680. // SVGElement
  9681. val.destroy();
  9682. }
  9683. else if (val instanceof window.HTMLElement) {
  9684. // HTML element
  9685. discardElement(val);
  9686. }
  9687. }
  9688. if (val !== RangeSelector.prototype[key]) {
  9689. rSelector[key] = null;
  9690. }
  9691. }, this);
  9692. };
  9693. return RangeSelector;
  9694. }());
  9695. /**
  9696. * The default buttons for pre-selecting time frames
  9697. */
  9698. RangeSelector.prototype.defaultButtons = [{
  9699. type: 'month',
  9700. count: 1,
  9701. text: '1m'
  9702. }, {
  9703. type: 'month',
  9704. count: 3,
  9705. text: '3m'
  9706. }, {
  9707. type: 'month',
  9708. count: 6,
  9709. text: '6m'
  9710. }, {
  9711. type: 'ytd',
  9712. text: 'YTD'
  9713. }, {
  9714. type: 'year',
  9715. count: 1,
  9716. text: '1y'
  9717. }, {
  9718. type: 'all',
  9719. text: 'All'
  9720. }];
  9721. /**
  9722. * Get the axis min value based on the range option and the current max. For
  9723. * stock charts this is extended via the {@link RangeSelector} so that if the
  9724. * selected range is a multiple of months or years, it is compensated for
  9725. * various month lengths.
  9726. *
  9727. * @private
  9728. * @function Highcharts.Axis#minFromRange
  9729. * @return {number|undefined}
  9730. * The new minimum value.
  9731. */
  9732. Axis.prototype.minFromRange = function () {
  9733. var rangeOptions = this.range,
  9734. type = rangeOptions.type,
  9735. min,
  9736. max = this.max,
  9737. dataMin,
  9738. range,
  9739. time = this.chart.time,
  9740. // Get the true range from a start date
  9741. getTrueRange = function (base,
  9742. count) {
  9743. var timeName = type === 'year' ? 'FullYear' : 'Month';
  9744. var date = new time.Date(base);
  9745. var basePeriod = time.get(timeName,
  9746. date);
  9747. time.set(timeName, date, basePeriod + count);
  9748. if (basePeriod === time.get(timeName, date)) {
  9749. time.set('Date', date, 0); // #6537
  9750. }
  9751. return date.getTime() - base;
  9752. };
  9753. if (isNumber(rangeOptions)) {
  9754. min = max - rangeOptions;
  9755. range = rangeOptions;
  9756. }
  9757. else {
  9758. min = max + getTrueRange(max, -rangeOptions.count);
  9759. // Let the fixedRange reflect initial settings (#5930)
  9760. if (this.chart) {
  9761. this.chart.fixedRange = max - min;
  9762. }
  9763. }
  9764. dataMin = pick(this.dataMin, Number.MIN_VALUE);
  9765. if (!isNumber(min)) {
  9766. min = dataMin;
  9767. }
  9768. if (min <= dataMin) {
  9769. min = dataMin;
  9770. if (typeof range === 'undefined') { // #4501
  9771. range = getTrueRange(min, rangeOptions.count);
  9772. }
  9773. this.newMax = Math.min(min + range, this.dataMax);
  9774. }
  9775. if (!isNumber(max)) {
  9776. min = void 0;
  9777. }
  9778. return min;
  9779. };
  9780. if (!H.RangeSelector) {
  9781. // Initialize rangeselector for stock charts
  9782. addEvent(Chart, 'afterGetContainer', function () {
  9783. if (this.options.rangeSelector.enabled) {
  9784. this.rangeSelector = new RangeSelector(this);
  9785. }
  9786. });
  9787. addEvent(Chart, 'beforeRender', function () {
  9788. var chart = this,
  9789. axes = chart.axes,
  9790. rangeSelector = chart.rangeSelector,
  9791. verticalAlign;
  9792. if (rangeSelector) {
  9793. if (isNumber(rangeSelector.deferredYTDClick)) {
  9794. rangeSelector.clickButton(rangeSelector.deferredYTDClick);
  9795. delete rangeSelector.deferredYTDClick;
  9796. }
  9797. axes.forEach(function (axis) {
  9798. axis.updateNames();
  9799. axis.setScale();
  9800. });
  9801. chart.getAxisMargins();
  9802. rangeSelector.render();
  9803. verticalAlign = rangeSelector.options.verticalAlign;
  9804. if (!rangeSelector.options.floating) {
  9805. if (verticalAlign === 'bottom') {
  9806. this.extraBottomMargin = true;
  9807. }
  9808. else if (verticalAlign !== 'middle') {
  9809. this.extraTopMargin = true;
  9810. }
  9811. }
  9812. }
  9813. });
  9814. addEvent(Chart, 'update', function (e) {
  9815. var chart = this,
  9816. options = e.options,
  9817. optionsRangeSelector = options.rangeSelector,
  9818. rangeSelector = chart.rangeSelector,
  9819. verticalAlign,
  9820. extraBottomMarginWas = this.extraBottomMargin,
  9821. extraTopMarginWas = this.extraTopMargin;
  9822. if (optionsRangeSelector &&
  9823. optionsRangeSelector.enabled &&
  9824. !defined(rangeSelector)) {
  9825. this.options.rangeSelector.enabled = true;
  9826. this.rangeSelector = new RangeSelector(this);
  9827. }
  9828. this.extraBottomMargin = false;
  9829. this.extraTopMargin = false;
  9830. if (rangeSelector) {
  9831. rangeSelector.render();
  9832. verticalAlign = (optionsRangeSelector &&
  9833. optionsRangeSelector.verticalAlign) || (rangeSelector.options && rangeSelector.options.verticalAlign);
  9834. if (!rangeSelector.options.floating) {
  9835. if (verticalAlign === 'bottom') {
  9836. this.extraBottomMargin = true;
  9837. }
  9838. else if (verticalAlign !== 'middle') {
  9839. this.extraTopMargin = true;
  9840. }
  9841. }
  9842. if (this.extraBottomMargin !== extraBottomMarginWas ||
  9843. this.extraTopMargin !== extraTopMarginWas) {
  9844. this.isDirtyBox = true;
  9845. }
  9846. }
  9847. });
  9848. addEvent(Chart, 'render', function () {
  9849. var chart = this,
  9850. rangeSelector = chart.rangeSelector,
  9851. verticalAlign;
  9852. if (rangeSelector && !rangeSelector.options.floating) {
  9853. rangeSelector.render();
  9854. verticalAlign = rangeSelector.options.verticalAlign;
  9855. if (verticalAlign === 'bottom') {
  9856. this.extraBottomMargin = true;
  9857. }
  9858. else if (verticalAlign !== 'middle') {
  9859. this.extraTopMargin = true;
  9860. }
  9861. }
  9862. });
  9863. addEvent(Chart, 'getMargins', function () {
  9864. var rangeSelector = this.rangeSelector,
  9865. rangeSelectorHeight;
  9866. if (rangeSelector) {
  9867. rangeSelectorHeight = rangeSelector.getHeight();
  9868. if (this.extraTopMargin) {
  9869. this.plotTop += rangeSelectorHeight;
  9870. }
  9871. if (this.extraBottomMargin) {
  9872. this.marginBottom += rangeSelectorHeight;
  9873. }
  9874. }
  9875. });
  9876. Chart.prototype.callbacks.push(function (chart) {
  9877. var extremes,
  9878. rangeSelector = chart.rangeSelector,
  9879. unbindRender,
  9880. unbindSetExtremes,
  9881. legend,
  9882. alignTo,
  9883. verticalAlign;
  9884. /**
  9885. * @private
  9886. */
  9887. function renderRangeSelector() {
  9888. extremes = chart.xAxis[0].getExtremes();
  9889. legend = chart.legend;
  9890. verticalAlign = rangeSelector === null || rangeSelector === void 0 ? void 0 : rangeSelector.options.verticalAlign;
  9891. if (isNumber(extremes.min)) {
  9892. rangeSelector.render(extremes.min, extremes.max);
  9893. }
  9894. // Re-align the legend so that it's below the rangeselector
  9895. if (rangeSelector && legend.display &&
  9896. verticalAlign === 'top' &&
  9897. verticalAlign === legend.options.verticalAlign) {
  9898. // Create a new alignment box for the legend.
  9899. alignTo = merge(chart.spacingBox);
  9900. if (legend.options.layout === 'vertical') {
  9901. alignTo.y = chart.plotTop;
  9902. }
  9903. else {
  9904. alignTo.y += rangeSelector.getHeight();
  9905. }
  9906. legend.group.placed = false; // Don't animate the alignment.
  9907. legend.align(alignTo);
  9908. }
  9909. }
  9910. if (rangeSelector) {
  9911. // redraw the scroller on setExtremes
  9912. unbindSetExtremes = addEvent(chart.xAxis[0], 'afterSetExtremes', function (e) {
  9913. rangeSelector.render(e.min, e.max);
  9914. });
  9915. // redraw the scroller chart resize
  9916. unbindRender = addEvent(chart, 'redraw', renderRangeSelector);
  9917. // do it now
  9918. renderRangeSelector();
  9919. }
  9920. // Remove resize/afterSetExtremes at chart destroy
  9921. addEvent(chart, 'destroy', function destroyEvents() {
  9922. if (rangeSelector) {
  9923. unbindRender();
  9924. unbindSetExtremes();
  9925. }
  9926. });
  9927. });
  9928. H.RangeSelector = RangeSelector;
  9929. }
  9930. return H.RangeSelector;
  9931. });
  9932. _registerModule(_modules, 'Core/Axis/NavigatorAxis.js', [_modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (H, U) {
  9933. /* *
  9934. *
  9935. * (c) 2010-2020 Torstein Honsi
  9936. *
  9937. * License: www.highcharts.com/license
  9938. *
  9939. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  9940. *
  9941. * */
  9942. var isTouchDevice = H.isTouchDevice;
  9943. var addEvent = U.addEvent,
  9944. correctFloat = U.correctFloat,
  9945. defined = U.defined,
  9946. isNumber = U.isNumber,
  9947. pick = U.pick;
  9948. /* eslint-disable valid-jsdoc */
  9949. /**
  9950. * @private
  9951. * @class
  9952. */
  9953. var NavigatorAxisAdditions = /** @class */ (function () {
  9954. /* *
  9955. *
  9956. * Constructors
  9957. *
  9958. * */
  9959. function NavigatorAxisAdditions(axis) {
  9960. this.axis = axis;
  9961. }
  9962. /* *
  9963. *
  9964. * Functions
  9965. *
  9966. * */
  9967. /**
  9968. * @private
  9969. */
  9970. NavigatorAxisAdditions.prototype.destroy = function () {
  9971. this.axis = void 0;
  9972. };
  9973. /**
  9974. * Add logic to normalize the zoomed range in order to preserve the pressed
  9975. * state of range selector buttons
  9976. *
  9977. * @private
  9978. * @function Highcharts.Axis#toFixedRange
  9979. * @param {number} [pxMin]
  9980. * @param {number} [pxMax]
  9981. * @param {number} [fixedMin]
  9982. * @param {number} [fixedMax]
  9983. * @return {*}
  9984. */
  9985. NavigatorAxisAdditions.prototype.toFixedRange = function (pxMin, pxMax, fixedMin, fixedMax) {
  9986. var navigator = this;
  9987. var axis = navigator.axis;
  9988. var chart = axis.chart;
  9989. var fixedRange = chart && chart.fixedRange,
  9990. halfPointRange = (axis.pointRange || 0) / 2,
  9991. newMin = pick(fixedMin,
  9992. axis.translate(pxMin,
  9993. true, !axis.horiz)),
  9994. newMax = pick(fixedMax,
  9995. axis.translate(pxMax,
  9996. true, !axis.horiz)),
  9997. changeRatio = fixedRange && (newMax - newMin) / fixedRange;
  9998. // Add/remove half point range to/from the extremes (#1172)
  9999. if (!defined(fixedMin)) {
  10000. newMin = correctFloat(newMin + halfPointRange);
  10001. }
  10002. if (!defined(fixedMax)) {
  10003. newMax = correctFloat(newMax - halfPointRange);
  10004. }
  10005. // If the difference between the fixed range and the actual requested
  10006. // range is too great, the user is dragging across an ordinal gap, and
  10007. // we need to release the range selector button.
  10008. if (changeRatio > 0.7 && changeRatio < 1.3) {
  10009. if (fixedMax) {
  10010. newMin = newMax - fixedRange;
  10011. }
  10012. else {
  10013. newMax = newMin + fixedRange;
  10014. }
  10015. }
  10016. if (!isNumber(newMin) || !isNumber(newMax)) { // #1195, #7411
  10017. newMin = newMax = void 0;
  10018. }
  10019. return {
  10020. min: newMin,
  10021. max: newMax
  10022. };
  10023. };
  10024. return NavigatorAxisAdditions;
  10025. }());
  10026. /**
  10027. * @private
  10028. * @class
  10029. */
  10030. var NavigatorAxis = /** @class */ (function () {
  10031. function NavigatorAxis() {
  10032. }
  10033. /* *
  10034. *
  10035. * Static Functions
  10036. *
  10037. * */
  10038. /**
  10039. * @private
  10040. */
  10041. NavigatorAxis.compose = function (AxisClass) {
  10042. AxisClass.keepProps.push('navigatorAxis');
  10043. /* eslint-disable no-invalid-this */
  10044. addEvent(AxisClass, 'init', function () {
  10045. var axis = this;
  10046. if (!axis.navigatorAxis) {
  10047. axis.navigatorAxis = new NavigatorAxisAdditions(axis);
  10048. }
  10049. });
  10050. // For Stock charts, override selection zooming with some special
  10051. // features because X axis zooming is already allowed by the Navigator
  10052. // and Range selector.
  10053. addEvent(AxisClass, 'zoom', function (e) {
  10054. var axis = this;
  10055. var chart = axis.chart;
  10056. var chartOptions = chart.options;
  10057. var navigator = chartOptions.navigator;
  10058. var navigatorAxis = axis.navigatorAxis;
  10059. var pinchType = chartOptions.chart.pinchType;
  10060. var rangeSelector = chartOptions.rangeSelector;
  10061. var zoomType = chartOptions.chart.zoomType;
  10062. var previousZoom;
  10063. if (axis.isXAxis && ((navigator && navigator.enabled) ||
  10064. (rangeSelector && rangeSelector.enabled))) {
  10065. // For y only zooming, ignore the X axis completely
  10066. if (zoomType === 'y') {
  10067. e.zoomed = false;
  10068. // For xy zooming, record the state of the zoom before zoom
  10069. // selection, then when the reset button is pressed, revert to
  10070. // this state. This should apply only if the chart is
  10071. // initialized with a range (#6612), otherwise zoom all the way
  10072. // out.
  10073. }
  10074. else if (((!isTouchDevice && zoomType === 'xy') ||
  10075. (isTouchDevice && pinchType === 'xy')) &&
  10076. axis.options.range) {
  10077. previousZoom = navigatorAxis.previousZoom;
  10078. if (defined(e.newMin)) {
  10079. navigatorAxis.previousZoom = [axis.min, axis.max];
  10080. }
  10081. else if (previousZoom) {
  10082. e.newMin = previousZoom[0];
  10083. e.newMax = previousZoom[1];
  10084. navigatorAxis.previousZoom = void 0;
  10085. }
  10086. }
  10087. }
  10088. if (typeof e.zoomed !== 'undefined') {
  10089. e.preventDefault();
  10090. }
  10091. });
  10092. /* eslint-enable no-invalid-this */
  10093. };
  10094. /* *
  10095. *
  10096. * Static Properties
  10097. *
  10098. * */
  10099. /**
  10100. * @private
  10101. */
  10102. NavigatorAxis.AdditionsClass = NavigatorAxisAdditions;
  10103. return NavigatorAxis;
  10104. }());
  10105. return NavigatorAxis;
  10106. });
  10107. _registerModule(_modules, 'Core/Navigator.js', [_modules['Core/Axis/Axis.js'], _modules['Core/Chart/Chart.js'], _modules['Core/Color.js'], _modules['Core/Globals.js'], _modules['Core/Axis/NavigatorAxis.js'], _modules['Core/Options.js'], _modules['Core/Scrollbar.js'], _modules['Core/Utilities.js']], function (Axis, Chart, Color, H, NavigatorAxis, O, Scrollbar, U) {
  10108. /* *
  10109. *
  10110. * (c) 2010-2020 Torstein Honsi
  10111. *
  10112. * License: www.highcharts.com/license
  10113. *
  10114. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  10115. *
  10116. * */
  10117. var color = Color.parse;
  10118. var defaultOptions = O.defaultOptions;
  10119. var addEvent = U.addEvent,
  10120. clamp = U.clamp,
  10121. correctFloat = U.correctFloat,
  10122. defined = U.defined,
  10123. destroyObjectProperties = U.destroyObjectProperties,
  10124. erase = U.erase,
  10125. extend = U.extend,
  10126. find = U.find,
  10127. isArray = U.isArray,
  10128. isNumber = U.isNumber,
  10129. merge = U.merge,
  10130. pick = U.pick,
  10131. removeEvent = U.removeEvent,
  10132. splat = U.splat;
  10133. var hasTouch = H.hasTouch,
  10134. isTouchDevice = H.isTouchDevice,
  10135. Series = H.Series,
  10136. seriesTypes = H.seriesTypes,
  10137. defaultSeriesType,
  10138. // Finding the min or max of a set of variables where we don't know if they
  10139. // are defined, is a pattern that is repeated several places in Highcharts.
  10140. // Consider making this a global utility method.
  10141. numExt = function (extreme) {
  10142. var args = [];
  10143. for (var _i = 1; _i < arguments.length; _i++) {
  10144. args[_i - 1] = arguments[_i];
  10145. }
  10146. var numbers = [].filter.call(args,
  10147. isNumber);
  10148. if (numbers.length) {
  10149. return Math[extreme].apply(0, numbers);
  10150. }
  10151. };
  10152. defaultSeriesType = typeof seriesTypes.areaspline === 'undefined' ?
  10153. 'line' :
  10154. 'areaspline';
  10155. extend(defaultOptions, {
  10156. /**
  10157. * Maximum range which can be set using the navigator's handles.
  10158. * Opposite of [xAxis.minRange](#xAxis.minRange).
  10159. *
  10160. * @sample {highstock} stock/navigator/maxrange/
  10161. * Defined max and min range
  10162. *
  10163. * @type {number}
  10164. * @since 6.0.0
  10165. * @product highstock gantt
  10166. * @apioption xAxis.maxRange
  10167. */
  10168. /**
  10169. * The navigator is a small series below the main series, displaying
  10170. * a view of the entire data set. It provides tools to zoom in and
  10171. * out on parts of the data as well as panning across the dataset.
  10172. *
  10173. * @product highstock gantt
  10174. * @optionparent navigator
  10175. */
  10176. navigator: {
  10177. /**
  10178. * Whether the navigator and scrollbar should adapt to updated data
  10179. * in the base X axis. When loading data async, as in the demo below,
  10180. * this should be `false`. Otherwise new data will trigger navigator
  10181. * redraw, which will cause unwanted looping. In the demo below, the
  10182. * data in the navigator is set only once. On navigating, only the main
  10183. * chart content is updated.
  10184. *
  10185. * @sample {highstock} stock/demo/lazy-loading/
  10186. * Set to false with async data loading
  10187. *
  10188. * @type {boolean}
  10189. * @default true
  10190. * @apioption navigator.adaptToUpdatedData
  10191. */
  10192. /**
  10193. * An integer identifying the index to use for the base series, or a
  10194. * string representing the id of the series.
  10195. *
  10196. * **Note**: As of Highcharts 5.0, this is now a deprecated option.
  10197. * Prefer [series.showInNavigator](#plotOptions.series.showInNavigator).
  10198. *
  10199. * @see [series.showInNavigator](#plotOptions.series.showInNavigator)
  10200. *
  10201. * @deprecated
  10202. * @type {number|string}
  10203. * @default 0
  10204. * @apioption navigator.baseSeries
  10205. */
  10206. /**
  10207. * Enable or disable the navigator.
  10208. *
  10209. * @sample {highstock} stock/navigator/enabled/
  10210. * Disable the navigator
  10211. *
  10212. * @type {boolean}
  10213. * @default true
  10214. * @apioption navigator.enabled
  10215. */
  10216. /**
  10217. * When the chart is inverted, whether to draw the navigator on the
  10218. * opposite side.
  10219. *
  10220. * @type {boolean}
  10221. * @default false
  10222. * @since 5.0.8
  10223. * @apioption navigator.opposite
  10224. */
  10225. /**
  10226. * The height of the navigator.
  10227. *
  10228. * @sample {highstock} stock/navigator/height/
  10229. * A higher navigator
  10230. */
  10231. height: 40,
  10232. /**
  10233. * The distance from the nearest element, the X axis or X axis labels.
  10234. *
  10235. * @sample {highstock} stock/navigator/margin/
  10236. * A margin of 2 draws the navigator closer to the X axis labels
  10237. */
  10238. margin: 25,
  10239. /**
  10240. * Whether the mask should be inside the range marking the zoomed
  10241. * range, or outside. In Highstock 1.x it was always `false`.
  10242. *
  10243. * @sample {highstock} stock/navigator/maskinside-false/
  10244. * False, mask outside
  10245. *
  10246. * @since 2.0
  10247. */
  10248. maskInside: true,
  10249. /**
  10250. * Options for the handles for dragging the zoomed area.
  10251. *
  10252. * @sample {highstock} stock/navigator/handles/
  10253. * Colored handles
  10254. */
  10255. handles: {
  10256. /**
  10257. * Width for handles.
  10258. *
  10259. * @sample {highstock} stock/navigator/styled-handles/
  10260. * Styled handles
  10261. *
  10262. * @since 6.0.0
  10263. */
  10264. width: 7,
  10265. /**
  10266. * Height for handles.
  10267. *
  10268. * @sample {highstock} stock/navigator/styled-handles/
  10269. * Styled handles
  10270. *
  10271. * @since 6.0.0
  10272. */
  10273. height: 15,
  10274. /**
  10275. * Array to define shapes of handles. 0-index for left, 1-index for
  10276. * right.
  10277. *
  10278. * Additionally, the URL to a graphic can be given on this form:
  10279. * `url(graphic.png)`. Note that for the image to be applied to
  10280. * exported charts, its URL needs to be accessible by the export
  10281. * server.
  10282. *
  10283. * Custom callbacks for symbol path generation can also be added to
  10284. * `Highcharts.SVGRenderer.prototype.symbols`. The callback is then
  10285. * used by its method name, as shown in the demo.
  10286. *
  10287. * @sample {highstock} stock/navigator/styled-handles/
  10288. * Styled handles
  10289. *
  10290. * @type {Array<string>}
  10291. * @default ["navigator-handle", "navigator-handle"]
  10292. * @since 6.0.0
  10293. */
  10294. symbols: ['navigator-handle', 'navigator-handle'],
  10295. /**
  10296. * Allows to enable/disable handles.
  10297. *
  10298. * @since 6.0.0
  10299. */
  10300. enabled: true,
  10301. /**
  10302. * The width for the handle border and the stripes inside.
  10303. *
  10304. * @sample {highstock} stock/navigator/styled-handles/
  10305. * Styled handles
  10306. *
  10307. * @since 6.0.0
  10308. * @apioption navigator.handles.lineWidth
  10309. */
  10310. lineWidth: 1,
  10311. /**
  10312. * The fill for the handle.
  10313. *
  10314. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10315. */
  10316. backgroundColor: '#f2f2f2',
  10317. /**
  10318. * The stroke for the handle border and the stripes inside.
  10319. *
  10320. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10321. */
  10322. borderColor: '#999999'
  10323. },
  10324. /**
  10325. * The color of the mask covering the areas of the navigator series
  10326. * that are currently not visible in the main series. The default
  10327. * color is bluish with an opacity of 0.3 to see the series below.
  10328. *
  10329. * @see In styled mode, the mask is styled with the
  10330. * `.highcharts-navigator-mask` and
  10331. * `.highcharts-navigator-mask-inside` classes.
  10332. *
  10333. * @sample {highstock} stock/navigator/maskfill/
  10334. * Blue, semi transparent mask
  10335. *
  10336. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10337. * @default rgba(102,133,194,0.3)
  10338. */
  10339. maskFill: color('#6685c2').setOpacity(0.3).get(),
  10340. /**
  10341. * The color of the line marking the currently zoomed area in the
  10342. * navigator.
  10343. *
  10344. * @sample {highstock} stock/navigator/outline/
  10345. * 2px blue outline
  10346. *
  10347. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10348. * @default #cccccc
  10349. */
  10350. outlineColor: '#cccccc',
  10351. /**
  10352. * The width of the line marking the currently zoomed area in the
  10353. * navigator.
  10354. *
  10355. * @see In styled mode, the outline stroke width is set with the
  10356. * `.highcharts-navigator-outline` class.
  10357. *
  10358. * @sample {highstock} stock/navigator/outline/
  10359. * 2px blue outline
  10360. *
  10361. * @type {number}
  10362. */
  10363. outlineWidth: 1,
  10364. /**
  10365. * Options for the navigator series. Available options are the same
  10366. * as any series, documented at [plotOptions](#plotOptions.series)
  10367. * and [series](#series).
  10368. *
  10369. * Unless data is explicitly defined on navigator.series, the data
  10370. * is borrowed from the first series in the chart.
  10371. *
  10372. * Default series options for the navigator series are:
  10373. * ```js
  10374. * series: {
  10375. * type: 'areaspline',
  10376. * fillOpacity: 0.05,
  10377. * dataGrouping: {
  10378. * smoothed: true
  10379. * },
  10380. * lineWidth: 1,
  10381. * marker: {
  10382. * enabled: false
  10383. * }
  10384. * }
  10385. * ```
  10386. *
  10387. * @see In styled mode, the navigator series is styled with the
  10388. * `.highcharts-navigator-series` class.
  10389. *
  10390. * @sample {highstock} stock/navigator/series-data/
  10391. * Using a separate data set for the navigator
  10392. * @sample {highstock} stock/navigator/series/
  10393. * A green navigator series
  10394. *
  10395. * @type {*|Array<*>|Highcharts.SeriesOptionsType|Array<Highcharts.SeriesOptionsType>}
  10396. */
  10397. series: {
  10398. /**
  10399. * The type of the navigator series.
  10400. *
  10401. * Heads up:
  10402. * In column-type navigator, zooming is limited to at least one
  10403. * point with its `pointRange`.
  10404. *
  10405. * @sample {highstock} stock/navigator/column/
  10406. * Column type navigator
  10407. *
  10408. * @type {string}
  10409. * @default {highstock} `areaspline` if defined, otherwise `line`
  10410. * @default {gantt} gantt
  10411. */
  10412. type: defaultSeriesType,
  10413. /**
  10414. * The fill opacity of the navigator series.
  10415. */
  10416. fillOpacity: 0.05,
  10417. /**
  10418. * The pixel line width of the navigator series.
  10419. */
  10420. lineWidth: 1,
  10421. /**
  10422. * @ignore-option
  10423. */
  10424. compare: null,
  10425. /**
  10426. * Unless data is explicitly defined, the data is borrowed from the
  10427. * first series in the chart.
  10428. *
  10429. * @type {Array<number|Array<number|string|null>|object|null>}
  10430. * @product highstock
  10431. * @apioption navigator.series.data
  10432. */
  10433. /**
  10434. * Data grouping options for the navigator series.
  10435. *
  10436. * @extends plotOptions.series.dataGrouping
  10437. */
  10438. dataGrouping: {
  10439. approximation: 'average',
  10440. enabled: true,
  10441. groupPixelWidth: 2,
  10442. smoothed: true,
  10443. // Day and week differs from plotOptions.series.dataGrouping
  10444. units: [
  10445. ['millisecond', [1, 2, 5, 10, 20, 25, 50, 100, 200, 500]],
  10446. ['second', [1, 2, 5, 10, 15, 30]],
  10447. ['minute', [1, 2, 5, 10, 15, 30]],
  10448. ['hour', [1, 2, 3, 4, 6, 8, 12]],
  10449. ['day', [1, 2, 3, 4]],
  10450. ['week', [1, 2, 3]],
  10451. ['month', [1, 3, 6]],
  10452. ['year', null]
  10453. ]
  10454. },
  10455. /**
  10456. * Data label options for the navigator series. Data labels are
  10457. * disabled by default on the navigator series.
  10458. *
  10459. * @extends plotOptions.series.dataLabels
  10460. */
  10461. dataLabels: {
  10462. enabled: false,
  10463. zIndex: 2 // #1839
  10464. },
  10465. id: 'highcharts-navigator-series',
  10466. className: 'highcharts-navigator-series',
  10467. /**
  10468. * Sets the fill color of the navigator series.
  10469. *
  10470. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  10471. * @apioption navigator.series.color
  10472. */
  10473. /**
  10474. * Line color for the navigator series. Allows setting the color
  10475. * while disallowing the default candlestick setting.
  10476. *
  10477. * @type {Highcharts.ColorString|null}
  10478. */
  10479. lineColor: null,
  10480. marker: {
  10481. enabled: false
  10482. },
  10483. /**
  10484. * Since Highstock v8, default value is the same as default
  10485. * `pointRange` defined for a specific type (e.g. `null` for
  10486. * column type).
  10487. *
  10488. * In Highstock version < 8, defaults to 0.
  10489. *
  10490. * @extends plotOptions.series.pointRange
  10491. * @type {number|null}
  10492. * @apioption navigator.series.pointRange
  10493. */
  10494. /**
  10495. * The threshold option. Setting it to 0 will make the default
  10496. * navigator area series draw its area from the 0 value and up.
  10497. *
  10498. * @type {number|null}
  10499. */
  10500. threshold: null
  10501. },
  10502. /**
  10503. * Options for the navigator X axis. Default series options for the
  10504. * navigator xAxis are:
  10505. * ```js
  10506. * xAxis: {
  10507. * tickWidth: 0,
  10508. * lineWidth: 0,
  10509. * gridLineWidth: 1,
  10510. * tickPixelInterval: 200,
  10511. * labels: {
  10512. * align: 'left',
  10513. * style: {
  10514. * color: '#888'
  10515. * },
  10516. * x: 3,
  10517. * y: -4
  10518. * }
  10519. * }
  10520. * ```
  10521. *
  10522. * @extends xAxis
  10523. * @excluding linkedTo, maxZoom, minRange, opposite, range, scrollbar,
  10524. * showEmpty, maxRange
  10525. */
  10526. xAxis: {
  10527. /**
  10528. * Additional range on the right side of the xAxis. Works similar to
  10529. * xAxis.maxPadding, but value is set in milliseconds.
  10530. * Can be set for both, main xAxis and navigator's xAxis.
  10531. *
  10532. * @since 6.0.0
  10533. */
  10534. overscroll: 0,
  10535. className: 'highcharts-navigator-xaxis',
  10536. tickLength: 0,
  10537. lineWidth: 0,
  10538. gridLineColor: '#e6e6e6',
  10539. gridLineWidth: 1,
  10540. tickPixelInterval: 200,
  10541. labels: {
  10542. align: 'left',
  10543. /**
  10544. * @type {Highcharts.CSSObject}
  10545. */
  10546. style: {
  10547. /** @ignore */
  10548. color: '#999999'
  10549. },
  10550. x: 3,
  10551. y: -4
  10552. },
  10553. crosshair: false
  10554. },
  10555. /**
  10556. * Options for the navigator Y axis. Default series options for the
  10557. * navigator yAxis are:
  10558. * ```js
  10559. * yAxis: {
  10560. * gridLineWidth: 0,
  10561. * startOnTick: false,
  10562. * endOnTick: false,
  10563. * minPadding: 0.1,
  10564. * maxPadding: 0.1,
  10565. * labels: {
  10566. * enabled: false
  10567. * },
  10568. * title: {
  10569. * text: null
  10570. * },
  10571. * tickWidth: 0
  10572. * }
  10573. * ```
  10574. *
  10575. * @extends yAxis
  10576. * @excluding height, linkedTo, maxZoom, minRange, ordinal, range,
  10577. * showEmpty, scrollbar, top, units, maxRange, minLength,
  10578. * maxLength, resize
  10579. */
  10580. yAxis: {
  10581. className: 'highcharts-navigator-yaxis',
  10582. gridLineWidth: 0,
  10583. startOnTick: false,
  10584. endOnTick: false,
  10585. minPadding: 0.1,
  10586. maxPadding: 0.1,
  10587. labels: {
  10588. enabled: false
  10589. },
  10590. crosshair: false,
  10591. title: {
  10592. text: null
  10593. },
  10594. tickLength: 0,
  10595. tickWidth: 0
  10596. }
  10597. }
  10598. });
  10599. /* eslint-disable no-invalid-this, valid-jsdoc */
  10600. /**
  10601. * Draw one of the handles on the side of the zoomed range in the navigator
  10602. *
  10603. * @private
  10604. * @function Highcharts.Renderer#symbols.navigator-handle
  10605. * @param {number} x
  10606. * @param {number} y
  10607. * @param {number} w
  10608. * @param {number} h
  10609. * @param {Highcharts.NavigatorHandlesOptions} options
  10610. * @return {Highcharts.SVGPathArray}
  10611. * Path to be used in a handle
  10612. */
  10613. H.Renderer.prototype.symbols['navigator-handle'] = function (x, y, w, h, options) {
  10614. var halfWidth = (options && options.width || 0) / 2,
  10615. markerPosition = Math.round(halfWidth / 3) + 0.5,
  10616. height = options && options.height || 0;
  10617. return [
  10618. ['M', -halfWidth - 1, 0.5],
  10619. ['L', halfWidth, 0.5],
  10620. ['L', halfWidth, height + 0.5],
  10621. ['L', -halfWidth - 1, height + 0.5],
  10622. ['L', -halfWidth - 1, 0.5],
  10623. ['M', -markerPosition, 4],
  10624. ['L', -markerPosition, height - 3],
  10625. ['M', markerPosition - 1, 4],
  10626. ['L', markerPosition - 1, height - 3]
  10627. ];
  10628. };
  10629. /**
  10630. * The Navigator class
  10631. *
  10632. * @private
  10633. * @class
  10634. * @name Highcharts.Navigator
  10635. *
  10636. * @param {Highcharts.Chart} chart
  10637. * Chart object
  10638. */
  10639. var Navigator = /** @class */ (function () {
  10640. function Navigator(chart) {
  10641. this.baseSeries = void 0;
  10642. this.chart = void 0;
  10643. this.handles = void 0;
  10644. this.height = void 0;
  10645. this.left = void 0;
  10646. this.navigatorEnabled = void 0;
  10647. this.navigatorGroup = void 0;
  10648. this.navigatorOptions = void 0;
  10649. this.navigatorSeries = void 0;
  10650. this.navigatorSize = void 0;
  10651. this.opposite = void 0;
  10652. this.outline = void 0;
  10653. this.outlineHeight = void 0;
  10654. this.range = void 0;
  10655. this.rendered = void 0;
  10656. this.shades = void 0;
  10657. this.size = void 0;
  10658. this.top = void 0;
  10659. this.xAxis = void 0;
  10660. this.yAxis = void 0;
  10661. this.zoomedMax = void 0;
  10662. this.zoomedMin = void 0;
  10663. this.init(chart);
  10664. }
  10665. /**
  10666. * Draw one of the handles on the side of the zoomed range in the navigator
  10667. *
  10668. * @private
  10669. * @function Highcharts.Navigator#drawHandle
  10670. *
  10671. * @param {number} x
  10672. * The x center for the handle
  10673. *
  10674. * @param {number} index
  10675. * 0 for left and 1 for right
  10676. *
  10677. * @param {boolean|undefined} inverted
  10678. * flag for chart.inverted
  10679. *
  10680. * @param {string} verb
  10681. * use 'animate' or 'attr'
  10682. */
  10683. Navigator.prototype.drawHandle = function (x, index, inverted, verb) {
  10684. var navigator = this,
  10685. height = navigator.navigatorOptions.handles.height;
  10686. // Place it
  10687. navigator.handles[index][verb](inverted ? {
  10688. translateX: Math.round(navigator.left + navigator.height / 2),
  10689. translateY: Math.round(navigator.top + parseInt(x, 10) + 0.5 - height)
  10690. } : {
  10691. translateX: Math.round(navigator.left + parseInt(x, 10)),
  10692. translateY: Math.round(navigator.top + navigator.height / 2 - height / 2 - 1)
  10693. });
  10694. };
  10695. /**
  10696. * Render outline around the zoomed range
  10697. *
  10698. * @private
  10699. * @function Highcharts.Navigator#drawOutline
  10700. *
  10701. * @param {number} zoomedMin
  10702. * in pixels position where zoomed range starts
  10703. *
  10704. * @param {number} zoomedMax
  10705. * in pixels position where zoomed range ends
  10706. *
  10707. * @param {boolean|undefined} inverted
  10708. * flag if chart is inverted
  10709. *
  10710. * @param {string} verb
  10711. * use 'animate' or 'attr'
  10712. */
  10713. Navigator.prototype.drawOutline = function (zoomedMin, zoomedMax, inverted, verb) {
  10714. var navigator = this,
  10715. maskInside = navigator.navigatorOptions.maskInside,
  10716. outlineWidth = navigator.outline.strokeWidth(),
  10717. halfOutline = outlineWidth / 2,
  10718. outlineCorrection = (outlineWidth % 2) / 2, // #5800
  10719. outlineHeight = navigator.outlineHeight,
  10720. scrollbarHeight = navigator.scrollbarHeight || 0,
  10721. navigatorSize = navigator.size,
  10722. left = navigator.left - scrollbarHeight,
  10723. navigatorTop = navigator.top,
  10724. verticalMin,
  10725. path;
  10726. if (inverted) {
  10727. left -= halfOutline;
  10728. verticalMin = navigatorTop + zoomedMax + outlineCorrection;
  10729. zoomedMax = navigatorTop + zoomedMin + outlineCorrection;
  10730. path = [
  10731. ['M', left + outlineHeight, navigatorTop - scrollbarHeight - outlineCorrection],
  10732. ['L', left + outlineHeight, verticalMin],
  10733. ['L', left, verticalMin],
  10734. ['L', left, zoomedMax],
  10735. ['L', left + outlineHeight, zoomedMax],
  10736. ['L', left + outlineHeight, navigatorTop + navigatorSize + scrollbarHeight]
  10737. ];
  10738. if (maskInside) {
  10739. path.push(['M', left + outlineHeight, verticalMin - halfOutline], // upper left of zoomed range
  10740. ['L', left + outlineHeight, zoomedMax + halfOutline] // upper right of z.r.
  10741. );
  10742. }
  10743. }
  10744. else {
  10745. zoomedMin += left + scrollbarHeight - outlineCorrection;
  10746. zoomedMax += left + scrollbarHeight - outlineCorrection;
  10747. navigatorTop += halfOutline;
  10748. path = [
  10749. ['M', left, navigatorTop],
  10750. ['L', zoomedMin, navigatorTop],
  10751. ['L', zoomedMin, navigatorTop + outlineHeight],
  10752. ['L', zoomedMax, navigatorTop + outlineHeight],
  10753. ['L', zoomedMax, navigatorTop],
  10754. ['L', left + navigatorSize + scrollbarHeight * 2, navigatorTop] // right
  10755. ];
  10756. if (maskInside) {
  10757. path.push(['M', zoomedMin - halfOutline, navigatorTop], // upper left of zoomed range
  10758. ['L', zoomedMax + halfOutline, navigatorTop] // upper right of z.r.
  10759. );
  10760. }
  10761. }
  10762. navigator.outline[verb]({
  10763. d: path
  10764. });
  10765. };
  10766. /**
  10767. * Render outline around the zoomed range
  10768. *
  10769. * @private
  10770. * @function Highcharts.Navigator#drawMasks
  10771. *
  10772. * @param {number} zoomedMin
  10773. * in pixels position where zoomed range starts
  10774. *
  10775. * @param {number} zoomedMax
  10776. * in pixels position where zoomed range ends
  10777. *
  10778. * @param {boolean|undefined} inverted
  10779. * flag if chart is inverted
  10780. *
  10781. * @param {string} verb
  10782. * use 'animate' or 'attr'
  10783. */
  10784. Navigator.prototype.drawMasks = function (zoomedMin, zoomedMax, inverted, verb) {
  10785. var navigator = this,
  10786. left = navigator.left,
  10787. top = navigator.top,
  10788. navigatorHeight = navigator.height,
  10789. height,
  10790. width,
  10791. x,
  10792. y;
  10793. // Determine rectangle position & size
  10794. // According to (non)inverted position:
  10795. if (inverted) {
  10796. x = [left, left, left];
  10797. y = [top, top + zoomedMin, top + zoomedMax];
  10798. width = [navigatorHeight, navigatorHeight, navigatorHeight];
  10799. height = [
  10800. zoomedMin,
  10801. zoomedMax - zoomedMin,
  10802. navigator.size - zoomedMax
  10803. ];
  10804. }
  10805. else {
  10806. x = [left, left + zoomedMin, left + zoomedMax];
  10807. y = [top, top, top];
  10808. width = [
  10809. zoomedMin,
  10810. zoomedMax - zoomedMin,
  10811. navigator.size - zoomedMax
  10812. ];
  10813. height = [navigatorHeight, navigatorHeight, navigatorHeight];
  10814. }
  10815. navigator.shades.forEach(function (shade, i) {
  10816. shade[verb]({
  10817. x: x[i],
  10818. y: y[i],
  10819. width: width[i],
  10820. height: height[i]
  10821. });
  10822. });
  10823. };
  10824. /**
  10825. * Generate DOM elements for a navigator:
  10826. *
  10827. * - main navigator group
  10828. *
  10829. * - all shades
  10830. *
  10831. * - outline
  10832. *
  10833. * - handles
  10834. *
  10835. * @private
  10836. * @function Highcharts.Navigator#renderElements
  10837. */
  10838. Navigator.prototype.renderElements = function () {
  10839. var navigator = this,
  10840. navigatorOptions = navigator.navigatorOptions,
  10841. maskInside = navigatorOptions.maskInside,
  10842. chart = navigator.chart,
  10843. inverted = chart.inverted,
  10844. renderer = chart.renderer,
  10845. navigatorGroup,
  10846. mouseCursor = {
  10847. cursor: inverted ? 'ns-resize' : 'ew-resize'
  10848. };
  10849. // Create the main navigator group
  10850. navigator.navigatorGroup = navigatorGroup = renderer.g('navigator')
  10851. .attr({
  10852. zIndex: 8,
  10853. visibility: 'hidden'
  10854. })
  10855. .add();
  10856. // Create masks, each mask will get events and fill:
  10857. [
  10858. !maskInside,
  10859. maskInside,
  10860. !maskInside
  10861. ].forEach(function (hasMask, index) {
  10862. navigator.shades[index] = renderer.rect()
  10863. .addClass('highcharts-navigator-mask' +
  10864. (index === 1 ? '-inside' : '-outside'))
  10865. .add(navigatorGroup);
  10866. if (!chart.styledMode) {
  10867. navigator.shades[index]
  10868. .attr({
  10869. fill: hasMask ?
  10870. navigatorOptions.maskFill :
  10871. 'rgba(0,0,0,0)'
  10872. })
  10873. .css((index === 1) && mouseCursor);
  10874. }
  10875. });
  10876. // Create the outline:
  10877. navigator.outline = renderer.path()
  10878. .addClass('highcharts-navigator-outline')
  10879. .add(navigatorGroup);
  10880. if (!chart.styledMode) {
  10881. navigator.outline.attr({
  10882. 'stroke-width': navigatorOptions.outlineWidth,
  10883. stroke: navigatorOptions.outlineColor
  10884. });
  10885. }
  10886. // Create the handlers:
  10887. if (navigatorOptions.handles.enabled) {
  10888. [0, 1].forEach(function (index) {
  10889. navigatorOptions.handles.inverted = chart.inverted;
  10890. navigator.handles[index] = renderer.symbol(navigatorOptions.handles.symbols[index], -navigatorOptions.handles.width / 2 - 1, 0, navigatorOptions.handles.width, navigatorOptions.handles.height, navigatorOptions.handles);
  10891. // zIndex = 6 for right handle, 7 for left.
  10892. // Can't be 10, because of the tooltip in inverted chart #2908
  10893. navigator.handles[index].attr({ zIndex: 7 - index })
  10894. .addClass('highcharts-navigator-handle ' +
  10895. 'highcharts-navigator-handle-' +
  10896. ['left', 'right'][index]).add(navigatorGroup);
  10897. if (!chart.styledMode) {
  10898. var handlesOptions = navigatorOptions.handles;
  10899. navigator.handles[index]
  10900. .attr({
  10901. fill: handlesOptions.backgroundColor,
  10902. stroke: handlesOptions.borderColor,
  10903. 'stroke-width': handlesOptions.lineWidth
  10904. })
  10905. .css(mouseCursor);
  10906. }
  10907. });
  10908. }
  10909. };
  10910. /**
  10911. * Update navigator
  10912. *
  10913. * @private
  10914. * @function Highcharts.Navigator#update
  10915. *
  10916. * @param {Highcharts.NavigatorOptions} options
  10917. * Options to merge in when updating navigator
  10918. */
  10919. Navigator.prototype.update = function (options) {
  10920. // Remove references to old navigator series in base series
  10921. (this.series || []).forEach(function (series) {
  10922. if (series.baseSeries) {
  10923. delete series.baseSeries.navigatorSeries;
  10924. }
  10925. });
  10926. // Destroy and rebuild navigator
  10927. this.destroy();
  10928. var chartOptions = this.chart.options;
  10929. merge(true, chartOptions.navigator, this.options, options);
  10930. this.init(this.chart);
  10931. };
  10932. /**
  10933. * Render the navigator
  10934. *
  10935. * @private
  10936. * @function Highcharts.Navigator#render
  10937. * @param {number} min
  10938. * X axis value minimum
  10939. * @param {number} max
  10940. * X axis value maximum
  10941. * @param {number} [pxMin]
  10942. * Pixel value minimum
  10943. * @param {number} [pxMax]
  10944. * Pixel value maximum
  10945. * @return {void}
  10946. */
  10947. Navigator.prototype.render = function (min, max, pxMin, pxMax) {
  10948. var navigator = this,
  10949. chart = navigator.chart,
  10950. navigatorWidth,
  10951. scrollbarLeft,
  10952. scrollbarTop,
  10953. scrollbarHeight = navigator.scrollbarHeight,
  10954. navigatorSize,
  10955. xAxis = navigator.xAxis,
  10956. pointRange = xAxis.pointRange || 0,
  10957. scrollbarXAxis = xAxis.navigatorAxis.fake ? chart.xAxis[0] : xAxis,
  10958. navigatorEnabled = navigator.navigatorEnabled,
  10959. zoomedMin,
  10960. zoomedMax,
  10961. rendered = navigator.rendered,
  10962. inverted = chart.inverted,
  10963. verb,
  10964. newMin,
  10965. newMax,
  10966. currentRange,
  10967. minRange = chart.xAxis[0].minRange,
  10968. maxRange = chart.xAxis[0].options.maxRange;
  10969. // Don't redraw while moving the handles (#4703).
  10970. if (this.hasDragged && !defined(pxMin)) {
  10971. return;
  10972. }
  10973. min = correctFloat(min - pointRange / 2);
  10974. max = correctFloat(max + pointRange / 2);
  10975. // Don't render the navigator until we have data (#486, #4202, #5172).
  10976. if (!isNumber(min) || !isNumber(max)) {
  10977. // However, if navigator was already rendered, we may need to resize
  10978. // it. For example hidden series, but visible navigator (#6022).
  10979. if (rendered) {
  10980. pxMin = 0;
  10981. pxMax = pick(xAxis.width, scrollbarXAxis.width);
  10982. }
  10983. else {
  10984. return;
  10985. }
  10986. }
  10987. navigator.left = pick(xAxis.left,
  10988. // in case of scrollbar only, without navigator
  10989. chart.plotLeft + scrollbarHeight +
  10990. (inverted ? chart.plotWidth : 0));
  10991. navigator.size = zoomedMax = navigatorSize = pick(xAxis.len, (inverted ? chart.plotHeight : chart.plotWidth) -
  10992. 2 * scrollbarHeight);
  10993. if (inverted) {
  10994. navigatorWidth = scrollbarHeight;
  10995. }
  10996. else {
  10997. navigatorWidth = navigatorSize + 2 * scrollbarHeight;
  10998. }
  10999. // Get the pixel position of the handles
  11000. pxMin = pick(pxMin, xAxis.toPixels(min, true));
  11001. pxMax = pick(pxMax, xAxis.toPixels(max, true));
  11002. // Verify (#1851, #2238)
  11003. if (!isNumber(pxMin) || Math.abs(pxMin) === Infinity) {
  11004. pxMin = 0;
  11005. pxMax = navigatorWidth;
  11006. }
  11007. // Are we below the minRange? (#2618, #6191)
  11008. newMin = xAxis.toValue(pxMin, true);
  11009. newMax = xAxis.toValue(pxMax, true);
  11010. currentRange = Math.abs(correctFloat(newMax - newMin));
  11011. if (currentRange < minRange) {
  11012. if (this.grabbedLeft) {
  11013. pxMin = xAxis.toPixels(newMax - minRange - pointRange, true);
  11014. }
  11015. else if (this.grabbedRight) {
  11016. pxMax = xAxis.toPixels(newMin + minRange + pointRange, true);
  11017. }
  11018. }
  11019. else if (defined(maxRange) &&
  11020. correctFloat(currentRange - pointRange) > maxRange) {
  11021. if (this.grabbedLeft) {
  11022. pxMin = xAxis.toPixels(newMax - maxRange - pointRange, true);
  11023. }
  11024. else if (this.grabbedRight) {
  11025. pxMax = xAxis.toPixels(newMin + maxRange + pointRange, true);
  11026. }
  11027. }
  11028. // Handles are allowed to cross, but never exceed the plot area
  11029. navigator.zoomedMax = clamp(Math.max(pxMin, pxMax), 0, zoomedMax);
  11030. navigator.zoomedMin = clamp(navigator.fixedWidth ?
  11031. navigator.zoomedMax - navigator.fixedWidth :
  11032. Math.min(pxMin, pxMax), 0, zoomedMax);
  11033. navigator.range = navigator.zoomedMax - navigator.zoomedMin;
  11034. zoomedMax = Math.round(navigator.zoomedMax);
  11035. zoomedMin = Math.round(navigator.zoomedMin);
  11036. if (navigatorEnabled) {
  11037. navigator.navigatorGroup.attr({
  11038. visibility: 'visible'
  11039. });
  11040. // Place elements
  11041. verb = rendered && !navigator.hasDragged ? 'animate' : 'attr';
  11042. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  11043. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  11044. if (navigator.navigatorOptions.handles.enabled) {
  11045. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  11046. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  11047. }
  11048. }
  11049. if (navigator.scrollbar) {
  11050. if (inverted) {
  11051. scrollbarTop = navigator.top - scrollbarHeight;
  11052. scrollbarLeft = navigator.left - scrollbarHeight +
  11053. (navigatorEnabled || !scrollbarXAxis.opposite ? 0 :
  11054. // Multiple axes has offsets:
  11055. (scrollbarXAxis.titleOffset || 0) +
  11056. // Self margin from the axis.title
  11057. scrollbarXAxis.axisTitleMargin);
  11058. scrollbarHeight = navigatorSize + 2 * scrollbarHeight;
  11059. }
  11060. else {
  11061. scrollbarTop = navigator.top + (navigatorEnabled ?
  11062. navigator.height :
  11063. -scrollbarHeight);
  11064. scrollbarLeft = navigator.left - scrollbarHeight;
  11065. }
  11066. // Reposition scrollbar
  11067. navigator.scrollbar.position(scrollbarLeft, scrollbarTop, navigatorWidth, scrollbarHeight);
  11068. // Keep scale 0-1
  11069. navigator.scrollbar.setRange(
  11070. // Use real value, not rounded because range can be very small
  11071. // (#1716)
  11072. navigator.zoomedMin / (navigatorSize || 1), navigator.zoomedMax / (navigatorSize || 1));
  11073. }
  11074. navigator.rendered = true;
  11075. };
  11076. /**
  11077. * Set up the mouse and touch events for the navigator
  11078. *
  11079. * @private
  11080. * @function Highcharts.Navigator#addMouseEvents
  11081. */
  11082. Navigator.prototype.addMouseEvents = function () {
  11083. var navigator = this,
  11084. chart = navigator.chart,
  11085. container = chart.container,
  11086. eventsToUnbind = [],
  11087. mouseMoveHandler,
  11088. mouseUpHandler;
  11089. /**
  11090. * Create mouse events' handlers.
  11091. * Make them as separate functions to enable wrapping them:
  11092. */
  11093. navigator.mouseMoveHandler = mouseMoveHandler = function (e) {
  11094. navigator.onMouseMove(e);
  11095. };
  11096. navigator.mouseUpHandler = mouseUpHandler = function (e) {
  11097. navigator.onMouseUp(e);
  11098. };
  11099. // Add shades and handles mousedown events
  11100. eventsToUnbind = navigator.getPartsEvents('mousedown');
  11101. // Add mouse move and mouseup events. These are bind to doc/container,
  11102. // because Navigator.grabbedSomething flags are stored in mousedown
  11103. // events
  11104. eventsToUnbind.push(addEvent(chart.renderTo, 'mousemove', mouseMoveHandler), addEvent(container.ownerDocument, 'mouseup', mouseUpHandler));
  11105. // Touch events
  11106. if (hasTouch) {
  11107. eventsToUnbind.push(addEvent(chart.renderTo, 'touchmove', mouseMoveHandler), addEvent(container.ownerDocument, 'touchend', mouseUpHandler));
  11108. eventsToUnbind.concat(navigator.getPartsEvents('touchstart'));
  11109. }
  11110. navigator.eventsToUnbind = eventsToUnbind;
  11111. // Data events
  11112. if (navigator.series && navigator.series[0]) {
  11113. eventsToUnbind.push(addEvent(navigator.series[0].xAxis, 'foundExtremes', function () {
  11114. chart.navigator.modifyNavigatorAxisExtremes();
  11115. }));
  11116. }
  11117. };
  11118. /**
  11119. * Generate events for handles and masks
  11120. *
  11121. * @private
  11122. * @function Highcharts.Navigator#getPartsEvents
  11123. *
  11124. * @param {string} eventName
  11125. * Event name handler, 'mousedown' or 'touchstart'
  11126. *
  11127. * @return {Array<Function>}
  11128. * An array of functions to remove navigator functions from the
  11129. * events again.
  11130. */
  11131. Navigator.prototype.getPartsEvents = function (eventName) {
  11132. var navigator = this,
  11133. events = [];
  11134. ['shades', 'handles'].forEach(function (name) {
  11135. navigator[name].forEach(function (navigatorItem, index) {
  11136. events.push(addEvent(navigatorItem.element, eventName, function (e) {
  11137. navigator[name + 'Mousedown'](e, index);
  11138. }));
  11139. });
  11140. });
  11141. return events;
  11142. };
  11143. /**
  11144. * Mousedown on a shaded mask, either:
  11145. *
  11146. * - will be stored for future drag&drop
  11147. *
  11148. * - will directly shift to a new range
  11149. *
  11150. * @private
  11151. * @function Highcharts.Navigator#shadesMousedown
  11152. *
  11153. * @param {Highcharts.PointerEventObject} e
  11154. * Mouse event
  11155. *
  11156. * @param {number} index
  11157. * Index of a mask in Navigator.shades array
  11158. */
  11159. Navigator.prototype.shadesMousedown = function (e, index) {
  11160. e = this.chart.pointer.normalize(e);
  11161. var navigator = this,
  11162. chart = navigator.chart,
  11163. xAxis = navigator.xAxis,
  11164. zoomedMin = navigator.zoomedMin,
  11165. navigatorPosition = navigator.left,
  11166. navigatorSize = navigator.size,
  11167. range = navigator.range,
  11168. chartX = e.chartX,
  11169. fixedMax,
  11170. fixedMin,
  11171. ext,
  11172. left;
  11173. // For inverted chart, swap some options:
  11174. if (chart.inverted) {
  11175. chartX = e.chartY;
  11176. navigatorPosition = navigator.top;
  11177. }
  11178. if (index === 1) {
  11179. // Store information for drag&drop
  11180. navigator.grabbedCenter = chartX;
  11181. navigator.fixedWidth = range;
  11182. navigator.dragOffset = chartX - zoomedMin;
  11183. }
  11184. else {
  11185. // Shift the range by clicking on shaded areas
  11186. left = chartX - navigatorPosition - range / 2;
  11187. if (index === 0) {
  11188. left = Math.max(0, left);
  11189. }
  11190. else if (index === 2 && left + range >= navigatorSize) {
  11191. left = navigatorSize - range;
  11192. if (navigator.reversedExtremes) {
  11193. // #7713
  11194. left -= range;
  11195. fixedMin = navigator.getUnionExtremes().dataMin;
  11196. }
  11197. else {
  11198. // #2293, #3543
  11199. fixedMax = navigator.getUnionExtremes().dataMax;
  11200. }
  11201. }
  11202. if (left !== zoomedMin) { // it has actually moved
  11203. navigator.fixedWidth = range; // #1370
  11204. ext = xAxis.navigatorAxis.toFixedRange(left, left + range, fixedMin, fixedMax);
  11205. if (defined(ext.min)) { // #7411
  11206. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true, null, // auto animation
  11207. { trigger: 'navigator' });
  11208. }
  11209. }
  11210. }
  11211. };
  11212. /**
  11213. * Mousedown on a handle mask.
  11214. * Will store necessary information for drag&drop.
  11215. *
  11216. * @private
  11217. * @function Highcharts.Navigator#handlesMousedown
  11218. * @param {Highcharts.PointerEventObject} e
  11219. * Mouse event
  11220. * @param {number} index
  11221. * Index of a handle in Navigator.handles array
  11222. * @return {void}
  11223. */
  11224. Navigator.prototype.handlesMousedown = function (e, index) {
  11225. e = this.chart.pointer.normalize(e);
  11226. var navigator = this,
  11227. chart = navigator.chart,
  11228. baseXAxis = chart.xAxis[0],
  11229. // For reversed axes, min and max are changed,
  11230. // so the other extreme should be stored
  11231. reverse = navigator.reversedExtremes;
  11232. if (index === 0) {
  11233. // Grab the left handle
  11234. navigator.grabbedLeft = true;
  11235. navigator.otherHandlePos = navigator.zoomedMax;
  11236. navigator.fixedExtreme = reverse ? baseXAxis.min : baseXAxis.max;
  11237. }
  11238. else {
  11239. // Grab the right handle
  11240. navigator.grabbedRight = true;
  11241. navigator.otherHandlePos = navigator.zoomedMin;
  11242. navigator.fixedExtreme = reverse ? baseXAxis.max : baseXAxis.min;
  11243. }
  11244. chart.fixedRange = null;
  11245. };
  11246. /**
  11247. * Mouse move event based on x/y mouse position.
  11248. *
  11249. * @private
  11250. * @function Highcharts.Navigator#onMouseMove
  11251. *
  11252. * @param {Highcharts.PointerEventObject} e
  11253. * Mouse event
  11254. */
  11255. Navigator.prototype.onMouseMove = function (e) {
  11256. var navigator = this,
  11257. chart = navigator.chart,
  11258. left = navigator.left,
  11259. navigatorSize = navigator.navigatorSize,
  11260. range = navigator.range,
  11261. dragOffset = navigator.dragOffset,
  11262. inverted = chart.inverted,
  11263. chartX;
  11264. // In iOS, a mousemove event with e.pageX === 0 is fired when holding
  11265. // the finger down in the center of the scrollbar. This should be
  11266. // ignored.
  11267. if (!e.touches || e.touches[0].pageX !== 0) { // #4696
  11268. e = chart.pointer.normalize(e);
  11269. chartX = e.chartX;
  11270. // Swap some options for inverted chart
  11271. if (inverted) {
  11272. left = navigator.top;
  11273. chartX = e.chartY;
  11274. }
  11275. // Drag left handle or top handle
  11276. if (navigator.grabbedLeft) {
  11277. navigator.hasDragged = true;
  11278. navigator.render(0, 0, chartX - left, navigator.otherHandlePos);
  11279. // Drag right handle or bottom handle
  11280. }
  11281. else if (navigator.grabbedRight) {
  11282. navigator.hasDragged = true;
  11283. navigator.render(0, 0, navigator.otherHandlePos, chartX - left);
  11284. // Drag scrollbar or open area in navigator
  11285. }
  11286. else if (navigator.grabbedCenter) {
  11287. navigator.hasDragged = true;
  11288. if (chartX < dragOffset) { // outside left
  11289. chartX = dragOffset;
  11290. // outside right
  11291. }
  11292. else if (chartX >
  11293. navigatorSize + dragOffset - range) {
  11294. chartX = navigatorSize + dragOffset - range;
  11295. }
  11296. navigator.render(0, 0, chartX - dragOffset, chartX - dragOffset + range);
  11297. }
  11298. if (navigator.hasDragged &&
  11299. navigator.scrollbar &&
  11300. pick(navigator.scrollbar.options.liveRedraw,
  11301. // By default, don't run live redraw on VML, on touch
  11302. // devices or if the chart is in boost.
  11303. H.svg && !isTouchDevice && !this.chart.isBoosting)) {
  11304. e.DOMType = e.type; // DOMType is for IE8
  11305. setTimeout(function () {
  11306. navigator.onMouseUp(e);
  11307. }, 0);
  11308. }
  11309. }
  11310. };
  11311. /**
  11312. * Mouse up event based on x/y mouse position.
  11313. *
  11314. * @private
  11315. * @function Highcharts.Navigator#onMouseUp
  11316. * @param {Highcharts.PointerEventObject} e
  11317. * Mouse event
  11318. * @return {void}
  11319. */
  11320. Navigator.prototype.onMouseUp = function (e) {
  11321. var navigator = this,
  11322. chart = navigator.chart,
  11323. xAxis = navigator.xAxis,
  11324. scrollbar = navigator.scrollbar,
  11325. DOMEvent = e.DOMEvent || e,
  11326. inverted = chart.inverted,
  11327. verb = navigator.rendered && !navigator.hasDragged ?
  11328. 'animate' : 'attr',
  11329. zoomedMax,
  11330. zoomedMin,
  11331. unionExtremes,
  11332. fixedMin,
  11333. fixedMax,
  11334. ext;
  11335. if (
  11336. // MouseUp is called for both, navigator and scrollbar (that order),
  11337. // which causes calling afterSetExtremes twice. Prevent first call
  11338. // by checking if scrollbar is going to set new extremes (#6334)
  11339. (navigator.hasDragged && (!scrollbar || !scrollbar.hasDragged)) ||
  11340. e.trigger === 'scrollbar') {
  11341. unionExtremes = navigator.getUnionExtremes();
  11342. // When dragging one handle, make sure the other one doesn't change
  11343. if (navigator.zoomedMin === navigator.otherHandlePos) {
  11344. fixedMin = navigator.fixedExtreme;
  11345. }
  11346. else if (navigator.zoomedMax === navigator.otherHandlePos) {
  11347. fixedMax = navigator.fixedExtreme;
  11348. }
  11349. // Snap to right edge (#4076)
  11350. if (navigator.zoomedMax === navigator.size) {
  11351. fixedMax = navigator.reversedExtremes ?
  11352. unionExtremes.dataMin :
  11353. unionExtremes.dataMax;
  11354. }
  11355. // Snap to left edge (#7576)
  11356. if (navigator.zoomedMin === 0) {
  11357. fixedMin = navigator.reversedExtremes ?
  11358. unionExtremes.dataMax :
  11359. unionExtremes.dataMin;
  11360. }
  11361. ext = xAxis.navigatorAxis.toFixedRange(navigator.zoomedMin, navigator.zoomedMax, fixedMin, fixedMax);
  11362. if (defined(ext.min)) {
  11363. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true,
  11364. // Run animation when clicking buttons, scrollbar track etc,
  11365. // but not when dragging handles or scrollbar
  11366. navigator.hasDragged ? false : null, {
  11367. trigger: 'navigator',
  11368. triggerOp: 'navigator-drag',
  11369. DOMEvent: DOMEvent // #1838
  11370. });
  11371. }
  11372. }
  11373. if (e.DOMType !== 'mousemove' &&
  11374. e.DOMType !== 'touchmove') {
  11375. navigator.grabbedLeft = navigator.grabbedRight =
  11376. navigator.grabbedCenter = navigator.fixedWidth =
  11377. navigator.fixedExtreme = navigator.otherHandlePos =
  11378. navigator.hasDragged = navigator.dragOffset = null;
  11379. }
  11380. // Update position of navigator shades, outline and handles (#12573)
  11381. if (navigator.navigatorEnabled &&
  11382. isNumber(navigator.zoomedMin) &&
  11383. isNumber(navigator.zoomedMax)) {
  11384. zoomedMin = Math.round(navigator.zoomedMin);
  11385. zoomedMax = Math.round(navigator.zoomedMax);
  11386. if (navigator.shades) {
  11387. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  11388. }
  11389. if (navigator.outline) {
  11390. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  11391. }
  11392. if (navigator.navigatorOptions.handles.enabled &&
  11393. Object.keys(navigator.handles).length ===
  11394. navigator.handles.length) {
  11395. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  11396. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  11397. }
  11398. }
  11399. };
  11400. /**
  11401. * Removes the event handlers attached previously with addEvents.
  11402. *
  11403. * @private
  11404. * @function Highcharts.Navigator#removeEvents
  11405. * @return {void}
  11406. */
  11407. Navigator.prototype.removeEvents = function () {
  11408. if (this.eventsToUnbind) {
  11409. this.eventsToUnbind.forEach(function (unbind) {
  11410. unbind();
  11411. });
  11412. this.eventsToUnbind = void 0;
  11413. }
  11414. this.removeBaseSeriesEvents();
  11415. };
  11416. /**
  11417. * Remove data events.
  11418. *
  11419. * @private
  11420. * @function Highcharts.Navigator#removeBaseSeriesEvents
  11421. * @return {void}
  11422. */
  11423. Navigator.prototype.removeBaseSeriesEvents = function () {
  11424. var baseSeries = this.baseSeries || [];
  11425. if (this.navigatorEnabled && baseSeries[0]) {
  11426. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  11427. baseSeries.forEach(function (series) {
  11428. removeEvent(series, 'updatedData', this.updatedDataHandler);
  11429. }, this);
  11430. }
  11431. // We only listen for extremes-events on the first baseSeries
  11432. if (baseSeries[0].xAxis) {
  11433. removeEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  11434. }
  11435. }
  11436. };
  11437. /**
  11438. * Initialize the Navigator object
  11439. *
  11440. * @private
  11441. * @function Highcharts.Navigator#init
  11442. *
  11443. * @param {Highcharts.Chart} chart
  11444. */
  11445. Navigator.prototype.init = function (chart) {
  11446. var chartOptions = chart.options,
  11447. navigatorOptions = chartOptions.navigator,
  11448. navigatorEnabled = navigatorOptions.enabled,
  11449. scrollbarOptions = chartOptions.scrollbar,
  11450. scrollbarEnabled = scrollbarOptions.enabled,
  11451. height = navigatorEnabled ? navigatorOptions.height : 0,
  11452. scrollbarHeight = scrollbarEnabled ?
  11453. scrollbarOptions.height :
  11454. 0;
  11455. this.handles = [];
  11456. this.shades = [];
  11457. this.chart = chart;
  11458. this.setBaseSeries();
  11459. this.height = height;
  11460. this.scrollbarHeight = scrollbarHeight;
  11461. this.scrollbarEnabled = scrollbarEnabled;
  11462. this.navigatorEnabled = navigatorEnabled;
  11463. this.navigatorOptions = navigatorOptions;
  11464. this.scrollbarOptions = scrollbarOptions;
  11465. this.outlineHeight = height + scrollbarHeight;
  11466. this.opposite = pick(navigatorOptions.opposite, Boolean(!navigatorEnabled && chart.inverted)); // #6262
  11467. var navigator = this,
  11468. baseSeries = navigator.baseSeries,
  11469. xAxisIndex = chart.xAxis.length,
  11470. yAxisIndex = chart.yAxis.length,
  11471. baseXaxis = baseSeries && baseSeries[0] && baseSeries[0].xAxis ||
  11472. chart.xAxis[0] || { options: {} };
  11473. chart.isDirtyBox = true;
  11474. if (navigator.navigatorEnabled) {
  11475. // an x axis is required for scrollbar also
  11476. navigator.xAxis = new Axis(chart, merge({
  11477. // inherit base xAxis' break and ordinal options
  11478. breaks: baseXaxis.options.breaks,
  11479. ordinal: baseXaxis.options.ordinal
  11480. }, navigatorOptions.xAxis, {
  11481. id: 'navigator-x-axis',
  11482. yAxis: 'navigator-y-axis',
  11483. isX: true,
  11484. type: 'datetime',
  11485. index: xAxisIndex,
  11486. isInternal: true,
  11487. offset: 0,
  11488. keepOrdinalPadding: true,
  11489. startOnTick: false,
  11490. endOnTick: false,
  11491. minPadding: 0,
  11492. maxPadding: 0,
  11493. zoomEnabled: false
  11494. }, chart.inverted ? {
  11495. offsets: [scrollbarHeight, 0, -scrollbarHeight, 0],
  11496. width: height
  11497. } : {
  11498. offsets: [0, -scrollbarHeight, 0, scrollbarHeight],
  11499. height: height
  11500. }));
  11501. navigator.yAxis = new Axis(chart, merge(navigatorOptions.yAxis, {
  11502. id: 'navigator-y-axis',
  11503. alignTicks: false,
  11504. offset: 0,
  11505. index: yAxisIndex,
  11506. isInternal: true,
  11507. zoomEnabled: false
  11508. }, chart.inverted ? {
  11509. width: height
  11510. } : {
  11511. height: height
  11512. }));
  11513. // If we have a base series, initialize the navigator series
  11514. if (baseSeries || navigatorOptions.series.data) {
  11515. navigator.updateNavigatorSeries(false);
  11516. // If not, set up an event to listen for added series
  11517. }
  11518. else if (chart.series.length === 0) {
  11519. navigator.unbindRedraw = addEvent(chart, 'beforeRedraw', function () {
  11520. // We've got one, now add it as base
  11521. if (chart.series.length > 0 && !navigator.series) {
  11522. navigator.setBaseSeries();
  11523. navigator.unbindRedraw(); // reset
  11524. }
  11525. });
  11526. }
  11527. navigator.reversedExtremes = (chart.inverted && !navigator.xAxis.reversed) || (!chart.inverted && navigator.xAxis.reversed);
  11528. // Render items, so we can bind events to them:
  11529. navigator.renderElements();
  11530. // Add mouse events
  11531. navigator.addMouseEvents();
  11532. // in case of scrollbar only, fake an x axis to get translation
  11533. }
  11534. else {
  11535. navigator.xAxis = {
  11536. chart: chart,
  11537. navigatorAxis: {
  11538. fake: true
  11539. },
  11540. translate: function (value, reverse) {
  11541. 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;
  11542. return reverse ?
  11543. // from pixel to value
  11544. (value * valueRange / scrollTrackWidth) + min :
  11545. // from value to pixel
  11546. scrollTrackWidth * (value - min) / valueRange;
  11547. },
  11548. toPixels: function (value) {
  11549. return this.translate(value);
  11550. },
  11551. toValue: function (value) {
  11552. return this.translate(value, true);
  11553. }
  11554. };
  11555. navigator.xAxis.navigatorAxis.axis = navigator.xAxis;
  11556. navigator.xAxis.navigatorAxis.toFixedRange = (NavigatorAxis.AdditionsClass.prototype.toFixedRange.bind(navigator.xAxis.navigatorAxis));
  11557. }
  11558. // Initialize the scrollbar
  11559. if (chart.options.scrollbar.enabled) {
  11560. chart.scrollbar = navigator.scrollbar = new Scrollbar(chart.renderer, merge(chart.options.scrollbar, {
  11561. margin: navigator.navigatorEnabled ? 0 : 10,
  11562. vertical: chart.inverted
  11563. }), chart);
  11564. addEvent(navigator.scrollbar, 'changed', function (e) {
  11565. var range = navigator.size,
  11566. to = range * this.to,
  11567. from = range * this.from;
  11568. navigator.hasDragged = navigator.scrollbar.hasDragged;
  11569. navigator.render(0, 0, from, to);
  11570. if (chart.options.scrollbar.liveRedraw ||
  11571. (e.DOMType !== 'mousemove' &&
  11572. e.DOMType !== 'touchmove')) {
  11573. setTimeout(function () {
  11574. navigator.onMouseUp(e);
  11575. });
  11576. }
  11577. });
  11578. }
  11579. // Add data events
  11580. navigator.addBaseSeriesEvents();
  11581. // Add redraw events
  11582. navigator.addChartEvents();
  11583. };
  11584. /**
  11585. * Get the union data extremes of the chart - the outer data extremes of the
  11586. * base X axis and the navigator axis.
  11587. *
  11588. * @private
  11589. * @function Highcharts.Navigator#getUnionExtremes
  11590. * @param {boolean} [returnFalseOnNoBaseSeries]
  11591. * as the param says.
  11592. * @return {Highcharts.Dictionary<(number|undefined)>|undefined}
  11593. */
  11594. Navigator.prototype.getUnionExtremes = function (returnFalseOnNoBaseSeries) {
  11595. var baseAxis = this.chart.xAxis[0],
  11596. navAxis = this.xAxis,
  11597. navAxisOptions = navAxis.options,
  11598. baseAxisOptions = baseAxis.options,
  11599. ret;
  11600. if (!returnFalseOnNoBaseSeries || baseAxis.dataMin !== null) {
  11601. ret = {
  11602. dataMin: pick(// #4053
  11603. navAxisOptions && navAxisOptions.min, numExt('min', baseAxisOptions.min, baseAxis.dataMin, navAxis.dataMin, navAxis.min)),
  11604. dataMax: pick(navAxisOptions && navAxisOptions.max, numExt('max', baseAxisOptions.max, baseAxis.dataMax, navAxis.dataMax, navAxis.max))
  11605. };
  11606. }
  11607. return ret;
  11608. };
  11609. /**
  11610. * Set the base series and update the navigator series from this. With a bit
  11611. * of modification we should be able to make this an API method to be called
  11612. * from the outside
  11613. *
  11614. * @private
  11615. * @function Highcharts.Navigator#setBaseSeries
  11616. * @param {Highcharts.SeriesOptionsType} [baseSeriesOptions]
  11617. * Additional series options for a navigator
  11618. * @param {boolean} [redraw]
  11619. * Whether to redraw after update.
  11620. * @return {void}
  11621. */
  11622. Navigator.prototype.setBaseSeries = function (baseSeriesOptions, redraw) {
  11623. var chart = this.chart,
  11624. baseSeries = this.baseSeries = [];
  11625. baseSeriesOptions = (baseSeriesOptions ||
  11626. chart.options && chart.options.navigator.baseSeries ||
  11627. (chart.series.length ?
  11628. // Find the first non-navigator series (#8430)
  11629. find(chart.series, function (s) {
  11630. return !s.options.isInternal;
  11631. }).index :
  11632. 0));
  11633. // Iterate through series and add the ones that should be shown in
  11634. // navigator.
  11635. (chart.series || []).forEach(function (series, i) {
  11636. if (
  11637. // Don't include existing nav series
  11638. !series.options.isInternal &&
  11639. (series.options.showInNavigator ||
  11640. (i === baseSeriesOptions ||
  11641. series.options.id === baseSeriesOptions) &&
  11642. series.options.showInNavigator !== false)) {
  11643. baseSeries.push(series);
  11644. }
  11645. });
  11646. // When run after render, this.xAxis already exists
  11647. if (this.xAxis && !this.xAxis.navigatorAxis.fake) {
  11648. this.updateNavigatorSeries(true, redraw);
  11649. }
  11650. };
  11651. /**
  11652. * Update series in the navigator from baseSeries, adding new if does not
  11653. * exist.
  11654. *
  11655. * @private
  11656. * @function Highcharts.Navigator.updateNavigatorSeries
  11657. * @param {boolean} addEvents
  11658. * @param {boolean} [redraw]
  11659. * @return {void}
  11660. */
  11661. Navigator.prototype.updateNavigatorSeries = function (addEvents, redraw) {
  11662. var navigator = this,
  11663. chart = navigator.chart,
  11664. baseSeries = navigator.baseSeries,
  11665. baseOptions,
  11666. mergedNavSeriesOptions,
  11667. chartNavigatorSeriesOptions = navigator.navigatorOptions.series,
  11668. baseNavigatorOptions,
  11669. navSeriesMixin = {
  11670. enableMouseTracking: false,
  11671. index: null,
  11672. linkedTo: null,
  11673. group: 'nav',
  11674. padXAxis: false,
  11675. xAxis: 'navigator-x-axis',
  11676. yAxis: 'navigator-y-axis',
  11677. showInLegend: false,
  11678. stacking: void 0,
  11679. isInternal: true,
  11680. states: {
  11681. inactive: {
  11682. opacity: 1
  11683. }
  11684. }
  11685. },
  11686. // Remove navigator series that are no longer in the baseSeries
  11687. navigatorSeries = navigator.series =
  11688. (navigator.series || []).filter(function (navSeries) {
  11689. var base = navSeries.baseSeries;
  11690. if (baseSeries.indexOf(base) < 0) { // Not in array
  11691. // If there is still a base series connected to this
  11692. // series, remove event handler and reference.
  11693. if (base) {
  11694. removeEvent(base, 'updatedData', navigator.updatedDataHandler);
  11695. delete base.navigatorSeries;
  11696. }
  11697. // Kill the nav series. It may already have been
  11698. // destroyed (#8715).
  11699. if (navSeries.chart) {
  11700. navSeries.destroy();
  11701. }
  11702. return false;
  11703. }
  11704. return true;
  11705. });
  11706. // Go through each base series and merge the options to create new
  11707. // series
  11708. if (baseSeries && baseSeries.length) {
  11709. baseSeries.forEach(function eachBaseSeries(base) {
  11710. var linkedNavSeries = base.navigatorSeries,
  11711. userNavOptions = extend(
  11712. // Grab color and visibility from base as default
  11713. {
  11714. color: base.color,
  11715. visible: base.visible
  11716. }, !isArray(chartNavigatorSeriesOptions) ?
  11717. chartNavigatorSeriesOptions :
  11718. defaultOptions.navigator.series);
  11719. // Don't update if the series exists in nav and we have disabled
  11720. // adaptToUpdatedData.
  11721. if (linkedNavSeries &&
  11722. navigator.navigatorOptions.adaptToUpdatedData === false) {
  11723. return;
  11724. }
  11725. navSeriesMixin.name = 'Navigator ' + baseSeries.length;
  11726. baseOptions = base.options || {};
  11727. baseNavigatorOptions = baseOptions.navigatorOptions || {};
  11728. mergedNavSeriesOptions = merge(baseOptions, navSeriesMixin, userNavOptions, baseNavigatorOptions);
  11729. // Once nav series type is resolved, pick correct pointRange
  11730. mergedNavSeriesOptions.pointRange = pick(
  11731. // Stricte set pointRange in options
  11732. userNavOptions.pointRange, baseNavigatorOptions.pointRange,
  11733. // Fallback to default values, e.g. `null` for column
  11734. defaultOptions.plotOptions[mergedNavSeriesOptions.type || 'line'].pointRange);
  11735. // Merge data separately. Do a slice to avoid mutating the
  11736. // navigator options from base series (#4923).
  11737. var navigatorSeriesData = baseNavigatorOptions.data || userNavOptions.data;
  11738. navigator.hasNavigatorData =
  11739. navigator.hasNavigatorData || !!navigatorSeriesData;
  11740. mergedNavSeriesOptions.data =
  11741. navigatorSeriesData ||
  11742. baseOptions.data && baseOptions.data.slice(0);
  11743. // Update or add the series
  11744. if (linkedNavSeries && linkedNavSeries.options) {
  11745. linkedNavSeries.update(mergedNavSeriesOptions, redraw);
  11746. }
  11747. else {
  11748. base.navigatorSeries = chart.initSeries(mergedNavSeriesOptions);
  11749. base.navigatorSeries.baseSeries = base; // Store ref
  11750. navigatorSeries.push(base.navigatorSeries);
  11751. }
  11752. });
  11753. }
  11754. // If user has defined data (and no base series) or explicitly defined
  11755. // navigator.series as an array, we create these series on top of any
  11756. // base series.
  11757. if (chartNavigatorSeriesOptions.data &&
  11758. !(baseSeries && baseSeries.length) ||
  11759. isArray(chartNavigatorSeriesOptions)) {
  11760. navigator.hasNavigatorData = false;
  11761. // Allow navigator.series to be an array
  11762. chartNavigatorSeriesOptions =
  11763. splat(chartNavigatorSeriesOptions);
  11764. chartNavigatorSeriesOptions.forEach(function (userSeriesOptions, i) {
  11765. navSeriesMixin.name =
  11766. 'Navigator ' + (navigatorSeries.length + 1);
  11767. mergedNavSeriesOptions = merge(defaultOptions.navigator.series, {
  11768. // Since we don't have a base series to pull color from,
  11769. // try to fake it by using color from series with same
  11770. // index. Otherwise pull from the colors array. We need
  11771. // an explicit color as otherwise updates will increment
  11772. // color counter and we'll get a new color for each
  11773. // update of the nav series.
  11774. color: chart.series[i] &&
  11775. !chart.series[i].options.isInternal &&
  11776. chart.series[i].color ||
  11777. chart.options.colors[i] ||
  11778. chart.options.colors[0]
  11779. }, navSeriesMixin, userSeriesOptions);
  11780. mergedNavSeriesOptions.data = userSeriesOptions.data;
  11781. if (mergedNavSeriesOptions.data) {
  11782. navigator.hasNavigatorData = true;
  11783. navigatorSeries.push(chart.initSeries(mergedNavSeriesOptions));
  11784. }
  11785. });
  11786. }
  11787. if (addEvents) {
  11788. this.addBaseSeriesEvents();
  11789. }
  11790. };
  11791. /**
  11792. * Add data events.
  11793. * For example when main series is updated we need to recalculate extremes
  11794. *
  11795. * @private
  11796. * @function Highcharts.Navigator#addBaseSeriesEvent
  11797. * @return {void}
  11798. */
  11799. Navigator.prototype.addBaseSeriesEvents = function () {
  11800. var navigator = this,
  11801. baseSeries = navigator.baseSeries || [];
  11802. // Bind modified extremes event to first base's xAxis only.
  11803. // In event of > 1 base-xAxes, the navigator will ignore those.
  11804. // Adding this multiple times to the same axis is no problem, as
  11805. // duplicates should be discarded by the browser.
  11806. if (baseSeries[0] && baseSeries[0].xAxis) {
  11807. addEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  11808. }
  11809. baseSeries.forEach(function (base) {
  11810. // Link base series show/hide to navigator series visibility
  11811. addEvent(base, 'show', function () {
  11812. if (this.navigatorSeries) {
  11813. this.navigatorSeries.setVisible(true, false);
  11814. }
  11815. });
  11816. addEvent(base, 'hide', function () {
  11817. if (this.navigatorSeries) {
  11818. this.navigatorSeries.setVisible(false, false);
  11819. }
  11820. });
  11821. // Respond to updated data in the base series, unless explicitily
  11822. // not adapting to data changes.
  11823. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  11824. if (base.xAxis) {
  11825. addEvent(base, 'updatedData', this.updatedDataHandler);
  11826. }
  11827. }
  11828. // Handle series removal
  11829. addEvent(base, 'remove', function () {
  11830. if (this.navigatorSeries) {
  11831. erase(navigator.series, this.navigatorSeries);
  11832. if (defined(this.navigatorSeries.options)) {
  11833. this.navigatorSeries.remove(false);
  11834. }
  11835. delete this.navigatorSeries;
  11836. }
  11837. });
  11838. }, this);
  11839. };
  11840. /**
  11841. * Get minimum from all base series connected to the navigator
  11842. * @private
  11843. * @param {number} currentSeriesMin
  11844. * Minium from the current series
  11845. * @return {number} Minimum from all series
  11846. */
  11847. Navigator.prototype.getBaseSeriesMin = function (currentSeriesMin) {
  11848. return this.baseSeries.reduce(function (min, series) {
  11849. // (#10193)
  11850. return Math.min(min, series.xData ? series.xData[0] : min);
  11851. }, currentSeriesMin);
  11852. };
  11853. /**
  11854. * Set the navigator x axis extremes to reflect the total. The navigator
  11855. * extremes should always be the extremes of the union of all series in the
  11856. * chart as well as the navigator series.
  11857. *
  11858. * @private
  11859. * @function Highcharts.Navigator#modifyNavigatorAxisExtremes
  11860. */
  11861. Navigator.prototype.modifyNavigatorAxisExtremes = function () {
  11862. var xAxis = this.xAxis,
  11863. unionExtremes;
  11864. if (typeof xAxis.getExtremes !== 'undefined') {
  11865. unionExtremes = this.getUnionExtremes(true);
  11866. if (unionExtremes &&
  11867. (unionExtremes.dataMin !== xAxis.min ||
  11868. unionExtremes.dataMax !== xAxis.max)) {
  11869. xAxis.min = unionExtremes.dataMin;
  11870. xAxis.max = unionExtremes.dataMax;
  11871. }
  11872. }
  11873. };
  11874. /**
  11875. * Hook to modify the base axis extremes with information from the Navigator
  11876. *
  11877. * @private
  11878. * @function Highcharts.Navigator#modifyBaseAxisExtremes
  11879. */
  11880. Navigator.prototype.modifyBaseAxisExtremes = function () {
  11881. var baseXAxis = this,
  11882. navigator = baseXAxis.chart.navigator,
  11883. baseExtremes = baseXAxis.getExtremes(),
  11884. baseMin = baseExtremes.min,
  11885. baseMax = baseExtremes.max,
  11886. baseDataMin = baseExtremes.dataMin,
  11887. baseDataMax = baseExtremes.dataMax,
  11888. range = baseMax - baseMin,
  11889. stickToMin = navigator.stickToMin,
  11890. stickToMax = navigator.stickToMax,
  11891. overscroll = pick(baseXAxis.options.overscroll, 0),
  11892. newMax,
  11893. newMin,
  11894. navigatorSeries = navigator.series && navigator.series[0],
  11895. hasSetExtremes = !!baseXAxis.setExtremes,
  11896. // When the extremes have been set by range selector button, don't
  11897. // stick to min or max. The range selector buttons will handle the
  11898. // extremes. (#5489)
  11899. unmutable = baseXAxis.eventArgs &&
  11900. baseXAxis.eventArgs.trigger === 'rangeSelectorButton';
  11901. if (!unmutable) {
  11902. // If the zoomed range is already at the min, move it to the right
  11903. // as new data comes in
  11904. if (stickToMin) {
  11905. newMin = baseDataMin;
  11906. newMax = newMin + range;
  11907. }
  11908. // If the zoomed range is already at the max, move it to the right
  11909. // as new data comes in
  11910. if (stickToMax) {
  11911. newMax = baseDataMax + overscroll;
  11912. // If stickToMin is true, the new min value is set above
  11913. if (!stickToMin) {
  11914. newMin = Math.max(baseDataMin, // don't go below data extremes (#13184)
  11915. newMax - range, navigator.getBaseSeriesMin(navigatorSeries && navigatorSeries.xData ?
  11916. navigatorSeries.xData[0] :
  11917. -Number.MAX_VALUE));
  11918. }
  11919. }
  11920. // Update the extremes
  11921. if (hasSetExtremes && (stickToMin || stickToMax)) {
  11922. if (isNumber(newMin)) {
  11923. baseXAxis.min = baseXAxis.userMin = newMin;
  11924. baseXAxis.max = baseXAxis.userMax = newMax;
  11925. }
  11926. }
  11927. }
  11928. // Reset
  11929. navigator.stickToMin =
  11930. navigator.stickToMax = null;
  11931. };
  11932. /**
  11933. * Handler for updated data on the base series. When data is modified, the
  11934. * navigator series must reflect it. This is called from the Chart.redraw
  11935. * function before axis and series extremes are computed.
  11936. *
  11937. * @private
  11938. * @function Highcharts.Navigator#updateDataHandler
  11939. */
  11940. Navigator.prototype.updatedDataHandler = function () {
  11941. var navigator = this.chart.navigator,
  11942. baseSeries = this,
  11943. navigatorSeries = this.navigatorSeries,
  11944. xDataMin = navigator.getBaseSeriesMin(baseSeries.xData[0]);
  11945. // If the scrollbar is scrolled all the way to the right, keep right as
  11946. // new data comes in.
  11947. navigator.stickToMax = navigator.reversedExtremes ?
  11948. Math.round(navigator.zoomedMin) === 0 :
  11949. Math.round(navigator.zoomedMax) >= Math.round(navigator.size);
  11950. // Detect whether the zoomed area should stick to the minimum or
  11951. // maximum. If the current axis minimum falls outside the new updated
  11952. // dataset, we must adjust.
  11953. navigator.stickToMin = isNumber(baseSeries.xAxis.min) &&
  11954. (baseSeries.xAxis.min <= xDataMin) &&
  11955. (!this.chart.fixedRange || !navigator.stickToMax);
  11956. // Set the navigator series data to the new data of the base series
  11957. if (navigatorSeries && !navigator.hasNavigatorData) {
  11958. navigatorSeries.options.pointStart = baseSeries.xData[0];
  11959. navigatorSeries.setData(baseSeries.options.data, false, null, false); // #5414
  11960. }
  11961. };
  11962. /**
  11963. * Add chart events, like redrawing navigator, when chart requires that.
  11964. *
  11965. * @private
  11966. * @function Highcharts.Navigator#addChartEvents
  11967. * @return {void}
  11968. */
  11969. Navigator.prototype.addChartEvents = function () {
  11970. if (!this.eventsToUnbind) {
  11971. this.eventsToUnbind = [];
  11972. }
  11973. this.eventsToUnbind.push(
  11974. // Move the scrollbar after redraw, like after data updata even if
  11975. // axes don't redraw
  11976. addEvent(this.chart, 'redraw', function () {
  11977. var navigator = this.navigator,
  11978. xAxis = navigator && (navigator.baseSeries &&
  11979. navigator.baseSeries[0] &&
  11980. navigator.baseSeries[0].xAxis ||
  11981. this.xAxis[0]); // #5709, #13114
  11982. if (xAxis) {
  11983. navigator.render(xAxis.min,
  11984. xAxis.max);
  11985. }
  11986. }),
  11987. // Make room for the navigator, can be placed around the chart:
  11988. addEvent(this.chart, 'getMargins', function () {
  11989. var chart = this,
  11990. navigator = chart.navigator,
  11991. marginName = navigator.opposite ?
  11992. 'plotTop' : 'marginBottom';
  11993. if (chart.inverted) {
  11994. marginName = navigator.opposite ?
  11995. 'marginRight' : 'plotLeft';
  11996. }
  11997. chart[marginName] =
  11998. (chart[marginName] || 0) + (navigator.navigatorEnabled || !chart.inverted ?
  11999. navigator.outlineHeight :
  12000. 0) + navigator.navigatorOptions.margin;
  12001. }));
  12002. };
  12003. /**
  12004. * Destroys allocated elements.
  12005. *
  12006. * @private
  12007. * @function Highcharts.Navigator#destroy
  12008. */
  12009. Navigator.prototype.destroy = function () {
  12010. // Disconnect events added in addEvents
  12011. this.removeEvents();
  12012. if (this.xAxis) {
  12013. erase(this.chart.xAxis, this.xAxis);
  12014. erase(this.chart.axes, this.xAxis);
  12015. }
  12016. if (this.yAxis) {
  12017. erase(this.chart.yAxis, this.yAxis);
  12018. erase(this.chart.axes, this.yAxis);
  12019. }
  12020. // Destroy series
  12021. (this.series || []).forEach(function (s) {
  12022. if (s.destroy) {
  12023. s.destroy();
  12024. }
  12025. });
  12026. // Destroy properties
  12027. [
  12028. 'series', 'xAxis', 'yAxis', 'shades', 'outline', 'scrollbarTrack',
  12029. 'scrollbarRifles', 'scrollbarGroup', 'scrollbar', 'navigatorGroup',
  12030. 'rendered'
  12031. ].forEach(function (prop) {
  12032. if (this[prop] && this[prop].destroy) {
  12033. this[prop].destroy();
  12034. }
  12035. this[prop] = null;
  12036. }, this);
  12037. // Destroy elements in collection
  12038. [this.handles].forEach(function (coll) {
  12039. destroyObjectProperties(coll);
  12040. }, this);
  12041. };
  12042. return Navigator;
  12043. }());
  12044. // End of prototype
  12045. if (!H.Navigator) {
  12046. H.Navigator = Navigator;
  12047. NavigatorAxis.compose(Axis);
  12048. // For Stock charts. For x only zooming, do not to create the zoom button
  12049. // because X axis zooming is already allowed by the Navigator and Range
  12050. // selector. (#9285)
  12051. addEvent(Chart, 'beforeShowResetZoom', function () {
  12052. var chartOptions = this.options,
  12053. navigator = chartOptions.navigator,
  12054. rangeSelector = chartOptions.rangeSelector;
  12055. if (((navigator && navigator.enabled) ||
  12056. (rangeSelector && rangeSelector.enabled)) &&
  12057. ((!isTouchDevice && chartOptions.chart.zoomType === 'x') ||
  12058. (isTouchDevice && chartOptions.chart.pinchType === 'x'))) {
  12059. return false;
  12060. }
  12061. });
  12062. // Initialize navigator for stock charts
  12063. addEvent(Chart, 'beforeRender', function () {
  12064. var options = this.options;
  12065. if (options.navigator.enabled ||
  12066. options.scrollbar.enabled) {
  12067. this.scroller = this.navigator = new Navigator(this);
  12068. }
  12069. });
  12070. // For stock charts, extend the Chart.setChartSize method so that we can set
  12071. // the final top position of the navigator once the height of the chart,
  12072. // including the legend, is determined. #367. We can't use Chart.getMargins,
  12073. // because labels offsets are not calculated yet.
  12074. addEvent(Chart, 'afterSetChartSize', function () {
  12075. var legend = this.legend,
  12076. navigator = this.navigator,
  12077. scrollbarHeight,
  12078. legendOptions,
  12079. xAxis,
  12080. yAxis;
  12081. if (navigator) {
  12082. legendOptions = legend && legend.options;
  12083. xAxis = navigator.xAxis;
  12084. yAxis = navigator.yAxis;
  12085. scrollbarHeight = navigator.scrollbarHeight;
  12086. // Compute the top position
  12087. if (this.inverted) {
  12088. navigator.left = navigator.opposite ?
  12089. this.chartWidth - scrollbarHeight -
  12090. navigator.height :
  12091. this.spacing[3] + scrollbarHeight;
  12092. navigator.top = this.plotTop + scrollbarHeight;
  12093. }
  12094. else {
  12095. navigator.left = this.plotLeft + scrollbarHeight;
  12096. navigator.top = navigator.navigatorOptions.top ||
  12097. this.chartHeight -
  12098. navigator.height -
  12099. scrollbarHeight -
  12100. this.spacing[2] -
  12101. (this.rangeSelector && this.extraBottomMargin ?
  12102. this.rangeSelector.getHeight() :
  12103. 0) -
  12104. ((legendOptions &&
  12105. legendOptions.verticalAlign === 'bottom' &&
  12106. legendOptions.layout !== 'proximate' && // #13392
  12107. legendOptions.enabled &&
  12108. !legendOptions.floating) ?
  12109. legend.legendHeight +
  12110. pick(legendOptions.margin, 10) :
  12111. 0) -
  12112. (this.titleOffset ? this.titleOffset[2] : 0);
  12113. }
  12114. if (xAxis && yAxis) { // false if navigator is disabled (#904)
  12115. if (this.inverted) {
  12116. xAxis.options.left = yAxis.options.left = navigator.left;
  12117. }
  12118. else {
  12119. xAxis.options.top = yAxis.options.top = navigator.top;
  12120. }
  12121. xAxis.setAxisSize();
  12122. yAxis.setAxisSize();
  12123. }
  12124. }
  12125. });
  12126. // Merge options, if no scrolling exists yet
  12127. addEvent(Chart, 'update', function (e) {
  12128. var navigatorOptions = (e.options.navigator || {}),
  12129. scrollbarOptions = (e.options.scrollbar || {});
  12130. if (!this.navigator && !this.scroller &&
  12131. (navigatorOptions.enabled || scrollbarOptions.enabled)) {
  12132. merge(true, this.options.navigator, navigatorOptions);
  12133. merge(true, this.options.scrollbar, scrollbarOptions);
  12134. delete e.options.navigator;
  12135. delete e.options.scrollbar;
  12136. }
  12137. });
  12138. // Initialize navigator, if no scrolling exists yet
  12139. addEvent(Chart, 'afterUpdate', function (event) {
  12140. if (!this.navigator && !this.scroller &&
  12141. (this.options.navigator.enabled ||
  12142. this.options.scrollbar.enabled)) {
  12143. this.scroller = this.navigator = new Navigator(this);
  12144. if (pick(event.redraw, true)) {
  12145. this.redraw(event.animation); // #7067
  12146. }
  12147. }
  12148. });
  12149. // Handle adding new series
  12150. addEvent(Chart, 'afterAddSeries', function () {
  12151. if (this.navigator) {
  12152. // Recompute which series should be shown in navigator, and add them
  12153. this.navigator.setBaseSeries(null, false);
  12154. }
  12155. });
  12156. // Handle updating series
  12157. addEvent(Series, 'afterUpdate', function () {
  12158. if (this.chart.navigator && !this.options.isInternal) {
  12159. this.chart.navigator.setBaseSeries(null, false);
  12160. }
  12161. });
  12162. Chart.prototype.callbacks.push(function (chart) {
  12163. var extremes,
  12164. navigator = chart.navigator;
  12165. // Initialize the navigator
  12166. if (navigator && chart.xAxis[0]) {
  12167. extremes = chart.xAxis[0].getExtremes();
  12168. navigator.render(extremes.min, extremes.max);
  12169. }
  12170. });
  12171. }
  12172. H.Navigator = Navigator;
  12173. return H.Navigator;
  12174. });
  12175. _registerModule(_modules, 'masters/modules/gantt.src.js', [], function () {
  12176. });
  12177. }));