gantt.src.js 215 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707
  1. /**
  2. * @license Highcharts JS v7.0.2 (2019-01-17)
  3. * Gantt series
  4. *
  5. * (c) 2016-2019 Lars A. V. Cabrera
  6. *
  7. * License: www.highcharts.com/license
  8. */
  9. 'use strict';
  10. (function (factory) {
  11. if (typeof module === 'object' && module.exports) {
  12. factory['default'] = factory;
  13. module.exports = factory;
  14. } else if (typeof define === 'function' && define.amd) {
  15. define(function () {
  16. return factory;
  17. });
  18. } else {
  19. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  20. }
  21. }(function (Highcharts) {
  22. (function (H) {
  23. /* *
  24. *
  25. * (c) 2016-2019 Highsoft AS
  26. *
  27. * Author: Lars A. V. Cabrera
  28. *
  29. * License: www.highcharts.com/license
  30. *
  31. * */
  32. var addEvent = H.addEvent,
  33. Axis = H.Axis,
  34. PlotLineOrBand = H.PlotLineOrBand,
  35. merge = H.merge;
  36. var defaultConfig = {
  37. /**
  38. * Show an indicator on the axis for the current date and time. Can be a
  39. * boolean or a configuration object similar to
  40. * [xAxis.plotLines](#xAxis.plotLines).
  41. *
  42. * @sample gantt/current-date-indicator/demo
  43. * Current date indicator enabled
  44. * @sample gantt/current-date-indicator/object-config
  45. * Current date indicator with custom options
  46. *
  47. * @type {boolean|*}
  48. * @default true
  49. * @extends xAxis.plotLines
  50. * @excluding value
  51. * @product gantt
  52. * @apioption xAxis.currentDateIndicator
  53. */
  54. currentDateIndicator: true,
  55. color: '#ccd6eb',
  56. width: 2,
  57. label: {
  58. format: '%a, %b %d %Y, %H:%M',
  59. formatter: undefined,
  60. rotation: 0,
  61. style: {
  62. fontSize: '10px'
  63. }
  64. }
  65. };
  66. addEvent(Axis, 'afterSetOptions', function () {
  67. var options = this.options,
  68. cdiOptions = options.currentDateIndicator;
  69. if (cdiOptions) {
  70. if (typeof cdiOptions === 'object') {
  71. // Ignore formatter if custom format is defined
  72. if (cdiOptions.label && cdiOptions.label.format) {
  73. cdiOptions.label.formatter = undefined;
  74. }
  75. cdiOptions = merge(defaultConfig, cdiOptions);
  76. } else {
  77. cdiOptions = merge(defaultConfig);
  78. }
  79. cdiOptions.value = new Date();
  80. if (!options.plotLines) {
  81. options.plotLines = [];
  82. }
  83. options.plotLines.push(cdiOptions);
  84. }
  85. });
  86. addEvent(PlotLineOrBand, 'render', function () {
  87. var options = this.options,
  88. format,
  89. formatter;
  90. if (options.currentDateIndicator && options.label) {
  91. format = options.label.format;
  92. formatter = options.label.formatter;
  93. options.value = new Date();
  94. if (typeof formatter === 'function') {
  95. options.label.text = formatter(this);
  96. } else {
  97. options.label.text = H.dateFormat(format, new Date());
  98. }
  99. // If the label already exists, update its text
  100. if (this.label) {
  101. this.label.attr({
  102. text: options.label.text
  103. });
  104. }
  105. }
  106. });
  107. }(Highcharts));
  108. (function (H) {
  109. /* *
  110. * (c) 2016 Highsoft AS
  111. * Authors: Lars A. V. Cabrera
  112. *
  113. * License: www.highcharts.com/license
  114. */
  115. var addEvent = H.addEvent,
  116. argsToArray = function (args) {
  117. return Array.prototype.slice.call(args, 1);
  118. },
  119. dateFormat = H.dateFormat,
  120. defined = H.defined,
  121. isArray = H.isArray,
  122. isNumber = H.isNumber,
  123. isObject = function (x) {
  124. // Always use strict mode
  125. return H.isObject(x, true);
  126. },
  127. merge = H.merge,
  128. pick = H.pick,
  129. wrap = H.wrap,
  130. Axis = H.Axis,
  131. Tick = H.Tick;
  132. /**
  133. * Set grid options for the axis labels. Requires Highcharts Gantt.
  134. *
  135. * @since 6.2.0
  136. * @product gantt
  137. * @apioption xAxis.grid
  138. */
  139. /**
  140. * Enable grid on the axis labels. Defaults to true for Gantt charts.
  141. *
  142. * @type {boolean}
  143. * @default true
  144. * @since 6.2.0
  145. * @product gantt
  146. * @apioption xAxis.grid.enabled
  147. */
  148. /**
  149. * Set specific options for each column (or row for horizontal axes) in the
  150. * grid. Each extra column/row is its own axis, and the axis options can be set
  151. * here.
  152. *
  153. * @sample gantt/demo/left-axis-table
  154. * Left axis as a table
  155. *
  156. * @type {Array<Highcharts.XAxisOptions>}
  157. * @apioption xAxis.grid.columns
  158. */
  159. /**
  160. * Set border color for the label grid lines.
  161. *
  162. * @type {Highcharts.ColorString}
  163. * @apioption xAxis.grid.borderColor
  164. */
  165. /**
  166. * Set border width of the label grid lines.
  167. *
  168. * @type {number}
  169. * @default 1
  170. * @apioption xAxis.grid.borderWidth
  171. */
  172. /**
  173. * Set cell height for grid axis labels. By default this is calculated from font
  174. * size.
  175. *
  176. * @type {number}
  177. * @apioption xAxis.grid.cellHeight
  178. */
  179. // Enum for which side the axis is on.
  180. // Maps to axis.side
  181. var axisSide = {
  182. top: 0,
  183. right: 1,
  184. bottom: 2,
  185. left: 3,
  186. 0: 'top',
  187. 1: 'right',
  188. 2: 'bottom',
  189. 3: 'left'
  190. };
  191. /**
  192. * Checks if an axis is a navigator axis.
  193. *
  194. * @private
  195. * @function Highcharts.Axis#isNavigatorAxis
  196. *
  197. * @return {boolean}
  198. * true if axis is found in axis.chart.navigator
  199. */
  200. Axis.prototype.isNavigatorAxis = function () {
  201. return /highcharts-navigator-[xy]axis/.test(this.options.className);
  202. };
  203. /**
  204. * Checks if an axis is the outer axis in its dimension. Since
  205. * axes are placed outwards in order, the axis with the highest
  206. * index is the outermost axis.
  207. *
  208. * Example: If there are multiple x-axes at the top of the chart,
  209. * this function returns true if the axis supplied is the last
  210. * of the x-axes.
  211. *
  212. * @private
  213. * @function Highcharts.Axis#isOuterAxis
  214. *
  215. * @return {boolean}
  216. * true if the axis is the outermost axis in its dimension; false if not
  217. */
  218. Axis.prototype.isOuterAxis = function () {
  219. var axis = this,
  220. chart = axis.chart,
  221. thisIndex = -1,
  222. isOuter = true;
  223. chart.axes.forEach(function (otherAxis, index) {
  224. if (otherAxis.side === axis.side && !otherAxis.isNavigatorAxis()) {
  225. if (otherAxis === axis) {
  226. // Get the index of the axis in question
  227. thisIndex = index;
  228. // Check thisIndex >= 0 in case thisIndex has
  229. // not been found yet
  230. } else if (thisIndex >= 0 && index > thisIndex) {
  231. // There was an axis on the same side with a
  232. // higher index.
  233. isOuter = false;
  234. }
  235. }
  236. });
  237. // There were either no other axes on the same side,
  238. // or the other axes were not farther from the chart
  239. return isOuter;
  240. };
  241. /**
  242. * Get the largest label width and height.
  243. *
  244. * @private
  245. * @function Highcharts.Axis#getMaxLabelDimensions
  246. *
  247. * @param {Highcharts.Dictionary<Highcharts.Tick>} ticks
  248. * All the ticks on one axis.
  249. *
  250. * @param {Array<number|string>} tickPositions
  251. * All the tick positions on one axis.
  252. *
  253. * @return {object}
  254. * object containing the properties height and width.
  255. */
  256. Axis.prototype.getMaxLabelDimensions = function (ticks, tickPositions) {
  257. var dimensions = {
  258. width: 0,
  259. height: 0
  260. };
  261. tickPositions.forEach(function (pos) {
  262. var tick = ticks[pos],
  263. tickHeight = 0,
  264. tickWidth = 0,
  265. label;
  266. if (isObject(tick)) {
  267. label = isObject(tick.label) ? tick.label : {};
  268. // Find width and height of tick
  269. tickHeight = label.getBBox ? label.getBBox().height : 0;
  270. tickWidth = isNumber(label.textPxLength) ? label.textPxLength : 0;
  271. // Update the result if width and/or height are larger
  272. dimensions.height = Math.max(tickHeight, dimensions.height);
  273. dimensions.width = Math.max(tickWidth, dimensions.width);
  274. }
  275. });
  276. return dimensions;
  277. };
  278. // Add custom date formats
  279. H.dateFormats = {
  280. // Week number
  281. W: function (timestamp) {
  282. var d = new Date(timestamp),
  283. yearStart,
  284. weekNo;
  285. d.setHours(0, 0, 0, 0);
  286. d.setDate(d.getDate() - (d.getDay() || 7));
  287. yearStart = new Date(d.getFullYear(), 0, 1);
  288. weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
  289. return weekNo;
  290. },
  291. // First letter of the day of the week, e.g. 'M' for 'Monday'.
  292. E: function (timestamp) {
  293. return dateFormat('%a', timestamp, true).charAt(0);
  294. }
  295. };
  296. addEvent(
  297. Tick,
  298. 'afterGetLabelPosition',
  299. /**
  300. * Center tick labels in cells.
  301. *
  302. * @private
  303. */
  304. function (e) {
  305. var tick = this,
  306. label = tick.label,
  307. axis = tick.axis,
  308. reversed = axis.reversed,
  309. chart = axis.chart,
  310. options = axis.options,
  311. gridOptions = (
  312. (options && isObject(options.grid)) ? options.grid : {}
  313. ),
  314. labelOpts = axis.options.labels,
  315. align = labelOpts.align,
  316. // verticalAlign is currently not supported for axis.labels.
  317. verticalAlign = 'middle', // labelOpts.verticalAlign,
  318. side = axisSide[axis.side],
  319. tickmarkOffset = e.tickmarkOffset,
  320. tickPositions = axis.tickPositions,
  321. tickPos = tick.pos - tickmarkOffset,
  322. nextTickPos = (
  323. isNumber(tickPositions[e.index + 1]) ?
  324. tickPositions[e.index + 1] - tickmarkOffset :
  325. axis.max + tickmarkOffset
  326. ),
  327. tickSize = axis.tickSize('tick', true),
  328. tickWidth = isArray(tickSize) ? tickSize[0] : 0,
  329. crispCorr = tickSize && tickSize[1] / 2,
  330. labelHeight,
  331. lblMetrics,
  332. lines,
  333. bottom,
  334. top,
  335. left,
  336. right;
  337. // Only center tick labels in grid axes
  338. if (gridOptions.enabled === true) {
  339. // Calculate top and bottom positions of the cell.
  340. if (side === 'top') {
  341. bottom = axis.top + axis.offset;
  342. top = bottom - tickWidth;
  343. } else if (side === 'bottom') {
  344. top = chart.chartHeight - axis.bottom + axis.offset;
  345. bottom = top + tickWidth;
  346. } else {
  347. bottom = axis.top + axis.len - axis.translate(
  348. reversed ? nextTickPos : tickPos
  349. );
  350. top = axis.top + axis.len - axis.translate(
  351. reversed ? tickPos : nextTickPos
  352. );
  353. }
  354. // Calculate left and right positions of the cell.
  355. if (side === 'right') {
  356. left = chart.chartWidth - axis.right + axis.offset;
  357. right = left + tickWidth;
  358. } else if (side === 'left') {
  359. right = axis.left + axis.offset;
  360. left = right - tickWidth;
  361. } else {
  362. left = Math.round(axis.left + axis.translate(
  363. reversed ? nextTickPos : tickPos
  364. )) - crispCorr;
  365. right = Math.round(axis.left + axis.translate(
  366. reversed ? tickPos : nextTickPos
  367. )) - crispCorr;
  368. }
  369. tick.slotWidth = right - left;
  370. // Calculate the positioning of the label based on alignment.
  371. e.pos.x = (
  372. align === 'left' ?
  373. left :
  374. align === 'right' ?
  375. right :
  376. left + ((right - left) / 2) // default to center
  377. );
  378. e.pos.y = (
  379. verticalAlign === 'top' ?
  380. top :
  381. verticalAlign === 'bottom' ?
  382. bottom :
  383. top + ((bottom - top) / 2) // default to middle
  384. );
  385. lblMetrics = chart.renderer.fontMetrics(
  386. labelOpts.style.fontSize,
  387. label.element
  388. );
  389. labelHeight = label.getBBox().height;
  390. // Adjustment to y position to align the label correctly.
  391. // Would be better to have a setter or similar for this.
  392. if (!labelOpts.useHTML) {
  393. lines = Math.round(labelHeight / lblMetrics.h);
  394. e.pos.y += (
  395. // Center the label
  396. // TODO: why does this actually center the label?
  397. ((lblMetrics.b - (lblMetrics.h - lblMetrics.f)) / 2) +
  398. // Adjust for height of additional lines.
  399. -(((lines - 1) * lblMetrics.h) / 2)
  400. );
  401. } else {
  402. e.pos.y += (
  403. // Readjust yCorr in htmlUpdateTransform
  404. lblMetrics.b +
  405. // Adjust for height of html label
  406. -(labelHeight / 2)
  407. );
  408. }
  409. e.pos.x += (axis.horiz && labelOpts.x || 0);
  410. }
  411. }
  412. );
  413. // Draw vertical axis ticks extra long to create cell floors and roofs.
  414. // Overrides the tickLength for vertical axes.
  415. addEvent(Axis, 'afterTickSize', function (e) {
  416. var axis = this,
  417. dimensions = axis.maxLabelDimensions,
  418. options = axis.options,
  419. gridOptions = (options && isObject(options.grid)) ? options.grid : {},
  420. labelPadding,
  421. distance;
  422. if (gridOptions.enabled === true) {
  423. labelPadding = (Math.abs(axis.defaultLeftAxisOptions.labels.x) * 2);
  424. distance = labelPadding +
  425. (axis.horiz ? dimensions.height : dimensions.width);
  426. if (isArray(e.tickSize)) {
  427. e.tickSize[0] = distance;
  428. } else {
  429. e.tickSize = [distance];
  430. }
  431. }
  432. });
  433. addEvent(Axis, 'afterGetTitlePosition', function (e) {
  434. var axis = this,
  435. options = axis.options,
  436. gridOptions = (options && isObject(options.grid)) ? options.grid : {};
  437. if (gridOptions.enabled === true) {
  438. // compute anchor points for each of the title align options
  439. var title = axis.axisTitle,
  440. titleWidth = title && title.getBBox().width,
  441. horiz = axis.horiz,
  442. axisLeft = axis.left,
  443. axisTop = axis.top,
  444. axisWidth = axis.width,
  445. axisHeight = axis.height,
  446. axisTitleOptions = options.title,
  447. opposite = axis.opposite,
  448. offset = axis.offset,
  449. tickSize = axis.tickSize() || [0],
  450. xOption = axisTitleOptions.x || 0,
  451. yOption = axisTitleOptions.y || 0,
  452. titleMargin = pick(axisTitleOptions.margin, horiz ? 5 : 10),
  453. titleFontSize = axis.chart.renderer.fontMetrics(
  454. axisTitleOptions.style && axisTitleOptions.style.fontSize,
  455. title
  456. ).f,
  457. // TODO account for alignment
  458. // the position in the perpendicular direction of the axis
  459. offAxis = (horiz ? axisTop + axisHeight : axisLeft) +
  460. (horiz ? 1 : -1) * // horizontal axis reverses the margin
  461. (opposite ? -1 : 1) * // so does opposite axes
  462. (tickSize[0] / 2) +
  463. (axis.side === axisSide.bottom ? titleFontSize : 0);
  464. e.titlePosition.x = horiz ?
  465. axisLeft - titleWidth / 2 - titleMargin + xOption :
  466. offAxis + (opposite ? axisWidth : 0) + offset + xOption;
  467. e.titlePosition.y = horiz ?
  468. (
  469. offAxis -
  470. (opposite ? axisHeight : 0) +
  471. (opposite ? titleFontSize : -titleFontSize) / 2 +
  472. offset +
  473. yOption
  474. ) :
  475. axisTop - titleMargin + yOption;
  476. }
  477. });
  478. // Avoid altering tickInterval when reserving space.
  479. wrap(Axis.prototype, 'unsquish', function (proceed) {
  480. var axis = this,
  481. options = axis.options,
  482. gridOptions = (options && isObject(options.grid)) ? options.grid : {};
  483. if (gridOptions.enabled === true && this.categories) {
  484. return this.tickInterval;
  485. }
  486. return proceed.apply(this, argsToArray(arguments));
  487. });
  488. addEvent(
  489. Axis,
  490. 'afterSetOptions',
  491. /**
  492. * Creates a left and right wall on horizontal axes:
  493. *
  494. * - Places leftmost tick at the start of the axis, to create a left wall
  495. *
  496. * - Ensures that the rightmost tick is at the end of the axis, to create a
  497. * right wall.
  498. *
  499. * @private
  500. * @function
  501. */
  502. function (e) {
  503. var options = this.options,
  504. userOptions = e.userOptions,
  505. gridAxisOptions,
  506. gridOptions = (
  507. (options && isObject(options.grid)) ? options.grid : {}
  508. );
  509. if (gridOptions.enabled === true) {
  510. // Merge the user options into default grid axis options so that
  511. // when a user option is set, it takes presedence.
  512. gridAxisOptions = merge(true, {
  513. className: (
  514. 'highcharts-grid-axis ' + (userOptions.className || '')
  515. ),
  516. dateTimeLabelFormats: {
  517. hour: {
  518. list: ['%H:%M', '%H']
  519. },
  520. day: {
  521. list: ['%A, %e. %B', '%a, %e. %b', '%E']
  522. },
  523. week: {
  524. list: ['Week %W', 'W%W']
  525. },
  526. month: {
  527. list: ['%B', '%b', '%o']
  528. }
  529. },
  530. grid: {
  531. borderWidth: 1
  532. },
  533. labels: {
  534. padding: 2,
  535. style: {
  536. fontSize: '13px'
  537. }
  538. },
  539. title: {
  540. text: null,
  541. reserveSpace: false,
  542. rotation: 0
  543. },
  544. // In a grid axis, only allow one unit of certain types, for
  545. // example we shouln't have one grid cell spanning two days.
  546. units: [[
  547. 'millisecond', // unit name
  548. [1, 10, 100]
  549. ], [
  550. 'second',
  551. [1, 10]
  552. ], [
  553. 'minute',
  554. [1, 5, 15]
  555. ], [
  556. 'hour',
  557. [1, 6]
  558. ], [
  559. 'day',
  560. [1]
  561. ], [
  562. 'week',
  563. [1]
  564. ], [
  565. 'month',
  566. [1]
  567. ], [
  568. 'year',
  569. null
  570. ]]
  571. }, userOptions);
  572. // X-axis specific options
  573. if (this.coll === 'xAxis') {
  574. // For linked axes, tickPixelInterval is used only if the
  575. // tickPositioner below doesn't run or returns undefined (like
  576. // multiple years)
  577. if (
  578. defined(userOptions.linkedTo) &&
  579. !defined(userOptions.tickPixelInterval)
  580. ) {
  581. gridAxisOptions.tickPixelInterval = 350;
  582. }
  583. // For the secondary grid axis, use the primary axis' tick
  584. // intervals and return ticks one level higher.
  585. if (
  586. // Check for tick pixel interval in options
  587. !defined(userOptions.tickPixelInterval) &&
  588. // Only for linked axes
  589. defined(userOptions.linkedTo) &&
  590. !defined(userOptions.tickPositioner) &&
  591. !defined(userOptions.tickInterval)
  592. ) {
  593. gridAxisOptions.tickPositioner = function (min, max) {
  594. var parentInfo = (
  595. this.linkedParent &&
  596. this.linkedParent.tickPositions &&
  597. this.linkedParent.tickPositions.info
  598. );
  599. if (parentInfo) {
  600. var unitIdx,
  601. count,
  602. unitName,
  603. i,
  604. units = gridAxisOptions.units,
  605. unitRange;
  606. for (i = 0; i < units.length; i++) {
  607. if (units[i][0] === parentInfo.unitName) {
  608. unitIdx = i;
  609. break;
  610. }
  611. }
  612. // Spanning multiple years, go default
  613. if (!units[unitIdx][1]) {
  614. return;
  615. }
  616. // Get the first allowed count on the next unit.
  617. if (units[unitIdx + 1]) {
  618. unitName = units[unitIdx + 1][0];
  619. count = (units[unitIdx + 1][1] || [1])[0];
  620. }
  621. unitRange = H.timeUnits[unitName];
  622. this.tickInterval = unitRange * count;
  623. return this.getTimeTicks(
  624. {
  625. unitRange: unitRange,
  626. count: count,
  627. unitName: unitName
  628. },
  629. min,
  630. max,
  631. this.options.startOfWeek
  632. );
  633. }
  634. };
  635. }
  636. }
  637. // Now merge the combined options into the axis options
  638. merge(true, this.options, gridAxisOptions);
  639. if (this.horiz) {
  640. /* _________________________
  641. Make this: ___|_____|_____|_____|__|
  642. ^ ^
  643. _________________________
  644. Into this: |_____|_____|_____|_____|
  645. ^ ^ */
  646. options.minPadding = pick(userOptions.minPadding, 0);
  647. options.maxPadding = pick(userOptions.maxPadding, 0);
  648. }
  649. // If borderWidth is set, then use its value for tick and line
  650. // width.
  651. if (isNumber(options.grid.borderWidth)) {
  652. options.tickWidth = options.lineWidth = gridOptions.borderWidth;
  653. }
  654. }
  655. }
  656. );
  657. addEvent(
  658. Axis,
  659. 'afterSetAxisTranslation',
  660. function () {
  661. var axis = this,
  662. options = axis.options,
  663. gridOptions = (
  664. (options && isObject(options.grid)) ? options.grid : {}
  665. ),
  666. tickInfo = this.tickPositions && this.tickPositions.info,
  667. userLabels = this.userOptions.labels || {};
  668. if (this.horiz) {
  669. if (gridOptions.enabled === true) {
  670. axis.series.forEach(function (series) {
  671. series.options.pointRange = 0;
  672. });
  673. }
  674. // Lower level time ticks, like hours or minutes, represent points
  675. // in time and not ranges. These should be aligned left in the grid
  676. // cell by default. The same applies to years of higher order.
  677. if (
  678. tickInfo &&
  679. (
  680. options.dateTimeLabelFormats[tickInfo.unitName]
  681. .range === false ||
  682. tickInfo.count > 1 // years
  683. ) &&
  684. !defined(userLabels.align)
  685. ) {
  686. options.labels.align = 'left';
  687. if (!defined(userLabels.x)) {
  688. options.labels.x = 3;
  689. }
  690. }
  691. }
  692. }
  693. );
  694. // @todo Does this function do what the drawing says? Seems to affect ticks and
  695. // not the labels directly?
  696. addEvent(
  697. Axis,
  698. 'trimTicks',
  699. /**
  700. * Makes tick labels which are usually ignored in a linked axis displayed if
  701. * they are within range of linkedParent.min.
  702. * ```
  703. * _____________________________
  704. * | | | | |
  705. * Make this: | | 2 | 3 | 4 |
  706. * |___|_______|_______|_______|
  707. * ^
  708. * _____________________________
  709. * | | | | |
  710. * Into this: | 1 | 2 | 3 | 4 |
  711. * |___|_______|_______|_______|
  712. * ^
  713. * ```
  714. *
  715. * @private
  716. */
  717. function () {
  718. var axis = this,
  719. options = axis.options,
  720. gridOptions = (
  721. (options && isObject(options.grid)) ? options.grid : {}
  722. ),
  723. categoryAxis = axis.categories,
  724. tickPositions = axis.tickPositions,
  725. firstPos = tickPositions[0],
  726. lastPos = tickPositions[tickPositions.length - 1],
  727. linkedMin = axis.linkedParent && axis.linkedParent.min,
  728. linkedMax = axis.linkedParent && axis.linkedParent.max,
  729. min = linkedMin || axis.min,
  730. max = linkedMax || axis.max,
  731. tickInterval = axis.tickInterval,
  732. moreThanMin = firstPos > min,
  733. lessThanMax = lastPos < max,
  734. endMoreThanMin = firstPos < min && firstPos + tickInterval > min,
  735. startLessThanMax = lastPos > max && lastPos - tickInterval < max;
  736. if (
  737. gridOptions.enabled === true &&
  738. !categoryAxis &&
  739. (axis.horiz || axis.isLinked)
  740. ) {
  741. if ((moreThanMin || endMoreThanMin) && !options.startOnTick) {
  742. tickPositions[0] = min;
  743. }
  744. if ((lessThanMax || startLessThanMax) && !options.endOnTick) {
  745. tickPositions[tickPositions.length - 1] = max;
  746. }
  747. }
  748. }
  749. );
  750. addEvent(
  751. Axis,
  752. 'afterRender',
  753. /**
  754. * Draw an extra line on the far side of the outermost axis,
  755. * creating floor/roof/wall of a grid. And some padding.
  756. * ```
  757. * Make this:
  758. * (axis.min) __________________________ (axis.max)
  759. * | | | | |
  760. * Into this:
  761. * (axis.min) __________________________ (axis.max)
  762. * ___|____|____|____|____|__
  763. * ```
  764. *
  765. * @private
  766. * @function
  767. *
  768. * @param {Function} proceed
  769. * the original function
  770. */
  771. function () {
  772. var axis = this,
  773. options = axis.options,
  774. gridOptions = ((
  775. options && isObject(options.grid)) ? options.grid : {}
  776. ),
  777. labelPadding,
  778. distance,
  779. lineWidth,
  780. linePath,
  781. yStartIndex,
  782. yEndIndex,
  783. xStartIndex,
  784. xEndIndex,
  785. renderer = axis.chart.renderer,
  786. horiz = axis.horiz,
  787. axisGroupBox;
  788. if (gridOptions.enabled === true) {
  789. // @todo acutual label padding (top, bottom, left, right)
  790. // Label padding is needed to figure out where to draw the outer
  791. // line.
  792. labelPadding = (Math.abs(axis.defaultLeftAxisOptions.labels.x) * 2);
  793. axis.maxLabelDimensions = axis.getMaxLabelDimensions(
  794. axis.ticks,
  795. axis.tickPositions
  796. );
  797. distance = axis.maxLabelDimensions.width + labelPadding;
  798. lineWidth = options.lineWidth;
  799. // Remove right wall before rendering if updating
  800. if (axis.rightWall) {
  801. axis.rightWall.destroy();
  802. }
  803. axisGroupBox = axis.axisGroup.getBBox();
  804. /*
  805. Draw an extra axis line on outer axes
  806. >
  807. Make this: |______|______|______|___
  808. > _________________________
  809. Into this: |______|______|______|__|
  810. */
  811. if (axis.isOuterAxis() && axis.axisLine) {
  812. if (horiz) {
  813. // -1 to avoid adding distance each time the chart updates
  814. distance = axisGroupBox.height - 1;
  815. }
  816. if (lineWidth) {
  817. linePath = axis.getLinePath(lineWidth);
  818. xStartIndex = linePath.indexOf('M') + 1;
  819. xEndIndex = linePath.indexOf('L') + 1;
  820. yStartIndex = linePath.indexOf('M') + 2;
  821. yEndIndex = linePath.indexOf('L') + 2;
  822. // Negate distance if top or left axis
  823. if (axis.side === axisSide.top ||
  824. axis.side === axisSide.left
  825. ) {
  826. distance = -distance;
  827. }
  828. // If axis is horizontal, reposition line path vertically
  829. if (horiz) {
  830. linePath[yStartIndex] = (
  831. linePath[yStartIndex] + distance
  832. );
  833. linePath[yEndIndex] = linePath[yEndIndex] + distance;
  834. } else {
  835. // If axis is vertical, reposition line path
  836. // horizontally
  837. linePath[xStartIndex] = (
  838. linePath[xStartIndex] + distance
  839. );
  840. linePath[xEndIndex] = linePath[xEndIndex] + distance;
  841. }
  842. if (!axis.axisLineExtra) {
  843. axis.axisLineExtra = renderer.path(linePath)
  844. .attr({
  845. stroke: options.lineColor,
  846. 'stroke-width': lineWidth,
  847. zIndex: 7
  848. })
  849. .addClass('highcharts-axis-line')
  850. .add(axis.axisGroup);
  851. } else {
  852. axis.axisLineExtra.animate({
  853. d: linePath
  854. });
  855. }
  856. // show or hide the line depending on options.showEmpty
  857. axis.axisLine[axis.showAxis ? 'show' : 'hide'](true);
  858. }
  859. }
  860. }
  861. }
  862. );
  863. // Wraps axis init to draw cell walls on vertical axes.
  864. addEvent(Axis, 'init', function (e) {
  865. var axis = this,
  866. chart = axis.chart,
  867. userOptions = e.userOptions,
  868. gridOptions = (
  869. (userOptions && isObject(userOptions.grid)) ?
  870. userOptions.grid :
  871. {}
  872. ),
  873. columnOptions,
  874. column,
  875. columnIndex,
  876. i;
  877. function applyGridOptions() {
  878. var options = axis.options,
  879. // TODO: Consider using cell margins defined in % of font size?
  880. // 25 is optimal height for default fontSize (11px)
  881. // 25 / 11 ≈ 2.28
  882. fontSizeToCellHeightRatio = 25 / 11,
  883. fontSize = options.labels.style.fontSize,
  884. fontMetrics = axis.chart.renderer.fontMetrics(fontSize);
  885. // Center-align by default
  886. if (!options.labels) {
  887. options.labels = {};
  888. }
  889. options.labels.align = pick(options.labels.align, 'center');
  890. // @todo: Check against tickLabelPlacement between/on etc
  891. /* Prevents adding the last tick label if the axis is not a category
  892. axis.
  893. Since numeric labels are normally placed at starts and ends of a
  894. range of value, and this module makes the label point at the value,
  895. an "extra" label would appear. */
  896. if (!axis.categories) {
  897. options.showLastLabel = false;
  898. }
  899. // Make tick marks taller, creating cell walls of a grid. Use cellHeight
  900. // axis option if set
  901. if (axis.horiz) {
  902. options.tickLength = gridOptions.cellHeight ||
  903. fontMetrics.h * fontSizeToCellHeightRatio;
  904. }
  905. // Prevents rotation of labels when squished, as rotating them would not
  906. // help.
  907. axis.labelRotation = 0;
  908. options.labels.rotation = 0;
  909. }
  910. if (gridOptions.enabled) {
  911. if (defined(gridOptions.borderColor)) {
  912. userOptions.tickColor =
  913. userOptions.lineColor = gridOptions.borderColor;
  914. }
  915. // Handle columns, each column is a grid axis
  916. if (isArray(gridOptions.columns)) {
  917. columnIndex = 0;
  918. i = gridOptions.columns.length;
  919. while (i--) {
  920. columnOptions = merge(
  921. userOptions,
  922. gridOptions.columns[i],
  923. {
  924. // Force to behave like category axis
  925. type: 'category'
  926. }
  927. );
  928. delete columnOptions.grid.columns; // Prevent recursion
  929. column = new Axis(axis.chart, columnOptions);
  930. column.isColumn = true;
  931. column.columnIndex = columnIndex;
  932. wrap(column, 'labelFormatter', function (proceed) {
  933. var axis = this.axis,
  934. tickPos = axis.tickPositions,
  935. value = this.value,
  936. series = axis.series[0],
  937. isFirst = value === tickPos[0],
  938. isLast = value === tickPos[tickPos.length - 1],
  939. point = H.find(series.options.data, function (p) {
  940. return p[axis.isXAxis ? 'x' : 'y'] === value;
  941. });
  942. // Make additional properties available for the formatter
  943. this.isFirst = isFirst;
  944. this.isLast = isLast;
  945. this.point = point;
  946. // Call original labelFormatter
  947. return proceed.call(this);
  948. });
  949. columnIndex++;
  950. }
  951. // This axis should not be shown, instead the column axes take over
  952. addEvent(this, 'afterInit', function () {
  953. H.erase(chart.axes, this);
  954. H.erase(chart[axis.coll], this);
  955. });
  956. } else {
  957. addEvent(this, 'afterInit', applyGridOptions);
  958. }
  959. }
  960. });
  961. }(Highcharts));
  962. (function (H) {
  963. /* *
  964. * (c) 2016-2019 Torstein Honsi, Lars Cabrera
  965. *
  966. * License: www.highcharts.com/license
  967. */
  968. var Chart = H.Chart,
  969. pick = H.pick;
  970. /**
  971. * For vertical axes only. Setting the static scale ensures that each tick unit
  972. * is translated into a fixed pixel height. For example, setting the static
  973. * scale to 24 results in each Y axis category taking up 24 pixels, and the
  974. * height of the chart adjusts. Adding or removing items will make the chart
  975. * resize.
  976. *
  977. * @sample gantt/xrange-series/demo/
  978. * X-range series with static scale
  979. *
  980. * @type {number}
  981. * @default 50
  982. * @since 6.2.0
  983. * @product gantt
  984. * @apioption yAxis.staticScale
  985. */
  986. H.addEvent(H.Axis, 'afterSetOptions', function () {
  987. if (
  988. !this.horiz &&
  989. H.isNumber(this.options.staticScale) &&
  990. !this.chart.options.chart.height
  991. ) {
  992. this.staticScale = this.options.staticScale;
  993. }
  994. });
  995. Chart.prototype.adjustHeight = function () {
  996. if (this.redrawTrigger !== 'adjustHeight') {
  997. (this.axes || []).forEach(function (axis) {
  998. var chart = axis.chart,
  999. animate = !!chart.initiatedScale && chart.options.animation,
  1000. staticScale = axis.options.staticScale,
  1001. height,
  1002. diff;
  1003. if (axis.staticScale && H.defined(axis.min)) {
  1004. height = pick(
  1005. axis.unitLength,
  1006. axis.max + axis.tickInterval - axis.min
  1007. ) * staticScale;
  1008. // Minimum height is 1 x staticScale.
  1009. height = Math.max(height, staticScale);
  1010. diff = height - chart.plotHeight;
  1011. if (Math.abs(diff) >= 1) {
  1012. chart.plotHeight = height;
  1013. chart.redrawTrigger = 'adjustHeight';
  1014. chart.setSize(undefined, chart.chartHeight + diff, animate);
  1015. }
  1016. // Make sure clip rects have the right height before initial
  1017. // animation.
  1018. axis.series.forEach(function (series) {
  1019. var clipRect =
  1020. series.sharedClipKey && chart[series.sharedClipKey];
  1021. if (clipRect) {
  1022. clipRect.attr({
  1023. height: chart.plotHeight
  1024. });
  1025. }
  1026. });
  1027. }
  1028. });
  1029. this.initiatedScale = true;
  1030. }
  1031. this.redrawTrigger = null;
  1032. };
  1033. H.addEvent(Chart, 'render', Chart.prototype.adjustHeight);
  1034. }(Highcharts));
  1035. var Tree = (function (H) {
  1036. /* *
  1037. *
  1038. * (c) 2016-2019 Highsoft AS
  1039. *
  1040. * Authors: Jon Arild Nygard
  1041. *
  1042. * License: www.highcharts.com/license
  1043. *
  1044. * */
  1045. /* eslint no-console: 0 */
  1046. var extend = H.extend,
  1047. isNumber = H.isNumber,
  1048. pick = H.pick,
  1049. isFunction = function (x) {
  1050. return typeof x === 'function';
  1051. };
  1052. /**
  1053. * Creates an object map from parent id to childrens index.
  1054. *
  1055. * @private
  1056. * @function Highcharts.Tree#getListOfParents
  1057. *
  1058. * @param {Array<*>} data
  1059. * List of points set in options. `Array<*>.parent`is parent id of point.
  1060. *
  1061. * @param {Array<string>} ids
  1062. * List of all point ids.
  1063. *
  1064. * @return {object}
  1065. * Map from parent id to children index in data
  1066. */
  1067. var getListOfParents = function (data, ids) {
  1068. var listOfParents = data.reduce(function (prev, curr) {
  1069. var parent = pick(curr.parent, '');
  1070. if (prev[parent] === undefined) {
  1071. prev[parent] = [];
  1072. }
  1073. prev[parent].push(curr);
  1074. return prev;
  1075. }, {}),
  1076. parents = Object.keys(listOfParents);
  1077. // If parent does not exist, hoist parent to root of tree.
  1078. parents.forEach(function (parent, list) {
  1079. var children = listOfParents[parent];
  1080. if ((parent !== '') && (ids.indexOf(parent) === -1)) {
  1081. children.forEach(function (child) {
  1082. list[''].push(child);
  1083. });
  1084. delete list[parent];
  1085. }
  1086. });
  1087. return listOfParents;
  1088. };
  1089. var getNode = function (id, parent, level, data, mapOfIdToChildren, options) {
  1090. var descendants = 0,
  1091. height = 0,
  1092. after = options && options.after,
  1093. before = options && options.before,
  1094. node = {
  1095. data: data,
  1096. depth: level - 1,
  1097. id: id,
  1098. level: level,
  1099. parent: parent
  1100. },
  1101. start,
  1102. end,
  1103. children;
  1104. // Allow custom logic before the children has been created.
  1105. if (isFunction(before)) {
  1106. before(node, options);
  1107. }
  1108. // Call getNode recursively on the children. Calulate the height of the
  1109. // node, and the number of descendants.
  1110. children = ((mapOfIdToChildren[id] || [])).map(function (child) {
  1111. var node = getNode(
  1112. child.id,
  1113. id,
  1114. (level + 1),
  1115. child,
  1116. mapOfIdToChildren,
  1117. options
  1118. ),
  1119. childStart = child.start,
  1120. childEnd = (
  1121. child.milestone === true ?
  1122. childStart :
  1123. child.end
  1124. );
  1125. // Start should be the lowest child.start.
  1126. start = (
  1127. (!isNumber(start) || childStart < start) ?
  1128. childStart :
  1129. start
  1130. );
  1131. // End should be the largest child.end.
  1132. // If child is milestone, then use start as end.
  1133. end = (
  1134. (!isNumber(end) || childEnd > end) ?
  1135. childEnd :
  1136. end
  1137. );
  1138. descendants = descendants + 1 + node.descendants;
  1139. height = Math.max(node.height + 1, height);
  1140. return node;
  1141. });
  1142. // Calculate start and end for point if it is not already explicitly set.
  1143. if (data) {
  1144. data.start = pick(data.start, start);
  1145. data.end = pick(data.end, end);
  1146. }
  1147. extend(node, {
  1148. children: children,
  1149. descendants: descendants,
  1150. height: height
  1151. });
  1152. // Allow custom logic after the children has been created.
  1153. if (isFunction(after)) {
  1154. after(node, options);
  1155. }
  1156. return node;
  1157. };
  1158. var getTree = function (data, options) {
  1159. var ids = data.map(function (d) {
  1160. return d.id;
  1161. }),
  1162. mapOfIdToChildren = getListOfParents(data, ids);
  1163. return getNode('', null, 1, null, mapOfIdToChildren, options);
  1164. };
  1165. var Tree = {
  1166. getListOfParents: getListOfParents,
  1167. getNode: getNode,
  1168. getTree: getTree
  1169. };
  1170. return Tree;
  1171. }(Highcharts));
  1172. var result = (function (H) {
  1173. var extend = H.extend,
  1174. isArray = H.isArray,
  1175. isBoolean = function (x) {
  1176. return typeof x === 'boolean';
  1177. },
  1178. isFn = function (x) {
  1179. return typeof x === 'function';
  1180. },
  1181. isObject = H.isObject,
  1182. isNumber = H.isNumber,
  1183. merge = H.merge,
  1184. pick = H.pick;
  1185. // TODO Combine buildTree and buildNode with setTreeValues
  1186. // TODO Remove logic from Treemap and make it utilize this mixin.
  1187. var setTreeValues = function setTreeValues(tree, options) {
  1188. var before = options.before,
  1189. idRoot = options.idRoot,
  1190. mapIdToNode = options.mapIdToNode,
  1191. nodeRoot = mapIdToNode[idRoot],
  1192. levelIsConstant = (
  1193. isBoolean(options.levelIsConstant) ?
  1194. options.levelIsConstant :
  1195. true
  1196. ),
  1197. points = options.points,
  1198. point = points[tree.i],
  1199. optionsPoint = point && point.options || {},
  1200. childrenTotal = 0,
  1201. children = [],
  1202. value;
  1203. extend(tree, {
  1204. levelDynamic: tree.level - (levelIsConstant ? 0 : nodeRoot.level),
  1205. name: pick(point && point.name, ''),
  1206. visible: (
  1207. idRoot === tree.id ||
  1208. (isBoolean(options.visible) ? options.visible : false)
  1209. )
  1210. });
  1211. if (isFn(before)) {
  1212. tree = before(tree, options);
  1213. }
  1214. // First give the children some values
  1215. tree.children.forEach(function (child, i) {
  1216. var newOptions = extend({}, options);
  1217. extend(newOptions, {
  1218. index: i,
  1219. siblings: tree.children.length,
  1220. visible: tree.visible
  1221. });
  1222. child = setTreeValues(child, newOptions);
  1223. children.push(child);
  1224. if (child.visible) {
  1225. childrenTotal += child.val;
  1226. }
  1227. });
  1228. tree.visible = childrenTotal > 0 || tree.visible;
  1229. // Set the values
  1230. value = pick(optionsPoint.value, childrenTotal);
  1231. extend(tree, {
  1232. children: children,
  1233. childrenTotal: childrenTotal,
  1234. isLeaf: tree.visible && !childrenTotal,
  1235. val: value
  1236. });
  1237. return tree;
  1238. };
  1239. var getColor = function getColor(node, options) {
  1240. var index = options.index,
  1241. mapOptionsToLevel = options.mapOptionsToLevel,
  1242. parentColor = options.parentColor,
  1243. parentColorIndex = options.parentColorIndex,
  1244. series = options.series,
  1245. colors = options.colors,
  1246. siblings = options.siblings,
  1247. points = series.points,
  1248. getColorByPoint,
  1249. chartOptionsChart = series.chart.options.chart,
  1250. point,
  1251. level,
  1252. colorByPoint,
  1253. colorIndexByPoint,
  1254. color,
  1255. colorIndex;
  1256. function variation(color) {
  1257. var colorVariation = level && level.colorVariation;
  1258. if (colorVariation) {
  1259. if (colorVariation.key === 'brightness') {
  1260. return H.color(color).brighten(
  1261. colorVariation.to * (index / siblings)
  1262. ).get();
  1263. }
  1264. }
  1265. return color;
  1266. }
  1267. if (node) {
  1268. point = points[node.i];
  1269. level = mapOptionsToLevel[node.level] || {};
  1270. getColorByPoint = point && level.colorByPoint;
  1271. if (getColorByPoint) {
  1272. colorIndexByPoint = point.index % (colors ?
  1273. colors.length :
  1274. chartOptionsChart.colorCount
  1275. );
  1276. colorByPoint = colors && colors[colorIndexByPoint];
  1277. }
  1278. // Select either point color, level color or inherited color.
  1279. if (!series.chart.styledMode) {
  1280. color = pick(
  1281. point && point.options.color,
  1282. level && level.color,
  1283. colorByPoint,
  1284. parentColor && variation(parentColor),
  1285. series.color
  1286. );
  1287. }
  1288. colorIndex = pick(
  1289. point && point.options.colorIndex,
  1290. level && level.colorIndex,
  1291. colorIndexByPoint,
  1292. parentColorIndex,
  1293. options.colorIndex
  1294. );
  1295. }
  1296. return {
  1297. color: color,
  1298. colorIndex: colorIndex
  1299. };
  1300. };
  1301. /**
  1302. * Creates a map from level number to its given options.
  1303. *
  1304. * @private
  1305. * @function getLevelOptions
  1306. *
  1307. * @param {object} params
  1308. * Object containing parameters.
  1309. * - `defaults` Object containing default options. The default options
  1310. * are merged with the userOptions to get the final options for a
  1311. * specific level.
  1312. * - `from` The lowest level number.
  1313. * - `levels` User options from series.levels.
  1314. * - `to` The highest level number.
  1315. *
  1316. * @return {Highcharts.Dictionary<object>}
  1317. * Returns a map from level number to its given options.
  1318. */
  1319. var getLevelOptions = function getLevelOptions(params) {
  1320. var result = null,
  1321. defaults,
  1322. converted,
  1323. i,
  1324. from,
  1325. to,
  1326. levels;
  1327. if (isObject(params)) {
  1328. result = {};
  1329. from = isNumber(params.from) ? params.from : 1;
  1330. levels = params.levels;
  1331. converted = {};
  1332. defaults = isObject(params.defaults) ? params.defaults : {};
  1333. if (isArray(levels)) {
  1334. converted = levels.reduce(function (obj, item) {
  1335. var level,
  1336. levelIsConstant,
  1337. options;
  1338. if (isObject(item) && isNumber(item.level)) {
  1339. options = merge({}, item);
  1340. levelIsConstant = (
  1341. isBoolean(options.levelIsConstant) ?
  1342. options.levelIsConstant :
  1343. defaults.levelIsConstant
  1344. );
  1345. // Delete redundant properties.
  1346. delete options.levelIsConstant;
  1347. delete options.level;
  1348. // Calculate which level these options apply to.
  1349. level = item.level + (levelIsConstant ? 0 : from - 1);
  1350. if (isObject(obj[level])) {
  1351. extend(obj[level], options);
  1352. } else {
  1353. obj[level] = options;
  1354. }
  1355. }
  1356. return obj;
  1357. }, {});
  1358. }
  1359. to = isNumber(params.to) ? params.to : 1;
  1360. for (i = 0; i <= to; i++) {
  1361. result[i] = merge(
  1362. {},
  1363. defaults,
  1364. isObject(converted[i]) ? converted[i] : {}
  1365. );
  1366. }
  1367. }
  1368. return result;
  1369. };
  1370. /**
  1371. * Update the rootId property on the series. Also makes sure that it is
  1372. * accessible to exporting.
  1373. *
  1374. * @private
  1375. * @function updateRootId
  1376. *
  1377. * @param {object} series
  1378. * The series to operate on.
  1379. *
  1380. * @return {string}
  1381. * Returns the resulting rootId after update.
  1382. */
  1383. var updateRootId = function (series) {
  1384. var rootId,
  1385. options;
  1386. if (isObject(series)) {
  1387. // Get the series options.
  1388. options = isObject(series.options) ? series.options : {};
  1389. // Calculate the rootId.
  1390. rootId = pick(series.rootNode, options.rootId, '');
  1391. // Set rootId on series.userOptions to pick it up in exporting.
  1392. if (isObject(series.userOptions)) {
  1393. series.userOptions.rootId = rootId;
  1394. }
  1395. // Set rootId on series to pick it up on next update.
  1396. series.rootNode = rootId;
  1397. }
  1398. return rootId;
  1399. };
  1400. var result = {
  1401. getColor: getColor,
  1402. getLevelOptions: getLevelOptions,
  1403. setTreeValues: setTreeValues,
  1404. updateRootId: updateRootId
  1405. };
  1406. return result;
  1407. }(Highcharts));
  1408. (function (H) {
  1409. /**
  1410. * (c) 2009-2019 Torstein Honsi
  1411. *
  1412. * License: www.highcharts.com/license
  1413. */
  1414. var addEvent = H.addEvent,
  1415. pick = H.pick,
  1416. extend = H.extend,
  1417. isArray = H.isArray,
  1418. fireEvent = H.fireEvent,
  1419. Axis = H.Axis,
  1420. Series = H.Series;
  1421. extend(Axis.prototype, {
  1422. isInBreak: function (brk, val) {
  1423. var ret,
  1424. repeat = brk.repeat || Infinity,
  1425. from = brk.from,
  1426. length = brk.to - brk.from,
  1427. test = (
  1428. val >= from ?
  1429. (val - from) % repeat :
  1430. repeat - ((from - val) % repeat)
  1431. );
  1432. if (!brk.inclusive) {
  1433. ret = test < length && test !== 0;
  1434. } else {
  1435. ret = test <= length;
  1436. }
  1437. return ret;
  1438. },
  1439. isInAnyBreak: function (val, testKeep) {
  1440. var breaks = this.options.breaks,
  1441. i = breaks && breaks.length,
  1442. inbrk,
  1443. keep,
  1444. ret;
  1445. if (i) {
  1446. while (i--) {
  1447. if (this.isInBreak(breaks[i], val)) {
  1448. inbrk = true;
  1449. if (!keep) {
  1450. keep = pick(
  1451. breaks[i].showPoints,
  1452. !this.isXAxis
  1453. );
  1454. }
  1455. }
  1456. }
  1457. if (inbrk && testKeep) {
  1458. ret = inbrk && !keep;
  1459. } else {
  1460. ret = inbrk;
  1461. }
  1462. }
  1463. return ret;
  1464. }
  1465. });
  1466. addEvent(Axis, 'afterInit', function () {
  1467. if (typeof this.setBreaks === 'function') {
  1468. this.setBreaks(this.options.breaks, false);
  1469. }
  1470. });
  1471. addEvent(Axis, 'afterSetTickPositions', function () {
  1472. if (this.isBroken) {
  1473. var axis = this,
  1474. tickPositions = this.tickPositions,
  1475. info = this.tickPositions.info,
  1476. newPositions = [],
  1477. i;
  1478. for (i = 0; i < tickPositions.length; i++) {
  1479. if (!axis.isInAnyBreak(tickPositions[i])) {
  1480. newPositions.push(tickPositions[i]);
  1481. }
  1482. }
  1483. this.tickPositions = newPositions;
  1484. this.tickPositions.info = info;
  1485. }
  1486. });
  1487. // Force Axis to be not-ordinal when breaks are defined
  1488. addEvent(Axis, 'afterSetOptions', function () {
  1489. if (this.isBroken) {
  1490. this.options.ordinal = false;
  1491. }
  1492. });
  1493. /**
  1494. * Dynamically set or unset breaks in an axis. This function in lighter than
  1495. * usin Axis.update, and it also preserves animation.
  1496. *
  1497. * @private
  1498. * @function Highcharts.Axis#setBreaks
  1499. *
  1500. * @param {Array<*>} [breaks]
  1501. * The breaks to add. When `undefined` it removes existing breaks.
  1502. *
  1503. * @param {boolean} [redraw=true]
  1504. * Whether to redraw the chart immediately.
  1505. */
  1506. Axis.prototype.setBreaks = function (breaks, redraw) {
  1507. var axis = this,
  1508. isBroken = (isArray(breaks) && !!breaks.length);
  1509. function breakVal2Lin(val) {
  1510. var nval = val,
  1511. brk,
  1512. i;
  1513. for (i = 0; i < axis.breakArray.length; i++) {
  1514. brk = axis.breakArray[i];
  1515. if (brk.to <= val) {
  1516. nval -= brk.len;
  1517. } else if (brk.from >= val) {
  1518. break;
  1519. } else if (axis.isInBreak(brk, val)) {
  1520. nval -= (val - brk.from);
  1521. break;
  1522. }
  1523. }
  1524. return nval;
  1525. }
  1526. function breakLin2Val(val) {
  1527. var nval = val,
  1528. brk,
  1529. i;
  1530. for (i = 0; i < axis.breakArray.length; i++) {
  1531. brk = axis.breakArray[i];
  1532. if (brk.from >= nval) {
  1533. break;
  1534. } else if (brk.to < nval) {
  1535. nval += brk.len;
  1536. } else if (axis.isInBreak(brk, nval)) {
  1537. nval += brk.len;
  1538. }
  1539. }
  1540. return nval;
  1541. }
  1542. axis.isDirty = axis.isBroken !== isBroken;
  1543. axis.isBroken = isBroken;
  1544. axis.options.breaks = axis.userOptions.breaks = breaks;
  1545. axis.forceRedraw = true; // Force recalculation in setScale
  1546. if (!isBroken && axis.val2lin === breakVal2Lin) {
  1547. // Revert to prototype functions
  1548. delete axis.val2lin;
  1549. delete axis.lin2val;
  1550. }
  1551. if (isBroken) {
  1552. axis.userOptions.ordinal = false;
  1553. axis.val2lin = breakVal2Lin;
  1554. axis.lin2val = breakLin2Val;
  1555. axis.setExtremes = function (
  1556. newMin,
  1557. newMax,
  1558. redraw,
  1559. animation,
  1560. eventArguments
  1561. ) {
  1562. // If trying to set extremes inside a break, extend it to before and
  1563. // after the break ( #3857 )
  1564. if (this.isBroken) {
  1565. while (this.isInAnyBreak(newMin)) {
  1566. newMin -= this.closestPointRange;
  1567. }
  1568. while (this.isInAnyBreak(newMax)) {
  1569. newMax -= this.closestPointRange;
  1570. }
  1571. }
  1572. Axis.prototype.setExtremes.call(
  1573. this,
  1574. newMin,
  1575. newMax,
  1576. redraw,
  1577. animation,
  1578. eventArguments
  1579. );
  1580. };
  1581. axis.setAxisTranslation = function (saveOld) {
  1582. Axis.prototype.setAxisTranslation.call(this, saveOld);
  1583. this.unitLength = null;
  1584. if (this.isBroken) {
  1585. var breaks = axis.options.breaks,
  1586. breakArrayT = [], // Temporary one
  1587. breakArray = [],
  1588. length = 0,
  1589. inBrk,
  1590. repeat,
  1591. min = axis.userMin || axis.min,
  1592. max = axis.userMax || axis.max,
  1593. pointRangePadding = pick(axis.pointRangePadding, 0),
  1594. start,
  1595. i;
  1596. // Min & max check (#4247)
  1597. breaks.forEach(function (brk) {
  1598. repeat = brk.repeat || Infinity;
  1599. if (axis.isInBreak(brk, min)) {
  1600. min += (brk.to % repeat) - (min % repeat);
  1601. }
  1602. if (axis.isInBreak(brk, max)) {
  1603. max -= (max % repeat) - (brk.from % repeat);
  1604. }
  1605. });
  1606. // Construct an array holding all breaks in the axis
  1607. breaks.forEach(function (brk) {
  1608. start = brk.from;
  1609. repeat = brk.repeat || Infinity;
  1610. while (start - repeat > min) {
  1611. start -= repeat;
  1612. }
  1613. while (start < min) {
  1614. start += repeat;
  1615. }
  1616. for (i = start; i < max; i += repeat) {
  1617. breakArrayT.push({
  1618. value: i,
  1619. move: 'in'
  1620. });
  1621. breakArrayT.push({
  1622. value: i + (brk.to - brk.from),
  1623. move: 'out',
  1624. size: brk.breakSize
  1625. });
  1626. }
  1627. });
  1628. breakArrayT.sort(function (a, b) {
  1629. return (
  1630. (a.value === b.value) ?
  1631. (
  1632. (a.move === 'in' ? 0 : 1) -
  1633. (b.move === 'in' ? 0 : 1)
  1634. ) :
  1635. a.value - b.value
  1636. );
  1637. });
  1638. // Simplify the breaks
  1639. inBrk = 0;
  1640. start = min;
  1641. breakArrayT.forEach(function (brk) {
  1642. inBrk += (brk.move === 'in' ? 1 : -1);
  1643. if (inBrk === 1 && brk.move === 'in') {
  1644. start = brk.value;
  1645. }
  1646. if (inBrk === 0) {
  1647. breakArray.push({
  1648. from: start,
  1649. to: brk.value,
  1650. len: brk.value - start - (brk.size || 0)
  1651. });
  1652. length += brk.value - start - (brk.size || 0);
  1653. }
  1654. });
  1655. axis.breakArray = breakArray;
  1656. // Used with staticScale, and below, the actual axis length when
  1657. // breaks are substracted.
  1658. axis.unitLength = max - min - length + pointRangePadding;
  1659. fireEvent(axis, 'afterBreaks');
  1660. if (axis.staticScale) {
  1661. axis.transA = axis.staticScale;
  1662. } else if (axis.unitLength) {
  1663. axis.transA *= (max - axis.min + pointRangePadding) /
  1664. axis.unitLength;
  1665. }
  1666. if (pointRangePadding) {
  1667. axis.minPixelPadding = axis.transA * axis.minPointOffset;
  1668. }
  1669. axis.min = min;
  1670. axis.max = max;
  1671. }
  1672. };
  1673. }
  1674. if (pick(redraw, true)) {
  1675. this.chart.redraw();
  1676. }
  1677. };
  1678. addEvent(Series, 'afterGeneratePoints', function () {
  1679. var series = this,
  1680. xAxis = series.xAxis,
  1681. yAxis = series.yAxis,
  1682. points = series.points,
  1683. point,
  1684. i = points.length,
  1685. connectNulls = series.options.connectNulls,
  1686. nullGap;
  1687. if (xAxis && yAxis && (xAxis.options.breaks || yAxis.options.breaks)) {
  1688. while (i--) {
  1689. point = points[i];
  1690. // Respect nulls inside the break (#4275)
  1691. nullGap = point.y === null && connectNulls === false;
  1692. if (
  1693. !nullGap &&
  1694. (
  1695. xAxis.isInAnyBreak(point.x, true) ||
  1696. yAxis.isInAnyBreak(point.y, true)
  1697. )
  1698. ) {
  1699. points.splice(i, 1);
  1700. if (this.data[i]) {
  1701. // Removes the graphics for this point if they exist
  1702. this.data[i].destroyElements();
  1703. }
  1704. }
  1705. }
  1706. }
  1707. });
  1708. addEvent(Series, 'afterRender', function drawPointsWrapped() {
  1709. this.drawBreaks(this.xAxis, ['x']);
  1710. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  1711. });
  1712. H.Series.prototype.drawBreaks = function (axis, keys) {
  1713. var series = this,
  1714. points = series.points,
  1715. breaks,
  1716. threshold,
  1717. eventName,
  1718. y;
  1719. if (!axis) {
  1720. return; // #5950
  1721. }
  1722. keys.forEach(function (key) {
  1723. breaks = axis.breakArray || [];
  1724. threshold = axis.isXAxis ?
  1725. axis.min :
  1726. pick(series.options.threshold, axis.min);
  1727. points.forEach(function (point) {
  1728. y = pick(point['stack' + key.toUpperCase()], point[key]);
  1729. breaks.forEach(function (brk) {
  1730. eventName = false;
  1731. if (
  1732. (threshold < brk.from && y > brk.to) ||
  1733. (threshold > brk.from && y < brk.from)
  1734. ) {
  1735. eventName = 'pointBreak';
  1736. } else if (
  1737. (threshold < brk.from && y > brk.from && y < brk.to) ||
  1738. (threshold > brk.from && y > brk.to && y < brk.from)
  1739. ) {
  1740. eventName = 'pointInBreak';
  1741. }
  1742. if (eventName) {
  1743. fireEvent(axis, eventName, { point: point, brk: brk });
  1744. }
  1745. });
  1746. });
  1747. });
  1748. };
  1749. /**
  1750. * Extend getGraphPath by identifying gaps in the data so that we can draw a gap
  1751. * in the line or area. This was moved from ordinal axis module to broken axis
  1752. * module as of #5045.
  1753. *
  1754. * @private
  1755. * @function Highcharts.Series#gappedPath
  1756. */
  1757. H.Series.prototype.gappedPath = function () {
  1758. var currentDataGrouping = this.currentDataGrouping,
  1759. groupingSize = currentDataGrouping && currentDataGrouping.totalRange,
  1760. gapSize = this.options.gapSize,
  1761. points = this.points.slice(),
  1762. i = points.length - 1,
  1763. yAxis = this.yAxis,
  1764. xRange,
  1765. stack;
  1766. /**
  1767. * Defines when to display a gap in the graph, together with the
  1768. * [gapUnit](plotOptions.series.gapUnit) option.
  1769. *
  1770. * In case when `dataGrouping` is enabled, points can be grouped into a
  1771. * larger time span. This can make the grouped points to have a greater
  1772. * distance than the absolute value of `gapSize` property, which will result
  1773. * in disappearing graph completely. To prevent this situation the mentioned
  1774. * distance between grouped points is used instead of previously defined
  1775. * `gapSize`.
  1776. *
  1777. * In practice, this option is most often used to visualize gaps in
  1778. * time series. In a stock chart, intraday data is available for daytime
  1779. * hours, while gaps will appear in nights and weekends.
  1780. *
  1781. * @see [gapUnit](plotOptions.series.gapUnit)
  1782. * @see [xAxis.breaks](#xAxis.breaks)
  1783. *
  1784. * @sample {highstock} stock/plotoptions/series-gapsize/
  1785. * Setting the gap size to 2 introduces gaps for weekends in daily
  1786. * datasets.
  1787. *
  1788. * @type {number}
  1789. * @default 0
  1790. * @product highstock
  1791. * @apioption plotOptions.series.gapSize
  1792. */
  1793. /**
  1794. * Together with [gapSize](plotOptions.series.gapSize), this option defines
  1795. * where to draw gaps in the graph.
  1796. *
  1797. * When the `gapUnit` is `relative` (default), a gap size of 5 means
  1798. * that if the distance between two points is greater than five times
  1799. * that of the two closest points, the graph will be broken.
  1800. *
  1801. * When the `gapUnit` is `value`, the gap is based on absolute axis values,
  1802. * which on a datetime axis is milliseconds. This also applies to the
  1803. * navigator series that inherits gap options from the base series.
  1804. *
  1805. * @see [gapSize](plotOptions.series.gapSize)
  1806. *
  1807. * @type {string}
  1808. * @default relative
  1809. * @since 5.0.13
  1810. * @product highstock
  1811. * @validvalue ["relative", "value"]
  1812. * @apioption plotOptions.series.gapUnit
  1813. */
  1814. if (gapSize && i > 0) { // #5008
  1815. // Gap unit is relative
  1816. if (this.options.gapUnit !== 'value') {
  1817. gapSize *= this.closestPointRange;
  1818. }
  1819. // Setting a new gapSize in case dataGrouping is enabled (#7686)
  1820. if (groupingSize && groupingSize > gapSize) {
  1821. gapSize = groupingSize;
  1822. }
  1823. // extension for ordinal breaks
  1824. while (i--) {
  1825. if (points[i + 1].x - points[i].x > gapSize) {
  1826. xRange = (points[i].x + points[i + 1].x) / 2;
  1827. points.splice( // insert after this one
  1828. i + 1,
  1829. 0,
  1830. {
  1831. isNull: true,
  1832. x: xRange
  1833. }
  1834. );
  1835. // For stacked chart generate empty stack items, #6546
  1836. if (this.options.stacking) {
  1837. stack = yAxis.stacks[this.stackKey][xRange] =
  1838. new H.StackItem(
  1839. yAxis,
  1840. yAxis.options.stackLabels,
  1841. false,
  1842. xRange,
  1843. this.stack
  1844. );
  1845. stack.total = 0;
  1846. }
  1847. }
  1848. }
  1849. }
  1850. // Call base method
  1851. return this.getGraphPath(points);
  1852. };
  1853. }(Highcharts));
  1854. (function (H, Tree, mixinTreeSeries) {
  1855. /* *
  1856. * (c) 2016 Highsoft AS
  1857. * Authors: Jon Arild Nygard
  1858. *
  1859. * License: www.highcharts.com/license
  1860. */
  1861. /* eslint no-console: 0 */
  1862. var argsToArray = function (args) {
  1863. return Array.prototype.slice.call(args, 1);
  1864. },
  1865. defined = H.defined,
  1866. extend = H.extend,
  1867. find = H.find,
  1868. fireEvent = H.fireEvent,
  1869. getLevelOptions = mixinTreeSeries.getLevelOptions,
  1870. merge = H.merge,
  1871. isBoolean = function (x) {
  1872. return typeof x === 'boolean';
  1873. },
  1874. isNumber = H.isNumber,
  1875. isObject = function (x) {
  1876. // Always use strict mode.
  1877. return H.isObject(x, true);
  1878. },
  1879. isString = H.isString,
  1880. pick = H.pick,
  1881. wrap = H.wrap,
  1882. GridAxis = H.Axis,
  1883. GridAxisTick = H.Tick;
  1884. var override = function (obj, methods) {
  1885. var method,
  1886. func;
  1887. for (method in methods) {
  1888. if (methods.hasOwnProperty(method)) {
  1889. func = methods[method];
  1890. wrap(obj, method, func);
  1891. }
  1892. }
  1893. };
  1894. var getBreakFromNode = function (node, max) {
  1895. var from = node.collapseStart,
  1896. to = node.collapseEnd;
  1897. // In broken-axis, the axis.max is minimized until it is not within a break.
  1898. // Therefore, if break.to is larger than axis.max, the axis.to should not
  1899. // add the 0.5 axis.tickMarkOffset, to avoid adding a break larger than
  1900. // axis.max
  1901. // TODO consider simplifying broken-axis and this might solve itself
  1902. if (to >= max) {
  1903. from -= 0.5;
  1904. }
  1905. return {
  1906. from: from,
  1907. to: to,
  1908. showPoints: false
  1909. };
  1910. };
  1911. /**
  1912. * Creates a list of positions for the ticks on the axis. Filters out positions
  1913. * that are outside min and max, or is inside an axis break.
  1914. *
  1915. * @private
  1916. * @function getTickPositions
  1917. *
  1918. * @param {Highcharts.Axis} axis
  1919. * The Axis to get the tick positions from.
  1920. *
  1921. * @return {Array<number>}
  1922. * List of positions.
  1923. */
  1924. var getTickPositions = function (axis) {
  1925. return Object.keys(axis.mapOfPosToGridNode).reduce(
  1926. function (arr, key) {
  1927. var pos = +key;
  1928. if (
  1929. axis.min <= pos &&
  1930. axis.max >= pos &&
  1931. !axis.isInAnyBreak(pos)
  1932. ) {
  1933. arr.push(pos);
  1934. }
  1935. return arr;
  1936. },
  1937. []
  1938. );
  1939. };
  1940. /**
  1941. * Check if a node is collapsed.
  1942. *
  1943. * @private
  1944. * @function isCollapsed
  1945. *
  1946. * @param {Highcharts.Axis} axis
  1947. * The axis to check against.
  1948. *
  1949. * @param {object} node
  1950. * The node to check if is collapsed.
  1951. *
  1952. * @param {number} pos
  1953. * The tick position to collapse.
  1954. *
  1955. * @return {boolean}
  1956. * Returns true if collapsed, false if expanded.
  1957. */
  1958. var isCollapsed = function (axis, node) {
  1959. var breaks = (axis.options.breaks || []),
  1960. obj = getBreakFromNode(node, axis.max);
  1961. return breaks.some(function (b) {
  1962. return b.from === obj.from && b.to === obj.to;
  1963. });
  1964. };
  1965. /**
  1966. * Calculates the new axis breaks to collapse a node.
  1967. *
  1968. * @private
  1969. * @function collapse
  1970. *
  1971. * @param {Highcharts.Axis} axis
  1972. * The axis to check against.
  1973. *
  1974. * @param {object} node
  1975. * The node to collapse.
  1976. *
  1977. * @param {number} pos
  1978. * The tick position to collapse.
  1979. *
  1980. * @return {Array<object>}
  1981. * Returns an array of the new breaks for the axis.
  1982. */
  1983. var collapse = function (axis, node) {
  1984. var breaks = (axis.options.breaks || []),
  1985. obj = getBreakFromNode(node, axis.max);
  1986. breaks.push(obj);
  1987. return breaks;
  1988. };
  1989. /**
  1990. * Calculates the new axis breaks to expand a node.
  1991. *
  1992. * @private
  1993. * @function expand
  1994. *
  1995. * @param {Highcharts.Axis} axis
  1996. * The axis to check against.
  1997. *
  1998. * @param {object} node
  1999. * The node to expand.
  2000. *
  2001. * @param {number} pos
  2002. * The tick position to expand.
  2003. *
  2004. * @returns {Array<object>} Returns an array of the new breaks for the axis.
  2005. */
  2006. var expand = function (axis, node) {
  2007. var breaks = (axis.options.breaks || []),
  2008. obj = getBreakFromNode(node, axis.max);
  2009. // Remove the break from the axis breaks array.
  2010. return breaks.reduce(function (arr, b) {
  2011. if (b.to !== obj.to || b.from !== obj.from) {
  2012. arr.push(b);
  2013. }
  2014. return arr;
  2015. }, []);
  2016. };
  2017. /**
  2018. * Calculates the new axis breaks after toggling the collapse/expand state of a
  2019. * node. If it is collapsed it will be expanded, and if it is exapended it will
  2020. * be collapsed.
  2021. *
  2022. * @private
  2023. * @function toggleCollapse
  2024. *
  2025. * @param {Highcharts.Axis} axis
  2026. * The axis to check against.
  2027. *
  2028. * @param {object} node
  2029. * The node to toggle.
  2030. *
  2031. * @param {number} pos
  2032. * The tick position to toggle.
  2033. *
  2034. * @return {Array<object>}
  2035. * Returns an array of the new breaks for the axis.
  2036. */
  2037. var toggleCollapse = function (axis, node) {
  2038. return (
  2039. isCollapsed(axis, node) ?
  2040. expand(axis, node) :
  2041. collapse(axis, node)
  2042. );
  2043. };
  2044. var renderLabelIcon = function (tick, params) {
  2045. var icon = tick.labelIcon,
  2046. isNew = !icon,
  2047. renderer = params.renderer,
  2048. labelBox = params.xy,
  2049. options = params.options,
  2050. width = options.width,
  2051. height = options.height,
  2052. iconCenter = {
  2053. x: labelBox.x - (width / 2) - options.padding,
  2054. y: labelBox.y - (height / 2)
  2055. },
  2056. rotation = params.collapsed ? 90 : 180,
  2057. shouldRender = params.show && H.isNumber(iconCenter.y);
  2058. if (isNew) {
  2059. tick.labelIcon = icon = renderer.path(renderer.symbols[options.type](
  2060. options.x,
  2061. options.y,
  2062. width,
  2063. height
  2064. ))
  2065. .addClass('highcharts-label-icon')
  2066. .add(params.group);
  2067. }
  2068. // Set the new position, and show or hide
  2069. if (!shouldRender) {
  2070. icon.attr({ y: -9999 }); // #1338
  2071. }
  2072. // Presentational attributes
  2073. if (!renderer.styledMode) {
  2074. icon
  2075. .attr({
  2076. 'stroke-width': 1,
  2077. 'fill': pick(params.color, '#666666')
  2078. })
  2079. .css({
  2080. cursor: 'pointer',
  2081. stroke: options.lineColor,
  2082. strokeWidth: options.lineWidth
  2083. });
  2084. }
  2085. // Update the icon positions
  2086. icon[isNew ? 'attr' : 'animate']({
  2087. translateX: iconCenter.x,
  2088. translateY: iconCenter.y,
  2089. rotation: rotation
  2090. });
  2091. };
  2092. var onTickHover = function (label) {
  2093. label.addClass('highcharts-treegrid-node-active');
  2094. if (!label.renderer.styledMode) {
  2095. label.css({
  2096. textDecoration: 'underline'
  2097. });
  2098. }
  2099. };
  2100. var onTickHoverExit = function (label, options) {
  2101. var css = defined(options.style) ? options.style : {};
  2102. label.removeClass('highcharts-treegrid-node-active');
  2103. if (!label.renderer.styledMode) {
  2104. label.css({
  2105. textDecoration: css.textDecoration
  2106. });
  2107. }
  2108. };
  2109. /**
  2110. * Creates a tree structure of the data, and the treegrid. Calculates
  2111. * categories, and y-values of points based on the tree.
  2112. *
  2113. * @private
  2114. * @function getTreeGridFromData
  2115. *
  2116. * @param {Array<*>} data
  2117. * All the data points to display in the axis.
  2118. *
  2119. * @param {boolean} uniqueNames
  2120. * Wether or not the data node with the same name should share grid cell.
  2121. * If true they do share cell. False by default.
  2122. *
  2123. * @return {object}
  2124. * Returns an object containing categories, mapOfIdToNode,
  2125. * mapOfPosToGridNode, and tree.
  2126. *
  2127. * @todo There should be only one point per line.
  2128. * @todo It should be optional to have one category per point, or merge cells
  2129. * @todo Add unit-tests.
  2130. */
  2131. var getTreeGridFromData = function (data, uniqueNames, numberOfSeries) {
  2132. var categories = [],
  2133. collapsedNodes = [],
  2134. mapOfIdToNode = {},
  2135. mapOfPosToGridNode = {},
  2136. posIterator = -1,
  2137. uniqueNamesEnabled = isBoolean(uniqueNames) ? uniqueNames : false,
  2138. tree,
  2139. treeParams,
  2140. updateYValuesAndTickPos;
  2141. // Build the tree from the series data.
  2142. treeParams = {
  2143. // After the children has been created.
  2144. after: function (node) {
  2145. var gridNode = mapOfPosToGridNode[node.pos],
  2146. height = 0,
  2147. descendants = 0;
  2148. gridNode.children.forEach(function (child) {
  2149. descendants += child.descendants + 1;
  2150. height = Math.max(child.height + 1, height);
  2151. });
  2152. gridNode.descendants = descendants;
  2153. gridNode.height = height;
  2154. if (gridNode.collapsed) {
  2155. collapsedNodes.push(gridNode);
  2156. }
  2157. },
  2158. // Before the children has been created.
  2159. before: function (node) {
  2160. var data = isObject(node.data) ? node.data : {},
  2161. name = isString(data.name) ? data.name : '',
  2162. parentNode = mapOfIdToNode[node.parent],
  2163. parentGridNode = (
  2164. isObject(parentNode) ?
  2165. mapOfPosToGridNode[parentNode.pos] :
  2166. null
  2167. ),
  2168. hasSameName = function (x) {
  2169. return x.name === name;
  2170. },
  2171. gridNode,
  2172. pos;
  2173. // If not unique names, look for a sibling node with the same name.
  2174. if (
  2175. uniqueNamesEnabled &&
  2176. isObject(parentGridNode) &&
  2177. !!(gridNode = find(parentGridNode.children, hasSameName))
  2178. ) {
  2179. // If if there is a gridNode with the same name, reuse position.
  2180. pos = gridNode.pos;
  2181. // Add data node to list of nodes in the grid node.
  2182. gridNode.nodes.push(node);
  2183. } else {
  2184. // If it is a new grid node, increment position.
  2185. pos = posIterator++;
  2186. }
  2187. // Add new grid node to map.
  2188. if (!mapOfPosToGridNode[pos]) {
  2189. mapOfPosToGridNode[pos] = gridNode = {
  2190. depth: parentGridNode ? parentGridNode.depth + 1 : 0,
  2191. name: name,
  2192. nodes: [node],
  2193. children: [],
  2194. pos: pos
  2195. };
  2196. // If not root, then add name to categories.
  2197. if (pos !== -1) {
  2198. categories.push(name);
  2199. }
  2200. // Add name to list of children.
  2201. if (isObject(parentGridNode)) {
  2202. parentGridNode.children.push(gridNode);
  2203. }
  2204. }
  2205. // Add data node to map
  2206. if (isString(node.id)) {
  2207. mapOfIdToNode[node.id] = node;
  2208. }
  2209. // If one of the points are collapsed, then start the grid node in
  2210. // collapsed state.
  2211. if (data.collapsed === true) {
  2212. gridNode.collapsed = true;
  2213. }
  2214. // Assign pos to data node
  2215. node.pos = pos;
  2216. }
  2217. };
  2218. updateYValuesAndTickPos = function (map, numberOfSeries) {
  2219. var setValues = function (gridNode, start, result) {
  2220. var nodes = gridNode.nodes,
  2221. end = start + (start === -1 ? 0 : numberOfSeries - 1),
  2222. diff = (end - start) / 2,
  2223. padding = 0.5,
  2224. pos = start + diff;
  2225. nodes.forEach(function (node) {
  2226. var data = node.data;
  2227. if (isObject(data)) {
  2228. // Update point
  2229. data.y = start + data.seriesIndex;
  2230. // Remove the property once used
  2231. delete data.seriesIndex;
  2232. }
  2233. node.pos = pos;
  2234. });
  2235. result[pos] = gridNode;
  2236. gridNode.pos = pos;
  2237. gridNode.tickmarkOffset = diff + padding;
  2238. gridNode.collapseStart = end + padding;
  2239. gridNode.children.forEach(function (child) {
  2240. setValues(child, end + 1, result);
  2241. end = child.collapseEnd - padding;
  2242. });
  2243. // Set collapseEnd to the end of the last child node.
  2244. gridNode.collapseEnd = end + padding;
  2245. return result;
  2246. };
  2247. return setValues(map['-1'], -1, {});
  2248. };
  2249. // Create tree from data
  2250. tree = Tree.getTree(data, treeParams);
  2251. // Update y values of data, and set calculate tick positions.
  2252. mapOfPosToGridNode = updateYValuesAndTickPos(
  2253. mapOfPosToGridNode,
  2254. numberOfSeries
  2255. );
  2256. // Return the resulting data.
  2257. return {
  2258. categories: categories,
  2259. mapOfIdToNode: mapOfIdToNode,
  2260. mapOfPosToGridNode: mapOfPosToGridNode,
  2261. collapsedNodes: collapsedNodes,
  2262. tree: tree
  2263. };
  2264. };
  2265. H.addEvent(H.Chart, 'beforeRender', function () {
  2266. this.axes.forEach(function (axis) {
  2267. if (axis.userOptions.type === 'treegrid') {
  2268. var labelOptions = axis.options && axis.options.labels,
  2269. removeFoundExtremesEvent;
  2270. // beforeRender is fired after all the series is initialized,
  2271. // which is an ideal time to update the axis.categories.
  2272. axis.updateYNames();
  2273. // Update yData now that we have calculated the y values
  2274. // TODO: it would be better to be able to calculate y values
  2275. // before Series.setData
  2276. axis.series.forEach(function (series) {
  2277. series.yData = series.options.data.map(function (data) {
  2278. return data.y;
  2279. });
  2280. });
  2281. // Calculate the label options for each level in the tree.
  2282. axis.mapOptionsToLevel = getLevelOptions({
  2283. defaults: labelOptions,
  2284. from: 1,
  2285. levels: labelOptions.levels,
  2286. to: axis.tree.height
  2287. });
  2288. // Collapse all the nodes belonging to a point where collapsed
  2289. // equals true.
  2290. // Can be called from beforeRender, if getBreakFromNode removes
  2291. // its dependency on axis.max.
  2292. removeFoundExtremesEvent =
  2293. H.addEvent(axis, 'foundExtremes', function () {
  2294. axis.collapsedNodes.forEach(function (node) {
  2295. var breaks = collapse(axis, node);
  2296. axis.setBreaks(breaks, false);
  2297. });
  2298. removeFoundExtremesEvent();
  2299. });
  2300. }
  2301. });
  2302. });
  2303. override(GridAxis.prototype, {
  2304. init: function (proceed, chart, userOptions) {
  2305. var axis = this,
  2306. isTreeGrid = userOptions.type === 'treegrid';
  2307. // Set default and forced options for TreeGrid
  2308. if (isTreeGrid) {
  2309. userOptions = merge({
  2310. // Default options
  2311. grid: {
  2312. enabled: true
  2313. },
  2314. // TODO: add support for align in treegrid.
  2315. labels: {
  2316. align: 'left',
  2317. /**
  2318. * Set options on specific levels in a tree grid axis. Takes
  2319. * precedence over labels options.
  2320. *
  2321. * @sample {gantt} gantt/treegrid-axis/labels-levels
  2322. * Levels on TreeGrid Labels
  2323. *
  2324. * @type {Array<*>}
  2325. * @product gantt
  2326. * @apioption yAxis.labels.levels
  2327. */
  2328. levels: [{
  2329. /**
  2330. * Specify the level which the options within this object
  2331. * applies to.
  2332. *
  2333. * @sample {gantt} gantt/treegrid-axis/labels-levels
  2334. *
  2335. * @type {number}
  2336. * @product gantt
  2337. * @apioption yAxis.labels.levels.level
  2338. */
  2339. level: undefined
  2340. }, {
  2341. level: 1,
  2342. /**
  2343. * @type {Highcharts.CSSObject}
  2344. * @product gantt
  2345. * @apioption yAxis.labels.levels.style
  2346. */
  2347. style: {
  2348. /** @ignore-option */
  2349. fontWeight: 'bold'
  2350. }
  2351. }],
  2352. /**
  2353. * The symbol for the collapse and expand icon in a
  2354. * treegrid.
  2355. *
  2356. * @product gantt
  2357. * @optionparent yAxis.labels.symbol
  2358. */
  2359. symbol: {
  2360. /**
  2361. * The symbol type. Points to a definition function in
  2362. * the `Highcharts.Renderer.symbols` collection.
  2363. *
  2364. * @validvalue ["arc", "circle", "diamond", "square", "triangle", "triangle-down"]
  2365. */
  2366. type: 'triangle',
  2367. x: -5,
  2368. y: -5,
  2369. height: 10,
  2370. width: 10,
  2371. padding: 5
  2372. }
  2373. },
  2374. uniqueNames: false
  2375. }, userOptions, { // User options
  2376. // Forced options
  2377. reversed: true,
  2378. // grid.columns is not supported in treegrid
  2379. grid: {
  2380. columns: undefined
  2381. }
  2382. });
  2383. }
  2384. // Now apply the original function with the original arguments,
  2385. // which are sliced off this function's arguments
  2386. proceed.apply(axis, [chart, userOptions]);
  2387. if (isTreeGrid) {
  2388. axis.hasNames = true;
  2389. axis.options.showLastLabel = true;
  2390. }
  2391. },
  2392. /**
  2393. * Override to add indentation to axis.maxLabelDimensions.
  2394. *
  2395. * @private
  2396. * @function Highcharts.GridAxis#getMaxLabelDimensions
  2397. *
  2398. * @param {Function} proceed
  2399. * The original function
  2400. */
  2401. getMaxLabelDimensions: function (proceed) {
  2402. var axis = this,
  2403. options = axis.options,
  2404. labelOptions = options && options.labels,
  2405. indentation = (
  2406. labelOptions && isNumber(labelOptions.indentation) ?
  2407. options.labels.indentation :
  2408. 0
  2409. ),
  2410. retVal = proceed.apply(axis, argsToArray(arguments)),
  2411. isTreeGrid = axis.options.type === 'treegrid',
  2412. treeDepth;
  2413. if (isTreeGrid && this.mapOfPosToGridNode) {
  2414. treeDepth = axis.mapOfPosToGridNode[-1].height;
  2415. retVal.width += indentation * (treeDepth - 1);
  2416. }
  2417. return retVal;
  2418. },
  2419. /**
  2420. * Generates a tick for initial positioning.
  2421. *
  2422. * @private
  2423. * @function Highcharts.GridAxis#generateTick
  2424. *
  2425. * @param {Function} proceed
  2426. * The original generateTick function.
  2427. *
  2428. * @param {number} pos
  2429. * The tick position in axis values.
  2430. */
  2431. generateTick: function (proceed, pos) {
  2432. var axis = this,
  2433. mapOptionsToLevel = (
  2434. isObject(axis.mapOptionsToLevel) ? axis.mapOptionsToLevel : {}
  2435. ),
  2436. isTreeGrid = axis.options.type === 'treegrid',
  2437. ticks = axis.ticks,
  2438. tick = ticks[pos],
  2439. levelOptions,
  2440. options,
  2441. gridNode;
  2442. if (isTreeGrid) {
  2443. gridNode = axis.mapOfPosToGridNode[pos];
  2444. levelOptions = mapOptionsToLevel[gridNode.depth];
  2445. if (levelOptions) {
  2446. options = {
  2447. labels: levelOptions
  2448. };
  2449. }
  2450. if (!tick) {
  2451. ticks[pos] = tick =
  2452. new GridAxisTick(axis, pos, null, undefined, {
  2453. category: gridNode.name,
  2454. tickmarkOffset: gridNode.tickmarkOffset,
  2455. options: options
  2456. });
  2457. } else {
  2458. // update labels depending on tick interval
  2459. tick.parameters.category = gridNode.name;
  2460. tick.options = options;
  2461. tick.addLabel();
  2462. }
  2463. } else {
  2464. proceed.apply(axis, argsToArray(arguments));
  2465. }
  2466. },
  2467. /**
  2468. * Set the tick positions, tickInterval, axis min and max.
  2469. *
  2470. * @private
  2471. * @function Highcharts.GridAxis#setTickInterval
  2472. *
  2473. * @param {Function} proceed
  2474. * The original setTickInterval function.
  2475. */
  2476. setTickInterval: function (proceed) {
  2477. var axis = this,
  2478. options = axis.options,
  2479. isTreeGrid = options.type === 'treegrid';
  2480. if (isTreeGrid && this.mapOfPosToGridNode) {
  2481. axis.min = pick(axis.userMin, options.min, axis.dataMin);
  2482. axis.max = pick(axis.userMax, options.max, axis.dataMax);
  2483. fireEvent(axis, 'foundExtremes');
  2484. // setAxisTranslation modifies the min and max according to
  2485. // axis breaks.
  2486. axis.setAxisTranslation(true);
  2487. axis.tickmarkOffset = 0.5;
  2488. axis.tickInterval = 1;
  2489. axis.tickPositions = getTickPositions(axis);
  2490. } else {
  2491. proceed.apply(axis, argsToArray(arguments));
  2492. }
  2493. }
  2494. });
  2495. override(GridAxisTick.prototype, {
  2496. getLabelPosition: function (
  2497. proceed,
  2498. x,
  2499. y,
  2500. label,
  2501. horiz,
  2502. labelOptions,
  2503. tickmarkOffset,
  2504. index,
  2505. step
  2506. ) {
  2507. var tick = this,
  2508. lbOptions = pick(
  2509. tick.options && tick.options.labels,
  2510. labelOptions
  2511. ),
  2512. pos = tick.pos,
  2513. axis = tick.axis,
  2514. options = axis.options,
  2515. isTreeGrid = options.type === 'treegrid',
  2516. result = proceed.apply(
  2517. tick,
  2518. [x, y, label, horiz, lbOptions, tickmarkOffset, index, step]
  2519. ),
  2520. symbolOptions,
  2521. indentation,
  2522. mapOfPosToGridNode,
  2523. node,
  2524. level;
  2525. if (isTreeGrid) {
  2526. symbolOptions = (
  2527. lbOptions && isObject(lbOptions.symbol) ?
  2528. lbOptions.symbol :
  2529. {}
  2530. );
  2531. indentation = (
  2532. lbOptions && isNumber(lbOptions.indentation) ?
  2533. lbOptions.indentation :
  2534. 0
  2535. );
  2536. mapOfPosToGridNode = axis.mapOfPosToGridNode;
  2537. node = mapOfPosToGridNode && mapOfPosToGridNode[pos];
  2538. level = (node && node.depth) || 1;
  2539. result.x += (
  2540. // Add space for symbols
  2541. ((symbolOptions.width) + (symbolOptions.padding * 2)) +
  2542. // Apply indentation
  2543. ((level - 1) * indentation)
  2544. );
  2545. }
  2546. return result;
  2547. },
  2548. renderLabel: function (proceed) {
  2549. var tick = this,
  2550. pos = tick.pos,
  2551. axis = tick.axis,
  2552. label = tick.label,
  2553. mapOfPosToGridNode = axis.mapOfPosToGridNode,
  2554. options = axis.options,
  2555. labelOptions = pick(
  2556. tick.options && tick.options.labels,
  2557. options && options.labels
  2558. ),
  2559. symbolOptions = (
  2560. labelOptions && isObject(labelOptions.symbol) ?
  2561. labelOptions.symbol :
  2562. {}
  2563. ),
  2564. node = mapOfPosToGridNode && mapOfPosToGridNode[pos],
  2565. level = node && node.depth,
  2566. isTreeGrid = options.type === 'treegrid',
  2567. hasLabel = !!(label && label.element),
  2568. shouldRender = axis.tickPositions.indexOf(pos) > -1,
  2569. prefixClassName = 'highcharts-treegrid-node-',
  2570. collapsed,
  2571. addClassName,
  2572. removeClassName,
  2573. styledMode = axis.chart.styledMode;
  2574. if (isTreeGrid && node) {
  2575. // Add class name for hierarchical styling.
  2576. if (hasLabel) {
  2577. label.addClass(prefixClassName + 'level-' + level);
  2578. }
  2579. }
  2580. proceed.apply(tick, argsToArray(arguments));
  2581. if (isTreeGrid && node && hasLabel && node.descendants > 0) {
  2582. collapsed = isCollapsed(axis, node);
  2583. renderLabelIcon(
  2584. tick,
  2585. {
  2586. color: !styledMode && label.styles.color,
  2587. collapsed: collapsed,
  2588. group: label.parentGroup,
  2589. options: symbolOptions,
  2590. renderer: label.renderer,
  2591. show: shouldRender,
  2592. xy: label.xy
  2593. }
  2594. );
  2595. // Add class name for the node.
  2596. addClassName = prefixClassName +
  2597. (collapsed ? 'collapsed' : 'expanded');
  2598. removeClassName = prefixClassName +
  2599. (collapsed ? 'expanded' : 'collapsed');
  2600. label
  2601. .addClass(addClassName)
  2602. .removeClass(removeClassName);
  2603. if (!styledMode) {
  2604. label.css({
  2605. cursor: 'pointer'
  2606. });
  2607. }
  2608. // Add events to both label text and icon
  2609. [label, tick.labelIcon].forEach(function (object) {
  2610. if (!object.attachedTreeGridEvents) {
  2611. // On hover
  2612. H.addEvent(object.element, 'mouseover', function () {
  2613. onTickHover(label);
  2614. });
  2615. // On hover out
  2616. H.addEvent(object.element, 'mouseout', function () {
  2617. onTickHoverExit(label, labelOptions);
  2618. });
  2619. H.addEvent(object.element, 'click', function () {
  2620. tick.toggleCollapse();
  2621. });
  2622. object.attachedTreeGridEvents = true;
  2623. }
  2624. });
  2625. }
  2626. }
  2627. });
  2628. extend(GridAxisTick.prototype, /** @lends Highcharts.Tick.prototype */{
  2629. /**
  2630. * Collapse the grid cell. Used when axis is of type treegrid.
  2631. *
  2632. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  2633. *
  2634. * @private
  2635. * @function Highcharts.GridAxisTick#collapse
  2636. *
  2637. * @param {boolean} [redraw=true]
  2638. * Whether to redraw the chart or wait for an explicit call to
  2639. * {@link Highcharts.Chart#redraw}
  2640. */
  2641. collapse: function (redraw) {
  2642. var tick = this,
  2643. axis = tick.axis,
  2644. pos = tick.pos,
  2645. node = axis.mapOfPosToGridNode[pos],
  2646. breaks = collapse(axis, node);
  2647. axis.setBreaks(breaks, pick(redraw, true));
  2648. },
  2649. /**
  2650. * Expand the grid cell. Used when axis is of type treegrid.
  2651. *
  2652. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  2653. *
  2654. * @private
  2655. * @function Highcharts.GridAxisTick#expand
  2656. *
  2657. * @param {boolean} [redraw=true]
  2658. * Whether to redraw the chart or wait for an explicit call to
  2659. * {@link Highcharts.Chart#redraw}
  2660. */
  2661. expand: function (redraw) {
  2662. var tick = this,
  2663. axis = tick.axis,
  2664. pos = tick.pos,
  2665. node = axis.mapOfPosToGridNode[pos],
  2666. breaks = expand(axis, node);
  2667. axis.setBreaks(breaks, pick(redraw, true));
  2668. },
  2669. /**
  2670. * Toggle the collapse/expand state of the grid cell. Used when axis is of
  2671. * type treegrid.
  2672. *
  2673. * @see gantt/treegrid-axis/collapsed-dynamically/demo.js
  2674. *
  2675. * @private
  2676. * @function Highcharts.GridAxisTick#toggleCollapse
  2677. *
  2678. * @param {boolean} [redraw=true]
  2679. * Whether to redraw the chart or wait for an explicit call to
  2680. * {@link Highcharts.Chart#redraw}
  2681. */
  2682. toggleCollapse: function (redraw) {
  2683. var tick = this,
  2684. axis = tick.axis,
  2685. pos = tick.pos,
  2686. node = axis.mapOfPosToGridNode[pos],
  2687. breaks = toggleCollapse(axis, node);
  2688. axis.setBreaks(breaks, pick(redraw, true));
  2689. }
  2690. });
  2691. GridAxis.prototype.updateYNames = function () {
  2692. var axis = this,
  2693. options = axis.options,
  2694. isTreeGrid = options.type === 'treegrid',
  2695. uniqueNames = options.uniqueNames,
  2696. isYAxis = !axis.isXAxis,
  2697. series = axis.series,
  2698. numberOfSeries = 0,
  2699. treeGrid,
  2700. data;
  2701. if (isTreeGrid && isYAxis) {
  2702. // Concatenate data from all series assigned to this axis.
  2703. data = series.reduce(function (arr, s) {
  2704. if (s.visible) {
  2705. // Push all data to array
  2706. s.options.data.forEach(function (data) {
  2707. if (isObject(data)) {
  2708. // Set series index on data. Removed again after use.
  2709. data.seriesIndex = numberOfSeries;
  2710. arr.push(data);
  2711. }
  2712. });
  2713. // Increment series index
  2714. if (uniqueNames === true) {
  2715. numberOfSeries++;
  2716. }
  2717. }
  2718. return arr;
  2719. }, []);
  2720. // Calculate categories and the hierarchy for the grid.
  2721. treeGrid = getTreeGridFromData(
  2722. data,
  2723. uniqueNames,
  2724. (uniqueNames === true) ? numberOfSeries : 1
  2725. );
  2726. // Assign values to the axis.
  2727. axis.categories = treeGrid.categories;
  2728. axis.mapOfPosToGridNode = treeGrid.mapOfPosToGridNode;
  2729. // Used on init to start a node as collapsed
  2730. axis.collapsedNodes = treeGrid.collapsedNodes;
  2731. axis.hasNames = true;
  2732. axis.tree = treeGrid.tree;
  2733. }
  2734. };
  2735. // Make utility functions available for testing.
  2736. GridAxis.prototype.utils = {
  2737. getNode: Tree.getNode
  2738. };
  2739. }(Highcharts, Tree, result));
  2740. var algorithms = (function (H) {
  2741. /* *
  2742. * (c) 2016 Highsoft AS
  2743. * Author: Øystein Moseng
  2744. *
  2745. * License: www.highcharts.com/license
  2746. */
  2747. var min = Math.min,
  2748. max = Math.max,
  2749. abs = Math.abs,
  2750. pick = H.pick;
  2751. /**
  2752. * Get index of last obstacle before xMin. Employs a type of binary search, and
  2753. * thus requires that obstacles are sorted by xMin value.
  2754. *
  2755. * @private
  2756. * @function findLastObstacleBefore
  2757. *
  2758. * @param {Array<object>} obstacles
  2759. * Array of obstacles to search in.
  2760. *
  2761. * @param {number} xMin
  2762. * The xMin threshold.
  2763. *
  2764. * @param {number} startIx
  2765. * Starting index to search from. Must be within array range.
  2766. *
  2767. * @return {number}
  2768. * The index of the last obstacle element before xMin.
  2769. */
  2770. function findLastObstacleBefore(obstacles, xMin, startIx) {
  2771. var left = startIx || 0, // left limit
  2772. right = obstacles.length - 1, // right limit
  2773. min = xMin - 0.0000001, // Make sure we include all obstacles at xMin
  2774. cursor,
  2775. cmp;
  2776. while (left <= right) {
  2777. cursor = (right + left) >> 1;
  2778. cmp = min - obstacles[cursor].xMin;
  2779. if (cmp > 0) {
  2780. left = cursor + 1;
  2781. } else if (cmp < 0) {
  2782. right = cursor - 1;
  2783. } else {
  2784. return cursor;
  2785. }
  2786. }
  2787. return left > 0 ? left - 1 : 0;
  2788. }
  2789. /**
  2790. * Test if a point lays within an obstacle.
  2791. *
  2792. * @private
  2793. * @function pointWithinObstacle
  2794. *
  2795. * @param {object} obstacle
  2796. * Obstacle to test.
  2797. *
  2798. * @param {Highcharts.Point} point
  2799. * Point with x/y props.
  2800. *
  2801. * @return {boolean}
  2802. * Whether point is within the obstacle or not.
  2803. */
  2804. function pointWithinObstacle(obstacle, point) {
  2805. return (
  2806. point.x <= obstacle.xMax &&
  2807. point.x >= obstacle.xMin &&
  2808. point.y <= obstacle.yMax &&
  2809. point.y >= obstacle.yMin
  2810. );
  2811. }
  2812. /**
  2813. * Find the index of an obstacle that wraps around a point.
  2814. * Returns -1 if not found.
  2815. *
  2816. * @private
  2817. * @function findObstacleFromPoint
  2818. *
  2819. * @param {Array<object>} obstacles
  2820. * Obstacles to test.
  2821. *
  2822. * @param {Highcharts.Point} point
  2823. * Point with x/y props.
  2824. *
  2825. * @return {number}
  2826. * Ix of the obstacle in the array, or -1 if not found.
  2827. */
  2828. function findObstacleFromPoint(obstacles, point) {
  2829. var i = findLastObstacleBefore(obstacles, point.x + 1) + 1;
  2830. while (i--) {
  2831. if (obstacles[i].xMax >= point.x &&
  2832. // optimization using lazy evaluation
  2833. pointWithinObstacle(obstacles[i], point)) {
  2834. return i;
  2835. }
  2836. }
  2837. return -1;
  2838. }
  2839. /**
  2840. * Get SVG path array from array of line segments.
  2841. *
  2842. * @private
  2843. * @function pathFromSegments
  2844. *
  2845. * @param {Array<object>} segments
  2846. * The segments to build the path from.
  2847. *
  2848. * @return {Highcharts.SVGPathArray}
  2849. * SVG path array as accepted by the SVG Renderer.
  2850. */
  2851. function pathFromSegments(segments) {
  2852. var path = [];
  2853. if (segments.length) {
  2854. path.push('M', segments[0].start.x, segments[0].start.y);
  2855. for (var i = 0; i < segments.length; ++i) {
  2856. path.push('L', segments[i].end.x, segments[i].end.y);
  2857. }
  2858. }
  2859. return path;
  2860. }
  2861. /**
  2862. * Limits obstacle max/mins in all directions to bounds. Modifies input
  2863. * obstacle.
  2864. *
  2865. * @private
  2866. * @function limitObstacleToBounds
  2867. *
  2868. * @param {object} obstacle
  2869. * Obstacle to limit.
  2870. *
  2871. * @param {object} bounds
  2872. * Bounds to use as limit.
  2873. */
  2874. function limitObstacleToBounds(obstacle, bounds) {
  2875. obstacle.yMin = max(obstacle.yMin, bounds.yMin);
  2876. obstacle.yMax = min(obstacle.yMax, bounds.yMax);
  2877. obstacle.xMin = max(obstacle.xMin, bounds.xMin);
  2878. obstacle.xMax = min(obstacle.xMax, bounds.xMax);
  2879. }
  2880. // Define the available pathfinding algorithms.
  2881. // Algorithms take up to 3 arguments: starting point, ending point, and an
  2882. // options object.
  2883. var algorithms = {
  2884. /**
  2885. * Get an SVG path from a starting coordinate to an ending coordinate.
  2886. * Draws a straight line.
  2887. *
  2888. * @function Highcharts.Pathfinder.algorithms.straight
  2889. *
  2890. * @param {object} start
  2891. * Starting coordinate, object with x/y props.
  2892. *
  2893. * @param {object} end
  2894. * Ending coordinate, object with x/y props.
  2895. *
  2896. * @return {object}
  2897. * An object with the SVG path in Array form as accepted by the SVG
  2898. * renderer, as well as an array of new obstacles making up this
  2899. * path.
  2900. */
  2901. straight: function (start, end) {
  2902. return {
  2903. path: ['M', start.x, start.y, 'L', end.x, end.y],
  2904. obstacles: [{ start: start, end: end }]
  2905. };
  2906. },
  2907. /**
  2908. * Find a path from a starting coordinate to an ending coordinate, using
  2909. * right angles only, and taking only starting/ending obstacle into
  2910. * consideration.
  2911. *
  2912. * @function Highcharts.Pathfinder.algorithms.simpleConnect
  2913. *
  2914. * @param {object} start
  2915. * Starting coordinate, object with x/y props.
  2916. *
  2917. * @param {object} end
  2918. * Ending coordinate, object with x/y props.
  2919. *
  2920. * @param {object} options
  2921. * Options for the algorithm:
  2922. * - chartObstacles: Array of chart obstacles to avoid
  2923. * - startDirectionX: Optional. True if starting in the X direction.
  2924. * If not provided, the algorithm starts in the direction that is
  2925. * the furthest between start/end.
  2926. *
  2927. * @return {object}
  2928. * An object with the SVG path in Array form as accepted by the SVG
  2929. * renderer, as well as an array of new obstacles making up this
  2930. * path.
  2931. */
  2932. simpleConnect: H.extend(function (start, end, options) {
  2933. var segments = [],
  2934. endSegment,
  2935. dir = pick(
  2936. options.startDirectionX,
  2937. abs(end.x - start.x) > abs(end.y - start.y)
  2938. ) ? 'x' : 'y',
  2939. chartObstacles = options.chartObstacles,
  2940. startObstacleIx = findObstacleFromPoint(chartObstacles, start),
  2941. endObstacleIx = findObstacleFromPoint(chartObstacles, end),
  2942. startObstacle,
  2943. endObstacle,
  2944. prevWaypoint,
  2945. waypoint,
  2946. waypoint2,
  2947. useMax,
  2948. endPoint;
  2949. // Return a clone of a point with a property set from a target object,
  2950. // optionally with an offset
  2951. function copyFromPoint(from, fromKey, to, toKey, offset) {
  2952. var point = {
  2953. x: from.x,
  2954. y: from.y
  2955. };
  2956. point[fromKey] = to[toKey || fromKey] + (offset || 0);
  2957. return point;
  2958. }
  2959. // Return waypoint outside obstacle
  2960. function getMeOut(obstacle, point, direction) {
  2961. var useMax = abs(point[direction] - obstacle[direction + 'Min']) >
  2962. abs(point[direction] - obstacle[direction + 'Max']);
  2963. return copyFromPoint(
  2964. point,
  2965. direction,
  2966. obstacle,
  2967. direction + (useMax ? 'Max' : 'Min'),
  2968. useMax ? 1 : -1
  2969. );
  2970. }
  2971. // Pull out end point
  2972. if (endObstacleIx > -1) {
  2973. endObstacle = chartObstacles[endObstacleIx];
  2974. waypoint = getMeOut(endObstacle, end, dir);
  2975. endSegment = {
  2976. start: waypoint,
  2977. end: end
  2978. };
  2979. endPoint = waypoint;
  2980. } else {
  2981. endPoint = end;
  2982. }
  2983. // If an obstacle envelops the start point, add a segment to get out,
  2984. // and around it.
  2985. if (startObstacleIx > -1) {
  2986. startObstacle = chartObstacles[startObstacleIx];
  2987. waypoint = getMeOut(startObstacle, start, dir);
  2988. segments.push({
  2989. start: start,
  2990. end: waypoint
  2991. });
  2992. // If we are going back again, switch direction to get around start
  2993. // obstacle.
  2994. if (
  2995. waypoint[dir] > start[dir] === // Going towards max from start
  2996. waypoint[dir] > endPoint[dir] // Going towards min to end
  2997. ) {
  2998. dir = dir === 'y' ? 'x' : 'y';
  2999. useMax = start[dir] < end[dir];
  3000. segments.push({
  3001. start: waypoint,
  3002. end: copyFromPoint(
  3003. waypoint,
  3004. dir,
  3005. startObstacle,
  3006. dir + (useMax ? 'Max' : 'Min'),
  3007. useMax ? 1 : -1
  3008. )
  3009. });
  3010. // Switch direction again
  3011. dir = dir === 'y' ? 'x' : 'y';
  3012. }
  3013. }
  3014. // We are around the start obstacle. Go towards the end in one
  3015. // direction.
  3016. prevWaypoint = segments.length ?
  3017. segments[segments.length - 1].end :
  3018. start;
  3019. waypoint = copyFromPoint(prevWaypoint, dir, endPoint);
  3020. segments.push({
  3021. start: prevWaypoint,
  3022. end: waypoint
  3023. });
  3024. // Final run to end point in the other direction
  3025. dir = dir === 'y' ? 'x' : 'y';
  3026. waypoint2 = copyFromPoint(waypoint, dir, endPoint);
  3027. segments.push({
  3028. start: waypoint,
  3029. end: waypoint2
  3030. });
  3031. // Finally add the endSegment
  3032. segments.push(endSegment);
  3033. return {
  3034. path: pathFromSegments(segments),
  3035. obstacles: segments
  3036. };
  3037. }, {
  3038. requiresObstacles: true
  3039. }),
  3040. /**
  3041. * Find a path from a starting coordinate to an ending coordinate, taking
  3042. * obstacles into consideration. Might not always find the optimal path,
  3043. * but is fast, and usually good enough.
  3044. *
  3045. * @function Highcharts.Pathfinder.algorithms.fastAvoid
  3046. *
  3047. * @param {object} start
  3048. * Starting coordinate, object with x/y props.
  3049. *
  3050. * @param {object} end
  3051. * Ending coordinate, object with x/y props.
  3052. *
  3053. * @param {object} options
  3054. * Options for the algorithm.
  3055. * - chartObstacles: Array of chart obstacles to avoid
  3056. * - lineObstacles: Array of line obstacles to jump over
  3057. * - obstacleMetrics: Object with metrics of chartObstacles cached
  3058. * - hardBounds: Hard boundaries to not cross
  3059. * - obstacleOptions: Options for the obstacles, including margin
  3060. * - startDirectionX: Optional. True if starting in the X direction.
  3061. * If not provided, the algorithm starts in the
  3062. * direction that is the furthest between
  3063. * start/end.
  3064. *
  3065. * @return {object}
  3066. * An object with the SVG path in Array form as accepted by the SVG
  3067. * renderer, as well as an array of new obstacles making up this
  3068. * path.
  3069. */
  3070. fastAvoid: H.extend(function (start, end, options) {
  3071. /*
  3072. Algorithm rules/description
  3073. - Find initial direction
  3074. - Determine soft/hard max for each direction.
  3075. - Move along initial direction until obstacle.
  3076. - Change direction.
  3077. - If hitting obstacle, first try to change length of previous line
  3078. before changing direction again.
  3079. Soft min/max x = start/destination x +/- widest obstacle + margin
  3080. Soft min/max y = start/destination y +/- tallest obstacle + margin
  3081. @todo:
  3082. - Make retrospective, try changing prev segment to reduce
  3083. corners
  3084. - Fix logic for breaking out of end-points - not always picking
  3085. the best direction currently
  3086. - When going around the end obstacle we should not always go the
  3087. shortest route, rather pick the one closer to the end point
  3088. */
  3089. var dirIsX = pick(
  3090. options.startDirectionX,
  3091. abs(end.x - start.x) > abs(end.y - start.y)
  3092. ),
  3093. dir = dirIsX ? 'x' : 'y',
  3094. segments,
  3095. useMax,
  3096. extractedEndPoint,
  3097. endSegments = [],
  3098. forceObstacleBreak = false, // Used in clearPathTo to keep track of
  3099. // when to force break through an obstacle.
  3100. // Boundaries to stay within. If beyond soft boundary, prefer to
  3101. // change direction ASAP. If at hard max, always change immediately.
  3102. metrics = options.obstacleMetrics,
  3103. softMinX = min(start.x, end.x) - metrics.maxWidth - 10,
  3104. softMaxX = max(start.x, end.x) + metrics.maxWidth + 10,
  3105. softMinY = min(start.y, end.y) - metrics.maxHeight - 10,
  3106. softMaxY = max(start.y, end.y) + metrics.maxHeight + 10,
  3107. // Obstacles
  3108. chartObstacles = options.chartObstacles,
  3109. startObstacleIx = findLastObstacleBefore(chartObstacles, softMinX),
  3110. endObstacleIx = findLastObstacleBefore(chartObstacles, softMaxX);
  3111. // How far can you go between two points before hitting an obstacle?
  3112. // Does not work for diagonal lines (because it doesn't have to).
  3113. function pivotPoint(fromPoint, toPoint, directionIsX) {
  3114. var firstPoint,
  3115. lastPoint,
  3116. highestPoint,
  3117. lowestPoint,
  3118. i,
  3119. searchDirection = fromPoint.x < toPoint.x ? 1 : -1;
  3120. if (fromPoint.x < toPoint.x) {
  3121. firstPoint = fromPoint;
  3122. lastPoint = toPoint;
  3123. } else {
  3124. firstPoint = toPoint;
  3125. lastPoint = fromPoint;
  3126. }
  3127. if (fromPoint.y < toPoint.y) {
  3128. lowestPoint = fromPoint;
  3129. highestPoint = toPoint;
  3130. } else {
  3131. lowestPoint = toPoint;
  3132. highestPoint = fromPoint;
  3133. }
  3134. // Go through obstacle range in reverse if toPoint is before
  3135. // fromPoint in the X-dimension.
  3136. i = searchDirection < 0 ?
  3137. // Searching backwards, start at last obstacle before last point
  3138. min(findLastObstacleBefore(chartObstacles, lastPoint.x),
  3139. chartObstacles.length - 1) :
  3140. // Forwards. Since we're not sorted by xMax, we have to look
  3141. // at all obstacles.
  3142. 0;
  3143. // Go through obstacles in this X range
  3144. while (chartObstacles[i] && (
  3145. searchDirection > 0 && chartObstacles[i].xMin <= lastPoint.x ||
  3146. searchDirection < 0 && chartObstacles[i].xMax >= firstPoint.x
  3147. )) {
  3148. // If this obstacle is between from and to points in a straight
  3149. // line, pivot at the intersection.
  3150. if (
  3151. chartObstacles[i].xMin <= lastPoint.x &&
  3152. chartObstacles[i].xMax >= firstPoint.x &&
  3153. chartObstacles[i].yMin <= highestPoint.y &&
  3154. chartObstacles[i].yMax >= lowestPoint.y
  3155. ) {
  3156. if (directionIsX) {
  3157. return {
  3158. y: fromPoint.y,
  3159. x: fromPoint.x < toPoint.x ?
  3160. chartObstacles[i].xMin - 1 :
  3161. chartObstacles[i].xMax + 1,
  3162. obstacle: chartObstacles[i]
  3163. };
  3164. }
  3165. // else ...
  3166. return {
  3167. x: fromPoint.x,
  3168. y: fromPoint.y < toPoint.y ?
  3169. chartObstacles[i].yMin - 1 :
  3170. chartObstacles[i].yMax + 1,
  3171. obstacle: chartObstacles[i]
  3172. };
  3173. }
  3174. i += searchDirection;
  3175. }
  3176. return toPoint;
  3177. }
  3178. /**
  3179. * Decide in which direction to dodge or get out of an obstacle.
  3180. * Considers desired direction, which way is shortest, soft and hard
  3181. * bounds.
  3182. *
  3183. * (? Returns a string, either xMin, xMax, yMin or yMax.)
  3184. *
  3185. * @private
  3186. * @function
  3187. *
  3188. * @param {object} obstacle
  3189. * Obstacle to dodge/escape.
  3190. *
  3191. * @param {object} fromPoint
  3192. * Point with x/y props that's dodging/escaping.
  3193. *
  3194. * @param {object} toPoint
  3195. * Goal point.
  3196. *
  3197. * @param {boolean} dirIsX
  3198. * Dodge in X dimension.
  3199. *
  3200. * @param {object} bounds
  3201. * Hard and soft boundaries.
  3202. *
  3203. * @return {boolean}
  3204. * Use max or not.
  3205. */
  3206. function getDodgeDirection(
  3207. obstacle,
  3208. fromPoint,
  3209. toPoint,
  3210. dirIsX,
  3211. bounds
  3212. ) {
  3213. var softBounds = bounds.soft,
  3214. hardBounds = bounds.hard,
  3215. dir = dirIsX ? 'x' : 'y',
  3216. toPointMax = { x: fromPoint.x, y: fromPoint.y },
  3217. toPointMin = { x: fromPoint.x, y: fromPoint.y },
  3218. minPivot,
  3219. maxPivot,
  3220. maxOutOfSoftBounds = obstacle[dir + 'Max'] >=
  3221. softBounds[dir + 'Max'],
  3222. minOutOfSoftBounds = obstacle[dir + 'Min'] <=
  3223. softBounds[dir + 'Min'],
  3224. maxOutOfHardBounds = obstacle[dir + 'Max'] >=
  3225. hardBounds[dir + 'Max'],
  3226. minOutOfHardBounds = obstacle[dir + 'Min'] <=
  3227. hardBounds[dir + 'Min'],
  3228. // Find out if we should prefer one direction over the other if
  3229. // we can choose freely
  3230. minDistance = abs(obstacle[dir + 'Min'] - fromPoint[dir]),
  3231. maxDistance = abs(obstacle[dir + 'Max'] - fromPoint[dir]),
  3232. // If it's a small difference, pick the one leading towards dest
  3233. // point. Otherwise pick the shortest distance
  3234. useMax = abs(minDistance - maxDistance) < 10 ?
  3235. fromPoint[dir] < toPoint[dir] :
  3236. maxDistance < minDistance;
  3237. // Check if we hit any obstacles trying to go around in either
  3238. // direction.
  3239. toPointMin[dir] = obstacle[dir + 'Min'];
  3240. toPointMax[dir] = obstacle[dir + 'Max'];
  3241. minPivot = pivotPoint(fromPoint, toPointMin, dirIsX)[dir] !==
  3242. toPointMin[dir];
  3243. maxPivot = pivotPoint(fromPoint, toPointMax, dirIsX)[dir] !==
  3244. toPointMax[dir];
  3245. useMax = minPivot ?
  3246. (maxPivot ? useMax : true) :
  3247. (maxPivot ? false : useMax);
  3248. // useMax now contains our preferred choice, bounds not taken into
  3249. // account. If both or neither direction is out of bounds we want to
  3250. // use this.
  3251. // Deal with soft bounds
  3252. useMax = minOutOfSoftBounds ?
  3253. (maxOutOfSoftBounds ? useMax : true) : // Out on min
  3254. (maxOutOfSoftBounds ? false : useMax); // Not out on min
  3255. // Deal with hard bounds
  3256. useMax = minOutOfHardBounds ?
  3257. (maxOutOfHardBounds ? useMax : true) : // Out on min
  3258. (maxOutOfHardBounds ? false : useMax); // Not out on min
  3259. return useMax;
  3260. }
  3261. // Find a clear path between point
  3262. function clearPathTo(fromPoint, toPoint, dirIsX) {
  3263. // Don't waste time if we've hit goal
  3264. if (fromPoint.x === toPoint.x && fromPoint.y === toPoint.y) {
  3265. return [];
  3266. }
  3267. var dir = dirIsX ? 'x' : 'y',
  3268. pivot,
  3269. segments,
  3270. waypoint,
  3271. waypointUseMax,
  3272. envelopingObstacle,
  3273. secondEnvelopingObstacle,
  3274. envelopWaypoint,
  3275. obstacleMargin = options.obstacleOptions.margin,
  3276. bounds = {
  3277. soft: {
  3278. xMin: softMinX,
  3279. xMax: softMaxX,
  3280. yMin: softMinY,
  3281. yMax: softMaxY
  3282. },
  3283. hard: options.hardBounds
  3284. };
  3285. // If fromPoint is inside an obstacle we have a problem. Break out
  3286. // by just going to the outside of this obstacle. We prefer to go to
  3287. // the nearest edge in the chosen direction.
  3288. envelopingObstacle =
  3289. findObstacleFromPoint(chartObstacles, fromPoint);
  3290. if (envelopingObstacle > -1) {
  3291. envelopingObstacle = chartObstacles[envelopingObstacle];
  3292. waypointUseMax = getDodgeDirection(
  3293. envelopingObstacle, fromPoint, toPoint, dirIsX, bounds
  3294. );
  3295. // Cut obstacle to hard bounds to make sure we stay within
  3296. limitObstacleToBounds(envelopingObstacle, options.hardBounds);
  3297. envelopWaypoint = dirIsX ? {
  3298. y: fromPoint.y,
  3299. x: envelopingObstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  3300. (waypointUseMax ? 1 : -1)
  3301. } : {
  3302. x: fromPoint.x,
  3303. y: envelopingObstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  3304. (waypointUseMax ? 1 : -1)
  3305. };
  3306. // If we crashed into another obstacle doing this, we put the
  3307. // waypoint between them instead
  3308. secondEnvelopingObstacle = findObstacleFromPoint(
  3309. chartObstacles, envelopWaypoint
  3310. );
  3311. if (secondEnvelopingObstacle > -1) {
  3312. secondEnvelopingObstacle = chartObstacles[
  3313. secondEnvelopingObstacle
  3314. ];
  3315. // Cut obstacle to hard bounds
  3316. limitObstacleToBounds(
  3317. secondEnvelopingObstacle,
  3318. options.hardBounds
  3319. );
  3320. // Modify waypoint to lay between obstacles
  3321. envelopWaypoint[dir] = waypointUseMax ? max(
  3322. envelopingObstacle[dir + 'Max'] - obstacleMargin + 1,
  3323. (
  3324. secondEnvelopingObstacle[dir + 'Min'] +
  3325. envelopingObstacle[dir + 'Max']
  3326. ) / 2
  3327. ) :
  3328. min((
  3329. envelopingObstacle[dir + 'Min'] + obstacleMargin - 1
  3330. ), (
  3331. (
  3332. secondEnvelopingObstacle[dir + 'Max'] +
  3333. envelopingObstacle[dir + 'Min']
  3334. ) / 2
  3335. ));
  3336. // We are not going anywhere. If this happens for the first
  3337. // time, do nothing. Otherwise, try to go to the extreme of
  3338. // the obstacle pair in the current direction.
  3339. if (fromPoint.x === envelopWaypoint.x &&
  3340. fromPoint.y === envelopWaypoint.y) {
  3341. if (forceObstacleBreak) {
  3342. envelopWaypoint[dir] = waypointUseMax ?
  3343. max(
  3344. envelopingObstacle[dir + 'Max'],
  3345. secondEnvelopingObstacle[dir + 'Max']
  3346. ) + 1 :
  3347. min(
  3348. envelopingObstacle[dir + 'Min'],
  3349. secondEnvelopingObstacle[dir + 'Min']
  3350. ) - 1;
  3351. }
  3352. // Toggle on if off, and the opposite
  3353. forceObstacleBreak = !forceObstacleBreak;
  3354. } else {
  3355. // This point is not identical to previous.
  3356. // Clear break trigger.
  3357. forceObstacleBreak = false;
  3358. }
  3359. }
  3360. segments = [{
  3361. start: fromPoint,
  3362. end: envelopWaypoint
  3363. }];
  3364. } else { // If not enveloping, use standard pivot calculation
  3365. pivot = pivotPoint(fromPoint, {
  3366. x: dirIsX ? toPoint.x : fromPoint.x,
  3367. y: dirIsX ? fromPoint.y : toPoint.y
  3368. }, dirIsX);
  3369. segments = [{
  3370. start: fromPoint,
  3371. end: {
  3372. x: pivot.x,
  3373. y: pivot.y
  3374. }
  3375. }];
  3376. // Pivot before goal, use a waypoint to dodge obstacle
  3377. if (pivot[dirIsX ? 'x' : 'y'] !== toPoint[dirIsX ? 'x' : 'y']) {
  3378. // Find direction of waypoint
  3379. waypointUseMax = getDodgeDirection(
  3380. pivot.obstacle, pivot, toPoint, !dirIsX, bounds
  3381. );
  3382. // Cut waypoint to hard bounds
  3383. limitObstacleToBounds(pivot.obstacle, options.hardBounds);
  3384. waypoint = {
  3385. x: dirIsX ?
  3386. pivot.x :
  3387. pivot.obstacle[waypointUseMax ? 'xMax' : 'xMin'] +
  3388. (waypointUseMax ? 1 : -1),
  3389. y: dirIsX ?
  3390. pivot.obstacle[waypointUseMax ? 'yMax' : 'yMin'] +
  3391. (waypointUseMax ? 1 : -1) :
  3392. pivot.y
  3393. };
  3394. // We're changing direction here, store that to make sure we
  3395. // also change direction when adding the last segment array
  3396. // after handling waypoint.
  3397. dirIsX = !dirIsX;
  3398. segments = segments.concat(clearPathTo({
  3399. x: pivot.x,
  3400. y: pivot.y
  3401. }, waypoint, dirIsX));
  3402. }
  3403. }
  3404. // Get segments for the other direction too
  3405. // Recursion is our friend
  3406. segments = segments.concat(clearPathTo(
  3407. segments[segments.length - 1].end, toPoint, !dirIsX
  3408. ));
  3409. return segments;
  3410. }
  3411. // Extract point to outside of obstacle in whichever direction is
  3412. // closest. Returns new point outside obstacle.
  3413. function extractFromObstacle(obstacle, point, goalPoint) {
  3414. var dirIsX = min(obstacle.xMax - point.x, point.x - obstacle.xMin) <
  3415. min(obstacle.yMax - point.y, point.y - obstacle.yMin),
  3416. bounds = {
  3417. soft: options.hardBounds,
  3418. hard: options.hardBounds
  3419. },
  3420. useMax = getDodgeDirection(
  3421. obstacle, point, goalPoint, dirIsX, bounds
  3422. );
  3423. return dirIsX ? {
  3424. y: point.y,
  3425. x: obstacle[useMax ? 'xMax' : 'xMin'] + (useMax ? 1 : -1)
  3426. } : {
  3427. x: point.x,
  3428. y: obstacle[useMax ? 'yMax' : 'yMin'] + (useMax ? 1 : -1)
  3429. };
  3430. }
  3431. // Cut the obstacle array to soft bounds for optimization in large
  3432. // datasets.
  3433. chartObstacles =
  3434. chartObstacles.slice(startObstacleIx, endObstacleIx + 1);
  3435. // If an obstacle envelops the end point, move it out of there and add
  3436. // a little segment to where it was.
  3437. if ((endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1) {
  3438. extractedEndPoint = extractFromObstacle(
  3439. chartObstacles[endObstacleIx],
  3440. end,
  3441. start
  3442. );
  3443. endSegments.push({
  3444. end: end,
  3445. start: extractedEndPoint
  3446. });
  3447. end = extractedEndPoint;
  3448. }
  3449. // If it's still inside one or more obstacles, get out of there by
  3450. // force-moving towards the start point.
  3451. while (
  3452. (endObstacleIx = findObstacleFromPoint(chartObstacles, end)) > -1
  3453. ) {
  3454. useMax = end[dir] - start[dir] < 0;
  3455. extractedEndPoint = {
  3456. x: end.x,
  3457. y: end.y
  3458. };
  3459. extractedEndPoint[dir] = chartObstacles[endObstacleIx][
  3460. useMax ? dir + 'Max' : dir + 'Min'
  3461. ] + (useMax ? 1 : -1);
  3462. endSegments.push({
  3463. end: end,
  3464. start: extractedEndPoint
  3465. });
  3466. end = extractedEndPoint;
  3467. }
  3468. // Find the path
  3469. segments = clearPathTo(start, end, dirIsX);
  3470. // Add the end-point segments
  3471. segments = segments.concat(endSegments.reverse());
  3472. return {
  3473. path: pathFromSegments(segments),
  3474. obstacles: segments
  3475. };
  3476. }, {
  3477. requiresObstacles: true
  3478. })
  3479. };
  3480. return algorithms;
  3481. }(Highcharts));
  3482. (function (H) {
  3483. /* *
  3484. * (c) 2017 Highsoft AS
  3485. * Authors: Lars A. V. Cabrera
  3486. *
  3487. * License: www.highcharts.com/license
  3488. */
  3489. /**
  3490. * Creates an arrow symbol. Like a triangle, except not filled.
  3491. * ```
  3492. * o
  3493. * o
  3494. * o
  3495. * o
  3496. * o
  3497. * o
  3498. * o
  3499. * ```
  3500. *
  3501. * @private
  3502. * @function
  3503. *
  3504. * @param {number} x
  3505. * x position of the arrow
  3506. *
  3507. * @param {number} y
  3508. * y position of the arrow
  3509. *
  3510. * @param {number} w
  3511. * width of the arrow
  3512. *
  3513. * @param {number} h
  3514. * height of the arrow
  3515. *
  3516. * @return {Highcharts.SVGPathArray}
  3517. * Path array
  3518. */
  3519. H.SVGRenderer.prototype.symbols.arrow = function (x, y, w, h) {
  3520. return [
  3521. 'M', x, y + h / 2,
  3522. 'L', x + w, y,
  3523. 'L', x, y + h / 2,
  3524. 'L', x + w, y + h
  3525. ];
  3526. };
  3527. /**
  3528. * Creates a half-width arrow symbol. Like a triangle, except not filled.
  3529. * ```
  3530. * o
  3531. * o
  3532. * o
  3533. * o
  3534. * o
  3535. * ```
  3536. *
  3537. * @private
  3538. * @function
  3539. *
  3540. * @param {number} x
  3541. * x position of the arrow
  3542. *
  3543. * @param {number} y
  3544. * y position of the arrow
  3545. *
  3546. * @param {number} w
  3547. * width of the arrow
  3548. *
  3549. * @param {number} h
  3550. * height of the arrow
  3551. *
  3552. * @return {Highcharts.SVGPathArray}
  3553. * Path array
  3554. */
  3555. H.SVGRenderer.prototype.symbols['arrow-half'] = function (x, y, w, h) {
  3556. return H.SVGRenderer.prototype.symbols.arrow(x, y, w / 2, h);
  3557. };
  3558. /**
  3559. * Creates a left-oriented triangle.
  3560. * ```
  3561. * o
  3562. * ooooooo
  3563. * ooooooooooooo
  3564. * ooooooo
  3565. * o
  3566. * ```
  3567. *
  3568. * @private
  3569. * @function
  3570. *
  3571. * @param {number} x
  3572. * x position of the triangle
  3573. *
  3574. * @param {number} y
  3575. * y position of the triangle
  3576. *
  3577. * @param {number} w
  3578. * width of the triangle
  3579. *
  3580. * @param {number} h
  3581. * height of the triangle
  3582. *
  3583. * @return {Highcharts.SVGPathArray}
  3584. * Path array
  3585. */
  3586. H.SVGRenderer.prototype.symbols['triangle-left'] = function (x, y, w, h) {
  3587. return [
  3588. 'M', x + w, y,
  3589. 'L', x, y + h / 2,
  3590. 'L', x + w, y + h,
  3591. 'Z'
  3592. ];
  3593. };
  3594. /**
  3595. * Alias function for triangle-left.
  3596. *
  3597. * @private
  3598. * @function
  3599. *
  3600. * @param {number} x
  3601. * x position of the arrow
  3602. *
  3603. * @param {number} y
  3604. * y position of the arrow
  3605. *
  3606. * @param {number} w
  3607. * width of the arrow
  3608. *
  3609. * @param {number} h
  3610. * height of the arrow
  3611. *
  3612. * @return {Highcharts.SVGPathArray}
  3613. * Path array
  3614. */
  3615. H.SVGRenderer.prototype.symbols['arrow-filled'] =
  3616. H.SVGRenderer.prototype.symbols['triangle-left'];
  3617. /**
  3618. * Creates a half-width, left-oriented triangle.
  3619. * ```
  3620. * o
  3621. * oooo
  3622. * ooooooo
  3623. * oooo
  3624. * o
  3625. * ```
  3626. *
  3627. * @private
  3628. * @function
  3629. *
  3630. * @param {number} x
  3631. * x position of the triangle
  3632. *
  3633. * @param {number} y
  3634. * y position of the triangle
  3635. *
  3636. * @param {number} w
  3637. * width of the triangle
  3638. *
  3639. * @param {number} h
  3640. * height of the triangle
  3641. *
  3642. * @return {Highcharts.SVGPathArray}
  3643. * Path array
  3644. */
  3645. H.SVGRenderer.prototype.symbols['triangle-left-half'] = function (x, y, w, h) {
  3646. return H.SVGRenderer.prototype.symbols['triangle-left'](x, y, w / 2, h);
  3647. };
  3648. /**
  3649. * Alias function for triangle-left-half.
  3650. *
  3651. * @private
  3652. * @function
  3653. *
  3654. * @param {number} x
  3655. * x position of the arrow
  3656. *
  3657. * @param {number} y
  3658. * y position of the arrow
  3659. *
  3660. * @param {number} w
  3661. * width of the arrow
  3662. *
  3663. * @param {number} h
  3664. * height of the arrow
  3665. *
  3666. * @return {Highcharts.SVGPathArray}
  3667. * Path array
  3668. */
  3669. H.SVGRenderer.prototype.symbols['arrow-filled-half'] =
  3670. H.SVGRenderer.prototype.symbols['triangle-left-half'];
  3671. }(Highcharts));
  3672. (function (H, pathfinderAlgorithms) {
  3673. /* *
  3674. * (c) 2016 Highsoft AS
  3675. * Authors: Øystein Moseng, Lars A. V. Cabrera
  3676. *
  3677. * License: www.highcharts.com/license
  3678. */
  3679. var defined = H.defined,
  3680. deg2rad = H.deg2rad,
  3681. extend = H.extend,
  3682. addEvent = H.addEvent,
  3683. merge = H.merge,
  3684. pick = H.pick,
  3685. max = Math.max,
  3686. min = Math.min;
  3687. /*
  3688. @todo:
  3689. - Document how to write your own algorithms
  3690. - Consider adding a Point.pathTo method that wraps creating a connection
  3691. and rendering it
  3692. */
  3693. // Set default Pathfinder options
  3694. extend(H.defaultOptions, {
  3695. /**
  3696. * The Pathfinder module allows you to define connections between any two
  3697. * points, represented as lines - optionally with markers for the start
  3698. * and/or end points. Multiple algorithms are available for calculating how
  3699. * the connecting lines are drawn.
  3700. *
  3701. * Connector functionality requires Highcharts Gantt to be loaded. In Gantt
  3702. * charts, the connectors are used to draw dependencies between tasks.
  3703. *
  3704. * @see [dependency](series.gantt.data.dependency)
  3705. *
  3706. * @sample gantt/pathfinder/demo
  3707. * Pathfinder connections
  3708. *
  3709. * @product gantt
  3710. * @optionparent connectors
  3711. */
  3712. connectors: {
  3713. /**
  3714. * Enable connectors for this chart. Requires Highcharts Gantt.
  3715. *
  3716. * @type {boolean}
  3717. * @default true
  3718. * @since 6.2.0
  3719. * @apioption connectors.enabled
  3720. */
  3721. /**
  3722. * Set the default dash style for this chart's connecting lines.
  3723. *
  3724. * @type {string}
  3725. * @default solid
  3726. * @since 6.2.0
  3727. * @apioption connectors.dashStyle
  3728. */
  3729. /**
  3730. * Set the default color for this chart's Pathfinder connecting lines.
  3731. * Defaults to the color of the point being connected.
  3732. *
  3733. * @type {Highcharts.ColorString}
  3734. * @since 6.2.0
  3735. * @apioption connectors.lineColor
  3736. */
  3737. /**
  3738. * Set the default pathfinder margin to use, in pixels. Some Pathfinder
  3739. * algorithms attempt to avoid obstacles, such as other points in the
  3740. * chart. These algorithms use this margin to determine how close lines
  3741. * can be to an obstacle. The default is to compute this automatically
  3742. * from the size of the obstacles in the chart.
  3743. *
  3744. * To draw connecting lines close to existing points, set this to a low
  3745. * number. For more space around existing points, set this number
  3746. * higher.
  3747. *
  3748. * @sample gantt/pathfinder/algorithm-margin
  3749. * Small algorithmMargin
  3750. *
  3751. * @type {number}
  3752. * @since 6.2.0
  3753. * @apioption connectors.algorithmMargin
  3754. */
  3755. /**
  3756. * Set the default pathfinder algorithm to use for this chart. It is
  3757. * possible to define your own algorithms by adding them to the
  3758. * Highcharts.Pathfinder.prototype.algorithms object before the chart
  3759. * has been created.
  3760. *
  3761. * The default algorithms are as follows:
  3762. *
  3763. * `straight`: Draws a straight line between the connecting
  3764. * points. Does not avoid other points when drawing.
  3765. *
  3766. * `simpleConnect`: Finds a path between the points using right angles
  3767. * only. Takes only starting/ending points into
  3768. * account, and will not avoid other points.
  3769. *
  3770. * `fastAvoid`: Finds a path between the points using right angles
  3771. * only. Will attempt to avoid other points, but its
  3772. * focus is performance over accuracy. Works well with
  3773. * less dense datasets.
  3774. *
  3775. * Default value: `straight` is used as default for most series types,
  3776. * while `simpleConnect` is used as default for Gantt series, to show
  3777. * dependencies between points.
  3778. *
  3779. * @sample gantt/pathfinder/demo
  3780. * Different types used
  3781. *
  3782. * @default undefined
  3783. * @since 6.2.0
  3784. * @validvalue ["straight", "simpleConnect", "fastAvoid"]
  3785. */
  3786. type: 'straight',
  3787. /**
  3788. * Set the default pixel width for this chart's Pathfinder connecting
  3789. * lines.
  3790. *
  3791. * @since 6.2.0
  3792. */
  3793. lineWidth: 1,
  3794. /**
  3795. * Marker options for this chart's Pathfinder connectors. Note that
  3796. * this option is overridden by the `startMarker` and `endMarker`
  3797. * options.
  3798. *
  3799. * @since 6.2.0
  3800. */
  3801. marker: {
  3802. /**
  3803. * Set the radius of the connector markers. The default is
  3804. * automatically computed based on the algorithmMargin setting.
  3805. *
  3806. * Setting marker.width and marker.height will override this
  3807. * setting.
  3808. *
  3809. * @type {number}
  3810. * @since 6.2.0
  3811. * @apioption connectors.marker.radius
  3812. */
  3813. /**
  3814. * Set the width of the connector markers. If not supplied, this
  3815. * is inferred from the marker radius.
  3816. *
  3817. * @type {number}
  3818. * @since 6.2.0
  3819. * @apioption connectors.marker.width
  3820. */
  3821. /**
  3822. * Set the height of the connector markers. If not supplied, this
  3823. * is inferred from the marker radius.
  3824. *
  3825. * @type {number}
  3826. * @since 6.2.0
  3827. * @apioption connectors.marker.height
  3828. */
  3829. /**
  3830. * Set the color of the connector markers. By default this is the
  3831. * same as the connector color.
  3832. *
  3833. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  3834. * @since 6.2.0
  3835. * @apioption connectors.marker.color
  3836. */
  3837. /**
  3838. * Set the line/border color of the connector markers. By default
  3839. * this is the same as the marker color.
  3840. *
  3841. * @type {Highcharts.ColorString}
  3842. * @since 6.2.0
  3843. * @apioption connectors.marker.lineColor
  3844. */
  3845. /**
  3846. * Enable markers for the connectors.
  3847. */
  3848. enabled: false,
  3849. /**
  3850. * Horizontal alignment of the markers relative to the points.
  3851. *
  3852. * @type {Highcharts.AlignType}
  3853. */
  3854. align: 'center',
  3855. /**
  3856. * Vertical alignment of the markers relative to the points.
  3857. *
  3858. * @type {Highcharts.VerticalAlignType}
  3859. */
  3860. verticalAlign: 'middle',
  3861. /**
  3862. * Whether or not to draw the markers inside the points.
  3863. */
  3864. inside: false,
  3865. /**
  3866. * Set the line/border width of the pathfinder markers.
  3867. */
  3868. lineWidth: 1
  3869. },
  3870. /**
  3871. * Marker options specific to the start markers for this chart's
  3872. * Pathfinder connectors. Overrides the generic marker options.
  3873. *
  3874. * @extends connectors.marker
  3875. * @since 6.2.0
  3876. */
  3877. startMarker: {
  3878. /**
  3879. * Set the symbol of the connector start markers.
  3880. */
  3881. symbol: 'diamond'
  3882. },
  3883. /**
  3884. * Marker options specific to the end markers for this chart's
  3885. * Pathfinder connectors. Overrides the generic marker options.
  3886. *
  3887. * @extends connectors.marker
  3888. * @since 6.2.0
  3889. */
  3890. endMarker: {
  3891. /**
  3892. * Set the symbol of the connector end markers.
  3893. */
  3894. symbol: 'arrow-filled'
  3895. }
  3896. }
  3897. });
  3898. /**
  3899. * Override Pathfinder connector options for a series. Requires Highcharts Gantt
  3900. * to be loaded.
  3901. *
  3902. * @extends connectors
  3903. * @since 6.2.0
  3904. * @excluding enabled, algorithmMargin
  3905. * @product gantt
  3906. * @apioption plotOptions.series.connectors
  3907. */
  3908. /**
  3909. * Connect to a point. Requires Highcharts Gantt to be loaded. This option can
  3910. * be either a string, referring to the ID of another point, or an object, or an
  3911. * array of either. If the option is an array, each element defines a
  3912. * connection.
  3913. *
  3914. * @sample gantt/pathfinder/demo
  3915. * Different connection types
  3916. *
  3917. * @type {string|Array<string|*>|*}
  3918. * @extends plotOptions.series.connectors
  3919. * @since 6.2.0
  3920. * @excluding enabled
  3921. * @product gantt
  3922. * @apioption series.xrange.data.connect
  3923. */
  3924. /**
  3925. * The ID of the point to connect to.
  3926. *
  3927. * @type {string}
  3928. * @since 6.2.0
  3929. * @product gantt
  3930. * @apioption series.xrange.data.connect.to
  3931. */
  3932. /**
  3933. * Get point bounding box using plotX/plotY and shapeArgs. If using
  3934. * graphic.getBBox() directly, the bbox will be affected by animation.
  3935. *
  3936. * @private
  3937. * @function
  3938. *
  3939. * @param {Highcharts.Point} point
  3940. * The point to get BB of.
  3941. *
  3942. * @return {object}
  3943. * Result xMax, xMin, yMax, yMin.
  3944. */
  3945. function getPointBB(point) {
  3946. var shapeArgs = point.shapeArgs,
  3947. bb;
  3948. // Prefer using shapeArgs (columns)
  3949. if (shapeArgs) {
  3950. return {
  3951. xMin: shapeArgs.x,
  3952. xMax: shapeArgs.x + shapeArgs.width,
  3953. yMin: shapeArgs.y,
  3954. yMax: shapeArgs.y + shapeArgs.height
  3955. };
  3956. }
  3957. // Otherwise use plotX/plotY and bb
  3958. bb = point.graphic && point.graphic.getBBox();
  3959. return bb ? {
  3960. xMin: point.plotX - bb.width / 2,
  3961. xMax: point.plotX + bb.width / 2,
  3962. yMin: point.plotY - bb.height / 2,
  3963. yMax: point.plotY + bb.height / 2
  3964. } : null;
  3965. }
  3966. /**
  3967. * Calculate margin to place around obstacles for the pathfinder in pixels.
  3968. * Returns a minimum of 1 pixel margin.
  3969. *
  3970. * @private
  3971. * @function
  3972. *
  3973. * @param {Array<object>} obstacles
  3974. * Obstacles to calculate margin from.
  3975. *
  3976. * @return {number}
  3977. * The calculated margin in pixels. At least 1.
  3978. */
  3979. function calculateObstacleMargin(obstacles) {
  3980. var len = obstacles.length,
  3981. i = 0,
  3982. j,
  3983. obstacleDistance,
  3984. distances = [],
  3985. // Compute smallest distance between two rectangles
  3986. distance = function (a, b, bbMargin) {
  3987. // Count the distance even if we are slightly off
  3988. var margin = pick(bbMargin, 10),
  3989. yOverlap = a.yMax + margin > b.yMin - margin &&
  3990. a.yMin - margin < b.yMax + margin,
  3991. xOverlap = a.xMax + margin > b.xMin - margin &&
  3992. a.xMin - margin < b.xMax + margin,
  3993. xDistance = yOverlap ? (
  3994. a.xMin > b.xMax ? a.xMin - b.xMax : b.xMin - a.xMax
  3995. ) : Infinity,
  3996. yDistance = xOverlap ? (
  3997. a.yMin > b.yMax ? a.yMin - b.yMax : b.yMin - a.yMax
  3998. ) : Infinity;
  3999. // If the rectangles collide, try recomputing with smaller margin.
  4000. // If they collide anyway, discard the obstacle.
  4001. if (xOverlap && yOverlap) {
  4002. return (
  4003. margin ?
  4004. distance(a, b, Math.floor(margin / 2)) :
  4005. Infinity
  4006. );
  4007. }
  4008. return min(xDistance, yDistance);
  4009. };
  4010. // Go over all obstacles and compare them to the others.
  4011. for (; i < len; ++i) {
  4012. // Compare to all obstacles ahead. We will already have compared this
  4013. // obstacle to the ones before.
  4014. for (j = i + 1; j < len; ++j) {
  4015. obstacleDistance = distance(obstacles[i], obstacles[j]);
  4016. // TODO: Magic number 80
  4017. if (obstacleDistance < 80) { // Ignore large distances
  4018. distances.push(obstacleDistance);
  4019. }
  4020. }
  4021. }
  4022. // Ensure we always have at least one value, even in very spaceous charts
  4023. distances.push(80);
  4024. return max(
  4025. Math.floor(
  4026. distances.sort(function (a, b) {
  4027. return a - b;
  4028. })[
  4029. // Discard first 10% of the relevant distances, and then grab
  4030. // the smallest one.
  4031. Math.floor(distances.length / 10)
  4032. ] / 2 - 1 // Divide the distance by 2 and subtract 1.
  4033. ),
  4034. 1 // 1 is the minimum margin
  4035. );
  4036. }
  4037. /**
  4038. * The Connection class. Used internally to represent a connection between two
  4039. * points.
  4040. *
  4041. * @private
  4042. * @class
  4043. * @name Highcharts.Connection
  4044. *
  4045. * @param {Highcharts.Point} from
  4046. * Connection runs from this Point.
  4047. *
  4048. * @param {Highcharts.Point} to
  4049. * Connection runs to this Point.
  4050. *
  4051. * @param {Highcharts.ConnectorsOptions} [options]
  4052. * Connection options.
  4053. */
  4054. function Connection(from, to, options) {
  4055. this.init(from, to, options);
  4056. }
  4057. Connection.prototype = {
  4058. /**
  4059. * Initialize the Connection object. Used as constructor only.
  4060. *
  4061. * @function Highcharts.Connection#init
  4062. *
  4063. * @param {Highcharts.Point} from
  4064. * Connection runs from this Point.
  4065. *
  4066. * @param {Highcharts.Point} to
  4067. * Connection runs to this Point.
  4068. *
  4069. * @param {Highcharts.ConnectorsOptions} [options]
  4070. * Connection options.
  4071. */
  4072. init: function (from, to, options) {
  4073. this.fromPoint = from;
  4074. this.toPoint = to;
  4075. this.options = options;
  4076. this.chart = from.series.chart;
  4077. this.pathfinder = this.chart.pathfinder;
  4078. },
  4079. /**
  4080. * Add (or update) this connection's path on chart. Stores reference to the
  4081. * created element on this.graphics.path.
  4082. *
  4083. * @function Highcharts.Connection#renderPath
  4084. *
  4085. * @param {Highcharts.SVGPathArray} path
  4086. * Path to render, in array format. E.g. ['M', 0, 0, 'L', 10, 10]
  4087. *
  4088. * @param {Highcharts.SVGAttributes} [attribs]
  4089. * SVG attributes for the path.
  4090. *
  4091. * @param {Highcharts.AnimationOptionsObject} [animation]
  4092. * Animation options for the rendering.
  4093. *
  4094. * @param {Function} [complete]
  4095. * Callback function when the path has been rendered and animation is
  4096. * complete.
  4097. */
  4098. renderPath: function (path, attribs, animation) {
  4099. var connection = this,
  4100. chart = this.chart,
  4101. styledMode = chart.styledMode,
  4102. pathfinder = chart.pathfinder,
  4103. animate = !chart.options.chart.forExport && animation !== false,
  4104. pathGraphic = connection.graphics && connection.graphics.path,
  4105. anim;
  4106. // Add the SVG element of the pathfinder group if it doesn't exist
  4107. if (!pathfinder.group) {
  4108. pathfinder.group = chart.renderer.g()
  4109. .addClass('highcharts-pathfinder-group')
  4110. .attr({ zIndex: -1 })
  4111. .add(chart.seriesGroup);
  4112. }
  4113. // Shift the group to compensate for plot area.
  4114. // Note: Do this always (even when redrawing a path) to avoid issues
  4115. // when updating chart in a way that changes plot metrics.
  4116. pathfinder.group.translate(chart.plotLeft, chart.plotTop);
  4117. // Create path if does not exist
  4118. if (!(pathGraphic && pathGraphic.renderer)) {
  4119. pathGraphic = chart.renderer.path()
  4120. .add(pathfinder.group);
  4121. if (!styledMode) {
  4122. pathGraphic.attr({
  4123. opacity: 0
  4124. });
  4125. }
  4126. }
  4127. // Set path attribs and animate to the new path
  4128. pathGraphic.attr(attribs);
  4129. anim = { d: path };
  4130. if (!styledMode) {
  4131. anim.opacity = 1;
  4132. }
  4133. pathGraphic[animate ? 'animate' : 'attr'](anim, animation);
  4134. // Store reference on connection
  4135. this.graphics = this.graphics || {};
  4136. this.graphics.path = pathGraphic;
  4137. },
  4138. /**
  4139. * Calculate and add marker graphics for connection to the chart. The
  4140. * created/updated elements are stored on this.graphics.start and
  4141. * this.graphics.end.
  4142. *
  4143. * @function Highcharts.Connection#addMarker
  4144. *
  4145. * @param {string} type
  4146. * Marker type, either 'start' or 'end'.
  4147. *
  4148. * @param {Highcharts.ConnectorsMarkerOptions} options
  4149. * All options for this marker. Not calculated or merged with other
  4150. * options.
  4151. *
  4152. * @param {Highcharts.SVGPathArray} path
  4153. * Connection path in array format. This is used to calculate the
  4154. * rotation angle of the markers.
  4155. */
  4156. addMarker: function (type, options, path) {
  4157. var connection = this,
  4158. chart = connection.fromPoint.series.chart,
  4159. pathfinder = chart.pathfinder,
  4160. renderer = chart.renderer,
  4161. point = (
  4162. type === 'start' ?
  4163. connection.fromPoint :
  4164. connection.toPoint
  4165. ),
  4166. anchor = point.getPathfinderAnchorPoint(options),
  4167. markerVector,
  4168. radians,
  4169. rotation,
  4170. box,
  4171. width,
  4172. height,
  4173. pathVector;
  4174. if (!options.enabled) {
  4175. return;
  4176. }
  4177. // Last vector before start/end of path, used to get angle
  4178. if (type === 'start') {
  4179. pathVector = {
  4180. x: path[4],
  4181. y: path[5]
  4182. };
  4183. } else { // 'end'
  4184. pathVector = {
  4185. x: path[path.length - 5],
  4186. y: path[path.length - 4]
  4187. };
  4188. }
  4189. // Get angle between pathVector and anchor point and use it to create
  4190. // marker position.
  4191. radians = point.getRadiansToVector(pathVector, anchor);
  4192. markerVector = point.getMarkerVector(
  4193. radians,
  4194. options.radius,
  4195. anchor
  4196. );
  4197. // Rotation of marker is calculated from angle between pathVector and
  4198. // markerVector.
  4199. // (Note:
  4200. // Used to recalculate radians between markerVector and pathVector,
  4201. // but this should be the same as between pathVector and anchor.)
  4202. rotation = -radians / deg2rad;
  4203. if (options.width && options.height) {
  4204. width = options.width;
  4205. height = options.height;
  4206. } else {
  4207. width = height = options.radius * 2;
  4208. }
  4209. // Add graphics object if it does not exist
  4210. connection.graphics = connection.graphics || {};
  4211. box = {
  4212. x: markerVector.x - (width / 2),
  4213. y: markerVector.y - (height / 2),
  4214. width: width,
  4215. height: height,
  4216. rotation: rotation,
  4217. rotationOriginX: markerVector.x,
  4218. rotationOriginY: markerVector.y
  4219. };
  4220. if (!connection.graphics[type]) {
  4221. // Create new marker element
  4222. connection.graphics[type] = renderer.symbol(
  4223. options.symbol
  4224. )
  4225. .addClass(
  4226. 'highcharts-point-connecting-path-' + type + '-marker'
  4227. )
  4228. .attr(box)
  4229. .add(pathfinder.group);
  4230. if (!renderer.styledMode) {
  4231. connection.graphics[type].attr({
  4232. fill: options.color || connection.fromPoint.color,
  4233. stroke: options.lineColor,
  4234. 'stroke-width': options.lineWidth,
  4235. opacity: 0
  4236. })
  4237. .animate({
  4238. opacity: 1
  4239. }, point.series.options.animation);
  4240. }
  4241. } else {
  4242. connection.graphics[type].animate(box);
  4243. }
  4244. },
  4245. /**
  4246. * Calculate and return connection path.
  4247. * Note: Recalculates chart obstacles on demand if they aren't calculated.
  4248. *
  4249. * @function Highcharts.Connection#getPath
  4250. *
  4251. * @param {Highcharts.ConnectorsOptions} options
  4252. * Connector options. Not calculated or merged with other options.
  4253. *
  4254. * @return {Highcharts.SVHPathArray}
  4255. * Calculated SVG path data in array format.
  4256. */
  4257. getPath: function (options) {
  4258. var pathfinder = this.pathfinder,
  4259. chart = this.chart,
  4260. algorithm = pathfinder.algorithms[options.type],
  4261. chartObstacles = pathfinder.chartObstacles;
  4262. if (typeof algorithm !== 'function') {
  4263. H.error(
  4264. '"' + options.type + '" is not a Pathfinder algorithm.'
  4265. );
  4266. return;
  4267. }
  4268. // This function calculates obstacles on demand if they don't exist
  4269. if (algorithm.requiresObstacles && !chartObstacles) {
  4270. chartObstacles =
  4271. pathfinder.chartObstacles =
  4272. pathfinder.getChartObstacles(options);
  4273. // If the algorithmMargin was computed, store the result in default
  4274. // options.
  4275. chart.options.connectors.algorithmMargin = options.algorithmMargin;
  4276. // Cache some metrics too
  4277. pathfinder.chartObstacleMetrics =
  4278. pathfinder.getObstacleMetrics(chartObstacles);
  4279. }
  4280. // Get the SVG path
  4281. return algorithm(
  4282. // From
  4283. this.fromPoint.getPathfinderAnchorPoint(options.startMarker),
  4284. // To
  4285. this.toPoint.getPathfinderAnchorPoint(options.endMarker),
  4286. merge({
  4287. chartObstacles: chartObstacles,
  4288. lineObstacles: pathfinder.lineObstacles || [],
  4289. obstacleMetrics: pathfinder.chartObstacleMetrics,
  4290. hardBounds: {
  4291. xMin: 0,
  4292. xMax: chart.plotWidth,
  4293. yMin: 0,
  4294. yMax: chart.plotHeight
  4295. },
  4296. obstacleOptions: {
  4297. margin: options.algorithmMargin
  4298. },
  4299. startDirectionX: pathfinder.getAlgorithmStartDirection(
  4300. options.startMarker
  4301. )
  4302. }, options)
  4303. );
  4304. },
  4305. /**
  4306. * (re)Calculate and (re)draw the connection.
  4307. *
  4308. * @function Highcharts.Connection#render
  4309. */
  4310. render: function () {
  4311. var connection = this,
  4312. fromPoint = connection.fromPoint,
  4313. series = fromPoint.series,
  4314. chart = series.chart,
  4315. pathfinder = chart.pathfinder,
  4316. pathResult,
  4317. path,
  4318. options = merge(
  4319. chart.options.connectors, series.options.connectors,
  4320. fromPoint.options.connectors, connection.options
  4321. ),
  4322. attribs = {};
  4323. // Set path attribs
  4324. if (!chart.styledMode) {
  4325. attribs.stroke = options.lineColor || fromPoint.color;
  4326. attribs['stroke-width'] = options.lineWidth;
  4327. if (options.dashStyle) {
  4328. attribs.dashstyle = options.dashStyle;
  4329. }
  4330. }
  4331. attribs.class = 'highcharts-point-connecting-path ' +
  4332. 'highcharts-color-' + fromPoint.colorIndex;
  4333. options = merge(attribs, options);
  4334. // Set common marker options
  4335. if (!defined(options.marker.radius)) {
  4336. options.marker.radius = min(max(
  4337. Math.ceil((options.algorithmMargin || 8) / 2) - 1, 1
  4338. ), 5);
  4339. }
  4340. // Get the path
  4341. pathResult = connection.getPath(options);
  4342. path = pathResult.path;
  4343. // Always update obstacle storage with obstacles from this path.
  4344. // We don't know if future calls will need this for their algorithm.
  4345. if (pathResult.obstacles) {
  4346. pathfinder.lineObstacles = pathfinder.lineObstacles || [];
  4347. pathfinder.lineObstacles =
  4348. pathfinder.lineObstacles.concat(pathResult.obstacles);
  4349. }
  4350. // Add the calculated path to the pathfinder group
  4351. connection.renderPath(path, attribs, series.options.animation);
  4352. // Render the markers
  4353. connection.addMarker(
  4354. 'start',
  4355. merge(options.marker, options.startMarker),
  4356. path
  4357. );
  4358. connection.addMarker(
  4359. 'end',
  4360. merge(options.marker, options.endMarker),
  4361. path
  4362. );
  4363. },
  4364. /**
  4365. * Destroy connection by destroying the added graphics elements.
  4366. *
  4367. * @function Highcharts.Connection#destroy
  4368. */
  4369. destroy: function () {
  4370. if (this.graphics) {
  4371. H.objectEach(this.graphics, function (val) {
  4372. val.destroy();
  4373. });
  4374. delete this.graphics;
  4375. }
  4376. }
  4377. };
  4378. /**
  4379. * The Pathfinder class.
  4380. *
  4381. * @private
  4382. * @class
  4383. * @name Highcharts.Pathfinder
  4384. *
  4385. * @param {Highcharts.Chart} chart
  4386. * The chart to operate on.
  4387. */
  4388. function Pathfinder(chart) {
  4389. this.init(chart);
  4390. }
  4391. Pathfinder.prototype = {
  4392. /**
  4393. * @name Highcharts.Pathfinder#algorithms
  4394. * @type {Highcharts.Dictionary<Function>}
  4395. */
  4396. algorithms: pathfinderAlgorithms,
  4397. /**
  4398. * Initialize the Pathfinder object.
  4399. *
  4400. * @function Highcharts.Pathfinder#init
  4401. *
  4402. * @param {Highcharts.Chart} chart
  4403. * The chart context.
  4404. */
  4405. init: function (chart) {
  4406. // Initialize pathfinder with chart context
  4407. this.chart = chart;
  4408. // Init connection reference list
  4409. this.connections = [];
  4410. // Recalculate paths/obstacles on chart redraw
  4411. addEvent(chart, 'redraw', function () {
  4412. this.pathfinder.update();
  4413. });
  4414. },
  4415. /**
  4416. * Update Pathfinder connections from scratch.
  4417. *
  4418. * @function Highcharts.Pathfinder#update
  4419. *
  4420. * @param {boolean} deferRender
  4421. * Whether or not to defer rendering of connections until
  4422. * series.afterAnimate event has fired. Used on first render.
  4423. */
  4424. update: function (deferRender) {
  4425. var chart = this.chart,
  4426. pathfinder = this,
  4427. oldConnections = pathfinder.connections;
  4428. // Rebuild pathfinder connections from options
  4429. pathfinder.connections = [];
  4430. chart.series.forEach(function (series) {
  4431. if (series.visible) {
  4432. series.points.forEach(function (point) {
  4433. var to,
  4434. connects = (
  4435. point.options &&
  4436. point.options.connect &&
  4437. H.splat(point.options.connect)
  4438. );
  4439. if (point.visible && point.isInside !== false && connects) {
  4440. connects.forEach(function (connect) {
  4441. to = chart.get(
  4442. typeof connect === 'string' ?
  4443. connect : connect.to
  4444. );
  4445. if (
  4446. to instanceof H.Point &&
  4447. to.series.visible &&
  4448. to.visible &&
  4449. to.isInside !== false
  4450. ) {
  4451. // Add new connection
  4452. pathfinder.connections.push(new Connection(
  4453. point, // from
  4454. to,
  4455. typeof connect === 'string' ? {} : connect
  4456. ));
  4457. }
  4458. });
  4459. }
  4460. });
  4461. }
  4462. });
  4463. // Clear connections that should not be updated, and move old info over
  4464. // to new connections.
  4465. for (
  4466. var j = 0, k, found, lenOld = oldConnections.length,
  4467. lenNew = pathfinder.connections.length;
  4468. j < lenOld;
  4469. ++j
  4470. ) {
  4471. found = false;
  4472. for (k = 0; k < lenNew; ++k) {
  4473. if (
  4474. oldConnections[j].fromPoint ===
  4475. pathfinder.connections[k].fromPoint &&
  4476. oldConnections[j].toPoint ===
  4477. pathfinder.connections[k].toPoint
  4478. ) {
  4479. pathfinder.connections[k].graphics =
  4480. oldConnections[j].graphics;
  4481. found = true;
  4482. break;
  4483. }
  4484. }
  4485. if (!found) {
  4486. oldConnections[j].destroy();
  4487. }
  4488. }
  4489. // Clear obstacles to force recalculation. This must be done on every
  4490. // redraw in case positions have changed. Recalculation is handled in
  4491. // Connection.getPath on demand.
  4492. delete this.chartObstacles;
  4493. delete this.lineObstacles;
  4494. // Draw the pending connections
  4495. pathfinder.renderConnections(deferRender);
  4496. },
  4497. /**
  4498. * Draw the chart's connecting paths.
  4499. *
  4500. * @function Highcharts.Pathfinder#renderConnections
  4501. *
  4502. * @param {boolean} deferRender
  4503. * Whether or not to defer render until series animation is finished.
  4504. * Used on first render.
  4505. */
  4506. renderConnections: function (deferRender) {
  4507. if (deferRender) {
  4508. // Render after series are done animating
  4509. this.chart.series.forEach(function (series) {
  4510. var render = function () {
  4511. // Find pathfinder connections belonging to this series
  4512. // that haven't rendered, and render them now.
  4513. var pathfinder = series.chart.pathfinder,
  4514. conns = pathfinder && pathfinder.connections || [];
  4515. conns.forEach(function (connection) {
  4516. if (
  4517. connection.fromPoint &&
  4518. connection.fromPoint.series === series
  4519. ) {
  4520. connection.render();
  4521. }
  4522. });
  4523. if (series.pathfinderRemoveRenderEvent) {
  4524. series.pathfinderRemoveRenderEvent();
  4525. delete series.pathfinderRemoveRenderEvent;
  4526. }
  4527. };
  4528. if (series.options.animation === false) {
  4529. render();
  4530. } else {
  4531. series.pathfinderRemoveRenderEvent = addEvent(
  4532. series, 'afterAnimate', render
  4533. );
  4534. }
  4535. });
  4536. } else {
  4537. // Go through connections and render them
  4538. this.connections.forEach(function (connection) {
  4539. connection.render();
  4540. });
  4541. }
  4542. },
  4543. /**
  4544. * Get obstacles for the points in the chart. Does not include connecting
  4545. * lines from Pathfinder. Applies algorithmMargin to the obstacles.
  4546. *
  4547. * @function Highcharts.Pathfinder#getChartObstacles
  4548. *
  4549. * @param {object} options
  4550. * Options for the calculation. Currenlty only
  4551. * options.algorithmMargin.
  4552. *
  4553. * @return {Array<object>}
  4554. * An array of calculated obstacles. Each obstacle is defined as an
  4555. * object with xMin, xMax, yMin and yMax properties.
  4556. */
  4557. getChartObstacles: function (options) {
  4558. var obstacles = [],
  4559. series = this.chart.series,
  4560. margin = pick(options.algorithmMargin, 0),
  4561. calculatedMargin;
  4562. for (var i = 0, sLen = series.length; i < sLen; ++i) {
  4563. if (series[i].visible) {
  4564. for (
  4565. var j = 0, pLen = series[i].points.length, bb, point;
  4566. j < pLen;
  4567. ++j
  4568. ) {
  4569. point = series[i].points[j];
  4570. if (point.visible) {
  4571. bb = getPointBB(point);
  4572. if (bb) {
  4573. obstacles.push({
  4574. xMin: bb.xMin - margin,
  4575. xMax: bb.xMax + margin,
  4576. yMin: bb.yMin - margin,
  4577. yMax: bb.yMax + margin
  4578. });
  4579. }
  4580. }
  4581. }
  4582. }
  4583. }
  4584. // Sort obstacles by xMin for optimization
  4585. obstacles = obstacles.sort(function (a, b) {
  4586. return a.xMin - b.xMin;
  4587. });
  4588. // Add auto-calculated margin if the option is not defined
  4589. if (!defined(options.algorithmMargin)) {
  4590. calculatedMargin =
  4591. options.algorithmMargin =
  4592. calculateObstacleMargin(obstacles);
  4593. obstacles.forEach(function (obstacle) {
  4594. obstacle.xMin -= calculatedMargin;
  4595. obstacle.xMax += calculatedMargin;
  4596. obstacle.yMin -= calculatedMargin;
  4597. obstacle.yMax += calculatedMargin;
  4598. });
  4599. }
  4600. return obstacles;
  4601. },
  4602. /**
  4603. * Utility function to get metrics for obstacles:
  4604. * - Widest obstacle width
  4605. * - Tallest obstacle height
  4606. *
  4607. * @function Highcharts.Pathfinder#getObstacleMetrics
  4608. *
  4609. * @param {Array<object>} obstacles
  4610. * An array of obstacles to inspect.
  4611. *
  4612. * @return {object}
  4613. * The calculated metrics, as an object with maxHeight and maxWidth
  4614. * properties.
  4615. */
  4616. getObstacleMetrics: function (obstacles) {
  4617. var maxWidth = 0,
  4618. maxHeight = 0,
  4619. width,
  4620. height,
  4621. i = obstacles.length;
  4622. while (i--) {
  4623. width = obstacles[i].xMax - obstacles[i].xMin;
  4624. height = obstacles[i].yMax - obstacles[i].yMin;
  4625. if (maxWidth < width) {
  4626. maxWidth = width;
  4627. }
  4628. if (maxHeight < height) {
  4629. maxHeight = height;
  4630. }
  4631. }
  4632. return {
  4633. maxHeight: maxHeight,
  4634. maxWidth: maxWidth
  4635. };
  4636. },
  4637. /**
  4638. * Utility to get which direction to start the pathfinding algorithm
  4639. * (X vs Y), calculated from a set of marker options.
  4640. *
  4641. * @function Highcharts.Pathfinder#getAlgorithmStartDirection
  4642. *
  4643. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  4644. * Marker options to calculate from.
  4645. *
  4646. * @return {boolean}
  4647. * Returns true for X, false for Y, and undefined for autocalculate.
  4648. */
  4649. getAlgorithmStartDirection: function (markerOptions) {
  4650. var xCenter = markerOptions.align !== 'left' &&
  4651. markerOptions.align !== 'right',
  4652. yCenter = markerOptions.verticalAlign !== 'top' &&
  4653. markerOptions.verticalAlign !== 'bottom',
  4654. undef;
  4655. return xCenter ?
  4656. (yCenter ? undef : false) : // x is centered
  4657. (yCenter ? true : undef); // x is off-center
  4658. }
  4659. };
  4660. // Add to Highcharts namespace
  4661. H.Connection = Connection;
  4662. H.Pathfinder = Pathfinder;
  4663. // Add pathfinding capabilities to Points
  4664. extend(H.Point.prototype, /** @lends Point.prototype */ {
  4665. /**
  4666. * Get coordinates of anchor point for pathfinder connection.
  4667. *
  4668. * @private
  4669. * @function Highcharts.Point#getPathfinderAnchorPoint
  4670. *
  4671. * @param {Highcharts.ConnectorsMarkerOptions} markerOptions
  4672. * Connection options for position on point.
  4673. *
  4674. * @return {object}
  4675. * An object with x/y properties for the position. Coordinates are
  4676. * in plot values, not relative to point.
  4677. */
  4678. getPathfinderAnchorPoint: function (markerOptions) {
  4679. var bb = getPointBB(this),
  4680. x,
  4681. y;
  4682. switch (markerOptions.align) { // eslint-disable-line default-case
  4683. case 'right':
  4684. x = 'xMax';
  4685. break;
  4686. case 'left':
  4687. x = 'xMin';
  4688. }
  4689. switch (markerOptions.verticalAlign) { // eslint-disable-line default-case
  4690. case 'top':
  4691. y = 'yMin';
  4692. break;
  4693. case 'bottom':
  4694. y = 'yMax';
  4695. }
  4696. return {
  4697. x: x ? bb[x] : (bb.xMin + bb.xMax) / 2,
  4698. y: y ? bb[y] : (bb.yMin + bb.yMax) / 2
  4699. };
  4700. },
  4701. /**
  4702. * Utility to get the angle from one point to another.
  4703. *
  4704. * @private
  4705. * @function Highcharts.Point#getRadiansToVector
  4706. *
  4707. * @param {object} v1
  4708. * The first vector, as an object with x/y properties.
  4709. *
  4710. * @param {object} v2
  4711. * The second vector, as an object with x/y properties.
  4712. *
  4713. * @return {number}
  4714. * The angle in degrees
  4715. */
  4716. getRadiansToVector: function (v1, v2) {
  4717. var box;
  4718. if (!defined(v2)) {
  4719. box = getPointBB(this);
  4720. v2 = {
  4721. x: (box.xMin + box.xMax) / 2,
  4722. y: (box.yMin + box.yMax) / 2
  4723. };
  4724. }
  4725. return Math.atan2(v2.y - v1.y, v1.x - v2.x);
  4726. },
  4727. /**
  4728. * Utility to get the position of the marker, based on the path angle and
  4729. * the marker's radius.
  4730. *
  4731. * @private
  4732. * @function Highcharts.Point#getMarkerVector
  4733. *
  4734. * @param {number} radians
  4735. * The angle in radians from the point center to another vector.
  4736. *
  4737. * @param {number} markerRadius
  4738. * The radius of the marker, to calculate the additional distance to
  4739. * the center of the marker.
  4740. *
  4741. * @param {object} anchor
  4742. * The anchor point of the path and marker as an object with x/y
  4743. * properties.
  4744. *
  4745. * @return {object}
  4746. * The marker vector as an object with x/y properties.
  4747. */
  4748. getMarkerVector: function (radians, markerRadius, anchor) {
  4749. var twoPI = Math.PI * 2.0,
  4750. theta = radians,
  4751. bb = getPointBB(this),
  4752. rectWidth = bb.xMax - bb.xMin,
  4753. rectHeight = bb.yMax - bb.yMin,
  4754. rAtan = Math.atan2(rectHeight, rectWidth),
  4755. tanTheta = 1,
  4756. leftOrRightRegion = false,
  4757. rectHalfWidth = rectWidth / 2.0,
  4758. rectHalfHeight = rectHeight / 2.0,
  4759. rectHorizontalCenter = bb.xMin + rectHalfWidth,
  4760. rectVerticalCenter = bb.yMin + rectHalfHeight,
  4761. edgePoint = {
  4762. x: rectHorizontalCenter,
  4763. y: rectVerticalCenter
  4764. },
  4765. markerPoint = {},
  4766. xFactor = 1,
  4767. yFactor = 1;
  4768. while (theta < -Math.PI) {
  4769. theta += twoPI;
  4770. }
  4771. while (theta > Math.PI) {
  4772. theta -= twoPI;
  4773. }
  4774. tanTheta = Math.tan(theta);
  4775. if ((theta > -rAtan) && (theta <= rAtan)) {
  4776. // Right side
  4777. yFactor = -1;
  4778. leftOrRightRegion = true;
  4779. } else if (theta > rAtan && theta <= (Math.PI - rAtan)) {
  4780. // Top side
  4781. yFactor = -1;
  4782. } else if (theta > (Math.PI - rAtan) || theta <= -(Math.PI - rAtan)) {
  4783. // Left side
  4784. xFactor = -1;
  4785. leftOrRightRegion = true;
  4786. } else {
  4787. // Bottom side
  4788. xFactor = -1;
  4789. }
  4790. // Correct the edgePoint according to the placement of the marker
  4791. if (leftOrRightRegion) {
  4792. edgePoint.x += xFactor * (rectHalfWidth);
  4793. edgePoint.y += yFactor * (rectHalfWidth) * tanTheta;
  4794. } else {
  4795. edgePoint.x += xFactor * (rectHeight / (2.0 * tanTheta));
  4796. edgePoint.y += yFactor * (rectHalfHeight);
  4797. }
  4798. if (anchor.x !== rectHorizontalCenter) {
  4799. edgePoint.x = anchor.x;
  4800. }
  4801. if (anchor.y !== rectVerticalCenter) {
  4802. edgePoint.y = anchor.y;
  4803. }
  4804. markerPoint.x = edgePoint.x + (markerRadius * Math.cos(theta));
  4805. markerPoint.y = edgePoint.y - (markerRadius * Math.sin(theta));
  4806. return markerPoint;
  4807. }
  4808. });
  4809. // Warn if using legacy options. Copy the options over. Note that this will
  4810. // still break if using the legacy options in chart.update, addSeries etc.
  4811. function warnLegacy(chart) {
  4812. if (
  4813. chart.options.pathfinder ||
  4814. chart.series.reduce(function (acc, series) {
  4815. if (series.options) {
  4816. merge(
  4817. true,
  4818. (
  4819. series.options.connectors = series.options.connectors ||
  4820. {}
  4821. ), series.options.pathfinder
  4822. );
  4823. }
  4824. return acc || series.options && series.options.pathfinder;
  4825. }, false)
  4826. ) {
  4827. merge(
  4828. true,
  4829. (chart.options.connectors = chart.options.connectors || {}),
  4830. chart.options.pathfinder
  4831. );
  4832. H.error('WARNING: Pathfinder options have been renamed. ' +
  4833. 'Use "chart.connectors" or "series.connectors" instead.');
  4834. }
  4835. }
  4836. // Initialize Pathfinder for charts
  4837. H.Chart.prototype.callbacks.push(function (chart) {
  4838. var options = chart.options;
  4839. if (options.connectors.enabled !== false) {
  4840. warnLegacy(chart);
  4841. this.pathfinder = new Pathfinder(this);
  4842. this.pathfinder.update(true); // First draw, defer render
  4843. }
  4844. });
  4845. }(Highcharts, algorithms));
  4846. (function (H) {
  4847. /* *
  4848. * X-range series module
  4849. *
  4850. * (c) 2010-2019 Torstein Honsi, Lars A. V. Cabrera
  4851. *
  4852. * License: www.highcharts.com/license
  4853. */
  4854. var addEvent = H.addEvent,
  4855. defined = H.defined,
  4856. color = H.Color,
  4857. columnType = H.seriesTypes.column,
  4858. correctFloat = H.correctFloat,
  4859. isNumber = H.isNumber,
  4860. isObject = H.isObject,
  4861. merge = H.merge,
  4862. pick = H.pick,
  4863. seriesType = H.seriesType,
  4864. seriesTypes = H.seriesTypes,
  4865. Axis = H.Axis,
  4866. Point = H.Point,
  4867. Series = H.Series;
  4868. /**
  4869. * Return color of a point based on its category.
  4870. *
  4871. * @private
  4872. * @function getColorByCategory
  4873. *
  4874. * @param {object} series
  4875. * The series which the point belongs to.
  4876. *
  4877. * @param {object} point
  4878. * The point to calculate its color for.
  4879. *
  4880. * @return {object}
  4881. * Returns an object containing the properties color and colorIndex.
  4882. */
  4883. function getColorByCategory(series, point) {
  4884. var colors = series.options.colors || series.chart.options.colors,
  4885. colorCount = colors ?
  4886. colors.length :
  4887. series.chart.options.chart.colorCount,
  4888. colorIndex = point.y % colorCount,
  4889. color = colors && colors[colorIndex];
  4890. return {
  4891. colorIndex: colorIndex,
  4892. color: color
  4893. };
  4894. }
  4895. /**
  4896. * @private
  4897. * @class
  4898. * @name Highcharts.seriesTypes.xrange
  4899. *
  4900. * @augments Highcharts.Series
  4901. */
  4902. seriesType('xrange', 'column'
  4903. /**
  4904. * The X-range series displays ranges on the X axis, typically time intervals
  4905. * with a start and end date.
  4906. *
  4907. * @sample {highcharts} highcharts/demo/x-range/
  4908. * X-range
  4909. * @sample {highcharts} highcharts/css/x-range/
  4910. * Styled mode X-range
  4911. * @sample {highcharts} highcharts/chart/inverted-xrange/
  4912. * Inverted X-range
  4913. *
  4914. * @extends plotOptions.column
  4915. * @since 6.0.0
  4916. * @product highcharts highstock gantt
  4917. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor,
  4918. * edgeWidth, findNearestPointBy, getExtremesFromAll,
  4919. * negativeColor, pointInterval, pointIntervalUnit,
  4920. * pointPlacement, pointRange, pointStart, softThreshold,
  4921. * stacking, threshold, data
  4922. * @optionparent plotOptions.xrange
  4923. */
  4924. , {
  4925. /**
  4926. * A partial fill for each point, typically used to visualize how much of
  4927. * a task is performed. The partial fill object can be set either on series
  4928. * or point level.
  4929. *
  4930. * @sample {highcharts} highcharts/demo/x-range
  4931. * X-range with partial fill
  4932. *
  4933. * @product highcharts highstock gantt
  4934. * @apioption plotOptions.xrange.partialFill
  4935. */
  4936. /**
  4937. * The fill color to be used for partial fills. Defaults to a darker shade
  4938. * of the point color.
  4939. *
  4940. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  4941. * @product highcharts highstock gantt
  4942. * @apioption plotOptions.xrange.partialFill.fill
  4943. */
  4944. /**
  4945. * A partial fill for each point, typically used to visualize how much of
  4946. * a task is performed. See [completed](series.gantt.data.completed).
  4947. *
  4948. * @sample gantt/demo/progress-indicator
  4949. * Gantt with progress indicator
  4950. *
  4951. * @product gantt
  4952. * @apioption plotOptions.gantt.partialFill
  4953. */
  4954. /**
  4955. * In an X-range series, this option makes all points of the same Y-axis
  4956. * category the same color.
  4957. */
  4958. colorByPoint: true,
  4959. dataLabels: {
  4960. verticalAlign: 'middle',
  4961. inside: true,
  4962. /**
  4963. * The default formatter for X-range data labels displays the percentage
  4964. * of the partial fill amount.
  4965. *
  4966. * @type {Highcharts.FormatterCallbackFunction<Highcharts.SeriesDataLabelsFormatterContextObject>}
  4967. * @default function () { return (amount * 100) + '%'; }
  4968. */
  4969. formatter: function () {
  4970. var point = this.point,
  4971. amount = point.partialFill;
  4972. if (isObject(amount)) {
  4973. amount = amount.amount;
  4974. }
  4975. if (!defined(amount)) {
  4976. amount = 0;
  4977. }
  4978. return correctFloat(amount * 100) + '%';
  4979. }
  4980. },
  4981. tooltip: {
  4982. headerFormat: '<span style="font-size: 10px">{point.x} - {point.x2}</span><br/>',
  4983. pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
  4984. },
  4985. borderRadius: 3,
  4986. pointRange: 0
  4987. }, {
  4988. type: 'xrange',
  4989. parallelArrays: ['x', 'x2', 'y'],
  4990. requireSorting: false,
  4991. animate: seriesTypes.line.prototype.animate,
  4992. cropShoulder: 1,
  4993. getExtremesFromAll: true,
  4994. autoIncrement: H.noop,
  4995. /**
  4996. * Borrow the column series metrics, but with swapped axes. This gives free
  4997. * access to features like groupPadding, grouping, pointWidth etc.
  4998. *
  4999. * @private
  5000. * @function Higcharts.Series#getColumnMetrics
  5001. *
  5002. * @return {Highcharts.ColumnMetricsObject}
  5003. */
  5004. getColumnMetrics: function () {
  5005. var metrics,
  5006. chart = this.chart;
  5007. function swapAxes() {
  5008. chart.series.forEach(function (s) {
  5009. var xAxis = s.xAxis;
  5010. s.xAxis = s.yAxis;
  5011. s.yAxis = xAxis;
  5012. });
  5013. }
  5014. swapAxes();
  5015. metrics = columnType.prototype.getColumnMetrics.call(this);
  5016. swapAxes();
  5017. return metrics;
  5018. },
  5019. /**
  5020. * Override cropData to show a point where x or x2 is outside visible range,
  5021. * but one of them is inside.
  5022. *
  5023. * @private
  5024. * @function Highcharts.Series#cropData
  5025. *
  5026. * @param {Array<number>} xData
  5027. *
  5028. * @param {Array<number>} yData
  5029. *
  5030. * @param {number} min
  5031. *
  5032. * @param {number} max
  5033. *
  5034. * @param {number} [cropShoulder]
  5035. *
  5036. * @return {*}
  5037. */
  5038. cropData: function (xData, yData, min, max) {
  5039. // Replace xData with x2Data to find the appropriate cropStart
  5040. var cropData = Series.prototype.cropData,
  5041. crop = cropData.call(this, this.x2Data, yData, min, max);
  5042. // Re-insert the cropped xData
  5043. crop.xData = xData.slice(crop.start, crop.end);
  5044. return crop;
  5045. },
  5046. /**
  5047. * @private
  5048. * @function Highcharts.Series#translatePoint
  5049. *
  5050. * @param {Highcharts.Point} point
  5051. */
  5052. translatePoint: function (point) {
  5053. var series = this,
  5054. xAxis = series.xAxis,
  5055. yAxis = series.yAxis,
  5056. metrics = series.columnMetrics,
  5057. options = series.options,
  5058. minPointLength = options.minPointLength || 0,
  5059. plotX = point.plotX,
  5060. posX = pick(point.x2, point.x + (point.len || 0)),
  5061. plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
  5062. length = Math.abs(plotX2 - plotX),
  5063. widthDifference,
  5064. shapeArgs,
  5065. partialFill,
  5066. inverted = this.chart.inverted,
  5067. borderWidth = pick(options.borderWidth, 1),
  5068. crisper = borderWidth % 2 / 2,
  5069. yOffset = metrics.offset,
  5070. pointHeight = Math.round(metrics.width),
  5071. dlLeft,
  5072. dlRight,
  5073. dlWidth;
  5074. if (minPointLength) {
  5075. widthDifference = minPointLength - length;
  5076. if (widthDifference < 0) {
  5077. widthDifference = 0;
  5078. }
  5079. plotX -= widthDifference / 2;
  5080. plotX2 += widthDifference / 2;
  5081. }
  5082. plotX = Math.max(plotX, -10);
  5083. plotX2 = Math.min(Math.max(plotX2, -10), xAxis.len + 10);
  5084. // Handle individual pointWidth
  5085. if (defined(point.options.pointWidth)) {
  5086. yOffset -= (
  5087. (Math.ceil(point.options.pointWidth) - pointHeight) / 2
  5088. );
  5089. pointHeight = Math.ceil(point.options.pointWidth);
  5090. }
  5091. // Apply pointPlacement to the Y axis
  5092. if (
  5093. options.pointPlacement &&
  5094. isNumber(point.plotY) &&
  5095. yAxis.categories
  5096. ) {
  5097. point.plotY = yAxis
  5098. .translate(point.y, 0, 1, 0, 1, options.pointPlacement);
  5099. }
  5100. point.shapeArgs = {
  5101. x: Math.floor(Math.min(plotX, plotX2)) + crisper,
  5102. y: Math.floor(point.plotY + yOffset) + crisper,
  5103. width: Math.round(Math.abs(plotX2 - plotX)),
  5104. height: pointHeight,
  5105. r: series.options.borderRadius
  5106. };
  5107. // Align data labels inside the shape and inside the plot area
  5108. dlLeft = point.shapeArgs.x;
  5109. dlRight = dlLeft + point.shapeArgs.width;
  5110. if (dlLeft < 0 || dlRight > xAxis.len) {
  5111. dlLeft = Math.min(xAxis.len, Math.max(0, dlLeft));
  5112. dlRight = Math.max(0, Math.min(dlRight, xAxis.len));
  5113. dlWidth = dlRight - dlLeft;
  5114. point.dlBox = merge(point.shapeArgs, {
  5115. x: dlLeft,
  5116. width: dlRight - dlLeft,
  5117. centerX: dlWidth ? dlWidth / 2 : null
  5118. });
  5119. } else {
  5120. point.dlBox = null;
  5121. }
  5122. // Tooltip position
  5123. if (!inverted) {
  5124. point.tooltipPos[0] += length / 2 * (xAxis.reversed ? -1 : 1);
  5125. point.tooltipPos[1] -= metrics.width / 2;
  5126. // Limit position by the correct axis size (#9727)
  5127. point.tooltipPos[0] = Math.max(
  5128. Math.min(point.tooltipPos[0], xAxis.len - 1), 0
  5129. );
  5130. point.tooltipPos[1] = Math.max(
  5131. Math.min(point.tooltipPos[1], yAxis.len - 1), 0
  5132. );
  5133. } else {
  5134. point.tooltipPos[1] += length / 2 * (xAxis.reversed ? 1 : -1);
  5135. point.tooltipPos[0] += metrics.width / 2;
  5136. // Limit position by the correct axis size (#9727)
  5137. point.tooltipPos[1] = Math.max(
  5138. Math.min(point.tooltipPos[1], xAxis.len - 1), 0
  5139. );
  5140. point.tooltipPos[0] = Math.max(
  5141. Math.min(point.tooltipPos[0], yAxis.len - 1), 0
  5142. );
  5143. }
  5144. // Add a partShapeArgs to the point, based on the shapeArgs property
  5145. partialFill = point.partialFill;
  5146. if (partialFill) {
  5147. // Get the partial fill amount
  5148. if (isObject(partialFill)) {
  5149. partialFill = partialFill.amount;
  5150. }
  5151. // If it was not a number, assume 0
  5152. if (!isNumber(partialFill)) {
  5153. partialFill = 0;
  5154. }
  5155. shapeArgs = point.shapeArgs;
  5156. point.partShapeArgs = {
  5157. x: shapeArgs.x,
  5158. y: shapeArgs.y,
  5159. width: shapeArgs.width,
  5160. height: shapeArgs.height,
  5161. r: series.options.borderRadius
  5162. };
  5163. point.clipRectArgs = {
  5164. x: shapeArgs.x,
  5165. y: shapeArgs.y,
  5166. width: Math.max(
  5167. Math.round(
  5168. length * partialFill +
  5169. (point.plotX - plotX)
  5170. ),
  5171. 0
  5172. ),
  5173. height: shapeArgs.height
  5174. };
  5175. }
  5176. },
  5177. /**
  5178. * @private
  5179. * @function Highcharts.Series#translate
  5180. */
  5181. translate: function () {
  5182. columnType.prototype.translate.apply(this, arguments);
  5183. this.points.forEach(function (point) {
  5184. this.translatePoint(point);
  5185. }, this);
  5186. },
  5187. /**
  5188. * Draws a single point in the series. Needed for partial fill.
  5189. *
  5190. * This override turns point.graphic into a group containing the original
  5191. * graphic and an overlay displaying the partial fill.
  5192. *
  5193. * @private
  5194. * @function Highcharts.Series#drawPoint
  5195. *
  5196. * @param {Highcharts.Point} point
  5197. * An instance of Point in the series.
  5198. *
  5199. * @param {"animate"|"attr"} verb
  5200. * 'animate' (animates changes) or 'attr' (sets options)
  5201. */
  5202. drawPoint: function (point, verb) {
  5203. var series = this,
  5204. seriesOpts = series.options,
  5205. renderer = series.chart.renderer,
  5206. graphic = point.graphic,
  5207. type = point.shapeType,
  5208. shapeArgs = point.shapeArgs,
  5209. partShapeArgs = point.partShapeArgs,
  5210. clipRectArgs = point.clipRectArgs,
  5211. pfOptions = point.partialFill,
  5212. fill,
  5213. state = point.selected && 'select',
  5214. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius;
  5215. if (!point.isNull) {
  5216. // Original graphic
  5217. if (graphic) { // update
  5218. point.graphicOriginal[verb](
  5219. merge(shapeArgs)
  5220. );
  5221. } else {
  5222. point.graphic = graphic = renderer.g('point')
  5223. .addClass(point.getClassName())
  5224. .add(point.group || series.group);
  5225. point.graphicOriginal = renderer[type](shapeArgs)
  5226. .addClass(point.getClassName())
  5227. .addClass('highcharts-partfill-original')
  5228. .add(graphic);
  5229. }
  5230. // Partial fill graphic
  5231. if (partShapeArgs) {
  5232. if (point.graphicOverlay) {
  5233. point.graphicOverlay[verb](
  5234. merge(partShapeArgs)
  5235. );
  5236. point.clipRect.animate(
  5237. merge(clipRectArgs)
  5238. );
  5239. } else {
  5240. point.clipRect = renderer.clipRect(
  5241. clipRectArgs.x,
  5242. clipRectArgs.y,
  5243. clipRectArgs.width,
  5244. clipRectArgs.height
  5245. );
  5246. point.graphicOverlay = renderer[type](partShapeArgs)
  5247. .addClass('highcharts-partfill-overlay')
  5248. .add(graphic)
  5249. .clip(point.clipRect);
  5250. }
  5251. }
  5252. // Presentational
  5253. if (!series.chart.styledMode) {
  5254. point.graphicOriginal
  5255. .attr(series.pointAttribs(point, state))
  5256. .shadow(seriesOpts.shadow, null, cutOff);
  5257. if (partShapeArgs) {
  5258. // Ensure pfOptions is an object
  5259. if (!isObject(pfOptions)) {
  5260. pfOptions = {};
  5261. }
  5262. if (isObject(seriesOpts.partialFill)) {
  5263. pfOptions = merge(
  5264. pfOptions, seriesOpts.partialFill
  5265. );
  5266. }
  5267. fill = (
  5268. pfOptions.fill ||
  5269. color(point.color || series.color).brighten(-0.3).get()
  5270. );
  5271. point.graphicOverlay
  5272. .attr(series.pointAttribs(point, state))
  5273. .attr({
  5274. 'fill': fill
  5275. })
  5276. .shadow(seriesOpts.shadow, null, cutOff);
  5277. }
  5278. }
  5279. } else if (graphic) {
  5280. point.graphic = graphic.destroy(); // #1269
  5281. }
  5282. },
  5283. /**
  5284. * @private
  5285. * @function Highcharts.Series#drawPoints
  5286. */
  5287. drawPoints: function () {
  5288. var series = this,
  5289. verb = series.getAnimationVerb();
  5290. // Draw the columns
  5291. series.points.forEach(function (point) {
  5292. series.drawPoint(point, verb);
  5293. });
  5294. },
  5295. /**
  5296. * Returns "animate", or "attr" if the number of points is above the
  5297. * animation limit.
  5298. *
  5299. * @private
  5300. * @function Highcharts.Series#getAnimationVerb
  5301. *
  5302. * @return {string}
  5303. */
  5304. getAnimationVerb: function () {
  5305. return (
  5306. this.chart.pointCount < (this.options.animationLimit || 250) ?
  5307. 'animate' :
  5308. 'attr'
  5309. );
  5310. }
  5311. /*
  5312. // Override to remove stroke from points. For partial fill.
  5313. pointAttribs: function () {
  5314. var series = this,
  5315. retVal = columnType.prototype.pointAttribs.apply(series, arguments);
  5316. //retVal['stroke-width'] = 0;
  5317. return retVal;
  5318. }
  5319. //*/
  5320. }, { // Point class properties
  5321. /**
  5322. * Extend applyOptions so that `colorByPoint` for x-range means that one
  5323. * color is applied per Y axis category.
  5324. *
  5325. * @private
  5326. * @function Highcharts.Point#applyOptions
  5327. *
  5328. * @return {Highcharts.Series}
  5329. */
  5330. applyOptions: function () {
  5331. var point = Point.prototype.applyOptions.apply(this, arguments),
  5332. series = point.series,
  5333. colorByPoint;
  5334. if (series.options.colorByPoint && !point.options.color) {
  5335. colorByPoint = getColorByCategory(series, point);
  5336. if (!series.chart.styledMode) {
  5337. point.color = colorByPoint.color;
  5338. }
  5339. if (!point.options.colorIndex) {
  5340. point.colorIndex = colorByPoint.colorIndex;
  5341. }
  5342. }
  5343. return point;
  5344. },
  5345. /**
  5346. * Extend init to have y default to 0.
  5347. *
  5348. * @private
  5349. * @function Highcharts.Point#init
  5350. *
  5351. * @return {Highcharts.Series}
  5352. */
  5353. init: function () {
  5354. Point.prototype.init.apply(this, arguments);
  5355. if (!this.y) {
  5356. this.y = 0;
  5357. }
  5358. return this;
  5359. },
  5360. /**
  5361. * @private
  5362. * @function Highcharts.Point#setState
  5363. */
  5364. setState: function () {
  5365. Point.prototype.setState.apply(this, arguments);
  5366. this.series.drawPoint(this, this.series.getAnimationVerb());
  5367. },
  5368. /**
  5369. * @private
  5370. * @function Highcharts.Point#getLabelConfig
  5371. *
  5372. * @return {Highcharts.PointLabelObject}
  5373. */
  5374. // Add x2 and yCategory to the available properties for tooltip formats
  5375. getLabelConfig: function () {
  5376. var point = this,
  5377. cfg = Point.prototype.getLabelConfig.call(point),
  5378. yCats = point.series.yAxis.categories;
  5379. cfg.x2 = point.x2;
  5380. cfg.yCategory = point.yCategory = yCats && yCats[point.y];
  5381. return cfg;
  5382. },
  5383. tooltipDateKeys: ['x', 'x2'],
  5384. /**
  5385. * @private
  5386. * @function Highcharts.Point#isValid
  5387. *
  5388. * @return {boolean}
  5389. */
  5390. isValid: function () {
  5391. return typeof this.x === 'number' &&
  5392. typeof this.x2 === 'number';
  5393. }
  5394. });
  5395. // Max x2 should be considered in xAxis extremes
  5396. addEvent(Axis, 'afterGetSeriesExtremes', function () {
  5397. var axis = this,
  5398. axisSeries = axis.series,
  5399. dataMax,
  5400. modMax;
  5401. if (axis.isXAxis) {
  5402. dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
  5403. axisSeries.forEach(function (series) {
  5404. if (series.x2Data) {
  5405. series.x2Data.forEach(function (val) {
  5406. if (val > dataMax) {
  5407. dataMax = val;
  5408. modMax = true;
  5409. }
  5410. });
  5411. }
  5412. });
  5413. if (modMax) {
  5414. axis.dataMax = dataMax;
  5415. }
  5416. }
  5417. });
  5418. /**
  5419. * An `xrange` series. If the [type](#series.xrange.type) option is not
  5420. * specified, it is inherited from [chart.type](#chart.type).
  5421. *
  5422. * @extends series,plotOptions.xrange
  5423. * @excluding boostThreshold, crisp, cropThreshold, depth, edgeColor, edgeWidth,
  5424. * findNearestPointBy, getExtremesFromAll, negativeColor,
  5425. * pointInterval, pointIntervalUnit, pointPlacement, pointRange,
  5426. * pointStart, softThreshold, stacking, threshold
  5427. * @product highcharts highstock gantt
  5428. * @apioption series.xrange
  5429. */
  5430. /**
  5431. * An array of data points for the series. For the `xrange` series type,
  5432. * points can be given in the following ways:
  5433. *
  5434. * 1. An array of objects with named values. The objects are point configuration
  5435. * objects as seen below.
  5436. * ```js
  5437. * data: [{
  5438. * x: Date.UTC(2017, 0, 1),
  5439. * x2: Date.UTC(2017, 0, 3),
  5440. * name: "Test",
  5441. * y: 0,
  5442. * color: "#00FF00"
  5443. * }, {
  5444. * x: Date.UTC(2017, 0, 4),
  5445. * x2: Date.UTC(2017, 0, 5),
  5446. * name: "Deploy",
  5447. * y: 1,
  5448. * color: "#FF0000"
  5449. * }]
  5450. * ```
  5451. *
  5452. * @sample {highcharts} highcharts/series/data-array-of-objects/
  5453. * Config objects
  5454. *
  5455. * @type {Array<*>}
  5456. * @extends series.line.data
  5457. * @product highcharts highstock gantt
  5458. * @apioption series.xrange.data
  5459. */
  5460. /**
  5461. * The starting X value of the range point.
  5462. *
  5463. * @sample {highcharts} highcharts/demo/x-range
  5464. * X-range
  5465. *
  5466. * @type {number}
  5467. * @product highcharts highstock gantt
  5468. * @apioption series.xrange.data.x
  5469. */
  5470. /**
  5471. * The ending X value of the range point.
  5472. *
  5473. * @sample {highcharts} highcharts/demo/x-range
  5474. * X-range
  5475. *
  5476. * @type {number}
  5477. * @product highcharts highstock gantt
  5478. * @apioption series.xrange.data.x2
  5479. */
  5480. /**
  5481. * The Y value of the range point.
  5482. *
  5483. * @sample {highcharts} highcharts/demo/x-range
  5484. * X-range
  5485. *
  5486. * @type {number}
  5487. * @product highcharts highstock gantt
  5488. * @apioption series.xrange.data.y
  5489. */
  5490. /**
  5491. * A partial fill for each point, typically used to visualize how much of
  5492. * a task is performed. The partial fill object can be set either on series
  5493. * or point level.
  5494. *
  5495. * @sample {highcharts} highcharts/demo/x-range
  5496. * X-range with partial fill
  5497. *
  5498. * @product highcharts highstock gantt
  5499. * @apioption series.xrange.data.partialFill
  5500. */
  5501. /**
  5502. * The amount of the X-range point to be filled. Values can be 0-1 and are
  5503. * converted to percentages in the default data label formatter.
  5504. *
  5505. * @type {number}
  5506. * @product highcharts highstock gantt
  5507. * @apioption series.xrange.data.partialFill.amount
  5508. */
  5509. /**
  5510. * The fill color to be used for partial fills. Defaults to a darker shade
  5511. * of the point color.
  5512. *
  5513. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5514. * @product highcharts highstock gantt
  5515. * @apioption series.xrange.data.partialFill.fill
  5516. */
  5517. }(Highcharts));
  5518. (function (H) {
  5519. /* *
  5520. *
  5521. * (c) 2016-2019 Highsoft AS
  5522. *
  5523. * Author: Lars A. V. Cabrera
  5524. *
  5525. * License: www.highcharts.com/license
  5526. *
  5527. * */
  5528. var dateFormat = H.dateFormat,
  5529. isObject = H.isObject,
  5530. isNumber = H.isNumber,
  5531. merge = H.merge,
  5532. pick = H.pick,
  5533. seriesType = H.seriesType,
  5534. seriesTypes = H.seriesTypes,
  5535. stop = H.stop,
  5536. Series = H.Series,
  5537. parent = seriesTypes.xrange;
  5538. /**
  5539. * @private
  5540. * @class
  5541. * @name Highcharts.seriesTypes.gantt
  5542. *
  5543. * @augments Highcharts.Series
  5544. */
  5545. seriesType('gantt', 'xrange'
  5546. /**
  5547. * A `gantt` series. If the [type](#series.gantt.type) option is not specified,
  5548. * it is inherited from [chart.type](#chart.type).
  5549. *
  5550. * @extends plotOptions.xrange
  5551. * @product gantt
  5552. * @optionparent plotOptions.gantt
  5553. */
  5554. , {
  5555. // options - default options merged with parent
  5556. grouping: false,
  5557. dataLabels: {
  5558. enabled: true,
  5559. formatter: function () {
  5560. var point = this,
  5561. amount = point.point.partialFill;
  5562. if (isObject(amount)) {
  5563. amount = amount.amount;
  5564. }
  5565. if (isNumber(amount) && amount > 0) {
  5566. return (amount * 100) + '%';
  5567. }
  5568. }
  5569. },
  5570. tooltip: {
  5571. headerFormat: '<span style="font-size: 10px">{series.name}</span><br/>',
  5572. pointFormat: null,
  5573. pointFormatter: function () {
  5574. var point = this,
  5575. series = point.series,
  5576. tooltip = series.chart.tooltip,
  5577. xAxis = series.xAxis,
  5578. options = xAxis.options,
  5579. formats = options.dateTimeLabelFormats,
  5580. startOfWeek = xAxis.options.startOfWeek,
  5581. ttOptions = series.tooltipOptions,
  5582. format = ttOptions.xDateFormat,
  5583. range = point.end ? point.end - point.start : 0,
  5584. start,
  5585. end,
  5586. milestone = point.options.milestone,
  5587. retVal = '<b>' + (point.name || point.yCategory) + '</b>';
  5588. if (ttOptions.pointFormat) {
  5589. return point.tooltipFormatter(ttOptions.pointFormat);
  5590. }
  5591. if (!format) {
  5592. format = H.splat(
  5593. tooltip.getDateFormat(
  5594. range,
  5595. point.start,
  5596. startOfWeek,
  5597. formats
  5598. )
  5599. )[0];
  5600. }
  5601. start = dateFormat(format, point.start);
  5602. end = dateFormat(format, point.end);
  5603. retVal += '<br/>';
  5604. if (!milestone) {
  5605. retVal += 'Start: ' + start + '<br/>';
  5606. retVal += 'End: ' + end + '<br/>';
  5607. } else {
  5608. retVal += 'Date ' + start + '<br/>';
  5609. }
  5610. return retVal;
  5611. }
  5612. },
  5613. connectors: {
  5614. type: 'simpleConnect',
  5615. animation: {
  5616. reversed: true // Dependencies go from child to parent
  5617. },
  5618. startMarker: {
  5619. enabled: true,
  5620. symbol: 'arrow-filled',
  5621. radius: 4,
  5622. fill: '#fa0',
  5623. align: 'left'
  5624. },
  5625. endMarker: {
  5626. enabled: false, // Only show arrow on the dependent task
  5627. align: 'right'
  5628. }
  5629. }
  5630. }, {
  5631. // props - series member overrides
  5632. pointArrayMap: ['start', 'end', 'y'],
  5633. // Keyboard navigation, don't use nearest vertical mode
  5634. keyboardMoveVertical: false,
  5635. // Handle milestones, as they have no x2
  5636. translatePoint: function (point) {
  5637. var series = this,
  5638. shapeArgs,
  5639. size;
  5640. parent.prototype.translatePoint.call(series, point);
  5641. if (point.options.milestone) {
  5642. shapeArgs = point.shapeArgs;
  5643. size = shapeArgs.height;
  5644. point.shapeArgs = {
  5645. x: shapeArgs.x - (size / 2),
  5646. y: shapeArgs.y,
  5647. width: size,
  5648. height: size
  5649. };
  5650. }
  5651. },
  5652. /**
  5653. * Draws a single point in the series.
  5654. *
  5655. * This override draws the point as a diamond if point.options.milestone is
  5656. * true, and uses the original drawPoint() if it is false or not set.
  5657. *
  5658. * @requires module:highcharts-gantt
  5659. *
  5660. * @private
  5661. * @function Highcharts.seriesTypes.gantt#drawPoint
  5662. *
  5663. * @param {Highcharts.Point} point
  5664. * An instance of Point in the series
  5665. *
  5666. * @param {"animate"|"attr"} verb
  5667. * 'animate' (animates changes) or 'attr' (sets options)
  5668. */
  5669. drawPoint: function (point, verb) {
  5670. var series = this,
  5671. seriesOpts = series.options,
  5672. renderer = series.chart.renderer,
  5673. shapeArgs = point.shapeArgs,
  5674. plotY = point.plotY,
  5675. graphic = point.graphic,
  5676. state = point.selected && 'select',
  5677. cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
  5678. diamondShape;
  5679. if (point.options.milestone) {
  5680. if (isNumber(plotY) && point.y !== null) {
  5681. diamondShape = renderer.symbols.diamond(
  5682. shapeArgs.x,
  5683. shapeArgs.y,
  5684. shapeArgs.width,
  5685. shapeArgs.height
  5686. );
  5687. if (graphic) {
  5688. stop(graphic);
  5689. graphic[verb]({
  5690. d: diamondShape
  5691. });
  5692. } else {
  5693. point.graphic = graphic = renderer.path(diamondShape)
  5694. .addClass(point.getClassName(), true)
  5695. .add(point.group || series.group);
  5696. }
  5697. // Presentational
  5698. if (!series.chart.styledMode) {
  5699. point.graphic
  5700. .attr(series.pointAttribs(point, state))
  5701. .shadow(seriesOpts.shadow, null, cutOff);
  5702. }
  5703. } else if (graphic) {
  5704. point.graphic = graphic.destroy(); // #1269
  5705. }
  5706. } else {
  5707. parent.prototype.drawPoint.call(series, point, verb);
  5708. }
  5709. },
  5710. setData: Series.prototype.setData,
  5711. setGanttPointAliases: function (options) {
  5712. // Add a value to options if the value exists
  5713. function addIfExists(prop, val) {
  5714. if (val !== undefined) {
  5715. options[prop] = val;
  5716. }
  5717. }
  5718. addIfExists('x', pick(options.start, options.x));
  5719. addIfExists('x2', pick(options.end, options.x2));
  5720. addIfExists(
  5721. 'partialFill', pick(options.completed, options.partialFill)
  5722. );
  5723. addIfExists('connect', pick(options.dependency, options.connect));
  5724. }
  5725. }, merge(parent.prototype.pointClass.prototype, {
  5726. // pointProps - point member overrides. We inherit from parent as well.
  5727. /**
  5728. * Applies the options containing the x and y data and possible some extra
  5729. * properties. This is called on point init or from point.update.
  5730. *
  5731. * @private
  5732. * @function Highcharts.Point#applyOptions
  5733. *
  5734. * @param {object} options
  5735. * The point options
  5736. *
  5737. * @param {number} x
  5738. * The x value
  5739. *
  5740. * @return {Highcharts.Point}
  5741. * The Point instance
  5742. */
  5743. applyOptions: function (options, x) {
  5744. var point = this,
  5745. retVal = merge(options);
  5746. H.seriesTypes.gantt.prototype.setGanttPointAliases(retVal);
  5747. retVal = parent.prototype.pointClass.prototype.applyOptions
  5748. .call(point, retVal, x);
  5749. return retVal;
  5750. }
  5751. }));
  5752. /**
  5753. * A `gantt` series.
  5754. *
  5755. * @extends series,plotOptions.gantt
  5756. * @excluding boostThreshold, connectors, dashStyle, findNearestPointBy,
  5757. * getExtremesFromAll, marker, negativeColor, pointInterval,
  5758. * pointIntervalUnit, pointPlacement, pointStart
  5759. * @product gantt
  5760. * @apioption series.gantt
  5761. */
  5762. /**
  5763. * Data for a Gantt series.
  5764. *
  5765. * @type {Array<*>}
  5766. * @extends series.xrange.data
  5767. * @excluding className, color, colorIndex, connect, dataLabels, events, id,
  5768. * partialFill, selected, x, x2
  5769. * @product gantt
  5770. * @apioption series.gantt.data
  5771. */
  5772. /**
  5773. * Whether the grid node belonging to this point should start as collapsed. Used
  5774. * in axes of type treegrid.
  5775. *
  5776. * @sample {gantt} gantt/treegrid-axis/collapsed/
  5777. * Start as collapsed
  5778. *
  5779. * @type {boolean}
  5780. * @default false
  5781. * @product gantt
  5782. * @apioption series.gantt.data.collapsed
  5783. */
  5784. /**
  5785. * The start time of a task.
  5786. *
  5787. * @type {number}
  5788. * @product gantt
  5789. * @apioption series.gantt.data.start
  5790. */
  5791. /**
  5792. * The end time of a task.
  5793. *
  5794. * @type {number}
  5795. * @product gantt
  5796. * @apioption series.gantt.data.end
  5797. */
  5798. /**
  5799. * The Y value of a task.
  5800. *
  5801. * @type {number}
  5802. * @product gantt
  5803. * @apioption series.gantt.data.y
  5804. */
  5805. /**
  5806. * The name of a task. If a `treegrid` y-axis is used (default in Gantt charts),
  5807. * this will be picked up automatically, and used to calculate the y-value.
  5808. *
  5809. * @type {string}
  5810. * @product gantt
  5811. * @apioption series.gantt.data.name
  5812. */
  5813. /**
  5814. * Progress indicator, how much of the task completed. If it is a number, the
  5815. * `fill` will be applied automatically.
  5816. *
  5817. * @sample {gantt} gantt/demo/progress-indicator
  5818. * Progress indicator
  5819. *
  5820. * @type {number|*}
  5821. * @extends series.xrange.data.partialFill
  5822. * @product gantt
  5823. * @apioption series.gantt.data.completed
  5824. */
  5825. /**
  5826. * The amount of the progress indicator, ranging from 0 (not started) to 1
  5827. * (finished).
  5828. *
  5829. * @type {number}
  5830. * @default 0
  5831. * @apioption series.gantt.data.completed.amount
  5832. */
  5833. /**
  5834. * The fill of the progress indicator. Defaults to a darkened variety of the
  5835. * main color.
  5836. *
  5837. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5838. * @apioption series.gantt.data.completed.fill
  5839. */
  5840. /**
  5841. * The ID of the point (task) that this point depends on in Gantt charts.
  5842. * Aliases [connect](series.xrange.data.connect). Can also be an object,
  5843. * specifying further connecting [options](series.gantt.connectors) between the
  5844. * points. Multiple connections can be specified by providing an array.
  5845. *
  5846. * @sample gantt/demo/project-management
  5847. * Dependencies
  5848. * @sample gantt/pathfinder/demo
  5849. * Different connection types
  5850. *
  5851. * @type {string|Array<string|*>|*}
  5852. * @extends series.xrange.data.connect
  5853. * @since 6.2.0
  5854. * @product gantt
  5855. * @apioption series.gantt.data.dependency
  5856. */
  5857. /**
  5858. * Whether this point is a milestone. If so, only the `start` option is handled,
  5859. * while `end` is ignored.
  5860. *
  5861. * @sample gantt/gantt/milestones
  5862. * Milestones
  5863. *
  5864. * @type {boolean}
  5865. * @since 6.2.0
  5866. * @product gantt
  5867. * @apioption series.gantt.data.milestone
  5868. */
  5869. /**
  5870. * The ID of the parent point (task) of this point in Gantt charts.
  5871. *
  5872. * @sample gantt/demo/subtasks
  5873. * Gantt chart with subtasks
  5874. *
  5875. * @type {string}
  5876. * @since 6.2.0
  5877. * @product gantt
  5878. * @apioption series.gantt.data.parent
  5879. */
  5880. /**
  5881. * @excluding afterAnimate
  5882. * @apioption series.gantt.events
  5883. */
  5884. }(Highcharts));
  5885. (function (H) {
  5886. /* *
  5887. * (c) 2016 Highsoft AS
  5888. * Authors: Lars A. V. Cabrera
  5889. *
  5890. * License: www.highcharts.com/license
  5891. */
  5892. var merge = H.merge,
  5893. splat = H.splat,
  5894. Chart = H.Chart;
  5895. /**
  5896. * Factory function for Gantt charts.
  5897. *
  5898. * @example
  5899. * // Render a chart in to div#container
  5900. * var chart = Highcharts.ganttChart('container', {
  5901. * title: {
  5902. * text: 'My chart'
  5903. * },
  5904. * series: [{
  5905. * data: ...
  5906. * }]
  5907. * });
  5908. *
  5909. * @function Highcharts.ganttChart
  5910. *
  5911. * @param {string|Highcharts.HTMLDOMElement} [renderTo]
  5912. * The DOM element to render to, or its id.
  5913. *
  5914. * @param {Highcharts.Options} options
  5915. * The chart options structure.
  5916. *
  5917. * @param {Highcharts.ChartCallbackFunction} [callback]
  5918. * Function to run when the chart has loaded and and all external images
  5919. * are loaded. Defining a
  5920. * [chart.events.load](https://api.highcharts.com/highcharts/chart.events.load)
  5921. * handler is equivalent.
  5922. *
  5923. * @return {Highcharts.Chart}
  5924. * Returns the Chart object.
  5925. */
  5926. H.ganttChart = function (renderTo, options, callback) {
  5927. var hasRenderToArg = typeof renderTo === 'string' || renderTo.nodeName,
  5928. seriesOptions = options.series,
  5929. defaultOptions = H.getOptions(),
  5930. defaultLinkedTo,
  5931. userOptions = options;
  5932. options = arguments[hasRenderToArg ? 1 : 0];
  5933. // If user hasn't defined axes as array, make it into an array and add a
  5934. // second axis by default.
  5935. if (!H.isArray(options.xAxis)) {
  5936. options.xAxis = [options.xAxis || {}, {}];
  5937. }
  5938. // apply X axis options to both single and multi x axes
  5939. options.xAxis = options.xAxis.map(function (xAxisOptions, i) {
  5940. if (i === 1) { // Second xAxis
  5941. defaultLinkedTo = 0;
  5942. }
  5943. return merge(
  5944. defaultOptions.xAxis,
  5945. { // defaults
  5946. grid: {
  5947. enabled: true
  5948. },
  5949. opposite: true,
  5950. linkedTo: defaultLinkedTo
  5951. },
  5952. xAxisOptions, // user options
  5953. { // forced options
  5954. type: 'datetime'
  5955. }
  5956. );
  5957. });
  5958. // apply Y axis options to both single and multi y axes
  5959. options.yAxis = (splat(options.yAxis || {})).map(function (yAxisOptions) {
  5960. return merge(
  5961. defaultOptions.yAxis, // #3802
  5962. { // defaults
  5963. grid: {
  5964. enabled: true
  5965. },
  5966. staticScale: 50,
  5967. reversed: true,
  5968. // Set default type treegrid, but only if 'categories' is
  5969. // undefined
  5970. type: yAxisOptions.categories ? yAxisOptions.type : 'treegrid'
  5971. },
  5972. yAxisOptions // user options
  5973. );
  5974. });
  5975. options.series = null;
  5976. options = merge(
  5977. true,
  5978. {
  5979. chart: {
  5980. type: 'gantt'
  5981. },
  5982. title: {
  5983. text: null
  5984. },
  5985. legend: {
  5986. enabled: false
  5987. }
  5988. },
  5989. options, // user's options
  5990. // forced options
  5991. {
  5992. isGantt: true
  5993. }
  5994. );
  5995. options.series = userOptions.series = seriesOptions;
  5996. options.series.forEach(function (series) {
  5997. series.data.forEach(function (point) {
  5998. H.seriesTypes.gantt.prototype.setGanttPointAliases(point);
  5999. });
  6000. });
  6001. return hasRenderToArg ?
  6002. new Chart(renderTo, options, callback) :
  6003. new Chart(options, options);
  6004. };
  6005. }(Highcharts));
  6006. return (function () {
  6007. }());
  6008. }));