stock.src.js 396 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681
  1. /**
  2. * @license Highstock JS v8.0.0 (2019-12-10)
  3. *
  4. * Highstock as a plugin for Highcharts
  5. *
  6. * (c) 2010-2019 Torstein Honsi
  7. *
  8. * License: www.highcharts.com/license
  9. */
  10. 'use strict';
  11. (function (factory) {
  12. if (typeof module === 'object' && module.exports) {
  13. factory['default'] = factory;
  14. module.exports = factory;
  15. } else if (typeof define === 'function' && define.amd) {
  16. define('highcharts/modules/stock', ['highcharts'], function (Highcharts) {
  17. factory(Highcharts);
  18. factory.Highcharts = Highcharts;
  19. return factory;
  20. });
  21. } else {
  22. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  23. }
  24. }(function (Highcharts) {
  25. var _modules = Highcharts ? Highcharts._modules : {};
  26. function _registerModule(obj, path, args, fn) {
  27. if (!obj.hasOwnProperty(path)) {
  28. obj[path] = fn.apply(null, args);
  29. }
  30. }
  31. _registerModule(_modules, 'parts/Scrollbar.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  32. /* *
  33. *
  34. * (c) 2010-2019 Torstein Honsi
  35. *
  36. * License: www.highcharts.com/license
  37. *
  38. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  39. *
  40. * */
  41. var correctFloat = U.correctFloat, defined = U.defined, destroyObjectProperties = U.destroyObjectProperties, pick = U.pick;
  42. var addEvent = H.addEvent, Axis = H.Axis, defaultOptions = H.defaultOptions, fireEvent = H.fireEvent, hasTouch = H.hasTouch, isTouchDevice = H.isTouchDevice, merge = H.merge, removeEvent = H.removeEvent, swapXY;
  43. /**
  44. *
  45. * The scrollbar is a means of panning over the X axis of a stock chart.
  46. * Scrollbars can also be applied to other types of axes.
  47. *
  48. * Another approach to scrollable charts is the [chart.scrollablePlotArea](
  49. * https://api.highcharts.com/highcharts/chart.scrollablePlotArea) option that
  50. * is especially suitable for simpler cartesian charts on mobile.
  51. *
  52. * In styled mode, all the presentational options for the
  53. * scrollbar are replaced by the classes `.highcharts-scrollbar-thumb`,
  54. * `.highcharts-scrollbar-arrow`, `.highcharts-scrollbar-button`,
  55. * `.highcharts-scrollbar-rifles` and `.highcharts-scrollbar-track`.
  56. *
  57. * @sample stock/yaxis/inverted-bar-scrollbar/
  58. * A scrollbar on a simple bar chart
  59. *
  60. * @product highstock gantt
  61. * @optionparent scrollbar
  62. */
  63. var defaultScrollbarOptions = {
  64. /**
  65. * The height of the scrollbar. The height also applies to the width
  66. * of the scroll arrows so that they are always squares. Defaults to
  67. * 20 for touch devices and 14 for mouse devices.
  68. *
  69. * @sample stock/scrollbar/height/
  70. * A 30px scrollbar
  71. *
  72. * @type {number}
  73. * @default 20/14
  74. */
  75. height: isTouchDevice ? 20 : 14,
  76. /**
  77. * The border rounding radius of the bar.
  78. *
  79. * @sample stock/scrollbar/style/
  80. * Scrollbar styling
  81. */
  82. barBorderRadius: 0,
  83. /**
  84. * The corner radius of the scrollbar buttons.
  85. *
  86. * @sample stock/scrollbar/style/
  87. * Scrollbar styling
  88. */
  89. buttonBorderRadius: 0,
  90. /**
  91. * Enable or disable the scrollbar.
  92. *
  93. * @sample stock/scrollbar/enabled/
  94. * Disable the scrollbar, only use navigator
  95. *
  96. * @type {boolean}
  97. * @default true
  98. * @apioption scrollbar.enabled
  99. */
  100. /**
  101. * Whether to redraw the main chart as the scrollbar or the navigator
  102. * zoomed window is moved. Defaults to `true` for modern browsers and
  103. * `false` for legacy IE browsers as well as mobile devices.
  104. *
  105. * @sample stock/scrollbar/liveredraw
  106. * Setting live redraw to false
  107. *
  108. * @type {boolean}
  109. * @since 1.3
  110. */
  111. liveRedraw: void 0,
  112. /**
  113. * The margin between the scrollbar and its axis when the scrollbar is
  114. * applied directly to an axis.
  115. */
  116. margin: 10,
  117. /**
  118. * The minimum width of the scrollbar.
  119. *
  120. * @since 1.2.5
  121. */
  122. minWidth: 6,
  123. /**
  124. * Whether to show or hide the scrollbar when the scrolled content is
  125. * zoomed out to it full extent.
  126. *
  127. * @type {boolean}
  128. * @default true
  129. * @apioption scrollbar.showFull
  130. */
  131. step: 0.2,
  132. /**
  133. * The z index of the scrollbar group.
  134. */
  135. zIndex: 3,
  136. /**
  137. * The background color of the scrollbar itself.
  138. *
  139. * @sample stock/scrollbar/style/
  140. * Scrollbar styling
  141. *
  142. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  143. */
  144. barBackgroundColor: '#cccccc',
  145. /**
  146. * The width of the bar's border.
  147. *
  148. * @sample stock/scrollbar/style/
  149. * Scrollbar styling
  150. */
  151. barBorderWidth: 1,
  152. /**
  153. * The color of the scrollbar's border.
  154. *
  155. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  156. */
  157. barBorderColor: '#cccccc',
  158. /**
  159. * The color of the small arrow inside the scrollbar buttons.
  160. *
  161. * @sample stock/scrollbar/style/
  162. * Scrollbar styling
  163. *
  164. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  165. */
  166. buttonArrowColor: '#333333',
  167. /**
  168. * The color of scrollbar buttons.
  169. *
  170. * @sample stock/scrollbar/style/
  171. * Scrollbar styling
  172. *
  173. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  174. */
  175. buttonBackgroundColor: '#e6e6e6',
  176. /**
  177. * The color of the border of the scrollbar buttons.
  178. *
  179. * @sample stock/scrollbar/style/
  180. * Scrollbar styling
  181. *
  182. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  183. */
  184. buttonBorderColor: '#cccccc',
  185. /**
  186. * The border width of the scrollbar buttons.
  187. *
  188. * @sample stock/scrollbar/style/
  189. * Scrollbar styling
  190. */
  191. buttonBorderWidth: 1,
  192. /**
  193. * The color of the small rifles in the middle of the scrollbar.
  194. *
  195. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  196. */
  197. rifleColor: '#333333',
  198. /**
  199. * The color of the track background.
  200. *
  201. * @sample stock/scrollbar/style/
  202. * Scrollbar styling
  203. *
  204. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  205. */
  206. trackBackgroundColor: '#f2f2f2',
  207. /**
  208. * The color of the border of the scrollbar track.
  209. *
  210. * @sample stock/scrollbar/style/
  211. * Scrollbar styling
  212. *
  213. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  214. */
  215. trackBorderColor: '#f2f2f2',
  216. /**
  217. * The corner radius of the border of the scrollbar track.
  218. *
  219. * @sample stock/scrollbar/style/
  220. * Scrollbar styling
  221. *
  222. * @type {number}
  223. * @default 0
  224. * @apioption scrollbar.trackBorderRadius
  225. */
  226. /**
  227. * The width of the border of the scrollbar track.
  228. *
  229. * @sample stock/scrollbar/style/
  230. * Scrollbar styling
  231. */
  232. trackBorderWidth: 1
  233. };
  234. defaultOptions.scrollbar = merge(true, defaultScrollbarOptions, defaultOptions.scrollbar);
  235. /**
  236. * When we have vertical scrollbar, rifles and arrow in buttons should be
  237. * rotated. The same method is used in Navigator's handles, to rotate them.
  238. *
  239. * @function Highcharts.swapXY
  240. *
  241. * @param {Highcharts.SVGPathArray} path
  242. * Path to be rotated.
  243. *
  244. * @param {boolean} [vertical]
  245. * If vertical scrollbar, swap x-y values.
  246. *
  247. * @return {Highcharts.SVGPathArray}
  248. * Rotated path.
  249. */
  250. H.swapXY = swapXY = function (path, vertical) {
  251. var i, len = path.length, temp;
  252. if (vertical) {
  253. for (i = 0; i < len; i += 3) {
  254. temp = path[i + 1];
  255. path[i + 1] = path[i + 2];
  256. path[i + 2] = temp;
  257. }
  258. }
  259. return path;
  260. };
  261. /* eslint-disable no-invalid-this, valid-jsdoc */
  262. /**
  263. * A reusable scrollbar, internally used in Highstock's navigator and optionally
  264. * on individual axes.
  265. *
  266. * @private
  267. * @class
  268. * @name Highcharts.Scrollbar
  269. * @param {Highcharts.SVGRenderer} renderer
  270. * @param {Highcharts.ScrollbarOptions} options
  271. * @param {Highcharts.Chart} chart
  272. */
  273. function Scrollbar(renderer, options, chart) {
  274. this.init(renderer, options, chart);
  275. }
  276. Scrollbar.prototype = {
  277. /**
  278. * @private
  279. * @function Highcharts.Scrollbar#init
  280. * @param {Highcharts.SVGRenderer} renderer
  281. * @param {Highcharts.ScrollbarOptions} options
  282. * @param {Highcharts.Chart} chart
  283. * @return {void}
  284. */
  285. init: function (renderer, options, chart) {
  286. this.scrollbarButtons = [];
  287. this.renderer = renderer;
  288. this.userOptions = options;
  289. this.options = merge(defaultScrollbarOptions, options);
  290. this.chart = chart;
  291. // backward compatibility
  292. this.size = pick(this.options.size, this.options.height);
  293. // Init
  294. if (options.enabled) {
  295. this.render();
  296. this.initEvents();
  297. this.addEvents();
  298. }
  299. },
  300. /**
  301. * Render scrollbar with all required items.
  302. *
  303. * @private
  304. * @function Highcharts.Scrollbar#render
  305. */
  306. render: function () {
  307. var scroller = this, renderer = scroller.renderer, options = scroller.options, size = scroller.size, styledMode = this.chart.styledMode, group;
  308. // Draw the scrollbar group
  309. scroller.group = group = renderer.g('scrollbar').attr({
  310. zIndex: options.zIndex,
  311. translateY: -99999
  312. }).add();
  313. // Draw the scrollbar track:
  314. scroller.track = renderer.rect()
  315. .addClass('highcharts-scrollbar-track')
  316. .attr({
  317. x: 0,
  318. r: options.trackBorderRadius || 0,
  319. height: size,
  320. width: size
  321. }).add(group);
  322. if (!styledMode) {
  323. scroller.track.attr({
  324. fill: options.trackBackgroundColor,
  325. stroke: options.trackBorderColor,
  326. 'stroke-width': options.trackBorderWidth
  327. });
  328. }
  329. this.trackBorderWidth = scroller.track.strokeWidth();
  330. scroller.track.attr({
  331. y: -this.trackBorderWidth % 2 / 2
  332. });
  333. // Draw the scrollbar itself
  334. scroller.scrollbarGroup = renderer.g().add(group);
  335. scroller.scrollbar = renderer.rect()
  336. .addClass('highcharts-scrollbar-thumb')
  337. .attr({
  338. height: size,
  339. width: size,
  340. r: options.barBorderRadius || 0
  341. }).add(scroller.scrollbarGroup);
  342. scroller.scrollbarRifles = renderer
  343. .path(swapXY([
  344. 'M',
  345. -3, size / 4,
  346. 'L',
  347. -3, 2 * size / 3,
  348. 'M',
  349. 0, size / 4,
  350. 'L',
  351. 0, 2 * size / 3,
  352. 'M',
  353. 3, size / 4,
  354. 'L',
  355. 3, 2 * size / 3
  356. ], options.vertical))
  357. .addClass('highcharts-scrollbar-rifles')
  358. .add(scroller.scrollbarGroup);
  359. if (!styledMode) {
  360. scroller.scrollbar.attr({
  361. fill: options.barBackgroundColor,
  362. stroke: options.barBorderColor,
  363. 'stroke-width': options.barBorderWidth
  364. });
  365. scroller.scrollbarRifles.attr({
  366. stroke: options.rifleColor,
  367. 'stroke-width': 1
  368. });
  369. }
  370. scroller.scrollbarStrokeWidth = scroller.scrollbar.strokeWidth();
  371. scroller.scrollbarGroup.translate(-scroller.scrollbarStrokeWidth % 2 / 2, -scroller.scrollbarStrokeWidth % 2 / 2);
  372. // Draw the buttons:
  373. scroller.drawScrollbarButton(0);
  374. scroller.drawScrollbarButton(1);
  375. },
  376. /**
  377. * Position the scrollbar, method called from a parent with defined
  378. * dimensions.
  379. *
  380. * @private
  381. * @function Highcharts.Scrollbar#position
  382. * @param {number} x
  383. * x-position on the chart
  384. * @param {number} y
  385. * y-position on the chart
  386. * @param {number} width
  387. * width of the scrollbar
  388. * @param {number} height
  389. * height of the scorllbar
  390. * @return {void}
  391. */
  392. position: function (x, y, width, height) {
  393. var scroller = this, options = scroller.options, vertical = options.vertical, xOffset = height, yOffset = 0, method = scroller.rendered ? 'animate' : 'attr';
  394. scroller.x = x;
  395. scroller.y = y + this.trackBorderWidth;
  396. scroller.width = width; // width with buttons
  397. scroller.height = height;
  398. scroller.xOffset = xOffset;
  399. scroller.yOffset = yOffset;
  400. // If Scrollbar is a vertical type, swap options:
  401. if (vertical) {
  402. scroller.width = scroller.yOffset = width = yOffset = scroller.size;
  403. scroller.xOffset = xOffset = 0;
  404. scroller.barWidth = height - width * 2; // width without buttons
  405. scroller.x = x = x + scroller.options.margin;
  406. }
  407. else {
  408. scroller.height = scroller.xOffset = height = xOffset =
  409. scroller.size;
  410. scroller.barWidth = width - height * 2; // width without buttons
  411. scroller.y = scroller.y + scroller.options.margin;
  412. }
  413. // Set general position for a group:
  414. scroller.group[method]({
  415. translateX: x,
  416. translateY: scroller.y
  417. });
  418. // Resize background/track:
  419. scroller.track[method]({
  420. width: width,
  421. height: height
  422. });
  423. // Move right/bottom button ot it's place:
  424. scroller.scrollbarButtons[1][method]({
  425. translateX: vertical ? 0 : width - xOffset,
  426. translateY: vertical ? height - yOffset : 0
  427. });
  428. },
  429. /**
  430. * Draw the scrollbar buttons with arrows
  431. *
  432. * @private
  433. * @function Highcharts.Scrollbar#drawScrollbarButton
  434. * @param {number} index
  435. * 0 is left, 1 is right
  436. * @return {void}
  437. */
  438. drawScrollbarButton: function (index) {
  439. var scroller = this, renderer = scroller.renderer, scrollbarButtons = scroller.scrollbarButtons, options = scroller.options, size = scroller.size, group, tempElem;
  440. group = renderer.g().add(scroller.group);
  441. scrollbarButtons.push(group);
  442. // Create a rectangle for the scrollbar button
  443. tempElem = renderer.rect()
  444. .addClass('highcharts-scrollbar-button')
  445. .add(group);
  446. // Presentational attributes
  447. if (!this.chart.styledMode) {
  448. tempElem.attr({
  449. stroke: options.buttonBorderColor,
  450. 'stroke-width': options.buttonBorderWidth,
  451. fill: options.buttonBackgroundColor
  452. });
  453. }
  454. // Place the rectangle based on the rendered stroke width
  455. tempElem.attr(tempElem.crisp({
  456. x: -0.5,
  457. y: -0.5,
  458. width: size + 1,
  459. height: size + 1,
  460. r: options.buttonBorderRadius
  461. }, tempElem.strokeWidth()));
  462. // Button arrow
  463. tempElem = renderer
  464. .path(swapXY([
  465. 'M',
  466. size / 2 + (index ? -1 : 1),
  467. size / 2 - 3,
  468. 'L',
  469. size / 2 + (index ? -1 : 1),
  470. size / 2 + 3,
  471. 'L',
  472. size / 2 + (index ? 2 : -2),
  473. size / 2
  474. ], options.vertical))
  475. .addClass('highcharts-scrollbar-arrow')
  476. .add(scrollbarButtons[index]);
  477. if (!this.chart.styledMode) {
  478. tempElem.attr({
  479. fill: options.buttonArrowColor
  480. });
  481. }
  482. },
  483. /**
  484. * Set scrollbar size, with a given scale.
  485. *
  486. * @private
  487. * @function Highcharts.Scrollbar#setRange
  488. * @param {number} from
  489. * scale (0-1) where bar should start
  490. * @param {number} to
  491. * scale (0-1) where bar should end
  492. * @return {void}
  493. */
  494. setRange: function (from, to) {
  495. var scroller = this, options = scroller.options, vertical = options.vertical, minWidth = options.minWidth, fullWidth = scroller.barWidth, fromPX, toPX, newPos, newSize, newRiflesPos, method = (this.rendered &&
  496. !this.hasDragged &&
  497. !(this.chart.navigator && this.chart.navigator.hasDragged)) ? 'animate' : 'attr';
  498. if (!defined(fullWidth)) {
  499. return;
  500. }
  501. from = Math.max(from, 0);
  502. fromPX = Math.ceil(fullWidth * from);
  503. toPX = fullWidth * Math.min(to, 1);
  504. scroller.calculatedWidth = newSize = correctFloat(toPX - fromPX);
  505. // We need to recalculate position, if minWidth is used
  506. if (newSize < minWidth) {
  507. fromPX = (fullWidth - minWidth + newSize) * from;
  508. newSize = minWidth;
  509. }
  510. newPos = Math.floor(fromPX + scroller.xOffset + scroller.yOffset);
  511. newRiflesPos = newSize / 2 - 0.5; // -0.5 -> rifle line width / 2
  512. // Store current position:
  513. scroller.from = from;
  514. scroller.to = to;
  515. if (!vertical) {
  516. scroller.scrollbarGroup[method]({
  517. translateX: newPos
  518. });
  519. scroller.scrollbar[method]({
  520. width: newSize
  521. });
  522. scroller.scrollbarRifles[method]({
  523. translateX: newRiflesPos
  524. });
  525. scroller.scrollbarLeft = newPos;
  526. scroller.scrollbarTop = 0;
  527. }
  528. else {
  529. scroller.scrollbarGroup[method]({
  530. translateY: newPos
  531. });
  532. scroller.scrollbar[method]({
  533. height: newSize
  534. });
  535. scroller.scrollbarRifles[method]({
  536. translateY: newRiflesPos
  537. });
  538. scroller.scrollbarTop = newPos;
  539. scroller.scrollbarLeft = 0;
  540. }
  541. if (newSize <= 12) {
  542. scroller.scrollbarRifles.hide();
  543. }
  544. else {
  545. scroller.scrollbarRifles.show(true);
  546. }
  547. // Show or hide the scrollbar based on the showFull setting
  548. if (options.showFull === false) {
  549. if (from <= 0 && to >= 1) {
  550. scroller.group.hide();
  551. }
  552. else {
  553. scroller.group.show();
  554. }
  555. }
  556. scroller.rendered = true;
  557. },
  558. /**
  559. * Init events methods, so we have an access to the Scrollbar itself
  560. *
  561. * @private
  562. * @function Highcharts.Scrollbar#initEvents
  563. * @return {void}
  564. * @fires Highcharts.Scrollbar#event:changed
  565. */
  566. initEvents: function () {
  567. var scroller = this;
  568. /**
  569. * Event handler for the mouse move event.
  570. * @private
  571. */
  572. scroller.mouseMoveHandler = function (e) {
  573. var normalizedEvent = scroller.chart.pointer.normalize(e), options = scroller.options, direction = options.vertical ? 'chartY' : 'chartX', initPositions = scroller.initPositions, scrollPosition, chartPosition, change;
  574. // In iOS, a mousemove event with e.pageX === 0 is fired when
  575. // holding the finger down in the center of the scrollbar. This
  576. // should be ignored.
  577. if (scroller.grabbedCenter &&
  578. // #4696, scrollbar failed on Android
  579. (!e.touches || e.touches[0][direction] !== 0)) {
  580. chartPosition = scroller.cursorToScrollbarPosition(normalizedEvent)[direction];
  581. scrollPosition = scroller[direction];
  582. change = chartPosition - scrollPosition;
  583. scroller.hasDragged = true;
  584. scroller.updatePosition(initPositions[0] + change, initPositions[1] + change);
  585. if (scroller.hasDragged) {
  586. fireEvent(scroller, 'changed', {
  587. from: scroller.from,
  588. to: scroller.to,
  589. trigger: 'scrollbar',
  590. DOMType: e.type,
  591. DOMEvent: e
  592. });
  593. }
  594. }
  595. };
  596. /**
  597. * Event handler for the mouse up event.
  598. * @private
  599. */
  600. scroller.mouseUpHandler = function (e) {
  601. if (scroller.hasDragged) {
  602. fireEvent(scroller, 'changed', {
  603. from: scroller.from,
  604. to: scroller.to,
  605. trigger: 'scrollbar',
  606. DOMType: e.type,
  607. DOMEvent: e
  608. });
  609. }
  610. scroller.grabbedCenter =
  611. scroller.hasDragged =
  612. scroller.chartX =
  613. scroller.chartY = null;
  614. };
  615. scroller.mouseDownHandler = function (e) {
  616. var normalizedEvent = scroller.chart.pointer.normalize(e), mousePosition = scroller.cursorToScrollbarPosition(normalizedEvent);
  617. scroller.chartX = mousePosition.chartX;
  618. scroller.chartY = mousePosition.chartY;
  619. scroller.initPositions = [scroller.from, scroller.to];
  620. scroller.grabbedCenter = true;
  621. };
  622. scroller.buttonToMinClick = function (e) {
  623. var range = correctFloat(scroller.to - scroller.from) *
  624. scroller.options.step;
  625. scroller.updatePosition(correctFloat(scroller.from - range), correctFloat(scroller.to - range));
  626. fireEvent(scroller, 'changed', {
  627. from: scroller.from,
  628. to: scroller.to,
  629. trigger: 'scrollbar',
  630. DOMEvent: e
  631. });
  632. };
  633. scroller.buttonToMaxClick = function (e) {
  634. var range = (scroller.to - scroller.from) * scroller.options.step;
  635. scroller.updatePosition(scroller.from + range, scroller.to + range);
  636. fireEvent(scroller, 'changed', {
  637. from: scroller.from,
  638. to: scroller.to,
  639. trigger: 'scrollbar',
  640. DOMEvent: e
  641. });
  642. };
  643. scroller.trackClick = function (e) {
  644. var normalizedEvent = scroller.chart.pointer.normalize(e), range = scroller.to - scroller.from, top = scroller.y + scroller.scrollbarTop, left = scroller.x + scroller.scrollbarLeft;
  645. if ((scroller.options.vertical && normalizedEvent.chartY > top) ||
  646. (!scroller.options.vertical && normalizedEvent.chartX > left)) {
  647. // On the top or on the left side of the track:
  648. scroller.updatePosition(scroller.from + range, scroller.to + range);
  649. }
  650. else {
  651. // On the bottom or the right side of the track:
  652. scroller.updatePosition(scroller.from - range, scroller.to - range);
  653. }
  654. fireEvent(scroller, 'changed', {
  655. from: scroller.from,
  656. to: scroller.to,
  657. trigger: 'scrollbar',
  658. DOMEvent: e
  659. });
  660. };
  661. },
  662. /**
  663. * Get normalized (0-1) cursor position over the scrollbar
  664. *
  665. * @private
  666. * @function Highcharts.Scrollbar#cursorToScrollbarPosition
  667. *
  668. * @param {*} normalizedEvent
  669. * normalized event, with chartX and chartY values
  670. *
  671. * @return {Highcharts.Dictionary<number>}
  672. * Local position {chartX, chartY}
  673. */
  674. cursorToScrollbarPosition: function (normalizedEvent) {
  675. var scroller = this, options = scroller.options, minWidthDifference = options.minWidth > scroller.calculatedWidth ?
  676. options.minWidth :
  677. 0; // minWidth distorts translation
  678. return {
  679. chartX: (normalizedEvent.chartX - scroller.x -
  680. scroller.xOffset) /
  681. (scroller.barWidth - minWidthDifference),
  682. chartY: (normalizedEvent.chartY - scroller.y -
  683. scroller.yOffset) /
  684. (scroller.barWidth - minWidthDifference)
  685. };
  686. },
  687. /**
  688. * Update position option in the Scrollbar, with normalized 0-1 scale
  689. *
  690. * @private
  691. * @function Highcharts.Scrollbar#updatePosition
  692. * @param {number} from
  693. * @param {number} to
  694. * @return {void}
  695. */
  696. updatePosition: function (from, to) {
  697. if (to > 1) {
  698. from = correctFloat(1 - correctFloat(to - from));
  699. to = 1;
  700. }
  701. if (from < 0) {
  702. to = correctFloat(to - from);
  703. from = 0;
  704. }
  705. this.from = from;
  706. this.to = to;
  707. },
  708. /**
  709. * Update the scrollbar with new options
  710. *
  711. * @private
  712. * @function Highcharts.Scrollbar#update
  713. * @param {Highcharts.ScrollbarOptions} options
  714. * @return {void}
  715. */
  716. update: function (options) {
  717. this.destroy();
  718. this.init(this.chart.renderer, merge(true, this.options, options), this.chart);
  719. },
  720. /**
  721. * Set up the mouse and touch events for the Scrollbar
  722. *
  723. * @private
  724. * @function Highcharts.Scrollbar#addEvents
  725. * @return {void}
  726. */
  727. addEvents: function () {
  728. var buttonsOrder = this.options.inverted ? [1, 0] : [0, 1], buttons = this.scrollbarButtons, bar = this.scrollbarGroup.element, track = this.track.element, mouseDownHandler = this.mouseDownHandler, mouseMoveHandler = this.mouseMoveHandler, mouseUpHandler = this.mouseUpHandler, _events;
  729. // Mouse events
  730. _events = [
  731. [buttons[buttonsOrder[0]].element, 'click', this.buttonToMinClick],
  732. [buttons[buttonsOrder[1]].element, 'click', this.buttonToMaxClick],
  733. [track, 'click', this.trackClick],
  734. [bar, 'mousedown', mouseDownHandler],
  735. [bar.ownerDocument, 'mousemove', mouseMoveHandler],
  736. [bar.ownerDocument, 'mouseup', mouseUpHandler]
  737. ];
  738. // Touch events
  739. if (hasTouch) {
  740. _events.push([bar, 'touchstart', mouseDownHandler], [bar.ownerDocument, 'touchmove', mouseMoveHandler], [bar.ownerDocument, 'touchend', mouseUpHandler]);
  741. }
  742. // Add them all
  743. _events.forEach(function (args) {
  744. addEvent.apply(null, args);
  745. });
  746. this._events = _events;
  747. },
  748. /**
  749. * Removes the event handlers attached previously with addEvents.
  750. *
  751. * @private
  752. * @function Highcharts.Scrollbar#removeEvents
  753. * @return {void}
  754. */
  755. removeEvents: function () {
  756. this._events.forEach(function (args) {
  757. removeEvent.apply(null, args);
  758. });
  759. this._events.length = 0;
  760. },
  761. /**
  762. * Destroys allocated elements.
  763. *
  764. * @private
  765. * @function Highcharts.Scrollbar#destroy
  766. * @return {void}
  767. */
  768. destroy: function () {
  769. var scroller = this.chart.scroller;
  770. // Disconnect events added in addEvents
  771. this.removeEvents();
  772. // Destroy properties
  773. [
  774. 'track',
  775. 'scrollbarRifles',
  776. 'scrollbar',
  777. 'scrollbarGroup',
  778. 'group'
  779. ].forEach(function (prop) {
  780. if (this[prop] && this[prop].destroy) {
  781. this[prop] = this[prop].destroy();
  782. }
  783. }, this);
  784. // #6421, chart may have more scrollbars
  785. if (scroller && this === scroller.scrollbar) {
  786. scroller.scrollbar = null;
  787. // Destroy elements in collection
  788. destroyObjectProperties(scroller.scrollbarButtons);
  789. }
  790. }
  791. };
  792. if (!H.Scrollbar) {
  793. /* *
  794. * Wrap axis initialization and create scrollbar if enabled:
  795. */
  796. addEvent(Axis, 'afterInit', function () {
  797. var axis = this;
  798. if (axis.options &&
  799. axis.options.scrollbar &&
  800. axis.options.scrollbar.enabled) {
  801. // Predefined options:
  802. axis.options.scrollbar.vertical = !axis.horiz;
  803. axis.options.startOnTick = axis.options.endOnTick = false;
  804. axis.scrollbar = new Scrollbar(axis.chart.renderer, axis.options.scrollbar, axis.chart);
  805. addEvent(axis.scrollbar, 'changed', function (e) {
  806. var unitedMin = Math.min(pick(axis.options.min, axis.min), axis.min, axis.dataMin), unitedMax = Math.max(pick(axis.options.max, axis.max), axis.max, axis.dataMax), range = unitedMax - unitedMin, to, from;
  807. if ((axis.horiz && !axis.reversed) ||
  808. (!axis.horiz && axis.reversed)) {
  809. to = unitedMin + range * this.to;
  810. from = unitedMin + range * this.from;
  811. }
  812. else {
  813. // y-values in browser are reversed, but this also applies
  814. // for reversed horizontal axis:
  815. to = unitedMin + range * (1 - this.from);
  816. from = unitedMin + range * (1 - this.to);
  817. }
  818. if (pick(this.options.liveRedraw, H.svg && !H.isTouchDevice && !this.chart.isBoosting) ||
  819. // Mouseup always should change extremes
  820. e.DOMType === 'mouseup' ||
  821. // Internal events
  822. !defined(e.DOMType)) {
  823. axis.setExtremes(from, to, true, e.DOMType !== 'mousemove', e);
  824. }
  825. else {
  826. // When live redraw is disabled, don't change extremes
  827. // Only change the position of the scollbar thumb
  828. this.setRange(this.from, this.to);
  829. }
  830. });
  831. }
  832. });
  833. /* *
  834. * Wrap rendering axis, and update scrollbar if one is created:
  835. */
  836. addEvent(Axis, 'afterRender', function () {
  837. var axis = this, scrollMin = Math.min(pick(axis.options.min, axis.min), axis.min, pick(axis.dataMin, axis.min) // #6930
  838. ), scrollMax = Math.max(pick(axis.options.max, axis.max), axis.max, pick(axis.dataMax, axis.max) // #6930
  839. ), scrollbar = axis.scrollbar, offset = axis.axisTitleMargin + (axis.titleOffset || 0), scrollbarsOffsets = axis.chart.scrollbarsOffsets, axisMargin = axis.options.margin || 0, offsetsIndex, from, to;
  840. if (scrollbar) {
  841. if (axis.horiz) {
  842. // Reserve space for labels/title
  843. if (!axis.opposite) {
  844. scrollbarsOffsets[1] += offset;
  845. }
  846. scrollbar.position(axis.left, axis.top + axis.height + 2 + scrollbarsOffsets[1] -
  847. (axis.opposite ? axisMargin : 0), axis.width, axis.height);
  848. // Next scrollbar should reserve space for margin (if set)
  849. if (!axis.opposite) {
  850. scrollbarsOffsets[1] += axisMargin;
  851. }
  852. offsetsIndex = 1;
  853. }
  854. else {
  855. // Reserve space for labels/title
  856. if (axis.opposite) {
  857. scrollbarsOffsets[0] += offset;
  858. }
  859. scrollbar.position(axis.left + axis.width + 2 + scrollbarsOffsets[0] -
  860. (axis.opposite ? 0 : axisMargin), axis.top, axis.width, axis.height);
  861. // Next scrollbar should reserve space for margin (if set)
  862. if (axis.opposite) {
  863. scrollbarsOffsets[0] += axisMargin;
  864. }
  865. offsetsIndex = 0;
  866. }
  867. scrollbarsOffsets[offsetsIndex] += scrollbar.size +
  868. scrollbar.options.margin;
  869. if (isNaN(scrollMin) ||
  870. isNaN(scrollMax) ||
  871. !defined(axis.min) ||
  872. !defined(axis.max) ||
  873. axis.min === axis.max // #10733
  874. ) {
  875. // default action: when extremes are the same or there is not
  876. // extremes on the axis, but scrollbar exists, make it full size
  877. scrollbar.setRange(0, 1);
  878. }
  879. else {
  880. from =
  881. (axis.min - scrollMin) / (scrollMax - scrollMin);
  882. to =
  883. (axis.max - scrollMin) / (scrollMax - scrollMin);
  884. if ((axis.horiz && !axis.reversed) ||
  885. (!axis.horiz && axis.reversed)) {
  886. scrollbar.setRange(from, to);
  887. }
  888. else {
  889. // inverse vertical axis
  890. scrollbar.setRange(1 - to, 1 - from);
  891. }
  892. }
  893. }
  894. });
  895. /* *
  896. * Make space for a scrollbar
  897. * @private
  898. */
  899. addEvent(Axis, 'afterGetOffset', function () {
  900. var axis = this, index = axis.horiz ? 2 : 1, scrollbar = axis.scrollbar;
  901. if (scrollbar) {
  902. axis.chart.scrollbarsOffsets = [0, 0]; // reset scrollbars offsets
  903. axis.chart.axisOffset[index] +=
  904. scrollbar.size + scrollbar.options.margin;
  905. }
  906. });
  907. H.Scrollbar = Scrollbar;
  908. }
  909. });
  910. _registerModule(_modules, 'parts/Navigator.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  911. /* *
  912. *
  913. * (c) 2010-2019 Torstein Honsi
  914. *
  915. * License: www.highcharts.com/license
  916. *
  917. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  918. *
  919. * */
  920. var clamp = U.clamp, correctFloat = U.correctFloat, defined = U.defined, destroyObjectProperties = U.destroyObjectProperties, erase = U.erase, extend = U.extend, isArray = U.isArray, isNumber = U.isNumber, pick = U.pick, splat = U.splat;
  921. var addEvent = H.addEvent, Axis = H.Axis, Chart = H.Chart, color = H.color, defaultOptions = H.defaultOptions, hasTouch = H.hasTouch, isTouchDevice = H.isTouchDevice, merge = H.merge, removeEvent = H.removeEvent, Scrollbar = H.Scrollbar, Series = H.Series, seriesTypes = H.seriesTypes, defaultSeriesType,
  922. // Finding the min or max of a set of variables where we don't know if they
  923. // are defined, is a pattern that is repeated several places in Highcharts.
  924. // Consider making this a global utility method.
  925. numExt = function (extreme) {
  926. var args = [];
  927. for (var _i = 1; _i < arguments.length; _i++) {
  928. args[_i - 1] = arguments[_i];
  929. }
  930. var numbers = [].filter.call(args, isNumber);
  931. if (numbers.length) {
  932. return Math[extreme].apply(0, numbers);
  933. }
  934. };
  935. defaultSeriesType = typeof seriesTypes.areaspline === 'undefined' ?
  936. 'line' :
  937. 'areaspline';
  938. extend(defaultOptions, {
  939. /**
  940. * Maximum range which can be set using the navigator's handles.
  941. * Opposite of [xAxis.minRange](#xAxis.minRange).
  942. *
  943. * @sample {highstock} stock/navigator/maxrange/
  944. * Defined max and min range
  945. *
  946. * @type {number}
  947. * @since 6.0.0
  948. * @product highstock gantt
  949. * @apioption xAxis.maxRange
  950. */
  951. /**
  952. * The navigator is a small series below the main series, displaying
  953. * a view of the entire data set. It provides tools to zoom in and
  954. * out on parts of the data as well as panning across the dataset.
  955. *
  956. * @product highstock gantt
  957. * @optionparent navigator
  958. */
  959. navigator: {
  960. /**
  961. * Whether the navigator and scrollbar should adapt to updated data
  962. * in the base X axis. When loading data async, as in the demo below,
  963. * this should be `false`. Otherwise new data will trigger navigator
  964. * redraw, which will cause unwanted looping. In the demo below, the
  965. * data in the navigator is set only once. On navigating, only the main
  966. * chart content is updated.
  967. *
  968. * @sample {highstock} stock/demo/lazy-loading/
  969. * Set to false with async data loading
  970. *
  971. * @type {boolean}
  972. * @default true
  973. * @apioption navigator.adaptToUpdatedData
  974. */
  975. /**
  976. * An integer identifying the index to use for the base series, or a
  977. * string representing the id of the series.
  978. *
  979. * **Note**: As of Highcharts 5.0, this is now a deprecated option.
  980. * Prefer [series.showInNavigator](#plotOptions.series.showInNavigator).
  981. *
  982. * @see [series.showInNavigator](#plotOptions.series.showInNavigator)
  983. *
  984. * @deprecated
  985. * @type {number|string}
  986. * @default 0
  987. * @apioption navigator.baseSeries
  988. */
  989. /**
  990. * Enable or disable the navigator.
  991. *
  992. * @sample {highstock} stock/navigator/enabled/
  993. * Disable the navigator
  994. *
  995. * @type {boolean}
  996. * @default true
  997. * @apioption navigator.enabled
  998. */
  999. /**
  1000. * When the chart is inverted, whether to draw the navigator on the
  1001. * opposite side.
  1002. *
  1003. * @type {boolean}
  1004. * @default false
  1005. * @since 5.0.8
  1006. * @apioption navigator.opposite
  1007. */
  1008. /**
  1009. * The height of the navigator.
  1010. *
  1011. * @sample {highstock} stock/navigator/height/
  1012. * A higher navigator
  1013. */
  1014. height: 40,
  1015. /**
  1016. * The distance from the nearest element, the X axis or X axis labels.
  1017. *
  1018. * @sample {highstock} stock/navigator/margin/
  1019. * A margin of 2 draws the navigator closer to the X axis labels
  1020. */
  1021. margin: 25,
  1022. /**
  1023. * Whether the mask should be inside the range marking the zoomed
  1024. * range, or outside. In Highstock 1.x it was always `false`.
  1025. *
  1026. * @sample {highstock} stock/navigator/maskinside-false/
  1027. * False, mask outside
  1028. *
  1029. * @since 2.0
  1030. */
  1031. maskInside: true,
  1032. /**
  1033. * Options for the handles for dragging the zoomed area.
  1034. *
  1035. * @sample {highstock} stock/navigator/handles/
  1036. * Colored handles
  1037. */
  1038. handles: {
  1039. /**
  1040. * Width for handles.
  1041. *
  1042. * @sample {highstock} stock/navigator/styled-handles/
  1043. * Styled handles
  1044. *
  1045. * @since 6.0.0
  1046. */
  1047. width: 7,
  1048. /**
  1049. * Height for handles.
  1050. *
  1051. * @sample {highstock} stock/navigator/styled-handles/
  1052. * Styled handles
  1053. *
  1054. * @since 6.0.0
  1055. */
  1056. height: 15,
  1057. /**
  1058. * Array to define shapes of handles. 0-index for left, 1-index for
  1059. * right.
  1060. *
  1061. * Additionally, the URL to a graphic can be given on this form:
  1062. * `url(graphic.png)`. Note that for the image to be applied to
  1063. * exported charts, its URL needs to be accessible by the export
  1064. * server.
  1065. *
  1066. * Custom callbacks for symbol path generation can also be added to
  1067. * `Highcharts.SVGRenderer.prototype.symbols`. The callback is then
  1068. * used by its method name, as shown in the demo.
  1069. *
  1070. * @sample {highstock} stock/navigator/styled-handles/
  1071. * Styled handles
  1072. *
  1073. * @type {Array<string>}
  1074. * @default ["navigator-handle", "navigator-handle"]
  1075. * @since 6.0.0
  1076. */
  1077. symbols: ['navigator-handle', 'navigator-handle'],
  1078. /**
  1079. * Allows to enable/disable handles.
  1080. *
  1081. * @since 6.0.0
  1082. */
  1083. enabled: true,
  1084. /**
  1085. * The width for the handle border and the stripes inside.
  1086. *
  1087. * @sample {highstock} stock/navigator/styled-handles/
  1088. * Styled handles
  1089. *
  1090. * @since 6.0.0
  1091. * @apioption navigator.handles.lineWidth
  1092. */
  1093. lineWidth: 1,
  1094. /**
  1095. * The fill for the handle.
  1096. *
  1097. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1098. */
  1099. backgroundColor: '#f2f2f2',
  1100. /**
  1101. * The stroke for the handle border and the stripes inside.
  1102. *
  1103. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1104. */
  1105. borderColor: '#999999'
  1106. },
  1107. /**
  1108. * The color of the mask covering the areas of the navigator series
  1109. * that are currently not visible in the main series. The default
  1110. * color is bluish with an opacity of 0.3 to see the series below.
  1111. *
  1112. * @see In styled mode, the mask is styled with the
  1113. * `.highcharts-navigator-mask` and
  1114. * `.highcharts-navigator-mask-inside` classes.
  1115. *
  1116. * @sample {highstock} stock/navigator/maskfill/
  1117. * Blue, semi transparent mask
  1118. *
  1119. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1120. * @default rgba(102,133,194,0.3)
  1121. */
  1122. maskFill: color('#6685c2').setOpacity(0.3).get(),
  1123. /**
  1124. * The color of the line marking the currently zoomed area in the
  1125. * navigator.
  1126. *
  1127. * @sample {highstock} stock/navigator/outline/
  1128. * 2px blue outline
  1129. *
  1130. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1131. * @default #cccccc
  1132. */
  1133. outlineColor: '#cccccc',
  1134. /**
  1135. * The width of the line marking the currently zoomed area in the
  1136. * navigator.
  1137. *
  1138. * @see In styled mode, the outline stroke width is set with the
  1139. * `.highcharts-navigator-outline` class.
  1140. *
  1141. * @sample {highstock} stock/navigator/outline/
  1142. * 2px blue outline
  1143. *
  1144. * @type {number}
  1145. */
  1146. outlineWidth: 1,
  1147. /**
  1148. * Options for the navigator series. Available options are the same
  1149. * as any series, documented at [plotOptions](#plotOptions.series)
  1150. * and [series](#series).
  1151. *
  1152. * Unless data is explicitly defined on navigator.series, the data
  1153. * is borrowed from the first series in the chart.
  1154. *
  1155. * Default series options for the navigator series are:
  1156. * ```js
  1157. * series: {
  1158. * type: 'areaspline',
  1159. * fillOpacity: 0.05,
  1160. * dataGrouping: {
  1161. * smoothed: true
  1162. * },
  1163. * lineWidth: 1,
  1164. * marker: {
  1165. * enabled: false
  1166. * }
  1167. * }
  1168. * ```
  1169. *
  1170. * @see In styled mode, the navigator series is styled with the
  1171. * `.highcharts-navigator-series` class.
  1172. *
  1173. * @sample {highstock} stock/navigator/series-data/
  1174. * Using a separate data set for the navigator
  1175. * @sample {highstock} stock/navigator/series/
  1176. * A green navigator series
  1177. *
  1178. * @type {*|Array<*>|Highcharts.SeriesOptionsType|Array<Highcharts.SeriesOptionsType>}
  1179. */
  1180. series: {
  1181. /**
  1182. * The type of the navigator series. Defaults to `areaspline` if
  1183. * defined, otherwise `line`.
  1184. *
  1185. * Heads up:
  1186. * In column-type navigator, zooming is limited to at least one
  1187. * point with its `pointRange`.
  1188. *
  1189. * @sample {highstock} stock/navigator/column/
  1190. * Column type navigator
  1191. *
  1192. * @type {string}
  1193. * @default areaspline
  1194. */
  1195. type: defaultSeriesType,
  1196. /**
  1197. * The fill opacity of the navigator series.
  1198. */
  1199. fillOpacity: 0.05,
  1200. /**
  1201. * The pixel line width of the navigator series.
  1202. */
  1203. lineWidth: 1,
  1204. /**
  1205. * @ignore-option
  1206. */
  1207. compare: null,
  1208. /**
  1209. * Unless data is explicitly defined, the data is borrowed from the
  1210. * first series in the chart.
  1211. *
  1212. * @type {Array<number|Array<number|string|null>|object|null>}
  1213. * @product highstock
  1214. * @apioption navigator.series.data
  1215. */
  1216. /**
  1217. * Data grouping options for the navigator series.
  1218. *
  1219. * @extends plotOptions.series.dataGrouping
  1220. */
  1221. dataGrouping: {
  1222. approximation: 'average',
  1223. enabled: true,
  1224. groupPixelWidth: 2,
  1225. smoothed: true,
  1226. // Day and week differs from plotOptions.series.dataGrouping
  1227. units: [
  1228. ['millisecond', [1, 2, 5, 10, 20, 25, 50, 100, 200, 500]],
  1229. ['second', [1, 2, 5, 10, 15, 30]],
  1230. ['minute', [1, 2, 5, 10, 15, 30]],
  1231. ['hour', [1, 2, 3, 4, 6, 8, 12]],
  1232. ['day', [1, 2, 3, 4]],
  1233. ['week', [1, 2, 3]],
  1234. ['month', [1, 3, 6]],
  1235. ['year', null]
  1236. ]
  1237. },
  1238. /**
  1239. * Data label options for the navigator series. Data labels are
  1240. * disabled by default on the navigator series.
  1241. *
  1242. * @extends plotOptions.series.dataLabels
  1243. */
  1244. dataLabels: {
  1245. enabled: false,
  1246. zIndex: 2 // #1839
  1247. },
  1248. id: 'highcharts-navigator-series',
  1249. className: 'highcharts-navigator-series',
  1250. /**
  1251. * Sets the fill color of the navigator series.
  1252. *
  1253. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  1254. * @apioption navigator.series.color
  1255. */
  1256. /**
  1257. * Line color for the navigator series. Allows setting the color
  1258. * while disallowing the default candlestick setting.
  1259. *
  1260. * @type {Highcharts.ColorString|null}
  1261. */
  1262. lineColor: null,
  1263. marker: {
  1264. enabled: false
  1265. },
  1266. /**
  1267. * Since Highstock v8, default value is the same as default
  1268. * `pointRange` defined for a specific type (e.g. `null` for
  1269. * column type).
  1270. *
  1271. * In Highstock version < 8, defaults to 0.
  1272. *
  1273. * @extends plotOptions.series.pointRange
  1274. * @type {number|null}
  1275. * @apioption navigator.series.pointRange
  1276. */
  1277. /**
  1278. * The threshold option. Setting it to 0 will make the default
  1279. * navigator area series draw its area from the 0 value and up.
  1280. *
  1281. * @type {number|null}
  1282. */
  1283. threshold: null
  1284. },
  1285. /**
  1286. * Options for the navigator X axis. Default series options for the
  1287. * navigator xAxis are:
  1288. * ```js
  1289. * xAxis: {
  1290. * tickWidth: 0,
  1291. * lineWidth: 0,
  1292. * gridLineWidth: 1,
  1293. * tickPixelInterval: 200,
  1294. * labels: {
  1295. * align: 'left',
  1296. * style: {
  1297. * color: '#888'
  1298. * },
  1299. * x: 3,
  1300. * y: -4
  1301. * }
  1302. * }
  1303. * ```
  1304. *
  1305. * @extends xAxis
  1306. * @excluding linkedTo, maxZoom, minRange, opposite, range, scrollbar,
  1307. * showEmpty, maxRange
  1308. */
  1309. xAxis: {
  1310. /**
  1311. * Additional range on the right side of the xAxis. Works similar to
  1312. * xAxis.maxPadding, but value is set in milliseconds.
  1313. * Can be set for both, main xAxis and navigator's xAxis.
  1314. *
  1315. * @since 6.0.0
  1316. */
  1317. overscroll: 0,
  1318. className: 'highcharts-navigator-xaxis',
  1319. tickLength: 0,
  1320. lineWidth: 0,
  1321. gridLineColor: '#e6e6e6',
  1322. gridLineWidth: 1,
  1323. tickPixelInterval: 200,
  1324. labels: {
  1325. align: 'left',
  1326. /**
  1327. * @type {Highcharts.CSSObject}
  1328. */
  1329. style: {
  1330. /** @ignore */
  1331. color: '#999999'
  1332. },
  1333. x: 3,
  1334. y: -4
  1335. },
  1336. crosshair: false
  1337. },
  1338. /**
  1339. * Options for the navigator Y axis. Default series options for the
  1340. * navigator yAxis are:
  1341. * ```js
  1342. * yAxis: {
  1343. * gridLineWidth: 0,
  1344. * startOnTick: false,
  1345. * endOnTick: false,
  1346. * minPadding: 0.1,
  1347. * maxPadding: 0.1,
  1348. * labels: {
  1349. * enabled: false
  1350. * },
  1351. * title: {
  1352. * text: null
  1353. * },
  1354. * tickWidth: 0
  1355. * }
  1356. * ```
  1357. *
  1358. * @extends yAxis
  1359. * @excluding height, linkedTo, maxZoom, minRange, ordinal, range,
  1360. * showEmpty, scrollbar, top, units, maxRange, minLength,
  1361. * maxLength, resize
  1362. */
  1363. yAxis: {
  1364. className: 'highcharts-navigator-yaxis',
  1365. gridLineWidth: 0,
  1366. startOnTick: false,
  1367. endOnTick: false,
  1368. minPadding: 0.1,
  1369. maxPadding: 0.1,
  1370. labels: {
  1371. enabled: false
  1372. },
  1373. crosshair: false,
  1374. title: {
  1375. text: null
  1376. },
  1377. tickLength: 0,
  1378. tickWidth: 0
  1379. }
  1380. }
  1381. });
  1382. /* eslint-disable no-invalid-this, valid-jsdoc */
  1383. /**
  1384. * Draw one of the handles on the side of the zoomed range in the navigator
  1385. *
  1386. * @private
  1387. * @function Highcharts.Renderer#symbols.navigator-handle
  1388. * @param {number} x
  1389. * @param {number} y
  1390. * @param {number} w
  1391. * @param {number} h
  1392. * @param {Highcharts.NavigatorHandlesOptions} options
  1393. * @return {Highcharts.SVGPathArray}
  1394. * Path to be used in a handle
  1395. */
  1396. H.Renderer.prototype.symbols['navigator-handle'] = function (x, y, w, h, options) {
  1397. var halfWidth = options.width / 2, markerPosition = Math.round(halfWidth / 3) + 0.5, height = options.height;
  1398. return [
  1399. 'M',
  1400. -halfWidth - 1, 0.5,
  1401. 'L',
  1402. halfWidth, 0.5,
  1403. 'L',
  1404. halfWidth, height + 0.5,
  1405. 'L',
  1406. -halfWidth - 1, height + 0.5,
  1407. 'L',
  1408. -halfWidth - 1, 0.5,
  1409. 'M',
  1410. -markerPosition, 4,
  1411. 'L',
  1412. -markerPosition, height - 3,
  1413. 'M',
  1414. markerPosition - 1, 4,
  1415. 'L',
  1416. markerPosition - 1, height - 3
  1417. ];
  1418. };
  1419. /**
  1420. * Add logic to normalize the zoomed range in order to preserve the pressed
  1421. * state of range selector buttons
  1422. *
  1423. * @private
  1424. * @function Highcharts.Axis#toFixedRange
  1425. * @param {number} [pxMin]
  1426. * @param {number} [pxMax]
  1427. * @param {number} [fixedMin]
  1428. * @param {number} [fixedMax]
  1429. * @return {*}
  1430. */
  1431. Axis.prototype.toFixedRange = function (pxMin, pxMax, fixedMin, fixedMax) {
  1432. var fixedRange = this.chart && this.chart.fixedRange, halfPointRange = (this.pointRange || 0) / 2, newMin = pick(fixedMin, this.translate(pxMin, true, !this.horiz)), newMax = pick(fixedMax, this.translate(pxMax, true, !this.horiz)), changeRatio = fixedRange && (newMax - newMin) / fixedRange;
  1433. // Add/remove half point range to/from the extremes (#1172)
  1434. if (!defined(fixedMin)) {
  1435. newMin = correctFloat(newMin + halfPointRange);
  1436. }
  1437. if (!defined(fixedMax)) {
  1438. newMax = correctFloat(newMax - halfPointRange);
  1439. }
  1440. // If the difference between the fixed range and the actual requested range
  1441. // is too great, the user is dragging across an ordinal gap, and we need to
  1442. // release the range selector button.
  1443. if (changeRatio > 0.7 && changeRatio < 1.3) {
  1444. if (fixedMax) {
  1445. newMin = newMax - fixedRange;
  1446. }
  1447. else {
  1448. newMax = newMin + fixedRange;
  1449. }
  1450. }
  1451. if (!isNumber(newMin) || !isNumber(newMax)) { // #1195, #7411
  1452. newMin = newMax = void 0;
  1453. }
  1454. return {
  1455. min: newMin,
  1456. max: newMax
  1457. };
  1458. };
  1459. /**
  1460. * The Navigator class
  1461. *
  1462. * @private
  1463. * @class
  1464. * @name Highcharts.Navigator
  1465. *
  1466. * @param {Highcharts.Chart} chart
  1467. * Chart object
  1468. */
  1469. function Navigator(chart) {
  1470. this.init(chart);
  1471. }
  1472. Navigator.prototype = {
  1473. /**
  1474. * Draw one of the handles on the side of the zoomed range in the navigator
  1475. *
  1476. * @private
  1477. * @function Highcharts.Navigator#drawHandle
  1478. *
  1479. * @param {number} x
  1480. * The x center for the handle
  1481. *
  1482. * @param {number} index
  1483. * 0 for left and 1 for right
  1484. *
  1485. * @param {boolean|undefined} inverted
  1486. * flag for chart.inverted
  1487. *
  1488. * @param {string} verb
  1489. * use 'animate' or 'attr'
  1490. */
  1491. drawHandle: function (x, index, inverted, verb) {
  1492. var navigator = this, height = navigator.navigatorOptions.handles.height;
  1493. // Place it
  1494. navigator.handles[index][verb](inverted ? {
  1495. translateX: Math.round(navigator.left + navigator.height / 2),
  1496. translateY: Math.round(navigator.top + parseInt(x, 10) + 0.5 - height)
  1497. } : {
  1498. translateX: Math.round(navigator.left + parseInt(x, 10)),
  1499. translateY: Math.round(navigator.top + navigator.height / 2 - height / 2 - 1)
  1500. });
  1501. },
  1502. /**
  1503. * Render outline around the zoomed range
  1504. *
  1505. * @private
  1506. * @function Highcharts.Navigator#drawOutline
  1507. *
  1508. * @param {number} zoomedMin
  1509. * in pixels position where zoomed range starts
  1510. *
  1511. * @param {number} zoomedMax
  1512. * in pixels position where zoomed range ends
  1513. *
  1514. * @param {boolean|undefined} inverted
  1515. * flag if chart is inverted
  1516. *
  1517. * @param {string} verb
  1518. * use 'animate' or 'attr'
  1519. */
  1520. drawOutline: function (zoomedMin, zoomedMax, inverted, verb) {
  1521. var navigator = this, maskInside = navigator.navigatorOptions.maskInside, outlineWidth = navigator.outline.strokeWidth(), halfOutline = outlineWidth / 2, outlineCorrection = (outlineWidth % 2) / 2, // #5800
  1522. outlineHeight = navigator.outlineHeight, scrollbarHeight = navigator.scrollbarHeight, navigatorSize = navigator.size, left = navigator.left - scrollbarHeight, navigatorTop = navigator.top, verticalMin, path;
  1523. if (inverted) {
  1524. left -= halfOutline;
  1525. verticalMin = navigatorTop + zoomedMax + outlineCorrection;
  1526. zoomedMax = navigatorTop + zoomedMin + outlineCorrection;
  1527. path = [
  1528. 'M',
  1529. left + outlineHeight,
  1530. // top edge
  1531. navigatorTop - scrollbarHeight - outlineCorrection,
  1532. 'L',
  1533. left + outlineHeight,
  1534. verticalMin,
  1535. 'L',
  1536. left,
  1537. verticalMin,
  1538. 'L',
  1539. left,
  1540. zoomedMax,
  1541. 'L',
  1542. left + outlineHeight,
  1543. zoomedMax,
  1544. 'L',
  1545. left + outlineHeight,
  1546. // bottom edge
  1547. navigatorTop + navigatorSize + scrollbarHeight
  1548. ].concat(maskInside ? [
  1549. 'M',
  1550. left + outlineHeight,
  1551. verticalMin - halfOutline,
  1552. 'L',
  1553. left + outlineHeight,
  1554. zoomedMax + halfOutline // upper right of z.r.
  1555. ] : []);
  1556. }
  1557. else {
  1558. zoomedMin += left + scrollbarHeight - outlineCorrection;
  1559. zoomedMax += left + scrollbarHeight - outlineCorrection;
  1560. navigatorTop += halfOutline;
  1561. path = [
  1562. 'M',
  1563. left,
  1564. navigatorTop,
  1565. 'L',
  1566. zoomedMin,
  1567. navigatorTop,
  1568. 'L',
  1569. zoomedMin,
  1570. navigatorTop + outlineHeight,
  1571. 'L',
  1572. zoomedMax,
  1573. navigatorTop + outlineHeight,
  1574. 'L',
  1575. zoomedMax,
  1576. navigatorTop,
  1577. 'L',
  1578. left + navigatorSize + scrollbarHeight * 2,
  1579. navigatorTop // right
  1580. ].concat(maskInside ? [
  1581. 'M',
  1582. zoomedMin - halfOutline,
  1583. navigatorTop,
  1584. 'L',
  1585. zoomedMax + halfOutline,
  1586. navigatorTop // upper right of z.r.
  1587. ] : []);
  1588. }
  1589. navigator.outline[verb]({
  1590. d: path
  1591. });
  1592. },
  1593. /**
  1594. * Render outline around the zoomed range
  1595. *
  1596. * @private
  1597. * @function Highcharts.Navigator#drawMasks
  1598. *
  1599. * @param {number} zoomedMin
  1600. * in pixels position where zoomed range starts
  1601. *
  1602. * @param {number} zoomedMax
  1603. * in pixels position where zoomed range ends
  1604. *
  1605. * @param {boolean|undefined} inverted
  1606. * flag if chart is inverted
  1607. *
  1608. * @param {string} verb
  1609. * use 'animate' or 'attr'
  1610. */
  1611. drawMasks: function (zoomedMin, zoomedMax, inverted, verb) {
  1612. var navigator = this, left = navigator.left, top = navigator.top, navigatorHeight = navigator.height, height, width, x, y;
  1613. // Determine rectangle position & size
  1614. // According to (non)inverted position:
  1615. if (inverted) {
  1616. x = [left, left, left];
  1617. y = [top, top + zoomedMin, top + zoomedMax];
  1618. width = [navigatorHeight, navigatorHeight, navigatorHeight];
  1619. height = [
  1620. zoomedMin,
  1621. zoomedMax - zoomedMin,
  1622. navigator.size - zoomedMax
  1623. ];
  1624. }
  1625. else {
  1626. x = [left, left + zoomedMin, left + zoomedMax];
  1627. y = [top, top, top];
  1628. width = [
  1629. zoomedMin,
  1630. zoomedMax - zoomedMin,
  1631. navigator.size - zoomedMax
  1632. ];
  1633. height = [navigatorHeight, navigatorHeight, navigatorHeight];
  1634. }
  1635. navigator.shades.forEach(function (shade, i) {
  1636. shade[verb]({
  1637. x: x[i],
  1638. y: y[i],
  1639. width: width[i],
  1640. height: height[i]
  1641. });
  1642. });
  1643. },
  1644. /**
  1645. * Generate DOM elements for a navigator:
  1646. *
  1647. * - main navigator group
  1648. *
  1649. * - all shades
  1650. *
  1651. * - outline
  1652. *
  1653. * - handles
  1654. *
  1655. * @private
  1656. * @function Highcharts.Navigator#renderElements
  1657. */
  1658. renderElements: function () {
  1659. var navigator = this, navigatorOptions = navigator.navigatorOptions, maskInside = navigatorOptions.maskInside, chart = navigator.chart, inverted = chart.inverted, renderer = chart.renderer, navigatorGroup, mouseCursor = {
  1660. cursor: inverted ? 'ns-resize' : 'ew-resize'
  1661. };
  1662. // Create the main navigator group
  1663. navigator.navigatorGroup = navigatorGroup = renderer.g('navigator')
  1664. .attr({
  1665. zIndex: 8,
  1666. visibility: 'hidden'
  1667. })
  1668. .add();
  1669. // Create masks, each mask will get events and fill:
  1670. [
  1671. !maskInside,
  1672. maskInside,
  1673. !maskInside
  1674. ].forEach(function (hasMask, index) {
  1675. navigator.shades[index] = renderer.rect()
  1676. .addClass('highcharts-navigator-mask' +
  1677. (index === 1 ? '-inside' : '-outside'))
  1678. .add(navigatorGroup);
  1679. if (!chart.styledMode) {
  1680. navigator.shades[index]
  1681. .attr({
  1682. fill: hasMask ?
  1683. navigatorOptions.maskFill :
  1684. 'rgba(0,0,0,0)'
  1685. })
  1686. .css((index === 1) && mouseCursor);
  1687. }
  1688. });
  1689. // Create the outline:
  1690. navigator.outline = renderer.path()
  1691. .addClass('highcharts-navigator-outline')
  1692. .add(navigatorGroup);
  1693. if (!chart.styledMode) {
  1694. navigator.outline.attr({
  1695. 'stroke-width': navigatorOptions.outlineWidth,
  1696. stroke: navigatorOptions.outlineColor
  1697. });
  1698. }
  1699. // Create the handlers:
  1700. if (navigatorOptions.handles.enabled) {
  1701. [0, 1].forEach(function (index) {
  1702. navigatorOptions.handles.inverted = chart.inverted;
  1703. navigator.handles[index] = renderer.symbol(navigatorOptions.handles.symbols[index], -navigatorOptions.handles.width / 2 - 1, 0, navigatorOptions.handles.width, navigatorOptions.handles.height, navigatorOptions.handles);
  1704. // zIndex = 6 for right handle, 7 for left.
  1705. // Can't be 10, because of the tooltip in inverted chart #2908
  1706. navigator.handles[index].attr({ zIndex: 7 - index })
  1707. .addClass('highcharts-navigator-handle ' +
  1708. 'highcharts-navigator-handle-' +
  1709. ['left', 'right'][index]).add(navigatorGroup);
  1710. if (!chart.styledMode) {
  1711. var handlesOptions = navigatorOptions.handles;
  1712. navigator.handles[index]
  1713. .attr({
  1714. fill: handlesOptions.backgroundColor,
  1715. stroke: handlesOptions.borderColor,
  1716. 'stroke-width': handlesOptions.lineWidth
  1717. })
  1718. .css(mouseCursor);
  1719. }
  1720. });
  1721. }
  1722. },
  1723. /**
  1724. * Update navigator
  1725. *
  1726. * @private
  1727. * @function Highcharts.Navigator#update
  1728. *
  1729. * @param {Highcharts.NavigatorOptions} options
  1730. * Options to merge in when updating navigator
  1731. */
  1732. update: function (options) {
  1733. // Remove references to old navigator series in base series
  1734. (this.series || []).forEach(function (series) {
  1735. if (series.baseSeries) {
  1736. delete series.baseSeries.navigatorSeries;
  1737. }
  1738. });
  1739. // Destroy and rebuild navigator
  1740. this.destroy();
  1741. var chartOptions = this.chart.options;
  1742. merge(true, chartOptions.navigator, this.options, options);
  1743. this.init(this.chart);
  1744. },
  1745. /**
  1746. * Render the navigator
  1747. *
  1748. * @private
  1749. * @function Highcharts.Navigator#render
  1750. * @param {number} min
  1751. * X axis value minimum
  1752. * @param {number} max
  1753. * X axis value maximum
  1754. * @param {number} [pxMin]
  1755. * Pixel value minimum
  1756. * @param {number} [pxMax]
  1757. * Pixel value maximum
  1758. * @return {void}
  1759. */
  1760. render: function (min, max, pxMin, pxMax) {
  1761. var navigator = this, chart = navigator.chart, navigatorWidth, scrollbarLeft, scrollbarTop, scrollbarHeight = navigator.scrollbarHeight, navigatorSize, xAxis = navigator.xAxis, pointRange = xAxis.pointRange || 0, scrollbarXAxis = xAxis.fake ? chart.xAxis[0] : xAxis, navigatorEnabled = navigator.navigatorEnabled, zoomedMin, zoomedMax, rendered = navigator.rendered, inverted = chart.inverted, verb, newMin, newMax, currentRange, minRange = chart.xAxis[0].minRange, maxRange = chart.xAxis[0].options.maxRange;
  1762. // Don't redraw while moving the handles (#4703).
  1763. if (this.hasDragged && !defined(pxMin)) {
  1764. return;
  1765. }
  1766. min = correctFloat(min - pointRange / 2);
  1767. max = correctFloat(max + pointRange / 2);
  1768. // Don't render the navigator until we have data (#486, #4202, #5172).
  1769. if (!isNumber(min) || !isNumber(max)) {
  1770. // However, if navigator was already rendered, we may need to resize
  1771. // it. For example hidden series, but visible navigator (#6022).
  1772. if (rendered) {
  1773. pxMin = 0;
  1774. pxMax = pick(xAxis.width, scrollbarXAxis.width);
  1775. }
  1776. else {
  1777. return;
  1778. }
  1779. }
  1780. navigator.left = pick(xAxis.left,
  1781. // in case of scrollbar only, without navigator
  1782. chart.plotLeft + scrollbarHeight +
  1783. (inverted ? chart.plotWidth : 0));
  1784. navigator.size = zoomedMax = navigatorSize = pick(xAxis.len, (inverted ? chart.plotHeight : chart.plotWidth) -
  1785. 2 * scrollbarHeight);
  1786. if (inverted) {
  1787. navigatorWidth = scrollbarHeight;
  1788. }
  1789. else {
  1790. navigatorWidth = navigatorSize + 2 * scrollbarHeight;
  1791. }
  1792. // Get the pixel position of the handles
  1793. pxMin = pick(pxMin, xAxis.toPixels(min, true));
  1794. pxMax = pick(pxMax, xAxis.toPixels(max, true));
  1795. // Verify (#1851, #2238)
  1796. if (!isNumber(pxMin) || Math.abs(pxMin) === Infinity) {
  1797. pxMin = 0;
  1798. pxMax = navigatorWidth;
  1799. }
  1800. // Are we below the minRange? (#2618, #6191)
  1801. newMin = xAxis.toValue(pxMin, true);
  1802. newMax = xAxis.toValue(pxMax, true);
  1803. currentRange = Math.abs(correctFloat(newMax - newMin));
  1804. if (currentRange < minRange) {
  1805. if (this.grabbedLeft) {
  1806. pxMin = xAxis.toPixels(newMax - minRange - pointRange, true);
  1807. }
  1808. else if (this.grabbedRight) {
  1809. pxMax = xAxis.toPixels(newMin + minRange + pointRange, true);
  1810. }
  1811. }
  1812. else if (defined(maxRange) &&
  1813. correctFloat(currentRange - pointRange) > maxRange) {
  1814. if (this.grabbedLeft) {
  1815. pxMin = xAxis.toPixels(newMax - maxRange - pointRange, true);
  1816. }
  1817. else if (this.grabbedRight) {
  1818. pxMax = xAxis.toPixels(newMin + maxRange + pointRange, true);
  1819. }
  1820. }
  1821. // Handles are allowed to cross, but never exceed the plot area
  1822. navigator.zoomedMax = clamp(Math.max(pxMin, pxMax), 0, zoomedMax);
  1823. navigator.zoomedMin = clamp(navigator.fixedWidth ?
  1824. navigator.zoomedMax - navigator.fixedWidth :
  1825. Math.min(pxMin, pxMax), 0, zoomedMax);
  1826. navigator.range = navigator.zoomedMax - navigator.zoomedMin;
  1827. zoomedMax = Math.round(navigator.zoomedMax);
  1828. zoomedMin = Math.round(navigator.zoomedMin);
  1829. if (navigatorEnabled) {
  1830. navigator.navigatorGroup.attr({
  1831. visibility: 'visible'
  1832. });
  1833. // Place elements
  1834. verb = rendered && !navigator.hasDragged ? 'animate' : 'attr';
  1835. navigator.drawMasks(zoomedMin, zoomedMax, inverted, verb);
  1836. navigator.drawOutline(zoomedMin, zoomedMax, inverted, verb);
  1837. if (navigator.navigatorOptions.handles.enabled) {
  1838. navigator.drawHandle(zoomedMin, 0, inverted, verb);
  1839. navigator.drawHandle(zoomedMax, 1, inverted, verb);
  1840. }
  1841. }
  1842. if (navigator.scrollbar) {
  1843. if (inverted) {
  1844. scrollbarTop = navigator.top - scrollbarHeight;
  1845. scrollbarLeft = navigator.left - scrollbarHeight +
  1846. (navigatorEnabled || !scrollbarXAxis.opposite ? 0 :
  1847. // Multiple axes has offsets:
  1848. (scrollbarXAxis.titleOffset || 0) +
  1849. // Self margin from the axis.title
  1850. scrollbarXAxis.axisTitleMargin);
  1851. scrollbarHeight = navigatorSize + 2 * scrollbarHeight;
  1852. }
  1853. else {
  1854. scrollbarTop = navigator.top + (navigatorEnabled ?
  1855. navigator.height :
  1856. -scrollbarHeight);
  1857. scrollbarLeft = navigator.left - scrollbarHeight;
  1858. }
  1859. // Reposition scrollbar
  1860. navigator.scrollbar.position(scrollbarLeft, scrollbarTop, navigatorWidth, scrollbarHeight);
  1861. // Keep scale 0-1
  1862. navigator.scrollbar.setRange(
  1863. // Use real value, not rounded because range can be very small
  1864. // (#1716)
  1865. navigator.zoomedMin / (navigatorSize || 1), navigator.zoomedMax / (navigatorSize || 1));
  1866. }
  1867. navigator.rendered = true;
  1868. },
  1869. /**
  1870. * Set up the mouse and touch events for the navigator
  1871. *
  1872. * @private
  1873. * @function Highcharts.Navigator#addMouseEvents
  1874. */
  1875. addMouseEvents: function () {
  1876. var navigator = this, chart = navigator.chart, container = chart.container, eventsToUnbind = [], mouseMoveHandler, mouseUpHandler;
  1877. /**
  1878. * Create mouse events' handlers.
  1879. * Make them as separate functions to enable wrapping them:
  1880. */
  1881. navigator.mouseMoveHandler = mouseMoveHandler = function (e) {
  1882. navigator.onMouseMove(e);
  1883. };
  1884. navigator.mouseUpHandler = mouseUpHandler = function (e) {
  1885. navigator.onMouseUp(e);
  1886. };
  1887. // Add shades and handles mousedown events
  1888. eventsToUnbind = navigator.getPartsEvents('mousedown');
  1889. // Add mouse move and mouseup events. These are bind to doc/container,
  1890. // because Navigator.grabbedSomething flags are stored in mousedown
  1891. // events
  1892. eventsToUnbind.push(addEvent(chart.renderTo, 'mousemove', mouseMoveHandler), addEvent(container.ownerDocument, 'mouseup', mouseUpHandler));
  1893. // Touch events
  1894. if (hasTouch) {
  1895. eventsToUnbind.push(addEvent(chart.renderTo, 'touchmove', mouseMoveHandler), addEvent(container.ownerDocument, 'touchend', mouseUpHandler));
  1896. eventsToUnbind.concat(navigator.getPartsEvents('touchstart'));
  1897. }
  1898. navigator.eventsToUnbind = eventsToUnbind;
  1899. // Data events
  1900. if (navigator.series && navigator.series[0]) {
  1901. eventsToUnbind.push(addEvent(navigator.series[0].xAxis, 'foundExtremes', function () {
  1902. chart.navigator.modifyNavigatorAxisExtremes();
  1903. }));
  1904. }
  1905. },
  1906. /**
  1907. * Generate events for handles and masks
  1908. *
  1909. * @private
  1910. * @function Highcharts.Navigator#getPartsEvents
  1911. *
  1912. * @param {string} eventName
  1913. * Event name handler, 'mousedown' or 'touchstart'
  1914. *
  1915. * @return {Array<Function>}
  1916. * An array of functions to remove navigator functions from the
  1917. * events again.
  1918. */
  1919. getPartsEvents: function (eventName) {
  1920. var navigator = this, events = [];
  1921. ['shades', 'handles'].forEach(function (name) {
  1922. navigator[name].forEach(function (navigatorItem, index) {
  1923. events.push(addEvent(navigatorItem.element, eventName, function (e) {
  1924. navigator[name + 'Mousedown'](e, index);
  1925. }));
  1926. });
  1927. });
  1928. return events;
  1929. },
  1930. /**
  1931. * Mousedown on a shaded mask, either:
  1932. *
  1933. * - will be stored for future drag&drop
  1934. *
  1935. * - will directly shift to a new range
  1936. *
  1937. * @private
  1938. * @function Highcharts.Navigator#shadesMousedown
  1939. *
  1940. * @param {Highcharts.PointerEventObject} e
  1941. * Mouse event
  1942. *
  1943. * @param {number} index
  1944. * Index of a mask in Navigator.shades array
  1945. */
  1946. shadesMousedown: function (e, index) {
  1947. e = this.chart.pointer.normalize(e);
  1948. var navigator = this, chart = navigator.chart, xAxis = navigator.xAxis, zoomedMin = navigator.zoomedMin, navigatorPosition = navigator.left, navigatorSize = navigator.size, range = navigator.range, chartX = e.chartX, fixedMax, fixedMin, ext, left;
  1949. // For inverted chart, swap some options:
  1950. if (chart.inverted) {
  1951. chartX = e.chartY;
  1952. navigatorPosition = navigator.top;
  1953. }
  1954. if (index === 1) {
  1955. // Store information for drag&drop
  1956. navigator.grabbedCenter = chartX;
  1957. navigator.fixedWidth = range;
  1958. navigator.dragOffset = chartX - zoomedMin;
  1959. }
  1960. else {
  1961. // Shift the range by clicking on shaded areas
  1962. left = chartX - navigatorPosition - range / 2;
  1963. if (index === 0) {
  1964. left = Math.max(0, left);
  1965. }
  1966. else if (index === 2 && left + range >= navigatorSize) {
  1967. left = navigatorSize - range;
  1968. if (navigator.reversedExtremes) {
  1969. // #7713
  1970. left -= range;
  1971. fixedMin = navigator.getUnionExtremes().dataMin;
  1972. }
  1973. else {
  1974. // #2293, #3543
  1975. fixedMax = navigator.getUnionExtremes().dataMax;
  1976. }
  1977. }
  1978. if (left !== zoomedMin) { // it has actually moved
  1979. navigator.fixedWidth = range; // #1370
  1980. ext = xAxis.toFixedRange(left, left + range, fixedMin, fixedMax);
  1981. if (defined(ext.min)) { // #7411
  1982. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true, null, // auto animation
  1983. { trigger: 'navigator' });
  1984. }
  1985. }
  1986. }
  1987. },
  1988. /**
  1989. * Mousedown on a handle mask.
  1990. * Will store necessary information for drag&drop.
  1991. *
  1992. * @private
  1993. * @function Highcharts.Navigator#handlesMousedown
  1994. * @param {Highcharts.PointerEventObject} e
  1995. * Mouse event
  1996. * @param {number} index
  1997. * Index of a handle in Navigator.handles array
  1998. * @return {void}
  1999. */
  2000. handlesMousedown: function (e, index) {
  2001. e = this.chart.pointer.normalize(e);
  2002. var navigator = this, chart = navigator.chart, baseXAxis = chart.xAxis[0],
  2003. // For reversed axes, min and max are changed,
  2004. // so the other extreme should be stored
  2005. reverse = navigator.reversedExtremes;
  2006. if (index === 0) {
  2007. // Grab the left handle
  2008. navigator.grabbedLeft = true;
  2009. navigator.otherHandlePos = navigator.zoomedMax;
  2010. navigator.fixedExtreme = reverse ? baseXAxis.min : baseXAxis.max;
  2011. }
  2012. else {
  2013. // Grab the right handle
  2014. navigator.grabbedRight = true;
  2015. navigator.otherHandlePos = navigator.zoomedMin;
  2016. navigator.fixedExtreme = reverse ? baseXAxis.max : baseXAxis.min;
  2017. }
  2018. chart.fixedRange = null;
  2019. },
  2020. /**
  2021. * Mouse move event based on x/y mouse position.
  2022. *
  2023. * @private
  2024. * @function Highcharts.Navigator#onMouseMove
  2025. *
  2026. * @param {Highcharts.PointerEventObject} e
  2027. * Mouse event
  2028. */
  2029. onMouseMove: function (e) {
  2030. var navigator = this, chart = navigator.chart, left = navigator.left, navigatorSize = navigator.navigatorSize, range = navigator.range, dragOffset = navigator.dragOffset, inverted = chart.inverted, chartX;
  2031. // In iOS, a mousemove event with e.pageX === 0 is fired when holding
  2032. // the finger down in the center of the scrollbar. This should be
  2033. // ignored.
  2034. if (!e.touches || e.touches[0].pageX !== 0) { // #4696
  2035. e = chart.pointer.normalize(e);
  2036. chartX = e.chartX;
  2037. // Swap some options for inverted chart
  2038. if (inverted) {
  2039. left = navigator.top;
  2040. chartX = e.chartY;
  2041. }
  2042. // Drag left handle or top handle
  2043. if (navigator.grabbedLeft) {
  2044. navigator.hasDragged = true;
  2045. navigator.render(0, 0, chartX - left, navigator.otherHandlePos);
  2046. // Drag right handle or bottom handle
  2047. }
  2048. else if (navigator.grabbedRight) {
  2049. navigator.hasDragged = true;
  2050. navigator.render(0, 0, navigator.otherHandlePos, chartX - left);
  2051. // Drag scrollbar or open area in navigator
  2052. }
  2053. else if (navigator.grabbedCenter) {
  2054. navigator.hasDragged = true;
  2055. if (chartX < dragOffset) { // outside left
  2056. chartX = dragOffset;
  2057. // outside right
  2058. }
  2059. else if (chartX >
  2060. navigatorSize + dragOffset - range) {
  2061. chartX = navigatorSize + dragOffset - range;
  2062. }
  2063. navigator.render(0, 0, chartX - dragOffset, chartX - dragOffset + range);
  2064. }
  2065. if (navigator.hasDragged &&
  2066. navigator.scrollbar &&
  2067. pick(navigator.scrollbar.options.liveRedraw,
  2068. // By default, don't run live redraw on VML, on touch
  2069. // devices or if the chart is in boost.
  2070. H.svg && !isTouchDevice && !this.chart.isBoosting)) {
  2071. e.DOMType = e.type; // DOMType is for IE8
  2072. setTimeout(function () {
  2073. navigator.onMouseUp(e);
  2074. }, 0);
  2075. }
  2076. }
  2077. },
  2078. /**
  2079. * Mouse up event based on x/y mouse position.
  2080. *
  2081. * @private
  2082. * @function Highcharts.Navigator#onMouseUp
  2083. * @param {Highcharts.PointerEventObject} e
  2084. * Mouse event
  2085. * @return {void}
  2086. */
  2087. onMouseUp: function (e) {
  2088. var navigator = this, chart = navigator.chart, xAxis = navigator.xAxis, scrollbar = navigator.scrollbar, unionExtremes, fixedMin, fixedMax, ext, DOMEvent = e.DOMEvent || e;
  2089. if (
  2090. // MouseUp is called for both, navigator and scrollbar (that order),
  2091. // which causes calling afterSetExtremes twice. Prevent first call
  2092. // by checking if scrollbar is going to set new extremes (#6334)
  2093. (navigator.hasDragged && (!scrollbar || !scrollbar.hasDragged)) ||
  2094. e.trigger === 'scrollbar') {
  2095. unionExtremes = navigator.getUnionExtremes();
  2096. // When dragging one handle, make sure the other one doesn't change
  2097. if (navigator.zoomedMin === navigator.otherHandlePos) {
  2098. fixedMin = navigator.fixedExtreme;
  2099. }
  2100. else if (navigator.zoomedMax === navigator.otherHandlePos) {
  2101. fixedMax = navigator.fixedExtreme;
  2102. }
  2103. // Snap to right edge (#4076)
  2104. if (navigator.zoomedMax === navigator.size) {
  2105. fixedMax = navigator.reversedExtremes ?
  2106. unionExtremes.dataMin :
  2107. unionExtremes.dataMax;
  2108. }
  2109. // Snap to left edge (#7576)
  2110. if (navigator.zoomedMin === 0) {
  2111. fixedMin = navigator.reversedExtremes ?
  2112. unionExtremes.dataMax :
  2113. unionExtremes.dataMin;
  2114. }
  2115. ext = xAxis.toFixedRange(navigator.zoomedMin, navigator.zoomedMax, fixedMin, fixedMax);
  2116. if (defined(ext.min)) {
  2117. chart.xAxis[0].setExtremes(Math.min(ext.min, ext.max), Math.max(ext.min, ext.max), true,
  2118. // Run animation when clicking buttons, scrollbar track etc,
  2119. // but not when dragging handles or scrollbar
  2120. navigator.hasDragged ? false : null, {
  2121. trigger: 'navigator',
  2122. triggerOp: 'navigator-drag',
  2123. DOMEvent: DOMEvent // #1838
  2124. });
  2125. }
  2126. }
  2127. if (e.DOMType !== 'mousemove' &&
  2128. e.DOMType !== 'touchmove') {
  2129. navigator.grabbedLeft = navigator.grabbedRight =
  2130. navigator.grabbedCenter = navigator.fixedWidth =
  2131. navigator.fixedExtreme = navigator.otherHandlePos =
  2132. navigator.hasDragged = navigator.dragOffset = null;
  2133. }
  2134. },
  2135. /**
  2136. * Removes the event handlers attached previously with addEvents.
  2137. *
  2138. * @private
  2139. * @function Highcharts.Navigator#removeEvents
  2140. * @return {void}
  2141. */
  2142. removeEvents: function () {
  2143. if (this.eventsToUnbind) {
  2144. this.eventsToUnbind.forEach(function (unbind) {
  2145. unbind();
  2146. });
  2147. this.eventsToUnbind = void 0;
  2148. }
  2149. this.removeBaseSeriesEvents();
  2150. },
  2151. /**
  2152. * Remove data events.
  2153. *
  2154. * @private
  2155. * @function Highcharts.Navigator#removeBaseSeriesEvents
  2156. * @return {void}
  2157. */
  2158. removeBaseSeriesEvents: function () {
  2159. var baseSeries = this.baseSeries || [];
  2160. if (this.navigatorEnabled && baseSeries[0]) {
  2161. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  2162. baseSeries.forEach(function (series) {
  2163. removeEvent(series, 'updatedData', this.updatedDataHandler);
  2164. }, this);
  2165. }
  2166. // We only listen for extremes-events on the first baseSeries
  2167. if (baseSeries[0].xAxis) {
  2168. removeEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  2169. }
  2170. }
  2171. },
  2172. /**
  2173. * Initialize the Navigator object
  2174. *
  2175. * @private
  2176. * @function Highcharts.Navigator#init
  2177. *
  2178. * @param {Highcharts.Chart} chart
  2179. */
  2180. init: function (chart) {
  2181. var chartOptions = chart.options, navigatorOptions = chartOptions.navigator, navigatorEnabled = navigatorOptions.enabled, scrollbarOptions = chartOptions.scrollbar, scrollbarEnabled = scrollbarOptions.enabled, height = navigatorEnabled ? navigatorOptions.height : 0, scrollbarHeight = scrollbarEnabled ?
  2182. scrollbarOptions.height :
  2183. 0;
  2184. this.handles = [];
  2185. this.shades = [];
  2186. this.chart = chart;
  2187. this.setBaseSeries();
  2188. this.height = height;
  2189. this.scrollbarHeight = scrollbarHeight;
  2190. this.scrollbarEnabled = scrollbarEnabled;
  2191. this.navigatorEnabled = navigatorEnabled;
  2192. this.navigatorOptions = navigatorOptions;
  2193. this.scrollbarOptions = scrollbarOptions;
  2194. this.outlineHeight = height + scrollbarHeight;
  2195. this.opposite = pick(navigatorOptions.opposite, Boolean(!navigatorEnabled && chart.inverted)); // #6262
  2196. var navigator = this, baseSeries = navigator.baseSeries, xAxisIndex = chart.xAxis.length, yAxisIndex = chart.yAxis.length, baseXaxis = baseSeries && baseSeries[0] && baseSeries[0].xAxis ||
  2197. chart.xAxis[0] || { options: {} };
  2198. chart.isDirtyBox = true;
  2199. if (navigator.navigatorEnabled) {
  2200. // an x axis is required for scrollbar also
  2201. navigator.xAxis = new Axis(chart, merge({
  2202. // inherit base xAxis' break and ordinal options
  2203. breaks: baseXaxis.options.breaks,
  2204. ordinal: baseXaxis.options.ordinal
  2205. }, navigatorOptions.xAxis, {
  2206. id: 'navigator-x-axis',
  2207. yAxis: 'navigator-y-axis',
  2208. isX: true,
  2209. type: 'datetime',
  2210. index: xAxisIndex,
  2211. isInternal: true,
  2212. offset: 0,
  2213. keepOrdinalPadding: true,
  2214. startOnTick: false,
  2215. endOnTick: false,
  2216. minPadding: 0,
  2217. maxPadding: 0,
  2218. zoomEnabled: false
  2219. }, chart.inverted ? {
  2220. offsets: [scrollbarHeight, 0, -scrollbarHeight, 0],
  2221. width: height
  2222. } : {
  2223. offsets: [0, -scrollbarHeight, 0, scrollbarHeight],
  2224. height: height
  2225. }));
  2226. navigator.yAxis = new Axis(chart, merge(navigatorOptions.yAxis, {
  2227. id: 'navigator-y-axis',
  2228. alignTicks: false,
  2229. offset: 0,
  2230. index: yAxisIndex,
  2231. isInternal: true,
  2232. zoomEnabled: false
  2233. }, chart.inverted ? {
  2234. width: height
  2235. } : {
  2236. height: height
  2237. }));
  2238. // If we have a base series, initialize the navigator series
  2239. if (baseSeries || navigatorOptions.series.data) {
  2240. navigator.updateNavigatorSeries(false);
  2241. // If not, set up an event to listen for added series
  2242. }
  2243. else if (chart.series.length === 0) {
  2244. navigator.unbindRedraw = addEvent(chart, 'beforeRedraw', function () {
  2245. // We've got one, now add it as base
  2246. if (chart.series.length > 0 && !navigator.series) {
  2247. navigator.setBaseSeries();
  2248. navigator.unbindRedraw(); // reset
  2249. }
  2250. });
  2251. }
  2252. navigator.reversedExtremes = (chart.inverted && !navigator.xAxis.reversed) || (!chart.inverted && navigator.xAxis.reversed);
  2253. // Render items, so we can bind events to them:
  2254. navigator.renderElements();
  2255. // Add mouse events
  2256. navigator.addMouseEvents();
  2257. // in case of scrollbar only, fake an x axis to get translation
  2258. }
  2259. else {
  2260. navigator.xAxis = {
  2261. translate: function (value, reverse) {
  2262. var axis = chart.xAxis[0], ext = axis.getExtremes(), scrollTrackWidth = axis.len - 2 * scrollbarHeight, min = numExt('min', axis.options.min, ext.dataMin), valueRange = numExt('max', axis.options.max, ext.dataMax) - min;
  2263. return reverse ?
  2264. // from pixel to value
  2265. (value * valueRange / scrollTrackWidth) + min :
  2266. // from value to pixel
  2267. scrollTrackWidth * (value - min) / valueRange;
  2268. },
  2269. toPixels: function (value) {
  2270. return this.translate(value);
  2271. },
  2272. toValue: function (value) {
  2273. return this.translate(value, true);
  2274. },
  2275. toFixedRange: Axis.prototype.toFixedRange,
  2276. fake: true
  2277. };
  2278. }
  2279. // Initialize the scrollbar
  2280. if (chart.options.scrollbar.enabled) {
  2281. chart.scrollbar = navigator.scrollbar = new Scrollbar(chart.renderer, merge(chart.options.scrollbar, {
  2282. margin: navigator.navigatorEnabled ? 0 : 10,
  2283. vertical: chart.inverted
  2284. }), chart);
  2285. addEvent(navigator.scrollbar, 'changed', function (e) {
  2286. var range = navigator.size, to = range * this.to, from = range * this.from;
  2287. navigator.hasDragged = navigator.scrollbar.hasDragged;
  2288. navigator.render(0, 0, from, to);
  2289. if (chart.options.scrollbar.liveRedraw ||
  2290. (e.DOMType !== 'mousemove' &&
  2291. e.DOMType !== 'touchmove')) {
  2292. setTimeout(function () {
  2293. navigator.onMouseUp(e);
  2294. });
  2295. }
  2296. });
  2297. }
  2298. // Add data events
  2299. navigator.addBaseSeriesEvents();
  2300. // Add redraw events
  2301. navigator.addChartEvents();
  2302. },
  2303. /**
  2304. * Get the union data extremes of the chart - the outer data extremes of the
  2305. * base X axis and the navigator axis.
  2306. *
  2307. * @private
  2308. * @function Highcharts.Navigator#getUnionExtremes
  2309. * @param {boolean} [returnFalseOnNoBaseSeries]
  2310. * as the param says.
  2311. * @return {Highcharts.Dictionary<(number|undefined)>|undefined}
  2312. */
  2313. getUnionExtremes: function (returnFalseOnNoBaseSeries) {
  2314. var baseAxis = this.chart.xAxis[0], navAxis = this.xAxis, navAxisOptions = navAxis.options, baseAxisOptions = baseAxis.options, ret;
  2315. if (!returnFalseOnNoBaseSeries || baseAxis.dataMin !== null) {
  2316. ret = {
  2317. dataMin: pick(// #4053
  2318. navAxisOptions && navAxisOptions.min, numExt('min', baseAxisOptions.min, baseAxis.dataMin, navAxis.dataMin, navAxis.min)),
  2319. dataMax: pick(navAxisOptions && navAxisOptions.max, numExt('max', baseAxisOptions.max, baseAxis.dataMax, navAxis.dataMax, navAxis.max))
  2320. };
  2321. }
  2322. return ret;
  2323. },
  2324. /**
  2325. * Set the base series and update the navigator series from this. With a bit
  2326. * of modification we should be able to make this an API method to be called
  2327. * from the outside
  2328. *
  2329. * @private
  2330. * @function Highcharts.Navigator#setBaseSeries
  2331. * @param {Highcharts.SeriesOptionsType} [baseSeriesOptions]
  2332. * Additional series options for a navigator
  2333. * @param {boolean} [redraw]
  2334. * Whether to redraw after update.
  2335. * @return {void}
  2336. */
  2337. setBaseSeries: function (baseSeriesOptions, redraw) {
  2338. var chart = this.chart, baseSeries = this.baseSeries = [];
  2339. baseSeriesOptions = (baseSeriesOptions ||
  2340. chart.options && chart.options.navigator.baseSeries ||
  2341. (chart.series.length ?
  2342. // Find the first non-navigator series (#8430)
  2343. H.find(chart.series, function (s) {
  2344. return !s.options.isInternal;
  2345. }).index :
  2346. 0));
  2347. // Iterate through series and add the ones that should be shown in
  2348. // navigator.
  2349. (chart.series || []).forEach(function (series, i) {
  2350. if (
  2351. // Don't include existing nav series
  2352. !series.options.isInternal &&
  2353. (series.options.showInNavigator ||
  2354. (i === baseSeriesOptions ||
  2355. series.options.id === baseSeriesOptions) &&
  2356. series.options.showInNavigator !== false)) {
  2357. baseSeries.push(series);
  2358. }
  2359. });
  2360. // When run after render, this.xAxis already exists
  2361. if (this.xAxis && !this.xAxis.fake) {
  2362. this.updateNavigatorSeries(true, redraw);
  2363. }
  2364. },
  2365. /**
  2366. * Update series in the navigator from baseSeries, adding new if does not
  2367. * exist.
  2368. *
  2369. * @private
  2370. * @function Highcharts.Navigator.updateNavigatorSeries
  2371. * @param {boolean} addEvents
  2372. * @param {boolean} [redraw]
  2373. * @return {void}
  2374. */
  2375. updateNavigatorSeries: function (addEvents, redraw) {
  2376. var navigator = this, chart = navigator.chart, baseSeries = navigator.baseSeries, baseOptions, mergedNavSeriesOptions, chartNavigatorSeriesOptions = navigator.navigatorOptions.series, baseNavigatorOptions, navSeriesMixin = {
  2377. enableMouseTracking: false,
  2378. index: null,
  2379. linkedTo: null,
  2380. group: 'nav',
  2381. padXAxis: false,
  2382. xAxis: 'navigator-x-axis',
  2383. yAxis: 'navigator-y-axis',
  2384. showInLegend: false,
  2385. stacking: false,
  2386. isInternal: true,
  2387. states: {
  2388. inactive: {
  2389. opacity: 1
  2390. }
  2391. }
  2392. },
  2393. // Remove navigator series that are no longer in the baseSeries
  2394. navigatorSeries = navigator.series =
  2395. (navigator.series || []).filter(function (navSeries) {
  2396. var base = navSeries.baseSeries;
  2397. if (baseSeries.indexOf(base) < 0) { // Not in array
  2398. // If there is still a base series connected to this
  2399. // series, remove event handler and reference.
  2400. if (base) {
  2401. removeEvent(base, 'updatedData', navigator.updatedDataHandler);
  2402. delete base.navigatorSeries;
  2403. }
  2404. // Kill the nav series. It may already have been
  2405. // destroyed (#8715).
  2406. if (navSeries.chart) {
  2407. navSeries.destroy();
  2408. }
  2409. return false;
  2410. }
  2411. return true;
  2412. });
  2413. // Go through each base series and merge the options to create new
  2414. // series
  2415. if (baseSeries && baseSeries.length) {
  2416. baseSeries.forEach(function eachBaseSeries(base) {
  2417. var linkedNavSeries = base.navigatorSeries, userNavOptions = extend(
  2418. // Grab color and visibility from base as default
  2419. {
  2420. color: base.color,
  2421. visible: base.visible
  2422. }, !isArray(chartNavigatorSeriesOptions) ?
  2423. chartNavigatorSeriesOptions :
  2424. defaultOptions.navigator.series);
  2425. // Don't update if the series exists in nav and we have disabled
  2426. // adaptToUpdatedData.
  2427. if (linkedNavSeries &&
  2428. navigator.navigatorOptions.adaptToUpdatedData === false) {
  2429. return;
  2430. }
  2431. navSeriesMixin.name = 'Navigator ' + baseSeries.length;
  2432. baseOptions = base.options || {};
  2433. baseNavigatorOptions = baseOptions.navigatorOptions || {};
  2434. mergedNavSeriesOptions = merge(baseOptions, navSeriesMixin, userNavOptions, baseNavigatorOptions);
  2435. // Once nav series type is resolved, pick correct pointRange
  2436. mergedNavSeriesOptions.pointRange = pick(
  2437. // Stricte set pointRange in options
  2438. userNavOptions.pointRange, baseNavigatorOptions.pointRange,
  2439. // Fallback to default values, e.g. `null` for column
  2440. defaultOptions.plotOptions[mergedNavSeriesOptions.type || 'line'].pointRange);
  2441. // Merge data separately. Do a slice to avoid mutating the
  2442. // navigator options from base series (#4923).
  2443. var navigatorSeriesData = baseNavigatorOptions.data || userNavOptions.data;
  2444. navigator.hasNavigatorData =
  2445. navigator.hasNavigatorData || !!navigatorSeriesData;
  2446. mergedNavSeriesOptions.data =
  2447. navigatorSeriesData ||
  2448. baseOptions.data && baseOptions.data.slice(0);
  2449. // Update or add the series
  2450. if (linkedNavSeries && linkedNavSeries.options) {
  2451. linkedNavSeries.update(mergedNavSeriesOptions, redraw);
  2452. }
  2453. else {
  2454. base.navigatorSeries = chart.initSeries(mergedNavSeriesOptions);
  2455. base.navigatorSeries.baseSeries = base; // Store ref
  2456. navigatorSeries.push(base.navigatorSeries);
  2457. }
  2458. });
  2459. }
  2460. // If user has defined data (and no base series) or explicitly defined
  2461. // navigator.series as an array, we create these series on top of any
  2462. // base series.
  2463. if (chartNavigatorSeriesOptions.data &&
  2464. !(baseSeries && baseSeries.length) ||
  2465. isArray(chartNavigatorSeriesOptions)) {
  2466. navigator.hasNavigatorData = false;
  2467. // Allow navigator.series to be an array
  2468. chartNavigatorSeriesOptions =
  2469. splat(chartNavigatorSeriesOptions);
  2470. chartNavigatorSeriesOptions.forEach(function (userSeriesOptions, i) {
  2471. navSeriesMixin.name =
  2472. 'Navigator ' + (navigatorSeries.length + 1);
  2473. mergedNavSeriesOptions = merge(defaultOptions.navigator.series, {
  2474. // Since we don't have a base series to pull color from,
  2475. // try to fake it by using color from series with same
  2476. // index. Otherwise pull from the colors array. We need
  2477. // an explicit color as otherwise updates will increment
  2478. // color counter and we'll get a new color for each
  2479. // update of the nav series.
  2480. color: chart.series[i] &&
  2481. !chart.series[i].options.isInternal &&
  2482. chart.series[i].color ||
  2483. chart.options.colors[i] ||
  2484. chart.options.colors[0]
  2485. }, navSeriesMixin, userSeriesOptions);
  2486. mergedNavSeriesOptions.data = userSeriesOptions.data;
  2487. if (mergedNavSeriesOptions.data) {
  2488. navigator.hasNavigatorData = true;
  2489. navigatorSeries.push(chart.initSeries(mergedNavSeriesOptions));
  2490. }
  2491. });
  2492. }
  2493. if (addEvents) {
  2494. this.addBaseSeriesEvents();
  2495. }
  2496. },
  2497. /**
  2498. * Add data events.
  2499. * For example when main series is updated we need to recalculate extremes
  2500. *
  2501. * @private
  2502. * @function Highcharts.Navigator#addBaseSeriesEvent
  2503. * @return {void}
  2504. */
  2505. addBaseSeriesEvents: function () {
  2506. var navigator = this, baseSeries = navigator.baseSeries || [];
  2507. // Bind modified extremes event to first base's xAxis only.
  2508. // In event of > 1 base-xAxes, the navigator will ignore those.
  2509. // Adding this multiple times to the same axis is no problem, as
  2510. // duplicates should be discarded by the browser.
  2511. if (baseSeries[0] && baseSeries[0].xAxis) {
  2512. addEvent(baseSeries[0].xAxis, 'foundExtremes', this.modifyBaseAxisExtremes);
  2513. }
  2514. baseSeries.forEach(function (base) {
  2515. // Link base series show/hide to navigator series visibility
  2516. addEvent(base, 'show', function () {
  2517. if (this.navigatorSeries) {
  2518. this.navigatorSeries.setVisible(true, false);
  2519. }
  2520. });
  2521. addEvent(base, 'hide', function () {
  2522. if (this.navigatorSeries) {
  2523. this.navigatorSeries.setVisible(false, false);
  2524. }
  2525. });
  2526. // Respond to updated data in the base series, unless explicitily
  2527. // not adapting to data changes.
  2528. if (this.navigatorOptions.adaptToUpdatedData !== false) {
  2529. if (base.xAxis) {
  2530. addEvent(base, 'updatedData', this.updatedDataHandler);
  2531. }
  2532. }
  2533. // Handle series removal
  2534. addEvent(base, 'remove', function () {
  2535. if (this.navigatorSeries) {
  2536. erase(navigator.series, this.navigatorSeries);
  2537. if (defined(this.navigatorSeries.options)) {
  2538. this.navigatorSeries.remove(false);
  2539. }
  2540. delete this.navigatorSeries;
  2541. }
  2542. });
  2543. }, this);
  2544. },
  2545. /**
  2546. * Get minimum from all base series connected to the navigator
  2547. * @private
  2548. * @param {number} currentSeriesMin
  2549. * Minium from the current series
  2550. * @return {number} Minimum from all series
  2551. */
  2552. getBaseSeriesMin: function (currentSeriesMin) {
  2553. return this.baseSeries.reduce(function (min, series) {
  2554. // (#10193)
  2555. return Math.min(min, series.xData ? series.xData[0] : min);
  2556. }, currentSeriesMin);
  2557. },
  2558. /**
  2559. * Set the navigator x axis extremes to reflect the total. The navigator
  2560. * extremes should always be the extremes of the union of all series in the
  2561. * chart as well as the navigator series.
  2562. *
  2563. * @private
  2564. * @function Highcharts.Navigator#modifyNavigatorAxisExtremes
  2565. */
  2566. modifyNavigatorAxisExtremes: function () {
  2567. var xAxis = this.xAxis, unionExtremes;
  2568. if (typeof xAxis.getExtremes !== 'undefined') {
  2569. unionExtremes = this.getUnionExtremes(true);
  2570. if (unionExtremes &&
  2571. (unionExtremes.dataMin !== xAxis.min ||
  2572. unionExtremes.dataMax !== xAxis.max)) {
  2573. xAxis.min = unionExtremes.dataMin;
  2574. xAxis.max = unionExtremes.dataMax;
  2575. }
  2576. }
  2577. },
  2578. /**
  2579. * Hook to modify the base axis extremes with information from the Navigator
  2580. *
  2581. * @private
  2582. * @function Highcharts.Navigator#modifyBaseAxisExtremes
  2583. */
  2584. modifyBaseAxisExtremes: function () {
  2585. var baseXAxis = this, navigator = baseXAxis.chart.navigator, baseExtremes = baseXAxis.getExtremes(), baseMin = baseExtremes.min, baseMax = baseExtremes.max, baseDataMin = baseExtremes.dataMin, baseDataMax = baseExtremes.dataMax, range = baseMax - baseMin, stickToMin = navigator.stickToMin, stickToMax = navigator.stickToMax, overscroll = pick(baseXAxis.options.overscroll, 0), newMax, newMin, navigatorSeries = navigator.series && navigator.series[0], hasSetExtremes = !!baseXAxis.setExtremes,
  2586. // When the extremes have been set by range selector button, don't
  2587. // stick to min or max. The range selector buttons will handle the
  2588. // extremes. (#5489)
  2589. unmutable = baseXAxis.eventArgs &&
  2590. baseXAxis.eventArgs.trigger === 'rangeSelectorButton';
  2591. if (!unmutable) {
  2592. // If the zoomed range is already at the min, move it to the right
  2593. // as new data comes in
  2594. if (stickToMin) {
  2595. newMin = baseDataMin;
  2596. newMax = newMin + range;
  2597. }
  2598. // If the zoomed range is already at the max, move it to the right
  2599. // as new data comes in
  2600. if (stickToMax) {
  2601. newMax = baseDataMax + overscroll;
  2602. // if stickToMin is true, the new min value is set above
  2603. if (!stickToMin) {
  2604. newMin = Math.max(newMax - range, navigator.getBaseSeriesMin(navigatorSeries && navigatorSeries.xData ?
  2605. navigatorSeries.xData[0] :
  2606. -Number.MAX_VALUE));
  2607. }
  2608. }
  2609. // Update the extremes
  2610. if (hasSetExtremes && (stickToMin || stickToMax)) {
  2611. if (isNumber(newMin)) {
  2612. baseXAxis.min = baseXAxis.userMin = newMin;
  2613. baseXAxis.max = baseXAxis.userMax = newMax;
  2614. }
  2615. }
  2616. }
  2617. // Reset
  2618. navigator.stickToMin =
  2619. navigator.stickToMax = null;
  2620. },
  2621. /**
  2622. * Handler for updated data on the base series. When data is modified, the
  2623. * navigator series must reflect it. This is called from the Chart.redraw
  2624. * function before axis and series extremes are computed.
  2625. *
  2626. * @private
  2627. * @function Highcharts.Navigator#updateDataHandler
  2628. */
  2629. updatedDataHandler: function () {
  2630. var navigator = this.chart.navigator, baseSeries = this, navigatorSeries = this.navigatorSeries, xDataMin = navigator.getBaseSeriesMin(baseSeries.xData[0]);
  2631. // If the scrollbar is scrolled all the way to the right, keep right as
  2632. // new data comes in.
  2633. navigator.stickToMax = navigator.reversedExtremes ?
  2634. Math.round(navigator.zoomedMin) === 0 :
  2635. Math.round(navigator.zoomedMax) >= Math.round(navigator.size);
  2636. // Detect whether the zoomed area should stick to the minimum or
  2637. // maximum. If the current axis minimum falls outside the new updated
  2638. // dataset, we must adjust.
  2639. navigator.stickToMin = isNumber(baseSeries.xAxis.min) &&
  2640. (baseSeries.xAxis.min <= xDataMin) &&
  2641. (!this.chart.fixedRange || !navigator.stickToMax);
  2642. // Set the navigator series data to the new data of the base series
  2643. if (navigatorSeries && !navigator.hasNavigatorData) {
  2644. navigatorSeries.options.pointStart = baseSeries.xData[0];
  2645. navigatorSeries.setData(baseSeries.options.data, false, null, false); // #5414
  2646. }
  2647. },
  2648. /**
  2649. * Add chart events, like redrawing navigator, when chart requires that.
  2650. *
  2651. * @private
  2652. * @function Highcharts.Navigator#addChartEvents
  2653. * @return {void}
  2654. */
  2655. addChartEvents: function () {
  2656. if (!this.eventsToUnbind) {
  2657. this.eventsToUnbind = [];
  2658. }
  2659. this.eventsToUnbind.push(
  2660. // Move the scrollbar after redraw, like after data updata even if
  2661. // axes don't redraw
  2662. addEvent(this.chart, 'redraw', function () {
  2663. var navigator = this.navigator, xAxis = navigator && (navigator.baseSeries &&
  2664. navigator.baseSeries[0] &&
  2665. navigator.baseSeries[0].xAxis ||
  2666. navigator.scrollbar && this.xAxis[0]); // #5709
  2667. if (xAxis) {
  2668. navigator.render(xAxis.min, xAxis.max);
  2669. }
  2670. }),
  2671. // Make room for the navigator, can be placed around the chart:
  2672. addEvent(this.chart, 'getMargins', function () {
  2673. var chart = this, navigator = chart.navigator, marginName = navigator.opposite ?
  2674. 'plotTop' : 'marginBottom';
  2675. if (chart.inverted) {
  2676. marginName = navigator.opposite ?
  2677. 'marginRight' : 'plotLeft';
  2678. }
  2679. chart[marginName] =
  2680. (chart[marginName] || 0) + (navigator.navigatorEnabled || !chart.inverted ?
  2681. navigator.outlineHeight :
  2682. 0) + navigator.navigatorOptions.margin;
  2683. }));
  2684. },
  2685. /**
  2686. * Destroys allocated elements.
  2687. *
  2688. * @private
  2689. * @function Highcharts.Navigator#destroy
  2690. */
  2691. destroy: function () {
  2692. // Disconnect events added in addEvents
  2693. this.removeEvents();
  2694. if (this.xAxis) {
  2695. erase(this.chart.xAxis, this.xAxis);
  2696. erase(this.chart.axes, this.xAxis);
  2697. }
  2698. if (this.yAxis) {
  2699. erase(this.chart.yAxis, this.yAxis);
  2700. erase(this.chart.axes, this.yAxis);
  2701. }
  2702. // Destroy series
  2703. (this.series || []).forEach(function (s) {
  2704. if (s.destroy) {
  2705. s.destroy();
  2706. }
  2707. });
  2708. // Destroy properties
  2709. [
  2710. 'series', 'xAxis', 'yAxis', 'shades', 'outline', 'scrollbarTrack',
  2711. 'scrollbarRifles', 'scrollbarGroup', 'scrollbar', 'navigatorGroup',
  2712. 'rendered'
  2713. ].forEach(function (prop) {
  2714. if (this[prop] && this[prop].destroy) {
  2715. this[prop].destroy();
  2716. }
  2717. this[prop] = null;
  2718. }, this);
  2719. // Destroy elements in collection
  2720. [this.handles].forEach(function (coll) {
  2721. destroyObjectProperties(coll);
  2722. }, this);
  2723. }
  2724. };
  2725. if (!H.Navigator) {
  2726. H.Navigator = Navigator;
  2727. // For Stock charts, override selection zooming with some special features
  2728. // because X axis zooming is already allowed by the Navigator and Range
  2729. // selector.
  2730. addEvent(Axis, 'zoom', function (e) {
  2731. var chart = this.chart, chartOptions = chart.options, zoomType = chartOptions.chart.zoomType, pinchType = chartOptions.chart.pinchType, previousZoom, navigator = chartOptions.navigator, rangeSelector = chartOptions.rangeSelector;
  2732. if (this.isXAxis && ((navigator && navigator.enabled) ||
  2733. (rangeSelector && rangeSelector.enabled))) {
  2734. // For y only zooming, ignore the X axis completely
  2735. if (zoomType === 'y') {
  2736. e.zoomed = false;
  2737. // For xy zooming, record the state of the zoom before zoom
  2738. // selection, then when the reset button is pressed, revert to this
  2739. // state. This should apply only if the chart is initialized with a
  2740. // range (#6612), otherwise zoom all the way out.
  2741. }
  2742. else if (((!isTouchDevice && zoomType === 'xy') ||
  2743. (isTouchDevice && pinchType === 'xy')) &&
  2744. this.options.range) {
  2745. previousZoom = this.previousZoom;
  2746. if (defined(e.newMin)) {
  2747. this.previousZoom = [this.min, this.max];
  2748. }
  2749. else if (previousZoom) {
  2750. e.newMin = previousZoom[0];
  2751. e.newMax = previousZoom[1];
  2752. delete this.previousZoom;
  2753. }
  2754. }
  2755. }
  2756. if (typeof e.zoomed !== 'undefined') {
  2757. e.preventDefault();
  2758. }
  2759. });
  2760. // For Stock charts. For x only zooming, do not to create the zoom button
  2761. // because X axis zooming is already allowed by the Navigator and Range
  2762. // selector. (#9285)
  2763. addEvent(Chart, 'beforeShowResetZoom', function () {
  2764. var chartOptions = this.options, navigator = chartOptions.navigator, rangeSelector = chartOptions.rangeSelector;
  2765. if (((navigator && navigator.enabled) ||
  2766. (rangeSelector && rangeSelector.enabled)) &&
  2767. ((!isTouchDevice && chartOptions.chart.zoomType === 'x') ||
  2768. (isTouchDevice && chartOptions.chart.pinchType === 'x'))) {
  2769. return false;
  2770. }
  2771. });
  2772. // Initialize navigator for stock charts
  2773. addEvent(Chart, 'beforeRender', function () {
  2774. var options = this.options;
  2775. if (options.navigator.enabled ||
  2776. options.scrollbar.enabled) {
  2777. this.scroller = this.navigator = new Navigator(this);
  2778. }
  2779. });
  2780. // For stock charts, extend the Chart.setChartSize method so that we can set
  2781. // the final top position of the navigator once the height of the chart,
  2782. // including the legend, is determined. #367. We can't use Chart.getMargins,
  2783. // because labels offsets are not calculated yet.
  2784. addEvent(Chart, 'afterSetChartSize', function () {
  2785. var legend = this.legend, navigator = this.navigator, scrollbarHeight, legendOptions, xAxis, yAxis;
  2786. if (navigator) {
  2787. legendOptions = legend && legend.options;
  2788. xAxis = navigator.xAxis;
  2789. yAxis = navigator.yAxis;
  2790. scrollbarHeight = navigator.scrollbarHeight;
  2791. // Compute the top position
  2792. if (this.inverted) {
  2793. navigator.left = navigator.opposite ?
  2794. this.chartWidth - scrollbarHeight -
  2795. navigator.height :
  2796. this.spacing[3] + scrollbarHeight;
  2797. navigator.top = this.plotTop + scrollbarHeight;
  2798. }
  2799. else {
  2800. navigator.left = this.plotLeft + scrollbarHeight;
  2801. navigator.top = navigator.navigatorOptions.top ||
  2802. this.chartHeight -
  2803. navigator.height -
  2804. scrollbarHeight -
  2805. this.spacing[2] -
  2806. (this.rangeSelector && this.extraBottomMargin ?
  2807. this.rangeSelector.getHeight() :
  2808. 0) -
  2809. ((legendOptions &&
  2810. legendOptions.verticalAlign === 'bottom' &&
  2811. legendOptions.enabled &&
  2812. !legendOptions.floating) ?
  2813. legend.legendHeight +
  2814. pick(legendOptions.margin, 10) :
  2815. 0) -
  2816. (this.titleOffset ? this.titleOffset[2] : 0);
  2817. }
  2818. if (xAxis && yAxis) { // false if navigator is disabled (#904)
  2819. if (this.inverted) {
  2820. xAxis.options.left = yAxis.options.left = navigator.left;
  2821. }
  2822. else {
  2823. xAxis.options.top = yAxis.options.top = navigator.top;
  2824. }
  2825. xAxis.setAxisSize();
  2826. yAxis.setAxisSize();
  2827. }
  2828. }
  2829. });
  2830. // Merge options, if no scrolling exists yet
  2831. addEvent(Chart, 'update', function (e) {
  2832. var navigatorOptions = (e.options.navigator || {}), scrollbarOptions = (e.options.scrollbar || {});
  2833. if (!this.navigator && !this.scroller &&
  2834. (navigatorOptions.enabled || scrollbarOptions.enabled)) {
  2835. merge(true, this.options.navigator, navigatorOptions);
  2836. merge(true, this.options.scrollbar, scrollbarOptions);
  2837. delete e.options.navigator;
  2838. delete e.options.scrollbar;
  2839. }
  2840. });
  2841. // Initialize navigator, if no scrolling exists yet
  2842. addEvent(Chart, 'afterUpdate', function (event) {
  2843. if (!this.navigator && !this.scroller &&
  2844. (this.options.navigator.enabled ||
  2845. this.options.scrollbar.enabled)) {
  2846. this.scroller = this.navigator = new Navigator(this);
  2847. if (pick(event.redraw, true)) {
  2848. this.redraw(event.animation); // #7067
  2849. }
  2850. }
  2851. });
  2852. // Handle adding new series
  2853. addEvent(Chart, 'afterAddSeries', function () {
  2854. if (this.navigator) {
  2855. // Recompute which series should be shown in navigator, and add them
  2856. this.navigator.setBaseSeries(null, false);
  2857. }
  2858. });
  2859. // Handle updating series
  2860. addEvent(Series, 'afterUpdate', function () {
  2861. if (this.chart.navigator && !this.options.isInternal) {
  2862. this.chart.navigator.setBaseSeries(null, false);
  2863. }
  2864. });
  2865. Chart.prototype.callbacks.push(function (chart) {
  2866. var extremes, navigator = chart.navigator;
  2867. // Initialize the navigator
  2868. if (navigator && chart.xAxis[0]) {
  2869. extremes = chart.xAxis[0].getExtremes();
  2870. navigator.render(extremes.min, extremes.max);
  2871. }
  2872. });
  2873. }
  2874. });
  2875. _registerModule(_modules, 'parts/OrdinalAxis.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  2876. /* *
  2877. *
  2878. * (c) 2010-2019 Torstein Honsi
  2879. *
  2880. * License: www.highcharts.com/license
  2881. *
  2882. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  2883. *
  2884. * */
  2885. var defined = U.defined, extend = U.extend, pick = U.pick;
  2886. // Has a dependency on Navigator due to the use of Axis.toFixedRange
  2887. var addEvent = H.addEvent, Axis = H.Axis, Chart = H.Chart, css = H.css, noop = H.noop, Series = H.Series, timeUnits = H.timeUnits;
  2888. /* eslint-disable no-invalid-this, valid-jsdoc */
  2889. /* ************************************************************************** *
  2890. * Start ordinal axis logic *
  2891. * ************************************************************************** */
  2892. addEvent(Series, 'updatedData', function () {
  2893. var xAxis = this.xAxis;
  2894. // Destroy the extended ordinal index on updated data
  2895. if (xAxis && xAxis.options.ordinal) {
  2896. delete xAxis.ordinalIndex;
  2897. }
  2898. });
  2899. /**
  2900. * In an ordinal axis, there might be areas with dense consentrations of points,
  2901. * then large gaps between some. Creating equally distributed ticks over this
  2902. * entire range may lead to a huge number of ticks that will later be removed.
  2903. * So instead, break the positions up in segments, find the tick positions for
  2904. * each segment then concatenize them. This method is used from both data
  2905. * grouping logic and X axis tick position logic.
  2906. * @private
  2907. */
  2908. Axis.prototype.getTimeTicks = function (normalizedInterval, min, max, startOfWeek, positions, closestDistance, findHigherRanks) {
  2909. var start = 0, end, segmentPositions, higherRanks = {}, hasCrossedHigherRank, info, posLength, outsideMax, groupPositions = [], lastGroupPosition = -Number.MAX_VALUE, tickPixelIntervalOption = this.options.tickPixelInterval, time = this.chart.time,
  2910. // Record all the start positions of a segment, to use when deciding
  2911. // what's a gap in the data.
  2912. segmentStarts = [];
  2913. // The positions are not always defined, for example for ordinal positions
  2914. // when data has regular interval (#1557, #2090)
  2915. if ((!this.options.ordinal && !this.options.breaks) ||
  2916. !positions ||
  2917. positions.length < 3 ||
  2918. typeof min === 'undefined') {
  2919. return time.getTimeTicks.apply(time, arguments);
  2920. }
  2921. // Analyze the positions array to split it into segments on gaps larger than
  2922. // 5 times the closest distance. The closest distance is already found at
  2923. // this point, so we reuse that instead of computing it again.
  2924. posLength = positions.length;
  2925. for (end = 0; end < posLength; end++) {
  2926. outsideMax = end && positions[end - 1] > max;
  2927. if (positions[end] < min) { // Set the last position before min
  2928. start = end;
  2929. }
  2930. if (end === posLength - 1 ||
  2931. positions[end + 1] - positions[end] > closestDistance * 5 ||
  2932. outsideMax) {
  2933. // For each segment, calculate the tick positions from the
  2934. // getTimeTicks utility function. The interval will be the same
  2935. // regardless of how long the segment is.
  2936. if (positions[end] > lastGroupPosition) { // #1475
  2937. segmentPositions = time.getTimeTicks(normalizedInterval, positions[start], positions[end], startOfWeek);
  2938. // Prevent duplicate groups, for example for multiple segments
  2939. // within one larger time frame (#1475)
  2940. while (segmentPositions.length &&
  2941. segmentPositions[0] <= lastGroupPosition) {
  2942. segmentPositions.shift();
  2943. }
  2944. if (segmentPositions.length) {
  2945. lastGroupPosition =
  2946. segmentPositions[segmentPositions.length - 1];
  2947. }
  2948. segmentStarts.push(groupPositions.length);
  2949. groupPositions = groupPositions.concat(segmentPositions);
  2950. }
  2951. // Set start of next segment
  2952. start = end + 1;
  2953. }
  2954. if (outsideMax) {
  2955. break;
  2956. }
  2957. }
  2958. // Get the grouping info from the last of the segments. The info is the same
  2959. // for all segments.
  2960. info = segmentPositions.info;
  2961. // Optionally identify ticks with higher rank, for example when the ticks
  2962. // have crossed midnight.
  2963. if (findHigherRanks && info.unitRange <= timeUnits.hour) {
  2964. end = groupPositions.length - 1;
  2965. // Compare points two by two
  2966. for (start = 1; start < end; start++) {
  2967. if (time.dateFormat('%d', groupPositions[start]) !==
  2968. time.dateFormat('%d', groupPositions[start - 1])) {
  2969. higherRanks[groupPositions[start]] = 'day';
  2970. hasCrossedHigherRank = true;
  2971. }
  2972. }
  2973. // If the complete array has crossed midnight, we want to mark the first
  2974. // positions also as higher rank
  2975. if (hasCrossedHigherRank) {
  2976. higherRanks[groupPositions[0]] = 'day';
  2977. }
  2978. info.higherRanks = higherRanks;
  2979. }
  2980. // Save the info
  2981. info.segmentStarts = segmentStarts;
  2982. groupPositions.info = info;
  2983. // Don't show ticks within a gap in the ordinal axis, where the space
  2984. // between two points is greater than a portion of the tick pixel interval
  2985. if (findHigherRanks && defined(tickPixelIntervalOption)) {
  2986. var length = groupPositions.length, i = length, itemToRemove, translated, translatedArr = [], lastTranslated, medianDistance, distance, distances = [];
  2987. // Find median pixel distance in order to keep a reasonably even
  2988. // distance between ticks (#748)
  2989. while (i--) {
  2990. translated = this.translate(groupPositions[i]);
  2991. if (lastTranslated) {
  2992. distances[i] = lastTranslated - translated;
  2993. }
  2994. translatedArr[i] = lastTranslated = translated;
  2995. }
  2996. distances.sort();
  2997. medianDistance = distances[Math.floor(distances.length / 2)];
  2998. if (medianDistance < tickPixelIntervalOption * 0.6) {
  2999. medianDistance = null;
  3000. }
  3001. // Now loop over again and remove ticks where needed
  3002. i = groupPositions[length - 1] > max ? length - 1 : length; // #817
  3003. lastTranslated = void 0;
  3004. while (i--) {
  3005. translated = translatedArr[i];
  3006. distance = Math.abs(lastTranslated - translated);
  3007. // #4175 - when axis is reversed, the distance, is negative but
  3008. // tickPixelIntervalOption positive, so we need to compare the same
  3009. // values
  3010. // Remove ticks that are closer than 0.6 times the pixel interval
  3011. // from the one to the right, but not if it is close to the median
  3012. // distance (#748).
  3013. if (lastTranslated &&
  3014. distance < tickPixelIntervalOption * 0.8 &&
  3015. (medianDistance === null || distance < medianDistance * 0.8)) {
  3016. // Is this a higher ranked position with a normal position to
  3017. // the right?
  3018. if (higherRanks[groupPositions[i]] &&
  3019. !higherRanks[groupPositions[i + 1]]) {
  3020. // Yes: remove the lower ranked neighbour to the right
  3021. itemToRemove = i + 1;
  3022. lastTranslated = translated; // #709
  3023. }
  3024. else {
  3025. // No: remove this one
  3026. itemToRemove = i;
  3027. }
  3028. groupPositions.splice(itemToRemove, 1);
  3029. }
  3030. else {
  3031. lastTranslated = translated;
  3032. }
  3033. }
  3034. }
  3035. return groupPositions;
  3036. };
  3037. // Extend the Axis prototype
  3038. extend(Axis.prototype, /** @lends Axis.prototype */ {
  3039. /**
  3040. * Calculate the ordinal positions before tick positions are calculated.
  3041. *
  3042. * @private
  3043. * @function Highcharts.Axis#beforeSetTickPositions
  3044. * @return {void}
  3045. */
  3046. beforeSetTickPositions: function () {
  3047. var axis = this, len, ordinalPositions = [], uniqueOrdinalPositions, useOrdinal = false, dist, extremes = axis.getExtremes(), min = extremes.min, max = extremes.max, minIndex, maxIndex, slope, hasBreaks = axis.isXAxis && !!axis.options.breaks, isOrdinal = axis.options.ordinal, overscrollPointsRange = Number.MAX_VALUE, ignoreHiddenSeries = axis.chart.options.chart.ignoreHiddenSeries, i, hasBoostedSeries;
  3048. // Apply the ordinal logic
  3049. if (isOrdinal || hasBreaks) { // #4167 YAxis is never ordinal ?
  3050. axis.series.forEach(function (series, i) {
  3051. uniqueOrdinalPositions = [];
  3052. if ((!ignoreHiddenSeries || series.visible !== false) &&
  3053. (series.takeOrdinalPosition !== false || hasBreaks)) {
  3054. // concatenate the processed X data into the existing
  3055. // positions, or the empty array
  3056. ordinalPositions = ordinalPositions.concat(series.processedXData);
  3057. len = ordinalPositions.length;
  3058. // remove duplicates (#1588)
  3059. ordinalPositions.sort(function (a, b) {
  3060. // without a custom function it is sorted as strings
  3061. return a - b;
  3062. });
  3063. overscrollPointsRange = Math.min(overscrollPointsRange, pick(
  3064. // Check for a single-point series:
  3065. series.closestPointRange, overscrollPointsRange));
  3066. if (len) {
  3067. i = 0;
  3068. while (i < len - 1) {
  3069. if (ordinalPositions[i] !== ordinalPositions[i + 1]) {
  3070. uniqueOrdinalPositions.push(ordinalPositions[i + 1]);
  3071. }
  3072. i++;
  3073. }
  3074. // Check first item:
  3075. if (uniqueOrdinalPositions[0] !== ordinalPositions[0]) {
  3076. uniqueOrdinalPositions.unshift(ordinalPositions[0]);
  3077. }
  3078. ordinalPositions = uniqueOrdinalPositions;
  3079. }
  3080. }
  3081. if (series.isSeriesBoosting) {
  3082. hasBoostedSeries = true;
  3083. }
  3084. });
  3085. if (hasBoostedSeries) {
  3086. ordinalPositions.length = 0;
  3087. }
  3088. // cache the length
  3089. len = ordinalPositions.length;
  3090. // Check if we really need the overhead of mapping axis data against
  3091. // the ordinal positions. If the series consist of evenly spaced
  3092. // data any way, we don't need any ordinal logic.
  3093. if (len > 2) { // two points have equal distance by default
  3094. dist = ordinalPositions[1] - ordinalPositions[0];
  3095. i = len - 1;
  3096. while (i-- && !useOrdinal) {
  3097. if (ordinalPositions[i + 1] - ordinalPositions[i] !== dist) {
  3098. useOrdinal = true;
  3099. }
  3100. }
  3101. // When zooming in on a week, prevent axis padding for weekends
  3102. // even though the data within the week is evenly spaced.
  3103. if (!axis.options.keepOrdinalPadding &&
  3104. (ordinalPositions[0] - min > dist ||
  3105. max - ordinalPositions[ordinalPositions.length - 1] >
  3106. dist)) {
  3107. useOrdinal = true;
  3108. }
  3109. }
  3110. else if (axis.options.overscroll) {
  3111. if (len === 2) {
  3112. // Exactly two points, distance for overscroll is fixed:
  3113. overscrollPointsRange =
  3114. ordinalPositions[1] - ordinalPositions[0];
  3115. }
  3116. else if (len === 1) {
  3117. // We have just one point, closest distance is unknown.
  3118. // Assume then it is last point and overscrolled range:
  3119. overscrollPointsRange = axis.options.overscroll;
  3120. ordinalPositions = [
  3121. ordinalPositions[0],
  3122. ordinalPositions[0] + overscrollPointsRange
  3123. ];
  3124. }
  3125. else {
  3126. // In case of zooming in on overscrolled range, stick to the
  3127. // old range:
  3128. overscrollPointsRange = axis.overscrollPointsRange;
  3129. }
  3130. }
  3131. // Record the slope and offset to compute the linear values from the
  3132. // array index. Since the ordinal positions may exceed the current
  3133. // range, get the start and end positions within it (#719, #665b)
  3134. if (useOrdinal) {
  3135. if (axis.options.overscroll) {
  3136. axis.overscrollPointsRange = overscrollPointsRange;
  3137. ordinalPositions = ordinalPositions.concat(axis.getOverscrollPositions());
  3138. }
  3139. // Register
  3140. axis.ordinalPositions = ordinalPositions;
  3141. // This relies on the ordinalPositions being set. Use Math.max
  3142. // and Math.min to prevent padding on either sides of the data.
  3143. minIndex = axis.ordinal2lin(// #5979
  3144. Math.max(min, ordinalPositions[0]), true);
  3145. maxIndex = Math.max(axis.ordinal2lin(Math.min(max, ordinalPositions[ordinalPositions.length - 1]), true), 1); // #3339
  3146. // Set the slope and offset of the values compared to the
  3147. // indices in the ordinal positions
  3148. axis.ordinalSlope = slope = (max - min) / (maxIndex - minIndex);
  3149. axis.ordinalOffset = min - (minIndex * slope);
  3150. }
  3151. else {
  3152. axis.overscrollPointsRange = pick(axis.closestPointRange, axis.overscrollPointsRange);
  3153. axis.ordinalPositions = axis.ordinalSlope = axis.ordinalOffset =
  3154. void 0;
  3155. }
  3156. }
  3157. axis.isOrdinal = isOrdinal && useOrdinal; // #3818, #4196, #4926
  3158. axis.groupIntervalFactor = null; // reset for next run
  3159. },
  3160. /**
  3161. * Translate from a linear axis value to the corresponding ordinal axis
  3162. * position. If there are no gaps in the ordinal axis this will be the same.
  3163. * The translated value is the value that the point would have if the axis
  3164. * were linear, using the same min and max.
  3165. *
  3166. * @private
  3167. * @function Highcharts.Axis#val2lin
  3168. *
  3169. * @param {number} val
  3170. * The axis value.
  3171. *
  3172. * @param {boolean} [toIndex]
  3173. * Whether to return the index in the ordinalPositions or the new
  3174. * value.
  3175. *
  3176. * @return {number}
  3177. */
  3178. val2lin: function (val, toIndex) {
  3179. var axis = this, ordinalPositions = axis.ordinalPositions, ret;
  3180. if (!ordinalPositions) {
  3181. ret = val;
  3182. }
  3183. else {
  3184. var ordinalLength = ordinalPositions.length, i, distance, ordinalIndex;
  3185. // first look for an exact match in the ordinalpositions array
  3186. i = ordinalLength;
  3187. while (i--) {
  3188. if (ordinalPositions[i] === val) {
  3189. ordinalIndex = i;
  3190. break;
  3191. }
  3192. }
  3193. // if that failed, find the intermediate position between the two
  3194. // nearest values
  3195. i = ordinalLength - 1;
  3196. while (i--) {
  3197. if (val > ordinalPositions[i] || i === 0) { // interpolate
  3198. // something between 0 and 1
  3199. distance = (val - ordinalPositions[i]) /
  3200. (ordinalPositions[i + 1] - ordinalPositions[i]);
  3201. ordinalIndex = i + distance;
  3202. break;
  3203. }
  3204. }
  3205. ret = toIndex ?
  3206. ordinalIndex :
  3207. axis.ordinalSlope *
  3208. (ordinalIndex || 0) +
  3209. axis.ordinalOffset;
  3210. }
  3211. return ret;
  3212. },
  3213. /**
  3214. * Translate from linear (internal) to axis value.
  3215. *
  3216. * @private
  3217. * @function Highcharts.Axis#lin2val
  3218. *
  3219. * @param {number} val
  3220. * The linear abstracted value.
  3221. *
  3222. * @param {boolean} [fromIndex]
  3223. * Translate from an index in the ordinal positions rather than a
  3224. * value.
  3225. *
  3226. * @return {number}
  3227. */
  3228. lin2val: function (val, fromIndex) {
  3229. var axis = this, ordinalPositions = axis.ordinalPositions, ret;
  3230. // the visible range contains only equally spaced values
  3231. if (!ordinalPositions) {
  3232. ret = val;
  3233. }
  3234. else {
  3235. var ordinalSlope = axis.ordinalSlope, ordinalOffset = axis.ordinalOffset, i = ordinalPositions.length - 1, linearEquivalentLeft, linearEquivalentRight, distance;
  3236. // Handle the case where we translate from the index directly, used
  3237. // only when panning an ordinal axis
  3238. if (fromIndex) {
  3239. if (val < 0) { // out of range, in effect panning to the left
  3240. val = ordinalPositions[0];
  3241. }
  3242. else if (val > i) { // out of range, panning to the right
  3243. val = ordinalPositions[i];
  3244. }
  3245. else { // split it up
  3246. i = Math.floor(val);
  3247. distance = val - i; // the decimal
  3248. }
  3249. // Loop down along the ordinal positions. When the linear equivalent
  3250. // of i matches an ordinal position, interpolate between the left
  3251. // and right values.
  3252. }
  3253. else {
  3254. while (i--) {
  3255. linearEquivalentLeft =
  3256. (ordinalSlope * i) + ordinalOffset;
  3257. if (val >= linearEquivalentLeft) {
  3258. linearEquivalentRight =
  3259. (ordinalSlope *
  3260. (i + 1)) +
  3261. ordinalOffset;
  3262. // something between 0 and 1
  3263. distance = (val - linearEquivalentLeft) /
  3264. (linearEquivalentRight - linearEquivalentLeft);
  3265. break;
  3266. }
  3267. }
  3268. }
  3269. // If the index is within the range of the ordinal positions, return
  3270. // the associated or interpolated value. If not, just return the
  3271. // value
  3272. return (typeof distance !== 'undefined' &&
  3273. typeof ordinalPositions[i] !== 'undefined' ?
  3274. ordinalPositions[i] + (distance ?
  3275. distance *
  3276. (ordinalPositions[i + 1] - ordinalPositions[i]) :
  3277. 0) :
  3278. val);
  3279. }
  3280. return ret;
  3281. },
  3282. /**
  3283. * Get the ordinal positions for the entire data set. This is necessary in
  3284. * chart panning because we need to find out what points or data groups are
  3285. * available outside the visible range. When a panning operation starts, if
  3286. * an index for the given grouping does not exists, it is created and
  3287. * cached. This index is deleted on updated data, so it will be regenerated
  3288. * the next time a panning operation starts.
  3289. *
  3290. * @private
  3291. * @function Highcharts.Axis#getExtendedPositions
  3292. *
  3293. * @return {Array<number>}
  3294. */
  3295. getExtendedPositions: function () {
  3296. var axis = this, chart = axis.chart, grouping = axis.series[0].currentDataGrouping, ordinalIndex = axis.ordinalIndex, key = grouping ?
  3297. grouping.count + grouping.unitName :
  3298. 'raw', overscroll = axis.options.overscroll, extremes = axis.getExtremes(), fakeAxis, fakeSeries;
  3299. // If this is the first time, or the ordinal index is deleted by
  3300. // updatedData,
  3301. // create it.
  3302. if (!ordinalIndex) {
  3303. ordinalIndex = axis.ordinalIndex = {};
  3304. }
  3305. if (!ordinalIndex[key]) {
  3306. // Create a fake axis object where the extended ordinal positions
  3307. // are emulated
  3308. fakeAxis = {
  3309. series: [],
  3310. chart: chart,
  3311. getExtremes: function () {
  3312. return {
  3313. min: extremes.dataMin,
  3314. max: extremes.dataMax + overscroll
  3315. };
  3316. },
  3317. options: {
  3318. ordinal: true
  3319. },
  3320. val2lin: Axis.prototype.val2lin,
  3321. ordinal2lin: Axis.prototype.ordinal2lin // #6276
  3322. };
  3323. // Add the fake series to hold the full data, then apply processData
  3324. // to it
  3325. axis.series.forEach(function (series) {
  3326. fakeSeries = {
  3327. xAxis: fakeAxis,
  3328. xData: series.xData.slice(),
  3329. chart: chart,
  3330. destroyGroupedData: noop
  3331. };
  3332. fakeSeries.xData = fakeSeries.xData.concat(axis.getOverscrollPositions());
  3333. fakeSeries.options = {
  3334. dataGrouping: grouping ? {
  3335. enabled: true,
  3336. forced: true,
  3337. // doesn't matter which, use the fastest
  3338. approximation: 'open',
  3339. units: [[
  3340. grouping.unitName,
  3341. [grouping.count]
  3342. ]]
  3343. } : {
  3344. enabled: false
  3345. }
  3346. };
  3347. series.processData.apply(fakeSeries);
  3348. fakeAxis.series.push(fakeSeries);
  3349. });
  3350. // Run beforeSetTickPositions to compute the ordinalPositions
  3351. axis.beforeSetTickPositions.apply(fakeAxis);
  3352. // Cache it
  3353. ordinalIndex[key] = fakeAxis.ordinalPositions;
  3354. }
  3355. return ordinalIndex[key];
  3356. },
  3357. /**
  3358. * Get ticks for an ordinal axis within a range where points don't exist.
  3359. * It is required when overscroll is enabled. We can't base on points,
  3360. * because we may not have any, so we use approximated pointRange and
  3361. * generate these ticks between Axis.dataMax, Axis.dataMax + Axis.overscroll
  3362. * evenly spaced. Used in panning and navigator scrolling.
  3363. *
  3364. * @private
  3365. * @function Highcharts.Axis#getOverscrollPositions
  3366. *
  3367. * @returns {Array<number>}
  3368. * Generated ticks
  3369. */
  3370. getOverscrollPositions: function () {
  3371. var axis = this, extraRange = axis.options.overscroll, distance = axis.overscrollPointsRange, positions = [], max = axis.dataMax;
  3372. if (defined(distance)) {
  3373. // Max + pointRange because we need to scroll to the last
  3374. positions.push(max);
  3375. while (max <= axis.dataMax + extraRange) {
  3376. max += distance;
  3377. positions.push(max);
  3378. }
  3379. }
  3380. return positions;
  3381. },
  3382. /**
  3383. * Find the factor to estimate how wide the plot area would have been if
  3384. * ordinal gaps were included. This value is used to compute an imagined
  3385. * plot width in order to establish the data grouping interval.
  3386. *
  3387. * A real world case is the intraday-candlestick example. Without this
  3388. * logic, it would show the correct data grouping when viewing a range
  3389. * within each day, but once moving the range to include the gap between two
  3390. * days, the interval would include the cut-away night hours and the data
  3391. * grouping would be wrong. So the below method tries to compensate by
  3392. * identifying the most common point interval, in this case days.
  3393. *
  3394. * An opposite case is presented in issue #718. We have a long array of
  3395. * daily data, then one point is appended one hour after the last point. We
  3396. * expect the data grouping not to change.
  3397. *
  3398. * In the future, if we find cases where this estimation doesn't work
  3399. * optimally, we might need to add a second pass to the data grouping logic,
  3400. * where we do another run with a greater interval if the number of data
  3401. * groups is more than a certain fraction of the desired group count.
  3402. *
  3403. * @private
  3404. * @function Highcharts.Axis#getGroupIntervalFactor
  3405. *
  3406. * @param {number} xMin
  3407. *
  3408. * @param {number} xMax
  3409. *
  3410. * @param {Highcharts.Series} series
  3411. *
  3412. * @return {number}
  3413. */
  3414. getGroupIntervalFactor: function (xMin, xMax, series) {
  3415. var i, processedXData = series.processedXData, len = processedXData.length, distances = [], median, groupIntervalFactor = this.groupIntervalFactor;
  3416. // Only do this computation for the first series, let the other inherit
  3417. // it (#2416)
  3418. if (!groupIntervalFactor) {
  3419. // Register all the distances in an array
  3420. for (i = 0; i < len - 1; i++) {
  3421. distances[i] =
  3422. processedXData[i + 1] - processedXData[i];
  3423. }
  3424. // Sort them and find the median
  3425. distances.sort(function (a, b) {
  3426. return a - b;
  3427. });
  3428. median = distances[Math.floor(len / 2)];
  3429. // Compensate for series that don't extend through the entire axis
  3430. // extent. #1675.
  3431. xMin = Math.max(xMin, processedXData[0]);
  3432. xMax = Math.min(xMax, processedXData[len - 1]);
  3433. this.groupIntervalFactor = groupIntervalFactor =
  3434. (len * median) / (xMax - xMin);
  3435. }
  3436. // Return the factor needed for data grouping
  3437. return groupIntervalFactor;
  3438. },
  3439. /**
  3440. * Make the tick intervals closer because the ordinal gaps make the ticks
  3441. * spread out or cluster.
  3442. *
  3443. * @private
  3444. * @function Highcharts.Axis#postProcessTickInterval
  3445. *
  3446. * @param {number} tickInterval
  3447. *
  3448. * @return {number}
  3449. */
  3450. postProcessTickInterval: function (tickInterval) {
  3451. // Problem: https://jsfiddle.net/highcharts/FQm4E/1/
  3452. // This is a case where this algorithm doesn't work optimally. In this
  3453. // case, the tick labels are spread out per week, but all the gaps
  3454. // reside within weeks. So we have a situation where the labels are
  3455. // courser than the ordinal gaps, and thus the tick interval should not
  3456. // be altered
  3457. var ordinalSlope = this.ordinalSlope, ret;
  3458. if (ordinalSlope) {
  3459. if (!this.options.breaks) {
  3460. ret = tickInterval / (ordinalSlope / this.closestPointRange);
  3461. }
  3462. else {
  3463. ret = this.closestPointRange || tickInterval; // #7275
  3464. }
  3465. }
  3466. else {
  3467. ret = tickInterval;
  3468. }
  3469. return ret;
  3470. }
  3471. });
  3472. // Record this to prevent overwriting by broken-axis module (#5979)
  3473. Axis.prototype.ordinal2lin = Axis.prototype.val2lin;
  3474. // Extending the Chart.pan method for ordinal axes
  3475. addEvent(Chart, 'pan', function (e) {
  3476. var chart = this, xAxis = chart.xAxis[0], overscroll = xAxis.options.overscroll, chartX = e.originalEvent.chartX, panning = chart.options.chart &&
  3477. chart.options.chart.panning, runBase = false;
  3478. if (panning &&
  3479. panning.type !== 'y' &&
  3480. xAxis.options.ordinal &&
  3481. xAxis.series.length) {
  3482. var mouseDownX = chart.mouseDownX, extremes = xAxis.getExtremes(), dataMax = extremes.dataMax, min = extremes.min, max = extremes.max, trimmedRange, hoverPoints = chart.hoverPoints, closestPointRange = xAxis.closestPointRange || xAxis.overscrollPointsRange, pointPixelWidth = (xAxis.translationSlope *
  3483. (xAxis.ordinalSlope || closestPointRange)),
  3484. // how many ordinal units did we move?
  3485. movedUnits = (mouseDownX - chartX) / pointPixelWidth,
  3486. // get index of all the chart's points
  3487. extendedAxis = { ordinalPositions: xAxis.getExtendedPositions() }, ordinalPositions, searchAxisLeft, lin2val = xAxis.lin2val, val2lin = xAxis.val2lin, searchAxisRight;
  3488. // we have an ordinal axis, but the data is equally spaced
  3489. if (!extendedAxis.ordinalPositions) {
  3490. runBase = true;
  3491. }
  3492. else if (Math.abs(movedUnits) > 1) {
  3493. // Remove active points for shared tooltip
  3494. if (hoverPoints) {
  3495. hoverPoints.forEach(function (point) {
  3496. point.setState();
  3497. });
  3498. }
  3499. if (movedUnits < 0) {
  3500. searchAxisLeft = extendedAxis;
  3501. searchAxisRight = xAxis.ordinalPositions ? xAxis : extendedAxis;
  3502. }
  3503. else {
  3504. searchAxisLeft = xAxis.ordinalPositions ? xAxis : extendedAxis;
  3505. searchAxisRight = extendedAxis;
  3506. }
  3507. // In grouped data series, the last ordinal position represents the
  3508. // grouped data, which is to the left of the real data max. If we
  3509. // don't compensate for this, we will be allowed to pan grouped data
  3510. // series passed the right of the plot area.
  3511. ordinalPositions = searchAxisRight.ordinalPositions;
  3512. if (dataMax >
  3513. ordinalPositions[ordinalPositions.length - 1]) {
  3514. ordinalPositions.push(dataMax);
  3515. }
  3516. // Get the new min and max values by getting the ordinal index for
  3517. // the current extreme, then add the moved units and translate back
  3518. // to values. This happens on the extended ordinal positions if the
  3519. // new position is out of range, else it happens on the current x
  3520. // axis which is smaller and faster.
  3521. chart.fixedRange = max - min;
  3522. trimmedRange = xAxis.toFixedRange(null, null, lin2val.apply(searchAxisLeft, [
  3523. val2lin.apply(searchAxisLeft, [min, true]) + movedUnits,
  3524. true // translate from index
  3525. ]), lin2val.apply(searchAxisRight, [
  3526. val2lin.apply(searchAxisRight, [max, true]) + movedUnits,
  3527. true // translate from index
  3528. ]));
  3529. // Apply it if it is within the available data range
  3530. if (trimmedRange.min >= Math.min(extremes.dataMin, min) &&
  3531. trimmedRange.max <= Math.max(dataMax, max) + overscroll) {
  3532. xAxis.setExtremes(trimmedRange.min, trimmedRange.max, true, false, { trigger: 'pan' });
  3533. }
  3534. chart.mouseDownX = chartX; // set new reference for next run
  3535. css(chart.container, { cursor: 'move' });
  3536. }
  3537. }
  3538. else {
  3539. runBase = true;
  3540. }
  3541. // revert to the linear chart.pan version
  3542. if (runBase || (panning && /y/.test(panning.type))) {
  3543. if (overscroll) {
  3544. xAxis.max = xAxis.dataMax + overscroll;
  3545. }
  3546. }
  3547. else {
  3548. e.preventDefault();
  3549. }
  3550. });
  3551. addEvent(Axis, 'foundExtremes', function () {
  3552. var axis = this;
  3553. if (axis.isXAxis &&
  3554. defined(axis.options.overscroll) &&
  3555. axis.max === axis.dataMax &&
  3556. (
  3557. // Panning is an execption,
  3558. // We don't want to apply overscroll when panning over the dataMax
  3559. !axis.chart.mouseIsDown ||
  3560. axis.isInternal) && (
  3561. // Scrollbar buttons are the other execption:
  3562. !axis.eventArgs ||
  3563. axis.eventArgs && axis.eventArgs.trigger !== 'navigator')) {
  3564. axis.max += axis.options.overscroll;
  3565. // Live data and buttons require translation for the min:
  3566. if (!axis.isInternal && defined(axis.userMin)) {
  3567. axis.min += axis.options.overscroll;
  3568. }
  3569. }
  3570. });
  3571. // For ordinal axis, that loads data async, redraw axis after data is loaded.
  3572. // If we don't do that, axis will have the same extremes as previously, but
  3573. // ordinal positions won't be calculated. See #10290
  3574. addEvent(Axis, 'afterSetScale', function () {
  3575. var axis = this;
  3576. if (axis.horiz && !axis.isDirty) {
  3577. axis.isDirty = axis.isOrdinal &&
  3578. axis.chart.navigator &&
  3579. !axis.chart.navigator.adaptToUpdatedData;
  3580. }
  3581. });
  3582. });
  3583. _registerModule(_modules, 'modules/broken-axis.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  3584. /* *
  3585. *
  3586. * (c) 2009-2019 Torstein Honsi
  3587. *
  3588. * License: www.highcharts.com/license
  3589. *
  3590. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  3591. *
  3592. * */
  3593. var extend = U.extend, isArray = U.isArray, pick = U.pick;
  3594. var addEvent = H.addEvent, find = H.find, fireEvent = H.fireEvent, Axis = H.Axis, Series = H.Series;
  3595. /**
  3596. * Returns the first break found where the x is larger then break.from and
  3597. * smaller then break.to.
  3598. *
  3599. * @param {number} x
  3600. * The number which should be within a break.
  3601. * @param {Array<Highcharts.XAxisBreaksOptions>} breaks
  3602. * The array of breaks to search within.
  3603. * @return {Highcharts.XAxisBreaksOptions|undefined}
  3604. * Returns the first break found that matches, returns false if no break
  3605. * is found.
  3606. */
  3607. var findBreakAt = function (x, breaks) {
  3608. return find(breaks, function (b) {
  3609. return b.from < x && x < b.to;
  3610. });
  3611. };
  3612. extend(Axis.prototype, {
  3613. isInBreak: function (brk, val) {
  3614. var ret, repeat = brk.repeat || Infinity, from = brk.from, length = brk.to - brk.from, test = (val >= from ?
  3615. (val - from) % repeat :
  3616. repeat - ((from - val) % repeat));
  3617. if (!brk.inclusive) {
  3618. ret = test < length && test !== 0;
  3619. }
  3620. else {
  3621. ret = test <= length;
  3622. }
  3623. return ret;
  3624. },
  3625. isInAnyBreak: function (val, testKeep) {
  3626. var breaks = this.options.breaks, i = breaks && breaks.length, inbrk, keep, ret;
  3627. if (i) {
  3628. while (i--) {
  3629. if (this.isInBreak(breaks[i], val)) {
  3630. inbrk = true;
  3631. if (!keep) {
  3632. keep = pick(breaks[i].showPoints, !this.isXAxis);
  3633. }
  3634. }
  3635. }
  3636. if (inbrk && testKeep) {
  3637. ret = inbrk && !keep;
  3638. }
  3639. else {
  3640. ret = inbrk;
  3641. }
  3642. }
  3643. return ret;
  3644. }
  3645. });
  3646. /* eslint-disable no-invalid-this */
  3647. addEvent(Axis, 'afterInit', function () {
  3648. if (typeof this.setBreaks === 'function') {
  3649. this.setBreaks(this.options.breaks, false);
  3650. }
  3651. });
  3652. addEvent(Axis, 'afterSetTickPositions', function () {
  3653. if (this.isBroken) {
  3654. var axis = this, tickPositions = this.tickPositions, info = this.tickPositions.info, newPositions = [], i;
  3655. for (i = 0; i < tickPositions.length; i++) {
  3656. if (!axis.isInAnyBreak(tickPositions[i])) {
  3657. newPositions.push(tickPositions[i]);
  3658. }
  3659. }
  3660. this.tickPositions = newPositions;
  3661. this.tickPositions.info = info;
  3662. }
  3663. });
  3664. // Force Axis to be not-ordinal when breaks are defined
  3665. addEvent(Axis, 'afterSetOptions', function () {
  3666. if (this.isBroken) {
  3667. this.options.ordinal = false;
  3668. }
  3669. });
  3670. /**
  3671. * Dynamically set or unset breaks in an axis. This function in lighter than
  3672. * usin Axis.update, and it also preserves animation.
  3673. *
  3674. * @private
  3675. * @function Highcharts.Axis#setBreaks
  3676. *
  3677. * @param {Array<Highcharts.XAxisBreaksOptions>} [breaks]
  3678. * The breaks to add. When `undefined` it removes existing breaks.
  3679. *
  3680. * @param {boolean} [redraw=true]
  3681. * Whether to redraw the chart immediately.
  3682. *
  3683. * @return {void}
  3684. */
  3685. Axis.prototype.setBreaks = function (breaks, redraw) {
  3686. var axis = this, isBroken = (isArray(breaks) && !!breaks.length);
  3687. /* eslint-disable valid-jsdoc */
  3688. /**
  3689. * @private
  3690. */
  3691. function breakVal2Lin(val) {
  3692. var nval = val, brk, i;
  3693. for (i = 0; i < axis.breakArray.length; i++) {
  3694. brk = axis.breakArray[i];
  3695. if (brk.to <= val) {
  3696. nval -= brk.len;
  3697. }
  3698. else if (brk.from >= val) {
  3699. break;
  3700. }
  3701. else if (axis.isInBreak(brk, val)) {
  3702. nval -= (val - brk.from);
  3703. break;
  3704. }
  3705. }
  3706. return nval;
  3707. }
  3708. /**
  3709. * @private
  3710. */
  3711. function breakLin2Val(val) {
  3712. var nval = val, brk, i;
  3713. for (i = 0; i < axis.breakArray.length; i++) {
  3714. brk = axis.breakArray[i];
  3715. if (brk.from >= nval) {
  3716. break;
  3717. }
  3718. else if (brk.to < nval) {
  3719. nval += brk.len;
  3720. }
  3721. else if (axis.isInBreak(brk, nval)) {
  3722. nval += brk.len;
  3723. }
  3724. }
  3725. return nval;
  3726. }
  3727. /* eslint-enable valid-jsdoc */
  3728. axis.isDirty = axis.isBroken !== isBroken;
  3729. axis.isBroken = isBroken;
  3730. axis.options.breaks = axis.userOptions.breaks = breaks;
  3731. axis.forceRedraw = true; // Force recalculation in setScale
  3732. // Recalculate series related to the axis.
  3733. axis.series.forEach(function (series) {
  3734. series.isDirty = true;
  3735. });
  3736. if (!isBroken && axis.val2lin === breakVal2Lin) {
  3737. // Revert to prototype functions
  3738. delete axis.val2lin;
  3739. delete axis.lin2val;
  3740. }
  3741. if (isBroken) {
  3742. axis.userOptions.ordinal = false;
  3743. axis.val2lin = breakVal2Lin;
  3744. axis.lin2val = breakLin2Val;
  3745. axis.setExtremes = function (newMin, newMax, redraw, animation, eventArguments) {
  3746. // If trying to set extremes inside a break, extend min to after,
  3747. // and max to before the break ( #3857 )
  3748. if (this.isBroken) {
  3749. var axisBreak, breaks = this.options.breaks;
  3750. while ((axisBreak = findBreakAt(newMin, breaks))) {
  3751. newMin = axisBreak.to;
  3752. }
  3753. while ((axisBreak = findBreakAt(newMax, breaks))) {
  3754. newMax = axisBreak.from;
  3755. }
  3756. // If both min and max is within the same break.
  3757. if (newMax < newMin) {
  3758. newMax = newMin;
  3759. }
  3760. }
  3761. Axis.prototype.setExtremes.call(this, newMin, newMax, redraw, animation, eventArguments);
  3762. };
  3763. axis.setAxisTranslation = function (saveOld) {
  3764. Axis.prototype.setAxisTranslation.call(this, saveOld);
  3765. this.unitLength = null;
  3766. if (this.isBroken) {
  3767. var breaks = axis.options.breaks,
  3768. // Temporary one:
  3769. breakArrayT = [], breakArray = [], length = 0, inBrk, repeat, min = axis.userMin || axis.min, max = axis.userMax || axis.max, pointRangePadding = pick(axis.pointRangePadding, 0), start, i;
  3770. // Min & max check (#4247)
  3771. breaks.forEach(function (brk) {
  3772. repeat = brk.repeat || Infinity;
  3773. if (axis.isInBreak(brk, min)) {
  3774. min +=
  3775. (brk.to % repeat) -
  3776. (min % repeat);
  3777. }
  3778. if (axis.isInBreak(brk, max)) {
  3779. max -=
  3780. (max % repeat) -
  3781. (brk.from % repeat);
  3782. }
  3783. });
  3784. // Construct an array holding all breaks in the axis
  3785. breaks.forEach(function (brk) {
  3786. start = brk.from;
  3787. repeat = brk.repeat || Infinity;
  3788. while (start - repeat > min) {
  3789. start -= repeat;
  3790. }
  3791. while (start < min) {
  3792. start += repeat;
  3793. }
  3794. for (i = start; i < max; i += repeat) {
  3795. breakArrayT.push({
  3796. value: i,
  3797. move: 'in'
  3798. });
  3799. breakArrayT.push({
  3800. value: i + (brk.to - brk.from),
  3801. move: 'out',
  3802. size: brk.breakSize
  3803. });
  3804. }
  3805. });
  3806. breakArrayT.sort(function (a, b) {
  3807. return ((a.value === b.value) ?
  3808. ((a.move === 'in' ? 0 : 1) -
  3809. (b.move === 'in' ? 0 : 1)) :
  3810. a.value - b.value);
  3811. });
  3812. // Simplify the breaks
  3813. inBrk = 0;
  3814. start = min;
  3815. breakArrayT.forEach(function (brk) {
  3816. inBrk += (brk.move === 'in' ? 1 : -1);
  3817. if (inBrk === 1 && brk.move === 'in') {
  3818. start = brk.value;
  3819. }
  3820. if (inBrk === 0) {
  3821. breakArray.push({
  3822. from: start,
  3823. to: brk.value,
  3824. len: brk.value - start - (brk.size || 0)
  3825. });
  3826. length += brk.value - start - (brk.size || 0);
  3827. }
  3828. });
  3829. axis.breakArray = breakArray;
  3830. // Used with staticScale, and below, the actual axis length when
  3831. // breaks are substracted.
  3832. axis.unitLength =
  3833. max - min - length + pointRangePadding;
  3834. fireEvent(axis, 'afterBreaks');
  3835. if (axis.staticScale) {
  3836. axis.transA = axis.staticScale;
  3837. }
  3838. else if (axis.unitLength) {
  3839. axis.transA *=
  3840. (max - axis.min + pointRangePadding) /
  3841. axis.unitLength;
  3842. }
  3843. if (pointRangePadding) {
  3844. axis.minPixelPadding =
  3845. axis.transA * axis.minPointOffset;
  3846. }
  3847. axis.min = min;
  3848. axis.max = max;
  3849. }
  3850. };
  3851. }
  3852. if (pick(redraw, true)) {
  3853. this.chart.redraw();
  3854. }
  3855. };
  3856. addEvent(Series, 'afterGeneratePoints', function () {
  3857. var _a = this, isDirty = _a.isDirty, connectNulls = _a.options.connectNulls, points = _a.points, xAxis = _a.xAxis, yAxis = _a.yAxis;
  3858. /* Set, or reset visibility of the points. Axis.setBreaks marks the series
  3859. as isDirty */
  3860. if (isDirty) {
  3861. var i = points.length;
  3862. while (i--) {
  3863. var point = points[i];
  3864. // Respect nulls inside the break (#4275)
  3865. var nullGap = point.y === null && connectNulls === false;
  3866. var isPointInBreak = (!nullGap &&
  3867. (xAxis && xAxis.isInAnyBreak(point.x, true) ||
  3868. yAxis && yAxis.isInAnyBreak(point.y, true)));
  3869. // Set point.visible if in any break.
  3870. // If not in break, reset visible to original value.
  3871. point.visible = isPointInBreak ?
  3872. false :
  3873. point.options.visible !== false;
  3874. }
  3875. }
  3876. });
  3877. addEvent(Series, 'afterRender', function drawPointsWrapped() {
  3878. this.drawBreaks(this.xAxis, ['x']);
  3879. this.drawBreaks(this.yAxis, pick(this.pointArrayMap, ['y']));
  3880. });
  3881. /* eslint-enable no-invalid-this */
  3882. H.Series.prototype.drawBreaks = function (axis, keys) {
  3883. var series = this, points = series.points, breaks, threshold, eventName, y;
  3884. if (!axis) {
  3885. return; // #5950
  3886. }
  3887. keys.forEach(function (key) {
  3888. breaks = axis.breakArray || [];
  3889. threshold = axis.isXAxis ?
  3890. axis.min :
  3891. pick(series.options.threshold, axis.min);
  3892. points.forEach(function (point) {
  3893. y = pick(point['stack' + key.toUpperCase()], point[key]);
  3894. breaks.forEach(function (brk) {
  3895. eventName = false;
  3896. if ((threshold < brk.from &&
  3897. y > brk.to) ||
  3898. (threshold > brk.from &&
  3899. y < brk.from)) {
  3900. eventName = 'pointBreak';
  3901. }
  3902. else if ((threshold < brk.from &&
  3903. y > brk.from &&
  3904. y < brk.to) ||
  3905. (threshold > brk.from &&
  3906. y > brk.to &&
  3907. y < brk.from)) {
  3908. eventName = 'pointInBreak';
  3909. }
  3910. if (eventName) {
  3911. fireEvent(axis, eventName, { point: point, brk: brk });
  3912. }
  3913. });
  3914. });
  3915. });
  3916. };
  3917. /**
  3918. * Extend getGraphPath by identifying gaps in the data so that we can draw a gap
  3919. * in the line or area. This was moved from ordinal axis module to broken axis
  3920. * module as of #5045.
  3921. *
  3922. * @private
  3923. * @function Highcharts.Series#gappedPath
  3924. *
  3925. * @return {Highcharts.SVGPathArray}
  3926. * Gapped path
  3927. */
  3928. H.Series.prototype.gappedPath = function () {
  3929. var currentDataGrouping = this.currentDataGrouping, groupingSize = currentDataGrouping && currentDataGrouping.gapSize, gapSize = this.options.gapSize, points = this.points.slice(), i = points.length - 1, yAxis = this.yAxis, stack;
  3930. /**
  3931. * Defines when to display a gap in the graph, together with the
  3932. * [gapUnit](plotOptions.series.gapUnit) option.
  3933. *
  3934. * In case when `dataGrouping` is enabled, points can be grouped into a
  3935. * larger time span. This can make the grouped points to have a greater
  3936. * distance than the absolute value of `gapSize` property, which will result
  3937. * in disappearing graph completely. To prevent this situation the mentioned
  3938. * distance between grouped points is used instead of previously defined
  3939. * `gapSize`.
  3940. *
  3941. * In practice, this option is most often used to visualize gaps in
  3942. * time series. In a stock chart, intraday data is available for daytime
  3943. * hours, while gaps will appear in nights and weekends.
  3944. *
  3945. * @see [gapUnit](plotOptions.series.gapUnit)
  3946. * @see [xAxis.breaks](#xAxis.breaks)
  3947. *
  3948. * @sample {highstock} stock/plotoptions/series-gapsize/
  3949. * Setting the gap size to 2 introduces gaps for weekends in daily
  3950. * datasets.
  3951. *
  3952. * @type {number}
  3953. * @default 0
  3954. * @product highstock
  3955. * @requires modules/broken-axis
  3956. * @apioption plotOptions.series.gapSize
  3957. */
  3958. /**
  3959. * Together with [gapSize](plotOptions.series.gapSize), this option defines
  3960. * where to draw gaps in the graph.
  3961. *
  3962. * When the `gapUnit` is `relative` (default), a gap size of 5 means
  3963. * that if the distance between two points is greater than five times
  3964. * that of the two closest points, the graph will be broken.
  3965. *
  3966. * When the `gapUnit` is `value`, the gap is based on absolute axis values,
  3967. * which on a datetime axis is milliseconds. This also applies to the
  3968. * navigator series that inherits gap options from the base series.
  3969. *
  3970. * @see [gapSize](plotOptions.series.gapSize)
  3971. *
  3972. * @type {string}
  3973. * @default relative
  3974. * @since 5.0.13
  3975. * @product highstock
  3976. * @validvalue ["relative", "value"]
  3977. * @requires modules/broken-axis
  3978. * @apioption plotOptions.series.gapUnit
  3979. */
  3980. if (gapSize && i > 0) { // #5008
  3981. // Gap unit is relative
  3982. if (this.options.gapUnit !== 'value') {
  3983. gapSize *= this.basePointRange;
  3984. }
  3985. // Setting a new gapSize in case dataGrouping is enabled (#7686)
  3986. if (groupingSize &&
  3987. groupingSize > gapSize &&
  3988. // Except when DG is forced (e.g. from other series)
  3989. // and has lower granularity than actual points (#11351)
  3990. groupingSize >= this.basePointRange) {
  3991. gapSize = groupingSize;
  3992. }
  3993. // extension for ordinal breaks
  3994. var current = void 0, next = void 0;
  3995. while (i--) {
  3996. // Reassign next if it is not visible
  3997. if (!(next && next.visible !== false)) {
  3998. next = points[i + 1];
  3999. }
  4000. current = points[i];
  4001. // Skip iteration if one of the points is not visible
  4002. if (next.visible === false || current.visible === false) {
  4003. continue;
  4004. }
  4005. if (next.x - current.x > gapSize) {
  4006. var xRange = (current.x + next.x) / 2;
  4007. points.splice(// insert after this one
  4008. i + 1, 0, {
  4009. isNull: true,
  4010. x: xRange
  4011. });
  4012. // For stacked chart generate empty stack items, #6546
  4013. if (this.options.stacking) {
  4014. stack = yAxis.stacks[this.stackKey][xRange] =
  4015. new H.StackItem(yAxis, yAxis.options
  4016. .stackLabels, false, xRange, this.stack);
  4017. stack.total = 0;
  4018. }
  4019. }
  4020. // Assign current to next for the upcoming iteration
  4021. next = current;
  4022. }
  4023. }
  4024. // Call base method
  4025. return this.getGraphPath(points);
  4026. };
  4027. });
  4028. _registerModule(_modules, 'masters/modules/broken-axis.src.js', [], function () {
  4029. });
  4030. _registerModule(_modules, 'parts/DataGrouping.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  4031. /* *
  4032. *
  4033. * (c) 2010-2019 Torstein Honsi
  4034. *
  4035. * License: www.highcharts.com/license
  4036. *
  4037. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4038. *
  4039. * */
  4040. /**
  4041. * @typedef {"average"|"averages"|"open"|"high"|"low"|"close"|"sum"} Highcharts.DataGroupingApproximationValue
  4042. */
  4043. /**
  4044. * @interface Highcharts.DataGroupingInfoObject
  4045. */ /**
  4046. * @name Highcharts.DataGroupingInfoObject#length
  4047. * @type {number}
  4048. */ /**
  4049. * @name Highcharts.DataGroupingInfoObject#options
  4050. * @type {Highcharts.SeriesOptionsType|undefined}
  4051. */ /**
  4052. * @name Highcharts.DataGroupingInfoObject#start
  4053. * @type {number}
  4054. */
  4055. var arrayMax = U.arrayMax, arrayMin = U.arrayMin, correctFloat = U.correctFloat, defined = U.defined, extend = U.extend, isNumber = U.isNumber, pick = U.pick;
  4056. var addEvent = H.addEvent, Axis = H.Axis, defaultPlotOptions = H.defaultPlotOptions, format = H.format, merge = H.merge, Point = H.Point, Series = H.Series, Tooltip = H.Tooltip;
  4057. /* ************************************************************************** *
  4058. * Start data grouping module *
  4059. * ************************************************************************** */
  4060. /* eslint-disable no-invalid-this, valid-jsdoc */
  4061. /**
  4062. * Define the available approximation types. The data grouping
  4063. * approximations takes an array or numbers as the first parameter. In case
  4064. * of ohlc, four arrays are sent in as four parameters. Each array consists
  4065. * only of numbers. In case null values belong to the group, the property
  4066. * .hasNulls will be set to true on the array.
  4067. *
  4068. * @product highstock
  4069. *
  4070. * @private
  4071. * @name Highcharts.approximations
  4072. * @type {Highcharts.Dictionary<Function>}
  4073. */
  4074. var approximations = H.approximations = {
  4075. sum: function (arr) {
  4076. var len = arr.length, ret;
  4077. // 1. it consists of nulls exclusive
  4078. if (!len && arr.hasNulls) {
  4079. ret = null;
  4080. // 2. it has a length and real values
  4081. }
  4082. else if (len) {
  4083. ret = 0;
  4084. while (len--) {
  4085. ret += arr[len];
  4086. }
  4087. }
  4088. // 3. it has zero length, so just return undefined
  4089. // => doNothing()
  4090. return ret;
  4091. },
  4092. average: function (arr) {
  4093. var len = arr.length, ret = approximations.sum(arr);
  4094. // If we have a number, return it divided by the length. If not,
  4095. // return null or undefined based on what the sum method finds.
  4096. if (isNumber(ret) && len) {
  4097. ret = correctFloat(ret / len);
  4098. }
  4099. return ret;
  4100. },
  4101. // The same as average, but for series with multiple values, like area
  4102. // ranges.
  4103. averages: function () {
  4104. var ret = [];
  4105. [].forEach.call(arguments, function (arr) {
  4106. ret.push(approximations.average(arr));
  4107. });
  4108. // Return undefined when first elem. is undefined and let
  4109. // sum method handle null (#7377)
  4110. return typeof ret[0] === 'undefined' ? void 0 : ret;
  4111. },
  4112. open: function (arr) {
  4113. return arr.length ? arr[0] : (arr.hasNulls ? null : void 0);
  4114. },
  4115. high: function (arr) {
  4116. return arr.length ?
  4117. arrayMax(arr) :
  4118. (arr.hasNulls ? null : void 0);
  4119. },
  4120. low: function (arr) {
  4121. return arr.length ?
  4122. arrayMin(arr) :
  4123. (arr.hasNulls ? null : void 0);
  4124. },
  4125. close: function (arr) {
  4126. return arr.length ?
  4127. arr[arr.length - 1] :
  4128. (arr.hasNulls ? null : void 0);
  4129. },
  4130. // ohlc and range are special cases where a multidimensional array is
  4131. // input and an array is output
  4132. ohlc: function (open, high, low, close) {
  4133. open = approximations.open(open);
  4134. high = approximations.high(high);
  4135. low = approximations.low(low);
  4136. close = approximations.close(close);
  4137. if (isNumber(open) ||
  4138. isNumber(high) ||
  4139. isNumber(low) ||
  4140. isNumber(close)) {
  4141. return [open, high, low, close];
  4142. }
  4143. // else, return is undefined
  4144. },
  4145. range: function (low, high) {
  4146. low = approximations.low(low);
  4147. high = approximations.high(high);
  4148. if (isNumber(low) || isNumber(high)) {
  4149. return [low, high];
  4150. }
  4151. if (low === null && high === null) {
  4152. return null;
  4153. }
  4154. // else, return is undefined
  4155. }
  4156. };
  4157. var groupData = function (xData, yData, groupPositions, approximation) {
  4158. var series = this, data = series.data, dataOptions = series.options && series.options.data, groupedXData = [], groupedYData = [], groupMap = [], dataLength = xData.length, pointX, pointY, groupedY,
  4159. // when grouping the fake extended axis for panning,
  4160. // we don't need to consider y
  4161. handleYData = !!yData, values = [], approximationFn, pointArrayMap = series.pointArrayMap, pointArrayMapLength = pointArrayMap && pointArrayMap.length, extendedPointArrayMap = ['x'].concat(pointArrayMap || ['y']), pos = 0, start = 0, valuesLen, i, j;
  4162. /**
  4163. * @private
  4164. */
  4165. function getApproximation(approx) {
  4166. if (typeof approx === 'function') {
  4167. return approx;
  4168. }
  4169. if (approximations[approx]) {
  4170. return approximations[approx];
  4171. }
  4172. return approximations[(series.getDGApproximation && series.getDGApproximation()) ||
  4173. 'average'];
  4174. }
  4175. approximationFn = getApproximation(approximation);
  4176. // Calculate values array size from pointArrayMap length
  4177. if (pointArrayMapLength) {
  4178. pointArrayMap.forEach(function () {
  4179. values.push([]);
  4180. });
  4181. }
  4182. else {
  4183. values.push([]);
  4184. }
  4185. valuesLen = pointArrayMapLength || 1;
  4186. // Start with the first point within the X axis range (#2696)
  4187. for (i = 0; i <= dataLength; i++) {
  4188. if (xData[i] >= groupPositions[0]) {
  4189. break;
  4190. }
  4191. }
  4192. for (i; i <= dataLength; i++) {
  4193. // when a new group is entered, summarize and initialize
  4194. // the previous group
  4195. while ((typeof groupPositions[pos + 1] !== 'undefined' &&
  4196. xData[i] >= groupPositions[pos + 1]) ||
  4197. i === dataLength) { // get the last group
  4198. // get group x and y
  4199. pointX = groupPositions[pos];
  4200. series.dataGroupInfo = {
  4201. start: series.cropStart + start,
  4202. length: values[0].length
  4203. };
  4204. groupedY = approximationFn.apply(series, values);
  4205. // By default, let options of the first grouped point be passed over
  4206. // to the grouped point. This allows preserving properties like
  4207. // `name` and `color` or custom properties. Implementers can
  4208. // override this from the approximation function, where they can
  4209. // write custom options to `this.dataGroupInfo.options`.
  4210. if (series.pointClass && !defined(series.dataGroupInfo.options)) {
  4211. // Convert numbers and arrays into objects
  4212. series.dataGroupInfo.options = merge(series.pointClass.prototype
  4213. .optionsToObject.call({ series: series }, series.options.data[series.cropStart + start]));
  4214. // Make sure the raw data (x, y, open, high etc) is not copied
  4215. // over and overwriting approximated data.
  4216. extendedPointArrayMap.forEach(function (key) {
  4217. delete series.dataGroupInfo.options[key];
  4218. });
  4219. }
  4220. // push the grouped data
  4221. if (typeof groupedY !== 'undefined') {
  4222. groupedXData.push(pointX);
  4223. groupedYData.push(groupedY);
  4224. groupMap.push(series.dataGroupInfo);
  4225. }
  4226. // reset the aggregate arrays
  4227. start = i;
  4228. for (j = 0; j < valuesLen; j++) {
  4229. values[j].length = 0; // faster than values[j] = []
  4230. values[j].hasNulls = false;
  4231. }
  4232. // Advance on the group positions
  4233. pos += 1;
  4234. // don't loop beyond the last group
  4235. if (i === dataLength) {
  4236. break;
  4237. }
  4238. }
  4239. // break out
  4240. if (i === dataLength) {
  4241. break;
  4242. }
  4243. // for each raw data point, push it to an array that contains all values
  4244. // for this specific group
  4245. if (pointArrayMap) {
  4246. var index = series.cropStart + i, point = (data && data[index]) ||
  4247. series.pointClass.prototype.applyOptions.apply({
  4248. series: series
  4249. }, [dataOptions[index]]), val;
  4250. for (j = 0; j < pointArrayMapLength; j++) {
  4251. val = point[pointArrayMap[j]];
  4252. if (isNumber(val)) {
  4253. values[j].push(val);
  4254. }
  4255. else if (val === null) {
  4256. values[j].hasNulls = true;
  4257. }
  4258. }
  4259. }
  4260. else {
  4261. pointY = handleYData ? yData[i] : null;
  4262. if (isNumber(pointY)) {
  4263. values[0].push(pointY);
  4264. }
  4265. else if (pointY === null) {
  4266. values[0].hasNulls = true;
  4267. }
  4268. }
  4269. }
  4270. return {
  4271. groupedXData: groupedXData,
  4272. groupedYData: groupedYData,
  4273. groupMap: groupMap
  4274. };
  4275. };
  4276. var dataGrouping = {
  4277. approximations: approximations,
  4278. groupData: groupData
  4279. };
  4280. // -----------------------------------------------------------------------------
  4281. // The following code applies to implementation of data grouping on a Series
  4282. var seriesProto = Series.prototype, baseProcessData = seriesProto.processData, baseGeneratePoints = seriesProto.generatePoints,
  4283. /** @ignore */
  4284. commonOptions = {
  4285. // enabled: null, // (true for stock charts, false for basic),
  4286. // forced: undefined,
  4287. groupPixelWidth: 2,
  4288. // the first one is the point or start value, the second is the start
  4289. // value if we're dealing with range, the third one is the end value if
  4290. // dealing with a range
  4291. dateTimeLabelFormats: {
  4292. millisecond: [
  4293. '%A, %b %e, %H:%M:%S.%L',
  4294. '%A, %b %e, %H:%M:%S.%L',
  4295. '-%H:%M:%S.%L'
  4296. ],
  4297. second: [
  4298. '%A, %b %e, %H:%M:%S',
  4299. '%A, %b %e, %H:%M:%S',
  4300. '-%H:%M:%S'
  4301. ],
  4302. minute: [
  4303. '%A, %b %e, %H:%M',
  4304. '%A, %b %e, %H:%M',
  4305. '-%H:%M'
  4306. ],
  4307. hour: [
  4308. '%A, %b %e, %H:%M',
  4309. '%A, %b %e, %H:%M',
  4310. '-%H:%M'
  4311. ],
  4312. day: [
  4313. '%A, %b %e, %Y',
  4314. '%A, %b %e',
  4315. '-%A, %b %e, %Y'
  4316. ],
  4317. week: [
  4318. 'Week from %A, %b %e, %Y',
  4319. '%A, %b %e',
  4320. '-%A, %b %e, %Y'
  4321. ],
  4322. month: [
  4323. '%B %Y',
  4324. '%B',
  4325. '-%B %Y'
  4326. ],
  4327. year: [
  4328. '%Y',
  4329. '%Y',
  4330. '-%Y'
  4331. ]
  4332. }
  4333. // smoothed = false, // enable this for navigator series only
  4334. }, specificOptions = {
  4335. line: {},
  4336. spline: {},
  4337. area: {},
  4338. areaspline: {},
  4339. arearange: {},
  4340. column: {
  4341. groupPixelWidth: 10
  4342. },
  4343. columnrange: {
  4344. groupPixelWidth: 10
  4345. },
  4346. candlestick: {
  4347. groupPixelWidth: 10
  4348. },
  4349. ohlc: {
  4350. groupPixelWidth: 5
  4351. }
  4352. },
  4353. // units are defined in a separate array to allow complete overriding in
  4354. // case of a user option
  4355. defaultDataGroupingUnits = H.defaultDataGroupingUnits = [
  4356. [
  4357. 'millisecond',
  4358. [1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
  4359. ], [
  4360. 'second',
  4361. [1, 2, 5, 10, 15, 30]
  4362. ], [
  4363. 'minute',
  4364. [1, 2, 5, 10, 15, 30]
  4365. ], [
  4366. 'hour',
  4367. [1, 2, 3, 4, 6, 8, 12]
  4368. ], [
  4369. 'day',
  4370. [1]
  4371. ], [
  4372. 'week',
  4373. [1]
  4374. ], [
  4375. 'month',
  4376. [1, 3, 6]
  4377. ], [
  4378. 'year',
  4379. null
  4380. ]
  4381. ];
  4382. // Set default approximations to the prototypes if present. Properties are
  4383. // inherited down. Can be overridden for individual series types.
  4384. seriesProto.getDGApproximation = function () {
  4385. if (H.seriesTypes.arearange && this instanceof H.seriesTypes.arearange) {
  4386. return 'range';
  4387. }
  4388. if (H.seriesTypes.ohlc && this instanceof H.seriesTypes.ohlc) {
  4389. return 'ohlc';
  4390. }
  4391. if (H.seriesTypes.column && this instanceof H.seriesTypes.column) {
  4392. return 'sum';
  4393. }
  4394. return 'average';
  4395. };
  4396. /**
  4397. * Takes parallel arrays of x and y data and groups the data into intervals
  4398. * defined by groupPositions, a collection of starting x values for each group.
  4399. *
  4400. * @private
  4401. * @function Highcharts.Series#groupData
  4402. *
  4403. * @param {Array<number>} xData
  4404. *
  4405. * @param {Array<number>|Array<Array<number>>} yData
  4406. *
  4407. * @param {boolean} groupPositions
  4408. *
  4409. * @param {string|Function} approximation
  4410. *
  4411. * @return {void}
  4412. */
  4413. seriesProto.groupData = groupData;
  4414. // Extend the basic processData method, that crops the data to the current zoom
  4415. // range, with data grouping logic.
  4416. seriesProto.processData = function () {
  4417. var series = this, chart = series.chart, options = series.options, dataGroupingOptions = options.dataGrouping, groupingEnabled = series.allowDG !== false && dataGroupingOptions &&
  4418. pick(dataGroupingOptions.enabled, chart.options.isStock), visible = (series.visible || !chart.options.chart.ignoreHiddenSeries), hasGroupedData, skip, lastDataGrouping = this.currentDataGrouping, currentDataGrouping, croppedData, revertRequireSorting = false;
  4419. // Run base method
  4420. series.forceCrop = groupingEnabled; // #334
  4421. series.groupPixelWidth = null; // #2110
  4422. series.hasProcessed = true; // #2692
  4423. // Data needs to be sorted for dataGrouping
  4424. if (groupingEnabled && !series.requireSorting) {
  4425. series.requireSorting = revertRequireSorting = true;
  4426. }
  4427. // Skip if processData returns false or if grouping is disabled (in that
  4428. // order)
  4429. skip = (baseProcessData.apply(series, arguments) === false ||
  4430. !groupingEnabled);
  4431. // Revert original requireSorting value if changed
  4432. if (revertRequireSorting) {
  4433. series.requireSorting = false;
  4434. }
  4435. if (!skip) {
  4436. series.destroyGroupedData();
  4437. var i, processedXData = dataGroupingOptions.groupAll ?
  4438. series.xData :
  4439. series.processedXData, processedYData = dataGroupingOptions.groupAll ?
  4440. series.yData :
  4441. series.processedYData, plotSizeX = chart.plotSizeX, xAxis = series.xAxis, ordinal = xAxis.options.ordinal, groupPixelWidth = series.groupPixelWidth =
  4442. xAxis.getGroupPixelWidth && xAxis.getGroupPixelWidth();
  4443. // Execute grouping if the amount of points is greater than the limit
  4444. // defined in groupPixelWidth
  4445. if (groupPixelWidth) {
  4446. hasGroupedData = true;
  4447. // Force recreation of point instances in series.translate, #5699
  4448. series.isDirty = true;
  4449. series.points = null; // #6709
  4450. var extremes = xAxis.getExtremes(), xMin = extremes.min, xMax = extremes.max, groupIntervalFactor = (ordinal &&
  4451. xAxis.getGroupIntervalFactor(xMin, xMax, series)) || 1, interval = (groupPixelWidth * (xMax - xMin) / plotSizeX) *
  4452. groupIntervalFactor, groupPositions = xAxis.getTimeTicks(xAxis.normalizeTimeTickInterval(interval, dataGroupingOptions.units ||
  4453. defaultDataGroupingUnits),
  4454. // Processed data may extend beyond axis (#4907)
  4455. Math.min(xMin, processedXData[0]), Math.max(xMax, processedXData[processedXData.length - 1]), xAxis.options.startOfWeek, processedXData, series.closestPointRange), groupedData = seriesProto.groupData.apply(series, [
  4456. processedXData,
  4457. processedYData,
  4458. groupPositions,
  4459. dataGroupingOptions.approximation
  4460. ]), groupedXData = groupedData.groupedXData, groupedYData = groupedData.groupedYData, gapSize = 0;
  4461. // Prevent the smoothed data to spill out left and right, and make
  4462. // sure data is not shifted to the left
  4463. if (dataGroupingOptions.smoothed && groupedXData.length) {
  4464. i = groupedXData.length - 1;
  4465. groupedXData[i] = Math.min(groupedXData[i], xMax);
  4466. while (i-- && i > 0) {
  4467. groupedXData[i] += interval / 2;
  4468. }
  4469. groupedXData[0] = Math.max(groupedXData[0], xMin);
  4470. }
  4471. // Record what data grouping values were used
  4472. for (i = 1; i < groupPositions.length; i++) {
  4473. // The grouped gapSize needs to be the largest distance between
  4474. // the group to capture varying group sizes like months or DST
  4475. // crossing (#10000). Also check that the gap is not at the
  4476. // start of a segment.
  4477. if (!groupPositions.info.segmentStarts ||
  4478. groupPositions.info.segmentStarts.indexOf(i) === -1) {
  4479. gapSize = Math.max(groupPositions[i] - groupPositions[i - 1], gapSize);
  4480. }
  4481. }
  4482. currentDataGrouping = groupPositions.info;
  4483. currentDataGrouping.gapSize = gapSize;
  4484. series.closestPointRange = groupPositions.info.totalRange;
  4485. series.groupMap = groupedData.groupMap;
  4486. // Make sure the X axis extends to show the first group (#2533)
  4487. // But only for visible series (#5493, #6393)
  4488. if (defined(groupedXData[0]) &&
  4489. groupedXData[0] < xAxis.min &&
  4490. visible) {
  4491. if ((!defined(xAxis.options.min) &&
  4492. xAxis.min <= xAxis.dataMin) ||
  4493. xAxis.min === xAxis.dataMin) {
  4494. xAxis.min = Math.min(groupedXData[0], xAxis.min);
  4495. }
  4496. xAxis.dataMin = Math.min(groupedXData[0], xAxis.dataMin);
  4497. }
  4498. // We calculated all group positions but we should render
  4499. // only the ones within the visible range
  4500. if (dataGroupingOptions.groupAll) {
  4501. croppedData = series.cropData(groupedXData, groupedYData, xAxis.min, xAxis.max, 1 // Ordinal xAxis will remove left-most points otherwise
  4502. );
  4503. groupedXData = croppedData.xData;
  4504. groupedYData = croppedData.yData;
  4505. }
  4506. // Set series props
  4507. series.processedXData = groupedXData;
  4508. series.processedYData = groupedYData;
  4509. }
  4510. else {
  4511. series.groupMap = null;
  4512. }
  4513. series.hasGroupedData = hasGroupedData;
  4514. series.currentDataGrouping = currentDataGrouping;
  4515. series.preventGraphAnimation =
  4516. (lastDataGrouping && lastDataGrouping.totalRange) !==
  4517. (currentDataGrouping && currentDataGrouping.totalRange);
  4518. }
  4519. };
  4520. // Destroy the grouped data points. #622, #740
  4521. seriesProto.destroyGroupedData = function () {
  4522. // Clear previous groups
  4523. if (this.groupedData) {
  4524. this.groupedData.forEach(function (point, i) {
  4525. if (point) {
  4526. this.groupedData[i] = point.destroy ?
  4527. point.destroy() : null;
  4528. }
  4529. }, this);
  4530. // Clears all:
  4531. // - `this.groupedData`
  4532. // - `this.points`
  4533. // - `preserve` object in series.update()
  4534. this.groupedData.length = 0;
  4535. }
  4536. };
  4537. // Override the generatePoints method by adding a reference to grouped data
  4538. seriesProto.generatePoints = function () {
  4539. baseGeneratePoints.apply(this);
  4540. // Record grouped data in order to let it be destroyed the next time
  4541. // processData runs
  4542. this.destroyGroupedData(); // #622
  4543. this.groupedData = this.hasGroupedData ? this.points : null;
  4544. };
  4545. // Override point prototype to throw a warning when trying to update grouped
  4546. // points.
  4547. addEvent(Point, 'update', function () {
  4548. if (this.dataGroup) {
  4549. H.error(24, false, this.series.chart);
  4550. return false;
  4551. }
  4552. });
  4553. // Extend the original method, make the tooltip's header reflect the grouped
  4554. // range.
  4555. addEvent(Tooltip, 'headerFormatter', function (e) {
  4556. var tooltip = this, chart = this.chart, time = chart.time, labelConfig = e.labelConfig, series = labelConfig.series, options = series.options, tooltipOptions = series.tooltipOptions, dataGroupingOptions = options.dataGrouping, xDateFormat = tooltipOptions.xDateFormat, xDateFormatEnd, xAxis = series.xAxis, currentDataGrouping, dateTimeLabelFormats, labelFormats, formattedKey, formatString = tooltipOptions[(e.isFooter ? 'footer' : 'header') + 'Format'];
  4557. // apply only to grouped series
  4558. if (xAxis &&
  4559. xAxis.options.type === 'datetime' &&
  4560. dataGroupingOptions &&
  4561. isNumber(labelConfig.key)) {
  4562. // set variables
  4563. currentDataGrouping = series.currentDataGrouping;
  4564. dateTimeLabelFormats = dataGroupingOptions.dateTimeLabelFormats ||
  4565. // Fallback to commonOptions (#9693)
  4566. commonOptions.dateTimeLabelFormats;
  4567. // if we have grouped data, use the grouping information to get the
  4568. // right format
  4569. if (currentDataGrouping) {
  4570. labelFormats =
  4571. dateTimeLabelFormats[currentDataGrouping.unitName];
  4572. if (currentDataGrouping.count === 1) {
  4573. xDateFormat = labelFormats[0];
  4574. }
  4575. else {
  4576. xDateFormat = labelFormats[1];
  4577. xDateFormatEnd = labelFormats[2];
  4578. }
  4579. // if not grouped, and we don't have set the xDateFormat option, get the
  4580. // best fit, so if the least distance between points is one minute, show
  4581. // it, but if the least distance is one day, skip hours and minutes etc.
  4582. }
  4583. else if (!xDateFormat && dateTimeLabelFormats) {
  4584. xDateFormat = tooltip.getXDateFormat(labelConfig, tooltipOptions, xAxis);
  4585. }
  4586. // now format the key
  4587. formattedKey = time.dateFormat(xDateFormat, labelConfig.key);
  4588. if (xDateFormatEnd) {
  4589. formattedKey += time.dateFormat(xDateFormatEnd, labelConfig.key + currentDataGrouping.totalRange - 1);
  4590. }
  4591. // Replace default header style with class name
  4592. if (series.chart.styledMode) {
  4593. formatString = this.styledModeFormat(formatString);
  4594. }
  4595. // return the replaced format
  4596. e.text = format(formatString, {
  4597. point: extend(labelConfig.point, { key: formattedKey }),
  4598. series: series
  4599. }, chart);
  4600. e.preventDefault();
  4601. }
  4602. });
  4603. // Destroy grouped data on series destroy
  4604. addEvent(Series, 'destroy', seriesProto.destroyGroupedData);
  4605. // Handle default options for data grouping. This must be set at runtime because
  4606. // some series types are defined after this.
  4607. addEvent(Series, 'afterSetOptions', function (e) {
  4608. var options = e.options, type = this.type, plotOptions = this.chart.options.plotOptions, defaultOptions = defaultPlotOptions[type].dataGrouping,
  4609. // External series, for example technical indicators should also
  4610. // inherit commonOptions which are not available outside this module
  4611. baseOptions = this.useCommonDataGrouping && commonOptions;
  4612. if (specificOptions[type] || baseOptions) { // #1284
  4613. if (!defaultOptions) {
  4614. defaultOptions = merge(commonOptions, specificOptions[type]);
  4615. }
  4616. options.dataGrouping = merge(baseOptions, defaultOptions, plotOptions.series && plotOptions.series.dataGrouping, // #1228
  4617. // Set by the StockChart constructor:
  4618. plotOptions[type].dataGrouping, this.userOptions.dataGrouping);
  4619. }
  4620. });
  4621. // When resetting the scale reset the hasProccessed flag to avoid taking
  4622. // previous data grouping of neighbour series into accound when determining
  4623. // group pixel width (#2692).
  4624. addEvent(Axis, 'afterSetScale', function () {
  4625. this.series.forEach(function (series) {
  4626. series.hasProcessed = false;
  4627. });
  4628. });
  4629. // Get the data grouping pixel width based on the greatest defined individual
  4630. // width of the axis' series, and if whether one of the axes need grouping.
  4631. Axis.prototype.getGroupPixelWidth = function () {
  4632. var series = this.series, len = series.length, i, groupPixelWidth = 0, doGrouping = false, dataLength, dgOptions;
  4633. // If multiple series are compared on the same x axis, give them the same
  4634. // group pixel width (#334)
  4635. i = len;
  4636. while (i--) {
  4637. dgOptions = series[i].options.dataGrouping;
  4638. if (dgOptions) {
  4639. groupPixelWidth = Math.max(groupPixelWidth,
  4640. // Fallback to commonOptions (#9693)
  4641. pick(dgOptions.groupPixelWidth, commonOptions.groupPixelWidth));
  4642. }
  4643. }
  4644. // If one of the series needs grouping, apply it to all (#1634)
  4645. i = len;
  4646. while (i--) {
  4647. dgOptions = series[i].options.dataGrouping;
  4648. if (dgOptions && series[i].hasProcessed) { // #2692
  4649. dataLength = (series[i].processedXData || series[i].data).length;
  4650. // Execute grouping if the amount of points is greater than the
  4651. // limit defined in groupPixelWidth
  4652. if (series[i].groupPixelWidth ||
  4653. dataLength >
  4654. (this.chart.plotSizeX / groupPixelWidth) ||
  4655. (dataLength && dgOptions.forced)) {
  4656. doGrouping = true;
  4657. }
  4658. }
  4659. }
  4660. return doGrouping ? groupPixelWidth : 0;
  4661. };
  4662. /**
  4663. * Highstock only. Force data grouping on all the axis' series.
  4664. *
  4665. * @product highstock
  4666. *
  4667. * @function Highcharts.Axis#setDataGrouping
  4668. *
  4669. * @param {boolean|Highcharts.DataGroupingOptionsObject} [dataGrouping]
  4670. * A `dataGrouping` configuration. Use `false` to disable data grouping
  4671. * dynamically.
  4672. *
  4673. * @param {boolean} [redraw=true]
  4674. * Whether to redraw the chart or wait for a later call to
  4675. * {@link Chart#redraw}.
  4676. *
  4677. * @return {void}
  4678. */
  4679. Axis.prototype.setDataGrouping = function (dataGrouping, redraw) {
  4680. var i;
  4681. redraw = pick(redraw, true);
  4682. if (!dataGrouping) {
  4683. dataGrouping = {
  4684. forced: false,
  4685. units: null
  4686. };
  4687. }
  4688. // Axis is instantiated, update all series
  4689. if (this instanceof Axis) {
  4690. i = this.series.length;
  4691. while (i--) {
  4692. this.series[i].update({
  4693. dataGrouping: dataGrouping
  4694. }, false);
  4695. }
  4696. // Axis not yet instanciated, alter series options
  4697. }
  4698. else {
  4699. this.chart.options.series.forEach(function (seriesOptions) {
  4700. seriesOptions.dataGrouping = dataGrouping;
  4701. }, false);
  4702. }
  4703. // Clear ordinal slope, so we won't accidentaly use the old one (#7827)
  4704. this.ordinalSlope = null;
  4705. if (redraw) {
  4706. this.chart.redraw();
  4707. }
  4708. };
  4709. H.dataGrouping = dataGrouping;
  4710. /* eslint-enable no-invalid-this, valid-jsdoc */
  4711. /**
  4712. * Data grouping is the concept of sampling the data values into larger
  4713. * blocks in order to ease readability and increase performance of the
  4714. * JavaScript charts. Highstock by default applies data grouping when
  4715. * the points become closer than a certain pixel value, determined by
  4716. * the `groupPixelWidth` option.
  4717. *
  4718. * If data grouping is applied, the grouping information of grouped
  4719. * points can be read from the [Point.dataGroup](
  4720. * /class-reference/Highcharts.Point#dataGroup). If point options other than
  4721. * the data itself are set, for example `name` or `color` or custom properties,
  4722. * the grouping logic doesn't know how to group it. In this case the options of
  4723. * the first point instance are copied over to the group point. This can be
  4724. * altered through a custom `approximation` callback function.
  4725. *
  4726. * @declare Highcharts.DataGroupingOptionsObject
  4727. * @product highstock
  4728. * @requires modules/datagrouping
  4729. * @apioption plotOptions.series.dataGrouping
  4730. */
  4731. /**
  4732. * The method of approximation inside a group. When for example 30 days
  4733. * are grouped into one month, this determines what value should represent
  4734. * the group. Possible values are "average", "averages", "open", "high",
  4735. * "low", "close" and "sum". For OHLC and candlestick series the approximation
  4736. * is "ohlc" by default, which finds the open, high, low and close values
  4737. * within all the grouped data. For ranges, the approximation is "range",
  4738. * which finds the low and high values. For multi-dimensional data,
  4739. * like ranges and OHLC, "averages" will compute the average for each
  4740. * dimension.
  4741. *
  4742. * Custom aggregate methods can be added by assigning a callback function
  4743. * as the approximation. This function takes a numeric array as the
  4744. * argument and should return a single numeric value or `null`. Note
  4745. * that the numeric array will never contain null values, only true
  4746. * numbers. Instead, if null values are present in the raw data, the
  4747. * numeric array will have an `.hasNulls` property set to `true`. For
  4748. * single-value data sets the data is available in the first argument
  4749. * of the callback function. For OHLC data sets, all the open values
  4750. * are in the first argument, all high values in the second etc.
  4751. *
  4752. * Since v4.2.7, grouping meta data is available in the approximation
  4753. * callback from `this.dataGroupInfo`. It can be used to extract information
  4754. * from the raw data.
  4755. *
  4756. * Defaults to `average` for line-type series, `sum` for columns, `range`
  4757. * for range series and `ohlc` for OHLC and candlestick.
  4758. *
  4759. * @sample {highstock} stock/plotoptions/series-datagrouping-approximation
  4760. * Approximation callback with custom data
  4761. *
  4762. * @type {Highcharts.DataGroupingApproximationValue|Function}
  4763. * @product highstock
  4764. * @apioption plotOptions.series.dataGrouping.approximation
  4765. */
  4766. /**
  4767. * Datetime formats for the header of the tooltip in a stock chart.
  4768. * The format can vary within a chart depending on the currently selected
  4769. * time range and the current data grouping.
  4770. *
  4771. * The default formats are:
  4772. * ```js
  4773. * {
  4774. * millisecond: [
  4775. * '%A, %b %e, %H:%M:%S.%L', '%A, %b %e, %H:%M:%S.%L', '-%H:%M:%S.%L'
  4776. * ],
  4777. * second: ['%A, %b %e, %H:%M:%S', '%A, %b %e, %H:%M:%S', '-%H:%M:%S'],
  4778. * minute: ['%A, %b %e, %H:%M', '%A, %b %e, %H:%M', '-%H:%M'],
  4779. * hour: ['%A, %b %e, %H:%M', '%A, %b %e, %H:%M', '-%H:%M'],
  4780. * day: ['%A, %b %e, %Y', '%A, %b %e', '-%A, %b %e, %Y'],
  4781. * week: ['Week from %A, %b %e, %Y', '%A, %b %e', '-%A, %b %e, %Y'],
  4782. * month: ['%B %Y', '%B', '-%B %Y'],
  4783. * year: ['%Y', '%Y', '-%Y']
  4784. * }
  4785. * ```
  4786. *
  4787. * For each of these array definitions, the first item is the format
  4788. * used when the active time span is one unit. For instance, if the
  4789. * current data applies to one week, the first item of the week array
  4790. * is used. The second and third items are used when the active time
  4791. * span is more than two units. For instance, if the current data applies
  4792. * to two weeks, the second and third item of the week array are used,
  4793. * and applied to the start and end date of the time span.
  4794. *
  4795. * @type {object}
  4796. * @product highstock
  4797. * @apioption plotOptions.series.dataGrouping.dateTimeLabelFormats
  4798. */
  4799. /**
  4800. * Enable or disable data grouping.
  4801. *
  4802. * @type {boolean}
  4803. * @default true
  4804. * @product highstock
  4805. * @apioption plotOptions.series.dataGrouping.enabled
  4806. */
  4807. /**
  4808. * When data grouping is forced, it runs no matter how small the intervals
  4809. * are. This can be handy for example when the sum should be calculated
  4810. * for values appearing at random times within each hour.
  4811. *
  4812. * @type {boolean}
  4813. * @default false
  4814. * @product highstock
  4815. * @apioption plotOptions.series.dataGrouping.forced
  4816. */
  4817. /**
  4818. * The approximate pixel width of each group. If for example a series
  4819. * with 30 points is displayed over a 600 pixel wide plot area, no grouping
  4820. * is performed. If however the series contains so many points that
  4821. * the spacing is less than the groupPixelWidth, Highcharts will try
  4822. * to group it into appropriate groups so that each is more or less
  4823. * two pixels wide. If multiple series with different group pixel widths
  4824. * are drawn on the same x axis, all series will take the greatest width.
  4825. * For example, line series have 2px default group width, while column
  4826. * series have 10px. If combined, both the line and the column will
  4827. * have 10px by default.
  4828. *
  4829. * @type {number}
  4830. * @default 2
  4831. * @product highstock
  4832. * @apioption plotOptions.series.dataGrouping.groupPixelWidth
  4833. */
  4834. /**
  4835. * By default only points within the visible range are grouped. Enabling this
  4836. * option will force data grouping to calculate all grouped points for a given
  4837. * dataset. That option prevents for example a column series from calculating
  4838. * a grouped point partially. The effect is similar to
  4839. * [Series.getExtremesFromAll](#plotOptions.series.getExtremesFromAll) but does
  4840. * not affect yAxis extremes.
  4841. *
  4842. * @sample {highstock} stock/plotoptions/series-datagrouping-groupall/
  4843. * Two series with the same data but different groupAll setting
  4844. *
  4845. * @type {boolean}
  4846. * @default false
  4847. * @since 6.1.0
  4848. * @product highstock
  4849. * @apioption plotOptions.series.dataGrouping.groupAll
  4850. */
  4851. /**
  4852. * Normally, a group is indexed by the start of that group, so for example
  4853. * when 30 daily values are grouped into one month, that month's x value
  4854. * will be the 1st of the month. This apparently shifts the data to
  4855. * the left. When the smoothed option is true, this is compensated for.
  4856. * The data is shifted to the middle of the group, and min and max
  4857. * values are preserved. Internally, this is used in the Navigator series.
  4858. *
  4859. * @type {boolean}
  4860. * @default false
  4861. * @product highstock
  4862. * @apioption plotOptions.series.dataGrouping.smoothed
  4863. */
  4864. /**
  4865. * An array determining what time intervals the data is allowed to be
  4866. * grouped to. Each array item is an array where the first value is
  4867. * the time unit and the second value another array of allowed multiples.
  4868. *
  4869. * Defaults to:
  4870. * ```js
  4871. * units: [[
  4872. * 'millisecond', // unit name
  4873. * [1, 2, 5, 10, 20, 25, 50, 100, 200, 500] // allowed multiples
  4874. * ], [
  4875. * 'second',
  4876. * [1, 2, 5, 10, 15, 30]
  4877. * ], [
  4878. * 'minute',
  4879. * [1, 2, 5, 10, 15, 30]
  4880. * ], [
  4881. * 'hour',
  4882. * [1, 2, 3, 4, 6, 8, 12]
  4883. * ], [
  4884. * 'day',
  4885. * [1]
  4886. * ], [
  4887. * 'week',
  4888. * [1]
  4889. * ], [
  4890. * 'month',
  4891. * [1, 3, 6]
  4892. * ], [
  4893. * 'year',
  4894. * null
  4895. * ]]
  4896. * ```
  4897. *
  4898. * @type {Array<Array<string,(Array<number>|null)>>}
  4899. * @product highstock
  4900. * @apioption plotOptions.series.dataGrouping.units
  4901. */
  4902. /**
  4903. * The approximate pixel width of each group. If for example a series
  4904. * with 30 points is displayed over a 600 pixel wide plot area, no grouping
  4905. * is performed. If however the series contains so many points that
  4906. * the spacing is less than the groupPixelWidth, Highcharts will try
  4907. * to group it into appropriate groups so that each is more or less
  4908. * two pixels wide. Defaults to `10`.
  4909. *
  4910. * @sample {highstock} stock/plotoptions/series-datagrouping-grouppixelwidth/
  4911. * Two series with the same data density but different groupPixelWidth
  4912. *
  4913. * @type {number}
  4914. * @default 10
  4915. * @product highstock
  4916. * @apioption plotOptions.column.dataGrouping.groupPixelWidth
  4917. */
  4918. ''; // required by JSDoc parsing
  4919. return dataGrouping;
  4920. });
  4921. _registerModule(_modules, 'parts/OHLCSeries.js', [_modules['parts/Globals.js']], function (H) {
  4922. /* *
  4923. *
  4924. * (c) 2010-2019 Torstein Honsi
  4925. *
  4926. * License: www.highcharts.com/license
  4927. *
  4928. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  4929. *
  4930. * */
  4931. var Point = H.Point, seriesType = H.seriesType, seriesTypes = H.seriesTypes;
  4932. /**
  4933. * The ohlc series type.
  4934. *
  4935. * @private
  4936. * @class
  4937. * @name Highcharts.seriesTypes.ohlc
  4938. *
  4939. * @augments Highcharts.Series
  4940. */
  4941. seriesType('ohlc', 'column'
  4942. /**
  4943. * An OHLC chart is a style of financial chart used to describe price
  4944. * movements over time. It displays open, high, low and close values per
  4945. * data point.
  4946. *
  4947. * @sample stock/demo/ohlc/
  4948. * OHLC chart
  4949. *
  4950. * @extends plotOptions.column
  4951. * @excluding borderColor, borderRadius, borderWidth, crisp, stacking,
  4952. * stack
  4953. * @product highstock
  4954. * @optionparent plotOptions.ohlc
  4955. */
  4956. , {
  4957. /**
  4958. * The approximate pixel width of each group. If for example a series
  4959. * with 30 points is displayed over a 600 pixel wide plot area, no
  4960. * grouping is performed. If however the series contains so many points
  4961. * that the spacing is less than the groupPixelWidth, Highcharts will
  4962. * try to group it into appropriate groups so that each is more or less
  4963. * two pixels wide. Defaults to `5`.
  4964. *
  4965. * @type {number}
  4966. * @default 5
  4967. * @product highstock
  4968. * @apioption plotOptions.ohlc.dataGrouping.groupPixelWidth
  4969. */
  4970. /**
  4971. * The pixel width of the line/border. Defaults to `1`.
  4972. *
  4973. * @sample {highstock} stock/plotoptions/ohlc-linewidth/
  4974. * A greater line width
  4975. *
  4976. * @type {number}
  4977. * @default 1
  4978. * @product highstock
  4979. *
  4980. * @private
  4981. */
  4982. lineWidth: 1,
  4983. tooltip: {
  4984. pointFormat: '<span style="color:{point.color}">\u25CF</span> ' +
  4985. '<b> {series.name}</b><br/>' +
  4986. 'Open: {point.open}<br/>' +
  4987. 'High: {point.high}<br/>' +
  4988. 'Low: {point.low}<br/>' +
  4989. 'Close: {point.close}<br/>'
  4990. },
  4991. threshold: null,
  4992. states: {
  4993. /**
  4994. * @extends plotOptions.column.states.hover
  4995. * @product highstock
  4996. */
  4997. hover: {
  4998. /**
  4999. * The pixel width of the line representing the OHLC point.
  5000. *
  5001. * @type {number}
  5002. * @default 3
  5003. * @product highstock
  5004. */
  5005. lineWidth: 3
  5006. }
  5007. },
  5008. /**
  5009. * Determines which one of `open`, `high`, `low`, `close` values should
  5010. * be represented as `point.y`, which is later used to set dataLabel
  5011. * position and [compare](#plotOptions.series.compare).
  5012. *
  5013. * @sample {highstock} stock/plotoptions/ohlc-pointvalkey/
  5014. * Possible values
  5015. *
  5016. * @type {string}
  5017. * @default close
  5018. * @validvalue ["open", "high", "low", "close"]
  5019. * @product highstock
  5020. * @apioption plotOptions.ohlc.pointValKey
  5021. */
  5022. /**
  5023. * @default close
  5024. * @apioption plotOptions.ohlc.colorKey
  5025. */
  5026. /**
  5027. * Line color for up points.
  5028. *
  5029. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5030. * @product highstock
  5031. * @apioption plotOptions.ohlc.upColor
  5032. */
  5033. stickyTracking: true
  5034. },
  5035. /**
  5036. * @lends Highcharts.seriesTypes.ohlc
  5037. */
  5038. {
  5039. /* eslint-disable valid-jsdoc */
  5040. directTouch: false,
  5041. pointArrayMap: ['open', 'high', 'low', 'close'],
  5042. toYData: function (point) {
  5043. // return a plain array for speedy calculation
  5044. return [point.open, point.high, point.low, point.close];
  5045. },
  5046. pointValKey: 'close',
  5047. pointAttrToOptions: {
  5048. stroke: 'color',
  5049. 'stroke-width': 'lineWidth'
  5050. },
  5051. /**
  5052. * @private
  5053. * @function Highcarts.seriesTypes.ohlc#init
  5054. * @return {void}
  5055. */
  5056. init: function () {
  5057. seriesTypes.column.prototype.init.apply(this, arguments);
  5058. this.options.stacking = false; // #8817
  5059. },
  5060. /**
  5061. * Postprocess mapping between options and SVG attributes
  5062. *
  5063. * @private
  5064. * @function Highcharts.seriesTypes.ohlc#pointAttribs
  5065. * @param {Highcharts.OHLCPoint} point
  5066. * @param {string} state
  5067. * @return {Highcharts.SVGAttributes}
  5068. */
  5069. pointAttribs: function (point, state) {
  5070. var attribs = seriesTypes.column.prototype.pointAttribs.call(this, point, state), options = this.options;
  5071. delete attribs.fill;
  5072. if (!point.options.color &&
  5073. options.upColor &&
  5074. point.open < point.close) {
  5075. attribs.stroke = options.upColor;
  5076. }
  5077. return attribs;
  5078. },
  5079. /**
  5080. * Translate data points from raw values x and y to plotX and plotY
  5081. *
  5082. * @private
  5083. * @function Highcharts.seriesTypes.ohlc#translate
  5084. * @return {void}
  5085. */
  5086. translate: function () {
  5087. var series = this, yAxis = series.yAxis, hasModifyValue = !!series.modifyValue, translated = [
  5088. 'plotOpen',
  5089. 'plotHigh',
  5090. 'plotLow',
  5091. 'plotClose',
  5092. 'yBottom'
  5093. ]; // translate OHLC for
  5094. seriesTypes.column.prototype.translate.apply(series);
  5095. // Do the translation
  5096. series.points.forEach(function (point) {
  5097. [point.open, point.high, point.low, point.close, point.low]
  5098. .forEach(function (value, i) {
  5099. if (value !== null) {
  5100. if (hasModifyValue) {
  5101. value = series.modifyValue(value);
  5102. }
  5103. point[translated[i]] =
  5104. yAxis.toPixels(value, true);
  5105. }
  5106. });
  5107. // Align the tooltip to the high value to avoid covering the
  5108. // point
  5109. point.tooltipPos[1] =
  5110. point.plotHigh + yAxis.pos - series.chart.plotTop;
  5111. });
  5112. },
  5113. /**
  5114. * Draw the data points
  5115. *
  5116. * @private
  5117. * @function Highcharts.seriesTypes.ohlc#drawPoints
  5118. * @return {void}
  5119. */
  5120. drawPoints: function () {
  5121. var series = this, points = series.points, chart = series.chart;
  5122. points.forEach(function (point) {
  5123. var plotOpen, plotClose, crispCorr, halfWidth, path, graphic = point.graphic, crispX, isNew = !graphic;
  5124. if (typeof point.plotY !== 'undefined') {
  5125. // Create and/or update the graphic
  5126. if (!graphic) {
  5127. point.graphic = graphic = chart.renderer.path()
  5128. .add(series.group);
  5129. }
  5130. if (!chart.styledMode) {
  5131. graphic.attr(series.pointAttribs(point, (point.selected && 'select'))); // #3897
  5132. }
  5133. // crisp vector coordinates
  5134. crispCorr = (graphic.strokeWidth() % 2) / 2;
  5135. // #2596:
  5136. crispX = Math.round(point.plotX) - crispCorr;
  5137. halfWidth = Math.round(point.shapeArgs.width / 2);
  5138. // the vertical stem
  5139. path = [
  5140. 'M',
  5141. crispX, Math.round(point.yBottom),
  5142. 'L',
  5143. crispX, Math.round(point.plotHigh)
  5144. ];
  5145. // open
  5146. if (point.open !== null) {
  5147. plotOpen = Math.round(point.plotOpen) + crispCorr;
  5148. path.push('M', crispX, plotOpen, 'L', crispX - halfWidth, plotOpen);
  5149. }
  5150. // close
  5151. if (point.close !== null) {
  5152. plotClose = Math.round(point.plotClose) + crispCorr;
  5153. path.push('M', crispX, plotClose, 'L', crispX + halfWidth, plotClose);
  5154. }
  5155. graphic[isNew ? 'attr' : 'animate']({ d: path })
  5156. .addClass(point.getClassName(), true);
  5157. }
  5158. });
  5159. },
  5160. animate: null // Disable animation
  5161. /* eslint-enable valid-jsdoc */
  5162. },
  5163. /**
  5164. * @lends Highcharts.seriesTypes.ohlc.prototype.pointClass.prototype
  5165. */
  5166. {
  5167. /* eslint-disable valid-jsdoc */
  5168. /**
  5169. * Extend the parent method by adding up or down to the class name.
  5170. * @private
  5171. * @function Highcharts.seriesTypes.ohlc#getClassName
  5172. * @return {string}
  5173. */
  5174. getClassName: function () {
  5175. return Point.prototype.getClassName.call(this) +
  5176. (this.open < this.close ?
  5177. ' highcharts-point-up' :
  5178. ' highcharts-point-down');
  5179. }
  5180. /* eslint-enable valid-jsdoc */
  5181. });
  5182. /**
  5183. * A `ohlc` series. If the [type](#series.ohlc.type) option is not
  5184. * specified, it is inherited from [chart.type](#chart.type).
  5185. *
  5186. * @extends series,plotOptions.ohlc
  5187. * @excluding dataParser, dataURL
  5188. * @product highstock
  5189. * @apioption series.ohlc
  5190. */
  5191. /**
  5192. * An array of data points for the series. For the `ohlc` series type,
  5193. * points can be given in the following ways:
  5194. *
  5195. * 1. An array of arrays with 5 or 4 values. In this case, the values correspond
  5196. * to `x,open,high,low,close`. If the first value is a string, it is applied
  5197. * as the name of the point, and the `x` value is inferred. The `x` value can
  5198. * also be omitted, in which case the inner arrays should be of length 4\.
  5199. * Then the `x` value is automatically calculated, either starting at 0 and
  5200. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  5201. * series options.
  5202. * ```js
  5203. * data: [
  5204. * [0, 6, 5, 6, 7],
  5205. * [1, 9, 4, 8, 2],
  5206. * [2, 6, 3, 4, 10]
  5207. * ]
  5208. * ```
  5209. *
  5210. * 2. An array of objects with named values. The following snippet shows only a
  5211. * few settings, see the complete options set below. If the total number of
  5212. * data points exceeds the series'
  5213. * [turboThreshold](#series.ohlc.turboThreshold), this option is not
  5214. * available.
  5215. * ```js
  5216. * data: [{
  5217. * x: 1,
  5218. * open: 3,
  5219. * high: 4,
  5220. * low: 5,
  5221. * close: 2,
  5222. * name: "Point2",
  5223. * color: "#00FF00"
  5224. * }, {
  5225. * x: 1,
  5226. * open: 4,
  5227. * high: 3,
  5228. * low: 6,
  5229. * close: 7,
  5230. * name: "Point1",
  5231. * color: "#FF00FF"
  5232. * }]
  5233. * ```
  5234. *
  5235. * @type {Array<Array<(number|string),number,number,number>|Array<(number|string),number,number,number,number>|*>}
  5236. * @extends series.arearange.data
  5237. * @excluding y, marker
  5238. * @product highstock
  5239. * @apioption series.ohlc.data
  5240. */
  5241. /**
  5242. * The closing value of each data point.
  5243. *
  5244. * @type {number}
  5245. * @product highstock
  5246. * @apioption series.ohlc.data.close
  5247. */
  5248. /**
  5249. * The opening value of each data point.
  5250. *
  5251. * @type {number}
  5252. * @product highstock
  5253. * @apioption series.ohlc.data.open
  5254. */
  5255. ''; // adds doclets above to transpilat
  5256. });
  5257. _registerModule(_modules, 'parts/CandlestickSeries.js', [_modules['parts/Globals.js']], function (H) {
  5258. /* *
  5259. *
  5260. * (c) 2010-2019 Torstein Honsi
  5261. *
  5262. * License: www.highcharts.com/license
  5263. *
  5264. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5265. *
  5266. * */
  5267. var defaultPlotOptions = H.defaultPlotOptions, merge = H.merge, seriesType = H.seriesType, seriesTypes = H.seriesTypes;
  5268. /**
  5269. * A candlestick chart is a style of financial chart used to describe price
  5270. * movements over time.
  5271. *
  5272. * @sample stock/demo/candlestick/
  5273. * Candlestick chart
  5274. *
  5275. * @extends plotOptions.ohlc
  5276. * @excluding borderColor,borderRadius,borderWidth
  5277. * @product highstock
  5278. * @optionparent plotOptions.candlestick
  5279. */
  5280. var candlestickOptions = {
  5281. /**
  5282. * The specific line color for up candle sticks. The default is to inherit
  5283. * the general `lineColor` setting.
  5284. *
  5285. * @sample {highstock} stock/plotoptions/candlestick-linecolor/
  5286. * Candlestick line colors
  5287. *
  5288. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5289. * @since 1.3.6
  5290. * @product highstock
  5291. * @apioption plotOptions.candlestick.upLineColor
  5292. */
  5293. /**
  5294. * @type {Highcharts.DataGroupingApproximationValue|Function}
  5295. * @default ohlc
  5296. * @product highstock
  5297. * @apioption plotOptions.candlestick.dataGrouping.approximation
  5298. */
  5299. states: {
  5300. /**
  5301. * @extends plotOptions.column.states.hover
  5302. * @product highstock
  5303. */
  5304. hover: {
  5305. /**
  5306. * The pixel width of the line/border around the candlestick.
  5307. *
  5308. * @product highstock
  5309. */
  5310. lineWidth: 2
  5311. }
  5312. },
  5313. /**
  5314. * @extends plotOptions.ohlc.tooltip
  5315. */
  5316. tooltip: defaultPlotOptions.ohlc.tooltip,
  5317. /**
  5318. * @type {number|null}
  5319. * @product highstock
  5320. */
  5321. threshold: null,
  5322. /**
  5323. * The color of the line/border of the candlestick.
  5324. *
  5325. * In styled mode, the line stroke can be set with the
  5326. * `.highcharts-candlestick-series .highcahrts-point` rule.
  5327. *
  5328. * @see [upLineColor](#plotOptions.candlestick.upLineColor)
  5329. *
  5330. * @sample {highstock} stock/plotoptions/candlestick-linecolor/
  5331. * Candlestick line colors
  5332. *
  5333. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5334. * @default #000000
  5335. * @product highstock
  5336. */
  5337. lineColor: '#000000',
  5338. /**
  5339. * The pixel width of the candlestick line/border. Defaults to `1`.
  5340. *
  5341. *
  5342. * In styled mode, the line stroke width can be set with the
  5343. * `.highcharts-candlestick-series .highcahrts-point` rule.
  5344. *
  5345. * @product highstock
  5346. */
  5347. lineWidth: 1,
  5348. /**
  5349. * The fill color of the candlestick when values are rising.
  5350. *
  5351. * In styled mode, the up color can be set with the
  5352. * `.highcharts-candlestick-series .highcharts-point-up` rule.
  5353. *
  5354. * @sample {highstock} stock/plotoptions/candlestick-color/
  5355. * Custom colors
  5356. * @sample {highstock} highcharts/css/candlestick/
  5357. * Colors in styled mode
  5358. *
  5359. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5360. * @default #ffffff
  5361. * @product highstock
  5362. */
  5363. upColor: '#ffffff',
  5364. /**
  5365. * @product highstock
  5366. */
  5367. stickyTracking: true
  5368. };
  5369. /**
  5370. * The candlestick series type.
  5371. *
  5372. * @private
  5373. * @class
  5374. * @name Highcharts.seriesTypes.candlestick
  5375. *
  5376. * @augments Highcharts.seriesTypes.ohlc
  5377. */
  5378. seriesType('candlestick', 'ohlc', merge(defaultPlotOptions.column, candlestickOptions),
  5379. /**
  5380. * @lends seriesTypes.candlestick
  5381. */
  5382. {
  5383. /* eslint-disable valid-jsdoc */
  5384. /**
  5385. * Postprocess mapping between options and SVG attributes
  5386. *
  5387. * @private
  5388. * @function Highcharts.seriesTypes.candlestick#pointAttribs
  5389. * @param {Highcharts.Point} point
  5390. * @param {string} [state]
  5391. * @return {Highcharts.SVGAttributes}
  5392. */
  5393. pointAttribs: function (point, state) {
  5394. var attribs = seriesTypes.column.prototype.pointAttribs.call(this, point, state), options = this.options, isUp = point.open < point.close, stroke = options.lineColor || this.color, stateOptions;
  5395. attribs['stroke-width'] = options.lineWidth;
  5396. attribs.fill = point.options.color ||
  5397. (isUp ? (options.upColor || this.color) : this.color);
  5398. attribs.stroke = point.options.lineColor ||
  5399. (isUp ? (options.upLineColor || stroke) : stroke);
  5400. // Select or hover states
  5401. if (state) {
  5402. stateOptions = options.states[state];
  5403. attribs.fill = stateOptions.color || attribs.fill;
  5404. attribs.stroke = stateOptions.lineColor || attribs.stroke;
  5405. attribs['stroke-width'] =
  5406. stateOptions.lineWidth || attribs['stroke-width'];
  5407. }
  5408. return attribs;
  5409. },
  5410. /**
  5411. * Draw the data points.
  5412. *
  5413. * @private
  5414. * @function Highcharts.seriesTypes.candlestick#drawPoints
  5415. * @return {void}
  5416. */
  5417. drawPoints: function () {
  5418. var series = this, points = series.points, chart = series.chart, reversedYAxis = series.yAxis.reversed;
  5419. points.forEach(function (point) {
  5420. var graphic = point.graphic, plotOpen, plotClose, topBox, bottomBox, hasTopWhisker, hasBottomWhisker, crispCorr, crispX, path, halfWidth, isNew = !graphic;
  5421. if (typeof point.plotY !== 'undefined') {
  5422. if (!graphic) {
  5423. point.graphic = graphic = chart.renderer.path()
  5424. .add(series.group);
  5425. }
  5426. if (!series.chart.styledMode) {
  5427. graphic
  5428. .attr(series.pointAttribs(point, (point.selected && 'select'))) // #3897
  5429. .shadow(series.options.shadow);
  5430. }
  5431. // Crisp vector coordinates
  5432. crispCorr = (graphic.strokeWidth() % 2) / 2;
  5433. // #2596:
  5434. crispX = Math.round(point.plotX) - crispCorr;
  5435. plotOpen = point.plotOpen;
  5436. plotClose = point.plotClose;
  5437. topBox = Math.min(plotOpen, plotClose);
  5438. bottomBox = Math.max(plotOpen, plotClose);
  5439. halfWidth = Math.round(point.shapeArgs.width / 2);
  5440. hasTopWhisker = reversedYAxis ?
  5441. bottomBox !== point.yBottom :
  5442. Math.round(topBox) !==
  5443. Math.round(point.plotHigh);
  5444. hasBottomWhisker = reversedYAxis ?
  5445. Math.round(topBox) !==
  5446. Math.round(point.plotHigh) :
  5447. bottomBox !== point.yBottom;
  5448. topBox = Math.round(topBox) + crispCorr;
  5449. bottomBox = Math.round(bottomBox) + crispCorr;
  5450. // Create the path. Due to a bug in Chrome 49, the path is
  5451. // first instanciated with no values, then the values
  5452. // pushed. For unknown reasons, instanciating the path array
  5453. // with all the values would lead to a crash when updating
  5454. // frequently (#5193).
  5455. path = [];
  5456. path.push('M', crispX - halfWidth, bottomBox, 'L', crispX - halfWidth, topBox, 'L', crispX + halfWidth, topBox, 'L', crispX + halfWidth, bottomBox, 'Z', // Ensure a nice rectangle #2602
  5457. 'M', crispX, topBox, 'L',
  5458. // #460, #2094
  5459. crispX, hasTopWhisker ?
  5460. Math.round(reversedYAxis ?
  5461. point.yBottom :
  5462. point.plotHigh) :
  5463. topBox, 'M', crispX, bottomBox, 'L',
  5464. // #460, #2094
  5465. crispX, hasBottomWhisker ?
  5466. Math.round(reversedYAxis ?
  5467. point.plotHigh :
  5468. point.yBottom) :
  5469. bottomBox);
  5470. graphic[isNew ? 'attr' : 'animate']({ d: path })
  5471. .addClass(point.getClassName(), true);
  5472. }
  5473. });
  5474. /* eslint-enable valid-jsdoc */
  5475. }
  5476. });
  5477. /**
  5478. * A `candlestick` series. If the [type](#series.candlestick.type)
  5479. * option is not specified, it is inherited from [chart.type](
  5480. * #chart.type).
  5481. *
  5482. * @type {*}
  5483. * @extends series,plotOptions.candlestick
  5484. * @excluding dataParser, dataURL
  5485. * @product highstock
  5486. * @apioption series.candlestick
  5487. */
  5488. /**
  5489. * An array of data points for the series. For the `candlestick` series
  5490. * type, points can be given in the following ways:
  5491. *
  5492. * 1. An array of arrays with 5 or 4 values. In this case, the values correspond
  5493. * to `x,open,high,low,close`. If the first value is a string, it is applied
  5494. * as the name of the point, and the `x` value is inferred. The `x` value can
  5495. * also be omitted, in which case the inner arrays should be of length 4.
  5496. * Then the `x` value is automatically calculated, either starting at 0 and
  5497. * incremented by 1, or from `pointStart` and `pointInterval` given in the
  5498. * series options.
  5499. * ```js
  5500. * data: [
  5501. * [0, 7, 2, 0, 4],
  5502. * [1, 1, 4, 2, 8],
  5503. * [2, 3, 3, 9, 3]
  5504. * ]
  5505. * ```
  5506. *
  5507. * 2. An array of objects with named values. The following snippet shows only a
  5508. * few settings, see the complete options set below. If the total number of
  5509. * data points exceeds the series'
  5510. * [turboThreshold](#series.candlestick.turboThreshold), this option is not
  5511. * available.
  5512. * ```js
  5513. * data: [{
  5514. * x: 1,
  5515. * open: 9,
  5516. * high: 2,
  5517. * low: 4,
  5518. * close: 6,
  5519. * name: "Point2",
  5520. * color: "#00FF00"
  5521. * }, {
  5522. * x: 1,
  5523. * open: 1,
  5524. * high: 4,
  5525. * low: 7,
  5526. * close: 7,
  5527. * name: "Point1",
  5528. * color: "#FF00FF"
  5529. * }]
  5530. * ```
  5531. *
  5532. * @type {Array<Array<(number|string),number,number,number>|Array<(number|string),number,number,number,number>|*>}
  5533. * @extends series.ohlc.data
  5534. * @excluding y
  5535. * @product highstock
  5536. * @apioption series.candlestick.data
  5537. */
  5538. ''; // adds doclets above to transpilat
  5539. });
  5540. _registerModule(_modules, 'mixins/on-series.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  5541. /* *
  5542. *
  5543. * (c) 2010-2019 Torstein Honsi
  5544. *
  5545. * License: www.highcharts.com/license
  5546. *
  5547. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5548. *
  5549. * */
  5550. var defined = U.defined;
  5551. var seriesTypes = H.seriesTypes, stableSort = H.stableSort;
  5552. /**
  5553. * @private
  5554. * @mixin onSeriesMixin
  5555. */
  5556. var onSeriesMixin = {
  5557. /* eslint-disable valid-jsdoc */
  5558. /**
  5559. * Override getPlotBox. If the onSeries option is valid, return the plot box
  5560. * of the onSeries, otherwise proceed as usual.
  5561. *
  5562. * @private
  5563. * @function onSeriesMixin.getPlotBox
  5564. * @return {Highcharts.SeriesPlotBoxObject}
  5565. */
  5566. getPlotBox: function () {
  5567. return H.Series.prototype.getPlotBox.call((this.options.onSeries &&
  5568. this.chart.get(this.options.onSeries)) || this);
  5569. },
  5570. /**
  5571. * Extend the translate method by placing the point on the related series
  5572. *
  5573. * @private
  5574. * @function onSeriesMixin.translate
  5575. * @return {void}
  5576. */
  5577. translate: function () {
  5578. seriesTypes.column.prototype.translate.apply(this);
  5579. var series = this, options = series.options, chart = series.chart, points = series.points, cursor = points.length - 1, point, lastPoint, optionsOnSeries = options.onSeries, onSeries = (optionsOnSeries &&
  5580. chart.get(optionsOnSeries)), onKey = options.onKey || 'y', step = onSeries && onSeries.options.step, onData = (onSeries && onSeries.points), i = onData && onData.length, inverted = chart.inverted, xAxis = series.xAxis, yAxis = series.yAxis, xOffset = 0, leftPoint, lastX, rightPoint, currentDataGrouping, distanceRatio;
  5581. // relate to a master series
  5582. if (onSeries && onSeries.visible && i) {
  5583. xOffset = (onSeries.pointXOffset || 0) + (onSeries.barW || 0) / 2;
  5584. currentDataGrouping = onSeries.currentDataGrouping;
  5585. lastX = (onData[i - 1].x +
  5586. (currentDataGrouping ? currentDataGrouping.totalRange : 0)); // #2374
  5587. // sort the data points
  5588. stableSort(points, function (a, b) {
  5589. return (a.x - b.x);
  5590. });
  5591. onKey = 'plot' + onKey[0].toUpperCase() + onKey.substr(1);
  5592. while (i-- && points[cursor]) {
  5593. leftPoint = onData[i];
  5594. point = points[cursor];
  5595. point.y = leftPoint.y;
  5596. if (leftPoint.x <= point.x &&
  5597. typeof leftPoint[onKey] !== 'undefined') {
  5598. if (point.x <= lastX) { // #803
  5599. point.plotY = leftPoint[onKey];
  5600. // interpolate between points, #666
  5601. if (leftPoint.x < point.x &&
  5602. !step) {
  5603. rightPoint = onData[i + 1];
  5604. if (rightPoint &&
  5605. typeof rightPoint[onKey] !== 'undefined') {
  5606. // the distance ratio, between 0 and 1
  5607. distanceRatio =
  5608. (point.x - leftPoint.x) /
  5609. (rightPoint.x - leftPoint.x);
  5610. point.plotY +=
  5611. distanceRatio *
  5612. // the plotY distance
  5613. (rightPoint[onKey] - leftPoint[onKey]);
  5614. point.y +=
  5615. distanceRatio *
  5616. (rightPoint.y - leftPoint.y);
  5617. }
  5618. }
  5619. }
  5620. cursor--;
  5621. i++; // check again for points in the same x position
  5622. if (cursor < 0) {
  5623. break;
  5624. }
  5625. }
  5626. }
  5627. }
  5628. // Add plotY position and handle stacking
  5629. points.forEach(function (point, i) {
  5630. var stackIndex;
  5631. point.plotX += xOffset; // #2049
  5632. // Undefined plotY means the point is either on axis, outside series
  5633. // range or hidden series. If the series is outside the range of the
  5634. // x axis it should fall through with an undefined plotY, but then
  5635. // we must remove the shapeArgs (#847). For inverted charts, we need
  5636. // to calculate position anyway, because series.invertGroups is not
  5637. // defined
  5638. if (typeof point.plotY === 'undefined' || inverted) {
  5639. if (point.plotX >= 0 &&
  5640. point.plotX <= xAxis.len) {
  5641. // We're inside xAxis range
  5642. if (inverted) {
  5643. point.plotY = xAxis.translate(point.x, 0, 1, 0, 1);
  5644. point.plotX = defined(point.y) ?
  5645. yAxis.translate(point.y, 0, 0, 0, 1) :
  5646. 0;
  5647. }
  5648. else {
  5649. point.plotY = (xAxis.opposite ? 0 : series.yAxis.len) +
  5650. xAxis.offset; // For the windbarb demo
  5651. }
  5652. }
  5653. else {
  5654. point.shapeArgs = {}; // 847
  5655. }
  5656. }
  5657. // if multiple flags appear at the same x, order them into a stack
  5658. lastPoint = points[i - 1];
  5659. if (lastPoint && lastPoint.plotX === point.plotX) {
  5660. if (typeof lastPoint.stackIndex === 'undefined') {
  5661. lastPoint.stackIndex = 0;
  5662. }
  5663. stackIndex = lastPoint.stackIndex + 1;
  5664. }
  5665. point.stackIndex = stackIndex; // #3639
  5666. });
  5667. this.onSeries = onSeries;
  5668. }
  5669. /* eslint-enable valid-jsdoc */
  5670. };
  5671. return onSeriesMixin;
  5672. });
  5673. _registerModule(_modules, 'parts/FlagsSeries.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js'], _modules['mixins/on-series.js']], function (H, U, onSeriesMixin) {
  5674. /* *
  5675. *
  5676. * (c) 2010-2019 Torstein Honsi
  5677. *
  5678. * License: www.highcharts.com/license
  5679. *
  5680. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  5681. *
  5682. * */
  5683. /**
  5684. * @typedef {"circlepin"|"flag"|"squarepin"} Highcharts.FlagsShapeValue
  5685. */
  5686. var defined = U.defined, isNumber = U.isNumber, objectEach = U.objectEach, wrap = U.wrap;
  5687. var addEvent = H.addEvent, merge = H.merge, noop = H.noop, Renderer = H.Renderer, Series = H.Series, seriesType = H.seriesType, SVGRenderer = H.SVGRenderer, TrackerMixin = H.TrackerMixin, VMLRenderer = H.VMLRenderer, symbols = SVGRenderer.prototype.symbols;
  5688. /**
  5689. * The Flags series.
  5690. *
  5691. * @private
  5692. * @class
  5693. * @name Highcharts.seriesTypes.flags
  5694. *
  5695. * @augments Highcharts.Series
  5696. */
  5697. seriesType('flags', 'column'
  5698. /**
  5699. * Flags are used to mark events in stock charts. They can be added on the
  5700. * timeline, or attached to a specific series.
  5701. *
  5702. * @sample stock/demo/flags-general/
  5703. * Flags on a line series
  5704. *
  5705. * @extends plotOptions.column
  5706. * @excluding animation, borderColor, borderRadius, borderWidth,
  5707. * colorByPoint, dataGrouping, pointPadding, pointWidth,
  5708. * turboThreshold
  5709. * @product highstock
  5710. * @optionparent plotOptions.flags
  5711. */
  5712. , {
  5713. /**
  5714. * In case the flag is placed on a series, on what point key to place
  5715. * it. Line and columns have one key, `y`. In range or OHLC-type series,
  5716. * however, the flag can optionally be placed on the `open`, `high`,
  5717. * `low` or `close` key.
  5718. *
  5719. * @sample {highstock} stock/plotoptions/flags-onkey/
  5720. * Range series, flag on high
  5721. *
  5722. * @type {string}
  5723. * @default y
  5724. * @since 4.2.2
  5725. * @product highstock
  5726. * @validvalue ["y", "open", "high", "low", "close"]
  5727. * @apioption plotOptions.flags.onKey
  5728. */
  5729. /**
  5730. * The id of the series that the flags should be drawn on. If no id
  5731. * is given, the flags are drawn on the x axis.
  5732. *
  5733. * @sample {highstock} stock/plotoptions/flags/
  5734. * Flags on series and on x axis
  5735. *
  5736. * @type {string}
  5737. * @product highstock
  5738. * @apioption plotOptions.flags.onSeries
  5739. */
  5740. pointRange: 0,
  5741. /**
  5742. * Whether the flags are allowed to overlap sideways. If `false`, the
  5743. * flags are moved sideways using an algorithm that seeks to place every
  5744. * flag as close as possible to its original position.
  5745. *
  5746. * @sample {highstock} stock/plotoptions/flags-allowoverlapx
  5747. * Allow sideways overlap
  5748. *
  5749. * @since 6.0.4
  5750. */
  5751. allowOverlapX: false,
  5752. /**
  5753. * The shape of the marker. Can be one of "flag", "circlepin",
  5754. * "squarepin", or an image of the format `url(/path-to-image.jpg)`.
  5755. * Individual shapes can also be set for each point.
  5756. *
  5757. * @sample {highstock} stock/plotoptions/flags/
  5758. * Different shapes
  5759. *
  5760. * @type {Highcharts.FlagsShapeValue}
  5761. * @product highstock
  5762. */
  5763. shape: 'flag',
  5764. /**
  5765. * When multiple flags in the same series fall on the same value, this
  5766. * number determines the vertical offset between them.
  5767. *
  5768. * @sample {highstock} stock/plotoptions/flags-stackdistance/
  5769. * A greater stack distance
  5770. *
  5771. * @product highstock
  5772. */
  5773. stackDistance: 12,
  5774. /**
  5775. * Text alignment for the text inside the flag.
  5776. *
  5777. * @since 5.0.0
  5778. * @product highstock
  5779. * @validvalue ["left", "center", "right"]
  5780. */
  5781. textAlign: 'center',
  5782. /**
  5783. * Specific tooltip options for flag series. Flag series tooltips are
  5784. * different from most other types in that a flag doesn't have a data
  5785. * value, so the tooltip rather displays the `text` option for each
  5786. * point.
  5787. *
  5788. * @extends plotOptions.series.tooltip
  5789. * @excluding changeDecimals, valueDecimals, valuePrefix, valueSuffix
  5790. * @product highstock
  5791. */
  5792. tooltip: {
  5793. pointFormat: '{point.text}<br/>'
  5794. },
  5795. threshold: null,
  5796. /**
  5797. * The text to display on each flag. This can be defined on series
  5798. * level, or individually for each point. Defaults to `"A"`.
  5799. *
  5800. * @type {string}
  5801. * @default A
  5802. * @product highstock
  5803. * @apioption plotOptions.flags.title
  5804. */
  5805. /**
  5806. * The y position of the top left corner of the flag relative to either
  5807. * the series (if onSeries is defined), or the x axis. Defaults to
  5808. * `-30`.
  5809. *
  5810. * @product highstock
  5811. */
  5812. y: -30,
  5813. /**
  5814. * Whether to use HTML to render the flag texts. Using HTML allows for
  5815. * advanced formatting, images and reliable bi-directional text
  5816. * rendering. Note that exported images won't respect the HTML, and that
  5817. * HTML won't respect Z-index settings.
  5818. *
  5819. * @type {boolean}
  5820. * @default false
  5821. * @since 1.3
  5822. * @product highstock
  5823. * @apioption plotOptions.flags.useHTML
  5824. */
  5825. /**
  5826. * Fixed width of the flag's shape. By default, width is autocalculated
  5827. * according to the flag's title.
  5828. *
  5829. * @sample {highstock} stock/demo/flags-shapes/
  5830. * Flags with fixed width
  5831. *
  5832. * @type {number}
  5833. * @product highstock
  5834. * @apioption plotOptions.flags.width
  5835. */
  5836. /**
  5837. * Fixed height of the flag's shape. By default, height is
  5838. * autocalculated according to the flag's title.
  5839. *
  5840. * @type {number}
  5841. * @product highstock
  5842. * @apioption plotOptions.flags.height
  5843. */
  5844. /**
  5845. * The fill color for the flags.
  5846. *
  5847. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5848. * @product highstock
  5849. */
  5850. fillColor: '#ffffff',
  5851. /**
  5852. * The color of the line/border of the flag.
  5853. *
  5854. * In styled mode, the stroke is set in the
  5855. * `.highcharts-flag-series.highcharts-point` rule.
  5856. *
  5857. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5858. * @default #000000
  5859. * @product highstock
  5860. * @apioption plotOptions.flags.lineColor
  5861. */
  5862. /**
  5863. * The pixel width of the flag's line/border.
  5864. *
  5865. * @product highstock
  5866. */
  5867. lineWidth: 1,
  5868. states: {
  5869. /**
  5870. * @extends plotOptions.column.states.hover
  5871. * @product highstock
  5872. */
  5873. hover: {
  5874. /**
  5875. * The color of the line/border of the flag.
  5876. *
  5877. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5878. * @product highstock
  5879. */
  5880. lineColor: '#000000',
  5881. /**
  5882. * The fill or background color of the flag.
  5883. *
  5884. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  5885. * @product highstock
  5886. */
  5887. fillColor: '#ccd6eb'
  5888. }
  5889. },
  5890. /**
  5891. * The text styles of the flag.
  5892. *
  5893. * In styled mode, the styles are set in the
  5894. * `.highcharts-flag-series .highcharts-point` rule.
  5895. *
  5896. * @type {Highcharts.CSSObject}
  5897. * @default {"fontSize": "11px", "fontWeight": "bold"}
  5898. * @product highstock
  5899. */
  5900. style: {
  5901. /** @ignore-option */
  5902. fontSize: '11px',
  5903. /** @ignore-option */
  5904. fontWeight: 'bold'
  5905. }
  5906. },
  5907. /**
  5908. * @lends seriesTypes.flags.prototype
  5909. */
  5910. {
  5911. sorted: false,
  5912. noSharedTooltip: true,
  5913. allowDG: false,
  5914. takeOrdinalPosition: false,
  5915. trackerGroups: ['markerGroup'],
  5916. forceCrop: true,
  5917. /* eslint-disable no-invalid-this, valid-jsdoc */
  5918. /**
  5919. * Inherit the initialization from base Series.
  5920. *
  5921. * @private
  5922. * @borrows Highcharts.Series#init as Highcharts.seriesTypes.flags#init
  5923. */
  5924. init: Series.prototype.init,
  5925. /**
  5926. * Get presentational attributes
  5927. *
  5928. * @private
  5929. * @function Highcharts.seriesTypes.flags#pointAttribs
  5930. *
  5931. * @param {Highcharts.Point} point
  5932. *
  5933. * @param {string} [state]
  5934. *
  5935. * @return {Highcharts.SVGAttributes}
  5936. */
  5937. pointAttribs: function (point, state) {
  5938. var options = this.options, color = (point && point.color) || this.color, lineColor = options.lineColor, lineWidth = (point && point.lineWidth), fill = (point && point.fillColor) || options.fillColor;
  5939. if (state) {
  5940. fill = options.states[state].fillColor;
  5941. lineColor = options.states[state].lineColor;
  5942. lineWidth = options.states[state].lineWidth;
  5943. }
  5944. return {
  5945. fill: fill || color,
  5946. stroke: lineColor || color,
  5947. 'stroke-width': lineWidth || options.lineWidth || 0
  5948. };
  5949. },
  5950. translate: onSeriesMixin.translate,
  5951. getPlotBox: onSeriesMixin.getPlotBox,
  5952. /**
  5953. * Draw the markers.
  5954. *
  5955. * @private
  5956. * @function Highcharts.seriesTypes.flags#drawPoints
  5957. * @return {void}
  5958. */
  5959. drawPoints: function () {
  5960. var series = this, points = series.points, chart = series.chart, renderer = chart.renderer, plotX, plotY, inverted = chart.inverted, options = series.options, optionsY = options.y, shape, i, point, graphic, stackIndex, anchorY, attribs, outsideRight, yAxis = series.yAxis, boxesMap = {}, boxes = [], centered;
  5961. i = points.length;
  5962. while (i--) {
  5963. point = points[i];
  5964. outsideRight =
  5965. (inverted ? point.plotY : point.plotX) >
  5966. series.xAxis.len;
  5967. plotX = point.plotX;
  5968. stackIndex = point.stackIndex;
  5969. shape = point.options.shape || options.shape;
  5970. plotY = point.plotY;
  5971. if (typeof plotY !== 'undefined') {
  5972. plotY = point.plotY + optionsY -
  5973. (typeof stackIndex !== 'undefined' &&
  5974. (stackIndex * options.stackDistance));
  5975. }
  5976. // skip connectors for higher level stacked points
  5977. point.anchorX = stackIndex ? void 0 : point.plotX;
  5978. anchorY = stackIndex ? void 0 : point.plotY;
  5979. centered = shape !== 'flag';
  5980. graphic = point.graphic;
  5981. // Only draw the point if y is defined and the flag is within
  5982. // the visible area
  5983. if (typeof plotY !== 'undefined' &&
  5984. plotX >= 0 &&
  5985. !outsideRight) {
  5986. // Create the flag
  5987. if (!graphic) {
  5988. graphic = point.graphic = renderer.label('', null, null, shape, null, null, options.useHTML);
  5989. if (!chart.styledMode) {
  5990. graphic
  5991. .attr(series.pointAttribs(point))
  5992. .css(merge(options.style, point.style));
  5993. }
  5994. graphic.attr({
  5995. align: centered ? 'center' : 'left',
  5996. width: options.width,
  5997. height: options.height,
  5998. 'text-align': options.textAlign
  5999. })
  6000. .addClass('highcharts-point')
  6001. .add(series.markerGroup);
  6002. // Add reference to the point for tracker (#6303)
  6003. if (point.graphic.div) {
  6004. point.graphic.div.point = point;
  6005. }
  6006. if (!chart.styledMode) {
  6007. graphic.shadow(options.shadow);
  6008. }
  6009. graphic.isNew = true;
  6010. }
  6011. if (plotX > 0) { // #3119
  6012. plotX -= graphic.strokeWidth() % 2; // #4285
  6013. }
  6014. // Plant the flag
  6015. attribs = {
  6016. y: plotY,
  6017. anchorY: anchorY
  6018. };
  6019. if (options.allowOverlapX) {
  6020. attribs.x = plotX;
  6021. attribs.anchorX = point.anchorX;
  6022. }
  6023. graphic.attr({
  6024. text: point.options.title || options.title || 'A'
  6025. })[graphic.isNew ? 'attr' : 'animate'](attribs);
  6026. // Rig for the distribute function
  6027. if (!options.allowOverlapX) {
  6028. if (!boxesMap[point.plotX]) {
  6029. boxesMap[point.plotX] = {
  6030. align: centered ? 0.5 : 0,
  6031. size: graphic.width,
  6032. target: plotX,
  6033. anchorX: plotX
  6034. };
  6035. }
  6036. else {
  6037. boxesMap[point.plotX].size = Math.max(boxesMap[point.plotX].size, graphic.width);
  6038. }
  6039. }
  6040. // Set the tooltip anchor position
  6041. point.tooltipPos = [
  6042. plotX,
  6043. plotY + yAxis.pos - chart.plotTop
  6044. ]; // #6327
  6045. }
  6046. else if (graphic) {
  6047. point.graphic = graphic.destroy();
  6048. }
  6049. }
  6050. // Handle X-dimension overlapping
  6051. if (!options.allowOverlapX) {
  6052. objectEach(boxesMap, function (box) {
  6053. box.plotX = box.anchorX;
  6054. boxes.push(box);
  6055. });
  6056. H.distribute(boxes, inverted ? yAxis.len : this.xAxis.len, 100);
  6057. points.forEach(function (point) {
  6058. var box = point.graphic && boxesMap[point.plotX];
  6059. if (box) {
  6060. point.graphic[point.graphic.isNew ? 'attr' : 'animate']({
  6061. x: box.pos + box.align * box.size,
  6062. anchorX: point.anchorX
  6063. });
  6064. // Hide flag when its box position is not specified
  6065. // (#8573, #9299)
  6066. if (!defined(box.pos)) {
  6067. point.graphic.attr({
  6068. x: -9999,
  6069. anchorX: -9999
  6070. });
  6071. point.graphic.isNew = true;
  6072. }
  6073. else {
  6074. point.graphic.isNew = false;
  6075. }
  6076. }
  6077. });
  6078. }
  6079. // Can be a mix of SVG and HTML and we need events for both (#6303)
  6080. if (options.useHTML) {
  6081. wrap(series.markerGroup, 'on', function (proceed) {
  6082. return H.SVGElement.prototype.on.apply(
  6083. // for HTML
  6084. proceed.apply(this, [].slice.call(arguments, 1)),
  6085. // and for SVG
  6086. [].slice.call(arguments, 1));
  6087. });
  6088. }
  6089. },
  6090. /**
  6091. * Extend the column trackers with listeners to expand and contract
  6092. * stacks.
  6093. *
  6094. * @private
  6095. * @function Highcharts.seriesTypes.flags#drawTracker
  6096. * @return {void}
  6097. */
  6098. drawTracker: function () {
  6099. var series = this, points = series.points;
  6100. TrackerMixin.drawTrackerPoint.apply(this);
  6101. /* *
  6102. * Bring each stacked flag up on mouse over, this allows readability
  6103. * of vertically stacked elements as well as tight points on the x
  6104. * axis. #1924.
  6105. */
  6106. points.forEach(function (point) {
  6107. var graphic = point.graphic;
  6108. if (graphic) {
  6109. addEvent(graphic.element, 'mouseover', function () {
  6110. // Raise this point
  6111. if (point.stackIndex > 0 &&
  6112. !point.raised) {
  6113. point._y = graphic.y;
  6114. graphic.attr({
  6115. y: point._y - 8
  6116. });
  6117. point.raised = true;
  6118. }
  6119. // Revert other raised points
  6120. points.forEach(function (otherPoint) {
  6121. if (otherPoint !== point &&
  6122. otherPoint.raised &&
  6123. otherPoint.graphic) {
  6124. otherPoint.graphic.attr({
  6125. y: otherPoint._y
  6126. });
  6127. otherPoint.raised = false;
  6128. }
  6129. });
  6130. });
  6131. }
  6132. });
  6133. },
  6134. /**
  6135. * Disable animation, but keep clipping (#8546).
  6136. *
  6137. * @private
  6138. * @function Highcharts.seriesTypes.flags#animate
  6139. * @param {boolean} [init]
  6140. * @return {void}
  6141. */
  6142. animate: function (init) {
  6143. if (init) {
  6144. this.setClip();
  6145. }
  6146. else {
  6147. this.animate = null;
  6148. }
  6149. },
  6150. /**
  6151. * @private
  6152. * @function Highcharts.seriesTypes.flags#setClip
  6153. * @return {void}
  6154. */
  6155. setClip: function () {
  6156. Series.prototype.setClip.apply(this, arguments);
  6157. if (this.options.clip !== false && this.sharedClipKey) {
  6158. this.markerGroup
  6159. .clip(this.chart[this.sharedClipKey]);
  6160. }
  6161. },
  6162. /**
  6163. * @private
  6164. * @function Highcharts.seriesTypes.flags#buildKDTree
  6165. */
  6166. buildKDTree: noop,
  6167. /**
  6168. * Don't invert the flag marker group (#4960).
  6169. *
  6170. * @private
  6171. * @function Highcharts.seriesTypes.flags#invertGroups
  6172. */
  6173. invertGroups: noop
  6174. /* eslint-enable no-invalid-this, valid-jsdoc */
  6175. },
  6176. /**
  6177. * @lends Highcharts.seriesTypes.flag.prototype.pointClass.prototype
  6178. */
  6179. {
  6180. isValid: function () {
  6181. // #9233 - Prevent from treating flags as null points (even if
  6182. // they have no y values defined).
  6183. return isNumber(this.y) || typeof this.y === 'undefined';
  6184. }
  6185. });
  6186. // create the flag icon with anchor
  6187. symbols.flag = function (x, y, w, h, options) {
  6188. var anchorX = (options && options.anchorX) || x, anchorY = (options && options.anchorY) || y;
  6189. return symbols.circle(anchorX - 1, anchorY - 1, 2, 2).concat([
  6190. 'M', anchorX, anchorY,
  6191. 'L', x, y + h,
  6192. x, y,
  6193. x + w, y,
  6194. x + w, y + h,
  6195. x, y + h,
  6196. 'Z'
  6197. ]);
  6198. };
  6199. /**
  6200. * Create the circlepin and squarepin icons with anchor.
  6201. * @private
  6202. * @param {string} shape - circle or square
  6203. * @return {void}
  6204. */
  6205. function createPinSymbol(shape) {
  6206. symbols[shape + 'pin'] = function (x, y, w, h, options) {
  6207. var anchorX = options && options.anchorX, anchorY = options && options.anchorY, path, labelTopOrBottomY;
  6208. // For single-letter flags, make sure circular flags are not taller
  6209. // than their width
  6210. if (shape === 'circle' && h > w) {
  6211. x -= Math.round((h - w) / 2);
  6212. w = h;
  6213. }
  6214. path = symbols[shape](x, y, w, h);
  6215. if (anchorX && anchorY) {
  6216. /**
  6217. * If the label is below the anchor, draw the connecting line
  6218. * from the top edge of the label
  6219. * otherwise start drawing from the bottom edge
  6220. */
  6221. labelTopOrBottomY = (y > anchorY) ? y : y + h;
  6222. path.push('M', shape === 'circle' ?
  6223. x + w / 2 :
  6224. path[1] + path[4] / 2, labelTopOrBottomY, 'L', anchorX, anchorY);
  6225. path = path.concat(symbols.circle(anchorX - 1, anchorY - 1, 2, 2));
  6226. }
  6227. return path;
  6228. };
  6229. }
  6230. createPinSymbol('circle');
  6231. createPinSymbol('square');
  6232. /**
  6233. * The symbol callbacks are generated on the SVGRenderer object in all browsers.
  6234. * Even VML browsers need this in order to generate shapes in export. Now share
  6235. * them with the VMLRenderer.
  6236. */
  6237. if (Renderer === VMLRenderer) {
  6238. ['circlepin', 'flag', 'squarepin'].forEach(function (shape) {
  6239. VMLRenderer.prototype.symbols[shape] = symbols[shape];
  6240. });
  6241. }
  6242. /**
  6243. * A `flags` series. If the [type](#series.flags.type) option is not
  6244. * specified, it is inherited from [chart.type](#chart.type).
  6245. *
  6246. * @extends series,plotOptions.flags
  6247. * @excluding dataParser, dataURL
  6248. * @product highstock
  6249. * @apioption series.flags
  6250. */
  6251. /**
  6252. * An array of data points for the series. For the `flags` series type,
  6253. * points can be given in the following ways:
  6254. *
  6255. * 1. An array of objects with named values. The following snippet shows only a
  6256. * few settings, see the complete options set below. If the total number of
  6257. * data points exceeds the series'
  6258. * [turboThreshold](#series.flags.turboThreshold), this option is not
  6259. * available.
  6260. * ```js
  6261. * data: [{
  6262. * x: 1,
  6263. * title: "A",
  6264. * text: "First event"
  6265. * }, {
  6266. * x: 1,
  6267. * title: "B",
  6268. * text: "Second event"
  6269. * }]
  6270. * ```
  6271. *
  6272. * @type {Array<*>}
  6273. * @extends series.line.data
  6274. * @excluding dataLabels, marker, name, y
  6275. * @product highstock
  6276. * @apioption series.flags.data
  6277. */
  6278. /**
  6279. * The fill color of an individual flag. By default it inherits from
  6280. * the series color.
  6281. *
  6282. * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject}
  6283. * @product highstock
  6284. * @apioption series.flags.data.fillColor
  6285. */
  6286. /**
  6287. * The longer text to be shown in the flag's tooltip.
  6288. *
  6289. * @type {string}
  6290. * @product highstock
  6291. * @apioption series.flags.data.text
  6292. */
  6293. /**
  6294. * The short text to be shown on the flag.
  6295. *
  6296. * @type {string}
  6297. * @product highstock
  6298. * @apioption series.flags.data.title
  6299. */
  6300. ''; // adds doclets above to transpiled file
  6301. });
  6302. _registerModule(_modules, 'parts/RangeSelector.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  6303. /* *
  6304. *
  6305. * (c) 2010-2019 Torstein Honsi
  6306. *
  6307. * License: www.highcharts.com/license
  6308. *
  6309. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  6310. *
  6311. * */
  6312. /**
  6313. * Define the time span for the button
  6314. *
  6315. * @typedef {"all"|"day"|"hour"|"millisecond"|"minute"|"month"|"second"|"week"|"year"|"ytd"} Highcharts.RangeSelectorButtonTypeValue
  6316. */
  6317. /**
  6318. * Callback function to react on button clicks.
  6319. *
  6320. * @callback Highcharts.RangeSelectorClickCallbackFunction
  6321. *
  6322. * @param {global.Event} e
  6323. * Event arguments.
  6324. *
  6325. * @param {boolean|undefined}
  6326. * Return false to cancel the default button event.
  6327. */
  6328. /**
  6329. * Callback function to parse values entered in the input boxes and return a
  6330. * valid JavaScript time as milliseconds since 1970.
  6331. *
  6332. * @callback Highcharts.RangeSelectorParseCallbackFunction
  6333. *
  6334. * @param {string} value
  6335. * Input value to parse.
  6336. *
  6337. * @return {number}
  6338. * Parsed JavaScript time value.
  6339. */
  6340. var defined = U.defined, destroyObjectProperties = U.destroyObjectProperties, discardElement = U.discardElement, extend = U.extend, isNumber = U.isNumber, objectEach = U.objectEach, pick = U.pick, pInt = U.pInt, splat = U.splat;
  6341. var addEvent = H.addEvent, Axis = H.Axis, Chart = H.Chart, css = H.css, createElement = H.createElement, defaultOptions = H.defaultOptions, fireEvent = H.fireEvent, merge = H.merge;
  6342. /* ************************************************************************** *
  6343. * Start Range Selector code *
  6344. * ************************************************************************** */
  6345. extend(defaultOptions, {
  6346. /**
  6347. * The range selector is a tool for selecting ranges to display within
  6348. * the chart. It provides buttons to select preconfigured ranges in
  6349. * the chart, like 1 day, 1 week, 1 month etc. It also provides input
  6350. * boxes where min and max dates can be manually input.
  6351. *
  6352. * @product highstock gantt
  6353. * @optionparent rangeSelector
  6354. */
  6355. rangeSelector: {
  6356. /**
  6357. * Whether to enable all buttons from the start. By default buttons are
  6358. * only enabled if the corresponding time range exists on the X axis,
  6359. * but enabling all buttons allows for dynamically loading different
  6360. * time ranges.
  6361. *
  6362. * @sample {highstock} stock/rangeselector/allbuttonsenabled-true/
  6363. * All buttons enabled
  6364. *
  6365. * @type {boolean}
  6366. * @default false
  6367. * @since 2.0.3
  6368. * @apioption rangeSelector.allButtonsEnabled
  6369. */
  6370. /**
  6371. * An array of configuration objects for the buttons.
  6372. *
  6373. * Defaults to:
  6374. * ```js
  6375. * buttons: [{
  6376. * type: 'month',
  6377. * count: 1,
  6378. * text: '1m'
  6379. * }, {
  6380. * type: 'month',
  6381. * count: 3,
  6382. * text: '3m'
  6383. * }, {
  6384. * type: 'month',
  6385. * count: 6,
  6386. * text: '6m'
  6387. * }, {
  6388. * type: 'ytd',
  6389. * text: 'YTD'
  6390. * }, {
  6391. * type: 'year',
  6392. * count: 1,
  6393. * text: '1y'
  6394. * }, {
  6395. * type: 'all',
  6396. * text: 'All'
  6397. * }]
  6398. * ```
  6399. *
  6400. * @sample {highstock} stock/rangeselector/datagrouping/
  6401. * Data grouping by buttons
  6402. *
  6403. * @type {Array<*>}
  6404. * @apioption rangeSelector.buttons
  6405. */
  6406. /**
  6407. * How many units of the defined type the button should span. If `type`
  6408. * is "month" and `count` is 3, the button spans three months.
  6409. *
  6410. * @type {number}
  6411. * @default 1
  6412. * @apioption rangeSelector.buttons.count
  6413. */
  6414. /**
  6415. * Fires when clicking on the rangeSelector button. One parameter,
  6416. * event, is passed to the function, containing common event
  6417. * information.
  6418. *
  6419. * ```js
  6420. * click: function(e) {
  6421. * console.log(this);
  6422. * }
  6423. * ```
  6424. *
  6425. * Return false to stop default button's click action.
  6426. *
  6427. * @sample {highstock} stock/rangeselector/button-click/
  6428. * Click event on the button
  6429. *
  6430. * @type {Highcharts.RangeSelectorClickCallbackFunction}
  6431. * @apioption rangeSelector.buttons.events.click
  6432. */
  6433. /**
  6434. * Additional range (in milliseconds) added to the end of the calculated
  6435. * time span.
  6436. *
  6437. * @sample {highstock} stock/rangeselector/min-max-offsets/
  6438. * Button offsets
  6439. *
  6440. * @type {number}
  6441. * @default 0
  6442. * @since 6.0.0
  6443. * @apioption rangeSelector.buttons.offsetMax
  6444. */
  6445. /**
  6446. * Additional range (in milliseconds) added to the start of the
  6447. * calculated time span.
  6448. *
  6449. * @sample {highstock} stock/rangeselector/min-max-offsets/
  6450. * Button offsets
  6451. *
  6452. * @type {number}
  6453. * @default 0
  6454. * @since 6.0.0
  6455. * @apioption rangeSelector.buttons.offsetMin
  6456. */
  6457. /**
  6458. * When buttons apply dataGrouping on a series, by default zooming
  6459. * in/out will deselect buttons and unset dataGrouping. Enable this
  6460. * option to keep buttons selected when extremes change.
  6461. *
  6462. * @sample {highstock} stock/rangeselector/preserve-datagrouping/
  6463. * Different preserveDataGrouping settings
  6464. *
  6465. * @type {boolean}
  6466. * @default false
  6467. * @since 6.1.2
  6468. * @apioption rangeSelector.buttons.preserveDataGrouping
  6469. */
  6470. /**
  6471. * A custom data grouping object for each button.
  6472. *
  6473. * @see [series.dataGrouping](#plotOptions.series.dataGrouping)
  6474. *
  6475. * @sample {highstock} stock/rangeselector/datagrouping/
  6476. * Data grouping by range selector buttons
  6477. *
  6478. * @type {*}
  6479. * @extends plotOptions.series.dataGrouping
  6480. * @apioption rangeSelector.buttons.dataGrouping
  6481. */
  6482. /**
  6483. * The text for the button itself.
  6484. *
  6485. * @type {string}
  6486. * @apioption rangeSelector.buttons.text
  6487. */
  6488. /**
  6489. * Defined the time span for the button. Can be one of `millisecond`,
  6490. * `second`, `minute`, `hour`, `day`, `week`, `month`, `year`, `ytd`,
  6491. * and `all`.
  6492. *
  6493. * @type {Highcharts.RangeSelectorButtonTypeValue}
  6494. * @apioption rangeSelector.buttons.type
  6495. */
  6496. /**
  6497. * The space in pixels between the buttons in the range selector.
  6498. *
  6499. * @type {number}
  6500. * @default 0
  6501. * @apioption rangeSelector.buttonSpacing
  6502. */
  6503. /**
  6504. * Enable or disable the range selector.
  6505. *
  6506. * @sample {highstock} stock/rangeselector/enabled/
  6507. * Disable the range selector
  6508. *
  6509. * @type {boolean}
  6510. * @default true
  6511. * @apioption rangeSelector.enabled
  6512. */
  6513. /**
  6514. * The vertical alignment of the rangeselector box. Allowed properties
  6515. * are `top`, `middle`, `bottom`.
  6516. *
  6517. * @sample {highstock} stock/rangeselector/vertical-align-middle/
  6518. * Middle
  6519. * @sample {highstock} stock/rangeselector/vertical-align-bottom/
  6520. * Bottom
  6521. *
  6522. * @type {Highcharts.VerticalAlignValue}
  6523. * @since 6.0.0
  6524. */
  6525. verticalAlign: 'top',
  6526. /**
  6527. * A collection of attributes for the buttons. The object takes SVG
  6528. * attributes like `fill`, `stroke`, `stroke-width`, as well as `style`,
  6529. * a collection of CSS properties for the text.
  6530. *
  6531. * The object can also be extended with states, so you can set
  6532. * presentational options for `hover`, `select` or `disabled` button
  6533. * states.
  6534. *
  6535. * CSS styles for the text label.
  6536. *
  6537. * In styled mode, the buttons are styled by the
  6538. * `.highcharts-range-selector-buttons .highcharts-button` rule with its
  6539. * different states.
  6540. *
  6541. * @sample {highstock} stock/rangeselector/styling/
  6542. * Styling the buttons and inputs
  6543. *
  6544. * @type {Highcharts.SVGAttributes}
  6545. */
  6546. buttonTheme: {
  6547. /** @ignore */
  6548. width: 28,
  6549. /** @ignore */
  6550. height: 18,
  6551. /** @ignore */
  6552. padding: 2,
  6553. /** @ignore */
  6554. zIndex: 7 // #484, #852
  6555. },
  6556. /**
  6557. * When the rangeselector is floating, the plot area does not reserve
  6558. * space for it. This opens for positioning anywhere on the chart.
  6559. *
  6560. * @sample {highstock} stock/rangeselector/floating/
  6561. * Placing the range selector between the plot area and the
  6562. * navigator
  6563. *
  6564. * @since 6.0.0
  6565. */
  6566. floating: false,
  6567. /**
  6568. * The x offset of the range selector relative to its horizontal
  6569. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  6570. *
  6571. * @since 6.0.0
  6572. */
  6573. x: 0,
  6574. /**
  6575. * The y offset of the range selector relative to its horizontal
  6576. * alignment within `chart.spacingLeft` and `chart.spacingRight`.
  6577. *
  6578. * @since 6.0.0
  6579. */
  6580. y: 0,
  6581. /**
  6582. * Deprecated. The height of the range selector. Currently it is
  6583. * calculated dynamically.
  6584. *
  6585. * @deprecated
  6586. * @type {number|undefined}
  6587. * @since 2.1.9
  6588. */
  6589. height: void 0,
  6590. /**
  6591. * The border color of the date input boxes.
  6592. *
  6593. * @sample {highstock} stock/rangeselector/styling/
  6594. * Styling the buttons and inputs
  6595. *
  6596. * @type {Highcharts.ColorString}
  6597. * @default #cccccc
  6598. * @since 1.3.7
  6599. * @apioption rangeSelector.inputBoxBorderColor
  6600. */
  6601. /**
  6602. * The pixel height of the date input boxes.
  6603. *
  6604. * @sample {highstock} stock/rangeselector/styling/
  6605. * Styling the buttons and inputs
  6606. *
  6607. * @type {number}
  6608. * @default 17
  6609. * @since 1.3.7
  6610. * @apioption rangeSelector.inputBoxHeight
  6611. */
  6612. /**
  6613. * CSS for the container DIV holding the input boxes. Deprecated as
  6614. * of 1.2.5\. Use [inputPosition](#rangeSelector.inputPosition) instead.
  6615. *
  6616. * @sample {highstock} stock/rangeselector/styling/
  6617. * Styling the buttons and inputs
  6618. *
  6619. * @deprecated
  6620. * @type {Highcharts.CSSObject}
  6621. * @apioption rangeSelector.inputBoxStyle
  6622. */
  6623. /**
  6624. * The pixel width of the date input boxes.
  6625. *
  6626. * @sample {highstock} stock/rangeselector/styling/
  6627. * Styling the buttons and inputs
  6628. *
  6629. * @type {number}
  6630. * @default 90
  6631. * @since 1.3.7
  6632. * @apioption rangeSelector.inputBoxWidth
  6633. */
  6634. /**
  6635. * The date format in the input boxes when not selected for editing.
  6636. * Defaults to `%b %e, %Y`.
  6637. *
  6638. * @sample {highstock} stock/rangeselector/input-format/
  6639. * Milliseconds in the range selector
  6640. *
  6641. * @type {string}
  6642. * @default %b %e, %Y
  6643. * @apioption rangeSelector.inputDateFormat
  6644. */
  6645. /**
  6646. * A custom callback function to parse values entered in the input boxes
  6647. * and return a valid JavaScript time as milliseconds since 1970.
  6648. *
  6649. * @sample {highstock} stock/rangeselector/input-format/
  6650. * Milliseconds in the range selector
  6651. *
  6652. * @type {Highcharts.RangeSelectorParseCallbackFunction}
  6653. * @since 1.3.3
  6654. * @apioption rangeSelector.inputDateParser
  6655. */
  6656. /**
  6657. * The date format in the input boxes when they are selected for
  6658. * editing. This must be a format that is recognized by JavaScript
  6659. * Date.parse.
  6660. *
  6661. * @sample {highstock} stock/rangeselector/input-format/
  6662. * Milliseconds in the range selector
  6663. *
  6664. * @type {string}
  6665. * @default %Y-%m-%d
  6666. * @apioption rangeSelector.inputEditDateFormat
  6667. */
  6668. /**
  6669. * Enable or disable the date input boxes. Defaults to enabled when
  6670. * there is enough space, disabled if not (typically mobile).
  6671. *
  6672. * @sample {highstock} stock/rangeselector/input-datepicker/
  6673. * Extending the input with a jQuery UI datepicker
  6674. *
  6675. * @type {boolean}
  6676. * @default true
  6677. * @apioption rangeSelector.inputEnabled
  6678. */
  6679. /**
  6680. * Positioning for the input boxes. Allowed properties are `align`,
  6681. * `x` and `y`.
  6682. *
  6683. * @since 1.2.4
  6684. */
  6685. inputPosition: {
  6686. /**
  6687. * The alignment of the input box. Allowed properties are `left`,
  6688. * `center`, `right`.
  6689. *
  6690. * @sample {highstock} stock/rangeselector/input-button-position/
  6691. * Alignment
  6692. *
  6693. * @type {Highcharts.AlignValue}
  6694. * @since 6.0.0
  6695. */
  6696. align: 'right',
  6697. /**
  6698. * X offset of the input row.
  6699. */
  6700. x: 0,
  6701. /**
  6702. * Y offset of the input row.
  6703. */
  6704. y: 0
  6705. },
  6706. /**
  6707. * The index of the button to appear pre-selected.
  6708. *
  6709. * @type {number}
  6710. * @apioption rangeSelector.selected
  6711. */
  6712. /**
  6713. * Positioning for the button row.
  6714. *
  6715. * @since 1.2.4
  6716. */
  6717. buttonPosition: {
  6718. /**
  6719. * The alignment of the input box. Allowed properties are `left`,
  6720. * `center`, `right`.
  6721. *
  6722. * @sample {highstock} stock/rangeselector/input-button-position/
  6723. * Alignment
  6724. *
  6725. * @type {Highcharts.AlignValue}
  6726. * @since 6.0.0
  6727. */
  6728. align: 'left',
  6729. /**
  6730. * X offset of the button row.
  6731. */
  6732. x: 0,
  6733. /**
  6734. * Y offset of the button row.
  6735. */
  6736. y: 0
  6737. },
  6738. /**
  6739. * CSS for the HTML inputs in the range selector.
  6740. *
  6741. * In styled mode, the inputs are styled by the
  6742. * `.highcharts-range-input text` rule in SVG mode, and
  6743. * `input.highcharts-range-selector` when active.
  6744. *
  6745. * @sample {highstock} stock/rangeselector/styling/
  6746. * Styling the buttons and inputs
  6747. *
  6748. * @type {Highcharts.CSSObject}
  6749. * @apioption rangeSelector.inputStyle
  6750. */
  6751. /**
  6752. * CSS styles for the labels - the Zoom, From and To texts.
  6753. *
  6754. * In styled mode, the labels are styled by the
  6755. * `.highcharts-range-label` class.
  6756. *
  6757. * @sample {highstock} stock/rangeselector/styling/
  6758. * Styling the buttons and inputs
  6759. *
  6760. * @type {Highcharts.CSSObject}
  6761. */
  6762. labelStyle: {
  6763. /** @ignore */
  6764. color: '#666666'
  6765. }
  6766. }
  6767. });
  6768. defaultOptions.lang = merge(defaultOptions.lang,
  6769. /**
  6770. * Language object. The language object is global and it can't be set
  6771. * on each chart initialization. Instead, use `Highcharts.setOptions` to
  6772. * set it before any chart is initialized.
  6773. *
  6774. * ```js
  6775. * Highcharts.setOptions({
  6776. * lang: {
  6777. * months: [
  6778. * 'Janvier', 'Février', 'Mars', 'Avril',
  6779. * 'Mai', 'Juin', 'Juillet', 'Août',
  6780. * 'Septembre', 'Octobre', 'Novembre', 'Décembre'
  6781. * ],
  6782. * weekdays: [
  6783. * 'Dimanche', 'Lundi', 'Mardi', 'Mercredi',
  6784. * 'Jeudi', 'Vendredi', 'Samedi'
  6785. * ]
  6786. * }
  6787. * });
  6788. * ```
  6789. *
  6790. * @optionparent lang
  6791. */
  6792. {
  6793. /**
  6794. * The text for the label for the range selector buttons.
  6795. *
  6796. * @product highstock gantt
  6797. */
  6798. rangeSelectorZoom: 'Zoom',
  6799. /**
  6800. * The text for the label for the "from" input box in the range
  6801. * selector.
  6802. *
  6803. * @product highstock gantt
  6804. */
  6805. rangeSelectorFrom: 'From',
  6806. /**
  6807. * The text for the label for the "to" input box in the range selector.
  6808. *
  6809. * @product highstock gantt
  6810. */
  6811. rangeSelectorTo: 'To'
  6812. });
  6813. /* eslint-disable no-invalid-this, valid-jsdoc */
  6814. /**
  6815. * The range selector.
  6816. *
  6817. * @private
  6818. * @class
  6819. * @name Highcharts.RangeSelector
  6820. * @param {Highcharts.Chart} chart
  6821. */
  6822. function RangeSelector(chart) {
  6823. // Run RangeSelector
  6824. this.init(chart);
  6825. }
  6826. RangeSelector.prototype = {
  6827. /**
  6828. * The method to run when one of the buttons in the range selectors is
  6829. * clicked
  6830. *
  6831. * @private
  6832. * @function Highcharts.RangeSelector#clickButton
  6833. * @param {number} i
  6834. * The index of the button
  6835. * @param {boolean} [redraw]
  6836. * @return {void}
  6837. */
  6838. clickButton: function (i, redraw) {
  6839. var rangeSelector = this, chart = rangeSelector.chart, rangeOptions = rangeSelector.buttonOptions[i], baseAxis = chart.xAxis[0], unionExtremes = (chart.scroller && chart.scroller.getUnionExtremes()) || baseAxis || {}, dataMin = unionExtremes.dataMin, dataMax = unionExtremes.dataMax, newMin, newMax = baseAxis && Math.round(Math.min(baseAxis.max, pick(dataMax, baseAxis.max))), // #1568
  6840. type = rangeOptions.type, baseXAxisOptions, range = rangeOptions._range, rangeMin, minSetting, rangeSetting, ctx, ytdExtremes, dataGrouping = rangeOptions.dataGrouping;
  6841. // chart has no data, base series is removed
  6842. if (dataMin === null || dataMax === null) {
  6843. return;
  6844. }
  6845. // Set the fixed range before range is altered
  6846. chart.fixedRange = range;
  6847. // Apply dataGrouping associated to button
  6848. if (dataGrouping) {
  6849. this.forcedDataGrouping = true;
  6850. Axis.prototype.setDataGrouping.call(baseAxis || { chart: this.chart }, dataGrouping, false);
  6851. this.frozenStates = rangeOptions.preserveDataGrouping;
  6852. }
  6853. // Apply range
  6854. if (type === 'month' || type === 'year') {
  6855. if (!baseAxis) {
  6856. // This is set to the user options and picked up later when the
  6857. // axis is instantiated so that we know the min and max.
  6858. range = rangeOptions;
  6859. }
  6860. else {
  6861. ctx = {
  6862. range: rangeOptions,
  6863. max: newMax,
  6864. chart: chart,
  6865. dataMin: dataMin,
  6866. dataMax: dataMax
  6867. };
  6868. newMin = baseAxis.minFromRange.call(ctx);
  6869. if (isNumber(ctx.newMax)) {
  6870. newMax = ctx.newMax;
  6871. }
  6872. }
  6873. // Fixed times like minutes, hours, days
  6874. }
  6875. else if (range) {
  6876. newMin = Math.max(newMax - range, dataMin);
  6877. newMax = Math.min(newMin + range, dataMax);
  6878. }
  6879. else if (type === 'ytd') {
  6880. // On user clicks on the buttons, or a delayed action running from
  6881. // the beforeRender event (below), the baseAxis is defined.
  6882. if (baseAxis) {
  6883. // When "ytd" is the pre-selected button for the initial view,
  6884. // its calculation is delayed and rerun in the beforeRender
  6885. // event (below). When the series are initialized, but before
  6886. // the chart is rendered, we have access to the xData array
  6887. // (#942).
  6888. if (typeof dataMax === 'undefined') {
  6889. dataMin = Number.MAX_VALUE;
  6890. dataMax = Number.MIN_VALUE;
  6891. chart.series.forEach(function (series) {
  6892. // reassign it to the last item
  6893. var xData = series.xData;
  6894. dataMin = Math.min(xData[0], dataMin);
  6895. dataMax = Math.max(xData[xData.length - 1], dataMax);
  6896. });
  6897. redraw = false;
  6898. }
  6899. ytdExtremes = rangeSelector.getYTDExtremes(dataMax, dataMin, chart.time.useUTC);
  6900. newMin = rangeMin = ytdExtremes.min;
  6901. newMax = ytdExtremes.max;
  6902. // "ytd" is pre-selected. We don't yet have access to processed
  6903. // point and extremes data (things like pointStart and pointInterval
  6904. // are missing), so we delay the process (#942)
  6905. }
  6906. else {
  6907. rangeSelector.deferredYTDClick = i;
  6908. return;
  6909. }
  6910. }
  6911. else if (type === 'all' && baseAxis) {
  6912. newMin = dataMin;
  6913. newMax = dataMax;
  6914. }
  6915. newMin += rangeOptions._offsetMin;
  6916. newMax += rangeOptions._offsetMax;
  6917. rangeSelector.setSelected(i);
  6918. // Update the chart
  6919. if (!baseAxis) {
  6920. // Axis not yet instanciated. Temporarily set min and range
  6921. // options and remove them on chart load (#4317).
  6922. baseXAxisOptions = splat(chart.options.xAxis)[0];
  6923. rangeSetting = baseXAxisOptions.range;
  6924. baseXAxisOptions.range = range;
  6925. minSetting = baseXAxisOptions.min;
  6926. baseXAxisOptions.min = rangeMin;
  6927. addEvent(chart, 'load', function resetMinAndRange() {
  6928. baseXAxisOptions.range = rangeSetting;
  6929. baseXAxisOptions.min = minSetting;
  6930. });
  6931. }
  6932. else {
  6933. // Existing axis object. Set extremes after render time.
  6934. baseAxis.setExtremes(newMin, newMax, pick(redraw, 1), null, // auto animation
  6935. {
  6936. trigger: 'rangeSelectorButton',
  6937. rangeSelectorButton: rangeOptions
  6938. });
  6939. }
  6940. },
  6941. /**
  6942. * Set the selected option. This method only sets the internal flag, it
  6943. * doesn't update the buttons or the actual zoomed range.
  6944. *
  6945. * @private
  6946. * @function Highcharts.RangeSelector#setSelected
  6947. * @param {number} [selected]
  6948. * @return {void}
  6949. */
  6950. setSelected: function (selected) {
  6951. this.selected = this.options.selected = selected;
  6952. },
  6953. /**
  6954. * The default buttons for pre-selecting time frames
  6955. */
  6956. defaultButtons: [{
  6957. type: 'month',
  6958. count: 1,
  6959. text: '1m'
  6960. }, {
  6961. type: 'month',
  6962. count: 3,
  6963. text: '3m'
  6964. }, {
  6965. type: 'month',
  6966. count: 6,
  6967. text: '6m'
  6968. }, {
  6969. type: 'ytd',
  6970. text: 'YTD'
  6971. }, {
  6972. type: 'year',
  6973. count: 1,
  6974. text: '1y'
  6975. }, {
  6976. type: 'all',
  6977. text: 'All'
  6978. }],
  6979. /**
  6980. * Initialize the range selector
  6981. *
  6982. * @private
  6983. * @function Highcharts.RangeSelector#init
  6984. * @param {Highcharts.Chart} chart
  6985. * @return {void}
  6986. */
  6987. init: function (chart) {
  6988. var rangeSelector = this, options = chart.options.rangeSelector, buttonOptions = options.buttons ||
  6989. [].concat(rangeSelector.defaultButtons), selectedOption = options.selected, blurInputs = function () {
  6990. var minInput = rangeSelector.minInput, maxInput = rangeSelector.maxInput;
  6991. // #3274 in some case blur is not defined
  6992. if (minInput && minInput.blur) {
  6993. fireEvent(minInput, 'blur');
  6994. }
  6995. if (maxInput && maxInput.blur) {
  6996. fireEvent(maxInput, 'blur');
  6997. }
  6998. };
  6999. rangeSelector.chart = chart;
  7000. rangeSelector.options = options;
  7001. rangeSelector.buttons = [];
  7002. rangeSelector.buttonOptions = buttonOptions;
  7003. this.unMouseDown = addEvent(chart.container, 'mousedown', blurInputs);
  7004. this.unResize = addEvent(chart, 'resize', blurInputs);
  7005. // Extend the buttonOptions with actual range
  7006. buttonOptions.forEach(rangeSelector.computeButtonRange);
  7007. // zoomed range based on a pre-selected button index
  7008. if (typeof selectedOption !== 'undefined' &&
  7009. buttonOptions[selectedOption]) {
  7010. this.clickButton(selectedOption, false);
  7011. }
  7012. addEvent(chart, 'load', function () {
  7013. // If a data grouping is applied to the current button, release it
  7014. // when extremes change
  7015. if (chart.xAxis && chart.xAxis[0]) {
  7016. addEvent(chart.xAxis[0], 'setExtremes', function (e) {
  7017. if (this.max - this.min !==
  7018. chart.fixedRange &&
  7019. e.trigger !== 'rangeSelectorButton' &&
  7020. e.trigger !== 'updatedData' &&
  7021. rangeSelector.forcedDataGrouping &&
  7022. !rangeSelector.frozenStates) {
  7023. this.setDataGrouping(false, false);
  7024. }
  7025. });
  7026. }
  7027. });
  7028. },
  7029. /**
  7030. * Dynamically update the range selector buttons after a new range has been
  7031. * set
  7032. *
  7033. * @private
  7034. * @function Highcharts.RangeSelector#updateButtonStates
  7035. * @return {void}
  7036. */
  7037. updateButtonStates: function () {
  7038. var rangeSelector = this, chart = this.chart, baseAxis = chart.xAxis[0], actualRange = Math.round(baseAxis.max - baseAxis.min), hasNoData = !baseAxis.hasVisibleSeries, day = 24 * 36e5, // A single day in milliseconds
  7039. unionExtremes = (chart.scroller &&
  7040. chart.scroller.getUnionExtremes()) || baseAxis, dataMin = unionExtremes.dataMin, dataMax = unionExtremes.dataMax, ytdExtremes = rangeSelector.getYTDExtremes(dataMax, dataMin, chart.time.useUTC), ytdMin = ytdExtremes.min, ytdMax = ytdExtremes.max, selected = rangeSelector.selected, selectedExists = isNumber(selected), allButtonsEnabled = rangeSelector.options.allButtonsEnabled, buttons = rangeSelector.buttons;
  7041. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  7042. var range = rangeOptions._range, type = rangeOptions.type, count = rangeOptions.count || 1, button = buttons[i], state = 0, disable, select, offsetRange = rangeOptions._offsetMax -
  7043. rangeOptions._offsetMin, isSelected = i === selected,
  7044. // Disable buttons where the range exceeds what is allowed in
  7045. // the current view
  7046. isTooGreatRange = range >
  7047. dataMax - dataMin,
  7048. // Disable buttons where the range is smaller than the minimum
  7049. // range
  7050. isTooSmallRange = range < baseAxis.minRange,
  7051. // Do not select the YTD button if not explicitly told so
  7052. isYTDButNotSelected = false,
  7053. // Disable the All button if we're already showing all
  7054. isAllButAlreadyShowingAll = false, isSameRange = range === actualRange;
  7055. // Months and years have a variable range so we check the extremes
  7056. if ((type === 'month' || type === 'year') &&
  7057. (actualRange + 36e5 >=
  7058. { month: 28, year: 365 }[type] * day * count - offsetRange) &&
  7059. (actualRange - 36e5 <=
  7060. { month: 31, year: 366 }[type] * day * count + offsetRange)) {
  7061. isSameRange = true;
  7062. }
  7063. else if (type === 'ytd') {
  7064. isSameRange = (ytdMax - ytdMin + offsetRange) === actualRange;
  7065. isYTDButNotSelected = !isSelected;
  7066. }
  7067. else if (type === 'all') {
  7068. isSameRange = (baseAxis.max - baseAxis.min >=
  7069. dataMax - dataMin);
  7070. isAllButAlreadyShowingAll = (!isSelected &&
  7071. selectedExists &&
  7072. isSameRange);
  7073. }
  7074. // The new zoom area happens to match the range for a button - mark
  7075. // it selected. This happens when scrolling across an ordinal gap.
  7076. // It can be seen in the intraday demos when selecting 1h and scroll
  7077. // across the night gap.
  7078. disable = (!allButtonsEnabled &&
  7079. (isTooGreatRange ||
  7080. isTooSmallRange ||
  7081. isAllButAlreadyShowingAll ||
  7082. hasNoData));
  7083. select = ((isSelected && isSameRange) ||
  7084. (isSameRange && !selectedExists && !isYTDButNotSelected) ||
  7085. (isSelected && rangeSelector.frozenStates));
  7086. if (disable) {
  7087. state = 3;
  7088. }
  7089. else if (select) {
  7090. selectedExists = true; // Only one button can be selected
  7091. state = 2;
  7092. }
  7093. // If state has changed, update the button
  7094. if (button.state !== state) {
  7095. button.setState(state);
  7096. // Reset (#9209)
  7097. if (state === 0 && selected === i) {
  7098. rangeSelector.setSelected(null);
  7099. }
  7100. }
  7101. });
  7102. },
  7103. /**
  7104. * Compute and cache the range for an individual button
  7105. *
  7106. * @private
  7107. * @function Highcharts.RangeSelector#computeButtonRange
  7108. * @param {Highcharts.RangeSelectorButtonsOptions} rangeOptions
  7109. * @return {void}
  7110. */
  7111. computeButtonRange: function (rangeOptions) {
  7112. var type = rangeOptions.type, count = rangeOptions.count || 1,
  7113. // these time intervals have a fixed number of milliseconds, as
  7114. // opposed to month, ytd and year
  7115. fixedTimes = {
  7116. millisecond: 1,
  7117. second: 1000,
  7118. minute: 60 * 1000,
  7119. hour: 3600 * 1000,
  7120. day: 24 * 3600 * 1000,
  7121. week: 7 * 24 * 3600 * 1000
  7122. };
  7123. // Store the range on the button object
  7124. if (fixedTimes[type]) {
  7125. rangeOptions._range = fixedTimes[type] * count;
  7126. }
  7127. else if (type === 'month' || type === 'year') {
  7128. rangeOptions._range = {
  7129. month: 30,
  7130. year: 365
  7131. }[type] * 24 * 36e5 * count;
  7132. }
  7133. rangeOptions._offsetMin = pick(rangeOptions.offsetMin, 0);
  7134. rangeOptions._offsetMax = pick(rangeOptions.offsetMax, 0);
  7135. rangeOptions._range +=
  7136. rangeOptions._offsetMax - rangeOptions._offsetMin;
  7137. },
  7138. /**
  7139. * Set the internal and displayed value of a HTML input for the dates
  7140. *
  7141. * @private
  7142. * @function Highcharts.RangeSelector#setInputValue
  7143. * @param {string} name
  7144. * @param {number} [inputTime]
  7145. * @return {void}
  7146. */
  7147. setInputValue: function (name, inputTime) {
  7148. var options = this.chart.options.rangeSelector, time = this.chart.time, input = this[name + 'Input'];
  7149. if (defined(inputTime)) {
  7150. input.previousValue = input.HCTime;
  7151. input.HCTime = inputTime;
  7152. }
  7153. input.value = time.dateFormat(options.inputEditDateFormat || '%Y-%m-%d', input.HCTime);
  7154. this[name + 'DateBox'].attr({
  7155. text: time.dateFormat(options.inputDateFormat || '%b %e, %Y', input.HCTime)
  7156. });
  7157. },
  7158. /**
  7159. * @private
  7160. * @function Highcharts.RangeSelector#showInput
  7161. * @param {string} name
  7162. * @return {void}
  7163. */
  7164. showInput: function (name) {
  7165. var inputGroup = this.inputGroup, dateBox = this[name + 'DateBox'];
  7166. css(this[name + 'Input'], {
  7167. left: (inputGroup.translateX + dateBox.x) + 'px',
  7168. top: inputGroup.translateY + 'px',
  7169. width: (dateBox.width - 2) + 'px',
  7170. height: (dateBox.height - 2) + 'px',
  7171. border: '2px solid silver'
  7172. });
  7173. },
  7174. /**
  7175. * @private
  7176. * @function Highcharts.RangeSelector#hideInput
  7177. * @param {string} name
  7178. * @return {void}
  7179. */
  7180. hideInput: function (name) {
  7181. css(this[name + 'Input'], {
  7182. border: 0,
  7183. width: '1px',
  7184. height: '1px'
  7185. });
  7186. this.setInputValue(name);
  7187. },
  7188. /**
  7189. * Draw either the 'from' or the 'to' HTML input box of the range selector
  7190. *
  7191. * @private
  7192. * @function Highcharts.RangeSelector#drawInput
  7193. * @param {string} name
  7194. * @return {void}
  7195. */
  7196. drawInput: function (name) {
  7197. var rangeSelector = this, chart = rangeSelector.chart, chartStyle = chart.renderer.style || {}, renderer = chart.renderer, options = chart.options.rangeSelector, lang = defaultOptions.lang, div = rangeSelector.div, isMin = name === 'min', input, label, dateBox, inputGroup = this.inputGroup;
  7198. /**
  7199. * @private
  7200. */
  7201. function updateExtremes() {
  7202. var inputValue = input.value, value = (options.inputDateParser || Date.parse)(inputValue), chartAxis = chart.xAxis[0], dataAxis = chart.scroller && chart.scroller.xAxis ?
  7203. chart.scroller.xAxis :
  7204. chartAxis, dataMin = dataAxis.dataMin, dataMax = dataAxis.dataMax;
  7205. if (value !== input.previousValue) {
  7206. input.previousValue = value;
  7207. // If the value isn't parsed directly to a value by the
  7208. // browser's Date.parse method, like YYYY-MM-DD in IE, try
  7209. // parsing it a different way
  7210. if (!isNumber(value)) {
  7211. value = inputValue.split('-');
  7212. value = Date.UTC(pInt(value[0]), pInt(value[1]) - 1, pInt(value[2]));
  7213. }
  7214. if (isNumber(value)) {
  7215. // Correct for timezone offset (#433)
  7216. if (!chart.time.useUTC) {
  7217. value =
  7218. value + new Date().getTimezoneOffset() * 60 * 1000;
  7219. }
  7220. // Validate the extremes. If it goes beyound the data min or
  7221. // max, use the actual data extreme (#2438).
  7222. if (isMin) {
  7223. if (value > rangeSelector.maxInput.HCTime) {
  7224. value = void 0;
  7225. }
  7226. else if (value < dataMin) {
  7227. value = dataMin;
  7228. }
  7229. }
  7230. else {
  7231. if (value < rangeSelector.minInput.HCTime) {
  7232. value = void 0;
  7233. }
  7234. else if (value > dataMax) {
  7235. value = dataMax;
  7236. }
  7237. }
  7238. // Set the extremes
  7239. if (typeof value !== 'undefined') { // @todo typof undefined
  7240. chartAxis.setExtremes(isMin ? value : chartAxis.min, isMin ? chartAxis.max : value, void 0, void 0, { trigger: 'rangeSelectorInput' });
  7241. }
  7242. }
  7243. }
  7244. }
  7245. // Create the text label
  7246. this[name + 'Label'] = label = renderer
  7247. .label(lang[isMin ? 'rangeSelectorFrom' : 'rangeSelectorTo'], this.inputGroup.offset)
  7248. .addClass('highcharts-range-label')
  7249. .attr({
  7250. padding: 2
  7251. })
  7252. .add(inputGroup);
  7253. inputGroup.offset += label.width + 5;
  7254. // Create an SVG label that shows updated date ranges and and records
  7255. // click events that bring in the HTML input.
  7256. this[name + 'DateBox'] = dateBox = renderer
  7257. .label('', inputGroup.offset)
  7258. .addClass('highcharts-range-input')
  7259. .attr({
  7260. padding: 2,
  7261. width: options.inputBoxWidth || 90,
  7262. height: options.inputBoxHeight || 17,
  7263. 'text-align': 'center'
  7264. })
  7265. .on('click', function () {
  7266. // If it is already focused, the onfocus event doesn't fire
  7267. // (#3713)
  7268. rangeSelector.showInput(name);
  7269. rangeSelector[name + 'Input'].focus();
  7270. });
  7271. if (!chart.styledMode) {
  7272. dateBox.attr({
  7273. stroke: options.inputBoxBorderColor || '#cccccc',
  7274. 'stroke-width': 1
  7275. });
  7276. }
  7277. dateBox.add(inputGroup);
  7278. inputGroup.offset += dateBox.width + (isMin ? 10 : 0);
  7279. // Create the HTML input element. This is rendered as 1x1 pixel then set
  7280. // to the right size when focused.
  7281. this[name + 'Input'] = input = createElement('input', {
  7282. name: name,
  7283. className: 'highcharts-range-selector',
  7284. type: 'text'
  7285. }, {
  7286. top: chart.plotTop + 'px' // prevent jump on focus in Firefox
  7287. }, div);
  7288. if (!chart.styledMode) {
  7289. // Styles
  7290. label.css(merge(chartStyle, options.labelStyle));
  7291. dateBox.css(merge({
  7292. color: '#333333'
  7293. }, chartStyle, options.inputStyle));
  7294. css(input, extend({
  7295. position: 'absolute',
  7296. border: 0,
  7297. width: '1px',
  7298. height: '1px',
  7299. padding: 0,
  7300. textAlign: 'center',
  7301. fontSize: chartStyle.fontSize,
  7302. fontFamily: chartStyle.fontFamily,
  7303. top: '-9999em' // #4798
  7304. }, options.inputStyle));
  7305. }
  7306. // Blow up the input box
  7307. input.onfocus = function () {
  7308. rangeSelector.showInput(name);
  7309. };
  7310. // Hide away the input box
  7311. input.onblur = function () {
  7312. // update extermes only when inputs are active
  7313. if (input === H.doc.activeElement) { // Only when focused
  7314. // Update also when no `change` event is triggered, like when
  7315. // clicking inside the SVG (#4710)
  7316. updateExtremes();
  7317. }
  7318. // #10404 - move hide and blur outside focus
  7319. rangeSelector.hideInput(name);
  7320. input.blur(); // #4606
  7321. };
  7322. // handle changes in the input boxes
  7323. input.onchange = updateExtremes;
  7324. input.onkeypress = function (event) {
  7325. // IE does not fire onchange on enter
  7326. if (event.keyCode === 13) {
  7327. updateExtremes();
  7328. }
  7329. };
  7330. },
  7331. /**
  7332. * Get the position of the range selector buttons and inputs. This can be
  7333. * overridden from outside for custom positioning.
  7334. *
  7335. * @private
  7336. * @function Highcharts.RangeSelector#getPosition
  7337. *
  7338. * @return {Highcharts.Dictionary<number>}
  7339. */
  7340. getPosition: function () {
  7341. var chart = this.chart, options = chart.options.rangeSelector, top = options.verticalAlign === 'top' ?
  7342. chart.plotTop - chart.axisOffset[0] :
  7343. 0; // set offset only for varticalAlign top
  7344. return {
  7345. buttonTop: top + options.buttonPosition.y,
  7346. inputTop: top + options.inputPosition.y - 10
  7347. };
  7348. },
  7349. /**
  7350. * Get the extremes of YTD. Will choose dataMax if its value is lower than
  7351. * the current timestamp. Will choose dataMin if its value is higher than
  7352. * the timestamp for the start of current year.
  7353. *
  7354. * @private
  7355. * @function Highcharts.RangeSelector#getYTDExtremes
  7356. *
  7357. * @param {number} dataMax
  7358. *
  7359. * @param {number} dataMin
  7360. *
  7361. * @return {*}
  7362. * Returns min and max for the YTD
  7363. */
  7364. getYTDExtremes: function (dataMax, dataMin, useUTC) {
  7365. var time = this.chart.time, min, now = new time.Date(dataMax), year = time.get('FullYear', now), startOfYear = useUTC ?
  7366. time.Date.UTC(year, 0, 1) : // eslint-disable-line new-cap
  7367. +new time.Date(year, 0, 1);
  7368. min = Math.max(dataMin || 0, startOfYear);
  7369. now = now.getTime();
  7370. return {
  7371. max: Math.min(dataMax || now, now),
  7372. min: min
  7373. };
  7374. },
  7375. /**
  7376. * Render the range selector including the buttons and the inputs. The first
  7377. * time render is called, the elements are created and positioned. On
  7378. * subsequent calls, they are moved and updated.
  7379. *
  7380. * @private
  7381. * @function Highcharts.RangeSelector#render
  7382. * @param {number} [min]
  7383. * X axis minimum
  7384. * @param {number} [max]
  7385. * X axis maximum
  7386. * @return {void}
  7387. */
  7388. render: function (min, max) {
  7389. var rangeSelector = this, chart = rangeSelector.chart, renderer = chart.renderer, container = chart.container, chartOptions = chart.options, navButtonOptions = (chartOptions.exporting &&
  7390. chartOptions.exporting.enabled !== false &&
  7391. chartOptions.navigation &&
  7392. chartOptions.navigation.buttonOptions), lang = defaultOptions.lang, div = rangeSelector.div, options = chartOptions.rangeSelector,
  7393. // Place inputs above the container
  7394. inputsZIndex = pick(chartOptions.chart.style &&
  7395. chartOptions.chart.style.zIndex, 0) + 1, floating = options.floating, buttons = rangeSelector.buttons, inputGroup = rangeSelector.inputGroup, buttonTheme = options.buttonTheme, buttonPosition = options.buttonPosition, inputPosition = options.inputPosition, inputEnabled = options.inputEnabled, states = buttonTheme && buttonTheme.states, plotLeft = chart.plotLeft, buttonLeft, buttonGroup = rangeSelector.buttonGroup, group, groupHeight, rendered = rangeSelector.rendered, verticalAlign = rangeSelector.options.verticalAlign, legend = chart.legend, legendOptions = legend && legend.options, buttonPositionY = buttonPosition.y, inputPositionY = inputPosition.y, animate = rendered || false, verb = animate ? 'animate' : 'attr', exportingX = 0, alignTranslateY, legendHeight, minPosition, translateY = 0, translateX;
  7396. if (options.enabled === false) {
  7397. return;
  7398. }
  7399. // create the elements
  7400. if (!rendered) {
  7401. rangeSelector.group = group = renderer.g('range-selector-group')
  7402. .attr({
  7403. zIndex: 7
  7404. })
  7405. .add();
  7406. rangeSelector.buttonGroup = buttonGroup =
  7407. renderer.g('range-selector-buttons').add(group);
  7408. rangeSelector.zoomText = renderer
  7409. .text(lang.rangeSelectorZoom, 0, 15)
  7410. .add(buttonGroup);
  7411. if (!chart.styledMode) {
  7412. rangeSelector.zoomText.css(options.labelStyle);
  7413. buttonTheme['stroke-width'] =
  7414. pick(buttonTheme['stroke-width'], 0);
  7415. }
  7416. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  7417. buttons[i] = renderer
  7418. .button(rangeOptions.text, 0, 0, function (e) {
  7419. // extract events from button object and call
  7420. var buttonEvents = (rangeOptions.events &&
  7421. rangeOptions.events.click), callDefaultEvent;
  7422. if (buttonEvents) {
  7423. callDefaultEvent =
  7424. buttonEvents.call(rangeOptions, e);
  7425. }
  7426. if (callDefaultEvent !== false) {
  7427. rangeSelector.clickButton(i);
  7428. }
  7429. rangeSelector.isActive = true;
  7430. }, buttonTheme, states && states.hover, states && states.select, states && states.disabled)
  7431. .attr({
  7432. 'text-align': 'center'
  7433. })
  7434. .add(buttonGroup);
  7435. });
  7436. // first create a wrapper outside the container in order to make
  7437. // the inputs work and make export correct
  7438. if (inputEnabled !== false) {
  7439. rangeSelector.div = div = createElement('div', null, {
  7440. position: 'relative',
  7441. height: 0,
  7442. zIndex: inputsZIndex
  7443. });
  7444. container.parentNode.insertBefore(div, container);
  7445. // Create the group to keep the inputs
  7446. rangeSelector.inputGroup = inputGroup =
  7447. renderer.g('input-group').add(group);
  7448. inputGroup.offset = 0;
  7449. rangeSelector.drawInput('min');
  7450. rangeSelector.drawInput('max');
  7451. }
  7452. }
  7453. // #8769, allow dynamically updating margins
  7454. rangeSelector.zoomText[verb]({
  7455. x: pick(plotLeft + buttonPosition.x, plotLeft)
  7456. });
  7457. // button start position
  7458. buttonLeft = pick(plotLeft + buttonPosition.x, plotLeft) +
  7459. rangeSelector.zoomText.getBBox().width + 5;
  7460. rangeSelector.buttonOptions.forEach(function (rangeOptions, i) {
  7461. buttons[i][verb]({ x: buttonLeft });
  7462. // increase button position for the next button
  7463. buttonLeft += buttons[i].width + pick(options.buttonSpacing, 5);
  7464. });
  7465. plotLeft = chart.plotLeft - chart.spacing[3];
  7466. rangeSelector.updateButtonStates();
  7467. // detect collisiton with exporting
  7468. if (navButtonOptions &&
  7469. this.titleCollision(chart) &&
  7470. verticalAlign === 'top' &&
  7471. buttonPosition.align === 'right' && ((buttonPosition.y +
  7472. buttonGroup.getBBox().height - 12) <
  7473. ((navButtonOptions.y || 0) +
  7474. navButtonOptions.height))) {
  7475. exportingX = -40;
  7476. }
  7477. if (buttonPosition.align === 'left') {
  7478. translateX = buttonPosition.x - chart.spacing[3];
  7479. }
  7480. else if (buttonPosition.align === 'right') {
  7481. translateX =
  7482. buttonPosition.x + exportingX - chart.spacing[1];
  7483. }
  7484. // align button group
  7485. buttonGroup.align({
  7486. y: buttonPosition.y,
  7487. width: buttonGroup.getBBox().width,
  7488. align: buttonPosition.align,
  7489. x: translateX
  7490. }, true, chart.spacingBox);
  7491. // skip animation
  7492. rangeSelector.group.placed = animate;
  7493. rangeSelector.buttonGroup.placed = animate;
  7494. if (inputEnabled !== false) {
  7495. var inputGroupX, inputGroupWidth, buttonGroupX, buttonGroupWidth;
  7496. // detect collision with exporting
  7497. if (navButtonOptions &&
  7498. this.titleCollision(chart) &&
  7499. verticalAlign === 'top' &&
  7500. inputPosition.align === 'right' && ((inputPosition.y -
  7501. inputGroup.getBBox().height - 12) <
  7502. ((navButtonOptions.y || 0) +
  7503. navButtonOptions.height +
  7504. chart.spacing[0]))) {
  7505. exportingX = -40;
  7506. }
  7507. else {
  7508. exportingX = 0;
  7509. }
  7510. if (inputPosition.align === 'left') {
  7511. translateX = plotLeft;
  7512. }
  7513. else if (inputPosition.align === 'right') {
  7514. translateX = -Math.max(chart.axisOffset[1], -exportingX);
  7515. }
  7516. // Update the alignment to the updated spacing box
  7517. inputGroup.align({
  7518. y: inputPosition.y,
  7519. width: inputGroup.getBBox().width,
  7520. align: inputPosition.align,
  7521. // fix wrong getBBox() value on right align
  7522. x: inputPosition.x + translateX - 2
  7523. }, true, chart.spacingBox);
  7524. // detect collision
  7525. inputGroupX = (inputGroup.alignAttr.translateX +
  7526. inputGroup.alignOptions.x -
  7527. exportingX +
  7528. // getBBox for detecing left margin
  7529. inputGroup.getBBox().x +
  7530. // 2px padding to not overlap input and label
  7531. 2);
  7532. inputGroupWidth = inputGroup.alignOptions.width;
  7533. buttonGroupX = buttonGroup.alignAttr.translateX +
  7534. buttonGroup.getBBox().x;
  7535. // 20 is minimal spacing between elements
  7536. buttonGroupWidth = buttonGroup.getBBox().width + 20;
  7537. if ((inputPosition.align ===
  7538. buttonPosition.align) || ((buttonGroupX + buttonGroupWidth > inputGroupX) &&
  7539. (inputGroupX + inputGroupWidth > buttonGroupX) &&
  7540. (buttonPositionY <
  7541. (inputPositionY +
  7542. inputGroup.getBBox().height)))) {
  7543. inputGroup.attr({
  7544. translateX: inputGroup.alignAttr.translateX +
  7545. (chart.axisOffset[1] >= -exportingX ? 0 : -exportingX),
  7546. translateY: inputGroup.alignAttr.translateY +
  7547. buttonGroup.getBBox().height + 10
  7548. });
  7549. }
  7550. // Set or reset the input values
  7551. rangeSelector.setInputValue('min', min);
  7552. rangeSelector.setInputValue('max', max);
  7553. // skip animation
  7554. rangeSelector.inputGroup.placed = animate;
  7555. }
  7556. // vertical align
  7557. rangeSelector.group.align({
  7558. verticalAlign: verticalAlign
  7559. }, true, chart.spacingBox);
  7560. // set position
  7561. groupHeight =
  7562. rangeSelector.group.getBBox().height + 20; // # 20 padding
  7563. alignTranslateY =
  7564. rangeSelector.group.alignAttr.translateY;
  7565. // calculate bottom position
  7566. if (verticalAlign === 'bottom') {
  7567. legendHeight = (legendOptions &&
  7568. legendOptions.verticalAlign === 'bottom' &&
  7569. legendOptions.enabled &&
  7570. !legendOptions.floating ?
  7571. legend.legendHeight + pick(legendOptions.margin, 10) :
  7572. 0);
  7573. groupHeight = groupHeight + legendHeight - 20;
  7574. translateY = (alignTranslateY -
  7575. groupHeight -
  7576. (floating ? 0 : options.y) -
  7577. (chart.titleOffset ? chart.titleOffset[2] : 0) -
  7578. 10 // 10 spacing
  7579. );
  7580. }
  7581. if (verticalAlign === 'top') {
  7582. if (floating) {
  7583. translateY = 0;
  7584. }
  7585. if (chart.titleOffset && chart.titleOffset[0]) {
  7586. translateY = chart.titleOffset[0];
  7587. }
  7588. translateY += ((chart.margin[0] - chart.spacing[0]) || 0);
  7589. }
  7590. else if (verticalAlign === 'middle') {
  7591. if (inputPositionY === buttonPositionY) {
  7592. if (inputPositionY < 0) {
  7593. translateY = alignTranslateY + minPosition;
  7594. }
  7595. else {
  7596. translateY = alignTranslateY;
  7597. }
  7598. }
  7599. else if (inputPositionY || buttonPositionY) {
  7600. if (inputPositionY < 0 ||
  7601. buttonPositionY < 0) {
  7602. translateY -= Math.min(inputPositionY, buttonPositionY);
  7603. }
  7604. else {
  7605. translateY =
  7606. alignTranslateY - groupHeight + minPosition;
  7607. }
  7608. }
  7609. }
  7610. rangeSelector.group.translate(options.x, options.y + Math.floor(translateY));
  7611. // translate HTML inputs
  7612. if (inputEnabled !== false) {
  7613. rangeSelector.minInput.style.marginTop =
  7614. rangeSelector.group.translateY + 'px';
  7615. rangeSelector.maxInput.style.marginTop =
  7616. rangeSelector.group.translateY + 'px';
  7617. }
  7618. rangeSelector.rendered = true;
  7619. },
  7620. /**
  7621. * Extracts height of range selector
  7622. *
  7623. * @private
  7624. * @function Highcharts.RangeSelector#getHeight
  7625. * @return {number}
  7626. * Returns rangeSelector height
  7627. */
  7628. getHeight: function () {
  7629. var rangeSelector = this, options = rangeSelector.options, rangeSelectorGroup = rangeSelector.group, inputPosition = options.inputPosition, buttonPosition = options.buttonPosition, yPosition = options.y, buttonPositionY = buttonPosition.y, inputPositionY = inputPosition.y, rangeSelectorHeight = 0, minPosition;
  7630. if (options.height) {
  7631. return options.height;
  7632. }
  7633. rangeSelectorHeight = rangeSelectorGroup ?
  7634. // 13px to keep back compatibility
  7635. (rangeSelectorGroup.getBBox(true).height) + 13 +
  7636. yPosition :
  7637. 0;
  7638. minPosition = Math.min(inputPositionY, buttonPositionY);
  7639. if ((inputPositionY < 0 && buttonPositionY < 0) ||
  7640. (inputPositionY > 0 && buttonPositionY > 0)) {
  7641. rangeSelectorHeight += Math.abs(minPosition);
  7642. }
  7643. return rangeSelectorHeight;
  7644. },
  7645. /**
  7646. * Detect collision with title or subtitle
  7647. *
  7648. * @private
  7649. * @function Highcharts.RangeSelector#titleCollision
  7650. *
  7651. * @param {Highcharts.Chart} chart
  7652. *
  7653. * @return {boolean}
  7654. * Returns collision status
  7655. */
  7656. titleCollision: function (chart) {
  7657. return !(chart.options.title.text ||
  7658. chart.options.subtitle.text);
  7659. },
  7660. /**
  7661. * Update the range selector with new options
  7662. *
  7663. * @private
  7664. * @function Highcharts.RangeSelector#update
  7665. * @param {Highcharts.RangeSelectorOptions} options
  7666. * @return {void}
  7667. */
  7668. update: function (options) {
  7669. var chart = this.chart;
  7670. merge(true, chart.options.rangeSelector, options);
  7671. this.destroy();
  7672. this.init(chart);
  7673. chart.rangeSelector.render();
  7674. },
  7675. /**
  7676. * Destroys allocated elements.
  7677. *
  7678. * @private
  7679. * @function Highcharts.RangeSelector#destroy
  7680. */
  7681. destroy: function () {
  7682. var rSelector = this, minInput = rSelector.minInput, maxInput = rSelector.maxInput;
  7683. rSelector.unMouseDown();
  7684. rSelector.unResize();
  7685. // Destroy elements in collections
  7686. destroyObjectProperties(rSelector.buttons);
  7687. // Clear input element events
  7688. if (minInput) {
  7689. minInput.onfocus = minInput.onblur = minInput.onchange = null;
  7690. }
  7691. if (maxInput) {
  7692. maxInput.onfocus = maxInput.onblur = maxInput.onchange = null;
  7693. }
  7694. // Destroy HTML and SVG elements
  7695. objectEach(rSelector, function (val, key) {
  7696. if (val && key !== 'chart') {
  7697. if (val.destroy) {
  7698. // SVGElement
  7699. val.destroy();
  7700. }
  7701. else if (val.nodeType) {
  7702. // HTML element
  7703. discardElement(this[key]);
  7704. }
  7705. }
  7706. if (val !== RangeSelector.prototype[key]) {
  7707. rSelector[key] = null;
  7708. }
  7709. }, this);
  7710. }
  7711. };
  7712. /**
  7713. * Get the axis min value based on the range option and the current max. For
  7714. * stock charts this is extended via the {@link RangeSelector} so that if the
  7715. * selected range is a multiple of months or years, it is compensated for
  7716. * various month lengths.
  7717. *
  7718. * @private
  7719. * @function Highcharts.Axis#minFromRange
  7720. * @return {number|undefined}
  7721. * The new minimum value.
  7722. */
  7723. Axis.prototype.minFromRange = function () {
  7724. var rangeOptions = this.range, type = rangeOptions.type, timeName = {
  7725. month: 'Month',
  7726. year: 'FullYear'
  7727. }[type], min, max = this.max, dataMin, range, time = this.chart.time,
  7728. // Get the true range from a start date
  7729. getTrueRange = function (base, count) {
  7730. var date = new time.Date(base), basePeriod = time.get(timeName, date);
  7731. time.set(timeName, date, basePeriod + count);
  7732. if (basePeriod === time.get(timeName, date)) {
  7733. time.set('Date', date, 0); // #6537
  7734. }
  7735. return date.getTime() - base;
  7736. };
  7737. if (isNumber(rangeOptions)) {
  7738. min = max - rangeOptions;
  7739. range = rangeOptions;
  7740. }
  7741. else {
  7742. min = max + getTrueRange(max, -rangeOptions.count);
  7743. // Let the fixedRange reflect initial settings (#5930)
  7744. if (this.chart) {
  7745. this.chart.fixedRange = max - min;
  7746. }
  7747. }
  7748. dataMin = pick(this.dataMin, Number.MIN_VALUE);
  7749. if (!isNumber(min)) {
  7750. min = dataMin;
  7751. }
  7752. if (min <= dataMin) {
  7753. min = dataMin;
  7754. if (typeof range === 'undefined') { // #4501
  7755. range = getTrueRange(min, rangeOptions.count);
  7756. }
  7757. this.newMax = Math.min(min + range, this.dataMax);
  7758. }
  7759. if (!isNumber(max)) {
  7760. min = void 0;
  7761. }
  7762. return min;
  7763. };
  7764. if (!H.RangeSelector) {
  7765. // Initialize rangeselector for stock charts
  7766. addEvent(Chart, 'afterGetContainer', function () {
  7767. if (this.options.rangeSelector.enabled) {
  7768. this.rangeSelector = new RangeSelector(this);
  7769. }
  7770. });
  7771. addEvent(Chart, 'beforeRender', function () {
  7772. var chart = this, axes = chart.axes, rangeSelector = chart.rangeSelector, verticalAlign;
  7773. if (rangeSelector) {
  7774. if (isNumber(rangeSelector.deferredYTDClick)) {
  7775. rangeSelector.clickButton(rangeSelector.deferredYTDClick);
  7776. delete rangeSelector.deferredYTDClick;
  7777. }
  7778. axes.forEach(function (axis) {
  7779. axis.updateNames();
  7780. axis.setScale();
  7781. });
  7782. chart.getAxisMargins();
  7783. rangeSelector.render();
  7784. verticalAlign = rangeSelector.options.verticalAlign;
  7785. if (!rangeSelector.options.floating) {
  7786. if (verticalAlign === 'bottom') {
  7787. this.extraBottomMargin = true;
  7788. }
  7789. else if (verticalAlign !== 'middle') {
  7790. this.extraTopMargin = true;
  7791. }
  7792. }
  7793. }
  7794. });
  7795. addEvent(Chart, 'update', function (e) {
  7796. var chart = this, options = e.options, optionsRangeSelector = options.rangeSelector, rangeSelector = chart.rangeSelector, verticalAlign, extraBottomMarginWas = this.extraBottomMargin, extraTopMarginWas = this.extraTopMargin;
  7797. if (optionsRangeSelector &&
  7798. optionsRangeSelector.enabled &&
  7799. !defined(rangeSelector)) {
  7800. this.options.rangeSelector.enabled = true;
  7801. this.rangeSelector = new RangeSelector(this);
  7802. }
  7803. this.extraBottomMargin = false;
  7804. this.extraTopMargin = false;
  7805. if (rangeSelector) {
  7806. rangeSelector.render();
  7807. verticalAlign = (optionsRangeSelector &&
  7808. optionsRangeSelector.verticalAlign) || (rangeSelector.options && rangeSelector.options.verticalAlign);
  7809. if (!rangeSelector.options.floating) {
  7810. if (verticalAlign === 'bottom') {
  7811. this.extraBottomMargin = true;
  7812. }
  7813. else if (verticalAlign !== 'middle') {
  7814. this.extraTopMargin = true;
  7815. }
  7816. }
  7817. if (this.extraBottomMargin !== extraBottomMarginWas ||
  7818. this.extraTopMargin !== extraTopMarginWas) {
  7819. this.isDirtyBox = true;
  7820. }
  7821. }
  7822. });
  7823. addEvent(Chart, 'render', function () {
  7824. var chart = this, rangeSelector = chart.rangeSelector, verticalAlign;
  7825. if (rangeSelector && !rangeSelector.options.floating) {
  7826. rangeSelector.render();
  7827. verticalAlign = rangeSelector.options.verticalAlign;
  7828. if (verticalAlign === 'bottom') {
  7829. this.extraBottomMargin = true;
  7830. }
  7831. else if (verticalAlign !== 'middle') {
  7832. this.extraTopMargin = true;
  7833. }
  7834. }
  7835. });
  7836. addEvent(Chart, 'getMargins', function () {
  7837. var rangeSelector = this.rangeSelector, rangeSelectorHeight;
  7838. if (rangeSelector) {
  7839. rangeSelectorHeight = rangeSelector.getHeight();
  7840. if (this.extraTopMargin) {
  7841. this.plotTop += rangeSelectorHeight;
  7842. }
  7843. if (this.extraBottomMargin) {
  7844. this.marginBottom += rangeSelectorHeight;
  7845. }
  7846. }
  7847. });
  7848. Chart.prototype.callbacks.push(function (chart) {
  7849. var extremes, rangeSelector = chart.rangeSelector, unbindRender, unbindSetExtremes;
  7850. /**
  7851. * @private
  7852. */
  7853. function renderRangeSelector() {
  7854. extremes = chart.xAxis[0].getExtremes();
  7855. if (isNumber(extremes.min)) {
  7856. rangeSelector.render(extremes.min, extremes.max);
  7857. }
  7858. }
  7859. if (rangeSelector) {
  7860. // redraw the scroller on setExtremes
  7861. unbindSetExtremes = addEvent(chart.xAxis[0], 'afterSetExtremes', function (e) {
  7862. rangeSelector.render(e.min, e.max);
  7863. });
  7864. // redraw the scroller chart resize
  7865. unbindRender = addEvent(chart, 'redraw', renderRangeSelector);
  7866. // do it now
  7867. renderRangeSelector();
  7868. }
  7869. // Remove resize/afterSetExtremes at chart destroy
  7870. addEvent(chart, 'destroy', function destroyEvents() {
  7871. if (rangeSelector) {
  7872. unbindRender();
  7873. unbindSetExtremes();
  7874. }
  7875. });
  7876. });
  7877. H.RangeSelector = RangeSelector;
  7878. }
  7879. });
  7880. _registerModule(_modules, 'parts/StockChart.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
  7881. /* *
  7882. *
  7883. * (c) 2010-2019 Torstein Honsi
  7884. *
  7885. * License: www.highcharts.com/license
  7886. *
  7887. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  7888. *
  7889. * */
  7890. var arrayMax = U.arrayMax, arrayMin = U.arrayMin, clamp = U.clamp, defined = U.defined, extend = U.extend, isNumber = U.isNumber, isString = U.isString, pick = U.pick, splat = U.splat;
  7891. // Has a dependency on Navigator due to the use of
  7892. // defaultOptions.navigator
  7893. // Has a dependency on Scrollbar due to the use of
  7894. // defaultOptions.scrollbar
  7895. // Has a dependency on RangeSelector due to the use of
  7896. // defaultOptions.rangeSelector
  7897. var addEvent = H.addEvent, Axis = H.Axis, Chart = H.Chart, format = H.format, merge = H.merge, Point = H.Point, Renderer = H.Renderer, Series = H.Series, SVGRenderer = H.SVGRenderer, VMLRenderer = H.VMLRenderer, seriesProto = Series.prototype, seriesInit = seriesProto.init, seriesProcessData = seriesProto.processData, pointTooltipFormatter = Point.prototype.tooltipFormatter;
  7898. /**
  7899. * Compare the values of the series against the first non-null, non-
  7900. * zero value in the visible range. The y axis will show percentage
  7901. * or absolute change depending on whether `compare` is set to `"percent"`
  7902. * or `"value"`. When this is applied to multiple series, it allows
  7903. * comparing the development of the series against each other. Adds
  7904. * a `change` field to every point object.
  7905. *
  7906. * @see [compareBase](#plotOptions.series.compareBase)
  7907. * @see [Axis.setCompare()](/class-reference/Highcharts.Axis#setCompare)
  7908. *
  7909. * @sample {highstock} stock/plotoptions/series-compare-percent/
  7910. * Percent
  7911. * @sample {highstock} stock/plotoptions/series-compare-value/
  7912. * Value
  7913. *
  7914. * @type {string}
  7915. * @since 1.0.1
  7916. * @product highstock
  7917. * @apioption plotOptions.series.compare
  7918. */
  7919. /**
  7920. * Defines if comparison should start from the first point within the visible
  7921. * range or should start from the first point **before** the range.
  7922. *
  7923. * In other words, this flag determines if first point within the visible range
  7924. * will have 0% (`compareStart=true`) or should have been already calculated
  7925. * according to the previous point (`compareStart=false`).
  7926. *
  7927. * @sample {highstock} stock/plotoptions/series-comparestart/
  7928. * Calculate compare within visible range
  7929. *
  7930. * @type {boolean}
  7931. * @default false
  7932. * @since 6.0.0
  7933. * @product highstock
  7934. * @apioption plotOptions.series.compareStart
  7935. */
  7936. /**
  7937. * When [compare](#plotOptions.series.compare) is `percent`, this option
  7938. * dictates whether to use 0 or 100 as the base of comparison.
  7939. *
  7940. * @sample {highstock} stock/plotoptions/series-comparebase/
  7941. * Compare base is 100
  7942. *
  7943. * @type {number}
  7944. * @default 0
  7945. * @since 5.0.6
  7946. * @product highstock
  7947. * @validvalue [0, 100]
  7948. * @apioption plotOptions.series.compareBase
  7949. */
  7950. /* eslint-disable no-invalid-this, valid-jsdoc */
  7951. /**
  7952. * Factory function for creating new stock charts. Creates a new
  7953. * {@link Highcharts.Chart|Chart} object with different default options than the
  7954. * basic Chart.
  7955. *
  7956. * @example
  7957. * var chart = Highcharts.stockChart('container', {
  7958. * series: [{
  7959. * data: [1, 2, 3, 4, 5, 6, 7, 8, 9],
  7960. * pointInterval: 24 * 60 * 60 * 1000
  7961. * }]
  7962. * });
  7963. *
  7964. * @function Highcharts.stockChart
  7965. *
  7966. * @param {string|Highcharts.HTMLDOMElement} [renderTo]
  7967. * The DOM element to render to, or its id.
  7968. *
  7969. * @param {Highcharts.Options} options
  7970. * The chart options structure as described in the
  7971. * [options reference](https://api.highcharts.com/highstock).
  7972. *
  7973. * @param {Highcharts.ChartCallbackFunction} [callback]
  7974. * A function to execute when the chart object is finished loading and
  7975. * rendering. In most cases the chart is built in one thread, but in
  7976. * Internet Explorer version 8 or less the chart is sometimes
  7977. * initialized before the document is ready, and in these cases the
  7978. * chart object will not be finished synchronously. As a consequence,
  7979. * code that relies on the newly built Chart object should always run in
  7980. * the callback. Defining a
  7981. * [chart.events.load](https://api.highcharts.com/highstock/chart.events.load)
  7982. * handler is equivalent.
  7983. *
  7984. * @return {Highcharts.Chart}
  7985. * The chart object.
  7986. */
  7987. H.StockChart = H.stockChart = function (a, b, c) {
  7988. var hasRenderToArg = isString(a) || a.nodeName, options = arguments[hasRenderToArg ? 1 : 0], userOptions = options,
  7989. // to increase performance, don't merge the data
  7990. seriesOptions = options.series, defaultOptions = H.getOptions(), opposite, panning = options.chart && options.chart.panning,
  7991. // Always disable startOnTick:true on the main axis when the navigator
  7992. // is enabled (#1090)
  7993. navigatorEnabled = pick(options.navigator && options.navigator.enabled, defaultOptions.navigator.enabled, true), verticalPanningEnabled = panning && /y/.test(panning.type), disableStartOnTick = {
  7994. startOnTick: false,
  7995. endOnTick: false
  7996. };
  7997. // apply X axis options to both single and multi y axes
  7998. options.xAxis = splat(options.xAxis || {}).map(function (xAxisOptions, i) {
  7999. return merge({
  8000. minPadding: 0,
  8001. maxPadding: 0,
  8002. overscroll: 0,
  8003. ordinal: true,
  8004. title: {
  8005. text: null
  8006. },
  8007. labels: {
  8008. overflow: 'justify'
  8009. },
  8010. showLastLabel: true
  8011. }, defaultOptions.xAxis, // #3802
  8012. defaultOptions.xAxis && defaultOptions.xAxis[i], // #7690
  8013. xAxisOptions, // user options
  8014. {
  8015. type: 'datetime',
  8016. categories: null
  8017. }, (navigatorEnabled ? disableStartOnTick : null));
  8018. });
  8019. // apply Y axis options to both single and multi y axes
  8020. options.yAxis = splat(options.yAxis || {}).map(function (yAxisOptions, i) {
  8021. opposite = pick(yAxisOptions.opposite, true);
  8022. return merge({
  8023. labels: {
  8024. y: -2
  8025. },
  8026. opposite: opposite,
  8027. /**
  8028. * @default {highcharts} true
  8029. * @default {highstock} false
  8030. * @apioption yAxis.showLastLabel
  8031. *
  8032. * @private
  8033. */
  8034. showLastLabel: !!(
  8035. // #6104, show last label by default for category axes
  8036. yAxisOptions.categories ||
  8037. yAxisOptions.type === 'category'),
  8038. title: {
  8039. text: null
  8040. }
  8041. }, defaultOptions.yAxis, // #3802
  8042. defaultOptions.yAxis && defaultOptions.yAxis[i], // #7690
  8043. yAxisOptions, // user options
  8044. (verticalPanningEnabled ? disableStartOnTick : null));
  8045. });
  8046. options.series = null;
  8047. options = merge({
  8048. chart: {
  8049. panning: {
  8050. enabled: true,
  8051. type: 'x'
  8052. },
  8053. pinchType: 'x'
  8054. },
  8055. navigator: {
  8056. enabled: navigatorEnabled
  8057. },
  8058. scrollbar: {
  8059. // #4988 - check if setOptions was called
  8060. enabled: pick(defaultOptions.scrollbar.enabled, true)
  8061. },
  8062. rangeSelector: {
  8063. // #4988 - check if setOptions was called
  8064. enabled: pick(defaultOptions.rangeSelector.enabled, true)
  8065. },
  8066. title: {
  8067. text: null
  8068. },
  8069. tooltip: {
  8070. split: pick(defaultOptions.tooltip.split, true),
  8071. crosshairs: true
  8072. },
  8073. legend: {
  8074. enabled: false
  8075. }
  8076. }, options, // user's options
  8077. {
  8078. isStock: true // internal flag
  8079. });
  8080. options.series = userOptions.series = seriesOptions;
  8081. return hasRenderToArg ?
  8082. new Chart(a, options, c) :
  8083. new Chart(options, b);
  8084. };
  8085. // Handle som Stock-specific series defaults, override the plotOptions before
  8086. // series options are handled.
  8087. addEvent(Series, 'setOptions', function (e) {
  8088. var series = this, overrides;
  8089. /**
  8090. * @private
  8091. */
  8092. function is(type) {
  8093. return H.seriesTypes[type] && series instanceof H.seriesTypes[type];
  8094. }
  8095. if (this.chart.options.isStock) {
  8096. if (is('column') || is('columnrange')) {
  8097. overrides = {
  8098. borderWidth: 0,
  8099. shadow: false
  8100. };
  8101. }
  8102. else if (is('line') && !is('scatter') && !is('sma')) {
  8103. overrides = {
  8104. marker: {
  8105. enabled: false,
  8106. radius: 2
  8107. }
  8108. };
  8109. }
  8110. if (overrides) {
  8111. e.plotOptions[this.type] = merge(e.plotOptions[this.type], overrides);
  8112. }
  8113. }
  8114. });
  8115. // Override the automatic label alignment so that the first Y axis' labels
  8116. // are drawn on top of the grid line, and subsequent axes are drawn outside
  8117. addEvent(Axis, 'autoLabelAlign', function (e) {
  8118. var chart = this.chart, options = this.options, panes = chart._labelPanes = chart._labelPanes || {}, key, labelOptions = this.options.labels;
  8119. if (this.chart.options.isStock && this.coll === 'yAxis') {
  8120. key = options.top + ',' + options.height;
  8121. // do it only for the first Y axis of each pane
  8122. if (!panes[key] && labelOptions.enabled) {
  8123. if (labelOptions.x === 15) { // default
  8124. labelOptions.x = 0;
  8125. }
  8126. if (typeof labelOptions.align === 'undefined') {
  8127. labelOptions.align = 'right';
  8128. }
  8129. panes[key] = this;
  8130. e.align = 'right';
  8131. e.preventDefault();
  8132. }
  8133. }
  8134. });
  8135. // Clear axis from label panes (#6071)
  8136. addEvent(Axis, 'destroy', function () {
  8137. var chart = this.chart, key = this.options && (this.options.top + ',' + this.options.height);
  8138. if (key && chart._labelPanes && chart._labelPanes[key] === this) {
  8139. delete chart._labelPanes[key];
  8140. }
  8141. });
  8142. // Override getPlotLinePath to allow for multipane charts
  8143. addEvent(Axis, 'getPlotLinePath', function (e) {
  8144. var axis = this, series = (this.isLinked && !this.series ?
  8145. this.linkedParent.series :
  8146. this.series), chart = axis.chart, renderer = chart.renderer, axisLeft = axis.left, axisTop = axis.top, x1, y1, x2, y2, result = [], axes = [], // #3416 need a default array
  8147. axes2, uniqueAxes, translatedValue = e.translatedValue, value = e.value, force = e.force, transVal;
  8148. /**
  8149. * Return the other axis based on either the axis option or on related
  8150. * series.
  8151. * @private
  8152. */
  8153. function getAxis(coll) {
  8154. var otherColl = coll === 'xAxis' ? 'yAxis' : 'xAxis', opt = axis.options[otherColl];
  8155. // Other axis indexed by number
  8156. if (isNumber(opt)) {
  8157. return [chart[otherColl][opt]];
  8158. }
  8159. // Other axis indexed by id (like navigator)
  8160. if (isString(opt)) {
  8161. return [chart.get(opt)];
  8162. }
  8163. // Auto detect based on existing series
  8164. return series.map(function (s) {
  8165. return s[otherColl];
  8166. });
  8167. }
  8168. if ( // For stock chart, by default render paths across the panes
  8169. // except the case when `acrossPanes` is disabled by user (#6644)
  8170. (chart.options.isStock && e.acrossPanes !== false) &&
  8171. // Ignore in case of colorAxis or zAxis. #3360, #3524, #6720
  8172. axis.coll === 'xAxis' || axis.coll === 'yAxis') {
  8173. e.preventDefault();
  8174. // Get the related axes based on series
  8175. axes = getAxis(axis.coll);
  8176. // Get the related axes based options.*Axis setting #2810
  8177. axes2 = (axis.isXAxis ? chart.yAxis : chart.xAxis);
  8178. axes2.forEach(function (A) {
  8179. if (defined(A.options.id) ?
  8180. A.options.id.indexOf('navigator') === -1 :
  8181. true) {
  8182. var a = (A.isXAxis ? 'yAxis' : 'xAxis'), rax = (defined(A.options[a]) ?
  8183. chart[a][A.options[a]] :
  8184. chart[a][0]);
  8185. if (axis === rax) {
  8186. axes.push(A);
  8187. }
  8188. }
  8189. });
  8190. // Remove duplicates in the axes array. If there are no axes in the axes
  8191. // array, we are adding an axis without data, so we need to populate
  8192. // this with grid lines (#2796).
  8193. uniqueAxes = axes.length ?
  8194. [] :
  8195. [axis.isXAxis ? chart.yAxis[0] : chart.xAxis[0]]; // #3742
  8196. axes.forEach(function (axis2) {
  8197. if (uniqueAxes.indexOf(axis2) === -1 &&
  8198. // Do not draw on axis which overlap completely. #5424
  8199. !H.find(uniqueAxes, function (unique) {
  8200. return unique.pos === axis2.pos && unique.len === axis2.len;
  8201. })) {
  8202. uniqueAxes.push(axis2);
  8203. }
  8204. });
  8205. transVal = pick(translatedValue, axis.translate(value, null, null, e.old));
  8206. if (isNumber(transVal)) {
  8207. if (axis.horiz) {
  8208. uniqueAxes.forEach(function (axis2) {
  8209. var skip;
  8210. y1 = axis2.pos;
  8211. y2 = y1 + axis2.len;
  8212. x1 = x2 = Math.round(transVal + axis.transB);
  8213. // outside plot area
  8214. if (force !== 'pass' &&
  8215. (x1 < axisLeft || x1 > axisLeft + axis.width)) {
  8216. if (force) {
  8217. x1 = x2 = clamp(x1, axisLeft, axisLeft + axis.width);
  8218. }
  8219. else {
  8220. skip = true;
  8221. }
  8222. }
  8223. if (!skip) {
  8224. result.push('M', x1, y1, 'L', x2, y2);
  8225. }
  8226. });
  8227. }
  8228. else {
  8229. uniqueAxes.forEach(function (axis2) {
  8230. var skip;
  8231. x1 = axis2.pos;
  8232. x2 = x1 + axis2.len;
  8233. y1 = y2 = Math.round(axisTop + axis.height - transVal);
  8234. // outside plot area
  8235. if (force !== 'pass' &&
  8236. (y1 < axisTop || y1 > axisTop + axis.height)) {
  8237. if (force) {
  8238. y1 = y2 = clamp(y1, axisTop, axisTop + axis.height);
  8239. }
  8240. else {
  8241. skip = true;
  8242. }
  8243. }
  8244. if (!skip) {
  8245. result.push('M', x1, y1, 'L', x2, y2);
  8246. }
  8247. });
  8248. }
  8249. }
  8250. e.path = result.length > 0 ?
  8251. renderer.crispPolyLine(result, e.lineWidth || 1) :
  8252. // #3557 getPlotLinePath in regular Highcharts also returns null
  8253. null;
  8254. }
  8255. });
  8256. /**
  8257. * Function to crisp a line with multiple segments
  8258. *
  8259. * @private
  8260. * @function Highcharts.SVGRenderer#crispPolyLine
  8261. * @param {Highcharts.SVGPathArray} points
  8262. * @param {number} width
  8263. * @return {Highcharts.SVGPathArray}
  8264. */
  8265. SVGRenderer.prototype.crispPolyLine = function (points, width) {
  8266. // points format: ['M', 0, 0, 'L', 100, 0]
  8267. // normalize to a crisp line
  8268. var i;
  8269. for (i = 0; i < points.length; i = i + 6) {
  8270. if (points[i + 1] === points[i + 4]) {
  8271. // Substract due to #1129. Now bottom and left axis gridlines behave
  8272. // the same.
  8273. points[i + 1] = points[i + 4] =
  8274. Math.round(points[i + 1]) - (width % 2 / 2);
  8275. }
  8276. if (points[i + 2] === points[i + 5]) {
  8277. points[i + 2] = points[i + 5] =
  8278. Math.round(points[i + 2]) + (width % 2 / 2);
  8279. }
  8280. }
  8281. return points;
  8282. };
  8283. if (Renderer === VMLRenderer) {
  8284. VMLRenderer.prototype.crispPolyLine = SVGRenderer.prototype.crispPolyLine;
  8285. }
  8286. // Wrapper to hide the label
  8287. addEvent(Axis, 'afterHideCrosshair', function () {
  8288. if (this.crossLabel) {
  8289. this.crossLabel = this.crossLabel.hide();
  8290. }
  8291. });
  8292. // Extend crosshairs to also draw the label
  8293. addEvent(Axis, 'afterDrawCrosshair', function (event) {
  8294. // Check if the label has to be drawn
  8295. if (!defined(this.crosshair.label) ||
  8296. !this.crosshair.label.enabled ||
  8297. !this.cross) {
  8298. return;
  8299. }
  8300. var chart = this.chart, options = this.options.crosshair.label, // the label's options
  8301. horiz = this.horiz, // axis orientation
  8302. opposite = this.opposite, // axis position
  8303. left = this.left, // left position
  8304. top = this.top, // top position
  8305. crossLabel = this.crossLabel, // the svgElement
  8306. posx, posy, crossBox, formatOption = options.format, formatFormat = '', limit, align, tickInside = this.options.tickPosition === 'inside', snap = this.crosshair.snap !== false, value, offset = 0,
  8307. // Use last available event (#5287)
  8308. e = event.e || (this.cross && this.cross.e), point = event.point, lin2log = this.lin2log, min, max;
  8309. if (this.isLog) {
  8310. min = lin2log(this.min);
  8311. max = lin2log(this.max);
  8312. }
  8313. else {
  8314. min = this.min;
  8315. max = this.max;
  8316. }
  8317. align = (horiz ? 'center' : opposite ?
  8318. (this.labelAlign === 'right' ? 'right' : 'left') :
  8319. (this.labelAlign === 'left' ? 'left' : 'center'));
  8320. // If the label does not exist yet, create it.
  8321. if (!crossLabel) {
  8322. crossLabel = this.crossLabel = chart.renderer
  8323. .label(null, null, null, options.shape || 'callout')
  8324. .addClass('highcharts-crosshair-label' + (this.series[0] &&
  8325. ' highcharts-color-' + this.series[0].colorIndex))
  8326. .attr({
  8327. align: options.align || align,
  8328. padding: pick(options.padding, 8),
  8329. r: pick(options.borderRadius, 3),
  8330. zIndex: 2
  8331. })
  8332. .add(this.labelGroup);
  8333. // Presentational
  8334. if (!chart.styledMode) {
  8335. crossLabel
  8336. .attr({
  8337. fill: options.backgroundColor ||
  8338. (this.series[0] && this.series[0].color) ||
  8339. '#666666',
  8340. stroke: options.borderColor || '',
  8341. 'stroke-width': options.borderWidth || 0
  8342. })
  8343. .css(extend({
  8344. color: '#ffffff',
  8345. fontWeight: 'normal',
  8346. fontSize: '11px',
  8347. textAlign: 'center'
  8348. }, options.style));
  8349. }
  8350. }
  8351. if (horiz) {
  8352. posx = snap ? point.plotX + left : e.chartX;
  8353. posy = top + (opposite ? 0 : this.height);
  8354. }
  8355. else {
  8356. posx = opposite ? this.width + left : 0;
  8357. posy = snap ? point.plotY + top : e.chartY;
  8358. }
  8359. if (!formatOption && !options.formatter) {
  8360. if (this.isDatetimeAxis) {
  8361. formatFormat = '%b %d, %Y';
  8362. }
  8363. formatOption =
  8364. '{value' + (formatFormat ? ':' + formatFormat : '') + '}';
  8365. }
  8366. // Show the label
  8367. value = snap ?
  8368. point[this.isXAxis ? 'x' : 'y'] :
  8369. this.toValue(horiz ? e.chartX : e.chartY);
  8370. crossLabel.attr({
  8371. text: formatOption ?
  8372. format(formatOption, { value: value }, chart) :
  8373. options.formatter.call(this, value),
  8374. x: posx,
  8375. y: posy,
  8376. // Crosshair should be rendered within Axis range (#7219)
  8377. visibility: value < min || value > max ?
  8378. 'hidden' :
  8379. 'visible'
  8380. });
  8381. crossBox = crossLabel.getBBox();
  8382. // now it is placed we can correct its position
  8383. if (horiz) {
  8384. if ((tickInside && !opposite) || (!tickInside && opposite)) {
  8385. posy = crossLabel.y - crossBox.height;
  8386. }
  8387. }
  8388. else {
  8389. posy = crossLabel.y - (crossBox.height / 2);
  8390. }
  8391. // check the edges
  8392. if (horiz) {
  8393. limit = {
  8394. left: left - crossBox.x,
  8395. right: left + this.width - crossBox.x
  8396. };
  8397. }
  8398. else {
  8399. limit = {
  8400. left: this.labelAlign === 'left' ? left : 0,
  8401. right: this.labelAlign === 'right' ?
  8402. left + this.width :
  8403. chart.chartWidth
  8404. };
  8405. }
  8406. // left edge
  8407. if (crossLabel.translateX < limit.left) {
  8408. offset = limit.left - crossLabel.translateX;
  8409. }
  8410. // right edge
  8411. if (crossLabel.translateX + crossBox.width >= limit.right) {
  8412. offset = -(crossLabel.translateX + crossBox.width - limit.right);
  8413. }
  8414. // show the crosslabel
  8415. crossLabel.attr({
  8416. x: posx + offset,
  8417. y: posy,
  8418. // First set x and y, then anchorX and anchorY, when box is actually
  8419. // calculated, #5702
  8420. anchorX: horiz ?
  8421. posx :
  8422. (this.opposite ? 0 : chart.chartWidth),
  8423. anchorY: horiz ?
  8424. (this.opposite ? chart.chartHeight : 0) :
  8425. posy + crossBox.height / 2
  8426. });
  8427. });
  8428. /* ************************************************************************** *
  8429. * Start value compare logic *
  8430. * ************************************************************************** */
  8431. /**
  8432. * Extend series.init by adding a method to modify the y value used for plotting
  8433. * on the y axis. This method is called both from the axis when finding dataMin
  8434. * and dataMax, and from the series.translate method.
  8435. *
  8436. * @ignore
  8437. * @function Highcharts.Series#init
  8438. */
  8439. seriesProto.init = function () {
  8440. // Call base method
  8441. seriesInit.apply(this, arguments);
  8442. // Set comparison mode
  8443. this.setCompare(this.options.compare);
  8444. };
  8445. /**
  8446. * Highstock only. Set the
  8447. * [compare](https://api.highcharts.com/highstock/plotOptions.series.compare)
  8448. * mode of the series after render time. In most cases it is more useful running
  8449. * {@link Axis#setCompare} on the X axis to update all its series.
  8450. *
  8451. * @function Highcharts.Series#setCompare
  8452. *
  8453. * @param {string} [compare]
  8454. * Can be one of `null` (default), `"percent"` or `"value"`.
  8455. */
  8456. seriesProto.setCompare = function (compare) {
  8457. // Set or unset the modifyValue method
  8458. this.modifyValue = (compare === 'value' || compare === 'percent') ?
  8459. function (value, point) {
  8460. var compareValue = this.compareValue;
  8461. if (typeof value !== 'undefined' &&
  8462. typeof compareValue !== 'undefined') { // #2601, #5814
  8463. // Get the modified value
  8464. if (compare === 'value') {
  8465. value -= compareValue;
  8466. // Compare percent
  8467. }
  8468. else {
  8469. value = 100 * (value / compareValue) -
  8470. (this.options.compareBase === 100 ? 0 : 100);
  8471. }
  8472. // record for tooltip etc.
  8473. if (point) {
  8474. point.change = value;
  8475. }
  8476. return value;
  8477. }
  8478. return 0;
  8479. } :
  8480. null;
  8481. // Survive to export, #5485
  8482. this.userOptions.compare = compare;
  8483. // Mark dirty
  8484. if (this.chart.hasRendered) {
  8485. this.isDirty = true;
  8486. }
  8487. };
  8488. /**
  8489. * Extend series.processData by finding the first y value in the plot area,
  8490. * used for comparing the following values
  8491. *
  8492. * @ignore
  8493. * @function Highcharts.Series#processData
  8494. */
  8495. seriesProto.processData = function (force) {
  8496. var series = this, i, keyIndex = -1, processedXData, processedYData, compareStart = series.options.compareStart === true ? 0 : 1, length, compareValue;
  8497. // call base method
  8498. seriesProcessData.apply(this, arguments);
  8499. if (series.xAxis && series.processedYData) { // not pies
  8500. // local variables
  8501. processedXData = series.processedXData;
  8502. processedYData = series.processedYData;
  8503. length = processedYData.length;
  8504. // For series with more than one value (range, OHLC etc), compare
  8505. // against close or the pointValKey (#4922, #3112, #9854)
  8506. if (series.pointArrayMap) {
  8507. keyIndex = series.pointArrayMap.indexOf(series.options.pointValKey || series.pointValKey || 'y');
  8508. }
  8509. // find the first value for comparison
  8510. for (i = 0; i < length - compareStart; i++) {
  8511. compareValue = processedYData[i] && keyIndex > -1 ?
  8512. processedYData[i][keyIndex] :
  8513. processedYData[i];
  8514. if (isNumber(compareValue) &&
  8515. processedXData[i + compareStart] >=
  8516. series.xAxis.min &&
  8517. compareValue !== 0) {
  8518. series.compareValue = compareValue;
  8519. break;
  8520. }
  8521. }
  8522. }
  8523. return;
  8524. };
  8525. // Modify series extremes
  8526. addEvent(Series, 'afterGetExtremes', function () {
  8527. if (this.modifyValue) {
  8528. var extremes = [
  8529. this.modifyValue(this.dataMin),
  8530. this.modifyValue(this.dataMax)
  8531. ];
  8532. this.dataMin = arrayMin(extremes);
  8533. this.dataMax = arrayMax(extremes);
  8534. }
  8535. });
  8536. /**
  8537. * Highstock only. Set the compare mode on all series belonging to an Y axis
  8538. * after render time.
  8539. *
  8540. * @see [series.plotOptions.compare](https://api.highcharts.com/highstock/series.plotOptions.compare)
  8541. *
  8542. * @sample stock/members/axis-setcompare/
  8543. * Set compoare
  8544. *
  8545. * @function Highcharts.Axis#setCompare
  8546. *
  8547. * @param {string} [compare]
  8548. * The compare mode. Can be one of `null` (default), `"value"` or
  8549. * `"percent"`.
  8550. *
  8551. * @param {boolean} [redraw=true]
  8552. * Whether to redraw the chart or to wait for a later call to
  8553. * {@link Chart#redraw}.
  8554. */
  8555. Axis.prototype.setCompare = function (compare, redraw) {
  8556. if (!this.isXAxis) {
  8557. this.series.forEach(function (series) {
  8558. series.setCompare(compare);
  8559. });
  8560. if (pick(redraw, true)) {
  8561. this.chart.redraw();
  8562. }
  8563. }
  8564. };
  8565. /**
  8566. * Extend the tooltip formatter by adding support for the point.change variable
  8567. * as well as the changeDecimals option.
  8568. *
  8569. * @ignore
  8570. * @function Highcharts.Point#tooltipFormatter
  8571. *
  8572. * @param {string} pointFormat
  8573. */
  8574. Point.prototype.tooltipFormatter = function (pointFormat) {
  8575. var point = this;
  8576. var numberFormatter = point.series.chart.numberFormatter;
  8577. pointFormat = pointFormat.replace('{point.change}', (point.change > 0 ? '+' : '') + numberFormatter(point.change, pick(point.series.tooltipOptions.changeDecimals, 2)));
  8578. return pointTooltipFormatter.apply(this, [pointFormat]);
  8579. };
  8580. /* ************************************************************************** *
  8581. * End value compare logic *
  8582. * ************************************************************************** */
  8583. // Extend the Series prototype to create a separate series clip box. This is
  8584. // related to using multiple panes, and a future pane logic should incorporate
  8585. // this feature (#2754).
  8586. addEvent(Series, 'render', function () {
  8587. var chart = this.chart, clipHeight;
  8588. // Only do this on not 3d (#2939, #5904) nor polar (#6057) charts, and only
  8589. // if the series type handles clipping in the animate method (#2975).
  8590. if (!(chart.is3d && chart.is3d()) &&
  8591. !chart.polar &&
  8592. this.xAxis &&
  8593. !this.xAxis.isRadial // Gauge, #6192
  8594. ) {
  8595. clipHeight = this.yAxis.len;
  8596. // Include xAxis line width (#8031) but only if the Y axis ends on the
  8597. // edge of the X axis (#11005).
  8598. if (this.xAxis.axisLine) {
  8599. var dist = chart.plotTop + chart.plotHeight -
  8600. this.yAxis.pos - this.yAxis.len, lineHeightCorrection = Math.floor(this.xAxis.axisLine.strokeWidth() / 2);
  8601. if (dist >= 0) {
  8602. clipHeight -= Math.max(lineHeightCorrection - dist, 0);
  8603. }
  8604. }
  8605. // First render, initial clip box
  8606. if (!this.clipBox && this.animate) {
  8607. this.clipBox = merge(chart.clipBox);
  8608. this.clipBox.width = this.xAxis.len;
  8609. this.clipBox.height = clipHeight;
  8610. // On redrawing, resizing etc, update the clip rectangle
  8611. }
  8612. else if (chart[this.sharedClipKey]) {
  8613. // animate in case resize is done during initial animation
  8614. chart[this.sharedClipKey].animate({
  8615. width: this.xAxis.len,
  8616. height: clipHeight
  8617. });
  8618. // also change markers clip animation for consistency
  8619. // (marker clip rects should exist only on chart init)
  8620. if (chart[this.sharedClipKey + 'm']) {
  8621. chart[this.sharedClipKey + 'm'].animate({
  8622. width: this.xAxis.len
  8623. });
  8624. }
  8625. }
  8626. }
  8627. });
  8628. addEvent(Chart, 'update', function (e) {
  8629. var options = e.options;
  8630. // Use case: enabling scrollbar from a disabled state.
  8631. // Scrollbar needs to be initialized from a controller, Navigator in this
  8632. // case (#6615)
  8633. if ('scrollbar' in options && this.navigator) {
  8634. merge(true, this.options.scrollbar, options.scrollbar);
  8635. this.navigator.update({}, false);
  8636. delete options.scrollbar;
  8637. }
  8638. });
  8639. // Extend the Axis prototype to calculate start min/max values
  8640. // (including min/maxPadding). This is related to using vertical panning
  8641. // (#11315).
  8642. addEvent(Axis, 'afterSetScale', function () {
  8643. var axis = this, panning = axis.chart.options.chart &&
  8644. axis.chart.options.chart.panning;
  8645. if (panning &&
  8646. (panning.type === 'y' ||
  8647. panning.type === 'xy') &&
  8648. !axis.isXAxis &&
  8649. !defined(axis.panningState)) {
  8650. var min = Number.MAX_VALUE, max = Number.MIN_VALUE;
  8651. axis.series.forEach(function (series) {
  8652. min = Math.min(H.arrayMin(series.yData), min) -
  8653. (axis.min && axis.dataMin ? axis.dataMin - axis.min : 0);
  8654. max = Math.max(H.arrayMax(series.yData), max) +
  8655. (axis.max && axis.dataMax ? axis.max - axis.dataMax : 0);
  8656. });
  8657. axis.panningState = {
  8658. startMin: min,
  8659. startMax: max
  8660. };
  8661. }
  8662. });
  8663. });
  8664. _registerModule(_modules, 'masters/modules/stock.src.js', [], function () {
  8665. });
  8666. }));