stock.src.js 439 KB

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