stock.src.js 311 KB

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